]> git.saurik.com Git - wxWidgets.git/blame - src/unix/fontutil.cpp
gtk+-2.x runtime compatibility when compile-time gtk+ version is 2.7+
[wxWidgets.git] / src / unix / fontutil.cpp
CommitLineData
7beba2fc
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: unix/fontutil.cpp
3// Purpose: Font helper functions for X11 (GDK/X)
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 05.11.99
7// RCS-ID: $Id$
8// Copyright: (c) Vadim Zeitlin
65571936 9// Licence: wxWindows licence
7beba2fc
VZ
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
7beba2fc
VZ
21 #pragma implementation "fontutil.h"
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
28 #pragma hdrstop
29#endif
30
31#ifndef WX_PRECOMP
0f6858b6 32 #include "wx/font.h" // wxFont enums
e4ffab29 33 #include "wx/encinfo.h"
7beba2fc
VZ
34#endif // PCH
35
db16cab4
RR
36#include "wx/fontutil.h"
37#include "wx/fontmap.h"
38#include "wx/tokenzr.h"
39#include "wx/hash.h"
40#include "wx/module.h"
41
2b5f62a0
VZ
42#if wxUSE_PANGO
43
44#include "pango/pango.h"
db16cab4 45
2b5f62a0 46#ifdef __WXGTK20__
db16cab4 47#include "wx/gtk/private.h"
38d446db 48extern GtkWidget *wxGetRootWindow();
2b5f62a0
VZ
49#else
50#include "wx/x11/private.h"
51#endif
db16cab4
RR
52
53// ----------------------------------------------------------------------------
54// wxNativeFontInfo
55// ----------------------------------------------------------------------------
56
57void wxNativeFontInfo::Init()
58{
59 description = NULL;
60}
61
23afe648
VZ
62void
63wxNativeFontInfo::Init(const wxNativeFontInfo& info)
fdf7514a
VS
64{
65 if (info.description)
66 description = pango_font_description_copy(info.description);
67 else
82680055 68 description = NULL;
fdf7514a
VS
69}
70
82680055 71void wxNativeFontInfo::Free()
fdf7514a
VS
72{
73 if (description)
74 pango_font_description_free(description);
75}
76
db16cab4
RR
77int wxNativeFontInfo::GetPointSize() const
78{
79 return pango_font_description_get_size( description ) / PANGO_SCALE;
80}
81
82wxFontStyle wxNativeFontInfo::GetStyle() const
83{
84 wxFontStyle m_style = wxFONTSTYLE_NORMAL;
85
86 switch (pango_font_description_get_style( description ))
87 {
88 case PANGO_STYLE_NORMAL:
89 m_style = wxFONTSTYLE_NORMAL;
90 break;
91 case PANGO_STYLE_ITALIC:
92 m_style = wxFONTSTYLE_ITALIC;
93 break;
94 case PANGO_STYLE_OBLIQUE:
95 m_style = wxFONTSTYLE_SLANT;
96 break;
97 }
2b5f62a0 98
db16cab4
RR
99 return m_style;
100}
101
102wxFontWeight wxNativeFontInfo::GetWeight() const
103{
0f6858b6
RR
104#if 0
105 // We seem to currently initialize only by string.
106 // In that case PANGO_FONT_MASK_WEIGHT is always set.
107 if (!(pango_font_description_get_set_fields(description) & PANGO_FONT_MASK_WEIGHT))
108 return wxFONTWEIGHT_NORMAL;
109#endif
db16cab4 110
0f6858b6
RR
111 PangoWeight pango_weight = pango_font_description_get_weight( description );
112
113 // Until the API can be changed the following ranges of weight values are used:
114 // wxFONTWEIGHT_LIGHT: 100 .. 349 - range of 250
115 // wxFONTWEIGHT_NORMAL: 350 .. 599 - range of 250
116 // wxFONTWEIGHT_BOLD: 600 .. 900 - range of 301 (600 is "semibold" already)
117
118 if (pango_weight >= 600)
119 return wxFONTWEIGHT_BOLD;
120
121 if (pango_weight < 350)
122 return wxFONTWEIGHT_LIGHT;
2b5f62a0 123
0f6858b6 124 return wxFONTWEIGHT_NORMAL;
db16cab4
RR
125}
126
127bool wxNativeFontInfo::GetUnderlined() const
128{
129 return FALSE;
130}
131
132wxString wxNativeFontInfo::GetFaceName() const
133{
134 wxString tmp = wxGTK_CONV_BACK( pango_font_description_get_family( description ) );
2b5f62a0 135
db16cab4
RR
136 return tmp;
137}
138
139wxFontFamily wxNativeFontInfo::GetFamily() const
140{
b67d14be
MR
141 wxFontFamily ret = wxFONTFAMILY_DEFAULT;
142 char *family_text = g_ascii_strdown( pango_font_description_get_family( description ), -1 );
143 // Check for some common fonts, to salvage what we can from the current win32 centric wxFont API:
144 if (strncmp( family_text, "monospace", 9 ) == 0)
145 ret = wxFONTFAMILY_TELETYPE; // begins with "Monospace"
146 else if (strncmp( family_text, "courier", 7 ) == 0)
147 ret = wxFONTFAMILY_TELETYPE; // begins with "Courier"
148#ifdef HAVE_PANGO_FONT_FAMILY_IS_MONOSPACE
149 else
150 {
151 PangoFontFamily **families;
b20cb045 152 PangoFontFamily *family = NULL;
b67d14be
MR
153 int n_families;
154 pango_context_list_families(
38d446db 155#ifdef __WXGTK20__
b67d14be 156 gtk_widget_get_pango_context( wxGetRootWindow() ),
38d446db 157#else
b67d14be 158 wxTheApp->GetPangoContext(),
38d446db 159#endif
b67d14be 160 &families, &n_families);
38d446db 161
b67d14be 162 for (int i = 0;i < n_families;++i)
38d446db 163 {
b67d14be
MR
164 if (g_ascii_strcasecmp(pango_font_family_get_name( families[i] ), pango_font_description_get_family( description )) == 0 )
165 {
166 family = families[i];
167 break;
168 }
38d446db 169 }
38d446db 170
b67d14be 171 g_free(families);
38d446db 172
b67d14be 173 wxASSERT_MSG( family, wxT("wxNativeFontInfo::GetFamily() - No appropriate PangoFontFamily found for ::description") );
38d446db 174
b67d14be
MR
175 //BCI: Cache the wxFontFamily inside the class. Validate cache with
176 //BCI: g_ascii_strcasecmp(pango_font_description_get_family(description), pango_font_family_get_name(family)) == 0
38d446db 177
b20cb045 178 if (family != NULL && pango_font_family_is_monospace( family ))
b67d14be
MR
179 ret = wxFONTFAMILY_TELETYPE; // is deemed a monospace font by pango
180 }
38d446db
MR
181#endif // pango_font_family_is_monospace
182
b67d14be
MR
183 if (ret == wxFONTFAMILY_DEFAULT)
184 {
185 if (strstr( family_text, "sans" ) != NULL) // checked before serif, so that "* Sans Serif" fonts are detected correctly
186 ret = wxFONTFAMILY_SWISS; // contains "Sans"
187 else if (strstr( family_text, "serif" ) != NULL)
188 ret = wxFONTFAMILY_ROMAN; // contains "Serif"
189 else if (strncmp( family_text, "times", 5 ) == 0)
190 ret = wxFONTFAMILY_ROMAN; // begins with "Times"
191 else if (strncmp( family_text, "old", 3 ) == 0)
192 ret = wxFONTFAMILY_DECORATIVE; // Begins with "Old" - "Old English", "Old Town"
193 }
194
195 free(family_text);
196 return ret;
db16cab4
RR
197}
198
199wxFontEncoding wxNativeFontInfo::GetEncoding() const
200{
201 return wxFONTENCODING_SYSTEM;
202}
203
3398cf2c 204
8a15e8ba 205void wxNativeFontInfo::SetPointSize(int pointsize)
3398cf2c 206{
8a15e8ba 207 pango_font_description_set_size( description, pointsize * PANGO_SCALE );
3398cf2c
VZ
208}
209
7533ba25 210void wxNativeFontInfo::SetStyle(wxFontStyle style)
3398cf2c 211{
7533ba25
MR
212 switch (style)
213 {
214 case wxFONTSTYLE_ITALIC:
215 pango_font_description_set_style( description, PANGO_STYLE_ITALIC );
216 break;
217 case wxFONTSTYLE_SLANT:
218 pango_font_description_set_style( description, PANGO_STYLE_OBLIQUE );
219 break;
220 default:
221 wxFAIL_MSG( _T("unknown font style") );
222 // fall through
223 case wxFONTSTYLE_NORMAL:
224 pango_font_description_set_style( description, PANGO_STYLE_NORMAL );
225 break;
226 }
3398cf2c
VZ
227}
228
7533ba25 229void wxNativeFontInfo::SetWeight(wxFontWeight weight)
3398cf2c 230{
7533ba25
MR
231 switch (weight)
232 {
233 case wxFONTWEIGHT_BOLD:
234 pango_font_description_set_weight(description, PANGO_WEIGHT_BOLD);
235 break;
236 case wxFONTWEIGHT_LIGHT:
237 pango_font_description_set_weight(description, PANGO_WEIGHT_LIGHT);
238 break;
239 default:
240 wxFAIL_MSG( _T("unknown font weight") );
241 // fall through
242 case wxFONTWEIGHT_NORMAL:
243 pango_font_description_set_weight(description, PANGO_WEIGHT_NORMAL);
244 }
3398cf2c
VZ
245}
246
247void wxNativeFontInfo::SetUnderlined(bool WXUNUSED(underlined))
248{
249 wxFAIL_MSG( _T("not implemented") );
250}
251
8a15e8ba 252void wxNativeFontInfo::SetFaceName(wxString facename)
3398cf2c 253{
8a15e8ba 254 pango_font_description_set_family( description, wxGTK_CONV(facename) );
3398cf2c
VZ
255}
256
257void wxNativeFontInfo::SetFamily(wxFontFamily WXUNUSED(family))
258{
259 wxFAIL_MSG( _T("not implemented") );
260}
261
262void wxNativeFontInfo::SetEncoding(wxFontEncoding WXUNUSED(encoding))
263{
264 wxFAIL_MSG( _T("not implemented") );
265}
266
267
268
db16cab4
RR
269bool wxNativeFontInfo::FromString(const wxString& s)
270{
271 if (description)
272 pango_font_description_free( description );
273
274 description = pango_font_description_from_string( wxGTK_CONV( s ) );
275
276 return TRUE;
277}
278
279wxString wxNativeFontInfo::ToString() const
280{
61850501
RR
281 char *str = pango_font_description_to_string( description );
282 wxString tmp = wxGTK_CONV_BACK( str );
283 g_free( str );
db16cab4
RR
284
285 return tmp;
286}
287
288bool wxNativeFontInfo::FromUserString(const wxString& s)
289{
290 return FromString( s );
291}
292
293wxString wxNativeFontInfo::ToUserString() const
294{
295 return ToString();
296}
297
298// ----------------------------------------------------------------------------
299// wxNativeEncodingInfo
300// ----------------------------------------------------------------------------
301
302bool wxNativeEncodingInfo::FromString(const wxString& s)
303{
304 return FALSE;
305}
306
307wxString wxNativeEncodingInfo::ToString() const
308{
309 return wxEmptyString;
310}
311
312bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
313{
314 return TRUE;
315}
316
317bool wxGetNativeFontEncoding(wxFontEncoding encoding,
318 wxNativeEncodingInfo *info)
319{
f8b29974
VZ
320 // we *must* return true for default encoding as otherwise wxFontMapper
321 // considers that we can't load any font and aborts with wxLogFatalError!
322 if ( encoding == wxFONTENCODING_SYSTEM )
323 {
324 info->facename.clear();
325 info->encoding = wxFONTENCODING_SYSTEM;
326 }
327
328 // pretend that we support everything, it's better than to always return
329 // false as the old code did
330 return true;
db16cab4
RR
331}
332
2b5f62a0 333#else // GTK+ 1.x
db16cab4 334
79e4b627 335#ifdef __X__
4ea45e6b
VZ
336 #ifdef __VMS__
337 #pragma message disable nosimpint
338 #endif
339
340 #include <X11/Xlib.h>
341
342 #ifdef __VMS__
343 #pragma message enable nosimpint
344 #endif
79e4b627
VZ
345
346 #include "wx/utils.h" // for wxGetDisplay()
347#elif defined(__WXGTK__)
4ea45e6b
VZ
348 // we have to declare struct tm to avoid problems with first forward
349 // declaring it in C code (glib.h included from gdk.h does it) and then
350 // defining it when time.h is included from the headers below - this is
351 // known not to work at least with Sun CC 6.01
352 #include <time.h>
353
354 #include <gdk/gdk.h>
79e4b627
VZ
355#endif
356
2e0e025e
RR
357
358// ----------------------------------------------------------------------------
359// private data
360// ----------------------------------------------------------------------------
361
362static wxHashTable *g_fontHash = (wxHashTable*) NULL;
7beba2fc
VZ
363
364// ----------------------------------------------------------------------------
365// private functions
366// ----------------------------------------------------------------------------
367
368// define the functions to create and destroy native fonts for this toolkit
369#ifdef __X__
3fe34ed0 370 wxNativeFont wxLoadFont(const wxString& fontSpec)
7beba2fc
VZ
371 {
372 return XLoadQueryFont((Display *)wxGetDisplay(), fontSpec);
373 }
374
409d5a58 375 inline void wxFreeFont(wxNativeFont font)
7beba2fc 376 {
a5fc62a1 377 XFreeFont((Display *)wxGetDisplay(), (XFontStruct *)font);
7beba2fc
VZ
378 }
379#elif defined(__WXGTK__)
3fe34ed0 380 wxNativeFont wxLoadFont(const wxString& fontSpec)
7beba2fc 381 {
8fa3a431
VZ
382 // VZ: we should use gdk_fontset_load() instead of gdk_font_load()
383 // here to be able to display Japanese fonts correctly (at least
384 // this is what people report) but unfortunately doing it results
385 // in tons of warnings when using GTK with "normal" European
386 // languages and so we can't always do it and I don't know enough
387 // to determine when should this be done... (FIXME)
388 return gdk_font_load( wxConvertWX2MB(fontSpec) );
7beba2fc
VZ
389 }
390
409d5a58 391 inline void wxFreeFont(wxNativeFont font)
7beba2fc
VZ
392 {
393 gdk_font_unref(font);
394 }
395#else
396 #error "Unknown GUI toolkit"
397#endif
398
399static bool wxTestFontSpec(const wxString& fontspec);
400
401static wxNativeFont wxLoadQueryFont(int pointSize,
402 int family,
403 int style,
404 int weight,
405 bool underlined,
406 const wxString& facename,
407 const wxString& xregistry,
30764ab5
VZ
408 const wxString& xencoding,
409 wxString* xFontName);
7beba2fc
VZ
410
411// ============================================================================
412// implementation
413// ============================================================================
414
415// ----------------------------------------------------------------------------
416// wxNativeEncodingInfo
417// ----------------------------------------------------------------------------
418
419// convert to/from the string representation: format is
1e1d0be1 420// encodingid;registry;encoding[;facename]
7beba2fc
VZ
421bool wxNativeEncodingInfo::FromString(const wxString& s)
422{
6c49baf2 423 // use ";", not "-" because it may be part of encoding name
1e1d0be1 424 wxStringTokenizer tokenizer(s, _T(";"));
1e1d0be1
VS
425
426 wxString encid = tokenizer.GetNextToken();
427 long enc;
428 if ( !encid.ToLong(&enc) )
429 return FALSE;
430 encoding = (wxFontEncoding)enc;
7beba2fc
VZ
431
432 xregistry = tokenizer.GetNextToken();
433 if ( !xregistry )
434 return FALSE;
435
436 xencoding = tokenizer.GetNextToken();
437 if ( !xencoding )
438 return FALSE;
439
440 // ok even if empty
441 facename = tokenizer.GetNextToken();
442
443 return TRUE;
444}
445
446wxString wxNativeEncodingInfo::ToString() const
447{
448 wxString s;
1e1d0be1 449 s << (long)encoding << _T(';') << xregistry << _T(';') << xencoding;
7beba2fc
VZ
450 if ( !!facename )
451 {
1e1d0be1 452 s << _T(';') << facename;
7beba2fc
VZ
453 }
454
455 return s;
456}
457
ab5fe833
VZ
458// ----------------------------------------------------------------------------
459// wxNativeFontInfo
460// ----------------------------------------------------------------------------
461
462void wxNativeFontInfo::Init()
463{
409d5a58 464 m_isDefault = TRUE;
ab5fe833
VZ
465}
466
467bool wxNativeFontInfo::FromString(const wxString& s)
468{
469 wxStringTokenizer tokenizer(s, _T(";"));
470
471 // check the version
472 wxString token = tokenizer.GetNextToken();
473 if ( token != _T('0') )
474 return FALSE;
475
476 xFontName = tokenizer.GetNextToken();
477
478 // this should be the end
479 if ( tokenizer.HasMoreTokens() )
480 return FALSE;
481
482 return FromXFontName(xFontName);
483}
484
485wxString wxNativeFontInfo::ToString() const
486{
487 // 0 is the version
488 return wxString::Format(_T("%d;%s"), 0, GetXFontName().c_str());
489}
490
491bool wxNativeFontInfo::FromUserString(const wxString& s)
492{
493 return FromXFontName(s);
494}
495
496wxString wxNativeFontInfo::ToUserString() const
497{
498 return GetXFontName();
499}
500
409d5a58
VZ
501bool wxNativeFontInfo::HasElements() const
502{
503 // we suppose that the foundry is never empty, so if it is it means that we
504 // had never parsed the XLFD
505 return !fontElements[0].empty();
506}
507
53f6aab7
VZ
508wxString wxNativeFontInfo::GetXFontComponent(wxXLFDField field) const
509{
510 wxCHECK_MSG( field < wxXLFD_MAX, _T(""), _T("invalid XLFD field") );
511
409d5a58 512 if ( !HasElements() )
53f6aab7
VZ
513 {
514 // const_cast
515 if ( !((wxNativeFontInfo *)this)->FromXFontName(xFontName) )
516 return _T("");
517 }
518
519 return fontElements[field];
520}
521
295272bd 522bool wxNativeFontInfo::FromXFontName(const wxString& fontname)
ab5fe833
VZ
523{
524 // TODO: we should be able to handle the font aliases here, but how?
409d5a58
VZ
525 wxStringTokenizer tokenizer(fontname, _T("-"));
526
527 // skip the leading, usually empty field (font name registry)
528 if ( !tokenizer.HasMoreTokens() )
529 return FALSE;
530
531 (void)tokenizer.GetNextToken();
ab5fe833
VZ
532
533 for ( size_t n = 0; n < WXSIZEOF(fontElements); n++ )
534 {
535 if ( !tokenizer.HasMoreTokens() )
536 {
537 // not enough elements in the XLFD - or maybe an alias
538 return FALSE;
539 }
540
b4e4abb5
VZ
541 wxString field = tokenizer.GetNextToken();
542 if ( !field.empty() && field != _T('*') )
543 {
544 // we're really initialized now
545 m_isDefault = FALSE;
546 }
547
548 fontElements[n] = field;
ab5fe833
VZ
549 }
550
551 // this should be all
011ba5ed
VZ
552 if ( tokenizer.HasMoreTokens() )
553 return FALSE;
554
011ba5ed 555 return TRUE;
ab5fe833
VZ
556}
557
558wxString wxNativeFontInfo::GetXFontName() const
559{
560 if ( xFontName.empty() )
561 {
562 for ( size_t n = 0; n < WXSIZEOF(fontElements); n++ )
563 {
564 // replace the non specified elements with '*' except for the
565 // additional style which is usually just omitted
566 wxString elt = fontElements[n];
409d5a58 567 if ( elt.empty() && n != wxXLFD_ADDSTYLE )
ab5fe833
VZ
568 {
569 elt = _T('*');
570 }
571
572 // const_cast
573 ((wxNativeFontInfo *)this)->xFontName << _T('-') << elt;
574 }
575 }
576
577 return xFontName;
578}
579
409d5a58
VZ
580void
581wxNativeFontInfo::SetXFontComponent(wxXLFDField field, const wxString& value)
582{
583 wxCHECK_RET( field < wxXLFD_MAX, _T("invalid XLFD field") );
584
585 // this class should be initialized with a valid font spec first and only
586 // then the fields may be modified!
587 wxASSERT_MSG( !IsDefault(), _T("can't modify an uninitialized XLFD") );
588
589 if ( !HasElements() )
590 {
591 // const_cast
592 if ( !((wxNativeFontInfo *)this)->FromXFontName(xFontName) )
593 {
594 wxFAIL_MSG( _T("can't set font element for invalid XLFD") );
595
596 return;
597 }
598 }
599
600 fontElements[field] = value;
601
602 // invalidate the XFLD, it doesn't correspond to the font elements any more
603 xFontName.clear();
604}
605
606void wxNativeFontInfo::SetXFontName(const wxString& xFontName_)
607{
608 // invalidate the font elements, GetXFontComponent() will reparse the XLFD
609 fontElements[0].clear();
610
611 xFontName = xFontName_;
612
613 m_isDefault = FALSE;
614}
615
2b5f62a0
VZ
616int wxNativeFontInfo::GetPointSize() const
617{
618 const wxString s = GetXFontComponent(wxXLFD_POINTSIZE);
619
620 // return -1 to indicate that the size is unknown
621 long l;
622 return s.ToLong(&l) ? l : -1;
623}
624
625wxFontStyle wxNativeFontInfo::GetStyle() const
626{
627 const wxString s = GetXFontComponent(wxXLFD_SLANT);
628
629 if ( s.length() != 1 )
630 {
631 // it is really unknown but we don't have any way to return it from
632 // here
633 return wxFONTSTYLE_NORMAL;
634 }
635
636 switch ( s[0] )
637 {
638 default:
639 // again, unknown but consider normal by default
640
641 case _T('r'):
642 return wxFONTSTYLE_NORMAL;
643
644 case _T('i'):
645 return wxFONTSTYLE_ITALIC;
646
647 case _T('o'):
648 return wxFONTSTYLE_SLANT;
649 }
650}
651
652wxFontWeight wxNativeFontInfo::GetWeight() const
653{
654 const wxString s = GetXFontComponent(wxXLFD_WEIGHT).MakeLower();
655 if ( s.find(_T("bold")) != wxString::npos || s == _T("black") )
656 return wxFONTWEIGHT_BOLD;
657 else if ( s == _T("light") )
658 return wxFONTWEIGHT_LIGHT;
659
660 return wxFONTWEIGHT_NORMAL;
661}
662
663bool wxNativeFontInfo::GetUnderlined() const
664{
665 // X fonts are never underlined
666 return FALSE;
667}
668
669wxString wxNativeFontInfo::GetFaceName() const
670{
77ffb593 671 // wxWidgets facename probably more accurately corresponds to X family
2b5f62a0
VZ
672 return GetXFontComponent(wxXLFD_FAMILY);
673}
674
675wxFontFamily wxNativeFontInfo::GetFamily() const
676{
77ffb593 677 // and wxWidgets family -- to X foundry, but we have to translate it to
2b5f62a0
VZ
678 // wxFontFamily somehow...
679 wxFAIL_MSG(_T("not implemented")); // GetXFontComponent(wxXLFD_FOUNDRY);
680
681 return wxFONTFAMILY_DEFAULT;
682}
683
684wxFontEncoding wxNativeFontInfo::GetEncoding() const
685{
686 // we already have the code for this but need to refactor it first
687 wxFAIL_MSG( _T("not implemented") );
688
689 return wxFONTENCODING_MAX;
690}
691
692void wxNativeFontInfo::SetPointSize(int pointsize)
693{
694 SetXFontComponent(wxXLFD_POINTSIZE, wxString::Format(_T("%d"), pointsize));
695}
696
697void wxNativeFontInfo::SetStyle(wxFontStyle style)
698{
699 wxString s;
700 switch ( style )
701 {
702 case wxFONTSTYLE_ITALIC:
703 s = _T('i');
704 break;
705
706 case wxFONTSTYLE_SLANT:
707 s = _T('o');
708 break;
709
710 case wxFONTSTYLE_NORMAL:
711 s = _T('r');
712
713 default:
714 wxFAIL_MSG( _T("unknown wxFontStyle in wxNativeFontInfo::SetStyle") );
715 return;
716 }
717
718 SetXFontComponent(wxXLFD_SLANT, s);
719}
720
721void wxNativeFontInfo::SetWeight(wxFontWeight weight)
722{
723 wxString s;
724 switch ( weight )
725 {
726 case wxFONTWEIGHT_BOLD:
727 s = _T("bold");
728 break;
729
730 case wxFONTWEIGHT_LIGHT:
731 s = _T("light");
732 break;
733
734 case wxFONTWEIGHT_NORMAL:
735 s = _T("medium");
736 break;
737
738 default:
739 wxFAIL_MSG( _T("unknown wxFontWeight in wxNativeFontInfo::SetWeight") );
740 return;
741 }
742
743 SetXFontComponent(wxXLFD_WEIGHT, s);
744}
745
746void wxNativeFontInfo::SetUnderlined(bool WXUNUSED(underlined))
747{
748 // can't do this under X
749}
750
751void wxNativeFontInfo::SetFaceName(wxString facename)
752{
753 SetXFontComponent(wxXLFD_FAMILY, facename);
754}
755
756void wxNativeFontInfo::SetFamily(wxFontFamily family)
757{
758 // wxFontFamily -> X foundry, anyone?
759 wxFAIL_MSG( _T("not implemented") );
760
761 // SetXFontComponent(wxXLFD_FOUNDRY, ...);
762}
763
764void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding)
765{
766 wxNativeEncodingInfo info;
767 if ( wxGetNativeFontEncoding(encoding, &info) )
768 {
769 SetXFontComponent(wxXLFD_ENCODING, info.xencoding);
770 SetXFontComponent(wxXLFD_REGISTRY, info.xregistry);
771 }
772}
773
7beba2fc
VZ
774// ----------------------------------------------------------------------------
775// common functions
776// ----------------------------------------------------------------------------
777
778bool wxGetNativeFontEncoding(wxFontEncoding encoding,
779 wxNativeEncodingInfo *info)
780{
781 wxCHECK_MSG( info, FALSE, _T("bad pointer in wxGetNativeFontEncoding") );
782
783 if ( encoding == wxFONTENCODING_DEFAULT )
784 {
785 encoding = wxFont::GetDefaultEncoding();
786 }
787
788 switch ( encoding )
789 {
790 case wxFONTENCODING_ISO8859_1:
791 case wxFONTENCODING_ISO8859_2:
792 case wxFONTENCODING_ISO8859_3:
793 case wxFONTENCODING_ISO8859_4:
794 case wxFONTENCODING_ISO8859_5:
795 case wxFONTENCODING_ISO8859_6:
796 case wxFONTENCODING_ISO8859_7:
797 case wxFONTENCODING_ISO8859_8:
798 case wxFONTENCODING_ISO8859_9:
799 case wxFONTENCODING_ISO8859_10:
800 case wxFONTENCODING_ISO8859_11:
80a24267 801 case wxFONTENCODING_ISO8859_12:
7beba2fc
VZ
802 case wxFONTENCODING_ISO8859_13:
803 case wxFONTENCODING_ISO8859_14:
804 case wxFONTENCODING_ISO8859_15:
805 {
806 int cp = encoding - wxFONTENCODING_ISO8859_1 + 1;
807 info->xregistry = wxT("iso8859");
808 info->xencoding.Printf(wxT("%d"), cp);
809 }
810 break;
811
bb84929e 812 case wxFONTENCODING_UTF8:
5707316c 813 info->xregistry = wxT("iso10646");
bb84929e
VZ
814 info->xencoding = wxT("*");
815 break;
816
2b5f62a0 817 case wxFONTENCODING_GB2312:
82680055 818 info->xregistry = wxT("GB2312"); // or the otherway round?
2b5f62a0
VZ
819 info->xencoding = wxT("*");
820 break;
821
7beba2fc 822 case wxFONTENCODING_KOI8:
15ad38c3 823 case wxFONTENCODING_KOI8_U:
7beba2fc
VZ
824 info->xregistry = wxT("koi8");
825
5707316c 826 // we don't make distinction between koi8-r, koi8-u and koi8-ru (so far)
7beba2fc
VZ
827 info->xencoding = wxT("*");
828 break;
829
830 case wxFONTENCODING_CP1250:
831 case wxFONTENCODING_CP1251:
832 case wxFONTENCODING_CP1252:
833 case wxFONTENCODING_CP1253:
834 case wxFONTENCODING_CP1254:
835 case wxFONTENCODING_CP1255:
836 case wxFONTENCODING_CP1256:
837 case wxFONTENCODING_CP1257:
838 {
839 int cp = encoding - wxFONTENCODING_CP1250 + 1250;
840 info->xregistry = wxT("microsoft");
841 info->xencoding.Printf(wxT("cp%d"), cp);
842 }
843 break;
844
d946915c
MB
845 case wxFONTENCODING_EUC_JP:
846 case wxFONTENCODING_SHIFT_JIS:
847 info->xregistry = "jis*";
848 info->xencoding = "*";
849 break;
850
7beba2fc
VZ
851 case wxFONTENCODING_SYSTEM:
852 info->xregistry =
81c67e27 853 info->xencoding = wxT("*");
7beba2fc
VZ
854 break;
855
856 default:
857 // don't know how to translate this encoding into X fontspec
858 return FALSE;
859 }
860
ab5fe833 861 info->encoding = encoding;
6b0eebc5 862
7beba2fc
VZ
863 return TRUE;
864}
865
866bool wxTestFontEncoding(const wxNativeEncodingInfo& info)
867{
868 wxString fontspec;
869 fontspec.Printf(_T("-*-%s-*-*-*-*-*-*-*-*-*-*-%s-%s"),
870 !info.facename ? _T("*") : info.facename.c_str(),
871 info.xregistry.c_str(),
872 info.xencoding.c_str());
873
874 return wxTestFontSpec(fontspec);
875}
876
877// ----------------------------------------------------------------------------
878// X-specific functions
879// ----------------------------------------------------------------------------
880
881wxNativeFont wxLoadQueryNearestFont(int pointSize,
882 int family,
883 int style,
884 int weight,
885 bool underlined,
886 const wxString &facename,
30764ab5
VZ
887 wxFontEncoding encoding,
888 wxString* xFontName)
7beba2fc 889{
97d3f0ee
VZ
890 if ( encoding == wxFONTENCODING_DEFAULT )
891 {
892 encoding = wxFont::GetDefaultEncoding();
893 }
894
7beba2fc
VZ
895 // first determine the encoding - if the font doesn't exist at all in this
896 // encoding, it's useless to do all other approximations (i.e. size,
897 // family &c don't matter much)
898 wxNativeEncodingInfo info;
97d3f0ee 899 if ( encoding == wxFONTENCODING_SYSTEM )
81c67e27
RR
900 {
901 // This will always work so we don't test to save time
902 wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM, &info);
903 }
904 else
7beba2fc 905 {
81c67e27
RR
906 if ( !wxGetNativeFontEncoding(encoding, &info) ||
907 !wxTestFontEncoding(info) )
7beba2fc 908 {
1e6feb95 909#if wxUSE_FONTMAP
142b3bc2 910 if ( !wxFontMapper::Get()->GetAltForEncoding(encoding, &info) )
1e6feb95 911#endif // wxUSE_FONTMAP
81c67e27
RR
912 {
913 // unspported encoding - replace it with the default
914 //
915 // NB: we can't just return 0 from here because wxGTK code doesn't
916 // check for it (i.e. it supposes that we'll always succeed),
917 // so it would provoke a crash
918 wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM, &info);
919 }
97d3f0ee 920 }
7beba2fc 921 }
6c49baf2 922
81c67e27 923 // OK, we have the correct xregistry/xencoding in info structure
30764ab5
VZ
924 wxNativeFont font = 0;
925
926 // if we already have the X font name, try to use it
927 if( xFontName && !xFontName->IsEmpty() )
6c49baf2
VZ
928 {
929 //
930 // Make sure point size is correct for scale factor.
931 //
932 wxStringTokenizer tokenizer(*xFontName, _T("-"), wxTOKEN_RET_DELIMS);
933 wxString newFontName;
934
935 for(int i = 0; i < 8; i++)
936 newFontName += tokenizer.NextToken();
937
938 (void) tokenizer.NextToken();
939
401eb3de 940 newFontName += wxString::Format(wxT("%d-"), pointSize);
6c49baf2
VZ
941
942 while(tokenizer.HasMoreTokens())
943 newFontName += tokenizer.GetNextToken();
944
945 font = wxLoadFont(newFontName);
946
947 if(font)
948 *xFontName = newFontName;
949 }
30764ab5 950
7beba2fc
VZ
951 if ( !font )
952 {
953 // search up and down by stepsize 10
954 int max_size = pointSize + 20 * (1 + (pointSize/180));
955 int min_size = pointSize - 20 * (1 + (pointSize/180));
956
34791896 957 int i, round; // counters
7beba2fc 958
34791896
RR
959 // first round: search for equal, then for smaller and for larger size with the given weight and style
960 int testweight = weight;
961 int teststyle = style;
962
963 for ( round = 0; round < 3; round++ )
964 {
965 // second round: use normal weight
966 if ( round == 1 )
b12401e0 967 {
34791896
RR
968 if ( testweight != wxNORMAL )
969 {
970 testweight = wxNORMAL;
971 }
972 else
973 {
974 ++round; // fall through to third round
975 }
976 }
977
978 // third round: ... and use normal style
979 if ( round == 2 )
980 {
981 if ( teststyle != wxNORMAL )
982 {
983 teststyle = wxNORMAL;
984 }
985 else
986 {
987 break;
988 }
989 }
990 // Search for equal or smaller size (approx.)
991 for ( i = pointSize; !font && i >= 10 && i >= min_size; i -= 10 )
992 {
993 font = wxLoadQueryFont(i, family, teststyle, testweight, underlined,
30764ab5
VZ
994 facename, info.xregistry, info.xencoding,
995 xFontName);
b12401e0 996 }
7beba2fc 997
b12401e0
MB
998 // Search for larger size (approx.)
999 for ( i = pointSize + 10; !font && i <= max_size; i += 10 )
1000 {
34791896 1001 font = wxLoadQueryFont(i, family, teststyle, testweight, underlined,
30764ab5
VZ
1002 facename, info.xregistry, info.xencoding,
1003 xFontName);
34791896 1004 }
7beba2fc
VZ
1005 }
1006
1007 // Try default family
1008 if ( !font && family != wxDEFAULT )
1009 {
1010 font = wxLoadQueryFont(pointSize, wxDEFAULT, style, weight,
1011 underlined, facename,
30764ab5
VZ
1012 info.xregistry, info.xencoding,
1013 xFontName );
7beba2fc
VZ
1014 }
1015
f139dfe8
VZ
1016 // ignore size, family, style and weight but try to find font with the
1017 // given facename and encoding
7beba2fc
VZ
1018 if ( !font )
1019 {
1020 font = wxLoadQueryFont(120, wxDEFAULT, wxNORMAL, wxNORMAL,
1021 underlined, facename,
30764ab5
VZ
1022 info.xregistry, info.xencoding,
1023 xFontName);
7beba2fc 1024
f139dfe8
VZ
1025 // ignore family as well
1026 if ( !font )
1027 {
1028 font = wxLoadQueryFont(120, wxDEFAULT, wxNORMAL, wxNORMAL,
1029 underlined, wxEmptyString,
1030 info.xregistry, info.xencoding,
1031 xFontName);
1032
1033 // if it still failed, try to get the font of any size but
1034 // with the requested encoding: this can happen if the
1035 // encoding is only available in one size which happens to be
1036 // different from 120
1037 if ( !font )
1038 {
1039 font = wxLoadQueryFont(-1, wxDEFAULT, wxNORMAL, wxNORMAL,
1040 FALSE, wxEmptyString,
1041 info.xregistry, info.xencoding,
1042 xFontName);
1043
1044 // this should never happen as we had tested for it in the
1045 // very beginning, but if it does, do return something non
1046 // NULL or we'd crash in wxFont code
1047 if ( !font )
1048 {
1049 wxFAIL_MSG( _T("this encoding should be available!") );
1050
1051 font = wxLoadQueryFont(-1,
1052 wxDEFAULT, wxNORMAL, wxNORMAL,
1053 FALSE, wxEmptyString,
1054 _T("*"), _T("*"),
1055 xFontName);
1056 }
1057 }
1058 }
7beba2fc
VZ
1059 }
1060 }
1061
1062 return font;
1063}
1064
1065// ----------------------------------------------------------------------------
1066// private functions
1067// ----------------------------------------------------------------------------
1068
1069// returns TRUE if there are any fonts matching this font spec
1070static bool wxTestFontSpec(const wxString& fontspec)
1071{
97d3f0ee
VZ
1072 // some X servers will fail to load this font because there are too many
1073 // matches so we must test explicitly for this
1074 if ( fontspec == _T("-*-*-*-*-*-*-*-*-*-*-*-*-*-*") )
1075 {
1076 return TRUE;
1077 }
1078
2e0e025e
RR
1079 wxNativeFont test = (wxNativeFont) g_fontHash->Get( fontspec );
1080 if (test)
1081 {
2e0e025e
RR
1082 return TRUE;
1083 }
1084
1085 test = wxLoadFont(fontspec);
1086 g_fontHash->Put( fontspec, (wxObject*) test );
6c49baf2 1087
7beba2fc
VZ
1088 if ( test )
1089 {
1090 wxFreeFont(test);
1091
1092 return TRUE;
1093 }
1094 else
1095 {
1096 return FALSE;
1097 }
1098}
1099
1100static wxNativeFont wxLoadQueryFont(int pointSize,
1101 int family,
1102 int style,
1103 int weight,
1104 bool WXUNUSED(underlined),
1105 const wxString& facename,
1106 const wxString& xregistry,
30764ab5
VZ
1107 const wxString& xencoding,
1108 wxString* xFontName)
7beba2fc
VZ
1109{
1110 wxString xfamily;
1111 switch (family)
1112 {
1113 case wxDECORATIVE: xfamily = wxT("lucida"); break;
1114 case wxROMAN: xfamily = wxT("times"); break;
1115 case wxMODERN: xfamily = wxT("courier"); break;
1116 case wxSWISS: xfamily = wxT("helvetica"); break;
1117 case wxTELETYPE: xfamily = wxT("lucidatypewriter"); break;
1118 case wxSCRIPT: xfamily = wxT("utopia"); break;
1119 default: xfamily = wxT("*");
1120 }
16d865f7 1121#if wxUSE_NANOX
c2ff68d3
JS
1122 int xweight;
1123 switch (weight)
1124 {
1125 case wxBOLD:
1126 {
1127 xweight = MWLF_WEIGHT_BOLD;
1128 break;
1129 }
1130 case wxLIGHT:
1131 {
1132 xweight = MWLF_WEIGHT_LIGHT;
1133 break;
1134 }
1135 case wxNORMAL:
1136 {
1137 xweight = MWLF_WEIGHT_NORMAL;
1138 break;
1139 }
1140
1141 default:
1142 {
1143 xweight = MWLF_WEIGHT_DEFAULT;
1144 break;
1145 }
1146 }
16d865f7
JS
1147 GR_SCREEN_INFO screenInfo;
1148 GrGetScreenInfo(& screenInfo);
1149
1150 int yPixelsPerCM = screenInfo.ydpcm;
1151
0a68bc69 1152 // A point is 1/72 of an inch.
16d865f7 1153 // An inch is 2.541 cm.
0a68bc69 1154 // So pixelHeight = (pointSize / 72) (inches) * 2.541 (for cm) * yPixelsPerCM (for pixels)
c2ff68d3
JS
1155 // In fact pointSize is 10 * the normal point size so
1156 // divide by 10.
1157
15d5a947 1158 int pixelHeight = (int) ( (((float)pointSize) / 720.0) * 2.541 * (float) yPixelsPerCM) ;
c2ff68d3
JS
1159
1160 // An alternative: assume that the screen is 72 dpi.
0a68bc69
JS
1161 //int pixelHeight = (int) (((float)pointSize / 720.0) * 72.0) ;
1162 //int pixelHeight = (int) ((float)pointSize / 10.0) ;
2b5f62a0 1163
16d865f7
JS
1164 GR_LOGFONT logFont;
1165 logFont.lfHeight = pixelHeight;
1166 logFont.lfWidth = 0;
1167 logFont.lfEscapement = 0;
1168 logFont.lfOrientation = 0;
c2ff68d3 1169 logFont.lfWeight = xweight;
16d865f7
JS
1170 logFont.lfItalic = (style == wxNORMAL ? 0 : 1) ;
1171 logFont.lfUnderline = 0;
1172 logFont.lfStrikeOut = 0;
1173 logFont.lfCharSet = MWLF_CHARSET_DEFAULT; // TODO: select appropriate one
1174 logFont.lfOutPrecision = MWLF_TYPE_DEFAULT;
1175 logFont.lfClipPrecision = 0; // Not used
1176 logFont.lfRoman = (family == wxROMAN ? 1 : 0) ;
1177 logFont.lfSerif = (family == wxSWISS ? 0 : 1) ;
1178 logFont.lfSansSerif = !logFont.lfSerif ;
1179 logFont.lfModern = (family == wxMODERN ? 1 : 0) ;
1180 logFont.lfProportional = (family == wxTELETYPE ? 0 : 1) ;
1181 logFont.lfOblique = 0;
1182 logFont.lfSmallCaps = 0;
1183 logFont.lfPitch = 0; // 0 = default
1184 strcpy(logFont.lfFaceName, facename.c_str());
1185
1186 XFontStruct* fontInfo = (XFontStruct*) malloc(sizeof(XFontStruct));
1187 fontInfo->fid = GrCreateFont((GR_CHAR*) facename.c_str(), pixelHeight, & logFont);
1188 GrGetFontInfo(fontInfo->fid, & fontInfo->info);
1189 return (wxNativeFont) fontInfo;
2b5f62a0 1190
16d865f7 1191#else
7beba2fc
VZ
1192 wxString fontSpec;
1193 if (!facename.IsEmpty())
1194 {
1195 fontSpec.Printf(wxT("-*-%s-*-*-normal-*-*-*-*-*-*-*-*-*"),
1196 facename.c_str());
1197
1198 if ( wxTestFontSpec(fontSpec) )
1199 {
1200 xfamily = facename;
1201 }
1202 //else: no such family, use default one instead
1203 }
1204
1205 wxString xstyle;
1206 switch (style)
1207 {
f9dbf34f
VZ
1208 case wxSLANT:
1209 fontSpec.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
1210 xfamily.c_str());
1211 if ( wxTestFontSpec(fontSpec) )
1212 {
1213 xstyle = wxT("o");
1214 break;
1215 }
1216 // fall through - try wxITALIC now
1217
1218 case wxITALIC:
1219 fontSpec.Printf(wxT("-*-%s-*-i-*-*-*-*-*-*-*-*-*-*"),
1220 xfamily.c_str());
1221 if ( wxTestFontSpec(fontSpec) )
1222 {
1223 xstyle = wxT("i");
1224 }
1225 else if ( style == wxITALIC ) // and not wxSLANT
1226 {
1227 // try wxSLANT
1228 fontSpec.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
1229 xfamily.c_str());
1230 if ( wxTestFontSpec(fontSpec) )
1231 {
1232 xstyle = wxT("o");
1233 }
1234 else
1235 {
1236 // no italic, no slant - leave default
1237 xstyle = wxT("*");
1238 }
1239 }
1240 break;
1241
1242 default:
1243 wxFAIL_MSG(_T("unknown font style"));
1244 // fall back to normal
1245
1246 case wxNORMAL:
1247 xstyle = wxT("r");
1248 break;
7beba2fc
VZ
1249 }
1250
1251 wxString xweight;
1252 switch (weight)
1253 {
1254 case wxBOLD:
1255 {
1256 fontSpec.Printf(wxT("-*-%s-bold-*-*-*-*-*-*-*-*-*-*-*"),
1257 xfamily.c_str());
1258 if ( wxTestFontSpec(fontSpec) )
1259 {
1260 xweight = wxT("bold");
1261 break;
1262 }
1263 fontSpec.Printf(wxT("-*-%s-heavy-*-*-*-*-*-*-*-*-*-*-*"),
1264 xfamily.c_str());
1265 if ( wxTestFontSpec(fontSpec) )
1266 {
1267 xweight = wxT("heavy");
1268 break;
1269 }
1270 fontSpec.Printf(wxT("-*-%s-extrabold-*-*-*-*-*-*-*-*-*-*-*"),
1271 xfamily.c_str());
1272 if ( wxTestFontSpec(fontSpec) )
1273 {
1274 xweight = wxT("extrabold");
1275 break;
1276 }
1277 fontSpec.Printf(wxT("-*-%s-demibold-*-*-*-*-*-*-*-*-*-*-*"),
1278 xfamily.c_str());
1279 if ( wxTestFontSpec(fontSpec) )
1280 {
1281 xweight = wxT("demibold");
1282 break;
1283 }
1284 fontSpec.Printf(wxT("-*-%s-black-*-*-*-*-*-*-*-*-*-*-*"),
1285 xfamily.c_str());
1286 if ( wxTestFontSpec(fontSpec) )
1287 {
1288 xweight = wxT("black");
1289 break;
1290 }
1291 fontSpec.Printf(wxT("-*-%s-ultrablack-*-*-*-*-*-*-*-*-*-*-*"),
1292 xfamily.c_str());
1293 if ( wxTestFontSpec(fontSpec) )
1294 {
1295 xweight = wxT("ultrablack");
1296 break;
1297 }
1298 }
1299 break;
1300 case wxLIGHT:
1301 {
1302 fontSpec.Printf(wxT("-*-%s-light-*-*-*-*-*-*-*-*-*-*-*"),
1303 xfamily.c_str());
1304 if ( wxTestFontSpec(fontSpec) )
1305 {
1306 xweight = wxT("light");
1307 break;
1308 }
1309 fontSpec.Printf(wxT("-*-%s-thin-*-*-*-*-*-*-*-*-*-*-*"),
1310 xfamily.c_str());
1311 if ( wxTestFontSpec(fontSpec) )
1312 {
1313 xweight = wxT("thin");
1314 break;
1315 }
1316 }
1317 break;
1318 case wxNORMAL:
1319 {
1320 fontSpec.Printf(wxT("-*-%s-medium-*-*-*-*-*-*-*-*-*-*-*"),
1321 xfamily.c_str());
1322 if ( wxTestFontSpec(fontSpec) )
1323 {
1324 xweight = wxT("medium");
1325 break;
1326 }
1327 fontSpec.Printf(wxT("-*-%s-normal-*-*-*-*-*-*-*-*-*-*-*"),
1328 xfamily.c_str());
1329 if ( wxTestFontSpec(fontSpec) )
1330 {
1331 xweight = wxT("normal");
1332 break;
1333 }
1334 fontSpec.Printf(wxT("-*-%s-regular-*-*-*-*-*-*-*-*-*-*-*"),
1335 xfamily.c_str());
1336 if ( wxTestFontSpec(fontSpec) )
1337 {
1338 xweight = wxT("regular");
1339 break;
1340 }
1341 xweight = wxT("*");
1342 }
1343 break;
1344 default: xweight = wxT("*"); break;
1345 }
1346
f139dfe8
VZ
1347 // if pointSize is -1, don't specify any
1348 wxString sizeSpec;
73b0423d 1349 if ( pointSize == -1 )
f139dfe8
VZ
1350 {
1351 sizeSpec = _T('*');
1352 }
1353 else
1354 {
1355 sizeSpec.Printf(_T("%d"), pointSize);
1356 }
1357
7beba2fc 1358 // construct the X font spec from our data
f139dfe8 1359 fontSpec.Printf(wxT("-*-%s-%s-%s-normal-*-*-%s-*-*-*-*-%s-%s"),
7beba2fc 1360 xfamily.c_str(), xweight.c_str(), xstyle.c_str(),
f139dfe8 1361 sizeSpec.c_str(), xregistry.c_str(), xencoding.c_str());
7beba2fc 1362
30764ab5
VZ
1363 if( xFontName )
1364 *xFontName = fontSpec;
1365
7beba2fc 1366 return wxLoadFont(fontSpec);
16d865f7
JS
1367#endif
1368 // wxUSE_NANOX
7beba2fc
VZ
1369}
1370
2e0e025e
RR
1371// ----------------------------------------------------------------------------
1372// wxFontModule
1373// ----------------------------------------------------------------------------
1374
1375class wxFontModule : public wxModule
1376{
1377public:
1378 bool OnInit();
1379 void OnExit();
1380
1381private:
1382 DECLARE_DYNAMIC_CLASS(wxFontModule)
1383};
1384
1385IMPLEMENT_DYNAMIC_CLASS(wxFontModule, wxModule)
1386
1387bool wxFontModule::OnInit()
1388{
1389 g_fontHash = new wxHashTable( wxKEY_STRING );
1390
1391 return TRUE;
1392}
1393
1394void wxFontModule::OnExit()
1395{
1396 delete g_fontHash;
1397
1398 g_fontHash = (wxHashTable *)NULL;
1399}
db16cab4 1400
2b5f62a0
VZ
1401#endif // GTK 2.0/1.x
1402