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