]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_font.i
reSWIGged
[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)
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_MAX, // highest enumerated encoding value
157
158
159 // aliases for endian-dependent UTF encodings
160 wxFONTENCODING_UTF16, // native UTF-16
161 wxFONTENCODING_UTF32, // native UTF-32
162
163 // alias for the native Unicode encoding on this platform
164 // (this is used by wxEncodingConverter and wxUTFFile only for now)
165 wxFONTENCODING_UNICODE = wxFONTENCODING_UTF16,
166
167 // alternative names for Far Eastern encodings
168 // Chinese
169 wxFONTENCODING_GB2312 = wxFONTENCODING_CP936, // Simplified Chinese
170 wxFONTENCODING_BIG5 = wxFONTENCODING_CP950, // Traditional Chinese
171
172 // Japanese (see http://zsigri.tripod.com/fontboard/cjk/jis.html)
173 wxFONTENCODING_SHIFT_JIS = wxFONTENCODING_CP932 // Shift JIS
174};
175
176//---------------------------------------------------------------------------
177%newgroup
178
179// wxNativeFontInfo is platform-specific font representation: this struct
180// should be considered as opaque font description only used by the native
181// functions, the user code can only get the objects of this type from
182// somewhere and pass it somewhere else (possibly save them somewhere using
183// ToString() and restore them using FromString())
184struct wxNativeFontInfo
185{
186public:
187 wxNativeFontInfo();
188 ~wxNativeFontInfo();
189
190 // reset to the default state
191 void Init();
192
193 // init with the parameters of the given font
194 void InitFromFont(const wxFont& font);
195
196 // accessors and modifiers for the font elements
197 int GetPointSize() const;
198 wxFontStyle GetStyle() const;
199 wxFontWeight GetWeight() const;
200 bool GetUnderlined() const;
201 wxString GetFaceName() const;
202 wxFontFamily GetFamily() const;
203 wxFontEncoding GetEncoding() const;
204
205 void SetPointSize(int pointsize);
206 void SetStyle(wxFontStyle style);
207 void SetWeight(wxFontWeight weight);
208 void SetUnderlined(bool underlined);
209 void SetFaceName(wxString facename);
210 void SetFamily(wxFontFamily family);
211 void SetEncoding(wxFontEncoding encoding);
212
213 // it is important to be able to serialize wxNativeFontInfo objects to be
214 // able to store them (in config file, for example)
215 bool FromString(const wxString& s);
216 wxString ToString() const;
217
218 %extend {
219 wxString __str__() {
220 return self->ToString();
221 }
222 }
223
224 // we also want to present the native font descriptions to the user in some
225 // human-readable form (it is not platform independent neither, but can
226 // hopefully be understood by the user)
227 bool FromUserString(const wxString& s);
228 wxString ToUserString() const;
229};
230
231
232
233
234struct wxNativeEncodingInfo
235{
236 wxString facename; // may be empty meaning "any"
237 wxFontEncoding encoding; // so that we know what this struct represents
238
239 wxNativeEncodingInfo();
240 ~wxNativeEncodingInfo();
241
242 // this struct is saved in config by wxFontMapper, so it should know to
243 // serialise itself (implemented in platform-specific code)
244 bool FromString(const wxString& s);
245 wxString ToString() const;
246};
247
248
249#ifndef __WXMSW__
250// translate a wxFontEncoding into native encoding parameter (defined above),
251// returning a wxNativeEncodingInfo if an (exact) match could be found, NULL
252// otherwise.
253%inline %{
254 wxNativeEncodingInfo* wxGetNativeFontEncoding(wxFontEncoding encoding) {
255 static wxNativeEncodingInfo info;
256 if ( wxGetNativeFontEncoding(encoding, &info) )
257 return &info;
258 else
259 return NULL;
260 }
261%}
262
263// test for the existence of the font described by this facename/encoding,
dd9f7fea 264// return True if such font(s) exist, False otherwise
d14a1e28
RD
265bool wxTestFontEncoding(const wxNativeEncodingInfo& info);
266
267#else
268
269%inline %{
270 wxNativeEncodingInfo* wxGetNativeFontEncoding(wxFontEncoding encoding)
271 { PyErr_SetNone(PyExc_NotImplementedError); return NULL; }
272
273 bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
dd9f7fea 274 { PyErr_SetNone(PyExc_NotImplementedError); return False; }
d14a1e28
RD
275%}
276#endif
277
278//---------------------------------------------------------------------------
279%newgroup
280
281// wxFontMapper manages user-definable correspondence between logical font
282// names and the fonts present on the machine.
283//
284// The default implementations of all functions will ask the user if they are
285// not capable of finding the answer themselves and store the answer in a
286// config file (configurable via SetConfigXXX functions). This behaviour may
dd9f7fea 287// be disabled by giving the value of False to "interactive" parameter.
d14a1e28
RD
288// However, the functions will always consult the config file to allow the
289// user-defined values override the default logic and there is no way to
290// disable this - which shouldn't be ever needed because if "interactive" was
dd9f7fea 291// never True, the config file is never created anyhow.
d14a1e28
RD
292//
293// This is a singleton class, font mapper objects can only be accessed using
294// wxFontMapper::Get().
295
296class wxFontMapper
297{
298public:
299 wxFontMapper();
300 ~wxFontMapper();
301
302 // return instance of the wxFontMapper singleton
303 static wxFontMapper *Get();
304 // set the sigleton to 'mapper' instance and return previous one
305 static wxFontMapper *Set(wxFontMapper *mapper);
306
307
308 // returns the encoding for the given charset (in the form of RFC 2046) or
309 // wxFONTENCODING_SYSTEM if couldn't decode it
310 //
311 // interactive parameter is ignored in the base class, we behave as if it
dd9f7fea 312 // were always False
d14a1e28 313 virtual wxFontEncoding CharsetToEncoding(const wxString& charset,
dd9f7fea 314 bool interactive = True);
d14a1e28
RD
315
316
317 // get the number of font encodings we know about
318 static size_t GetSupportedEncodingsCount();
319
320 // get the n-th supported encoding
321 static wxFontEncoding GetEncoding(size_t n);
322
323 // return internal string identifier for the encoding (see also
324 // GetEncodingDescription())
325 static wxString GetEncodingName(wxFontEncoding encoding);
326
327 // return user-readable string describing the given encoding
328 //
329 // NB: hard-coded now, but might change later (read it from config?)
330 static wxString GetEncodingDescription(wxFontEncoding encoding);
331
332
333 // set the config object to use (may be NULL to use default)
334 void SetConfig(wxConfigBase *config);
335
336 // set the root config path to use (should be an absolute path)
337 void SetConfigPath(const wxString& prefix);
338
339 // return default config path
340 static const wxString GetDefaultConfigPath();
341
342
343
344 // Find an alternative for the given encoding (which is supposed to not be
345 // available on this system). If successful, returns the encoding otherwise
346 // returns None.
347 %extend {
348 PyObject* GetAltForEncoding(wxFontEncoding encoding,
349 const wxString& facename = wxPyEmptyString,
dd9f7fea 350 bool interactive = True) {
d14a1e28
RD
351 wxFontEncoding alt_enc;
352 if (self->GetAltForEncoding(encoding, &alt_enc, facename, interactive))
353 return PyInt_FromLong(alt_enc);
354 else {
355 Py_INCREF(Py_None);
356 return Py_None;
357 }
358 }
359 }
360
361
362 // checks whether given encoding is available in given face or not.
363 // If no facename is given,
364 bool IsEncodingAvailable(wxFontEncoding encoding,
365 const wxString& facename = wxPyEmptyString);
366
367 // the parent window for modal dialogs
368 void SetDialogParent(wxWindow *parent);
369
370 // the title for the dialogs (note that default is quite reasonable)
371 void SetDialogTitle(const wxString& title);
372
373};
374
375
376
377//---------------------------------------------------------------------------
378%newgroup
379
380
381class wxFont : public wxGDIObject {
382public:
383 wxFont( int pointSize, int family, int style, int weight,
dd9f7fea 384 bool underline=False, const wxString& face = wxPyEmptyString,
d14a1e28
RD
385 wxFontEncoding encoding=wxFONTENCODING_DEFAULT);
386 ~wxFont();
387
388 %name(FontFromNativeInfo) wxFont(const wxNativeFontInfo& info);
389 %extend {
390 %name(FontFromNativeInfoString) wxFont(const wxString& info) {
391 wxNativeFontInfo nfi;
392 nfi.FromString(info);
393 return new wxFont(nfi);
394 }
395
396 %name(Font2) wxFont(int pointSize,
397 wxFontFamily family,
398 int flags = wxFONTFLAG_DEFAULT,
399 const wxString& face = wxPyEmptyString,
400 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) {
401 return wxFont::New(pointSize, family, flags, face, encoding);
402 }
403 }
404
405
406 // was the font successfully created?
407 bool Ok() const;
408 %pythoncode { def __nonzero__(self): return self.Ok() }
409
410 // comparison
411 bool operator == (const wxFont& font) const;
412 bool operator != (const wxFont& font) const;
413
414 // accessors: get the font characteristics
415 virtual int GetPointSize() const;
416 virtual int GetFamily() const;
417 virtual int GetStyle() const;
418 virtual int GetWeight() const;
419 virtual bool GetUnderlined() const;
420 virtual wxString GetFaceName() const;
421 virtual wxFontEncoding GetEncoding() const;
422 virtual const wxNativeFontInfo *GetNativeFontInfo() const;
423
424 virtual bool IsFixedWidth() const;
425
426 wxString GetNativeFontInfoDesc() const;
427 wxString GetNativeFontInfoUserDesc() const;
428
429 // change the font characteristics
430 virtual void SetPointSize( int pointSize );
431 virtual void SetFamily( int family );
432 virtual void SetStyle( int style );
433 virtual void SetWeight( int weight );
434 virtual void SetFaceName( const wxString& faceName );
435 virtual void SetUnderlined( bool underlined );
436 virtual void SetEncoding(wxFontEncoding encoding);
437 void SetNativeFontInfo(const wxNativeFontInfo& info);
438 %name(SetNativeFontInfoFromString) void SetNativeFontInfo(const wxString& info);
439 void SetNativeFontInfoUserDesc(const wxString& info);
440
441 // translate the fonts into human-readable string (i.e. GetStyleString()
442 // will return "wxITALIC" for an italic font, ...)
443 wxString GetFamilyString() const;
444 wxString GetStyleString() const;
445 wxString GetWeightString() const;
446
447 // Unofficial API, don't use
dd9f7fea 448 virtual void SetNoAntiAliasing( bool no = True );
d14a1e28
RD
449 virtual bool GetNoAntiAliasing();
450
451 // the default encoding is used for creating all fonts with default
452 // encoding parameter
453 static wxFontEncoding GetDefaultEncoding() { return ms_encodingDefault; }
454 static void SetDefaultEncoding(wxFontEncoding encoding);
455};
456
457
458
459//---------------------------------------------------------------------------
460%newgroup
461
462// wxFontEnumerator
463%{
464class wxPyFontEnumerator : public wxFontEnumerator {
465public:
466 wxPyFontEnumerator() {}
467 ~wxPyFontEnumerator() {}
468
469 DEC_PYCALLBACK_BOOL_STRING(OnFacename);
470 DEC_PYCALLBACK_BOOL_STRINGSTRING(OnFontEncoding);
471
472 PYPRIVATE;
473};
474
475IMP_PYCALLBACK_BOOL_STRING(wxPyFontEnumerator, wxFontEnumerator, OnFacename);
476IMP_PYCALLBACK_BOOL_STRINGSTRING(wxPyFontEnumerator, wxFontEnumerator, OnFontEncoding);
477
478%}
479
480%name(FontEnumerator) class wxPyFontEnumerator {
481public:
482 %addtofunc wxPyFontEnumerator "self._setCallbackInfo(self, FontEnumerator, 0)"
483
484 wxPyFontEnumerator();
485 ~wxPyFontEnumerator();
486 void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref);
487
488 bool EnumerateFacenames(
489 wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all
dd9f7fea 490 bool fixedWidthOnly = False);
d14a1e28
RD
491
492 bool EnumerateEncodings(const wxString& facename = wxPyEmptyString);
493
494 //wxArrayString* GetEncodings();
495 //wxArrayString* GetFacenames();
496 %extend {
497 PyObject* GetEncodings() {
498 wxArrayString* arr = self->GetEncodings();
499 return wxArrayString2PyList_helper(*arr);
500 }
501
502 PyObject* GetFacenames() {
503 wxArrayString* arr = self->GetFacenames();
504 return wxArrayString2PyList_helper(*arr);
505 }
506 }
507};
508
509
510
511%init %{
512 wxPyPtrTypeMap_Add("wxFontEnumerator", "wxPyFontEnumerator");
513%}
514
515//---------------------------------------------------------------------------