Skip to content

Transparent stroke/fill breaks SVG context #386

@kimikage

Description

@kimikage

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))])

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