Skip to content

Commit

Permalink
parseSvg: accept either a string or XmlNode as input
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmry committed Apr 3, 2023
1 parent f3e73f7 commit 937208f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/pixie/fileformats/svg.nim
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 937208f

Please sign in to comment.