Functions

cairo_create ()

Creates a new cairo_t with all graphics state parameters set to
default values and with target
as a target surface. The target
surface should be constructed with a backend-specific function such
as cairo_image_surface_create() (or any other
cairo_backend_surface_create()
variant).

This function references target
, so you can immediately
call cairo_surface_destroy() on it if you don't need to
maintain a separate reference to it.

Parameters

target

target surface for the context

Returns

a newly allocated cairo_t with a reference
count of 1. The initial reference count should be released
with cairo_destroy() when you are done using the cairo_t.
This function never returns NULL. If memory cannot be
allocated, a special cairo_t object will be returned on
which cairo_status() returns CAIRO_STATUS_NO_MEMORY. If
you attempt to target a surface which does not support
writing (such as cairo_mime_surface_t) then a
CAIRO_STATUS_WRITE_ERROR will be raised. You can use this
object normally, but no drawing will be done.

It isn't necessary to clear all saved states before
a cairo_t is freed. If the reference count of a cairo_t
drops to zero in response to a call to cairo_destroy(),
any saved states will be freed along with the cairo_t.

Returns

cairo_push_group ()

Temporarily redirects drawing to an intermediate surface known as a
group. The redirection lasts until the group is completed by a call
to cairo_pop_group() or cairo_pop_group_to_source(). These calls
provide the result of any drawing to the group as a pattern,
(either as an explicit object, or set as the source pattern).

This group functionality can be convenient for performing
intermediate compositing. One common use of a group is to render
objects as opaque within the group, (so that they occlude each
other), and then blend the result with translucence onto the
destination.

Parameters

cairo_push_group_with_content ()

Temporarily redirects drawing to an intermediate surface known as a
group. The redirection lasts until the group is completed by a call
to cairo_pop_group() or cairo_pop_group_to_source(). These calls
provide the result of any drawing to the group as a pattern,
(either as an explicit object, or set as the source pattern).

The group will have a content type of content
. The ability to
control this content type is the only distinction between this
function and cairo_push_group() which you should see for a more
detailed description of group rendering.

Parameters

cr

a cairo context

Returns

a newly created (surface) pattern containing the
results of all drawing operations performed to the group. The
caller owns the returned object and should call
cairo_pattern_destroy() when finished with it.

cairo_set_source ()

Sets the source pattern within cr
to source
. This pattern
will then be used for any subsequent drawing operation until a new
source pattern is set.

Note: The pattern's transformation matrix will be locked to the
user space in effect at the time of cairo_set_source(). This means
that further modifications of the current transformation matrix
will not affect the source pattern. See cairo_pattern_set_matrix().

The default source pattern is a solid pattern that is opaque black,
(that is, it is equivalent to cairo_set_source_rgb(cr, 0.0, 0.0,
0.0)).

Parameters

cr

a cairo context

source

a cairo_pattern_t to be used as the source for
subsequent drawing operations.

cairo_set_source_surface ()

This is a convenience function for creating a pattern from surface
and setting it as the source in cr
with cairo_set_source().

The x
and y
parameters give the user-space coordinate at which
the surface origin should appear. (The surface origin is its
upper-left corner before any transformation has been applied.) The
x
and y
parameters are negated and then set as translation values
in the pattern matrix.

cairo_set_antialias ()

Set the antialiasing mode of the rasterizer used for drawing shapes.
This value is a hint, and a particular backend may or may not support
a particular value. At the current time, no backend supports
CAIRO_ANTIALIAS_SUBPIXEL when drawing shapes.

Parameters

Returns

cairo_set_dash ()

Sets the dash pattern to be used by cairo_stroke(). A dash pattern
is specified by dashes
, an array of positive values. Each value
provides the length of alternate "on" and "off" portions of the
stroke. The offset
specifies an offset into the pattern at which
the stroke begins.

Each "on" segment will have caps applied as if the segment were a
separate sub-path. In particular, it is valid to use an "on" length
of 0.0 with CAIRO_LINE_CAP_ROUND or CAIRO_LINE_CAP_SQUARE in order
to distributed dots or squares along a path.

Note: The length values are in user-space units as evaluated at the
time of stroking. This is not necessarily the same as the user
space at the time of cairo_set_dash().

If num_dashes
is 0 dashing is disabled.

If num_dashes
is 1 a symmetric pattern is assumed with alternating
on and off portions of the size specified by the single value in
dashes
.

If any value in dashes
is negative, or if all values are 0, then
cr
will be put into an error state with a status of
CAIRO_STATUS_INVALID_DASH.

cairo_set_fill_rule ()

Set the current fill rule within the cairo context. The fill rule
is used to determine which regions are inside or outside a complex
(potentially self-intersecting) path. The current fill rule affects
both cairo_fill() and cairo_clip(). See cairo_fill_rule_t for details
on the semantics of each available fill rule.

Parameters

Returns

cairo_set_line_cap ()

