]> git.saurik.com Git - wxWidgets.git/blame - src/motif/font.cpp
account for the label size in wxDisclosureTriangle under Carbon
[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();
d3c7fc99 57 virtual ~wxXFont();
93ccaed8 58
996994c7 59#if !wxMOTIF_NEW_FONT_HANDLING
93ccaed8 60 WXFontStructPtr m_fontStruct; // XFontStruct
996994c7 61#endif
105fbe1f 62#if !wxMOTIF_USE_RENDER_TABLE
93ccaed8 63 WXFontList m_fontList; // Motif XmFontList
b0f76951 64#else // if wxMOTIF_USE_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,
0c14b6c3
FM
78 wxFontFamily family = wxFONTFAMILY_DEFAULT,
79 wxFontStyle style = wxFONTSTYLE_NORMAL,
80 wxFontWeight weight = wxFONTWEIGHT_NORMAL,
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
d3c7fc99 94 virtual ~wxFontRefData();
93ccaed8
VZ
95
96protected:
97 // common part of all ctors
98 void Init(int size,
0c14b6c3
FM
99 wxFontFamily family,
100 wxFontStyle style,
101 wxFontWeight weight,
93ccaed8
VZ
102 bool underlined,
103 const wxString& faceName,
104 wxFontEncoding encoding);
105
106 // font attributes
107 int m_pointSize;
0c14b6c3
FM
108 wxFontFamily m_family;
109 wxFontStyle m_style;
110 wxFontWeight m_weight;
93ccaed8
VZ
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
105fbe1f 134#if !wxMOTIF_USE_RENDER_TABLE
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;
b0f76951 150#else // if wxMOTIF_USE_RENDER_TABLE
73608949
MB
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,
0c14b6c3
FM
169 wxFontFamily family,
170 wxFontStyle style,
171 wxFontWeight weight,
93ccaed8
VZ
172 bool underlined,
173 const wxString& faceName,
174 wxFontEncoding encoding)
4bb6408c 175{
93ccaed8 176 if (family == wxDEFAULT)
0c14b6c3 177 m_family = wxFONTFAMILY_SWISS;
93ccaed8
VZ
178 else
179 m_family = family;
4bb6408c 180
93ccaed8
VZ
181 m_faceName = faceName;
182
183 if (style == wxDEFAULT)
0c14b6c3 184 m_style = wxFONTSTYLE_NORMAL;
93ccaed8
VZ
185 else
186 m_style = style;
187
188 if (weight == wxDEFAULT)
0c14b6c3 189 m_weight = wxFONTWEIGHT_NORMAL;
93ccaed8
VZ
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
68c95704 214#define M_FONTDATA ((wxFontRefData*)m_refData)
873fd4af 215
93ccaed8
VZ
216// ----------------------------------------------------------------------------
217// wxFont
218// ----------------------------------------------------------------------------
4bb6408c 219
ef4e8ebd 220wxFont::wxFont(const wxNativeFontInfo& info)
98c9fc2d 221{
42f30fa2 222 (void)Create(info.GetXFontName());
98c9fc2d
VZ
223}
224
93ccaed8 225bool wxFont::Create(int pointSize,
0c14b6c3
FM
226 wxFontFamily family,
227 wxFontStyle style,
228 wxFontWeight weight,
93ccaed8
VZ
229 bool underlined,
230 const wxString& faceName,
231 wxFontEncoding encoding)
4bb6408c
JS
232{
233 UnRef();
93ccaed8
VZ
234 m_refData = new wxFontRefData(pointSize, family, style, weight,
235 underlined, faceName, encoding);
dfe1eee3 236
96be256b 237 return true;
4bb6408c
JS
238}
239
563f868d
GD
240bool wxFont::Create(const wxString& fontname, wxFontEncoding enc)
241{
242 if( !fontname )
243 {
a756f210 244 *this = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT);
96be256b 245 return true;
563f868d
GD
246 }
247
248 m_refData = new wxFontRefData();
249
42f30fa2 250 M_FONTDATA->m_nativeFontInfo.SetXFontName(fontname); // X font name
563f868d
GD
251
252 wxString tmp;
253
254 wxStringTokenizer tn( fontname, wxT("-") );
255
256 tn.GetNextToken(); // skip initial empty token
257 tn.GetNextToken(); // foundry
258
259
260 M_FONTDATA->m_faceName = tn.GetNextToken(); // family
261
262 tmp = tn.GetNextToken().MakeUpper(); // weight
0c14b6c3
FM
263 if (tmp == wxT("BOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
264 if (tmp == wxT("BLACK")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
265 if (tmp == wxT("EXTRABOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
266 if (tmp == wxT("DEMIBOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
267 if (tmp == wxT("ULTRABOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
563f868d 268
0c14b6c3
FM
269 if (tmp == wxT("LIGHT")) M_FONTDATA->m_weight = wxFONTWEIGHT_LIGHT;
270 if (tmp == wxT("THIN")) M_FONTDATA->m_weight = wxFONTWEIGHT_LIGHT;
563f868d
GD
271
272 tmp = tn.GetNextToken().MakeUpper(); // slant
0c14b6c3
FM
273 if (tmp == wxT("I")) M_FONTDATA->m_style = wxFONTSTYLE_ITALIC;
274 if (tmp == wxT("O")) M_FONTDATA->m_style = wxFONTSTYLE_ITALIC;
563f868d
GD
275
276 tn.GetNextToken(); // set width
277 tn.GetNextToken(); // add. style
278 tn.GetNextToken(); // pixel size
279
280 tmp = tn.GetNextToken(); // pointsize
281 if (tmp != wxT("*"))
282 {
9b135950 283 long num = wxStrtol (tmp.mb_str(), (wxChar **) NULL, 10);
563f868d
GD
284 M_FONTDATA->m_pointSize = (int)(num / 10);
285 }
286
287 tn.GetNextToken(); // x-res
288 tn.GetNextToken(); // y-res
289
290 tmp = tn.GetNextToken().MakeUpper(); // spacing
291
292 if (tmp == wxT("M"))
0c14b6c3 293 M_FONTDATA->m_family = wxFONTFAMILY_MODERN;
563f868d 294 else if (M_FONTDATA->m_faceName == wxT("TIMES"))
0c14b6c3 295 M_FONTDATA->m_family = wxFONTFAMILY_ROMAN;
563f868d 296 else if (M_FONTDATA->m_faceName == wxT("HELVETICA"))
0c14b6c3 297 M_FONTDATA->m_family = wxFONTFAMILY_SWISS;
563f868d 298 else if (M_FONTDATA->m_faceName == wxT("LUCIDATYPEWRITER"))
0c14b6c3 299 M_FONTDATA->m_family = wxFONTFAMILY_TELETYPE;
563f868d 300 else if (M_FONTDATA->m_faceName == wxT("LUCIDA"))
0c14b6c3 301 M_FONTDATA->m_family = wxFONTFAMILY_DECORATIVE;
563f868d 302 else if (M_FONTDATA->m_faceName == wxT("UTOPIA"))
0c14b6c3 303 M_FONTDATA->m_family = wxFONTFAMILY_SCRIPT;
563f868d
GD
304
305 tn.GetNextToken(); // avg width
306
307 // deal with font encoding
308 M_FONTDATA->m_encoding = enc;
309 if ( M_FONTDATA->m_encoding == wxFONTENCODING_SYSTEM )
310 {
311 wxString registry = tn.GetNextToken().MakeUpper(),
312 encoding = tn.GetNextToken().MakeUpper();
313
314 if ( registry == _T("ISO8859") )
315 {
316 int cp;
317 if ( wxSscanf(encoding, wxT("%d"), &cp) == 1 )
318 {
319 M_FONTDATA->m_encoding =
320 (wxFontEncoding)(wxFONTENCODING_ISO8859_1 + cp - 1);
321 }
322 }
323 else if ( registry == _T("MICROSOFT") )
324 {
325 int cp;
326 if ( wxSscanf(encoding, wxT("cp125%d"), &cp) == 1 )
327 {
328 M_FONTDATA->m_encoding =
329 (wxFontEncoding)(wxFONTENCODING_CP1250 + cp);
330 }
331 }
332 else if ( registry == _T("KOI8") )
333 {
334 M_FONTDATA->m_encoding = wxFONTENCODING_KOI8;
335 }
336 //else: unknown encoding - may be give a warning here?
337 else
96be256b 338 return false;
563f868d 339 }
96be256b 340 return true;
563f868d
GD
341}
342
4bb6408c
JS
343wxFont::~wxFont()
344{
4bb6408c
JS
345}
346
8f884a0d
VZ
347wxGDIRefData *wxFont::CreateGDIRefData() const
348{
349 return new wxFontRefData;
350}
351
352wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const
353{
5c33522f 354 return new wxFontRefData(*static_cast<const wxFontRefData *>(data));
8f884a0d
VZ
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
4bb6408c
JS
382}
383
0c14b6c3 384void wxFont::SetFamily(wxFontFamily family)
4bb6408c
JS
385{
386 Unshare();
dfe1eee3 387
4bb6408c 388 M_FONTDATA->m_family = family;
42f30fa2 389 M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
4bb6408c
JS
390}
391
0c14b6c3 392void wxFont::SetStyle(wxFontStyle style)
4bb6408c
JS
393{
394 Unshare();
dfe1eee3 395
4bb6408c 396 M_FONTDATA->m_style = style;
42f30fa2 397 M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
4bb6408c
JS
398}
399
0c14b6c3 400void wxFont::SetWeight(wxFontWeight weight)
4bb6408c
JS
401{
402 Unshare();
dfe1eee3 403
4bb6408c 404 M_FONTDATA->m_weight = weight;
42f30fa2 405 M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
4bb6408c
JS
406}
407
85ab460e 408bool wxFont::SetFaceName(const wxString& faceName)
4bb6408c
JS
409{
410 Unshare();
dfe1eee3 411
4bb6408c 412 M_FONTDATA->m_faceName = faceName;
42f30fa2 413 M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
85ab460e
VZ
414
415 return wxFontBase::SetFaceName(faceName);
4bb6408c
JS
416}
417
418void wxFont::SetUnderlined(bool underlined)
419{
420 Unshare();
dfe1eee3 421
4bb6408c 422 M_FONTDATA->m_underlined = underlined;
4bb6408c
JS
423}
424
93ccaed8 425void wxFont::SetEncoding(wxFontEncoding encoding)
4bb6408c 426{
93ccaed8
VZ
427 Unshare();
428
429 M_FONTDATA->m_encoding = encoding;
42f30fa2 430 M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
93ccaed8
VZ
431}
432
9045ad9d 433void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info)
563f868d
GD
434{
435 Unshare();
436
437 M_FONTDATA->m_nativeFontInfo = info;
438}
439
93ccaed8
VZ
440// ----------------------------------------------------------------------------
441// query font attributes
442// ----------------------------------------------------------------------------
443
444int wxFont::GetPointSize() const
445{
563f868d 446 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
9045ad9d 447
93ccaed8
VZ
448 return M_FONTDATA->m_pointSize;
449}
450
563f868d
GD
451wxString wxFont::GetFaceName() const
452{
7520f3da 453 wxCHECK_MSG( Ok(), wxEmptyString, wxT("invalid font") );
563f868d
GD
454
455 return M_FONTDATA->m_faceName ;
456}
457
0c14b6c3 458wxFontFamily wxFont::GetFamily() const
93ccaed8 459{
0c14b6c3 460 wxCHECK_MSG( Ok(), wxFONTFAMILY_MAX, wxT("invalid font") );
563f868d 461
93ccaed8
VZ
462 return M_FONTDATA->m_family;
463}
464
0c14b6c3 465wxFontStyle wxFont::GetStyle() const
93ccaed8 466{
0c14b6c3 467 wxCHECK_MSG( Ok(), wxFONTSTYLE_MAX, wxT("invalid font") );
563f868d 468
93ccaed8
VZ
469 return M_FONTDATA->m_style;
470}
471
0c14b6c3 472wxFontWeight wxFont::GetWeight() const
93ccaed8 473{
0c14b6c3 474 wxCHECK_MSG( Ok(), wxFONTWEIGHT_MAX, wxT("invalid font") );
563f868d 475
93ccaed8
VZ
476 return M_FONTDATA->m_weight;
477}
478
479bool wxFont::GetUnderlined() const
480{
96be256b 481 wxCHECK_MSG( Ok(), false, wxT("invalid font") );
563f868d 482
93ccaed8 483 return M_FONTDATA->m_underlined;
4bb6408c
JS
484}
485
563f868d 486wxFontEncoding wxFont::GetEncoding() const
4bb6408c 487{
563f868d
GD
488 wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") );
489
490 return M_FONTDATA->m_encoding;
4bb6408c
JS
491}
492
3bf5a59b 493const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
4bb6408c 494{
d3b9f782 495 wxCHECK_MSG( Ok(), NULL, wxT("invalid font") );
563f868d 496
7520f3da 497 if(M_FONTDATA->m_nativeFontInfo.GetXFontName().empty())
563f868d
GD
498 GetInternalFont();
499
3bf5a59b 500 return &(M_FONTDATA->m_nativeFontInfo);
4bb6408c
JS
501}
502
93ccaed8
VZ
503// ----------------------------------------------------------------------------
504// real implementation
505// ----------------------------------------------------------------------------
4bb6408c 506
dfc54541
JS
507// Find an existing, or create a new, XFontStruct
508// based on this wxFont and the given scale. Append the
509// font to list in the private data for future reference.
f97c9854 510wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const
dfc54541 511{
93ccaed8 512 if ( !Ok() )
d3b9f782 513 return NULL;
dfe1eee3 514
2d120f83
JS
515 long intScale = long(scale * 100.0 + 0.5); // key for wxXFont
516 int pointSize = (M_FONTDATA->m_pointSize * 10 * intScale) / 100;
dfe1eee3 517
93ccaed8 518 // search existing fonts first
ac32ba44 519 wxList::compatibility_iterator node = M_FONTDATA->m_fonts.GetFirst();
2d120f83
JS
520 while (node)
521 {
fd304d98 522 wxXFont* f = (wxXFont*) node->GetData();
2d120f83
JS
523 if ((!display || (f->m_display == display)) && (f->m_scale == intScale))
524 return f;
fd304d98 525 node = node->GetNext();
2d120f83 526 }
dfe1eee3 527
93ccaed8 528 // not found, create a new one
996994c7 529 wxString xFontSpec;
0d083705
VZ
530 XFontStruct *font = (XFontStruct *)
531 wxLoadQueryNearestFont(pointSize,
93ccaed8
VZ
532 M_FONTDATA->m_family,
533 M_FONTDATA->m_style,
534 M_FONTDATA->m_weight,
535 M_FONTDATA->m_underlined,
223d09f6 536 wxT(""),
996994c7
MB
537 M_FONTDATA->m_encoding,
538 &xFontSpec);
dfe1eee3 539
93ccaed8 540 if ( !font )
2d120f83 541 {
223d09f6 542 wxFAIL_MSG( wxT("Could not allocate even a default font -- something is wrong.") );
93ccaed8 543
d3b9f782 544 return NULL;
2d120f83 545 }
93ccaed8
VZ
546
547 wxXFont* f = new wxXFont;
996994c7
MB
548#if wxMOTIF_NEW_FONT_HANDLING
549 XFreeFont( (Display*) display, font );
550#else
93ccaed8 551 f->m_fontStruct = (WXFontStructPtr)font;
996994c7 552#endif
93ccaed8
VZ
553 f->m_display = ( display ? display : wxGetDisplay() );
554 f->m_scale = intScale;
7520f3da 555
eb9d223a 556#if wxMOTIF_USE_RENDER_TABLE
da494b40
MB
557 XmRendition rendition;
558 XmRenderTable renderTable;
559 Arg args[5];
560 int count = 0;
561
996994c7 562#if wxMOTIF_NEW_FONT_HANDLING
6991087b 563 char* fontSpec = wxStrdup(xFontSpec.mb_str());
996994c7
MB
564 XtSetArg( args[count], XmNfontName, fontSpec ); ++count;
565 XtSetArg( args[count], XmNfontType, XmFONT_IS_FONTSET ); ++count;
566#else
da494b40 567 XtSetArg( args[count], XmNfont, font ); ++count;
996994c7 568#endif
da494b40
MB
569 XtSetArg( args[count], XmNunderlineType,
570 GetUnderlined() ? XmSINGLE_LINE : XmNO_LINE ); ++count;
571 rendition = XmRenditionCreate( XmGetXmDisplay( (Display*)f->m_display ),
572 (XmStringTag)"",
573 args, count );
574 renderTable = XmRenderTableAddRenditions( NULL, &rendition, 1,
575 XmMERGE_REPLACE );
576
577 f->m_renderTable = (WXRenderTable)renderTable;
996994c7
MB
578 f->m_rendition = (WXRendition)rendition;
579 wxASSERT( f->m_renderTable != NULL );
eb9d223a 580#else // if !wxMOTIF_USE_RENDER_TABLE
996994c7
MB
581 f->m_fontList = XmFontListCreate ((XFontStruct*) font, XmSTRING_DEFAULT_CHARSET);
582 wxASSERT( f->m_fontList != NULL );
da494b40
MB
583#endif
584
996994c7
MB
585 M_FONTDATA->m_fonts.Append(f);
586
93ccaed8 587 return f;
dfc54541
JS
588}
589
996994c7
MB
590#if !wxMOTIF_NEW_FONT_HANDLING
591
93ccaed8 592WXFontStructPtr wxFont::GetFontStruct(double scale, WXDisplay* display) const
dfc54541 593{
93ccaed8 594 wxXFont* f = GetInternalFont(scale, display);
dfe1eee3 595
93ccaed8
VZ
596 return (f ? f->m_fontStruct : (WXFontStructPtr) 0);
597}
dfe1eee3 598
eb9d223a
MB
599#endif
600
601#if !wxMOTIF_USE_RENDER_TABLE
602
93ccaed8
VZ
603WXFontList wxFont::GetFontList(double scale, WXDisplay* display) const
604{
605 wxXFont* f = GetInternalFont(scale, display);
dfe1eee3 606
93ccaed8 607 return (f ? f->m_fontList : (WXFontList) 0);
dfc54541 608}
7ecb8b06 609
eb9d223a 610#else // if wxMOTIF_USE_RENDER_TABLE
da494b40
MB
611
612WXRenderTable wxFont::GetRenderTable(WXDisplay* display) const
613{
614 wxXFont* f = GetInternalFont(1.0, display);
615
eb9d223a 616 return (f ? f->m_renderTable : (WXRenderTable) 0);
da494b40
MB
617}
618
eb9d223a 619#endif // wxMOTIF_USE_RENDER_TABLE
da494b40
MB
620
621WXFontType wxFont::GetFontType(WXDisplay* display) const
622{
eb9d223a 623#if wxMOTIF_USE_RENDER_TABLE
da494b40
MB
624 return Ok() ? GetRenderTable(display) : NULL;
625#else
626 return Ok() ? GetFontList(1.0, display) : NULL;
627#endif
628}
629
73608949
MB
630WXFontType wxFont::GetFontTypeC(WXDisplay* display) const
631{
eb9d223a 632#if wxMOTIF_USE_RENDER_TABLE
73608949
MB
633 return Ok() ? GetRenderTable(display) : NULL;
634#else
635 return Ok() ? XmFontListCopy( (XmFontList)GetFontList(1.0, display) ) : NULL;
636#endif
637}
638
da494b40
MB
639/*static*/ WXString wxFont::GetFontTag()
640{
eb9d223a 641#if wxMOTIF_USE_RENDER_TABLE
da494b40
MB
642 return (WXString)XmNrenderTable;
643#else
644 return (WXString)XmNfontList;
645#endif
646}
996994c7 647
105fbe1f 648#if wxMOTIF_USE_RENDER_TABLE
996994c7
MB
649
650WXFontSet wxFont::GetFontSet(double scale, WXDisplay* display) const
651{
652 wxXFont* f = GetInternalFont(scale, display);
653
654 if( !f ) return (WXFontSet) 0;
655
656 Arg args[2];
657 int count = 0;
658
659 XtSetArg( args[count], XmNfont, 0 ); ++count;
660 XmRenditionRetrieve( (XmRendition) f->m_rendition, args, count );
661
662 return (WXFontSet) args[0].value;
663}
664
665void wxGetTextExtent(WXDisplay* display, const wxFont& font, double scale,
666 const wxString& str,
667 int* width, int* height, int* ascent, int* descent)
668{
669 XRectangle ink, logical;
670 WXFontSet fset = font.GetFontSet(scale, display);
7520f3da 671
9b135950 672 XmbTextExtents( (XFontSet)fset, str.mb_str(), str.length(), &ink, &logical);
996994c7
MB
673
674 if( width ) *width = logical.width;
675 if( height ) *height = logical.height;
7520f3da
WS
676 if( ascent ) *ascent = -logical.y;
677 if( descent ) *descent = logical.height + logical.y;
996994c7
MB
678}
679
105fbe1f 680#else // if !wxMOTIF_USE_RENDER_TABLE
996994c7
MB
681
682void wxGetTextExtent(WXDisplay* display, const wxFont& font,
683 double scale, const wxString& str,
684 int* width, int* height, int* ascent, int* descent)
685{
686 WXFontStructPtr pFontStruct = font.GetFontStruct(scale, display);
687
688 int direction, ascent2, descent2;
689 XCharStruct overall;
dd05139a 690 int slen = str.length();
996994c7 691
efb35beb 692 XTextExtents((XFontStruct*) pFontStruct,
5c33522f 693 const_cast<char*>((const char *)str.mb_str()), slen,
996994c7
MB
694 &direction, &ascent2, &descent2, &overall);
695
696 if ( width )
697 *width = (overall.width);
698 if ( height )
699 *height = (ascent2 + descent2);
700 if ( descent )
701 *descent = descent2;
702 if ( ascent )
703 *ascent = ascent2;
704}
705
105fbe1f 706#endif // !wxMOTIF_USE_RENDER_TABLE