X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/189e08b45ac97195a4f975fe8507439a8739e5fa..124193837f27d1fb75b9607f0e005b9897d1e320:/src/common/fontcmn.cpp diff --git a/src/common/fontcmn.cpp b/src/common/fontcmn.cpp index c1eec3bd25..1a8b50c376 100644 --- a/src/common/fontcmn.cpp +++ b/src/common/fontcmn.cpp @@ -32,6 +32,9 @@ #include "wx/font.h" #endif // WX_PRECOMP +#include "wx/gdicmn.h" +#include "wx/fontutil.h" // for wxNativeFontInfo + #include "wx/tokenzr.h" // ============================================================================ @@ -62,28 +65,38 @@ wxFont *wxFontBase::New(const wxNativeFontInfo& info) return new wxFont(info); } -wxNativeFontInfo wxFontBase::GetNativeFontInfo() const +/* static */ +wxFont *wxFontBase::New(const wxString& strNativeFontDesc) { -#if !defined(__WXGTK__) wxNativeFontInfo fontInfo; + if ( !fontInfo.FromString(strNativeFontDesc) ) + return new wxFont(*wxNORMAL_FONT); + + return New(fontInfo); +} - fontInfo.pointSize = GetPointSize(); - fontInfo.family = GetFamily(); - fontInfo.style = GetStyle(); - fontInfo.weight = GetWeight(); - fontInfo.underlined = GetUnderlined(); - fontInfo.faceName = GetFaceName(); - fontInfo.encoding = GetEncoding(); +wxNativeFontInfo *wxFontBase::GetNativeFontInfo() const +{ +#if !defined(__WXGTK__) && !defined(__WXMSW__) + wxNativeFontInfo *fontInfo = new wxNativeFontInfo; + + fontInfo->pointSize = GetPointSize(); + fontInfo->family = GetFamily(); + fontInfo->style = GetStyle(); + fontInfo->weight = GetWeight(); + fontInfo->underlined = GetUnderlined(); + fontInfo->faceName = GetFaceName(); + fontInfo->encoding = GetEncoding(); return fontInfo; #else - return wxNullNativeFontInfo; + return (wxNativeFontInfo *)NULL; #endif } void wxFontBase::SetNativeFontInfo(const wxNativeFontInfo& info) { -#if !defined(__WXGTK__) +#if !defined(__WXGTK__) && !defined(__WXMSW__) SetPointSize(info.pointSize); SetFamily(info.family); SetStyle(info.style); @@ -91,9 +104,24 @@ void wxFontBase::SetNativeFontInfo(const wxNativeFontInfo& info) SetUnderlined(info.underlined); SetFaceName(info.faceName); SetEncoding(info.encoding); +#else + (void)info; #endif } +wxString wxFontBase::GetNativeFontInfoDesc() const +{ + wxString fontDesc; + wxNativeFontInfo *fontInfo = GetNativeFontInfo(); + if ( fontInfo ) + { + fontDesc = fontInfo->ToString(); + delete fontInfo; + } + + return fontDesc; +} + wxFont& wxFont::operator=(const wxFont& font) { if ( this != &font ) @@ -102,15 +130,26 @@ wxFont& wxFont::operator=(const wxFont& font) return (wxFont &)*this; } -// VZ: is it correct to compare pointers and not the contents? (FIXME) bool wxFontBase::operator==(const wxFont& font) const { - return GetFontData() == font.GetFontData(); + // 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() || + ( + Ok() == font.Ok() && + GetPointSize() == font.GetPointSize() && + GetFamily() == font.GetFamily() && + GetStyle() == font.GetStyle() && + GetWeight() == font.GetWeight() && + GetUnderlined() == font.GetUnderlined() && + GetFaceName() == font.GetFaceName() && + GetEncoding() == font.GetEncoding() + ); } bool wxFontBase::operator!=(const wxFont& font) const { - return GetFontData() != font.GetFontData(); + return !(*this == font); } wxString wxFontBase::GetFamilyString() const @@ -155,7 +194,7 @@ wxString wxFontBase::GetWeightString() const } } -#if !defined(__WXGTK__) +#if !defined(__WXGTK__) && !defined(__WXMSW__) // ---------------------------------------------------------------------------- // wxNativeFontInfo @@ -164,7 +203,7 @@ wxString wxFontBase::GetWeightString() const // These are the generic forms of FromString()/ToString. // // convert to/from the string representation: format is -// pointsize;family;style;weight;underlined;facename;encoding +// version;pointsize;family;style;weight;underlined;facename;encoding bool wxNativeFontInfo::FromString(const wxString& s) { @@ -173,6 +212,11 @@ bool wxNativeFontInfo::FromString(const wxString& s) wxStringTokenizer tokenizer(s, _T(";")); wxString token = tokenizer.GetNextToken(); + // + // Ignore the version for now + // + + token = tokenizer.GetNextToken(); if ( !token.ToLong(&l) ) return FALSE; pointSize = (int)l; @@ -213,7 +257,8 @@ wxString wxNativeFontInfo::ToString() const { wxString s; - s.Printf("%d;%d;%d;%d;%d;%s;%d", + s.Printf(_T("%d;%d;%d;%d;%d;%d;%s;%d"), + 0, // version pointSize, family, style, @@ -225,5 +270,5 @@ wxString wxNativeFontInfo::ToString() const return s; } -#endif +#endif // generic wxNativeFontInfo implementation