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