]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/src/_font.i
Use a compatible bitmap if a depth of -1 is given
[wxWidgets.git] / wxPython / src / _font.i
... / ...
CommitLineData
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_MACROMAN, // the standard mac encodings
157 wxFONTENCODING_MACJAPANESE,
158 wxFONTENCODING_MACCHINESETRAD,
159 wxFONTENCODING_MACKOREAN,
160 wxFONTENCODING_MACARABIC,
161 wxFONTENCODING_MACHEBREW,
162 wxFONTENCODING_MACGREEK,
163 wxFONTENCODING_MACCYRILLIC,
164 wxFONTENCODING_MACDEVANAGARI,
165 wxFONTENCODING_MACGURMUKHI,
166 wxFONTENCODING_MACGUJARATI,
167 wxFONTENCODING_MACORIYA,
168 wxFONTENCODING_MACBENGALI,
169 wxFONTENCODING_MACTAMIL,
170 wxFONTENCODING_MACTELUGU,
171 wxFONTENCODING_MACKANNADA,
172 wxFONTENCODING_MACMALAJALAM,
173 wxFONTENCODING_MACSINHALESE,
174 wxFONTENCODING_MACBURMESE,
175 wxFONTENCODING_MACKHMER,
176 wxFONTENCODING_MACTHAI,
177 wxFONTENCODING_MACLAOTIAN,
178 wxFONTENCODING_MACGEORGIAN,
179 wxFONTENCODING_MACARMENIAN,
180 wxFONTENCODING_MACCHINESESIMP,
181 wxFONTENCODING_MACTIBETAN,
182 wxFONTENCODING_MACMONGOLIAN,
183 wxFONTENCODING_MACETHIOPIC,
184 wxFONTENCODING_MACCENTRALEUR,
185 wxFONTENCODING_MACVIATNAMESE,
186 wxFONTENCODING_MACARABICEXT,
187 wxFONTENCODING_MACSYMBOL,
188 wxFONTENCODING_MACDINGBATS,
189 wxFONTENCODING_MACTURKISH,
190 wxFONTENCODING_MACCROATIAN,
191 wxFONTENCODING_MACICELANDIC,
192 wxFONTENCODING_MACROMANIAN,
193 wxFONTENCODING_MACCELTIC,
194 wxFONTENCODING_MACGAELIC,
195 wxFONTENCODING_MACKEYBOARD,
196
197 wxFONTENCODING_MACMIN = wxFONTENCODING_MACROMAN ,
198 wxFONTENCODING_MACMAX = wxFONTENCODING_MACKEYBOARD ,
199
200 wxFONTENCODING_MAX, // highest enumerated encoding value
201
202
203 // aliases for endian-dependent UTF encodings
204 wxFONTENCODING_UTF16, // native UTF-16
205 wxFONTENCODING_UTF32, // native UTF-32
206
207 // alias for the native Unicode encoding on this platform
208 // (this is used by wxEncodingConverter and wxUTFFile only for now)
209 wxFONTENCODING_UNICODE = wxFONTENCODING_UTF16,
210
211 // alternative names for Far Eastern encodings
212 // Chinese
213 wxFONTENCODING_GB2312 = wxFONTENCODING_CP936, // Simplified Chinese
214 wxFONTENCODING_BIG5 = wxFONTENCODING_CP950, // Traditional Chinese
215
216 // Japanese (see http://zsigri.tripod.com/fontboard/cjk/jis.html)
217 wxFONTENCODING_SHIFT_JIS = wxFONTENCODING_CP932 // Shift JIS
218};
219
220//---------------------------------------------------------------------------
221%newgroup
222
223// wxNativeFontInfo is platform-specific font representation: this struct
224// should be considered as opaque font description only used by the native
225// functions, the user code can only get the objects of this type from
226// somewhere and pass it somewhere else (possibly save them somewhere using
227// ToString() and restore them using FromString())
228struct wxNativeFontInfo
229{
230public:
231 wxNativeFontInfo();
232 ~wxNativeFontInfo();
233
234 // reset to the default state
235 void Init();
236
237 // init with the parameters of the given font
238 void InitFromFont(const wxFont& font);
239
240 // accessors and modifiers for the font elements
241 int GetPointSize() const;
242 wxFontStyle GetStyle() const;
243 wxFontWeight GetWeight() const;
244 bool GetUnderlined() const;
245 wxString GetFaceName() const;
246 wxFontFamily GetFamily() const;
247 wxFontEncoding GetEncoding() const;
248
249 void SetPointSize(int pointsize);
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
278struct 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
309bool 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
340class wxFontMapper
341{
342public:
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
377 // set the config object to use (may be NULL to use default)
378 void SetConfig(wxConfigBase *config);
379
380 // set the root config path to use (should be an absolute path)
381 void SetConfigPath(const wxString& prefix);
382
383 // return default config path
384 static const wxString GetDefaultConfigPath();
385
386
387
388 // Find an alternative for the given encoding (which is supposed to not be
389 // available on this system). If successful, returns the encoding otherwise
390 // returns None.
391 %extend {
392 PyObject* GetAltForEncoding(wxFontEncoding encoding,
393 const wxString& facename = wxPyEmptyString,
394 bool interactive = True) {
395 wxFontEncoding alt_enc;
396 if (self->GetAltForEncoding(encoding, &alt_enc, facename, interactive))
397 return PyInt_FromLong(alt_enc);
398 else {
399 Py_INCREF(Py_None);
400 return Py_None;
401 }
402 }
403 }
404
405
406 // checks whether given encoding is available in given face or not.
407 // If no facename is given,
408 bool IsEncodingAvailable(wxFontEncoding encoding,
409 const wxString& facename = wxPyEmptyString);
410
411 // the parent window for modal dialogs
412 void SetDialogParent(wxWindow *parent);
413
414 // the title for the dialogs (note that default is quite reasonable)
415 void SetDialogTitle(const wxString& title);
416
417};
418
419
420
421//---------------------------------------------------------------------------
422%newgroup
423
424
425class wxFont : public wxGDIObject {
426public:
427 wxFont( int pointSize, int family, int style, int weight,
428 bool underline=False, const wxString& face = wxPyEmptyString,
429 wxFontEncoding encoding=wxFONTENCODING_DEFAULT);
430 ~wxFont();
431
432 %name(FontFromNativeInfo) wxFont(const wxNativeFontInfo& info);
433 %extend {
434 %name(FontFromNativeInfoString) wxFont(const wxString& info) {
435 wxNativeFontInfo nfi;
436 nfi.FromString(info);
437 return new wxFont(nfi);
438 }
439
440 %name(Font2) wxFont(int pointSize,
441 wxFontFamily family,
442 int flags = wxFONTFLAG_DEFAULT,
443 const wxString& face = wxPyEmptyString,
444 wxFontEncoding encoding = wxFONTENCODING_DEFAULT) {
445 return wxFont::New(pointSize, family, flags, face, encoding);
446 }
447 }
448
449
450 // was the font successfully created?
451 bool Ok() const;
452 %pythoncode { def __nonzero__(self): return self.Ok() }
453
454 // comparison
455 bool operator == (const wxFont& font) const;
456 bool operator != (const wxFont& font) const;
457
458 // accessors: get the font characteristics
459 virtual int GetPointSize() const;
460 virtual int GetFamily() const;
461 virtual int GetStyle() const;
462 virtual int GetWeight() const;
463 virtual bool GetUnderlined() const;
464 virtual wxString GetFaceName() const;
465 virtual wxFontEncoding GetEncoding() const;
466 virtual const wxNativeFontInfo *GetNativeFontInfo() const;
467
468 virtual bool IsFixedWidth() const;
469
470 wxString GetNativeFontInfoDesc() const;
471 wxString GetNativeFontInfoUserDesc() const;
472
473 // change the font characteristics
474 virtual void SetPointSize( int pointSize );
475 virtual void SetFamily( int family );
476 virtual void SetStyle( int style );
477 virtual void SetWeight( int weight );
478 virtual void SetFaceName( const wxString& faceName );
479 virtual void SetUnderlined( bool underlined );
480 virtual void SetEncoding(wxFontEncoding encoding);
481 void SetNativeFontInfo(const wxNativeFontInfo& info);
482 %name(SetNativeFontInfoFromString) void SetNativeFontInfo(const wxString& info);
483 void SetNativeFontInfoUserDesc(const wxString& info);
484
485 // translate the fonts into human-readable string (i.e. GetStyleString()
486 // will return "wxITALIC" for an italic font, ...)
487 wxString GetFamilyString() const;
488 wxString GetStyleString() const;
489 wxString GetWeightString() const;
490
491 // Unofficial API, don't use
492 virtual void SetNoAntiAliasing( bool no = True );
493 virtual bool GetNoAntiAliasing();
494
495 // the default encoding is used for creating all fonts with default
496 // encoding parameter
497 static wxFontEncoding GetDefaultEncoding() { return ms_encodingDefault; }
498 static void SetDefaultEncoding(wxFontEncoding encoding);
499};
500
501
502
503//---------------------------------------------------------------------------
504%newgroup
505
506// wxFontEnumerator
507%{
508class wxPyFontEnumerator : public wxFontEnumerator {
509public:
510 wxPyFontEnumerator() {}
511 ~wxPyFontEnumerator() {}
512
513 DEC_PYCALLBACK_BOOL_STRING(OnFacename);
514 DEC_PYCALLBACK_BOOL_STRINGSTRING(OnFontEncoding);
515
516 PYPRIVATE;
517};
518
519IMP_PYCALLBACK_BOOL_STRING(wxPyFontEnumerator, wxFontEnumerator, OnFacename);
520IMP_PYCALLBACK_BOOL_STRINGSTRING(wxPyFontEnumerator, wxFontEnumerator, OnFontEncoding);
521
522%}
523
524%name(FontEnumerator) class wxPyFontEnumerator {
525public:
526 %pythonAppend wxPyFontEnumerator "self._setCallbackInfo(self, FontEnumerator, 0)"
527
528 wxPyFontEnumerator();
529 ~wxPyFontEnumerator();
530 void _setCallbackInfo(PyObject* self, PyObject* _class, bool incref);
531
532 bool EnumerateFacenames(
533 wxFontEncoding encoding = wxFONTENCODING_SYSTEM, // all
534 bool fixedWidthOnly = False);
535
536 bool EnumerateEncodings(const wxString& facename = wxPyEmptyString);
537
538 //wxArrayString* GetEncodings();
539 //wxArrayString* GetFacenames();
540 %extend {
541 PyObject* GetEncodings() {
542 wxArrayString* arr = self->GetEncodings();
543 return wxArrayString2PyList_helper(*arr);
544 }
545
546 PyObject* GetFacenames() {
547 wxArrayString* arr = self->GetFacenames();
548 return wxArrayString2PyList_helper(*arr);
549 }
550 }
551};
552
553
554
555%init %{
556 wxPyPtrTypeMap_Add("wxFontEnumerator", "wxPyFontEnumerator");
557%}
558
559//---------------------------------------------------------------------------