Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/pixie/fileformats/svg.nim
Original file line number Diff line number Diff line change
Expand Up @@ -561,14 +561,10 @@ proc draw(img: Image, node: XmlNode, ctxStack: var seq[Ctx]) =
raise currentExceptionAsPixieError()

proc decodeSvg*(
data: string, width = 0, height = 0
root: XmlNode, width = 0, height = 0
): Image {.raises: [PixieError].} =
## Render SVG file and return the image. Defaults to the SVG's view box size.
## Render SVG XML and return the image. Defaults to the SVG's view box size.
try:
let root = parseXml(data)
if root.tag != "svg":
failInvalid()

let
viewBox = root.attr("viewBox")
box = viewBox.split(" ")
Expand Down Expand Up @@ -602,3 +598,13 @@ proc decodeSvg*(
raise e
except:
raise newException(PixieError, "Unable to load SVG")

proc decodeSvg*(
data: string, width = 0, height = 0
): Image {.raises: [PixieError].} =
## Render SVG file and return the image. Defaults to the SVG's view box size.
var root: XmlNode
try: root = parseXml(data)
except: raise currentExceptionAsPixieError()
if root.tag != "svg": failInvalid()
decodeSvg(root, width, height)