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 // VZ: we should use gdk_fontset_load() instead of gdk_font_load()
239 // here to be able to display Japanese fonts correctly (at least
240 // this is what people report) but unfortunately doing it results
241 // in tons of warnings when using GTK with "normal" European
242 // languages and so we can't always do it and I don't know enough
243 // to determine when should this be done... (FIXME)
244 return gdk_font_load( wxConvertWX2MB(fontSpec
) );
247 inline void wxFreeFont(wxNativeFont font
)
249 gdk_font_unref(font
);
252 #error "Unknown GUI toolkit"
255 static bool wxTestFontSpec(const wxString
& fontspec
);
257 static wxNativeFont
wxLoadQueryFont(int pointSize
,
262 const wxString
& facename
,
263 const wxString
& xregistry
,
264 const wxString
& xencoding
,
265 wxString
* xFontName
);
267 // ============================================================================
269 // ============================================================================
271 // ----------------------------------------------------------------------------
272 // wxNativeEncodingInfo
273 // ----------------------------------------------------------------------------
275 // convert to/from the string representation: format is
276 // encodingid;registry;encoding[;facename]
277 bool wxNativeEncodingInfo::FromString(const wxString
& s
)
279 // use ";", not "-" because it may be part of encoding name
280 wxStringTokenizer
tokenizer(s
, _T(";"));
282 wxString encid
= tokenizer
.GetNextToken();
284 if ( !encid
.ToLong(&enc
) )
286 encoding
= (wxFontEncoding
)enc
;
288 xregistry
= tokenizer
.GetNextToken();
292 xencoding
= tokenizer
.GetNextToken();
297 facename
= tokenizer
.GetNextToken();
302 wxString
wxNativeEncodingInfo::ToString() const
305 s
<< (long)encoding
<< _T(';') << xregistry
<< _T(';') << xencoding
;
308 s
<< _T(';') << facename
;
314 // ----------------------------------------------------------------------------
316 // ----------------------------------------------------------------------------
318 void wxNativeFontInfo::Init()
323 bool wxNativeFontInfo::FromString(const wxString
& s
)
325 wxStringTokenizer
tokenizer(s
, _T(";"));
328 wxString token
= tokenizer
.GetNextToken();
329 if ( token
!= _T('0') )
332 xFontName
= tokenizer
.GetNextToken();
334 // this should be the end
335 if ( tokenizer
.HasMoreTokens() )
338 return FromXFontName(xFontName
);
341 wxString
wxNativeFontInfo::ToString() const
344 return wxString::Format(_T("%d;%s"), 0, GetXFontName().c_str());
347 bool wxNativeFontInfo::FromUserString(const wxString
& s
)
349 return FromXFontName(s
);
352 wxString
wxNativeFontInfo::ToUserString() const
354 return GetXFontName();
357 bool wxNativeFontInfo::HasElements() const
359 // we suppose that the foundry is never empty, so if it is it means that we
360 // had never parsed the XLFD
361 return !fontElements
[0].empty();
364 wxString
wxNativeFontInfo::GetXFontComponent(wxXLFDField field
) const
366 wxCHECK_MSG( field
< wxXLFD_MAX
, _T(""), _T("invalid XLFD field") );
368 if ( !HasElements() )
371 if ( !((wxNativeFontInfo
*)this)->FromXFontName(xFontName
) )
375 return fontElements
[field
];
378 bool wxNativeFontInfo::FromXFontName(const wxString
& fontname
)
380 // TODO: we should be able to handle the font aliases here, but how?
381 wxStringTokenizer
tokenizer(fontname
, _T("-"));
383 // skip the leading, usually empty field (font name registry)
384 if ( !tokenizer
.HasMoreTokens() )
387 (void)tokenizer
.GetNextToken();
389 for ( size_t n
= 0; n
< WXSIZEOF(fontElements
); n
++ )
391 if ( !tokenizer
.HasMoreTokens() )
393 // not enough elements in the XLFD - or maybe an alias
397 wxString field
= tokenizer
.GetNextToken();
398 if ( !field
.empty() && field
!= _T('*') )
400 // we're really initialized now
404 fontElements
[n
] = field
;
407 // this should be all
408 if ( tokenizer
.HasMoreTokens() )
414 wxString
wxNativeFontInfo::GetXFontName() const
416 if ( xFontName
.empty() )
418 for ( size_t n
= 0; n
< WXSIZEOF(fontElements
); n
++ )
420 // replace the non specified elements with '*' except for the
421 // additional style which is usually just omitted
422 wxString elt
= fontElements
[n
];
423 if ( elt
.empty() && n
!= wxXLFD_ADDSTYLE
)
429 ((wxNativeFontInfo
*)this)->xFontName
<< _T('-') << elt
;
437 wxNativeFontInfo::SetXFontComponent(wxXLFDField field
, const wxString
& value
)
439 wxCHECK_RET( field
< wxXLFD_MAX
, _T("invalid XLFD field") );
441 // this class should be initialized with a valid font spec first and only
442 // then the fields may be modified!
443 wxASSERT_MSG( !IsDefault(), _T("can't modify an uninitialized XLFD") );
445 if ( !HasElements() )
448 if ( !((wxNativeFontInfo
*)this)->FromXFontName(xFontName
) )
450 wxFAIL_MSG( _T("can't set font element for invalid XLFD") );
456 fontElements
[field
] = value
;
458 // invalidate the XFLD, it doesn't correspond to the font elements any more
462 void wxNativeFontInfo::SetXFontName(const wxString
& xFontName_
)
464 // invalidate the font elements, GetXFontComponent() will reparse the XLFD
465 fontElements
[0].clear();
467 xFontName
= xFontName_
;
472 int wxNativeFontInfo::GetPointSize() const
474 const wxString s
= GetXFontComponent(wxXLFD_POINTSIZE
);
476 // return -1 to indicate that the size is unknown
478 return s
.ToLong(&l
) ? l
: -1;
481 wxFontStyle
wxNativeFontInfo::GetStyle() const
483 const wxString s
= GetXFontComponent(wxXLFD_SLANT
);
485 if ( s
.length() != 1 )
487 // it is really unknown but we don't have any way to return it from
489 return wxFONTSTYLE_NORMAL
;
495 // again, unknown but consider normal by default
498 return wxFONTSTYLE_NORMAL
;
501 return wxFONTSTYLE_ITALIC
;
504 return wxFONTSTYLE_SLANT
;
508 wxFontWeight
wxNativeFontInfo::GetWeight() const
510 const wxString s
= GetXFontComponent(wxXLFD_WEIGHT
).MakeLower();
511 if ( s
.find(_T("bold")) != wxString::npos
|| s
== _T("black") )
512 return wxFONTWEIGHT_BOLD
;
513 else if ( s
== _T("light") )
514 return wxFONTWEIGHT_LIGHT
;
516 return wxFONTWEIGHT_NORMAL
;
519 bool wxNativeFontInfo::GetUnderlined() const
521 // X fonts are never underlined
525 wxString
wxNativeFontInfo::GetFaceName() const
527 // wxWindows facename probably more accurately corresponds to X family
528 return GetXFontComponent(wxXLFD_FAMILY
);
531 wxFontFamily
wxNativeFontInfo::GetFamily() const
533 // and wxWindows family -- to X foundry, but we have to translate it to
534 // wxFontFamily somehow...
535 wxFAIL_MSG(_T("not implemented")); // GetXFontComponent(wxXLFD_FOUNDRY);
537 return wxFONTFAMILY_DEFAULT
;
540 wxFontEncoding
wxNativeFontInfo::GetEncoding() const
542 // we already have the code for this but need to refactor it first
543 wxFAIL_MSG( _T("not implemented") );
545 return wxFONTENCODING_MAX
;
548 void wxNativeFontInfo::SetPointSize(int pointsize
)
550 SetXFontComponent(wxXLFD_POINTSIZE
, wxString::Format(_T("%d"), pointsize
));
553 void wxNativeFontInfo::SetStyle(wxFontStyle style
)
558 case wxFONTSTYLE_ITALIC
:
562 case wxFONTSTYLE_SLANT
:
566 case wxFONTSTYLE_NORMAL
:
570 wxFAIL_MSG( _T("unknown wxFontStyle in wxNativeFontInfo::SetStyle") );
574 SetXFontComponent(wxXLFD_SLANT
, s
);
577 void wxNativeFontInfo::SetWeight(wxFontWeight weight
)
582 case wxFONTWEIGHT_BOLD
:
586 case wxFONTWEIGHT_LIGHT
:
590 case wxFONTWEIGHT_NORMAL
:
595 wxFAIL_MSG( _T("unknown wxFontWeight in wxNativeFontInfo::SetWeight") );
599 SetXFontComponent(wxXLFD_WEIGHT
, s
);
602 void wxNativeFontInfo::SetUnderlined(bool WXUNUSED(underlined
))
604 // can't do this under X
607 void wxNativeFontInfo::SetFaceName(wxString facename
)
609 SetXFontComponent(wxXLFD_FAMILY
, facename
);
612 void wxNativeFontInfo::SetFamily(wxFontFamily family
)
614 // wxFontFamily -> X foundry, anyone?
615 wxFAIL_MSG( _T("not implemented") );
617 // SetXFontComponent(wxXLFD_FOUNDRY, ...);
620 void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding
)
622 wxNativeEncodingInfo info
;
623 if ( wxGetNativeFontEncoding(encoding
, &info
) )
625 SetXFontComponent(wxXLFD_ENCODING
, info
.xencoding
);
626 SetXFontComponent(wxXLFD_REGISTRY
, info
.xregistry
);
630 // ----------------------------------------------------------------------------
632 // ----------------------------------------------------------------------------
634 bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
635 wxNativeEncodingInfo
*info
)
637 wxCHECK_MSG( info
, FALSE
, _T("bad pointer in wxGetNativeFontEncoding") );
639 if ( encoding
== wxFONTENCODING_DEFAULT
)
641 encoding
= wxFont::GetDefaultEncoding();
646 case wxFONTENCODING_ISO8859_1
:
647 case wxFONTENCODING_ISO8859_2
:
648 case wxFONTENCODING_ISO8859_3
:
649 case wxFONTENCODING_ISO8859_4
:
650 case wxFONTENCODING_ISO8859_5
:
651 case wxFONTENCODING_ISO8859_6
:
652 case wxFONTENCODING_ISO8859_7
:
653 case wxFONTENCODING_ISO8859_8
:
654 case wxFONTENCODING_ISO8859_9
:
655 case wxFONTENCODING_ISO8859_10
:
656 case wxFONTENCODING_ISO8859_11
:
657 case wxFONTENCODING_ISO8859_12
:
658 case wxFONTENCODING_ISO8859_13
:
659 case wxFONTENCODING_ISO8859_14
:
660 case wxFONTENCODING_ISO8859_15
:
662 int cp
= encoding
- wxFONTENCODING_ISO8859_1
+ 1;
663 info
->xregistry
= wxT("iso8859");
664 info
->xencoding
.Printf(wxT("%d"), cp
);
668 case wxFONTENCODING_UTF8
:
669 info
->xregistry
= wxT("iso10646");
670 info
->xencoding
= wxT("*");
673 case wxFONTENCODING_GB2312
:
674 info
->xregistry
= wxT("GB2312"); // or the otherway round?
675 info
->xencoding
= wxT("*");
678 case wxFONTENCODING_KOI8
:
679 info
->xregistry
= wxT("koi8");
681 // we don't make distinction between koi8-r, koi8-u and koi8-ru (so far)
682 info
->xencoding
= wxT("*");
685 case wxFONTENCODING_CP1250
:
686 case wxFONTENCODING_CP1251
:
687 case wxFONTENCODING_CP1252
:
688 case wxFONTENCODING_CP1253
:
689 case wxFONTENCODING_CP1254
:
690 case wxFONTENCODING_CP1255
:
691 case wxFONTENCODING_CP1256
:
692 case wxFONTENCODING_CP1257
:
694 int cp
= encoding
- wxFONTENCODING_CP1250
+ 1250;
695 info
->xregistry
= wxT("microsoft");
696 info
->xencoding
.Printf(wxT("cp%d"), cp
);
700 case wxFONTENCODING_SYSTEM
:
702 info
->xencoding
= wxT("*");
706 // don't know how to translate this encoding into X fontspec
710 info
->encoding
= encoding
;
715 bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
)
718 fontspec
.Printf(_T("-*-%s-*-*-*-*-*-*-*-*-*-*-%s-%s"),
719 !info
.facename
? _T("*") : info
.facename
.c_str(),
720 info
.xregistry
.c_str(),
721 info
.xencoding
.c_str());
723 return wxTestFontSpec(fontspec
);
726 // ----------------------------------------------------------------------------
727 // X-specific functions
728 // ----------------------------------------------------------------------------
730 wxNativeFont
wxLoadQueryNearestFont(int pointSize
,
735 const wxString
&facename
,
736 wxFontEncoding encoding
,
739 if ( encoding
== wxFONTENCODING_DEFAULT
)
741 encoding
= wxFont::GetDefaultEncoding();
744 // first determine the encoding - if the font doesn't exist at all in this
745 // encoding, it's useless to do all other approximations (i.e. size,
746 // family &c don't matter much)
747 wxNativeEncodingInfo info
;
748 if ( encoding
== wxFONTENCODING_SYSTEM
)
750 // This will always work so we don't test to save time
751 wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM
, &info
);
755 if ( !wxGetNativeFontEncoding(encoding
, &info
) ||
756 !wxTestFontEncoding(info
) )
759 if ( !wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
760 #endif // wxUSE_FONTMAP
762 // unspported encoding - replace it with the default
764 // NB: we can't just return 0 from here because wxGTK code doesn't
765 // check for it (i.e. it supposes that we'll always succeed),
766 // so it would provoke a crash
767 wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM
, &info
);
772 // OK, we have the correct xregistry/xencoding in info structure
773 wxNativeFont font
= 0;
775 // if we already have the X font name, try to use it
776 if( xFontName
&& !xFontName
->IsEmpty() )
779 // Make sure point size is correct for scale factor.
781 wxStringTokenizer
tokenizer(*xFontName
, _T("-"), wxTOKEN_RET_DELIMS
);
782 wxString newFontName
;
784 for(int i
= 0; i
< 8; i
++)
785 newFontName
+= tokenizer
.NextToken();
787 (void) tokenizer
.NextToken();
789 newFontName
+= wxString::Format(wxT("%d-"), pointSize
);
791 while(tokenizer
.HasMoreTokens())
792 newFontName
+= tokenizer
.GetNextToken();
794 font
= wxLoadFont(newFontName
);
797 *xFontName
= newFontName
;
800 // try to load exactly the font requested first
803 font
= wxLoadQueryFont( pointSize
, family
, style
, weight
,
804 underlined
, facename
,
805 info
.xregistry
, info
.xencoding
,
811 // search up and down by stepsize 10
812 int max_size
= pointSize
+ 20 * (1 + (pointSize
/180));
813 int min_size
= pointSize
- 20 * (1 + (pointSize
/180));
817 // Search for smaller size (approx.)
818 for ( i
= pointSize
- 10; !font
&& i
>= 10 && i
>= min_size
; i
-= 10 )
820 font
= wxLoadQueryFont(i
, family
, style
, weight
, underlined
,
821 facename
, info
.xregistry
, info
.xencoding
,
825 // Search for larger size (approx.)
826 for ( i
= pointSize
+ 10; !font
&& i
<= max_size
; i
+= 10 )
828 font
= wxLoadQueryFont(i
, family
, style
, weight
, underlined
,
829 facename
, info
.xregistry
, info
.xencoding
,
833 // Try default family
834 if ( !font
&& family
!= wxDEFAULT
)
836 font
= wxLoadQueryFont(pointSize
, wxDEFAULT
, style
, weight
,
837 underlined
, facename
,
838 info
.xregistry
, info
.xencoding
,
842 // ignore size, family, style and weight but try to find font with the
843 // given facename and encoding
846 font
= wxLoadQueryFont(120, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
847 underlined
, facename
,
848 info
.xregistry
, info
.xencoding
,
851 // ignore family as well
854 font
= wxLoadQueryFont(120, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
855 underlined
, wxEmptyString
,
856 info
.xregistry
, info
.xencoding
,
859 // if it still failed, try to get the font of any size but
860 // with the requested encoding: this can happen if the
861 // encoding is only available in one size which happens to be
862 // different from 120
865 font
= wxLoadQueryFont(-1, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
866 FALSE
, wxEmptyString
,
867 info
.xregistry
, info
.xencoding
,
870 // this should never happen as we had tested for it in the
871 // very beginning, but if it does, do return something non
872 // NULL or we'd crash in wxFont code
875 wxFAIL_MSG( _T("this encoding should be available!") );
877 font
= wxLoadQueryFont(-1,
878 wxDEFAULT
, wxNORMAL
, wxNORMAL
,
879 FALSE
, wxEmptyString
,
891 // ----------------------------------------------------------------------------
893 // ----------------------------------------------------------------------------
895 // returns TRUE if there are any fonts matching this font spec
896 static bool wxTestFontSpec(const wxString
& fontspec
)
898 // some X servers will fail to load this font because there are too many
899 // matches so we must test explicitly for this
900 if ( fontspec
== _T("-*-*-*-*-*-*-*-*-*-*-*-*-*-*") )
905 wxNativeFont test
= (wxNativeFont
) g_fontHash
->Get( fontspec
);
911 test
= wxLoadFont(fontspec
);
912 g_fontHash
->Put( fontspec
, (wxObject
*) test
);
926 static wxNativeFont
wxLoadQueryFont(int pointSize
,
930 bool WXUNUSED(underlined
),
931 const wxString
& facename
,
932 const wxString
& xregistry
,
933 const wxString
& xencoding
,
939 case wxDECORATIVE
: xfamily
= wxT("lucida"); break;
940 case wxROMAN
: xfamily
= wxT("times"); break;
941 case wxMODERN
: xfamily
= wxT("courier"); break;
942 case wxSWISS
: xfamily
= wxT("helvetica"); break;
943 case wxTELETYPE
: xfamily
= wxT("lucidatypewriter"); break;
944 case wxSCRIPT
: xfamily
= wxT("utopia"); break;
945 default: xfamily
= wxT("*");
953 xweight
= MWLF_WEIGHT_BOLD
;
958 xweight
= MWLF_WEIGHT_LIGHT
;
963 xweight
= MWLF_WEIGHT_NORMAL
;
969 xweight
= MWLF_WEIGHT_DEFAULT
;
973 GR_SCREEN_INFO screenInfo
;
974 GrGetScreenInfo(& screenInfo
);
976 int yPixelsPerCM
= screenInfo
.ydpcm
;
978 // A point is 1/72 of an inch.
979 // An inch is 2.541 cm.
980 // So pixelHeight = (pointSize / 72) (inches) * 2.541 (for cm) * yPixelsPerCM (for pixels)
981 // In fact pointSize is 10 * the normal point size so
984 int pixelHeight
= (int) ( (((float)pointSize
) / 720.0) * 2.541 * (float) yPixelsPerCM
) ;
986 // An alternative: assume that the screen is 72 dpi.
987 //int pixelHeight = (int) (((float)pointSize / 720.0) * 72.0) ;
988 //int pixelHeight = (int) ((float)pointSize / 10.0) ;
991 logFont
.lfHeight
= pixelHeight
;
993 logFont
.lfEscapement
= 0;
994 logFont
.lfOrientation
= 0;
995 logFont
.lfWeight
= xweight
;
996 logFont
.lfItalic
= (style
== wxNORMAL
? 0 : 1) ;
997 logFont
.lfUnderline
= 0;
998 logFont
.lfStrikeOut
= 0;
999 logFont
.lfCharSet
= MWLF_CHARSET_DEFAULT
; // TODO: select appropriate one
1000 logFont
.lfOutPrecision
= MWLF_TYPE_DEFAULT
;
1001 logFont
.lfClipPrecision
= 0; // Not used
1002 logFont
.lfRoman
= (family
== wxROMAN
? 1 : 0) ;
1003 logFont
.lfSerif
= (family
== wxSWISS
? 0 : 1) ;
1004 logFont
.lfSansSerif
= !logFont
.lfSerif
;
1005 logFont
.lfModern
= (family
== wxMODERN
? 1 : 0) ;
1006 logFont
.lfProportional
= (family
== wxTELETYPE
? 0 : 1) ;
1007 logFont
.lfOblique
= 0;
1008 logFont
.lfSmallCaps
= 0;
1009 logFont
.lfPitch
= 0; // 0 = default
1010 strcpy(logFont
.lfFaceName
, facename
.c_str());
1012 XFontStruct
* fontInfo
= (XFontStruct
*) malloc(sizeof(XFontStruct
));
1013 fontInfo
->fid
= GrCreateFont((GR_CHAR
*) facename
.c_str(), pixelHeight
, & logFont
);
1014 GrGetFontInfo(fontInfo
->fid
, & fontInfo
->info
);
1015 return (wxNativeFont
) fontInfo
;
1019 if (!facename
.IsEmpty())
1021 fontSpec
.Printf(wxT("-*-%s-*-*-normal-*-*-*-*-*-*-*-*-*"),
1024 if ( wxTestFontSpec(fontSpec
) )
1028 //else: no such family, use default one instead
1035 fontSpec
.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
1037 if ( wxTestFontSpec(fontSpec
) )
1042 // fall through - try wxITALIC now
1045 fontSpec
.Printf(wxT("-*-%s-*-i-*-*-*-*-*-*-*-*-*-*"),
1047 if ( wxTestFontSpec(fontSpec
) )
1051 else if ( style
== wxITALIC
) // and not wxSLANT
1054 fontSpec
.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
1056 if ( wxTestFontSpec(fontSpec
) )
1062 // no italic, no slant - leave default
1069 wxFAIL_MSG(_T("unknown font style"));
1070 // fall back to normal
1082 fontSpec
.Printf(wxT("-*-%s-bold-*-*-*-*-*-*-*-*-*-*-*"),
1084 if ( wxTestFontSpec(fontSpec
) )
1086 xweight
= wxT("bold");
1089 fontSpec
.Printf(wxT("-*-%s-heavy-*-*-*-*-*-*-*-*-*-*-*"),
1091 if ( wxTestFontSpec(fontSpec
) )
1093 xweight
= wxT("heavy");
1096 fontSpec
.Printf(wxT("-*-%s-extrabold-*-*-*-*-*-*-*-*-*-*-*"),
1098 if ( wxTestFontSpec(fontSpec
) )
1100 xweight
= wxT("extrabold");
1103 fontSpec
.Printf(wxT("-*-%s-demibold-*-*-*-*-*-*-*-*-*-*-*"),
1105 if ( wxTestFontSpec(fontSpec
) )
1107 xweight
= wxT("demibold");
1110 fontSpec
.Printf(wxT("-*-%s-black-*-*-*-*-*-*-*-*-*-*-*"),
1112 if ( wxTestFontSpec(fontSpec
) )
1114 xweight
= wxT("black");
1117 fontSpec
.Printf(wxT("-*-%s-ultrablack-*-*-*-*-*-*-*-*-*-*-*"),
1119 if ( wxTestFontSpec(fontSpec
) )
1121 xweight
= wxT("ultrablack");
1128 fontSpec
.Printf(wxT("-*-%s-light-*-*-*-*-*-*-*-*-*-*-*"),
1130 if ( wxTestFontSpec(fontSpec
) )
1132 xweight
= wxT("light");
1135 fontSpec
.Printf(wxT("-*-%s-thin-*-*-*-*-*-*-*-*-*-*-*"),
1137 if ( wxTestFontSpec(fontSpec
) )
1139 xweight
= wxT("thin");
1146 fontSpec
.Printf(wxT("-*-%s-medium-*-*-*-*-*-*-*-*-*-*-*"),
1148 if ( wxTestFontSpec(fontSpec
) )
1150 xweight
= wxT("medium");
1153 fontSpec
.Printf(wxT("-*-%s-normal-*-*-*-*-*-*-*-*-*-*-*"),
1155 if ( wxTestFontSpec(fontSpec
) )
1157 xweight
= wxT("normal");
1160 fontSpec
.Printf(wxT("-*-%s-regular-*-*-*-*-*-*-*-*-*-*-*"),
1162 if ( wxTestFontSpec(fontSpec
) )
1164 xweight
= wxT("regular");
1170 default: xweight
= wxT("*"); break;
1173 // if pointSize is -1, don't specify any
1175 if ( pointSize
== -1 )
1181 sizeSpec
.Printf(_T("%d"), pointSize
);
1184 // construct the X font spec from our data
1185 fontSpec
.Printf(wxT("-*-%s-%s-%s-normal-*-*-%s-*-*-*-*-%s-%s"),
1186 xfamily
.c_str(), xweight
.c_str(), xstyle
.c_str(),
1187 sizeSpec
.c_str(), xregistry
.c_str(), xencoding
.c_str());
1190 *xFontName
= fontSpec
;
1192 return wxLoadFont(fontSpec
);
1197 // ----------------------------------------------------------------------------
1199 // ----------------------------------------------------------------------------
1201 class wxFontModule
: public wxModule
1208 DECLARE_DYNAMIC_CLASS(wxFontModule
)
1211 IMPLEMENT_DYNAMIC_CLASS(wxFontModule
, wxModule
)
1213 bool wxFontModule::OnInit()
1215 g_fontHash
= new wxHashTable( wxKEY_STRING
);
1220 void wxFontModule::OnExit()
1224 g_fontHash
= (wxHashTable
*)NULL
;
1227 #endif // GTK 2.0/1.x