#include "wx/fontutil.h"
#include "wx/graphics.h"
+#include "wx/settings.h"
#include "wx/mac/uma.h"
#include <ATSUnicode.h>
#endif
+#include <map>
+#include <string>
IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
wxFontEncoding encoding)
{
m_style = style;
- m_pointSize = pointSize;
+ m_pointSize = (pointSize == -1) ? wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).GetPointSize() : pointSize;
m_family = family;
m_style = style;
m_weight = weight;
CFRelease(symTraits);
}
}
- // Create the font descriptor with our attributes and input size.
+ // Create the font descriptor with our attributes
descriptor = CTFontDescriptorCreateWithAttributes(attributes);
check(descriptor != NULL);
}
}
- wxCFStringRef cf( m_faceName, wxLocale::GetSystemEncoding() );
+
CTFontSymbolicTraits traits = 0;
if (m_weight == wxBOLD)
traits |= kCTFontBoldTrait;
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
+ 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 ) );
+ fontcache[ std::wstring(lookupnameWithSize.wc_str()) ] = m_ctFont;
+ }
+#else
m_ctFont.reset( CTFontCreateWithFontDescriptor( m_ctFontDescriptor, m_pointSize, NULL ) );
+#endif
}
#if wxMAC_USE_ATSU_TEXT == 0
OSStatus status = noErr;