JuliaGraphics / Luxor.jl

Simple drawings using vector graphics; Cairo "for tourists!"
http://juliagraphics.github.io/Luxor.jl/
Other
575 stars 72 forks source link

transparency does not work for background color in svg #288

Closed jonalm closed 4 months ago

jonalm commented 7 months ago
@svg begin
    background(1,0,0,0.5)
    setcolor(1,0,0,0.5) # note same color with same alpha value
    circle(Point(0, 0), 100, action = :fill)
end 200 200  "circle.svg"

produces svg

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200pt" height="200pt" viewBox="0 0 200 200" version="1.1">
<g id="surface362">
<rect x="0" y="0" width="200" height="200" style="fill:rgb(100%,100%,100%);fill-opacity:1;stroke:none;"/>
<rect x="0" y="0" width="200" height="200" style="fill:rgb(100%,0%,0%);fill-opacity:0.5;stroke:none;"/>
<path style=" stroke:none;fill-rule:nonzero;fill:rgb(100%,0%,0%);fill-opacity:0.5;" d="M 200 100 C 200 155.226562 155.226562 200 100 200 C 44.773438 200 0 155.226562 0 100 C 0 44.773438 44.773438 0 100 0 C 155.226562 0 200 44.773438 200 100 Z M 200 100 "/>
</g>
</svg>

The line

<rect x="0" y="0" width="200" height="200" style="fill:rgb(100%,100%,100%);fill-opacity:1;stroke:none;"/>

makes the background non-transparent

jonalm commented 7 months ago

Ah, so the background color is transparent on top of a white background. Sorry, I'm a bit slow. In any case, why is the white (non-transparent) background needed?

cormullion commented 7 months ago

Hi! Yes, @svg sets the background to white... source

Perhaps this is helpful?