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