1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: wx/font.h 3 // Purpose: wxFontBase class: the interface of wxFont 4 // Author: Vadim Zeitlin 5 // Modified by: 6 // Created: 20.09.99 7 // Copyright: (c) wxWidgets team 8 // Licence: wxWindows licence 9 ///////////////////////////////////////////////////////////////////////////// 10 11 #ifndef _WX_FONT_H_BASE_ 12 #define _WX_FONT_H_BASE_ 13 14 // ---------------------------------------------------------------------------- 15 // headers 16 // ---------------------------------------------------------------------------- 17 18 #include "wx/defs.h" // for wxDEFAULT &c 19 #include "wx/fontenc.h" // the font encoding constants 20 #include "wx/gdiobj.h" // the base class 21 #include "wx/gdicmn.h" // for wxGDIObjListBase 22 #include "wx/math.h" // for wxRound() 23 24 // ---------------------------------------------------------------------------- 25 // forward declarations 26 // ---------------------------------------------------------------------------- 27 28 class WXDLLIMPEXP_FWD_CORE wxFont; 29 30 // ---------------------------------------------------------------------------- 31 // font constants 32 // ---------------------------------------------------------------------------- 33 34 // standard font families: these may be used only for the font creation, it 35 // doesn't make sense to query an existing font for its font family as, 36 // especially if the font had been created from a native font description, it 37 // may be unknown 38 enum wxFontFamily 39 { 40 wxFONTFAMILY_DEFAULT = wxDEFAULT, 41 wxFONTFAMILY_DECORATIVE = wxDECORATIVE, 42 wxFONTFAMILY_ROMAN = wxROMAN, 43 wxFONTFAMILY_SCRIPT = wxSCRIPT, 44 wxFONTFAMILY_SWISS = wxSWISS, 45 wxFONTFAMILY_MODERN = wxMODERN, 46 wxFONTFAMILY_TELETYPE = wxTELETYPE, 47 wxFONTFAMILY_MAX, 48 wxFONTFAMILY_UNKNOWN = wxFONTFAMILY_MAX 49 }; 50 51 // font styles 52 enum wxFontStyle 53 { 54 wxFONTSTYLE_NORMAL = wxNORMAL, 55 wxFONTSTYLE_ITALIC = wxITALIC, 56 wxFONTSTYLE_SLANT = wxSLANT, 57 wxFONTSTYLE_MAX 58 }; 59 60 // font weights 61 enum wxFontWeight 62 { 63 wxFONTWEIGHT_INVALID = 0, 64 wxFONTWEIGHT_THIN = 100, 65 wxFONTWEIGHT_EXTRALIGHT = 200, 66 wxFONTWEIGHT_LIGHT = 300, 67 wxFONTWEIGHT_NORMAL = 400, 68 wxFONTWEIGHT_MEDIUM = 500, 69 wxFONTWEIGHT_SEMIBOLD = 600, 70 wxFONTWEIGHT_BOLD = 700, 71 wxFONTWEIGHT_EXTRABOLD = 800, 72 wxFONTWEIGHT_HEAVY = 900, 73 wxFONTWEIGHT_EXTRAHEAVY = 1000, 74 wxFONTWEIGHT_MAX = wxFONTWEIGHT_EXTRAHEAVY 75 }; 76 77 // Symbolic font sizes as defined in CSS specification. 78 enum wxFontSymbolicSize 79 { 80 wxFONTSIZE_XX_SMALL = -3, 81 wxFONTSIZE_X_SMALL, 82 wxFONTSIZE_SMALL, 83 wxFONTSIZE_MEDIUM, 84 wxFONTSIZE_LARGE, 85 wxFONTSIZE_X_LARGE, 86 wxFONTSIZE_XX_LARGE 87 }; 88 89 // the font flag bits for the new font ctor accepting one combined flags word 90 enum wxFontFlag 91 { 92 // no special flags: font with default weight/slant/anti-aliasing 93 wxFONTFLAG_DEFAULT = 0, 94 95 // slant flags (default: no slant) 96 wxFONTFLAG_ITALIC = 1 << 0, 97 wxFONTFLAG_SLANT = 1 << 1, 98 99 // weight flags (default: medium): 100 wxFONTFLAG_LIGHT = 1 << 2, 101 wxFONTFLAG_BOLD = 1 << 3, 102 103 // anti-aliasing flag: force on or off (default: the current system default) 104 wxFONTFLAG_ANTIALIASED = 1 << 4, 105 wxFONTFLAG_NOT_ANTIALIASED = 1 << 5, 106 107 // underlined/strikethrough flags (default: no lines) 108 wxFONTFLAG_UNDERLINED = 1 << 6, 109 wxFONTFLAG_STRIKETHROUGH = 1 << 7, 110 111 // the mask of all currently used flags 112 wxFONTFLAG_MASK = wxFONTFLAG_ITALIC | 113 wxFONTFLAG_SLANT | 114 wxFONTFLAG_LIGHT | 115 wxFONTFLAG_BOLD | 116 wxFONTFLAG_ANTIALIASED | 117 wxFONTFLAG_NOT_ANTIALIASED | 118 wxFONTFLAG_UNDERLINED | 119 wxFONTFLAG_STRIKETHROUGH 120 }; 121 122 // ---------------------------------------------------------------------------- 123 // wxFontInfo describes a wxFont 124 // ---------------------------------------------------------------------------- 125 126 class wxFontInfo 127 { 128 public: 129 // Default ctor uses the default font size appropriate for the current 130 // platform. wxFontInfo()131 wxFontInfo() 132 : m_pointSize(-1.0) 133 , m_pixelSize(wxDefaultSize) 134 { 135 Init(); 136 } 137 138 // These ctors specify the font size, either in points or in pixels. wxFontInfo(double pointSize)139 explicit wxFontInfo(double pointSize) 140 : m_pointSize(pointSize >= 0.0 ? pointSize : -1.0) 141 , m_pixelSize(wxDefaultSize) 142 { 143 Init(); 144 if (!wxIsSameDouble(m_pointSize, pointSize)) 145 { 146 wxFAIL_MSG("Invalid font point size"); 147 } 148 } wxFontInfo(const wxSize & pixelSize)149 explicit wxFontInfo(const wxSize& pixelSize) 150 : m_pointSize(-1.0) 151 , m_pixelSize(pixelSize) 152 { 153 Init(); 154 } 155 // Default copy ctor, assignment operator and dtor are OK 156 157 // Setters for the various attributes. All of them return the object itself 158 // so that the calls to them could be chained. Family(wxFontFamily family)159 wxFontInfo& Family(wxFontFamily family) 160 { m_family = family; return *this; } FaceName(const wxString & faceName)161 wxFontInfo& FaceName(const wxString& faceName) 162 { m_faceName = faceName; return *this; } 163 Weight(int weight)164 wxFontInfo& Weight(int weight) 165 { m_weight = weight; return *this; } 166 wxFontInfo& Bold(bool bold = true) 167 { return Weight(bold ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL); } 168 wxFontInfo& Light(bool light = true) 169 { return Weight(light ? wxFONTWEIGHT_LIGHT : wxFONTWEIGHT_NORMAL); } 170 171 wxFontInfo& Italic(bool italic = true) 172 { SetFlag(wxFONTFLAG_ITALIC, italic); return *this; } 173 wxFontInfo& Slant(bool slant = true) 174 { SetFlag(wxFONTFLAG_SLANT, slant); return *this; } Style(wxFontStyle style)175 wxFontInfo& Style(wxFontStyle style) 176 { 177 if ( style == wxFONTSTYLE_ITALIC ) 178 return Italic(); 179 180 if ( style == wxFONTSTYLE_SLANT ) 181 return Slant(); 182 183 return *this; 184 } 185 186 wxFontInfo& AntiAliased(bool antiAliased = true) 187 { SetFlag(wxFONTFLAG_ANTIALIASED, antiAliased); return *this; } 188 wxFontInfo& Underlined(bool underlined = true) 189 { SetFlag(wxFONTFLAG_UNDERLINED, underlined); return *this; } 190 wxFontInfo& Strikethrough(bool strikethrough = true) 191 { SetFlag(wxFONTFLAG_STRIKETHROUGH, strikethrough); return *this; } 192 Encoding(wxFontEncoding encoding)193 wxFontInfo& Encoding(wxFontEncoding encoding) 194 { m_encoding = encoding; return *this; } 195 196 // Set all flags at once. AllFlags(int flags)197 wxFontInfo& AllFlags(int flags) 198 { 199 m_flags = flags; 200 201 m_weight = m_flags & wxFONTFLAG_BOLD 202 ? wxFONTWEIGHT_BOLD 203 : m_flags & wxFONTFLAG_LIGHT 204 ? wxFONTWEIGHT_LIGHT 205 : wxFONTWEIGHT_NORMAL; 206 207 return *this; 208 } 209 210 // Accessors are mostly meant to be used by wxFont itself to extract the 211 // various pieces of the font description. 212 IsUsingSizeInPixels()213 bool IsUsingSizeInPixels() const { return m_pixelSize != wxDefaultSize; } GetFractionalPointSize()214 double GetFractionalPointSize() const { return m_pointSize; } GetPointSize()215 int GetPointSize() const { return wxRound(m_pointSize); } GetPixelSize()216 wxSize GetPixelSize() const { return m_pixelSize; } 217 218 // If face name is not empty, it has priority, otherwise use family. HasFaceName()219 bool HasFaceName() const { return !m_faceName.empty(); } GetFamily()220 wxFontFamily GetFamily() const { return m_family; } GetFaceName()221 const wxString& GetFaceName() const { return m_faceName; } 222 GetStyle()223 wxFontStyle GetStyle() const 224 { 225 return m_flags & wxFONTFLAG_ITALIC 226 ? wxFONTSTYLE_ITALIC 227 : m_flags & wxFONTFLAG_SLANT 228 ? wxFONTSTYLE_SLANT 229 : wxFONTSTYLE_NORMAL; 230 } 231 GetNumericWeight()232 int GetNumericWeight() const 233 { 234 return m_weight; 235 } 236 GetWeight()237 wxFontWeight GetWeight() const 238 { 239 return GetWeightClosestToNumericValue(m_weight); 240 } 241 IsAntiAliased()242 bool IsAntiAliased() const 243 { 244 return (m_flags & wxFONTFLAG_ANTIALIASED) != 0; 245 } 246 IsUnderlined()247 bool IsUnderlined() const 248 { 249 return (m_flags & wxFONTFLAG_UNDERLINED) != 0; 250 } 251 IsStrikethrough()252 bool IsStrikethrough() const 253 { 254 return (m_flags & wxFONTFLAG_STRIKETHROUGH) != 0; 255 } 256 GetEncoding()257 wxFontEncoding GetEncoding() const { return m_encoding; } 258 259 // Another helper for converting arbitrary numeric weight to the closest 260 // value of wxFontWeight enum. It should be avoided in the new code (also 261 // note that the function for the conversion in the other direction is 262 // trivial and so is not provided, we only have GetNumericWeightOf() which 263 // contains backwards compatibility hacks, but we don't need it here). GetWeightClosestToNumericValue(int numWeight)264 static wxFontWeight GetWeightClosestToNumericValue(int numWeight) 265 { 266 wxASSERT(numWeight > 0); 267 wxASSERT(numWeight <= 1000); 268 269 // round to nearest hundredth = wxFONTWEIGHT_ constant 270 int weight = ((numWeight + 50) / 100) * 100; 271 272 if (weight < wxFONTWEIGHT_THIN) 273 weight = wxFONTWEIGHT_THIN; 274 if (weight > wxFONTWEIGHT_MAX) 275 weight = wxFONTWEIGHT_MAX; 276 277 return static_cast<wxFontWeight>(weight); 278 } 279 280 private: Init()281 void Init() 282 { 283 m_family = wxFONTFAMILY_DEFAULT; 284 m_flags = wxFONTFLAG_DEFAULT; 285 m_weight = wxFONTWEIGHT_NORMAL; 286 m_encoding = wxFONTENCODING_DEFAULT; 287 } 288 289 // Turn on or off the given bit in m_flags depending on the value of the 290 // boolean argument. SetFlag(int flag,bool on)291 void SetFlag(int flag, bool on) 292 { 293 if ( on ) 294 m_flags |= flag; 295 else 296 m_flags &= ~flag; 297 } 298 299 // The size information: if m_pixelSize is valid (!= wxDefaultSize), then 300 // it is used. Otherwise m_pointSize is used, except if it is < 0, which 301 // means that the platform dependent font size should be used instead. 302 double m_pointSize; 303 wxSize m_pixelSize; 304 305 wxFontFamily m_family; 306 wxString m_faceName; 307 int m_flags; 308 int m_weight; 309 wxFontEncoding m_encoding; 310 }; 311 312 // ---------------------------------------------------------------------------- 313 // wxFontBase represents a font object 314 // ---------------------------------------------------------------------------- 315 316 class WXDLLIMPEXP_FWD_CORE wxNativeFontInfo; 317 318 class WXDLLIMPEXP_CORE wxFontBase : public wxGDIObject 319 { 320 public: 321 /* 322 derived classes should provide the following ctors: 323 324 wxFont(); 325 wxFont(const wxFontInfo& info); 326 wxFont(const wxString& nativeFontInfoString); 327 wxFont(const wxNativeFontInfo& info); 328 wxFont(int size, 329 wxFontFamily family, 330 wxFontStyle style, 331 wxFontWeight weight, 332 bool underlined = false, 333 const wxString& face = wxEmptyString, 334 wxFontEncoding encoding = wxFONTENCODING_DEFAULT); 335 wxFont(const wxSize& pixelSize, 336 wxFontFamily family, 337 wxFontStyle style, 338 wxFontWeight weight, 339 bool underlined = false, 340 const wxString& face = wxEmptyString, 341 wxFontEncoding encoding = wxFONTENCODING_DEFAULT); 342 */ 343 344 // creator function 345 virtual ~wxFontBase(); 346 347 348 // from the font components 349 static wxFont *New( 350 int pointSize, // size of the font in points 351 wxFontFamily family, // see wxFontFamily enum 352 wxFontStyle style, // see wxFontStyle enum 353 wxFontWeight weight, // see wxFontWeight enum 354 bool underlined = false, // not underlined by default 355 const wxString& face = wxEmptyString, // facename 356 wxFontEncoding encoding = wxFONTENCODING_DEFAULT); // ISO8859-X, ... 357 358 // from the font components 359 static wxFont *New( 360 const wxSize& pixelSize, // size of the font in pixels 361 wxFontFamily family, // see wxFontFamily enum 362 wxFontStyle style, // see wxFontStyle enum 363 wxFontWeight weight, // see wxFontWeight enum 364 bool underlined = false, // not underlined by default 365 const wxString& face = wxEmptyString, // facename 366 wxFontEncoding encoding = wxFONTENCODING_DEFAULT); // ISO8859-X, ... 367 368 // from the font components but using the font flags instead of separate 369 // parameters for each flag 370 static wxFont *New(int pointSize, 371 wxFontFamily family, 372 int flags = wxFONTFLAG_DEFAULT, 373 const wxString& face = wxEmptyString, 374 wxFontEncoding encoding = wxFONTENCODING_DEFAULT); 375 376 377 // from the font components but using the font flags instead of separate 378 // parameters for each flag 379 static wxFont *New(const wxSize& pixelSize, 380 wxFontFamily family, 381 int flags = wxFONTFLAG_DEFAULT, 382 const wxString& face = wxEmptyString, 383 wxFontEncoding encoding = wxFONTENCODING_DEFAULT); 384 385 // from the (opaque) native font description object 386 static wxFont *New(const wxNativeFontInfo& nativeFontDesc); 387 388 // from the string representation of wxNativeFontInfo 389 static wxFont *New(const wxString& strNativeFontDesc); 390 391 // Load the font from the given file and return true on success or false on 392 // error (an error message will be logged in this case). 393 #if wxUSE_PRIVATE_FONTS 394 static bool AddPrivateFont(const wxString& filename); 395 #endif // wxUSE_PRIVATE_FONTS 396 397 // comparison 398 bool operator==(const wxFont& font) const; 399 bool operator!=(const wxFont& font) const { return !(*this == font); } 400 401 // accessors: get the font characteristics 402 virtual int GetPointSize() const; 403 virtual double GetFractionalPointSize() const = 0; 404 virtual wxSize GetPixelSize() const; 405 virtual bool IsUsingSizeInPixels() const; 406 wxFontFamily GetFamily() const; 407 virtual wxFontStyle GetStyle() const = 0; 408 virtual int GetNumericWeight() const = 0; 409 virtual bool GetUnderlined() const = 0; GetStrikethrough()410 virtual bool GetStrikethrough() const { return false; } 411 virtual wxString GetFaceName() const = 0; 412 virtual wxFontEncoding GetEncoding() const = 0; 413 virtual const wxNativeFontInfo *GetNativeFontInfo() const = 0; 414 415 // Accessors that can be overridden in the platform-specific code but for 416 // which we provide a reasonable default implementation in the base class. 417 virtual wxFontWeight GetWeight() const; 418 virtual bool IsFixedWidth() const; 419 420 wxString GetNativeFontInfoDesc() const; 421 wxString GetNativeFontInfoUserDesc() const; 422 423 // change the font characteristics 424 virtual void SetPointSize( int pointSize ); 425 virtual void SetFractionalPointSize( double pointSize ) = 0; 426 virtual void SetPixelSize( const wxSize& pixelSize ); 427 virtual void SetFamily( wxFontFamily family ) = 0; 428 virtual void SetStyle( wxFontStyle style ) = 0; 429 virtual void SetNumericWeight( int weight ) = 0; 430 431 virtual void SetUnderlined( bool underlined ) = 0; SetStrikethrough(bool WXUNUSED (strikethrough))432 virtual void SetStrikethrough( bool WXUNUSED(strikethrough) ) {} 433 virtual void SetEncoding(wxFontEncoding encoding) = 0; 434 virtual bool SetFaceName( const wxString& faceName ); SetNativeFontInfo(const wxNativeFontInfo & info)435 void SetNativeFontInfo(const wxNativeFontInfo& info) 436 { DoSetNativeFontInfo(info); } 437 438 // Similarly to the accessors above, the functions in this group have a 439 // reasonable default implementation in the base class. 440 virtual void SetWeight( wxFontWeight weight ); 441 442 bool SetNativeFontInfo(const wxString& info); 443 bool SetNativeFontInfoUserDesc(const wxString& info); 444 445 // Symbolic font sizes support: set the font size to "large" or "very 446 // small" either absolutely (i.e. compared to the default font size) or 447 // relatively to the given font size. 448 void SetSymbolicSize(wxFontSymbolicSize size); SetSymbolicSizeRelativeTo(wxFontSymbolicSize size,int base)449 void SetSymbolicSizeRelativeTo(wxFontSymbolicSize size, int base) 450 { 451 SetPointSize(AdjustToSymbolicSize(size, base)); 452 } 453 454 // Adjust the base size in points according to symbolic size. 455 static int AdjustToSymbolicSize(wxFontSymbolicSize size, int base); 456 457 458 // translate the fonts into human-readable string (i.e. GetStyleString() 459 // will return "wxITALIC" for an italic font, ...) 460 wxString GetFamilyString() const; 461 wxString GetStyleString() const; 462 wxString GetWeightString() const; 463 464 // the default encoding is used for creating all fonts with default 465 // encoding parameter GetDefaultEncoding()466 static wxFontEncoding GetDefaultEncoding() { return ms_encodingDefault; } 467 static void SetDefaultEncoding(wxFontEncoding encoding); 468 469 // Account for legacy font weight values: if the argument is one of 470 // wxNORMAL, wxLIGHT or wxBOLD, return the corresponding wxFONTWEIGHT_XXX 471 // enum value. Otherwise just return it unchanged. 472 static int ConvertFromLegacyWeightIfNecessary(int weight); 473 474 // Convert between symbolic and numeric font weights. This function uses 475 // ConvertFromLegacyWeightIfNecessary(), so takes legacy values into 476 // account as well. 477 static int GetNumericWeightOf(wxFontWeight weight); 478 479 // this doesn't do anything and is kept for compatibility only 480 #if WXWIN_COMPATIBILITY_2_8 481 wxDEPRECATED_INLINE(void SetNoAntiAliasing(bool no = true), wxUnusedVar(no);) wxDEPRECATED_INLINE(bool GetNoAntiAliasing ()const,return false;)482 wxDEPRECATED_INLINE(bool GetNoAntiAliasing() const, return false;) 483 #endif // WXWIN_COMPATIBILITY_2_8 484 485 wxDEPRECATED_MSG("use wxFONTWEIGHT_XXX constants instead of raw values") 486 void SetWeight(int weight) 487 { SetWeight(static_cast<wxFontWeight>(weight)); } 488 489 wxDEPRECATED_MSG("use wxFONTWEIGHT_XXX constants instead of wxLIGHT/wxNORMAL/wxBOLD") SetWeight(wxDeprecatedGUIConstants weight)490 void SetWeight(wxDeprecatedGUIConstants weight) 491 { SetWeight(static_cast<wxFontWeight>(weight)); } 492 493 // from the font components 494 wxDEPRECATED_MSG("use wxFONT{FAMILY,STYLE,WEIGHT}_XXX constants") 495 static wxFont *New( 496 int pointSize, // size of the font in points 497 int family, // see wxFontFamily enum 498 int style, // see wxFontStyle enum 499 int weight, // see wxFontWeight enum 500 bool underlined = false, // not underlined by default 501 const wxString& face = wxEmptyString, // facename 502 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) // ISO8859-X, ... 503 { return New(pointSize, (wxFontFamily)family, (wxFontStyle)style, 504 (wxFontWeight)weight, underlined, face, encoding); } 505 506 // from the font components 507 wxDEPRECATED_MSG("use wxFONT{FAMILY,STYLE,WEIGHT}_XXX constants") 508 static wxFont *New( 509 const wxSize& pixelSize, // size of the font in pixels 510 int family, // see wxFontFamily enum 511 int style, // see wxFontStyle enum 512 int weight, // see wxFontWeight enum 513 bool underlined = false, // not underlined by default 514 const wxString& face = wxEmptyString, // facename 515 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) // ISO8859-X, ... 516 { return New(pixelSize, (wxFontFamily)family, (wxFontStyle)style, 517 (wxFontWeight)weight, underlined, face, encoding); } 518 519 520 protected: 521 // the function called by both overloads of SetNativeFontInfo() 522 virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info); 523 524 // The function called by public GetFamily(): it can return 525 // wxFONTFAMILY_UNKNOWN unlike the public method (see comment there). 526 virtual wxFontFamily DoGetFamily() const = 0; 527 528 529 // Helper functions to recover wxFONTSTYLE/wxFONTWEIGHT and underlined flag 530 // values from flags containing a combination of wxFONTFLAG_XXX. GetStyleFromFlags(int flags)531 static wxFontStyle GetStyleFromFlags(int flags) 532 { 533 return flags & wxFONTFLAG_ITALIC 534 ? wxFONTSTYLE_ITALIC 535 : flags & wxFONTFLAG_SLANT 536 ? wxFONTSTYLE_SLANT 537 : wxFONTSTYLE_NORMAL; 538 } 539 GetWeightFromFlags(int flags)540 static wxFontWeight GetWeightFromFlags(int flags) 541 { 542 return flags & wxFONTFLAG_LIGHT 543 ? wxFONTWEIGHT_LIGHT 544 : flags & wxFONTFLAG_BOLD 545 ? wxFONTWEIGHT_BOLD 546 : wxFONTWEIGHT_NORMAL; 547 } 548 GetUnderlinedFromFlags(int flags)549 static bool GetUnderlinedFromFlags(int flags) 550 { 551 return (flags & wxFONTFLAG_UNDERLINED) != 0; 552 } 553 GetStrikethroughFromFlags(int flags)554 static bool GetStrikethroughFromFlags(int flags) 555 { 556 return (flags & wxFONTFLAG_STRIKETHROUGH) != 0; 557 } 558 559 // Create wxFontInfo object from the parameters passed to the legacy wxFont 560 // ctor/Create() overload. This function implements the compatibility hack 561 // which interprets wxDEFAULT value of size as meaning -1 and also supports 562 // specifying wxNORMAL, wxLIGHT and wxBOLD as weight values. 563 static wxFontInfo InfoFromLegacyParams(int pointSize, 564 wxFontFamily family, 565 wxFontStyle style, 566 wxFontWeight weight, 567 bool underlined, 568 const wxString& face, 569 wxFontEncoding encoding); 570 571 static wxFontInfo InfoFromLegacyParams(const wxSize& pixelSize, 572 wxFontFamily family, 573 wxFontStyle style, 574 wxFontWeight weight, 575 bool underlined, 576 const wxString& face, 577 wxFontEncoding encoding); 578 579 private: 580 // the currently default encoding: by default, it's the default system 581 // encoding, but may be changed by the application using 582 // SetDefaultEncoding() to make all subsequent fonts created without 583 // specifying encoding parameter using this encoding 584 static wxFontEncoding ms_encodingDefault; 585 }; 586 587 // wxFontBase <-> wxString utilities, used by wxConfig 588 WXDLLIMPEXP_CORE wxString wxToString(const wxFontBase& font); 589 WXDLLIMPEXP_CORE bool wxFromString(const wxString& str, wxFontBase* font); 590 591 592 // this macro must be used in all derived wxFont classes declarations 593 #define wxDECLARE_COMMON_FONT_METHODS() \ 594 wxDEPRECATED_MSG("use wxFONTFAMILY_XXX constants") \ 595 void SetFamily(int family) \ 596 { SetFamily((wxFontFamily)family); } \ 597 wxDEPRECATED_MSG("use wxFONTSTYLE_XXX constants") \ 598 void SetStyle(int style) \ 599 { SetStyle((wxFontStyle)style); } \ 600 wxDEPRECATED_MSG("use wxFONTFAMILY_XXX constants") \ 601 void SetFamily(wxDeprecatedGUIConstants family) \ 602 { SetFamily((wxFontFamily)family); } \ 603 wxDEPRECATED_MSG("use wxFONTSTYLE_XXX constants") \ 604 void SetStyle(wxDeprecatedGUIConstants style) \ 605 { SetStyle((wxFontStyle)style); } \ 606 \ 607 /* functions for modifying font in place */ \ 608 wxFont& MakeBold(); \ 609 wxFont& MakeItalic(); \ 610 wxFont& MakeUnderlined(); \ 611 wxFont& MakeStrikethrough(); \ 612 wxFont& MakeLarger() { return Scale(1.2f); } \ 613 wxFont& MakeSmaller() { return Scale(1/1.2f); } \ 614 wxFont& Scale(float x); \ 615 /* functions for creating fonts based on this one */ \ 616 wxFont Bold() const; \ 617 wxFont GetBaseFont() const; \ 618 wxFont Italic() const; \ 619 wxFont Underlined() const; \ 620 wxFont Strikethrough() const; \ 621 wxFont Larger() const { return Scaled(1.2f); } \ 622 wxFont Smaller() const { return Scaled(1/1.2f); } \ 623 wxFont Scaled(float x) const 624 625 // include the real class declaration 626 #if defined(__WXMSW__) 627 #include "wx/msw/font.h" 628 #elif defined(__WXMOTIF__) 629 #include "wx/motif/font.h" 630 #elif defined(__WXGTK20__) 631 #include "wx/gtk/font.h" 632 #elif defined(__WXGTK__) 633 #include "wx/gtk1/font.h" 634 #elif defined(__WXX11__) 635 #include "wx/x11/font.h" 636 #elif defined(__WXDFB__) 637 #include "wx/dfb/font.h" 638 #elif defined(__WXMAC__) 639 #include "wx/osx/font.h" 640 #elif defined(__WXQT__) 641 #include "wx/qt/font.h" 642 #endif 643 644 class WXDLLIMPEXP_CORE wxFontList: public wxGDIObjListBase 645 { 646 public: 647 wxFont *FindOrCreateFont(int pointSize, 648 wxFontFamily family, 649 wxFontStyle style, 650 wxFontWeight weight, 651 bool underline = false, 652 const wxString& face = wxEmptyString, 653 wxFontEncoding encoding = wxFONTENCODING_DEFAULT); 654 655 wxDEPRECATED_MSG("use wxFONT{FAMILY,STYLE,WEIGHT}_XXX constants") 656 wxFont *FindOrCreateFont(int pointSize, int family, int style, int weight, 657 bool underline = false, 658 const wxString& face = wxEmptyString, 659 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) 660 { return FindOrCreateFont(pointSize, (wxFontFamily)family, (wxFontStyle)style, 661 (wxFontWeight)weight, underline, face, encoding); } 662 FindOrCreateFont(const wxFontInfo & fontInfo)663 wxFont *FindOrCreateFont(const wxFontInfo& fontInfo) 664 { return FindOrCreateFont(fontInfo.GetPointSize(), fontInfo.GetFamily(), 665 fontInfo.GetStyle(), fontInfo.GetWeight(), 666 fontInfo.IsUnderlined(), fontInfo.GetFaceName(), 667 fontInfo.GetEncoding()); } 668 }; 669 670 extern WXDLLIMPEXP_DATA_CORE(wxFontList*) wxTheFontList; 671 672 673 // provide comparison operators to allow code such as 674 // 675 // if ( font.GetStyle() == wxFONTSTYLE_SLANT ) 676 // 677 // to compile without warnings which it would otherwise provoke from some 678 // compilers as it compares elements of different enums 679 680 wxDEPRECATED_MSG("use wxFONTFAMILY_XXX constants") \ 681 inline bool operator==(wxFontFamily s, wxDeprecatedGUIConstants t) 682 { return static_cast<int>(s) == static_cast<int>(t); } 683 wxDEPRECATED_MSG("use wxFONTFAMILY_XXX constants") \ 684 inline bool operator!=(wxFontFamily s, wxDeprecatedGUIConstants t) 685 { return static_cast<int>(s) != static_cast<int>(t); } 686 wxDEPRECATED_MSG("use wxFONTSTYLE_XXX constants") \ 687 inline bool operator==(wxFontStyle s, wxDeprecatedGUIConstants t) 688 { return static_cast<int>(s) == static_cast<int>(t); } 689 wxDEPRECATED_MSG("use wxFONTSTYLE_XXX constants") \ 690 inline bool operator!=(wxFontStyle s, wxDeprecatedGUIConstants t) 691 { return static_cast<int>(s) != static_cast<int>(t); } 692 wxDEPRECATED_MSG("use wxFONTWEIGHT_XXX constants") \ 693 inline bool operator==(wxFontWeight s, wxDeprecatedGUIConstants t) 694 { return static_cast<int>(s) == static_cast<int>(t); } 695 wxDEPRECATED_MSG("use wxFONTWEIGHT_XXX constants") \ 696 inline bool operator!=(wxFontWeight s, wxDeprecatedGUIConstants t) 697 { return static_cast<int>(s) != static_cast<int>(t); } 698 699 #endif // _WX_FONT_H_BASE_ 700