Page
Library
Module
Module type
Parameter
Class
Class type
Source
This is an OCaml binding for the Cairo library, a 2D graphics library with support for multiple output devices.
You can read the API of Cairo, Cairo_gtk, and Cairo_pango online.
You need the development files of Cairo (see the conf-cairo package) and the OCaml package lablgtk2 (in the OPAM package lablgtk).
The easier way to install this library — once the prerequisites are set up — is to use opam:
opam install cairo2If you would like to compile from the sources, install Dune
opam install duneand do:
dune build @installor just make. You can then install it with:
dune installYou can read a version of the Cairo tutorial using this module. The code of this tutorial is available in the examples/ directory. To compile it, just do
dune build @examplesAll the examples below are available (with some comments) by clicking on images in the tutorial.
setsourcergba.ml produces

setsourcegradient.ml shows how to use radial and linear patterns. It generates:

path_close.ml shows how to draw a closed path. It produces the PNG:

textextents.ml displays graphically the various dimensions one can request about text. It generates the PNG:

tips_ellipse.ml shows the action of dilation on the line width and how to properly draw ellipses. It generates the PNG:

tips_letter.ml illustrates the wrong way of centering characters based on their individual extents:

Instead, one should combine them with the font extents as shown in tips_font.ml to have:

diagram.ml draw the images of the section Cairo's Drawing Model:

draw.ml generates the various images in Drawing with Cairo, namely:
