Fix caching of wxFONTSTYLE_SLANT fonts in wxTheFontList in wxMSW

Creating a font with wxFONTSTYLE_SLANT results in a font whose
GetStyle() returned wxFONTSTYLE_ITALIC, so it was never found in the
cache, resulting in, effectively, leaking memory and GDI handles because
each new call to wxFontList::FindOrCreateFont(...wxFONTSTYLE_SLANT)
created a new font.

Fix this by just hardcoding that wxFONTSTYLE_SLANT is wxFONTSTYLE_ITALIC
under MSW, this is ugly but avoids backwards incompatible (and not
obviously correct) change of making wxFont::GetStyle() return
wxFONTSTYLE_SLANT if the font was created using this style.

Notice that wxFont::GetStyle() does behave like this in wxOSX currently,
so there is an inconsistency between ports here. It would arguably be
better to make wxOSX behave like wxMSW because the actual font is really
italic and not slant/oblique and if we do this, the preprocessor
condition in this commit should be extended to cover wxOSX too.

Closes #17903.
This commit is contained in:
Vadim Zeitlin 2017-07-06 15:01:00 +02:00
parent b158385c47
commit 7092b1112e
2 changed files with 13 additions and 0 deletions

View File

@ -192,6 +192,7 @@ wxMSW:
- Fix updating bounding box in wxDC::DrawSpline().
- Fix placing 0RGB wxBitmaps on the clipboard.
- Fix handling wxClipboard data when wxUSE_OLE == 0.
- Fix caching of wxFONTSTYLE_SLANT fonts in wxTheFontList.
wxOSX:

View File

@ -782,6 +782,18 @@ wxFont *wxFontList::FindOrCreateFont(int pointSize,
family = wxFONTFAMILY_SWISS;
#endif // !__WXOSX__
// In wxMSW, creating a font with wxFONTSTYLE_SLANT creates the same font
// as wxFONTSTYLE_ITALIC and its GetStyle() returns the latter, so we must
// account for it here. Notice that wxOSX also uses the same native font
// for these styles, but wxFont::GetStyle() in it still returns different
// values depending on how the font was created, so there is inconsistency
// between ports here which it would be nice to fix in one way or another
// (wxGTK supports both as separate styles, so it doesn't suffer from it).
#ifdef __WXMSW__
if ( style == wxFONTSTYLE_SLANT )
style = wxFONTSTYLE_ITALIC;
#endif // __WXMSW__
wxFont *font;
wxList::compatibility_iterator node;
for (node = list.GetFirst(); node; node = node->GetNext())