Closed simbleau closed 9 months ago
Are you sure you are using the newest version? It renders fine for me:
It uses 0.37, but I didn't see anything in the changelog to address opacity parsing.
I tried it on v0.37 and it also works fine there. :/
This applies to usvg
, not resvg
.
I'm not sure how yours is rendering correctly. The path is parsed into this:
Path(Path { id: "", visibility: Visible, fill: Some(Fill { paint: Color(Color { red: 255, green: 255, blue: 255 }), opacity: NormalizedF32(FiniteF32(1.0)), rule: NonZero }), stroke: None, paint_order: FillAndStroke, rendering_mode: GeometricPrecision, data: Path { segments: "M 40.16 12.86 C 40.16 10.56 38.56 9.86 29.36 10.16 C 21.66 10.46 17.86 11.36 15.56 14.16 C 13.26 16.96 12.66 22.66 12.56 29.46 C 12.56 34.26 12.56 38.76 15.06 38.76 C 18.46 38.76 18.46 30.86 21.26 26.46 C 26.66 17.76 40.16 15.86 40.16 12.86 Z", bounds: Rect { left: 12.56, top: 9.86, right: 40.16, bottom: 38.76 } } })
Nothing in that string says 0.3 opacity, infact it says 1.0 opacity.
Dually mentioned, I am rendering the svg using vello, not resvg. If this works in resvg, I must be missing where the 0.3 opacity is passed down. usvg parses the tree without opacity on my end.
Nothing in that string says 0.3 opacity, infact it says 1.0 opacity.
This is because opacity can only be set on groups. The opacity you're looking at is fill-opacity
. I guess this is just a vello
bug then.
You have to look at path's parent node to get opacity
.
Nothing in that string says 0.3 opacity, infact it says 1.0 opacity.
This is because opacity can only be set on groups. The opacity you're looking at is
fill-opacity
. I guess this is just avello
bug then. You have to look at path's parent node to getopacity
.
That seems weird. The SVG itself doesn't have groups?
Are groups only a logical implementation, not part of SVG itself?
In SVG:
<path opacity="0.5"/>
is just a syntax sugar for:
<g opacity="0.5">
<path/>
</g>
If you look at vello SVG implementation it's insanely primitive and you probably shouldn't be using it.
The SVG itself doesn't have groups?
If you mean something like Photoshop groups then no. See: https://razrfalcon.github.io/notes-on-svg-parsing/isolated-groups.html
<path opacity="0.5"/>
is just a syntax sugar for:
<g opacity="0.5"> <path/> </g>
Ah, this is great info! I'll close the issue, then.
If you look at vello SVG implementation it's insanely primitive and you probably shouldn't be using it.
Actually I asked because I'm trying to contribute to vello
.
I see. Good luck. I think vello
needs a couple of more years to be good enough for a proper SVG renderer.
My motivation is only to get it compatible with the outputs of simpler tooling like Figma and LottieLab so it can be used for realtime graphics applications like Figma.
Afaik, Figma supports complex stroking (caps, joins, dashing) and SVG filters (mainly blur). vello
doesn't support this at the moment.
But you can use tiny_skia::Path::stroke
to get fill-ready stroke path. Not sure how well it would work.
Either way, good luck. SVG is a monster.
Example file:
The button highlight gets parsed as if it has full opacity, e.g.
Internally, this is because usvg parses it into this Path:
It never reads opacity