From 5c60643f1dc7b5697857facd0b0015540f59e181 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Tue, 4 Jan 2022 14:15:50 +0100 Subject: [PATCH] svg: decode from XmlNode --- src/pixie/fileformats/svg.nim | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/pixie/fileformats/svg.nim b/src/pixie/fileformats/svg.nim index 293d3a20..88ace8db 100644 --- a/src/pixie/fileformats/svg.nim +++ b/src/pixie/fileformats/svg.nim @@ -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(" ") @@ -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)