]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_font.i
wxMemoryDC constructor now optionally accepts a wxBitmap parameter,
[wxWidgets.git] / wxPython / src / _font.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _font.i
3 // Purpose: SWIG interface file for wxFont and related classes
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 1-Apr-2002
8 // RCS-ID: $Id$
9 // Copyright: (c) 2002 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17
18 %{
19 #include <wx/fontutil.h>
20 #include <wx/fontmap.h>
21 #include <wx/fontenum.h>
22 %}
23
24 //---------------------------------------------------------------------------
25 %newgroup
26
27
28 enum wxFontFamily
29 {
30 wxFONTFAMILY_DEFAULT = wxDEFAULT,
31 wxFONTFAMILY_DECORATIVE = wxDECORATIVE,
32 wxFONTFAMILY_ROMAN = wxROMAN,
33 wxFONTFAMILY_SCRIPT = wxSCRIPT,
34 wxFONTFAMILY_SWISS = wxSWISS,
35 wxFONTFAMILY_MODERN = wxMODERN,
36 wxFONTFAMILY_TELETYPE = wxTELETYPE,
37 wxFONTFAMILY_MAX,
38 wxFONTFAMILY_UNKNOWN = wxFONTFAMILY_MAX
39 };
40
41 // font styles
42 enum wxFontStyle
43 {
44 wxFONTSTYLE_NORMAL = wxNORMAL,
45 wxFONTSTYLE_ITALIC = wxITALIC,
46 wxFONTSTYLE_SLANT = wxSLANT,
47 wxFONTSTYLE_MAX
48 };
49
50 // font weights
51 enum wxFontWeight
52 {
53 wxFONTWEIGHT_NORMAL = wxNORMAL,
54 wxFONTWEIGHT_LIGHT = wxLIGHT,
55 wxFONTWEIGHT_BOLD = wxBOLD,
56 wxFONTWEIGHT_MAX
57 };
58
59
60 // the font flag bits for the new font ctor accepting one combined flags word
61 enum
62 {
63 // no special flags: font with default weight/slant/anti-aliasing
64 wxFONTFLAG_DEFAULT,
65
66 // slant flags (default: no slant)
67 wxFONTFLAG_ITALIC,
68 wxFONTFLAG_SLANT,
69
70 // weight flags (default: medium)
71 wxFONTFLAG_LIGHT,
72 wxFONTFLAG_BOLD,
73
74 // anti-aliasing flag: force on or off (default: the current system default)
75 wxFONTFLAG_ANTIALIASED,
76 wxFONTFLAG_NOT_ANTIALIASED,
77
78 // underlined/strikethrough flags (default: no lines)
79 wxFONTFLAG_UNDERLINED,
80 wxFONTFLAG_STRIKETHROUGH,
81
82 // the mask of all currently used flags
83 wxFONTFLAG_MASK
84 };
85
86
87 // font encodings
88 enum wxFontEncoding
89 {
90 wxFONTENCODING_SYSTEM = -1, // system default
91 wxFONTENCODING_DEFAULT, // current default encoding
92
93 // ISO8859 standard defines a number of single-byte charsets
94 wxFONTENCODING_ISO8859_1, // West European (Latin1)
95 wxFONTENCODING_ISO8859_2, // Central and East European (Latin2)
96 wxFONTENCODING_ISO8859_3, // Esperanto (Latin3)
97 wxFONTENCODING_ISO8859_4, // Baltic (old) (Latin4)
98 wxFONTENCODING_ISO8859_5, // Cyrillic
99 wxFONTENCODING_ISO8859_6, // Arabic
100 wxFONTENCODING_ISO8859_7, // Greek
101 wxFONTENCODING_ISO8859_8, // Hebrew
102 wxFONTENCODING_ISO8859_9, // Turkish (Latin5)
103 wxFONTENCODING_ISO8859_10, // Variation of Latin4 (Latin6)
104 wxFONTENCODING_ISO8859_11, // Thai
105 wxFONTENCODING_ISO8859_12, // doesn't exist currently, but put it
106 // here anyhow to make all ISO8859
107 // consecutive numbers
108 wxFONTENCODING_ISO8859_13, // Baltic (Latin7)
109 wxFONTENCODING_ISO8859_14, // Latin8
110 wxFONTENCODING_ISO8859_15, // Latin9 (a.k.a. Latin0, includes euro)
111 wxFONTENCODING_ISO8859_MAX,
112
113 // Cyrillic charset soup (see http://czyborra.com/charsets/cyrillic.html)
114 wxFONTENCODING_KOI8, // KOI8 Russian
115 wxFONTENCODING_KOI8_U, // KOI8 Ukrainian
116 wxFONTENCODING_ALTERNATIVE, // same as MS-DOS CP866
117 wxFONTENCODING_BULGARIAN, // used under Linux in Bulgaria
118
119 // what would we do without Microsoft? They have their own encodings
120 // for DOS
121 wxFONTENCODING_CP437, // original MS-DOS codepage
122 wxFONTENCODING_CP850, // CP437 merged with Latin1
123 wxFONTENCODING_CP852, // CP437 merged with Latin2
124 wxFONTENCODING_CP855, // another cyrillic encoding
125 wxFONTENCODING_CP866, // and another one
126 // and for Windows
127 wxFONTENCODING_CP874, // WinThai
128 wxFONTENCODING_CP932, // Japanese (shift-JIS)
129 wxFONTENCODING_CP936, // Chinese simplified (GB)
130 wxFONTENCODING_CP949, // Korean (Hangul charset)
131 wxFONTENCODING_CP950, // Chinese (traditional - Big5)
132 wxFONTENCODING_CP1250, // WinLatin2
133 wxFONTENCODING_CP1251, // WinCyrillic
134 wxFONTENCODING_CP1252, // WinLatin1
135 wxFONTENCODING_CP1253, // WinGreek (8859-7)
136 wxFONTENCODING_CP1254, // WinTurkish
137 wxFONTENCODING_CP1255, // WinHebrew
138 wxFONTENCODING_CP1256, // WinArabic
139 wxFONTENCODING_CP1257, // WinBaltic (same as Latin 7)
140 wxFONTENCODING_CP12_MAX,
141
142 wxFONTENCODING_UTF7, // UTF-7 Unicode encoding
143 wxFONTENCODING_UTF8, // UTF-8 Unicode encoding
144 wxFONTENCODING_EUC_JP, // Extended Unix Codepage for Japanese
145 wxFONTENCODING_UTF16BE, // UTF-16 Big Endian Unicode encoding
146 wxFONTENCODING_UTF16LE, // UTF-16 Little Endian Unicode encoding
147 wxFONTENCODING_UTF32BE, // UTF-32 Big Endian Unicode encoding
148 wxFONTENCODING_UTF32LE, // UTF-32 Little Endian Unicode encoding
149
150 wxFONTENCODING_MACROMAN, // the standard mac encodings
151 wxFONTENCODING_MACJAPANESE,
152 wxFONTENCODING_MACCHINESETRAD,
153 wxFONTENCODING_MACKOREAN,
154 wxFONTENCODING_MACARABIC,
155 wxFONTENCODING_MACHEBREW,
156 wxFONTENCODING_MACGREEK,
157 wxFONTENCODING_MACCYRILLIC,
158 wxFONTENCODING_MACDEVANAGARI,
159 wxFONTENCODING_MACGURMUKHI,
160 wxFONTENCODING_MACGUJARATI,
161 wxFONTENCODING_MACORIYA,
162 wxFONTENCODING_MACBENGALI,
163 wxFONTENCODING_MACTAMIL,
164 wxFONTENCODING_MACTELUGU,
165 wxFONTENCODING_MACKANNADA,
166 wxFONTENCODING_MACMALAJALAM,
167 wxFONTENCODING_MACSINHALESE,
168 wxFONTENCODING_MACBURMESE,
169 wxFONTENCODING_MACKHMER,
170 wxFONTENCODING_MACTHAI,
171 wxFONTENCODING_MACLAOTIAN,
172 wxFONTENCODING_MACGEORGIAN,
173 wxFONTENCODING_MACARMENIAN,
174 wxFONTENCODING_MACCHINESESIMP,
175 wxFONTENCODING_MACTIBETAN,
176 wxFONTENCODING_MACMONGOLIAN,
177 wxFONTENCODING_MACETHIOPIC,
178 wxFONTENCODING_MACCENTRALEUR,
179 wxFONTENCODING_MACVIATNAMESE,
180 wxFONTENCODING_MACARABICEXT,
181 wxFONTENCODING_MACSYMBOL,
182 wxFONTENCODING_MACDINGBATS,
183 wxFONTENCODING_MACTURKISH,
184 wxFONTENCODING_MACCROATIAN,
185 wxFONTENCODING_MACICELANDIC,
186 wxFONTENCODING_MACROMANIAN,
187 wxFONTENCODING_MACCELTIC,
188 wxFONTENCODING_MACGAELIC,
189 wxFONTENCODING_MACKEYBOARD,
190
191 wxFONTENCODING_MACMIN = wxFONTENCODING_MACROMAN ,
192 wxFONTENCODING_MACMAX = wxFONTENCODING_MACKEYBOARD ,
193
194 wxFONTENCODING_MAX, // highest enumerated encoding value
195
196
197 // aliases for endian-dependent UTF encodings
198 wxFONTENCODING_UTF16, // native UTF-16
199 wxFONTENCODING_UTF32, // native UTF-32
200
201 // alias for the native Unicode encoding on this platform
202 // (this is used by wxEncodingConverter and wxUTFFile only for now)
203 wxFONTENCODING_UNICODE = wxFONTENCODING_UTF16,
204
205 // alternative names for Far Eastern encodings
206 // Chinese
207 wxFONTENCODING_GB2312 = wxFONTENCODING_CP936, // Simplified Chinese
208 wxFONTENCODING_BIG5 = wxFONTENCODING_CP950, // Traditional Chinese
209
210 // Japanese (see http://zsigri.tripod.com/fontboard/cjk/jis.html)
211 wxFONTENCODING_SHIFT_JIS = wxFONTENCODING_CP932 // Shift JIS
212 };
213
214 //---------------------------------------------------------------------------
215 %newgroup
216
217 // wxNativeFontInfo is platform-specific font representation: this struct
218 // should be considered as opaque font description only used by the native
219 // functions, the user code can only get the objects of this type from
220 // somewhere and pass it somewhere else (possibly save them somewhere using
221 // ToString() and restore them using FromString())
222 struct wxNativeFontInfo
223 {
224 public:
225 wxNativeFontInfo();
226 ~wxNativeFontInfo();
227
228 // reset to the default state
229 void Init();
230
231 // init with the parameters of the given font
232 void InitFromFont(const wxFont& font);
233
234 // accessors and modifiers for the font elements
235 int GetPointSize() const;
236 #ifdef __WXMSW__
237 wxSize GetPixelSize() const;
238 #endif
239 wxFontStyle GetStyle() const;
240 wxFontWeight GetWeight() const;
241 bool GetUnderlined() const;
242 wxString GetFaceName() const;
243 wxFontFamily GetFamily() const;
244 wxFontEncoding GetEncoding() const;
245
246 void SetPointSize(int pointsize);
247 #ifdef __WXMSW__
248 void SetPixelSize(const wxSize& pixelSize);
249 #endif
250 void SetStyle(wxFontStyle style);
251 void SetWeight(wxFontWeight weight);
252 void SetUnderlined(bool underlined);
253 bool SetFaceName(wxString facename);
254 void SetFamily(wxFontFamily family);
255 void SetEncoding(wxFontEncoding encoding);
256
257 // TODO:
258 // // sets the first facename in the given array which is found
259 // // to be valid. If no valid facename is given, sets the
260 // // first valid facename returned by wxFontEnumerator::GetFacenames().
261 // // Does not return a bool since it cannot fail.
262 // void SetFaceName(const wxArrayString &facenames);
263
264
265 // it is important to be able to serialize wxNativeFontInfo objects to be
266 // able to store them (in config file, for example)
267 bool FromString(const wxString& s);
268 wxString ToString() const;
269
270 %extend {
271 wxString __str__() {
272 return self->ToString();
273 }
274 }
275
276 // we also want to present the native font descriptions to the user in some
277 // human-readable form (it is not platform independent neither, but can
278 // hopefully be understood by the user)
279 bool FromUserString(const wxString& s);
280 wxString ToUserString() const;
281
282 %property(Encoding, GetEncoding, SetEncoding, doc="See `GetEncoding` and `SetEncoding`");
283 %property(FaceName, GetFaceName, SetFaceName, doc="See `GetFaceName` and `SetFaceName`");
284 %property(Family, GetFamily, SetFamily, doc="See `GetFamily` and `SetFamily`");
285 %property(PointSize, GetPointSize, SetPointSize, doc="See `GetPointSize` and `SetPointSize`");
286 %property(Style, GetStyle, SetStyle, doc="See `GetStyle` and `SetStyle`");
287 %property(Underlined, GetUnderlined, SetUnderlined, doc="See `GetUnderlined` and `SetUnderlined`");
288 %property(Weight, GetWeight, SetWeight, doc="See `GetWeight` and `SetWeight`");
289 };
290
291
292
293
294 struct wxNativeEncodingInfo
295 {
296 wxString facename; // may be empty meaning "any"
297 wxFontEncoding encoding; // so that we know what this struct represents
298
299 wxNativeEncodingInfo();
300 ~wxNativeEncodingInfo();
301
302 // this struct is saved in config by wxFontMapper, so it should know to
303 // serialise itself (implemented in platform-specific code)
304 bool FromString(const wxString& s);
305 wxString ToString() const;
306 };
307
308
309 #ifndef __WXMSW__
310 // translate a wxFontEncoding into native encoding parameter (defined above),
311 // returning a wxNativeEncodingInfo if an (exact) match could be found, NULL
312 // otherwise.
313 %inline %{
314 wxNativeEncodingInfo* wxGetNativeFontEncoding(wxFontEncoding encoding) {
315 static wxNativeEncodingInfo info;
316 if ( wxGetNativeFontEncoding(encoding, &info) )
317 return &info;
318 else
319 return NULL;
320 }
321 %}
322
323 // test for the existence of the font described by this facename/encoding,
324 // return True if such font(s) exist, False otherwise
325 bool wxTestFontEncoding(const wxNativeEncodingInfo& info);
326
327 #else
328
329 %inline %{
330 wxNativeEncodingInfo* wxGetNativeFontEncoding(wxFontEncoding encoding)
331 { wxPyRaiseNotImplemented(); return NULL; }
332
333 bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
334 { wxPyRaiseNotImplemented(); return false; }
335 %}
336 #endif
337
338 //---------------------------------------------------------------------------
339 %newgroup
340
341 // wxFontMapper manages user-definable correspondence between logical font
342 // names and the fonts present on the machine.
343 //
344 // The default implementations of all functions will ask the user if they are
345 // not capable of finding the answer themselves and store the answer in a
346 // config file (configurable via SetConfigXXX functions). This behaviour may
347 // be disabled by giving the value of False to "interactive" parameter.
348 // However, the functions will always consult the config file to allow the
349 // user-defined values override the default logic and there is no way to
350 // disable this - which shouldn't be ever needed because if "interactive" was
351 // never True, the config file is never created anyhow.
352 //
353 // This is a singleton class, font mapper objects can only be accessed using
354 // wxFontMapper::Get().
355
356 class wxFontMapper
357 {
358 public:
359 wxFontMapper();
360 ~wxFontMapper();
361
362 // return instance of the wxFontMapper singleton
363 static wxFontMapper *Get();
364 // set the singleton to 'mapper' instance and return previous one
365 static wxFontMapper *Set(wxFontMapper *mapper);
366
367
368 // returns the encoding for the given charset (in the form of RFC 2046) or
369 // wxFONTENCODING_SYSTEM if couldn't decode it
370 //
371 // interactive parameter is ignored in the base class, we behave as if it
372 // were always False
373 virtual wxFontEncoding CharsetToEncoding(const wxString& charset,
374 bool interactive = true);
375
376
377 // get the number of font encodings we know about
378 static size_t GetSupportedEncodingsCount();
379
380 // get the n-th supported encoding
381 static wxFontEncoding GetEncoding(size_t n);
382
383 // return canonical name of this encoding (this is a short string,
384 // GetEncodingDescription() returns a longer one)
385 static wxString GetEncodingName(wxFontEncoding encoding);
386
387 // // return a list of all names of this encoding (see GetEncodingName)
388 // static const wxChar** GetAllEncodingNames(wxFontEncoding encoding);
389
390 // return user-readable string describing the given encoding
391 //
392 // NB: hard-coded now, but might change later (read it from config?)
393 static wxString GetEncodingDescription(wxFontEncoding encoding);
394
395 // find the encoding corresponding to the given name, inverse of
396 // GetEncodingName() and less general than CharsetToEncoding()
397 //
398 // returns wxFONTENCODING_MAX if the name is not a supported encoding
399 static wxFontEncoding GetEncodingFromName(const wxString& name);
400
401
402 // set the root config path to use (should be an absolute path)
403 void SetConfigPath(const wxString& prefix);
404
405 // return default config path
406 static const wxString GetDefaultConfigPath();
407
408
409
410 // Find an alternative for the given encoding (which is supposed to not be
411 // available on this system). If successful, returns the encoding otherwise
412 // returns None.
413 %extend {
414 PyObject* GetAltForEncoding(wxFontEncoding encoding,
415 const wxString& facename = wxPyEmptyString,
416 bool interactive = true) {
417 wxFontEncoding alt_enc;
418 if (self->GetAltForEncoding(encoding, &alt_enc, facename, interactive))
419 return PyInt_FromLong(alt_enc);
420 else {
421 Py_INCREF(Py_None);
422 return Py_None;
423 }
424 }
425 }
426
427
428 // checks whether given encoding is available in given face or not.
429 // If no facename is given (default), return true if it's available in any
430 // facename at all.
431 bool IsEncodingAvailable(wxFontEncoding encoding,
432 const wxString& facename = wxPyEmptyString);
433
434 // the parent window for modal dialogs
435 void SetDialogParent(wxWindow *parent);
436
437 // the title for the dialogs (note that default is quite reasonable)
438 void SetDialogTitle(const wxString& title);
439
440
441 %property(AltForEncoding, GetAltForEncoding, doc="See `GetAltForEncoding`");
442 };
443
444
445
446 //---------------------------------------------------------------------------
447 %newgroup
448
449
450 MustHaveApp(wxFont);
451 MustHaveApp(wxFont::GetDefaultEncoding);
452 MustHaveApp(wxFont::SetDefaultEncoding);
453
454 DocStr(wxFont,
455 "A font is an object which determines the appearance of text. Fonts are
456 used for drawing text to a device context, and setting the appearance
457 of a window's text.
458
459 You can retrieve the current system font settings with `wx.SystemSettings`.", "
460
461 The possible values for the family parameter of wx.Font constructor are:
462
463 ======================== =============================
464 wx.FONTFAMILY_DEFAULT Chooses a default font.
465 wx.FONTFAMILY_DECORATIVE A decorative font.
466 wx.FONTFAMILY_ROMAN A formal, serif font.
467 wx.FONTFAMILY_SCRIPT A handwriting font.
468 wx.FONTFAMILY_SWISS A sans-serif font.
469 wx.FONTFAMILY_MODERN Usually a fixed pitch font.
470 wx.FONTFAMILY_TELETYPE A teletype font.
471 ======================== =============================
472
473 The possible values for the weight parameter are:
474
475 ==================== ==
476 wx.FONTWEIGHT_NORMAL
477 wx.FONTWEIGHT_LIGHT
478 wx.FONTWEIGHT_BOLD
479 ==================== ==
480
481 The known font encodings are:
482
483 =========================== ====================================
484 wx.FONTENCODING_SYSTEM system default
485 wx.FONTENCODING_DEFAULT current default encoding
486 wx.FONTENCODING_ISO8859_1 West European (Latin1)
487 wx.FONTENCODING_ISO8859_2 Central and East European (Latin2)
488 wx.FONTENCODING_ISO8859_3 Esperanto (Latin3)
489 wx.FONTENCODING_ISO8859_4 Baltic (old) (Latin4)
490 wx.FONTENCODING_ISO8859_5 Cyrillic
491 wx.FONTENCODING_ISO8859_6 Arabic
492 wx.FONTENCODING_ISO8859_7 Greek
493 wx.FONTENCODING_ISO8859_8 Hebrew
494 wx.FONTENCODING_ISO8859_9 Turkish (Latin5)
495 wx.FONTENCODING_ISO8859_10 Variation of Latin4 (Latin6)
496 wx.FONTENCODING_ISO8859_11 Thai
497 wx.FONTENCODING_ISO8859_12 doesn't exist currently, but put it
498 here anyhow to make all ISO8859
499 consecutive numbers
500 wx.FONTENCODING_ISO8859_13 Baltic (Latin7)
501 wx.FONTENCODING_ISO8859_14 Latin8
502 wx.FONTENCODING_ISO8859_15 Latin9 (a.k.a. Latin0, includes euro)
503 wx.FONTENCODING_KOI8 Cyrillic charset
504 wx.FONTENCODING_ALTERNATIVE same as MS-DOS CP866
505 wx.FONTENCODING_BULGARIAN used under Linux in Bulgaria
506 wx.FONTENCODING_CP437 original MS-DOS codepage
507 wx.FONTENCODING_CP850 CP437 merged with Latin1
508 wx.FONTENCODING_CP852 CP437 merged with Latin2
509 wx.FONTENCODING_CP855 another cyrillic encoding
510 wx.FONTENCODING_CP866 and another one
511 wx.FONTENCODING_CP874 WinThai
512 wx.FONTENCODING_CP1250 WinLatin2
513 wx.FONTENCODING_CP1251 WinCyrillic
514 wx.FONTENCODING_CP1252 WinLatin1
515 wx.FONTENCODING_CP1253 WinGreek (8859-7)
516 wx.FONTENCODING_CP1254 WinTurkish
517 wx.FONTENCODING_CP1255 WinHebrew
518 wx.FONTENCODING_CP1256 WinArabic
519 wx.FONTENCODING_CP1257 WinBaltic (same as Latin 7)
520 wx.FONTENCODING_UTF7 UTF-7 Unicode encoding
521 wx.FONTENCODING_UTF8 UTF-8 Unicode encoding
522 =========================== ====================================
523
524 ");
525
526 class wxFont : public wxGDIObject {
527 public:
528 %pythonPrepend wxFont "if kwargs.has_key('faceName'): kwargs['face'] = kwargs['faceName'];del kwargs['faceName']"
529
530 DocCtorStr(
531 wxFont( int pointSize, int family, int style, int weight,
532 bool underline=false, const wxString& face = wxPyEmptyString,
533 wxFontEncoding encoding = wxFONTENCODING_DEFAULT),
534 "Creates a font object with the specified attributes.
535
536 :param pointSize: The size of the font in points.
537
538 :param family: Font family. A generic way of referring to fonts
539 without specifying actual facename. It can be One of
540 the ``wx.FONTFAMILY_xxx`` constants.
541
542 :param style: One of the ``wx.FONTSTYLE_xxx`` constants.
543
544 :param weight: Font weight, sometimes also referred to as font
545 boldness. One of the ``wx.FONTWEIGHT_xxx`` constants.
546
547 :param underline: The value can be ``True`` or ``False`` and
548 indicates whether the font will include an underline. This
549 may not be supported on all platforms.
550
551 :param face: An optional string specifying the actual typeface to
552 be used. If it is an empty string, a default typeface will be
553 chosen based on the family.
554
555 :param encoding: An encoding which may be one of the
556 ``wx.FONTENCODING_xxx`` constants. If the specified encoding isn't
557 available, no font is created.
558
559 :see: `wx.FFont`, `wx.FontFromPixelSize`, `wx.FFontFromPixelSize`,
560 `wx.FontFromNativeInfoString`, `wx.FontFromNativeInfo`
561 ", "");
562
563 ~wxFont();
564
565 %RenameDocCtor(
566 FontFromNativeInfo,
567 "Construct a `wx.Font` from a `wx.NativeFontInfo` object.", "",
568 wxFont(const wxNativeFontInfo& info));
569
570 %extend {
571 %RenameDocCtor(
572 FontFromNativeInfoString,
573 "Construct a `wx.Font` from the string representation of a
574 `wx.NativeFontInfo` object.", "",
575 wxFont(const wxString& info))
576 {
577 wxNativeFontInfo nfi;
578 nfi.FromString(info);
579 return new wxFont(nfi);
580 }
581 }
582
583
584 %extend {
585 %RenameDocCtor(
586 FFont,
587 "A bit of a simpler way to create a `wx.Font` using flags instead of
588 individual attribute settings. The value of flags can be a
589 combination of the following:
590
591 ============================ ==
592 wx.FONTFLAG_DEFAULT
593 wx.FONTFLAG_ITALIC
594 wx.FONTFLAG_SLANT
595 wx.FONTFLAG_LIGHT
596 wx.FONTFLAG_BOLD
597 wx.FONTFLAG_ANTIALIASED
598 wx.FONTFLAG_NOT_ANTIALIASED
599 wx.FONTFLAG_UNDERLINED
600 wx.FONTFLAG_STRIKETHROUGH
601 ============================ ==
602
603 :see: `wx.Font.__init__`", "",
604
605 wxFont(int pointSize,
606 wxFontFamily family,
607 int flags = wxFONTFLAG_DEFAULT,
608 const wxString& face = wxPyEmptyString,
609 wxFontEncoding encoding = wxFONTENCODING_DEFAULT))
610 {
611 return wxFont::New(pointSize, family, flags, face, encoding);
612 }
613
614
615 // There is a real ctor for this on wxMSW, but not the others, so just
616 // use the factory function in all cases.
617
618 %RenameDocCtor(
619 FontFromPixelSize,
620 "Creates a font using a size in pixels rather than points. If there is
621 platform API support for this then it is used, otherwise a font with
622 the closest size is found using a binary search.
623
624 :see: `wx.Font.__init__`", "",
625 wxFont(const wxSize& pixelSize,
626 int family,
627 int style,
628 int weight,
629 bool underlined = false,
630 const wxString& face = wxEmptyString,
631 wxFontEncoding encoding = wxFONTENCODING_DEFAULT))
632 {
633 return wxFontBase::New(pixelSize, family,
634 style, weight, underlined,
635 face, encoding);
636 }
637
638 %RenameDocCtor(
639 FFontFromPixelSize,
640 "Creates a font using a size in pixels rather than points. If there is
641 platform API support for this then it is used, otherwise a font with
642 the closest size is found using a binary search.
643
644 :see: `wx.Font.__init__`, `wx.FFont`", "",
645 wxFont(const wxSize& pixelSize,
646 wxFontFamily family,
647 int flags = wxFONTFLAG_DEFAULT,
648 const wxString& face = wxEmptyString,
649 wxFontEncoding encoding = wxFONTENCODING_DEFAULT))
650 {
651 return wxFontBase::New(pixelSize, family, flags, face, encoding);
652 }
653 }
654
655
656
657 // was the font successfully created?
658 DocDeclStr(
659 bool , IsOk() const,
660 "Returns ``True`` if this font was successfully created.", "");
661 %pythoncode { Ok = IsOk }
662 %pythoncode { def __nonzero__(self): return self.IsOk() }
663
664
665 // comparison
666 %extend {
667 bool __eq__(const wxFont* other) { return other ? (*self == *other) : false; }
668 bool __ne__(const wxFont* other) { return other ? (*self != *other) : true; }
669 }
670
671
672 DocDeclStr(
673 virtual int , GetPointSize() const,
674 "Gets the point size.", "");
675
676 DocDeclStr(
677 virtual wxSize , GetPixelSize() const,
678 "Returns the size in pixels if the font was constructed with a pixel
679 size.", "");
680
681 DocDeclStr(
682 virtual bool , IsUsingSizeInPixels() const,
683 "Returns ``True`` if the font is using a pixelSize.", "");
684
685
686 DocDeclStr(
687 virtual int , GetFamily() const,
688 "Gets the font family. ", "");
689
690 DocDeclStr(
691 virtual int , GetStyle() const,
692 "Gets the font style.", "");
693
694 DocDeclStr(
695 virtual int , GetWeight() const,
696 "Gets the font weight. ", "");
697
698 DocDeclStr(
699 virtual bool , GetUnderlined() const,
700 "Returns ``True`` if the font is underlined, ``False`` otherwise.", "");
701
702 DocDeclStr(
703 virtual wxString , GetFaceName() const,
704 "Returns the typeface name associated with the font, or the empty
705 string if there is no typeface information.", "");
706
707 DocDeclStr(
708 virtual wxFontEncoding , GetEncoding() const,
709 "Get the font's encoding.", "");
710
711 DocDeclStr(
712 virtual const wxNativeFontInfo *, GetNativeFontInfo() const,
713 "Constructs a `wx.NativeFontInfo` object from this font.", "");
714
715
716 DocDeclStr(
717 virtual bool , IsFixedWidth() const,
718 "Returns true if the font is a fixed width (or monospaced) font, false
719 if it is a proportional one or font is invalid.", "");
720
721
722 DocDeclStr(
723 wxString , GetNativeFontInfoDesc() const,
724 "Returns the platform-dependent string completely describing this font
725 or an empty string if the font isn't valid.", "");
726
727 DocDeclStr(
728 wxString , GetNativeFontInfoUserDesc() const,
729 "Returns a human readable version of `GetNativeFontInfoDesc`.", "");
730
731
732 // change the font characteristics
733 DocDeclStr(
734 virtual void , SetPointSize( int pointSize ),
735 "Sets the point size.", "");
736
737 DocDeclStr(
738 virtual void , SetPixelSize( const wxSize& pixelSize ),
739 "Sets the size in pixels rather than points. If there is platform API
740 support for this then it is used, otherwise a font with the closest
741 size is found using a binary search.", "");
742
743 DocDeclStr(
744 virtual void , SetFamily( int family ),
745 "Sets the font family.", "");
746
747 DocDeclStr(
748 virtual void , SetStyle( int style ),
749 "Sets the font style.", "");
750
751 DocDeclStr(
752 virtual void , SetWeight( int weight ),
753 "Sets the font weight.", "");
754
755 DocDeclStr(
756 virtual bool , SetFaceName( const wxString& faceName ),
757 "Sets the facename for the font. The facename, which should be a valid
758 font installed on the end-user's system.
759
760 To avoid portability problems, don't rely on a specific face, but
761 specify the font family instead or as well. A suitable font will be
762 found on the end-user's system. If both the family and the facename
763 are specified, wxWidgets will first search for the specific face, and
764 then for a font belonging to the same family.", "");
765
766 DocDeclStr(
767 virtual void , SetUnderlined( bool underlined ),
768 "Sets underlining.", "");
769
770 DocDeclStr(
771 virtual void , SetEncoding(wxFontEncoding encoding),
772 "Set the font encoding.", "");
773
774 DocDeclStr(
775 void , SetNativeFontInfo(const wxNativeFontInfo& info),
776 "Set the font's attributes from a `wx.NativeFontInfo` object.", "");
777
778
779 DocDeclStrName(
780 bool , SetNativeFontInfo(const wxString& info),
781 "Set the font's attributes from string representation of a
782 `wx.NativeFontInfo` object.", "",
783 SetNativeFontInfoFromString);
784
785 DocDeclStr(
786 bool , SetNativeFontInfoUserDesc(const wxString& info),
787 "Set the font's attributes from a string formerly returned from
788 `GetNativeFontInfoDesc`.", "");
789
790
791 DocDeclStr(
792 wxString , GetFamilyString() const,
793 "Returns a string representation of the font family.", "");
794
795 DocDeclStr(
796 wxString , GetStyleString() const,
797 "Returns a string representation of the font style.", "");
798
799 DocDeclStr(
800 wxString , GetWeightString() const,
801 "Return a string representation of the font weight.", "");
802
803
804 virtual void SetNoAntiAliasing( bool no = true );
805 virtual bool GetNoAntiAliasing() const;
806
807 // the default encoding is used for creating all fonts with default
808 // encoding parameter
809 DocDeclStr(
810 static wxFontEncoding , GetDefaultEncoding(),
811 "Returns the encoding used for all fonts created with an encoding of
812 ``wx.FONTENCODING_DEFAULT``.", "");
813
814 DocDeclStr(
815 static void , SetDefaultEncoding(wxFontEncoding encoding),
816 "Sets the default font encoding.", "");
817
818 %property(Encoding, GetEncoding, SetEncoding, doc="See `GetEncoding` and `SetEncoding`");
819 %property(FaceName, GetFaceName, SetFaceName, doc="See `GetFaceName` and `SetFaceName`");
820 %property(Family, GetFamily, SetFamily, doc="See `GetFamily` and `SetFamily`");
821 %property(FamilyString, GetFamilyString, doc="See `GetFamilyString`");
822 %property(NativeFontInfo, GetNativeFontInfo, SetNativeFontInfo, doc="See `GetNativeFontInfo` and `SetNativeFontInfo`");
823 %property(NativeFontInfoDesc, GetNativeFontInfoDesc, doc="See `GetNativeFontInfoDesc`");
824 %property(NativeFontInfoUserDesc, GetNativeFontInfoUserDesc, SetNativeFontInfoUserDesc, doc="See `GetNativeFontInfoUserDesc` and `SetNativeFontInfoUserDesc`");
825 %property(NoAntiAliasing, GetNoAntiAliasing, SetNoAntiAliasing, doc="See `GetNoAntiAliasing` and `SetNoAntiAliasing`");
826 %property(PixelSize, GetPixelSize, SetPixelSize, doc="See `GetPixelSize` and `SetPixelSize`");
827 %property(PointSize, GetPointSize, SetPointSize, doc="See `GetPointSize` and `SetPointSize`");
828 %property(Style, GetStyle, SetStyle, doc="See `GetStyle` and `SetStyle`");
829 %property(StyleString, GetStyleString, doc="See `GetStyleString`");
830 %property(Underlined, GetUnderlined, SetUnderlined, doc="See `GetUnderlined` and `SetUnderlined`");
831 %property(Weight, GetWeight, SetWeight, doc="See `GetWeight` and `SetWeight`");
832 %property(WeightString, GetWeightString, doc="See `GetWeightString`");
833
834 };
835
836 %pythoncode { Font2 = wx._deprecated(FFont, "Use `wx.FFont` instead.") }
837
838 //---------------------------------------------------------------------------
839 %newgroup
840
841 // wxFontEnumerator
842 %{
843 class wxPyFontEnumerator : public wxFontEnumerator {
844 public:
845 wxPyFontEnumerator() {}
846 ~wxPyFontEnumerator() {}
847
848 DEC_PYCALLBACK_BOOL_STRING(OnFacename);
849 DEC_PYCALLBACK_BOOL_STRINGSTRING(OnFontEncoding);
850
851 PYPRIVATE;
852 };
853
854 IMP_PYCALLBACK_BOOL_STRING(wxPyFontEnumerator, wxFontEnumerator, OnFacename);
855 IMP_PYCALLBACK_BOOL_STRINGSTRING(wxPyFontEnumerator, wxFontEnumerator, OnFontEncoding);
856
857 %}
858
859 MustHaveApp(wxPyFontEnumerator);
860
861 %rename(FontEnumerator) wxPyFontEnumerator;
862 class wxPyFontEnumerator {
863 public:
864 %pythonAppend wxPyFontEnumerator "self._setCallbackInfo(self, FontEnumerator, 0)"
865
866 wxPyFontEnumerator();
867 ~wxPyFontEnumerator();
868 void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref);
869
870 bool EnumerateFacenames(
871 wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all
872 bool fixedWidthOnly = false);
873
874 bool EnumerateEncodings(const wxString& facename = wxPyEmptyString);
875
876 %extend {
877 static PyObject* GetEncodings() {
878 PyObject* ret;
879 wxArrayString arr = wxFontEnumerator::GetEncodings();
880 wxPyBlock_t blocked = wxPyBeginBlockThreads();
881 ret = wxArrayString2PyList_helper(arr);
882 wxPyEndBlockThreads(blocked);
883 return ret;
884 }
885
886 static PyObject* GetFacenames() {
887 PyObject* ret;
888 wxArrayString arr = wxFontEnumerator::GetFacenames();
889 wxPyBlock_t blocked = wxPyBeginBlockThreads();
890 ret = wxArrayString2PyList_helper(arr);
891 wxPyEndBlockThreads(blocked);
892 return ret;
893 }
894 }
895
896 DocDeclStr(
897 static bool , IsValidFacename(const wxString &str),
898 "Convenience function that returns true if the given face name exist in
899 the user's system", "");
900
901 };
902
903
904
905 %init %{
906 wxPyPtrTypeMap_Add("wxFontEnumerator", "wxPyFontEnumerator");
907 %}
908
909 //---------------------------------------------------------------------------