Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support defining symbols as styles over other symbols #1

Open
jbosboom opened this issue Sep 10, 2015 · 2 comments
Open

Support defining symbols as styles over other symbols #1

jbosboom opened this issue Sep 10, 2015 · 2 comments

Comments

@jbosboom
Copy link
Owner

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

K @white-king.svg
k @black-king.svg
Q @white-queen.svg
q @black-queen.svg

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:

  • Use CSS classes in the tile SVG files and specify a stylesheet on the command line, which will be embedded as a <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;).
  • Extend the mapping file syntax to long names, then define other symbols as <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.)
@edemaine
Copy link

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?

@jbosboom
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants