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 if ( tokenizer
.HasMoreTokens() )
391 // we're initialized now
397 wxString
wxNativeFontInfo::GetXFontName() const
399 if ( xFontName
.empty() )
401 for ( size_t n
= 0; n
< WXSIZEOF(fontElements
); n
++ )
403 // replace the non specified elements with '*' except for the
404 // additional style which is usually just omitted
405 wxString elt
= fontElements
[n
];
406 if ( elt
.empty() && n
!= wxXLFD_ADDSTYLE
)
412 ((wxNativeFontInfo
*)this)->xFontName
<< _T('-') << elt
;
420 wxNativeFontInfo::SetXFontComponent(wxXLFDField field
, const wxString
& value
)
422 wxCHECK_RET( field
< wxXLFD_MAX
, _T("invalid XLFD field") );
424 // this class should be initialized with a valid font spec first and only
425 // then the fields may be modified!
426 wxASSERT_MSG( !IsDefault(), _T("can't modify an uninitialized XLFD") );
428 if ( !HasElements() )
431 if ( !((wxNativeFontInfo
*)this)->FromXFontName(xFontName
) )
433 wxFAIL_MSG( _T("can't set font element for invalid XLFD") );
439 fontElements
[field
] = value
;
441 // invalidate the XFLD, it doesn't correspond to the font elements any more
445 void wxNativeFontInfo::SetXFontName(const wxString
& xFontName_
)
447 // invalidate the font elements, GetXFontComponent() will reparse the XLFD
448 fontElements
[0].clear();
450 xFontName
= xFontName_
;
455 // ----------------------------------------------------------------------------
457 // ----------------------------------------------------------------------------
459 bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
460 wxNativeEncodingInfo
*info
)
462 wxCHECK_MSG( info
, FALSE
, _T("bad pointer in wxGetNativeFontEncoding") );
464 if ( encoding
== wxFONTENCODING_DEFAULT
)
466 encoding
= wxFont::GetDefaultEncoding();
471 case wxFONTENCODING_ISO8859_1
:
472 case wxFONTENCODING_ISO8859_2
:
473 case wxFONTENCODING_ISO8859_3
:
474 case wxFONTENCODING_ISO8859_4
:
475 case wxFONTENCODING_ISO8859_5
:
476 case wxFONTENCODING_ISO8859_6
:
477 case wxFONTENCODING_ISO8859_7
:
478 case wxFONTENCODING_ISO8859_8
:
479 case wxFONTENCODING_ISO8859_9
:
480 case wxFONTENCODING_ISO8859_10
:
481 case wxFONTENCODING_ISO8859_11
:
482 case wxFONTENCODING_ISO8859_12
:
483 case wxFONTENCODING_ISO8859_13
:
484 case wxFONTENCODING_ISO8859_14
:
485 case wxFONTENCODING_ISO8859_15
:
487 int cp
= encoding
- wxFONTENCODING_ISO8859_1
+ 1;
488 info
->xregistry
= wxT("iso8859");
489 info
->xencoding
.Printf(wxT("%d"), cp
);
493 case wxFONTENCODING_UTF8
:
494 info
->xregistry
= wxT("iso10646");
495 info
->xencoding
= wxT("*");
498 case wxFONTENCODING_KOI8
:
499 info
->xregistry
= wxT("koi8");
501 // we don't make distinction between koi8-r, koi8-u and koi8-ru (so far)
502 info
->xencoding
= wxT("*");
505 case wxFONTENCODING_CP1250
:
506 case wxFONTENCODING_CP1251
:
507 case wxFONTENCODING_CP1252
:
508 case wxFONTENCODING_CP1253
:
509 case wxFONTENCODING_CP1254
:
510 case wxFONTENCODING_CP1255
:
511 case wxFONTENCODING_CP1256
:
512 case wxFONTENCODING_CP1257
:
514 int cp
= encoding
- wxFONTENCODING_CP1250
+ 1250;
515 info
->xregistry
= wxT("microsoft");
516 info
->xencoding
.Printf(wxT("cp%d"), cp
);
520 case wxFONTENCODING_SYSTEM
:
522 info
->xencoding
= wxT("*");
526 // don't know how to translate this encoding into X fontspec
530 info
->encoding
= encoding
;
535 bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
)
538 fontspec
.Printf(_T("-*-%s-*-*-*-*-*-*-*-*-*-*-%s-%s"),
539 !info
.facename
? _T("*") : info
.facename
.c_str(),
540 info
.xregistry
.c_str(),
541 info
.xencoding
.c_str());
543 return wxTestFontSpec(fontspec
);
546 // ----------------------------------------------------------------------------
547 // X-specific functions
548 // ----------------------------------------------------------------------------
550 wxNativeFont
wxLoadQueryNearestFont(int pointSize
,
555 const wxString
&facename
,
556 wxFontEncoding encoding
,
559 if ( encoding
== wxFONTENCODING_DEFAULT
)
561 encoding
= wxFont::GetDefaultEncoding();
564 // first determine the encoding - if the font doesn't exist at all in this
565 // encoding, it's useless to do all other approximations (i.e. size,
566 // family &c don't matter much)
567 wxNativeEncodingInfo info
;
568 if ( encoding
== wxFONTENCODING_SYSTEM
)
570 // This will always work so we don't test to save time
571 wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM
, &info
);
575 if ( !wxGetNativeFontEncoding(encoding
, &info
) ||
576 !wxTestFontEncoding(info
) )
579 if ( !wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
580 #endif // wxUSE_FONTMAP
582 // unspported encoding - replace it with the default
584 // NB: we can't just return 0 from here because wxGTK code doesn't
585 // check for it (i.e. it supposes that we'll always succeed),
586 // so it would provoke a crash
587 wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM
, &info
);
592 // OK, we have the correct xregistry/xencoding in info structure
593 wxNativeFont font
= 0;
595 // if we already have the X font name, try to use it
596 if( xFontName
&& !xFontName
->IsEmpty() )
599 // Make sure point size is correct for scale factor.
601 wxStringTokenizer
tokenizer(*xFontName
, _T("-"), wxTOKEN_RET_DELIMS
);
602 wxString newFontName
;
604 for(int i
= 0; i
< 8; i
++)
605 newFontName
+= tokenizer
.NextToken();
607 (void) tokenizer
.NextToken();
609 newFontName
+= wxString::Format(wxT("%d-"), pointSize
);
611 while(tokenizer
.HasMoreTokens())
612 newFontName
+= tokenizer
.GetNextToken();
614 font
= wxLoadFont(newFontName
);
617 *xFontName
= newFontName
;
620 // try to load exactly the font requested first
623 font
= wxLoadQueryFont( pointSize
, family
, style
, weight
,
624 underlined
, facename
,
625 info
.xregistry
, info
.xencoding
,
631 // search up and down by stepsize 10
632 int max_size
= pointSize
+ 20 * (1 + (pointSize
/180));
633 int min_size
= pointSize
- 20 * (1 + (pointSize
/180));
637 // Search for smaller size (approx.)
638 for ( i
= pointSize
- 10; !font
&& i
>= 10 && i
>= min_size
; i
-= 10 )
640 font
= wxLoadQueryFont(i
, family
, style
, weight
, underlined
,
641 facename
, info
.xregistry
, info
.xencoding
,
645 // Search for larger size (approx.)
646 for ( i
= pointSize
+ 10; !font
&& i
<= max_size
; i
+= 10 )
648 font
= wxLoadQueryFont(i
, family
, style
, weight
, underlined
,
649 facename
, info
.xregistry
, info
.xencoding
,
653 // Try default family
654 if ( !font
&& family
!= wxDEFAULT
)
656 font
= wxLoadQueryFont(pointSize
, wxDEFAULT
, style
, weight
,
657 underlined
, facename
,
658 info
.xregistry
, info
.xencoding
,
662 // ignore size, family, style and weight but try to find font with the
663 // given facename and encoding
666 font
= wxLoadQueryFont(120, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
667 underlined
, facename
,
668 info
.xregistry
, info
.xencoding
,
671 // ignore family as well
674 font
= wxLoadQueryFont(120, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
675 underlined
, wxEmptyString
,
676 info
.xregistry
, info
.xencoding
,
679 // if it still failed, try to get the font of any size but
680 // with the requested encoding: this can happen if the
681 // encoding is only available in one size which happens to be
682 // different from 120
685 font
= wxLoadQueryFont(-1, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
686 FALSE
, wxEmptyString
,
687 info
.xregistry
, info
.xencoding
,
690 // this should never happen as we had tested for it in the
691 // very beginning, but if it does, do return something non
692 // NULL or we'd crash in wxFont code
695 wxFAIL_MSG( _T("this encoding should be available!") );
697 font
= wxLoadQueryFont(-1,
698 wxDEFAULT
, wxNORMAL
, wxNORMAL
,
699 FALSE
, wxEmptyString
,
711 // ----------------------------------------------------------------------------
713 // ----------------------------------------------------------------------------
715 // returns TRUE if there are any fonts matching this font spec
716 static bool wxTestFontSpec(const wxString
& fontspec
)
718 // some X servers will fail to load this font because there are too many
719 // matches so we must test explicitly for this
720 if ( fontspec
== _T("-*-*-*-*-*-*-*-*-*-*-*-*-*-*") )
725 wxNativeFont test
= (wxNativeFont
) g_fontHash
->Get( fontspec
);
731 test
= wxLoadFont(fontspec
);
732 g_fontHash
->Put( fontspec
, (wxObject
*) test
);
746 static wxNativeFont
wxLoadQueryFont(int pointSize
,
750 bool WXUNUSED(underlined
),
751 const wxString
& facename
,
752 const wxString
& xregistry
,
753 const wxString
& xencoding
,
759 case wxDECORATIVE
: xfamily
= wxT("lucida"); break;
760 case wxROMAN
: xfamily
= wxT("times"); break;
761 case wxMODERN
: xfamily
= wxT("courier"); break;
762 case wxSWISS
: xfamily
= wxT("helvetica"); break;
763 case wxTELETYPE
: xfamily
= wxT("lucidatypewriter"); break;
764 case wxSCRIPT
: xfamily
= wxT("utopia"); break;
765 default: xfamily
= wxT("*");
773 xweight
= MWLF_WEIGHT_BOLD
;
778 xweight
= MWLF_WEIGHT_LIGHT
;
783 xweight
= MWLF_WEIGHT_NORMAL
;
789 xweight
= MWLF_WEIGHT_DEFAULT
;
793 GR_SCREEN_INFO screenInfo
;
794 GrGetScreenInfo(& screenInfo
);
796 int yPixelsPerCM
= screenInfo
.ydpcm
;
798 // A point is 1/72 of an inch.
799 // An inch is 2.541 cm.
800 // So pixelHeight = (pointSize / 72) (inches) * 2.541 (for cm) * yPixelsPerCM (for pixels)
801 // In fact pointSize is 10 * the normal point size so
804 int pixelHeight
= (int) ( (((float)pointSize
) / 720.0) * 2.541 * (float) yPixelsPerCM
) ;
806 // An alternative: assume that the screen is 72 dpi.
807 //int pixelHeight = (int) (((float)pointSize / 720.0) * 72.0) ;
808 //int pixelHeight = (int) ((float)pointSize / 10.0) ;
811 logFont
.lfHeight
= pixelHeight
;
813 logFont
.lfEscapement
= 0;
814 logFont
.lfOrientation
= 0;
815 logFont
.lfWeight
= xweight
;
816 logFont
.lfItalic
= (style
== wxNORMAL
? 0 : 1) ;
817 logFont
.lfUnderline
= 0;
818 logFont
.lfStrikeOut
= 0;
819 logFont
.lfCharSet
= MWLF_CHARSET_DEFAULT
; // TODO: select appropriate one
820 logFont
.lfOutPrecision
= MWLF_TYPE_DEFAULT
;
821 logFont
.lfClipPrecision
= 0; // Not used
822 logFont
.lfRoman
= (family
== wxROMAN
? 1 : 0) ;
823 logFont
.lfSerif
= (family
== wxSWISS
? 0 : 1) ;
824 logFont
.lfSansSerif
= !logFont
.lfSerif
;
825 logFont
.lfModern
= (family
== wxMODERN
? 1 : 0) ;
826 logFont
.lfProportional
= (family
== wxTELETYPE
? 0 : 1) ;
827 logFont
.lfOblique
= 0;
828 logFont
.lfSmallCaps
= 0;
829 logFont
.lfPitch
= 0; // 0 = default
830 strcpy(logFont
.lfFaceName
, facename
.c_str());
832 XFontStruct
* fontInfo
= (XFontStruct
*) malloc(sizeof(XFontStruct
));
833 fontInfo
->fid
= GrCreateFont((GR_CHAR
*) facename
.c_str(), pixelHeight
, & logFont
);
834 GrGetFontInfo(fontInfo
->fid
, & fontInfo
->info
);
835 return (wxNativeFont
) fontInfo
;
839 if (!facename
.IsEmpty())
841 fontSpec
.Printf(wxT("-*-%s-*-*-normal-*-*-*-*-*-*-*-*-*"),
844 if ( wxTestFontSpec(fontSpec
) )
848 //else: no such family, use default one instead
855 fontSpec
.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
857 if ( wxTestFontSpec(fontSpec
) )
862 // fall through - try wxITALIC now
865 fontSpec
.Printf(wxT("-*-%s-*-i-*-*-*-*-*-*-*-*-*-*"),
867 if ( wxTestFontSpec(fontSpec
) )
871 else if ( style
== wxITALIC
) // and not wxSLANT
874 fontSpec
.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
876 if ( wxTestFontSpec(fontSpec
) )
882 // no italic, no slant - leave default
889 wxFAIL_MSG(_T("unknown font style"));
890 // fall back to normal
902 fontSpec
.Printf(wxT("-*-%s-bold-*-*-*-*-*-*-*-*-*-*-*"),
904 if ( wxTestFontSpec(fontSpec
) )
906 xweight
= wxT("bold");
909 fontSpec
.Printf(wxT("-*-%s-heavy-*-*-*-*-*-*-*-*-*-*-*"),
911 if ( wxTestFontSpec(fontSpec
) )
913 xweight
= wxT("heavy");
916 fontSpec
.Printf(wxT("-*-%s-extrabold-*-*-*-*-*-*-*-*-*-*-*"),
918 if ( wxTestFontSpec(fontSpec
) )
920 xweight
= wxT("extrabold");
923 fontSpec
.Printf(wxT("-*-%s-demibold-*-*-*-*-*-*-*-*-*-*-*"),
925 if ( wxTestFontSpec(fontSpec
) )
927 xweight
= wxT("demibold");
930 fontSpec
.Printf(wxT("-*-%s-black-*-*-*-*-*-*-*-*-*-*-*"),
932 if ( wxTestFontSpec(fontSpec
) )
934 xweight
= wxT("black");
937 fontSpec
.Printf(wxT("-*-%s-ultrablack-*-*-*-*-*-*-*-*-*-*-*"),
939 if ( wxTestFontSpec(fontSpec
) )
941 xweight
= wxT("ultrablack");
948 fontSpec
.Printf(wxT("-*-%s-light-*-*-*-*-*-*-*-*-*-*-*"),
950 if ( wxTestFontSpec(fontSpec
) )
952 xweight
= wxT("light");
955 fontSpec
.Printf(wxT("-*-%s-thin-*-*-*-*-*-*-*-*-*-*-*"),
957 if ( wxTestFontSpec(fontSpec
) )
959 xweight
= wxT("thin");
966 fontSpec
.Printf(wxT("-*-%s-medium-*-*-*-*-*-*-*-*-*-*-*"),
968 if ( wxTestFontSpec(fontSpec
) )
970 xweight
= wxT("medium");
973 fontSpec
.Printf(wxT("-*-%s-normal-*-*-*-*-*-*-*-*-*-*-*"),
975 if ( wxTestFontSpec(fontSpec
) )
977 xweight
= wxT("normal");
980 fontSpec
.Printf(wxT("-*-%s-regular-*-*-*-*-*-*-*-*-*-*-*"),
982 if ( wxTestFontSpec(fontSpec
) )
984 xweight
= wxT("regular");
990 default: xweight
= wxT("*"); break;
993 // if pointSize is -1, don't specify any
995 if ( pointSize
== -1 )
1001 sizeSpec
.Printf(_T("%d"), pointSize
);
1004 // construct the X font spec from our data
1005 fontSpec
.Printf(wxT("-*-%s-%s-%s-normal-*-*-%s-*-*-*-*-%s-%s"),
1006 xfamily
.c_str(), xweight
.c_str(), xstyle
.c_str(),
1007 sizeSpec
.c_str(), xregistry
.c_str(), xencoding
.c_str());
1010 *xFontName
= fontSpec
;
1012 return wxLoadFont(fontSpec
);
1017 // ----------------------------------------------------------------------------
1019 // ----------------------------------------------------------------------------
1021 class wxFontModule
: public wxModule
1028 DECLARE_DYNAMIC_CLASS(wxFontModule
)
1031 IMPLEMENT_DYNAMIC_CLASS(wxFontModule
, wxModule
)
1033 bool wxFontModule::OnInit()
1035 g_fontHash
= new wxHashTable( wxKEY_STRING
);
1040 void wxFontModule::OnExit()
1044 g_fontHash
= (wxHashTable
*)NULL
;