diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b348a7980779e2e2902c3ff6c16b03fb09d566d..99a8ceba0dce26cd31b4952010233710dd6dee95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -106,6 +106,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 2.38.0 to the behavior Graphviz 2.36.0 and prior had. The difference is most apparent when using a non-default `dpi` setting. #2669 - The Tcl bindings have been updated for compatibility with Tcl 9. #2668 +- The SVG output format (`-Tsvg`, `-Tsvg_inline`) no longer duplicates font + families. ### Fixed diff --git a/plugin/core/gvrender_core_svg.c b/plugin/core/gvrender_core_svg.c index 1bac43a08d28c08b55b394ac669d0597ffc99612..f20307f26951f095c3f9abc30da632328fe98194 100644 --- a/plugin/core/gvrender_core_svg.c +++ b/plugin/core/gvrender_core_svg.c @@ -481,7 +481,7 @@ static void svg_textspan(GVJ_t * job, pointf p, textspan_t * span) stretch = pA->stretch; gvprintf(job, " font-family=\"%s", family); - if (pA->svg_font_family) + if (pA->svg_font_family && pA->svg_font_family != family) gvprintf(job, ",%s", pA->svg_font_family); gvputc(job, '"'); if (weight) diff --git a/tests/test_regression.py b/tests/test_regression.py index 685bf135317e8e3b31317063600a2fb3a90862ba..bec38a2d65148646f6678b68a1a1621d0af37ba4 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -6335,3 +6335,28 @@ def test_lock_graph(): # now try this with a large integer for the locking operation output = run(["gvpr", "-f", program2], input=src) assert output == "0\n1\n", "locking a graph using a large integer did not work" + + +def test_duplicate_font_family(): + """ + SVG output should not contain duplicate `font-family` items + https://gitlab.com/graphviz/graphviz/-/merge_requests/4298 + """ + + # a sample graph to exercise font families + source = textwrap.dedent( + """\ + graph G { + graph [fontnames=svg]; + N [label="node" fontname="Helvetica"]; + } + """ + ) + + # convert this to SVG + svg = dot("svg", source=source) + + # extract font families + for ff in re.findall(r'font-family="(?P[^"]*)', svg): + families = [f.strip() for f in ff.split(",")] + assert len(families) == len(set(families)), "duplicate font families listed"