]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/latex/wx/font.tex
corrected ancient event type constant in an example
[wxWidgets.git] / docs / latex / wx / font.tex
... / ...
CommitLineData
1\section{\class{wxFont}}\label{wxfont}
2
3A font is an object which determines the appearance of text. Fonts are
4used for drawing text to a device context, and setting the appearance of
5a window's text.
6
7You can retrieve the current system font settings with \helpref{wxSystemSettings}{wxsystemsettings}.
8
9\helpref{wxSystemSettings}{wxsystemsettings}
10
11\wxheading{Derived from}
12
13\helpref{wxGDIObject}{wxgdiobject}\\
14\helpref{wxObject}{wxobject}
15
16\wxheading{Include files}
17
18<wx/font.h>
19
20\wxheading{Constants}
21
22The possible values for the \arg{family} parameter of \helpref{wxFont
23constructor}{wxfontctor} are (the old names are for compatibility only):
24
25\begin{verbatim}
26enum wxFontFamily
27{
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,
35 wxFONTFAMILY_MAX
36};
37\end{verbatim}
38
39The possible values for the \arg{weight} parameter are (the old names
40are for compatibility only):
41
42\begin{verbatim}
43enum wxFontWeight
44{
45 wxFONTWEIGHT_NORMAL = wxNORMAL,
46 wxFONTWEIGHT_LIGHT = wxLIGHT,
47 wxFONTWEIGHT_BOLD = wxBOLD,
48 wxFONTWEIGHT_MAX
49};
50\end{verbatim}
51
52The font flags which can be used during the font creation are:
53
54\begin{verbatim}
55enum
56{
57 // no special flags: font with default weight/slant/anti-aliasing
58 wxFONTFLAG_DEFAULT = 0,
59
60 // slant flags (default: no slant)
61 wxFONTFLAG_ITALIC = 1 << 0,
62 wxFONTFLAG_SLANT = 1 << 1,
63
64 // weight flags (default: medium)
65 wxFONTFLAG_LIGHT = 1 << 2,
66 wxFONTFLAG_BOLD = 1 << 3,
67
68 // anti-aliasing flag: force on or off (default: the current system default)
69 wxFONTFLAG_ANTIALIASED = 1 << 4,
70 wxFONTFLAG_NOT_ANTIALIASED = 1 << 5,
71
72 // underlined/strikethrough flags (default: no lines)
73 wxFONTFLAG_UNDERLINED = 1 << 6,
74 wxFONTFLAG_STRIKETHROUGH = 1 << 7,
75};
76\end{verbatim}
77
78The known font encodings are:
79
80\begin{verbatim}
81enum wxFontEncoding
82{
83 wxFONTENCODING_SYSTEM = -1, // system default
84 wxFONTENCODING_DEFAULT, // current default encoding
85
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,
105
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
110
111 // what would we do without Microsoft? They have their own encodings
112 // for DOS
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
118 // and for Windows
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,
129
130 wxFONTENCODING_UTF7, // UTF-7 Unicode encoding
131 wxFONTENCODING_UTF8, // UTF-8 Unicode encoding
132
133 wxFONTENCODING_UNICODE, // Unicode - currently used only by
134 // wxEncodingConverter class
135
136 wxFONTENCODING_MAX
137};
138\end{verbatim}
139
140\wxheading{Predefined objects}
141
142Objects:
143
144{\bf wxNullFont}
145
146Pointers:
147
148{\bf wxNORMAL\_FONT\\
149wxSMALL\_FONT\\
150wxITALIC\_FONT\\
151wxSWISS\_FONT}
152
153\wxheading{See also}
154
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}
158
159\latexignore{\rtfignore{\wxheading{Members}}}
160
161
162\membersection{wxFont::wxFont}\label{wxfontctor}
163
164\func{}{wxFont}{\void}
165
166Default constructor.
167
168\func{}{wxFont}{\param{int}{ pointSize}, \param{wxFontFamily}{ family}, \param{int}{ style}, \param{wxFontWeight}{ weight},
169 \param{const bool}{ underline = false}, \param{const wxString\& }{faceName = ""},
170 \param{wxFontEncoding }{encoding = wxFONTENCODING\_DEFAULT}}
171
172\func{}{wxFont}{\param{const wxSize\&}{ pixelSize}, \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}}
175
176Creates a font object with the specified attributes.
177
178\wxheading{Parameters}
179
180\docparam{pointSize}{Size in points.}
181
182\docparam{pixelSize}{Size in pixels: this is directly supported only under MSW
183currently where this constructor can be used directly, under other platforms a
184font with the closest size to the given one is found using binary search and
185the static \helpref{New}{wxfontnew} method must be used.}
186
187\docparam{family}{Font family, a generic way of referring to fonts without specifying actual facename. One of:
188
189\twocolwidtha{5cm}
190\begin{twocollist}\itemsep=0pt
191\twocolitem{{\bf wxFONTFAMILY\_DEFAULT}}{Chooses a default font.}
192\twocolitem{{\bf wxFONTFAMILY\_DECORATIVE}}{A decorative font.}
193\twocolitem{{\bf wxFONTFAMILY\_ROMAN}}{A formal, serif font.}
194\twocolitem{{\bf wxFONTFAMILY\_SCRIPT}}{A handwriting font.}
195\twocolitem{{\bf wxFONTFAMILY\_SWISS}}{A sans-serif font.}
196\twocolitem{{\bf wxFONTFAMILY\_MODERN}}{A fixed pitch font.}
197\twocolitem{{\bf wxFONTFAMILY\_TELETYPE}}{A teletype font.}
198\end{twocollist}}
199
200\docparam{style}{One of {\bf wxFONTSTYLE\_NORMAL}, {\bf wxFONTSTYLE\_SLANT} and {\bf wxFONTSTYLE\_ITALIC}.}
201
202\docparam{weight}{Font weight, sometimes also referred to as font boldness. One of:
203
204\twocolwidtha{5cm}
205\begin{twocollist}\itemsep=0pt
206\twocolitem{{\bf wxFONTWEIGHT\_NORMAL}}{Normal font.}
207\twocolitem{{\bf wxFONTWEIGHT\_LIGHT}}{Light font.}
208\twocolitem{{\bf wxFONTWEIGHT\_BOLD}}{Bold font.}
209\end{twocollist}}
210
211\docparam{underline}{The value can be true or false. At present this has an effect on Windows and Motif 2.x only.}
212
213\docparam{faceName}{An optional string specifying the actual typeface to be used. If it is an empty string,
214a default typeface will be chosen based on the family.}
215
216\docparam{encoding}{An encoding which may be one of
217\twocolwidtha{5cm}
218\begin{twocollist}\itemsep=0pt
219\twocolitem{{\bf wxFONTENCODING\_SYSTEM}}{Default system encoding.}
220\twocolitem{{\bf wxFONTENCODING\_DEFAULT}}{Default application encoding: this
221is the encoding set by calls to
222\helpref{SetDefaultEncoding}{wxfontsetdefaultencoding} and which may be set to,
223say, KOI8 to create all fonts by default with KOI8 encoding. Initially, the
224default application encoding is the same as default system encoding.}
225\twocolitem{{\bf wxFONTENCODING\_ISO8859\_1...15}}{ISO8859 encodings.}
226\twocolitem{{\bf wxFONTENCODING\_KOI8}}{The standard Russian encoding for Internet.}
227\twocolitem{{\bf wxFONTENCODING\_CP1250...1252}}{Windows encodings similar to ISO8859 (but not identical).}
228\end{twocollist}
229If the specified encoding isn't available, no font is created
230(see also \helpref{font encoding overview}{wxfontencodingoverview}).
231}
232
233\wxheading{Remarks}
234
235If the desired font does not exist, the closest match will be chosen.
236Under Windows, only scalable TrueType fonts are used.
237
238See also \helpref{wxDC::SetFont}{wxdcsetfont}, \helpref{wxDC::DrawText}{wxdcdrawtext}
239and \helpref{wxDC::GetTextExtent}{wxdcgettextextent}.
240
241
242\membersection{wxFont::\destruct{wxFont}}\label{wxfontdtor}
243
244\func{}{\destruct{wxFont}}{\void}
245
246Destructor.
247
248\wxheading{Remarks}
249
250The destructor may not delete the underlying font object of the native windowing
251system, since wxFont uses a reference counting system for efficiency.
252
253Although all remaining fonts are deleted when the application exits,
254the application should try to clean up all fonts itself. This is because
255wxWidgets cannot know if a pointer to the font object is stored in an
256application data structure, and there is a risk of double deletion.
257
258
259\membersection{wxFont::IsFixedWidth}\label{wxfontisfixedwidth}
260
261\constfunc{bool}{IsFixedWidth}{\void}
262
263Returns {\tt true} if the font is a fixed width (or monospaced) font,
264{\tt false} if it is a proportional one or font is invalid.
265
266
267\membersection{wxFont::GetDefaultEncoding}\label{wxfontgetdefaultencoding}
268
269\func{static wxFontEncoding}{GetDefaultEncoding}{\void}
270
271Returns the current application's default encoding.
272
273\wxheading{See also}
274
275\helpref{Font encoding overview}{wxfontencodingoverview},
276\helpref{SetDefaultEncoding}{wxfontsetdefaultencoding}
277
278
279\membersection{wxFont::GetFaceName}\label{wxfontgetfacename}
280
281\constfunc{wxString}{GetFaceName}{\void}
282
283Returns the typeface name associated with the font, or the empty string if there is no
284typeface information.
285
286\wxheading{See also}
287
288\helpref{wxFont::SetFaceName}{wxfontsetfacename}
289
290
291\membersection{wxFont::GetFamily}\label{wxfontgetfamily}
292
293\constfunc{wxFontFamily}{GetFamily}{\void}
294
295Gets the font family. See \helpref{wxFont::SetFamily}{wxfontsetfamily} for a list of valid
296family identifiers.
297
298\wxheading{See also}
299
300\helpref{wxFont::SetFamily}{wxfontsetfamily}
301
302
303\membersection{wxFont::GetNativeFontInfoDesc}\label{wxfontgetnativefontinfodesc}
304
305\constfunc{wxString}{GetNativeFontInfoDesc}{\void}
306
307Returns the platform-dependent string completely describing this font or an
308empty string if the font wasn't constructed using the native font description.
309
310\wxheading{See also}
311
312\helpref{wxFont::SetNativeFontInfo}{wxfontsetnativefontinfo}
313
314
315\membersection{wxFont::GetPointSize}\label{wxfontgetpointsize}
316
317\constfunc{int}{GetPointSize}{\void}
318
319Gets the point size.
320
321\wxheading{See also}
322
323\helpref{wxFont::SetPointSize}{wxfontsetpointsize}
324
325
326\membersection{wxFont::GetStyle}\label{wxfontgetstyle}
327
328\constfunc{int}{GetStyle}{\void}
329
330Gets the font style. See \helpref{wxFont::wxFont}{wxfontctor} for a list of valid
331styles.
332
333\wxheading{See also}
334
335\helpref{wxFont::SetStyle}{wxfontsetstyle}
336
337
338\membersection{wxFont::GetUnderlined}\label{wxfontgetunderlined}
339
340\constfunc{bool}{GetUnderlined}{\void}
341
342Returns true if the font is underlined, false otherwise.
343
344\wxheading{See also}
345
346\helpref{wxFont::SetUnderlined}{wxfontsetunderlined}
347
348
349\membersection{wxFont::GetWeight}\label{wxfontgetweight}
350
351\constfunc{wxFontWeight}{GetWeight}{\void}
352
353Gets the font weight. See \helpref{wxFont::wxFont}{wxfontctor} for a list of valid
354weight identifiers.
355
356\wxheading{See also}
357
358\helpref{wxFont::SetWeight}{wxfontsetweight}
359
360
361\membersection{wxFont::New}\label{wxfontnew}
362
363\func{static wxFont *}{New}{\param{int}{ pointSize}, \param{wxFontFamily}{ family}, \param{int}{ style}, \param{wxFontWeight}{ weight},
364 \param{const bool}{ underline = false}, \param{const wxString\& }{faceName = ""},
365 \param{wxFontEncoding }{encoding = wxFONTENCODING\_DEFAULT}}
366
367\func{static wxFont *}{New}{\param{int}{ pointSize}, \param{wxFontFamily}{ family},
368 \param{int}{ flags = \texttt{wxFONTFLAG\_DEFAULT}}, \param{const wxString\& }{faceName = ""},
369 \param{wxFontEncoding }{encoding = wxFONTENCODING\_DEFAULT}}
370
371\func{static wxFont *}{New}{\param{const wxSize\&}{ pixelSize}, \param{wxFontFamily}{ family}, \param{int}{ style}, \param{wxFontWeight}{ weight},
372 \param{const bool}{ underline = false}, \param{const wxString\& }{faceName = ""},
373 \param{wxFontEncoding }{encoding = wxFONTENCODING\_DEFAULT}}
374
375\func{static wxFont *}{New}{\param{const wxSize\&}{ pixelSize}, \param{wxFontFamily}{ family},
376 \param{int}{ flags = \texttt{wxFONTFLAG\_DEFAULT}}, \param{const wxString\& }{faceName = ""},
377 \param{wxFontEncoding }{encoding = wxFONTENCODING\_DEFAULT}}
378
379These functions take the same parameters as \helpref{wxFont
380constructor}{wxfontctor} and return a new font object allocated on the heap.
381
382Using \texttt{New()} is currently the only way to directly create a font with
383the given size in pixels on platforms other than wxMSW.
384
385
386\membersection{wxFont::Ok}\label{wxfontok}
387
388\constfunc{bool}{Ok}{\void}
389
390Returns {\tt true} if this object is a valid font, {\tt false} otherwise.
391
392
393\membersection{wxFont::SetDefaultEncoding}\label{wxfontsetdefaultencoding}
394
395\func{static void}{SetDefaultEncoding}{\param{wxFontEncoding }{encoding}}
396
397Sets the default font encoding.
398
399\wxheading{See also}
400
401\helpref{Font encoding overview}{wxfontencodingoverview},
402\helpref{GetDefaultEncoding}{wxfontgetdefaultencoding}
403
404
405\membersection{wxFont::SetFaceName}\label{wxfontsetfacename}
406
407\func{void}{SetFaceName}{\param{const wxString\& }{faceName}}
408
409Sets the facename for the font.
410
411\wxheading{Parameters}
412
413\docparam{faceName}{A valid facename, which should be on the end-user's system.}
414
415\wxheading{Remarks}
416
417To avoid portability problems, don't rely on a specific face, but specify the font family
418instead or as well. A suitable font will be found on the end-user's system. If both the
419family and the facename are specified, wxWidgets will first search for the specific face,
420and then for a font belonging to the same family.
421
422\wxheading{See also}
423
424\helpref{wxFont::GetFaceName}{wxfontgetfacename}, \helpref{wxFont::SetFamily}{wxfontsetfamily}
425
426
427\membersection{wxFont::SetFamily}\label{wxfontsetfamily}
428
429\func{void}{SetFamily}{\param{wxFontFamily}{ family}}
430
431Sets the font family.
432
433\wxheading{Parameters}
434
435\docparam{family}{One of:
436
437\twocolwidtha{5cm}
438\begin{twocollist}\itemsep=0pt
439\twocolitem{{\bf wxFONTFAMILY\_DEFAULT}}{Chooses a default font.}
440\twocolitem{{\bf wxFONTFAMILY\_DECORATIVE}}{A decorative font.}
441\twocolitem{{\bf wxFONTFAMILY\_ROMAN}}{A formal, serif font.}
442\twocolitem{{\bf wxFONTFAMILY\_SCRIPT}}{A handwriting font.}
443\twocolitem{{\bf wxFONTFAMILY\_SWISS}}{A sans-serif font.}
444\twocolitem{{\bf wxFONTFAMILY\_MODERN}}{A fixed pitch font.}
445\twocolitem{{\bf wxFONTFAMILY\_TELETYPE}}{A teletype font.}
446\end{twocollist}}
447
448\wxheading{See also}
449
450\helpref{wxFont::GetFamily}{wxfontgetfamily}, \helpref{wxFont::SetFaceName}{wxfontsetfacename}
451
452
453\membersection{wxFont::SetNativeFontInfo}\label{wxfontsetnativefontinfo}
454
455\func{void}{SetNativeFontInfo}{\param{const wxString\& }{info}}
456
457Creates the font corresponding to the given native font description string
458which must have been previously returned by
459\helpref{GetNativeFontInfoDesc}{wxfontgetnativefontinfodesc}. If the string is
460invalid, font is unchanged.
461
462
463\membersection{wxFont::SetPointSize}\label{wxfontsetpointsize}
464
465\func{void}{SetPointSize}{\param{int}{ pointSize}}
466
467Sets the point size.
468
469\wxheading{Parameters}
470
471\docparam{pointSize}{Size in points.}
472
473\wxheading{See also}
474
475\helpref{wxFont::GetPointSize}{wxfontgetpointsize}
476
477
478\membersection{wxFont::SetStyle}\label{wxfontsetstyle}
479
480\func{void}{SetStyle}{\param{int}{ style}}
481
482Sets the font style.
483
484\wxheading{Parameters}
485
486\docparam{style}{One of {\bf wxFONTSTYLE\_NORMAL}, {\bf wxFONTSTYLE\_SLANT} and {\bf wxFONTSTYLE\_ITALIC}.}
487
488\wxheading{See also}
489
490\helpref{wxFont::GetStyle}{wxfontgetstyle}
491
492
493\membersection{wxFont::SetUnderlined}\label{wxfontsetunderlined}
494
495\func{void}{SetUnderlined}{\param{const bool}{ underlined}}
496
497Sets underlining.
498
499\wxheading{Parameters}
500
501\docparam{underlining}{true to underline, false otherwise.}
502
503\wxheading{See also}
504
505\helpref{wxFont::GetUnderlined}{wxfontgetunderlined}
506
507
508\membersection{wxFont::SetWeight}\label{wxfontsetweight}
509
510\func{void}{SetWeight}{\param{wxFontWeight}{ weight}}
511
512Sets the font weight.
513
514\wxheading{Parameters}
515
516\docparam{weight}{One of:
517
518\twocolwidtha{5cm}
519\begin{twocollist}\itemsep=0pt
520\twocolitem{{\bf wxFONTWEIGHT\_NORMAL}}{Normal font.}
521\twocolitem{{\bf wxFONTWEIGHT\_LIGHT}}{Light font.}
522\twocolitem{{\bf wxFONTWEIGHT\_BOLD}}{Bold font.}
523\end{twocollist}}
524
525\wxheading{See also}
526
527\helpref{wxFont::GetWeight}{wxfontgetweight}
528
529
530\membersection{wxFont::operator $=$}\label{wxfontassignment}
531
532\func{wxFont\&}{operator $=$}{\param{const wxFont\& }{font}}
533
534Assignment operator, using reference counting. Returns a reference
535to `this'.
536
537
538\membersection{wxFont::operator $==$}\label{wxfontequals}
539
540\func{bool}{operator $==$}{\param{const wxFont\& }{font}}
541
542Equality operator. Two fonts are equal if they contain pointers
543to the same underlying font data. It does not compare each attribute,
544so two independently-created fonts using the same parameters will
545fail the test.
546
547
548\membersection{wxFont::operator $!=$}\label{wxfontnotequals}
549
550\func{bool}{operator $!=$}{\param{const wxFont\& }{font}}
551
552Inequality operator. Two fonts are not equal if they contain pointers
553to different underlying font data. It does not compare each attribute.
554