30 releases

0.7.0 Oct 24, 2024
0.6.2 Jan 30, 2023
0.6.0 Nov 24, 2022
0.5.0 Nov 12, 2021
0.0.2 Feb 22, 2019

#666 in Graphics APIs

Download history 1582/week @ 2024-08-20 1481/week @ 2024-08-27 1333/week @ 2024-09-03 1258/week @ 2024-09-10 1208/week @ 2024-09-17 1454/week @ 2024-09-24 920/week @ 2024-10-01 563/week @ 2024-10-08 1026/week @ 2024-10-15 1417/week @ 2024-10-22 1080/week @ 2024-10-29 928/week @ 2024-11-05 493/week @ 2024-11-12 732/week @ 2024-11-19 1162/week @ 2024-11-26 1087/week @ 2024-12-03

3,521 downloads per month
Used in 63 crates (2 directly)

Apache-2.0 OR MIT

375KB
4K SLoC

piet-cairo: Cairo backend for piet

This is the Cairo back-end for the piet graphics API.

Toy text API

For simplicity, the back-end currently uses the toy text API in Cairo. Essentially, this means there is no shaping, so complex scripts won't render correctly at all, and Latin will be missing kerning, ligatures, and other refinements. According to the docs, "Any serious application should avoid them."

Fairly soon, I hope to have some type of higher-level text in place. One possibility is pango. From what I can tell, this should work well on Linux, but since it has a non-optional glib dependency, it might be non-trivial to get it building portably. It's also not clear to me how well this approach handles discovering system fonts.

Another possibility is to use HarfBuzz more directly, using the rust-harfbuzz bindings. This will require more work for font discovery and selection, but has the possibility to be considerably more native. A good Rust-native candidate for system font discovery is font-kit.

A third possibility is to adapt libTXT from Flutter. This is a state of the art text layout library, with considerable investment in making it work well on mobile. However, it is in C++ and thus at the very least will need nontrivial work to make good Rust bindings.

The need for text shaping will be common to many low-level renderers that are not supported by system text services, not just Cairo.

Building on non-Linux

Cairo is quite portable, and it is quite feasible to build on other systems. However, the cairo-rs crate seems to expect a library to be provided, rather than building it from sources.

On Windows, I've been using prebuilt binary releases from cairo-windows.

On macOS with Homebrew, the following should work:

brew install cairo

On OpenBSD, the library can be installed from official packages:

pkg_add cairo

On FreeBSD, the library can be installed with pkg:

pkg install cairo

On NetBSD, the library can be installed with:

pkgin install cairo

A pkg-config file is provided as usual and cairo-rs will build as expected.

TODO: nicer installation instructions (contributions welcome)

Dependencies

~9–17MB
~261K SLoC