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 licence
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 "pango/pango.h"
45 #include "wx/gtk/private.h"
47 #include "wx/x11/private.h"
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 void wxNativeFontInfo::Init()
59 int wxNativeFontInfo::GetPointSize() const
61 return pango_font_description_get_size( description
) / PANGO_SCALE
;
64 wxFontStyle
wxNativeFontInfo::GetStyle() const
66 wxFontStyle m_style
= wxFONTSTYLE_NORMAL
;
68 switch (pango_font_description_get_style( description
))
70 case PANGO_STYLE_NORMAL
:
71 m_style
= wxFONTSTYLE_NORMAL
;
73 case PANGO_STYLE_ITALIC
:
74 m_style
= wxFONTSTYLE_ITALIC
;
76 case PANGO_STYLE_OBLIQUE
:
77 m_style
= wxFONTSTYLE_SLANT
;
84 wxFontWeight
wxNativeFontInfo::GetWeight() const
86 wxFontWeight m_weight
= wxFONTWEIGHT_NORMAL
;
88 switch (pango_font_description_get_weight( description
))
90 case PANGO_WEIGHT_ULTRALIGHT
:
91 m_weight
= wxFONTWEIGHT_LIGHT
;
93 case PANGO_WEIGHT_LIGHT
:
94 m_weight
= wxFONTWEIGHT_LIGHT
;
96 case PANGO_WEIGHT_NORMAL
:
97 m_weight
= wxFONTWEIGHT_NORMAL
;
99 case PANGO_WEIGHT_BOLD
:
100 m_weight
= wxFONTWEIGHT_BOLD
;
102 case PANGO_WEIGHT_ULTRABOLD
:
103 m_weight
= wxFONTWEIGHT_BOLD
;
105 case PANGO_WEIGHT_HEAVY
:
106 m_weight
= wxFONTWEIGHT_BOLD
;
113 bool wxNativeFontInfo::GetUnderlined() const
118 wxString
wxNativeFontInfo::GetFaceName() const
120 wxString tmp
= wxGTK_CONV_BACK( pango_font_description_get_family( description
) );
125 wxFontFamily
wxNativeFontInfo::GetFamily() const
127 return wxFONTFAMILY_SWISS
;
130 wxFontEncoding
wxNativeFontInfo::GetEncoding() const
132 return wxFONTENCODING_SYSTEM
;
135 bool wxNativeFontInfo::FromString(const wxString
& s
)
138 pango_font_description_free( description
);
140 description
= pango_font_description_from_string( wxGTK_CONV( s
) );
145 wxString
wxNativeFontInfo::ToString() const
147 char *str
= pango_font_description_to_string( description
);
148 wxString tmp
= wxGTK_CONV_BACK( str
);
154 bool wxNativeFontInfo::FromUserString(const wxString
& s
)
156 return FromString( s
);
159 wxString
wxNativeFontInfo::ToUserString() const
164 // ----------------------------------------------------------------------------
165 // wxNativeEncodingInfo
166 // ----------------------------------------------------------------------------
168 bool wxNativeEncodingInfo::FromString(const wxString
& s
)
173 wxString
wxNativeEncodingInfo::ToString() const
175 return wxEmptyString
;
178 bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
)
183 bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
184 wxNativeEncodingInfo
*info
)
193 #pragma message disable nosimpint
196 #include <X11/Xlib.h>
199 #pragma message enable nosimpint
202 #include "wx/utils.h" // for wxGetDisplay()
203 #elif defined(__WXGTK__)
204 // we have to declare struct tm to avoid problems with first forward
205 // declaring it in C code (glib.h included from gdk.h does it) and then
206 // defining it when time.h is included from the headers below - this is
207 // known not to work at least with Sun CC 6.01
214 // ----------------------------------------------------------------------------
216 // ----------------------------------------------------------------------------
218 static wxHashTable
*g_fontHash
= (wxHashTable
*) NULL
;
220 // ----------------------------------------------------------------------------
222 // ----------------------------------------------------------------------------
224 // define the functions to create and destroy native fonts for this toolkit
226 wxNativeFont
wxLoadFont(const wxString
& fontSpec
)
228 return XLoadQueryFont((Display
*)wxGetDisplay(), fontSpec
);
231 inline void wxFreeFont(wxNativeFont font
)
233 XFreeFont((Display
*)wxGetDisplay(), (XFontStruct
*)font
);
235 #elif defined(__WXGTK__)
236 wxNativeFont
wxLoadFont(const wxString
& fontSpec
)
238 // use gdk_fontset_load() instead of gdk_font_load() because otherwise
239 // we have problems with Japanese (not terribly precise, I know, but
240 // this is all the patch said)
241 return gdk_fontset_load( wxConvertWX2MB(fontSpec
) );
244 inline void wxFreeFont(wxNativeFont font
)
246 gdk_font_unref(font
);
249 #error "Unknown GUI toolkit"
252 static bool wxTestFontSpec(const wxString
& fontspec
);
254 static wxNativeFont
wxLoadQueryFont(int pointSize
,
259 const wxString
& facename
,
260 const wxString
& xregistry
,
261 const wxString
& xencoding
,
262 wxString
* xFontName
);
264 // ============================================================================
266 // ============================================================================
268 // ----------------------------------------------------------------------------
269 // wxNativeEncodingInfo
270 // ----------------------------------------------------------------------------
272 // convert to/from the string representation: format is
273 // encodingid;registry;encoding[;facename]
274 bool wxNativeEncodingInfo::FromString(const wxString
& s
)
276 // use ";", not "-" because it may be part of encoding name
277 wxStringTokenizer
tokenizer(s
, _T(";"));
279 wxString encid
= tokenizer
.GetNextToken();
281 if ( !encid
.ToLong(&enc
) )
283 encoding
= (wxFontEncoding
)enc
;
285 xregistry
= tokenizer
.GetNextToken();
289 xencoding
= tokenizer
.GetNextToken();
294 facename
= tokenizer
.GetNextToken();
299 wxString
wxNativeEncodingInfo::ToString() const
302 s
<< (long)encoding
<< _T(';') << xregistry
<< _T(';') << xencoding
;
305 s
<< _T(';') << facename
;
311 // ----------------------------------------------------------------------------
313 // ----------------------------------------------------------------------------
315 void wxNativeFontInfo::Init()
320 bool wxNativeFontInfo::FromString(const wxString
& s
)
322 wxStringTokenizer
tokenizer(s
, _T(";"));
325 wxString token
= tokenizer
.GetNextToken();
326 if ( token
!= _T('0') )
329 xFontName
= tokenizer
.GetNextToken();
331 // this should be the end
332 if ( tokenizer
.HasMoreTokens() )
335 return FromXFontName(xFontName
);
338 wxString
wxNativeFontInfo::ToString() const
341 return wxString::Format(_T("%d;%s"), 0, GetXFontName().c_str());
344 bool wxNativeFontInfo::FromUserString(const wxString
& s
)
346 return FromXFontName(s
);
349 wxString
wxNativeFontInfo::ToUserString() const
351 return GetXFontName();
354 bool wxNativeFontInfo::HasElements() const
356 // we suppose that the foundry is never empty, so if it is it means that we
357 // had never parsed the XLFD
358 return !fontElements
[0].empty();
361 wxString
wxNativeFontInfo::GetXFontComponent(wxXLFDField field
) const
363 wxCHECK_MSG( field
< wxXLFD_MAX
, _T(""), _T("invalid XLFD field") );
365 if ( !HasElements() )
368 if ( !((wxNativeFontInfo
*)this)->FromXFontName(xFontName
) )
372 return fontElements
[field
];
375 bool wxNativeFontInfo::FromXFontName(const wxString
& fontname
)
377 // TODO: we should be able to handle the font aliases here, but how?
378 wxStringTokenizer
tokenizer(fontname
, _T("-"));
380 // skip the leading, usually empty field (font name registry)
381 if ( !tokenizer
.HasMoreTokens() )
384 (void)tokenizer
.GetNextToken();
386 for ( size_t n
= 0; n
< WXSIZEOF(fontElements
); n
++ )
388 if ( !tokenizer
.HasMoreTokens() )
390 // not enough elements in the XLFD - or maybe an alias
394 fontElements
[n
] = tokenizer
.GetNextToken();
397 // this should be all
398 if ( tokenizer
.HasMoreTokens() )
401 // we're initialized now
407 wxString
wxNativeFontInfo::GetXFontName() const
409 if ( xFontName
.empty() )
411 for ( size_t n
= 0; n
< WXSIZEOF(fontElements
); n
++ )
413 // replace the non specified elements with '*' except for the
414 // additional style which is usually just omitted
415 wxString elt
= fontElements
[n
];
416 if ( elt
.empty() && n
!= wxXLFD_ADDSTYLE
)
422 ((wxNativeFontInfo
*)this)->xFontName
<< _T('-') << elt
;
430 wxNativeFontInfo::SetXFontComponent(wxXLFDField field
, const wxString
& value
)
432 wxCHECK_RET( field
< wxXLFD_MAX
, _T("invalid XLFD field") );
434 // this class should be initialized with a valid font spec first and only
435 // then the fields may be modified!
436 wxASSERT_MSG( !IsDefault(), _T("can't modify an uninitialized XLFD") );
438 if ( !HasElements() )
441 if ( !((wxNativeFontInfo
*)this)->FromXFontName(xFontName
) )
443 wxFAIL_MSG( _T("can't set font element for invalid XLFD") );
449 fontElements
[field
] = value
;
451 // invalidate the XFLD, it doesn't correspond to the font elements any more
455 void wxNativeFontInfo::SetXFontName(const wxString
& xFontName_
)
457 // invalidate the font elements, GetXFontComponent() will reparse the XLFD
458 fontElements
[0].clear();
460 xFontName
= xFontName_
;
465 int wxNativeFontInfo::GetPointSize() const
467 const wxString s
= GetXFontComponent(wxXLFD_POINTSIZE
);
469 // return -1 to indicate that the size is unknown
471 return s
.ToLong(&l
) ? l
: -1;
474 wxFontStyle
wxNativeFontInfo::GetStyle() const
476 const wxString s
= GetXFontComponent(wxXLFD_SLANT
);
478 if ( s
.length() != 1 )
480 // it is really unknown but we don't have any way to return it from
482 return wxFONTSTYLE_NORMAL
;
488 // again, unknown but consider normal by default
491 return wxFONTSTYLE_NORMAL
;
494 return wxFONTSTYLE_ITALIC
;
497 return wxFONTSTYLE_SLANT
;
501 wxFontWeight
wxNativeFontInfo::GetWeight() const
503 const wxString s
= GetXFontComponent(wxXLFD_WEIGHT
).MakeLower();
504 if ( s
.find(_T("bold")) != wxString::npos
|| s
== _T("black") )
505 return wxFONTWEIGHT_BOLD
;
506 else if ( s
== _T("light") )
507 return wxFONTWEIGHT_LIGHT
;
509 return wxFONTWEIGHT_NORMAL
;
512 bool wxNativeFontInfo::GetUnderlined() const
514 // X fonts are never underlined
518 wxString
wxNativeFontInfo::GetFaceName() const
520 // wxWindows facename probably more accurately corresponds to X family
521 return GetXFontComponent(wxXLFD_FAMILY
);
524 wxFontFamily
wxNativeFontInfo::GetFamily() const
526 // and wxWindows family -- to X foundry, but we have to translate it to
527 // wxFontFamily somehow...
528 wxFAIL_MSG(_T("not implemented")); // GetXFontComponent(wxXLFD_FOUNDRY);
530 return wxFONTFAMILY_DEFAULT
;
533 wxFontEncoding
wxNativeFontInfo::GetEncoding() const
535 // we already have the code for this but need to refactor it first
536 wxFAIL_MSG( _T("not implemented") );
538 return wxFONTENCODING_MAX
;
541 void wxNativeFontInfo::SetPointSize(int pointsize
)
543 SetXFontComponent(wxXLFD_POINTSIZE
, wxString::Format(_T("%d"), pointsize
));
546 void wxNativeFontInfo::SetStyle(wxFontStyle style
)
551 case wxFONTSTYLE_ITALIC
:
555 case wxFONTSTYLE_SLANT
:
559 case wxFONTSTYLE_NORMAL
:
563 wxFAIL_MSG( _T("unknown wxFontStyle in wxNativeFontInfo::SetStyle") );
567 SetXFontComponent(wxXLFD_SLANT
, s
);
570 void wxNativeFontInfo::SetWeight(wxFontWeight weight
)
575 case wxFONTWEIGHT_BOLD
:
579 case wxFONTWEIGHT_LIGHT
:
583 case wxFONTWEIGHT_NORMAL
:
588 wxFAIL_MSG( _T("unknown wxFontWeight in wxNativeFontInfo::SetWeight") );
592 SetXFontComponent(wxXLFD_WEIGHT
, s
);
595 void wxNativeFontInfo::SetUnderlined(bool WXUNUSED(underlined
))
597 // can't do this under X
600 void wxNativeFontInfo::SetFaceName(wxString facename
)
602 SetXFontComponent(wxXLFD_FAMILY
, facename
);
605 void wxNativeFontInfo::SetFamily(wxFontFamily family
)
607 // wxFontFamily -> X foundry, anyone?
608 wxFAIL_MSG( _T("not implemented") );
610 // SetXFontComponent(wxXLFD_FOUNDRY, ...);
613 void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding
)
615 wxNativeEncodingInfo info
;
616 if ( wxGetNativeFontEncoding(encoding
, &info
) )
618 SetXFontComponent(wxXLFD_ENCODING
, info
.xencoding
);
619 SetXFontComponent(wxXLFD_REGISTRY
, info
.xregistry
);
623 // ----------------------------------------------------------------------------
625 // ----------------------------------------------------------------------------
627 bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
628 wxNativeEncodingInfo
*info
)
630 wxCHECK_MSG( info
, FALSE
, _T("bad pointer in wxGetNativeFontEncoding") );
632 if ( encoding
== wxFONTENCODING_DEFAULT
)
634 encoding
= wxFont::GetDefaultEncoding();
639 case wxFONTENCODING_ISO8859_1
:
640 case wxFONTENCODING_ISO8859_2
:
641 case wxFONTENCODING_ISO8859_3
:
642 case wxFONTENCODING_ISO8859_4
:
643 case wxFONTENCODING_ISO8859_5
:
644 case wxFONTENCODING_ISO8859_6
:
645 case wxFONTENCODING_ISO8859_7
:
646 case wxFONTENCODING_ISO8859_8
:
647 case wxFONTENCODING_ISO8859_9
:
648 case wxFONTENCODING_ISO8859_10
:
649 case wxFONTENCODING_ISO8859_11
:
650 case wxFONTENCODING_ISO8859_12
:
651 case wxFONTENCODING_ISO8859_13
:
652 case wxFONTENCODING_ISO8859_14
:
653 case wxFONTENCODING_ISO8859_15
:
655 int cp
= encoding
- wxFONTENCODING_ISO8859_1
+ 1;
656 info
->xregistry
= wxT("iso8859");
657 info
->xencoding
.Printf(wxT("%d"), cp
);
661 case wxFONTENCODING_UTF8
:
662 info
->xregistry
= wxT("iso10646");
663 info
->xencoding
= wxT("*");
666 case wxFONTENCODING_GB2312
:
667 info
->xregistry
= wxT("GB2312"); // or the otherway round?
668 info
->xencoding
= wxT("*");
671 case wxFONTENCODING_KOI8
:
672 info
->xregistry
= wxT("koi8");
674 // we don't make distinction between koi8-r, koi8-u and koi8-ru (so far)
675 info
->xencoding
= wxT("*");
678 case wxFONTENCODING_CP1250
:
679 case wxFONTENCODING_CP1251
:
680 case wxFONTENCODING_CP1252
:
681 case wxFONTENCODING_CP1253
:
682 case wxFONTENCODING_CP1254
:
683 case wxFONTENCODING_CP1255
:
684 case wxFONTENCODING_CP1256
:
685 case wxFONTENCODING_CP1257
:
687 int cp
= encoding
- wxFONTENCODING_CP1250
+ 1250;
688 info
->xregistry
= wxT("microsoft");
689 info
->xencoding
.Printf(wxT("cp%d"), cp
);
693 case wxFONTENCODING_SYSTEM
:
695 info
->xencoding
= wxT("*");
699 // don't know how to translate this encoding into X fontspec
703 info
->encoding
= encoding
;
708 bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
)
711 fontspec
.Printf(_T("-*-%s-*-*-*-*-*-*-*-*-*-*-%s-%s"),
712 !info
.facename
? _T("*") : info
.facename
.c_str(),
713 info
.xregistry
.c_str(),
714 info
.xencoding
.c_str());
716 return wxTestFontSpec(fontspec
);
719 // ----------------------------------------------------------------------------
720 // X-specific functions
721 // ----------------------------------------------------------------------------
723 wxNativeFont
wxLoadQueryNearestFont(int pointSize
,
728 const wxString
&facename
,
729 wxFontEncoding encoding
,
732 if ( encoding
== wxFONTENCODING_DEFAULT
)
734 encoding
= wxFont::GetDefaultEncoding();
737 // first determine the encoding - if the font doesn't exist at all in this
738 // encoding, it's useless to do all other approximations (i.e. size,
739 // family &c don't matter much)
740 wxNativeEncodingInfo info
;
741 if ( encoding
== wxFONTENCODING_SYSTEM
)
743 // This will always work so we don't test to save time
744 wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM
, &info
);
748 if ( !wxGetNativeFontEncoding(encoding
, &info
) ||
749 !wxTestFontEncoding(info
) )
752 if ( !wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
753 #endif // wxUSE_FONTMAP
755 // unspported encoding - replace it with the default
757 // NB: we can't just return 0 from here because wxGTK code doesn't
758 // check for it (i.e. it supposes that we'll always succeed),
759 // so it would provoke a crash
760 wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM
, &info
);
765 // OK, we have the correct xregistry/xencoding in info structure
766 wxNativeFont font
= 0;
768 // if we already have the X font name, try to use it
769 if( xFontName
&& !xFontName
->IsEmpty() )
772 // Make sure point size is correct for scale factor.
774 wxStringTokenizer
tokenizer(*xFontName
, _T("-"), wxTOKEN_RET_DELIMS
);
775 wxString newFontName
;
777 for(int i
= 0; i
< 8; i
++)
778 newFontName
+= tokenizer
.NextToken();
780 (void) tokenizer
.NextToken();
782 newFontName
+= wxString::Format(wxT("%d-"), pointSize
);
784 while(tokenizer
.HasMoreTokens())
785 newFontName
+= tokenizer
.GetNextToken();
787 font
= wxLoadFont(newFontName
);
790 *xFontName
= newFontName
;
793 // try to load exactly the font requested first
796 font
= wxLoadQueryFont( pointSize
, family
, style
, weight
,
797 underlined
, facename
,
798 info
.xregistry
, info
.xencoding
,
804 // search up and down by stepsize 10
805 int max_size
= pointSize
+ 20 * (1 + (pointSize
/180));
806 int min_size
= pointSize
- 20 * (1 + (pointSize
/180));
810 // Search for smaller size (approx.)
811 for ( i
= pointSize
- 10; !font
&& i
>= 10 && i
>= min_size
; i
-= 10 )
813 font
= wxLoadQueryFont(i
, family
, style
, weight
, underlined
,
814 facename
, info
.xregistry
, info
.xencoding
,
818 // Search for larger size (approx.)
819 for ( i
= pointSize
+ 10; !font
&& i
<= max_size
; i
+= 10 )
821 font
= wxLoadQueryFont(i
, family
, style
, weight
, underlined
,
822 facename
, info
.xregistry
, info
.xencoding
,
826 // Try default family
827 if ( !font
&& family
!= wxDEFAULT
)
829 font
= wxLoadQueryFont(pointSize
, wxDEFAULT
, style
, weight
,
830 underlined
, facename
,
831 info
.xregistry
, info
.xencoding
,
835 // ignore size, family, style and weight but try to find font with the
836 // given facename and encoding
839 font
= wxLoadQueryFont(120, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
840 underlined
, facename
,
841 info
.xregistry
, info
.xencoding
,
844 // ignore family as well
847 font
= wxLoadQueryFont(120, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
848 underlined
, wxEmptyString
,
849 info
.xregistry
, info
.xencoding
,
852 // if it still failed, try to get the font of any size but
853 // with the requested encoding: this can happen if the
854 // encoding is only available in one size which happens to be
855 // different from 120
858 font
= wxLoadQueryFont(-1, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
859 FALSE
, wxEmptyString
,
860 info
.xregistry
, info
.xencoding
,
863 // this should never happen as we had tested for it in the
864 // very beginning, but if it does, do return something non
865 // NULL or we'd crash in wxFont code
868 wxFAIL_MSG( _T("this encoding should be available!") );
870 font
= wxLoadQueryFont(-1,
871 wxDEFAULT
, wxNORMAL
, wxNORMAL
,
872 FALSE
, wxEmptyString
,
884 // ----------------------------------------------------------------------------
886 // ----------------------------------------------------------------------------
888 // returns TRUE if there are any fonts matching this font spec
889 static bool wxTestFontSpec(const wxString
& fontspec
)
891 // some X servers will fail to load this font because there are too many
892 // matches so we must test explicitly for this
893 if ( fontspec
== _T("-*-*-*-*-*-*-*-*-*-*-*-*-*-*") )
898 wxNativeFont test
= (wxNativeFont
) g_fontHash
->Get( fontspec
);
904 test
= wxLoadFont(fontspec
);
905 g_fontHash
->Put( fontspec
, (wxObject
*) test
);
919 static wxNativeFont
wxLoadQueryFont(int pointSize
,
923 bool WXUNUSED(underlined
),
924 const wxString
& facename
,
925 const wxString
& xregistry
,
926 const wxString
& xencoding
,
932 case wxDECORATIVE
: xfamily
= wxT("lucida"); break;
933 case wxROMAN
: xfamily
= wxT("times"); break;
934 case wxMODERN
: xfamily
= wxT("courier"); break;
935 case wxSWISS
: xfamily
= wxT("helvetica"); break;
936 case wxTELETYPE
: xfamily
= wxT("lucidatypewriter"); break;
937 case wxSCRIPT
: xfamily
= wxT("utopia"); break;
938 default: xfamily
= wxT("*");
946 xweight
= MWLF_WEIGHT_BOLD
;
951 xweight
= MWLF_WEIGHT_LIGHT
;
956 xweight
= MWLF_WEIGHT_NORMAL
;
962 xweight
= MWLF_WEIGHT_DEFAULT
;
966 GR_SCREEN_INFO screenInfo
;
967 GrGetScreenInfo(& screenInfo
);
969 int yPixelsPerCM
= screenInfo
.ydpcm
;
971 // A point is 1/72 of an inch.
972 // An inch is 2.541 cm.
973 // So pixelHeight = (pointSize / 72) (inches) * 2.541 (for cm) * yPixelsPerCM (for pixels)
974 // In fact pointSize is 10 * the normal point size so
977 int pixelHeight
= (int) ( (((float)pointSize
) / 720.0) * 2.541 * (float) yPixelsPerCM
) ;
979 // An alternative: assume that the screen is 72 dpi.
980 //int pixelHeight = (int) (((float)pointSize / 720.0) * 72.0) ;
981 //int pixelHeight = (int) ((float)pointSize / 10.0) ;
984 logFont
.lfHeight
= pixelHeight
;
986 logFont
.lfEscapement
= 0;
987 logFont
.lfOrientation
= 0;
988 logFont
.lfWeight
= xweight
;
989 logFont
.lfItalic
= (style
== wxNORMAL
? 0 : 1) ;
990 logFont
.lfUnderline
= 0;
991 logFont
.lfStrikeOut
= 0;
992 logFont
.lfCharSet
= MWLF_CHARSET_DEFAULT
; // TODO: select appropriate one
993 logFont
.lfOutPrecision
= MWLF_TYPE_DEFAULT
;
994 logFont
.lfClipPrecision
= 0; // Not used
995 logFont
.lfRoman
= (family
== wxROMAN
? 1 : 0) ;
996 logFont
.lfSerif
= (family
== wxSWISS
? 0 : 1) ;
997 logFont
.lfSansSerif
= !logFont
.lfSerif
;
998 logFont
.lfModern
= (family
== wxMODERN
? 1 : 0) ;
999 logFont
.lfProportional
= (family
== wxTELETYPE
? 0 : 1) ;
1000 logFont
.lfOblique
= 0;
1001 logFont
.lfSmallCaps
= 0;
1002 logFont
.lfPitch
= 0; // 0 = default
1003 strcpy(logFont
.lfFaceName
, facename
.c_str());
1005 XFontStruct
* fontInfo
= (XFontStruct
*) malloc(sizeof(XFontStruct
));
1006 fontInfo
->fid
= GrCreateFont((GR_CHAR
*) facename
.c_str(), pixelHeight
, & logFont
);
1007 GrGetFontInfo(fontInfo
->fid
, & fontInfo
->info
);
1008 return (wxNativeFont
) fontInfo
;
1012 if (!facename
.IsEmpty())
1014 fontSpec
.Printf(wxT("-*-%s-*-*-normal-*-*-*-*-*-*-*-*-*"),
1017 if ( wxTestFontSpec(fontSpec
) )
1021 //else: no such family, use default one instead
1028 fontSpec
.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
1030 if ( wxTestFontSpec(fontSpec
) )
1035 // fall through - try wxITALIC now
1038 fontSpec
.Printf(wxT("-*-%s-*-i-*-*-*-*-*-*-*-*-*-*"),
1040 if ( wxTestFontSpec(fontSpec
) )
1044 else if ( style
== wxITALIC
) // and not wxSLANT
1047 fontSpec
.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
1049 if ( wxTestFontSpec(fontSpec
) )
1055 // no italic, no slant - leave default
1062 wxFAIL_MSG(_T("unknown font style"));
1063 // fall back to normal
1075 fontSpec
.Printf(wxT("-*-%s-bold-*-*-*-*-*-*-*-*-*-*-*"),
1077 if ( wxTestFontSpec(fontSpec
) )
1079 xweight
= wxT("bold");
1082 fontSpec
.Printf(wxT("-*-%s-heavy-*-*-*-*-*-*-*-*-*-*-*"),
1084 if ( wxTestFontSpec(fontSpec
) )
1086 xweight
= wxT("heavy");
1089 fontSpec
.Printf(wxT("-*-%s-extrabold-*-*-*-*-*-*-*-*-*-*-*"),
1091 if ( wxTestFontSpec(fontSpec
) )
1093 xweight
= wxT("extrabold");
1096 fontSpec
.Printf(wxT("-*-%s-demibold-*-*-*-*-*-*-*-*-*-*-*"),
1098 if ( wxTestFontSpec(fontSpec
) )
1100 xweight
= wxT("demibold");
1103 fontSpec
.Printf(wxT("-*-%s-black-*-*-*-*-*-*-*-*-*-*-*"),
1105 if ( wxTestFontSpec(fontSpec
) )
1107 xweight
= wxT("black");
1110 fontSpec
.Printf(wxT("-*-%s-ultrablack-*-*-*-*-*-*-*-*-*-*-*"),
1112 if ( wxTestFontSpec(fontSpec
) )
1114 xweight
= wxT("ultrablack");
1121 fontSpec
.Printf(wxT("-*-%s-light-*-*-*-*-*-*-*-*-*-*-*"),
1123 if ( wxTestFontSpec(fontSpec
) )
1125 xweight
= wxT("light");
1128 fontSpec
.Printf(wxT("-*-%s-thin-*-*-*-*-*-*-*-*-*-*-*"),
1130 if ( wxTestFontSpec(fontSpec
) )
1132 xweight
= wxT("thin");
1139 fontSpec
.Printf(wxT("-*-%s-medium-*-*-*-*-*-*-*-*-*-*-*"),
1141 if ( wxTestFontSpec(fontSpec
) )
1143 xweight
= wxT("medium");
1146 fontSpec
.Printf(wxT("-*-%s-normal-*-*-*-*-*-*-*-*-*-*-*"),
1148 if ( wxTestFontSpec(fontSpec
) )
1150 xweight
= wxT("normal");
1153 fontSpec
.Printf(wxT("-*-%s-regular-*-*-*-*-*-*-*-*-*-*-*"),
1155 if ( wxTestFontSpec(fontSpec
) )
1157 xweight
= wxT("regular");
1163 default: xweight
= wxT("*"); break;
1166 // if pointSize is -1, don't specify any
1168 if ( pointSize
== -1 )
1174 sizeSpec
.Printf(_T("%d"), pointSize
);
1177 // construct the X font spec from our data
1178 fontSpec
.Printf(wxT("-*-%s-%s-%s-normal-*-*-%s-*-*-*-*-%s-%s"),
1179 xfamily
.c_str(), xweight
.c_str(), xstyle
.c_str(),
1180 sizeSpec
.c_str(), xregistry
.c_str(), xencoding
.c_str());
1183 *xFontName
= fontSpec
;
1185 return wxLoadFont(fontSpec
);
1190 // ----------------------------------------------------------------------------
1192 // ----------------------------------------------------------------------------
1194 class wxFontModule
: public wxModule
1201 DECLARE_DYNAMIC_CLASS(wxFontModule
)
1204 IMPLEMENT_DYNAMIC_CLASS(wxFontModule
, wxModule
)
1206 bool wxFontModule::OnInit()
1208 g_fontHash
= new wxHashTable( wxKEY_STRING
);
1213 void wxFontModule::OnExit()
1217 g_fontHash
= (wxHashTable
*)NULL
;
1220 #endif // GTK 2.0/1.x