]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_font.i
Fixed SWIG warning
[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 = 0,
65
66 // slant flags (default: no slant)
67 wxFONTFLAG_ITALIC = 1 << 0,
68 wxFONTFLAG_SLANT = 1 << 1,
69
70 // weight flags (default: medium)
71 wxFONTFLAG_LIGHT = 1 << 2,
72 wxFONTFLAG_BOLD = 1 << 3,
73
74 // anti-aliasing flag: force on or off (default: the current system default)
75 wxFONTFLAG_ANTIALIASED = 1 << 4,
76 wxFONTFLAG_NOT_ANTIALIASED = 1 << 5,
77
78 // underlined/strikethrough flags (default: no lines)
79 wxFONTFLAG_UNDERLINED = 1 << 6,
80 wxFONTFLAG_STRIKETHROUGH = 1 << 7,
81
82 // the mask of all currently used flags
83 wxFONTFLAG_MASK = wxFONTFLAG_ITALIC |
84 wxFONTFLAG_SLANT |
85 wxFONTFLAG_LIGHT |
86 wxFONTFLAG_BOLD |
87 wxFONTFLAG_ANTIALIASED |
88 wxFONTFLAG_NOT_ANTIALIASED |
89 wxFONTFLAG_UNDERLINED |
90 wxFONTFLAG_STRIKETHROUGH
91 };
92
93
94 // font encodings
95 enum wxFontEncoding
96 {
97 wxFONTENCODING_SYSTEM = -1, // system default
98 wxFONTENCODING_DEFAULT, // current default encoding
99
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,
119
120 // Cyrillic charset soup (see http://czyborra.com/charsets/cyrillic.html)
121 wxFONTENCODING_KOI8, // we don't support any of KOI8 variants
122 wxFONTENCODING_ALTERNATIVE, // same as MS-DOS CP866
123 wxFONTENCODING_BULGARIAN, // used under Linux in Bulgaria
124
125 // what would we do without Microsoft? They have their own encodings
126 // for DOS
127 wxFONTENCODING_CP437, // original MS-DOS codepage
128 wxFONTENCODING_CP850, // CP437 merged with Latin1
129 wxFONTENCODING_CP852, // CP437 merged with Latin2
130 wxFONTENCODING_CP855, // another cyrillic encoding
131 wxFONTENCODING_CP866, // and another one
132 // and for Windows
133 wxFONTENCODING_CP874, // WinThai
134 wxFONTENCODING_CP932, // Japanese (shift-JIS)
135 wxFONTENCODING_CP936, // Chinese simplified (GB)
136 wxFONTENCODING_CP949, // Korean (Hangul charset)
137 wxFONTENCODING_CP950, // Chinese (traditional - Big5)
138 wxFONTENCODING_CP1250, // WinLatin2
139 wxFONTENCODING_CP1251, // WinCyrillic
140 wxFONTENCODING_CP1252, // WinLatin1
141 wxFONTENCODING_CP1253, // WinGreek (8859-7)
142 wxFONTENCODING_CP1254, // WinTurkish
143 wxFONTENCODING_CP1255, // WinHebrew
144 wxFONTENCODING_CP1256, // WinArabic
145 wxFONTENCODING_CP1257, // WinBaltic (same as Latin 7)
146 wxFONTENCODING_CP12_MAX,
147
148 wxFONTENCODING_UTF7, // UTF-7 Unicode encoding
149 wxFONTENCODING_UTF8, // UTF-8 Unicode encoding
150 wxFONTENCODING_EUC_JP, // Extended Unix Codepage for Japanese
151 wxFONTENCODING_UTF16BE, // UTF-16 Big Endian Unicode encoding
152 wxFONTENCODING_UTF16LE, // UTF-16 Little Endian Unicode encoding
153 wxFONTENCODING_UTF32BE, // UTF-32 Big Endian Unicode encoding
154 wxFONTENCODING_UTF32LE, // UTF-32 Little Endian Unicode encoding
155
156 wxFONTENCODING_MACROMAN, // Mac Roman encoding
157 wxFONTENCODING_MACCENTRALEUR, // Mac Roman Central Europe encoding
158 wxFONTENCODING_MACHEBREW, // Mac Hebrew encoding
159 wxFONTENCODING_MACGREEK, // Mac Greek encoding
160 wxFONTENCODING_MACARABIC, // Mac Arabic encoding
161 wxFONTENCODING_MACTURKISH, // Mac Turkish encoding
162 wxFONTENCODING_MACCYRILLIC, // Mac Cyrillic encoding
163
164 wxFONTENCODING_MAX, // highest enumerated encoding value
165
166
167 // aliases for endian-dependent UTF encodings
168 wxFONTENCODING_UTF16, // native UTF-16
169 wxFONTENCODING_UTF32, // native UTF-32
170
171 // alias for the native Unicode encoding on this platform
172 // (this is used by wxEncodingConverter and wxUTFFile only for now)
173 wxFONTENCODING_UNICODE = wxFONTENCODING_UTF16,
174
175 // alternative names for Far Eastern encodings
176 // Chinese
177 wxFONTENCODING_GB2312 = wxFONTENCODING_CP936, // Simplified Chinese
178 wxFONTENCODING_BIG5 = wxFONTENCODING_CP950, // Traditional Chinese
179
180 // Japanese (see http://zsigri.tripod.com/fontboard/cjk/jis.html)
181 wxFONTENCODING_SHIFT_JIS = wxFONTENCODING_CP932 // Shift JIS
182 };
183
184 //---------------------------------------------------------------------------
185 %newgroup
186
187 // wxNativeFontInfo is platform-specific font representation: this struct
188 // should be considered as opaque font description only used by the native
189 // functions, the user code can only get the objects of this type from
190 // somewhere and pass it somewhere else (possibly save them somewhere using
191 // ToString() and restore them using FromString())
192 struct wxNativeFontInfo
193 {
194 public:
195 wxNativeFontInfo();
196 ~wxNativeFontInfo();
197
198 // reset to the default state
199 void Init();
200
201 // init with the parameters of the given font
202 void InitFromFont(const wxFont& font);
203
204 // accessors and modifiers for the font elements
205 int GetPointSize() const;
206 wxFontStyle GetStyle() const;
207 wxFontWeight GetWeight() const;
208 bool GetUnderlined() const;
209 wxString GetFaceName() const;
210 wxFontFamily GetFamily() const;
211 wxFontEncoding GetEncoding() const;
212
213 void SetPointSize(int pointsize);
214 void SetStyle(wxFontStyle style);
215 void SetWeight(wxFontWeight weight);
216 void SetUnderlined(bool underlined);
217 void SetFaceName(wxString facename);
218 void SetFamily(wxFontFamily family);
219 void SetEncoding(wxFontEncoding encoding);
220
221 // it is important to be able to serialize wxNativeFontInfo objects to be
222 // able to store them (in config file, for example)
223 bool FromString(const wxString& s);
224 wxString ToString() const;
225
226 %extend {
227 wxString __str__() {
228 return self->ToString();
229 }
230 }
231
232 // we also want to present the native font descriptions to the user in some
233 // human-readable form (it is not platform independent neither, but can
234 // hopefully be understood by the user)
235 bool FromUserString(const wxString& s);
236 wxString ToUserString() const;
237 };
238
239
240
241
242 struct wxNativeEncodingInfo
243 {
244 wxString facename; // may be empty meaning "any"
245 wxFontEncoding encoding; // so that we know what this struct represents
246
247 wxNativeEncodingInfo();
248 ~wxNativeEncodingInfo();
249
250 // this struct is saved in config by wxFontMapper, so it should know to
251 // serialise itself (implemented in platform-specific code)
252 bool FromString(const wxString& s);
253 wxString ToString() const;
254 };
255
256
257 #ifndef __WXMSW__
258 // translate a wxFontEncoding into native encoding parameter (defined above),
259 // returning a wxNativeEncodingInfo if an (exact) match could be found, NULL
260 // otherwise.
261 %inline %{
262 wxNativeEncodingInfo* wxGetNativeFontEncoding(wxFontEncoding encoding) {
263 static wxNativeEncodingInfo info;
264 if ( wxGetNativeFontEncoding(encoding, &info) )
265 return &info;
266 else
267 return NULL;
268 }
269 %}
270
271 // test for the existence of the font described by this facename/encoding,
272 // return True if such font(s) exist, False otherwise
273 bool wxTestFontEncoding(const wxNativeEncodingInfo& info);
274
275 #else
276
277 %inline %{
278 wxNativeEncodingInfo* wxGetNativeFontEncoding(wxFontEncoding encoding)
279 { wxPyRaiseNotImplemented(); return NULL; }
280
281 bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
282 { wxPyRaiseNotImplemented(); return False; }
283 %}
284 #endif
285
286 //---------------------------------------------------------------------------
287 %newgroup
288
289 // wxFontMapper manages user-definable correspondence between logical font
290 // names and the fonts present on the machine.
291 //
292 // The default implementations of all functions will ask the user if they are
293 // not capable of finding the answer themselves and store the answer in a
294 // config file (configurable via SetConfigXXX functions). This behaviour may
295 // be disabled by giving the value of False to "interactive" parameter.
296 // However, the functions will always consult the config file to allow the
297 // user-defined values override the default logic and there is no way to
298 // disable this - which shouldn't be ever needed because if "interactive" was
299 // never True, the config file is never created anyhow.
300 //
301 // This is a singleton class, font mapper objects can only be accessed using
302 // wxFontMapper::Get().
303
304 class wxFontMapper
305 {
306 public:
307 wxFontMapper();
308 ~wxFontMapper();
309
310 // return instance of the wxFontMapper singleton
311 static wxFontMapper *Get();
312 // set the sigleton to 'mapper' instance and return previous one
313 static wxFontMapper *Set(wxFontMapper *mapper);
314
315
316 // returns the encoding for the given charset (in the form of RFC 2046) or
317 // wxFONTENCODING_SYSTEM if couldn't decode it
318 //
319 // interactive parameter is ignored in the base class, we behave as if it
320 // were always False
321 virtual wxFontEncoding CharsetToEncoding(const wxString& charset,
322 bool interactive = True);
323
324
325 // get the number of font encodings we know about
326 static size_t GetSupportedEncodingsCount();
327
328 // get the n-th supported encoding
329 static wxFontEncoding GetEncoding(size_t n);
330
331 // return internal string identifier for the encoding (see also
332 // GetEncodingDescription())
333 static wxString GetEncodingName(wxFontEncoding encoding);
334
335 // return user-readable string describing the given encoding
336 //
337 // NB: hard-coded now, but might change later (read it from config?)
338 static wxString GetEncodingDescription(wxFontEncoding encoding);
339
340
341 // set the config object to use (may be NULL to use default)
342 void SetConfig(wxConfigBase *config);
343
344 // set the root config path to use (should be an absolute path)
345 void SetConfigPath(const wxString& prefix);
346
347 // return default config path
348 static const wxString GetDefaultConfigPath();
349
350
351
352 // Find an alternative for the given encoding (which is supposed to not be
353 // available on this system). If successful, returns the encoding otherwise
354 // returns None.
355 %extend {
356 PyObject* GetAltForEncoding(wxFontEncoding encoding,
357 const wxString& facename = wxPyEmptyString,
358 bool interactive = True) {
359 wxFontEncoding alt_enc;
360 if (self->GetAltForEncoding(encoding, &alt_enc, facename, interactive))
361 return PyInt_FromLong(alt_enc);
362 else {
363 Py_INCREF(Py_None);
364 return Py_None;
365 }
366 }
367 }
368
369
370 // checks whether given encoding is available in given face or not.
371 // If no facename is given,
372 bool IsEncodingAvailable(wxFontEncoding encoding,
373 const wxString& facename = wxPyEmptyString);
374
375 // the parent window for modal dialogs
376 void SetDialogParent(wxWindow *parent);
377
378 // the title for the dialogs (note that default is quite reasonable)
379 void SetDialogTitle(const wxString& title);
380
381 };
382
383
384
385 //---------------------------------------------------------------------------
386 %newgroup
387
388
389 class wxFont : public wxGDIObject {
390 public:
391 wxFont( int pointSize, int family, int style, int weight,
392 bool underline=False, const wxString& face = wxPyEmptyString,
393 wxFontEncoding encoding=wxFONTENCODING_DEFAULT);
394 ~wxFont();
395
396 %name(FontFromNativeInfo) wxFont(const wxNativeFontInfo& info);
397 %extend {
398 %name(FontFromNativeInfoString) wxFont(const wxString& info) {
399 wxNativeFontInfo nfi;
400 nfi.FromString(info);
401 return new wxFont(nfi);
402 }
403
404 %name(Font2) wxFont(int pointSize,
405 wxFontFamily family,
406 int flags = wxFONTFLAG_DEFAULT,
407 const wxString& face = wxPyEmptyString,
408 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) {
409 return wxFont::New(pointSize, family, flags, face, encoding);
410 }
411 }
412
413
414 // was the font successfully created?
415 bool Ok() const;
416 %pythoncode { def __nonzero__(self): return self.Ok() }
417
418 // comparison
419 bool operator == (const wxFont& font) const;
420 bool operator != (const wxFont& font) const;
421
422 // accessors: get the font characteristics
423 virtual int GetPointSize() const;
424 virtual int GetFamily() const;
425 virtual int GetStyle() const;
426 virtual int GetWeight() const;
427 virtual bool GetUnderlined() const;
428 virtual wxString GetFaceName() const;
429 virtual wxFontEncoding GetEncoding() const;
430 virtual const wxNativeFontInfo *GetNativeFontInfo() const;
431
432 virtual bool IsFixedWidth() const;
433
434 wxString GetNativeFontInfoDesc() const;
435 wxString GetNativeFontInfoUserDesc() const;
436
437 // change the font characteristics
438 virtual void SetPointSize( int pointSize );
439 virtual void SetFamily( int family );
440 virtual void SetStyle( int style );
441 virtual void SetWeight( int weight );
442 virtual void SetFaceName( const wxString& faceName );
443 virtual void SetUnderlined( bool underlined );
444 virtual void SetEncoding(wxFontEncoding encoding);
445 void SetNativeFontInfo(const wxNativeFontInfo& info);
446 %name(SetNativeFontInfoFromString) void SetNativeFontInfo(const wxString& info);
447 void SetNativeFontInfoUserDesc(const wxString& info);
448
449 // translate the fonts into human-readable string (i.e. GetStyleString()
450 // will return "wxITALIC" for an italic font, ...)
451 wxString GetFamilyString() const;
452 wxString GetStyleString() const;
453 wxString GetWeightString() const;
454
455 // Unofficial API, don't use
456 virtual void SetNoAntiAliasing( bool no = True );
457 virtual bool GetNoAntiAliasing();
458
459 // the default encoding is used for creating all fonts with default
460 // encoding parameter
461 static wxFontEncoding GetDefaultEncoding() { return ms_encodingDefault; }
462 static void SetDefaultEncoding(wxFontEncoding encoding);
463 };
464
465
466
467 //---------------------------------------------------------------------------
468 %newgroup
469
470 // wxFontEnumerator
471 %{
472 class wxPyFontEnumerator : public wxFontEnumerator {
473 public:
474 wxPyFontEnumerator() {}
475 ~wxPyFontEnumerator() {}
476
477 DEC_PYCALLBACK_BOOL_STRING(OnFacename);
478 DEC_PYCALLBACK_BOOL_STRINGSTRING(OnFontEncoding);
479
480 PYPRIVATE;
481 };
482
483 IMP_PYCALLBACK_BOOL_STRING(wxPyFontEnumerator, wxFontEnumerator, OnFacename);
484 IMP_PYCALLBACK_BOOL_STRINGSTRING(wxPyFontEnumerator, wxFontEnumerator, OnFontEncoding);
485
486 %}
487
488 %name(FontEnumerator) class wxPyFontEnumerator {
489 public:
490 %addtofunc wxPyFontEnumerator "self._setCallbackInfo(self, FontEnumerator, 0)"
491
492 wxPyFontEnumerator();
493 ~wxPyFontEnumerator();
494 void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref);
495
496 bool EnumerateFacenames(
497 wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all
498 bool fixedWidthOnly = False);
499
500 bool EnumerateEncodings(const wxString& facename = wxPyEmptyString);
501
502 //wxArrayString* GetEncodings();
503 //wxArrayString* GetFacenames();
504 %extend {
505 PyObject* GetEncodings() {
506 wxArrayString* arr = self->GetEncodings();
507 return wxArrayString2PyList_helper(*arr);
508 }
509
510 PyObject* GetFacenames() {
511 wxArrayString* arr = self->GetFacenames();
512 return wxArrayString2PyList_helper(*arr);
513 }
514 }
515 };
516
517
518
519 %init %{
520 wxPyPtrTypeMap_Add("wxFontEnumerator", "wxPyFontEnumerator");
521 %}
522
523 //---------------------------------------------------------------------------