cairo

MoonBit bindings for the Cairo 2D graphics library

cairo
graphics
ffi
bindings
moon add tonyfettes/cairo@0.2.0
Download zip
Version
0.2.0
License
Apache-2.0
Last updated
23 days ago
Downloads
10
README

#Cairo bindings for MoonBit

This module contains an initial hand-written native binding for representative Cairo APIs. It is deliberately small so the ownership rules and public API can be validated before extending the GIR generator for Cairo.

The current surface covers image and recording surfaces, drawing contexts, path construction, owned path snapshots with typed segments, painting, transforms, status inspection, PNG output, and current-point output parameters. Cairo is discovered at build time with pkg-config cairo.

#
Content

pub(all) enum Content {
Color
Alpha
ColorAlpha
} derive(Eq,
Debug
)

The color and alpha channels stored by a surface.

#
Context

type Context

An owned reference to a Cairo drawing context.

#
Context::append_path

fn Context::append_path(self : Context, path : Path) -> Unit

#
Context::arc

fn Context::arc(self : Context, center_x : Double, center_y : Double, radius : Double, angle_1 : Double, angle_2 : Double) -> Unit

#
Context::close_path

fn Context::close_path(self : Context) -> Unit

#
Context::copy_path

fn Context::copy_path(self : Context) -> Path

#
Context::copy_path_flat

fn Context::copy_path_flat(self : Context) -> Path

#
Context::create

fn Context::create(surface : Surface) -> Context

#
Context::curve_to

fn Context::curve_to(self : Context, x1 : Double, y1 : Double, x2 : Double, y2 : Double, x3 : Double, y3 : Double) -> Unit

#
Context::fill

fn Context::fill(self : Context) -> Unit

#
Context::get_current_point

fn Context::get_current_point(self : Context) -> (Double, Double)

Returns the current path point through Cairo's output-parameter API.

#
Context::get_target

fn Context::get_target(self : Context) -> Surface

#
Context::line_to

fn Context::line_to(self : Context, x : Double, y : Double) -> Unit

#
Context::move_to

fn Context::move_to(self : Context, x : Double, y : Double) -> Unit

#
Context::new_path

fn Context::new_path(self : Context) -> Unit

#
Context::paint

fn Context::paint(self : Context) -> Unit

#
Context::rectangle

fn Context::rectangle(self : Context, x : Double, y : Double, width : Double, height : Double) -> Unit

#
Context::restore

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

#
Context::rotate

fn Context::rotate(self : Context, radians : Double) -> Unit

#
Context::save

fn Context::save(self : Context) -> Unit

#
Context::scale

fn Context::scale(self : Context, sx : Double, sy : Double) -> Unit

#
Context::set_line_width

fn Context::set_line_width(self : Context, width : Double) -> Unit

#
Context::set_source_rgb

fn Context::set_source_rgb(self : Context, red : Double, green : Double, blue : Double) -> Unit

#
Context::set_source_rgba

fn Context::set_source_rgba(self : Context, red : Double, green : Double, blue : Double, alpha : Double) -> Unit

#
Context::set_source_surface

fn Context::set_source_surface(self : Context, surface : Surface, x? : Double, y? : Double) -> Unit

#
Context::status

fn Context::status(self : Context) -> Status

Returns this context's current status.

#
Context::stroke

fn Context::stroke(self : Context) -> Unit

#
Context::translate

fn Context::translate(self : Context, tx : Double, ty : Double) -> Unit

#
FontType

pub(all) enum FontType {
Toy
Ft
Win32
Quartz
User
Dwrite
} derive(Eq,
Debug
)

The backend used by a Cairo font face or scaled font.

#
Format

pub(all) enum Format {
Argb32
Rgb24
A8
A1
} derive(Eq,
Debug
)

The pixel layout used by an image surface.

#
Path

type Path

An independently owned snapshot of Cairo path data.

#
Path::segments

fn Path::segments(self : Path) -> Array[PathSegment]

Copies the native path data into typed MoonBit segments.

A path with a non-success status produces an empty array; inspect Path::status before consuming its segments when errors are possible.

#
Path::status

fn Path::status(self : Path) -> Status

Returns the status stored in this path snapshot.

#
PathSegment

pub(all) enum PathSegment {
PathSegmentMoveTo(Double, Double)
PathSegmentLineTo(Double, Double)
PathSegmentCurveTo(Double, Double, Double, Double, Double, Double)
PathSegmentClosePath
} derive(Eq,
Debug
)

One typed command from a Cairo path snapshot.

#
Rectangle

pub struct Rectangle {
x : Double
y : Double
width : Double
height : Double
} derive(Eq,
Debug
)

A floating-point rectangle.

The Cairo API that consumes the rectangle defines its coordinate space.

#
Rectangle::components

fn Rectangle::components(self : Rectangle) -> (Double, Double, Double, Double)

Returns (x, y, width, height).

#
Rectangle::new

fn Rectangle::new(x : Double, y : Double, width : Double, height : Double) -> Rectangle

Creates a rectangle without restricting its origin or dimensions.

#
Status

A version-tolerant Cairo status code.

Status remains opaque so newer Cairo releases can return status values that were unknown when this binding was compiled.

#
Status::is_success

fn Status::is_success(self : Status) -> Bool

Returns whether this status represents a successful operation.

#
Status::to_int

fn Status::to_int(self : Status) -> Int

Returns Cairo's numeric representation of this status.

#
Status::to_string

fn Status::to_string(self : Status) -> String

Returns Cairo's description of this status.

#
Surface

type Surface

An owned reference to a Cairo surface.

#
Surface::create_image

fn Surface::create_image(format : Format, width : Int, height : Int) -> Surface

Creates an image surface with the requested pixel format and dimensions.

#
Surface::create_recording

fn Surface::create_recording(content : Content, extents? : Rectangle) -> Surface

Creates a surface that records drawing operations for later replay.

Omitting extents creates an unbounded recording surface. A supplied rectangle limits recording in the surface's device-space coordinates. Transformations later applied to a drawing context, such as scaling or translation, do not transform these bounds. Cairo copies the rectangle during this call.

#
Surface::height

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

#
Surface::status

fn Surface::status(self : Surface) -> Status

Returns this surface's current status.

#
Surface::stride

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

#
Surface::width

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

#
Surface::write_to_png

fn Surface::write_to_png(self : Surface, path : String) -> Status

Writes this surface to a PNG file and returns Cairo's operation status.

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io