]> git.saurik.com Git - wxWidgets.git/blame - src/motif/font.cpp
[ 1509599 ] 'Split pickers page in widgets sample' with more icons and rebaking.
[wxWidgets.git] / src / motif / font.cpp
CommitLineData
4bb6408c 1/////////////////////////////////////////////////////////////////////////////
7ecb8b06 2// Name: src/motif/font.cpp
4bb6408c
JS
3// Purpose: wxFont class
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
93ccaed8
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
1248b41f
MB
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
338dd992
JJ
23#ifdef __VMS
24#pragma message disable nosimpint
4dff3400 25#include "wx/vms_x_fix.h"
338dd992 26#endif
79e4b627 27#include <Xm/Xm.h>
338dd992
JJ
28#ifdef __VMS
29#pragma message enable nosimpint
30#endif
79e4b627 31
4bb6408c 32#include "wx/font.h"
df91131c
WS
33
34#ifndef WX_PRECOMP
35 #include "wx/string.h"
de6185e2 36 #include "wx/utils.h" // for wxGetDisplay()
9eddec69 37 #include "wx/settings.h"
dd05139a 38 #include "wx/gdicmn.h"
df91131c
WS
39#endif
40
98c9fc2d 41#include "wx/fontutil.h" // for wxNativeFontInfo
563f868d 42#include "wx/tokenzr.h"
da494b40 43#include "wx/motif/private.h"
4bb6408c 44
98c9fc2d 45IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
4bb6408c 46
93ccaed8
VZ
47// ----------------------------------------------------------------------------
48// private classes
49// ----------------------------------------------------------------------------
50
51// For every wxFont, there must be a font for each display and scale requested.
52// So these objects are stored in wxFontRefData::m_fonts
79e4b627 53class wxXFont : public wxObject
93ccaed8
VZ
54{
55public:
56 wxXFont();
57 ~wxXFont();
58
996994c7 59#if !wxMOTIF_NEW_FONT_HANDLING
93ccaed8 60 WXFontStructPtr m_fontStruct; // XFontStruct
996994c7 61#endif
eb9d223a 62#if !wxMOTIF_USE_RENDER_TABLE && !wxMOTIF_NEW_FONT_HANDLING
93ccaed8 63 WXFontList m_fontList; // Motif XmFontList
73608949 64#else // if wxUSE_RENDER_TABLE
da494b40 65 WXRenderTable m_renderTable; // Motif XmRenderTable
996994c7 66 WXRendition m_rendition; // Motif XmRendition
da494b40 67#endif
93ccaed8
VZ
68 WXDisplay* m_display; // XDisplay
69 int m_scale; // Scale * 100
70};
71
72class wxFontRefData: public wxGDIRefData
73{
73608949 74 friend class wxFont;
93ccaed8
VZ
75
76public:
77 wxFontRefData(int size = wxDEFAULT,
78 int family = wxDEFAULT,
79 int style = wxDEFAULT,
80 int weight = wxDEFAULT,
96be256b 81 bool underlined = false,
93ccaed8
VZ
82 const wxString& faceName = wxEmptyString,
83 wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
84 {
85 Init(size, family, style, weight, underlined, faceName, encoding);
86 }
87
88 wxFontRefData(const wxFontRefData& data)
89 {
90 Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight,
91 data.m_underlined, data.m_faceName, data.m_encoding);
92 }
93
94 ~wxFontRefData();
95
96protected:
97 // common part of all ctors
98 void Init(int size,
99 int family,
100 int style,
101 int weight,
102 bool underlined,
103 const wxString& faceName,
104 wxFontEncoding encoding);
105
106 // font attributes
107 int m_pointSize;
108 int m_family;
109 int m_style;
110 int m_weight;
111 bool m_underlined;
112 wxString m_faceName;
113 wxFontEncoding m_encoding;
114
563f868d 115 wxNativeFontInfo m_nativeFontInfo;
9045ad9d 116
93ccaed8
VZ
117 // A list of wxXFonts
118 wxList m_fonts;
119};
120
121// ============================================================================
122// implementation
123// ============================================================================
124
125// ----------------------------------------------------------------------------
126// wxXFont
127// ----------------------------------------------------------------------------
128
f97c9854
JS
129wxXFont::wxXFont()
130{
996994c7 131#if !wxMOTIF_NEW_FONT_HANDLING
f97c9854 132 m_fontStruct = (WXFontStructPtr) 0;
996994c7 133#endif
eb9d223a 134#if !wxMOTIF_USE_RENDER_TABLE && !wxMOTIF_NEW_FONT_HANDLING
f97c9854 135 m_fontList = (WXFontList) 0;
eb9d223a 136#else // if wxMOTIF_USE_RENDER_TABLE
da494b40 137 m_renderTable = (WXRenderTable) 0;
996994c7 138 m_rendition = (WXRendition) 0;
da494b40 139#endif
f97c9854
JS
140 m_display = (WXDisplay*) 0;
141 m_scale = 100;
142}
143
144wxXFont::~wxXFont()
145{
eb9d223a 146#if !wxMOTIF_USE_RENDER_TABLE
73608949
MB
147 if (m_fontList)
148 XmFontListFree ((XmFontList) m_fontList);
149 m_fontList = NULL;
150#else // if wxUSE_RENDER_TABLE
151 if (m_renderTable)
152 XmRenderTableFree ((XmRenderTable) m_renderTable);
153 m_renderTable = NULL;
da494b40
MB
154#endif
155
2d120f83 156 // TODO: why does freeing the font produce a segv???
f97c9854 157 // Note that XFreeFont wasn't called in wxWin 1.68 either.
73608949
MB
158 // MBN: probably some interaction with fonts being still
159 // in use in some widgets...
dfe1eee3 160 // XFontStruct* fontStruct = (XFontStruct*) m_fontStruct;
2d120f83 161 // XFreeFont((Display*) m_display, fontStruct);
f97c9854
JS
162}
163
93ccaed8
VZ
164// ----------------------------------------------------------------------------
165// wxFontRefData
166// ----------------------------------------------------------------------------
167
168void wxFontRefData::Init(int pointSize,
169 int family,
170 int style,
171 int weight,
172 bool underlined,
173 const wxString& faceName,
174 wxFontEncoding encoding)
4bb6408c 175{
93ccaed8
VZ
176 if (family == wxDEFAULT)
177 m_family = wxSWISS;
178 else
179 m_family = family;
4bb6408c 180
93ccaed8
VZ
181 m_faceName = faceName;
182
183 if (style == wxDEFAULT)
184 m_style = wxNORMAL;
185 else
186 m_style = style;
187
188 if (weight == wxDEFAULT)
189 m_weight = wxNORMAL;
190 else
191 m_weight = weight;
192
193 if (pointSize == wxDEFAULT)
194 m_pointSize = 12;
195 else
196 m_pointSize = pointSize;
197
198 m_underlined = underlined;
199 m_encoding = encoding;
4bb6408c
JS
200}
201
202wxFontRefData::~wxFontRefData()
203{
ac32ba44 204 wxList::compatibility_iterator node = m_fonts.GetFirst();
dfc54541
JS
205 while (node)
206 {
fd304d98 207 wxXFont* f = (wxXFont*) node->GetData();
f97c9854 208 delete f;
fd304d98 209 node = node->GetNext();
dfc54541 210 }
f97c9854 211 m_fonts.Clear();
4bb6408c
JS
212}
213
93ccaed8
VZ
214// ----------------------------------------------------------------------------
215// wxFont
216// ----------------------------------------------------------------------------
4bb6408c 217
ef4e8ebd 218wxFont::wxFont(const wxNativeFontInfo& info)
98c9fc2d 219{
42f30fa2 220 (void)Create(info.GetXFontName());
98c9fc2d
VZ
221}
222
93ccaed8
VZ
223bool wxFont::Create(int pointSize,
224 int family,
225 int style,
226 int weight,
227 bool underlined,
228 const wxString& faceName,
229 wxFontEncoding encoding)
4bb6408c
JS
230{
231 UnRef();
93ccaed8
VZ
232 m_refData = new wxFontRefData(pointSize, family, style, weight,
233 underlined, faceName, encoding);
dfe1eee3 234
96be256b 235 return true;
4bb6408c
JS
236}
237
563f868d
GD
238bool wxFont::Create(const wxString& fontname, wxFontEncoding enc)
239{
240 if( !fontname )
241 {
a756f210 242 *this = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT);
96be256b 243 return true;
563f868d
GD
244 }
245
246 m_refData = new wxFontRefData();
247
42f30fa2 248 M_FONTDATA->m_nativeFontInfo.SetXFontName(fontname); // X font name
563f868d
GD
249
250 wxString tmp;
251
252 wxStringTokenizer tn( fontname, wxT("-") );
253
254 tn.GetNextToken(); // skip initial empty token
255 tn.GetNextToken(); // foundry
256
257
258 M_FONTDATA->m_faceName = tn.GetNextToken(); // family
259
260 tmp = tn.GetNextToken().MakeUpper(); // weight
261 if (tmp == wxT("BOLD")) M_FONTDATA->m_weight = wxBOLD;
262 if (tmp == wxT("BLACK")) M_FONTDATA->m_weight = wxBOLD;
263 if (tmp == wxT("EXTRABOLD")) M_FONTDATA->m_weight = wxBOLD;
264 if (tmp == wxT("DEMIBOLD")) M_FONTDATA->m_weight = wxBOLD;
265 if (tmp == wxT("ULTRABOLD")) M_FONTDATA->m_weight = wxBOLD;
266
267 if (tmp == wxT("LIGHT")) M_FONTDATA->m_weight = wxLIGHT;
268 if (tmp == wxT("THIN")) M_FONTDATA->m_weight = wxLIGHT;
269
270 tmp = tn.GetNextToken().MakeUpper(); // slant
271 if (tmp == wxT("I")) M_FONTDATA->m_style = wxITALIC;
272 if (tmp == wxT("O")) M_FONTDATA->m_style = wxITALIC;
273
274 tn.GetNextToken(); // set width
275 tn.GetNextToken(); // add. style
276 tn.GetNextToken(); // pixel size
277
278 tmp = tn.GetNextToken(); // pointsize
279 if (tmp != wxT("*"))
280 {
281 long num = wxStrtol (tmp.c_str(), (wxChar **) NULL, 10);
282 M_FONTDATA->m_pointSize = (int)(num / 10);
283 }
284
285 tn.GetNextToken(); // x-res
286 tn.GetNextToken(); // y-res
287
288 tmp = tn.GetNextToken().MakeUpper(); // spacing
289
290 if (tmp == wxT("M"))
291 M_FONTDATA->m_family = wxMODERN;
292 else if (M_FONTDATA->m_faceName == wxT("TIMES"))
293 M_FONTDATA->m_family = wxROMAN;
294 else if (M_FONTDATA->m_faceName == wxT("HELVETICA"))
295 M_FONTDATA->m_family = wxSWISS;
296 else if (M_FONTDATA->m_faceName == wxT("LUCIDATYPEWRITER"))
297 M_FONTDATA->m_family = wxTELETYPE;
298 else if (M_FONTDATA->m_faceName == wxT("LUCIDA"))
299 M_FONTDATA->m_family = wxDECORATIVE;
300 else if (M_FONTDATA->m_faceName == wxT("UTOPIA"))
301 M_FONTDATA->m_family = wxSCRIPT;
302
303 tn.GetNextToken(); // avg width
304
305 // deal with font encoding
306 M_FONTDATA->m_encoding = enc;
307 if ( M_FONTDATA->m_encoding == wxFONTENCODING_SYSTEM )
308 {
309 wxString registry = tn.GetNextToken().MakeUpper(),
310 encoding = tn.GetNextToken().MakeUpper();
311
312 if ( registry == _T("ISO8859") )
313 {
314 int cp;
315 if ( wxSscanf(encoding, wxT("%d"), &cp) == 1 )
316 {
317 M_FONTDATA->m_encoding =
318 (wxFontEncoding)(wxFONTENCODING_ISO8859_1 + cp - 1);
319 }
320 }
321 else if ( registry == _T("MICROSOFT") )
322 {
323 int cp;
324 if ( wxSscanf(encoding, wxT("cp125%d"), &cp) == 1 )
325 {
326 M_FONTDATA->m_encoding =
327 (wxFontEncoding)(wxFONTENCODING_CP1250 + cp);
328 }
329 }
330 else if ( registry == _T("KOI8") )
331 {
332 M_FONTDATA->m_encoding = wxFONTENCODING_KOI8;
333 }
334 //else: unknown encoding - may be give a warning here?
335 else
96be256b 336 return false;
563f868d 337 }
96be256b 338 return true;
563f868d
GD
339}
340
4bb6408c
JS
341wxFont::~wxFont()
342{
4bb6408c
JS
343}
344
93ccaed8
VZ
345// ----------------------------------------------------------------------------
346// change the font attributes
347// ----------------------------------------------------------------------------
4bb6408c
JS
348
349void wxFont::Unshare()
350{
2d120f83
JS
351 // Don't change shared data
352 if (!m_refData)
4bb6408c 353 {
2d120f83
JS
354 m_refData = new wxFontRefData();
355 }
4bb6408c
JS
356 else
357 {
2d120f83
JS
358 wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
359 UnRef();
360 m_refData = ref;
361 }
4bb6408c
JS
362}
363
364void wxFont::SetPointSize(int pointSize)
365{
366 Unshare();
dfe1eee3 367
4bb6408c 368 M_FONTDATA->m_pointSize = pointSize;
42f30fa2 369 M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
4bb6408c
JS
370}
371
372void wxFont::SetFamily(int family)
373{
374 Unshare();
dfe1eee3 375
4bb6408c 376 M_FONTDATA->m_family = family;
42f30fa2 377 M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
4bb6408c
JS
378}
379
380void wxFont::SetStyle(int style)
381{
382 Unshare();
dfe1eee3 383
4bb6408c 384 M_FONTDATA->m_style = style;
42f30fa2 385 M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
4bb6408c
JS
386}
387
388void wxFont::SetWeight(int weight)
389{
390 Unshare();
dfe1eee3 391
4bb6408c 392 M_FONTDATA->m_weight = weight;
42f30fa2 393 M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
4bb6408c
JS
394}
395
85ab460e 396bool wxFont::SetFaceName(const wxString& faceName)
4bb6408c
JS
397{
398 Unshare();
dfe1eee3 399
4bb6408c 400 M_FONTDATA->m_faceName = faceName;
42f30fa2 401 M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
85ab460e
VZ
402
403 return wxFontBase::SetFaceName(faceName);
4bb6408c
JS
404}
405
406void wxFont::SetUnderlined(bool underlined)
407{
408 Unshare();
dfe1eee3 409
4bb6408c 410 M_FONTDATA->m_underlined = underlined;
4bb6408c
JS
411}
412
93ccaed8 413void wxFont::SetEncoding(wxFontEncoding encoding)
4bb6408c 414{
93ccaed8
VZ
415 Unshare();
416
417 M_FONTDATA->m_encoding = encoding;
42f30fa2 418 M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
93ccaed8
VZ
419}
420
9045ad9d 421void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info)
563f868d
GD
422{
423 Unshare();
424
425 M_FONTDATA->m_nativeFontInfo = info;
426}
427
93ccaed8
VZ
428// ----------------------------------------------------------------------------
429// query font attributes
430// ----------------------------------------------------------------------------
431
432int wxFont::GetPointSize() const
433{
563f868d 434 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
9045ad9d 435
93ccaed8
VZ
436 return M_FONTDATA->m_pointSize;
437}
438
563f868d
GD
439wxString wxFont::GetFaceName() const
440{
7520f3da 441 wxCHECK_MSG( Ok(), wxEmptyString, wxT("invalid font") );
563f868d
GD
442
443 return M_FONTDATA->m_faceName ;
444}
445
93ccaed8
VZ
446int wxFont::GetFamily() const
447{
563f868d
GD
448 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
449
93ccaed8
VZ
450 return M_FONTDATA->m_family;
451}
452
453int wxFont::GetStyle() const
454{
563f868d
GD
455 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
456
93ccaed8
VZ
457 return M_FONTDATA->m_style;
458}
459
460int wxFont::GetWeight() const
461{
563f868d
GD
462 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
463
93ccaed8
VZ
464 return M_FONTDATA->m_weight;
465}
466
467bool wxFont::GetUnderlined() const
468{
96be256b 469 wxCHECK_MSG( Ok(), false, wxT("invalid font") );
563f868d 470
93ccaed8 471 return M_FONTDATA->m_underlined;
4bb6408c
JS
472}
473
563f868d 474wxFontEncoding wxFont::GetEncoding() const
4bb6408c 475{
563f868d
GD
476 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") );
477
478 return M_FONTDATA->m_encoding;
4bb6408c
JS
479}
480
3bf5a59b 481const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
4bb6408c 482{
563f868d
GD
483 wxCHECK_MSG( Ok(), (wxNativeFontInfo *)NULL, wxT("invalid font") );
484
7520f3da 485 if(M_FONTDATA->m_nativeFontInfo.GetXFontName().empty())
563f868d
GD
486 GetInternalFont();
487
3bf5a59b 488 return &(M_FONTDATA->m_nativeFontInfo);
4bb6408c
JS
489}
490
93ccaed8
VZ
491// ----------------------------------------------------------------------------
492// real implementation
493// ----------------------------------------------------------------------------
4bb6408c 494
dfc54541
JS
495// Find an existing, or create a new, XFontStruct
496// based on this wxFont and the given scale. Append the
497// font to list in the private data for future reference.
f97c9854 498wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const
dfc54541 499{
93ccaed8
VZ
500 if ( !Ok() )
501 return (wxXFont *)NULL;
dfe1eee3 502
2d120f83
JS
503 long intScale = long(scale * 100.0 + 0.5); // key for wxXFont
504 int pointSize = (M_FONTDATA->m_pointSize * 10 * intScale) / 100;
dfe1eee3 505
93ccaed8 506 // search existing fonts first
ac32ba44 507 wxList::compatibility_iterator node = M_FONTDATA->m_fonts.GetFirst();
2d120f83
JS
508 while (node)
509 {
fd304d98 510 wxXFont* f = (wxXFont*) node->GetData();
2d120f83
JS
511 if ((!display || (f->m_display == display)) && (f->m_scale == intScale))
512 return f;
fd304d98 513 node = node->GetNext();
2d120f83 514 }
dfe1eee3 515
93ccaed8 516 // not found, create a new one
996994c7 517 wxString xFontSpec;
0d083705
VZ
518 XFontStruct *font = (XFontStruct *)
519 wxLoadQueryNearestFont(pointSize,
93ccaed8
VZ
520 M_FONTDATA->m_family,
521 M_FONTDATA->m_style,
522 M_FONTDATA->m_weight,
523 M_FONTDATA->m_underlined,
223d09f6 524 wxT(""),
996994c7
MB
525 M_FONTDATA->m_encoding,
526 &xFontSpec);
dfe1eee3 527
93ccaed8 528 if ( !font )
2d120f83 529 {
223d09f6 530 wxFAIL_MSG( wxT("Could not allocate even a default font -- something is wrong.") );
93ccaed8
VZ
531
532 return (wxXFont*) NULL;
2d120f83 533 }
93ccaed8
VZ
534
535 wxXFont* f = new wxXFont;
996994c7
MB
536#if wxMOTIF_NEW_FONT_HANDLING
537 XFreeFont( (Display*) display, font );
538#else
93ccaed8 539 f->m_fontStruct = (WXFontStructPtr)font;
996994c7 540#endif
93ccaed8
VZ
541 f->m_display = ( display ? display : wxGetDisplay() );
542 f->m_scale = intScale;
7520f3da 543
eb9d223a 544#if wxMOTIF_USE_RENDER_TABLE
da494b40
MB
545 XmRendition rendition;
546 XmRenderTable renderTable;
547 Arg args[5];
548 int count = 0;
549
996994c7
MB
550#if wxMOTIF_NEW_FONT_HANDLING
551 wxChar* fontSpec = wxStrdup( xFontSpec.c_str() );
552 XtSetArg( args[count], XmNfontName, fontSpec ); ++count;
553 XtSetArg( args[count], XmNfontType, XmFONT_IS_FONTSET ); ++count;
554#else
da494b40 555 XtSetArg( args[count], XmNfont, font ); ++count;
996994c7 556#endif
da494b40
MB
557 XtSetArg( args[count], XmNunderlineType,
558 GetUnderlined() ? XmSINGLE_LINE : XmNO_LINE ); ++count;
559 rendition = XmRenditionCreate( XmGetXmDisplay( (Display*)f->m_display ),
560 (XmStringTag)"",
561 args, count );
562 renderTable = XmRenderTableAddRenditions( NULL, &rendition, 1,
563 XmMERGE_REPLACE );
564
565 f->m_renderTable = (WXRenderTable)renderTable;
996994c7
MB
566 f->m_rendition = (WXRendition)rendition;
567 wxASSERT( f->m_renderTable != NULL );
eb9d223a 568#else // if !wxMOTIF_USE_RENDER_TABLE
996994c7
MB
569 f->m_fontList = XmFontListCreate ((XFontStruct*) font, XmSTRING_DEFAULT_CHARSET);
570 wxASSERT( f->m_fontList != NULL );
da494b40
MB
571#endif
572
996994c7
MB
573 M_FONTDATA->m_fonts.Append(f);
574
93ccaed8 575 return f;
dfc54541
JS
576}
577
996994c7
MB
578#if !wxMOTIF_NEW_FONT_HANDLING
579
93ccaed8 580WXFontStructPtr wxFont::GetFontStruct(double scale, WXDisplay* display) const
dfc54541 581{
93ccaed8 582 wxXFont* f = GetInternalFont(scale, display);
dfe1eee3 583
93ccaed8
VZ
584 return (f ? f->m_fontStruct : (WXFontStructPtr) 0);
585}
dfe1eee3 586
eb9d223a
MB
587#endif
588
589#if !wxMOTIF_USE_RENDER_TABLE
590
93ccaed8
VZ
591WXFontList wxFont::GetFontList(double scale, WXDisplay* display) const
592{
593 wxXFont* f = GetInternalFont(scale, display);
dfe1eee3 594
93ccaed8 595 return (f ? f->m_fontList : (WXFontList) 0);
dfc54541 596}
7ecb8b06 597
eb9d223a 598#else // if wxMOTIF_USE_RENDER_TABLE
da494b40
MB
599
600WXRenderTable wxFont::GetRenderTable(WXDisplay* display) const
601{
602 wxXFont* f = GetInternalFont(1.0, display);
603
eb9d223a 604 return (f ? f->m_renderTable : (WXRenderTable) 0);
da494b40
MB
605}
606
eb9d223a 607#endif // wxMOTIF_USE_RENDER_TABLE
da494b40
MB
608
609WXFontType wxFont::GetFontType(WXDisplay* display) const
610{
eb9d223a 611#if wxMOTIF_USE_RENDER_TABLE
da494b40
MB
612 return Ok() ? GetRenderTable(display) : NULL;
613#else
614 return Ok() ? GetFontList(1.0, display) : NULL;
615#endif
616}
617
73608949
MB
618WXFontType wxFont::GetFontTypeC(WXDisplay* display) const
619{
eb9d223a 620#if wxMOTIF_USE_RENDER_TABLE
73608949
MB
621 return Ok() ? GetRenderTable(display) : NULL;
622#else
623 return Ok() ? XmFontListCopy( (XmFontList)GetFontList(1.0, display) ) : NULL;
624#endif
625}
626
da494b40
MB
627/*static*/ WXString wxFont::GetFontTag()
628{
eb9d223a 629#if wxMOTIF_USE_RENDER_TABLE
da494b40
MB
630 return (WXString)XmNrenderTable;
631#else
632 return (WXString)XmNfontList;
633#endif
634}
996994c7
MB
635
636#if wxMOTIF_NEW_FONT_HANDLING
637
638WXFontSet wxFont::GetFontSet(double scale, WXDisplay* display) const
639{
640 wxXFont* f = GetInternalFont(scale, display);
641
642 if( !f ) return (WXFontSet) 0;
643
644 Arg args[2];
645 int count = 0;
646
647 XtSetArg( args[count], XmNfont, 0 ); ++count;
648 XmRenditionRetrieve( (XmRendition) f->m_rendition, args, count );
649
650 return (WXFontSet) args[0].value;
651}
652
653void wxGetTextExtent(WXDisplay* display, const wxFont& font, double scale,
654 const wxString& str,
655 int* width, int* height, int* ascent, int* descent)
656{
657 XRectangle ink, logical;
658 WXFontSet fset = font.GetFontSet(scale, display);
7520f3da 659
996994c7
MB
660 XmbTextExtents( (XFontSet)fset, str.c_str(), str.length(), &ink, &logical);
661
662 if( width ) *width = logical.width;
663 if( height ) *height = logical.height;
7520f3da
WS
664 if( ascent ) *ascent = -logical.y;
665 if( descent ) *descent = logical.height + logical.y;
996994c7
MB
666}
667
668#else // if !wxMOTIF_NEW_FONT_HANDLING
669
670void wxGetTextExtent(WXDisplay* display, const wxFont& font,
671 double scale, const wxString& str,
672 int* width, int* height, int* ascent, int* descent)
673{
674 WXFontStructPtr pFontStruct = font.GetFontStruct(scale, display);
675
676 int direction, ascent2, descent2;
677 XCharStruct overall;
dd05139a 678 int slen = str.length();
996994c7
MB
679
680 XTextExtents((XFontStruct*) pFontStruct, (char*) str.c_str(), slen,
681 &direction, &ascent2, &descent2, &overall);
682
683 if ( width )
684 *width = (overall.width);
685 if ( height )
686 *height = (ascent2 + descent2);
687 if ( descent )
688 *descent = descent2;
689 if ( ascent )
690 *ascent = ascent2;
691}
692
693#endif // !wxMOTIF_NEW_FONT_HANDLING