Cairo (graphics)

Cairo is a free 2D graphics library. It allows a device-independent, vector-based API for software developers to output to various so-called backends. Currently, the output on the X Window System, Win32, under Quartz, in local frame buffer, and in the file formats PNG, PostScript, PDF and SVG is described as stable. Back-ends for the issue under OpenGL (via glitz ), XCB, DirectFB, BeOS and OS / 2 are in development.

Cairo has been designed so that it - if available - for all output back-ends the possibility of acceleration by the GPU, for example for anti-aliasing uses.

The Cairo- development was originally started under the name Xr or Xr / Xc by Keith Packard and Carl Worth for use with the X Window System.

Competing technologies are WPF and GDI from Microsoft and Quartz from Apple.

Character model

Cairo pursues an unusual drawing technique, which is based on a tripartite model layers (see figure " Cairo's character model " ):

A drawing process takes place by a Mask (English for mask) is created, which includes one or more vector primitives or forms, that is, circles, rectangles, TTF fonts, bezier curves, etc. Then, a source must (engl. of source ) can be defined, which for example may consist of a color, a gradient, a bitmap or vector graphics. Now, stood out with the Mask as a cookie cutter of the painted part of the source. The result is finally transferred to the destination or surface which is provided by the output backend.

Thus, a fundamentally different approach than, for example, in SVG vector graphics.

Programming Example

Cairo is written in C, and there is language bindings to many other programming languages ​​, including Haskell, Java, Perl, Ruby, Python, Scheme, Smalltalk.

More complex "Hello World " graphics can already draw a few lines of source code with Cairo:


In the open- source community Cairo is due to its ability to create platform-independent high-quality 2D drawings, wide distribution. Among other things, using a variety of toolkits for graphical user interfaces, browsers and graphics programs Engines Cairo.

Use in Grafiktoolkits

Cairo is supported since version 2.8.0 of GTK . Thus, it is possible of GTK widgets a Cairokontext ( cairo_t, see line five in the example) to gain and then to draw in those with Cairofunktionen. With the same methods GTK is characterized internally from this version most of its widgets with Cairo and can thus benefit from hardware-accelerated rendering.

The developers of the C binding of GTK , gtkmm, gradually drawing with the GDK already be obsolete ( deprecated ) because, on the drawing functions from GDK complicated to use and are relatively inefficient. Instead, the invariable usage of Cairo is recommended.

Also the FLTK can use Cairo to draw the entire surface.

Thanks to its platform independence Cairo is also used in wxWidgets.

Also the Mono project used since the first versions Cairo to draw a GDI surface.

The Standard Widget Toolkit uses Cairo since version 3.1 on Linux for its characters API.

Use in browser engines

In Gecko-based browsers Cairo is from the Gecko version 1.8 ( such as but not used as of Firefox 1.5 ) used to display SVG files and from Gecko version 1.9 ( Firefox 3 ), but also to identify the complete graphical user interface ( XUL ) including web pages.

Also, WebKit uses Cairo to render all graphical elements in its GTK port. SVG and elements are also rendered using Cairo.

Use in graphics software

Since 0.46 the vector graphics program Inkscape Cairo used for the outline display mode as well as writing of PDF and PostScript documents.

Also, the PDF rendering engine used Poppler Cairo for rendering PDF documents. As a spin-off of Xpdf is Poppler in many popular PDF viewers such as Evince and Okular using.

Cairo can be used in the office suite since version 2 for hardware accelerated presentation effects.

Connection to other programming languages

Thanks to its implementation in C programming language are links to other programming languages ​​(language bindings ) easy to implement. There are bindings for C ( cairomm, analogous to gtkmm ), Java, Haskell, Mono / .NET, Perl, PHP, Python, Ruby, OCaml, Scheme, Lua, Vala and many others.

Pictures of Cairo (graphics)