diff --git a/bindings/bindings.nim b/bindings/bindings.nim index 561786c..d52f717 100644 --- a/bindings/bindings.nim +++ b/bindings/bindings.nim @@ -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, diff --git a/bindings/generated/internal.nim b/bindings/generated/internal.nim index 29920ae..304bfec 100644 --- a/bindings/generated/internal.nim +++ b/bindings/generated/internal.nim @@ -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 @@ -691,24 +718,6 @@ proc pixie_context_get_text_align*(context: Context): HorizontalAlignment {.rais proc pixie_context_set_text_align*(context: Context, textAlign: HorizontalAlignment) {.raises: [], cdecl, exportc, dynlib.} = context.textAlign = textAlign -proc pixie_context_line_dash_len*(context: Context): int {.raises: [], cdecl, exportc, dynlib.} = - context.lineDash.len - -proc pixie_context_line_dash_add*(context: Context, v: float32) {.raises: [], cdecl, exportc, dynlib.} = - context.lineDash.add(v) - -proc pixie_context_line_dash_get*(context: Context, i: int): float32 {.raises: [], cdecl, exportc, dynlib.} = - context.lineDash[i] - -proc pixie_context_line_dash_set*(context: Context, i: int, v: float32) {.raises: [], cdecl, exportc, dynlib.} = - context.lineDash[i] = v - -proc pixie_context_line_dash_remove*(context: Context, i: int) {.raises: [], cdecl, exportc, dynlib.} = - context.lineDash.delete(i) - -proc pixie_context_line_dash_clear*(context: Context) {.raises: [], cdecl, exportc, dynlib.} = - context.lineDash.setLen(0) - proc pixie_context_save*(ctx: Context) {.raises: [], cdecl, exportc, dynlib.} = try: save(ctx) @@ -895,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.`$`) diff --git a/bindings/generated/pixie.nim b/bindings/generated/pixie.nim index af2b8aa..fa12da2 100644 --- a/bindings/generated/pixie.nim +++ b/bindings/generated/pixie.nim @@ -2,7 +2,14 @@ import bumpy, chroma, unicode, vmath export bumpy, chroma, unicode, vmath -{.push dynlib: "pixie.dll".} +when defined(windows): + const dllPath = "pixie.dll" +elif defined(macosx): + const dllPath = "libpixie.dll" +else: + const dllPath = "libpixie.so" + +{.push dynlib: dllPath.} type PixieError = object of ValueError @@ -85,92 +92,114 @@ type ColorStop* = object type TextMetrics* = object width*: float32 -type SeqFloat32* = object +type SeqFloat32Obj* = object reference: pointer -proc pixie_seq_float_32_unref*(x: SeqFloat32) {.importc: "pixie_seq_float_32_unref", cdecl.} +type SeqFloat32* = ref SeqFloat32Obj -proc `=destroy`(x: var SeqFloat32) = +proc pixie_seq_float_32_unref(x: SeqFloat32Obj) {.importc: "pixie_seq_float_32_unref", cdecl.} + +proc `=destroy`(x: var SeqFloat32Obj) = pixie_seq_float_32_unref(x) -type SeqSpan* = object +type SeqSpanObj* = object reference: pointer -proc pixie_seq_span_unref*(x: SeqSpan) {.importc: "pixie_seq_span_unref", cdecl.} +type SeqSpan* = ref SeqSpanObj -proc `=destroy`(x: var SeqSpan) = +proc pixie_seq_span_unref(x: SeqSpanObj) {.importc: "pixie_seq_span_unref", cdecl.} + +proc `=destroy`(x: var SeqSpanObj) = pixie_seq_span_unref(x) -type Image* = object +type ImageObj* = object reference: pointer -proc pixie_image_unref*(x: Image) {.importc: "pixie_image_unref", cdecl.} +type Image* = ref ImageObj -proc `=destroy`(x: var Image) = +proc pixie_image_unref(x: ImageObj) {.importc: "pixie_image_unref", cdecl.} + +proc `=destroy`(x: var ImageObj) = pixie_image_unref(x) -type Mask* = object +type MaskObj* = object reference: pointer -proc pixie_mask_unref*(x: Mask) {.importc: "pixie_mask_unref", cdecl.} +type Mask* = ref MaskObj -proc `=destroy`(x: var Mask) = +proc pixie_mask_unref(x: MaskObj) {.importc: "pixie_mask_unref", cdecl.} + +proc `=destroy`(x: var MaskObj) = pixie_mask_unref(x) -type Paint* = object +type PaintObj* = object reference: pointer -proc pixie_paint_unref*(x: Paint) {.importc: "pixie_paint_unref", cdecl.} +type Paint* = ref PaintObj -proc `=destroy`(x: var Paint) = +proc pixie_paint_unref(x: PaintObj) {.importc: "pixie_paint_unref", cdecl.} + +proc `=destroy`(x: var PaintObj) = pixie_paint_unref(x) -type Path* = object +type PathObj* = object reference: pointer -proc pixie_path_unref*(x: Path) {.importc: "pixie_path_unref", cdecl.} +type Path* = ref PathObj -proc `=destroy`(x: var Path) = +proc pixie_path_unref(x: PathObj) {.importc: "pixie_path_unref", cdecl.} + +proc `=destroy`(x: var PathObj) = pixie_path_unref(x) -type Typeface* = object +type TypefaceObj* = object reference: pointer -proc pixie_typeface_unref*(x: Typeface) {.importc: "pixie_typeface_unref", cdecl.} +type Typeface* = ref TypefaceObj -proc `=destroy`(x: var Typeface) = +proc pixie_typeface_unref(x: TypefaceObj) {.importc: "pixie_typeface_unref", cdecl.} + +proc `=destroy`(x: var TypefaceObj) = pixie_typeface_unref(x) -type Font* = object +type FontObj* = object reference: pointer -proc pixie_font_unref*(x: Font) {.importc: "pixie_font_unref", cdecl.} +type Font* = ref FontObj -proc `=destroy`(x: var Font) = +proc pixie_font_unref(x: FontObj) {.importc: "pixie_font_unref", cdecl.} + +proc `=destroy`(x: var FontObj) = pixie_font_unref(x) -type Span* = object +type SpanObj* = object reference: pointer -proc pixie_span_unref*(x: Span) {.importc: "pixie_span_unref", cdecl.} +type Span* = ref SpanObj -proc `=destroy`(x: var Span) = +proc pixie_span_unref(x: SpanObj) {.importc: "pixie_span_unref", cdecl.} + +proc `=destroy`(x: var SpanObj) = pixie_span_unref(x) -type Arrangement* = object +type ArrangementObj* = object reference: pointer -proc pixie_arrangement_unref*(x: Arrangement) {.importc: "pixie_arrangement_unref", cdecl.} +type Arrangement* = ref ArrangementObj -proc `=destroy`(x: var Arrangement) = +proc pixie_arrangement_unref(x: ArrangementObj) {.importc: "pixie_arrangement_unref", cdecl.} + +proc `=destroy`(x: var ArrangementObj) = pixie_arrangement_unref(x) -type Context* = object +type ContextObj* = object reference: pointer -proc pixie_context_unref*(x: Context) {.importc: "pixie_context_unref", cdecl.} +type Context* = ref ContextObj -proc `=destroy`(x: var Context) = +proc pixie_context_unref(x: ContextObj) {.importc: "pixie_context_unref", cdecl.} + +proc `=destroy`(x: var ContextObj) = pixie_context_unref(x) proc pixie_check_error(): bool {.importc: "pixie_check_error", cdecl.} @@ -185,16 +214,34 @@ proc takeError*(): cstring {.inline.} = proc pixie_seq_float_32_len(s: SeqFloat32): int {.importc: "pixie_seq_float_32_len", cdecl.} +proc len*(s: SeqFloat32): int = + pixie_seq_float_32_len(s) + proc pixie_seq_float_32_add(s: SeqFloat32, v: float32) {.importc: "pixie_seq_float_32_add", cdecl.} +proc add*(s: SeqFloat32, v: float32) = + pixie_seq_float_32_add(s, v) + proc pixie_seq_float_32_get(s: SeqFloat32, i: int): float32 {.importc: "pixie_seq_float_32_get", cdecl.} +proc `[]`*(s: SeqFloat32, i: int): float32 = + pixie_seq_float_32_get(s, i) + proc pixie_seq_float_32_set(s: SeqFloat32, i: int, v: float32) {.importc: "pixie_seq_float_32_set", cdecl.} +proc `[]=`*(s: SeqFloat32, i: int, v: float32) = + pixie_seq_float_32_set(s, i, v) + proc pixie_seq_float_32_remove(s: SeqFloat32, i: int) {.importc: "pixie_seq_float_32_remove", cdecl.} +proc remove*(s: SeqFloat32, i: int) = + pixie_seq_float_32_remove(s, i) + proc pixie_seq_float_32_clear(s: SeqFloat32) {.importc: "pixie_seq_float_32_clear", cdecl.} +proc clear*(s: SeqFloat32) = + pixie_seq_float_32_clear(s) + proc pixie_new_seq_float_32*(): SeqFloat32 {.importc: "pixie_new_seq_float_32", cdecl.} proc newSeqFloat32*(): SeqFloat32 = @@ -202,16 +249,34 @@ proc newSeqFloat32*(): SeqFloat32 = proc pixie_seq_span_len(s: SeqSpan): int {.importc: "pixie_seq_span_len", cdecl.} +proc len*(s: SeqSpan): int = + pixie_seq_span_len(s) + proc pixie_seq_span_add(s: SeqSpan, v: Span) {.importc: "pixie_seq_span_add", cdecl.} +proc add*(s: SeqSpan, v: Span) = + pixie_seq_span_add(s, v) + proc pixie_seq_span_get(s: SeqSpan, i: int): Span {.importc: "pixie_seq_span_get", cdecl.} +proc `[]`*(s: SeqSpan, i: int): Span = + pixie_seq_span_get(s, i) + proc pixie_seq_span_set(s: SeqSpan, i: int, v: Span) {.importc: "pixie_seq_span_set", cdecl.} +proc `[]=`*(s: SeqSpan, i: int, v: Span) = + pixie_seq_span_set(s, i, v) + proc pixie_seq_span_remove(s: SeqSpan, i: int) {.importc: "pixie_seq_span_remove", cdecl.} +proc remove*(s: SeqSpan, i: int) = + pixie_seq_span_remove(s, i) + proc pixie_seq_span_clear(s: SeqSpan) {.importc: "pixie_seq_span_clear", cdecl.} +proc clear*(s: SeqSpan) = + pixie_seq_span_clear(s) + proc pixie_new_seq_span*(): SeqSpan {.importc: "pixie_new_seq_span", cdecl.} proc newSeqSpan*(): SeqSpan = @@ -227,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.} = @@ -425,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.} = @@ -578,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.} = @@ -638,35 +722,88 @@ proc pixie_paint_set_image_mat(paint: Paint, imageMat: Mat3) {.importc: "pixie_p proc `imageMat=`*(paint: Paint, imageMat: Mat3) = pixie_paint_set_image_mat(paint, imageMat) +type PaintGradientHandlePositions = object + paint: Paint + +proc gradientHandlePositions*(paint: Paint): PaintGradientHandlePositions = + PaintGradientHandlePositions(paint: paint) + proc pixie_paint_gradient_handle_positions_len(s: Paint): int {.importc: "pixie_paint_gradient_handle_positions_len", cdecl.} +proc len*(s: PaintGradientHandlePositions): int = + pixie_paint_gradient_handle_positions_len(s.paint) + proc pixie_paint_gradient_handle_positions_add(s: Paint, v: Vec2) {.importc: "pixie_paint_gradient_handle_positions_add", cdecl.} +proc add*(s: PaintGradientHandlePositions, v: Vec2) = + pixie_paint_gradient_handle_positions_add(s.paint, v) + proc pixie_paint_gradient_handle_positions_get(s: Paint, i: int): Vec2 {.importc: "pixie_paint_gradient_handle_positions_get", cdecl.} +proc `[]`*(s: PaintGradientHandlePositions, i: int): Vec2 = + pixie_paint_gradient_handle_positions_get(s.paint, i) + proc pixie_paint_gradient_handle_positions_set(s: Paint, i: int, v: Vec2) {.importc: "pixie_paint_gradient_handle_positions_set", cdecl.} +proc `[]=`*(s: PaintGradientHandlePositions, i: int, v: Vec2) = + pixie_paint_gradient_handle_positions_set(s.paint, i, v) + proc pixie_paint_gradient_handle_positions_remove(s: Paint, i: int) {.importc: "pixie_paint_gradient_handle_positions_remove", cdecl.} +proc remove*(s: PaintGradientHandlePositions, i: int) = + pixie_paint_gradient_handle_positions_remove(s.paint, i) + proc pixie_paint_gradient_handle_positions_clear(s: Paint) {.importc: "pixie_paint_gradient_handle_positions_clear", cdecl.} +proc clear*(s: PaintGradientHandlePositions) = + pixie_paint_gradient_handle_positions_clear(s.paint) + +type PaintGradientStops = object + paint: Paint + +proc gradientStops*(paint: Paint): PaintGradientStops = + PaintGradientStops(paint: paint) + proc pixie_paint_gradient_stops_len(s: Paint): int {.importc: "pixie_paint_gradient_stops_len", cdecl.} +proc len*(s: PaintGradientStops): int = + pixie_paint_gradient_stops_len(s.paint) + proc pixie_paint_gradient_stops_add(s: Paint, v: ColorStop) {.importc: "pixie_paint_gradient_stops_add", cdecl.} +proc add*(s: PaintGradientStops, v: ColorStop) = + pixie_paint_gradient_stops_add(s.paint, v) + proc pixie_paint_gradient_stops_get(s: Paint, i: int): ColorStop {.importc: "pixie_paint_gradient_stops_get", cdecl.} +proc `[]`*(s: PaintGradientStops, i: int): ColorStop = + pixie_paint_gradient_stops_get(s.paint, i) + proc pixie_paint_gradient_stops_set(s: Paint, i: int, v: ColorStop) {.importc: "pixie_paint_gradient_stops_set", cdecl.} +proc `[]=`*(s: PaintGradientStops, i: int, v: ColorStop) = + pixie_paint_gradient_stops_set(s.paint, i, v) + proc pixie_paint_gradient_stops_remove(s: Paint, i: int) {.importc: "pixie_paint_gradient_stops_remove", cdecl.} +proc remove*(s: PaintGradientStops, i: int) = + pixie_paint_gradient_stops_remove(s.paint, i) + proc pixie_paint_gradient_stops_clear(s: Paint) {.importc: "pixie_paint_gradient_stops_clear", cdecl.} +proc clear*(s: PaintGradientStops) = + pixie_paint_gradient_stops_clear(s.paint) + proc pixie_paint_new_paint(paint: Paint): Paint {.importc: "pixie_paint_new_paint", cdecl.} 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.} = @@ -849,18 +986,42 @@ proc pixie_font_set_line_height(font: Font, lineHeight: float32) {.importc: "pix proc `lineHeight=`*(font: Font, lineHeight: float32) = pixie_font_set_line_height(font, lineHeight) +type FontPaints = object + font: Font + +proc paints*(font: Font): FontPaints = + FontPaints(font: font) + proc pixie_font_paints_len(s: Font): int {.importc: "pixie_font_paints_len", cdecl.} +proc len*(s: FontPaints): int = + pixie_font_paints_len(s.font) + proc pixie_font_paints_add(s: Font, v: Paint) {.importc: "pixie_font_paints_add", cdecl.} +proc add*(s: FontPaints, v: Paint) = + pixie_font_paints_add(s.font, v) + proc pixie_font_paints_get(s: Font, i: int): Paint {.importc: "pixie_font_paints_get", cdecl.} +proc `[]`*(s: FontPaints, i: int): Paint = + pixie_font_paints_get(s.font, i) + proc pixie_font_paints_set(s: Font, i: int, v: Paint) {.importc: "pixie_font_paints_set", cdecl.} +proc `[]=`*(s: FontPaints, i: int, v: Paint) = + pixie_font_paints_set(s.font, i, v) + proc pixie_font_paints_remove(s: Font, i: int) {.importc: "pixie_font_paints_remove", cdecl.} +proc remove*(s: FontPaints, i: int) = + pixie_font_paints_remove(s.font, i) + proc pixie_font_paints_clear(s: Font) {.importc: "pixie_font_paints_clear", cdecl.} +proc clear*(s: FontPaints) = + pixie_font_paints_clear(s.font) + proc pixie_font_get_text_case(font: Font): TextCase {.importc: "pixie_font_get_text_case", cdecl.} proc textCase*(font: Font): TextCase {.inline.} = @@ -921,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.} = @@ -946,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.} = @@ -1056,18 +1229,6 @@ proc pixie_context_set_text_align(context: Context, textAlign: HorizontalAlignme proc `textAlign=`*(context: Context, textAlign: HorizontalAlignment) = pixie_context_set_text_align(context, textAlign) -proc pixie_context_line_dash_len(s: Context): int {.importc: "pixie_context_line_dash_len", cdecl.} - -proc pixie_context_line_dash_add(s: Context, v: float32) {.importc: "pixie_context_line_dash_add", cdecl.} - -proc pixie_context_line_dash_get(s: Context, i: int): float32 {.importc: "pixie_context_line_dash_get", cdecl.} - -proc pixie_context_line_dash_set(s: Context, i: int, v: float32) {.importc: "pixie_context_line_dash_set", cdecl.} - -proc pixie_context_line_dash_remove(s: Context, i: int) {.importc: "pixie_context_line_dash_remove", cdecl.} - -proc pixie_context_line_dash_clear(s: Context) {.importc: "pixie_context_line_dash_clear", cdecl.} - proc pixie_context_save(ctx: Context) {.importc: "pixie_context_save", cdecl.} proc save*(ctx: Context) {.inline.} = @@ -1312,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.} = diff --git a/bindings/generated/pixie.py b/bindings/generated/pixie.py index 0523cda..6c7dacc 100644 --- a/bindings/generated/pixie.py +++ b/bindings/generated/pixie.py @@ -1,6 +1,17 @@ from ctypes import * +import os, sys +from pathlib import Path -dll = cdll.LoadLibrary("pixie.dll") +src_path = Path(__file__).resolve() +src_dir = str(src_path.parent) + +if sys.platform == "win32": + dllPath = "pixie.dll" +elif sys.platform == "darwin": + dllPath = "libpixie.dylib" +else: + dllPath = "libpixie.so" +dll = cdll.LoadLibrary(src_dir + "/" + dllPath) class PixieError(Exception): pass @@ -263,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) @@ -424,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) @@ -548,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) @@ -596,7 +623,7 @@ class Paint(Structure): def image_mat(self, image_mat): dll.pixie_paint_set_image_mat(self, image_mat) - class GradientHandlePositions: + class PaintGradientHandlePositions: def __init__(self, paint): self.paint = paint @@ -621,9 +648,9 @@ class Paint(Structure): @property def gradient_handle_positions(self): - return self.GradientHandlePositions(self) + return self.PaintGradientHandlePositions(self) - class GradientStops: + class PaintGradientStops: def __init__(self, paint): self.paint = paint @@ -648,7 +675,7 @@ class Paint(Structure): @property def gradient_stops(self): - return self.GradientStops(self) + return self.PaintGradientStops(self) def new_paint(self): result = dll.pixie_paint_new_paint(self) @@ -666,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) @@ -823,7 +854,7 @@ class Font(Structure): def line_height(self, line_height): dll.pixie_font_set_line_height(self, line_height) - class Paints: + class FontPaints: def __init__(self, font): self.font = font @@ -848,7 +879,7 @@ class Font(Structure): @property def paints(self): - return self.Paints(self) + return self.FontPaints(self) @property def text_case(self): @@ -910,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") @@ -954,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) @@ -1042,33 +1083,6 @@ class Context(Structure): def text_align(self, text_align): dll.pixie_context_set_text_align(self, text_align) - class LineDash: - - def __init__(self, context): - self.context = context - - def __len__(self): - return dll.pixie_context_line_dash_len(self.context) - - def __getitem__(self, index): - return dll.pixie_context_line_dash_get(self.context, index) - - def __setitem__(self, index, value): - dll.pixie_context_line_dash_set(self.context, index, value) - - def __delitem__(self, index): - dll.pixie_context_line_dash_remove(self.context, index) - - def append(self, value): - dll.pixie_context_line_dash_add(self.context, value) - - def clear(self): - dll.pixie_context_line_dash_clear(self.context) - - @property - def line_dash(self): - return self.LineDash(self) - def save(self): dll.pixie_context_save(self) if check_error(): @@ -1237,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(): @@ -1368,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 @@ -1467,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 @@ -1545,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 @@ -1623,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 @@ -1788,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 @@ -1809,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 @@ -1875,24 +1877,6 @@ dll.pixie_context_get_text_align.restype = HorizontalAlignment dll.pixie_context_set_text_align.argtypes = [Context, HorizontalAlignment] dll.pixie_context_set_text_align.restype = None -dll.pixie_context_line_dash_len.argtypes = [Context] -dll.pixie_context_line_dash_len.restype = c_longlong - -dll.pixie_context_line_dash_get.argtypes = [Context, c_longlong] -dll.pixie_context_line_dash_get.restype = c_float - -dll.pixie_context_line_dash_set.argtypes = [Context, c_longlong, c_float] -dll.pixie_context_line_dash_set.restype = None - -dll.pixie_context_line_dash_remove.argtypes = [Context, c_longlong] -dll.pixie_context_line_dash_remove.restype = None - -dll.pixie_context_line_dash_add.argtypes = [Context, c_float] -dll.pixie_context_line_dash_add.restype = None - -dll.pixie_context_line_dash_clear.argtypes = [Context] -dll.pixie_context_line_dash_clear.restype = None - dll.pixie_context_save.argtypes = [Context] dll.pixie_context_save.restype = None @@ -2013,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 diff --git a/src/pixie/contexts.nim b/src/pixie/contexts.nim index 3759b82..deb7eac 100644 --- a/src/pixie/contexts.nim +++ b/src/pixie/contexts.nim @@ -18,7 +18,7 @@ type font*: string ## File path to a .ttf or .otf file. fontSize*: float32 textAlign*: HorizontalAlignment - lineDash*: seq[float32] + lineDash: seq[float32] path: Path mat: Mat3 mask: Mask