X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4913272f9cdead94a6d1470e51d6fb14946b50e0..f100b1c33ed3266515ae7c2cd4978ea9c9fceddc:/src/mac/carbon/font.cpp diff --git a/src/mac/carbon/font.cpp b/src/mac/carbon/font.cpp index e2c9d4f9a0..0fcdd8ad72 100644 --- a/src/mac/carbon/font.cpp +++ b/src/mac/carbon/font.cpp @@ -18,10 +18,11 @@ #include "wx/utils.h" #include "wx/intl.h" #include "wx/gdicmn.h" + #include "wx/log.h" #endif #include "wx/fontutil.h" -#include "wx/fontutil.h" +#include "wx/graphics.h" #include "wx/mac/private.h" @@ -154,6 +155,8 @@ public: wxNativeFontInfo m_info; }; +#define M_FONTDATA ((wxFontRefData*)m_refData) + // ============================================================================ // implementation @@ -251,6 +254,7 @@ void wxFontRefData::MacFindFont() break ; case wxMODERN : + case wxTELETYPE: m_faceName = wxT("Monaco"); break ; @@ -261,6 +265,11 @@ void wxFontRefData::MacFindFont() #ifndef __LP64__ wxMacStringToPascal( m_faceName , qdFontName ); m_macFontFamily = FMGetFontFamilyFromName( qdFontName ); + if ( m_macFontFamily == kInvalidFontFamily ) + { + wxLogDebug( wxT("ATSFontFamilyFindFromName failed for %s"), m_faceName.c_str() ); + m_macFontFamily = GetAppFont(); + } #endif } } @@ -281,8 +290,16 @@ void wxFontRefData::MacFindFont() { wxMacCFStringHolder cf( m_faceName, wxLocale::GetSystemEncoding() ); ATSFontFamilyRef atsfamily = ATSFontFamilyFindFromName( cf , kATSOptionFlagsDefault ); - wxASSERT_MSG( atsfamily != (ATSFontFamilyRef) -1 , wxT("ATSFontFamilyFindFromName failed") ); - m_macFontFamily = FMGetFontFamilyFromATSFontFamilyRef( atsfamily ); + + // ATSFontFamilyRef is an unsigned type, so check against max + // for an invalid value, not -1. + if ( atsfamily == 0xffffffff ) + { + wxLogDebug( wxT("ATSFontFamilyFindFromName failed for ") + m_faceName ); + m_macFontFamily = GetAppFont(); + } + else + m_macFontFamily = FMGetFontFamilyFromATSFontFamilyRef( atsfamily ); } } @@ -528,6 +545,20 @@ int wxFont::GetPointSize() const return M_FONTDATA->m_pointSize; } +wxSize wxFont::GetPixelSize() const +{ +#if wxUSE_GRAPHICS_CONTEXT + // TODO: consider caching the value + wxGraphicsContext* dc = wxGraphicsContext::CreateFromNative((CGContextRef) NULL); + dc->SetFont(*(wxFont *)this,*wxBLACK); + wxDouble width, height = 0; + dc->GetTextExtent( wxT("g"), &width, &height, NULL, NULL); + return wxSize((int)width, (int)height); +#else + return wxFontBase::GetPixelSize(); +#endif +} + int wxFont::GetFamily() const { wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );