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 wxString tmp
= wxGTK_CONV_BACK( pango_font_description_to_string( description
) );
152 bool wxNativeFontInfo::FromUserString(const wxString
& s
)
154 return FromString( s
);
157 wxString
wxNativeFontInfo::ToUserString() const
162 // ----------------------------------------------------------------------------
163 // wxNativeEncodingInfo
164 // ----------------------------------------------------------------------------
166 bool wxNativeEncodingInfo::FromString(const wxString
& s
)
171 wxString
wxNativeEncodingInfo::ToString() const
173 return wxEmptyString
;
176 bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
)
181 bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
182 wxNativeEncodingInfo
*info
)
191 #pragma message disable nosimpint
194 #include <X11/Xlib.h>
197 #pragma message enable nosimpint
200 #include "wx/utils.h" // for wxGetDisplay()
201 #elif defined(__WXGTK__)
202 // we have to declare struct tm to avoid problems with first forward
203 // declaring it in C code (glib.h included from gdk.h does it) and then
204 // defining it when time.h is included from the headers below - this is
205 // known not to work at least with Sun CC 6.01
212 // ----------------------------------------------------------------------------
214 // ----------------------------------------------------------------------------
216 static wxHashTable
*g_fontHash
= (wxHashTable
*) NULL
;
218 // ----------------------------------------------------------------------------
220 // ----------------------------------------------------------------------------
222 // define the functions to create and destroy native fonts for this toolkit
224 wxNativeFont
wxLoadFont(const wxString
& fontSpec
)
226 return XLoadQueryFont((Display
*)wxGetDisplay(), fontSpec
);
229 inline void wxFreeFont(wxNativeFont font
)
231 XFreeFont((Display
*)wxGetDisplay(), (XFontStruct
*)font
);
233 #elif defined(__WXGTK__)
234 wxNativeFont
wxLoadFont(const wxString
& fontSpec
)
236 return gdk_font_load( wxConvertWX2MB(fontSpec
) );
239 inline void wxFreeFont(wxNativeFont font
)
241 gdk_font_unref(font
);
244 #error "Unknown GUI toolkit"
247 static bool wxTestFontSpec(const wxString
& fontspec
);
249 static wxNativeFont
wxLoadQueryFont(int pointSize
,
254 const wxString
& facename
,
255 const wxString
& xregistry
,
256 const wxString
& xencoding
,
257 wxString
* xFontName
);
259 // ============================================================================
261 // ============================================================================
263 // ----------------------------------------------------------------------------
264 // wxNativeEncodingInfo
265 // ----------------------------------------------------------------------------
267 // convert to/from the string representation: format is
268 // encodingid;registry;encoding[;facename]
269 bool wxNativeEncodingInfo::FromString(const wxString
& s
)
271 // use ";", not "-" because it may be part of encoding name
272 wxStringTokenizer
tokenizer(s
, _T(";"));
274 wxString encid
= tokenizer
.GetNextToken();
276 if ( !encid
.ToLong(&enc
) )
278 encoding
= (wxFontEncoding
)enc
;
280 xregistry
= tokenizer
.GetNextToken();
284 xencoding
= tokenizer
.GetNextToken();
289 facename
= tokenizer
.GetNextToken();
294 wxString
wxNativeEncodingInfo::ToString() const
297 s
<< (long)encoding
<< _T(';') << xregistry
<< _T(';') << xencoding
;
300 s
<< _T(';') << facename
;
306 // ----------------------------------------------------------------------------
308 // ----------------------------------------------------------------------------
310 void wxNativeFontInfo::Init()
315 bool wxNativeFontInfo::FromString(const wxString
& s
)
317 wxStringTokenizer
tokenizer(s
, _T(";"));
320 wxString token
= tokenizer
.GetNextToken();
321 if ( token
!= _T('0') )
324 xFontName
= tokenizer
.GetNextToken();
326 // this should be the end
327 if ( tokenizer
.HasMoreTokens() )
330 return FromXFontName(xFontName
);
333 wxString
wxNativeFontInfo::ToString() const
336 return wxString::Format(_T("%d;%s"), 0, GetXFontName().c_str());
339 bool wxNativeFontInfo::FromUserString(const wxString
& s
)
341 return FromXFontName(s
);
344 wxString
wxNativeFontInfo::ToUserString() const
346 return GetXFontName();
349 bool wxNativeFontInfo::HasElements() const
351 // we suppose that the foundry is never empty, so if it is it means that we
352 // had never parsed the XLFD
353 return !fontElements
[0].empty();
356 wxString
wxNativeFontInfo::GetXFontComponent(wxXLFDField field
) const
358 wxCHECK_MSG( field
< wxXLFD_MAX
, _T(""), _T("invalid XLFD field") );
360 if ( !HasElements() )
363 if ( !((wxNativeFontInfo
*)this)->FromXFontName(xFontName
) )
367 return fontElements
[field
];
370 bool wxNativeFontInfo::FromXFontName(const wxString
& fontname
)
372 // TODO: we should be able to handle the font aliases here, but how?
373 wxStringTokenizer
tokenizer(fontname
, _T("-"));
375 // skip the leading, usually empty field (font name registry)
376 if ( !tokenizer
.HasMoreTokens() )
379 (void)tokenizer
.GetNextToken();
381 for ( size_t n
= 0; n
< WXSIZEOF(fontElements
); n
++ )
383 if ( !tokenizer
.HasMoreTokens() )
385 // not enough elements in the XLFD - or maybe an alias
389 fontElements
[n
] = tokenizer
.GetNextToken();
392 // this should be all
393 if ( tokenizer
.HasMoreTokens() )
396 // we're initialized now
402 wxString
wxNativeFontInfo::GetXFontName() const
404 if ( xFontName
.empty() )
406 for ( size_t n
= 0; n
< WXSIZEOF(fontElements
); n
++ )
408 // replace the non specified elements with '*' except for the
409 // additional style which is usually just omitted
410 wxString elt
= fontElements
[n
];
411 if ( elt
.empty() && n
!= wxXLFD_ADDSTYLE
)
417 ((wxNativeFontInfo
*)this)->xFontName
<< _T('-') << elt
;
425 wxNativeFontInfo::SetXFontComponent(wxXLFDField field
, const wxString
& value
)
427 wxCHECK_RET( field
< wxXLFD_MAX
, _T("invalid XLFD field") );
429 // this class should be initialized with a valid font spec first and only
430 // then the fields may be modified!
431 wxASSERT_MSG( !IsDefault(), _T("can't modify an uninitialized XLFD") );
433 if ( !HasElements() )
436 if ( !((wxNativeFontInfo
*)this)->FromXFontName(xFontName
) )
438 wxFAIL_MSG( _T("can't set font element for invalid XLFD") );
444 fontElements
[field
] = value
;
446 // invalidate the XFLD, it doesn't correspond to the font elements any more
450 void wxNativeFontInfo::SetXFontName(const wxString
& xFontName_
)
452 // invalidate the font elements, GetXFontComponent() will reparse the XLFD
453 fontElements
[0].clear();
455 xFontName
= xFontName_
;
460 int wxNativeFontInfo::GetPointSize() const
462 const wxString s
= GetXFontComponent(wxXLFD_POINTSIZE
);
464 // return -1 to indicate that the size is unknown
466 return s
.ToLong(&l
) ? l
: -1;
469 wxFontStyle
wxNativeFontInfo::GetStyle() const
471 const wxString s
= GetXFontComponent(wxXLFD_SLANT
);
473 if ( s
.length() != 1 )
475 // it is really unknown but we don't have any way to return it from
477 return wxFONTSTYLE_NORMAL
;
483 // again, unknown but consider normal by default
486 return wxFONTSTYLE_NORMAL
;
489 return wxFONTSTYLE_ITALIC
;
492 return wxFONTSTYLE_SLANT
;
496 wxFontWeight
wxNativeFontInfo::GetWeight() const
498 const wxString s
= GetXFontComponent(wxXLFD_WEIGHT
).MakeLower();
499 if ( s
.find(_T("bold")) != wxString::npos
|| s
== _T("black") )
500 return wxFONTWEIGHT_BOLD
;
501 else if ( s
== _T("light") )
502 return wxFONTWEIGHT_LIGHT
;
504 return wxFONTWEIGHT_NORMAL
;
507 bool wxNativeFontInfo::GetUnderlined() const
509 // X fonts are never underlined
513 wxString
wxNativeFontInfo::GetFaceName() const
515 // wxWindows facename probably more accurately corresponds to X family
516 return GetXFontComponent(wxXLFD_FAMILY
);
519 wxFontFamily
wxNativeFontInfo::GetFamily() const
521 // and wxWindows family -- to X foundry, but we have to translate it to
522 // wxFontFamily somehow...
523 wxFAIL_MSG(_T("not implemented")); // GetXFontComponent(wxXLFD_FOUNDRY);
525 return wxFONTFAMILY_DEFAULT
;
528 wxFontEncoding
wxNativeFontInfo::GetEncoding() const
530 // we already have the code for this but need to refactor it first
531 wxFAIL_MSG( _T("not implemented") );
533 return wxFONTENCODING_MAX
;
536 void wxNativeFontInfo::SetPointSize(int pointsize
)
538 SetXFontComponent(wxXLFD_POINTSIZE
, wxString::Format(_T("%d"), pointsize
));
541 void wxNativeFontInfo::SetStyle(wxFontStyle style
)
546 case wxFONTSTYLE_ITALIC
:
550 case wxFONTSTYLE_SLANT
:
554 case wxFONTSTYLE_NORMAL
:
558 wxFAIL_MSG( _T("unknown wxFontStyle in wxNativeFontInfo::SetStyle") );
562 SetXFontComponent(wxXLFD_SLANT
, s
);
565 void wxNativeFontInfo::SetWeight(wxFontWeight weight
)
570 case wxFONTWEIGHT_BOLD
:
574 case wxFONTWEIGHT_LIGHT
:
578 case wxFONTWEIGHT_NORMAL
:
583 wxFAIL_MSG( _T("unknown wxFontWeight in wxNativeFontInfo::SetWeight") );
587 SetXFontComponent(wxXLFD_WEIGHT
, s
);
590 void wxNativeFontInfo::SetUnderlined(bool WXUNUSED(underlined
))
592 // can't do this under X
595 void wxNativeFontInfo::SetFaceName(wxString facename
)
597 SetXFontComponent(wxXLFD_FAMILY
, facename
);
600 void wxNativeFontInfo::SetFamily(wxFontFamily family
)
602 // wxFontFamily -> X foundry, anyone?
603 wxFAIL_MSG( _T("not implemented") );
605 // SetXFontComponent(wxXLFD_FOUNDRY, ...);
608 void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding
)
610 wxNativeEncodingInfo info
;
611 if ( wxGetNativeFontEncoding(encoding
, &info
) )
613 SetXFontComponent(wxXLFD_ENCODING
, info
.xencoding
);
614 SetXFontComponent(wxXLFD_REGISTRY
, info
.xregistry
);
618 // ----------------------------------------------------------------------------
620 // ----------------------------------------------------------------------------
622 bool wxGetNativeFontEncoding(wxFontEncoding encoding
,
623 wxNativeEncodingInfo
*info
)
625 wxCHECK_MSG( info
, FALSE
, _T("bad pointer in wxGetNativeFontEncoding") );
627 if ( encoding
== wxFONTENCODING_DEFAULT
)
629 encoding
= wxFont::GetDefaultEncoding();
634 case wxFONTENCODING_ISO8859_1
:
635 case wxFONTENCODING_ISO8859_2
:
636 case wxFONTENCODING_ISO8859_3
:
637 case wxFONTENCODING_ISO8859_4
:
638 case wxFONTENCODING_ISO8859_5
:
639 case wxFONTENCODING_ISO8859_6
:
640 case wxFONTENCODING_ISO8859_7
:
641 case wxFONTENCODING_ISO8859_8
:
642 case wxFONTENCODING_ISO8859_9
:
643 case wxFONTENCODING_ISO8859_10
:
644 case wxFONTENCODING_ISO8859_11
:
645 case wxFONTENCODING_ISO8859_12
:
646 case wxFONTENCODING_ISO8859_13
:
647 case wxFONTENCODING_ISO8859_14
:
648 case wxFONTENCODING_ISO8859_15
:
650 int cp
= encoding
- wxFONTENCODING_ISO8859_1
+ 1;
651 info
->xregistry
= wxT("iso8859");
652 info
->xencoding
.Printf(wxT("%d"), cp
);
656 case wxFONTENCODING_UTF8
:
657 info
->xregistry
= wxT("iso10646");
658 info
->xencoding
= wxT("*");
661 case wxFONTENCODING_GB2312
:
662 info
->xregistry
= wxT("GB2312"); // or the otherway round?
663 info
->xencoding
= wxT("*");
666 case wxFONTENCODING_KOI8
:
667 info
->xregistry
= wxT("koi8");
669 // we don't make distinction between koi8-r, koi8-u and koi8-ru (so far)
670 info
->xencoding
= wxT("*");
673 case wxFONTENCODING_CP1250
:
674 case wxFONTENCODING_CP1251
:
675 case wxFONTENCODING_CP1252
:
676 case wxFONTENCODING_CP1253
:
677 case wxFONTENCODING_CP1254
:
678 case wxFONTENCODING_CP1255
:
679 case wxFONTENCODING_CP1256
:
680 case wxFONTENCODING_CP1257
:
682 int cp
= encoding
- wxFONTENCODING_CP1250
+ 1250;
683 info
->xregistry
= wxT("microsoft");
684 info
->xencoding
.Printf(wxT("cp%d"), cp
);
688 case wxFONTENCODING_SYSTEM
:
690 info
->xencoding
= wxT("*");
694 // don't know how to translate this encoding into X fontspec
698 info
->encoding
= encoding
;
703 bool wxTestFontEncoding(const wxNativeEncodingInfo
& info
)
706 fontspec
.Printf(_T("-*-%s-*-*-*-*-*-*-*-*-*-*-%s-%s"),
707 !info
.facename
? _T("*") : info
.facename
.c_str(),
708 info
.xregistry
.c_str(),
709 info
.xencoding
.c_str());
711 return wxTestFontSpec(fontspec
);
714 // ----------------------------------------------------------------------------
715 // X-specific functions
716 // ----------------------------------------------------------------------------
718 wxNativeFont
wxLoadQueryNearestFont(int pointSize
,
723 const wxString
&facename
,
724 wxFontEncoding encoding
,
727 if ( encoding
== wxFONTENCODING_DEFAULT
)
729 encoding
= wxFont::GetDefaultEncoding();
732 // first determine the encoding - if the font doesn't exist at all in this
733 // encoding, it's useless to do all other approximations (i.e. size,
734 // family &c don't matter much)
735 wxNativeEncodingInfo info
;
736 if ( encoding
== wxFONTENCODING_SYSTEM
)
738 // This will always work so we don't test to save time
739 wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM
, &info
);
743 if ( !wxGetNativeFontEncoding(encoding
, &info
) ||
744 !wxTestFontEncoding(info
) )
747 if ( !wxFontMapper::Get()->GetAltForEncoding(encoding
, &info
) )
748 #endif // wxUSE_FONTMAP
750 // unspported encoding - replace it with the default
752 // NB: we can't just return 0 from here because wxGTK code doesn't
753 // check for it (i.e. it supposes that we'll always succeed),
754 // so it would provoke a crash
755 wxGetNativeFontEncoding(wxFONTENCODING_SYSTEM
, &info
);
760 // OK, we have the correct xregistry/xencoding in info structure
761 wxNativeFont font
= 0;
763 // if we already have the X font name, try to use it
764 if( xFontName
&& !xFontName
->IsEmpty() )
767 // Make sure point size is correct for scale factor.
769 wxStringTokenizer
tokenizer(*xFontName
, _T("-"), wxTOKEN_RET_DELIMS
);
770 wxString newFontName
;
772 for(int i
= 0; i
< 8; i
++)
773 newFontName
+= tokenizer
.NextToken();
775 (void) tokenizer
.NextToken();
777 newFontName
+= wxString::Format(wxT("%d-"), pointSize
);
779 while(tokenizer
.HasMoreTokens())
780 newFontName
+= tokenizer
.GetNextToken();
782 font
= wxLoadFont(newFontName
);
785 *xFontName
= newFontName
;
788 // try to load exactly the font requested first
791 font
= wxLoadQueryFont( pointSize
, family
, style
, weight
,
792 underlined
, facename
,
793 info
.xregistry
, info
.xencoding
,
799 // search up and down by stepsize 10
800 int max_size
= pointSize
+ 20 * (1 + (pointSize
/180));
801 int min_size
= pointSize
- 20 * (1 + (pointSize
/180));
805 // Search for smaller size (approx.)
806 for ( i
= pointSize
- 10; !font
&& i
>= 10 && i
>= min_size
; i
-= 10 )
808 font
= wxLoadQueryFont(i
, family
, style
, weight
, underlined
,
809 facename
, info
.xregistry
, info
.xencoding
,
813 // Search for larger size (approx.)
814 for ( i
= pointSize
+ 10; !font
&& i
<= max_size
; i
+= 10 )
816 font
= wxLoadQueryFont(i
, family
, style
, weight
, underlined
,
817 facename
, info
.xregistry
, info
.xencoding
,
821 // Try default family
822 if ( !font
&& family
!= wxDEFAULT
)
824 font
= wxLoadQueryFont(pointSize
, wxDEFAULT
, style
, weight
,
825 underlined
, facename
,
826 info
.xregistry
, info
.xencoding
,
830 // ignore size, family, style and weight but try to find font with the
831 // given facename and encoding
834 font
= wxLoadQueryFont(120, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
835 underlined
, facename
,
836 info
.xregistry
, info
.xencoding
,
839 // ignore family as well
842 font
= wxLoadQueryFont(120, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
843 underlined
, wxEmptyString
,
844 info
.xregistry
, info
.xencoding
,
847 // if it still failed, try to get the font of any size but
848 // with the requested encoding: this can happen if the
849 // encoding is only available in one size which happens to be
850 // different from 120
853 font
= wxLoadQueryFont(-1, wxDEFAULT
, wxNORMAL
, wxNORMAL
,
854 FALSE
, wxEmptyString
,
855 info
.xregistry
, info
.xencoding
,
858 // this should never happen as we had tested for it in the
859 // very beginning, but if it does, do return something non
860 // NULL or we'd crash in wxFont code
863 wxFAIL_MSG( _T("this encoding should be available!") );
865 font
= wxLoadQueryFont(-1,
866 wxDEFAULT
, wxNORMAL
, wxNORMAL
,
867 FALSE
, wxEmptyString
,
879 // ----------------------------------------------------------------------------
881 // ----------------------------------------------------------------------------
883 // returns TRUE if there are any fonts matching this font spec
884 static bool wxTestFontSpec(const wxString
& fontspec
)
886 // some X servers will fail to load this font because there are too many
887 // matches so we must test explicitly for this
888 if ( fontspec
== _T("-*-*-*-*-*-*-*-*-*-*-*-*-*-*") )
893 wxNativeFont test
= (wxNativeFont
) g_fontHash
->Get( fontspec
);
899 test
= wxLoadFont(fontspec
);
900 g_fontHash
->Put( fontspec
, (wxObject
*) test
);
914 static wxNativeFont
wxLoadQueryFont(int pointSize
,
918 bool WXUNUSED(underlined
),
919 const wxString
& facename
,
920 const wxString
& xregistry
,
921 const wxString
& xencoding
,
927 case wxDECORATIVE
: xfamily
= wxT("lucida"); break;
928 case wxROMAN
: xfamily
= wxT("times"); break;
929 case wxMODERN
: xfamily
= wxT("courier"); break;
930 case wxSWISS
: xfamily
= wxT("helvetica"); break;
931 case wxTELETYPE
: xfamily
= wxT("lucidatypewriter"); break;
932 case wxSCRIPT
: xfamily
= wxT("utopia"); break;
933 default: xfamily
= wxT("*");
941 xweight
= MWLF_WEIGHT_BOLD
;
946 xweight
= MWLF_WEIGHT_LIGHT
;
951 xweight
= MWLF_WEIGHT_NORMAL
;
957 xweight
= MWLF_WEIGHT_DEFAULT
;
961 GR_SCREEN_INFO screenInfo
;
962 GrGetScreenInfo(& screenInfo
);
964 int yPixelsPerCM
= screenInfo
.ydpcm
;
966 // A point is 1/72 of an inch.
967 // An inch is 2.541 cm.
968 // So pixelHeight = (pointSize / 72) (inches) * 2.541 (for cm) * yPixelsPerCM (for pixels)
969 // In fact pointSize is 10 * the normal point size so
972 int pixelHeight
= (int) ( (((float)pointSize
) / 720.0) * 2.541 * (float) yPixelsPerCM
) ;
974 // An alternative: assume that the screen is 72 dpi.
975 //int pixelHeight = (int) (((float)pointSize / 720.0) * 72.0) ;
976 //int pixelHeight = (int) ((float)pointSize / 10.0) ;
979 logFont
.lfHeight
= pixelHeight
;
981 logFont
.lfEscapement
= 0;
982 logFont
.lfOrientation
= 0;
983 logFont
.lfWeight
= xweight
;
984 logFont
.lfItalic
= (style
== wxNORMAL
? 0 : 1) ;
985 logFont
.lfUnderline
= 0;
986 logFont
.lfStrikeOut
= 0;
987 logFont
.lfCharSet
= MWLF_CHARSET_DEFAULT
; // TODO: select appropriate one
988 logFont
.lfOutPrecision
= MWLF_TYPE_DEFAULT
;
989 logFont
.lfClipPrecision
= 0; // Not used
990 logFont
.lfRoman
= (family
== wxROMAN
? 1 : 0) ;
991 logFont
.lfSerif
= (family
== wxSWISS
? 0 : 1) ;
992 logFont
.lfSansSerif
= !logFont
.lfSerif
;
993 logFont
.lfModern
= (family
== wxMODERN
? 1 : 0) ;
994 logFont
.lfProportional
= (family
== wxTELETYPE
? 0 : 1) ;
995 logFont
.lfOblique
= 0;
996 logFont
.lfSmallCaps
= 0;
997 logFont
.lfPitch
= 0; // 0 = default
998 strcpy(logFont
.lfFaceName
, facename
.c_str());
1000 XFontStruct
* fontInfo
= (XFontStruct
*) malloc(sizeof(XFontStruct
));
1001 fontInfo
->fid
= GrCreateFont((GR_CHAR
*) facename
.c_str(), pixelHeight
, & logFont
);
1002 GrGetFontInfo(fontInfo
->fid
, & fontInfo
->info
);
1003 return (wxNativeFont
) fontInfo
;
1007 if (!facename
.IsEmpty())
1009 fontSpec
.Printf(wxT("-*-%s-*-*-normal-*-*-*-*-*-*-*-*-*"),
1012 if ( wxTestFontSpec(fontSpec
) )
1016 //else: no such family, use default one instead
1023 fontSpec
.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
1025 if ( wxTestFontSpec(fontSpec
) )
1030 // fall through - try wxITALIC now
1033 fontSpec
.Printf(wxT("-*-%s-*-i-*-*-*-*-*-*-*-*-*-*"),
1035 if ( wxTestFontSpec(fontSpec
) )
1039 else if ( style
== wxITALIC
) // and not wxSLANT
1042 fontSpec
.Printf(wxT("-*-%s-*-o-*-*-*-*-*-*-*-*-*-*"),
1044 if ( wxTestFontSpec(fontSpec
) )
1050 // no italic, no slant - leave default
1057 wxFAIL_MSG(_T("unknown font style"));
1058 // fall back to normal
1070 fontSpec
.Printf(wxT("-*-%s-bold-*-*-*-*-*-*-*-*-*-*-*"),
1072 if ( wxTestFontSpec(fontSpec
) )
1074 xweight
= wxT("bold");
1077 fontSpec
.Printf(wxT("-*-%s-heavy-*-*-*-*-*-*-*-*-*-*-*"),
1079 if ( wxTestFontSpec(fontSpec
) )
1081 xweight
= wxT("heavy");
1084 fontSpec
.Printf(wxT("-*-%s-extrabold-*-*-*-*-*-*-*-*-*-*-*"),
1086 if ( wxTestFontSpec(fontSpec
) )
1088 xweight
= wxT("extrabold");
1091 fontSpec
.Printf(wxT("-*-%s-demibold-*-*-*-*-*-*-*-*-*-*-*"),
1093 if ( wxTestFontSpec(fontSpec
) )
1095 xweight
= wxT("demibold");
1098 fontSpec
.Printf(wxT("-*-%s-black-*-*-*-*-*-*-*-*-*-*-*"),
1100 if ( wxTestFontSpec(fontSpec
) )
1102 xweight
= wxT("black");
1105 fontSpec
.Printf(wxT("-*-%s-ultrablack-*-*-*-*-*-*-*-*-*-*-*"),
1107 if ( wxTestFontSpec(fontSpec
) )
1109 xweight
= wxT("ultrablack");
1116 fontSpec
.Printf(wxT("-*-%s-light-*-*-*-*-*-*-*-*-*-*-*"),
1118 if ( wxTestFontSpec(fontSpec
) )
1120 xweight
= wxT("light");
1123 fontSpec
.Printf(wxT("-*-%s-thin-*-*-*-*-*-*-*-*-*-*-*"),
1125 if ( wxTestFontSpec(fontSpec
) )
1127 xweight
= wxT("thin");
1134 fontSpec
.Printf(wxT("-*-%s-medium-*-*-*-*-*-*-*-*-*-*-*"),
1136 if ( wxTestFontSpec(fontSpec
) )
1138 xweight
= wxT("medium");
1141 fontSpec
.Printf(wxT("-*-%s-normal-*-*-*-*-*-*-*-*-*-*-*"),
1143 if ( wxTestFontSpec(fontSpec
) )
1145 xweight
= wxT("normal");
1148 fontSpec
.Printf(wxT("-*-%s-regular-*-*-*-*-*-*-*-*-*-*-*"),
1150 if ( wxTestFontSpec(fontSpec
) )
1152 xweight
= wxT("regular");
1158 default: xweight
= wxT("*"); break;
1161 // if pointSize is -1, don't specify any
1163 if ( pointSize
== -1 )
1169 sizeSpec
.Printf(_T("%d"), pointSize
);
1172 // construct the X font spec from our data
1173 fontSpec
.Printf(wxT("-*-%s-%s-%s-normal-*-*-%s-*-*-*-*-%s-%s"),
1174 xfamily
.c_str(), xweight
.c_str(), xstyle
.c_str(),
1175 sizeSpec
.c_str(), xregistry
.c_str(), xencoding
.c_str());
1178 *xFontName
= fontSpec
;
1180 return wxLoadFont(fontSpec
);
1185 // ----------------------------------------------------------------------------
1187 // ----------------------------------------------------------------------------
1189 class wxFontModule
: public wxModule
1196 DECLARE_DYNAMIC_CLASS(wxFontModule
)
1199 IMPLEMENT_DYNAMIC_CLASS(wxFontModule
, wxModule
)
1201 bool wxFontModule::OnInit()
1203 g_fontHash
= new wxHashTable( wxKEY_STRING
);
1208 void wxFontModule::OnExit()
1212 g_fontHash
= (wxHashTable
*)NULL
;
1215 #endif // GTK 2.0/1.x