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.
This commit is contained in:
Vadim Zeitlin
2020-06-10 23:46:13 +02:00
parent bfeae1922d
commit 70768a33d2

View File

@@ -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();