]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_font.i
4166b3df39c42c565ff23058985405556598cc32
[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 void SetFaceName(wxString facename);
254 void SetFamily(wxFontFamily family);
255 void SetEncoding(wxFontEncoding encoding);
256
257 // it is important to be able to serialize wxNativeFontInfo objects to be
258 // able to store them (in config file, for example)
259 bool FromString(const wxString& s);
260 wxString ToString() const;
261
262 %extend {
263 wxString __str__() {
264 return self->ToString();
265 }
266 }
267
268 // we also want to present the native font descriptions to the user in some
269 // human-readable form (it is not platform independent neither, but can
270 // hopefully be understood by the user)
271 bool FromUserString(const wxString& s);
272 wxString ToUserString() const;
273 };
274
275
276
277
278 struct wxNativeEncodingInfo
279 {
280 wxString facename; // may be empty meaning "any"
281 wxFontEncoding encoding; // so that we know what this struct represents
282
283 wxNativeEncodingInfo();
284 ~wxNativeEncodingInfo();
285
286 // this struct is saved in config by wxFontMapper, so it should know to
287 // serialise itself (implemented in platform-specific code)
288 bool FromString(const wxString& s);
289 wxString ToString() const;
290 };
291
292
293 #ifndef __WXMSW__
294 // translate a wxFontEncoding into native encoding parameter (defined above),
295 // returning a wxNativeEncodingInfo if an (exact) match could be found, NULL
296 // otherwise.
297 %inline %{
298 wxNativeEncodingInfo* wxGetNativeFontEncoding(wxFontEncoding encoding) {
299 static wxNativeEncodingInfo info;
300 if ( wxGetNativeFontEncoding(encoding, &info) )
301 return &info;
302 else
303 return NULL;
304 }
305 %}
306
307 // test for the existence of the font described by this facename/encoding,
308 // return True if such font(s) exist, False otherwise
309 bool wxTestFontEncoding(const wxNativeEncodingInfo& info);
310
311 #else
312
313 %inline %{
314 wxNativeEncodingInfo* wxGetNativeFontEncoding(wxFontEncoding encoding)
315 { wxPyRaiseNotImplemented(); return NULL; }
316
317 bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
318 { wxPyRaiseNotImplemented(); return false; }
319 %}
320 #endif
321
322 //---------------------------------------------------------------------------
323 %newgroup
324
325 // wxFontMapper manages user-definable correspondence between logical font
326 // names and the fonts present on the machine.
327 //
328 // The default implementations of all functions will ask the user if they are
329 // not capable of finding the answer themselves and store the answer in a
330 // config file (configurable via SetConfigXXX functions). This behaviour may
331 // be disabled by giving the value of False to "interactive" parameter.
332 // However, the functions will always consult the config file to allow the
333 // user-defined values override the default logic and there is no way to
334 // disable this - which shouldn't be ever needed because if "interactive" was
335 // never True, the config file is never created anyhow.
336 //
337 // This is a singleton class, font mapper objects can only be accessed using
338 // wxFontMapper::Get().
339
340 class wxFontMapper
341 {
342 public:
343 wxFontMapper();
344 ~wxFontMapper();
345
346 // return instance of the wxFontMapper singleton
347 static wxFontMapper *Get();
348 // set the sigleton to 'mapper' instance and return previous one
349 static wxFontMapper *Set(wxFontMapper *mapper);
350
351
352 // returns the encoding for the given charset (in the form of RFC 2046) or
353 // wxFONTENCODING_SYSTEM if couldn't decode it
354 //
355 // interactive parameter is ignored in the base class, we behave as if it
356 // were always False
357 virtual wxFontEncoding CharsetToEncoding(const wxString& charset,
358 bool interactive = true);
359
360
361 // get the number of font encodings we know about
362 static size_t GetSupportedEncodingsCount();
363
364 // get the n-th supported encoding
365 static wxFontEncoding GetEncoding(size_t n);
366
367 // return internal string identifier for the encoding (see also
368 // GetEncodingDescription())
369 static wxString GetEncodingName(wxFontEncoding encoding);
370
371 // return user-readable string describing the given encoding
372 //
373 // NB: hard-coded now, but might change later (read it from config?)
374 static wxString GetEncodingDescription(wxFontEncoding encoding);
375
376 // find the encoding corresponding to the given name, inverse of
377 // GetEncodingName() and less general than CharsetToEncoding()
378 //
379 // returns wxFONTENCODING_MAX if the name is not a supported encoding
380 static wxFontEncoding GetEncodingFromName(const wxString& name);
381
382
383 // set the config object to use (may be NULL to use default)
384 void SetConfig(wxConfigBase *config);
385
386 // set the root config path to use (should be an absolute path)
387 void SetConfigPath(const wxString& prefix);
388
389 // return default config path
390 static const wxString GetDefaultConfigPath();
391
392
393
394 // Find an alternative for the given encoding (which is supposed to not be
395 // available on this system). If successful, returns the encoding otherwise
396 // returns None.
397 %extend {
398 PyObject* GetAltForEncoding(wxFontEncoding encoding,
399 const wxString& facename = wxPyEmptyString,
400 bool interactive = true) {
401 wxFontEncoding alt_enc;
402 if (self->GetAltForEncoding(encoding, &alt_enc, facename, interactive))
403 return PyInt_FromLong(alt_enc);
404 else {
405 Py_INCREF(Py_None);
406 return Py_None;
407 }
408 }
409 }
410
411
412 // checks whether given encoding is available in given face or not.
413 // If no facename is given (default), return true if it's available in any
414 // facename at all.
415 bool IsEncodingAvailable(wxFontEncoding encoding,
416 const wxString& facename = wxPyEmptyString);
417
418 // the parent window for modal dialogs
419 void SetDialogParent(wxWindow *parent);
420
421 // the title for the dialogs (note that default is quite reasonable)
422 void SetDialogTitle(const wxString& title);
423
424 };
425
426
427
428 //---------------------------------------------------------------------------
429 %newgroup
430
431
432 MustHaveApp(wxFont);
433 MustHaveApp(wxFont::GetDefaultEncoding);
434 MustHaveApp(wxFont::SetDefaultEncoding);
435
436 class wxFont : public wxGDIObject {
437 public:
438 %pythonPrepend wxFont "if kwargs.has_key('faceName'): kwargs['face'] = kwargs['faceName'];del kwargs['faceName']"
439
440 wxFont( int pointSize, int family, int style, int weight,
441 bool underline=false, const wxString& face = wxPyEmptyString,
442 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
443
444 ~wxFont();
445
446 %RenameCtor(FontFromNativeInfo, wxFont(const wxNativeFontInfo& info));
447 %extend {
448 %RenameCtor(FontFromNativeInfoString, wxFont(const wxString& info))
449 {
450 wxNativeFontInfo nfi;
451 nfi.FromString(info);
452 return new wxFont(nfi);
453 }
454
455 %RenameCtor(FFont, wxFont(int pointSize,
456 wxFontFamily family,
457 int flags = wxFONTFLAG_DEFAULT,
458 const wxString& face = wxPyEmptyString,
459 wxFontEncoding encoding = wxFONTENCODING_DEFAULT))
460 {
461 return wxFont::New(pointSize, family, flags, face, encoding);
462 }
463 }
464
465 // There is a real ctor for this on wxMSW, but not the others, so just use
466 // the factory function in all cases.
467 %extend {
468 %RenameCtor(FontFromPixelSize, wxFont(const wxSize& pixelSize,
469 int family,
470 int style,
471 int weight,
472 bool underlined = false,
473 const wxString& face = wxEmptyString,
474 wxFontEncoding encoding = wxFONTENCODING_DEFAULT))
475 {
476 return wxFontBase::New(pixelSize, family,
477 style, weight, underlined,
478 face, encoding);
479 }
480
481 %RenameCtor(FFontFromPixelSize, wxFont(const wxSize& pixelSize,
482 wxFontFamily family,
483 int flags = wxFONTFLAG_DEFAULT,
484 const wxString& face = wxEmptyString,
485 wxFontEncoding encoding = wxFONTENCODING_DEFAULT))
486 {
487 return wxFontBase::New(pixelSize, family, flags, face, encoding);
488 }
489 }
490
491
492
493 // was the font successfully created?
494 bool Ok() const;
495 %pythoncode { def __nonzero__(self): return self.Ok() }
496
497 // comparison
498 %extend {
499 bool __eq__(const wxFont* other) { return other ? (*self == *other) : false; }
500 bool __ne__(const wxFont* other) { return other ? (*self != *other) : true; }
501 }
502
503 // accessors: get the font characteristics
504 virtual int GetPointSize() const;
505 virtual wxSize GetPixelSize() const;
506 virtual bool IsUsingSizeInPixels() const;
507 virtual int GetFamily() const;
508 virtual int GetStyle() const;
509 virtual int GetWeight() const;
510 virtual bool GetUnderlined() const;
511 virtual wxString GetFaceName() const;
512 virtual wxFontEncoding GetEncoding() const;
513 virtual const wxNativeFontInfo *GetNativeFontInfo() const;
514
515 virtual bool IsFixedWidth() const;
516
517 wxString GetNativeFontInfoDesc() const;
518 wxString GetNativeFontInfoUserDesc() const;
519
520 // change the font characteristics
521 virtual void SetPointSize( int pointSize );
522 virtual void SetPixelSize( const wxSize& pixelSize );
523 virtual void SetFamily( int family );
524 virtual void SetStyle( int style );
525 virtual void SetWeight( int weight );
526 virtual void SetFaceName( const wxString& faceName );
527 virtual void SetUnderlined( bool underlined );
528 virtual void SetEncoding(wxFontEncoding encoding);
529 void SetNativeFontInfo(const wxNativeFontInfo& info);
530 %Rename(SetNativeFontInfoFromString, void, SetNativeFontInfo(const wxString& info));
531 void SetNativeFontInfoUserDesc(const wxString& info);
532
533 // translate the fonts into human-readable string (i.e. GetStyleString()
534 // will return "wxITALIC" for an italic font, ...)
535 wxString GetFamilyString() const;
536 wxString GetStyleString() const;
537 wxString GetWeightString() const;
538
539 // Unofficial API, don't use
540 virtual void SetNoAntiAliasing( bool no = true );
541 virtual bool GetNoAntiAliasing() const;
542
543 // the default encoding is used for creating all fonts with default
544 // encoding parameter
545 static wxFontEncoding GetDefaultEncoding() { return ms_encodingDefault; }
546 static void SetDefaultEncoding(wxFontEncoding encoding);
547 };
548
549 %pythoncode { Font2 = wx._deprecated(FFont, "Use `FFont` instead.") }
550
551 //---------------------------------------------------------------------------
552 %newgroup
553
554 // wxFontEnumerator
555 %{
556 class wxPyFontEnumerator : public wxFontEnumerator {
557 public:
558 wxPyFontEnumerator() {}
559 ~wxPyFontEnumerator() {}
560
561 DEC_PYCALLBACK_BOOL_STRING(OnFacename);
562 DEC_PYCALLBACK_BOOL_STRINGSTRING(OnFontEncoding);
563
564 PYPRIVATE;
565 };
566
567 IMP_PYCALLBACK_BOOL_STRING(wxPyFontEnumerator, wxFontEnumerator, OnFacename);
568 IMP_PYCALLBACK_BOOL_STRINGSTRING(wxPyFontEnumerator, wxFontEnumerator, OnFontEncoding);
569
570 %}
571
572 MustHaveApp(wxPyFontEnumerator);
573
574 %rename(FontEnumerator) wxPyFontEnumerator;
575 class wxPyFontEnumerator {
576 public:
577 %pythonAppend wxPyFontEnumerator "self._setCallbackInfo(self, FontEnumerator, 0)"
578
579 wxPyFontEnumerator();
580 ~wxPyFontEnumerator();
581 void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref);
582
583 bool EnumerateFacenames(
584 wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all
585 bool fixedWidthOnly = false);
586
587 bool EnumerateEncodings(const wxString& facename = wxPyEmptyString);
588
589 //wxArrayString* GetEncodings();
590 //wxArrayString* GetFacenames();
591 %extend {
592 PyObject* GetEncodings() {
593 wxArrayString* arr = self->GetEncodings();
594 if (arr)
595 return wxArrayString2PyList_helper(*arr);
596 else
597 return PyList_New(0);
598 }
599
600 PyObject* GetFacenames() {
601 wxArrayString* arr = self->GetFacenames();
602 if (arr)
603 return wxArrayString2PyList_helper(*arr);
604 else
605 return PyList_New(0);
606 }
607 }
608 };
609
610
611
612 %init %{
613 wxPyPtrTypeMap_Add("wxFontEnumerator", "wxPyFontEnumerator");
614 %}
615
616 //---------------------------------------------------------------------------