Compose.jl icon indicating copy to clipboard operation
Compose.jl copied to clipboard

Transparent stroke/fill breaks SVG context

Open kimikage opened this issue 5 years ago • 4 comments

At least since 2014, when I learned about Gadfly.jl, using transparent (i.e. alpha != 1.0) strokes and fills breaks the SVG context (i.e. stroke-opacity and fill-opacity). Is this a known issue or desired behavior? https://github.com/GiovineItalia/Compose.jl/blob/e08b5cac84627389c729502fa1cbae615212d1f9/src/svg.jl#L608-L615 https://github.com/GiovineItalia/Compose.jl/blob/e08b5cac84627389c729502fa1cbae615212d1f9/src/svg.jl#L617-L624

Of course, adding stroke-opacity="1"/fill-opacity="1" for opaque colors also causes context breaking.

This problem can be avoided by specifying stroke-opacity and fill-opacity manually. If it is an official solution, we need to fix the code of Gadfly. The stroke(nothing) sets stroke-opacity to zero.

While it is not a complete solution, at least, it is better to distinguish between the strokes/fills which actually exist but fully-transparent, and no-stroke/no-fill. https://github.com/GiovineItalia/Compose.jl/blob/2b561b0f53a81cbf9a4001d721d29880d6e50ebc/src/property.jl#L54 https://github.com/GiovineItalia/Compose.jl/blob/2b561b0f53a81cbf9a4001d721d29880d6e50ebc/src/property.jl#L71

kimikage avatar Feb 14 '20 18:02 kimikage

While work has been done to fix fillopacity (#314, #318, #319, #322, #332), strokeopacity needs work. Note fillopacity is documented, but not strokeopacity.

Mattriks avatar Feb 14 '20 20:02 Mattriks

The following is the case with "explicit" fillopacity(a). https://github.com/GiovineItalia/Compose.jl/blob/e08b5cac84627389c729502fa1cbae615212d1f9/src/property.jl#L212-L214 For users who understand the inheritance in SVG, like us, this explanation may be sufficient. What I want to emphasize in this issue is that transparent colors implicitly change stroke-opacity/fill-opacity and opaque colors not. fillopacity

I think at least additional docs are needed. In particular, the latter nothing is reminiscent of none for users familiar with SVG.

kimikage avatar Feb 14 '20 20:02 kimikage

The way I think fill(RGBA(r,g,b,a)) and fillopacity(a) should currently work is explained in https://github.com/GiovineItalia/Gadfly.jl/issues/1290#issuecomment-544323436. Yes the design/inheritance rules could be better documented. Because Compose uses multiple backends, Compose inheritance may not work in precisely the same way as a particular backend. Color inheritance (different from opacity inheritance) would also work better if svg2's rgba spec was implemented (#319), but users don't like that rgba is not supported by Inkscape.

Perhaps you could implement the rgba spec in Inkscape?

Mattriks avatar Feb 14 '20 22:02 Mattriks

Perhaps you could implement the rgba spec in Inkscape?

Inkscape places importance on conforming to the standard, so I think it is difficult to implement it within SVG1.

BTW, SVG 1.2 Full was canceled, so version="1.2" is just for SVG Tiny (i.e. with baseProfile="tiny"). https://github.com/GiovineItalia/Compose.jl/blob/e08b5cac84627389c729502fa1cbae615212d1f9/src/svg.jl#L342

I believe this problem can be mitigated by being able to determine whether fill-opacity was set by FillOpacityPrimitive or FillPrimitive.

kimikage avatar Feb 15 '20 02:02 kimikage