FR: Support parsing style with `light-dark()`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 4.1k
- Forks
- 348
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 3
Description
This PR asks for supporting [`light-dark()`](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/light-dark), a newly available feature, in style.
### Background and Motivation
`light-dark()` enables setting two colors for an element. For example, draw.io generates the following SVG segment:
```svg
```
When using this kind of SVG in downstream crates (e.g., typst), usvg fails to parse them and falls back to black:
```console
> resvg test.drawio.svg test.png
Warning (in usvg::parser::style:140): Failed to parse fill value: 'light-dark(#ffffff, var(--ge-dark-color, #121212)'. Fallback to black.
```
It would be nice to support parsing `light-dark()`.
### Discussion
It's weird for me to have two colors for an SVG that will be converted to PNG or PDF. Thus, my first thought would be to ignore the color of the dark theme and only use the color of the light theme. Since downstream users may use this feature to decide how to render SVG themselves, providing both color codes in `svgtypes::Paint` may be helpful.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the style parser named in the warning and the representation of colors in svgtypes::Paint. Reproduce the failure with the shown draw.io SVG or the resvg command, then verify that light-dark() no longer falls back to black and that the chosen handling of both colors is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- computer-graphics
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100