Lots of work to set PangoFontDescription as the
[wxWidgets.git] / src / gtk1 / font.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: gtk/font.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // ============================================================================
11 // declarations
12 // ============================================================================
13
14 // ----------------------------------------------------------------------------
15 // headers
16 // ----------------------------------------------------------------------------
17
18 #ifdef __GNUG__
19 #pragma implementation "font.h"
20 #endif
21
22 #include "wx/font.h"
23 #include "wx/fontutil.h"
24 #include "wx/cmndata.h"
25 #include "wx/utils.h"
26 #include "wx/log.h"
27 #include "wx/gdicmn.h"
28 #include "wx/tokenzr.h"
29 #include "wx/settings.h"
30
31 #include <strings.h>
32
33 #include "wx/gtk/private.h"
34 #include <gdk/gdkprivate.h>
35
36 // ----------------------------------------------------------------------------
37 // constants
38 // ----------------------------------------------------------------------------
39
40 // the default size (in points) for the fonts
41 static const int wxDEFAULT_FONT_SIZE = 12;
42
43 // ----------------------------------------------------------------------------
44 // wxScaledFontList
45 // ----------------------------------------------------------------------------
46
47 // TODO: replace this with a type safe list or hash!!
48 class wxScaledFontList : public wxList
49 {
50 public:
51 wxScaledFontList() : wxList(wxKEY_INTEGER) { }
52 };
53
54 // ----------------------------------------------------------------------------
55 // wxFontRefData
56 // ----------------------------------------------------------------------------
57
58 class wxFontRefData : public wxObjectRefData
59 {
60 public:
61 // from broken down font parameters, also default ctor
62 wxFontRefData(int size = -1,
63 int family = wxFONTFAMILY_DEFAULT,
64 int style = wxFONTSTYLE_NORMAL,
65 int weight = wxFONTWEIGHT_NORMAL,
66 bool underlined = FALSE,
67 const wxString& faceName = wxEmptyString,
68 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
69
70 // from XFLD
71 wxFontRefData(const wxString& fontname);
72
73 // copy ctor
74 wxFontRefData( const wxFontRefData& data );
75
76 virtual ~wxFontRefData();
77
78 // do we have the native font info?
79 bool HasNativeFont() const
80 {
81 #ifdef __WXGTK20__
82 return TRUE; // ?
83 #else
84 return !m_nativeFontInfo.IsDefault();
85 #endif
86 }
87
88 // setters: all of them also take care to modify m_nativeFontInfo if we
89 // have it so as to not lose the information not carried by our fields
90 void SetPointSize(int pointSize);
91 void SetFamily(int family);
92 void SetStyle(int style);
93 void SetWeight(int weight);
94 void SetUnderlined(bool underlined);
95 void SetFaceName(const wxString& facename);
96 void SetEncoding(wxFontEncoding encoding);
97
98 // debugger helper: shows what the font really is
99 //
100 // VZ: I need this as my gdb either shows wildly wrong values or crashes
101 // when I ask it to "p fontRefData" :-(
102 #if defined(__WXDEBUG__) && !defined(__WXGTK20__)
103 void Dump() const
104 {
105 wxPrintf(_T("%s-%s-%s-%d-%d\n"),
106 m_faceName.c_str(),
107 m_weight == wxFONTWEIGHT_NORMAL
108 ? _T("normal")
109 : m_weight == wxFONTWEIGHT_BOLD
110 ? _T("bold")
111 : _T("light"),
112 m_style == wxFONTSTYLE_NORMAL ? _T("regular") : _T("italic"),
113 m_pointSize,
114 m_encoding);
115 }
116 #endif // Debug
117
118 protected:
119 // common part of all ctors
120 void Init(int pointSize,
121 int family,
122 int style,
123 int weight,
124 bool underlined,
125 const wxString& faceName,
126 wxFontEncoding encoding);
127
128 private:
129 #ifndef __WXGTK20__
130 // the map of font sizes to "GdkFont *"
131 wxScaledFontList m_scaled_xfonts;
132 #endif
133
134 // the broken down font parameters
135 int m_pointSize;
136 int m_family,
137 m_style,
138 m_weight;
139 bool m_underlined;
140 wxString m_faceName;
141 wxFontEncoding m_encoding; // Unused under GTK 2.0
142
143 // The native font info, basicly an XFLD under GTK 1.2 and
144 // the pango font description under GTK 2.0.
145 wxNativeFontInfo m_nativeFontInfo;
146
147 friend class wxFont;
148 };
149
150 // ============================================================================
151 // wxFontRefData implementation
152 // ============================================================================
153
154 // ----------------------------------------------------------------------------
155 // wxFontRefData creation
156 // ----------------------------------------------------------------------------
157
158 void wxFontRefData::Init(int pointSize,
159 int family,
160 int style,
161 int weight,
162 bool underlined,
163 const wxString& faceName,
164 wxFontEncoding encoding)
165 {
166 m_family = family == wxFONTFAMILY_DEFAULT ? wxFONTFAMILY_SWISS : family;
167
168 m_faceName = faceName;
169
170 // we accept both wxDEFAULT and wxNORMAL here - should we?
171 m_style = style == wxDEFAULT ? wxFONTSTYLE_NORMAL : style;
172 m_weight = weight == wxDEFAULT ? wxFONTWEIGHT_NORMAL : weight;
173
174 // and here, do we really want to forbid creation of the font of the size
175 // 90 (the value of wxDEFAULT)??
176 m_pointSize = pointSize == wxDEFAULT ||
177 pointSize == -1 ? wxDEFAULT_FONT_SIZE : pointSize;
178
179 m_underlined = underlined;
180 m_encoding = encoding;
181 }
182
183 wxFontRefData::wxFontRefData( const wxFontRefData& data )
184 : wxObjectRefData()
185 {
186 m_pointSize = data.m_pointSize;
187 m_family = data.m_family;
188 m_style = data.m_style;
189 m_weight = data.m_weight;
190
191 m_underlined = data.m_underlined;
192
193 m_faceName = data.m_faceName;
194 m_encoding = data.m_encoding;
195
196 m_nativeFontInfo = data.m_nativeFontInfo;
197 }
198
199 wxFontRefData::wxFontRefData(int size, int family, int style,
200 int weight, bool underlined,
201 const wxString& faceName,
202 wxFontEncoding encoding)
203 {
204 Init(size, family, style, weight, underlined, faceName, encoding);
205 }
206
207 wxFontRefData::wxFontRefData(const wxString& fontname)
208 {
209 #ifdef __WXGTK20__
210 m_nativeFontInfo.FromString( fontname );
211
212 // Get native info
213 PangoFontDescription *desc = m_nativeFontInfo.description;
214
215 // init fields
216 m_faceName = wxGTK_CONV_BACK( pango_font_description_get_family( desc ) );
217
218 m_pointSize = pango_font_description_get_size( desc ) / PANGO_SCALE;
219
220 switch (pango_font_description_get_style( desc ))
221 {
222 case PANGO_STYLE_NORMAL:
223 m_style = wxFONTSTYLE_NORMAL;
224 break;
225 case PANGO_STYLE_ITALIC:
226 m_style = wxFONTSTYLE_ITALIC;
227 break;
228 case PANGO_STYLE_OBLIQUE:
229 m_style = wxFONTSTYLE_SLANT;
230 break;
231 }
232
233 switch (pango_font_description_get_weight( desc ))
234 {
235 case PANGO_WEIGHT_ULTRALIGHT:
236 m_weight = wxFONTWEIGHT_LIGHT;
237 break;
238 case PANGO_WEIGHT_LIGHT:
239 m_weight = wxFONTWEIGHT_LIGHT;
240 break;
241 case PANGO_WEIGHT_NORMAL:
242 m_weight = wxFONTWEIGHT_NORMAL;
243 break;
244 case PANGO_WEIGHT_BOLD:
245 m_weight = wxFONTWEIGHT_BOLD;
246 break;
247 case PANGO_WEIGHT_ULTRABOLD:
248 m_weight = wxFONTWEIGHT_BOLD;
249 break;
250 case PANGO_WEIGHT_HEAVY:
251 m_weight = wxFONTWEIGHT_BOLD;
252 break;
253 }
254
255 if (m_faceName == wxT("monospaced"))
256 {
257 m_family = wxFONTFAMILY_TELETYPE;
258 }
259 else if (m_faceName == wxT("sans"))
260 {
261 m_family = wxFONTFAMILY_SWISS;
262 }
263 else
264 {
265 m_family = wxFONTFAMILY_UNKNOWN;
266 }
267
268 // Pango description are never underlined (?)
269 m_underlined = FALSE;
270
271 // Cannot we choose that
272 m_encoding = wxFONTENCODING_SYSTEM;
273 #else
274 // remember the X font name
275 m_nativeFontInfo.SetXFontName(fontname);
276
277 // get the font parameters from the XLFD
278 // -------------------------------------
279
280 m_faceName = m_nativeFontInfo.GetXFontComponent(wxXLFD_FAMILY);
281
282 m_weight = wxFONTWEIGHT_NORMAL;
283
284 wxString w = m_nativeFontInfo.GetXFontComponent(wxXLFD_WEIGHT).Upper();
285 if ( !w.empty() && w != _T('*') )
286 {
287 // the test below catches all of BOLD, EXTRABOLD, DEMIBOLD, ULTRABOLD
288 // and BLACK
289 if ( ((w[0u] == _T('B') && (!wxStrcmp(w.c_str() + 1, wxT("OLD")) ||
290 !wxStrcmp(w.c_str() + 1, wxT("LACK"))))) ||
291 wxStrstr(w.c_str() + 1, _T("BOLD")) )
292 {
293 m_weight = wxFONTWEIGHT_BOLD;
294 }
295 else if ( w == _T("LIGHT") || w == _T("THIN") )
296 {
297 m_weight = wxFONTWEIGHT_LIGHT;
298 }
299 }
300
301 switch ( wxToupper(*m_nativeFontInfo.
302 GetXFontComponent(wxXLFD_SLANT).c_str()) )
303 {
304 case _T('I'): // italique
305 m_style = wxFONTSTYLE_ITALIC;
306 break;
307
308 case _T('O'): // oblique
309 m_style = wxFONTSTYLE_SLANT;
310 break;
311
312 default:
313 m_style = wxFONTSTYLE_NORMAL;
314 }
315
316 long ptSize;
317 if ( m_nativeFontInfo.GetXFontComponent(wxXLFD_POINTSIZE).ToLong(&ptSize) )
318 {
319 // size in XLFD is in 10 point units
320 m_pointSize = (int)(ptSize / 10);
321 }
322 else
323 {
324 m_pointSize = wxDEFAULT_FONT_SIZE;
325 }
326
327 // examine the spacing: if the font is monospaced, assume wxTELETYPE
328 // family for compatibility with the old code which used it instead of
329 // IsFixedWidth()
330 if ( m_nativeFontInfo.GetXFontComponent(wxXLFD_SPACING).Upper() == _T('M') )
331 {
332 m_family = wxFONTFAMILY_TELETYPE;
333 }
334 else // not monospaceed
335 {
336 // don't even try guessing it, it doesn't work for too many fonts
337 // anyhow
338 m_family = wxFONTFAMILY_UNKNOWN;
339 }
340
341 // X fonts are never underlined...
342 m_underlined = FALSE;
343
344 // deal with font encoding
345 wxString
346 registry = m_nativeFontInfo.GetXFontComponent(wxXLFD_REGISTRY).Upper(),
347 encoding = m_nativeFontInfo.GetXFontComponent(wxXLFD_ENCODING).Upper();
348
349 if ( registry == _T("ISO8859") )
350 {
351 int cp;
352 if ( wxSscanf(encoding, wxT("%d"), &cp) == 1 )
353 {
354 m_encoding = (wxFontEncoding)(wxFONTENCODING_ISO8859_1 + cp - 1);
355 }
356 }
357 else if ( registry == _T("MICROSOFT") )
358 {
359 int cp;
360 if ( wxSscanf(encoding, wxT("cp125%d"), &cp) == 1 )
361 {
362 m_encoding = (wxFontEncoding)(wxFONTENCODING_CP1250 + cp);
363 }
364 }
365 else if ( registry == _T("KOI8") )
366 {
367 m_encoding = wxFONTENCODING_KOI8;
368 }
369 else // unknown encoding
370 {
371 // may be give a warning here?
372 m_encoding = wxFONTENCODING_SYSTEM;
373 }
374 #endif
375 }
376
377 wxFontRefData::~wxFontRefData()
378 {
379 #ifndef __WXGTK20__
380 wxNode *node = m_scaled_xfonts.First();
381 while (node)
382 {
383 GdkFont *font = (GdkFont*)node->Data();
384 wxNode *next = node->Next();
385 gdk_font_unref( font );
386 node = next;
387 }
388 #endif
389 }
390
391 // ----------------------------------------------------------------------------
392 // wxFontRefData SetXXX()
393 // ----------------------------------------------------------------------------
394
395 void wxFontRefData::SetPointSize(int pointSize)
396 {
397 m_pointSize = pointSize;
398
399 #ifdef __WXGTK20__
400 // Get native info
401 PangoFontDescription *desc = m_nativeFontInfo.description;
402
403 pango_font_description_set_size( desc, m_pointSize * PANGO_SCALE );
404 #else
405 if ( HasNativeFont() )
406 {
407 wxString size;
408 if ( pointSize == -1 )
409 size = _T('*');
410 else
411 size.Printf(_T("%d"), 10*pointSize);
412
413 m_nativeFontInfo.SetXFontComponent(wxXLFD_POINTSIZE, size);
414 }
415 #endif
416 }
417
418 void wxFontRefData::SetFamily(int family)
419 {
420 m_family = family;
421
422 // TODO: what are we supposed to do with m_nativeFontInfo here?
423 }
424
425 void wxFontRefData::SetStyle(int style)
426 {
427 m_style = style;
428
429 #ifdef __WXGTK20__
430 // Get native info
431 PangoFontDescription *desc = m_nativeFontInfo.description;
432
433 switch ( style )
434 {
435 case wxFONTSTYLE_ITALIC:
436 pango_font_description_set_style( desc, PANGO_STYLE_ITALIC );
437 break;
438 case wxFONTSTYLE_SLANT:
439 pango_font_description_set_style( desc, PANGO_STYLE_OBLIQUE );
440 break;
441 default:
442 wxFAIL_MSG( _T("unknown font style") );
443 // fall through
444 case wxFONTSTYLE_NORMAL:
445 pango_font_description_set_style( desc, PANGO_STYLE_NORMAL );
446 break;
447 }
448 #else
449 if ( HasNativeFont() )
450 {
451 wxString slant;
452 switch ( style )
453 {
454 case wxFONTSTYLE_ITALIC:
455 slant = _T('i');
456 break;
457
458 case wxFONTSTYLE_SLANT:
459 slant = _T('o');
460 break;
461
462 default:
463 wxFAIL_MSG( _T("unknown font style") );
464 // fall through
465
466 case wxFONTSTYLE_NORMAL:
467 slant = _T('r');
468 }
469
470 m_nativeFontInfo.SetXFontComponent(wxXLFD_SLANT, slant);
471 }
472 #endif
473 }
474
475 void wxFontRefData::SetWeight(int weight)
476 {
477 m_weight = weight;
478
479 #ifndef __WXGTK20__
480 if ( HasNativeFont() )
481 {
482 wxString boldness;
483 switch ( weight )
484 {
485 case wxFONTWEIGHT_BOLD:
486 boldness = _T("bold");
487 break;
488
489 case wxFONTWEIGHT_LIGHT:
490 boldness = _T("light");
491 break;
492
493 default:
494 wxFAIL_MSG( _T("unknown font weight") );
495 // fall through
496
497 case wxFONTWEIGHT_NORMAL:
498 // unspecified
499 boldness = _T("medium");
500 }
501
502 m_nativeFontInfo.SetXFontComponent(wxXLFD_WEIGHT, boldness);
503 }
504 #endif
505 }
506
507 void wxFontRefData::SetUnderlined(bool underlined)
508 {
509 m_underlined = underlined;
510
511 // the XLFD doesn't have "underlined" field anyhow
512 }
513
514 void wxFontRefData::SetFaceName(const wxString& facename)
515 {
516 m_faceName = facename;
517
518 #ifndef __WXGTK20__
519 if ( HasNativeFont() )
520 {
521 m_nativeFontInfo.SetXFontComponent(wxXLFD_FAMILY, facename);
522 }
523 #endif
524 }
525
526 void wxFontRefData::SetEncoding(wxFontEncoding encoding)
527 {
528 m_encoding = encoding;
529
530 #ifndef __WXGTK20__
531 if ( HasNativeFont() )
532 {
533 wxNativeEncodingInfo info;
534 if ( wxGetNativeFontEncoding(encoding, &info) )
535 {
536 m_nativeFontInfo.SetXFontComponent(wxXLFD_REGISTRY, info.xregistry);
537 m_nativeFontInfo.SetXFontComponent(wxXLFD_ENCODING, info.xencoding);
538 }
539 }
540 #endif
541 }
542
543 // ============================================================================
544 // wxFont implementation
545 // ============================================================================
546
547 // ----------------------------------------------------------------------------
548 // wxFont creation
549 // ----------------------------------------------------------------------------
550
551 IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
552
553 void wxFont::Init()
554 {
555 }
556
557 wxFont::wxFont(const wxNativeFontInfo& info)
558 {
559 Init();
560
561 #ifdef __WXGTK20__
562 Create( info.GetPointSize(),
563 info.GetFamily(),
564 info.GetStyle(),
565 info.GetWeight(),
566 info.GetUnderlined(),
567 info.GetFaceName(),
568 info.GetEncoding() );
569 #else
570 Create(info.GetXFontName());
571 #endif
572 }
573
574 bool wxFont::Create( int pointSize,
575 int family,
576 int style,
577 int weight,
578 bool underlined,
579 const wxString& face,
580 wxFontEncoding encoding)
581 {
582 m_refData = new wxFontRefData(pointSize, family, style, weight,
583 underlined, face, encoding);
584
585 return TRUE;
586 }
587
588 bool wxFont::Create(const wxString& fontname)
589 {
590 // VZ: does this really happen?
591 if ( fontname.empty() )
592 {
593 *this = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
594
595 return TRUE;
596 }
597
598 m_refData = new wxFontRefData(fontname);
599
600 return TRUE;
601 }
602
603 void wxFont::Unshare()
604 {
605 if (!m_refData)
606 {
607 m_refData = new wxFontRefData();
608 }
609 else
610 {
611 wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
612 UnRef();
613 m_refData = ref;
614 }
615 }
616
617 wxFont::~wxFont()
618 {
619 }
620
621 // ----------------------------------------------------------------------------
622 // accessors
623 // ----------------------------------------------------------------------------
624
625 // all accessors are just forwarded to wxFontRefData which has everything we
626 // need
627
628 int wxFont::GetPointSize() const
629 {
630 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
631
632 return M_FONTDATA->m_pointSize;
633 }
634
635 wxString wxFont::GetFaceName() const
636 {
637 wxCHECK_MSG( Ok(), wxT(""), wxT("invalid font") );
638
639 return M_FONTDATA->m_faceName;
640 }
641
642 int wxFont::GetFamily() const
643 {
644 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
645
646 return M_FONTDATA->m_family;
647 }
648
649 int wxFont::GetStyle() const
650 {
651 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
652
653 return M_FONTDATA->m_style;
654 }
655
656 int wxFont::GetWeight() const
657 {
658 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
659
660 return M_FONTDATA->m_weight;
661 }
662
663 bool wxFont::GetUnderlined() const
664 {
665 wxCHECK_MSG( Ok(), FALSE, wxT("invalid font") );
666
667 return M_FONTDATA->m_underlined;
668 }
669
670 wxFontEncoding wxFont::GetEncoding() const
671 {
672 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") );
673
674 return M_FONTDATA->m_encoding;
675 }
676
677 wxNativeFontInfo *wxFont::GetNativeFontInfo() const
678 {
679 wxCHECK_MSG( Ok(), (wxNativeFontInfo *)NULL, wxT("invalid font") );
680
681 #ifndef __WXGTK20__ // ???
682 if ( M_FONTDATA->m_nativeFontInfo.GetXFontName().empty() )
683 GetInternalFont();
684 #endif
685
686 return new wxNativeFontInfo(M_FONTDATA->m_nativeFontInfo);
687 }
688
689 bool wxFont::IsFixedWidth() const
690 {
691 wxCHECK_MSG( Ok(), FALSE, wxT("invalid font") );
692
693 #ifndef __WXGTK20__
694 if ( M_FONTDATA->HasNativeFont() )
695 {
696 // the monospace fonts are supposed to have "M" in the spacing field
697 wxString spacing = M_FONTDATA->
698 m_nativeFontInfo.GetXFontComponent(wxXLFD_SPACING);
699
700 return spacing.Upper() == _T('M');
701 }
702 #endif
703
704 return wxFontBase::IsFixedWidth();
705 }
706
707 // ----------------------------------------------------------------------------
708 // change font attributes
709 // ----------------------------------------------------------------------------
710
711 void wxFont::SetPointSize(int pointSize)
712 {
713 Unshare();
714
715 M_FONTDATA->SetPointSize(pointSize);
716 }
717
718 void wxFont::SetFamily(int family)
719 {
720 Unshare();
721
722 M_FONTDATA->SetFamily(family);
723 }
724
725 void wxFont::SetStyle(int style)
726 {
727 Unshare();
728
729 M_FONTDATA->SetStyle(style);
730 }
731
732 void wxFont::SetWeight(int weight)
733 {
734 Unshare();
735
736 M_FONTDATA->SetWeight(weight);
737 }
738
739 void wxFont::SetFaceName(const wxString& faceName)
740 {
741 Unshare();
742
743 M_FONTDATA->SetFaceName(faceName);
744 }
745
746 void wxFont::SetUnderlined(bool underlined)
747 {
748 Unshare();
749
750 M_FONTDATA->SetUnderlined(underlined);
751 }
752
753 void wxFont::SetEncoding(wxFontEncoding encoding)
754 {
755 Unshare();
756
757 M_FONTDATA->SetEncoding(encoding);
758 }
759
760 void wxFont::SetNativeFontInfo(const wxNativeFontInfo& info)
761 {
762 Unshare();
763
764 M_FONTDATA->m_nativeFontInfo = info;
765 }
766
767 // ----------------------------------------------------------------------------
768 // get internal representation of font
769 // ----------------------------------------------------------------------------
770
771 static GdkFont *g_systemDefaultGuiFont = (GdkFont*) NULL;
772
773 // this is also used from tbargtk.cpp and tooltip.cpp, hence extern
774 extern GdkFont *GtkGetDefaultGuiFont()
775 {
776 if (!g_systemDefaultGuiFont)
777 {
778 GtkWidget *widget = gtk_button_new();
779 GtkStyle *def = gtk_rc_get_style( widget );
780 if (def)
781 {
782 g_systemDefaultGuiFont = gdk_font_ref( GET_STYLE_FONT(def) );
783 }
784 else
785 {
786 def = gtk_widget_get_default_style();
787 if (def)
788 g_systemDefaultGuiFont = gdk_font_ref( GET_STYLE_FONT(def) );
789 }
790 gtk_widget_destroy( widget );
791 }
792 else
793 {
794 // already have it, but ref it once more before returning
795 gdk_font_ref(g_systemDefaultGuiFont);
796 }
797
798 return g_systemDefaultGuiFont;
799 }
800
801 GdkFont *wxFont::GetInternalFont( float scale ) const
802 {
803 GdkFont *font = (GdkFont *) NULL;
804
805 wxCHECK_MSG( Ok(), font, wxT("invalid font") )
806
807 #ifdef __WXGTK20__
808 if (*this == wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT))
809 {
810 font = GtkGetDefaultGuiFont();
811 }
812 else
813 {
814 PangoFontDescription *font_description = GetNativeFontInfo()->description;
815
816 font = gdk_font_from_description( font_description );
817 }
818 #else
819 long int_scale = long(scale * 100.0 + 0.5); // key for fontlist
820 int point_scale = (int)((M_FONTDATA->m_pointSize * 10 * int_scale) / 100);
821
822 wxNode *node = M_FONTDATA->m_scaled_xfonts.Find(int_scale);
823 if (node)
824 {
825 font = (GdkFont*)node->Data();
826 }
827 else // we don't have this font in this size yet
828 {
829 if (*this == wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT))
830 {
831 font = GtkGetDefaultGuiFont();
832 }
833
834 if ( !font )
835 {
836 // do we have the XLFD?
837 if ( M_FONTDATA->HasNativeFont() )
838 {
839 font = wxLoadFont(M_FONTDATA->m_nativeFontInfo.GetXFontName());
840 }
841
842 // no XLFD of no exact match - try the approximate one now
843 if ( !font )
844 {
845 wxString xfontname;
846 font = wxLoadQueryNearestFont( point_scale,
847 M_FONTDATA->m_family,
848 M_FONTDATA->m_style,
849 M_FONTDATA->m_weight,
850 M_FONTDATA->m_underlined,
851 M_FONTDATA->m_faceName,
852 M_FONTDATA->m_encoding,
853 &xfontname);
854 if ( font )
855 {
856 M_FONTDATA->m_nativeFontInfo.SetXFontName(xfontname);
857 }
858 }
859 }
860
861 if ( font )
862 {
863 M_FONTDATA->m_scaled_xfonts.Append( int_scale, (wxObject*)font );
864 }
865 }
866 #endif // GTK 2.0
867
868 // it's quite useless to make it a wxCHECK because we're going to crash
869 // anyhow...
870 wxASSERT_MSG( font, wxT("could not load any font?") );
871
872 return font;
873 }
874