Sets the current line cap style within the cairo context. See
cairo_line_cap_t for details about how the available line cap
styles are drawn.

As with the other stroke parameters, the current line cap style is
examined by cairo_stroke(), cairo_stroke_extents(), and
cairo_stroke_to_path(), but does not have any effect during path
construction.

Parameters

Returns

cairo_set_line_join ()

Sets the current line join style within the cairo context. See
cairo_line_join_t for details about how the available line join
styles are drawn.

As with the other stroke parameters, the current line join style is
examined by cairo_stroke(), cairo_stroke_extents(), and
cairo_stroke_to_path(), but does not have any effect during path
construction.

Parameters

Returns

cairo_set_line_width ()

Sets the current line width within the cairo context. The line
width value specifies the diameter of a pen that is circular in
user space, (though device-space pen may be an ellipse in general
due to scaling/shear/rotation of the CTM).

Note: When the description above refers to user space and CTM it
refers to the user space and CTM in effect at the time of the
stroking operation, not the user space and CTM in effect at the
time of the call to cairo_set_line_width(). The simplest usage
makes both of these spaces identical. That is, if there is no
change to the CTM between a call to cairo_set_line_width() and the
stroking operation, then one can just pass user-space values to
cairo_set_line_width() and ignore this note.

As with the other stroke parameters, the current line width is
examined by cairo_stroke(), cairo_stroke_extents(), and
cairo_stroke_to_path(), but does not have any effect during path
construction.

Parameters

Returns

cairo_set_miter_limit ()

If the current line join style is set to CAIRO_LINE_JOIN_MITER
(see cairo_set_line_join()), the miter limit is used to determine
whether the lines should be joined with a bevel instead of a miter.
Cairo divides the length of the miter by the line width.
If the result is greater than the miter limit, the style is
converted to a bevel.

As with the other stroke parameters, the current line miter limit is
examined by cairo_stroke(), cairo_stroke_extents(), and
cairo_stroke_to_path(), but does not have any effect during path
construction.

The default miter limit value is 10.0, which will convert joins
with interior angles less than 11 degrees to bevels instead of
miters. For reference, a miter limit of 2.0 makes the miter cutoff
at 60 degrees, and a miter limit of 1.414 makes the cutoff at 90
degrees.

A miter limit for a desired angle can be computed as: miter limit =
1/sin(angle/2)

Parameters

Returns

cairo_set_tolerance ()

Sets the tolerance used when converting paths into trapezoids.
Curved segments of the path will be subdivided until the maximum
deviation between the original path and the polygonal approximation
is less than tolerance
. The default value is 0.1. A larger
value will give better performance, a smaller value, better
appearance. (Reducing the value from the default value of 0.1
is unlikely to improve appearance significantly.) The accuracy of paths
within Cairo is limited by the precision of its internal arithmetic, and
the prescribed tolerance
is restricted to the smallest
representable internal value.

Returns

cairo_reset_clip ()

Reset the current clip region to its original, unrestricted
state. That is, set the clip region to an infinitely large shape
containing the target surface. Equivalently, if infinity is too
hard to grasp, one can imagine the clip region being reset to the
exact bounds of the target surface.

Parameters

cairo_copy_clip_rectangle_list ()

Gets the current clip region as a list of rectangles in user coordinates.
Never returns NULL.

The status in the list may be CAIRO_STATUS_CLIP_NOT_REPRESENTABLE to
indicate that the clip region cannot be represented as a list of
user-space rectangles. The status may have other values to indicate
other errors.

Parameters

cr

a cairo context

Returns

cairo_fill ()

A drawing operator that fills the current path according to the
current fill rule, (each sub-path is implicitly closed before being
filled). After cairo_fill(), the current path will be cleared from
the cairo context. See cairo_set_fill_rule() and
cairo_fill_preserve().

Parameters

cr

a cairo context

Since 1.0

cairo_fill_preserve ()

A drawing operator that fills the current path according to the
current fill rule, (each sub-path is implicitly closed before being
filled). Unlike cairo_fill(), cairo_fill_preserve() preserves the
path within the cairo context.

Parameters

cairo_fill_extents ()

Computes a bounding box in user coordinates covering the area that
would be affected, (the "inked" area), by a cairo_fill() operation
given the current path and fill parameters. If the current path is
empty, returns an empty rectangle ((0,0), (0,0)). Surface
dimensions and clipping are not taken into account.

Contrast with cairo_path_extents(), which is similar, but returns
non-zero extents for some paths with no inked area, (such as a
simple line segment).

Note that cairo_fill_extents() must necessarily do more work to
compute the precise inked areas in light of the fill rule, so
cairo_path_extents() may be more desirable for sake of performance
if the non-inked path extents are desired.

cairo_in_fill ()

Tests whether the given point is inside the area that would be
affected by a cairo_fill() operation given the current path and
filling parameters. Surface dimensions and clipping are not taken
into account.

Parameters

