Fix losing underline/strike-through in wxFont in wxOSX sometimes

The call to wxNativeFontInfo::InitFromFont(), added to
wxFontRefData::Alloc() in 74c0fe6dcc (Serialize font style correctly in
Mac wxNativeFontInfo, 2022-04-28), lost the existing values of the
underline and strike-through attributes that are not represented by
CTFont and so resulted in some underlined fonts being actually rendered
without underline.

Fix this by explicitly preserving and restoring these attributes before
and after calling InitFromFont().

Also remove the unneeded assignment to m_info, as InitFromFont() already
fully reinitializes it anyhow.

See #23264.

(cherry picked from commit 8b5f0493151f1b74180021256e3ee4b6b2617e9e)
This commit is contained in:
Vadim Zeitlin 2023-02-22 17:22:40 +01:00
parent acd030c707
commit 35adde26b5
2 changed files with 11 additions and 1 deletions

View File

@ -250,6 +250,7 @@ wxMSW:
wxOSX:
- Fix underlined fonts sometimes appearing without underline (#23264).
- Respect composition mode when drawing bitmaps (#23240).

View File

@ -387,9 +387,18 @@ void wxFontRefData::Alloc()
}
}
m_info = wxNativeFontInfo();
// Preserve the fields not represented by CTFont.
const bool wasUnderlined = m_info.GetUnderlined();
const bool wasStrikethrough = m_info.GetStrikethrough();
m_info.InitFromFont(m_ctFont);
// Restore them as they were reset by InitFromFont().
if ( wasUnderlined )
m_info.SetUnderlined(wasUnderlined);
if ( wasStrikethrough )
m_info.SetStrikethrough(wasStrikethrough);
entryWithSize.font = m_ctFont;
entryWithSize.cgFont = m_cgFont;
entryWithSize.fontAttributes = m_ctFontAttributes;