package cairo2

  1. Overview
  2. Docs
Binding to Cairo, a 2D Vector Graphics Library

Install

Dune Dependency

Authors

Maintainers

Sources

cairo2-0.6.5.tbz
sha256=25dc41c9436d9abcf56caad9a105944ff7346041b8cc6a2a654ab8848b657372
sha512=9c13aaf0c716ac2fdec90d6dcb90a654c051cb9aa896e9333b819e68669efbf3ee7bb147882d45dd5b86db3fd868158bce46f46c5c8960f9add523d64342f704

Description

This is a binding to Cairo, a 2D graphics library with support for multiple output devices. Currently supported output targets include the X Window System, Quartz, Win32, image buffers, PostScript, PDF, and SVG file output.

Tags

Cairo stroke drawing tutorial

Published: 12 Nov 2024

README

README.md

OCaml interface to Cairo

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.

Prerequisites

You need the development files of Cairo (see the conf-cairo package) and the OCaml package lablgtk2 (in the OPAM package lablgtk).

Compilation & Installation

The easier way to install this library — once the prerequisites are set up — is to use opam:

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

Examples

You 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 @examples

All the examples below are available (with some comments) by clicking on images in the tutorial.

Basic examples

  • stroke.ml shows how to draw (stroke) a simple rectangle on a PNG surface.

  • stroke.ml shows how to fill a simple rectangle on a PNG surface.

  • showtext.ml illustrates how to select a font and draw some text on a PNG surface.

  • paint.ml shows how to paint the current source everywhere within the current clip region.

  • mask.ml shows how to apply a radial transparency mask on top of a linear gradient.

  • 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:

  • 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 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:

Examples generating the images of the tutorial

Dependencies (5)

  1. conf-cairo
  2. dune-configurator >= "2.7.0"
  3. dune >= "2.7.0"
  4. base-bigarray
  5. ocaml >= "4.03"

Dev Dependencies

None

Used by (16)

  1. acgtk >= "1.3.2"
  2. altgr-ergo >= "2.4.3"
  3. bimage-gtk
  4. cairo2-gtk < "0.6.1" | >= "0.6.5"
  5. cairo2-pango < "0.6.1" | >= "0.6.5"
  6. coqide >= "8.17.0"
  7. DrawGrammar != "0.2.1"
  8. elm_playground_native
  9. JsOfOCairo = "1.0.1" | >= "2.0.0"
  10. jupyter-archimedes >= "2.7.2"
  11. lablgtk3 >= "3.0.beta4"
  12. matita
  13. mlpost >= "0.9"
  14. OCADml < "0.4.0"
  15. OSCADml
  16. ocamlviz

Conflicts (2)

  1. cairo = "0.4.2"
  2. cairo = "0.4.1"
OCaml

Innovation. Community. Security.