X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d7ae4a62645d369fbd6b8b5f3f0e12ee86536da1..8244507f687f59a6493948cc4482ee19f82e66c5:/src/common/fontmgrcmn.cpp?ds=sidebyside diff --git a/src/common/fontmgrcmn.cpp b/src/common/fontmgrcmn.cpp index 6a5d0683ec..6ecd7e610e 100644 --- a/src/common/fontmgrcmn.cpp +++ b/src/common/fontmgrcmn.cpp @@ -24,9 +24,15 @@ WX_DECLARE_LIST(wxFontInstance, wxFontInstanceList); WX_DEFINE_LIST(wxFontInstanceList) WX_DEFINE_LIST(wxFontBundleList) + WX_DECLARE_HASH_MAP(wxString, wxFontBundle*, wxStringHash, wxStringEqual, - wxFontBundleHash); + wxFontBundleHashBase); +// in STL build, hash class is typedef to a template, so it can't be forward +// declared, as we do; solve it by having a dummy class: +class wxFontBundleHash : public wxFontBundleHashBase +{ +}; // ============================================================================ // implementation @@ -63,19 +69,16 @@ void wxFontFaceBase::Release() wxFontInstance *wxFontFaceBase::GetFontInstance(float ptSize, bool aa) { - wxASSERT_MSG( m_refCnt > 0, _T("font library not loaded!") ); - - wxFontInstance *i; - wxFontInstanceList::Node *node; + wxASSERT_MSG( m_refCnt > 0, wxT("font library not loaded!") ); - for ( node = m_instances->GetFirst(); node; node = node->GetNext() ) + for ( wxFontInstanceList::const_iterator i = m_instances->begin(); + i != m_instances->end(); ++i ) { - i = node->GetData(); - if ( i->GetPointSize() == ptSize && i->IsAntiAliased() == aa ) - return i; + if ( (*i)->GetPointSize() == ptSize && (*i)->IsAntiAliased() == aa ) + return *i; } - i = CreateFontInstance(ptSize, aa); + wxFontInstance *i = CreateFontInstance(ptSize, aa); m_instances->Append(i); return i; } @@ -100,7 +103,7 @@ wxFontFace *wxFontBundleBase::GetFace(FaceType type) const { wxFontFace *f = m_faces[type]; - wxCHECK_MSG( f, NULL, _T("no such face in font bundle") ); + wxCHECK_MSG( f, NULL, wxT("no such face in font bundle") ); f->Acquire(); @@ -110,8 +113,9 @@ wxFontFace *wxFontBundleBase::GetFace(FaceType type) const wxFontFace * wxFontBundleBase::GetFaceForFont(const wxFontMgrFontRefData& font) const { - wxASSERT_MSG( font.GetFaceName().empty() || font.GetFaceName() == GetName(), - _T("calling GetFaceForFont for incompatible font") ); + wxASSERT_MSG( font.GetFaceName().empty() || + GetName().CmpNoCase(font.GetFaceName()) == 0, + wxT("calling GetFaceForFont for incompatible font") ); int type = FaceType_Regular; @@ -129,13 +133,15 @@ wxFontBundleBase::GetFaceForFont(const wxFontMgrFontRefData& font) const if ( !HasFace((FaceType)type) ) { + // if we can't get the exact font requested, substitute it with + // some other variant: for (int i = 0; i < FaceType_Max; i++) { if ( HasFace((FaceType)i) ) return GetFace((FaceType)i); } - wxFAIL_MSG( _T("no face") ); + wxFAIL_MSG( wxT("no face") ); return NULL; } @@ -219,19 +225,15 @@ void wxFontsManagerBase::AddBundle(wxFontBundle *bundle) // ---------------------------------------------------------------------------- wxFontMgrFontRefData::wxFontMgrFontRefData(int size, - int family, - int style, - int weight, + wxFontFamily family, + wxFontStyle style, + wxFontWeight weight, bool underlined, const wxString& faceName, wxFontEncoding encoding) { - if ( family == wxDEFAULT ) - family = wxSWISS; - if ( style == wxDEFAULT ) - style = wxNORMAL; - if ( weight == wxDEFAULT ) - weight = wxNORMAL; + if ( family == wxFONTFAMILY_DEFAULT ) + family = wxFONTFAMILY_SWISS; if ( size == wxDEFAULT ) size = 12; @@ -243,8 +245,6 @@ wxFontMgrFontRefData::wxFontMgrFontRefData(int size, m_info.underlined = underlined; m_info.encoding = encoding; - m_noAA = false; - m_fontFace = NULL; m_fontBundle = NULL; m_fontValid = false; @@ -253,7 +253,6 @@ wxFontMgrFontRefData::wxFontMgrFontRefData(int size, wxFontMgrFontRefData::wxFontMgrFontRefData(const wxFontMgrFontRefData& data) { m_info = data.m_info; - m_noAA = data.m_noAA; m_fontFace = data.m_fontFace; m_fontBundle = data.m_fontBundle; @@ -279,7 +278,7 @@ wxFontMgrFontRefData::GetFontInstance(float scale, bool antialiased) const { wxConstCast(this, wxFontMgrFontRefData)->EnsureValidFont(); return m_fontFace->GetFontInstance(m_info.pointSize * scale, - antialiased && !m_noAA); + antialiased); } void wxFontMgrFontRefData::SetPointSize(int pointSize) @@ -288,21 +287,21 @@ void wxFontMgrFontRefData::SetPointSize(int pointSize) m_fontValid = false; } -void wxFontMgrFontRefData::SetFamily(int family) +void wxFontMgrFontRefData::SetFamily(wxFontFamily family) { - m_info.family = (wxFontFamily)family; + m_info.family = family; m_fontValid = false; } -void wxFontMgrFontRefData::SetStyle(int style) +void wxFontMgrFontRefData::SetStyle(wxFontStyle style) { - m_info.style = (wxFontStyle)style; + m_info.style = style; m_fontValid = false; } -void wxFontMgrFontRefData::SetWeight(int weight) +void wxFontMgrFontRefData::SetWeight(wxFontWeight weight) { - m_info.weight = (wxFontWeight)weight; + m_info.weight = weight; m_fontValid = false; } @@ -324,12 +323,6 @@ void wxFontMgrFontRefData::SetEncoding(wxFontEncoding encoding) m_fontValid = false; } -void wxFontMgrFontRefData::SetNoAntiAliasing(bool no) -{ - m_noAA = no; -} - - void wxFontMgrFontRefData::EnsureValidFont() { if ( !m_fontValid )