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