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

@@ -954,6 +954,8 @@ public:
used for the text extent calculation. Otherwise the currently selected
font is.
If @a string is empty, its extent is 0 in both directions, as expected.
@note This function only works with single-line strings.
@beginWxPerlOnly