Next: Transformations, Previous: Paths, Up: Top [Index]
Sources for drawing
<cairo-pattern>
is the paint with which cairo draws. The
primary use of patterns is as the source for all cairo drawing
operations, although they can also be used as masks, that is, as the
brush too.
A cairo pattern is created by using one of the many constructors, of the form cairo_pattern_create_type() or implicitly through cairo_set_source_type() functions.
<cairo-pattern-t>
) (offset <double>
) (red <double>
) (green <double>
) (blue <double>
)Adds an opaque color stop to a gradient pattern. The offset specifies the location along the gradient’s control vector. For example, a linear gradient’s control vector is from (x0,y0) to (x1,y1) while a radial gradient’s control vector is from any point on the start circle to the corresponding point on the end circle.
The color is specified in the same way as in
cairo-set-source-rgb
.
If two (or more) stops are specified with identical offset values, they will be sorted according to the order in which the stops are added, (stops added earlier will compare less than stops added later). This can be useful for reliably making sharp color transitions instead of the typical blend.
Note: If the pattern is not a gradient pattern, (eg. a linear or radial pattern), then the pattern will be put into an error status with a status of ‘CAIRO_STATUS_PATTERN_TYPE_MISMATCH’.
a <cairo-pattern-t>
an offset in the range [0.0 .. 1.0]
red component of color
green component of color
blue component of color
<cairo-pattern-t>
) (offset <double>
) (red <double>
) (green <double>
) (blue <double>
) (alpha <double>
)Adds a translucent color stop to a gradient pattern. The offset specifies the location along the gradient’s control vector. For example, a linear gradient’s control vector is from (x0,y0) to (x1,y1) while a radial gradient’s control vector is from any point on the start circle to the corresponding point on the end circle.
The color is specified in the same way as in
cairo-set-source-rgba
.
If two (or more) stops are specified with identical offset values, they will be sorted according to the order in which the stops are added, (stops added earlier will compare less than stops added later). This can be useful for reliably making sharp color transitions instead of the typical blend.
Note: If the pattern is not a gradient pattern, (eg. a linear or radial pattern), then the pattern will be put into an error status with a status of ‘CAIRO_STATUS_PATTERN_TYPE_MISMATCH’.
a <cairo-pattern-t>
an offset in the range [0.0 .. 1.0]
red component of color
green component of color
blue component of color
alpha component of color
<cairo-pattern-t>
) (index <int>
) ⇒ (ret <cairo-status-t>
) (offset <double>
) (red <double>
) (green <double>
) (blue <double>
) (alpha <double>
)Gets the color and offset information at the given index for a
gradient pattern. Values of index are 0 to 1 less than the number
returned by cairo-pattern-get-color-stop-count
.
a <cairo-pattern-t>
index of the stop to return data for
return value for the offset of the stop, or ‘#f
’
return value for red component of color, or ‘#f
’
return value for green component of color, or ‘#f
’
return value for blue component of color, or ‘#f
’
return value for alpha component of color, or ‘#f
’
‘CAIRO_STATUS_SUCCESS’, or ‘CAIRO_STATUS_INVALID_INDEX’ if index is not valid for the given pattern. If the pattern is not a gradient pattern, ‘CAIRO_STATUS_PATTERN_TYPE_MISMATCH’ is returned.
Since 1.4
<double>
) (green <double>
) (blue <double>
) ⇒ (ret <cairo-pattern-t >
)Creates a new <cairo-pattern-t>
corresponding to an opaque color.
The color components are floating point numbers in the range 0 to 1. If
the values passed in are outside that range, they will be clamped.
red component of the color
green component of the color
blue component of the color
the newly created <cairo-pattern-t>
if successful, or an error
pattern in case of no memory. The caller owns the returned object and
should call cairo-pattern-destroy
when finished with it. This
function will always return a valid pointer, but if an error occurred
the pattern status will be set to an error. To inspect the status of a
pattern use cairo-pattern-status
.
<double>
) (green <double>
) (blue <double>
) (alpha <double>
) ⇒ (ret <cairo-pattern-t >
)Creates a new <cairo-pattern-t>
corresponding to a translucent
color. The color components are floating point numbers in the range 0 to
1. If the values passed in are outside that range, they will be clamped.
red component of the color
green component of the color
blue component of the color
alpha component of the color
the newly created <cairo-pattern-t>
if successful, or an error
pattern in case of no memory. The caller owns the returned object and
should call cairo-pattern-destroy
when finished with it. This
function will always return a valid pointer, but if an error occurred
the pattern status will be set to an error. To inspect the status of a
pattern use cairo-pattern-status
.
<cairo-pattern-t>
) ⇒ (ret <cairo-status-t>
) (red <double>
) (green <double>
) (blue <double>
) (alpha <double>
)Gets the solid color for a solid color pattern.
a <cairo-pattern-t>
return value for red component of color, or ‘#f
’
return value for green component of color, or ‘#f
’
return value for blue component of color, or ‘#f
’
return value for alpha component of color, or ‘#f
’
‘CAIRO_STATUS_SUCCESS’, or ‘CAIRO_STATUS_PATTERN_TYPE_MISMATCH’ if the pattern is not a solid color pattern.
Since 1.4
<cairo-surface-t>
) ⇒ (ret <cairo-pattern-t >
)Create a new <cairo-pattern-t>
for the given surface.
the surface
the newly created <cairo-pattern-t>
if successful, or an error
pattern in case of no memory. The caller owns the returned object and
should call cairo-pattern-destroy
when finished with it. This
function will always return a valid pointer, but if an error occurred
the pattern status will be set to an error. To inspect the status of a
pattern use cairo-pattern-status
.
<cairo-pattern-t>
) ⇒ (ret <cairo-status-t>
) (surface <cairo-surface-t*>
)Gets the surface of a surface pattern. The reference returned in
surface is owned by the pattern; the caller should call
cairo-surface-reference
if the surface is to be retained.
a <cairo-pattern-t>
return value for surface of pattern, or ‘#f
’
‘CAIRO_STATUS_SUCCESS’, or ‘CAIRO_STATUS_PATTERN_TYPE_MISMATCH’ if the pattern is not a surface pattern.
Since 1.4
<double>
) (y0 <double>
) (x1 <double>
) (y1 <double>
) ⇒ (ret <cairo-pattern-t >
)Create a new linear gradient <cairo-pattern-t>
along the line
defined by (x0, y0) and (x1, y1). Before using the gradient pattern, a
number of color stops should be defined using
cairo-pattern-add-color-stop-rgb
or
cairo-pattern-add-color-stop-rgba
.
Note: The coordinates here are in pattern space. For a new pattern,
pattern space is identical to user space, but the relationship between
the spaces can be changed with cairo-pattern-set-matrix
.
x coordinate of the start point
y coordinate of the start point
x coordinate of the end point
y coordinate of the end point
the newly created <cairo-pattern-t>
if successful, or an error
pattern in case of no memory. The caller owns the returned object and
should call cairo-pattern-destroy
when finished with it. This
function will always return a valid pointer, but if an error occurred
the pattern status will be set to an error. To inspect the status of a
pattern use cairo-pattern-status
.
<cairo-pattern-t>
) ⇒ (ret <cairo-status-t>
) (x0 <double>
) (y0 <double>
) (x1 <double>
) (y1 <double>
)Gets the gradient endpoints for a linear gradient.
a <cairo-pattern-t>
return value for the x coordinate of the first point, or
‘#f
’
return value for the y coordinate of the first point, or
‘#f
’
return value for the x coordinate of the second point, or
‘#f
’
return value for the y coordinate of the second point, or
‘#f
’
‘CAIRO_STATUS_SUCCESS’, or ‘CAIRO_STATUS_PATTERN_TYPE_MISMATCH’ if pattern is not a linear gradient pattern.
Since 1.4
<double>
) (cy0 <double>
) (radius0 <double>
) (cx1 <double>
) (cy1 <double>
) (radius1 <double>
) ⇒ (ret <cairo-pattern-t >
)Creates a new radial gradient <cairo-pattern-t>
between the two
circles defined by (cx0, cy0, radius0) and (cx1, cy1, radius1). Before
using the gradient pattern, a number of color stops should be defined
using cairo-pattern-add-color-stop-rgb
or
cairo-pattern-add-color-stop-rgba
.
Note: The coordinates here are in pattern space. For a new pattern,
pattern space is identical to user space, but the relationship between
the spaces can be changed with cairo-pattern-set-matrix
.
x coordinate for the center of the start circle
y coordinate for the center of the start circle
radius of the start circle
x coordinate for the center of the end circle
y coordinate for the center of the end circle
radius of the end circle
the newly created <cairo-pattern-t>
if successful, or an error
pattern in case of no memory. The caller owns the returned object and
should call cairo-pattern-destroy
when finished with it. This
function will always return a valid pointer, but if an error occurred
the pattern status will be set to an error. To inspect the status of a
pattern use cairo-pattern-status
.
<cairo-pattern-t>
) ⇒ (ret <cairo-status-t>
) (x0 <double>
) (y0 <double>
) (r0 <double>
) (x1 <double>
) (y1 <double>
) (r1 <double>
)Gets the gradient endpoint circles for a radial gradient, each specified as a center coordinate and a radius.
a <cairo-pattern-t>
return value for the x coordinate of the center of the first circle, or
‘#f
’
return value for the y coordinate of the center of the first circle, or
‘#f
’
return value for the radius of the first circle, or ‘#f
’
return value for the x coordinate of the center of the second circle, or
‘#f
’
return value for the y coordinate of the center of the second circle, or
‘#f
’
return value for the radius of the second circle, or ‘#f
’
‘CAIRO_STATUS_SUCCESS’, or ‘CAIRO_STATUS_PATTERN_TYPE_MISMATCH’ if pattern is not a radial gradient pattern.
Since 1.4
<cairo-pattern-t>
) (extend <cairo-extend-t>
)Sets the mode to be used for drawing outside the area of a pattern. See
<cairo-extend-t>
for details on the semantics of each extend
strategy.
The default extend mode is ‘CAIRO_EXTEND_NONE’ for surface patterns and ‘CAIRO_EXTEND_PAD’ for gradient patterns.
a <cairo-pattern-t>
a <cairo-extend-t>
describing how the area outside of the pattern
will be drawn
<cairo-pattern-t>
) ⇒ (ret <cairo-extend-t>
)Gets the current extend mode for a pattern. See <cairo-extend-t>
for details on the semantics of each extend strategy.
a <cairo-pattern-t>
the current extend strategy used for drawing the pattern.
<cairo-pattern-t>
) (filter <cairo-filter-t>
)Sets the filter to be used for resizing when using this pattern. See
<cairo-filter-t>
for details on each filter.
* Note that you might want to control filtering even when you do not
have an explicit <cairo-pattern-t>
object, (for example when
using cairo-set-source-surface
). In these cases, it is convenient
to use cairo-get-source
to get access to the pattern that cairo
creates implicitly. For example:
cairo_set_source_surface (cr, image, x, y); cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_NEAREST);
a <cairo-pattern-t>
a <cairo-filter-t>
describing the filter to use for resizing the
pattern
<cairo-pattern-t>
) ⇒ (ret <cairo-filter-t>
)Gets the current filter for a pattern. See <cairo-filter-t>
for
details on each filter.
a <cairo-pattern-t>
the current filter used for resizing the pattern.
<cairo-pattern-t>
) (matrix <cairo-matrix-t>
)Sets the pattern’s transformation matrix to matrix. This matrix is a transformation from user space to pattern space.
When a pattern is first created it always has the identity matrix for its transformation matrix, which means that pattern space is initially identical to user space.
Important: Please note that the direction of this transformation matrix is from user space to pattern space. This means that if you imagine the flow from a pattern to user space (and on to device space), then coordinates in that flow will be transformed by the inverse of the pattern matrix.
For example, if you want to make a pattern appear twice as large as it does by default the correct code to use is:
cairo_matrix_init_scale (&matrix, 0.5, 0.5); cairo_pattern_set_matrix (pattern, &matrix);
Meanwhile, using values of 2.0 rather than 0.5 in the code above would cause the pattern to appear at half of its default size.
Also, please note the discussion of the user-space locking semantics of
cairo-set-source
.
a <cairo-pattern-t>
a <cairo-matrix-t>
<cairo-pattern-t>
) (matrix <cairo-matrix-t>
)Stores the pattern’s transformation matrix into matrix.
a <cairo-pattern-t>
return value for the matrix
<cairo-pattern-t>
) ⇒ (ret <cairo-pattern-type-t>
)This function returns the type a pattern. See
<cairo-pattern-type-t>
for available types.
a <cairo-pattern-t>
The type of pattern.
Since 1.2
Next: Transformations, Previous: Paths, Up: Top [Index]