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 var when resolving colors #821

Open
LaurenzV opened this issue Sep 21, 2024 · 4 comments
Open

Support var when resolving colors #821

LaurenzV opened this issue Sep 21, 2024 · 4 comments

Comments

@LaurenzV
Copy link
Contributor

See here: https://developer.mozilla.org/en-US/docs/Web/CSS/var

Reason I want this is that the SVG OpenType spec allows reference CPAL palettes via vars. They way this should probably work is that the user can optionally provide a callback function that receives a string and then optionally returns a color.

@LaurenzV
Copy link
Contributor Author

Thinking about it a bit more though, implementing this properly would probably require full-blown support for resolving variables in resvg (including its dependencies), so I guess this won't happen for a while...

@RazrFalcon
Copy link
Collaborator

This should be implemented in simplecss first.
And yes, I have no plans on working on it. Or any other features to begin with. So patches are welcome.

@Caellian
Copy link

Caellian commented Nov 3, 2024

Thinking about it a bit more though, implementing this properly would probably require full-blown support for resolving variables in resvg (including its dependencies), so I guess this won't happen for a while...

Tbh, just having a way to define color variables (even without fallback) would be nice. It would greatly simplify cases like svg icon rasterization in programs where the colors might have to change.

e.g. if you want to animate icon button color on hover, currently you have to:

  • render icon as a mask and pass it through a fragment shader which modifies the color each frame
    • annoying if you want to use multiple colors in icons
    • doesn't handle gradients well (it can but it's very tricky)
  • parse the same SVG file every frame with changed color values
    • bad performance

@Caellian
Copy link

Caellian commented Nov 3, 2024

I'm waiting for feedback, but yeah, after delving into this a bit, it seems like it requires a lot of breaking changes to most CSS related dependencies. It also complicates code a lot because none of these crates expect values to change after initial parsing.

EDIT:
CSS variable support isn't part of SVG specification. So if you use stroke="var(--color, red)" in an SVG file, only when opened with a browser will it display as you'd expect, other rasterizers (tried feh (librsvg)) and programs (tried inkscape) will assume the stroke color to be invalid.

However, this feature would be very useful when integrating resvg into other programs so it might be worth implementing.

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

3 participants