Merge pull request #336 from treeform/exceptions
Exceptions with parent Stack Trace As Pixie Error.
This commit is contained in:
commit
a86c4d4b14
6 changed files with 30 additions and 28 deletions
|
@ -38,8 +38,7 @@ proc parseColor(s: string): Color {.raises: [PixieError]} =
|
||||||
try:
|
try:
|
||||||
result = parseHtmlColor(s)
|
result = parseHtmlColor(s)
|
||||||
except:
|
except:
|
||||||
let e = getCurrentException()
|
raise currentExceptionAsPixieError()
|
||||||
raise newException(PixieError, e.msg, e)
|
|
||||||
|
|
||||||
proc drawImage2(
|
proc drawImage2(
|
||||||
ctx: Context, image: Image, dx, dy, dWidth, dHeight: float32
|
ctx: Context, image: Image, dx, dy, dWidth, dHeight: float32
|
||||||
|
|
|
@ -79,8 +79,7 @@ proc initCtx(): Ctx =
|
||||||
result.fill = parseHtmlColor("black").rgbx
|
result.fill = parseHtmlColor("black").rgbx
|
||||||
result.stroke = parseHtmlColor("black").rgbx
|
result.stroke = parseHtmlColor("black").rgbx
|
||||||
except:
|
except:
|
||||||
let e = getCurrentException()
|
raise currentExceptionAsPixieError()
|
||||||
raise newException(PixieError, e.msg, e)
|
|
||||||
result.strokeWidth = 1
|
result.strokeWidth = 1
|
||||||
result.transform = mat3()
|
result.transform = mat3()
|
||||||
result.strokeMiterLimit = defaultMiterLimit
|
result.strokeMiterLimit = defaultMiterLimit
|
||||||
|
@ -340,8 +339,7 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx =
|
||||||
except PixieError as e:
|
except PixieError as e:
|
||||||
raise e
|
raise e
|
||||||
except:
|
except:
|
||||||
let e = getCurrentException()
|
raise currentExceptionAsPixieError()
|
||||||
raise newException(PixieError, e.msg, e)
|
|
||||||
|
|
||||||
proc cairoLineCap(lineCap: LineCap): cairo.LineCap =
|
proc cairoLineCap(lineCap: LineCap): cairo.LineCap =
|
||||||
case lineCap:
|
case lineCap:
|
||||||
|
@ -526,8 +524,7 @@ proc draw(img: ptr Context, node: XmlNode, ctxStack: var seq[Ctx]) =
|
||||||
except PixieError as e:
|
except PixieError as e:
|
||||||
raise e
|
raise e
|
||||||
except:
|
except:
|
||||||
let e = getCurrentException()
|
raise currentExceptionAsPixieError()
|
||||||
raise newException(PixieError, e.msg, e)
|
|
||||||
|
|
||||||
proc decodeSvg*(data: string, width = 0, height = 0): Image =
|
proc decodeSvg*(data: string, width = 0, height = 0): Image =
|
||||||
## Render SVG file and return the image. Defaults to the SVG's view box size.
|
## Render SVG file and return the image. Defaults to the SVG's view box size.
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
## Load SVG files.
|
## Load SVG files.
|
||||||
|
|
||||||
import chroma, pixie/common, pixie/images, pixie/paints, pixie/paths, strutils,
|
import chroma, pixie/common, pixie/images, pixie/internal, pixie/paints,
|
||||||
tables, vmath, xmlparser, xmltree
|
pixie/paths, strutils, tables, vmath, xmlparser, xmltree
|
||||||
|
|
||||||
when defined(pixieDebugSvg):
|
when defined(pixieDebugSvg):
|
||||||
import strtabs
|
import strtabs
|
||||||
|
|
||||||
|
@ -44,8 +43,7 @@ proc initCtx(): Ctx =
|
||||||
result.fill = parseHtmlColor("black").rgbx
|
result.fill = parseHtmlColor("black").rgbx
|
||||||
result.stroke = parseHtmlColor("black").rgbx
|
result.stroke = parseHtmlColor("black").rgbx
|
||||||
except:
|
except:
|
||||||
let e = getCurrentException()
|
raise currentExceptionAsPixieError()
|
||||||
raise newException(PixieError, e.msg, e)
|
|
||||||
result.strokeWidth = 1
|
result.strokeWidth = 1
|
||||||
result.transform = mat3()
|
result.transform = mat3()
|
||||||
result.strokeMiterLimit = defaultMiterLimit
|
result.strokeMiterLimit = defaultMiterLimit
|
||||||
|
@ -323,8 +321,7 @@ proc decodeCtx(inherited: Ctx, node: XmlNode): Ctx =
|
||||||
except PixieError as e:
|
except PixieError as e:
|
||||||
raise e
|
raise e
|
||||||
except:
|
except:
|
||||||
let e = getCurrentException()
|
raise currentExceptionAsPixieError()
|
||||||
raise newException(PixieError, e.msg, e)
|
|
||||||
|
|
||||||
proc fill(img: Image, ctx: Ctx, path: Path) {.inline.} =
|
proc fill(img: Image, ctx: Ctx, path: Path) {.inline.} =
|
||||||
if ctx.display and ctx.opacity > 0:
|
if ctx.display and ctx.opacity > 0:
|
||||||
|
@ -560,8 +557,7 @@ proc draw(img: Image, node: XmlNode, ctxStack: var seq[Ctx]) =
|
||||||
except PixieError as e:
|
except PixieError as e:
|
||||||
raise e
|
raise e
|
||||||
except:
|
except:
|
||||||
let e = getCurrentException()
|
raise currentExceptionAsPixieError()
|
||||||
raise newException(PixieError, e.msg, e)
|
|
||||||
|
|
||||||
proc decodeSvg*(
|
proc decodeSvg*(
|
||||||
data: string, width = 0, height = 0
|
data: string, width = 0, height = 0
|
||||||
|
|
|
@ -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
|
type SvgFont* = ref object
|
||||||
unitsPerEm*, ascent*, descent*: float32
|
unitsPerEm*, ascent*, descent*: float32
|
||||||
|
@ -42,8 +43,7 @@ proc parseSvgFont*(buf: string): SvgFont {.raises: [PixieError].} =
|
||||||
try:
|
try:
|
||||||
parseXml(buf)
|
parseXml(buf)
|
||||||
except:
|
except:
|
||||||
let e = getCurrentException()
|
raise currentExceptionAsPixieError()
|
||||||
raise newException(PixieError, e.msg, e)
|
|
||||||
|
|
||||||
let defs = root.child("defs")
|
let defs = root.child("defs")
|
||||||
if defs == nil:
|
if defs == nil:
|
||||||
|
|
|
@ -3,6 +3,11 @@ import chroma, vmath
|
||||||
when defined(amd64) and not defined(pixieNoSimd):
|
when defined(amd64) and not defined(pixieNoSimd):
|
||||||
import nimsimd/sse2
|
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: [].} =
|
proc gaussianKernel*(radius: int): seq[uint16] {.raises: [].} =
|
||||||
## Compute lookup table for 1d Gaussian kernel.
|
## Compute lookup table for 1d Gaussian kernel.
|
||||||
## Values are [0, 255] * 256.
|
## Values are [0, 255] * 256.
|
||||||
|
|
|
@ -675,7 +675,7 @@ proc commandsToShapes(
|
||||||
pow(t, 3) * to
|
pow(t, 3) * to
|
||||||
|
|
||||||
var
|
var
|
||||||
t: float32 # Where we are at on the curve from [0, 1]
|
t: float32 # Where we are at on the curve from [0, 1]
|
||||||
step = 1.float32 # How far we want to try to move along the curve
|
step = 1.float32 # How far we want to try to move along the curve
|
||||||
prev = at
|
prev = at
|
||||||
next = compute(at, ctrl1, ctrl2, to, t + step)
|
next = compute(at, ctrl1, ctrl2, to, t + step)
|
||||||
|
@ -706,7 +706,7 @@ proc commandsToShapes(
|
||||||
pow(t, 2) * to
|
pow(t, 2) * to
|
||||||
|
|
||||||
var
|
var
|
||||||
t: float32 # Where we are at on the curve from [0, 1]
|
t: float32 # Where we are at on the curve from [0, 1]
|
||||||
step = 1.float32 # How far we want to try to move along the curve
|
step = 1.float32 # How far we want to try to move along the curve
|
||||||
prev = at
|
prev = at
|
||||||
next = compute(at, ctrl, to, t + step)
|
next = compute(at, ctrl, to, t + step)
|
||||||
|
@ -825,7 +825,7 @@ proc commandsToShapes(
|
||||||
let arc = endpointToCenterArcParams(at, radii, rotation, large, sweep, to)
|
let arc = endpointToCenterArcParams(at, radii, rotation, large, sweep, to)
|
||||||
|
|
||||||
var
|
var
|
||||||
t: float32 # Where we are at on the curve from [0, 1]
|
t: float32 # Where we are at on the curve from [0, 1]
|
||||||
step = 1.float32 # How far we want to try to move along the curve
|
step = 1.float32 # How far we want to try to move along the curve
|
||||||
prev = at
|
prev = at
|
||||||
while t != 1:
|
while t != 1:
|
||||||
|
@ -2330,7 +2330,8 @@ when defined(pixieSweeps):
|
||||||
let
|
let
|
||||||
sweepHeight = cutLines[currCutLine + 1] - cutLines[currCutLine]
|
sweepHeight = cutLines[currCutLine + 1] - cutLines[currCutLine]
|
||||||
yFracTop = ((y.float32 - cutLines[currCutLine]) / sweepHeight).clamp(0, 1)
|
yFracTop = ((y.float32 - cutLines[currCutLine]) / sweepHeight).clamp(0, 1)
|
||||||
yFracBottom = ((y.float32 + 1 - cutLines[currCutLine]) / sweepHeight).clamp(0, 1)
|
yFracBottom = ((y.float32 + 1 - cutLines[currCutLine]) /
|
||||||
|
sweepHeight).clamp(0, 1)
|
||||||
var i = 0
|
var i = 0
|
||||||
while i < sweep.len:
|
while i < sweep.len:
|
||||||
let
|
let
|
||||||
|
@ -2352,11 +2353,13 @@ when defined(pixieSweeps):
|
||||||
nw = vec2(sweep[i+0].atx, cutLines[currCutLine])
|
nw = vec2(sweep[i+0].atx, cutLines[currCutLine])
|
||||||
sw = vec2(sweep[i+0].tox, cutLines[currCutLine + 1])
|
sw = vec2(sweep[i+0].tox, cutLines[currCutLine + 1])
|
||||||
for x in minWi ..< maxWi:
|
for x in minWi ..< maxWi:
|
||||||
var area = pixelCover(nw - vec2(x.float32, y.float32), sw - vec2(x.float32, y.float32))
|
var area = pixelCover(nw - vec2(x.float32, y.float32), sw - vec2(
|
||||||
|
x.float32, y.float32))
|
||||||
coverages[x - startX] += (area * 255).uint8
|
coverages[x - startX] += (area * 255).uint8
|
||||||
|
|
||||||
let x = maxWi
|
let x = maxWi
|
||||||
var midArea = pixelCover(nw - vec2(x.float32, y.float32), sw - vec2(x.float32, y.float32))
|
var midArea = pixelCover(nw - vec2(x.float32, y.float32), sw - vec2(
|
||||||
|
x.float32, y.float32))
|
||||||
var midArea8 = (midArea * 255).uint8
|
var midArea8 = (midArea * 255).uint8
|
||||||
for x in maxWi ..< minEi:
|
for x in maxWi ..< minEi:
|
||||||
# TODO: Maybe try coverages of uint16 to prevent streeks in solid white fill?
|
# TODO: Maybe try coverages of uint16 to prevent streeks in solid white fill?
|
||||||
|
@ -2366,7 +2369,8 @@ when defined(pixieSweeps):
|
||||||
ne = vec2(sweep[i+1].atx, cutLines[currCutLine])
|
ne = vec2(sweep[i+1].atx, cutLines[currCutLine])
|
||||||
se = vec2(sweep[i+1].tox, cutLines[currCutLine + 1])
|
se = vec2(sweep[i+1].tox, cutLines[currCutLine + 1])
|
||||||
for x in minEi ..< maxEi:
|
for x in minEi ..< maxEi:
|
||||||
var area = midArea - pixelCover(ne - vec2(x.float32, y.float32), se - vec2(x.float32, y.float32))
|
var area = midArea - pixelCover(ne - vec2(x.float32, y.float32), se -
|
||||||
|
vec2(x.float32, y.float32))
|
||||||
coverages[x - startX] += (area * 255).uint8
|
coverages[x - startX] += (area * 255).uint8
|
||||||
|
|
||||||
i += 2
|
i += 2
|
||||||
|
@ -2382,7 +2386,8 @@ when defined(pixieSweeps):
|
||||||
inc currCutLine
|
inc currCutLine
|
||||||
if currCutLine == sweeps.len:
|
if currCutLine == sweeps.len:
|
||||||
break
|
break
|
||||||
coverages.computeCoverage(scanLine, startX, cutLines, currCutLine, sweeps[currCutLine])
|
coverages.computeCoverage(scanLine, startX, cutLines, currCutLine,
|
||||||
|
sweeps[currCutLine])
|
||||||
|
|
||||||
image.fillCoverage(
|
image.fillCoverage(
|
||||||
rgbx,
|
rgbx,
|
||||||
|
|
Loading…
Reference in a new issue