X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7456f3828a7dda585e6ecb04b738aa81bb0b0428..f0875501313903140a41dca0ba6ee2d85ed0536c:/src/common/fontcmn.cpp diff --git a/src/common/fontcmn.cpp b/src/common/fontcmn.cpp index f0d3ccf9c4..8a9063f5b3 100644 --- a/src/common/fontcmn.cpp +++ b/src/common/fontcmn.cpp @@ -31,10 +31,9 @@ #include "wx/intl.h" #include "wx/dcscreen.h" #include "wx/log.h" + #include "wx/gdicmn.h" #endif // WX_PRECOMP -#include "wx/gdicmn.h" - #if defined(__WXMSW__) #include "wx/msw/private.h" // includes windows.h for LOGFONT #include "wx/msw/winundef.h" @@ -268,7 +267,7 @@ wxString wxFontBase::GetNativeFontInfoDesc() const if ( fontInfo ) { fontDesc = fontInfo->ToString(); - wxASSERT_MSG(!fontDesc.IsEmpty(), wxT("This should be a non-empty string!")); + wxASSERT_MSG(!fontDesc.empty(), wxT("This should be a non-empty string!")); } else { @@ -285,7 +284,7 @@ wxString wxFontBase::GetNativeFontInfoUserDesc() const if ( fontInfo ) { fontDesc = fontInfo->ToUserString(); - wxASSERT_MSG(!fontDesc.IsEmpty(), wxT("This should be a non-empty string!")); + wxASSERT_MSG(!fontDesc.empty(), wxT("This should be a non-empty string!")); } else { @@ -304,7 +303,6 @@ bool wxFontBase::SetNativeFontInfo(const wxString& info) return true; } - UnRef(); return false; } @@ -317,7 +315,6 @@ bool wxFontBase::SetNativeFontInfoUserDesc(const wxString& info) return true; } - UnRef(); return false; } @@ -325,10 +322,16 @@ bool wxFontBase::operator==(const wxFont& font) const { // either it is the same font, i.e. they share the same common data or they // have different ref datas but still describe the same font - return GetFontData() == font.GetFontData() || + return IsSameAs(font) || ( Ok() == font.Ok() && GetPointSize() == font.GetPointSize() && + // in wxGTK1 GetPixelSize() calls GetInternalFont() which uses + // operator==() resulting in infinite recursion so we can't use it + // in that port +#if !defined(__WXGTK__) || defined(__WXGTK20__) + GetPixelSize() == font.GetPixelSize() && +#endif GetFamily() == font.GetFamily() && GetStyle() == font.GetStyle() && GetWeight() == font.GetWeight() && @@ -385,13 +388,17 @@ wxString wxFontBase::GetWeightString() const } } -bool wxFontBase::SetFaceName(const wxString &facename) +bool wxFontBase::SetFaceName(const wxString& facename) { +#if wxUSE_FONTENUM if (!wxFontEnumerator::IsValidFacename(facename)) { UnRef(); // make Ok() return false return false; } +#else // !wxUSE_FONTENUM + wxUnusedVar(facename); +#endif // wxUSE_FONTENUM/!wxUSE_FONTENUM return true; } @@ -402,8 +409,9 @@ bool wxFontBase::SetFaceName(const wxString &facename) // ---------------------------------------------------------------------------- // Up to now, there are no native implementations of this function: -void wxNativeFontInfo::SetFaceName(const wxArrayString &facenames) +void wxNativeFontInfo::SetFaceName(const wxArrayString& facenames) { +#if wxUSE_FONTENUM for (size_t i=0; i < facenames.GetCount(); i++) { if (wxFontEnumerator::IsValidFacename(facenames[i])) @@ -417,6 +425,9 @@ void wxNativeFontInfo::SetFaceName(const wxArrayString &facenames) wxString validfacename = wxFontEnumerator::GetFacenames().Item(0); wxLogTrace(wxT("font"), wxT("Falling back to '%s'"), validfacename.c_str()); SetFaceName(validfacename); +#else // !wxUSE_FONTENUM + SetFaceName(facenames[0]); +#endif // wxUSE_FONTENUM/!wxUSE_FONTENUM } @@ -666,7 +677,10 @@ bool wxNativeFontInfo::FromUserString(const wxString& s) wxString face; unsigned long size; - bool weightfound = false, pointsizefound = false, encodingfound = false; + bool weightfound = false, pointsizefound = false; +#if wxUSE_FONTMAP + bool encodingfound = false; +#endif while ( tokenizer.HasMoreTokens() ) { @@ -738,9 +752,15 @@ bool wxNativeFontInfo::FromUserString(const wxString& s) // NB: the check on the facename is implemented in wxFontBase::SetFaceName // and not in wxNativeFontInfo::SetFaceName thus we need to explicitely // call here wxFontEnumerator::IsValidFacename - if (!wxFontEnumerator::IsValidFacename(face) || - !SetFaceName(face)) + if ( +#if wxUSE_FONTENUM + !wxFontEnumerator::IsValidFacename(face) || +#endif // wxUSE_FONTENUM + !SetFaceName(face) ) + { SetFaceName(wxNORMAL_FONT->GetFaceName()); + } + face.clear(); } } @@ -751,9 +771,14 @@ bool wxNativeFontInfo::FromUserString(const wxString& s) // NB: the check on the facename is implemented in wxFontBase::SetFaceName // and not in wxNativeFontInfo::SetFaceName thus we need to explicitely // call here wxFontEnumerator::IsValidFacename - if (!wxFontEnumerator::IsValidFacename(face) || - !SetFaceName(face)) - SetFaceName(wxNORMAL_FONT->GetFaceName()); + if ( +#if wxUSE_FONTENUM + !wxFontEnumerator::IsValidFacename(face) || +#endif // wxUSE_FONTENUM + !SetFaceName(face) ) + { + SetFaceName(wxNORMAL_FONT->GetFaceName()); + } } // set point size to default value if size was not given @@ -774,3 +799,26 @@ bool wxNativeFontInfo::FromUserString(const wxString& s) } #endif // generic or wxMSW or wxOS2 + + +// wxFont <-> wxString utilities, used by wxConfig +wxString wxToString(const wxFontBase& font) +{ + return font.IsOk() ? font.GetNativeFontInfoDesc() + : wxString(); +} + +bool wxFromString(const wxString& str, wxFontBase *font) +{ + wxCHECK_MSG( font, false, _T("NULL output parameter") ); + + if ( str.empty() ) + { + *font = wxNullFont; + return true; + } + + return font->SetNativeFontInfo(str); +} + +