#include <map>
#include <string>
-IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
-
class WXDLLEXPORT wxFontRefData: public wxGDIRefData
{
public:
}
wxFontEncoding GetEncoding() const { return m_info.GetEncoding(); }
+
+ bool IsFixedWidth() const;
void Free();
#define M_FONTDATA ((wxFontRefData*)m_refData)
-wxFontRefData::wxFontRefData(const wxFontRefData& data)
+wxFontRefData::wxFontRefData(const wxFontRefData& data) : wxGDIRefData()
{
Init();
m_info = data.m_info;
Init();
#if wxOSX_USE_CORE_TEXT
- if ( UMAGetSystemVersion() >= 0x1050 )
{
CTFontUIFontType uifont = kCTFontSystemFontType;
switch( font )
}
#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 )
m_info.EnsureValid();
#if wxOSX_USE_CORE_TEXT
- if ( UMAGetSystemVersion() >= 0x1050 )
{
CTFontSymbolicTraits traits = 0;
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);
+ }
}
}
-
+
m_cgFont.reset(CTFontCopyGraphicsFont(m_ctFont, NULL));
}
m_fontValid = true;
}
+bool wxFontRefData::IsFixedWidth() const
+{
+#if wxOSX_USE_CORE_TEXT
+ CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(m_ctFont);
+ return (traits & kCTFontMonoSpaceTrait) != 0;
+#else
+ return false;
+#endif
+}
+
// ----------------------------------------------------------------------------
// wxFont
// ----------------------------------------------------------------------------
void wxFont::SetPointSize(int pointSize)
{
- if ( M_FONTDATA->GetPointSize() == pointSize )
+ if ( M_FONTDATA != NULL && M_FONTDATA->GetPointSize() == pointSize )
return;
AllocExclusive();
#endif
}
-wxFontFamily wxFont::GetFamily() const
+bool wxFont::IsFixedWidth() const
{
- wxCHECK_MSG( M_FONTDATA != NULL , wxFONTFAMILY_MAX, wxT("invalid font") );
+ wxCHECK_MSG( M_FONTDATA != NULL , false, wxT("invalid font") );
+
+ // cast away constness otherwise lazy font resolution is not possible
+ const_cast<wxFont *>(this)->RealizeResource();
+ return M_FONTDATA->IsFixedWidth();
+}
+
+wxFontFamily wxFont::DoGetFamily() const
+{
return M_FONTDATA->GetFamily();
}
return M_FONTDATA->m_macATSUStyle;
}
-#if WXWIN_COMPATIBILITY_2_8
wxUint32 wxFont::MacGetATSUFontID() const
{
wxCHECK_MSG( M_FONTDATA != NULL, 0, wxT("invalid font") );
}
#endif
-#endif
-
#if wxOSX_USE_CORE_TEXT
CTFontRef wxFont::OSXGetCTFont() 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") );
- wxCHECK_MSG( Ok(), NULL, wxT("invalid font") );
+ wxCHECK_MSG( IsOk(), NULL, wxT("invalid font") );
// cast away constness otherwise lazy font resolution is not possible
const_cast<wxFont *>(this)->RealizeResource();
// wxNativeFontInfo
// ----------------------------------------------------------------------------
-#if wxOSX_USE_CORE_TEXT
+#if 0 // wxOSX_USE_CORE_TEXT
/* from Core Text Manual Common Operations */
return m_encoding;
}
+bool wxNativeFontInfo::GetStrikethrough() const
+{
+ return false;
+}
+
+
// changing the font descriptor
void wxNativeFontInfo::SetPointSize(int pointsize)
m_encoding = encoding_;
// not reflected in native descriptors
}
+
+void wxNativeFontInfo::SetStrikethrough(bool WXUNUSED(strikethrough))
+{
+}
+
+