From 937208f2d3cdc354cf9b8e78709fe97ffa1e1333 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Mon, 3 Apr 2023 13:43:01 -0500 Subject: [PATCH] parseSvg: accept either a string or XmlNode as input --- src/pixie/fileformats/svg.nim | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/pixie/fileformats/svg.nim b/src/pixie/fileformats/svg.nim index c4f70dd1..23fdf5c7 100644 --- a/src/pixie/fileformats/svg.nim +++ b/src/pixie/fileformats/svg.nim @@ -500,11 +500,10 @@ proc parseSvgElement( raise newException(PixieError, "Unsupported SVG tag: " & node.tag) proc parseSvg*( - data: string | XmlNode, width = 0, height = 0 + root: XmlNode; width = 0; height = 0 ): Svg {.raises: [PixieError].} = ## Parse SVG XML. Defaults to the SVG's view box size. try: - let root = parseXml(data) if root.tag != "svg": failInvalid() @@ -545,6 +544,16 @@ proc parseSvg*( except: raise currentExceptionAsPixieError() +proc parseSvg*( + data: string; width = 0; height = 0 +): Svg {.raises: [PixieError].} = + ## Parse SVG XML. Defaults to the SVG's view box size. + try: parseSvg(parseXml(data), width, height) + except PixieError as e: + raise e + except: + raise currentExceptionAsPixieError() + proc newImage*(svg: Svg): Image {.raises: [PixieError].} = ## Render SVG and return the image. result = newImage(svg.width, svg.height)