From 14aa0f9e9fedb438bfecc1fda0c244abc4beafb0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 13 Jun 2020 23:45:51 +0200 Subject: [PATCH] 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. --- src/msw/textmeasure.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/msw/textmeasure.cpp b/src/msw/textmeasure.cpp index 624dc520c8..31133f9778 100644 --- a/src/msw/textmeasure.cpp +++ b/src/msw/textmeasure.cpp @@ -113,7 +113,8 @@ void wxTextMeasure::DoGetTextExtent(const wxString& string, // and calling GetCharABCWidths() is pretty slow and much slower than // calling GetTextExtentPoint32() itself, so avoid its overhead unless it's // 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; const wxChar chFirst = *string.begin();