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

Transparent stroke/fill breaks SVG context #386

Open
kimikage opened this issue Feb 14, 2020 · 4 comments
Open

Transparent stroke/fill breaks SVG context #386

kimikage opened this issue Feb 14, 2020 · 4 comments

Comments

@kimikage
Copy link

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?

Compose.jl/src/svg.jl

Lines 608 to 615 in e08b5ca

function print_property(img::SVG, property::StrokePrimitive)
if property.color.alpha != 1.0
@printf(img.out, " stroke=\"%s\" stroke-opacity=\"%0.3f\"",
svg_fmt_color(color(property.color)), property.color.alpha)
else
@printf(img.out, " stroke=\"%s\"", svg_fmt_color(color(property.color)))
end
end

Compose.jl/src/svg.jl

Lines 617 to 624 in e08b5ca

function print_property(img::SVG, property::FillPrimitive)
if property.color.alpha != 1.0
@printf(img.out, " fill=\"%s\" fill-opacity=\"%0.3f\"",
svg_fmt_color(color(property.color)), property.color.alpha)
else
@printf(img.out, " fill=\"%s\"", svg_fmt_color(color(property.color)))
end
end

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.

stroke(c::Nothing) = Stroke([StrokePrimitive(RGBA{Float64}(0, 0, 0, 0))])

fill(c::Nothing) = Fill([FillPrimitive(RGBA{Float64}(0.0, 0.0, 0.0, 0.0))])

@Mattriks
Copy link
Member

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

@kimikage
Copy link
Author

The following is the case with "explicit" fillopacity(a).

Compose.jl/src/property.jl

Lines 212 to 214 in e08b5ca

fillopacity(value)
Define a fill opacity, where 0≤value≤1. For svg, nested contexts will inherit from parent contexts e.g. `(context(), fillopacity(a), (context(), fill(c::String), circle()))`.

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.

@Mattriks
Copy link
Member

The way I think fill(RGBA(r,g,b,a)) and fillopacity(a) should currently work is explained in GiovineItalia/Gadfly.jl#1290 (comment). 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?

@kimikage
Copy link
Author

kimikage commented Feb 15, 2020

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

version="1.2"

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

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

2 participants