ref type constructors

This commit is contained in:
Ryan Oldenburg 2021-08-26 14:00:30 -05:00
parent 50a6034096
commit 1a594fcbbc
4 changed files with 120 additions and 118 deletions

View file

@ -69,6 +69,7 @@ exportSeq seq[Span]:
pixie.computeBounds
exportRefObject Image, ["width", "height"]:
discard newImage(0, 0)
export
pixie.writeFile,
pixie.wh,
@ -97,6 +98,7 @@ exportRefObject Image, ["width", "height"]:
pixie.newContext
exportRefObject Mask, ["width", "height"]:
discard newMask(0, 0)
export
pixie.writeFile,
pixie.wh,
@ -118,10 +120,12 @@ exportRefObject Mask, ["width", "height"]:
pixie.strokePath
exportRefObject Paint, ["*"]:
discard newPaint(pkSolid)
export
pixie.newPaint
exportRefObject Path, ["*"]:
discard newPath()
export
pixie.transform,
pixie.addPath,
@ -147,6 +151,7 @@ exportRefObject Path, ["*"]:
pixie.polygon
exportRefObject Typeface, ["*"]:
discard
export
pixie.ascent,
pixie.descent,
@ -158,6 +163,7 @@ exportRefObject Typeface, ["*"]:
pixie.newFont
exportRefObject Font, ["*"]:
discard
export
pixie.scale,
pixie.defaultLineHeight,
@ -165,13 +171,15 @@ exportRefObject Font, ["*"]:
pixie.computeBounds
exportRefObject Span, ["*"]:
discard
discard newSpan("", Font())
exportRefObject Arrangement, []:
discard
export
pixie.computeBounds
exportRefObject Context, ["*"]:
discard newContext(0, 0)
export
pixie.save,
pixie.saveLayer,
@ -218,12 +226,6 @@ exportRefObject Context, ["*"]:
exportProcs:
export
pixie.newImage,
pixie.newMask,
pixie.newPaint,
pixie.newPath,
pixie.newSpan,
pixie.newContext,
pixie.readImage,
pixie.readmask,
pixie.readTypeface,

View file

