commit
f413ee733d
1 changed files with 15 additions and 6 deletions
|
@ -561,11 +561,10 @@ proc draw(img: Image, node: XmlNode, ctxStack: var seq[Ctx]) =
|
||||||
raise currentExceptionAsPixieError()
|
raise currentExceptionAsPixieError()
|
||||||
|
|
||||||
proc decodeSvg*(
|
proc decodeSvg*(
|
||||||
data: string, width = 0, height = 0
|
root: XmlNode, width = 0, height = 0
|
||||||
): Image {.raises: [PixieError].} =
|
): 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:
|
try:
|
||||||
let root = parseXml(data)
|
|
||||||
if root.tag != "svg":
|
if root.tag != "svg":
|
||||||
failInvalid()
|
failInvalid()
|
||||||
|
|
||||||
|
@ -581,9 +580,8 @@ proc decodeSvg*(
|
||||||
rootCtx = decodeCtx(rootCtx, root)
|
rootCtx = decodeCtx(rootCtx, root)
|
||||||
|
|
||||||
if viewBoxMinX != 0 or viewBoxMinY != 0:
|
if viewBoxMinX != 0 or viewBoxMinY != 0:
|
||||||
rootCtx.transform = rootCtx.transform * translate(
|
let viewBoxMin = vec2(-viewBoxMinX.float32, -viewBoxMinY.float32)
|
||||||
vec2(-viewBoxMinX.float32, -viewBoxMinY.float32)
|
rootCtx.transform = rootCtx.transform * translate(viewBoxMin)
|
||||||
)
|
|
||||||
|
|
||||||
if width == 0 and height == 0: # Default to the view box size
|
if width == 0 and height == 0: # Default to the view box size
|
||||||
result = newImage(viewBoxWidth, viewBoxHeight)
|
result = newImage(viewBoxWidth, viewBoxHeight)
|
||||||
|
@ -602,3 +600,14 @@ proc decodeSvg*(
|
||||||
raise e
|
raise e
|
||||||
except:
|
except:
|
||||||
raise newException(PixieError, "Unable to load SVG")
|
raise newException(PixieError, "Unable to load SVG")
|
||||||
|
|
||||||
|
proc decodeSvg*(
|
||||||
|
data: string, width = 0, height = 0
|
||||||
|
): Image {.raises: [PixieError].} =
|
||||||
|
## Render SVG data and return the image. Defaults to the SVG's view box size.
|
||||||
|
let root =
|
||||||
|
try:
|
||||||
|
parseXml(data)
|
||||||
|
except:
|
||||||
|
raise currentExceptionAsPixieError()
|
||||||
|
decodeSvg(root)
|
||||||
|
|
Loading…
Reference in a new issue