diff --git a/plugins/de.cau.cs.kieler.klighd.piccolo.freehep/src/de/cau/cs/kieler/klighd/piccolo/freehep/SemanticSVGGraphics2D.java b/plugins/de.cau.cs.kieler.klighd.piccolo.freehep/src/de/cau/cs/kieler/klighd/piccolo/freehep/SemanticSVGGraphics2D.java index ef98416a6..6c4fb7b55 100644 --- a/plugins/de.cau.cs.kieler.klighd.piccolo.freehep/src/de/cau/cs/kieler/klighd/piccolo/freehep/SemanticSVGGraphics2D.java +++ b/plugins/de.cau.cs.kieler.klighd.piccolo.freehep/src/de/cau/cs/kieler/klighd/piccolo/freehep/SemanticSVGGraphics2D.java @@ -855,15 +855,6 @@ protected void writeString(String str, double x, double y) } style.put("stroke", "none"); - // related to KIPRA-1637: preserve multiple spaces when displaying text strings - if (isProperty(STYLABLE)) - style.put("white-space", "pre"); - else - // avoid using the deprecated property 'xml:space' (https://docs.w3cub.com/svg/attribute/xml:space/) - // and sneak in the (css-based) replacement (https://www.w3schools.com/cssref/pr_text_white-space.asp) - // via a 'style' property definition - style.put("style", "white-space: pre"); - // convert tags to string values str = XMLWriter.normalizeText(str); @@ -910,7 +901,22 @@ private String getTextsString(String text, Properties style, String indentation) final String[] lines = text.split("\\r?\\n|\\r"); final boolean isSingleLine = lines.length <= 1; final StringBuffer content = new StringBuffer(); - + + // in case of a single line text + // clone the styles object in order to achieve identical order while iterating over the entries + // otherwise take an empty properties table, ... + final Properties textLineStyle = isSingleLine ? (Properties) style.clone() : new Properties(); + + // related to KIPRA-1637: preserve multiple spaces when displaying text strings; + // this property must be set per text field and won't be considered properly by chromium if outsourced to parent + if (isProperty(STYLABLE)) + textLineStyle.put("white-space", "pre"); + else + // avoid using the deprecated property 'xml:space' (https://docs.w3cub.com/svg/attribute/xml:space/) + // and sneak in the (css-based) replacement (https://www.w3schools.com/cssref/pr_text_white-space.asp) + // via a 'style' property definition + textLineStyle.put("style", "white-space: pre"); + int i = 0; if (display != null) { // Translate the font back to an swt font @@ -942,7 +948,7 @@ private String getTextsString(String text, Properties style, String indentation) content.append("\n" + indentation); content.append(""); diff --git a/test/de.cau.cs.kieler.klighd.piccolo.test/src/de/cau/cs/kieler/klighd/piccolo/test/freehep/FreeHEPSVGOffscreenRenderingTest.xtend b/test/de.cau.cs.kieler.klighd.piccolo.test/src/de/cau/cs/kieler/klighd/piccolo/test/freehep/FreeHEPSVGOffscreenRenderingTest.xtend index b7be5e938..020ba2125 100644 --- a/test/de.cau.cs.kieler.klighd.piccolo.test/src/de/cau/cs/kieler/klighd/piccolo/test/freehep/FreeHEPSVGOffscreenRenderingTest.xtend +++ b/test/de.cau.cs.kieler.klighd.piccolo.test/src/de/cau/cs/kieler/klighd/piccolo/test/freehep/FreeHEPSVGOffscreenRenderingTest.xtend @@ -291,9 +291,9 @@ class FreeHEPSVGOffscreenRenderingTest { - - NodeLabel: - Some additional info + + NodeLabel: + Some additional info '''.equalsSVGof[ // cs: deactivated generation of 'textLength' property settings on purpose, as we cannot inject reliable test size data per text line as of now @@ -317,9 +317,9 @@ class FreeHEPSVGOffscreenRenderingTest { - - NodeLabel: - Some additional info + + NodeLabel: + Some additional info @@ -448,9 +448,9 @@ class FreeHEPSVGOffscreenRenderingTest { - - PortLabel: - Some additional info + + PortLabel: + Some additional info