Add currentExceptionAsPixieError.

This commit is contained in:
treeform 2021-12-03 17:29:58 -08:00
parent f7a4bdcba7
commit ef20501ce1
5 changed files with 17 additions and 19 deletions

View file

@ -38,8 +38,7 @@ proc parseColor(s: string): Color {.raises: [PixieError]} =
try:
result = parseHtmlColor(s)
except:
let e = getCurrentException()
raise newException(PixieError, e.msg, e)
raise currentExceptionAsPixieError()
proc drawImage2(
ctx: Context, image: Image, dx, dy, dWidth, dHeight: float32

View file

@ -79,8 +79,7 @@ proc initCtx(): Ctx =
result.fill = parseHtmlColor("black").rgbx
result.stroke = parseHtmlColor("black").rgbx
except:
let e = getCurrentException()
raise newException(PixieError, e.msg, e)
raise currentExceptionAsPixieError()
result.strokeWidth = 1
result.transform = mat3()
result.strokeMiterLimit = defaultMiterLimit
@ -340,8 +339,7 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx =
except PixieError as e:
raise e
except:
let e = getCurrentException()
raise newException(PixieError, e.msg, e)
raise currentExceptionAsPixieError()
proc cairoLineCap(lineCap: LineCap): cairo.LineCap =
case lineCap:
@ -526,8 +524,7 @@ proc draw(img: ptr Context, node: XmlNode, ctxStack: var seq[Ctx]) =
except PixieError as e:
raise e
except:
let e = getCurrentException()
raise newException(PixieError, e.msg, e)
raise currentExceptionAsPixieError()
proc decodeSvg*(data: string, width = 0, height = 0): Image =
## Render SVG file and return the image. Defaults to the SVG's view box size.

View file

@ -1,7 +1,7 @@
## Load SVG files.
import chroma, pixie/common, pixie/images, pixie/paints, pixie/paths, strutils,
tables, vmath, xmlparser, xmltree
import chroma, pixie/common, pixie/internal, pixie/images, pixie/paints,
pixie/paths, strutils, tables, vmath, xmlparser, xmltree
when defined(pixieDebugSvg):
import strtabs
@ -44,8 +44,7 @@ proc initCtx(): Ctx =
result.fill = parseHtmlColor("black").rgbx
result.stroke = parseHtmlColor("black").rgbx
except:
let e = getCurrentException()
raise newException(PixieError, e.msg, e)
raise currentExceptionAsPixieError()
result.strokeWidth = 1
result.transform = mat3()
result.strokeMiterLimit = defaultMiterLimit
@ -323,8 +322,7 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx =
except PixieError as e:
raise e
except:
let e = getCurrentException()
raise newException(PixieError, e.msg, e)
raise currentExceptionAsPixieError()
proc fill(img: Image, ctx: Ctx, path: Path) {.inline.} =
if ctx.display and ctx.opacity > 0:
@ -560,8 +558,7 @@ proc draw(img: Image, node: XmlNode, ctxStack: var seq[Ctx]) =
except PixieError as e:
raise e
except:
let e = getCurrentException()
raise newException(PixieError, e.msg, e)
raise currentExceptionAsPixieError()
proc decodeSvg*(
data: string, width = 0, height = 0

View file

@ -1,4 +1,5 @@
import pixie/common, pixie/paths, strutils, tables, unicode, vmath, xmlparser, xmltree
import pixie/common, pixie/internal, pixie/paths, strutils, tables, unicode,
vmath, xmlparser, xmltree
type SvgFont* = ref object
unitsPerEm*, ascent*, descent*: float32
@ -42,8 +43,7 @@ proc parseSvgFont*(buf: string): SvgFont {.raises: [PixieError].} =
try:
parseXml(buf)
except:
let e = getCurrentException()
raise newException(PixieError, e.msg, e)
raise currentExceptionAsPixieError()
let defs = root.child("defs")
if defs == nil:

View file

@ -3,6 +3,11 @@ import chroma, vmath
when defined(amd64) and not defined(pixieNoSimd):
import nimsimd/sse2
template currentExceptionAsPixieError*(): untyped =
## Gets the current exception and returns it as a PixieError with stack trace.
let e = getCurrentException()
newException(PixieError, e.getStackTrace & e.msg, e)
proc gaussianKernel*(radius: int): seq[uint16] {.raises: [].} =
## Compute lookup table for 1d Gaussian kernel.
## Values are [0, 255] * 256.