Make wxGCDC::GetTextExtent("") return (0, 0)

This seems more logical and is compatible with wxDC in wxMSW and wxGTK2,
as well as other kinds of DC, e.g. wxPostScriptDC.

It also looks like the current behaviour was unintentional as it
happened only because wxGCDCImpl::DoGetTextExtent() always passed all
non-null parameters to wxGraphicsContext::GetTextExtent(), even if it
didn't need the values for all of them, and thus bypassed the special
case for the empty string which was already present in the latter
function.

Fix this, making DoGetTextExtent() more efficient as a side effect (we
now avoid unnecessary calls to pango_layout_iter_get_baseline() in the
most common case), and also add another test for empty string to
wxGraphicsContext itself, for non-GTK case.

Also document this behaviour and add a test checking for it.
This commit is contained in:
Vadim Zeitlin
2020-07-15 02:01:36 +02:00
parent a52a27ad90
commit 46d6866c9f
5 changed files with 21 additions and 2 deletions

View File

@@ -33,6 +33,8 @@
#include "wx/dcps.h"
#include "wx/metafile.h"
#include "asserthelper.h"
// ----------------------------------------------------------------------------
// helper for XXXTextExtent() methods
// ----------------------------------------------------------------------------
@@ -52,6 +54,9 @@ struct GetTextExtentTester
wxSize size = obj.GetTextExtent("Hello");
CHECK( size.x > 1 );
CHECK( size.y == y );
// Test that getting text extent of an empty string returns (0, 0).
CHECK( obj.GetTextExtent(wxString()) == wxSize() );
}
};