https://github.com/chris00/ocaml-cairo
Binding to Cairo, a 2D Vector Graphics Library.
https://github.com/chris00/ocaml-cairo
cairo cairo-drawing drawing dune ocaml ocaml-bindings stroke tutorial
Last synced: 3 months ago
JSON representation
Binding to Cairo, a 2D Vector Graphics Library.
- Host: GitHub
- URL: https://github.com/chris00/ocaml-cairo
- Owner: Chris00
- License: lgpl-3.0
- Created: 2013-08-10T09:29:30.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2024-11-08T19:34:40.000Z (8 months ago)
- Last Synced: 2025-04-09T15:09:38.932Z (3 months ago)
- Topics: cairo, cairo-drawing, drawing, dune, ocaml, ocaml-bindings, stroke, tutorial
- Language: OCaml
- Size: 3.97 MB
- Stars: 55
- Watchers: 5
- Forks: 9
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE.md
Awesome Lists containing this project
README

OCaml interface to Cairo
========================This is an OCaml binding for the
[Cairo](http://www.cairographics.org/) library, a 2D graphics library
with support for multiple output devices.You can read the API of
[Cairo](http://chris00.github.io/ocaml-cairo/doc/cairo2/Cairo/),
[Cairo_gtk](http://chris00.github.io/ocaml-cairo/doc/cairo2-gtk/Cairo_gtk/),
and
[Cairo_pango](http://chris00.github.io/ocaml-cairo/doc/cairo2-pango/Cairo_pango/)
online.Prerequisites
-------------You need the development files of Cairo (see the
[conf-cairo](https://github.com/ocaml/opam-repository/blob/master/packages/conf-cairo/conf-cairo.1/opam#L7)
package)
and the OCaml package
``lablgtk2`` (in the [OPAM](https://opam.ocaml.org/) package
``lablgtk``).Compilation & Installation
--------------------------The easier way to install this library — once the prerequisites are set
up — is to use [opam](http://opam.ocaml.org/):opam install cairo2
If you would like to compile from the sources, install [Dune][]
opam install dune
and do:
dune build @install
or just `make`. You can then install it with:
dune install
[Dune]: https://github.com/ocaml/dune
Examples
--------You can read a version of the
[Cairo tutorial](http://chris00.github.io/ocaml-cairo/) using
this module. The code of this tutorial is available in the
``examples/`` directory. To compile it, just dodune build @examples
All the examples below are available (with some comments) by clicking
on images in the [tutorial](http://cairo.forge.ocamlcore.org/tutorial/).### Basic examples
- [stroke.ml](examples/stroke.ml) shows how to draw (stroke) a simple
rectangle on a PNG surface.
- [stroke.ml](examples/stroke.ml) shows how to fill a simple
rectangle on a PNG surface.
- [showtext.ml](examples/showtext.ml) illustrates how to select a font
and draw some text on a PNG surface.
- [paint.ml](examples/paint.ml) shows how to paint the current source
everywhere within the current clip region.
- [mask.ml](examples/mask.ml) shows how to apply a radial transparency
mask on top of a linear gradient.
- [setsourcergba.ml](examples/setsourcergba.ml) produces
- [setsourcegradient.ml](examples/setsourcegradient.ml) shows how to use
radial and linear patterns. It generates:
- [path_close.ml](examples/path_close.ml) shows how to draw a closed
path. It produces the PNG:
- [textextents.ml](examples/textextents.ml) displays graphically the various
dimensions one can request about text. It generates the PNG:
- [text_extents.ml](examples/text_extents.ml) exemplifies drawing
consecutive UTF-8 strings in a PDF file. Some helping lines are
also added to show the text extents.- [tips_ellipse.ml](examples/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](examples/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](examples/tips_font.ml) to have:
### Examples generating the images of the tutorial
- [diagram.ml](examples/diagram.ml) draw the images of the section
[Cairo's Drawing Model](http://cairo.forge.ocamlcore.org/tutorial/#drawing_model):






- [draw.ml](examples/draw.ml) generates the various images in
[Drawing with Cairo](http://cairo.forge.ocamlcore.org/tutorial/#drawing_with_cairo), namely:






