Cairo Dart

Dart bindings to the Cairo C graphics library.

Features

  • Rendering lines, arcs, B├ęzier curves (cubic and quadratic).
  • Saving to an image
  • Transformations (rotation, translation, scaling, and any other matrix-described transformation)
  • Fill and stroke (only solid color for now)

Getting started

1. Download Cairo

Detailed on cairo's website

2. Install

dart pub install cairo

3. That's all, enjoy!

Usage

// Load the cairo c library
CairoLib.load();

// Create a 640x320 surface / canvas
final img = ImageSurface(
  format: ImageFormat.ARGB32,
  width: 640,
  height: 360,
);

// render a magenta background
img.rectangle(Point(0, 0), img.width, img.height);
img.sourceColor = Color.magenta;
img.fill();

// save the image
img.save('out.png');

// destroy the image data in the RAM
img.destroy();

For more complicated examples, look at the example/ folder.

Additional information

Some of the functions cairo has aren't implemented yet. If you think a function needs to be added, you can create an issue explaining this.

This project is part of Manim Web.

Libraries

cairo