X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/de6185e212ebc37ff11ff70278e3c4f68419b097..105fbe1ffa8968cb85fd2cac7192957e522d17ba:/src/mac/carbon/font.cpp diff --git a/src/mac/carbon/font.cpp b/src/mac/carbon/font.cpp index 666b85b5f7..fe8a315e25 100644 --- a/src/mac/carbon/font.cpp +++ b/src/mac/carbon/font.cpp @@ -16,11 +16,13 @@ #ifndef WX_PRECOMP #include "wx/string.h" #include "wx/utils.h" + #include "wx/intl.h" + #include "wx/gdicmn.h" + #include "wx/log.h" #endif #include "wx/fontutil.h" -#include "wx/gdicmn.h" -#include "wx/fontutil.h" +#include "wx/graphics.h" #include "wx/mac/private.h" @@ -153,6 +155,8 @@ public: wxNativeFontInfo m_info; }; +#define M_FONTDATA ((wxFontRefData*)m_refData) + // ============================================================================ // implementation @@ -219,8 +223,9 @@ void wxFontRefData::MacFindFont() if ( m_macFontStyle & underline ) m_underlined = true ; m_pointSize = m_macFontSize ; - +#ifndef __LP64__ m_macFontFamily = FMGetFontFamilyFromName( qdFontName ); +#endif } else { @@ -228,9 +233,11 @@ void wxFontRefData::MacFindFont() { if ( m_family == wxDEFAULT ) { +#ifndef __LP64__ m_macFontFamily = GetAppFont(); FMGetFontFamilyName(m_macFontFamily,qdFontName); m_faceName = wxMacMakeStringFromPascal( qdFontName ); +#endif } else { @@ -247,6 +254,7 @@ void wxFontRefData::MacFindFont() break ; case wxMODERN : + case wxTELETYPE: m_faceName = wxT("Monaco"); break ; @@ -254,21 +262,44 @@ void wxFontRefData::MacFindFont() m_faceName = wxT("Times"); break ; } +#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 } } else { +#ifndef __LP64__ if ( m_faceName == wxT("systemfont") ) m_macFontFamily = GetSysFont(); else if ( m_faceName == wxT("applicationfont") ) m_macFontFamily = GetAppFont(); else +#else + if ( m_faceName == wxT("systemfont") ) + m_faceName = wxT("Lucida Grande"); + else if ( m_faceName == wxT("applicationfont") ) + m_faceName = wxT("Lucida Grande"); +#endif { wxMacCFStringHolder cf( m_faceName, wxLocale::GetSystemEncoding() ); ATSFontFamilyRef atsfamily = ATSFontFamilyFindFromName( cf , kATSOptionFlagsDefault ); - 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 ); } } @@ -287,9 +318,10 @@ void wxFontRefData::MacFindFont() // ATSUFontID and FMFont are equivalent FMFontStyle intrinsicStyle = 0 ; +#ifndef __LP64__ status = FMGetFontFromFontFamilyInstance( m_macFontFamily , m_macFontStyle , &m_macATSUFontID , &intrinsicStyle); wxASSERT_MSG( status == noErr , wxT("couldn't get an ATSUFont from font family") ); - +#endif m_macATSUAdditionalQDStyles = m_macFontStyle & (~intrinsicStyle ); if ( m_macATSUStyle ) @@ -471,13 +503,15 @@ void wxFont::SetWeight(int weight) RealizeResource(); } -void wxFont::SetFaceName(const wxString& faceName) +bool wxFont::SetFaceName(const wxString& faceName) { Unshare(); M_FONTDATA->m_faceName = faceName; RealizeResource(); + + return wxFontBase::SetFaceName(faceName); } void wxFont::SetUnderlined(bool underlined) @@ -511,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 + wxFontBase::GetPixelSize(); +#endif +} + int wxFont::GetFamily() const { wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") );