Open jbosboom opened 8 years ago
Does Inkscape support named CSS class references? E.g., can you make a polygon of class "player", and later style "player" to use fill white? I think so, but worth checking, to see if we could reasonably use this approach. I assume it also binds the style within the file, though -- perhaps SVG Tiler could separate the built-in style from the content, so that restyling is possible?
According to the Inkscape manual, you can only add class
attributes and embedded stylesheets with Inkscape's XML editor. The FAQ mentions it may reformat embedded stylesheets, which at least means Inkscape has thought about preserving them.
The tiler can easily remove embedded stylesheets if we're willing to always lose them; I just don't want to be trying to preserve some elements while removing others. I don't know what happens if we leave them in with conflicting definitions from outside, but I'm guessing the inner definition will win, which would be the opposite of what we want.
Suppose we want to tile a chess position. The black and white pieces probably have the same shape, but differ in their color. Currently we'd have a mapping file like
where the SVG files have the same paths with different stroke and fill colors. This duplication makes changing the shapes or colors unnecessarily difficult.
SVG supports CSS-like styles, and we should use them. I see two particular ways forward:
<style>
element in the output SVG; the mapping file syntax will be extended to apply specified CSS classes to the<use>
element referencing the symbol (e.g.,K @white-king.svg; fill:white; stroke:black;
).<g>
elements with style attributes enclosing references to the previously-defined symbols (e.g.,K <g fill="white" stroke="black"><use id="knight-template" /></g>
). This still requires care when authoring the tile SVGs, as any styles specified in the symbol cannot be overridden at the<use>
site. (There is syntax for referencing external files from<use>
but I think the semantics are that of nested<svg>
rather than<symbol>
elements.)