Serialize font style correctly in Mac wxNativeFontInfo
The style needs to be explicitly included in the serialized representation as it's not necessarily part of the native font description itself, but can be emulated using a transform matrix. Also fix the font family handling by recreating the native font info from the newly generated font. Closes #22373.
This commit is contained in:
parent
5f7d4a70c2
commit
74c0fe6dcc
@ -384,6 +384,9 @@ void wxFontRefData::Alloc()
|
||||
}
|
||||
}
|
||||
|
||||
m_info = wxNativeFontInfo();
|
||||
m_info.InitFromFont(m_ctFont);
|
||||
|
||||
entryWithSize.font = m_ctFont;
|
||||
entryWithSize.cgFont = m_cgFont;
|
||||
entryWithSize.fontAttributes = m_ctFontAttributes;
|
||||
@ -855,6 +858,13 @@ void wxNativeFontInfo::InitFromFont(CTFontRef font)
|
||||
|
||||
wxCFRef<CTFontDescriptorRef> desc(CTFontCopyFontDescriptor(font));
|
||||
InitFromFontDescriptor( desc );
|
||||
|
||||
// in case the font itself does not exist as italic it might have
|
||||
// been created with the emulation via a font transform
|
||||
if ( !CGAffineTransformIsIdentity(CTFontGetMatrix(font)) )
|
||||
{
|
||||
m_style = wxFONTSTYLE_ITALIC;
|
||||
}
|
||||
}
|
||||
|
||||
void wxNativeFontInfo::InitFromFontDescriptor(CTFontDescriptorRef desc)
|
||||
@ -1122,8 +1132,18 @@ bool wxNativeFontInfo::FromString(const wxString& s)
|
||||
m_encoding = (wxFontEncoding)l;
|
||||
return true;
|
||||
}
|
||||
else if ( version == 2 )
|
||||
else if ( version == 2 || version == 3 )
|
||||
{
|
||||
wxFontStyle style = wxFONTSTYLE_NORMAL;
|
||||
|
||||
if ( version == 3 )
|
||||
{
|
||||
token = tokenizer.GetNextToken();
|
||||
if ( !token.ToLong(&l) )
|
||||
return false;
|
||||
style = (wxFontStyle)l;
|
||||
}
|
||||
|
||||
token = tokenizer.GetNextToken();
|
||||
if ( !token.ToLong(&l) )
|
||||
return false;
|
||||
@ -1154,6 +1174,7 @@ bool wxNativeFontInfo::FromString(const wxString& s)
|
||||
m_underlined = underlined;
|
||||
m_strikethrough = strikethrough;
|
||||
m_encoding = encoding;
|
||||
m_style = style;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -1167,6 +1188,9 @@ wxString wxNativeFontInfo::ToString() const
|
||||
|
||||
// version 2 is a streamed property list of the font descriptor as recommended by Apple
|
||||
// prefixed by the attributes that are non-native to the native font ref like underline, strikethrough etc.
|
||||
// version 3 adds to v2 the style attribute because this cannot always be expressed
|
||||
// in the native font descriptor. In situations where there is no native italic font
|
||||
// the slant-ness has to be emulated in the font's transform
|
||||
wxCFDictionaryRef attributes(CTFontDescriptorCopyAttributes(GetCTFontDescriptor()));
|
||||
|
||||
if (attributes != NULL)
|
||||
@ -1181,8 +1205,9 @@ wxString wxNativeFontInfo::ToString() const
|
||||
xml.Replace("\t",wxEmptyString,true);
|
||||
xml = xml.Mid(xml.Find("<plist"));
|
||||
|
||||
s.Printf("%d;%d;%d;%d;%s",
|
||||
2, // version
|
||||
s.Printf("%d;%d;%d;%d;%d;%s",
|
||||
3, // version
|
||||
(int)GetStyle(),
|
||||
GetUnderlined(),
|
||||
GetStrikethrough(),
|
||||
(int)GetEncoding(),
|
||||
|
Loading…
Reference in New Issue
Block a user