Update wxNativeFontInfo::{To,From}String() after wxFont changes
Handle fractional point sizes and numeric weights in the custom string formats in the ports using those.
This commit is contained in:
@@ -747,6 +747,7 @@ void wxNativeFontInfo::SetPointSize(int pointsize)
|
|||||||
bool wxNativeFontInfo::FromString(const wxString& s)
|
bool wxNativeFontInfo::FromString(const wxString& s)
|
||||||
{
|
{
|
||||||
long l;
|
long l;
|
||||||
|
double d;
|
||||||
unsigned long version;
|
unsigned long version;
|
||||||
|
|
||||||
wxStringTokenizer tokenizer(s, wxT(";"));
|
wxStringTokenizer tokenizer(s, wxT(";"));
|
||||||
@@ -756,9 +757,11 @@ bool wxNativeFontInfo::FromString(const wxString& s)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
token = tokenizer.GetNextToken();
|
token = tokenizer.GetNextToken();
|
||||||
if ( !token.ToLong(&l) )
|
if ( !token.ToCDouble(&d) )
|
||||||
|
return false;
|
||||||
|
pointSize = static_cast<float>(d);
|
||||||
|
if ( static_cast<double>(pointSize) != d )
|
||||||
return false;
|
return false;
|
||||||
pointSize = (int)l;
|
|
||||||
|
|
||||||
token = tokenizer.GetNextToken();
|
token = tokenizer.GetNextToken();
|
||||||
if ( !token.ToLong(&l) )
|
if ( !token.ToLong(&l) )
|
||||||
@@ -773,7 +776,9 @@ bool wxNativeFontInfo::FromString(const wxString& s)
|
|||||||
token = tokenizer.GetNextToken();
|
token = tokenizer.GetNextToken();
|
||||||
if ( !token.ToLong(&l) )
|
if ( !token.ToLong(&l) )
|
||||||
return false;
|
return false;
|
||||||
weight = (wxFontWeight)l;
|
weight = ConvertFromLegacyWeightIfNecessary(l);
|
||||||
|
if ( weight <= wxFONTWEIGHT_INVALID || weight > wxFONTWEIGHT_MAX )
|
||||||
|
return false;
|
||||||
|
|
||||||
token = tokenizer.GetNextToken();
|
token = tokenizer.GetNextToken();
|
||||||
if ( !token.ToLong(&l) )
|
if ( !token.ToLong(&l) )
|
||||||
@@ -807,12 +812,12 @@ wxString wxNativeFontInfo::ToString() const
|
|||||||
{
|
{
|
||||||
wxString s;
|
wxString s;
|
||||||
|
|
||||||
s.Printf(wxT("%d;%d;%d;%d;%d;%d;%d;%s;%d"),
|
s.Printf(wxT("%d;%f;%d;%d;%d;%d;%d;%s;%d"),
|
||||||
1, // version
|
1, // version
|
||||||
GetPointSize(),
|
GetFractionalPointSize(),
|
||||||
family,
|
family,
|
||||||
(int)style,
|
(int)style,
|
||||||
(int)weight,
|
weight,
|
||||||
underlined,
|
underlined,
|
||||||
strikethrough,
|
strikethrough,
|
||||||
faceName.GetData(),
|
faceName.GetData(),
|
||||||
|
|||||||
@@ -635,9 +635,32 @@ bool wxNativeFontInfo::FromString(const wxString& s)
|
|||||||
|
|
||||||
// first the version
|
// first the version
|
||||||
wxString token = tokenizer.GetNextToken();
|
wxString token = tokenizer.GetNextToken();
|
||||||
if ( token != wxS('0') )
|
if ( !token.ToLong(&l) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
switch ( l )
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
// Fractional point size is not present in this version.
|
||||||
|
pointSize = 0.0f;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
double d;
|
||||||
|
if ( !tokenizer.GetNextToken().ToCDouble(&d) )
|
||||||
|
return false;
|
||||||
|
pointSize = static_cast<float>(d);
|
||||||
|
if ( static_cast<double>(pointSize) != d )
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Unknown version.
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
token = tokenizer.GetNextToken();
|
token = tokenizer.GetNextToken();
|
||||||
if ( !token.ToLong(&l) )
|
if ( !token.ToLong(&l) )
|
||||||
return false;
|
return false;
|
||||||
@@ -716,8 +739,9 @@ wxString wxNativeFontInfo::ToString() const
|
|||||||
{
|
{
|
||||||
wxString s;
|
wxString s;
|
||||||
|
|
||||||
s.Printf(wxS("%d;%ld;%ld;%ld;%ld;%ld;%d;%d;%d;%d;%d;%d;%d;%d;%s"),
|
s.Printf(wxS("%d;%f;%ld;%ld;%ld;%ld;%ld;%d;%d;%d;%d;%d;%d;%d;%d;%s"),
|
||||||
0, // version, in case we want to change the format later
|
1, // version
|
||||||
|
pointSize,
|
||||||
lf.lfHeight,
|
lf.lfHeight,
|
||||||
lf.lfWidth,
|
lf.lfWidth,
|
||||||
lf.lfEscapement,
|
lf.lfEscapement,
|
||||||
|
|||||||
@@ -889,6 +889,7 @@ CGFloat wxNativeFontInfo::GetCTSlant(CTFontDescriptorRef descr)
|
|||||||
//
|
//
|
||||||
bool wxNativeFontInfo::FromString(const wxString& s)
|
bool wxNativeFontInfo::FromString(const wxString& s)
|
||||||
{
|
{
|
||||||
|
double d;
|
||||||
long l, version;
|
long l, version;
|
||||||
|
|
||||||
Init();
|
Init();
|
||||||
@@ -904,9 +905,16 @@ bool wxNativeFontInfo::FromString(const wxString& s)
|
|||||||
//
|
//
|
||||||
|
|
||||||
token = tokenizer.GetNextToken();
|
token = tokenizer.GetNextToken();
|
||||||
if ( !token.ToLong(&l) )
|
if ( !token.ToCDouble(&d) )
|
||||||
return false;
|
return false;
|
||||||
m_ctSize = (int)l;
|
#ifdef __LP64__
|
||||||
|
// CGFloat is just double in this case.
|
||||||
|
m_ctSize = d;
|
||||||
|
#else // !__LP64__
|
||||||
|
m_ctSize = static_cast<CGFloat>(d);
|
||||||
|
if ( static_cast<double>(m_ctSize) != d )
|
||||||
|
return false;
|
||||||
|
#endif // __LP64__/!__LP64__
|
||||||
|
|
||||||
token = tokenizer.GetNextToken();
|
token = tokenizer.GetNextToken();
|
||||||
if ( !token.ToLong(&l) )
|
if ( !token.ToLong(&l) )
|
||||||
@@ -959,12 +967,12 @@ wxString wxNativeFontInfo::ToString() const
|
|||||||
{
|
{
|
||||||
wxString s;
|
wxString s;
|
||||||
|
|
||||||
s.Printf(wxT("%d;%d;%d;%d;%d;%d;%d;%s;%d"),
|
s.Printf(wxT("%d;%f;%d;%d;%d;%d;%d;%s;%d"),
|
||||||
1, // version
|
1, // version
|
||||||
GetPointSize(),
|
GetFractionalPointSize(),
|
||||||
GetFamily(),
|
GetFamily(),
|
||||||
(int)GetStyle(),
|
(int)GetStyle(),
|
||||||
(int)GetWeight(),
|
GetNumericWeight(),
|
||||||
GetUnderlined(),
|
GetUnderlined(),
|
||||||
GetStrikethrough(),
|
GetStrikethrough(),
|
||||||
GetFaceName().GetData(),
|
GetFaceName().GetData(),
|
||||||
|
|||||||
Reference in New Issue
Block a user