This commit is contained in:
u80864958
2025-06-13 11:29:09 +02:00
commit 9a30b61931
10 changed files with 498 additions and 0 deletions

28
pkg/filler.go Normal file
View File

@ -0,0 +1,28 @@
package pkg
import (
"io"
"github.com/antchfx/xmlquery"
)
func Fill(svg io.Reader, data map[string]xmlquery.Node) (filledSvg string, err error) {
doc, err := xmlquery.Parse(svg)
defer func() { filledSvg = doc.OutputXML(true) }()
if err != nil {
return
}
for key, value := range data {
nodes := xmlquery.Find(doc, "//*/g[@inkscape:label='fill']/*[@inkscape:label='"+key+"']")
if err != nil {
return filledSvg, err
}
for _, node := range nodes {
node.FirstChild = &value
}
}
return
}