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 This class uses
\helpref{reference counting and copy-on-write
}{trefcount
}
8 internally so that assignments between two instances of this class are very
9 cheap. You can therefore use actual objects instead of pointers without
10 efficiency problems. If an instance of this class is changed it will create
11 its own data internally so that other instances, which previously shared the
12 data using the reference counting, are not affected.
14 You can retrieve the current system font settings with
\helpref{wxSystemSettings
}{wxsystemsettings
}.
16 \helpref{wxSystemSettings
}{wxsystemsettings
}
18 \wxheading{Derived from
}
20 \helpref{wxGDIObject
}{wxgdiobject
}\\
21 \helpref{wxObject
}{wxobject
}
23 \wxheading{Include files
}
29 \helpref{wxCore
}{librarieslist
}
33 The possible values for the
\arg{family
} parameter of
\helpref{wxFont
34 constructor
}{wxfontctor
} are (the old names are for compatibility only):
39 wxFONTFAMILY_DEFAULT = wxDEFAULT,
40 wxFONTFAMILY_DECORATIVE = wxDECORATIVE,
41 wxFONTFAMILY_ROMAN = wxROMAN,
42 wxFONTFAMILY_SCRIPT = wxSCRIPT,
43 wxFONTFAMILY_SWISS = wxSWISS,
44 wxFONTFAMILY_MODERN = wxMODERN,
45 wxFONTFAMILY_TELETYPE = wxTELETYPE,
50 The possible values for the
\arg{weight
} parameter are (the old names
51 are for compatibility only):
56 wxFONTWEIGHT_NORMAL = wxNORMAL,
57 wxFONTWEIGHT_LIGHT = wxLIGHT,
58 wxFONTWEIGHT_BOLD = wxBOLD,
63 The font flags which can be used during the font creation are:
68 // no special flags: font with default weight/slant/anti-aliasing
69 wxFONTFLAG_DEFAULT =
0,
71 // slant flags (default: no slant)
72 wxFONTFLAG_ITALIC =
1 <<
0,
73 wxFONTFLAG_SLANT =
1 <<
1,
75 // weight flags (default: medium)
76 wxFONTFLAG_LIGHT =
1 <<
2,
77 wxFONTFLAG_BOLD =
1 <<
3,
79 // anti-aliasing flag: force on or off (default: the current system default)
80 wxFONTFLAG_ANTIALIASED =
1 <<
4,
81 wxFONTFLAG_NOT_ANTIALIASED =
1 <<
5,
83 // underlined/strikethrough flags (default: no lines)
84 wxFONTFLAG_UNDERLINED =
1 <<
6,
85 wxFONTFLAG_STRIKETHROUGH =
1 <<
7,
89 The known font encodings are:
94 wxFONTENCODING_SYSTEM = -
1, // system default
95 wxFONTENCODING_DEFAULT, // current default encoding
97 // ISO8859 standard defines a number of single-byte charsets
98 wxFONTENCODING_ISO8859_1, // West European (Latin1)
99 wxFONTENCODING_ISO8859_2, // Central and East European (Latin2)
100 wxFONTENCODING_ISO8859_3, // Esperanto (Latin3)
101 wxFONTENCODING_ISO8859_4, // Baltic (old) (Latin4)
102 wxFONTENCODING_ISO8859_5, // Cyrillic
103 wxFONTENCODING_ISO8859_6, // Arabic
104 wxFONTENCODING_ISO8859_7, // Greek
105 wxFONTENCODING_ISO8859_8, // Hebrew
106 wxFONTENCODING_ISO8859_9, // Turkish (Latin5)
107 wxFONTENCODING_ISO8859_10, // Variation of Latin4 (Latin6)
108 wxFONTENCODING_ISO8859_11, // Thai
109 wxFONTENCODING_ISO8859_12, // doesn't exist currently, but put it
110 // here anyhow to make all ISO8859
111 // consecutive numbers
112 wxFONTENCODING_ISO8859_13, // Baltic (Latin7)
113 wxFONTENCODING_ISO8859_14, // Latin8
114 wxFONTENCODING_ISO8859_15, // Latin9 (a.k.a. Latin0, includes euro)
115 wxFONTENCODING_ISO8859_MAX,
117 // Cyrillic charset soup (see http://czyborra.com/charsets/cyrillic.html)
118 wxFONTENCODING_KOI8, // we don't support any of KOI8 variants
119 wxFONTENCODING_ALTERNATIVE, // same as MS-DOS CP866
120 wxFONTENCODING_BULGARIAN, // used under Linux in Bulgaria
122 // what would we do without Microsoft? They have their own encodings
124 wxFONTENCODING_CP437, // original MS-DOS codepage
125 wxFONTENCODING_CP850, // CP437 merged with Latin1
126 wxFONTENCODING_CP852, // CP437 merged with Latin2
127 wxFONTENCODING_CP855, // another cyrillic encoding
128 wxFONTENCODING_CP866, // and another one
130 wxFONTENCODING_CP874, // WinThai
131 wxFONTENCODING_CP1250, // WinLatin2
132 wxFONTENCODING_CP1251, // WinCyrillic
133 wxFONTENCODING_CP1252, // WinLatin1
134 wxFONTENCODING_CP1253, // WinGreek (
8859-
7)
135 wxFONTENCODING_CP1254, // WinTurkish
136 wxFONTENCODING_CP1255, // WinHebrew
137 wxFONTENCODING_CP1256, // WinArabic
138 wxFONTENCODING_CP1257, // WinBaltic (same as Latin
7)
139 wxFONTENCODING_CP12_MAX,
141 wxFONTENCODING_UTF7, // UTF-
7 Unicode encoding
142 wxFONTENCODING_UTF8, // UTF-
8 Unicode encoding
144 wxFONTENCODING_UNICODE, // Unicode - currently used only by
145 // wxEncodingConverter class
151 \wxheading{Predefined objects
}
159 {\bf wxNORMAL
\_FONT\\
166 \helpref{wxFont overview
}{wxfontoverview
},
\helpref{wxDC::SetFont
}{wxdcsetfont
},
\rtfsp
167 \helpref{wxDC::DrawText
}{wxdcdrawtext
},
\helpref{wxDC::GetTextExtent
}{wxdcgettextextent
},
\rtfsp
168 \helpref{wxFontDialog
}{wxfontdialog
},
\helpref{wxSystemSettings
}{wxsystemsettings
}
170 \latexignore{\rtfignore{\wxheading{Members
}}}
173 \membersection{wxFont::wxFont
}\label{wxfontctor
}
175 \func{}{wxFont
}{\void}
179 \func{}{wxFont
}{\param{const wxFont\&
}{ font
}}
181 Copy constructor, uses
\helpref{reference counting
}{trefcount
}.
183 \func{}{wxFont
}{\param{int
}{ pointSize
},
\param{wxFontFamily
}{ family
},
\param{int
}{ style
},
\param{wxFontWeight
}{ weight
},
184 \param{const bool
}{ underline = false
},
\param{const wxString\&
}{faceName = ""
},
185 \param{wxFontEncoding
}{encoding = wxFONTENCODING
\_DEFAULT}}
187 \func{}{wxFont
}{\param{const wxSize\&
}{ pixelSize
},
\param{wxFontFamily
}{ family
},
\param{int
}{ style
},
\param{wxFontWeight
}{ weight
},
188 \param{const bool
}{ underline = false
},
\param{const wxString\&
}{faceName = ""
},
189 \param{wxFontEncoding
}{encoding = wxFONTENCODING
\_DEFAULT}}
191 Creates a font object with the specified attributes.
193 \wxheading{Parameters
}
195 \docparam{pointSize
}{Size in points.
}
197 \docparam{pixelSize
}{Size in pixels: this is directly supported only under MSW
198 currently where this constructor can be used directly, under other platforms a
199 font with the closest size to the given one is found using binary search and
200 the static
\helpref{New
}{wxfontnew
} method must be used.
}
202 \docparam{family
}{Font family, a generic way of referring to fonts without specifying actual facename. One of:
205 \begin{twocollist
}\itemsep=
0pt
206 \twocolitem{{\bf wxFONTFAMILY
\_DEFAULT}}{Chooses a default font.
}
207 \twocolitem{{\bf wxFONTFAMILY
\_DECORATIVE}}{A decorative font.
}
208 \twocolitem{{\bf wxFONTFAMILY
\_ROMAN}}{A formal, serif font.
}
209 \twocolitem{{\bf wxFONTFAMILY
\_SCRIPT}}{A handwriting font.
}
210 \twocolitem{{\bf wxFONTFAMILY
\_SWISS}}{A sans-serif font.
}
211 \twocolitem{{\bf wxFONTFAMILY
\_MODERN}}{A fixed pitch font.
}
212 \twocolitem{{\bf wxFONTFAMILY
\_TELETYPE}}{A teletype font.
}
215 \docparam{style
}{One of
{\bf wxFONTSTYLE
\_NORMAL},
{\bf wxFONTSTYLE
\_SLANT} and
{\bf wxFONTSTYLE
\_ITALIC}.
}
217 \docparam{weight
}{Font weight, sometimes also referred to as font boldness. One of:
220 \begin{twocollist
}\itemsep=
0pt
221 \twocolitem{{\bf wxFONTWEIGHT
\_NORMAL}}{Normal font.
}
222 \twocolitem{{\bf wxFONTWEIGHT
\_LIGHT}}{Light font.
}
223 \twocolitem{{\bf wxFONTWEIGHT
\_BOLD}}{Bold font.
}
226 \docparam{underline
}{The value can be true or false. At present this has an effect on Windows and Motif
2.x only.
}
228 \docparam{faceName
}{An optional string specifying the actual typeface to be used. If it is an empty string,
229 a default typeface will be chosen based on the family.
}
231 \docparam{encoding
}{An encoding which may be one of
233 \begin{twocollist
}\itemsep=
0pt
234 \twocolitem{{\bf wxFONTENCODING
\_SYSTEM}}{Default system encoding.
}
235 \twocolitem{{\bf wxFONTENCODING
\_DEFAULT}}{Default application encoding: this
236 is the encoding set by calls to
237 \helpref{SetDefaultEncoding
}{wxfontsetdefaultencoding
} and which may be set to,
238 say, KOI8 to create all fonts by default with KOI8 encoding. Initially, the
239 default application encoding is the same as default system encoding.
}
240 \twocolitem{{\bf wxFONTENCODING
\_ISO8859\_1..
.15}}{ISO8859 encodings.
}
241 \twocolitem{{\bf wxFONTENCODING
\_KOI8}}{The standard Russian encoding for Internet.
}
242 \twocolitem{{\bf wxFONTENCODING
\_CP1250..
.1252}}{Windows encodings similar to ISO8859 (but not identical).
}
244 If the specified encoding isn't available, no font is created
245 (see also
\helpref{font encoding overview
}{wxfontencodingoverview
}).
250 If the desired font does not exist, the closest match will be chosen.
251 Under Windows, only scalable TrueType fonts are used.
253 See also
\helpref{wxDC::SetFont
}{wxdcsetfont
},
\helpref{wxDC::DrawText
}{wxdcdrawtext
}
254 and
\helpref{wxDC::GetTextExtent
}{wxdcgettextextent
}.
257 \membersection{wxFont::
\destruct{wxFont
}}\label{wxfontdtor
}
259 \func{}{\destruct{wxFont
}}{\void}
262 See
\helpref{reference-counted object destruction
}{refcountdestruct
} for more info.
266 Although all remaining fonts are deleted when the application exits,
267 the application should try to clean up all fonts itself. This is because
268 wxWidgets cannot know if a pointer to the font object is stored in an
269 application data structure, and there is a risk of double deletion.
272 \membersection{wxFont::IsFixedWidth
}\label{wxfontisfixedwidth
}
274 \constfunc{bool
}{IsFixedWidth
}{\void}
276 Returns
{\tt true
} if the font is a fixed width (or monospaced) font,
277 {\tt false
} if it is a proportional one or font is invalid.
280 \membersection{wxFont::GetDefaultEncoding
}\label{wxfontgetdefaultencoding
}
282 \func{static wxFontEncoding
}{GetDefaultEncoding
}{\void}
284 Returns the current application's default encoding.
288 \helpref{Font encoding overview
}{wxfontencodingoverview
},
289 \helpref{SetDefaultEncoding
}{wxfontsetdefaultencoding
}
292 \membersection{wxFont::GetFaceName
}\label{wxfontgetfacename
}
294 \constfunc{wxString
}{GetFaceName
}{\void}
296 Returns the typeface name associated with the font, or the empty string if there is no
297 typeface information.
301 \helpref{wxFont::SetFaceName
}{wxfontsetfacename
}
304 \membersection{wxFont::GetFamily
}\label{wxfontgetfamily
}
306 \constfunc{wxFontFamily
}{GetFamily
}{\void}
308 Gets the font family. See
\helpref{wxFont::SetFamily
}{wxfontsetfamily
} for a list of valid
313 \helpref{wxFont::SetFamily
}{wxfontsetfamily
}
316 \membersection{wxFont::GetNativeFontInfoDesc
}\label{wxfontgetnativefontinfodesc
}
318 \constfunc{wxString
}{GetNativeFontInfoDesc
}{\void}
320 Returns the platform-dependent string completely describing this font.
321 Returned string is always non-empty.
322 Note that the returned string is not meant to be shown or edited by the user: a typical
323 use of this function is for serializing in string-form a wxFont object.
327 \helpref{wxFont::SetNativeFontInfo
}{wxfontsetnativefontinfo
},
\helpref{wxFont::GetNativeFontInfoUserDesc
}{wxfontgetnativefontinfouserdesc
}
330 \membersection{wxFont::GetNativeFontInfoUserDesc
}\label{wxfontgetnativefontinfouserdesc
}
332 \func{wxString
}{GetNativeFontInfoUserDesc
}{\void}
334 Returns a user-friendly string for this font object. Returned string is always non-empty.
335 Some examples of the formats of returned strings (which are platform-dependent) are in
\helpref{SetNativeFontInfoUserDesc
}{wxfontsetnativefontinfouserdesc
}.
339 \helpref{wxFont::GetNativeFontInfoDesc
}{wxfontgetnativefontinfodesc
}
342 \membersection{wxFont::GetPointSize
}\label{wxfontgetpointsize
}
344 \constfunc{int
}{GetPointSize
}{\void}
350 \helpref{wxFont::SetPointSize
}{wxfontsetpointsize
}
353 \membersection{wxFont::GetStyle
}\label{wxfontgetstyle
}
355 \constfunc{int
}{GetStyle
}{\void}
357 Gets the font style. See
\helpref{wxFont::wxFont
}{wxfontctor
} for a list of valid
362 \helpref{wxFont::SetStyle
}{wxfontsetstyle
}
365 \membersection{wxFont::GetUnderlined
}\label{wxfontgetunderlined
}
367 \constfunc{bool
}{GetUnderlined
}{\void}
369 Returns true if the font is underlined, false otherwise.
373 \helpref{wxFont::SetUnderlined
}{wxfontsetunderlined
}
376 \membersection{wxFont::GetWeight
}\label{wxfontgetweight
}
378 \constfunc{wxFontWeight
}{GetWeight
}{\void}
380 Gets the font weight. See
\helpref{wxFont::wxFont
}{wxfontctor
} for a list of valid
385 \helpref{wxFont::SetWeight
}{wxfontsetweight
}
388 \membersection{wxFont::New
}\label{wxfontnew
}
390 \func{static wxFont *
}{New
}{\param{int
}{ pointSize
},
\param{wxFontFamily
}{ family
},
\param{int
}{ style
},
\param{wxFontWeight
}{ weight
},
391 \param{const bool
}{ underline = false
},
\param{const wxString\&
}{faceName = ""
},
392 \param{wxFontEncoding
}{encoding = wxFONTENCODING
\_DEFAULT}}
394 \func{static wxFont *
}{New
}{\param{int
}{ pointSize
},
\param{wxFontFamily
}{ family
},
395 \param{int
}{ flags =
\texttt{wxFONTFLAG
\_DEFAULT}},
\param{const wxString\&
}{faceName = ""
},
396 \param{wxFontEncoding
}{encoding = wxFONTENCODING
\_DEFAULT}}
398 \func{static wxFont *
}{New
}{\param{const wxSize\&
}{ pixelSize
},
\param{wxFontFamily
}{ family
},
\param{int
}{ style
},
\param{wxFontWeight
}{ weight
},
399 \param{const bool
}{ underline = false
},
\param{const wxString\&
}{faceName = ""
},
400 \param{wxFontEncoding
}{encoding = wxFONTENCODING
\_DEFAULT}}
402 \func{static wxFont *
}{New
}{\param{const wxSize\&
}{ pixelSize
},
\param{wxFontFamily
}{ family
},
403 \param{int
}{ flags =
\texttt{wxFONTFLAG
\_DEFAULT}},
\param{const wxString\&
}{faceName = ""
},
404 \param{wxFontEncoding
}{encoding = wxFONTENCODING
\_DEFAULT}}
406 These functions take the same parameters as
\helpref{wxFont
407 constructor
}{wxfontctor
} and return a new font object allocated on the heap.
409 Using
\texttt{New()
} is currently the only way to directly create a font with
410 the given size in pixels on platforms other than wxMSW.
413 \membersection{wxFont::IsOk
}\label{wxfontisok
}
415 \constfunc{bool
}{IsOk
}{\void}
417 Returns
{\tt true
} if this object is a valid font,
{\tt false
} otherwise.
420 \membersection{wxFont::SetDefaultEncoding
}\label{wxfontsetdefaultencoding
}
422 \func{static void
}{SetDefaultEncoding
}{\param{wxFontEncoding
}{encoding
}}
424 Sets the default font encoding.
428 \helpref{Font encoding overview
}{wxfontencodingoverview
},
429 \helpref{GetDefaultEncoding
}{wxfontgetdefaultencoding
}
432 \membersection{wxFont::SetFaceName
}\label{wxfontsetfacename
}
434 \func{bool
}{SetFaceName
}{\param{const wxString\&
}{faceName
}}
436 Sets the facename for the font.
437 Returns
\true if the given face name exists;
\false otherwise.
439 \wxheading{Parameters
}
441 \docparam{faceName
}{A valid facename, which should be on the end-user's system.
}
445 To avoid portability problems, don't rely on a specific face, but specify the font family
446 instead or as well. A suitable font will be found on the end-user's system. If both the
447 family and the facename are specified, wxWidgets will first search for the specific face,
448 and then for a font belonging to the same family.
452 \helpref{wxFont::GetFaceName
}{wxfontgetfacename
},
\helpref{wxFont::SetFamily
}{wxfontsetfamily
}
455 \membersection{wxFont::SetFamily
}\label{wxfontsetfamily
}
457 \func{void
}{SetFamily
}{\param{wxFontFamily
}{ family
}}
459 Sets the font family.
461 \wxheading{Parameters
}
463 \docparam{family
}{One of:
466 \begin{twocollist
}\itemsep=
0pt
467 \twocolitem{{\bf wxFONTFAMILY
\_DEFAULT}}{Chooses a default font.
}
468 \twocolitem{{\bf wxFONTFAMILY
\_DECORATIVE}}{A decorative font.
}
469 \twocolitem{{\bf wxFONTFAMILY
\_ROMAN}}{A formal, serif font.
}
470 \twocolitem{{\bf wxFONTFAMILY
\_SCRIPT}}{A handwriting font.
}
471 \twocolitem{{\bf wxFONTFAMILY
\_SWISS}}{A sans-serif font.
}
472 \twocolitem{{\bf wxFONTFAMILY
\_MODERN}}{A fixed pitch font.
}
473 \twocolitem{{\bf wxFONTFAMILY
\_TELETYPE}}{A teletype font.
}
478 \helpref{wxFont::GetFamily
}{wxfontgetfamily
},
\helpref{wxFont::SetFaceName
}{wxfontsetfacename
}
481 \membersection{wxFont::SetNativeFontInfo
}\label{wxfontsetnativefontinfo
}
483 \func{bool
}{SetNativeFontInfo
}{\param{const wxString\&
}{info
}}
485 Creates the font corresponding to the given native font description string and returns
\true if
486 the creation was successful.
487 which must have been previously returned by
488 \helpref{GetNativeFontInfoDesc
}{wxfontgetnativefontinfodesc
}. If the string is
489 invalid, font is unchanged. This function is typically used for de-serializing a wxFont
490 object previously saved in a string-form.
494 \helpref{wxFont::SetNativeFontInfoUserDesc
}{wxfontsetnativefontinfouserdesc
}
497 \membersection{wxFont::SetNativeFontInfoUserDesc
}\label{wxfontsetnativefontinfouserdesc
}
499 \func{bool
}{SetNativeFontInfoUserDesc
}{\param{const wxString\&
}{info
}}
501 Creates the font corresponding to the given native font description string and returns
\true if
502 the creation was successful.
503 Unlike
\helpref{SetNativeFontInfo
}{wxfontsetnativefontinfo
}, this function accepts
504 strings which are user-friendly.
505 Examples of accepted string formats are:
508 \begin{twocollist
}\itemsep=
0pt
509 \twocolitem{Generic syntax
}{Example
}
510 \twocolitem{on
{\bf wxGTK2
}:
{\tt $
[FACE-NAME
]$ $
[bold
]$ $
[oblique|italic
]$ $
[POINTSIZE
]$
}}{Monospace bold
10}
511 \twocolitem{on
{\bf wxMSW
}:
{\tt $
[light|bold
]$ $
[italic
]$ $
[FACE-NAME
]$ $
[POINTSIZE
]$ $
[ENCODING
]$
}}{Tahoma
10 WINDOWS-
1252}
512 \twocolitem{on
{\bf wxMac
}: FIXME
}{FIXME
}
515 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
}).
519 \helpref{wxFont::SetNativeFontInfo
}{wxfontsetnativefontinfo
}
523 \membersection{wxFont::SetPointSize
}\label{wxfontsetpointsize
}
525 \func{void
}{SetPointSize
}{\param{int
}{ pointSize
}}
529 \wxheading{Parameters
}
531 \docparam{pointSize
}{Size in points.
}
535 \helpref{wxFont::GetPointSize
}{wxfontgetpointsize
}
538 \membersection{wxFont::SetStyle
}\label{wxfontsetstyle
}
540 \func{void
}{SetStyle
}{\param{int
}{ style
}}
544 \wxheading{Parameters
}
546 \docparam{style
}{One of
{\bf wxFONTSTYLE
\_NORMAL},
{\bf wxFONTSTYLE
\_SLANT} and
{\bf wxFONTSTYLE
\_ITALIC}.
}
550 \helpref{wxFont::GetStyle
}{wxfontgetstyle
}
553 \membersection{wxFont::SetUnderlined
}\label{wxfontsetunderlined
}
555 \func{void
}{SetUnderlined
}{\param{const bool
}{ underlined
}}
559 \wxheading{Parameters
}
561 \docparam{underlining
}{true to underline, false otherwise.
}
565 \helpref{wxFont::GetUnderlined
}{wxfontgetunderlined
}
568 \membersection{wxFont::SetWeight
}\label{wxfontsetweight
}
570 \func{void
}{SetWeight
}{\param{wxFontWeight
}{ weight
}}
572 Sets the font weight.
574 \wxheading{Parameters
}
576 \docparam{weight
}{One of:
579 \begin{twocollist
}\itemsep=
0pt
580 \twocolitem{{\bf wxFONTWEIGHT
\_NORMAL}}{Normal font.
}
581 \twocolitem{{\bf wxFONTWEIGHT
\_LIGHT}}{Light font.
}
582 \twocolitem{{\bf wxFONTWEIGHT
\_BOLD}}{Bold font.
}
587 \helpref{wxFont::GetWeight
}{wxfontgetweight
}
590 \membersection{wxFont::operator $=$
}\label{wxfontassignment
}
592 \func{wxFont\&
}{operator $=$
}{\param{const wxFont\&
}{font
}}
594 Assignment operator, using
\helpref{reference counting
}{trefcount
}.
597 \membersection{wxFont::operator $==$
}\label{wxfontequals
}
599 \func{bool
}{operator $==$
}{\param{const wxFont\&
}{font
}}
602 See
\helpref{reference-counted object comparison
}{refcountequality
} for more info.
605 \membersection{wxFont::operator $!=$
}\label{wxfontnotequals
}
607 \func{bool
}{operator $!=$
}{\param{const wxFont\&
}{font
}}
610 See
\helpref{reference-counted object comparison
}{refcountequality
} for more info.