1 \section{\class{wxFont
}}\label{wxfont
}
3 A font is an object which determines the appearance of text. Fonts are
4 used for drawing text to a device context, and setting the appearance of
7 You can retrieve the current system font settings with
\helpref{wxSystemSettings
}{wxsystemsettings
}.
9 \helpref{wxSystemSettings
}{wxsystemsettings
}
11 \wxheading{Derived from
}
13 \helpref{wxGDIObject
}{wxgdiobject
}\\
14 \helpref{wxObject
}{wxobject
}
16 \wxheading{Include files
}
22 The possible values for the
\arg{family
} parameter of
\helpref{wxFont
23 constructor
}{wxfontctor
} are (the old names are for compatibility only):
28 wxFONTFAMILY_DEFAULT = wxDEFAULT,
29 wxFONTFAMILY_DECORATIVE = wxDECORATIVE,
30 wxFONTFAMILY_ROMAN = wxROMAN,
31 wxFONTFAMILY_SCRIPT = wxSCRIPT,
32 wxFONTFAMILY_SWISS = wxSWISS,
33 wxFONTFAMILY_MODERN = wxMODERN,
34 wxFONTFAMILY_TELETYPE = wxTELETYPE,
39 The possible values for the
\arg{weight
} parameter are (the old names
40 are for compatibility only):
45 wxFONTWEIGHT_NORMAL = wxNORMAL,
46 wxFONTWEIGHT_LIGHT = wxLIGHT,
47 wxFONTWEIGHT_BOLD = wxBOLD,
52 The font flags which can be used during the font creation are:
57 // no special flags: font with default weight/slant/anti-aliasing
58 wxFONTFLAG_DEFAULT =
0,
60 // slant flags (default: no slant)
61 wxFONTFLAG_ITALIC =
1 <<
0,
62 wxFONTFLAG_SLANT =
1 <<
1,
64 // weight flags (default: medium)
65 wxFONTFLAG_LIGHT =
1 <<
2,
66 wxFONTFLAG_BOLD =
1 <<
3,
68 // anti-aliasing flag: force on or off (default: the current system default)
69 wxFONTFLAG_ANTIALIASED =
1 <<
4,
70 wxFONTFLAG_NOT_ANTIALIASED =
1 <<
5,
72 // underlined/strikethrough flags (default: no lines)
73 wxFONTFLAG_UNDERLINED =
1 <<
6,
74 wxFONTFLAG_STRIKETHROUGH =
1 <<
7,
78 The known font encodings are:
83 wxFONTENCODING_SYSTEM = -
1, // system default
84 wxFONTENCODING_DEFAULT, // current default encoding
86 // ISO8859 standard defines a number of single-byte charsets
87 wxFONTENCODING_ISO8859_1, // West European (Latin1)
88 wxFONTENCODING_ISO8859_2, // Central and East European (Latin2)
89 wxFONTENCODING_ISO8859_3, // Esperanto (Latin3)
90 wxFONTENCODING_ISO8859_4, // Baltic (old) (Latin4)
91 wxFONTENCODING_ISO8859_5, // Cyrillic
92 wxFONTENCODING_ISO8859_6, // Arabic
93 wxFONTENCODING_ISO8859_7, // Greek
94 wxFONTENCODING_ISO8859_8, // Hebrew
95 wxFONTENCODING_ISO8859_9, // Turkish (Latin5)
96 wxFONTENCODING_ISO8859_10, // Variation of Latin4 (Latin6)
97 wxFONTENCODING_ISO8859_11, // Thai
98 wxFONTENCODING_ISO8859_12, // doesn't exist currently, but put it
99 // here anyhow to make all ISO8859
100 // consecutive numbers
101 wxFONTENCODING_ISO8859_13, // Baltic (Latin7)
102 wxFONTENCODING_ISO8859_14, // Latin8
103 wxFONTENCODING_ISO8859_15, // Latin9 (a.k.a. Latin0, includes euro)
104 wxFONTENCODING_ISO8859_MAX,
106 // Cyrillic charset soup (see http://czyborra.com/charsets/cyrillic.html)
107 wxFONTENCODING_KOI8, // we don't support any of KOI8 variants
108 wxFONTENCODING_ALTERNATIVE, // same as MS-DOS CP866
109 wxFONTENCODING_BULGARIAN, // used under Linux in Bulgaria
111 // what would we do without Microsoft? They have their own encodings
113 wxFONTENCODING_CP437, // original MS-DOS codepage
114 wxFONTENCODING_CP850, // CP437 merged with Latin1
115 wxFONTENCODING_CP852, // CP437 merged with Latin2
116 wxFONTENCODING_CP855, // another cyrillic encoding
117 wxFONTENCODING_CP866, // and another one
119 wxFONTENCODING_CP874, // WinThai
120 wxFONTENCODING_CP1250, // WinLatin2
121 wxFONTENCODING_CP1251, // WinCyrillic
122 wxFONTENCODING_CP1252, // WinLatin1
123 wxFONTENCODING_CP1253, // WinGreek (
8859-
7)
124 wxFONTENCODING_CP1254, // WinTurkish
125 wxFONTENCODING_CP1255, // WinHebrew
126 wxFONTENCODING_CP1256, // WinArabic
127 wxFONTENCODING_CP1257, // WinBaltic (same as Latin
7)
128 wxFONTENCODING_CP12_MAX,
130 wxFONTENCODING_UTF7, // UTF-
7 Unicode encoding
131 wxFONTENCODING_UTF8, // UTF-
8 Unicode encoding
133 wxFONTENCODING_UNICODE, // Unicode - currently used only by
134 // wxEncodingConverter class
140 \wxheading{Predefined objects
}
148 {\bf wxNORMAL
\_FONT\\
155 \helpref{wxFont overview
}{wxfontoverview
},
\helpref{wxDC::SetFont
}{wxdcsetfont
},
\rtfsp
156 \helpref{wxDC::DrawText
}{wxdcdrawtext
},
\helpref{wxDC::GetTextExtent
}{wxdcgettextextent
},
\rtfsp
157 \helpref{wxFontDialog
}{wxfontdialog
},
\helpref{wxSystemSettings
}{wxsystemsettings
}
159 \latexignore{\rtfignore{\wxheading{Members
}}}
162 \membersection{wxFont::wxFont
}\label{wxfontctor
}
164 \func{}{wxFont
}{\void}
168 \func{}{wxFont
}{\param{const wxFont\&
}{ font
}}
170 Copy constructor, uses
\helpref{reference counting
}{trefcount
}.
172 \func{}{wxFont
}{\param{int
}{ pointSize
},
\param{wxFontFamily
}{ family
},
\param{int
}{ style
},
\param{wxFontWeight
}{ weight
},
173 \param{const bool
}{ underline = false
},
\param{const wxString\&
}{faceName = ""
},
174 \param{wxFontEncoding
}{encoding = wxFONTENCODING
\_DEFAULT}}
176 \func{}{wxFont
}{\param{const wxSize\&
}{ pixelSize
},
\param{wxFontFamily
}{ family
},
\param{int
}{ style
},
\param{wxFontWeight
}{ weight
},
177 \param{const bool
}{ underline = false
},
\param{const wxString\&
}{faceName = ""
},
178 \param{wxFontEncoding
}{encoding = wxFONTENCODING
\_DEFAULT}}
180 Creates a font object with the specified attributes.
182 \wxheading{Parameters
}
184 \docparam{pointSize
}{Size in points.
}
186 \docparam{pixelSize
}{Size in pixels: this is directly supported only under MSW
187 currently where this constructor can be used directly, under other platforms a
188 font with the closest size to the given one is found using binary search and
189 the static
\helpref{New
}{wxfontnew
} method must be used.
}
191 \docparam{family
}{Font family, a generic way of referring to fonts without specifying actual facename. One of:
194 \begin{twocollist
}\itemsep=
0pt
195 \twocolitem{{\bf wxFONTFAMILY
\_DEFAULT}}{Chooses a default font.
}
196 \twocolitem{{\bf wxFONTFAMILY
\_DECORATIVE}}{A decorative font.
}
197 \twocolitem{{\bf wxFONTFAMILY
\_ROMAN}}{A formal, serif font.
}
198 \twocolitem{{\bf wxFONTFAMILY
\_SCRIPT}}{A handwriting font.
}
199 \twocolitem{{\bf wxFONTFAMILY
\_SWISS}}{A sans-serif font.
}
200 \twocolitem{{\bf wxFONTFAMILY
\_MODERN}}{A fixed pitch font.
}
201 \twocolitem{{\bf wxFONTFAMILY
\_TELETYPE}}{A teletype font.
}
204 \docparam{style
}{One of
{\bf wxFONTSTYLE
\_NORMAL},
{\bf wxFONTSTYLE
\_SLANT} and
{\bf wxFONTSTYLE
\_ITALIC}.
}
206 \docparam{weight
}{Font weight, sometimes also referred to as font boldness. One of:
209 \begin{twocollist
}\itemsep=
0pt
210 \twocolitem{{\bf wxFONTWEIGHT
\_NORMAL}}{Normal font.
}
211 \twocolitem{{\bf wxFONTWEIGHT
\_LIGHT}}{Light font.
}
212 \twocolitem{{\bf wxFONTWEIGHT
\_BOLD}}{Bold font.
}
215 \docparam{underline
}{The value can be true or false. At present this has an effect on Windows and Motif
2.x only.
}
217 \docparam{faceName
}{An optional string specifying the actual typeface to be used. If it is an empty string,
218 a default typeface will be chosen based on the family.
}
220 \docparam{encoding
}{An encoding which may be one of
222 \begin{twocollist
}\itemsep=
0pt
223 \twocolitem{{\bf wxFONTENCODING
\_SYSTEM}}{Default system encoding.
}
224 \twocolitem{{\bf wxFONTENCODING
\_DEFAULT}}{Default application encoding: this
225 is the encoding set by calls to
226 \helpref{SetDefaultEncoding
}{wxfontsetdefaultencoding
} and which may be set to,
227 say, KOI8 to create all fonts by default with KOI8 encoding. Initially, the
228 default application encoding is the same as default system encoding.
}
229 \twocolitem{{\bf wxFONTENCODING
\_ISO8859\_1..
.15}}{ISO8859 encodings.
}
230 \twocolitem{{\bf wxFONTENCODING
\_KOI8}}{The standard Russian encoding for Internet.
}
231 \twocolitem{{\bf wxFONTENCODING
\_CP1250..
.1252}}{Windows encodings similar to ISO8859 (but not identical).
}
233 If the specified encoding isn't available, no font is created
234 (see also
\helpref{font encoding overview
}{wxfontencodingoverview
}).
239 If the desired font does not exist, the closest match will be chosen.
240 Under Windows, only scalable TrueType fonts are used.
242 See also
\helpref{wxDC::SetFont
}{wxdcsetfont
},
\helpref{wxDC::DrawText
}{wxdcdrawtext
}
243 and
\helpref{wxDC::GetTextExtent
}{wxdcgettextextent
}.
246 \membersection{wxFont::
\destruct{wxFont
}}\label{wxfontdtor
}
248 \func{}{\destruct{wxFont
}}{\void}
254 The destructor may not delete the underlying font object of the native windowing
255 system, since wxFont uses a reference counting system for efficiency.
257 Although all remaining fonts are deleted when the application exits,
258 the application should try to clean up all fonts itself. This is because
259 wxWidgets cannot know if a pointer to the font object is stored in an
260 application data structure, and there is a risk of double deletion.
263 \membersection{wxFont::IsFixedWidth
}\label{wxfontisfixedwidth
}
265 \constfunc{bool
}{IsFixedWidth
}{\void}
267 Returns
{\tt true
} if the font is a fixed width (or monospaced) font,
268 {\tt false
} if it is a proportional one or font is invalid.
271 \membersection{wxFont::GetDefaultEncoding
}\label{wxfontgetdefaultencoding
}
273 \func{static wxFontEncoding
}{GetDefaultEncoding
}{\void}
275 Returns the current application's default encoding.
279 \helpref{Font encoding overview
}{wxfontencodingoverview
},
280 \helpref{SetDefaultEncoding
}{wxfontsetdefaultencoding
}
283 \membersection{wxFont::GetFaceName
}\label{wxfontgetfacename
}
285 \constfunc{wxString
}{GetFaceName
}{\void}
287 Returns the typeface name associated with the font, or the empty string if there is no
288 typeface information.
292 \helpref{wxFont::SetFaceName
}{wxfontsetfacename
}
295 \membersection{wxFont::GetFamily
}\label{wxfontgetfamily
}
297 \constfunc{wxFontFamily
}{GetFamily
}{\void}
299 Gets the font family. See
\helpref{wxFont::SetFamily
}{wxfontsetfamily
} for a list of valid
304 \helpref{wxFont::SetFamily
}{wxfontsetfamily
}
307 \membersection{wxFont::GetNativeFontInfoDesc
}\label{wxfontgetnativefontinfodesc
}
309 \constfunc{wxString
}{GetNativeFontInfoDesc
}{\void}
311 Returns the platform-dependent string completely describing this font.
312 Returned string is always non-empty.
313 Note that the returned string is not meant to be shown or edited by the user: a typical
314 use of this function is for serializing in string-form a wxFont object.
318 \helpref{wxFont::SetNativeFontInfo
}{wxfontsetnativefontinfo
},
\helpref{wxFont::GetNativeFontInfoUserDesc
}{wxfontgetnativefontinfouserdesc
}
321 \membersection{wxFont::GetNativeFontInfoUserDesc
}\label{wxfontgetnativefontinfouserdesc
}
323 \func{wxString
}{GetNativeFontInfoUserDesc
}{\void}
325 Returns a user-friendly string for this font object. Returned string is always non-empty.
326 Some examples of the formats of returned strings (which are platform-dependent) are in
\helpref{SetNativeFontInfoUserDesc
}{wxfontsetnativefontinfouserdesc
}.
330 \helpref{wxFont::GetNativeFontInfoDesc
}{wxfontgetnativefontinfodesc
}
333 \membersection{wxFont::GetPointSize
}\label{wxfontgetpointsize
}
335 \constfunc{int
}{GetPointSize
}{\void}
341 \helpref{wxFont::SetPointSize
}{wxfontsetpointsize
}
344 \membersection{wxFont::GetStyle
}\label{wxfontgetstyle
}
346 \constfunc{int
}{GetStyle
}{\void}
348 Gets the font style. See
\helpref{wxFont::wxFont
}{wxfontctor
} for a list of valid
353 \helpref{wxFont::SetStyle
}{wxfontsetstyle
}
356 \membersection{wxFont::GetUnderlined
}\label{wxfontgetunderlined
}
358 \constfunc{bool
}{GetUnderlined
}{\void}
360 Returns true if the font is underlined, false otherwise.
364 \helpref{wxFont::SetUnderlined
}{wxfontsetunderlined
}
367 \membersection{wxFont::GetWeight
}\label{wxfontgetweight
}
369 \constfunc{wxFontWeight
}{GetWeight
}{\void}
371 Gets the font weight. See
\helpref{wxFont::wxFont
}{wxfontctor
} for a list of valid
376 \helpref{wxFont::SetWeight
}{wxfontsetweight
}
379 \membersection{wxFont::New
}\label{wxfontnew
}
381 \func{static wxFont *
}{New
}{\param{int
}{ pointSize
},
\param{wxFontFamily
}{ family
},
\param{int
}{ style
},
\param{wxFontWeight
}{ weight
},
382 \param{const bool
}{ underline = false
},
\param{const wxString\&
}{faceName = ""
},
383 \param{wxFontEncoding
}{encoding = wxFONTENCODING
\_DEFAULT}}
385 \func{static wxFont *
}{New
}{\param{int
}{ pointSize
},
\param{wxFontFamily
}{ family
},
386 \param{int
}{ flags =
\texttt{wxFONTFLAG
\_DEFAULT}},
\param{const wxString\&
}{faceName = ""
},
387 \param{wxFontEncoding
}{encoding = wxFONTENCODING
\_DEFAULT}}
389 \func{static wxFont *
}{New
}{\param{const wxSize\&
}{ pixelSize
},
\param{wxFontFamily
}{ family
},
\param{int
}{ style
},
\param{wxFontWeight
}{ weight
},
390 \param{const bool
}{ underline = false
},
\param{const wxString\&
}{faceName = ""
},
391 \param{wxFontEncoding
}{encoding = wxFONTENCODING
\_DEFAULT}}
393 \func{static wxFont *
}{New
}{\param{const wxSize\&
}{ pixelSize
},
\param{wxFontFamily
}{ family
},
394 \param{int
}{ flags =
\texttt{wxFONTFLAG
\_DEFAULT}},
\param{const wxString\&
}{faceName = ""
},
395 \param{wxFontEncoding
}{encoding = wxFONTENCODING
\_DEFAULT}}
397 These functions take the same parameters as
\helpref{wxFont
398 constructor
}{wxfontctor
} and return a new font object allocated on the heap.
400 Using
\texttt{New()
} is currently the only way to directly create a font with
401 the given size in pixels on platforms other than wxMSW.
404 \membersection{wxFont::IsOk
}\label{wxfontisok
}
406 \constfunc{bool
}{IsOk
}{\void}
408 Returns
{\tt true
} if this object is a valid font,
{\tt false
} otherwise.
411 \membersection{wxFont::SetDefaultEncoding
}\label{wxfontsetdefaultencoding
}
413 \func{static void
}{SetDefaultEncoding
}{\param{wxFontEncoding
}{encoding
}}
415 Sets the default font encoding.
419 \helpref{Font encoding overview
}{wxfontencodingoverview
},
420 \helpref{GetDefaultEncoding
}{wxfontgetdefaultencoding
}
423 \membersection{wxFont::SetFaceName
}\label{wxfontsetfacename
}
425 \func{bool
}{SetFaceName
}{\param{const wxString\&
}{faceName
}}
427 Sets the facename for the font.
428 Returns
\true if the given face name exists;
\false otherwise.
430 \wxheading{Parameters
}
432 \docparam{faceName
}{A valid facename, which should be on the end-user's system.
}
436 To avoid portability problems, don't rely on a specific face, but specify the font family
437 instead or as well. A suitable font will be found on the end-user's system. If both the
438 family and the facename are specified, wxWidgets will first search for the specific face,
439 and then for a font belonging to the same family.
443 \helpref{wxFont::GetFaceName
}{wxfontgetfacename
},
\helpref{wxFont::SetFamily
}{wxfontsetfamily
}
446 \membersection{wxFont::SetFamily
}\label{wxfontsetfamily
}
448 \func{void
}{SetFamily
}{\param{wxFontFamily
}{ family
}}
450 Sets the font family.
452 \wxheading{Parameters
}
454 \docparam{family
}{One of:
457 \begin{twocollist
}\itemsep=
0pt
458 \twocolitem{{\bf wxFONTFAMILY
\_DEFAULT}}{Chooses a default font.
}
459 \twocolitem{{\bf wxFONTFAMILY
\_DECORATIVE}}{A decorative font.
}
460 \twocolitem{{\bf wxFONTFAMILY
\_ROMAN}}{A formal, serif font.
}
461 \twocolitem{{\bf wxFONTFAMILY
\_SCRIPT}}{A handwriting font.
}
462 \twocolitem{{\bf wxFONTFAMILY
\_SWISS}}{A sans-serif font.
}
463 \twocolitem{{\bf wxFONTFAMILY
\_MODERN}}{A fixed pitch font.
}
464 \twocolitem{{\bf wxFONTFAMILY
\_TELETYPE}}{A teletype font.
}
469 \helpref{wxFont::GetFamily
}{wxfontgetfamily
},
\helpref{wxFont::SetFaceName
}{wxfontsetfacename
}
472 \membersection{wxFont::SetNativeFontInfo
}\label{wxfontsetnativefontinfo
}
474 \func{bool
}{SetNativeFontInfo
}{\param{const wxString\&
}{info
}}
476 Creates the font corresponding to the given native font description string and returns
\true if
477 the creation was successful.
478 which must have been previously returned by
479 \helpref{GetNativeFontInfoDesc
}{wxfontgetnativefontinfodesc
}. If the string is
480 invalid, font is unchanged. This function is typically used for de-serializing a wxFont
481 object previously saved in a string-form.
485 \helpref{wxFont::SetNativeFontInfoUserDesc
}{wxfontsetnativefontinfouserdesc
}
488 \membersection{wxFont::SetNativeFontInfoUserDesc
}\label{wxfontsetnativefontinfouserdesc
}
490 \func{bool
}{SetNativeFontInfoUserDesc
}{\param{const wxString\&
}{info
}}
492 Creates the font corresponding to the given native font description string and returns
\true if
493 the creation was successful.
494 Unlike
\helpref{SetNativeFontInfo
}{wxfontsetnativefontinfo
}, this function accepts
495 strings which are user-friendly.
496 Examples of accepted string formats are:
499 \begin{twocollist
}\itemsep=
0pt
500 \twocolitem{Generic syntax
}{Example
}
501 \twocolitem{on
{\bf wxGTK2
}:
{\tt $
[FACE-NAME
]$ $
[bold
]$ $
[oblique|italic
]$ $
[POINTSIZE
]$
}}{Monospace bold
10}
502 \twocolitem{on
{\bf wxMSW
}:
{\tt $
[light|bold
]$ $
[italic
]$ $
[FACE-NAME
]$ $
[POINTSIZE
]$ $
[ENCODING
]$
}}{Tahoma
10 WINDOWS-
1252}
503 \twocolitem{on
{\bf wxMac
}: FIXME
}{FIXME
}
506 For more detailed information about the allowed syntaxes you can look at the documentation of the native API used for font-rendering (e.g.
\urlref{pango
\_font\_description\_from\_string}{http://developer.gnome.org/doc/API/
2.0/pango/pango-Fonts.html\#pango-font-description-from-string
}).
510 \helpref{wxFont::SetNativeFontInfo
}{wxfontsetnativefontinfo
}
514 \membersection{wxFont::SetPointSize
}\label{wxfontsetpointsize
}
516 \func{void
}{SetPointSize
}{\param{int
}{ pointSize
}}
520 \wxheading{Parameters
}
522 \docparam{pointSize
}{Size in points.
}
526 \helpref{wxFont::GetPointSize
}{wxfontgetpointsize
}
529 \membersection{wxFont::SetStyle
}\label{wxfontsetstyle
}
531 \func{void
}{SetStyle
}{\param{int
}{ style
}}
535 \wxheading{Parameters
}
537 \docparam{style
}{One of
{\bf wxFONTSTYLE
\_NORMAL},
{\bf wxFONTSTYLE
\_SLANT} and
{\bf wxFONTSTYLE
\_ITALIC}.
}
541 \helpref{wxFont::GetStyle
}{wxfontgetstyle
}
544 \membersection{wxFont::SetUnderlined
}\label{wxfontsetunderlined
}
546 \func{void
}{SetUnderlined
}{\param{const bool
}{ underlined
}}
550 \wxheading{Parameters
}
552 \docparam{underlining
}{true to underline, false otherwise.
}
556 \helpref{wxFont::GetUnderlined
}{wxfontgetunderlined
}
559 \membersection{wxFont::SetWeight
}\label{wxfontsetweight
}
561 \func{void
}{SetWeight
}{\param{wxFontWeight
}{ weight
}}
563 Sets the font weight.
565 \wxheading{Parameters
}
567 \docparam{weight
}{One of:
570 \begin{twocollist
}\itemsep=
0pt
571 \twocolitem{{\bf wxFONTWEIGHT
\_NORMAL}}{Normal font.
}
572 \twocolitem{{\bf wxFONTWEIGHT
\_LIGHT}}{Light font.
}
573 \twocolitem{{\bf wxFONTWEIGHT
\_BOLD}}{Bold font.
}
578 \helpref{wxFont::GetWeight
}{wxfontgetweight
}
581 \membersection{wxFont::operator $=$
}\label{wxfontassignment
}
583 \func{wxFont\&
}{operator $=$
}{\param{const wxFont\&
}{font
}}
585 Assignment operator, using
\helpref{reference counting
}{trefcount
}.
588 \membersection{wxFont::operator $==$
}\label{wxfontequals
}
590 \func{bool
}{operator $==$
}{\param{const wxFont\&
}{font
}}
592 Equality operator. Two fonts are equal if they contain pointers
593 to the same underlying font data. It does not compare each attribute,
594 so two independently-created fonts using the same parameters will
598 \membersection{wxFont::operator $!=$
}\label{wxfontnotequals
}
600 \func{bool
}{operator $!=$
}{\param{const wxFont\&
}{font
}}
602 Inequality operator. Two fonts are not equal if they contain pointers
603 to different underlying font data. It does not compare each attribute.