1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface file for wxFont and related classes
9 // Copyright: (c) 2002 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
19 #include <wx/fontutil.h>
20 #include <wx/fontmap.h>
21 #include <wx/fontenum.h>
24 //---------------------------------------------------------------------------
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,
38 wxFONTFAMILY_UNKNOWN = wxFONTFAMILY_MAX
44 wxFONTSTYLE_NORMAL = wxNORMAL,
45 wxFONTSTYLE_ITALIC = wxITALIC,
46 wxFONTSTYLE_SLANT = wxSLANT,
53 wxFONTWEIGHT_NORMAL = wxNORMAL,
54 wxFONTWEIGHT_LIGHT = wxLIGHT,
55 wxFONTWEIGHT_BOLD = wxBOLD,
60 // the font flag bits for the new font ctor accepting one combined flags word
63 // no special flags: font with default weight/slant/anti-aliasing
64 wxFONTFLAG_DEFAULT = 0,
66 // slant flags (default: no slant)
67 wxFONTFLAG_ITALIC = 1 << 0,
68 wxFONTFLAG_SLANT = 1 << 1,
70 // weight flags (default: medium)
71 wxFONTFLAG_LIGHT = 1 << 2,
72 wxFONTFLAG_BOLD = 1 << 3,
74 // anti-aliasing flag: force on or off (default: the current system default)
75 wxFONTFLAG_ANTIALIASED = 1 << 4,
76 wxFONTFLAG_NOT_ANTIALIASED = 1 << 5,
78 // underlined/strikethrough flags (default: no lines)
79 wxFONTFLAG_UNDERLINED = 1 << 6,
80 wxFONTFLAG_STRIKETHROUGH = 1 << 7,
82 // the mask of all currently used flags
83 wxFONTFLAG_MASK = wxFONTFLAG_ITALIC |
87 wxFONTFLAG_ANTIALIASED |
88 wxFONTFLAG_NOT_ANTIALIASED |
89 wxFONTFLAG_UNDERLINED |
90 wxFONTFLAG_STRIKETHROUGH
97 wxFONTENCODING_SYSTEM = -1, // system default
98 wxFONTENCODING_DEFAULT, // current default encoding
100 // ISO8859 standard defines a number of single-byte charsets
101 wxFONTENCODING_ISO8859_1, // West European (Latin1)
102 wxFONTENCODING_ISO8859_2, // Central and East European (Latin2)
103 wxFONTENCODING_ISO8859_3, // Esperanto (Latin3)
104 wxFONTENCODING_ISO8859_4, // Baltic (old) (Latin4)
105 wxFONTENCODING_ISO8859_5, // Cyrillic
106 wxFONTENCODING_ISO8859_6, // Arabic
107 wxFONTENCODING_ISO8859_7, // Greek
108 wxFONTENCODING_ISO8859_8, // Hebrew
109 wxFONTENCODING_ISO8859_9, // Turkish (Latin5)
110 wxFONTENCODING_ISO8859_10, // Variation of Latin4 (Latin6)
111 wxFONTENCODING_ISO8859_11, // Thai
112 wxFONTENCODING_ISO8859_12, // doesn't exist currently, but put it
113 // here anyhow to make all ISO8859
114 // consecutive numbers
115 wxFONTENCODING_ISO8859_13, // Baltic (Latin7)
116 wxFONTENCODING_ISO8859_14, // Latin8
117 wxFONTENCODING_ISO8859_15, // Latin9 (a.k.a. Latin0, includes euro)
118 wxFONTENCODING_ISO8859_MAX,
120 // Cyrillic charset soup (see http://czyborra.com/charsets/cyrillic.html)
121 wxFONTENCODING_KOI8, // KOI8 Russian
122 wxFONTENCODING_KOI8_U, // KOI8 Ukrainian
123 wxFONTENCODING_ALTERNATIVE, // same as MS-DOS CP866
124 wxFONTENCODING_BULGARIAN, // used under Linux in Bulgaria
126 // what would we do without Microsoft? They have their own encodings
128 wxFONTENCODING_CP437, // original MS-DOS codepage
129 wxFONTENCODING_CP850, // CP437 merged with Latin1
130 wxFONTENCODING_CP852, // CP437 merged with Latin2
131 wxFONTENCODING_CP855, // another cyrillic encoding
132 wxFONTENCODING_CP866, // and another one
134 wxFONTENCODING_CP874, // WinThai
135 wxFONTENCODING_CP932, // Japanese (shift-JIS)
136 wxFONTENCODING_CP936, // Chinese simplified (GB)
137 wxFONTENCODING_CP949, // Korean (Hangul charset)
138 wxFONTENCODING_CP950, // Chinese (traditional - Big5)
139 wxFONTENCODING_CP1250, // WinLatin2
140 wxFONTENCODING_CP1251, // WinCyrillic
141 wxFONTENCODING_CP1252, // WinLatin1
142 wxFONTENCODING_CP1253, // WinGreek (8859-7)
143 wxFONTENCODING_CP1254, // WinTurkish
144 wxFONTENCODING_CP1255, // WinHebrew
145 wxFONTENCODING_CP1256, // WinArabic
146 wxFONTENCODING_CP1257, // WinBaltic (same as Latin 7)
147 wxFONTENCODING_CP12_MAX,
149 wxFONTENCODING_UTF7, // UTF-7 Unicode encoding
150 wxFONTENCODING_UTF8, // UTF-8 Unicode encoding
151 wxFONTENCODING_EUC_JP, // Extended Unix Codepage for Japanese
152 wxFONTENCODING_UTF16BE, // UTF-16 Big Endian Unicode encoding
153 wxFONTENCODING_UTF16LE, // UTF-16 Little Endian Unicode encoding
154 wxFONTENCODING_UTF32BE, // UTF-32 Big Endian Unicode encoding
155 wxFONTENCODING_UTF32LE, // UTF-32 Little Endian Unicode encoding
157 wxFONTENCODING_MACROMAN, // the standard mac encodings
158 wxFONTENCODING_MACJAPANESE,
159 wxFONTENCODING_MACCHINESETRAD,
160 wxFONTENCODING_MACKOREAN,
161 wxFONTENCODING_MACARABIC,
162 wxFONTENCODING_MACHEBREW,
163 wxFONTENCODING_MACGREEK,
164 wxFONTENCODING_MACCYRILLIC,
165 wxFONTENCODING_MACDEVANAGARI,
166 wxFONTENCODING_MACGURMUKHI,
167 wxFONTENCODING_MACGUJARATI,
168 wxFONTENCODING_MACORIYA,
169 wxFONTENCODING_MACBENGALI,
170 wxFONTENCODING_MACTAMIL,
171 wxFONTENCODING_MACTELUGU,
172 wxFONTENCODING_MACKANNADA,
173 wxFONTENCODING_MACMALAJALAM,
174 wxFONTENCODING_MACSINHALESE,
175 wxFONTENCODING_MACBURMESE,
176 wxFONTENCODING_MACKHMER,
177 wxFONTENCODING_MACTHAI,
178 wxFONTENCODING_MACLAOTIAN,
179 wxFONTENCODING_MACGEORGIAN,
180 wxFONTENCODING_MACARMENIAN,
181 wxFONTENCODING_MACCHINESESIMP,
182 wxFONTENCODING_MACTIBETAN,
183 wxFONTENCODING_MACMONGOLIAN,
184 wxFONTENCODING_MACETHIOPIC,
185 wxFONTENCODING_MACCENTRALEUR,
186 wxFONTENCODING_MACVIATNAMESE,
187 wxFONTENCODING_MACARABICEXT,
188 wxFONTENCODING_MACSYMBOL,
189 wxFONTENCODING_MACDINGBATS,
190 wxFONTENCODING_MACTURKISH,
191 wxFONTENCODING_MACCROATIAN,
192 wxFONTENCODING_MACICELANDIC,
193 wxFONTENCODING_MACROMANIAN,
194 wxFONTENCODING_MACCELTIC,
195 wxFONTENCODING_MACGAELIC,
196 wxFONTENCODING_MACKEYBOARD,
198 wxFONTENCODING_MACMIN = wxFONTENCODING_MACROMAN ,
199 wxFONTENCODING_MACMAX = wxFONTENCODING_MACKEYBOARD ,
201 wxFONTENCODING_MAX, // highest enumerated encoding value
204 // aliases for endian-dependent UTF encodings
205 wxFONTENCODING_UTF16, // native UTF-16
206 wxFONTENCODING_UTF32, // native UTF-32
208 // alias for the native Unicode encoding on this platform
209 // (this is used by wxEncodingConverter and wxUTFFile only for now)
210 wxFONTENCODING_UNICODE = wxFONTENCODING_UTF16,
212 // alternative names for Far Eastern encodings
214 wxFONTENCODING_GB2312 = wxFONTENCODING_CP936, // Simplified Chinese
215 wxFONTENCODING_BIG5 = wxFONTENCODING_CP950, // Traditional Chinese
217 // Japanese (see http://zsigri.tripod.com/fontboard/cjk/jis.html)
218 wxFONTENCODING_SHIFT_JIS = wxFONTENCODING_CP932 // Shift JIS
221 //---------------------------------------------------------------------------
224 // wxNativeFontInfo is platform-specific font representation: this struct
225 // should be considered as opaque font description only used by the native
226 // functions, the user code can only get the objects of this type from
227 // somewhere and pass it somewhere else (possibly save them somewhere using
228 // ToString() and restore them using FromString())
229 struct wxNativeFontInfo
235 // reset to the default state
238 // init with the parameters of the given font
239 void InitFromFont(const wxFont& font);
241 // accessors and modifiers for the font elements
242 int GetPointSize() const;
244 wxSize GetPixelSize() const;
246 wxFontStyle GetStyle() const;
247 wxFontWeight GetWeight() const;
248 bool GetUnderlined() const;
249 wxString GetFaceName() const;
250 wxFontFamily GetFamily() const;
251 wxFontEncoding GetEncoding() const;
253 void SetPointSize(int pointsize);
255 void SetPixelSize(const wxSize& pixelSize);
257 void SetStyle(wxFontStyle style);
258 void SetWeight(wxFontWeight weight);
259 void SetUnderlined(bool underlined);
260 void SetFaceName(wxString facename);
261 void SetFamily(wxFontFamily family);
262 void SetEncoding(wxFontEncoding encoding);
264 // it is important to be able to serialize wxNativeFontInfo objects to be
265 // able to store them (in config file, for example)
266 bool FromString(const wxString& s);
267 wxString ToString() const;
271 return self->ToString();
275 // we also want to present the native font descriptions to the user in some
276 // human-readable form (it is not platform independent neither, but can
277 // hopefully be understood by the user)
278 bool FromUserString(const wxString& s);
279 wxString ToUserString() const;
285 struct wxNativeEncodingInfo
287 wxString facename; // may be empty meaning "any"
288 wxFontEncoding encoding; // so that we know what this struct represents
290 wxNativeEncodingInfo();
291 ~wxNativeEncodingInfo();
293 // this struct is saved in config by wxFontMapper, so it should know to
294 // serialise itself (implemented in platform-specific code)
295 bool FromString(const wxString& s);
296 wxString ToString() const;
301 // translate a wxFontEncoding into native encoding parameter (defined above),
302 // returning a wxNativeEncodingInfo if an (exact) match could be found, NULL
305 wxNativeEncodingInfo* wxGetNativeFontEncoding(wxFontEncoding encoding) {
306 static wxNativeEncodingInfo info;
307 if ( wxGetNativeFontEncoding(encoding, &info) )
314 // test for the existence of the font described by this facename/encoding,
315 // return True if such font(s) exist, False otherwise
316 bool wxTestFontEncoding(const wxNativeEncodingInfo& info);
321 wxNativeEncodingInfo* wxGetNativeFontEncoding(wxFontEncoding encoding)
322 { wxPyRaiseNotImplemented(); return NULL; }
324 bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
325 { wxPyRaiseNotImplemented(); return false; }
329 //---------------------------------------------------------------------------
332 // wxFontMapper manages user-definable correspondence between logical font
333 // names and the fonts present on the machine.
335 // The default implementations of all functions will ask the user if they are
336 // not capable of finding the answer themselves and store the answer in a
337 // config file (configurable via SetConfigXXX functions). This behaviour may
338 // be disabled by giving the value of False to "interactive" parameter.
339 // However, the functions will always consult the config file to allow the
340 // user-defined values override the default logic and there is no way to
341 // disable this - which shouldn't be ever needed because if "interactive" was
342 // never True, the config file is never created anyhow.
344 // This is a singleton class, font mapper objects can only be accessed using
345 // wxFontMapper::Get().
353 // return instance of the wxFontMapper singleton
354 static wxFontMapper *Get();
355 // set the sigleton to 'mapper' instance and return previous one
356 static wxFontMapper *Set(wxFontMapper *mapper);
359 // returns the encoding for the given charset (in the form of RFC 2046) or
360 // wxFONTENCODING_SYSTEM if couldn't decode it
362 // interactive parameter is ignored in the base class, we behave as if it
364 virtual wxFontEncoding CharsetToEncoding(const wxString& charset,
365 bool interactive = true);
368 // get the number of font encodings we know about
369 static size_t GetSupportedEncodingsCount();
371 // get the n-th supported encoding
372 static wxFontEncoding GetEncoding(size_t n);
374 // return internal string identifier for the encoding (see also
375 // GetEncodingDescription())
376 static wxString GetEncodingName(wxFontEncoding encoding);
378 // return user-readable string describing the given encoding
380 // NB: hard-coded now, but might change later (read it from config?)
381 static wxString GetEncodingDescription(wxFontEncoding encoding);
383 // find the encoding corresponding to the given name, inverse of
384 // GetEncodingName() and less general than CharsetToEncoding()
386 // returns wxFONTENCODING_MAX if the name is not a supported encoding
387 static wxFontEncoding GetEncodingFromName(const wxString& name);
390 // set the config object to use (may be NULL to use default)
391 void SetConfig(wxConfigBase *config);
393 // set the root config path to use (should be an absolute path)
394 void SetConfigPath(const wxString& prefix);
396 // return default config path
397 static const wxString GetDefaultConfigPath();
401 // Find an alternative for the given encoding (which is supposed to not be
402 // available on this system). If successful, returns the encoding otherwise
405 PyObject* GetAltForEncoding(wxFontEncoding encoding,
406 const wxString& facename = wxPyEmptyString,
407 bool interactive = true) {
408 wxFontEncoding alt_enc;
409 if (self->GetAltForEncoding(encoding, &alt_enc, facename, interactive))
410 return PyInt_FromLong(alt_enc);
419 // checks whether given encoding is available in given face or not.
420 // If no facename is given (default), return true if it's available in any
422 bool IsEncodingAvailable(wxFontEncoding encoding,
423 const wxString& facename = wxPyEmptyString);
425 // the parent window for modal dialogs
426 void SetDialogParent(wxWindow *parent);
428 // the title for the dialogs (note that default is quite reasonable)
429 void SetDialogTitle(const wxString& title);
435 //---------------------------------------------------------------------------
440 MustHaveApp(wxFont::GetDefaultEncoding);
441 MustHaveApp(wxFont::SetDefaultEncoding);
443 class wxFont : public wxGDIObject {
445 %pythonPrepend wxFont "if kwargs.has_key('faceName'): kwargs['face'] = kwargs['faceName'];del kwargs['faceName']"
447 wxFont( int pointSize, int family, int style, int weight,
448 bool underline=false, const wxString& face = wxPyEmptyString,
449 wxFontEncoding encoding=wxFONTENCODING_DEFAULT);
452 %name(FontFromNativeInfo) wxFont(const wxNativeFontInfo& info);
454 %name(FontFromNativeInfoString) wxFont(const wxString& info) {
455 wxNativeFontInfo nfi;
456 nfi.FromString(info);
457 return new wxFont(nfi);
460 %name(Font2) wxFont(int pointSize,
462 int flags = wxFONTFLAG_DEFAULT,
463 const wxString& face = wxPyEmptyString,
464 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) {
465 return wxFont::New(pointSize, family, flags, face, encoding);
469 // There is a real ctor for this on wxMSW, but not the others, so just use
470 // the factory funciton in all cases.
472 %name(FontFromPixelSize) wxFont(const wxSize& pixelSize,
476 bool underlined = false,
477 const wxString& face = wxEmptyString,
478 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) {
479 return wxFontBase::New(pixelSize, family,
480 style, weight, underlined,
487 // was the font successfully created?
489 %pythoncode { def __nonzero__(self): return self.Ok() }
493 bool __eq__(const wxFont* other) { return other ? (*self == *other) : false; }
494 bool __ne__(const wxFont* other) { return other ? (*self != *other) : true; }
497 // accessors: get the font characteristics
498 virtual int GetPointSize() const;
499 virtual wxSize GetPixelSize() const;
500 virtual bool IsUsingSizeInPixels() const;
501 virtual int GetFamily() const;
502 virtual int GetStyle() const;
503 virtual int GetWeight() const;
504 virtual bool GetUnderlined() const;
505 virtual wxString GetFaceName() const;
506 virtual wxFontEncoding GetEncoding() const;
507 virtual const wxNativeFontInfo *GetNativeFontInfo() const;
509 virtual bool IsFixedWidth() const;
511 wxString GetNativeFontInfoDesc() const;
512 wxString GetNativeFontInfoUserDesc() const;
514 // change the font characteristics
515 virtual void SetPointSize( int pointSize );
516 virtual void SetPixelSize( const wxSize& pixelSize );
517 virtual void SetFamily( int family );
518 virtual void SetStyle( int style );
519 virtual void SetWeight( int weight );
520 virtual void SetFaceName( const wxString& faceName );
521 virtual void SetUnderlined( bool underlined );
522 virtual void SetEncoding(wxFontEncoding encoding);
523 void SetNativeFontInfo(const wxNativeFontInfo& info);
524 %name(SetNativeFontInfoFromString) void SetNativeFontInfo(const wxString& info);
525 void SetNativeFontInfoUserDesc(const wxString& info);
527 // translate the fonts into human-readable string (i.e. GetStyleString()
528 // will return "wxITALIC" for an italic font, ...)
529 wxString GetFamilyString() const;
530 wxString GetStyleString() const;
531 wxString GetWeightString() const;
533 // Unofficial API, don't use
534 virtual void SetNoAntiAliasing( bool no = true );
535 virtual bool GetNoAntiAliasing() const;
537 // the default encoding is used for creating all fonts with default
538 // encoding parameter
539 static wxFontEncoding GetDefaultEncoding() { return ms_encodingDefault; }
540 static void SetDefaultEncoding(wxFontEncoding encoding);
545 //---------------------------------------------------------------------------
550 class wxPyFontEnumerator : public wxFontEnumerator {
552 wxPyFontEnumerator() {}
553 ~wxPyFontEnumerator() {}
555 DEC_PYCALLBACK_BOOL_STRING(OnFacename);
556 DEC_PYCALLBACK_BOOL_STRINGSTRING(OnFontEncoding);
561 IMP_PYCALLBACK_BOOL_STRING(wxPyFontEnumerator, wxFontEnumerator, OnFacename);
562 IMP_PYCALLBACK_BOOL_STRINGSTRING(wxPyFontEnumerator, wxFontEnumerator, OnFontEncoding);
566 MustHaveApp(wxPyFontEnumerator);
568 %name(FontEnumerator) class wxPyFontEnumerator {
570 %pythonAppend wxPyFontEnumerator "self._setCallbackInfo(self, FontEnumerator, 0)"
572 wxPyFontEnumerator();
573 ~wxPyFontEnumerator();
574 void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref);
576 bool EnumerateFacenames(
577 wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all
578 bool fixedWidthOnly = false);
580 bool EnumerateEncodings(const wxString& facename = wxPyEmptyString);
582 //wxArrayString* GetEncodings();
583 //wxArrayString* GetFacenames();
585 PyObject* GetEncodings() {
586 wxArrayString* arr = self->GetEncodings();
588 return wxArrayString2PyList_helper(*arr);
590 return PyList_New(0);
593 PyObject* GetFacenames() {
594 wxArrayString* arr = self->GetFacenames();
596 return wxArrayString2PyList_helper(*arr);
598 return PyList_New(0);
606 wxPyPtrTypeMap_Add("wxFontEnumerator", "wxPyFontEnumerator");
609 //---------------------------------------------------------------------------