The cairo drawing context
Methods and Functions
cairoSetSourceRgb(cr, red, green, blue)
cairoSetSourceRgba(cr, red, green, blue, alpha)
cairoSetSourceSurface(cr, surface, x, y)
cairoSetDash(cr, dashes, offset)
cairoInFill(cr, x, y)
cairoMaskSurface(cr, surface, surface.x, surface.y)
cairoInStroke(cr, x, y)
cairoSetUserData(cr, key, user.data)
Cairo is the main object used when drawing with cairo. To
draw with cairo, you create a
Cairo, set the target surface,
and drawing options for the
Cairo, create shapes with
cairoLineTo, and then
draw shapes with
Cairo's can be pushed to a stack via
They may then safely be changed, without loosing the current state.
cairoRestore to restore to the saved state.
Cairocontains the current state of the rendering device, including coordinates of yet to be drawn shapes. Cairo contexts, as
Cairoobjects are named, are central to cairo and all drawing with cairo is always done to a
Cairoobject. Memory management of
Cairois done with
A data structure for holding a rectangle.
CairoRectangleis a transparent-type.
- [numeric] X coordinate of the left side of the rectangle
- [numeric] Y coordinate of the the top side of the rectangle
- [numeric] width of the rectangle
- [numeric] height of the rectangle
A data structure for holding a dynamically allocated
array of rectangles.
CairoRectangleListis a transparent-type.
cairo is the equivalent of
Enums and Flags
Specifies the type of antialiasing to do when rendering text or shapes.
- Use the default antialiasing for the subsystem and target device
- Use a bilevel alpha mask
- Perform single-color antialiasing (using shades of gray for black text on a white background, for example).
- Perform antialiasing by taking advantage of the order of subpixel elements on devices such as LCD panels
CairoFillRuleis used to select how paths are filled. For both fill rules, whether or not a point is included in the fill is determined by taking a ray from that point to infinity and looking at intersections with the path. The ray can be in any direction, as long as it doesn't pass through the end point of a segment or have a tricky intersection such as intersecting tangent to the path. (Note that filling is not actually implemented in this way. This is just a description of the rule that is applied.) The default fill rule is
CAIRO_FILL_RULE_WINDING. New entries may be added in future versions.
- If the path crosses the ray from left-to-right, counts +1. If the path crosses the ray from right to left, counts -1. (Left and right are determined from the perspective of looking along the ray from the starting point.) If the total count is non-zero, the point will be filled.
- Counts the total number of intersections, without regard to the orientation of the contour. If the total number of intersections is odd, the point will be filled.
Specifies how to render the endpoints of the path when stroking. The default line cap style is
- start(stop) the line exactly at the start(end) point
- use a round ending, the center of the circle is the end point
- use squared ending, the center of the square is the end point
Specifies how to render the junction of two lines when stroking. The default line join style is
- use a sharp (angled) corner, see
- use a rounded join, the center of the circle is the joint point
- use a cut-off join, the join is cut off at half the line width from the joint point
CairoOperatoris used to set the compositing operator for all cairo drawing operations. The default operator is
CAIRO_OPERATOR_OVER. The operators marked as unbounded modify their destination even outside of the mask layer (that is, their effect is not bound by the mask layer). However, their effect can still be limited by way of clipping. To keep things simple, the operator descriptions here document the behavior for when both source and destination are either fully transparent or fully opaque. The actual implementation works for translucent layers too. For a more detailed explanation of the effects of each operator, including the mathematical definitions, see http://cairographics.org/operators/ (http://cairographics.org/operators/).
- clear destination layer (bounded)
- replace destination layer (bounded)
- draw source layer on top of destination layer (bounded)
- draw source where there was destination content (unbounded)
- draw source where there was no destination content (unbounded)
- draw source on top of destination content and only there
- ignore the source
- draw destination on top of source
- leave destination only where there was source content (unbounded)
- leave destination only where there was no source content
- leave destination on top of source content and only there (unbounded)
- source and destination are shown where there is only one of them
- source and destination layers are accumulated
- like over, but assuming source and dest are disjoint geometries