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