X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/70f70818c22dfa19fdec8f21a496d2a535333e0d..bca8c756a30d54ee4fade96a091d78ad8988fd23:/src/common/fontcmn.cpp?ds=sidebyside diff --git a/src/common/fontcmn.cpp b/src/common/fontcmn.cpp index 96407bbfd6..b10870a927 100644 --- a/src/common/fontcmn.cpp +++ b/src/common/fontcmn.cpp @@ -45,6 +45,32 @@ #include "wx/tokenzr.h" +// debugger helper: this function can be called from a debugger to show what +// the date really is +extern const char *wxDumpFont(const wxFont *font) +{ + static char buf[256]; + + const wxFontWeight weight = font->GetWeight(); + + wxString s; + s.Printf(wxS("%s-%s-%s-%d-%d"), + font->GetFaceName(), + weight == wxFONTWEIGHT_NORMAL + ? _T("normal") + : weight == wxFONTWEIGHT_BOLD + ? _T("bold") + : _T("light"), + font->GetStyle() == wxFONTSTYLE_NORMAL + ? _T("regular") + : _T("italic"), + font->GetPointSize(), + font->GetEncoding()); + + wxStrlcpy(buf, s.mb_str(), WXSIZEOF(buf)); + return buf; +} + // ============================================================================ // implementation // ============================================================================ @@ -349,6 +375,7 @@ wxString wxFontBase::GetFamilyString() const case wxFONTFAMILY_SWISS: return "wxFONTFAMILY_SWISS"; case wxFONTFAMILY_MODERN: return "wxFONTFAMILY_MODERN"; case wxFONTFAMILY_TELETYPE: return "wxFONTFAMILY_TELETYPE"; + case wxFONTFAMILY_UNKNOWN: return "wxFONTFAMILY_UNKNOWN"; default: return "wxFONTFAMILY_DEFAULT"; } } @@ -586,7 +613,7 @@ void wxNativeFontInfo::SetEncoding(wxFontEncoding encoding_) // format there anyhow (but there is a well-defined standard for X11 fonts used // by wxGTK and wxMotif) -#if defined(wxNO_NATIVE_FONTINFO) || defined(__WXMSW__) || defined (__WXPM__) +#if defined(wxNO_NATIVE_FONTINFO) || defined(__WXMSW__) || defined (__WXPM__) || defined(__WXOSX__) wxString wxNativeFontInfo::ToUserString() const { @@ -636,7 +663,20 @@ wxString wxNativeFontInfo::ToUserString() const wxString face = GetFaceName(); if ( !face.empty() ) { - desc << _T(' ') << face; + if (face.Contains(' ') || face.Contains(';') || face.Contains(',')) + { + face.Replace("'", ""); + // eventually remove quote characters: most systems do not + // allow them in a facename anyway so this usually does nothing + + // make it possible for FromUserString() function to understand + // that the different words which compose this facename are + // not different adjectives or other data but rather all parts + // of the facename + desc << _T(" '") << face << _("'"); + } + else + desc << _T(' ') << face; } int size = GetPointSize(); @@ -661,10 +701,20 @@ bool wxNativeFontInfo::FromUserString(const wxString& s) // reset to the default state Init(); + // ToUserString() will quote the facename if it contains spaces, commas + // or semicolons: we must be able to understand that quoted text is + // a single token: + wxString toparse(s); + /* + wxString::iterator i = toparse.find("'"); + if (i != wxString::npos) + { + for (; *i != '\'' && *i != toparse.end(); i++) + ; + }*/ + // parse a more or less free form string - // - // TODO: we should handle at least the quoted facenames - wxStringTokenizer tokenizer(s, _T(";, "), wxTOKEN_STRTOK); + wxStringTokenizer tokenizer(toparse, _T(";, "), wxTOKEN_STRTOK); wxString face; unsigned long size; @@ -672,6 +722,7 @@ bool wxNativeFontInfo::FromUserString(const wxString& s) #if wxUSE_FONTMAP bool encodingfound = false; #endif + bool insideQuotes = false; while ( tokenizer.HasMoreTokens() ) { @@ -679,8 +730,36 @@ bool wxNativeFontInfo::FromUserString(const wxString& s) // normalize it token.Trim(true).Trim(false).MakeLower(); + if (insideQuotes) + { + if (token.StartsWith("'") || + token.EndsWith("'")) + { + insideQuotes = false; + + // add this last token to the facename: + face += " " + token; + + // normalize facename: + face = face.Trim(true).Trim(false); + face.Replace("'", ""); + + continue; + } + } + else + { + if (token.StartsWith("'")) + insideQuotes = true; + } // look for the known tokens + if ( insideQuotes ) + { + // only the facename may be quoted: + face += " " + token; + continue; + } if ( token == _T("underlined") || token == _("underlined") ) { SetUnderlined(true);