]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/carbon/font.cpp
Correct format specifiers used to show wxIPV4address.
[wxWidgets.git] / src / osx / carbon / font.cpp
index c46f7747246fedfc2b382a7185980f535ae1245a..2d0ae842e25fdbe33bfff63fb61313d2a423eb4f 100644 (file)
@@ -454,6 +454,9 @@ void wxFontRefData::CreateATSUFont()
 }
 #endif
 
+static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
+static const CGAffineTransform kSlantTransform = CGAffineTransformMake( 1, 0, tan(DegToRad(11)), 1, 0, 0 );
+
 void wxFontRefData::MacFindFont()
 {
     if ( m_fontValid )
@@ -474,16 +477,54 @@ void wxFontRefData::MacFindFont()
             traits |= kCTFontItalicTrait;
 
         // use font caching
-        wxString lookupnameWithSize = wxString::Format( "%s_%ld_%ld", m_info.m_faceName.c_str(), traits, m_info.m_pointSize );
+        wxString lookupnameWithSize = wxString::Format( "%s_%u_%d", m_info.m_faceName, traits, m_info.m_pointSize );
 
         static std::map< std::wstring , wxCFRef< CTFontRef > > fontcache ;
         m_ctFont = fontcache[ std::wstring(lookupnameWithSize.wc_str()) ];
         if ( !m_ctFont )
         {
             m_ctFont.reset(CTFontCreateWithName( wxCFStringRef(m_info.m_faceName), m_info.m_pointSize , NULL ));
-            if ( traits != 0 )
+            if ( m_ctFont.get() == NULL )
+            {
+                // TODO try fallbacks according to font type
+                m_ctFont.reset(CTFontCreateUIFontForLanguage( kCTFontSystemFontType, m_info.m_pointSize , NULL ));
+            }
+            else
             {
-                m_ctFont.reset(CTFontCreateCopyWithSymbolicTraits( m_ctFont, 0, NULL, traits, traits ));
+                if ( traits != 0 )
+                {
+                    // attempt native font variant, if not available, fallback to italic emulation mode and remove bold
+                    CTFontRef fontWithTraits = CTFontCreateCopyWithSymbolicTraits( m_ctFont, 0, NULL, traits, traits );
+                    if ( fontWithTraits == NULL )
+                    {
+                        CTFontSymbolicTraits remainingTraits = traits;
+                        const CGAffineTransform* remainingTransform = NULL;
+                        
+                        if( remainingTraits & kCTFontItalicTrait )
+                        {
+                            remainingTraits &= ~kCTFontItalicTrait;
+                            remainingTransform = &kSlantTransform;
+                            if ( remainingTraits & kCTFontBoldTrait )
+                            {
+                                // first try an emulated oblique with an existing bold font
+                                fontWithTraits = CTFontCreateCopyWithSymbolicTraits( m_ctFont, 0, remainingTransform, remainingTraits, remainingTraits );
+                                if ( fontWithTraits == NULL )
+                                {
+                                    // give in on the bold, try native oblique
+                                    fontWithTraits = CTFontCreateCopyWithSymbolicTraits( m_ctFont, 0, NULL, kCTFontItalicTrait, kCTFontItalicTrait );
+                                }
+                            }
+                        }
+                        
+                        if ( fontWithTraits == NULL )
+                        {
+                            fontWithTraits = CTFontCreateWithName( wxCFStringRef(m_info.m_faceName), m_info.m_pointSize, remainingTransform );
+                        }
+                            
+                    }
+                    if ( fontWithTraits != NULL )
+                        m_ctFont.reset(fontWithTraits);
+                }
             }
         }
         
@@ -842,6 +883,20 @@ NSFont* wxFont::OSXGetNSFont() const
 
 #endif
 
+#if wxOSX_USE_IPHONE
+
+UIFont* wxFont::OSXGetUIFont() const
+{
+    wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );
+    
+    // cast away constness otherwise lazy font resolution is not possible
+    const_cast<wxFont *>(this)->RealizeResource();
+    
+    return (M_FONTDATA->m_uiFont);
+}
+
+#endif
+
 const wxNativeFontInfo * wxFont::GetNativeFontInfo() const
 {
     wxCHECK_MSG( M_FONTDATA != NULL , NULL, wxT("invalid font") );
@@ -859,7 +914,7 @@ const wxNativeFontInfo * wxFont::GetNativeFontInfo() const
 // wxNativeFontInfo
 // ----------------------------------------------------------------------------
 
-#if wxOSX_USE_CORE_TEXT
+#if 0 // wxOSX_USE_CORE_TEXT
 
 /* from Core Text Manual Common Operations */