Samiksha Jaiswal (Editor)

Cairo (graphics)

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Written in
  
C

Cairo (graphics)

Original author(s)
  
Keith Packard, Carl Worth

Developer(s)
  
Carl Worth, Behdad Esfahbod

Initial release
  
before 2003; 14 years ago (2003)

Stable release
  
1.15.4 (December 9, 2016; 2 months ago (2016-12-09)) [±]

Repository
  
cgit.freedesktop.org/cairo/

Cairo (stylized as cairo) is an open source programming library that provides a vector graphics-based, device-independent API for software developers. It provides primitives for two-dimensional drawing across a number of different back ends. Cairo uses hardware acceleration when available.

Contents

There is a formal proposal to standardize C++ 2D graphic API based on a mechanical transformation of Cairo.

Language bindings

A library written in one programming language may be used in another language if bindings are written; Cairo has a range of bindings for various languages including C++, C# and other CLI languages, Delphi, Factor, Haskell, Lua, Perl, PHP, Python, Ruby, Scheme, Smalltalk and several others.

Toolkit bindings

Since Cairo is only a drawing library, it can be quite useful to integrate it with a graphical user interface toolkit.

  • FLTK has full Cairo support (through "--enable-cairo" compile switch).
  • GNUstep currently uses Cairo as its primary backend on non-Windows systems.
  • GTK+ has not only full support for Cairo, but starting in 2005 with version 2.8, uses Cairo to render the majority of its graphical control elements, and since 3.0 all rendering is done through Cairo.
  • The Cairo development team maintains up-to-date instructions for rendering surfaces to SDL.
  • Available back-ends

    Cairo supports output to a number of different back-ends, known as "surfaces" in its code. Back-ends support includes output to the X Window System, via both Xlib and XCB, Win32 GDI, OS X Quartz Compositor, the BeOS API, OS/2, OpenGL contexts (directly and via glitz), local image buffers, PNG files, PDF, PostScript, DirectFB and SVG files.

    There are other back-ends in development targeting the graphics APIs OpenVG, Qt, Skia, and Microsoft's Direct2D.

    Drawing model

    The Cairo drawing model is somewhat unorthodox and relies on a three layer model.

    Any drawing process takes place in three steps:

    1. First a mask is created, which includes one or more vector primitives or forms, i.e., circles, squares, TrueType fonts, bézier curves, etc.
    2. Then source must be defined, which may be a color, a color gradient, a bitmap or some vector graphics, and from the painted parts of this source a die cut is made with the help of the above defined mask.
    3. Finally the result is transferred to the destination or surface, which is provided by the back-end for the output.

    This constitutes a fundamentally different approach from Scalable Vector Graphics.

    Example

    Quite complex "Hello world"-graphics can be drawn with the help of Cairo with only a few lines of source code:

    Notable usage

    Cairo is popular in the open source community for providing cross-platform support for advanced 2D drawing.

  • GTK+, starting in 2005 with version 2.8, uses Cairo to render the majority of its graphical control elements. Since GTK+ version 3, all the rendering is done using Cairo.
  • The Mono Project, including Moonlight, has been using Cairo since very early in conception to power the backends of its GDI+ (libgdiplus) and System.Drawing namespaces.
  • The Mozilla project has made use of Cairo in its Gecko layout engine, used for rendering the graphical output of Mozilla products. Gecko 1.8, the layout engine for Mozilla Firefox 2.0 and SeaMonkey 1.0, used Cairo to render SVG and <canvas> content. Gecko 1.9, the release of Gecko that serves as the basis of Firefox 3, uses Cairo as the graphics backend for rendering both web page content and the user interface (or "chrome").
  • The WebKit framework uses Cairo for all rendering in the GTK+ and EFL ports. Support has also been added for SVG and <canvas> content using Cairo.
  • The Poppler library uses Cairo to render PDF documents. Cairo enables the drawing of antialiased vector graphics and transparent objects.
  • The vector graphics application Inkscape uses the Cairo library for its outline mode display, as well as for PDF and PostScript export since release 0.46.
  • MorphOS 2.5 features a shared library implementation of Cairo, which was available as stand-alone release for earlier MorphOS versions.
  • AmigaOS 4.1 supports a shared object library of Cairo (libcairo.so) in its default installation.
  • FontForge enabled Cairo by default for rendering in mid-October 2008.
  • R can output plots in PDF, PostScript and SVG formats using Cairo if available.
  • Gnuplot 4.4 now uses Cairo for rendering PDF and PNG output.
  • Internet Browser for PlayStation 3 uses Cairo since system software update 4.10.
  • Synfig 0.64 now supports optional Cairo rendering
  • On-demand graphing of time series data in Graphite
  • History

    Keith Packard and Carl Worth founded the Cairo project for use in the X Window System. It was originally (until at least 2003) called Xr or Xr/Xc. The name was changed to emphasize the idea of a cross-platform library to access display server, not tied to the X Window System. The name Cairo derives from the original name Xr, interpreted as the Greek letters chi and rho.

    References

    Cairo (graphics) Wikipedia