skia

MoonBit bindings for Skia

skia
graphics
ffi
moon add klaseca/skia@0.1.0
Download zip
Author
Version
0.1.0
License
Apache-2.0
Last updated
2 days ago
Downloads
2

Dependencies

README

#klaseca/skia

High-level native MoonBit bindings for the C API provided by mono/skia's SkiaSharp native library.

#Native dependency

The package requires compatible mono/skia C headers and a libSkiaSharp library. Native artifacts are not included in the MoonBit package. The repository release matching this package pins compatible sources and provides the cross-platform build command in the building guide.

Set the absolute SKIA_PATH environment variable to the dependency root. It must contain include/c, and the matching library must be under out/<system>/<architecture>/release.

The native prebuild hook requires Node.js. It validates both <SKIA_PATH>/include/c/sk_types.h and the platform-specific library before compilation starts.

On Windows, the matching libSkiaSharp.dll must also be on PATH when running the executable. Linux and macOS builds use a runtime search path emitted by the native build hook.

#Usage

Owned resources have native finalizers. Call dispose() when deterministic release matters and do not use a resource after disposing it.

let surface = try! @skia.Surface(width=640, height=360)
defer surface.dispose()

let paint = @skia.Paint()
defer paint.dispose()

let typeface = try! @skia.Typeface::default()
defer typeface.dispose()

let font = try! @skia.Font(typeface, size=32.0)
defer font.dispose()

surface.canvas().draw_text(b"MoonBit + Skia", x=48.0, y=96.0, font, paint)
try! surface.write_png(b"out.png")

Canvas is a dependent view. It does not own the native canvas and retains its surface for as long as the view remains reachable.

Typeface::default() selects the platform default. One typeface can be reused to create multiple fonts and can be disposed after they have been created.

#
SkiaError

pub(all) suberror SkiaError {
InvalidPixelBufferSize(width~ : Int, height~ : Int)
InvalidSurfaceSize(width~ : Int, height~ : Int)
TypefaceCreateFailed
FontCreateFailed
PathParseSvgFailed
SurfaceReadPixelsFailed
SurfaceCreateFailed(width~ : Int, height~ : Int)
WritePngFailed(status~ : Int)
} derive(Eq,
Debug
)

#
Canvas

pub struct Canvas {
// private fields
}

#
Canvas::clear

fn Canvas::clear(self : Canvas, color : Color) -> Unit

#
Canvas::clip_rect

fn Canvas::clip_rect(self : Canvas, rect : Rect, antialias? : Bool) -> Unit

#
Canvas::draw_circle

fn Canvas::draw_circle(self : Canvas, cx : Float, cy : Float, radius : Float, paint : Paint) -> Unit

#
Canvas::draw_line

fn Canvas::draw_line(self : Canvas, x0 : Float, y0 : Float, x1 : Float, y1 : Float, paint : Paint) -> Unit

#
Canvas::draw_path

fn Canvas::draw_path(self : Canvas, path : Path, paint : Paint) -> Unit

#
Canvas::draw_round_rect

fn Canvas::draw_round_rect(self : Canvas, rect : Rect, rx : Float, ry : Float, paint : Paint) -> Unit

#
Canvas::draw_text

fn Canvas::draw_text(self : Canvas, text : Bytes, x~ : Float, y~ : Float, font : Font, paint : Paint) -> Unit

#
Canvas::restore

fn Canvas::restore(self : Canvas) -> Unit

#
Canvas::save

fn Canvas::save(self : Canvas) -> Int

#
Color

pub struct Color {
a : Byte
r : Byte
g : Byte
b : Byte
}

#
Color::Color

fn Color::Color(a~ : Byte, r~ : Byte, g~ : Byte, b~ : Byte) -> Color

#
Font

pub struct Font {
// private fields
}

#
Font::Font

fn Font::Font(typeface : Typeface, size~ : Float) -> Font raise SkiaError

#
Font::dispose

fn Font::dispose(self : Font) -> Unit

#
Font::measure_text

fn Font::measure_text(self : Font, text : Bytes) -> Float

#
Font::metrics

fn Font::metrics(self : Font) -> FontMetrics

#
Font::set_size

fn Font::set_size(self : Font, size : Float) -> Unit

#
FontMetrics

pub(all) struct FontMetrics {
ascent : Float
descent : Float
leading : Float
}

#
Paint

pub struct Paint {
// private fields
}

#
Paint::Paint

fn Paint::Paint() -> Paint

#
Paint::dispose

fn Paint::dispose(self : Paint) -> Unit

#
Paint::set_antialias

fn Paint::set_antialias(self : Paint, enabled : Bool) -> Unit

#
Paint::set_color

fn Paint::set_color(self : Paint, color : Color) -> Unit

#
Paint::set_stroke_width

fn Paint::set_stroke_width(self : Paint, width : Float) -> Unit

#
Paint::set_style

fn Paint::set_style(self : Paint, style : PaintStyle) -> Unit

#
PaintStyle

pub(all) enum PaintStyle {
Fill
Stroke
}

#
Path

pub struct Path {
// private fields
}

#
Path::Path

fn Path::Path() -> Path

#
Path::dispose

fn Path::dispose(self : Path) -> Unit

#
Path::parse_svg

fn Path::parse_svg(self : Path, svg : Bytes) -> Unit raise SkiaError

#
Path::reset

fn Path::reset(self : Path) -> Unit

#
Path::rewind

fn Path::rewind(self : Path) -> Unit

#
PixelBuffer

pub struct PixelBuffer {
data : Bytes
width : Int
height : Int
row_bytes : Int
}

#
PixelBuffer::PixelBuffer

fn PixelBuffer::PixelBuffer(width~ : Int, height~ : Int) -> PixelBuffer raise SkiaError

#
Rect

pub struct Rect {
left : Float
top : Float
right : Float
bottom : Float
}

#
Rect::Rect

fn Rect::Rect(left~ : Float, top~ : Float, right~ : Float, bottom~ : Float) -> Rect

#
Surface

pub struct Surface {
// private fields
}

#
Surface::Surface

fn Surface::Surface(width~ : Int, height~ : Int) -> Surface raise SkiaError

#
Surface::canvas

fn Surface::canvas(self : Surface) -> Canvas

#
Surface::dispose

fn Surface::dispose(self : Surface) -> Unit

#
Surface::height

fn Surface::height(self : Surface) -> Int

#
Surface::read_pixels

fn Surface::read_pixels(self : Surface) -> PixelBuffer raise SkiaError

#
Surface::read_pixels_into

fn Surface::read_pixels_into(self : Surface, buffer : PixelBuffer) -> Unit raise SkiaError

#
Surface::row_bytes

fn Surface::row_bytes(self : Surface) -> Int

#
Surface::width

fn Surface::width(self : Surface) -> Int

#
Surface::write_png

fn Surface::write_png(self : Surface, path : Bytes) -> Unit raise SkiaError

#
Typeface

pub struct Typeface {
// private fields
}

#
Typeface::default

fn Typeface::default() -> Typeface raise SkiaError

#
Typeface::dispose

fn Typeface::dispose(self : Typeface) -> Unit

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io