Skip to content

jackdbd/zig-cairo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zig-cairo

CI

Thin wrapper for the cairo 2D graphics library.

Tested on Zig version 0.9.1.

🚧 Very much a work in progress... 🚧

Naming convention

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.

Installation

Clone the repo and jump into it:

git clone git@github.com: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.

Examples

You can find many examples in the examples directory.

arc.zig arc_negative.zig curve_to.zig fill_style.zig gradient.zig image.zig spiral.zig spirograph.zig

compositing.zig pango_simple.zig

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

Tests

# 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

About

🪲 zig-idiomatic wrapper for cairo

Topics

Resources

License

Unknown, LGPL-2.1 licenses found

Licenses found

Unknown
LICENSE
LGPL-2.1
LICENSE-LGPL-2.1-only

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published