X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5c33522fca7cddc441a316f5b9fb50d7685435ba..f8d0234d39c66f3d1d7fc2346562cb96c8c7be20:/src/osx/carbon/font.cpp diff --git a/src/osx/carbon/font.cpp b/src/osx/carbon/font.cpp index bc6040b5af..3d295d4bb9 100644 --- a/src/osx/carbon/font.cpp +++ b/src/osx/carbon/font.cpp @@ -43,7 +43,7 @@ class WXDLLEXPORT wxFontRefData: public wxGDIRefData public: wxFontRefData() { - Init(10, wxDEFAULT, wxNORMAL, wxNORMAL, + Init(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT("applicationfont"), wxFONTENCODING_DEFAULT); } @@ -54,9 +54,9 @@ public: } wxFontRefData(int size, - int family, - int style, - int weight, + wxFontFamily family, + wxFontStyle style, + wxFontWeight weight, bool underlined, const wxString& faceName, wxFontEncoding encoding) @@ -84,32 +84,32 @@ public: int GetPointSize() const { return m_pointSize; } - void SetFamily( int family ) + void SetFamily( wxFontFamily family ) { m_family = family; MacInvalidateNativeFont(); } - int GetFamily() const { return m_family; } + wxFontFamily GetFamily() const { return m_family; } - void SetStyle( int style ) + void SetStyle( wxFontStyle style ) { m_style = style; MacInvalidateNativeFont(); } - int GetStyle() const { return m_style; } + wxFontStyle GetStyle() const { return m_style; } - void SetWeight( int weight ) + void SetWeight( wxFontWeight weight ) { m_weight = weight; MacInvalidateNativeFont(); } - int GetWeight() const { return m_weight; } + wxFontWeight GetWeight() const { return m_weight; } void SetUnderlined( bool u ) { @@ -142,9 +142,9 @@ public: protected: // common part of all ctors void Init(int size, - int family, - int style, - int weight, + wxFontFamily family, + wxFontStyle style, + wxFontWeight weight, bool underlined, const wxString& faceName, wxFontEncoding encoding); @@ -154,9 +154,9 @@ protected: #endif // font characterstics int m_pointSize; - int m_family; - int m_style; - int m_weight; + wxFontFamily m_family; + wxFontStyle m_style; + wxFontWeight m_weight; bool m_underlined; wxString m_faceName; wxFontEncoding m_encoding; @@ -202,9 +202,9 @@ public: // ---------------------------------------------------------------------------- void wxFontRefData::Init(int pointSize, - int family, - int style, - int weight, + wxFontFamily family, + wxFontStyle style, + wxFontWeight weight, bool underlined, const wxString& faceName, wxFontEncoding encoding) @@ -345,7 +345,7 @@ wxFontRefData::wxFontRefData( CTFontDescriptorRef fontdescriptor, int size ) void wxFontRefData::Init( CTFontRef font ) { - Init(10, wxDEFAULT, wxNORMAL, wxNORMAL, + Init(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT("applicationfont"), wxFONTENCODING_DEFAULT); m_ctFont.reset( font ); @@ -359,7 +359,7 @@ void wxFontRefData::MacFindFont() #if wxOSX_USE_CORE_TEXT if ( UMAGetSystemVersion() >= 0x1050 ) { - if ( m_faceName.empty() && m_family == wxDEFAULT ) + if ( m_faceName.empty() && m_family == wxFONTFAMILY_DEFAULT ) { m_ctFont.reset(CTFontCreateUIFontForLanguage( kCTFontSystemFontType, 0.0, NULL )); } @@ -371,9 +371,9 @@ void wxFontRefData::MacFindFont() m_pointSize = CTFontGetSize(m_ctFont) ; CTFontSymbolicTraits traits = CTFontGetSymbolicTraits( m_ctFont ); if ( traits & kCTFontItalicTrait ) - m_style = wxITALIC; + m_style = wxFONTSTYLE_ITALIC; if ( traits & kCTFontBoldTrait ) - m_weight = wxBOLD ; + m_weight = wxFONTWEIGHT_BOLD ; } else { @@ -381,22 +381,22 @@ void wxFontRefData::MacFindFont() { switch ( m_family ) { - case wxSCRIPT : - case wxROMAN : - case wxDECORATIVE : + case wxFONTFAMILY_SCRIPT : + case wxFONTFAMILY_ROMAN : + case wxFONTFAMILY_DECORATIVE : m_faceName = wxT("Times"); break ; - case wxSWISS : + case wxFONTFAMILY_SWISS : m_faceName = wxT("Helvetica"); break ; - case wxMODERN : - case wxTELETYPE: + case wxFONTFAMILY_MODERN : + case wxFONTFAMILY_TELETYPE: m_faceName = wxT("Courier"); - if ( m_style == wxITALIC && m_weight == wxNORMAL ) + if ( m_style == wxFONTSTYLE_ITALIC && m_weight == wxFONTWEIGHT_NORMAL ) { - m_style = wxITALIC; + m_style = wxFONTSTYLE_ITALIC; } break ; @@ -406,17 +406,17 @@ void wxFontRefData::MacFindFont() } } - + CTFontSymbolicTraits traits = 0; - if (m_weight == wxBOLD) + if (m_weight == wxFONTWEIGHT_BOLD) traits |= kCTFontBoldTrait; - if (m_style == wxITALIC || m_style == wxSLANT) + if (m_style == wxFONTSTYLE_ITALIC || m_style == wxFONTSTYLE_SLANT) traits |= kCTFontItalicTrait; - + // use font caching 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 ) @@ -424,12 +424,12 @@ void wxFontRefData::MacFindFont() // QD selection algorithm is the fastest by orders of magnitude on 10.5 if ( m_faceName.IsAscii() ) { - uint8 qdstyle = 0; - if (m_weight == wxBOLD) + uint8_t qdstyle = 0; + if (m_weight == wxFONTWEIGHT_BOLD) qdstyle |= bold; - if (m_style == wxITALIC || m_style == wxSLANT) + if (m_style == wxFONTSTYLE_ITALIC || m_style == wxFONTSTYLE_SLANT) qdstyle |= italic; - + Str255 qdFontName ; wxMacStringToPascal( m_faceName , qdFontName ); m_ctFont.reset( CTFontCreateWithQuickdrawInstance(qdFontName, 0 , qdstyle, m_pointSize) ); @@ -454,7 +454,7 @@ void wxFontRefData::MacFindFont() // TODO further fallbacks, synthesizing bold and italic, trying direct PostScript names etc } } - + fontcache[ std::wstring(lookupnameWithSize.wc_str()) ] = m_ctFont; #if 1 // debugging coretext font matching CTFontSymbolicTraits received = CTFontGetSymbolicTraits( m_ctFont ) & 0x03; @@ -473,7 +473,7 @@ void wxFontRefData::MacFindFont() CFShow( dict ); CFRelease( dict ); } -#endif +#endif } } @@ -509,8 +509,8 @@ void wxFontRefData::MacFindFont() &fmfont , &atsuSize , &kHorizontal, - (m_weight == wxBOLD) ? &kTrue : &kFalse , - (m_style == wxITALIC || m_style == wxSLANT) ? &kTrue : &kFalse , + (m_weight == wxFONTWEIGHT_BOLD) ? &kTrue : &kFalse , + (m_style == wxFONTSTYLE_ITALIC || m_style == wxFONTSTYLE_SLANT) ? &kTrue : &kFalse , (m_underlined) ? &kTrue : &kFalse , }; @@ -541,11 +541,11 @@ void wxFontRefData::MacFindFont() m_macFontStyle = style ; m_faceName = wxMacMakeStringFromPascal( qdFontName ); if ( m_macFontStyle & bold ) - m_weight = wxBOLD ; + m_weight = wxFONTWEIGHT_BOLD ; else - m_weight = wxNORMAL ; + m_weight = wxFONTWEIGHT_NORMAL ; if ( m_macFontStyle & italic ) - m_style = wxITALIC ; + m_style = wxFONTSTYLE_ITALIC ; if ( m_macFontStyle & underline ) m_underlined = true ; m_pointSize = m_macFontSize ; @@ -555,7 +555,7 @@ void wxFontRefData::MacFindFont() { if ( m_faceName.empty() ) { - if ( m_family == wxDEFAULT ) + if ( m_family == wxFONTFAMILY_DEFAULT ) { m_macFontFamily = GetAppFont(); FMGetFontFamilyName(m_macFontFamily,qdFontName); @@ -565,18 +565,18 @@ void wxFontRefData::MacFindFont() { switch ( m_family ) { - case wxSCRIPT : - case wxROMAN : - case wxDECORATIVE : + case wxFONTFAMILY_SCRIPT : + case wxFONTFAMILY_ROMAN : + case wxFONTFAMILY_DECORATIVE : m_faceName = wxT("Times"); break ; - case wxSWISS : + case wxFONTFAMILY_SWISS : m_faceName = wxT("Helvetica"); break ; - case wxMODERN : - case wxTELETYPE: + case wxFONTFAMILY_MODERN : + case wxFONTFAMILY_TELETYPE: m_faceName = wxT("Courier"); break ; @@ -614,9 +614,9 @@ void wxFontRefData::MacFindFont() } m_macFontStyle = 0; - if (m_weight == wxBOLD) + if (m_weight == wxFONTWEIGHT_BOLD) m_macFontStyle |= bold; - if (m_style == wxITALIC || m_style == wxSLANT) + if (m_style == wxFONTSTYLE_ITALIC || m_style == wxFONTSTYLE_SLANT) m_macFontStyle |= italic; if (m_underlined) m_macFontStyle |= underline; @@ -711,12 +711,12 @@ wxFont::wxFont(const wxString& fontdesc) } bool wxFont::Create(int pointSize, - int family, - int style, - int weight, - bool underlined, - const wxString& faceName, - wxFontEncoding encoding) + wxFontFamily family, + wxFontStyle style, + wxFontWeight weight, + bool underlined, + const wxString& faceName, + wxFontEncoding encoding) { UnRef(); @@ -754,7 +754,7 @@ bool wxFont::MacCreateFromCTFontDescriptor( const void * ctFontDescriptor , int #endif -#if wxOSX_USE_CARBON +#if wxOSX_USE_ATSU_TEXT bool wxFont::MacCreateFromThemeFont(wxUint16 themeFontID) { #if wxOSX_USE_CORE_TEXT @@ -763,19 +763,17 @@ bool wxFont::MacCreateFromThemeFont(wxUint16 themeFontID) return MacCreateFromUIFont(HIThemeGetUIFontType(themeFontID)); } #endif -#if wxOSX_USE_ATSU_TEXT { UnRef(); m_refData = new wxFontRefData( - 12, wxDEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, + 12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString, wxFONTENCODING_DEFAULT ); M_FONTDATA->m_macThemeFontID = themeFontID ; RealizeResource(); return true; } -#endif return false; } #endif @@ -837,7 +835,7 @@ void wxFont::SetPointSize(int pointSize) RealizeResource(); } -void wxFont::SetFamily(int family) +void wxFont::SetFamily(wxFontFamily family) { Unshare(); @@ -846,7 +844,7 @@ void wxFont::SetFamily(int family) RealizeResource(); } -void wxFont::SetStyle(int style) +void wxFont::SetStyle(wxFontStyle style) { Unshare(); @@ -855,7 +853,7 @@ void wxFont::SetStyle(int style) RealizeResource(); } -void wxFont::SetWeight(int weight) +void wxFont::SetWeight(wxFontWeight weight) { Unshare(); @@ -921,23 +919,23 @@ wxSize wxFont::GetPixelSize() const #endif } -int wxFont::GetFamily() const +wxFontFamily wxFont::GetFamily() const { - wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); + wxCHECK_MSG( M_FONTDATA != NULL , wxFONTFAMILY_MAX, wxT("invalid font") ); return M_FONTDATA->GetFamily(); } -int wxFont::GetStyle() const +wxFontStyle wxFont::GetStyle() const { - wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); + wxCHECK_MSG( M_FONTDATA != NULL , wxFONTSTYLE_MAX, wxT("invalid font") ); return M_FONTDATA->GetStyle() ; } -int wxFont::GetWeight() const +wxFontWeight wxFont::GetWeight() const { - wxCHECK_MSG( M_FONTDATA != NULL , 0, wxT("invalid font") ); + wxCHECK_MSG( M_FONTDATA != NULL , wxFONTWEIGHT_MAX, wxT("invalid font") ); return M_FONTDATA->GetWeight(); }