Drawing in Cairo is done via the 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, colour, the surface to draw to, and many other things. This allows the actual drawing functions to take fewer arguments to simplify the interface.
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, GtkWindow etc.
在Cairo中绘图是通过Context。Cairo context持有所有图形样式绘图变量。该变量是用来表示按什么样式去绘图,包括了线宽、颜色、画到surface等等。这允许实际的绘图函数采用较少的参数来简化界面。
所有的绘图都是用cairo_t
对象,一个Cairo context被贴在一个指定的surface。例如:PDF、SVG、PNG、GtkWindow等等。
A 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_IMAGE,
CAIRO_SURFACE_TYPE_PDF,
CAIRO_SURFACE_TYPE_PS,
CAIRO_SURFACE_TYPE_XLIB,
CAIRO_SURFACE_TYPE_XCB,
CAIRO_SURFACE_TYPE_GLITZ,
CAIRO_SURFACE_TYPE_QUARTZ,
CAIRO_SURFACE_TYPE_WIN32,
CAIRO_SURFACE_TYPE_BEOS,
CAIRO_SURFACE_TYPE_DIRECTFB,
CAIRO_SURFACE_TYPE_SVG,
CAIRO_SURFACE_TYPE_OS2
} cairo_surface_type_t;
表面是我们要去绘制的目标。我们可以渲染文档,使用PDF或者PostScript表面。通过Xlib和Win32表面,直接去画一个平台。