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 wxString field
= tokenizer
.GetNextToken();
395 if ( !field
.empty() && field
!= _T('*') )
397 // we're really initialized now
401 fontElements
[n
] = field
;
404 // this should be all
405 if ( tokenizer
.HasMoreTokens() )
411 wxString
wxNativeFontInfo::GetXFontName() const
413 if ( xFontName
.empty() )
415 for ( size_t n
= 0; n
< WXSIZEOF(fontElements
); n
++ )
417 // replace the non specified elements with '*' except for the
418 // additional style which is usually just omitted
419 wxString elt
= fontElements
[n
];
420 if ( elt
.empty() && n
!= wxXLFD_ADDSTYLE
)
426 ((wxNativeFontInfo
*)this)->xFontName
<< _T('-') << elt
;
434 wxNativeFontInfo::SetXFontComponent(wxXLFDField field
, const wxString
& value
)
436 wxCHECK_RET( field
< wxXLFD_MAX
, _T("invalid XLFD field") );
438 // this class should be initialized with a valid font spec first and only
439 // then the fields may be modified!
440 wxASSERT_MSG( !IsDefault(), _T("can't modify an uninitialized XLFD") );
442 if ( !HasElements() )
445 if ( !((wxNativeFontInfo
*)this)->FromXFontName(xFontName
) )
447 wxFAIL_MSG( _T("can't set font element for invalid XLFD") );
453 fontElements
[field
] = value
;
455 // invalidate the XFLD, it doesn't correspond to the font elements any more
459 void wxNativeFontInfo::SetXFontName(const wxString
& xFontName_
)
461 // invalidate the font elements, GetXFontComponent() will reparse the XLFD
462 fontElements
[0].clear();
464 xFontName
= xFontName_
;
469 int wxNativeFontInfo::GetPointSize() const
471 const wxString s
= GetXFontComponent(wxXLFD_POINTSIZE
);
473 // return -1 to indicate that the size is unknown
475 return s
.ToLong(&l
) ? l
: -1;
478 wxFontStyle
wxNativeFontInfo::GetStyle() const
480 const wxString s
= GetXFontComponent(wxXLFD_SLANT
);
482 if ( s
.length() != 1 )
484 // it is really unknown but we don't have any way to return it from
486 return wxFONTSTYLE_NORMAL
;
492 // again, unknown but consider normal by default
495 return wxFONTSTYLE_NORMAL
;
498 return wxFONTSTYLE_ITALIC
;
501 return wxFONTSTYLE_SLANT
;
505 wxFontWeight
wxNativeFontInfo::GetWeight() const
507 const wxString s
= GetXFontComponent(wxXLFD_WEIGHT
).MakeLower();
508 if ( s
.find(_T("bold")) != wxString::npos
|| s
== _T("black") )
509 return wxFONTWEIGHT_BOLD
;
510 else if ( s
== _T("light") )
511 return wxFONTWEIGHT_LIGHT
;
513 return wxFONTWEIGHT_NORMAL
;
516 bool wxNativeFontInfo::GetUnderlined() const
518 // X fonts are never underlined
522 wxString
wxNativeFontInfo::GetFaceName() const
524 // wxWindows facename probably more accurately corresponds to X family
525 return GetXFontComponent(wxXLFD_FAMILY
);
528 wxFontFamily
wxNativeFontInfo::GetFamily() const
530 // and wxWindows family -- to X foundry, but we have to translate it to
531 // wxFontFamily somehow...
532 wxFAIL_MSG(_T("not implemented")); // GetXFontComponent(wxXLFD_FOUNDRY);
534 return wxFONTFAMILY_DEFAULT
;
537 wxFontEncoding
wxNativeFontInfo::GetEncoding() const
539 // we already have the code for this but need to refactor it first
540 wxFAIL_MSG( _T("not implemented") );
542 return wxFONTENCODING_MAX
;
545 void wxNativeFontInfo::SetPointSize(int pointsize
)
547 SetXFontComponent(wxXLFD_POINTSIZE
, wxString::Format(_T("%d"), pointsize
));
550 void wxNativeFontInfo::SetStyle(wxFontStyle style
)
555 case wxFONTSTYLE_ITALIC
:
559 case wxFONTSTYLE_SLANT
:
563 case wxFONTSTYLE_NORMAL
:
567 wxFAIL_MSG( _T("unknown wxFontStyle in wxNativeFontInfo::SetStyle") );
571 SetXFontComponent(wxXLFD_SLANT
, s
);
574 void wxNativeFontInfo::SetWeight(wxFontWeight weight
)
579 case wxFONTWEIGHT_BOLD
:
583 case wxFONTWEIGHT_LIGHT
:
587 case wxFONTWEIGHT_NORMAL
:
592 wxFAIL_MSG( _T("unknown wxFontWeight in wxNativeFontInfo::SetWeight") );
596 SetXFontComponent(wxXLFD_WEIGHT
, s
);
599 void wxNativeFontInfo::SetUnderlined(bool WXUNUSED(underlined
))
601 // can't do this under X
604 void wxNativeFontInfo::SetFaceName(wxString facename
)
606 SetXFontComponent(wxXLFD_FAMILY
, facename
);
609 void wxNativeFontInfo::SetFamily(wxFontFamily family
)
611 // wxFontFamily -> X foundry, anyone?
612 wxFAIL_MSG( _T("not implemented") );
614 // SetXFontComponent(wxXLFD_FOUNDRY, ...);
617 void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding
)
619 wxNativeEncodingInfo info
;
620 if ( wxGetNativeFontEncoding(encoding
, &info
) )
622 SetXFontComponent(wxXLFD_ENCODING
, info
.xencoding
);
623 SetXFontComponent(wxXLFD_REGISTRY
, info
.xregistry
);
627 // ----------------------------------------------------------------------------
629 // ----------------------------------------------------------------------------
631 bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
632 wxNativeEncodingInfo
*info
)
634 wxCHECK_MSG( info
, FALSE
, _T("bad pointer in wxGetNativeFontEncoding") );
636 if ( encoding
== wxFONTENCODING_DEFAULT
)
638 encoding
= wxFont::GetDefaultEncoding();
643 case wxFONTENCODING_ISO8859_1
:
644 case wxFONTENCODING_ISO8859_2
:
645 case wxFONTENCODING_ISO8859_3
:
646 case wxFONTENCODING_ISO8859_4
:
647 case wxFONTENCODING_ISO8859_5
:
648 case wxFONTENCODING_ISO8859_6
:
649 case wxFONTENCODING_ISO8859_7
:
650 case wxFONTENCODING_ISO8859_8
:
651 case wxFONTENCODING_ISO8859_9
:
652 case wxFONTENCODING_ISO8859_10
:
653 case wxFONTENCODING_ISO8859_11
:
654 case wxFONTENCODING_ISO8859_12
:
655 case wxFONTENCODING_ISO8859_13
:
656 case wxFONTENCODING_ISO8859_14
:
657 case wxFONTENCODING_ISO8859_15
:
659 int cp
= encoding
- wxFONTENCODING_ISO8859_1
+ 1;
660 info
->xregistry
= wxT("iso8859");
661 info
->xencoding
.Printf(wxT("%d"), cp
);
665 case wxFONTENCODING_UTF8
:
666 info
->xregistry
= wxT("iso10646");
667 info
->xencoding
= wxT("*");
670 case wxFONTENCODING_GB2312
:
671 info
->xregistry
= wxT("GB2312"); // or the otherway round?
672 info
->xencoding
= wxT("*");
675 case wxFONTENCODING_KOI8
:
676 info
->xregistry
= wxT("koi8");
678 // we don't make distinction between koi8-r, koi8-u and koi8-ru (so far)
679 info
->xencoding
= wxT("*");
682 case wxFONTENCODING_CP1250
:
683 case wxFONTENCODING_CP1251
:
684 case wxFONTENCODING_CP1252
:
685 case wxFONTENCODING_CP1253
:
686 case wxFONTENCODING_CP1254
:
687 case wxFONTENCODING_CP1255
:
688 case wxFONTENCODING_CP1256
:
689 case wxFONTENCODING_CP1257
:
691 int cp
= encoding
- wxFONTENCODING_CP1250
+ 1250;
692 info
->xregistry
= wxT("microsoft");
693 info
->xencoding
.Printf(wxT("cp%d"), cp
);
697 case wxFONTENCODING_SYSTEM
:
699 info
->xencoding
= wxT("*");
703 // don't know how to translate this encoding into X fontspec
707 info
->encoding
= encoding
;
712 bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
)
715 fontspec
.Printf(_T("-*-%s-*-*-*-*-*-*-*-*-*-*-%s-%s"),
716 !info
.facename
? _T("*") : info
.facename
.c_str(),
717 info
.xregistry
.c_str(),
718 info
.xencoding
.c_str());
720 return wxTestFontSpec(fontspec
);
723 // ----------------------------------------------------------------------------
724 // X-specific functions
725 // ----------------------------------------------------------------------------
727 wxNativeFont
wxLoadQueryNearestFont(int pointSize
,
732 const wxString
&facename
,
733 wxFontEncoding encoding
,
736 if ( encoding
== wxFONTENCODING_DEFAULT
)
738 encoding
= wxFont::GetDefaultEncoding();
741 // first determine the encoding - if the font doesn't exist at all in this
742 // encoding, it's useless to do all other approximations (i.e. size,
743 // family &c don't matter much)
744 wxNativeEncodingInfo info
;
745 if ( encoding
== wxFONTENCODING_SYSTEM
)
747 // This will always work so we don't test to save time
748 wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM
, &info
);
752 if ( !wxGetNativeFontEncoding(encoding
, &info
) ||
753 !wxTestFontEncoding(info
) )
756 if ( !wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
757 #endif // wxUSE_FONTMAP
759 // unspported encoding - replace it with the default
761 // NB: we can't just return 0 from here because wxGTK code doesn't
762 // check for it (i.e. it supposes that we'll always succeed),
763 // so it would provoke a crash
764 wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM
, &info
);
769 // OK, we have the correct xregistry/xencoding in info structure
770 wxNativeFont font
= 0;
772 // if we already have the X font name, try to use it
773 if( xFontName
&& !xFontName
->IsEmpty() )
776 // Make sure point size is correct for scale factor.
778 wxStringTokenizer
tokenizer(*xFontName
, _T("-"), wxTOKEN_RET_DELIMS
);
779 wxString newFontName
;
781 for(int i
= 0; i
< 8; i
++)
782 newFontName
+= tokenizer
.NextToken();
784 (void) tokenizer
.NextToken();
786 newFontName
+= wxString::Format(wxT("%d-"), pointSize
);
788 while(tokenizer
.HasMoreTokens())
789 newFontName
+= tokenizer
.GetNextToken();
791 font
= wxLoadFont(newFontName
);
794 *xFontName
= newFontName
;
797 // try to load exactly the font requested first
800 font
= wxLoadQueryFont( pointSize
, family
, style
, weight
,
801 underlined
, facename
,
802 info
.xregistry
, info
.xencoding
,
808 // search up and down by stepsize 10
809 int max_size
= pointSize
+ 20 * (1 + (pointSize
/180));
810 int min_size
= pointSize
- 20 * (1 + (pointSize
/180));
814 // Search for smaller size (approx.)
815 for ( i
= pointSize
- 10; !font
&& i
>= 10 && i
>= min_size
; i
-= 10 )
817 font
= wxLoadQueryFont(i
, family
, style
, weight
, underlined
,
818 facename
, info
.xregistry
, info
.xencoding
,
822 // Search for larger size (approx.)
823 for ( i
= pointSize
+ 10; !font
&& i
<= max_size
; i
+= 10 )
825 font
= wxLoadQueryFont(i
, family
, style
, weight
, underlined
,
826 facename
, info
.xregistry
, info
.xencoding
,
830 // Try default family
831 if ( !font
&& family
!= wxDEFAULT
)
833 font
= wxLoadQueryFont(pointSize
, wxDEFAULT
, style
, weight
,
834 underlined
, facename
,
835 info
.xregistry
, info
.xencoding
,
839 // ignore size, family, style and weight but try to find font with the
840 // given facename and encoding
843 font
= wxLoadQueryFont(120, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
844 underlined
, facename
,
845 info
.xregistry
, info
.xencoding
,
848 // ignore family as well
851 font
= wxLoadQueryFont(120, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
852 underlined
, wxEmptyString
,
853 info
.xregistry
, info
.xencoding
,
856 // if it still failed, try to get the font of any size but
857 // with the requested encoding: this can happen if the
858 // encoding is only available in one size which happens to be
859 // different from 120
862 font
= wxLoadQueryFont(-1, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
863 FALSE
, wxEmptyString
,
864 info
.xregistry
, info
.xencoding
,
867 // this should never happen as we had tested for it in the
868 // very beginning, but if it does, do return something non
869 // NULL or we'd crash in wxFont code
872 wxFAIL_MSG( _T("this encoding should be available!") );
874 font
= wxLoadQueryFont(-1,
875 wxDEFAULT
, wxNORMAL
, wxNORMAL
,
876 FALSE
, wxEmptyString
,
888 // ----------------------------------------------------------------------------
890 // ----------------------------------------------------------------------------
892 // returns TRUE if there are any fonts matching this font spec
893 static bool wxTestFontSpec(const wxString
& fontspec
)
895 // some X servers will fail to load this font because there are too many
896 // matches so we must test explicitly for this
897 if ( fontspec
== _T("-*-*-*-*-*-*-*-*-*-*-*-*-*-*") )
902 wxNativeFont test
= (wxNativeFont
) g_fontHash
->Get( fontspec
);
908 test
= wxLoadFont(fontspec
);
909 g_fontHash
->Put( fontspec
, (wxObject
*) test
);
923 static wxNativeFont
wxLoadQueryFont(int pointSize
,
927 bool WXUNUSED(underlined
),
928 const wxString
& facename
,
929 const wxString
& xregistry
,
930 const wxString
& xencoding
,
936 case wxDECORATIVE
: xfamily
= wxT("lucida"); break;
937 case wxROMAN
: xfamily
= wxT("times"); break;
938 case wxMODERN
: xfamily
= wxT("courier"); break;
939 case wxSWISS
: xfamily
= wxT("helvetica"); break;
940 case wxTELETYPE
: xfamily
= wxT("lucidatypewriter"); break;
941 case wxSCRIPT
: xfamily
= wxT("utopia"); break;
942 default: xfamily
= wxT("*");
950 xweight
= MWLF_WEIGHT_BOLD
;
955 xweight
= MWLF_WEIGHT_LIGHT
;
960 xweight
= MWLF_WEIGHT_NORMAL
;
966 xweight
= MWLF_WEIGHT_DEFAULT
;
970 GR_SCREEN_INFO screenInfo
;
971 GrGetScreenInfo(& screenInfo
);
973 int yPixelsPerCM
= screenInfo
.ydpcm
;
975 // A point is 1/72 of an inch.
976 // An inch is 2.541 cm.
977 // So pixelHeight = (pointSize / 72) (inches) * 2.541 (for cm) * yPixelsPerCM (for pixels)
978 // In fact pointSize is 10 * the normal point size so
981 int pixelHeight
= (int) ( (((float)pointSize
) / 720.0) * 2.541 * (float) yPixelsPerCM
) ;
983 // An alternative: assume that the screen is 72 dpi.
984 //int pixelHeight = (int) (((float)pointSize / 720.0) * 72.0) ;
985 //int pixelHeight = (int) ((float)pointSize / 10.0) ;
988 logFont
.lfHeight
= pixelHeight
;
990 logFont
.lfEscapement
= 0;
991 logFont
.lfOrientation
= 0;
992 logFont
.lfWeight
= xweight
;
993 logFont
.lfItalic
= (style
== wxNORMAL
? 0 : 1) ;
994 logFont
.lfUnderline
= 0;
995 logFont
.lfStrikeOut
= 0;
996 logFont
.lfCharSet
= MWLF_CHARSET_DEFAULT
; // TODO: select appropriate one
997 logFont
.lfOutPrecision
= MWLF_TYPE_DEFAULT
;
998 logFont
.lfClipPrecision
= 0; // Not used
999 logFont
.lfRoman
= (family
== wxROMAN
? 1 : 0) ;
1000 logFont
.lfSerif
= (family
== wxSWISS
? 0 : 1) ;
1001 logFont
.lfSansSerif
= !logFont
.lfSerif
;
1002 logFont
.lfModern
= (family
== wxMODERN
? 1 : 0) ;
1003 logFont
.lfProportional
= (family
== wxTELETYPE
? 0 : 1) ;
1004 logFont
.lfOblique
= 0;
1005 logFont
.lfSmallCaps
= 0;
1006 logFont
.lfPitch
= 0; // 0 = default
1007 strcpy(logFont
.lfFaceName
, facename
.c_str());
1009 XFontStruct
* fontInfo
= (XFontStruct
*) malloc(sizeof(XFontStruct
));
1010 fontInfo
->fid
= GrCreateFont((GR_CHAR
*) facename
.c_str(), pixelHeight
, & logFont
);
1011 GrGetFontInfo(fontInfo
->fid
, & fontInfo
->info
);
1012 return (wxNativeFont
) fontInfo
;
1016 if (!facename
.IsEmpty())
1018 fontSpec
.Printf(wxT("-*-%s-*-*-normal-*-*-*-*-*-*-*-*-*"),
1021 if ( wxTestFontSpec(fontSpec
) )
1025 //else: no such family, use default one instead
1032 fontSpec
.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
1034 if ( wxTestFontSpec(fontSpec
) )
1039 // fall through - try wxITALIC now
1042 fontSpec
.Printf(wxT("-*-%s-*-i-*-*-*-*-*-*-*-*-*-*"),
1044 if ( wxTestFontSpec(fontSpec
) )
1048 else if ( style
== wxITALIC
) // and not wxSLANT
1051 fontSpec
.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
1053 if ( wxTestFontSpec(fontSpec
) )
1059 // no italic, no slant - leave default
1066 wxFAIL_MSG(_T("unknown font style"));
1067 // fall back to normal
1079 fontSpec
.Printf(wxT("-*-%s-bold-*-*-*-*-*-*-*-*-*-*-*"),
1081 if ( wxTestFontSpec(fontSpec
) )
1083 xweight
= wxT("bold");
1086 fontSpec
.Printf(wxT("-*-%s-heavy-*-*-*-*-*-*-*-*-*-*-*"),
1088 if ( wxTestFontSpec(fontSpec
) )
1090 xweight
= wxT("heavy");
1093 fontSpec
.Printf(wxT("-*-%s-extrabold-*-*-*-*-*-*-*-*-*-*-*"),
1095 if ( wxTestFontSpec(fontSpec
) )
1097 xweight
= wxT("extrabold");
1100 fontSpec
.Printf(wxT("-*-%s-demibold-*-*-*-*-*-*-*-*-*-*-*"),
1102 if ( wxTestFontSpec(fontSpec
) )
1104 xweight
= wxT("demibold");
1107 fontSpec
.Printf(wxT("-*-%s-black-*-*-*-*-*-*-*-*-*-*-*"),
1109 if ( wxTestFontSpec(fontSpec
) )
1111 xweight
= wxT("black");
1114 fontSpec
.Printf(wxT("-*-%s-ultrablack-*-*-*-*-*-*-*-*-*-*-*"),
1116 if ( wxTestFontSpec(fontSpec
) )
1118 xweight
= wxT("ultrablack");
1125 fontSpec
.Printf(wxT("-*-%s-light-*-*-*-*-*-*-*-*-*-*-*"),
1127 if ( wxTestFontSpec(fontSpec
) )
1129 xweight
= wxT("light");
1132 fontSpec
.Printf(wxT("-*-%s-thin-*-*-*-*-*-*-*-*-*-*-*"),
1134 if ( wxTestFontSpec(fontSpec
) )
1136 xweight
= wxT("thin");
1143 fontSpec
.Printf(wxT("-*-%s-medium-*-*-*-*-*-*-*-*-*-*-*"),
1145 if ( wxTestFontSpec(fontSpec
) )
1147 xweight
= wxT("medium");
1150 fontSpec
.Printf(wxT("-*-%s-normal-*-*-*-*-*-*-*-*-*-*-*"),
1152 if ( wxTestFontSpec(fontSpec
) )
1154 xweight
= wxT("normal");
1157 fontSpec
.Printf(wxT("-*-%s-regular-*-*-*-*-*-*-*-*-*-*-*"),
1159 if ( wxTestFontSpec(fontSpec
) )
1161 xweight
= wxT("regular");
1167 default: xweight
= wxT("*"); break;
1170 // if pointSize is -1, don't specify any
1172 if ( pointSize
== -1 )
1178 sizeSpec
.Printf(_T("%d"), pointSize
);
1181 // construct the X font spec from our data
1182 fontSpec
.Printf(wxT("-*-%s-%s-%s-normal-*-*-%s-*-*-*-*-%s-%s"),
1183 xfamily
.c_str(), xweight
.c_str(), xstyle
.c_str(),
1184 sizeSpec
.c_str(), xregistry
.c_str(), xencoding
.c_str());
1187 *xFontName
= fontSpec
;
1189 return wxLoadFont(fontSpec
);
1194 // ----------------------------------------------------------------------------
1196 // ----------------------------------------------------------------------------
1198 class wxFontModule
: public wxModule
1205 DECLARE_DYNAMIC_CLASS(wxFontModule
)
1208 IMPLEMENT_DYNAMIC_CLASS(wxFontModule
, wxModule
)
1210 bool wxFontModule::OnInit()
1212 g_fontHash
= new wxHashTable( wxKEY_STRING
);
1217 void wxFontModule::OnExit()
1221 g_fontHash
= (wxHashTable
*)NULL
;
1224 #endif // GTK 2.0/1.x