Skip to content

#715 HTML codegen: fix 'svgout' to work for all attributes.

  • Problem:
    • In SVG, some attributes may be used as SVG presentation attributes (<rect x="5">), while others may be used as CSS style properties (<rect style="x:5;">). Some may be used as both.
    • If the attribute is supported as both, the CSS style property takes precedence over the SVG presentation attribute, if they are both specified.
    • In the CIF simulator, we use Batik. We decide whether to set as a CSS style property by using org.eclipse.escet.common.svg.SvgUtils.isCssAttr and set it as SVG presentation attribute otherwise. This works. However, this logic does not work for a browser. It seems Batik has some internal logic that makes it work, that we don't duplicate in our code generation.
    • The current logic in HTML code generator treats fill, visibility and opacity as CSS style properties and the rest as SVG presentation attributes. This was a temporary workaround until a good solution is found. It fails for many attributes, including stroke, as reported to me by @koenveldik.
    • This is thus a real-world problem affecting users.
  • Solution:
    • I've come up with a simple solution: always set the attribute as both a CSS style property and an SVG presentation attribute, to ensure it works for all attributes, and is not overridden by something already present.
    • If an attribute is only supported as CSS style property or only as SVG presentation attribute, the non-supported version will be ignored by the browser.
    • This way, there is no hard-coded list (which would be a pain to get right anyway). And the user doesn't have to care about this either: it just works.
  • I've tested this for some models, and it seems to work well.

Addresses #715

Merge request reports

Loading