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