]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/font.cpp
cleanup, fixing exports
[wxWidgets.git] / src / mac / carbon / font.cpp
CommitLineData
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
df91131c 2// Name: src/mac/carbon/font.cpp
e9576ca5 3// Purpose: wxFont class
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3e527073
SC
12#include "wx/wxprec.h"
13
e9576ca5 14#include "wx/font.h"
df91131c
WS
15
16#ifndef WX_PRECOMP
17 #include "wx/string.h"
de6185e2 18 #include "wx/utils.h"
987e9419 19 #include "wx/intl.h"
dd05139a 20 #include "wx/gdicmn.h"
162f6b2a 21 #include "wx/log.h"
df91131c
WS
22#endif
23
5b781a67 24#include "wx/fontutil.h"
ccd67a6a 25#include "wx/graphics.h"
3b7e6277 26
76a5e5d2 27#include "wx/mac/private.h"
6eaa4426 28
768c6e8b 29#ifndef __DARWIN__
7f0c3a63 30#include <ATSUnicode.h>
768c6e8b 31#endif
76a5e5d2 32
6eaa4426 33
e9576ca5 34IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
e9576ca5 35
6eaa4426 36
3bf5a59b
VZ
37class WXDLLEXPORT wxFontRefData: public wxGDIRefData
38{
868302f3 39 friend class wxFont;
6eaa4426 40
3bf5a59b
VZ
41public:
42 wxFontRefData()
43 : m_fontId(0)
44 , m_pointSize(10)
45 , m_family(wxDEFAULT)
46 , m_style(wxNORMAL)
47 , m_weight(wxNORMAL)
df91131c 48 , m_underlined(false)
c277569a 49 , m_faceName(wxT("applicationfont"))
3bf5a59b 50 , m_encoding(wxFONTENCODING_DEFAULT)
6239ee05
SC
51#ifdef __LP64__
52#else
2a0155df 53 , m_macFontFamily(0)
3bf5a59b
VZ
54 , m_macFontSize(0)
55 , m_macFontStyle(0)
e369bddb 56 , m_macATSUFontID(0)
6239ee05
SC
57#endif
58 , m_macATSUStyle(0)
3bf5a59b 59 {
c277569a
SC
60 Init(m_pointSize, m_family, m_style, m_weight,
61 m_underlined, m_faceName, m_encoding);
3bf5a59b
VZ
62 }
63
64 wxFontRefData(const wxFontRefData& data)
65 : wxGDIRefData()
66 , m_fontId(data.m_fontId)
67 , m_pointSize(data.m_pointSize)
68 , m_family(data.m_family)
69 , m_style(data.m_style)
70 , m_weight(data.m_weight)
71 , m_underlined(data.m_underlined)
72 , m_faceName(data.m_faceName)
73 , m_encoding(data.m_encoding)
6239ee05
SC
74#ifdef __LP64__
75#else
2a0155df 76 , m_macFontFamily(data.m_macFontFamily)
3bf5a59b
VZ
77 , m_macFontSize(data.m_macFontSize)
78 , m_macFontStyle(data.m_macFontStyle)
e369bddb 79 , m_macATSUFontID(data.m_macATSUFontID)
6239ee05
SC
80#endif
81 , m_macATSUStyle(0)
3bf5a59b
VZ
82 {
83 Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight,
84 data.m_underlined, data.m_faceName, data.m_encoding);
85 }
86
87 wxFontRefData(int size,
88 int family,
89 int style,
90 int weight,
91 bool underlined,
92 const wxString& faceName,
93 wxFontEncoding encoding)
94 : m_fontId(0)
95 , m_pointSize(size)
96 , m_family(family)
97 , m_style(style)
98 , m_weight(weight)
99 , m_underlined(underlined)
100 , m_faceName(faceName)
101 , m_encoding(encoding)
6239ee05
SC
102#ifdef __LP64__
103#else
2a0155df 104 , m_macFontFamily(0)
3bf5a59b
VZ
105 , m_macFontSize(0)
106 , m_macFontStyle(0)
e369bddb 107 , m_macATSUFontID(0)
6239ee05
SC
108#endif
109 , m_macATSUStyle(0)
3bf5a59b
VZ
110 {
111 Init(size, family, style, weight, underlined, faceName, encoding);
112 }
113
114 virtual ~wxFontRefData();
6eaa4426
DS
115
116 void SetNoAntiAliasing( bool no = true )
117 { m_noAA = no; }
118
119 bool GetNoAntiAliasing() const
120 { return m_noAA; }
121
2a0155df 122 void MacFindFont();
6eaa4426 123
3bf5a59b
VZ
124protected:
125 // common part of all ctors
126 void Init(int size,
127 int family,
128 int style,
129 int weight,
130 bool underlined,
131 const wxString& faceName,
132 wxFontEncoding encoding);
133
134 // font characterstics
e369bddb
GD
135 int m_fontId;
136 int m_pointSize;
137 int m_family;
138 int m_style;
139 int m_weight;
140 bool m_underlined;
141 wxString m_faceName;
142 wxFontEncoding m_encoding;
3bf5a59b 143 bool m_noAA; // No anti-aliasing
6eaa4426 144
3bf5a59b 145public:
6239ee05 146#ifndef __LP64__
2a0155df
SC
147 FMFontFamily m_macFontFamily;
148 FMFontSize m_macFontSize;
149 FMFontStyle m_macFontStyle;
6eaa4426 150
facd6764 151 // ATSU Font Information
6eaa4426 152
3103e8a9 153 // this is split into an ATSU font id that may
facd6764
SC
154 // contain some styles (special bold fonts etc) and
155 // these are the additional qd styles that are not
156 // included in the ATSU font id
157 ATSUFontID m_macATSUFontID;
2a0155df 158 FMFontStyle m_macATSUAdditionalQDStyles ;
6eaa4426 159
facd6764
SC
160 // for true themeing support we must store the correct font
161 // information here, as this speeds up and optimizes rendering
162 ThemeFontID m_macThemeFontID ;
6239ee05
SC
163#else
164 CTFontRef m_macFontRef;
165 CTFontUIFontType m_macUIFontType;
166#endif
167 ATSUStyle m_macATSUStyle ;
6eaa4426 168 wxNativeFontInfo m_info;
3bf5a59b 169};
6eaa4426 170
68c95704 171#define M_FONTDATA ((wxFontRefData*)m_refData)
873fd4af 172
6eaa4426 173
e7549107
SC
174// ============================================================================
175// implementation
176// ============================================================================
177
178// ----------------------------------------------------------------------------
179// wxFontRefData
180// ----------------------------------------------------------------------------
181
182void wxFontRefData::Init(int pointSize,
6eaa4426
DS
183 int family,
184 int style,
185 int weight,
186 bool underlined,
187 const wxString& faceName,
188 wxFontEncoding encoding)
e9576ca5 189{
e7549107
SC
190 m_style = style;
191 m_pointSize = pointSize;
192 m_family = family;
193 m_style = style;
194 m_weight = weight;
195 m_underlined = underlined;
196 m_faceName = faceName;
197 m_encoding = encoding;
6239ee05
SC
198#ifdef __LP64__
199 m_macUIFontType = kCTFontNoFontType;
200 m_macFontRef = 0;
201#else
2a0155df 202 m_macFontFamily = 0 ;
d84afea9
GD
203 m_macFontSize = 0;
204 m_macFontStyle = 0;
facd6764
SC
205 m_macATSUFontID = 0;
206 m_macATSUAdditionalQDStyles = 0 ;
6eaa4426 207
facd6764 208 m_macThemeFontID = kThemeCurrentPortFont ;
6239ee05
SC
209#endif
210 m_macATSUStyle = NULL ;
6eaa4426 211 m_noAA = false;
e9576ca5
SC
212}
213
214wxFontRefData::~wxFontRefData()
215{
3e527073
SC
216 if ( m_macATSUStyle )
217 {
218 ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle);
219 m_macATSUStyle = NULL ;
220 }
e9576ca5
SC
221}
222
519cb848
SC
223void wxFontRefData::MacFindFont()
224{
6239ee05 225 OSStatus status = noErr;
2a0155df 226 Str255 qdFontName ;
6239ee05
SC
227
228#ifdef __LP64__
229 if ( m_faceName.empty() && m_family == wxDEFAULT )
230 {
231 m_macUIFontType = kCTFontSystemFontType;
232 }
233
234 if ( m_macUIFontType != kCTFontNoFontType )
235 {
236 m_macFontRef = CTFontCreateUIFontForLanguage( m_macUIFontType, 0.0, NULL );
237 wxMacCFStringHolder name( CTFontCopyFamilyName( m_macFontRef ) );
238 m_faceName = name.AsString();
239 }
240 else
241 {
242 if ( m_faceName.empty() )
243 {
244 switch ( m_family )
245 {
246 case wxSCRIPT :
247 case wxROMAN :
248 case wxDECORATIVE :
249 m_faceName = wxT("Times");
250 break ;
251
252 case wxSWISS :
253 m_faceName = wxT("Lucida Grande");
254 break ;
255
256 case wxMODERN :
257 case wxTELETYPE:
258 m_faceName = wxT("Monaco");
259 break ;
260
261 default:
262 m_faceName = wxT("Times");
263 break ;
264 }
265 }
266
267 wxMacCFStringHolder cf( m_faceName, wxLocale::GetSystemEncoding() );
268 m_macFontRef = CTFontCreateWithName( cf, m_pointSize, NULL);
269 }
270
271 if ( m_macATSUStyle )
272 {
273 ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle);
274 m_macATSUStyle = NULL ;
275 }
276
277 status = ::ATSUCreateStyle((ATSUStyle *)&m_macATSUStyle);
278 wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") );
279
280 ATSUAttributeTag atsuTags[] =
281 {
282 kATSUSizeTag ,
283 kATSUVerticalCharacterTag,
284 kATSUQDBoldfaceTag ,
285 kATSUQDItalicTag ,
286 kATSUQDUnderlineTag ,
287 kATSUQDCondensedTag ,
288 kATSUQDExtendedTag ,
289 kATSUFontTag ,
290 };
291 ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
292 {
293 sizeof( Fixed ) ,
294 sizeof( ATSUVerticalCharacterType),
295 sizeof( Boolean ) ,
296 sizeof( Boolean ) ,
297 sizeof( Boolean ) ,
298 sizeof( Boolean ) ,
299 sizeof( Boolean ) ,
300 sizeof( ATSUFontID ) ,
301 };
302
303 Boolean kTrue = true ;
304 Boolean kFalse = false ;
305
306 Fixed atsuSize = IntToFixed( m_pointSize );
307 short m_macATSUAdditionalQDStyles = 0;
308 ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
309 ATSUFontID atsuFontID = 0;
310 int attributeCount = sizeof(atsuTags) / sizeof(ATSUAttributeTag) ;
311
312 // attempt to add atsu font
1bd568fa 313#if 0
6239ee05
SC
314 status = ATSUFindFontFromName(m_faceName.c_str(), strlen(m_faceName.c_str()), kFontFamilyName, kFontNoPlatform, kFontNoScript, kFontNoLanguage, &atsuFontID);
315 if ( status != noErr )
316 {
317 attributeCount--;
318 }
1bd568fa 319#endif
6239ee05
SC
320 ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
321 {
322 &atsuSize ,
323 &kHorizontal,
324 (m_macATSUAdditionalQDStyles & bold) ? &kTrue : &kFalse ,
325 (m_macATSUAdditionalQDStyles & italic) ? &kTrue : &kFalse ,
326 (m_macATSUAdditionalQDStyles & underline) ? &kTrue : &kFalse ,
327 (m_macATSUAdditionalQDStyles & condense) ? &kTrue : &kFalse ,
328 (m_macATSUAdditionalQDStyles & extend) ? &kTrue : &kFalse ,
329 &atsuFontID ,
330 };
331
332 status = ::ATSUSetAttributes( (ATSUStyle)m_macATSUStyle, attributeCount, atsuTags, atsuSizes, atsuValues);
333
334 wxASSERT_MSG( status == noErr , wxT("couldn't modify ATSU style") );
335#else
6eaa4426 336 if ( m_macThemeFontID != kThemeCurrentPortFont )
e40298d5 337 {
2a0155df
SC
338 Style style ;
339 GetThemeFont( m_macThemeFontID, GetApplicationScript(), qdFontName, &m_macFontSize, &style );
340 m_macFontStyle = style ;
341 m_faceName = wxMacMakeStringFromPascal( qdFontName );
facd6764
SC
342 if ( m_macFontStyle & bold )
343 m_weight = wxBOLD ;
344 else
345 m_weight = wxNORMAL ;
346 if ( m_macFontStyle & italic )
347 m_style = wxITALIC ;
348 if ( m_macFontStyle & underline )
349 m_underlined = true ;
facd6764 350 m_pointSize = m_macFontSize ;
2a0155df 351 m_macFontFamily = FMGetFontFamilyFromName( qdFontName );
e40298d5
JS
352 }
353 else
354 {
df91131c 355 if ( m_faceName.empty() )
facd6764 356 {
2a0155df 357 if ( m_family == wxDEFAULT )
facd6764 358 {
2a0155df
SC
359 m_macFontFamily = GetAppFont();
360 FMGetFontFamilyName(m_macFontFamily,qdFontName);
361 m_faceName = wxMacMakeStringFromPascal( qdFontName );
362 }
363 else
364 {
365 switch ( m_family )
366 {
367 case wxSCRIPT :
368 case wxROMAN :
369 case wxDECORATIVE :
370 m_faceName = wxT("Times");
371 break ;
372
373 case wxSWISS :
374 m_faceName = wxT("Lucida Grande");
375 break ;
376
377 case wxMODERN :
d9485f89 378 case wxTELETYPE:
2a0155df
SC
379 m_faceName = wxT("Monaco");
380 break ;
381
382 default:
383 m_faceName = wxT("Times");
384 break ;
385 }
386 wxMacStringToPascal( m_faceName , qdFontName );
387 m_macFontFamily = FMGetFontFamilyFromName( qdFontName );
dedf5d9f
SC
388 if ( m_macFontFamily == kInvalidFontFamily )
389 {
f08b7bec 390 wxLogDebug( wxT("ATSFontFamilyFindFromName failed for %s"), m_faceName.c_str() );
dedf5d9f
SC
391 m_macFontFamily = GetAppFont();
392 }
facd6764 393 }
facd6764 394 }
e40298d5
JS
395 else
396 {
facd6764 397 if ( m_faceName == wxT("systemfont") )
2a0155df 398 m_macFontFamily = GetSysFont();
facd6764 399 else if ( m_faceName == wxT("applicationfont") )
2a0155df 400 m_macFontFamily = GetAppFont();
facd6764
SC
401 else
402 {
2a0155df
SC
403 wxMacCFStringHolder cf( m_faceName, wxLocale::GetSystemEncoding() );
404 ATSFontFamilyRef atsfamily = ATSFontFamilyFindFromName( cf , kATSOptionFlagsDefault );
6239ee05 405 if ( atsfamily == (ATSFontFamilyRef) -1 )
dedf5d9f 406 {
5d2ad2f1 407 wxLogDebug( wxT("ATSFontFamilyFindFromName failed for ") + m_faceName );
dedf5d9f
SC
408 m_macFontFamily = GetAppFont();
409 }
410 else
411 m_macFontFamily = FMGetFontFamilyFromATSFontFamilyRef( atsfamily );
facd6764 412 }
e40298d5 413 }
facd6764
SC
414
415 m_macFontStyle = 0;
416 if (m_weight == wxBOLD)
417 m_macFontStyle |= bold;
6eaa4426 418 if (m_style == wxITALIC || m_style == wxSLANT)
facd6764 419 m_macFontStyle |= italic;
6eaa4426 420 if (m_underlined)
facd6764
SC
421 m_macFontStyle |= underline;
422 m_macFontSize = m_pointSize ;
e40298d5
JS
423 }
424
facd6764 425 // we try to get as much styles as possible into ATSU
3e527073 426
6eaa4426 427
2a0155df
SC
428 // ATSUFontID and FMFont are equivalent
429 FMFontStyle intrinsicStyle = 0 ;
430 status = FMGetFontFromFontFamilyInstance( m_macFontFamily , m_macFontStyle , &m_macATSUFontID , &intrinsicStyle);
431 wxASSERT_MSG( status == noErr , wxT("couldn't get an ATSUFont from font family") );
2a0155df 432 m_macATSUAdditionalQDStyles = m_macFontStyle & (~intrinsicStyle );
de6185e2 433
3e527073
SC
434 if ( m_macATSUStyle )
435 {
436 ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle);
437 m_macATSUStyle = NULL ;
438 }
6eaa4426 439
2a0155df
SC
440 status = ::ATSUCreateStyle((ATSUStyle *)&m_macATSUStyle);
441 wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") );
6eaa4426 442
3e527073
SC
443 ATSUAttributeTag atsuTags[] =
444 {
2a0155df
SC
445 kATSUFontTag ,
446 kATSUSizeTag ,
447 kATSUVerticalCharacterTag,
448 kATSUQDBoldfaceTag ,
449 kATSUQDItalicTag ,
450 kATSUQDUnderlineTag ,
451 kATSUQDCondensedTag ,
452 kATSUQDExtendedTag ,
6eaa4426
DS
453 };
454 ByteCount atsuSizes[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
3e527073 455 {
2a0155df
SC
456 sizeof( ATSUFontID ) ,
457 sizeof( Fixed ) ,
458 sizeof( ATSUVerticalCharacterType),
459 sizeof( Boolean ) ,
460 sizeof( Boolean ) ,
461 sizeof( Boolean ) ,
462 sizeof( Boolean ) ,
463 sizeof( Boolean ) ,
6eaa4426
DS
464 };
465
3e527073
SC
466 Boolean kTrue = true ;
467 Boolean kFalse = false ;
468
2a0155df 469 Fixed atsuSize = IntToFixed( m_macFontSize );
3e527073 470 ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
6eaa4426 471 ATSUAttributeValuePtr atsuValues[sizeof(atsuTags) / sizeof(ATSUAttributeTag)] =
3e527073
SC
472 {
473 &m_macATSUFontID ,
474 &atsuSize ,
475 &kHorizontal,
476 (m_macATSUAdditionalQDStyles & bold) ? &kTrue : &kFalse ,
477 (m_macATSUAdditionalQDStyles & italic) ? &kTrue : &kFalse ,
478 (m_macATSUAdditionalQDStyles & underline) ? &kTrue : &kFalse ,
479 (m_macATSUAdditionalQDStyles & condense) ? &kTrue : &kFalse ,
480 (m_macATSUAdditionalQDStyles & extend) ? &kTrue : &kFalse ,
6eaa4426
DS
481 };
482
483 status = ::ATSUSetAttributes(
484 (ATSUStyle)m_macATSUStyle,
485 sizeof(atsuTags) / sizeof(ATSUAttributeTag) ,
3e527073
SC
486 atsuTags, atsuSizes, atsuValues);
487
2a0155df 488 wxASSERT_MSG( status == noErr , wxT("couldn't modify ATSU style") );
6239ee05 489#endif
519cb848
SC
490}
491
e7549107
SC
492// ----------------------------------------------------------------------------
493// wxFont
494// ----------------------------------------------------------------------------
e9576ca5 495
5b781a67
SC
496bool wxFont::Create(const wxNativeFontInfo& info)
497{
6eaa4426
DS
498 return Create(
499 info.pointSize, info.family, info.style, info.weight,
500 info.underlined, info.faceName, info.encoding );
5b781a67
SC
501}
502
3b7e6277
GD
503wxFont::wxFont(const wxString& fontdesc)
504{
505 wxNativeFontInfo info;
506 if ( info.FromString(fontdesc) )
507 (void)Create(info);
508}
509
e7549107 510bool wxFont::Create(int pointSize,
6eaa4426
DS
511 int family,
512 int style,
513 int weight,
514 bool underlined,
515 const wxString& faceName,
516 wxFontEncoding encoding)
e9576ca5
SC
517{
518 UnRef();
6eaa4426
DS
519
520 m_refData = new wxFontRefData(
521 pointSize, family, style, weight,
522 underlined, faceName, encoding);
e9576ca5
SC
523
524 RealizeResource();
525
6eaa4426 526 return true;
e9576ca5
SC
527}
528
6239ee05
SC
529#ifdef __LP64__
530
531bool wxFont::MacCreateUIFont(wxUint32 ctFontType )
532{
533 UnRef();
534
535 m_refData = new wxFontRefData(
536 12, wxDEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL,
537 false, wxEmptyString, wxFONTENCODING_DEFAULT );
538
539 M_FONTDATA->m_macUIFontType = ctFontType ;
540 RealizeResource();
541
542 return true;
543}
544
545#endif
546
6eaa4426 547bool wxFont::MacCreateThemeFont(wxUint16 themeFontID)
facd6764 548{
6239ee05
SC
549#ifdef __LP64__
550 return MacCreateUIFont(HIThemeGetUIFontType(themeFontID));
551#else
facd6764 552 UnRef();
6eaa4426
DS
553
554 m_refData = new wxFontRefData(
555 12, wxDEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL,
556 false, wxEmptyString, wxFONTENCODING_DEFAULT );
557
facd6764
SC
558 M_FONTDATA->m_macThemeFontID = themeFontID ;
559 RealizeResource();
560
6eaa4426 561 return true;
6239ee05 562#endif
facd6764
SC
563}
564
e9576ca5
SC
565wxFont::~wxFont()
566{
e9576ca5
SC
567}
568
569bool wxFont::RealizeResource()
570{
2a0155df 571 M_FONTDATA->MacFindFont();
6eaa4426
DS
572
573 return true;
e9576ca5
SC
574}
575
51abe921
SC
576void wxFont::SetEncoding(wxFontEncoding encoding)
577{
83dcd781 578 Unshare();
51abe921
SC
579
580 M_FONTDATA->m_encoding = encoding;
581
582 RealizeResource();
583}
584
83dcd781 585void wxFont::Unshare()
e9576ca5 586{
83dcd781
PC
587 // Don't change shared data
588 if (!m_refData)
589 {
590 m_refData = new wxFontRefData();
591 }
592 else
593 {
594 wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
595 UnRef();
596 m_refData = ref;
597 }
e9576ca5
SC
598}
599
600void wxFont::SetPointSize(int pointSize)
601{
83dcd781 602 Unshare();
e9576ca5
SC
603
604 M_FONTDATA->m_pointSize = pointSize;
605
606 RealizeResource();
607}
608
609void wxFont::SetFamily(int family)
610{
83dcd781 611 Unshare();
e9576ca5
SC
612
613 M_FONTDATA->m_family = family;
614
615 RealizeResource();
616}
617
618void wxFont::SetStyle(int style)
619{
83dcd781 620 Unshare();
e9576ca5
SC
621
622 M_FONTDATA->m_style = style;
623
624 RealizeResource();
625}
626
627void wxFont::SetWeight(int weight)
628{
83dcd781 629 Unshare();
e9576ca5
SC
630
631 M_FONTDATA->m_weight = weight;
632
633 RealizeResource();
634}
635
85ab460e 636bool wxFont::SetFaceName(const wxString& faceName)
e9576ca5 637{
83dcd781 638 Unshare();
e9576ca5
SC
639
640 M_FONTDATA->m_faceName = faceName;
641
642 RealizeResource();
85ab460e
VZ
643
644 return wxFontBase::SetFaceName(faceName);
e9576ca5
SC
645}
646
647void wxFont::SetUnderlined(bool underlined)
648{
83dcd781 649 Unshare();
e9576ca5
SC
650
651 M_FONTDATA->m_underlined = underlined;
652
653 RealizeResource();
654}
655
ac17f9b1
SC
656void wxFont::SetNoAntiAliasing( bool no )
657{
83dcd781 658 Unshare();
ac17f9b1
SC
659
660 M_FONTDATA->SetNoAntiAliasing( no );
661
662 RealizeResource();
663}
664
e7549107
SC
665// ----------------------------------------------------------------------------
666// accessors
667// ----------------------------------------------------------------------------
668
fcb35beb
VZ
669// TODO: insert checks everywhere for M_FONTDATA == NULL!
670
e7549107 671int wxFont::GetPointSize() const
e9576ca5 672{
77eddfb7 673 wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
6eaa4426 674
e7549107 675 return M_FONTDATA->m_pointSize;
e9576ca5
SC
676}
677
ccd67a6a
KO
678wxSize wxFont::GetPixelSize() const
679{
680#if wxUSE_GRAPHICS_CONTEXT
681 // TODO: consider caching the value
682 wxGraphicsContext* dc = wxGraphicsContext::CreateFromNative((CGContextRef) NULL);
40503c98 683 dc->SetFont(*(wxFont *)this,*wxBLACK);
ccd67a6a 684 wxDouble width, height = 0;
8a438f46 685 dc->GetTextExtent( wxT("g"), &width, &height, NULL, NULL);
6239ee05 686 delete dc;
8a438f46 687 return wxSize((int)width, (int)height);
ccd67a6a 688#else
5d465013 689 return wxFontBase::GetPixelSize();
ccd67a6a
KO
690#endif
691}
692
e7549107 693int wxFont::GetFamily() const
e9576ca5 694{
77eddfb7 695 wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
6eaa4426 696
e7549107 697 return M_FONTDATA->m_family;
e9576ca5
SC
698}
699
e7549107 700int wxFont::GetStyle() const
e9576ca5 701{
77eddfb7 702 wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
6eaa4426 703
e7549107
SC
704 return M_FONTDATA->m_style;
705}
706
707int wxFont::GetWeight() const
708{
77eddfb7 709 wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
6eaa4426 710
e7549107
SC
711 return M_FONTDATA->m_weight;
712}
713
714bool wxFont::GetUnderlined() const
715{
77eddfb7 716 wxCHECK_MSG( M_FONTDATA != NULL , false, wxT("invalid font") );
6eaa4426 717
e7549107
SC
718 return M_FONTDATA->m_underlined;
719}
720
721wxString wxFont::GetFaceName() const
722{
facd6764 723 wxCHECK_MSG( M_FONTDATA != NULL , wxEmptyString , wxT("invalid font") );
6eaa4426 724
facd6764 725 return M_FONTDATA->m_faceName;
e7549107
SC
726}
727
728wxFontEncoding wxFont::GetEncoding() const
729{
facd6764 730 wxCHECK_MSG( M_FONTDATA != NULL , wxFONTENCODING_DEFAULT , wxT("invalid font") );
6eaa4426 731
e7549107 732 return M_FONTDATA->m_encoding;
e9576ca5
SC
733}
734
5ac2e80c 735bool wxFont::GetNoAntiAliasing() const
ac17f9b1 736{
77eddfb7 737 wxCHECK_MSG( M_FONTDATA != NULL , false, wxT("invalid font") );
6eaa4426 738
ac17f9b1
SC
739 return M_FONTDATA->m_noAA;
740}
741
6239ee05
SC
742#ifndef __LP64__
743
facd6764 744short wxFont::MacGetFontNum() const
fcb35beb 745{
77eddfb7 746 wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
6eaa4426 747
2a0155df 748 return M_FONTDATA->m_macFontFamily;
fcb35beb
VZ
749}
750
facd6764 751short wxFont::MacGetFontSize() const
fcb35beb 752{
77eddfb7 753 wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
6eaa4426 754
fcb35beb
VZ
755 return M_FONTDATA->m_macFontSize;
756}
757
facd6764 758wxByte wxFont::MacGetFontStyle() const
fcb35beb 759{
77eddfb7 760 wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
6eaa4426 761
fcb35beb
VZ
762 return M_FONTDATA->m_macFontStyle;
763}
764
facd6764 765wxUint32 wxFont::MacGetATSUFontID() const
fcb35beb 766{
77eddfb7 767 wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
6eaa4426 768
fcb35beb
VZ
769 return M_FONTDATA->m_macATSUFontID;
770}
771
6eaa4426 772void * wxFont::MacGetATSUStyle() const
3e527073
SC
773{
774 wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") );
6eaa4426 775
3e527073
SC
776 return M_FONTDATA->m_macATSUStyle;
777}
778
facd6764
SC
779wxUint32 wxFont::MacGetATSUAdditionalQDStyles() const
780{
77eddfb7 781 wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
6eaa4426 782
facd6764
SC
783 return M_FONTDATA->m_macATSUAdditionalQDStyles;
784}
785
6eaa4426 786wxUint16 wxFont::MacGetThemeFontID() const
facd6764 787{
77eddfb7 788 wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
6eaa4426 789
facd6764
SC
790 return M_FONTDATA->m_macThemeFontID;
791}
6239ee05
SC
792#else
793const void * wxFont::MacGetCTFont() const
794{
795 wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
796
797 return M_FONTDATA->m_macFontRef;
798}
799
800// to be removed
801void * wxFont::MacGetATSUStyle() const
802{
803 wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") );
804
805 return M_FONTDATA->m_macATSUStyle;
806}
807
808#endif
facd6764 809
6eaa4426 810const wxNativeFontInfo * wxFont::GetNativeFontInfo() const
3bf5a59b 811{
facd6764 812 wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") );
3bf5a59b
VZ
813 wxCHECK_MSG( Ok(), NULL, wxT("invalid font") );
814
815 M_FONTDATA->m_info.InitFromFont(*this);
816
817 return &(M_FONTDATA->m_info);
818}