Thin wrapper for the cairo 2D graphics library.
Tested on Zig version 0.9.1.
🚧 Very much a work in progress... 🚧
As suggested in the cairo Appendix, the type names and method names of the original C library were changed to follow the Zig Style Guide. For example, a method like cairo_set_source(cr, source)
in cairo becomes cr.setSource(source)
in zig-cairo.
Clone the repo and jump into it:
git clone [email protected]:jackdbd/zig-cairo.git
cd zig-cairo
In order to use this library and run the examples you will need zig version 0.9.1. You can get it using zigup:
zigup fetch 0.9.1
zigup 0.9.1
You will also need cairo, pango, pangocairo, xcb, and xvfb if you want to run some tests/examples in a virtual framebuffer. See this script.
You can find many examples in the examples directory.
Run zig build --help
to see all the compilation targets.
Most examples generate a PNG. Here I use feh to view the generated file:
zig build rounded_rectangle && feh examples/generated/rounded_rectangle.png
zig build spirograph && feh examples/generated/spirograph.png
zig build text_extents && feh examples/generated/text_extents.png
A few examples generate a SVG:
zig build surface_svg && inkscape examples/generated/test-image.svg
Some other examples don't generate any image file. This one opens a window and renders cairo graphics inside of it (using a cairo XCB surface):
zig build surface_xcb
If you installed XVFB you can also run this example in a virtual framebuffer:
xvfb-run --server-args="-screen 0 1024x768x24" zig build surface_xcb
# run all tests, in all modes (debug, release-fast, release-safe, release-small)
zig build test
# run all tests, only in debug mode
zig build test-debug