Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bindings/bindings.nim
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,13 @@ exportRefObject Paint:
constructor:
newPaint(PaintKind)
procs:
newPaint(Paint)
copy(Paint)

exportRefObject Path:
constructor:
newPath
procs:
copy(Path)
transform(Path, Mat3)
addPath(Path, Path)
closePath(Path)
Expand Down Expand Up @@ -233,6 +234,7 @@ exportRefObject Font:
strikethrough
noKerningAdjustments
procs:
copy(Font)
scale(Font)
defaultLineHeight
typeset(Font, string, Vec2, HorizontalAlignment, VerticalAlignment, bool)
Expand Down
7 changes: 3 additions & 4 deletions src/pixie/contexts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,12 @@ proc state(ctx: Context): ContextState =
result.mat = ctx.mat
result.mask = if ctx.mask != nil: ctx.mask.copy() else: nil

proc save*(ctx: Context) {.inline, raises: [PixieError].} =
proc save*(ctx: Context) {.inline, raises: [].} =
## Saves the entire state of the context by pushing the current state onto
## a stack.
ctx.stateStack.add(ctx.state())

ctx.fillStyle = newPaint(ctx.fillStyle)
ctx.strokeStyle = newPaint(ctx.strokeStyle)
ctx.fillStyle = ctx.fillStyle.copy()
ctx.strokeStyle = ctx.strokeStyle.copy()

proc saveLayer*(ctx: Context) {.raises: [PixieError].} =
## Saves the entire state of the context by pushing the current state onto
Expand Down
2 changes: 1 addition & 1 deletion src/pixie/fileformats/svg.nim
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ proc newImage*(svg: Svg): Image {.raises: [PixieError].} =
blendMode = NormalBlend # Switch to normal when compositing multiple paths

if props.stroke != rgbx(0, 0, 0, 0) and props.strokeWidth > 0:
let paint = newPaint(props.stroke)
let paint = props.stroke.copy()
paint.color.a *= (props.opacity * props.strokeOpacity)
result.strokePath(
path,
Expand Down
11 changes: 11 additions & 0 deletions src/pixie/fonts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@ proc newFont*(typeface: Typeface): Font {.raises: [].} =
result.paint = newPaint(SolidPaint)
result.paint.color = color(0, 0, 0, 1)

proc copy*(font: Font): Font {.raises: [].} =
result = Font()
result.typeface = font.typeface
result.size = font.size
result.lineHeight = font.lineHeight
result.paints = font.paints
result.textCase = font.textCase
result.underline = font.underline
result.strikethrough = font.strikethrough
result.noKerningAdjustments = font.noKerningAdjustments

proc newSpan*(text: string, font: Font): Span {.raises: [].} =
## Creates a span, associating a font with the text.
result = Span()
Expand Down
6 changes: 4 additions & 2 deletions src/pixie/images.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ proc newMask*(image: Image): Mask {.hasSimd, raises: [PixieError].} =
for i in 0 ..< image.data.len:
result.data[i] = image.data[i].a

proc copy*(image: Image): Image {.raises: [PixieError].} =
proc copy*(image: Image): Image {.raises: [].} =
## Copies the image data into a new image.
result = newImage(image.width, image.height)
result = Image()
result.width = image.width
result.height = image.height
result.data = image.data

proc `$`*(image: Image): string {.raises: [].} =
Expand Down
6 changes: 4 additions & 2 deletions src/pixie/masks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ type UnsafeMask = distinct Mask
when defined(release):
{.push checks: off.}

proc copy*(mask: Mask): Mask {.raises: [PixieError].} =
proc copy*(mask: Mask): Mask {.raises: [].} =
## Copies the image data into a new image.
result = newMask(mask.width, mask.height)
result = Mask()
result.width = mask.width
result.height = mask.height
result.data = mask.data

proc `$`*(mask: Mask): string {.raises: [].} =
Expand Down
2 changes: 1 addition & 1 deletion src/pixie/paints.nim
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ proc newPaint*(kind: PaintKind): Paint {.raises: [].} =
## Create a new Paint.
result = Paint(kind: kind, opacity: 1, imageMat: mat3())

proc newPaint*(paint: Paint): Paint {.raises: [].} =
proc copy*(paint: Paint): Paint {.raises: [].} =
## Create a new Paint with the same properties.
result = newPaint(paint.kind)
result.blendMode = paint.blendMode
Expand Down
6 changes: 6 additions & 0 deletions src/pixie/paths.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ proc newPath*(): Path {.raises: [].} =
## Create a new Path.
Path()

proc copy*(path: Path): Path {.raises: [].} =
result = Path()
result.commands = path.commands
result.start = path.start
result.at = path.at

proc pixelScale(transform: Mat3): float32 =
## What is the largest scale factor of this transform?
max(
Expand Down