Merge pull request #268 from guzba/master

value obj constructors, default param values
This commit is contained in:
treeform 2021-08-27 20:49:43 -07:00 committed by GitHub
commit b04f0c3d6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 418 additions and 184 deletions

View file

@ -1,12 +1,5 @@
import bindy, pixie, unicode
type
Vector2 = object
x*, y*: float32
Matrix3 = object
a*, b*, c*, d*, e*, f*, g*, h*, i*: float32
var lastError*: ref PixieError
proc takeError*(): string =
@ -16,6 +9,19 @@ proc takeError*(): string =
proc checkError*(): bool =
result = lastError != nil
type
Vector2* = object
x*, y*: float32
Matrix3* = object
a*, b*, c*, d*, e*, f*, g*, h*, i*: float32
proc vector2*(x, y: float32): Vector2 =
Vector2(x: x, y: y)
proc matrix3*(): Matrix3 =
Matrix3(a: 1, b: 0, c: 0, d: 0, e: 1, f: 0, g: 0, h: 0, i: 1)
proc drawImage1*(
ctx: Context, image: Image, dx, dy: float32
) {.raises: [PixieError].} =
@ -34,6 +40,11 @@ proc drawImage3*(
) {.raises: [PixieError].} =
ctx.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight)
exportConsts:
export
defaultMiterLimit,
autoLineHeight
exportEnums:
export
FileFormat,
@ -46,20 +57,29 @@ exportEnums:
VerticalAlignment,
TextCase
exportObjects:
export
Vector2,
Matrix3,
Rect,
Color,
ColorStop,
TextMetrics
exportProcs:
export
bindings.checkError,
bindings.takeError
exportObject Vector2:
discard vector2(0, 0)
exportObject Matrix3:
discard matrix3()
exportObject Rect:
discard
exportObject Color:
discard
exportObject ColorStop:
discard colorStop(Color(), 0)
exportObject TextMetrics:
discard
exportSeq seq[float32]:
discard

View file

