Skip to content

FR: Support parsing style with light-dark() #900

@duskmoon314

Description

@duskmoon314

This PR asks for supporting 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:

<g>
  <rect
    x="120"
    y="0"
    width="120"
    height="60"
    fill="#ffffff"
    stroke="#000000"
    pointer-events="all"
    style="fill: light-dark(#ffffff, var(--ge-dark-color, #121212)); stroke: light-dark(rgb(0, 0, 0), rgb(255, 255, 255));"/>
</g>

When using this kind of SVG in downstream crates (e.g., typst), usvg fails to parse them and falls back to black:

> 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions