Cairo Graphics Library



Cairo is a popular graphics library that many open-source programs use. For instance, the desktop dock named "Cairo-Dock" uses Cairo for its graphics, hence the name "Cairo-Dock". Cairo is vector-based. In simple terms, this means the graphics uses equations and such to generate an image in contrast to bitmap-graphics (raster-graphics) which are pixels. The main website for Cairo is here (

Cairo-Dock Screenshot -


NOTE: There is a lot to know about vector-vs-bitmap. For those of you that want a detailed explanation of vector graphics and bitmap graphics, then you may want to read this Wikipedia article -

The Cairo library is an API written in the C language. The code is platform-independent. Because of this fact, programmers do not need to rewrite Cairo code for each type of system that may use their application. Just because Cairo is a C-based library does not mean developers using other languages cannot use Cairo. There is this special thing called a "language binding" or "binding", depending on which term you prefer. Bindings allow programmers to use libraries and other code in multiple languages. For instance, a developer that uses Python code can use a Python-based Cairo binding so Cairo can be implemented into their program.


Cairo provides two-dimensional graphics, although with some clever designing, the end product can appear 3D. Cairo can be used with various GUI-toolkits like GTK, SDL, FLTK, and others. Cairo is also implemented in the Webkit and Gecko engines to manage SVG and "<canvas>" rendering. PDF and Postscript has also found a use for Cairo.

NOTE: <canvas> is an HTML5 tag that allows shapes to be displayed or drawn.

If you are a programmer interested in graphics, then you may want to learn Cairo or its binding that pertains to your preferred language. To use Cairo in C/C++ code, import Cairo like this -

#include <cairo.h>

Cairo is capable of producing text. However, some developers prefer Pango, a text renderer library ( Yes, Pango can be used with Cairo without any conflicts. In fact, many developers recommend this including myself.

Cairo code for a C/C++ application looks no different than any other command or library for C/C++. For illustration, here is code to make a single rectangle by specifying the corners as parameters -

cairo_rectangle(cr, 30, 30, 120, 80);

If you wish to learn Cairo coding, then I recommend going to Cairo's main website or learn here (

If you are doing graphics programming for your application and you are wondering why you may want to use Cairo instead of your other possible alternatives, then here are some facts to consider. Cairo is a cross-platform open-source library. Cairo uses vector graphics instead of raster/bitmap. Cairo is capable of hardware-acceleration. Cairo is stable and many binding are available.

In summary, Cairo is a popular and widely used vector-graphics library that is compatible with many programming languages.


  • slide.jpg
    81.7 KB · Views: 59,569
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Members online