From: Matthew Fernandez Date: Mon, 28 Feb 2022 02:49:26 +0000 (-0800) Subject: Pango plugin: fix: do not judge empty lines as failing during text layout X-Git-Tag: 4.0.0~198^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=adfe04cad94ab7a42bd5702454618932caa3e9c3;p=graphviz Pango plugin: fix: do not judge empty lines as failing during text layout Text layout plugins are expected to return failure as `false` from their `textlayout` function. The Pango plugin considered failure to be anything that resulted in a horizontal layout width of 0. However, this is not a failure in the case where the text being laid out is the empty string; its horizontal width is expected to be 0. The effect of this was that HTML-like strings like `<
1>` were judged to fail during text layout and a (redundant) estimation of their text width was performed. This seems to have been a latent bug present since commit ad82ef8613b0731806b81f9c0047d0cbf6745470 (~July 2007). This recently became more visible due to commit 7aa0dcc03ea20b544b2463d97fe4a78af699589c that introduced warnings during text width estimation if a fallback metric needed to be used. Users were now presented with “Warning: no hard-coded metrics” when using fonts that Pango knew of and should not have needed estimation in the first place. This fix makes the Pango plugin consider 0 width for the layout of an empty string to be successful. To be clear, this commit is both a functional fix and a performance improvement. Gitlab: fixes #2179 --- diff --git a/CHANGELOG.md b/CHANGELOG.md index ec3c3f614..5484c1d02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 functions without corrupting their content. Some cases of this were a regression in Graphviz 2.46.0. Other cases have existed since the first release of `gvpr`. #2185 +- spurious "no hard-coded metrics" warnings on labels with empty lines #2179 ## [3.0.0] – 2022-02-26 diff --git a/plugin/pango/gvtextlayout_pango.c b/plugin/pango/gvtextlayout_pango.c index 3d54670c1..39e03cb3e 100644 --- a/plugin/pango/gvtextlayout_pango.c +++ b/plugin/pango/gvtextlayout_pango.c @@ -289,7 +289,7 @@ static bool pango_textlayout(textspan_t * span, char **fontpath) /* The distance below midline for y centering of text strings */ span->yoffset_centerline = 0.2 * span->font->size; - return logical_rect.width != 0; + return logical_rect.width != 0 || strcmp(text, "") == 0; } static gvtextlayout_engine_t pango_textlayout_engine = { diff --git a/rtest/test_regression.py b/rtest/test_regression.py index 679d4fddc..cc46c2c60 100644 --- a/rtest/test_regression.py +++ b/rtest/test_regression.py @@ -1353,7 +1353,6 @@ def test_2138(examine: str): assert "// tok[7] >>012<< should NOT include trailing spaces or " \ "junk chars" in result, "token 012 not found or has trailing garbage" -@pytest.mark.xfail(strict=True) # FIXME def test_2179(): """ processing a label with an empty line should not yield a warning