Pure-MoonBit headless 2D canvas rasterizer with PNG output.
Dependencies
test {
let canvas = @canvas.Canvas::new(200, 100)
let ctx = canvas.context()
ctx.set_fill_style(@canvas.Color::rgb(255, 0, 0))
ctx.fill_rect(10.0, 10.0, 50.0, 50.0)
let _png : Bytes = canvas.to_png()
inspect(canvas.width, content="200")
}just # check + test (js target)
just test # run tests
just check # type check with --deny-warn
just ci-all # check + test on js, native, and wasm-gc///|
test {
let canvas = @canvas.Canvas::new(200, 100)
let ctx = canvas.context()
ctx.set_fill_style(@canvas.Color::rgb(255, 0, 0))
ctx.fill_rect(10.0, 10.0, 50.0, 50.0)
// Convert to PNG bytes.
let _png : Bytes = canvas.to_png()
ignore(_png)
inspect(canvas.width, content="200")
inspect(canvas.height, content="100")
}pub suberror ColorParseError {
ColorParseError(String)
}impl Show for ColorParseErrorpub struct Canvas {
width : Int
height : Int
pixels : FixedArray[Byte]
antialias : Bool
}pub struct DrawState {
fill_style : FillStyle
stroke_style : FillStyle
line_width : Double
global_alpha : Double
transform : Matrix2D
font : TTFont?
font_size : Double
text_align : TextAlign
text_baseline : TextBaseline
clip : ClipMask?
line_dash : Array[Double]
line_dash_offset : Double
line_cap : LineCap
line_join : LineJoin
}impl Show for LinearGradientfn LinearGradient::new(x0 : Double, y0 : Double, x1 : Double, y1 : Double, stops~ : Array[ColorStop]) -> LinearGradientpub enum PathCmd {
MoveTo(Double, Double)
LineTo(Double, Double)
QuadTo(Double, Double, Double, Double)
CubicTo(Double, Double, Double, Double, Double, Double)
Close
} derive(Eq)impl Show for RadialGradientfn RadialGradient::new(x0 : Double, y0 : Double, r0 : Double, x1 : Double, y1 : Double, r1 : Double, stops~ : Array[ColorStop]) -> RadialGradientimpl Show for TextBaselinepub struct TextMetrics {
width : Double
ascent : Double
descent : Double
}impl Show for TextMetricsfn blend_over(pixels : FixedArray[Byte], offset : Int, src : Color, coverage : Int, global_alpha : Double) -> UnitPure-MoonBit headless 2D canvas rasterizer with PNG output.
Dependencies