Skip to content

Commit

Permalink
feat: shadow on safari
Browse files Browse the repository at this point in the history
  • Loading branch information
maaslalani committed Feb 1, 2024
1 parent 071aea9 commit 1c249de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func main() {
if config.Shadow.Blur > 0 || config.Shadow.X > 0 || config.Shadow.Y > 0 {
id := "shadow"
svg.AddShadow(image, id, config.Shadow.X, config.Shadow.Y, config.Shadow.Blur)
image.CreateAttr("filter", fmt.Sprintf("url(#%s)", id))
rect.CreateAttr("filter", fmt.Sprintf("url(#%s)", id))
}

lines := image.SelectElement("g").SelectElements("text")
Expand Down
34 changes: 13 additions & 21 deletions svg/svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,27 @@ import (
func AddShadow(element *etree.Element, id string, x, y, blur int) {
f := etree.NewElement("filter")
f.CreateAttr("id", id)
f.CreateAttr("x", "0")
f.CreateAttr("y", "0")
f.CreateAttr("filterUnits", "userSpaceOnUse")

b := etree.NewElement("feGaussianBlur")
b.CreateAttr("in", "SourceAlpha")
b.CreateAttr("stdDeviation", fmt.Sprintf("%d", blur))

o := etree.NewElement("feOffset")
o.CreateAttr("result", "offOut")
o.CreateAttr("in", "SourceAlpha")
o.CreateAttr("result", "offsetblur")
o.CreateAttr("dx", fmt.Sprintf("%d", x))
o.CreateAttr("dy", fmt.Sprintf("%d", y))

c := etree.NewElement("feColorMatrix")
c.CreateAttr("result", "matrixOut")
c.CreateAttr("in", "offOut")
c.CreateAttr("type", "matrix")
c.CreateAttr("values", "0.2 0 0 0 0 0 0.2 0 0 0 0 0 0.2 0 0 0 0 0 1 0")
m := etree.NewElement("feMerge")
mn1 := etree.NewElement("feMergeNode")
mn2 := etree.NewElement("feMergeNode")
mn2.CreateAttr("in", "SourceGraphic")
m.AddChild(mn1)
m.AddChild(mn2)

b := etree.NewElement("feGaussianBlur")
b.CreateAttr("result", "blurOut")
b.CreateAttr("in", "matrixOut")
b.CreateAttr("stdDeviation", fmt.Sprintf("%d", blur))

blend := etree.NewElement("feBlend")
blend.CreateAttr("in", "SourceGraphic")
blend.CreateAttr("in2", "blurOut")
blend.CreateAttr("mode", "normal")

f.AddChild(o)
f.AddChild(b)
f.AddChild(blend)
f.AddChild(o)
f.AddChild(m)

defs := etree.NewElement("defs")
defs.AddChild(f)
Expand Down

0 comments on commit 1c249de

Please sign in to comment.