]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_font.i
Force the output window to display at the begining of the app
[wxWidgets.git] / wxPython / src / _font.i
CommitLineData
d14a1e28
RD
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
28enum 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
42enum wxFontStyle
43{
44 wxFONTSTYLE_NORMAL = wxNORMAL,
45 wxFONTSTYLE_ITALIC = wxITALIC,
46 wxFONTSTYLE_SLANT = wxSLANT,
47 wxFONTSTYLE_MAX
48};
49
50// font weights
51enum 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
61enum
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
95enum 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)
56e63286
RD
121 wxFONTENCODING_KOI8, // KOI8 Russian
122 wxFONTENCODING_KOI8_U, // KOI8 Ukrainian
d14a1e28
RD
123 wxFONTENCODING_ALTERNATIVE, // same as MS-DOS CP866
124 wxFONTENCODING_BULGARIAN, // used under Linux in Bulgaria
125
126 // what would we do without Microsoft? They have their own encodings
127 // for DOS
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
133 // and for Windows
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,
148
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
156
9cca52ba
RD
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,
197
198 wxFONTENCODING_MACMIN = wxFONTENCODING_MACROMAN ,
199 wxFONTENCODING_MACMAX = wxFONTENCODING_MACKEYBOARD ,
f0cd63d2 200
d14a1e28
RD
201 wxFONTENCODING_MAX, // highest enumerated encoding value
202
203
204 // aliases for endian-dependent UTF encodings
205 wxFONTENCODING_UTF16, // native UTF-16
206 wxFONTENCODING_UTF32, // native UTF-32
207
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,
211
212 // alternative names for Far Eastern encodings
213 // Chinese
214 wxFONTENCODING_GB2312 = wxFONTENCODING_CP936, // Simplified Chinese
215 wxFONTENCODING_BIG5 = wxFONTENCODING_CP950, // Traditional Chinese
216
217 // Japanese (see http://zsigri.tripod.com/fontboard/cjk/jis.html)
218 wxFONTENCODING_SHIFT_JIS = wxFONTENCODING_CP932 // Shift JIS
219};
220
221//---------------------------------------------------------------------------
222%newgroup
223
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())
229struct wxNativeFontInfo
230{
231public:
232 wxNativeFontInfo();
233 ~wxNativeFontInfo();
234
235 // reset to the default state
236 void Init();
237
238 // init with the parameters of the given font
239 void InitFromFont(const wxFont& font);
240
241 // accessors and modifiers for the font elements
242 int GetPointSize() const;
243 wxFontStyle GetStyle() const;
244 wxFontWeight GetWeight() const;
245 bool GetUnderlined() const;
246 wxString GetFaceName() const;
247 wxFontFamily GetFamily() const;
248 wxFontEncoding GetEncoding() const;
249
250 void SetPointSize(int pointsize);
251 void SetStyle(wxFontStyle style);
252 void SetWeight(wxFontWeight weight);
253 void SetUnderlined(bool underlined);
254 void SetFaceName(wxString facename);
255 void SetFamily(wxFontFamily family);
256 void SetEncoding(wxFontEncoding encoding);
257
258 // it is important to be able to serialize wxNativeFontInfo objects to be
259 // able to store them (in config file, for example)
260 bool FromString(const wxString& s);
261 wxString ToString() const;
262
263 %extend {
264 wxString __str__() {
265 return self->ToString();
266 }
267 }
268
269 // we also want to present the native font descriptions to the user in some
270 // human-readable form (it is not platform independent neither, but can
271 // hopefully be understood by the user)
272 bool FromUserString(const wxString& s);
273 wxString ToUserString() const;
274};
275
276
277
278
279struct wxNativeEncodingInfo
280{
281 wxString facename; // may be empty meaning "any"
282 wxFontEncoding encoding; // so that we know what this struct represents
283
284 wxNativeEncodingInfo();
285 ~wxNativeEncodingInfo();
286
287 // this struct is saved in config by wxFontMapper, so it should know to
288 // serialise itself (implemented in platform-specific code)
289 bool FromString(const wxString& s);
290 wxString ToString() const;
291};
292
293
294#ifndef __WXMSW__
295// translate a wxFontEncoding into native encoding parameter (defined above),
296// returning a wxNativeEncodingInfo if an (exact) match could be found, NULL
297// otherwise.
298%inline %{
299 wxNativeEncodingInfo* wxGetNativeFontEncoding(wxFontEncoding encoding) {
300 static wxNativeEncodingInfo info;
301 if ( wxGetNativeFontEncoding(encoding, &info) )
302 return &info;
303 else
304 return NULL;
305 }
306%}
307
308// test for the existence of the font described by this facename/encoding,
dd9f7fea 309// return True if such font(s) exist, False otherwise
d14a1e28
RD
310bool wxTestFontEncoding(const wxNativeEncodingInfo& info);
311
312#else
313
314%inline %{
315 wxNativeEncodingInfo* wxGetNativeFontEncoding(wxFontEncoding encoding)
81cfe5e1 316 { wxPyRaiseNotImplemented(); return NULL; }
d14a1e28
RD
317
318 bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
a72f4631 319 { wxPyRaiseNotImplemented(); return false; }
d14a1e28
RD
320%}
321#endif
322
323//---------------------------------------------------------------------------
324%newgroup
325
326// wxFontMapper manages user-definable correspondence between logical font
327// names and the fonts present on the machine.
328//
329// The default implementations of all functions will ask the user if they are
330// not capable of finding the answer themselves and store the answer in a
331// config file (configurable via SetConfigXXX functions). This behaviour may
dd9f7fea 332// be disabled by giving the value of False to "interactive" parameter.
d14a1e28
RD
333// However, the functions will always consult the config file to allow the
334// user-defined values override the default logic and there is no way to
335// disable this - which shouldn't be ever needed because if "interactive" was
dd9f7fea 336// never True, the config file is never created anyhow.
d14a1e28
RD
337//
338// This is a singleton class, font mapper objects can only be accessed using
339// wxFontMapper::Get().
340
341class wxFontMapper
342{
343public:
344 wxFontMapper();
345 ~wxFontMapper();
346
347 // return instance of the wxFontMapper singleton
348 static wxFontMapper *Get();
349 // set the sigleton to 'mapper' instance and return previous one
350 static wxFontMapper *Set(wxFontMapper *mapper);
351
352
353 // returns the encoding for the given charset (in the form of RFC 2046) or
354 // wxFONTENCODING_SYSTEM if couldn't decode it
355 //
356 // interactive parameter is ignored in the base class, we behave as if it
dd9f7fea 357 // were always False
d14a1e28 358 virtual wxFontEncoding CharsetToEncoding(const wxString& charset,
a72f4631 359 bool interactive = true);
d14a1e28
RD
360
361
362 // get the number of font encodings we know about
363 static size_t GetSupportedEncodingsCount();
364
365 // get the n-th supported encoding
366 static wxFontEncoding GetEncoding(size_t n);
367
368 // return internal string identifier for the encoding (see also
369 // GetEncodingDescription())
370 static wxString GetEncodingName(wxFontEncoding encoding);
371
372 // return user-readable string describing the given encoding
373 //
374 // NB: hard-coded now, but might change later (read it from config?)
375 static wxString GetEncodingDescription(wxFontEncoding encoding);
376
56e63286
RD
377 // find the encoding corresponding to the given name, inverse of
378 // GetEncodingName() and less general than CharsetToEncoding()
379 //
380 // returns wxFONTENCODING_MAX if the name is not a supported encoding
381 static wxFontEncoding GetEncodingFromName(const wxString& name);
382
d14a1e28
RD
383
384 // set the config object to use (may be NULL to use default)
385 void SetConfig(wxConfigBase *config);
386
387 // set the root config path to use (should be an absolute path)
388 void SetConfigPath(const wxString& prefix);
389
390 // return default config path
391 static const wxString GetDefaultConfigPath();
392
393
394
395 // Find an alternative for the given encoding (which is supposed to not be
396 // available on this system). If successful, returns the encoding otherwise
397 // returns None.
398 %extend {
399 PyObject* GetAltForEncoding(wxFontEncoding encoding,
400 const wxString& facename = wxPyEmptyString,
a72f4631 401 bool interactive = true) {
d14a1e28
RD
402 wxFontEncoding alt_enc;
403 if (self->GetAltForEncoding(encoding, &alt_enc, facename, interactive))
404 return PyInt_FromLong(alt_enc);
405 else {
406 Py_INCREF(Py_None);
407 return Py_None;
408 }
409 }
410 }
411
412
413 // checks whether given encoding is available in given face or not.
56e63286
RD
414 // If no facename is given (default), return true if it's available in any
415 // facename at all.
d14a1e28
RD
416 bool IsEncodingAvailable(wxFontEncoding encoding,
417 const wxString& facename = wxPyEmptyString);
418
419 // the parent window for modal dialogs
420 void SetDialogParent(wxWindow *parent);
421
422 // the title for the dialogs (note that default is quite reasonable)
423 void SetDialogTitle(const wxString& title);
424
425};
426
427
428
429//---------------------------------------------------------------------------
430%newgroup
431
432
ab1f7d2a
RD
433MustHaveApp(wxFont);
434MustHaveApp(wxFont::GetDefaultEncoding);
435MustHaveApp(wxFont::SetDefaultEncoding);
436
d14a1e28
RD
437class wxFont : public wxGDIObject {
438public:
b60f943b
RD
439 %pythonPrepend wxFont "if kwargs.has_key('faceName'): kwargs['face'] = kwargs['faceName'];del kwargs['faceName']"
440
d14a1e28 441 wxFont( int pointSize, int family, int style, int weight,
a72f4631 442 bool underline=false, const wxString& face = wxPyEmptyString,
d14a1e28
RD
443 wxFontEncoding encoding=wxFONTENCODING_DEFAULT);
444 ~wxFont();
445
446 %name(FontFromNativeInfo) wxFont(const wxNativeFontInfo& info);
447 %extend {
448 %name(FontFromNativeInfoString) wxFont(const wxString& info) {
449 wxNativeFontInfo nfi;
450 nfi.FromString(info);
451 return new wxFont(nfi);
452 }
453
454 %name(Font2) wxFont(int pointSize,
b60f943b
RD
455 wxFontFamily family,
456 int flags = wxFONTFLAG_DEFAULT,
457 const wxString& face = wxPyEmptyString,
458 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) {
d14a1e28
RD
459 return wxFont::New(pointSize, family, flags, face, encoding);
460 }
461 }
462
463
464 // was the font successfully created?
465 bool Ok() const;
466 %pythoncode { def __nonzero__(self): return self.Ok() }
467
468 // comparison
22faec7d 469 %extend {
a72f4631
RD
470 bool __eq__(const wxFont* other) { return other ? (*self == *other) : false; }
471 bool __ne__(const wxFont* other) { return other ? (*self != *other) : true; }
22faec7d 472 }
d14a1e28
RD
473
474 // accessors: get the font characteristics
475 virtual int GetPointSize() const;
476 virtual int GetFamily() const;
477 virtual int GetStyle() const;
478 virtual int GetWeight() const;
479 virtual bool GetUnderlined() const;
480 virtual wxString GetFaceName() const;
481 virtual wxFontEncoding GetEncoding() const;
482 virtual const wxNativeFontInfo *GetNativeFontInfo() const;
483
484 virtual bool IsFixedWidth() const;
485
486 wxString GetNativeFontInfoDesc() const;
487 wxString GetNativeFontInfoUserDesc() const;
488
489 // change the font characteristics
490 virtual void SetPointSize( int pointSize );
491 virtual void SetFamily( int family );
492 virtual void SetStyle( int style );
493 virtual void SetWeight( int weight );
494 virtual void SetFaceName( const wxString& faceName );
495 virtual void SetUnderlined( bool underlined );
496 virtual void SetEncoding(wxFontEncoding encoding);
497 void SetNativeFontInfo(const wxNativeFontInfo& info);
498 %name(SetNativeFontInfoFromString) void SetNativeFontInfo(const wxString& info);
499 void SetNativeFontInfoUserDesc(const wxString& info);
500
501 // translate the fonts into human-readable string (i.e. GetStyleString()
502 // will return "wxITALIC" for an italic font, ...)
503 wxString GetFamilyString() const;
504 wxString GetStyleString() const;
505 wxString GetWeightString() const;
506
507 // Unofficial API, don't use
a72f4631 508 virtual void SetNoAntiAliasing( bool no = true );
5a319c5c 509 virtual bool GetNoAntiAliasing() const;
d14a1e28
RD
510
511 // the default encoding is used for creating all fonts with default
512 // encoding parameter
513 static wxFontEncoding GetDefaultEncoding() { return ms_encodingDefault; }
514 static void SetDefaultEncoding(wxFontEncoding encoding);
515};
516
517
518
519//---------------------------------------------------------------------------
520%newgroup
521
522// wxFontEnumerator
523%{
524class wxPyFontEnumerator : public wxFontEnumerator {
525public:
526 wxPyFontEnumerator() {}
527 ~wxPyFontEnumerator() {}
528
529 DEC_PYCALLBACK_BOOL_STRING(OnFacename);
530 DEC_PYCALLBACK_BOOL_STRINGSTRING(OnFontEncoding);
531
532 PYPRIVATE;
533};
534
535IMP_PYCALLBACK_BOOL_STRING(wxPyFontEnumerator, wxFontEnumerator, OnFacename);
536IMP_PYCALLBACK_BOOL_STRINGSTRING(wxPyFontEnumerator, wxFontEnumerator, OnFontEncoding);
537
538%}
539
ab1f7d2a
RD
540MustHaveApp(wxPyFontEnumerator);
541
d14a1e28
RD
542%name(FontEnumerator) class wxPyFontEnumerator {
543public:
2b9048c5 544 %pythonAppend wxPyFontEnumerator "self._setCallbackInfo(self, FontEnumerator, 0)"
d14a1e28
RD
545
546 wxPyFontEnumerator();
547 ~wxPyFontEnumerator();
548 void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref);
549
550 bool EnumerateFacenames(
551 wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all
a72f4631 552 bool fixedWidthOnly = false);
d14a1e28
RD
553
554 bool EnumerateEncodings(const wxString& facename = wxPyEmptyString);
555
556 //wxArrayString* GetEncodings();
557 //wxArrayString* GetFacenames();
558 %extend {
559 PyObject* GetEncodings() {
560 wxArrayString* arr = self->GetEncodings();
5a319c5c
RD
561 if (arr)
562 return wxArrayString2PyList_helper(*arr);
563 else
564 return PyList_New(0);
d14a1e28
RD
565 }
566
567 PyObject* GetFacenames() {
568 wxArrayString* arr = self->GetFacenames();
5a319c5c
RD
569 if (arr)
570 return wxArrayString2PyList_helper(*arr);
571 else
572 return PyList_New(0);
d14a1e28
RD
573 }
574 }
575};
576
577
578
579%init %{
580 wxPyPtrTypeMap_Add("wxFontEnumerator", "wxPyFontEnumerator");
581%}
582
583//---------------------------------------------------------------------------