Check for valid font in wxTextMeasure before using it

It turns out that wxEnhMetaFileDC doesn't have any valid font in wxMSW,
so the changes of 70768a33d2 (Dramatically speed up measuring text
extent in wxMSW, 2020-06-10) broke its GetTextExtent().

Fix this by checking if we have a valid font explicitly, although
perhaps a better fix would be to ensure that wxEnhMetaFileDC also always
has a default font, as the other wxDC classes.
This commit is contained in:
Vadim Zeitlin
2020-06-13 23:45:51 +02:00
parent 585ed986a2
commit 14aa0f9e9f

View File

@@ -113,7 +113,8 @@ void wxTextMeasure::DoGetTextExtent(const wxString& string,
// and calling GetCharABCWidths() is pretty slow and much slower than // and calling GetCharABCWidths() is pretty slow and much slower than
// calling GetTextExtentPoint32() itself, so avoid its overhead unless it's // calling GetTextExtentPoint32() itself, so avoid its overhead unless it's
// really, really necessary). // really, really necessary).
if ( GetFont().GetStyle() != wxFONTSTYLE_NORMAL && len > 0 ) const wxFont font = GetFont();
if ( font.IsOk() && font.GetStyle() != wxFONTSTYLE_NORMAL && len > 0 )
{ {
ABC widthABC; ABC widthABC;
const wxChar chFirst = *string.begin(); const wxChar chFirst = *string.begin();