/////////////////////////////////////////////////////////////////////////////
-// Name: src/mac/carbon/font.cpp
+// Name: src/osx/carbon/font.cpp
// Purpose: wxFont class
// Author: Stefan Csomor
// Modified by:
#include "wx/graphics.h"
#include "wx/settings.h"
-#include "wx/mac/uma.h"
+#include "wx/osx/private.h"
-#ifndef __DARWIN__
-#include <ATSUnicode.h>
+#if wxOSX_USE_ATSU_TEXT && !wxOSX_USE_CARBON
+// include themeing support
+#include <Carbon/Carbon.h>
#endif
#include <map>
Init(size, family, style, weight, underlined, faceName, encoding);
}
-#if wxMAC_USE_CORE_TEXT
+#if wxOSX_USE_CORE_TEXT
wxFontRefData( wxUint32 coreTextFontType );
wxFontRefData( CTFontRef font );
wxFontRefData( CTFontDescriptorRef fontdescriptor, int size );
const wxString& faceName,
wxFontEncoding encoding);
-#if wxMAC_USE_CORE_TEXT
+#if wxOSX_USE_CORE_TEXT
void Init( CTFontRef font );
#endif
// font characterstics
bool m_noAA; // No anti-aliasing
public:
-#if wxMAC_USE_ATSU_TEXT
+#if wxOSX_USE_ATSU_TEXT
FMFontFamily m_macFontFamily;
FMFontSize m_macFontSize;
FMFontStyle m_macFontStyle;
// information here, as this speeds up and optimizes rendering
ThemeFontID m_macThemeFontID ;
#endif
-#if wxMAC_USE_CORE_TEXT
+#if wxOSX_USE_CORE_TEXT
wxCFRef<CTFontRef> m_ctFont;
- wxCFRef<CTFontDescriptorRef> m_ctFontDescriptor;
#endif
-#if wxMAC_USE_CORE_TEXT || wxMAC_USE_ATSU_TEXT
+#if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT
ATSUStyle m_macATSUStyle ;
#endif
wxNativeFontInfo m_info;
m_faceName = faceName;
m_encoding = encoding;
m_noAA = false;
-#if wxMAC_USE_ATSU_TEXT
+#if wxOSX_USE_ATSU_TEXT
m_macFontFamily = 0 ;
m_macFontSize = 0;
m_macFontStyle = 0;
m_macATSUAdditionalQDStyles = 0 ;
m_macThemeFontID = kThemeCurrentPortFont ;
#endif
-#if wxMAC_USE_CORE_TEXT || wxMAC_USE_ATSU_TEXT
+#if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT
m_macATSUStyle = NULL ;
#endif
}
wxFontRefData::~wxFontRefData()
{
-#if wxMAC_USE_CORE_TEXT || wxMAC_USE_ATSU_TEXT
+#if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT
if ( m_macATSUStyle )
{
::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle);
void wxFontRefData::MacInvalidateNativeFont()
{
-#if wxMAC_USE_CORE_TEXT
+#if wxOSX_USE_CORE_TEXT
m_ctFont.reset();
- m_ctFontDescriptor.reset();
#endif
-#if wxMAC_USE_CORE_TEXT || wxMAC_USE_ATSU_TEXT
+#if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT
if ( m_macATSUStyle )
{
::ATSUDisposeStyle((ATSUStyle)m_macATSUStyle);
#endif
}
-#if wxMAC_USE_CORE_TEXT
+#if wxOSX_USE_CORE_TEXT
/* from Core Text Manual Common Operations */
wxFontRefData::wxFontRefData( wxUint32 coreTextFontType )
{
CTFontRef font = CTFontCreateUIFontForLanguage( coreTextFontType, 0.0, NULL ) ;
- if ( CTFontGetSize(m_ctFont) == 0 )
+ if ( CTFontGetSize(font) == 0 )
{
CFRelease(font);
font = CTFontCreateUIFontForLanguage( coreTextFontType, 12.0, NULL );
float fsize;
if ( CFNumberGetValue( value , kCFNumberFloatType , &fsize ) )
{
- size = (int) fsize + 0.5 ;
+ size = (int)( fsize + 0.5 );
}
}
Init( CTFontCreateWithFontDescriptor(fontdescriptor, size,NULL) );
void wxFontRefData::MacFindFont()
{
-#if wxMAC_USE_CORE_TEXT
+#if wxOSX_USE_CORE_TEXT
if ( UMAGetSystemVersion() >= 0x1050 )
{
if ( m_faceName.empty() && m_family == wxDEFAULT )
m_style = wxITALIC;
if ( traits & kCTFontBoldTrait )
m_weight = wxBOLD ;
- if ( !m_ctFontDescriptor.get() )
- m_ctFontDescriptor.reset( CTFontCopyFontDescriptor( m_ctFont ) );
}
else
{
break ;
case wxSWISS :
- m_faceName = wxT("Lucida Grande");
+ m_faceName = wxT("Helvetica");
break ;
case wxMODERN :
case wxTELETYPE:
- m_faceName = wxT("Monaco");
+ m_faceName = wxT("Courier");
+ if ( m_style == wxITALIC && m_weight == wxNORMAL )
+ {
+ m_style = wxITALIC;
+ }
break ;
default:
if (m_style == wxITALIC || m_style == wxSLANT)
traits |= kCTFontItalicTrait;
-// use font descriptor caching
-#if 1
- wxString lookupname = wxString::Format( "%s_%ld", m_faceName.c_str(), traits );
-
- static std::map< std::wstring , wxCFRef< CTFontDescriptorRef > > fontdescriptorcache ;
-
- m_ctFontDescriptor = fontdescriptorcache[ std::wstring(lookupname.wc_str()) ];
- if ( !m_ctFontDescriptor )
- {
- wxCFStringRef cf( m_faceName, wxLocale::GetSystemEncoding() );
- m_ctFontDescriptor.reset( wxMacCreateCTFontDescriptor( cf, traits ) );
- fontdescriptorcache[ std::wstring(lookupname.wc_str()) ] = m_ctFontDescriptor;
- }
-#else
- wxCFStringRef cf( m_faceName, wxLocale::GetSystemEncoding() );
- m_ctFontDescriptor.reset( wxMacCreateCTFontDescriptor( cf, traits ) );
-#endif
-
-// use font caching
-#if 1
+ // use font caching
wxString lookupnameWithSize = wxString::Format( "%s_%ld_%ld", m_faceName.c_str(), traits, m_pointSize );
static std::map< std::wstring , wxCFRef< CTFontRef > > fontcache ;
m_ctFont = fontcache[ std::wstring(lookupnameWithSize.wc_str()) ];
if ( !m_ctFont )
{
- m_ctFont.reset( CTFontCreateWithFontDescriptor( m_ctFontDescriptor, m_pointSize, NULL ) );
+ // QD selection algorithm is the fastest by orders of magnitude on 10.5
+ if ( m_faceName.IsAscii() )
+ {
+ uint8 qdstyle = 0;
+ if (m_weight == wxBOLD)
+ qdstyle |= bold;
+ if (m_style == wxITALIC || m_style == wxSLANT)
+ qdstyle |= italic;
+
+ Str255 qdFontName ;
+ wxMacStringToPascal( m_faceName , qdFontName );
+ m_ctFont.reset( CTFontCreateWithQuickdrawInstance(qdFontName, 0 , qdstyle, m_pointSize) );
+ }
+ else
+ {
+
+ static std::map< std::wstring , wxCFRef< CTFontDescriptorRef > > fontdescriptorcache ;
+ wxString lookupname = wxString::Format( "%s_%ld", m_faceName.c_str(), traits );
+ // descriptor caching
+ wxCFRef< CTFontDescriptorRef > descriptor = fontdescriptorcache[ std::wstring(lookupname.wc_str()) ];
+ if ( !descriptor )
+ {
+ wxCFStringRef cf( m_faceName, wxLocale::GetSystemEncoding() );
+ descriptor.reset( wxMacCreateCTFontDescriptor( cf, traits ) );
+ fontdescriptorcache[ std::wstring(lookupname.wc_str()) ] = descriptor;
+ }
+ m_ctFont.reset( CTFontCreateWithFontDescriptor( descriptor, m_pointSize, NULL ) );
+ CTFontSymbolicTraits received = CTFontGetSymbolicTraits( m_ctFont ) & 0x03;
+ if ( traits != received )
+ {
+ // TODO further fallbacks, synthesizing bold and italic, trying direct PostScript names etc
+ }
+ }
+
fontcache[ std::wstring(lookupnameWithSize.wc_str()) ] = m_ctFont;
+#if 1 // debugging coretext font matching
+ CTFontSymbolicTraits received = CTFontGetSymbolicTraits( m_ctFont ) & 0x03;
+ if ( received != traits )
+ {
+ float angle = CTFontGetSlantAngle( m_ctFont );
+ CFDictionaryRef dict = CTFontCopyTraits( m_ctFont );
+ CFNumberRef number = (CFNumberRef) CFDictionaryGetValue(dict, kCTFontWeightTrait );
+ float floatnumber;
+ CFNumberGetValue( number, kCFNumberFloatType, &floatnumber );
+ {
+ printf( wxString::Format( "font %s expected %d but got %d traits, %f angle \n" , m_faceName.c_str(), traits, received, angle ) );
+ }
+ CFShow( dict );
+ CFRelease( dict );
+ }
+#endif
}
-#else
- m_ctFont.reset( CTFontCreateWithFontDescriptor( m_ctFontDescriptor, m_pointSize, NULL ) );
-#endif
+
}
-#if wxMAC_USE_ATSU_TEXT == 0
+#if wxOSX_USE_ATSU_TEXT
OSStatus status = noErr;
- CTFontDescriptorRef desc = m_ctFontDescriptor ;
- ATSFontRef atsfont = CTFontGetPlatformFont( m_ctFont, &desc );
+ ATSFontRef atsfont = CTFontGetPlatformFont( m_ctFont, NULL );
FMFont fmfont = FMGetFontFromATSFontRef( atsfont );
ATSUAttributeTag atsuTags[] =
{
#endif
}
#endif
-#if wxMAC_USE_ATSU_TEXT
+#if wxOSX_USE_ATSU_TEXT
{
OSStatus status = noErr;
Str255 qdFontName ;
break ;
case wxSWISS :
- m_faceName = wxT("Lucida Grande");
+ m_faceName = wxT("Helvetica");
break ;
case wxMODERN :
case wxTELETYPE:
- m_faceName = wxT("Monaco");
+ m_faceName = wxT("Courier");
break ;
default:
return true;
}
-#if wxMAC_USE_CORE_TEXT
+#if wxOSX_USE_CORE_TEXT
bool wxFont::MacCreateFromUIFont(wxUint32 ctFontType )
{
#endif
+#if wxOSX_USE_CARBON
bool wxFont::MacCreateFromThemeFont(wxUint16 themeFontID)
{
-#if wxMAC_USE_CORE_TEXT
+#if wxOSX_USE_CORE_TEXT
if ( UMAGetSystemVersion() >= 0x1050)
{
return MacCreateFromUIFont(HIThemeGetUIFontType(themeFontID));
}
#endif
-#if wxMAC_USE_ATSU_TEXT
+#if wxOSX_USE_ATSU_TEXT
{
UnRef();
#endif
return false;
}
+#endif
wxFont::~wxFont()
{
return M_FONTDATA->GetNoAntiAliasing();
}
-#if wxMAC_USE_ATSU_TEXT
+#if wxOSX_USE_ATSU_TEXT
short wxFont::MacGetFontNum() const
{
}
#endif
-#if wxMAC_USE_CORE_TEXT || wxMAC_USE_ATSU_TEXT
+#if wxOSX_USE_CORE_TEXT || wxOSX_USE_ATSU_TEXT
void * wxFont::MacGetATSUStyle() const
{
wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") );
}
#endif
-#if wxMAC_USE_CORE_TEXT
+#if wxOSX_USE_CORE_TEXT
const void * wxFont::MacGetCTFont() const
{
return (CTFontRef)(M_FONTDATA->m_ctFont);
}
-const void * wxFont::MacGetCTFontDescriptor() const
-{
- wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
-
- return (CTFontDescriptorRef)(M_FONTDATA->m_ctFontDescriptor);
-}
-
#endif
const wxNativeFontInfo * wxFont::GetNativeFontInfo() const