@ -67,6 +67,12 @@ proc pixie_seq_span_compute_bounds*(spans: SeqSpan): Vec2 {.raises: [], cdecl, e
proc pixie_image_unref*(x: Image) {.raises: [], cdecl, exportc, dynlib.} =
GC_unref(x)
proc pixie_new_image*(width: int, height: int): Image {.raises: [], cdecl, exportc, dynlib.} =
try:
result = newImage(width, height)
except PixieError as e:
lastError = e
proc pixie_image_get_width*(image: Image): int {.raises: [], cdecl, exportc, dynlib.} =
image.width
@ -223,6 +229,12 @@ proc pixie_image_new_context*(image: Image): Context {.raises: [], cdecl, export
proc pixie_mask_unref*(x: Mask) {.raises: [], cdecl, exportc, dynlib.} =
GC_unref(x)
proc pixie_new_mask*(width: int, height: int): Mask {.raises: [], cdecl, exportc, dynlib.} =
try:
result = newMask(width, height)
except PixieError as e:
lastError = e
proc pixie_mask_get_width*(mask: Mask): int {.raises: [], cdecl, exportc, dynlib.} =
mask.width
@ -343,6 +355,9 @@ proc pixie_mask_stroke_path*(mask: Mask, path: Path, transform: Mat3, stroke_wid
proc pixie_paint_unref*(x: Paint) {.raises: [], cdecl, exportc, dynlib.} =
GC_unref(x)
proc pixie_new_paint*(kind: PaintKind): Paint {.raises: [], cdecl, exportc, dynlib.} =
newPaint(kind)
proc pixie_paint_get_kind*(paint: Paint): PaintKind {.raises: [], cdecl, exportc, dynlib.} =
paint.kind
@ -421,6 +436,9 @@ proc pixie_paint_new_paint*(paint: Paint): Paint {.raises: [], cdecl, exportc, d
proc pixie_path_unref*(x: Path) {.raises: [], cdecl, exportc, dynlib.} =
GC_unref(x)
proc pixie_new_path*(): Path {.raises: [], cdecl, exportc, dynlib.} =
newPath()
proc pixie_path_transform*(path: Path, mat: Mat3) {.raises: [], cdecl, exportc, dynlib.} =
transform(path, mat)
@ -604,6 +622,9 @@ proc pixie_font_compute_bounds*(font: Font, text: cstring): Vec2 {.raises: [], c
proc pixie_span_unref*(x: Span) {.raises: [], cdecl, exportc, dynlib.} =
GC_unref(x)
proc pixie_new_span*(text: cstring, font: Font): Span {.raises: [], cdecl, exportc, dynlib.} =
newSpan(text.`$`, font)
proc pixie_span_get_text*(span: Span): cstring {.raises: [], cdecl, exportc, dynlib.} =
span.text.cstring
@ -625,6 +646,12 @@ proc pixie_arrangement_compute_bounds*(arrangement: Arrangement): Vec2 {.raises:
proc pixie_context_unref*(x: Context) {.raises: [], cdecl, exportc, dynlib.} =
GC_unref(x)
proc pixie_new_context*(width: int, height: int): Context {.raises: [], cdecl, exportc, dynlib.} =
try:
result = newContext(width, height)
except PixieError as e:
lastError = e
proc pixie_context_get_image*(context: Context): Image {.raises: [], cdecl, exportc, dynlib.} =
context.image
@ -877,33 +904,6 @@ proc pixie_context_is_point_in_stroke*(ctx: Context, x: float32, y: float32): bo
except PixieError as e:
lastError = e
proc pixie_new_image*(width: int, height: int): Image {.raises: [], cdecl, exportc, dynlib.} =
try:
result = newImage(width, height)
except PixieError as e:
lastError = e
proc pixie_new_mask*(width: int, height: int): Mask {.raises: [], cdecl, exportc, dynlib.} =
try:
result = newMask(width, height)
except PixieError as e:
lastError = e
proc pixie_new_paint*(kind: PaintKind): Paint {.raises: [], cdecl, exportc, dynlib.} =
newPaint(kind)
proc pixie_new_path*(): Path {.raises: [], cdecl, exportc, dynlib.} =
newPath()
proc pixie_new_span*(text: cstring, font: Font): Span {.raises: [], cdecl, exportc, dynlib.} =
newSpan(text.`$`, font)
proc pixie_new_context*(width: int, height: int): Context {.raises: [], cdecl, exportc, dynlib.} =
try:
result = newContext(width, height)
except PixieError as e:
lastError = e
proc pixie_read_image*(file_path: cstring): Image {.raises: [], cdecl, exportc, dynlib.} =
try:
result = readImage(file_path.`$`)

View file

@ -292,6 +292,13 @@ proc pixie_seq_span_compute_bounds(spans: SeqSpan): Vec2 {.importc: "pixie_seq_s
proc computeBounds*(spans: SeqSpan): Vec2 {.inline.} =
result = pixie_seq_span_compute_bounds(spans)
proc pixie_new_image(width: int, height: int): Image {.importc: "pixie_new_image", cdecl.}
proc newImage*(width: int, height: int): Image {.inline.} =
result = pixie_new_image(width, height)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_image_get_width(image: Image): int {.importc: "pixie_image_get_width", cdecl.}
proc width*(image: Image): int {.inline.} =
@ -490,6 +497,13 @@ proc pixie_image_new_context(image: Image): Context {.importc: "pixie_image_new_
proc newContext*(image: Image): Context {.inline.} =
result = pixie_image_new_context(image)
proc pixie_new_mask(width: int, height: int): Mask {.importc: "pixie_new_mask", cdecl.}
proc newMask*(width: int, height: int): Mask {.inline.} =
result = pixie_new_mask(width, height)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_mask_get_width(mask: Mask): int {.importc: "pixie_mask_get_width", cdecl.}
proc width*(mask: Mask): int {.inline.} =
@ -643,6 +657,11 @@ proc strokePath*(mask: Mask, path: Path, transform: Mat3, strokeWidth: float32,
if checkError():
raise newException(PixieError, $takeError())
proc pixie_new_paint(kind: PaintKind): Paint {.importc: "pixie_new_paint", cdecl.}
proc newPaint*(kind: PaintKind): Paint {.inline.} =
result = pixie_new_paint(kind)
proc pixie_paint_get_kind(paint: Paint): PaintKind {.importc: "pixie_paint_get_kind", cdecl.}
proc kind*(paint: Paint): PaintKind {.inline.} =
@ -780,6 +799,11 @@ proc pixie_paint_new_paint(paint: Paint): Paint {.importc: "pixie_paint_new_pain
proc newPaint*(paint: Paint): Paint {.inline.} =
result = pixie_paint_new_paint(paint)
proc pixie_new_path(): Path {.importc: "pixie_new_path", cdecl.}
proc newPath*(): Path {.inline.} =
result = pixie_new_path()
proc pixie_path_transform(path: Path, mat: Mat3) {.importc: "pixie_path_transform", cdecl.}
proc transform*(path: Path, mat: Mat3) {.inline.} =
@ -1058,6 +1082,11 @@ proc pixie_font_compute_bounds(font: Font, text: cstring): Vec2 {.importc: "pixi
proc computeBounds*(font: Font, text: string): Vec2 {.inline.} =
result = pixie_font_compute_bounds(font, text.cstring)
proc pixie_new_span(text: cstring, font: Font): Span {.importc: "pixie_new_span", cdecl.}
proc newSpan*(text: string, font: Font): Span {.inline.} =
result = pixie_new_span(text.cstring, font)
proc pixie_span_get_text(span: Span): cstring {.importc: "pixie_span_get_text", cdecl.}
proc text*(span: Span): cstring {.inline.} =
@ -1083,6 +1112,13 @@ proc pixie_arrangement_compute_bounds(arrangement: Arrangement): Vec2 {.importc:
proc computeBounds*(arrangement: Arrangement): Vec2 {.inline.} =
result = pixie_arrangement_compute_bounds(arrangement)
proc pixie_new_context(width: int, height: int): Context {.importc: "pixie_new_context", cdecl.}
proc newContext*(width: int, height: int): Context {.inline.} =
result = pixie_new_context(width, height)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_context_get_image(context: Context): Image {.importc: "pixie_context_get_image", cdecl.}
proc image*(context: Context): Image {.inline.} =
@ -1437,42 +1473,6 @@ proc isPointInStroke*(ctx: Context, x: float32, y: float32): bool {.inline.} =
if checkError():
raise newException(PixieError, $takeError())
proc pixie_new_image(width: int, height: int): Image {.importc: "pixie_new_image", cdecl.}
proc newImage*(width: int, height: int): Image {.inline.} =
result = pixie_new_image(width, height)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_new_mask(width: int, height: int): Mask {.importc: "pixie_new_mask", cdecl.}
proc newMask*(width: int, height: int): Mask {.inline.} =
result = pixie_new_mask(width, height)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_new_paint(kind: PaintKind): Paint {.importc: "pixie_new_paint", cdecl.}
proc newPaint*(kind: PaintKind): Paint {.inline.} =
result = pixie_new_paint(kind)
proc pixie_new_path(): Path {.importc: "pixie_new_path", cdecl.}
proc newPath*(): Path {.inline.} =
result = pixie_new_path()
proc pixie_new_span(text: cstring, font: Font): Span {.importc: "pixie_new_span", cdecl.}
proc newSpan*(text: string, font: Font): Span {.inline.} =
result = pixie_new_span(text.cstring, font)
proc pixie_new_context(width: int, height: int): Context {.importc: "pixie_new_context", cdecl.}
proc newContext*(width: int, height: int): Context {.inline.} =
result = pixie_new_context(width, height)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_read_image(file_path: cstring): Image {.importc: "pixie_read_image", cdecl.}
proc readImage*(filePath: string): Image {.inline.} =

View file

@ -274,6 +274,12 @@ class Image(Structure):
def __del__(self):
dll.pixie_image_unref(self)
def __init__(self, width, height):
result = dll.pixie_new_image(width, height)
if check_error():
raise PixieError(take_error())
self.ref = result
@property
def width(self):
return dll.pixie_image_get_width(self)
@ -435,6 +441,12 @@ class Mask(Structure):
def __del__(self):
dll.pixie_mask_unref(self)
def __init__(self, width, height):
result = dll.pixie_new_mask(width, height)
if check_error():
raise PixieError(take_error())
self.ref = result
@property
def width(self):
return dll.pixie_mask_get_width(self)
@ -559,6 +571,10 @@ class Paint(Structure):
def __del__(self):
dll.pixie_paint_unref(self)
def __init__(self, kind):
result = dll.pixie_new_paint(kind)
self.ref = result
@property
def kind(self):
return dll.pixie_paint_get_kind(self)
@ -677,6 +693,10 @@ class Path(Structure):
def __del__(self):
dll.pixie_path_unref(self)
def __init__(self):
result = dll.pixie_new_path()
self.ref = result
def transform(self, mat):
dll.pixie_path_transform(self, mat)
@ -921,6 +941,10 @@ class Span(Structure):
def __del__(self):
dll.pixie_span_unref(self)
def __init__(self, text, font):
result = dll.pixie_new_span(text.encode("utf8"), font)
self.ref = result
@property
def text(self):
return dll.pixie_span_get_text(self).decode("utf8")
@ -965,6 +989,12 @@ class Context(Structure):
def __del__(self):
dll.pixie_context_unref(self)
def __init__(self, width, height):
result = dll.pixie_new_context(width, height)
if check_error():
raise PixieError(take_error())
self.ref = result
@property
def image(self):
return dll.pixie_context_get_image(self)
@ -1221,36 +1251,6 @@ class Context(Structure):
raise PixieError(take_error())
return result
def new_image(width, height):
result = dll.pixie_new_image(width, height)
if check_error():
raise PixieError(take_error())
return result
def new_mask(width, height):
result = dll.pixie_new_mask(width, height)
if check_error():
raise PixieError(take_error())
return result
def new_paint(kind):
result = dll.pixie_new_paint(kind)
return result
def new_path():
result = dll.pixie_new_path()
return result
def new_span(text, font):
result = dll.pixie_new_span(text.encode("utf8"), font)
return result
def new_context(width, height):
result = dll.pixie_new_context(width, height)
if check_error():
raise PixieError(take_error())
return result
def read_image(file_path):
result = dll.pixie_read_image(file_path.encode("utf8"))
if check_error():
@ -1352,6 +1352,9 @@ dll.pixie_seq_span_compute_bounds.restype = Vector2
dll.pixie_image_unref.argtypes = [Image]
dll.pixie_image_unref.restype = None
dll.pixie_new_image.argtypes = []
dll.pixie_new_image.restype = c_ulonglong
dll.pixie_image_get_width.argtypes = [Image]
dll.pixie_image_get_width.restype = c_longlong
@ -1451,6 +1454,9 @@ dll.pixie_image_new_context.restype = Context
dll.pixie_mask_unref.argtypes = [Mask]
dll.pixie_mask_unref.restype = None
dll.pixie_new_mask.argtypes = []
dll.pixie_new_mask.restype = c_ulonglong
dll.pixie_mask_get_width.argtypes = [Mask]
dll.pixie_mask_get_width.restype = c_longlong
@ -1529,6 +1535,9 @@ dll.pixie_mask_stroke_path.restype = None
dll.pixie_paint_unref.argtypes = [Paint]
dll.pixie_paint_unref.restype = None
dll.pixie_new_paint.argtypes = []
dll.pixie_new_paint.restype = c_ulonglong
dll.pixie_paint_get_kind.argtypes = [Paint]
dll.pixie_paint_get_kind.restype = PaintKind
@ -1607,6 +1616,9 @@ dll.pixie_paint_new_paint.restype = Paint
dll.pixie_path_unref.argtypes = [Path]
dll.pixie_path_unref.restype = None
dll.pixie_new_path.argtypes = []
dll.pixie_new_path.restype = c_ulonglong
dll.pixie_path_transform.argtypes = [Path, Matrix3]
dll.pixie_path_transform.restype = None
@ -1772,6 +1784,9 @@ dll.pixie_font_compute_bounds.restype = Vector2
dll.pixie_span_unref.argtypes = [Span]
dll.pixie_span_unref.restype = None
dll.pixie_new_span.argtypes = []
dll.pixie_new_span.restype = c_ulonglong
dll.pixie_span_get_text.argtypes = [Span]
dll.pixie_span_get_text.restype = c_char_p
@ -1793,6 +1808,9 @@ dll.pixie_arrangement_compute_bounds.restype = Vector2
dll.pixie_context_unref.argtypes = [Context]
dll.pixie_context_unref.restype = None
dll.pixie_new_context.argtypes = []
dll.pixie_new_context.restype = c_ulonglong
dll.pixie_context_get_image.argtypes = [Context]
dll.pixie_context_get_image.restype = Image
@ -1979,24 +1997,6 @@ dll.pixie_context_is_point_in_path.restype = c_bool
dll.pixie_context_is_point_in_stroke.argtypes = [Context, c_float, c_float]
dll.pixie_context_is_point_in_stroke.restype = c_bool
dll.pixie_new_image.argtypes = [c_longlong, c_longlong]
dll.pixie_new_image.restype = Image
dll.pixie_new_mask.argtypes = [c_longlong, c_longlong]
dll.pixie_new_mask.restype = Mask
dll.pixie_new_paint.argtypes = [PaintKind]
dll.pixie_new_paint.restype = Paint
dll.pixie_new_path.argtypes = []
dll.pixie_new_path.restype = Path
dll.pixie_new_span.argtypes = [c_char_p, Font]
dll.pixie_new_span.restype = Span
dll.pixie_new_context.argtypes = [c_longlong, c_longlong]
dll.pixie_new_context.restype = Context
dll.pixie_read_image.argtypes = [c_char_p]
dll.pixie_read_image.restype = Image