@ -4,6 +4,15 @@ proc pixie_check_error*(): bool {.raises: [], cdecl, exportc, dynlib.} =
proc pixie_take_error*(): cstring {.raises: [], cdecl, exportc, dynlib.} =
takeError().cstring
proc pixie_vector_2*(x: float32, y: float32): Vector2 {.raises: [], cdecl, exportc, dynlib.} =
vector2(x, y)
proc pixie_matrix_3*(): Matrix3 {.raises: [], cdecl, exportc, dynlib.} =
matrix3()
proc pixie_color_stop*(color: Color, position: float32): ColorStop {.raises: [], cdecl, exportc, dynlib.} =
colorStop(color, position)
type SeqFloat32* = ref object
s: seq[float32]
@ -22,7 +31,7 @@ proc pixie_seq_float_32_get*(s: SeqFloat32, i: int): float32 {.raises: [], cdecl
proc pixie_seq_float_32_set*(s: SeqFloat32, i: int, v: float32) {.raises: [], cdecl, exportc, dynlib.} =
s.s[i] = v
proc pixie_seq_float_32_remove*(s: SeqFloat32, i: int) {.raises: [], cdecl, exportc, dynlib.} =
proc pixie_seq_float_32_delete*(s: SeqFloat32, i: int) {.raises: [], cdecl, exportc, dynlib.} =
s.s.delete(i)
proc pixie_seq_float_32_clear*(s: SeqFloat32) {.raises: [], cdecl, exportc, dynlib.} =
@ -49,7 +58,7 @@ proc pixie_seq_span_get*(s: SeqSpan, i: int): Span {.raises: [], cdecl, exportc,
proc pixie_seq_span_set*(s: SeqSpan, i: int, v: Span) {.raises: [], cdecl, exportc, dynlib.} =
s.s[i] = v
proc pixie_seq_span_remove*(s: SeqSpan, i: int) {.raises: [], cdecl, exportc, dynlib.} =
proc pixie_seq_span_delete*(s: SeqSpan, i: int) {.raises: [], cdecl, exportc, dynlib.} =
s.s.delete(i)
proc pixie_seq_span_clear*(s: SeqSpan) {.raises: [], cdecl, exportc, dynlib.} =
@ -406,7 +415,7 @@ proc pixie_paint_gradient_handle_positions_get*(paint: Paint, i: int): Vec2 {.ra
proc pixie_paint_gradient_handle_positions_set*(paint: Paint, i: int, v: Vec2) {.raises: [], cdecl, exportc, dynlib.} =
paint.gradientHandlePositions[i] = v
proc pixie_paint_gradient_handle_positions_remove*(paint: Paint, i: int) {.raises: [], cdecl, exportc, dynlib.} =
proc pixie_paint_gradient_handle_positions_delete*(paint: Paint, i: int) {.raises: [], cdecl, exportc, dynlib.} =
paint.gradientHandlePositions.delete(i)
proc pixie_paint_gradient_handle_positions_clear*(paint: Paint) {.raises: [], cdecl, exportc, dynlib.} =
@ -424,7 +433,7 @@ proc pixie_paint_gradient_stops_get*(paint: Paint, i: int): ColorStop {.raises:
proc pixie_paint_gradient_stops_set*(paint: Paint, i: int, v: ColorStop) {.raises: [], cdecl, exportc, dynlib.} =
paint.gradientStops[i] = v
proc pixie_paint_gradient_stops_remove*(paint: Paint, i: int) {.raises: [], cdecl, exportc, dynlib.} =
proc pixie_paint_gradient_stops_delete*(paint: Paint, i: int) {.raises: [], cdecl, exportc, dynlib.} =
paint.gradientStops.delete(i)
proc pixie_paint_gradient_stops_clear*(paint: Paint) {.raises: [], cdecl, exportc, dynlib.} =
@ -577,7 +586,7 @@ proc pixie_font_paints_get*(font: Font, i: int): Paint {.raises: [], cdecl, expo
proc pixie_font_paints_set*(font: Font, i: int, v: Paint) {.raises: [], cdecl, exportc, dynlib.} =
font.paints[i] = v
proc pixie_font_paints_remove*(font: Font, i: int) {.raises: [], cdecl, exportc, dynlib.} =
proc pixie_font_paints_delete*(font: Font, i: int) {.raises: [], cdecl, exportc, dynlib.} =
font.paints.delete(i)
proc pixie_font_paints_clear*(font: Font) {.raises: [], cdecl, exportc, dynlib.} =

View file

@ -3,16 +3,20 @@ import bumpy, chroma, unicode, vmath
export bumpy, chroma, unicode, vmath
when defined(windows):
const dllPath = "pixie.dll"
const libName = "pixie.dll"
elif defined(macosx):
const dllPath = "libpixie.dll"
const libName = "libpixie.dylib"
else:
const dllPath = "libpixie.so"
const libName = "libpixie.so"
{.push dynlib: dllPath.}
{.push dynlib: libName.}
type PixieError = object of ValueError
const defaultMiterLimit* = 4.0
const autoLineHeight* = -1.0
type FileFormat* = enum
ffPng
ffBmp
@ -79,12 +83,6 @@ type TextCase* = enum
tcLower
tcTitle
type Rect* = object
x*: float32
y*: float32
w*: float32
h*: float32
type ColorStop* = object
color*: Color
position*: float32
@ -92,7 +90,7 @@ type ColorStop* = object
type TextMetrics* = object
width*: float32
type SeqFloat32Obj* = object
type SeqFloat32Obj = object
reference: pointer
type SeqFloat32* = ref SeqFloat32Obj
@ -102,7 +100,7 @@ proc pixie_seq_float_32_unref(x: SeqFloat32Obj) {.importc: "pixie_seq_float_32_u
proc `=destroy`(x: var SeqFloat32Obj) =
pixie_seq_float_32_unref(x)
type SeqSpanObj* = object
type SeqSpanObj = object
reference: pointer
type SeqSpan* = ref SeqSpanObj
@ -112,7 +110,7 @@ proc pixie_seq_span_unref(x: SeqSpanObj) {.importc: "pixie_seq_span_unref", cdec
proc `=destroy`(x: var SeqSpanObj) =
pixie_seq_span_unref(x)
type ImageObj* = object
type ImageObj = object
reference: pointer
type Image* = ref ImageObj
@ -122,7 +120,7 @@ proc pixie_image_unref(x: ImageObj) {.importc: "pixie_image_unref", cdecl.}
proc `=destroy`(x: var ImageObj) =
pixie_image_unref(x)
type MaskObj* = object
type MaskObj = object
reference: pointer
type Mask* = ref MaskObj
@ -132,7 +130,7 @@ proc pixie_mask_unref(x: MaskObj) {.importc: "pixie_mask_unref", cdecl.}
proc `=destroy`(x: var MaskObj) =
pixie_mask_unref(x)
type PaintObj* = object
type PaintObj = object
reference: pointer
type Paint* = ref PaintObj
@ -142,7 +140,7 @@ proc pixie_paint_unref(x: PaintObj) {.importc: "pixie_paint_unref", cdecl.}
proc `=destroy`(x: var PaintObj) =
pixie_paint_unref(x)
type PathObj* = object
type PathObj = object
reference: pointer
type Path* = ref PathObj
@ -152,7 +150,7 @@ proc pixie_path_unref(x: PathObj) {.importc: "pixie_path_unref", cdecl.}
proc `=destroy`(x: var PathObj) =
pixie_path_unref(x)
type TypefaceObj* = object
type TypefaceObj = object
reference: pointer
type Typeface* = ref TypefaceObj
@ -162,7 +160,7 @@ proc pixie_typeface_unref(x: TypefaceObj) {.importc: "pixie_typeface_unref", cde
proc `=destroy`(x: var TypefaceObj) =
pixie_typeface_unref(x)
type FontObj* = object
type FontObj = object
reference: pointer
type Font* = ref FontObj
@ -172,7 +170,7 @@ proc pixie_font_unref(x: FontObj) {.importc: "pixie_font_unref", cdecl.}
proc `=destroy`(x: var FontObj) =
pixie_font_unref(x)
type SpanObj* = object
type SpanObj = object
reference: pointer
type Span* = ref SpanObj
@ -182,7 +180,7 @@ proc pixie_span_unref(x: SpanObj) {.importc: "pixie_span_unref", cdecl.}
proc `=destroy`(x: var SpanObj) =
pixie_span_unref(x)
type ArrangementObj* = object
type ArrangementObj = object
reference: pointer
type Arrangement* = ref ArrangementObj
@ -192,7 +190,7 @@ proc pixie_arrangement_unref(x: ArrangementObj) {.importc: "pixie_arrangement_un
proc `=destroy`(x: var ArrangementObj) =
pixie_arrangement_unref(x)
type ContextObj* = object
type ContextObj = object
reference: pointer
type Context* = ref ContextObj
@ -212,6 +210,11 @@ proc pixie_take_error(): cstring {.importc: "pixie_take_error", cdecl.}
proc takeError*(): cstring {.inline.} =
result = pixie_take_error()
proc pixie_color_stop(color: Color, position: float32): ColorStop {.importc: "pixie_color_stop", cdecl.}
proc colorStop*(color: Color, position: float32): ColorStop {.inline.} =
result = pixie_color_stop(color, position)
proc pixie_seq_float_32_len(s: SeqFloat32): int {.importc: "pixie_seq_float_32_len", cdecl.}
proc len*(s: SeqFloat32): int =
@ -232,10 +235,10 @@ proc pixie_seq_float_32_set(s: SeqFloat32, i: int, v: float32) {.importc: "pixie
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 pixie_seq_float_32_delete(s: SeqFloat32, i: int) {.importc: "pixie_seq_float_32_delete", cdecl.}
proc remove*(s: SeqFloat32, i: int) =
pixie_seq_float_32_remove(s, i)
proc delete*(s: SeqFloat32, i: int) =
pixie_seq_float_32_delete(s, i)
proc pixie_seq_float_32_clear(s: SeqFloat32) {.importc: "pixie_seq_float_32_clear", cdecl.}
@ -267,10 +270,10 @@ proc pixie_seq_span_set(s: SeqSpan, i: int, v: Span) {.importc: "pixie_seq_span_
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 pixie_seq_span_delete(s: SeqSpan, i: int) {.importc: "pixie_seq_span_delete", cdecl.}
proc remove*(s: SeqSpan, i: int) =
pixie_seq_span_remove(s, i)
proc delete*(s: SeqSpan, i: int) =
pixie_seq_span_delete(s, i)
proc pixie_seq_span_clear(s: SeqSpan) {.importc: "pixie_seq_span_clear", cdecl.}
@ -284,7 +287,7 @@ proc newSeqSpan*(): SeqSpan =
proc pixie_seq_span_typeset(spans: SeqSpan, bounds: Vec2, h_align: HorizontalAlignment, v_align: VerticalAlignment, wrap: bool): Arrangement {.importc: "pixie_seq_span_typeset", cdecl.}
proc typeset*(spans: SeqSpan, bounds: Vec2, hAlign: HorizontalAlignment, vAlign: VerticalAlignment, wrap: bool): Arrangement {.inline.} =
proc typeset*(spans: SeqSpan, bounds: Vec2 = vec2(0, 0), hAlign: HorizontalAlignment = haLeft, vAlign: VerticalAlignment = vaTop, wrap: bool = true): Arrangement {.inline.} =
result = pixie_seq_span_typeset(spans, bounds, hAlign, vAlign, wrap)
proc pixie_seq_span_compute_bounds(spans: SeqSpan): Vec2 {.importc: "pixie_seq_span_compute_bounds", cdecl.}
@ -372,14 +375,14 @@ proc subImage*(image: Image, x: int, y: int, w: int, h: int): Image {.inline.} =
proc pixie_image_minify_by_2(image: Image, power: int): Image {.importc: "pixie_image_minify_by_2", cdecl.}
proc minifyBy2*(image: Image, power: int): Image {.inline.} =
proc minifyBy2*(image: Image, power: int = 1): Image {.inline.} =
result = pixie_image_minify_by_2(image, power)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_image_magnify_by_2(image: Image, power: int): Image {.importc: "pixie_image_magnify_by_2", cdecl.}
proc magnifyBy2*(image: Image, power: int): Image {.inline.} =
proc magnifyBy2*(image: Image, power: int = 1): Image {.inline.} =
result = pixie_image_magnify_by_2(image, power)
if checkError():
raise newException(PixieError, $takeError())
@ -431,14 +434,14 @@ proc superImage*(image: Image, x: int, y: int, w: int, h: int): Image {.inline.}
proc pixie_image_mask_draw(image: Image, mask: Mask, transform: Mat3, blend_mode: BlendMode) {.importc: "pixie_image_mask_draw", cdecl.}
proc draw*(image: Image, mask: Mask, transform: Mat3, blendMode: BlendMode) {.inline.} =
proc draw*(image: Image, mask: Mask, transform: Mat3 = mat3(), blendMode: BlendMode = bmMask) {.inline.} =
pixie_image_mask_draw(image, mask, transform, blendMode)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_image_image_draw(a: Image, b: Image, transform: Mat3, blend_mode: BlendMode) {.importc: "pixie_image_image_draw", cdecl.}
proc draw*(a: Image, b: Image, transform: Mat3, blendMode: BlendMode) {.inline.} =
proc draw*(a: Image, b: Image, transform: Mat3 = mat3(), blendMode: BlendMode = bmNormal) {.inline.} =
pixie_image_image_draw(a, b, transform, blendMode)
if checkError():
raise newException(PixieError, $takeError())
@ -452,42 +455,42 @@ proc fillGradient*(image: Image, paint: Paint) {.inline.} =
proc pixie_image_arrangement_fill_text(target: Image, arrangement: Arrangement, transform: Mat3) {.importc: "pixie_image_arrangement_fill_text", cdecl.}
proc fillText*(target: Image, arrangement: Arrangement, transform: Mat3) {.inline.} =
proc fillText*(target: Image, arrangement: Arrangement, transform: Mat3 = mat3()) {.inline.} =
pixie_image_arrangement_fill_text(target, arrangement, transform)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_image_font_fill_text(target: Image, font: Font, text: cstring, transform: Mat3, bounds: Vec2, h_align: HorizontalAlignment, v_align: VerticalAlignment) {.importc: "pixie_image_font_fill_text", cdecl.}
proc fillText*(target: Image, font: Font, text: string, transform: Mat3, bounds: Vec2, hAlign: HorizontalAlignment, vAlign: VerticalAlignment) {.inline.} =
proc fillText*(target: Image, font: Font, text: string, transform: Mat3 = mat3(), bounds: Vec2 = vec2(0, 0), hAlign: HorizontalAlignment = haLeft, vAlign: VerticalAlignment = vaTop) {.inline.} =
pixie_image_font_fill_text(target, font, text.cstring, transform, bounds, hAlign, vAlign)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_image_arrangement_stroke_text(target: Image, arrangement: Arrangement, transform: Mat3, stroke_width: float32, line_cap: LineCap, line_join: LineJoin, miter_limit: float32, dashes: SeqFloat32) {.importc: "pixie_image_arrangement_stroke_text", cdecl.}
proc strokeText*(target: Image, arrangement: Arrangement, transform: Mat3, strokeWidth: float32, lineCap: LineCap, lineJoin: LineJoin, miterLimit: float32, dashes: SeqFloat32) {.inline.} =
proc strokeText*(target: Image, arrangement: Arrangement, transform: Mat3 = mat3(), strokeWidth: float32 = 1.0, lineCap: LineCap = lcButt, lineJoin: LineJoin = ljMiter, miterLimit: float32 = defaultMiterLimit, dashes: SeqFloat32) {.inline.} =
pixie_image_arrangement_stroke_text(target, arrangement, transform, strokeWidth, lineCap, lineJoin, miterLimit, dashes)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_image_font_stroke_text(target: Image, font: Font, text: cstring, transform: Mat3, stroke_width: float32, bounds: Vec2, h_align: HorizontalAlignment, v_align: VerticalAlignment, line_cap: LineCap, line_join: LineJoin, miter_limit: float32, dashes: SeqFloat32) {.importc: "pixie_image_font_stroke_text", cdecl.}
proc strokeText*(target: Image, font: Font, text: string, transform: Mat3, strokeWidth: float32, bounds: Vec2, hAlign: HorizontalAlignment, vAlign: VerticalAlignment, lineCap: LineCap, lineJoin: LineJoin, miterLimit: float32, dashes: SeqFloat32) {.inline.} =
proc strokeText*(target: Image, font: Font, text: string, transform: Mat3 = mat3(), strokeWidth: float32 = 1.0, bounds: Vec2 = vec2(0, 0), hAlign: HorizontalAlignment = haLeft, vAlign: VerticalAlignment = vaTop, lineCap: LineCap = lcButt, lineJoin: LineJoin = ljMiter, miterLimit: float32 = defaultMiterLimit, dashes: SeqFloat32) {.inline.} =
pixie_image_font_stroke_text(target, font, text.cstring, transform, strokeWidth, bounds, hAlign, vAlign, lineCap, lineJoin, miterLimit, dashes)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_image_fill_path(image: Image, path: Path, paint: Paint, transform: Mat3, winding_rule: WindingRule) {.importc: "pixie_image_fill_path", cdecl.}
proc fillPath*(image: Image, path: Path, paint: Paint, transform: Mat3, windingRule: WindingRule) {.inline.} =
proc fillPath*(image: Image, path: Path, paint: Paint, transform: Mat3 = mat3(), windingRule: WindingRule = wrNonZero) {.inline.} =
pixie_image_fill_path(image, path, paint, transform, windingRule)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_image_stroke_path(image: Image, path: Path, paint: Paint, transform: Mat3, stroke_width: float32, line_cap: LineCap, line_join: LineJoin, miter_limit: float32, dashes: SeqFloat32) {.importc: "pixie_image_stroke_path", cdecl.}
proc strokePath*(image: Image, path: Path, paint: Paint, transform: Mat3, strokeWidth: float32, lineCap: LineCap, lineJoin: LineJoin, miterLimit: float32, dashes: SeqFloat32) {.inline.} =
proc strokePath*(image: Image, path: Path, paint: Paint, transform: Mat3 = mat3(), strokeWidth: float32 = 1.0, lineCap: LineCap = lcButt, lineJoin: LineJoin = ljMiter, miterLimit: float32 = defaultMiterLimit, dashes: SeqFloat32) {.inline.} =
pixie_image_stroke_path(image, path, paint, transform, strokeWidth, lineCap, lineJoin, miterLimit, dashes)
if checkError():
raise newException(PixieError, $takeError())
@ -560,7 +563,7 @@ proc fill*(mask: Mask, value: uint8) {.inline.} =
proc pixie_mask_minify_by_2(mask: Mask, power: int): Mask {.importc: "pixie_mask_minify_by_2", cdecl.}
proc minifyBy2*(mask: Mask, power: int): Mask {.inline.} =
proc minifyBy2*(mask: Mask, power: int = 1): Mask {.inline.} =
result = pixie_mask_minify_by_2(mask, power)
if checkError():
raise newException(PixieError, $takeError())
@ -596,63 +599,63 @@ proc invert*(target: Mask) {.inline.} =
proc pixie_mask_blur(mask: Mask, radius: float32, out_of_bounds: uint8) {.importc: "pixie_mask_blur", cdecl.}
proc blur*(mask: Mask, radius: float32, outOfBounds: uint8) {.inline.} =
proc blur*(mask: Mask, radius: float32, outOfBounds: uint8 = 0) {.inline.} =
pixie_mask_blur(mask, radius, outOfBounds)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_mask_mask_draw(a: Mask, b: Mask, transform: Mat3, blend_mode: BlendMode) {.importc: "pixie_mask_mask_draw", cdecl.}
proc draw*(a: Mask, b: Mask, transform: Mat3, blendMode: BlendMode) {.inline.} =
proc draw*(a: Mask, b: Mask, transform: Mat3 = mat3(), blendMode: BlendMode = bmMask) {.inline.} =
pixie_mask_mask_draw(a, b, transform, blendMode)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_mask_image_draw(mask: Mask, image: Image, transform: Mat3, blend_mode: BlendMode) {.importc: "pixie_mask_image_draw", cdecl.}
proc draw*(mask: Mask, image: Image, transform: Mat3, blendMode: BlendMode) {.inline.} =
proc draw*(mask: Mask, image: Image, transform: Mat3 = mat3(), blendMode: BlendMode = bmMask) {.inline.} =
pixie_mask_image_draw(mask, image, transform, blendMode)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_mask_arrangement_fill_text(target: Mask, arrangement: Arrangement, transform: Mat3) {.importc: "pixie_mask_arrangement_fill_text", cdecl.}
proc fillText*(target: Mask, arrangement: Arrangement, transform: Mat3) {.inline.} =
proc fillText*(target: Mask, arrangement: Arrangement, transform: Mat3 = mat3()) {.inline.} =
pixie_mask_arrangement_fill_text(target, arrangement, transform)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_mask_font_fill_text(target: Mask, font: Font, text: cstring, transform: Mat3, bounds: Vec2, h_align: HorizontalAlignment, v_align: VerticalAlignment) {.importc: "pixie_mask_font_fill_text", cdecl.}
proc fillText*(target: Mask, font: Font, text: string, transform: Mat3, bounds: Vec2, hAlign: HorizontalAlignment, vAlign: VerticalAlignment) {.inline.} =
proc fillText*(target: Mask, font: Font, text: string, transform: Mat3 = mat3(), bounds: Vec2 = vec2(0, 0), hAlign: HorizontalAlignment = haLeft, vAlign: VerticalAlignment = vaTop) {.inline.} =
pixie_mask_font_fill_text(target, font, text.cstring, transform, bounds, hAlign, vAlign)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_mask_arrangement_stroke_text(target: Mask, arrangement: Arrangement, transform: Mat3, stroke_width: float32, line_cap: LineCap, line_join: LineJoin, miter_limit: float32, dashes: SeqFloat32) {.importc: "pixie_mask_arrangement_stroke_text", cdecl.}
proc strokeText*(target: Mask, arrangement: Arrangement, transform: Mat3, strokeWidth: float32, lineCap: LineCap, lineJoin: LineJoin, miterLimit: float32, dashes: SeqFloat32) {.inline.} =
proc strokeText*(target: Mask, arrangement: Arrangement, transform: Mat3 = mat3(), strokeWidth: float32 = 1.0, lineCap: LineCap = lcButt, lineJoin: LineJoin = ljMiter, miterLimit: float32 = defaultMiterLimit, dashes: SeqFloat32) {.inline.} =
pixie_mask_arrangement_stroke_text(target, arrangement, transform, strokeWidth, lineCap, lineJoin, miterLimit, dashes)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_mask_font_stroke_text(target: Mask, font: Font, text: cstring, transform: Mat3, stroke_width: float32, bounds: Vec2, h_align: HorizontalAlignment, v_align: VerticalAlignment, line_cap: LineCap, line_join: LineJoin, miter_limit: float32, dashes: SeqFloat32) {.importc: "pixie_mask_font_stroke_text", cdecl.}
proc strokeText*(target: Mask, font: Font, text: string, transform: Mat3, strokeWidth: float32, bounds: Vec2, hAlign: HorizontalAlignment, vAlign: VerticalAlignment, lineCap: LineCap, lineJoin: LineJoin, miterLimit: float32, dashes: SeqFloat32) {.inline.} =
proc strokeText*(target: Mask, font: Font, text: string, transform: Mat3 = mat3(), strokeWidth: float32 = 1.0, bounds: Vec2 = vec2(0, 0), hAlign: HorizontalAlignment = haLeft, vAlign: VerticalAlignment = vaTop, lineCap: LineCap = lcButt, lineJoin: LineJoin = ljMiter, miterLimit: float32 = defaultMiterLimit, dashes: SeqFloat32) {.inline.} =
pixie_mask_font_stroke_text(target, font, text.cstring, transform, strokeWidth, bounds, hAlign, vAlign, lineCap, lineJoin, miterLimit, dashes)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_mask_fill_path(mask: Mask, path: Path, transform: Mat3, winding_rule: WindingRule, blend_mode: BlendMode) {.importc: "pixie_mask_fill_path", cdecl.}
proc fillPath*(mask: Mask, path: Path, transform: Mat3, windingRule: WindingRule, blendMode: BlendMode) {.inline.} =
proc fillPath*(mask: Mask, path: Path, transform: Mat3 = mat3(), windingRule: WindingRule = wrNonZero, blendMode: BlendMode = bmNormal) {.inline.} =
pixie_mask_fill_path(mask, path, transform, windingRule, blendMode)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_mask_stroke_path(mask: Mask, path: Path, transform: Mat3, stroke_width: float32, line_cap: LineCap, line_join: LineJoin, miter_limit: float32, dashes: SeqFloat32, blend_mode: BlendMode) {.importc: "pixie_mask_stroke_path", cdecl.}
proc strokePath*(mask: Mask, path: Path, transform: Mat3, strokeWidth: float32, lineCap: LineCap, lineJoin: LineJoin, miterLimit: float32, dashes: SeqFloat32, blendMode: BlendMode) {.inline.} =
proc strokePath*(mask: Mask, path: Path, transform: Mat3 = mat3(), strokeWidth: float32 = 1.0, lineCap: LineCap = lcButt, lineJoin: LineJoin = ljMiter, miterLimit: float32 = defaultMiterLimit, dashes: SeqFloat32, blendMode: BlendMode = bmNormal) {.inline.} =
pixie_mask_stroke_path(mask, path, transform, strokeWidth, lineCap, lineJoin, miterLimit, dashes, blendMode)
if checkError():
raise newException(PixieError, $takeError())
@ -748,10 +751,10 @@ proc pixie_paint_gradient_handle_positions_set(s: Paint, i: int, v: Vec2) {.impo
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 pixie_paint_gradient_handle_positions_delete(s: Paint, i: int) {.importc: "pixie_paint_gradient_handle_positions_delete", cdecl.}
proc remove*(s: PaintGradientHandlePositions, i: int) =
pixie_paint_gradient_handle_positions_remove(s.paint, i)
proc delete*(s: PaintGradientHandlePositions, i: int) =
pixie_paint_gradient_handle_positions_delete(s.paint, i)
proc pixie_paint_gradient_handle_positions_clear(s: Paint) {.importc: "pixie_paint_gradient_handle_positions_clear", cdecl.}
@ -784,10 +787,10 @@ proc pixie_paint_gradient_stops_set(s: Paint, i: int, v: ColorStop) {.importc: "
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 pixie_paint_gradient_stops_delete(s: Paint, i: int) {.importc: "pixie_paint_gradient_stops_delete", cdecl.}
proc remove*(s: PaintGradientStops, i: int) =
pixie_paint_gradient_stops_remove(s.paint, i)
proc delete*(s: PaintGradientStops, i: int) =
pixie_paint_gradient_stops_delete(s.paint, i)
proc pixie_paint_gradient_stops_clear(s: Paint) {.importc: "pixie_paint_gradient_stops_clear", cdecl.}
@ -821,21 +824,21 @@ proc closePath*(path: Path) {.inline.} =
proc pixie_path_compute_bounds(path: Path, transform: Mat3): Rect {.importc: "pixie_path_compute_bounds", cdecl.}
proc computeBounds*(path: Path, transform: Mat3): Rect {.inline.} =
proc computeBounds*(path: Path, transform: Mat3 = mat3()): Rect {.inline.} =
result = pixie_path_compute_bounds(path, transform)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_path_fill_overlaps(path: Path, test: Vec2, transform: Mat3, winding_rule: WindingRule): bool {.importc: "pixie_path_fill_overlaps", cdecl.}
proc fillOverlaps*(path: Path, test: Vec2, transform: Mat3, windingRule: WindingRule): bool {.inline.} =
proc fillOverlaps*(path: Path, test: Vec2, transform: Mat3 = mat3(), windingRule: WindingRule = wrNonZero): bool {.inline.} =
result = pixie_path_fill_overlaps(path, test, transform, windingRule)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_path_stroke_overlaps(path: Path, test: Vec2, transform: Mat3, stroke_width: float32, line_cap: LineCap, line_join: LineJoin, miter_limit: float32, dashes: SeqFloat32): bool {.importc: "pixie_path_stroke_overlaps", cdecl.}
proc strokeOverlaps*(path: Path, test: Vec2, transform: Mat3, strokeWidth: float32, lineCap: LineCap, lineJoin: LineJoin, miterLimit: float32, dashes: SeqFloat32): bool {.inline.} =
proc strokeOverlaps*(path: Path, test: Vec2, transform: Mat3 = mat3(), strokeWidth: float32 = 1.0, lineCap: LineCap = lcButt, lineJoin: LineJoin = ljMiter, miterLimit: float32 = defaultMiterLimit, dashes: SeqFloat32): bool {.inline.} =
result = pixie_path_stroke_overlaps(path, test, transform, strokeWidth, lineCap, lineJoin, miterLimit, dashes)
if checkError():
raise newException(PixieError, $takeError())
@ -881,12 +884,12 @@ proc arcTo*(path: Path, x1: float32, y1: float32, x2: float32, y2: float32, r: f
proc pixie_path_rect(path: Path, x: float32, y: float32, w: float32, h: float32, clockwise: bool) {.importc: "pixie_path_rect", cdecl.}
proc rect*(path: Path, x: float32, y: float32, w: float32, h: float32, clockwise: bool) {.inline.} =
proc rect*(path: Path, x: float32, y: float32, w: float32, h: float32, clockwise: bool = true) {.inline.} =
pixie_path_rect(path, x, y, w, h, clockwise)
proc pixie_path_rounded_rect(path: Path, x: float32, y: float32, w: float32, h: float32, nw: float32, ne: float32, se: float32, sw: float32, clockwise: bool) {.importc: "pixie_path_rounded_rect", cdecl.}
proc roundedRect*(path: Path, x: float32, y: float32, w: float32, h: float32, nw: float32, ne: float32, se: float32, sw: float32, clockwise: bool) {.inline.} =
proc roundedRect*(path: Path, x: float32, y: float32, w: float32, h: float32, nw: float32, ne: float32, se: float32, sw: float32, clockwise: bool = true) {.inline.} =
pixie_path_rounded_rect(path, x, y, w, h, nw, ne, se, sw, clockwise)
proc pixie_path_ellipse(path: Path, cx: float32, cy: float32, rx: float32, ry: float32) {.importc: "pixie_path_ellipse", cdecl.}
@ -1012,10 +1015,10 @@ proc pixie_font_paints_set(s: Font, i: int, v: Paint) {.importc: "pixie_font_pai
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 pixie_font_paints_delete(s: Font, i: int) {.importc: "pixie_font_paints_delete", cdecl.}
proc remove*(s: FontPaints, i: int) =
pixie_font_paints_remove(s.font, i)
proc delete*(s: FontPaints, i: int) =
pixie_font_paints_delete(s.font, i)
proc pixie_font_paints_clear(s: Font) {.importc: "pixie_font_paints_clear", cdecl.}
@ -1074,7 +1077,7 @@ proc defaultLineHeight*(font: Font): float32 {.inline.} =
proc pixie_font_typeset(font: Font, text: cstring, bounds: Vec2, h_align: HorizontalAlignment, v_align: VerticalAlignment, wrap: bool): Arrangement {.importc: "pixie_font_typeset", cdecl.}
proc typeset*(font: Font, text: string, bounds: Vec2, hAlign: HorizontalAlignment, vAlign: VerticalAlignment, wrap: bool): Arrangement {.inline.} =
proc typeset*(font: Font, text: string, bounds: Vec2 = vec2(0, 0), hAlign: HorizontalAlignment = haLeft, vAlign: VerticalAlignment = vaTop, wrap: bool = true): Arrangement {.inline.} =
result = pixie_font_typeset(font, text.cstring, bounds, hAlign, vAlign, wrap)
proc pixie_font_compute_bounds(font: Font, text: cstring): Vec2 {.importc: "pixie_font_compute_bounds", cdecl.}
@ -1262,28 +1265,28 @@ proc closePath*(ctx: Context) {.inline.} =
proc pixie_context_path_fill(ctx: Context, path: Path, winding_rule: WindingRule) {.importc: "pixie_context_path_fill", cdecl.}
proc fill*(ctx: Context, path: Path, windingRule: WindingRule) {.inline.} =
proc fill*(ctx: Context, path: Path, windingRule: WindingRule = wrNonZero) {.inline.} =
pixie_context_path_fill(ctx, path, windingRule)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_context_winding_rule_fill(ctx: Context, winding_rule: WindingRule) {.importc: "pixie_context_winding_rule_fill", cdecl.}
proc fill*(ctx: Context, windingRule: WindingRule) {.inline.} =
proc fill*(ctx: Context, windingRule: WindingRule = wrNonZero) {.inline.} =
pixie_context_winding_rule_fill(ctx, windingRule)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_context_path_clip(ctx: Context, path: Path, winding_rule: WindingRule) {.importc: "pixie_context_path_clip", cdecl.}
proc clip*(ctx: Context, path: Path, windingRule: WindingRule) {.inline.} =
proc clip*(ctx: Context, path: Path, windingRule: WindingRule = wrNonZero) {.inline.} =
pixie_context_path_clip(ctx, path, windingRule)
if checkError():
raise newException(PixieError, $takeError())
proc pixie_context_winding_rule_clip(ctx: Context, winding_rule: WindingRule) {.importc: "pixie_context_winding_rule_clip", cdecl.}
proc clip*(ctx: Context, windingRule: WindingRule) {.inline.} =
proc clip*(ctx: Context, windingRule: WindingRule = wrNonZero) {.inline.} =
pixie_context_winding_rule_clip(ctx, windingRule)
if checkError():
raise newException(PixieError, $takeError())
@ -1372,7 +1375,7 @@ proc quadraticCurveTo*(ctx: Context, cpx: float32, cpy: float32, x: float32, y:
proc pixie_context_arc(ctx: Context, x: float32, y: float32, r: float32, a_0: float32, a_1: float32, ccw: bool) {.importc: "pixie_context_arc", cdecl.}
proc arc*(ctx: Context, x: float32, y: float32, r: float32, a0: float32, a1: float32, ccw: bool) {.inline.} =
proc arc*(ctx: Context, x: float32, y: float32, r: float32, a0: float32, a1: float32, ccw: bool = false) {.inline.} =
pixie_context_arc(ctx, x, y, r, a0, a1, ccw)
if checkError():
raise newException(PixieError, $takeError())
@ -1461,7 +1464,7 @@ proc rotate*(ctx: Context, angle: float32) {.inline.} =
proc pixie_context_is_point_in_path(ctx: Context, x: float32, y: float32, winding_rule: WindingRule): bool {.importc: "pixie_context_is_point_in_path", cdecl.}
proc isPointInPath*(ctx: Context, x: float32, y: float32, windingRule: WindingRule): bool {.inline.} =
proc isPointInPath*(ctx: Context, x: float32, y: float32, windingRule: WindingRule = wrNonZero): bool {.inline.} =
result = pixie_context_is_point_in_path(ctx, x, y, windingRule)
if checkError():
raise newException(PixieError, $takeError())

View file

@ -6,16 +6,20 @@ src_path = Path(__file__).resolve()
src_dir = str(src_path.parent)
if sys.platform == "win32":
dllPath = "pixie.dll"
libName = "pixie.dll"
elif sys.platform == "darwin":
dllPath = "libpixie.dylib"
libName = "libpixie.dylib"
else:
dllPath = "libpixie.so"
dll = cdll.LoadLibrary(src_dir + "/" + dllPath)
libName = "libpixie.so"
dll = cdll.LoadLibrary(src_dir + "/" + libName)
class PixieError(Exception):
pass
DEFAULT_MITER_LIMIT = 4.0
AUTO_LINE_HEIGHT = -1.0
FileFormat = c_byte
FF_PNG = 0
FF_BMP = 1
@ -82,6 +86,14 @@ TC_UPPER = 1
TC_LOWER = 2
TC_TITLE = 3
def check_error():
result = dll.pixie_check_error()
return result
def take_error():
result = dll.pixie_take_error().decode("utf8")
return result
class Vector2(Structure):
_fields_ = [
("x", c_float),
@ -89,8 +101,9 @@ class Vector2(Structure):
]
def __init__(self, x, y):
self.x = x
self.y = y
tmp = dll.pixie_vector_2(x, y)
self.x = tmp.x
self.y = tmp.y
def __eq__(self, obj):
self.x == obj.x and self.y == obj.y
@ -108,16 +121,17 @@ class Matrix3(Structure):
("i", c_float)
]
def __init__(self, a, b, c, d, e, f, g, h, i):
self.a = a
self.b = b
self.c = c
self.d = d
self.e = e
self.f = f
self.g = g
self.h = h
self.i = i
def __init__(self):
tmp = dll.pixie_matrix_3()
self.a = tmp.a
self.b = tmp.b
self.c = tmp.c
self.d = tmp.d
self.e = tmp.e
self.f = tmp.f
self.g = tmp.g
self.h = tmp.h
self.i = tmp.i
def __eq__(self, obj):
self.a == obj.a and self.b == obj.b and self.c == obj.c and self.d == obj.d and self.e == obj.e and self.f == obj.f and self.g == obj.g and self.h == obj.h and self.i == obj.i
@ -130,12 +144,6 @@ class Rect(Structure):
("h", c_float)
]
def __init__(self, x, y, w, h):
self.x = x
self.y = y
self.w = w
self.h = h
def __eq__(self, obj):
self.x == obj.x and self.y == obj.y and self.w == obj.w and self.h == obj.h
@ -147,12 +155,6 @@ class Color(Structure):
("a", c_float)
]
def __init__(self, r, g, b, a):
self.r = r
self.g = g
self.b = b
self.a = a
def __eq__(self, obj):
self.r == obj.r and self.g == obj.g and self.b == obj.b and self.a == obj.a
@ -163,8 +165,9 @@ class ColorStop(Structure):
]
def __init__(self, color, position):
self.color = color
self.position = position
tmp = dll.pixie_color_stop(color, position)
self.color = tmp.color
self.position = tmp.position
def __eq__(self, obj):
self.color == obj.color and self.position == obj.position
@ -174,20 +177,9 @@ class TextMetrics(Structure):
("width", c_float)
]
def __init__(self, width):
self.width = width
def __eq__(self, obj):
self.width == obj.width
def check_error():
result = dll.pixie_check_error()
return result
def take_error():
result = dll.pixie_take_error().decode("utf8")
return result
class SeqFloat32(Structure):
_fields_ = [("ref", c_ulonglong)]
@ -213,7 +205,7 @@ class SeqFloat32(Structure):
dll.pixie_seq_float_32_set(self, index, value)
def __delitem__(self, index):
dll.pixie_seq_float_32_remove(self, index)
dll.pixie_seq_float_32_delete(self, index)
def append(self, value):
dll.pixie_seq_float_32_add(self, value)
@ -246,7 +238,7 @@ class SeqSpan(Structure):
dll.pixie_seq_span_set(self, index, value)
def __delitem__(self, index):
dll.pixie_seq_span_remove(self, index)
dll.pixie_seq_span_delete(self, index)
def append(self, value):
dll.pixie_seq_span_add(self, value)
@ -254,7 +246,15 @@ class SeqSpan(Structure):
def clear(self):
dll.pixie_seq_span_clear(self)
def typeset(self, bounds, h_align, v_align, wrap):
def typeset(self, bounds = None, h_align = None, v_align = None, wrap = None):
if bounds is None:
bounds = Vector2(0, 0)
if h_align is None:
h_align = HA_LEFT
if v_align is None:
v_align = VA_TOP
if wrap is None:
wrap = True
result = dll.pixie_seq_span_typeset(self, bounds, h_align, v_align, wrap)
return result
@ -333,13 +333,17 @@ class Image(Structure):
raise PixieError(take_error())
return result
def minify_by_2(self, power):
def minify_by_2(self, power = None):
if power is None:
power = 1
result = dll.pixie_image_minify_by_2(self, power)
if check_error():
raise PixieError(take_error())
return result
def magnify_by_2(self, power):
def magnify_by_2(self, power = None):
if power is None:
power = 1
result = dll.pixie_image_magnify_by_2(self, power)
if check_error():
raise PixieError(take_error())
@ -351,7 +355,9 @@ class Image(Structure):
def invert(self):
dll.pixie_image_invert(self)
def blur(self, radius, out_of_bounds):
def blur(self, radius, out_of_bounds = None):
if out_of_bounds is None:
out_of_bounds = Color()
dll.pixie_image_blur(self, radius, out_of_bounds)
if check_error():
raise PixieError(take_error())
@ -380,12 +386,20 @@ class Image(Structure):
raise PixieError(take_error())
return result
def mask_draw(self, mask, transform, blend_mode):
def mask_draw(self, mask, transform = None, blend_mode = None):
if transform is None:
transform = Matrix3()
if blend_mode is None:
blend_mode = BM_MASK
dll.pixie_image_mask_draw(self, mask, transform, blend_mode)
if check_error():
raise PixieError(take_error())
def image_draw(self, b, transform, blend_mode):
def image_draw(self, b, transform = None, blend_mode = None):
if transform is None:
transform = Matrix3()
if blend_mode is None:
blend_mode = BM_NORMAL
dll.pixie_image_image_draw(self, b, transform, blend_mode)
if check_error():
raise PixieError(take_error())
@ -395,32 +409,88 @@ class Image(Structure):
if check_error():
raise PixieError(take_error())
def arrangement_fill_text(self, arrangement, transform):
def arrangement_fill_text(self, arrangement, transform = None):
if transform is None:
transform = Matrix3()
dll.pixie_image_arrangement_fill_text(self, arrangement, transform)
if check_error():
raise PixieError(take_error())
def font_fill_text(self, font, text, transform, bounds, h_align, v_align):
def font_fill_text(self, font, text, transform = None, bounds = None, h_align = None, v_align = None):
if transform is None:
transform = Matrix3()
if bounds is None:
bounds = Vector2(0, 0)
if h_align is None:
h_align = HA_LEFT
if v_align is None:
v_align = VA_TOP
dll.pixie_image_font_fill_text(self, font, text.encode("utf8"), transform, bounds, h_align, v_align)
if check_error():
raise PixieError(take_error())
def arrangement_stroke_text(self, arrangement, transform, stroke_width, line_cap, line_join, miter_limit, dashes):
def arrangement_stroke_text(self, arrangement, transform = None, stroke_width = None, line_cap = None, line_join = None, miter_limit = None, dashes = None):
if transform is None:
transform = Matrix3()
if stroke_width is None:
stroke_width = 1.0
if line_cap is None:
line_cap = LC_BUTT
if line_join is None:
line_join = LJ_MITER
if miter_limit is None:
miter_limit = DEFAULT_MITER_LIMIT
if dashes is None:
dashes = SeqFloat32()
dll.pixie_image_arrangement_stroke_text(self, arrangement, transform, stroke_width, line_cap, line_join, miter_limit, dashes)
if check_error():
raise PixieError(take_error())
def font_stroke_text(self, font, text, transform, stroke_width, bounds, h_align, v_align, line_cap, line_join, miter_limit, dashes):
def font_stroke_text(self, font, text, transform = None, stroke_width = None, bounds = None, h_align = None, v_align = None, line_cap = None, line_join = None, miter_limit = None, dashes = None):
if transform is None:
transform = Matrix3()
if stroke_width is None:
stroke_width = 1.0
if bounds is None:
bounds = Vector2(0, 0)
if h_align is None:
h_align = HA_LEFT
if v_align is None:
v_align = VA_TOP
if line_cap is None:
line_cap = LC_BUTT
if line_join is None:
line_join = LJ_MITER
if miter_limit is None:
miter_limit = DEFAULT_MITER_LIMIT
if dashes is None:
dashes = SeqFloat32()
dll.pixie_image_font_stroke_text(self, font, text.encode("utf8"), transform, stroke_width, bounds, h_align, v_align, line_cap, line_join, miter_limit, dashes)
if check_error():
raise PixieError(take_error())
def fill_path(self, path, paint, transform, winding_rule):
def fill_path(self, path, paint, transform = None, winding_rule = None):
if transform is None:
transform = Matrix3()
if winding_rule is None:
winding_rule = WR_NON_ZERO
dll.pixie_image_fill_path(self, path, paint, transform, winding_rule)
if check_error():
raise PixieError(take_error())
def stroke_path(self, path, paint, transform, stroke_width, line_cap, line_join, miter_limit, dashes):
def stroke_path(self, path, paint, transform = None, stroke_width = None, line_cap = None, line_join = None, miter_limit = None, dashes = None):
if transform is None:
transform = Matrix3()
if stroke_width is None:
stroke_width = 1.0
if line_cap is None:
line_cap = LC_BUTT
if line_join is None:
line_join = LJ_MITER
if miter_limit is None:
miter_limit = DEFAULT_MITER_LIMIT
if dashes is None:
dashes = SeqFloat32()
dll.pixie_image_stroke_path(self, path, paint, transform, stroke_width, line_cap, line_join, miter_limit, dashes)
if check_error():
raise PixieError(take_error())
@ -488,7 +558,9 @@ class Mask(Structure):
def fill(self, value):
dll.pixie_mask_fill(self, value)
def minify_by_2(self, power):
def minify_by_2(self, power = None):
if power is None:
power = 1
result = dll.pixie_mask_minify_by_2(self, power)
if check_error():
raise PixieError(take_error())
@ -514,47 +586,117 @@ class Mask(Structure):
def invert(self):
dll.pixie_mask_invert(self)
def blur(self, radius, out_of_bounds):
def blur(self, radius, out_of_bounds = None):
if out_of_bounds is None:
out_of_bounds = 0
dll.pixie_mask_blur(self, radius, out_of_bounds)
if check_error():
raise PixieError(take_error())
def mask_draw(self, b, transform, blend_mode):
def mask_draw(self, b, transform = None, blend_mode = None):
if transform is None:
transform = Matrix3()
if blend_mode is None:
blend_mode = BM_MASK
dll.pixie_mask_mask_draw(self, b, transform, blend_mode)
if check_error():
raise PixieError(take_error())
def image_draw(self, image, transform, blend_mode):
def image_draw(self, image, transform = None, blend_mode = None):
if transform is None:
transform = Matrix3()
if blend_mode is None:
blend_mode = BM_MASK
dll.pixie_mask_image_draw(self, image, transform, blend_mode)
if check_error():
raise PixieError(take_error())
def arrangement_fill_text(self, arrangement, transform):
def arrangement_fill_text(self, arrangement, transform = None):
if transform is None:
transform = Matrix3()
dll.pixie_mask_arrangement_fill_text(self, arrangement, transform)
if check_error():
raise PixieError(take_error())
def font_fill_text(self, font, text, transform, bounds, h_align, v_align):
def font_fill_text(self, font, text, transform = None, bounds = None, h_align = None, v_align = None):
if transform is None:
transform = Matrix3()
if bounds is None:
bounds = Vector2(0, 0)
if h_align is None:
h_align = HA_LEFT
if v_align is None:
v_align = VA_TOP
dll.pixie_mask_font_fill_text(self, font, text.encode("utf8"), transform, bounds, h_align, v_align)
if check_error():
raise PixieError(take_error())
def arrangement_stroke_text(self, arrangement, transform, stroke_width, line_cap, line_join, miter_limit, dashes):
def arrangement_stroke_text(self, arrangement, transform = None, stroke_width = None, line_cap = None, line_join = None, miter_limit = None, dashes = None):
if transform is None:
transform = Matrix3()
if stroke_width is None:
stroke_width = 1.0
if line_cap is None:
line_cap = LC_BUTT
if line_join is None:
line_join = LJ_MITER
if miter_limit is None:
miter_limit = DEFAULT_MITER_LIMIT
if dashes is None:
dashes = SeqFloat32()
dll.pixie_mask_arrangement_stroke_text(self, arrangement, transform, stroke_width, line_cap, line_join, miter_limit, dashes)
if check_error():
raise PixieError(take_error())
def font_stroke_text(self, font, text, transform, stroke_width, bounds, h_align, v_align, line_cap, line_join, miter_limit, dashes):
def font_stroke_text(self, font, text, transform = None, stroke_width = None, bounds = None, h_align = None, v_align = None, line_cap = None, line_join = None, miter_limit = None, dashes = None):
if transform is None:
transform = Matrix3()
if stroke_width is None:
stroke_width = 1.0
if bounds is None:
bounds = Vector2(0, 0)
if h_align is None:
h_align = HA_LEFT
if v_align is None:
v_align = VA_TOP
if line_cap is None:
line_cap = LC_BUTT
if line_join is None:
line_join = LJ_MITER
if miter_limit is None:
miter_limit = DEFAULT_MITER_LIMIT
if dashes is None:
dashes = SeqFloat32()
dll.pixie_mask_font_stroke_text(self, font, text.encode("utf8"), transform, stroke_width, bounds, h_align, v_align, line_cap, line_join, miter_limit, dashes)
if check_error():
raise PixieError(take_error())
def fill_path(self, path, transform, winding_rule, blend_mode):
def fill_path(self, path, transform = None, winding_rule = None, blend_mode = None):
if transform is None:
transform = Matrix3()
if winding_rule is None:
winding_rule = WR_NON_ZERO
if blend_mode is None:
blend_mode = BM_NORMAL
dll.pixie_mask_fill_path(self, path, transform, winding_rule, blend_mode)
if check_error():
raise PixieError(take_error())
def stroke_path(self, path, transform, stroke_width, line_cap, line_join, miter_limit, dashes, blend_mode):
def stroke_path(self, path, transform = None, stroke_width = None, line_cap = None, line_join = None, miter_limit = None, dashes = None, blend_mode = None):
if transform is None:
transform = Matrix3()
if stroke_width is None:
stroke_width = 1.0
if line_cap is None:
line_cap = LC_BUTT
if line_join is None:
line_join = LJ_MITER
if miter_limit is None:
miter_limit = DEFAULT_MITER_LIMIT
if dashes is None:
dashes = SeqFloat32()
if blend_mode is None:
blend_mode = BM_NORMAL
dll.pixie_mask_stroke_path(self, path, transform, stroke_width, line_cap, line_join, miter_limit, dashes, blend_mode)
if check_error():
raise PixieError(take_error())
@ -638,7 +780,7 @@ class Paint(Structure):
dll.pixie_paint_gradient_handle_positions_set(self.paint, index, value)
def __delitem__(self, index):
dll.pixie_paint_gradient_handle_positions_remove(self.paint, index)
dll.pixie_paint_gradient_handle_positions_delete(self.paint, index)
def append(self, value):
dll.pixie_paint_gradient_handle_positions_add(self.paint, value)
@ -665,7 +807,7 @@ class Paint(Structure):
dll.pixie_paint_gradient_stops_set(self.paint, index, value)
def __delitem__(self, index):
dll.pixie_paint_gradient_stops_remove(self.paint, index)
dll.pixie_paint_gradient_stops_delete(self.paint, index)
def append(self, value):
dll.pixie_paint_gradient_stops_add(self.paint, value)
@ -706,19 +848,37 @@ class Path(Structure):
def close_path(self):
dll.pixie_path_close_path(self)
def compute_bounds(self, transform):
def compute_bounds(self, transform = None):
if transform is None:
transform = Matrix3()
result = dll.pixie_path_compute_bounds(self, transform)
if check_error():
raise PixieError(take_error())
return result
def fill_overlaps(self, test, transform, winding_rule):
def fill_overlaps(self, test, transform = None, winding_rule = None):
if transform is None:
transform = Matrix3()
if winding_rule is None:
winding_rule = WR_NON_ZERO
result = dll.pixie_path_fill_overlaps(self, test, transform, winding_rule)
if check_error():
raise PixieError(take_error())
return result
def stroke_overlaps(self, test, transform, stroke_width, line_cap, line_join, miter_limit, dashes):
def stroke_overlaps(self, test, transform = None, stroke_width = None, line_cap = None, line_join = None, miter_limit = None, dashes = None):
if transform is None:
transform = Matrix3()
if stroke_width is None:
stroke_width = 1.0
if line_cap is None:
line_cap = LC_BUTT
if line_join is None:
line_join = LJ_MITER
if miter_limit is None:
miter_limit = DEFAULT_MITER_LIMIT
if dashes is None:
dashes = SeqFloat32()
result = dll.pixie_path_stroke_overlaps(self, test, transform, stroke_width, line_cap, line_join, miter_limit, dashes)
if check_error():
raise PixieError(take_error())
@ -749,10 +909,14 @@ class Path(Structure):
if check_error():
raise PixieError(take_error())
def rect(self, x, y, w, h, clockwise):
def rect(self, x, y, w, h, clockwise = None):
if clockwise is None:
clockwise = True
dll.pixie_path_rect(self, x, y, w, h, clockwise)
def rounded_rect(self, x, y, w, h, nw, ne, se, sw, clockwise):
def rounded_rect(self, x, y, w, h, nw, ne, se, sw, clockwise = None):
if clockwise is None:
clockwise = True
dll.pixie_path_rounded_rect(self, x, y, w, h, nw, ne, se, sw, clockwise)
def ellipse(self, cx, cy, rx, ry):
@ -869,7 +1033,7 @@ class Font(Structure):
dll.pixie_font_paints_set(self.font, index, value)
def __delitem__(self, index):
dll.pixie_font_paints_remove(self.font, index)
dll.pixie_font_paints_delete(self.font, index)
def append(self, value):
dll.pixie_font_paints_add(self.font, value)
@ -921,7 +1085,15 @@ class Font(Structure):
result = dll.pixie_font_default_line_height(self)
return result
def typeset(self, text, bounds, h_align, v_align, wrap):
def typeset(self, text, bounds = None, h_align = None, v_align = None, wrap = None):
if bounds is None:
bounds = Vector2(0, 0)
if h_align is None:
h_align = HA_LEFT
if v_align is None:
v_align = VA_TOP
if wrap is None:
wrap = True
result = dll.pixie_font_typeset(self, text.encode("utf8"), bounds, h_align, v_align, wrap)
return result
@ -1104,22 +1276,30 @@ class Context(Structure):
def close_path(self):
dll.pixie_context_close_path(self)
def path_fill(self, path, winding_rule):
def path_fill(self, path, winding_rule = None):
if winding_rule is None:
winding_rule = WR_NON_ZERO
dll.pixie_context_path_fill(self, path, winding_rule)
if check_error():
raise PixieError(take_error())
def fill(self, winding_rule):
def fill(self, winding_rule = None):
if winding_rule is None:
winding_rule = WR_NON_ZERO
dll.pixie_context_winding_rule_fill(self, winding_rule)
if check_error():
raise PixieError(take_error())
def path_clip(self, path, winding_rule):
def path_clip(self, path, winding_rule = None):
if winding_rule is None:
winding_rule = WR_NON_ZERO
dll.pixie_context_path_clip(self, path, winding_rule)
if check_error():
raise PixieError(take_error())
def clip(self, winding_rule):
def clip(self, winding_rule = None):
if winding_rule is None:
winding_rule = WR_NON_ZERO
dll.pixie_context_winding_rule_clip(self, winding_rule)
if check_error():
raise PixieError(take_error())
@ -1180,7 +1360,9 @@ class Context(Structure):
def quadratic_curve_to(self, cpx, cpy, x, y):
dll.pixie_context_quadratic_curve_to(self, cpx, cpy, x, y)
def arc(self, x, y, r, a_0, a_1, ccw):
def arc(self, x, y, r, a_0, a_1, ccw = None):
if ccw is None:
ccw = False
dll.pixie_context_arc(self, x, y, r, a_0, a_1, ccw)
if check_error():
raise PixieError(take_error())
@ -1239,7 +1421,9 @@ class Context(Structure):
def rotate(self, angle):
dll.pixie_context_rotate(self, angle)
def is_point_in_path(self, x, y, winding_rule):
def is_point_in_path(self, x, y, winding_rule = None):
if winding_rule is None:
winding_rule = WR_NON_ZERO
result = dll.pixie_context_is_point_in_path(self, x, y, winding_rule)
if check_error():
raise PixieError(take_error())
@ -1295,6 +1479,15 @@ dll.pixie_check_error.restype = c_bool
dll.pixie_take_error.argtypes = []
dll.pixie_take_error.restype = c_char_p
dll.pixie_vector_2.argtypes = [c_float, c_float]
dll.pixie_vector_2.restype = Vector2
dll.pixie_matrix_3.argtypes = []
dll.pixie_matrix_3.restype = Matrix3
dll.pixie_color_stop.argtypes = [Color, c_float]
dll.pixie_color_stop.restype = ColorStop
dll.pixie_seq_float_32_unref.argtypes = [SeqFloat32]
dll.pixie_seq_float_32_unref.restype = None
@ -1310,8 +1503,8 @@ dll.pixie_seq_float_32_get.restype = c_float
dll.pixie_seq_float_32_set.argtypes = [SeqFloat32, c_longlong, c_float]
dll.pixie_seq_float_32_set.restype = None
dll.pixie_seq_float_32_remove.argtypes = [SeqFloat32, c_longlong]
dll.pixie_seq_float_32_remove.restype = None
dll.pixie_seq_float_32_delete.argtypes = [SeqFloat32, c_longlong]
dll.pixie_seq_float_32_delete.restype = None
dll.pixie_seq_float_32_add.argtypes = [SeqFloat32, c_float]
dll.pixie_seq_float_32_add.restype = None
@ -1334,8 +1527,8 @@ dll.pixie_seq_span_get.restype = Span
dll.pixie_seq_span_set.argtypes = [SeqSpan, c_longlong, Span]
dll.pixie_seq_span_set.restype = None
dll.pixie_seq_span_remove.argtypes = [SeqSpan, c_longlong]
dll.pixie_seq_span_remove.restype = None
dll.pixie_seq_span_delete.argtypes = [SeqSpan, c_longlong]
dll.pixie_seq_span_delete.restype = None
dll.pixie_seq_span_add.argtypes = [SeqSpan, Span]
dll.pixie_seq_span_add.restype = None
@ -1583,8 +1776,8 @@ dll.pixie_paint_gradient_handle_positions_get.restype = Vector2
dll.pixie_paint_gradient_handle_positions_set.argtypes = [Paint, c_longlong, Vector2]
dll.pixie_paint_gradient_handle_positions_set.restype = None
dll.pixie_paint_gradient_handle_positions_remove.argtypes = [Paint, c_longlong]
dll.pixie_paint_gradient_handle_positions_remove.restype = None
dll.pixie_paint_gradient_handle_positions_delete.argtypes = [Paint, c_longlong]
dll.pixie_paint_gradient_handle_positions_delete.restype = None
dll.pixie_paint_gradient_handle_positions_add.argtypes = [Paint, Vector2]
dll.pixie_paint_gradient_handle_positions_add.restype = None
@ -1601,8 +1794,8 @@ dll.pixie_paint_gradient_stops_get.restype = ColorStop
dll.pixie_paint_gradient_stops_set.argtypes = [Paint, c_longlong, ColorStop]
dll.pixie_paint_gradient_stops_set.restype = None
dll.pixie_paint_gradient_stops_remove.argtypes = [Paint, c_longlong]
dll.pixie_paint_gradient_stops_remove.restype = None
dll.pixie_paint_gradient_stops_delete.argtypes = [Paint, c_longlong]
dll.pixie_paint_gradient_stops_delete.restype = None
dll.pixie_paint_gradient_stops_add.argtypes = [Paint, ColorStop]
dll.pixie_paint_gradient_stops_add.restype = None
@ -1736,8 +1929,8 @@ dll.pixie_font_paints_get.restype = Paint
dll.pixie_font_paints_set.argtypes = [Font, c_longlong, Paint]
dll.pixie_font_paints_set.restype = None
dll.pixie_font_paints_remove.argtypes = [Font, c_longlong]
dll.pixie_font_paints_remove.restype = None
dll.pixie_font_paints_delete.argtypes = [Font, c_longlong]
dll.pixie_font_paints_delete.restype = None
dll.pixie_font_paints_add.argtypes = [Font, Paint]
dll.pixie_font_paints_add.restype = None

View file

@ -17,4 +17,10 @@ task docs, "Generate API documents":
exec "nim doc --index:on --project --out:docs --hints:off src/pixie.nim"
task bindings, "Generate bindings":
exec "nim c -f -d:release --app:lib --gc:arc --tlsEmulation:off --out:pixie --outdir:bindings/generated bindings/bindings.nim"
when defined(windows):
const libName = "pixie.dll"
elif defined(macosx):
const libName = "libpixie.dylib"
else:
const libName = "libpixie.so"
exec "nim c -f -d:release --app:lib --gc:arc --tlsEmulation:off --out:" & libName & " --outdir:bindings/generated bindings/bindings.nim"

View file

@ -3,7 +3,7 @@ import bumpy, chroma, common, os, pixie/fontformats/opentype,
pixie/paths, strutils, unicode, vmath
const
AutoLineHeight* = -1.float32 ## Use default line height for the font size
autoLineHeight*: float32 = -1 ## Use default line height for the font size
LF = Rune(10)
SP = Rune(32)
@ -16,7 +16,7 @@ type
Font* = ref object
typeface*: Typeface
size*: float32 ## Font size in pixels.
lineHeight*: float32 ## The line height in pixels or AutoLineHeight for the font's default line height.
lineHeight*: float32 ## The line height in pixels or autoLineHeight for the font's default line height.
paints*: seq[Paint]
textCase*: TextCase
underline*: bool ## Apply an underline.
@ -142,7 +142,7 @@ proc newFont*(typeface: Typeface): Font {.raises: [].} =
result = Font()
result.typeface = typeface
result.size = 12
result.lineHeight = AutoLineHeight
result.lineHeight = autoLineHeight
result.paint = newPaint(pkSolid)
result.paint.color = color(0, 0, 0, 1)

View file

@ -64,6 +64,9 @@ converter parseSomePaint*(
elif type(paint) is Paint:
paint
proc colorStop*(color: Color, position: float32): ColorStop =
ColorStop(color: color, position: position)
proc toLineSpace(at, to, point: Vec2): float32 {.inline.} =
## Convert position on to where it would fall on a line between at and to.
let