From 70768a33d2f7bc8dc01f1a1e8ecea8a2aeb1f550 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 10 Jun 2020 23:46:13 +0200 Subject: [PATCH] Dramatically speed up measuring text extent in wxMSW Skip correction for the under/overhang for non-italic fonts: it seems to be pretty small for them and avoiding the calls to ::GetCharABCWidths() makes GetTextExtent() 7-8 times faster, which seems to be a worthwhile compensation. If we decide to restore these calls in the future, we will need to implement some kind of cache for them, as they're just too slow otherwise. --- src/msw/textmeasure.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/msw/textmeasure.cpp b/src/msw/textmeasure.cpp index 7b68982d27..624dc520c8 100644 --- a/src/msw/textmeasure.cpp +++ b/src/msw/textmeasure.cpp @@ -108,7 +108,12 @@ void wxTextMeasure::DoGetTextExtent(const wxString& string, // the result computed by GetTextExtentPoint32() may be too small as it // accounts for under/overhang of the first/last character while we want // just the bounding rect for this string so adjust the width as needed - if ( len > 0 ) + // when using italic fonts as the difference is really noticeable for them + // (it may still exist, but seems to be at most 1px for the other fonts, + // 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 ) { ABC widthABC; const wxChar chFirst = *string.begin();