1 /////////////////////////////////////////////////////////////////////////////
2 // Name: unix/fontutil.cpp
3 // Purpose: Font helper functions for X11 (GDK/X)
4 // Author: Vadim Zeitlin
8 // Copyright: (c) Vadim Zeitlin
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "fontutil.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
34 #include "wx/fontutil.h"
35 #include "wx/fontmap.h"
36 #include "wx/tokenzr.h"
38 #include "wx/module.h"
42 #include "wx/gtk/private.h"
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 void wxNativeFontInfo::Init()
53 int wxNativeFontInfo::GetPointSize() const
55 return pango_font_description_get_size( description
) / PANGO_SCALE
;
58 wxFontStyle
wxNativeFontInfo::GetStyle() const
60 wxFontStyle m_style
= wxFONTSTYLE_NORMAL
;
62 switch (pango_font_description_get_style( description
))
64 case PANGO_STYLE_NORMAL
:
65 m_style
= wxFONTSTYLE_NORMAL
;
67 case PANGO_STYLE_ITALIC
:
68 m_style
= wxFONTSTYLE_ITALIC
;
70 case PANGO_STYLE_OBLIQUE
:
71 m_style
= wxFONTSTYLE_SLANT
;
78 wxFontWeight
wxNativeFontInfo::GetWeight() const
80 wxFontWeight m_weight
= wxFONTWEIGHT_NORMAL
;
82 switch (pango_font_description_get_weight( description
))
84 case PANGO_WEIGHT_ULTRALIGHT
:
85 m_weight
= wxFONTWEIGHT_LIGHT
;
87 case PANGO_WEIGHT_LIGHT
:
88 m_weight
= wxFONTWEIGHT_LIGHT
;
90 case PANGO_WEIGHT_NORMAL
:
91 m_weight
= wxFONTWEIGHT_NORMAL
;
93 case PANGO_WEIGHT_BOLD
:
94 m_weight
= wxFONTWEIGHT_BOLD
;
96 case PANGO_WEIGHT_ULTRABOLD
:
97 m_weight
= wxFONTWEIGHT_BOLD
;
99 case PANGO_WEIGHT_HEAVY
:
100 m_weight
= wxFONTWEIGHT_BOLD
;
107 bool wxNativeFontInfo::GetUnderlined() const
112 wxString
wxNativeFontInfo::GetFaceName() const
114 wxString tmp
= wxGTK_CONV_BACK( pango_font_description_get_family( description
) );
119 wxFontFamily
wxNativeFontInfo::GetFamily() const
121 return wxFONTFAMILY_SWISS
;
124 wxFontEncoding
wxNativeFontInfo::GetEncoding() const
126 return wxFONTENCODING_SYSTEM
;
129 bool wxNativeFontInfo::FromString(const wxString
& s
)
132 pango_font_description_free( description
);
134 description
= pango_font_description_from_string( wxGTK_CONV( s
) );
139 wxString
wxNativeFontInfo::ToString() const
141 wxString tmp
= wxGTK_CONV_BACK( pango_font_description_to_string( description
) );
146 bool wxNativeFontInfo::FromUserString(const wxString
& s
)
148 return FromString( s
);
151 wxString
wxNativeFontInfo::ToUserString() const
156 // ----------------------------------------------------------------------------
157 // wxNativeEncodingInfo
158 // ----------------------------------------------------------------------------
160 bool wxNativeEncodingInfo::FromString(const wxString
& s
)
165 wxString
wxNativeEncodingInfo::ToString() const
167 return wxEmptyString
;
170 bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
)
175 bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
176 wxNativeEncodingInfo
*info
)
186 #pragma message disable nosimpint
189 #include <X11/Xlib.h>
192 #pragma message enable nosimpint
195 #include "wx/utils.h" // for wxGetDisplay()
196 #elif defined(__WXGTK__)
197 // we have to declare struct tm to avoid problems with first forward
198 // declaring it in C code (glib.h included from gdk.h does it) and then
199 // defining it when time.h is included from the headers below - this is
200 // known not to work at least with Sun CC 6.01
207 // ----------------------------------------------------------------------------
209 // ----------------------------------------------------------------------------
211 static wxHashTable
*g_fontHash
= (wxHashTable
*) NULL
;
213 // ----------------------------------------------------------------------------
215 // ----------------------------------------------------------------------------
217 // define the functions to create and destroy native fonts for this toolkit
219 wxNativeFont
wxLoadFont(const wxString
& fontSpec
)
221 return XLoadQueryFont((Display
*)wxGetDisplay(), fontSpec
);
224 inline void wxFreeFont(wxNativeFont font
)
226 XFreeFont((Display
*)wxGetDisplay(), (XFontStruct
*)font
);
228 #elif defined(__WXGTK__)
229 wxNativeFont
wxLoadFont(const wxString
& fontSpec
)
231 return gdk_font_load( wxConvertWX2MB(fontSpec
) );
234 inline void wxFreeFont(wxNativeFont font
)
236 gdk_font_unref(font
);
239 #error "Unknown GUI toolkit"
242 static bool wxTestFontSpec(const wxString
& fontspec
);
244 static wxNativeFont
wxLoadQueryFont(int pointSize
,
249 const wxString
& facename
,
250 const wxString
& xregistry
,
251 const wxString
& xencoding
,
252 wxString
* xFontName
);
254 // ============================================================================
256 // ============================================================================
258 // ----------------------------------------------------------------------------
259 // wxNativeEncodingInfo
260 // ----------------------------------------------------------------------------
262 // convert to/from the string representation: format is
263 // encodingid;registry;encoding[;facename]
264 bool wxNativeEncodingInfo::FromString(const wxString
& s
)
266 // use ";", not "-" because it may be part of encoding name
267 wxStringTokenizer
tokenizer(s
, _T(";"));
269 wxString encid
= tokenizer
.GetNextToken();
271 if ( !encid
.ToLong(&enc
) )
273 encoding
= (wxFontEncoding
)enc
;
275 xregistry
= tokenizer
.GetNextToken();
279 xencoding
= tokenizer
.GetNextToken();
284 facename
= tokenizer
.GetNextToken();
289 wxString
wxNativeEncodingInfo::ToString() const
292 s
<< (long)encoding
<< _T(';') << xregistry
<< _T(';') << xencoding
;
295 s
<< _T(';') << facename
;
301 // ----------------------------------------------------------------------------
303 // ----------------------------------------------------------------------------
305 void wxNativeFontInfo::Init()
310 bool wxNativeFontInfo::FromString(const wxString
& s
)
312 wxStringTokenizer
tokenizer(s
, _T(";"));
315 wxString token
= tokenizer
.GetNextToken();
316 if ( token
!= _T('0') )
319 xFontName
= tokenizer
.GetNextToken();
321 // this should be the end
322 if ( tokenizer
.HasMoreTokens() )
325 return FromXFontName(xFontName
);
328 wxString
wxNativeFontInfo::ToString() const
331 return wxString::Format(_T("%d;%s"), 0, GetXFontName().c_str());
334 bool wxNativeFontInfo::FromUserString(const wxString
& s
)
336 return FromXFontName(s
);
339 wxString
wxNativeFontInfo::ToUserString() const
341 return GetXFontName();
344 bool wxNativeFontInfo::HasElements() const
346 // we suppose that the foundry is never empty, so if it is it means that we
347 // had never parsed the XLFD
348 return !fontElements
[0].empty();
351 wxString
wxNativeFontInfo::GetXFontComponent(wxXLFDField field
) const
353 wxCHECK_MSG( field
< wxXLFD_MAX
, _T(""), _T("invalid XLFD field") );
355 if ( !HasElements() )
358 if ( !((wxNativeFontInfo
*)this)->FromXFontName(xFontName
) )
362 return fontElements
[field
];
365 bool wxNativeFontInfo::FromXFontName(const wxString
& fontname
)
367 // TODO: we should be able to handle the font aliases here, but how?
368 wxStringTokenizer
tokenizer(fontname
, _T("-"));
370 // skip the leading, usually empty field (font name registry)
371 if ( !tokenizer
.HasMoreTokens() )
374 (void)tokenizer
.GetNextToken();
376 for ( size_t n
= 0; n
< WXSIZEOF(fontElements
); n
++ )
378 if ( !tokenizer
.HasMoreTokens() )
380 // not enough elements in the XLFD - or maybe an alias
384 fontElements
[n
] = tokenizer
.GetNextToken();
387 // this should be all
388 return !tokenizer
.HasMoreTokens();
391 wxString
wxNativeFontInfo::GetXFontName() const
393 if ( xFontName
.empty() )
395 for ( size_t n
= 0; n
< WXSIZEOF(fontElements
); n
++ )
397 // replace the non specified elements with '*' except for the
398 // additional style which is usually just omitted
399 wxString elt
= fontElements
[n
];
400 if ( elt
.empty() && n
!= wxXLFD_ADDSTYLE
)
406 ((wxNativeFontInfo
*)this)->xFontName
<< _T('-') << elt
;
414 wxNativeFontInfo::SetXFontComponent(wxXLFDField field
, const wxString
& value
)
416 wxCHECK_RET( field
< wxXLFD_MAX
, _T("invalid XLFD field") );
418 // this class should be initialized with a valid font spec first and only
419 // then the fields may be modified!
420 wxASSERT_MSG( !IsDefault(), _T("can't modify an uninitialized XLFD") );
422 if ( !HasElements() )
425 if ( !((wxNativeFontInfo
*)this)->FromXFontName(xFontName
) )
427 wxFAIL_MSG( _T("can't set font element for invalid XLFD") );
433 fontElements
[field
] = value
;
435 // invalidate the XFLD, it doesn't correspond to the font elements any more
439 void wxNativeFontInfo::SetXFontName(const wxString
& xFontName_
)
441 // invalidate the font elements, GetXFontComponent() will reparse the XLFD
442 fontElements
[0].clear();
444 xFontName
= xFontName_
;
449 // ----------------------------------------------------------------------------
451 // ----------------------------------------------------------------------------
453 bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
454 wxNativeEncodingInfo
*info
)
456 wxCHECK_MSG( info
, FALSE
, _T("bad pointer in wxGetNativeFontEncoding") );
458 if ( encoding
== wxFONTENCODING_DEFAULT
)
460 encoding
= wxFont::GetDefaultEncoding();
465 case wxFONTENCODING_ISO8859_1
:
466 case wxFONTENCODING_ISO8859_2
:
467 case wxFONTENCODING_ISO8859_3
:
468 case wxFONTENCODING_ISO8859_4
:
469 case wxFONTENCODING_ISO8859_5
:
470 case wxFONTENCODING_ISO8859_6
:
471 case wxFONTENCODING_ISO8859_7
:
472 case wxFONTENCODING_ISO8859_8
:
473 case wxFONTENCODING_ISO8859_9
:
474 case wxFONTENCODING_ISO8859_10
:
475 case wxFONTENCODING_ISO8859_11
:
476 case wxFONTENCODING_ISO8859_12
:
477 case wxFONTENCODING_ISO8859_13
:
478 case wxFONTENCODING_ISO8859_14
:
479 case wxFONTENCODING_ISO8859_15
:
481 int cp
= encoding
- wxFONTENCODING_ISO8859_1
+ 1;
482 info
->xregistry
= wxT("iso8859");
483 info
->xencoding
.Printf(wxT("%d"), cp
);
487 case wxFONTENCODING_UTF8
:
488 info
->xregistry
= wxT("iso10646");
489 info
->xencoding
= wxT("*");
492 case wxFONTENCODING_KOI8
:
493 info
->xregistry
= wxT("koi8");
495 // we don't make distinction between koi8-r, koi8-u and koi8-ru (so far)
496 info
->xencoding
= wxT("*");
499 case wxFONTENCODING_CP1250
:
500 case wxFONTENCODING_CP1251
:
501 case wxFONTENCODING_CP1252
:
502 case wxFONTENCODING_CP1253
:
503 case wxFONTENCODING_CP1254
:
504 case wxFONTENCODING_CP1255
:
505 case wxFONTENCODING_CP1256
:
506 case wxFONTENCODING_CP1257
:
508 int cp
= encoding
- wxFONTENCODING_CP1250
+ 1250;
509 info
->xregistry
= wxT("microsoft");
510 info
->xencoding
.Printf(wxT("cp%d"), cp
);
514 case wxFONTENCODING_SYSTEM
:
516 info
->xencoding
= wxT("*");
520 // don't know how to translate this encoding into X fontspec
524 info
->encoding
= encoding
;
529 bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
)
532 fontspec
.Printf(_T("-*-%s-*-*-*-*-*-*-*-*-*-*-%s-%s"),
533 !info
.facename
? _T("*") : info
.facename
.c_str(),
534 info
.xregistry
.c_str(),
535 info
.xencoding
.c_str());
537 return wxTestFontSpec(fontspec
);
540 // ----------------------------------------------------------------------------
541 // X-specific functions
542 // ----------------------------------------------------------------------------
544 wxNativeFont
wxLoadQueryNearestFont(int pointSize
,
549 const wxString
&facename
,
550 wxFontEncoding encoding
,
553 if ( encoding
== wxFONTENCODING_DEFAULT
)
555 encoding
= wxFont::GetDefaultEncoding();
558 // first determine the encoding - if the font doesn't exist at all in this
559 // encoding, it's useless to do all other approximations (i.e. size,
560 // family &c don't matter much)
561 wxNativeEncodingInfo info
;
562 if ( encoding
== wxFONTENCODING_SYSTEM
)
564 // This will always work so we don't test to save time
565 wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM
, &info
);
569 if ( !wxGetNativeFontEncoding(encoding
, &info
) ||
570 !wxTestFontEncoding(info
) )
573 if ( !wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
574 #endif // wxUSE_FONTMAP
576 // unspported encoding - replace it with the default
578 // NB: we can't just return 0 from here because wxGTK code doesn't
579 // check for it (i.e. it supposes that we'll always succeed),
580 // so it would provoke a crash
581 wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM
, &info
);
586 // OK, we have the correct xregistry/xencoding in info structure
587 wxNativeFont font
= 0;
589 // if we already have the X font name, try to use it
590 if( xFontName
&& !xFontName
->IsEmpty() )
593 // Make sure point size is correct for scale factor.
595 wxStringTokenizer
tokenizer(*xFontName
, _T("-"), wxTOKEN_RET_DELIMS
);
596 wxString newFontName
;
598 for(int i
= 0; i
< 8; i
++)
599 newFontName
+= tokenizer
.NextToken();
601 (void) tokenizer
.NextToken();
603 newFontName
+= wxString::Format(wxT("%d-"), pointSize
);
605 while(tokenizer
.HasMoreTokens())
606 newFontName
+= tokenizer
.GetNextToken();
608 font
= wxLoadFont(newFontName
);
611 *xFontName
= newFontName
;
614 // try to load exactly the font requested first
617 font
= wxLoadQueryFont( pointSize
, family
, style
, weight
,
618 underlined
, facename
,
619 info
.xregistry
, info
.xencoding
,
625 // search up and down by stepsize 10
626 int max_size
= pointSize
+ 20 * (1 + (pointSize
/180));
627 int min_size
= pointSize
- 20 * (1 + (pointSize
/180));
631 // Search for smaller size (approx.)
632 for ( i
= pointSize
- 10; !font
&& i
>= 10 && i
>= min_size
; i
-= 10 )
634 font
= wxLoadQueryFont(i
, family
, style
, weight
, underlined
,
635 facename
, info
.xregistry
, info
.xencoding
,
639 // Search for larger size (approx.)
640 for ( i
= pointSize
+ 10; !font
&& i
<= max_size
; i
+= 10 )
642 font
= wxLoadQueryFont(i
, family
, style
, weight
, underlined
,
643 facename
, info
.xregistry
, info
.xencoding
,
647 // Try default family
648 if ( !font
&& family
!= wxDEFAULT
)
650 font
= wxLoadQueryFont(pointSize
, wxDEFAULT
, style
, weight
,
651 underlined
, facename
,
652 info
.xregistry
, info
.xencoding
,
656 // ignore size, family, style and weight but try to find font with the
657 // given facename and encoding
660 font
= wxLoadQueryFont(120, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
661 underlined
, facename
,
662 info
.xregistry
, info
.xencoding
,
665 // ignore family as well
668 font
= wxLoadQueryFont(120, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
669 underlined
, wxEmptyString
,
670 info
.xregistry
, info
.xencoding
,
673 // if it still failed, try to get the font of any size but
674 // with the requested encoding: this can happen if the
675 // encoding is only available in one size which happens to be
676 // different from 120
679 font
= wxLoadQueryFont(-1, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
680 FALSE
, wxEmptyString
,
681 info
.xregistry
, info
.xencoding
,
684 // this should never happen as we had tested for it in the
685 // very beginning, but if it does, do return something non
686 // NULL or we'd crash in wxFont code
689 wxFAIL_MSG( _T("this encoding should be available!") );
691 font
= wxLoadQueryFont(-1,
692 wxDEFAULT
, wxNORMAL
, wxNORMAL
,
693 FALSE
, wxEmptyString
,
705 // ----------------------------------------------------------------------------
707 // ----------------------------------------------------------------------------
709 // returns TRUE if there are any fonts matching this font spec
710 static bool wxTestFontSpec(const wxString
& fontspec
)
712 // some X servers will fail to load this font because there are too many
713 // matches so we must test explicitly for this
714 if ( fontspec
== _T("-*-*-*-*-*-*-*-*-*-*-*-*-*-*") )
719 wxNativeFont test
= (wxNativeFont
) g_fontHash
->Get( fontspec
);
725 test
= wxLoadFont(fontspec
);
726 g_fontHash
->Put( fontspec
, (wxObject
*) test
);
740 static wxNativeFont
wxLoadQueryFont(int pointSize
,
744 bool WXUNUSED(underlined
),
745 const wxString
& facename
,
746 const wxString
& xregistry
,
747 const wxString
& xencoding
,
753 case wxDECORATIVE
: xfamily
= wxT("lucida"); break;
754 case wxROMAN
: xfamily
= wxT("times"); break;
755 case wxMODERN
: xfamily
= wxT("courier"); break;
756 case wxSWISS
: xfamily
= wxT("helvetica"); break;
757 case wxTELETYPE
: xfamily
= wxT("lucidatypewriter"); break;
758 case wxSCRIPT
: xfamily
= wxT("utopia"); break;
759 default: xfamily
= wxT("*");
767 xweight
= MWLF_WEIGHT_BOLD
;
772 xweight
= MWLF_WEIGHT_LIGHT
;
777 xweight
= MWLF_WEIGHT_NORMAL
;
783 xweight
= MWLF_WEIGHT_DEFAULT
;
787 GR_SCREEN_INFO screenInfo
;
788 GrGetScreenInfo(& screenInfo
);
790 int yPixelsPerCM
= screenInfo
.ydpcm
;
792 // A point is 1/72 of an inch.
793 // An inch is 2.541 cm.
794 // So pixelHeight = (pointSize / 72) (inches) * 2.541 (for cm) * yPixelsPerCM (for pixels)
795 // In fact pointSize is 10 * the normal point size so
798 int pixelHeight
= (int) ( (((float)pointSize
) / 720.0) * 2.541 * (float) yPixelsPerCM
) ;
800 // An alternative: assume that the screen is 72 dpi.
801 //int pixelHeight = (int) (((float)pointSize / 720.0) * 72.0) ;
802 //int pixelHeight = (int) ((float)pointSize / 10.0) ;
805 logFont
.lfHeight
= pixelHeight
;
807 logFont
.lfEscapement
= 0;
808 logFont
.lfOrientation
= 0;
809 logFont
.lfWeight
= xweight
;
810 logFont
.lfItalic
= (style
== wxNORMAL
? 0 : 1) ;
811 logFont
.lfUnderline
= 0;
812 logFont
.lfStrikeOut
= 0;
813 logFont
.lfCharSet
= MWLF_CHARSET_DEFAULT
; // TODO: select appropriate one
814 logFont
.lfOutPrecision
= MWLF_TYPE_DEFAULT
;
815 logFont
.lfClipPrecision
= 0; // Not used
816 logFont
.lfRoman
= (family
== wxROMAN
? 1 : 0) ;
817 logFont
.lfSerif
= (family
== wxSWISS
? 0 : 1) ;
818 logFont
.lfSansSerif
= !logFont
.lfSerif
;
819 logFont
.lfModern
= (family
== wxMODERN
? 1 : 0) ;
820 logFont
.lfProportional
= (family
== wxTELETYPE
? 0 : 1) ;
821 logFont
.lfOblique
= 0;
822 logFont
.lfSmallCaps
= 0;
823 logFont
.lfPitch
= 0; // 0 = default
824 strcpy(logFont
.lfFaceName
, facename
.c_str());
826 XFontStruct
* fontInfo
= (XFontStruct
*) malloc(sizeof(XFontStruct
));
827 fontInfo
->fid
= GrCreateFont((GR_CHAR
*) facename
.c_str(), pixelHeight
, & logFont
);
828 GrGetFontInfo(fontInfo
->fid
, & fontInfo
->info
);
829 return (wxNativeFont
) fontInfo
;
833 if (!facename
.IsEmpty())
835 fontSpec
.Printf(wxT("-*-%s-*-*-normal-*-*-*-*-*-*-*-*-*"),
838 if ( wxTestFontSpec(fontSpec
) )
842 //else: no such family, use default one instead
849 fontSpec
.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
851 if ( wxTestFontSpec(fontSpec
) )
856 // fall through - try wxITALIC now
859 fontSpec
.Printf(wxT("-*-%s-*-i-*-*-*-*-*-*-*-*-*-*"),
861 if ( wxTestFontSpec(fontSpec
) )
865 else if ( style
== wxITALIC
) // and not wxSLANT
868 fontSpec
.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
870 if ( wxTestFontSpec(fontSpec
) )
876 // no italic, no slant - leave default
883 wxFAIL_MSG(_T("unknown font style"));
884 // fall back to normal
896 fontSpec
.Printf(wxT("-*-%s-bold-*-*-*-*-*-*-*-*-*-*-*"),
898 if ( wxTestFontSpec(fontSpec
) )
900 xweight
= wxT("bold");
903 fontSpec
.Printf(wxT("-*-%s-heavy-*-*-*-*-*-*-*-*-*-*-*"),
905 if ( wxTestFontSpec(fontSpec
) )
907 xweight
= wxT("heavy");
910 fontSpec
.Printf(wxT("-*-%s-extrabold-*-*-*-*-*-*-*-*-*-*-*"),
912 if ( wxTestFontSpec(fontSpec
) )
914 xweight
= wxT("extrabold");
917 fontSpec
.Printf(wxT("-*-%s-demibold-*-*-*-*-*-*-*-*-*-*-*"),
919 if ( wxTestFontSpec(fontSpec
) )
921 xweight
= wxT("demibold");
924 fontSpec
.Printf(wxT("-*-%s-black-*-*-*-*-*-*-*-*-*-*-*"),
926 if ( wxTestFontSpec(fontSpec
) )
928 xweight
= wxT("black");
931 fontSpec
.Printf(wxT("-*-%s-ultrablack-*-*-*-*-*-*-*-*-*-*-*"),
933 if ( wxTestFontSpec(fontSpec
) )
935 xweight
= wxT("ultrablack");
942 fontSpec
.Printf(wxT("-*-%s-light-*-*-*-*-*-*-*-*-*-*-*"),
944 if ( wxTestFontSpec(fontSpec
) )
946 xweight
= wxT("light");
949 fontSpec
.Printf(wxT("-*-%s-thin-*-*-*-*-*-*-*-*-*-*-*"),
951 if ( wxTestFontSpec(fontSpec
) )
953 xweight
= wxT("thin");
960 fontSpec
.Printf(wxT("-*-%s-medium-*-*-*-*-*-*-*-*-*-*-*"),
962 if ( wxTestFontSpec(fontSpec
) )
964 xweight
= wxT("medium");
967 fontSpec
.Printf(wxT("-*-%s-normal-*-*-*-*-*-*-*-*-*-*-*"),
969 if ( wxTestFontSpec(fontSpec
) )
971 xweight
= wxT("normal");
974 fontSpec
.Printf(wxT("-*-%s-regular-*-*-*-*-*-*-*-*-*-*-*"),
976 if ( wxTestFontSpec(fontSpec
) )
978 xweight
= wxT("regular");
984 default: xweight
= wxT("*"); break;
987 // if pointSize is -1, don't specify any
989 if ( pointSize
== -1 )
995 sizeSpec
.Printf(_T("%d"), pointSize
);
998 // construct the X font spec from our data
999 fontSpec
.Printf(wxT("-*-%s-%s-%s-normal-*-*-%s-*-*-*-*-%s-%s"),
1000 xfamily
.c_str(), xweight
.c_str(), xstyle
.c_str(),
1001 sizeSpec
.c_str(), xregistry
.c_str(), xencoding
.c_str());
1004 *xFontName
= fontSpec
;
1006 return wxLoadFont(fontSpec
);
1011 // ----------------------------------------------------------------------------
1013 // ----------------------------------------------------------------------------
1015 class wxFontModule
: public wxModule
1022 DECLARE_DYNAMIC_CLASS(wxFontModule
)
1025 IMPLEMENT_DYNAMIC_CLASS(wxFontModule
, wxModule
)
1027 bool wxFontModule::OnInit()
1029 g_fontHash
= new wxHashTable( wxKEY_STRING
);
1034 void wxFontModule::OnExit()
1038 g_fontHash
= (wxHashTable
*)NULL
;