]> git.saurik.com Git - wxWidgets.git/blame - src/osx/carbon/font.cpp
Improve mouse handling code in wxAuiToolBar.
[wxWidgets.git] / src / osx / carbon / font.cpp
CommitLineData
489468fe 1/////////////////////////////////////////////////////////////////////////////
524c47aa 2// Name: src/osx/carbon/font.cpp
489468fe
SC
3// Purpose: wxFont class
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#include "wx/font.h"
15
16#ifndef WX_PRECOMP
17 #include "wx/string.h"
18 #include "wx/utils.h"
19 #include "wx/intl.h"
20 #include "wx/gdicmn.h"
21 #include "wx/log.h"
22#endif
23
24#include "wx/fontutil.h"
25#include "wx/graphics.h"
26#include "wx/settings.h"
f1c40652 27#include "wx/tokenzr.h"
489468fe 28
b2680ced 29#include "wx/osx/private.h"
29e32b7f 30
489468fe
SC
31#include <map>
32#include <string>
33
34IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
35
489468fe
SC
36class WXDLLEXPORT wxFontRefData: public wxGDIRefData
37{
38public:
489468fe 39
f1c40652 40 wxFontRefData()
489468fe 41 {
f1c40652
SC
42 Init();
43 m_info.Init(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL,
44 false, wxEmptyString, wxFONTENCODING_DEFAULT);
489468fe
SC
45 }
46
f1c40652 47 wxFontRefData(const wxFontRefData& data);
03647350 48
f1c40652 49 wxFontRefData( const wxNativeFontInfo& info ) : m_info(info)
489468fe 50 {
f1c40652 51 Init();
489468fe
SC
52 }
53
f1c40652 54 wxFontRefData(wxOSXSystemFont font, int size);
03647350 55
292e5e1f 56#if wxOSX_USE_CORE_TEXT
489468fe
SC
57 wxFontRefData( wxUint32 coreTextFontType );
58 wxFontRefData( CTFontRef font );
59 wxFontRefData( CTFontDescriptorRef fontdescriptor, int size );
60#endif
61
62 virtual ~wxFontRefData();
63
489468fe
SC
64 void SetPointSize( int size )
65 {
f1c40652
SC
66 if( GetPointSize() != size )
67 {
68 m_info.SetPointSize(size);
69 Free();
70 }
489468fe
SC
71 }
72
f1c40652 73 int GetPointSize() const { return m_info.GetPointSize(); }
489468fe 74
0c14b6c3 75 void SetFamily( wxFontFamily family )
489468fe 76 {
f1c40652
SC
77 if ( m_info.m_family != family )
78 {
79 m_info.SetFamily( family );
80 Free();
81 }
489468fe
SC
82 }
83
f1c40652 84 wxFontFamily GetFamily() const { return m_info.GetFamily(); }
489468fe 85
0c14b6c3 86 void SetStyle( wxFontStyle style )
489468fe 87 {
f1c40652
SC
88 if ( m_info.m_style != style )
89 {
90 m_info.SetStyle( style );
91 Free();
92 }
489468fe
SC
93 }
94
95
f1c40652 96 wxFontStyle GetStyle() const { return m_info.GetStyle(); }
489468fe 97
0c14b6c3 98 void SetWeight( wxFontWeight weight )
489468fe 99 {
f1c40652
SC
100 if ( m_info.m_weight != weight )
101 {
102 m_info.SetWeight( weight );
103 Free();
104 }
489468fe
SC
105 }
106
107
f1c40652 108 wxFontWeight GetWeight() const { return m_info.GetWeight(); }
489468fe
SC
109
110 void SetUnderlined( bool u )
111 {
f1c40652
SC
112 if ( m_info.m_underlined != u )
113 {
114 m_info.SetUnderlined( u );
115 Free();
116 }
489468fe
SC
117 }
118
f1c40652 119 bool GetUnderlined() const { return m_info.GetUnderlined(); }
489468fe
SC
120
121 void SetFaceName( const wxString& facename )
122 {
f1c40652
SC
123 if ( m_info.m_faceName != facename )
124 {
125 m_info.SetFaceName( facename );
126 Free();
127 }
489468fe
SC
128 }
129
f1c40652 130 wxString GetFaceName() const { return m_info.GetFaceName(); }
489468fe
SC
131
132 void SetEncoding( wxFontEncoding encoding )
133 {
f1c40652
SC
134 if ( m_info.m_encoding != encoding )
135 {
136 m_info.SetEncoding( encoding );
137 Free();
138 }
489468fe
SC
139 }
140
f1c40652 141 wxFontEncoding GetEncoding() const { return m_info.GetEncoding(); }
489468fe 142
f1c40652 143 void Free();
489468fe
SC
144
145 void MacFindFont();
146
147protected:
148 // common part of all ctors
f1c40652 149 void Init();
292e5e1f 150#if wxOSX_USE_CORE_TEXT
f1c40652 151 // void Init( CTFontRef font );
489468fe 152#endif
489468fe 153public:
f1c40652
SC
154 bool m_fontValid;
155#if wxOSX_USE_CARBON && wxOSX_USE_ATSU_TEXT
b3b17ee7 156 // for true theming support we must store the correct font
489468fe
SC
157 // information here, as this speeds up and optimizes rendering
158 ThemeFontID m_macThemeFontID ;
159#endif
292e5e1f 160#if wxOSX_USE_CORE_TEXT
489468fe 161 wxCFRef<CTFontRef> m_ctFont;
489468fe 162#endif
beb2638a 163#if wxOSX_USE_ATSU_TEXT
03c28161
SC
164 void CreateATSUFont();
165
489468fe 166 ATSUStyle m_macATSUStyle ;
f1c40652 167#endif
9445de1e 168 wxCFRef<CGFontRef> m_cgFont;
f1c40652
SC
169#if wxOSX_USE_COCOA
170 WX_NSFont m_nsFont;
171#endif
172#if wxOSX_USE_IPHONE
173 WX_UIFont m_uiFont;
489468fe
SC
174#endif
175 wxNativeFontInfo m_info;
176};
177
178#define M_FONTDATA ((wxFontRefData*)m_refData)
179
f1c40652
SC
180wxFontRefData::wxFontRefData(const wxFontRefData& data)
181{
182 Init();
183 m_info = data.m_info;
f1c40652
SC
184 m_fontValid = data.m_fontValid;
185#if wxOSX_USE_CARBON && wxOSX_USE_ATSU_TEXT
186 m_macThemeFontID = data.m_macThemeFontID;
187#endif
188#if wxOSX_USE_CORE_TEXT
189 m_ctFont = data.m_ctFont;
03647350 190#endif
9445de1e 191 m_cgFont = data.m_cgFont;
beb2638a 192#if wxOSX_USE_ATSU_TEXT
f1c40652
SC
193 if ( data.m_macATSUStyle != NULL )
194 {
195 ATSUCreateStyle(&m_macATSUStyle) ;
196 ATSUCopyAttributes(data.m_macATSUStyle, m_macATSUStyle);
197 }
198#endif
199#if wxOSX_USE_COCOA
200 m_nsFont = (NSFont*) wxMacCocoaRetain(data.m_nsFont);
201#endif
202#if wxOSX_USE_IPHONE
b4ff8b3e 203 m_uiFont = (UIFont*) wxMacCocoaRetain(data.m_uiFont);
f1c40652 204#endif
03647350 205
f1c40652 206}
489468fe
SC
207
208// ============================================================================
209// implementation
210// ============================================================================
211
212// ----------------------------------------------------------------------------
213// wxFontRefData
214// ----------------------------------------------------------------------------
215
f1c40652 216void wxFontRefData::Init()
489468fe 217{
f1c40652 218#if wxOSX_USE_CARBON && wxOSX_USE_ATSU_TEXT
489468fe
SC
219 m_macThemeFontID = kThemeCurrentPortFont ;
220#endif
beb2638a 221#if wxOSX_USE_ATSU_TEXT
489468fe
SC
222 m_macATSUStyle = NULL ;
223#endif
f1c40652
SC
224#if wxOSX_USE_COCOA
225 m_nsFont = NULL;
226#endif
227#if wxOSX_USE_IPHONE
228 m_uiFont = NULL;
229#endif
230 m_fontValid = false;
489468fe
SC
231}
232
233wxFontRefData::~wxFontRefData()
234{
f1c40652 235 Free();
489468fe
SC
236}
237
f1c40652 238void wxFontRefData::Free()
489468fe 239{
292e5e1f 240#if wxOSX_USE_CORE_TEXT
489468fe 241 m_ctFont.reset();
489468fe 242#endif
9445de1e 243 m_cgFont.reset();
beb2638a 244#if wxOSX_USE_ATSU_TEXT
9581362b
SC
245#if wxOSX_USE_CARBON
246 m_macThemeFontID = kThemeCurrentPortFont ;
247#endif
489468fe
SC
248 if ( m_macATSUStyle )
249 {
250 ::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle);
251 m_macATSUStyle = NULL ;
252 }
253#endif
f1c40652
SC
254#if wxOSX_USE_COCOA
255 if (m_nsFont != NULL)
256 {
257 wxMacCocoaRelease(m_nsFont);
258 m_nsFont = NULL;
489468fe 259 }
f1c40652
SC
260#endif
261#if wxOSX_USE_IPHONE
262 if (m_uiFont != NULL)
489468fe 263 {
f1c40652
SC
264 wxMacCocoaRelease(m_uiFont);
265 m_uiFont = NULL;
489468fe 266 }
f1c40652
SC
267#endif
268 m_fontValid = false;
489468fe
SC
269}
270
f1c40652 271wxFontRefData::wxFontRefData(wxOSXSystemFont font, int size)
489468fe 272{
f1c40652
SC
273 wxASSERT( font != wxOSX_SYSTEM_FONT_NONE );
274 Init();
03647350 275
f1c40652
SC
276#if wxOSX_USE_CORE_TEXT
277 if ( UMAGetSystemVersion() >= 0x1050 )
489468fe 278 {
de0d2095 279 CTFontUIFontType uifont = kCTFontSystemFontType;
f1c40652 280 switch( font )
489468fe 281 {
f1c40652
SC
282 case wxOSX_SYSTEM_FONT_NORMAL:
283 uifont = kCTFontSystemFontType;
284 break;
285 case wxOSX_SYSTEM_FONT_BOLD:
286 uifont = kCTFontEmphasizedSystemFontType;
287 break;
288 case wxOSX_SYSTEM_FONT_SMALL:
289 uifont = kCTFontSmallSystemFontType;
290 break;
291 case wxOSX_SYSTEM_FONT_SMALL_BOLD:
292 uifont = kCTFontSmallEmphasizedSystemFontType;
293 break;
294 case wxOSX_SYSTEM_FONT_MINI:
295 uifont = kCTFontMiniSystemFontType;
296 break;
297 case wxOSX_SYSTEM_FONT_MINI_BOLD:
298 uifont = kCTFontMiniEmphasizedSystemFontType;
299 break;
300 case wxOSX_SYSTEM_FONT_LABELS:
301 uifont = kCTFontLabelFontType;
302 break;
303 case wxOSX_SYSTEM_FONT_VIEWS:
304 uifont = kCTFontViewsFontType;
305 break;
306 default:
307 break;
489468fe 308 }
f1c40652
SC
309 m_ctFont.reset(CTFontCreateUIFontForLanguage( uifont, (CGFloat) size, NULL ));
310 wxCFRef<CTFontDescriptorRef> descr;
311 descr.reset( CTFontCopyFontDescriptor( m_ctFont ) );
312 m_info.Init(descr);
313 }
314#endif
315#if wxOSX_USE_ATSU_TEXT
316 {
9a672c75
SC
317#if !wxOSX_USE_CARBON
318 // not needed outside
de0d2095 319 ThemeFontID m_macThemeFontID = kThemeSystemFont;
9a672c75 320#endif
f1c40652
SC
321 switch( font )
322 {
323 case wxOSX_SYSTEM_FONT_NORMAL:
324 m_macThemeFontID = kThemeSystemFont;
325 break;
326 case wxOSX_SYSTEM_FONT_BOLD:
327 m_macThemeFontID = kThemeEmphasizedSystemFont;
328 break;
329 case wxOSX_SYSTEM_FONT_SMALL:
330 m_macThemeFontID = kThemeSmallSystemFont;
331 break;
332 case wxOSX_SYSTEM_FONT_SMALL_BOLD:
333 m_macThemeFontID = kThemeSmallEmphasizedSystemFont;
334 break;
335 case wxOSX_SYSTEM_FONT_MINI:
336 m_macThemeFontID = kThemeMiniSystemFont;
337 break;
338 case wxOSX_SYSTEM_FONT_MINI_BOLD:
b3b17ee7 339 // bold not available under theming
f1c40652
SC
340 m_macThemeFontID = kThemeMiniSystemFont;
341 break;
342 case wxOSX_SYSTEM_FONT_LABELS:
343 m_macThemeFontID = kThemeLabelFont;
344 break;
345 case wxOSX_SYSTEM_FONT_VIEWS:
346 m_macThemeFontID = kThemeViewsFont;
347 break;
348 default:
03647350 349 break;
f1c40652
SC
350 }
351 if ( m_info.m_faceName.empty() )
352 {
353 Style style ;
354 FMFontSize fontSize;
355 Str255 qdFontName ;
03647350 356
f1c40652
SC
357 GetThemeFont( m_macThemeFontID, GetApplicationScript(), qdFontName, &fontSize, &style );
358 if ( size != 0 )
359 fontSize = size;
360
361 wxFontStyle fontstyle = wxFONTSTYLE_NORMAL;
362 wxFontWeight fontweight = wxFONTWEIGHT_NORMAL;
363 bool underlined = false;
03647350 364
f1c40652
SC
365 if ( style & bold )
366 fontweight = wxFONTWEIGHT_BOLD ;
367 else
368 fontweight = wxFONTWEIGHT_NORMAL ;
369 if ( style & italic )
370 fontstyle = wxFONTSTYLE_ITALIC ;
371 if ( style & underline )
372 underlined = true ;
03647350 373
2ff0354a 374 m_info.Init(fontSize,wxFONTFAMILY_DEFAULT,fontstyle,fontweight,underlined,
f1c40652
SC
375 wxMacMakeStringFromPascal( qdFontName ), wxFONTENCODING_DEFAULT);
376 }
489468fe 377 }
489468fe 378#endif
f1c40652 379#if wxOSX_USE_COCOA
aa6208d9 380 m_nsFont = wxFont::OSXCreateNSFont( font, &m_info );
f1c40652
SC
381#endif
382#if wxOSX_USE_IPHONE
aa6208d9 383 m_uiFont = wxFont::OSXCreateUIFont( font, &m_info );
f1c40652 384#endif
03c28161
SC
385 m_info.EnsureValid();
386#if wxOSX_USE_ATSU_TEXT
387 CreateATSUFont();
388#endif
389
390 m_fontValid = true;
f1c40652 391}
489468fe 392
03c28161
SC
393#if wxOSX_USE_ATSU_TEXT
394void wxFontRefData::CreateATSUFont()
395{
396 // we try to get as much styles as possible into ATSU
397
398 OSStatus status = ::ATSUCreateStyle(&m_macATSUStyle);
399 wxASSERT_MSG( status == noErr , wxT("couldn't create ATSU style") );
400
401 ATSUAttributeTag atsuTags[] =
402 {
403 kATSUFontTag ,
404 kATSUSizeTag ,
405 kATSUVerticalCharacterTag,
406 kATSUQDBoldfaceTag ,
407 kATSUQDItalicTag ,
408 kATSUQDUnderlineTag ,
409 kATSUQDCondensedTag ,
410 kATSUQDExtendedTag ,
411 };
412 ByteCount atsuSizes[WXSIZEOF(atsuTags)] =
413 {
414 sizeof( ATSUFontID ) ,
415 sizeof( Fixed ) ,
416 sizeof( ATSUVerticalCharacterType),
417 sizeof( Boolean ) ,
418 sizeof( Boolean ) ,
419 sizeof( Boolean ) ,
420 sizeof( Boolean ) ,
421 sizeof( Boolean ) ,
422 };
423
424 Boolean kTrue = true ;
425 Boolean kFalse = false ;
426
427 Fixed atsuSize = IntToFixed( m_info.m_pointSize );
428 ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
429 FMFontStyle addQDStyle = m_info.m_atsuAdditionalQDStyles;
430 ATSUAttributeValuePtr atsuValues[WXSIZEOF(atsuTags)] =
431 {
432 &m_info.m_atsuFontID ,
433 &atsuSize ,
434 &kHorizontal,
435 (addQDStyle & bold) ? &kTrue : &kFalse ,
436 (addQDStyle & italic) ? &kTrue : &kFalse ,
437 (addQDStyle & underline) ? &kTrue : &kFalse ,
438 (addQDStyle & condense) ? &kTrue : &kFalse ,
439 (addQDStyle & extend) ? &kTrue : &kFalse ,
440 };
441
442 status = ::ATSUSetAttributes(
443 (ATSUStyle)m_macATSUStyle,
444 WXSIZEOF(atsuTags),
445 atsuTags, atsuSizes, atsuValues);
446
447 wxASSERT_MSG( status == noErr , wxString::Format(wxT("couldn't modify ATSU style. Status was %d"), (int) status).c_str() );
448
449 if ( m_cgFont.get() == NULL )
450 {
451 ATSFontRef fontRef = FMGetATSFontRefFromFont(m_info.m_atsuFontID);
452 m_cgFont.reset( CGFontCreateWithPlatformFont( &fontRef ) );
453 }
454}
455#endif
456
d0a7d7b1
SC
457static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
458static const CGAffineTransform kSlantTransform = CGAffineTransformMake( 1, 0, tan(DegToRad(11)), 1, 0, 0 );
459
489468fe
SC
460void wxFontRefData::MacFindFont()
461{
f1c40652
SC
462 if ( m_fontValid )
463 return;
03647350 464
72912228
JS
465 wxCHECK_RET( m_info.m_pointSize > 0, wxT("Point size should not be zero.") );
466
f1c40652 467 m_info.EnsureValid();
03647350 468
292e5e1f 469#if wxOSX_USE_CORE_TEXT
489468fe
SC
470 if ( UMAGetSystemVersion() >= 0x1050 )
471 {
f1c40652 472 CTFontSymbolicTraits traits = 0;
0c14b6c3 473
f1c40652
SC
474 if (m_info.m_weight == wxFONTWEIGHT_BOLD)
475 traits |= kCTFontBoldTrait;
476 if (m_info.m_style == wxFONTSTYLE_ITALIC || m_info.m_style == wxFONTSTYLE_SLANT)
477 traits |= kCTFontItalicTrait;
489468fe 478
f1c40652 479 // use font caching
c2eb8938 480 wxString lookupnameWithSize = wxString::Format( "%s_%u_%d", m_info.m_faceName, traits, m_info.m_pointSize );
489468fe 481
f1c40652
SC
482 static std::map< std::wstring , wxCFRef< CTFontRef > > fontcache ;
483 m_ctFont = fontcache[ std::wstring(lookupnameWithSize.wc_str()) ];
484 if ( !m_ctFont )
489468fe 485 {
03c28161 486 m_ctFont.reset(CTFontCreateWithName( wxCFStringRef(m_info.m_faceName), m_info.m_pointSize , NULL ));
d0a7d7b1 487 if ( m_ctFont.get() == NULL )
03c28161 488 {
d0a7d7b1
SC
489 // TODO try fallbacks according to font type
490 m_ctFont.reset(CTFontCreateUIFontForLanguage( kCTFontSystemFontType, m_info.m_pointSize , NULL ));
491 }
492 else
493 {
494 if ( traits != 0 )
495 {
496 // attempt native font variant, if not available, fallback to italic emulation mode and remove bold
497 CTFontRef fontWithTraits = CTFontCreateCopyWithSymbolicTraits( m_ctFont, 0, NULL, traits, traits );
498 if ( fontWithTraits == NULL )
499 {
500 CTFontSymbolicTraits remainingTraits = traits;
501 const CGAffineTransform* remainingTransform = NULL;
502
503 if( remainingTraits & kCTFontItalicTrait )
504 {
505 remainingTraits &= ~kCTFontItalicTrait;
506 remainingTransform = &kSlantTransform;
507 if ( remainingTraits & kCTFontBoldTrait )
508 {
509 // first try an emulated oblique with an existing bold font
510 fontWithTraits = CTFontCreateCopyWithSymbolicTraits( m_ctFont, 0, remainingTransform, remainingTraits, remainingTraits );
511 if ( fontWithTraits == NULL )
512 {
513 // give in on the bold, try native oblique
514 fontWithTraits = CTFontCreateCopyWithSymbolicTraits( m_ctFont, 0, NULL, kCTFontItalicTrait, kCTFontItalicTrait );
515 }
516 }
517 }
518
519 if ( fontWithTraits == NULL )
520 {
521 fontWithTraits = CTFontCreateWithName( wxCFStringRef(m_info.m_faceName), m_info.m_pointSize, remainingTransform );
522 }
523
524 }
525 if ( fontWithTraits != NULL )
526 m_ctFont.reset(fontWithTraits);
527 }
03c28161 528 }
489468fe 529 }
03c28161 530
9445de1e 531 m_cgFont.reset(CTFontCopyGraphicsFont(m_ctFont, NULL));
489468fe 532 }
f1c40652 533
489468fe 534#endif
292e5e1f 535#if wxOSX_USE_ATSU_TEXT
03c28161 536 CreateATSUFont();
489468fe 537#endif
f1c40652 538#if wxOSX_USE_COCOA
aa6208d9 539 m_nsFont = wxFont::OSXCreateNSFont( &m_info );
f1c40652
SC
540#endif
541#if wxOSX_USE_IPHONE
aa6208d9 542 m_uiFont = wxFont::OSXCreateUIFont( &m_info );
f1c40652
SC
543#endif
544 m_fontValid = true;
489468fe
SC
545}
546
547// ----------------------------------------------------------------------------
548// wxFont
549// ----------------------------------------------------------------------------
550
551bool wxFont::Create(const wxNativeFontInfo& info)
552{
f1c40652 553 UnRef();
03647350 554
f1c40652
SC
555 m_refData = new wxFontRefData( info );
556 RealizeResource();
03647350 557
f1c40652 558 return true;
489468fe
SC
559}
560
7eb8aeb8
SC
561wxFont::wxFont(wxOSXSystemFont font)
562{
563 m_refData = new wxFontRefData( font, 0 );
564}
565
489468fe
SC
566wxFont::wxFont(const wxString& fontdesc)
567{
568 wxNativeFontInfo info;
569 if ( info.FromString(fontdesc) )
570 (void)Create(info);
571}
572
573bool wxFont::Create(int pointSize,
0c14b6c3
FM
574 wxFontFamily family,
575 wxFontStyle style,
576 wxFontWeight weight,
577 bool underlined,
f1c40652 578 const wxString& faceNameParam,
0c14b6c3 579 wxFontEncoding encoding)
489468fe
SC
580{
581 UnRef();
03647350 582
f1c40652 583 wxString faceName = faceNameParam;
489468fe 584
f1c40652
SC
585 if ( faceName.empty() )
586 {
587 switch ( family )
588 {
589 case wxFONTFAMILY_DEFAULT :
590 faceName = wxT("Lucida Grande");
591 break;
03647350 592
f1c40652
SC
593 case wxFONTFAMILY_SCRIPT :
594 case wxFONTFAMILY_ROMAN :
595 case wxFONTFAMILY_DECORATIVE :
596 faceName = wxT("Times");
597 break ;
598
599 case wxFONTFAMILY_SWISS :
600 faceName = wxT("Helvetica");
601 break ;
602
603 case wxFONTFAMILY_MODERN :
604 case wxFONTFAMILY_TELETYPE:
605 faceName = wxT("Courier");
606 break ;
607
608 default:
609 faceName = wxT("Times");
610 break ;
611 }
612 }
03647350 613
f1c40652 614 wxNativeFontInfo info;
03647350 615
f1c40652 616 info.Init(pointSize, family, style, weight,
489468fe
SC
617 underlined, faceName, encoding);
618
f1c40652 619 m_refData = new wxFontRefData(info);
489468fe
SC
620
621 return true;
622}
623
f1c40652 624wxFont::~wxFont()
489468fe 625{
f1c40652 626}
489468fe 627
c443ff6f
SC
628void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info)
629{
630 UnRef();
03647350 631
c443ff6f
SC
632 m_refData = new wxFontRefData( info);
633}
634
635
f1c40652
SC
636bool wxFont::RealizeResource()
637{
638 M_FONTDATA->MacFindFont();
489468fe
SC
639
640 return true;
641}
642
f1c40652
SC
643void wxFont::SetEncoding(wxFontEncoding encoding)
644{
645 AllocExclusive();
489468fe
SC
646
647 M_FONTDATA->SetEncoding( encoding );
489468fe
SC
648}
649
650wxGDIRefData *wxFont::CreateGDIRefData() const
651{
652 return new wxFontRefData;
653}
654
655wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const
656{
5c33522f 657 return new wxFontRefData(*static_cast<const wxFontRefData *>(data));
489468fe
SC
658}
659
660void wxFont::SetPointSize(int pointSize)
661{
662 if ( M_FONTDATA->GetPointSize() == pointSize )
663 return;
664
f1c40652 665 AllocExclusive();
489468fe
SC
666
667 M_FONTDATA->SetPointSize( pointSize );
489468fe
SC
668}
669
0c14b6c3 670void wxFont::SetFamily(wxFontFamily family)
489468fe 671{
f1c40652 672 AllocExclusive();
489468fe
SC
673
674 M_FONTDATA->SetFamily( family );
489468fe
SC
675}
676
0c14b6c3 677void wxFont::SetStyle(wxFontStyle style)
489468fe 678{
f1c40652 679 AllocExclusive();
489468fe
SC
680
681 M_FONTDATA->SetStyle( style );
489468fe
SC
682}
683
0c14b6c3 684void wxFont::SetWeight(wxFontWeight weight)
489468fe 685{
f1c40652 686 AllocExclusive();
489468fe
SC
687
688 M_FONTDATA->SetWeight( weight );
489468fe
SC
689}
690
691bool wxFont::SetFaceName(const wxString& faceName)
692{
f1c40652 693 AllocExclusive();
489468fe
SC
694
695 M_FONTDATA->SetFaceName( faceName );
696
489468fe
SC
697 return wxFontBase::SetFaceName(faceName);
698}
699
700void wxFont::SetUnderlined(bool underlined)
701{
f1c40652 702 AllocExclusive();
489468fe
SC
703
704 M_FONTDATA->SetUnderlined( underlined );
489468fe
SC
705}
706
489468fe
SC
707// ----------------------------------------------------------------------------
708// accessors
709// ----------------------------------------------------------------------------
710
711// TODO: insert checks everywhere for M_FONTDATA == NULL!
712
713int wxFont::GetPointSize() const
714{
715 wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
716
717 return M_FONTDATA->GetPointSize();
718}
719
720wxSize wxFont::GetPixelSize() const
721{
722#if wxUSE_GRAPHICS_CONTEXT
723 // TODO: consider caching the value
724 wxGraphicsContext* dc = wxGraphicsContext::CreateFromNative((CGContextRef) NULL);
725 dc->SetFont(*(wxFont *)this,*wxBLACK);
726 wxDouble width, height = 0;
727 dc->GetTextExtent( wxT("g"), &width, &height, NULL, NULL);
728 delete dc;
729 return wxSize((int)width, (int)height);
730#else
731 return wxFontBase::GetPixelSize();
732#endif
733}
734
0c14b6c3 735wxFontFamily wxFont::GetFamily() const
489468fe 736{
0c14b6c3 737 wxCHECK_MSG( M_FONTDATA != NULL , wxFONTFAMILY_MAX, wxT("invalid font") );
489468fe
SC
738
739 return M_FONTDATA->GetFamily();
740}
741
0c14b6c3 742wxFontStyle wxFont::GetStyle() const
489468fe 743{
0c14b6c3 744 wxCHECK_MSG( M_FONTDATA != NULL , wxFONTSTYLE_MAX, wxT("invalid font") );
489468fe
SC
745
746 return M_FONTDATA->GetStyle() ;
747}
748
0c14b6c3 749wxFontWeight wxFont::GetWeight() const
489468fe 750{
0c14b6c3 751 wxCHECK_MSG( M_FONTDATA != NULL , wxFONTWEIGHT_MAX, wxT("invalid font") );
489468fe
SC
752
753 return M_FONTDATA->GetWeight();
754}
755
756bool wxFont::GetUnderlined() const
757{
758 wxCHECK_MSG( M_FONTDATA != NULL , false, wxT("invalid font") );
759
760 return M_FONTDATA->GetUnderlined();
761}
762
763wxString wxFont::GetFaceName() const
764{
765 wxCHECK_MSG( M_FONTDATA != NULL , wxEmptyString , wxT("invalid font") );
766
767 return M_FONTDATA->GetFaceName() ;
768}
769
770wxFontEncoding wxFont::GetEncoding() const
771{
772 wxCHECK_MSG( M_FONTDATA != NULL , wxFONTENCODING_DEFAULT , wxT("invalid font") );
773
774 return M_FONTDATA->GetEncoding() ;
775}
776
f1c40652 777#if wxOSX_USE_ATSU_TEXT && wxOSX_USE_CARBON
489468fe
SC
778
779short wxFont::MacGetFontNum() const
780{
781 wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
782
f1c40652
SC
783 // cast away constness otherwise lazy font resolution is not possible
784 const_cast<wxFont *>(this)->RealizeResource();
03647350 785
f1c40652 786 return M_FONTDATA->m_info.m_qdFontFamily;
489468fe
SC
787}
788
f1c40652 789wxByte wxFont::MacGetFontStyle() const
489468fe
SC
790{
791 wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
792
f1c40652
SC
793 // cast away constness otherwise lazy font resolution is not possible
794 const_cast<wxFont *>(this)->RealizeResource();
03647350 795
f1c40652 796 return M_FONTDATA->m_info.m_qdFontStyle;
489468fe
SC
797}
798
f1c40652 799wxUint16 wxFont::MacGetThemeFontID() const
489468fe
SC
800{
801 wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
802
f1c40652 803 return M_FONTDATA->m_macThemeFontID;
489468fe
SC
804}
805
f1c40652
SC
806#endif
807
beb2638a 808#if wxOSX_USE_ATSU_TEXT
f1c40652 809void * wxFont::MacGetATSUStyle() const
489468fe 810{
f1c40652 811 wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") );
489468fe 812
f1c40652
SC
813 // cast away constness otherwise lazy font resolution is not possible
814 const_cast<wxFont *>(this)->RealizeResource();
03647350 815
f1c40652 816 return M_FONTDATA->m_macATSUStyle;
489468fe 817}
6f283573
SC
818
819#if WXWIN_COMPATIBILITY_2_8
03647350 820wxUint32 wxFont::MacGetATSUFontID() const
6f283573 821{
c22ace4d 822 wxCHECK_MSG( M_FONTDATA != NULL, 0, wxT("invalid font") );
6f283573
SC
823
824 // cast away constness otherwise lazy font resolution is not possible
825 const_cast<wxFont *>(this)->RealizeResource();
03647350 826
6f283573
SC
827 return M_FONTDATA->m_info.m_atsuFontID;
828}
829
830wxUint32 wxFont::MacGetATSUAdditionalQDStyles() const
831{
c22ace4d 832 wxCHECK_MSG( M_FONTDATA != NULL, 0, wxT("invalid font") );
6f283573
SC
833
834 // cast away constness otherwise lazy font resolution is not possible
835 const_cast<wxFont *>(this)->RealizeResource();
03647350 836
6f283573
SC
837 return M_FONTDATA->m_info.m_atsuAdditionalQDStyles;
838}
839#endif
840
f1c40652
SC
841#endif
842
843#if wxOSX_USE_CORE_TEXT
489468fe 844
aa6208d9 845CTFontRef wxFont::OSXGetCTFont() const
489468fe
SC
846{
847 wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
848
f1c40652
SC
849 // cast away constness otherwise lazy font resolution is not possible
850 const_cast<wxFont *>(this)->RealizeResource();
03647350 851
f1c40652 852 return (CTFontRef)(M_FONTDATA->m_ctFont);
489468fe
SC
853}
854
f1c40652
SC
855#endif
856
9445de1e
SC
857#if wxOSX_USE_COCOA_OR_CARBON
858
aa6208d9 859CGFontRef wxFont::OSXGetCGFont() const
9445de1e
SC
860{
861 wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
862
863 // cast away constness otherwise lazy font resolution is not possible
864 const_cast<wxFont *>(this)->RealizeResource();
03647350 865
9445de1e
SC
866 return (M_FONTDATA->m_cgFont);
867}
868
869#endif
870
871
f1c40652
SC
872#if wxOSX_USE_COCOA
873
aa6208d9 874NSFont* wxFont::OSXGetNSFont() const
489468fe
SC
875{
876 wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
877
f1c40652
SC
878 // cast away constness otherwise lazy font resolution is not possible
879 const_cast<wxFont *>(this)->RealizeResource();
03647350 880
f1c40652 881 return (M_FONTDATA->m_nsFont);
489468fe 882}
f1c40652 883
489468fe
SC
884#endif
885
e5e5b843
SC
886#if wxOSX_USE_IPHONE
887
888UIFont* wxFont::OSXGetUIFont() const
889{
890 wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
891
892 // cast away constness otherwise lazy font resolution is not possible
893 const_cast<wxFont *>(this)->RealizeResource();
894
895 return (M_FONTDATA->m_uiFont);
896}
897
898#endif
899
f1c40652 900const wxNativeFontInfo * wxFont::GetNativeFontInfo() const
489468fe
SC
901{
902 wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") );
f1c40652 903 wxCHECK_MSG( Ok(), NULL, wxT("invalid font") );
489468fe 904
f1c40652
SC
905 // cast away constness otherwise lazy font resolution is not possible
906 const_cast<wxFont *>(this)->RealizeResource();
03647350 907
f1c40652
SC
908 // M_FONTDATA->m_info.InitFromFont(*this);
909
910 return &(M_FONTDATA->m_info);
911}
912
913// ----------------------------------------------------------------------------
914// wxNativeFontInfo
915// ----------------------------------------------------------------------------
916
d0a7d7b1 917#if 0 // wxOSX_USE_CORE_TEXT
f1c40652
SC
918
919/* from Core Text Manual Common Operations */
920
921static CTFontDescriptorRef wxMacCreateCTFontDescriptor(CFStringRef iFamilyName, CTFontSymbolicTraits iTraits )
922{
923 CTFontDescriptorRef descriptor = NULL;
924 CFMutableDictionaryRef attributes;
925
2e587bb9 926 wxASSERT(iFamilyName != NULL);
f1c40652
SC
927 // Create a mutable dictionary to hold our attributes.
928 attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
929 &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
2e587bb9 930 wxASSERT(attributes != NULL);
f1c40652
SC
931
932 if (attributes != NULL) {
933 // Add a family name to our attributes.
934 CFDictionaryAddValue(attributes, kCTFontFamilyNameAttribute, iFamilyName);
935
936
937 if ( iTraits ) {
938 CFMutableDictionaryRef traits;
939 CFNumberRef symTraits;
940
941 // Create the traits dictionary.
942 symTraits = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type,
943 &iTraits);
2e587bb9 944 wxASSERT(symTraits != NULL);
f1c40652
SC
945
946 if (symTraits != NULL) {
947 // Create a dictionary to hold our traits values.
948 traits = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
949 &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
2e587bb9 950 wxASSERT(traits != NULL);
f1c40652
SC
951
952 if (traits != NULL) {
953 // Add the symbolic traits value to the traits dictionary.
954 CFDictionaryAddValue(traits, kCTFontSymbolicTrait, symTraits);
955
956 // Add the traits attribute to our attributes.
957 CFDictionaryAddValue(attributes, kCTFontTraitsAttribute, traits);
958 CFRelease(traits);
959 }
960 CFRelease(symTraits);
961 }
962 }
963 // Create the font descriptor with our attributes
964 descriptor = CTFontDescriptorCreateWithAttributes(attributes);
2e587bb9 965 wxASSERT(descriptor != NULL);
f1c40652
SC
966
967 CFRelease(attributes);
968 }
969 // Return our font descriptor.
970 return descriptor ;
971}
972
973#endif
974
975void wxNativeFontInfo::Init()
976{
f1c40652
SC
977#if wxOSX_USE_ATSU_TEXT
978 m_atsuFontID = 0 ;
979 m_atsuAdditionalQDStyles = 0;
980 m_atsuFontValid = false;
981#if wxOSX_USE_CARBON
982 m_qdFontStyle = 0;
983 m_qdFontFamily = 0;
984#endif
f1c40652
SC
985#endif
986 m_pointSize = 0;
987 m_family = wxFONTFAMILY_DEFAULT;
988 m_style = wxFONTSTYLE_NORMAL;
989 m_weight = wxFONTWEIGHT_NORMAL;
990 m_underlined = false;
991 m_faceName.clear();
c443ff6f 992 m_encoding = wxFont::GetDefaultEncoding();
f1c40652
SC
993 m_descriptorValid = false;
994}
995
996#if wxOSX_USE_CORE_TEXT
997void wxNativeFontInfo::Init(CTFontDescriptorRef descr)
998{
999 Init();
03647350 1000
03c28161 1001 wxCFRef< CFNumberRef > sizevalue( (CFNumberRef) CTFontDescriptorCopyAttribute( descr, kCTFontSizeAttribute ) );
f1c40652
SC
1002 float fsize;
1003 if ( CFNumberGetValue( sizevalue , kCFNumberFloatType , &fsize ) )
1004 m_pointSize = (int)( fsize + 0.5 );
1005
03c28161 1006 wxCFRef< CFDictionaryRef > traitsvalue( (CFDictionaryRef) CTFontDescriptorCopyAttribute( descr, kCTFontTraitsAttribute ) );
f1c40652
SC
1007 CTFontSymbolicTraits traits;
1008 if ( CFNumberGetValue((CFNumberRef) CFDictionaryGetValue(traitsvalue,kCTFontSymbolicTrait),kCFNumberIntType,&traits) )
1009 {
1010 if ( traits & kCTFontItalicTrait )
1011 m_style = wxFONTSTYLE_ITALIC;
1012 if ( traits & kCTFontBoldTrait )
1013 m_weight = wxFONTWEIGHT_BOLD ;
1014 }
1015
03c28161 1016 wxCFStringRef familyName( (CFStringRef) CTFontDescriptorCopyAttribute(descr, kCTFontFamilyNameAttribute));
03647350 1017 m_faceName = familyName.AsString();
489468fe
SC
1018}
1019#endif
1020
f1c40652
SC
1021void wxNativeFontInfo::EnsureValid()
1022{
1023 if ( m_descriptorValid )
1024 return;
03647350 1025
f1c40652
SC
1026#if wxOSX_USE_ATSU_TEXT
1027 if ( !m_atsuFontValid )
1028 {
9a672c75
SC
1029#if !wxOSX_USE_CARBON
1030 // not needed outside
1031 wxInt16 m_qdFontFamily;
1032 wxInt16 m_qdFontStyle;
1033#endif
f1c40652
SC
1034 wxCFStringRef cf( m_faceName, wxLocale::GetSystemEncoding() );
1035 ATSFontFamilyRef atsfamily = ATSFontFamilyFindFromName( cf , kATSOptionFlagsDefault );
1036 if ( atsfamily == (ATSFontFamilyRef) -1 )
1037 {
1038 wxLogDebug( wxT("ATSFontFamilyFindFromName failed for ") + m_faceName );
1039 m_qdFontFamily = GetAppFont();
1040 }
1041 else
1042 {
1043 m_qdFontFamily = FMGetFontFamilyFromATSFontFamilyRef( atsfamily );
1044 }
1045
1046 m_qdFontStyle = 0;
1047 if (m_weight == wxFONTWEIGHT_BOLD)
1048 m_qdFontStyle |= bold;
1049 if (m_style == wxFONTSTYLE_ITALIC || m_style == wxFONTSTYLE_SLANT)
1050 m_qdFontStyle |= italic;
1051 if (m_underlined)
1052 m_qdFontStyle |= underline;
1053
489468fe 1054
f1c40652
SC
1055 // we try to get as much styles as possible into ATSU
1056
1057 // ATSUFontID and FMFont are equivalent
1058 FMFontStyle intrinsicStyle = 0 ;
1059 OSStatus status = FMGetFontFromFontFamilyInstance( m_qdFontFamily , m_qdFontStyle , (FMFont*)&m_atsuFontID , &intrinsicStyle);
ca910e1a
VZ
1060 if ( status != noErr )
1061 {
1062 wxFAIL_MSG( wxT("couldn't get an ATSUFont from font family") );
1063 }
f1c40652
SC
1064 m_atsuAdditionalQDStyles = m_qdFontStyle & (~intrinsicStyle );
1065 m_atsuFontValid = true;
1066 }
f1c40652
SC
1067#endif
1068 m_descriptorValid = true;
1069}
1070
1071void wxNativeFontInfo::Init(const wxNativeFontInfo& info)
489468fe 1072{
f1c40652 1073 Init();
f1c40652
SC
1074#if wxOSX_USE_ATSU_TEXT
1075 m_atsuFontValid = info.m_atsuFontValid;
1076 m_atsuFontID = info.m_atsuFontID ;
1077 m_atsuAdditionalQDStyles = info.m_atsuAdditionalQDStyles;
1078#if wxOSX_USE_CARBON
1079 m_qdFontFamily = info.m_qdFontFamily;
1080 m_qdFontStyle = info.m_qdFontStyle;
1081#endif
f1c40652
SC
1082#endif
1083 m_pointSize = info.m_pointSize;
1084 m_family = info.m_family;
1085 m_style = info.m_style;
1086 m_weight = info.m_weight;
1087 m_underlined = info.m_underlined;
1088 m_faceName = info.m_faceName;
1089 m_encoding = info.m_encoding;
1090 m_descriptorValid = info.m_descriptorValid;
1091}
1092
1093void wxNativeFontInfo::Init(int size,
1094 wxFontFamily family,
1095 wxFontStyle style,
1096 wxFontWeight weight,
1097 bool underlined,
1098 const wxString& faceName,
1099 wxFontEncoding encoding)
1100{
1101 Init();
1102 m_pointSize = size;
1103 m_family = family;
1104 m_style = style;
1105 m_weight = weight;
1106 m_underlined = underlined;
1107 m_faceName = faceName;
c443ff6f
SC
1108 if ( encoding == wxFONTENCODING_DEFAULT )
1109 encoding = wxFont::GetDefaultEncoding();
f1c40652 1110 m_encoding = encoding;
489468fe 1111
489468fe
SC
1112}
1113
f1c40652
SC
1114void wxNativeFontInfo::Free()
1115{
f1c40652
SC
1116#if wxOSX_USE_ATSU_TEXT
1117 m_atsuFontID = 0 ;
1118 m_atsuAdditionalQDStyles = 0;
1119 m_atsuFontValid = false;
489468fe 1120#endif
f1c40652
SC
1121 m_descriptorValid = false;
1122}
489468fe 1123
f1c40652 1124bool wxNativeFontInfo::FromString(const wxString& s)
489468fe 1125{
f1c40652 1126 long l;
489468fe 1127
9a83f860 1128 wxStringTokenizer tokenizer(s, wxT(";"));
489468fe 1129
f1c40652
SC
1130 wxString token = tokenizer.GetNextToken();
1131 //
1132 // Ignore the version for now
1133 //
1134
1135 token = tokenizer.GetNextToken();
1136 if ( !token.ToLong(&l) )
1137 return false;
1138 m_pointSize = (int)l;
1139
1140 token = tokenizer.GetNextToken();
1141 if ( !token.ToLong(&l) )
1142 return false;
1143 m_family = (wxFontFamily)l;
1144
1145 token = tokenizer.GetNextToken();
1146 if ( !token.ToLong(&l) )
1147 return false;
1148 m_style = (wxFontStyle)l;
1149
1150 token = tokenizer.GetNextToken();
1151 if ( !token.ToLong(&l) )
1152 return false;
1153 m_weight = (wxFontWeight)l;
1154
1155 token = tokenizer.GetNextToken();
1156 if ( !token.ToLong(&l) )
1157 return false;
1158 m_underlined = l != 0;
1159
1160 m_faceName = tokenizer.GetNextToken();
1161
1162#ifndef __WXMAC__
1163 if( !faceName )
1164 return false;
1165#endif
1166
1167 token = tokenizer.GetNextToken();
1168 if ( !token.ToLong(&l) )
1169 return false;
1170 m_encoding = (wxFontEncoding)l;
1171
1172 return true;
1173}
1174
1175wxString wxNativeFontInfo::ToString() const
1176{
1177 wxString s;
1178
9a83f860 1179 s.Printf(wxT("%d;%d;%d;%d;%d;%d;%s;%d"),
f1c40652
SC
1180 0, // version
1181 m_pointSize,
1182 m_family,
1183 (int)m_style,
1184 (int)m_weight,
1185 m_underlined,
1186 m_faceName.GetData(),
1187 (int)m_encoding);
1188
1189 return s;
1190}
1191
1192int wxNativeFontInfo::GetPointSize() const
1193{
1194 return m_pointSize;
1195}
1196
1197wxFontStyle wxNativeFontInfo::GetStyle() const
1198{
1199 return m_style;
1200}
1201
1202wxFontWeight wxNativeFontInfo::GetWeight() const
1203{
1204 return m_weight;
1205}
1206
1207bool wxNativeFontInfo::GetUnderlined() const
1208{
1209 return m_underlined;
1210}
1211
1212wxString wxNativeFontInfo::GetFaceName() const
1213{
1214 return m_faceName;
1215}
1216
1217wxFontFamily wxNativeFontInfo::GetFamily() const
1218{
1219 return m_family;
489468fe 1220}
f1c40652
SC
1221
1222wxFontEncoding wxNativeFontInfo::GetEncoding() const
1223{
1224 return m_encoding;
1225}
1226
1227// changing the font descriptor
1228
1229void wxNativeFontInfo::SetPointSize(int pointsize)
1230{
1231 if ( m_pointSize != pointsize )
1232 {
1233 m_pointSize = pointsize;
1234 Free();
1235 }
1236}
1237
1238void wxNativeFontInfo::SetStyle(wxFontStyle style_)
1239{
1240 if ( m_style != style_ )
1241 {
1242 m_style = style_;
1243 Free();
1244 }
1245}
1246
1247void wxNativeFontInfo::SetWeight(wxFontWeight weight_)
1248{
1249 if ( m_weight != weight_ )
1250 {
1251 m_weight = weight_;
1252 Free();
1253 }
1254}
1255
1256void wxNativeFontInfo::SetUnderlined(bool underlined_)
1257{
1258 if ( m_underlined != underlined_ )
1259 {
1260 m_underlined = underlined_;
1261 Free();
1262 }
1263}
1264
1265bool wxNativeFontInfo::SetFaceName(const wxString& facename_)
1266{
1267 if ( m_faceName != facename_ )
1268 {
1269 m_faceName = facename_;
1270 Free();
1271 }
1272 return true;
1273}
1274
1275void wxNativeFontInfo::SetFamily(wxFontFamily family_)
1276{
1277 if ( m_family != family_ )
1278 {
1279 m_family = family_;
1280 Free();
1281 }
1282}
1283
1284void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding_)
1285{
c443ff6f
SC
1286 if ( encoding_ == wxFONTENCODING_DEFAULT )
1287 encoding_ = wxFont::GetDefaultEncoding();
f1c40652
SC
1288 m_encoding = encoding_;
1289 // not reflected in native descriptors
c22ace4d 1290}