font.h 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: font.h
  3. // Purpose: interface of wxFont
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. Standard font families: these are used mainly during wxFont creation to specify
  9. the generic properties of the font without hardcoding in the sources a specific
  10. face name.
  11. wxFontFamily thus allows to group the font face names of fonts with similar
  12. properties. Most wxWidgets ports use lists of fonts for each font family
  13. inspired by the data taken from http://www.codestyle.org/css/font-family.
  14. */
  15. enum wxFontFamily
  16. {
  17. wxFONTFAMILY_DEFAULT = wxDEFAULT, //!< Chooses a default font.
  18. wxFONTFAMILY_DECORATIVE = wxDECORATIVE, //!< A decorative font.
  19. wxFONTFAMILY_ROMAN = wxROMAN, //!< A formal, serif font.
  20. wxFONTFAMILY_SCRIPT = wxSCRIPT, //!< A handwriting font.
  21. wxFONTFAMILY_SWISS = wxSWISS, //!< A sans-serif font.
  22. /// A fixed pitch font. Note that wxFont currently does not make distinctions
  23. /// between @c wxFONTFAMILY_MODERN and @c wxFONTFAMILY_TELETYPE.
  24. wxFONTFAMILY_MODERN = wxMODERN,
  25. /// A teletype (i.e. monospaced) font.
  26. /// Monospace fonts have a fixed width like typewriters and often have strong angular
  27. /// or block serifs. Monospace font faces are often used code samples and have a simple,
  28. /// functional font style.
  29. /// See also wxFont::IsFixedWidth() for an easy way to test for monospace property.
  30. wxFONTFAMILY_TELETYPE = wxTELETYPE,
  31. wxFONTFAMILY_MAX,
  32. /// Invalid font family value, returned by wxFont::GetFamily() when the
  33. /// font is invalid for example.
  34. wxFONTFAMILY_UNKNOWN = wxFONTFAMILY_MAX
  35. };
  36. /**
  37. Font styles.
  38. */
  39. enum wxFontStyle
  40. {
  41. /// The font is drawn without slant.
  42. wxFONTSTYLE_NORMAL = wxNORMAL,
  43. /// The font is slanted in an italic style.
  44. wxFONTSTYLE_ITALIC = wxITALIC,
  45. /// The font is slanted, but in a roman style.
  46. /// Note that under wxMSW this style is the same as @c wxFONTSTYLE_ITALIC.
  47. wxFONTSTYLE_SLANT = wxSLANT,
  48. wxFONTSTYLE_MAX
  49. };
  50. /**
  51. Font weights.
  52. */
  53. enum wxFontWeight
  54. {
  55. wxFONTWEIGHT_NORMAL = wxNORMAL, //!< Normal font.
  56. wxFONTWEIGHT_LIGHT = wxLIGHT, //!< Light font.
  57. wxFONTWEIGHT_BOLD = wxBOLD, //!< Bold font.
  58. wxFONTWEIGHT_MAX
  59. };
  60. /**
  61. Symbolic font sizes.
  62. The elements of this enum correspond to CSS absolute size specifications,
  63. see http://www.w3.org/TR/CSS21/fonts.html#font-size-props
  64. @see wxFont::SetSymbolicSize()
  65. @since 2.9.2
  66. */
  67. enum wxFontSymbolicSize
  68. {
  69. wxFONTSIZE_XX_SMALL = -3, //!< Extra small.
  70. wxFONTSIZE_X_SMALL, //!< Very small.
  71. wxFONTSIZE_SMALL, //!< Small.
  72. wxFONTSIZE_MEDIUM, //!< Normal.
  73. wxFONTSIZE_LARGE, //!< Large.
  74. wxFONTSIZE_X_LARGE, //!< Very large.
  75. wxFONTSIZE_XX_LARGE //!< Extra large.
  76. };
  77. /**
  78. The font flag bits for the new font ctor accepting one combined flags word.
  79. */
  80. enum wxFontFlag
  81. {
  82. /// no special flags: font with default weight/slant/anti-aliasing
  83. wxFONTFLAG_DEFAULT = 0,
  84. /// slant flags (default: no slant)
  85. wxFONTFLAG_ITALIC = 1 << 0,
  86. wxFONTFLAG_SLANT = 1 << 1,
  87. /// weight flags (default: medium)
  88. wxFONTFLAG_LIGHT = 1 << 2,
  89. wxFONTFLAG_BOLD = 1 << 3,
  90. /// anti-aliasing flag: force on or off (default: the current system default)
  91. wxFONTFLAG_ANTIALIASED = 1 << 4,
  92. wxFONTFLAG_NOT_ANTIALIASED = 1 << 5,
  93. /// Underlined style (not underlined by default).
  94. wxFONTFLAG_UNDERLINED = 1 << 6,
  95. /// Strike-through style (only supported in wxMSW and wxGTK currently).
  96. wxFONTFLAG_STRIKETHROUGH = 1 << 7,
  97. /// the mask of all currently used flags
  98. wxFONTFLAG_MASK = wxFONTFLAG_ITALIC |
  99. wxFONTFLAG_SLANT |
  100. wxFONTFLAG_LIGHT |
  101. wxFONTFLAG_BOLD |
  102. wxFONTFLAG_ANTIALIASED |
  103. wxFONTFLAG_NOT_ANTIALIASED |
  104. wxFONTFLAG_UNDERLINED |
  105. wxFONTFLAG_STRIKETHROUGH
  106. };
  107. /**
  108. Font encodings.
  109. See wxFont::SetEncoding().
  110. */
  111. enum wxFontEncoding
  112. {
  113. /// Default system encoding.
  114. wxFONTENCODING_SYSTEM = -1, // system default
  115. /// Default application encoding.
  116. wxFONTENCODING_DEFAULT, // current default encoding
  117. // ISO8859 standard defines a number of single-byte charsets
  118. wxFONTENCODING_ISO8859_1, //!< West European (Latin1)
  119. wxFONTENCODING_ISO8859_2, //!< Central and East European (Latin2)
  120. wxFONTENCODING_ISO8859_3, //!< Esperanto (Latin3)
  121. wxFONTENCODING_ISO8859_4, //!< Baltic (old) (Latin4)
  122. wxFONTENCODING_ISO8859_5, //!< Cyrillic
  123. wxFONTENCODING_ISO8859_6, //!< Arabic
  124. wxFONTENCODING_ISO8859_7, //!< Greek
  125. wxFONTENCODING_ISO8859_8, //!< Hebrew
  126. wxFONTENCODING_ISO8859_9, //!< Turkish (Latin5)
  127. wxFONTENCODING_ISO8859_10, //!< Variation of Latin4 (Latin6)
  128. wxFONTENCODING_ISO8859_11, //!< Thai
  129. wxFONTENCODING_ISO8859_12, //!< doesn't exist currently, but put it
  130. //!< here anyhow to make all ISO8859
  131. //!< consecutive numbers
  132. wxFONTENCODING_ISO8859_13, //!< Baltic (Latin7)
  133. wxFONTENCODING_ISO8859_14, //!< Latin8
  134. wxFONTENCODING_ISO8859_15, //!< Latin9 (a.k.a. Latin0, includes euro)
  135. wxFONTENCODING_ISO8859_MAX,
  136. // Cyrillic charset soup (see http://czyborra.com/charsets/cyrillic.html)
  137. wxFONTENCODING_KOI8, //!< KOI8 Russian
  138. wxFONTENCODING_KOI8_U, //!< KOI8 Ukrainian
  139. wxFONTENCODING_ALTERNATIVE, //!< same as MS-DOS CP866
  140. wxFONTENCODING_BULGARIAN, //!< used under Linux in Bulgaria
  141. // what would we do without Microsoft? They have their own encodings
  142. // for DOS
  143. wxFONTENCODING_CP437, //!< original MS-DOS codepage
  144. wxFONTENCODING_CP850, //!< CP437 merged with Latin1
  145. wxFONTENCODING_CP852, //!< CP437 merged with Latin2
  146. wxFONTENCODING_CP855, //!< another cyrillic encoding
  147. wxFONTENCODING_CP866, //!< and another one
  148. // and for Windows
  149. wxFONTENCODING_CP874, //!< WinThai
  150. wxFONTENCODING_CP932, //!< Japanese (shift-JIS)
  151. wxFONTENCODING_CP936, //!< Chinese simplified (GB)
  152. wxFONTENCODING_CP949, //!< Korean (Hangul charset)
  153. wxFONTENCODING_CP950, //!< Chinese (traditional - Big5)
  154. wxFONTENCODING_CP1250, //!< WinLatin2
  155. wxFONTENCODING_CP1251, //!< WinCyrillic
  156. wxFONTENCODING_CP1252, //!< WinLatin1
  157. wxFONTENCODING_CP1253, //!< WinGreek (8859-7)
  158. wxFONTENCODING_CP1254, //!< WinTurkish
  159. wxFONTENCODING_CP1255, //!< WinHebrew
  160. wxFONTENCODING_CP1256, //!< WinArabic
  161. wxFONTENCODING_CP1257, //!< WinBaltic (same as Latin 7)
  162. wxFONTENCODING_CP1258, //!< WinVietnamese (since 2.9.4)
  163. wxFONTENCODING_CP1361, //!< Johab Korean character set (since 2.9.4)
  164. wxFONTENCODING_CP12_MAX,
  165. wxFONTENCODING_UTF7, //!< UTF-7 Unicode encoding
  166. wxFONTENCODING_UTF8, //!< UTF-8 Unicode encoding
  167. wxFONTENCODING_EUC_JP, //!< Extended Unix Codepage for Japanese
  168. wxFONTENCODING_UTF16BE, //!< UTF-16 Big Endian Unicode encoding
  169. wxFONTENCODING_UTF16LE, //!< UTF-16 Little Endian Unicode encoding
  170. wxFONTENCODING_UTF32BE, //!< UTF-32 Big Endian Unicode encoding
  171. wxFONTENCODING_UTF32LE, // UTF-32 Little Endian Unicode encoding
  172. wxFONTENCODING_MACROMAN, //!< the standard mac encodings
  173. wxFONTENCODING_MACJAPANESE,
  174. wxFONTENCODING_MACCHINESETRAD,
  175. wxFONTENCODING_MACKOREAN,
  176. wxFONTENCODING_MACARABIC,
  177. wxFONTENCODING_MACHEBREW,
  178. wxFONTENCODING_MACGREEK,
  179. wxFONTENCODING_MACCYRILLIC,
  180. wxFONTENCODING_MACDEVANAGARI,
  181. wxFONTENCODING_MACGURMUKHI,
  182. wxFONTENCODING_MACGUJARATI,
  183. wxFONTENCODING_MACORIYA,
  184. wxFONTENCODING_MACBENGALI,
  185. wxFONTENCODING_MACTAMIL,
  186. wxFONTENCODING_MACTELUGU,
  187. wxFONTENCODING_MACKANNADA,
  188. wxFONTENCODING_MACMALAJALAM,
  189. wxFONTENCODING_MACSINHALESE,
  190. wxFONTENCODING_MACBURMESE,
  191. wxFONTENCODING_MACKHMER,
  192. wxFONTENCODING_MACTHAI,
  193. wxFONTENCODING_MACLAOTIAN,
  194. wxFONTENCODING_MACGEORGIAN,
  195. wxFONTENCODING_MACARMENIAN,
  196. wxFONTENCODING_MACCHINESESIMP,
  197. wxFONTENCODING_MACTIBETAN,
  198. wxFONTENCODING_MACMONGOLIAN,
  199. wxFONTENCODING_MACETHIOPIC,
  200. wxFONTENCODING_MACCENTRALEUR,
  201. wxFONTENCODING_MACVIATNAMESE,
  202. wxFONTENCODING_MACARABICEXT,
  203. wxFONTENCODING_MACSYMBOL,
  204. wxFONTENCODING_MACDINGBATS,
  205. wxFONTENCODING_MACTURKISH,
  206. wxFONTENCODING_MACCROATIAN,
  207. wxFONTENCODING_MACICELANDIC,
  208. wxFONTENCODING_MACROMANIAN,
  209. wxFONTENCODING_MACCELTIC,
  210. wxFONTENCODING_MACGAELIC,
  211. wxFONTENCODING_MACKEYBOARD,
  212. // more CJK encodings (for historical reasons some are already declared
  213. // above)
  214. wxFONTENCODING_ISO2022_JP, //!< ISO-2022-JP JIS encoding
  215. wxFONTENCODING_MAX, //!< highest enumerated encoding value
  216. wxFONTENCODING_MACMIN = wxFONTENCODING_MACROMAN ,
  217. wxFONTENCODING_MACMAX = wxFONTENCODING_MACKEYBOARD ,
  218. // aliases for endian-dependent UTF encodings
  219. wxFONTENCODING_UTF16, //!< native UTF-16
  220. wxFONTENCODING_UTF32, //!< native UTF-32
  221. /// Alias for the native Unicode encoding on this platform
  222. /// (this is used by wxEncodingConverter and wxUTFFile only for now)
  223. wxFONTENCODING_UNICODE,
  224. wxFONTENCODING_GB2312 = wxFONTENCODING_CP936, //!< Simplified Chinese
  225. wxFONTENCODING_BIG5 = wxFONTENCODING_CP950, //!< Traditional Chinese
  226. wxFONTENCODING_SHIFT_JIS = wxFONTENCODING_CP932, //!< Shift JIS
  227. wxFONTENCODING_EUC_KR = wxFONTENCODING_CP949, //!< Korean
  228. wxFONTENCODING_JOHAB = wxFONTENCODING_CP1361, //!< Korean Johab (since 2.9.4)
  229. wxFONTENCODING_VIETNAMESE = wxFONTENCODING_CP1258 //!< Vietnamese (since 2.9.4)
  230. };
  231. /**
  232. @class wxFontInfo
  233. This class is a helper used for wxFont creation using named parameter
  234. idiom: it allows to specify various wxFont attributes using the chained
  235. calls to its clearly named methods instead of passing them in the fixed
  236. order to wxFont constructors.
  237. For example, to create an italic font with the given face name and size you
  238. could use:
  239. @code
  240. wxFont font(wxFontInfo(12).FaceName("Helvetica").Italic());
  241. @endcode
  242. Notice that all of the methods of this object return a reference to the
  243. object itself, allowing the calls to them to be chained as in the example
  244. above.
  245. All methods taking boolean parameters can be used to turn the specified
  246. font attribute on or off and turn it on by default.
  247. @since 2.9.5
  248. */
  249. class wxFontInfo
  250. {
  251. public:
  252. /**
  253. Default constructor uses the default font size for the current
  254. platform.
  255. */
  256. wxFontInfo();
  257. /**
  258. Constructor setting the font size in points to use.
  259. @see wxFont::SetPointSize()
  260. */
  261. explicit wxFontInfo(int pointSize);
  262. /**
  263. Constructor setting the font size in pixels to use.
  264. @see wxFont::SetPixelSize()
  265. */
  266. explicit wxFontInfo(const wxSize& pixelSize);
  267. /**
  268. Set the font family.
  269. The family is a generic portable way of referring to fonts without
  270. specifying a precise face name. This parameter must be one of the
  271. ::wxFontFamily enumeration values.
  272. If the FaceName() is used, then it overrides the font family.
  273. @see wxFont::SetFamily()
  274. */
  275. wxFontInfo& Family(wxFontFamily family);
  276. /**
  277. Set the font face name to use.
  278. Face names are not portable, so prefer to use Family() in portable
  279. code.
  280. @see wxFont::SetFaceName()
  281. */
  282. wxFontInfo& FaceName(const wxString& faceName);
  283. /**
  284. Use a bold version of the font.
  285. @see ::wxFontWeight, wxFont::SetWeight()
  286. */
  287. wxFontInfo& Bold(bool bold = true);
  288. /**
  289. Use a lighter version of the font.
  290. @see ::wxFontWeight, wxFont::SetWeight()
  291. */
  292. wxFontInfo& Light(bool light = true);
  293. /**
  294. Use an italic version of the font.
  295. @see ::wxFontStyle, wxFont::SetStyle()
  296. */
  297. wxFontInfo& Italic(bool italic = true);
  298. /**
  299. Use a slanted version of the font.
  300. @see ::wxFontStyle, wxFont::SetStyle()
  301. */
  302. wxFontInfo& Slant(bool slant = true);
  303. /**
  304. Set anti-aliasing flag.
  305. Force the use of anti-aliasing on or off.
  306. Currently this is not implemented, i.e. using this method doesn't do
  307. anything.
  308. */
  309. wxFontInfo& AntiAliased(bool antiAliased = true);
  310. /**
  311. Use an underlined version of the font.
  312. */
  313. wxFontInfo& Underlined(bool underlined = true);
  314. /**
  315. Use a strike-through version of the font.
  316. Currently this is only implemented in wxMSW and wxGTK.
  317. */
  318. wxFontInfo& Strikethrough(bool strikethrough = true);
  319. /**
  320. Set the font encoding to use.
  321. This is mostly unneeded in Unicode builds of wxWidgets.
  322. @see ::wxFontEncoding, wxFont::SetEncoding()
  323. */
  324. wxFontInfo& Encoding(wxFontEncoding encoding);
  325. /**
  326. Set all the font attributes at once.
  327. See ::wxFontFlag for the various flags that can be used.
  328. */
  329. wxFontInfo& AllFlags(int flags);
  330. };
  331. /**
  332. @class wxFont
  333. A font is an object which determines the appearance of text.
  334. Fonts are used for drawing text to a device context, and setting the appearance
  335. of a window's text, see wxDC::SetFont() and wxWindow::SetFont().
  336. The easiest way to create a custom font is to use wxFontInfo object to
  337. specify the font attributes and then use wxFont::wxFont(const wxFontInfo&)
  338. constructor. Alternatively, you could start with one of the pre-defined
  339. fonts or use wxWindow::GetFont() and modify the font, e.g. by increasing
  340. its size using MakeLarger() or changing its weight using MakeBold().
  341. This class uses @ref overview_refcount "reference counting and copy-on-write"
  342. internally so that assignments between two instances of this class are very
  343. cheap. You can therefore use actual objects instead of pointers without
  344. efficiency problems. If an instance of this class is changed it will create
  345. its own data internally so that other instances, which previously shared the
  346. data using the reference counting, are not affected.
  347. You can retrieve the current system font settings with wxSystemSettings.
  348. @library{wxcore}
  349. @category{gdi}
  350. @stdobjects
  351. ::wxNullFont, ::wxNORMAL_FONT, ::wxSMALL_FONT, ::wxITALIC_FONT, ::wxSWISS_FONT
  352. @see @ref overview_font, wxDC::SetFont, wxDC::DrawText,
  353. wxDC::GetTextExtent, wxFontDialog, wxSystemSettings
  354. */
  355. class wxFont : public wxGDIObject
  356. {
  357. public:
  358. /**
  359. Default ctor.
  360. */
  361. wxFont();
  362. /**
  363. Copy constructor, uses @ref overview_refcount "reference counting".
  364. */
  365. wxFont(const wxFont& font);
  366. /**
  367. Creates a font object using the specified font description.
  368. This is the preferred way to create font objects as using this ctor
  369. results in more readable code and it is also extensible, e.g. it could
  370. continue to be used if support for more font attributes is added in the
  371. future. For example, this constructor provides the only way of creating
  372. fonts with strike-through style.
  373. Example of creating a font using this ctor:
  374. @code
  375. wxFont font(wxFontInfo(10).Bold().Underlined());
  376. @endcode
  377. @since 2.9.5
  378. */
  379. wxFont(const wxFontInfo& font);
  380. /**
  381. Creates a font object with the specified attributes and size in points.
  382. Notice that the use of this constructor is often more verbose and less
  383. readable than the use of constructor from wxFontInfo, e.g. the example
  384. in that constructor documentation would need to be written as
  385. @code
  386. wxFont font(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
  387. wxFONTWEIGHT_BOLD, true);
  388. @endcode
  389. which is longer and less clear.
  390. @param pointSize
  391. Size in points. See SetPointSize() for more info.
  392. @param family
  393. The font family: a generic portable way of referring to fonts without specifying a
  394. facename. This parameter must be one of the ::wxFontFamily enumeration values.
  395. If the @a faceName argument is provided, then it overrides the font family.
  396. @param style
  397. One of @c wxFONTSTYLE_NORMAL, @c wxFONTSTYLE_SLANT and @c wxFONTSTYLE_ITALIC.
  398. @param weight
  399. Font weight, sometimes also referred to as font boldness.
  400. One of the ::wxFontWeight enumeration values.
  401. @param underline
  402. The value can be @true or @false.
  403. At present this has an effect on Windows and Motif 2.x only.
  404. @param faceName
  405. An optional string specifying the face name to be used.
  406. If it is an empty string, a default face name will be chosen based on the family.
  407. @param encoding
  408. An encoding which may be one of the enumeration values of ::wxFontEncoding.
  409. Briefly these can be summed up as:
  410. <TABLE>
  411. <TR><TD>@c wxFONTENCODING_SYSTEM</TD><TD>Default system encoding.</TD></TR>
  412. <TR><TD>@c wxFONTENCODING_DEFAULT</TD><TD>
  413. Default application encoding: this is the encoding set by calls to
  414. SetDefaultEncoding() and which may be set to, say, KOI8 to create all
  415. fonts by default with KOI8 encoding. Initially, the default application
  416. encoding is the same as default system encoding.</TD></TR>
  417. <TR><TD>@c wxFONTENCODING_ISO8859_1...15</TD><TD>ISO8859 encodings.</TD></TR>
  418. <TR><TD>@c wxFONTENCODING_KOI8</TD><TD>The standard Russian encoding for Internet.</TD></TR>
  419. <TR><TD>@c wxFONTENCODING_CP1250...1252</TD><TD>Windows encodings similar to ISO8859 (but not identical).</TD></TR>
  420. </TABLE>
  421. If the specified encoding isn't available, no font is created
  422. (see also @ref overview_fontencoding).
  423. @remarks If the desired font does not exist, the closest match will be
  424. chosen. Under Windows, only scalable TrueType fonts are used.
  425. */
  426. wxFont(int pointSize, wxFontFamily family, wxFontStyle style,
  427. wxFontWeight weight,
  428. bool underline = false,
  429. const wxString& faceName = wxEmptyString,
  430. wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
  431. /**
  432. Creates a font object with the specified attributes and size in pixels.
  433. Notice that the use of this constructor is often more verbose and less
  434. readable than the use of constructor from wxFontInfo, consider using
  435. that constructor instead.
  436. @param pixelSize
  437. Size in pixels. See SetPixelSize() for more info.
  438. @param family
  439. The font family: a generic portable way of referring to fonts without specifying a
  440. facename. This parameter must be one of the ::wxFontFamily enumeration values.
  441. If the @a faceName argument is provided, then it overrides the font family.
  442. @param style
  443. One of @c wxFONTSTYLE_NORMAL, @c wxFONTSTYLE_SLANT and @c wxFONTSTYLE_ITALIC.
  444. @param weight
  445. Font weight, sometimes also referred to as font boldness.
  446. One of the ::wxFontWeight enumeration values.
  447. @param underline
  448. The value can be @true or @false.
  449. At present this has an effect on Windows and Motif 2.x only.
  450. @param faceName
  451. An optional string specifying the face name to be used.
  452. If it is an empty string, a default face name will be chosen based on the family.
  453. @param encoding
  454. An encoding which may be one of the enumeration values of ::wxFontEncoding.
  455. Briefly these can be summed up as:
  456. <TABLE>
  457. <TR><TD>@c wxFONTENCODING_SYSTEM</TD><TD>Default system encoding.</TD></TR>
  458. <TR><TD>@c wxFONTENCODING_DEFAULT</TD><TD>
  459. Default application encoding: this is the encoding set by calls to
  460. SetDefaultEncoding() and which may be set to, say, KOI8 to create all
  461. fonts by default with KOI8 encoding. Initially, the default application
  462. encoding is the same as default system encoding.</TD></TR>
  463. <TR><TD>@c wxFONTENCODING_ISO8859_1...15</TD><TD>ISO8859 encodings.</TD></TR>
  464. <TR><TD>@c wxFONTENCODING_KOI8</TD><TD>The standard Russian encoding for Internet.</TD></TR>
  465. <TR><TD>@c wxFONTENCODING_CP1250...1252</TD><TD>Windows encodings similar to ISO8859 (but not identical).</TD></TR>
  466. </TABLE>
  467. If the specified encoding isn't available, no font is created
  468. (see also @ref overview_fontencoding).
  469. @remarks If the desired font does not exist, the closest match will be
  470. chosen. Under Windows, only scalable TrueType fonts are used.
  471. */
  472. wxFont(const wxSize& pixelSize, wxFontFamily family,
  473. wxFontStyle style, wxFontWeight weight,
  474. bool underline = false,
  475. const wxString& faceName = wxEmptyString,
  476. wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
  477. /**
  478. Constructor from font description string.
  479. This constructor uses SetNativeFontInfo() to initialize the font.
  480. If @a fontdesc is invalid the font remains uninitialized, i.e. its IsOk() method
  481. will return @false.
  482. */
  483. wxFont(const wxString& nativeInfoString);
  484. /**
  485. Construct font from a native font info structure.
  486. */
  487. wxFont(const wxNativeFontInfo& nativeInfo);
  488. /**
  489. Destructor.
  490. See @ref overview_refcount_destruct "reference-counted object destruction"
  491. for more info.
  492. @remarks Although all remaining fonts are deleted when the application
  493. exits, the application should try to clean up all fonts
  494. itself. This is because wxWidgets cannot know if a
  495. pointer to the font object is stored in an application
  496. data structure, and there is a risk of double deletion.
  497. */
  498. virtual ~wxFont();
  499. /**
  500. @name Getters
  501. */
  502. //@{
  503. /**
  504. Returns the encoding of this font.
  505. Note that under wxGTK the returned value is always @c wxFONTENCODING_UTF8.
  506. @see SetEncoding()
  507. */
  508. virtual wxFontEncoding GetEncoding() const;
  509. /**
  510. Returns the face name associated with the font, or the empty string if
  511. there is no face information.
  512. @see SetFaceName()
  513. */
  514. virtual wxString GetFaceName() const;
  515. /**
  516. Gets the font family if possible.
  517. As described in ::wxFontFamily docs the returned value acts as a rough,
  518. basic classification of the main font properties (look, spacing).
  519. If the current font face name is not recognized by wxFont or by the
  520. underlying system, @c wxFONTFAMILY_DEFAULT is returned.
  521. Note that currently this function is not very precise and so not
  522. particularly useful. Font families mostly make sense only for font
  523. creation, see SetFamily().
  524. @see SetFamily()
  525. */
  526. virtual wxFontFamily GetFamily() const;
  527. /**
  528. Returns the platform-dependent string completely describing this font.
  529. Returned string is always non-empty unless the font is invalid (in
  530. which case an assert is triggered).
  531. Note that the returned string is not meant to be shown or edited by the user: a
  532. typical use of this function is for serializing in string-form a wxFont object.
  533. @see SetNativeFontInfo(), GetNativeFontInfoUserDesc()
  534. */
  535. wxString GetNativeFontInfoDesc() const;
  536. /**
  537. Returns a user-friendly string for this font object.
  538. Returned string is always non-empty unless the font is invalid (in
  539. which case an assert is triggered).
  540. The string does not encode all wxFont infos under all platforms;
  541. e.g. under wxMSW the font family is not present in the returned string.
  542. Some examples of the formats of returned strings (which are platform-dependent)
  543. are in SetNativeFontInfoUserDesc().
  544. @see SetNativeFontInfoUserDesc(), GetNativeFontInfoDesc()
  545. */
  546. wxString GetNativeFontInfoUserDesc() const;
  547. const wxNativeFontInfo *GetNativeFontInfo() const;
  548. /**
  549. Gets the point size.
  550. @see SetPointSize()
  551. */
  552. virtual int GetPointSize() const;
  553. /**
  554. Gets the pixel size.
  555. Note that under wxMSW if you passed to SetPixelSize() (or to the ctor)
  556. a wxSize object with a null width value, you'll get a null width in
  557. the returned object.
  558. @see SetPixelSize()
  559. */
  560. virtual wxSize GetPixelSize() const;
  561. /**
  562. Gets the font style. See ::wxFontStyle for a list of valid styles.
  563. @see SetStyle()
  564. */
  565. virtual wxFontStyle GetStyle() const;
  566. /**
  567. Returns @true if the font is underlined, @false otherwise.
  568. @see SetUnderlined()
  569. */
  570. virtual bool GetUnderlined() const;
  571. /**
  572. Returns @true if the font is stricken-through, @false otherwise.
  573. @see SetStrikethrough()
  574. @since 2.9.4
  575. */
  576. virtual bool GetStrikethrough() const;
  577. /**
  578. Gets the font weight. See ::wxFontWeight for a list of valid weight identifiers.
  579. @see SetWeight()
  580. */
  581. virtual wxFontWeight GetWeight() const;
  582. /**
  583. Returns @true if the font is a fixed width (or monospaced) font,
  584. @false if it is a proportional one or font is invalid.
  585. Note that this function under some platforms is different than just testing
  586. for the font family being equal to @c wxFONTFAMILY_TELETYPE because native
  587. platform-specific functions are used for the check (resulting in a more
  588. accurate return value).
  589. */
  590. virtual bool IsFixedWidth() const;
  591. /**
  592. Returns @true if this object is a valid font, @false otherwise.
  593. */
  594. virtual bool IsOk() const;
  595. //@}
  596. /**
  597. @name Similar fonts creation
  598. The functions in this section either modify the font in place or create
  599. a new font similar to the given one but with its weight, style or size
  600. changed.
  601. */
  602. //@{
  603. /**
  604. Returns a bold version of this font.
  605. @see MakeBold()
  606. @since 2.9.1
  607. */
  608. wxFont Bold() const;
  609. /**
  610. Returns an italic version of this font.
  611. @see MakeItalic()
  612. @since 2.9.1
  613. */
  614. wxFont Italic() const;
  615. /**
  616. Returns a larger version of this font.
  617. The font size is multiplied by @c 1.2, the factor of @c 1.2 being
  618. inspired by the W3C CSS specification.
  619. @see MakeLarger(), Smaller(), Scaled()
  620. @since 2.9.1
  621. */
  622. wxFont Larger() const;
  623. /**
  624. Returns a smaller version of this font.
  625. The font size is divided by @c 1.2, the factor of @c 1.2 being
  626. inspired by the W3C CSS specification.
  627. @see MakeSmaller(), Larger(), Scaled()
  628. @since 2.9.1
  629. */
  630. wxFont Smaller() const;
  631. /**
  632. Returns underlined version of this font.
  633. @see MakeUnderlined()
  634. @since 2.9.2
  635. */
  636. wxFont Underlined() const;
  637. /**
  638. Returns stricken-through version of this font.
  639. Currently stricken-through fonts are only supported in wxMSW and wxGTK.
  640. @see MakeStrikethrough()
  641. @since 2.9.4
  642. */
  643. wxFont Strikethrough() const;
  644. /**
  645. Changes this font to be bold.
  646. @see Bold()
  647. @since 2.9.1
  648. */
  649. wxFont& MakeBold();
  650. /**
  651. Changes this font to be italic.
  652. @see Italic()
  653. @since 2.9.1
  654. */
  655. wxFont& MakeItalic();
  656. /**
  657. Changes this font to be larger.
  658. The font size is multiplied by @c 1.2, the factor of @c 1.2 being
  659. inspired by the W3C CSS specification.
  660. @see Larger(), MakeSmaller(), Scale()
  661. @since 2.9.1
  662. */
  663. wxFont& MakeLarger();
  664. /**
  665. Changes this font to be smaller.
  666. The font size is divided by @c 1.2, the factor of @c 1.2 being
  667. inspired by the W3C CSS specification.
  668. @see Smaller(), MakeLarger(), Scale()
  669. @since 2.9.1
  670. */
  671. wxFont& MakeSmaller();
  672. /**
  673. Changes this font to be underlined.
  674. @see Underlined()
  675. @since 2.9.2
  676. */
  677. wxFont& MakeUnderlined();
  678. /**
  679. Changes this font to be stricken-through.
  680. Currently stricken-through fonts are only supported in wxMSW and wxGTK.
  681. @see Strikethrough()
  682. @since 2.9.4
  683. */
  684. wxFont& MakeStrikethrough();
  685. /**
  686. Changes the size of this font.
  687. The font size is multiplied by the given factor (which may be less than
  688. 1 to create a smaller version of the font).
  689. @see Scaled(), MakeLarger(), MakeSmaller()
  690. @since 2.9.1
  691. */
  692. wxFont& Scale(float x);
  693. /**
  694. Returns a scaled version of this font.
  695. The font size is multiplied by the given factor (which may be less than
  696. 1 to create a smaller version of the font).
  697. @see Scale(), Larger(), Smaller()
  698. @since 2.9.1
  699. */
  700. wxFont Scaled(float x) const;
  701. //@}
  702. /**
  703. @name Setters
  704. These functions internally recreate the native font object with the new
  705. specified property.
  706. */
  707. //@{
  708. /**
  709. Sets the encoding for this font.
  710. Note that under wxGTK this function has no effect (because the underlying
  711. Pango library always uses @c wxFONTENCODING_UTF8).
  712. @see GetEncoding()
  713. */
  714. virtual void SetEncoding(wxFontEncoding encoding);
  715. /**
  716. Sets the facename for the font.
  717. @param faceName
  718. A valid facename, which should be on the end-user's system.
  719. @remarks To avoid portability problems, don't rely on a specific face,
  720. but specify the font family instead (see ::wxFontFamily and SetFamily()).
  721. @return @true if the given face name exists; if the face name doesn't exist
  722. in the user's system then the font is invalidated (so that IsOk() will
  723. return @false) and @false is returned.
  724. @see GetFaceName(), SetFamily()
  725. */
  726. virtual bool SetFaceName(const wxString& faceName);
  727. /**
  728. Sets the font family.
  729. As described in ::wxFontFamily docs the given @a family value acts as a rough,
  730. basic indication of the main font properties (look, spacing).
  731. Note that changing the font family results in changing the font face name.
  732. @param family
  733. One of the ::wxFontFamily values.
  734. @see GetFamily(), SetFaceName()
  735. */
  736. virtual void SetFamily(wxFontFamily family);
  737. /**
  738. Creates the font corresponding to the given native font description string
  739. which must have been previously returned by GetNativeFontInfoDesc().
  740. If the string is invalid, font is unchanged.
  741. This function is typically used for de-serializing a wxFont object
  742. previously saved in a string-form.
  743. @return @true if the creation was successful.
  744. @see SetNativeFontInfoUserDesc()
  745. */
  746. bool SetNativeFontInfo(const wxString& info);
  747. /**
  748. Creates the font corresponding to the given native font description string and
  749. returns @true if the creation was successful.
  750. Unlike SetNativeFontInfo(), this function accepts strings which are user-friendly.
  751. Examples of accepted string formats are:
  752. @beginTable
  753. @hdr3col{platform, generic syntax, example}
  754. @row3col{wxGTK2, <tt>[underlined] [strikethrough] [FACE-NAME] [bold] [oblique|italic] [POINTSIZE]</tt>, Monospace bold 10}
  755. @row3col{wxMSW, <tt>[light|bold] [italic] [FACE-NAME] [POINTSIZE] [ENCODING]</tt>, Tahoma 10 WINDOWS-1252}
  756. @endTable
  757. @todo add an example for wxMac
  758. For more detailed information about the allowed syntaxes you can look at the
  759. documentation of the native API used for font-rendering
  760. (e.g. @c pango_font_description_from_string under GTK, although notice
  761. that it doesn't support the "underlined" and "strikethrough" attributes
  762. and so those are handled by wxWidgets itself).
  763. Note that unlike SetNativeFontInfo(), this function doesn't always restore all
  764. attributes of the wxFont object under all platforms; e.g. on wxMSW the font family
  765. is not restored (because GetNativeFontInfoUserDesc doesn't return it on wxMSW).
  766. If you want to serialize/deserialize a font in string form, you should use
  767. GetNativeFontInfoDesc() and SetNativeFontInfo() instead.
  768. @see SetNativeFontInfo()
  769. */
  770. bool SetNativeFontInfoUserDesc(const wxString& info);
  771. void SetNativeFontInfo(const wxNativeFontInfo& info);
  772. /**
  773. Sets the point size.
  774. The <em>point size</em> is defined as 1/72 of the Anglo-Saxon inch
  775. (25.4 mm): it is approximately 0.0139 inch or 352.8 um.
  776. @param pointSize
  777. Size in points.
  778. @see GetPointSize()
  779. */
  780. virtual void SetPointSize(int pointSize);
  781. /**
  782. Sets the pixel size.
  783. The height parameter of @a pixelSize must be positive while the width
  784. parameter may also be zero (to indicate that you're not interested in the
  785. width of the characters: a suitable width will be chosen for best rendering).
  786. This feature (specifying the font pixel size) is directly supported only
  787. under wxMSW and wxGTK currently; under other platforms a font with the
  788. closest size to the given one is found using binary search (this maybe slower).
  789. @see GetPixelSize()
  790. */
  791. virtual void SetPixelSize(const wxSize& pixelSize);
  792. /**
  793. Sets the font style.
  794. @param style
  795. One of the ::wxFontStyle enumeration values.
  796. @see GetStyle()
  797. */
  798. virtual void SetStyle(wxFontStyle style);
  799. /**
  800. Sets the font size using a predefined symbolic size name.
  801. This function allows to change font size to be (very) large or small
  802. compared to the standard font size.
  803. @see SetSymbolicSizeRelativeTo().
  804. @since 2.9.2
  805. */
  806. void SetSymbolicSize(wxFontSymbolicSize size);
  807. /**
  808. Sets the font size compared to the base font size.
  809. This is the same as SetSymbolicSize() except that it uses the given
  810. font size as the normal font size instead of the standard font size.
  811. @since 2.9.2
  812. */
  813. void SetSymbolicSizeRelativeTo(wxFontSymbolicSize size, int base);
  814. /**
  815. Sets underlining.
  816. @param underlined
  817. @true to underline, @false otherwise.
  818. @see GetUnderlined()
  819. */
  820. virtual void SetUnderlined(bool underlined);
  821. /**
  822. Sets strike-through attribute of the font.
  823. Currently stricken-through fonts are only supported in wxMSW and wxGTK.
  824. @param strikethrough
  825. @true to add strike-through style, @false to remove it.
  826. @see GetStrikethrough()
  827. @since 2.9.4
  828. */
  829. virtual void SetStrikethrough(bool strikethrough);
  830. /**
  831. Sets the font weight.
  832. @param weight
  833. One of the ::wxFontWeight values.
  834. @see GetWeight()
  835. */
  836. virtual void SetWeight(wxFontWeight weight);
  837. //@}
  838. /**
  839. Inequality operator.
  840. See @ref overview_refcount_equality "reference-counted object comparison" for
  841. more info.
  842. */
  843. bool operator!=(const wxFont& font) const;
  844. /**
  845. Equality operator.
  846. See @ref overview_refcount_equality "reference-counted object comparison" for
  847. more info.
  848. */
  849. bool operator==(const wxFont& font) const;
  850. /**
  851. Assignment operator, using @ref overview_refcount "reference counting".
  852. */
  853. wxFont& operator =(const wxFont& font);
  854. // statics
  855. /**
  856. Returns the current application's default encoding.
  857. @see @ref overview_fontencoding, SetDefaultEncoding()
  858. */
  859. static wxFontEncoding GetDefaultEncoding();
  860. /**
  861. Sets the default font encoding.
  862. @see @ref overview_fontencoding, GetDefaultEncoding()
  863. */
  864. static void SetDefaultEncoding(wxFontEncoding encoding);
  865. //@{
  866. /**
  867. This function takes the same parameters as the relative
  868. @ref wxFont::wxFont "wxFont constructor" and returns a new font
  869. object allocated on the heap.
  870. Their use is discouraged, use wxFont constructor from wxFontInfo
  871. instead.
  872. */
  873. static wxFont* New(int pointSize, wxFontFamily family, wxFontStyle style,
  874. wxFontWeight weight,
  875. bool underline = false,
  876. const wxString& faceName = wxEmptyString,
  877. wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
  878. static wxFont* New(int pointSize, wxFontFamily family,
  879. int flags = wxFONTFLAG_DEFAULT,
  880. const wxString& faceName = wxEmptyString,
  881. wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
  882. static wxFont* New(const wxSize& pixelSize,
  883. wxFontFamily family,
  884. wxFontStyle style,
  885. wxFontWeight weight,
  886. bool underline = false,
  887. const wxString& faceName = wxEmptyString,
  888. wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
  889. static wxFont* New(const wxSize& pixelSize,
  890. wxFontFamily family,
  891. int flags = wxFONTFLAG_DEFAULT,
  892. const wxString& faceName = wxEmptyString,
  893. wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
  894. static wxFont *New(const wxNativeFontInfo& nativeInfo);
  895. static wxFont *New(const wxString& nativeInfoString);
  896. //@}
  897. };
  898. /**
  899. An empty wxFont.
  900. */
  901. wxFont wxNullFont;
  902. /**
  903. Equivalent to wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).
  904. @see wxSystemSettings
  905. */
  906. wxFont* wxNORMAL_FONT;
  907. /**
  908. A font using the @c wxFONTFAMILY_SWISS family and 2 points smaller than
  909. ::wxNORMAL_FONT.
  910. */
  911. wxFont* wxSMALL_FONT;
  912. /**
  913. A font using the @c wxFONTFAMILY_ROMAN family and @c wxFONTSTYLE_ITALIC style and
  914. of the same size of ::wxNORMAL_FONT.
  915. */
  916. wxFont* wxITALIC_FONT;
  917. /**
  918. A font identic to ::wxNORMAL_FONT except for the family used which is
  919. @c wxFONTFAMILY_SWISS.
  920. */
  921. wxFont* wxSWISS_FONT;
  922. /**
  923. @class wxFontList
  924. A font list is a list containing all fonts which have been created.
  925. There is only one instance of this class: ::wxTheFontList.
  926. Use this object to search for a previously created font of the desired type
  927. and create it if not already found.
  928. In some windowing systems, the font may be a scarce resource, so it is best to
  929. reuse old resources if possible. When an application finishes, all fonts will
  930. be deleted and their resources freed, eliminating the possibility of 'memory
  931. leaks'.
  932. @library{wxcore}
  933. @category{gdi}
  934. @see wxFont
  935. */
  936. class wxFontList
  937. {
  938. public:
  939. /**
  940. Constructor. The application should not construct its own font list:
  941. use the object pointer ::wxTheFontList.
  942. */
  943. wxFontList();
  944. /**
  945. Finds a font of the given specification, or creates one and adds it to the
  946. list. See the @ref wxFont "wxFont constructor" for details of the arguments.
  947. */
  948. wxFont* FindOrCreateFont(int point_size, wxFontFamily family, wxFontStyle style,
  949. wxFontWeight weight, bool underline = false,
  950. const wxString& facename = wxEmptyString,
  951. wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
  952. };
  953. /**
  954. The global wxFontList instance.
  955. */
  956. wxFontList* wxTheFontList;
  957. // ============================================================================
  958. // Global functions/macros
  959. // ============================================================================
  960. /** @addtogroup group_funcmacro_misc */
  961. //@{
  962. /**
  963. Converts string to a wxFont best represented by the given string. Returns
  964. @true on success.
  965. @see wxToString(const wxFont&)
  966. @header{wx/font.h}
  967. */
  968. bool wxFromString(const wxString& string, wxFont* font);
  969. /**
  970. Converts the given wxFont into a string.
  971. @see wxFromString(const wxString&, wxFont*)
  972. @header{wx/font.h}
  973. */
  974. wxString wxToString(const wxFont& font);
  975. //@}