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