The Cairo graphics tutorial -------Cairo definitions

转载 2012年03月30日 08:14:42

Cairo definitions

In this part of the Cairo graphics tutorial, we will provide some useful definitions for the Cairo graphics library.This will help us better understand the Cairo drawing model.


To do some drawing in Cairo, we must first create a Cairo context. The Cairo context holds all of the graphics state parameters that describe how drawing is to be done. This includes information such as line width, color, the surface to draw to, and many other things. This allows the actual drawing functions to take fewer arguments to simplify the interface. The gdk_cairo_create() function call creates a cairo context for drawing to drawable.

cairo_t *cr;
cr = gdk_cairo_create(widget->window);

These two lines create a cairo context. In this example, the context is tied to a GdkDrawable. A cairo_t structure contains the current state of the rendering device, including coordinates of yet to be drawn shapes.Technically speaking, the cairo_t objects are called the Cairo contexts.

All drawing with cairo is always done to a cairo_t object. A Cairo context is tied to a specific surface. A pdf, svg, png, GdkDrawable etc.

The GDK does not wrap the Cairo API. It allows to create a Cairo context, which can be used to draw on GDK drawables. Additional functions allow to convert GDK's rectangles and regions into Cairo paths and to use pixbufs as sources for drawing operations.


A path is made up of one or more lines. These lines are connected by two or more anchor points. Paths can be made up of straight lines and curves. There are two kinds of paths. Open and closed paths. In a closed path, starting and ending points meet. In an open path, starting and ending point do not meet.

In Cairo, we start with an empty path. First we define a path and then we make them visible by stroking and filling them. One important note. After each cairo_stroke() or cairo_fill() function calls, the path is emptied. We have to define a new path.

A path is made of subpaths.


The source is the paint we use in drawing. We can compare the source to a pen or ink, that we will use to draw theoutlines and fill the shapes. There are four kinds of basic sources. Colors, gradients, patterns and images.


The surface is a destination that we are drawing to. We can render documents using the PDF or PostScript surfaces, directly draw to a platform via the Xlib and Win32 surfaces.

The documentation mentions the following surfaces:

typedef enum _cairo_surface_type {
} cairo_surface_type_t;


Before the source is applied to the surface, it is filtered first. The mask is used as a filter. The mask determines, where the sourse is applied and where not. Opaque parts of the mask allow to copy the source. Transparent parts do notlet to copy the source to the surface.


A cairo pattern represents a source when drawing onto a surface.In cairo, a pattern is something that you can read from, that is used as the source or mask of a drawing operation. Patterns in cairo can be solid, surface-based, or even gradients patterns.

In this chapter of the Cairo tutorial, we have given some basic definitions.

ubuntu Cairo图形库 环境搭建

Cairo官网: 根据官网指示,我使用如下语句安装好cairo库 sudo apt-get install libcairo2-dev 从官...
  • zh19921107
  • zh19921107
  • 2015年04月17日 11:27
  • 4605

Ubuntu 14.04 安装配置 cairo-dock 实现美化+特效

Ubuntu 14.04 安装配置 cairo-dock
  • u014731529
  • u014731529
  • 2014年05月31日 23:50
  • 16419


14、交叉编译cairo 目标平台:LOONGSON-1B开发板 内核:Linux 3.0 编译平台:ubuntu10.04 交叉工具链:gcc-3.4.6-2f   一、简介   ...
  • water_cow
  • water_cow
  • 2013年03月27日 20:15
  • 4343

The Cairo graphics tutorial -------Transformations

In this part of the Cairo graphics programming tutorial, we will talk about transformations. ...
  • intruder83
  • intruder83
  • 2012年03月30日 08:22
  • 307

The Cairo graphics tutorial -------Transparency

In this part of the Cairo C API tutorial, we will talk about transparency. We will provide some basi...
  • intruder83
  • intruder83
  • 2012年03月30日 08:19
  • 263

The Cairo graphics tutorial -------Custom GTK widget

In this part of the Cairo graphics tutorial, we will create a custom GTK widget, where we will use t...
  • intruder83
  • intruder83
  • 2012年03月30日 08:32
  • 236

The Cairo graphics tutorial -------Clipping and masking

In this part of the Cairo tutorial, we will talk about clipping and masking. Clipping ...
  • intruder83
  • intruder83
  • 2012年03月30日 08:21
  • 408

The Cairo graphics tutorial -------Text in Cairo

In this part of the Cairo graphics tutorial, we will work with text. Soulmate In the first...
  • intruder83
  • intruder83
  • 2012年03月30日 08:23
  • 202

The Cairo graphics tutorial -------Shapes and fills in Cairo

In this part of the Cairo tutorial, we will create some basic and more advanced shapes. We will fill...
  • intruder83
  • intruder83
  • 2012年03月30日 08:18
  • 352

The Cairo graphics tutorial -------Cairo backends

The Cairo library supports various backends. In this section of the Cairo graphics tutorial, we will...
  • intruder83
  • intruder83
  • 2012年03月30日 08:15
  • 330
您举报文章:The Cairo graphics tutorial -------Cairo definitions