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 "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 return gdk_font_load( wxConvertWX2MB(fontSpec
) );
241 inline void wxFreeFont(wxNativeFont font
)
243 gdk_font_unref(font
);
246 #error "Unknown GUI toolkit"
249 static bool wxTestFontSpec(const wxString
& fontspec
);
251 static wxNativeFont
wxLoadQueryFont(int pointSize
,
256 const wxString
& facename
,
257 const wxString
& xregistry
,
258 const wxString
& xencoding
,
259 wxString
* xFontName
);
261 // ============================================================================
263 // ============================================================================
265 // ----------------------------------------------------------------------------
266 // wxNativeEncodingInfo
267 // ----------------------------------------------------------------------------
269 // convert to/from the string representation: format is
270 // encodingid;registry;encoding[;facename]
271 bool wxNativeEncodingInfo::FromString(const wxString
& s
)
273 // use ";", not "-" because it may be part of encoding name
274 wxStringTokenizer
tokenizer(s
, _T(";"));
276 wxString encid
= tokenizer
.GetNextToken();
278 if ( !encid
.ToLong(&enc
) )
280 encoding
= (wxFontEncoding
)enc
;
282 xregistry
= tokenizer
.GetNextToken();
286 xencoding
= tokenizer
.GetNextToken();
291 facename
= tokenizer
.GetNextToken();
296 wxString
wxNativeEncodingInfo::ToString() const
299 s
<< (long)encoding
<< _T(';') << xregistry
<< _T(';') << xencoding
;
302 s
<< _T(';') << facename
;
308 // ----------------------------------------------------------------------------
310 // ----------------------------------------------------------------------------
312 void wxNativeFontInfo::Init()
317 bool wxNativeFontInfo::FromString(const wxString
& s
)
319 wxStringTokenizer
tokenizer(s
, _T(";"));
322 wxString token
= tokenizer
.GetNextToken();
323 if ( token
!= _T('0') )
326 xFontName
= tokenizer
.GetNextToken();
328 // this should be the end
329 if ( tokenizer
.HasMoreTokens() )
332 return FromXFontName(xFontName
);
335 wxString
wxNativeFontInfo::ToString() const
338 return wxString::Format(_T("%d;%s"), 0, GetXFontName().c_str());
341 bool wxNativeFontInfo::FromUserString(const wxString
& s
)
343 return FromXFontName(s
);
346 wxString
wxNativeFontInfo::ToUserString() const
348 return GetXFontName();
351 bool wxNativeFontInfo::HasElements() const
353 // we suppose that the foundry is never empty, so if it is it means that we
354 // had never parsed the XLFD
355 return !fontElements
[0].empty();
358 wxString
wxNativeFontInfo::GetXFontComponent(wxXLFDField field
) const
360 wxCHECK_MSG( field
< wxXLFD_MAX
, _T(""), _T("invalid XLFD field") );
362 if ( !HasElements() )
365 if ( !((wxNativeFontInfo
*)this)->FromXFontName(xFontName
) )
369 return fontElements
[field
];
372 bool wxNativeFontInfo::FromXFontName(const wxString
& fontname
)
374 // TODO: we should be able to handle the font aliases here, but how?
375 wxStringTokenizer
tokenizer(fontname
, _T("-"));
377 // skip the leading, usually empty field (font name registry)
378 if ( !tokenizer
.HasMoreTokens() )
381 (void)tokenizer
.GetNextToken();
383 for ( size_t n
= 0; n
< WXSIZEOF(fontElements
); n
++ )
385 if ( !tokenizer
.HasMoreTokens() )
387 // not enough elements in the XLFD - or maybe an alias
391 fontElements
[n
] = tokenizer
.GetNextToken();
394 // this should be all
395 if ( tokenizer
.HasMoreTokens() )
398 // we're initialized now
404 wxString
wxNativeFontInfo::GetXFontName() const
406 if ( xFontName
.empty() )
408 for ( size_t n
= 0; n
< WXSIZEOF(fontElements
); n
++ )
410 // replace the non specified elements with '*' except for the
411 // additional style which is usually just omitted
412 wxString elt
= fontElements
[n
];
413 if ( elt
.empty() && n
!= wxXLFD_ADDSTYLE
)
419 ((wxNativeFontInfo
*)this)->xFontName
<< _T('-') << elt
;
427 wxNativeFontInfo::SetXFontComponent(wxXLFDField field
, const wxString
& value
)
429 wxCHECK_RET( field
< wxXLFD_MAX
, _T("invalid XLFD field") );
431 // this class should be initialized with a valid font spec first and only
432 // then the fields may be modified!
433 wxASSERT_MSG( !IsDefault(), _T("can't modify an uninitialized XLFD") );
435 if ( !HasElements() )
438 if ( !((wxNativeFontInfo
*)this)->FromXFontName(xFontName
) )
440 wxFAIL_MSG( _T("can't set font element for invalid XLFD") );
446 fontElements
[field
] = value
;
448 // invalidate the XFLD, it doesn't correspond to the font elements any more
452 void wxNativeFontInfo::SetXFontName(const wxString
& xFontName_
)
454 // invalidate the font elements, GetXFontComponent() will reparse the XLFD
455 fontElements
[0].clear();
457 xFontName
= xFontName_
;
462 int wxNativeFontInfo::GetPointSize() const
464 const wxString s
= GetXFontComponent(wxXLFD_POINTSIZE
);
466 // return -1 to indicate that the size is unknown
468 return s
.ToLong(&l
) ? l
: -1;
471 wxFontStyle
wxNativeFontInfo::GetStyle() const
473 const wxString s
= GetXFontComponent(wxXLFD_SLANT
);
475 if ( s
.length() != 1 )
477 // it is really unknown but we don't have any way to return it from
479 return wxFONTSTYLE_NORMAL
;
485 // again, unknown but consider normal by default
488 return wxFONTSTYLE_NORMAL
;
491 return wxFONTSTYLE_ITALIC
;
494 return wxFONTSTYLE_SLANT
;
498 wxFontWeight
wxNativeFontInfo::GetWeight() const
500 const wxString s
= GetXFontComponent(wxXLFD_WEIGHT
).MakeLower();
501 if ( s
.find(_T("bold")) != wxString::npos
|| s
== _T("black") )
502 return wxFONTWEIGHT_BOLD
;
503 else if ( s
== _T("light") )
504 return wxFONTWEIGHT_LIGHT
;
506 return wxFONTWEIGHT_NORMAL
;
509 bool wxNativeFontInfo::GetUnderlined() const
511 // X fonts are never underlined
515 wxString
wxNativeFontInfo::GetFaceName() const
517 // wxWindows facename probably more accurately corresponds to X family
518 return GetXFontComponent(wxXLFD_FAMILY
);
521 wxFontFamily
wxNativeFontInfo::GetFamily() const
523 // and wxWindows family -- to X foundry, but we have to translate it to
524 // wxFontFamily somehow...
525 wxFAIL_MSG(_T("not implemented")); // GetXFontComponent(wxXLFD_FOUNDRY);
527 return wxFONTFAMILY_DEFAULT
;
530 wxFontEncoding
wxNativeFontInfo::GetEncoding() const
532 // we already have the code for this but need to refactor it first
533 wxFAIL_MSG( _T("not implemented") );
535 return wxFONTENCODING_MAX
;
538 void wxNativeFontInfo::SetPointSize(int pointsize
)
540 SetXFontComponent(wxXLFD_POINTSIZE
, wxString::Format(_T("%d"), pointsize
));
543 void wxNativeFontInfo::SetStyle(wxFontStyle style
)
548 case wxFONTSTYLE_ITALIC
:
552 case wxFONTSTYLE_SLANT
:
556 case wxFONTSTYLE_NORMAL
:
560 wxFAIL_MSG( _T("unknown wxFontStyle in wxNativeFontInfo::SetStyle") );
564 SetXFontComponent(wxXLFD_SLANT
, s
);
567 void wxNativeFontInfo::SetWeight(wxFontWeight weight
)
572 case wxFONTWEIGHT_BOLD
:
576 case wxFONTWEIGHT_LIGHT
:
580 case wxFONTWEIGHT_NORMAL
:
585 wxFAIL_MSG( _T("unknown wxFontWeight in wxNativeFontInfo::SetWeight") );
589 SetXFontComponent(wxXLFD_WEIGHT
, s
);
592 void wxNativeFontInfo::SetUnderlined(bool WXUNUSED(underlined
))
594 // can't do this under X
597 void wxNativeFontInfo::SetFaceName(wxString facename
)
599 SetXFontComponent(wxXLFD_FAMILY
, facename
);
602 void wxNativeFontInfo::SetFamily(wxFontFamily family
)
604 // wxFontFamily -> X foundry, anyone?
605 wxFAIL_MSG( _T("not implemented") );
607 // SetXFontComponent(wxXLFD_FOUNDRY, ...);
610 void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding
)
612 wxNativeEncodingInfo info
;
613 if ( wxGetNativeFontEncoding(encoding
, &info
) )
615 SetXFontComponent(wxXLFD_ENCODING
, info
.xencoding
);
616 SetXFontComponent(wxXLFD_REGISTRY
, info
.xregistry
);
620 // ----------------------------------------------------------------------------
622 // ----------------------------------------------------------------------------
624 bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
625 wxNativeEncodingInfo
*info
)
627 wxCHECK_MSG( info
, FALSE
, _T("bad pointer in wxGetNativeFontEncoding") );
629 if ( encoding
== wxFONTENCODING_DEFAULT
)
631 encoding
= wxFont::GetDefaultEncoding();
636 case wxFONTENCODING_ISO8859_1
:
637 case wxFONTENCODING_ISO8859_2
:
638 case wxFONTENCODING_ISO8859_3
:
639 case wxFONTENCODING_ISO8859_4
:
640 case wxFONTENCODING_ISO8859_5
:
641 case wxFONTENCODING_ISO8859_6
:
642 case wxFONTENCODING_ISO8859_7
:
643 case wxFONTENCODING_ISO8859_8
:
644 case wxFONTENCODING_ISO8859_9
:
645 case wxFONTENCODING_ISO8859_10
:
646 case wxFONTENCODING_ISO8859_11
:
647 case wxFONTENCODING_ISO8859_12
:
648 case wxFONTENCODING_ISO8859_13
:
649 case wxFONTENCODING_ISO8859_14
:
650 case wxFONTENCODING_ISO8859_15
:
652 int cp
= encoding
- wxFONTENCODING_ISO8859_1
+ 1;
653 info
->xregistry
= wxT("iso8859");
654 info
->xencoding
.Printf(wxT("%d"), cp
);
658 case wxFONTENCODING_UTF8
:
659 info
->xregistry
= wxT("iso10646");
660 info
->xencoding
= wxT("*");
663 case wxFONTENCODING_GB2312
:
664 info
->xregistry
= wxT("GB2312"); // or the otherway round?
665 info
->xencoding
= wxT("*");
668 case wxFONTENCODING_KOI8
:
669 info
->xregistry
= wxT("koi8");
671 // we don't make distinction between koi8-r, koi8-u and koi8-ru (so far)
672 info
->xencoding
= wxT("*");
675 case wxFONTENCODING_CP1250
:
676 case wxFONTENCODING_CP1251
:
677 case wxFONTENCODING_CP1252
:
678 case wxFONTENCODING_CP1253
:
679 case wxFONTENCODING_CP1254
:
680 case wxFONTENCODING_CP1255
:
681 case wxFONTENCODING_CP1256
:
682 case wxFONTENCODING_CP1257
:
684 int cp
= encoding
- wxFONTENCODING_CP1250
+ 1250;
685 info
->xregistry
= wxT("microsoft");
686 info
->xencoding
.Printf(wxT("cp%d"), cp
);
690 case wxFONTENCODING_SYSTEM
:
692 info
->xencoding
= wxT("*");
696 // don't know how to translate this encoding into X fontspec
700 info
->encoding
= encoding
;
705 bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
)
708 fontspec
.Printf(_T("-*-%s-*-*-*-*-*-*-*-*-*-*-%s-%s"),
709 !info
.facename
? _T("*") : info
.facename
.c_str(),
710 info
.xregistry
.c_str(),
711 info
.xencoding
.c_str());
713 return wxTestFontSpec(fontspec
);
716 // ----------------------------------------------------------------------------
717 // X-specific functions
718 // ----------------------------------------------------------------------------
720 wxNativeFont
wxLoadQueryNearestFont(int pointSize
,
725 const wxString
&facename
,
726 wxFontEncoding encoding
,
729 if ( encoding
== wxFONTENCODING_DEFAULT
)
731 encoding
= wxFont::GetDefaultEncoding();
734 // first determine the encoding - if the font doesn't exist at all in this
735 // encoding, it's useless to do all other approximations (i.e. size,
736 // family &c don't matter much)
737 wxNativeEncodingInfo info
;
738 if ( encoding
== wxFONTENCODING_SYSTEM
)
740 // This will always work so we don't test to save time
741 wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM
, &info
);
745 if ( !wxGetNativeFontEncoding(encoding
, &info
) ||
746 !wxTestFontEncoding(info
) )
749 if ( !wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
750 #endif // wxUSE_FONTMAP
752 // unspported encoding - replace it with the default
754 // NB: we can't just return 0 from here because wxGTK code doesn't
755 // check for it (i.e. it supposes that we'll always succeed),
756 // so it would provoke a crash
757 wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM
, &info
);
762 // OK, we have the correct xregistry/xencoding in info structure
763 wxNativeFont font
= 0;
765 // if we already have the X font name, try to use it
766 if( xFontName
&& !xFontName
->IsEmpty() )
769 // Make sure point size is correct for scale factor.
771 wxStringTokenizer
tokenizer(*xFontName
, _T("-"), wxTOKEN_RET_DELIMS
);
772 wxString newFontName
;
774 for(int i
= 0; i
< 8; i
++)
775 newFontName
+= tokenizer
.NextToken();
777 (void) tokenizer
.NextToken();
779 newFontName
+= wxString::Format(wxT("%d-"), pointSize
);
781 while(tokenizer
.HasMoreTokens())
782 newFontName
+= tokenizer
.GetNextToken();
784 font
= wxLoadFont(newFontName
);
787 *xFontName
= newFontName
;
790 // try to load exactly the font requested first
793 font
= wxLoadQueryFont( pointSize
, family
, style
, weight
,
794 underlined
, facename
,
795 info
.xregistry
, info
.xencoding
,
801 // search up and down by stepsize 10
802 int max_size
= pointSize
+ 20 * (1 + (pointSize
/180));
803 int min_size
= pointSize
- 20 * (1 + (pointSize
/180));
807 // Search for smaller size (approx.)
808 for ( i
= pointSize
- 10; !font
&& i
>= 10 && i
>= min_size
; i
-= 10 )
810 font
= wxLoadQueryFont(i
, family
, style
, weight
, underlined
,
811 facename
, info
.xregistry
, info
.xencoding
,
815 // Search for larger size (approx.)
816 for ( i
= pointSize
+ 10; !font
&& i
<= max_size
; i
+= 10 )
818 font
= wxLoadQueryFont(i
, family
, style
, weight
, underlined
,
819 facename
, info
.xregistry
, info
.xencoding
,
823 // Try default family
824 if ( !font
&& family
!= wxDEFAULT
)
826 font
= wxLoadQueryFont(pointSize
, wxDEFAULT
, style
, weight
,
827 underlined
, facename
,
828 info
.xregistry
, info
.xencoding
,
832 // ignore size, family, style and weight but try to find font with the
833 // given facename and encoding
836 font
= wxLoadQueryFont(120, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
837 underlined
, facename
,
838 info
.xregistry
, info
.xencoding
,
841 // ignore family as well
844 font
= wxLoadQueryFont(120, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
845 underlined
, wxEmptyString
,
846 info
.xregistry
, info
.xencoding
,
849 // if it still failed, try to get the font of any size but
850 // with the requested encoding: this can happen if the
851 // encoding is only available in one size which happens to be
852 // different from 120
855 font
= wxLoadQueryFont(-1, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
856 FALSE
, wxEmptyString
,
857 info
.xregistry
, info
.xencoding
,
860 // this should never happen as we had tested for it in the
861 // very beginning, but if it does, do return something non
862 // NULL or we'd crash in wxFont code
865 wxFAIL_MSG( _T("this encoding should be available!") );
867 font
= wxLoadQueryFont(-1,
868 wxDEFAULT
, wxNORMAL
, wxNORMAL
,
869 FALSE
, wxEmptyString
,
881 // ----------------------------------------------------------------------------
883 // ----------------------------------------------------------------------------
885 // returns TRUE if there are any fonts matching this font spec
886 static bool wxTestFontSpec(const wxString
& fontspec
)
888 // some X servers will fail to load this font because there are too many
889 // matches so we must test explicitly for this
890 if ( fontspec
== _T("-*-*-*-*-*-*-*-*-*-*-*-*-*-*") )
895 wxNativeFont test
= (wxNativeFont
) g_fontHash
->Get( fontspec
);
901 test
= wxLoadFont(fontspec
);
902 g_fontHash
->Put( fontspec
, (wxObject
*) test
);
916 static wxNativeFont
wxLoadQueryFont(int pointSize
,
920 bool WXUNUSED(underlined
),
921 const wxString
& facename
,
922 const wxString
& xregistry
,
923 const wxString
& xencoding
,
929 case wxDECORATIVE
: xfamily
= wxT("lucida"); break;
930 case wxROMAN
: xfamily
= wxT("times"); break;
931 case wxMODERN
: xfamily
= wxT("courier"); break;
932 case wxSWISS
: xfamily
= wxT("helvetica"); break;
933 case wxTELETYPE
: xfamily
= wxT("lucidatypewriter"); break;
934 case wxSCRIPT
: xfamily
= wxT("utopia"); break;
935 default: xfamily
= wxT("*");
943 xweight
= MWLF_WEIGHT_BOLD
;
948 xweight
= MWLF_WEIGHT_LIGHT
;
953 xweight
= MWLF_WEIGHT_NORMAL
;
959 xweight
= MWLF_WEIGHT_DEFAULT
;
963 GR_SCREEN_INFO screenInfo
;
964 GrGetScreenInfo(& screenInfo
);
966 int yPixelsPerCM
= screenInfo
.ydpcm
;
968 // A point is 1/72 of an inch.
969 // An inch is 2.541 cm.
970 // So pixelHeight = (pointSize / 72) (inches) * 2.541 (for cm) * yPixelsPerCM (for pixels)
971 // In fact pointSize is 10 * the normal point size so
974 int pixelHeight
= (int) ( (((float)pointSize
) / 720.0) * 2.541 * (float) yPixelsPerCM
) ;
976 // An alternative: assume that the screen is 72 dpi.
977 //int pixelHeight = (int) (((float)pointSize / 720.0) * 72.0) ;
978 //int pixelHeight = (int) ((float)pointSize / 10.0) ;
981 logFont
.lfHeight
= pixelHeight
;
983 logFont
.lfEscapement
= 0;
984 logFont
.lfOrientation
= 0;
985 logFont
.lfWeight
= xweight
;
986 logFont
.lfItalic
= (style
== wxNORMAL
? 0 : 1) ;
987 logFont
.lfUnderline
= 0;
988 logFont
.lfStrikeOut
= 0;
989 logFont
.lfCharSet
= MWLF_CHARSET_DEFAULT
; // TODO: select appropriate one
990 logFont
.lfOutPrecision
= MWLF_TYPE_DEFAULT
;
991 logFont
.lfClipPrecision
= 0; // Not used
992 logFont
.lfRoman
= (family
== wxROMAN
? 1 : 0) ;
993 logFont
.lfSerif
= (family
== wxSWISS
? 0 : 1) ;
994 logFont
.lfSansSerif
= !logFont
.lfSerif
;
995 logFont
.lfModern
= (family
== wxMODERN
? 1 : 0) ;
996 logFont
.lfProportional
= (family
== wxTELETYPE
? 0 : 1) ;
997 logFont
.lfOblique
= 0;
998 logFont
.lfSmallCaps
= 0;
999 logFont
.lfPitch
= 0; // 0 = default
1000 strcpy(logFont
.lfFaceName
, facename
.c_str());
1002 XFontStruct
* fontInfo
= (XFontStruct
*) malloc(sizeof(XFontStruct
));
1003 fontInfo
->fid
= GrCreateFont((GR_CHAR
*) facename
.c_str(), pixelHeight
, & logFont
);
1004 GrGetFontInfo(fontInfo
->fid
, & fontInfo
->info
);
1005 return (wxNativeFont
) fontInfo
;
1009 if (!facename
.IsEmpty())
1011 fontSpec
.Printf(wxT("-*-%s-*-*-normal-*-*-*-*-*-*-*-*-*"),
1014 if ( wxTestFontSpec(fontSpec
) )
1018 //else: no such family, use default one instead
1025 fontSpec
.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
1027 if ( wxTestFontSpec(fontSpec
) )
1032 // fall through - try wxITALIC now
1035 fontSpec
.Printf(wxT("-*-%s-*-i-*-*-*-*-*-*-*-*-*-*"),
1037 if ( wxTestFontSpec(fontSpec
) )
1041 else if ( style
== wxITALIC
) // and not wxSLANT
1044 fontSpec
.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
1046 if ( wxTestFontSpec(fontSpec
) )
1052 // no italic, no slant - leave default
1059 wxFAIL_MSG(_T("unknown font style"));
1060 // fall back to normal
1072 fontSpec
.Printf(wxT("-*-%s-bold-*-*-*-*-*-*-*-*-*-*-*"),
1074 if ( wxTestFontSpec(fontSpec
) )
1076 xweight
= wxT("bold");
1079 fontSpec
.Printf(wxT("-*-%s-heavy-*-*-*-*-*-*-*-*-*-*-*"),
1081 if ( wxTestFontSpec(fontSpec
) )
1083 xweight
= wxT("heavy");
1086 fontSpec
.Printf(wxT("-*-%s-extrabold-*-*-*-*-*-*-*-*-*-*-*"),
1088 if ( wxTestFontSpec(fontSpec
) )
1090 xweight
= wxT("extrabold");
1093 fontSpec
.Printf(wxT("-*-%s-demibold-*-*-*-*-*-*-*-*-*-*-*"),
1095 if ( wxTestFontSpec(fontSpec
) )
1097 xweight
= wxT("demibold");
1100 fontSpec
.Printf(wxT("-*-%s-black-*-*-*-*-*-*-*-*-*-*-*"),
1102 if ( wxTestFontSpec(fontSpec
) )
1104 xweight
= wxT("black");
1107 fontSpec
.Printf(wxT("-*-%s-ultrablack-*-*-*-*-*-*-*-*-*-*-*"),
1109 if ( wxTestFontSpec(fontSpec
) )
1111 xweight
= wxT("ultrablack");
1118 fontSpec
.Printf(wxT("-*-%s-light-*-*-*-*-*-*-*-*-*-*-*"),
1120 if ( wxTestFontSpec(fontSpec
) )
1122 xweight
= wxT("light");
1125 fontSpec
.Printf(wxT("-*-%s-thin-*-*-*-*-*-*-*-*-*-*-*"),
1127 if ( wxTestFontSpec(fontSpec
) )
1129 xweight
= wxT("thin");
1136 fontSpec
.Printf(wxT("-*-%s-medium-*-*-*-*-*-*-*-*-*-*-*"),
1138 if ( wxTestFontSpec(fontSpec
) )
1140 xweight
= wxT("medium");
1143 fontSpec
.Printf(wxT("-*-%s-normal-*-*-*-*-*-*-*-*-*-*-*"),
1145 if ( wxTestFontSpec(fontSpec
) )
1147 xweight
= wxT("normal");
1150 fontSpec
.Printf(wxT("-*-%s-regular-*-*-*-*-*-*-*-*-*-*-*"),
1152 if ( wxTestFontSpec(fontSpec
) )
1154 xweight
= wxT("regular");
1160 default: xweight
= wxT("*"); break;
1163 // if pointSize is -1, don't specify any
1165 if ( pointSize
== -1 )
1171 sizeSpec
.Printf(_T("%d"), pointSize
);
1174 // construct the X font spec from our data
1175 fontSpec
.Printf(wxT("-*-%s-%s-%s-normal-*-*-%s-*-*-*-*-%s-%s"),
1176 xfamily
.c_str(), xweight
.c_str(), xstyle
.c_str(),
1177 sizeSpec
.c_str(), xregistry
.c_str(), xencoding
.c_str());
1180 *xFontName
= fontSpec
;
1182 return wxLoadFont(fontSpec
);
1187 // ----------------------------------------------------------------------------
1189 // ----------------------------------------------------------------------------
1191 class wxFontModule
: public wxModule
1198 DECLARE_DYNAMIC_CLASS(wxFontModule
)
1201 IMPLEMENT_DYNAMIC_CLASS(wxFontModule
, wxModule
)
1203 bool wxFontModule::OnInit()
1205 g_fontHash
= new wxHashTable( wxKEY_STRING
);
1210 void wxFontModule::OnExit()
1214 g_fontHash
= (wxHashTable
*)NULL
;
1217 #endif // GTK 2.0/1.x