implement quoting for the facename and parsing of quoted facenames in wxNativeFontInfo::To/FromUserString()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59840 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -662,7 +662,20 @@ wxString wxNativeFontInfo::ToUserString() const
|
|||||||
wxString face = GetFaceName();
|
wxString face = GetFaceName();
|
||||||
if ( !face.empty() )
|
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();
|
int size = GetPointSize();
|
||||||
@@ -687,10 +700,20 @@ bool wxNativeFontInfo::FromUserString(const wxString& s)
|
|||||||
// reset to the default state
|
// reset to the default state
|
||||||
Init();
|
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
|
// parse a more or less free form string
|
||||||
//
|
wxStringTokenizer tokenizer(toparse, _T(";, "), wxTOKEN_STRTOK);
|
||||||
// TODO: we should handle at least the quoted facenames
|
|
||||||
wxStringTokenizer tokenizer(s, _T(";, "), wxTOKEN_STRTOK);
|
|
||||||
|
|
||||||
wxString face;
|
wxString face;
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
@@ -698,6 +721,7 @@ bool wxNativeFontInfo::FromUserString(const wxString& s)
|
|||||||
#if wxUSE_FONTMAP
|
#if wxUSE_FONTMAP
|
||||||
bool encodingfound = false;
|
bool encodingfound = false;
|
||||||
#endif
|
#endif
|
||||||
|
bool insideQuotes = false;
|
||||||
|
|
||||||
while ( tokenizer.HasMoreTokens() )
|
while ( tokenizer.HasMoreTokens() )
|
||||||
{
|
{
|
||||||
@@ -705,8 +729,36 @@ bool wxNativeFontInfo::FromUserString(const wxString& s)
|
|||||||
|
|
||||||
// normalize it
|
// normalize it
|
||||||
token.Trim(true).Trim(false).MakeLower();
|
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
|
// look for the known tokens
|
||||||
|
if ( insideQuotes )
|
||||||
|
{
|
||||||
|
// only the facename may be quoted:
|
||||||
|
face += " " + token;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if ( token == _T("underlined") || token == _("underlined") )
|
if ( token == _T("underlined") || token == _("underlined") )
|
||||||
{
|
{
|
||||||
SetUnderlined(true);
|
SetUnderlined(true);
|
||||||
|
Reference in New Issue
Block a user