cairo_paint_with_alpha ()

A drawing operator that paints the current source everywhere within
the current clip region using a mask of constant alpha value
alpha
. The effect is similar to cairo_paint(), but the drawing
is faded out using the alpha value.

Parameters

cairo_stroke_preserve ()

A drawing operator that strokes the current path according to the
current line width, line join, line cap, and dash settings. Unlike
cairo_stroke(), cairo_stroke_preserve() preserves the path within the
cairo context.

Parameters

cairo_stroke_extents ()

Computes a bounding box in user coordinates covering the area that
would be affected, (the "inked" area), by a cairo_stroke()
operation given the current path and stroke parameters.
If the current path is empty, returns an empty rectangle ((0,0), (0,0)).
Surface dimensions and clipping are not taken into account.

Note that if the line width is set to exactly zero, then
cairo_stroke_extents() will return an empty rectangle. Contrast with
cairo_path_extents() which can be used to compute the non-empty
bounds as the line width approaches zero.

Note that cairo_stroke_extents() must necessarily do more work to
compute the precise inked areas in light of the stroke parameters,
so cairo_path_extents() may be more desirable for sake of
performance if non-inked path extents are desired.

cairo_in_stroke ()

Tests whether the given point is inside the area that would be
affected by a cairo_stroke() operation given the current path and
stroking parameters. Surface dimensions and clipping are not taken
into account.

Returns

cairo_copy_page ()

Emits the current page for backends that support multiple pages, but
doesn't clear it, so, the contents of the current page will be retained
for the next page too. Use cairo_show_page() if you want to get an
empty page after the emission.

enum cairo_antialias_t

Specifies the type of antialiasing to do when rendering text or shapes.

As it is not necessarily clear from the above what advantages a particular
antialias method provides, since 1.12, there is also a set of hints:
CAIRO_ANTIALIAS_FAST
: Allow the backend to degrade raster quality for speed
CAIRO_ANTIALIAS_GOOD
: A balance between speed and quality
CAIRO_ANTIALIAS_BEST
: A high-fidelity, but potentially slow, raster mode

These make no guarantee on how the backend will perform its rasterisation
(if it even rasterises!), nor that they have any differing effect other
than to enable some form of antialiasing. In the case of glyph rendering,
CAIRO_ANTIALIAS_FAST
and CAIRO_ANTIALIAS_GOOD
will be mapped to
CAIRO_ANTIALIAS_GRAY
, with CAIRO_ANTALIAS_BEST
being equivalent to
CAIRO_ANTIALIAS_SUBPIXEL
.

The interpretation of CAIRO_ANTIALIAS_DEFAULT
is left entirely up to
the backend, typically this will be similar to CAIRO_ANTIALIAS_GOOD
.

Members

CAIRO_ANTIALIAS_DEFAULT

Use the default antialiasing for
the subsystem and target device, since 1.0

CAIRO_ANTIALIAS_NONE

Use a bilevel alpha mask, since 1.0

CAIRO_ANTIALIAS_GRAY

Perform single-color antialiasing (using
shades of gray for black text on a white background, for example), since 1.0

CAIRO_ANTIALIAS_SUBPIXEL

Perform antialiasing by taking
advantage of the order of subpixel elements on devices
such as LCD panels, since 1.0

CAIRO_ANTIALIAS_FAST

Hint that the backend should perform some
antialiasing but prefer speed over quality, since 1.12

CAIRO_ANTIALIAS_GOOD

The backend should balance quality against
performance, since 1.12

CAIRO_ANTIALIAS_BEST

Hint that the backend should render at the highest
quality, sacrificing speed if necessary, since 1.12

Since 1.0

enum cairo_fill_rule_t

cairo_fill_rule_t is 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.)

Members

CAIRO_FILL_RULE_WINDING

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. (Since 1.0)

CAIRO_FILL_RULE_EVEN_ODD

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. (Since 1.0)

enum cairo_operator_t

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

Takes the difference of the source and
destination color. (Since 1.10)

CAIRO_OPERATOR_EXCLUSION

Produces an effect similar to difference, but
with lower contrast. (Since 1.10)

CAIRO_OPERATOR_HSL_HUE

Creates a color with the hue of the source
and the saturation and luminosity of the target. (Since 1.10)

CAIRO_OPERATOR_HSL_SATURATION

Creates a color with the saturation
of the source and the hue and luminosity of the target. Painting with
this mode onto a gray area produces no change. (Since 1.10)

CAIRO_OPERATOR_HSL_COLOR

Creates a color with the hue and saturation
of the source and the luminosity of the target. This preserves the gray
levels of the target and is useful for coloring monochrome images or
tinting color images. (Since 1.10)

CAIRO_OPERATOR_HSL_LUMINOSITY

Creates a color with the luminosity of
the source and the hue and saturation of the target. This produces an
inverse effect to CAIRO_OPERATOR_HSL_COLOR
. (Since 1.10)