ksvg
ksvg copied to clipboard
add function to add raw SVG elements
having the option to insert "raw" child elements from string would be convenient
example:
fun generateSVG(
shapeViewBox: String = "0 0 100 100",
shapeContent: String = """<path d="M0 13.3333C0 5.96954 5.96954 0 13.3333 0H86.6667C94.0305 0 100 5.96954 100 13.3333V86.6667C100 94.0305 94.0305 100 86.6667 100H13.3333C5.96954 100 0 94.0305 0 86.6667V13.3333Z" fill="currentColor"/>"""
): String {
val svg = SVG.svg {
/* ...*/
children += SVG.svg {
id = "shape"
width = "100%"
height = "100%"
attributes["x"] = "0"
attributes["y"] = "0"
viewBox = shapeViewBox
body = "replace_shape"
}
}
return buildString {
svg.render(this, RenderMode.INLINE)
}.replace("replace_shape", "\n" +shapeContent + "\n")
}
i recently came across a problem in which i was given raw svg paths and viewport of a SVG and had to assemble nested SVGs out of them
i solved it by assigning a "replace_thing" value to tthe body of the nested SVGs and did some string manipulation on the rendered output
regardless.. a nicer api would make this type of problem easier to solve