class Cairo::Context
- Cairo::Context
- Reference
- Object
Overview
The cairo drawing context.
Context
is the main object used when drawing with cairo. To draw with cairo, you create a Context
,
set the target surface, and drawing options for the Context
, create shapes with functions like Context#move_to
and Context#line_to
, and then draw shapes with Context#stroke
or Context#fill
.
Context
's can be pushed to a stack via Context#save
. They may then safely be changed, without losing the current state.
Use Context#restore
to restore to the saved state.
A Context
contains the current state of the rendering device, including coordinates of yet to be drawn shapes.
Cairo contexts, as Context
objects are named, are central to cairo and all drawing with cairo is always done to a Context
object.
Memory management of Context
is done with Context#reference
and Context#finalize
.
Defined in:
cairo/context.crConstructors
- .new(cairo : LibCairo::PCairoT)
-
.new(target : Surface)
Creates a new
Context
with all graphics state parameters set to default values and with target as a target surface.
Class Method Summary
Instance Method Summary
-
#antialias : Antialias
Gets the current shape antialiasing mode, as set by
Context#antialias=
. -
#antialias=(antialias : Antialias)
Set the antialiasing mode of the rasterizer used for drawing shapes.
-
#append(path : Path)
Append the path onto the current path.
-
#arc(xc : Int32 | Float64, yc : Int32 | Float64, radius : Int32 | Float64, angle1 : Float64, angle2 : Float64)
Adds a circular arc of the given radius to the current path.
- #arc(c : Point, radius : Float64, angle1 : Float64, angle2 : Float64)
-
#arc_negative(xc : Float64, yc : Float64, radius : Float64, angle1 : Float64, angle2 : Float64)
Adds a circular arc of the given radius to the current path.
- #arc_negative(c : Point, radius : Float64, angle1 : Float64, angle2 : Float64)
-
#clip
Establishes a new clip region by intersecting the current clip region with the current path as it would be filled by
Context#fill
and according to the current fill rule (seeContext#fill_rule=
). -
#clip_extents : Extents
Computes a bounding box in user coordinates covering the area inside the current clip.
-
#clip_preserve
Establishes a new clip region by intersecting the current clip region with the current path as it would be filled by
Context#fill
and according to the current fill rule (seeContext#fill_rule=
). -
#close_path
Adds a line segment to the path from the current point to the beginning of the current sub-path, (the most recent point passed to
Context#move_to
), and closes this sub-path. -
#copy_clip_rectangle_list : RectangleList?
Gets the current clip region as a list of rectangles in user coordinates.
-
#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.
-
#copy_path : Path
Creates a copy of the current path and returns it to the user as a
Path
. -
#copy_path_flat : Path
Gets a flattened copy of the current path and returns it to the user as a
Path
. -
#current_point : Point
Gets the current point of the current path, which is conceptually the final point reached by the path so far.
-
#curve_to(x1 : Float64, y1 : Float64, x2 : Float64, y2 : Float64, x3 : Float64, y3 : Float64)
Adds a cubic Bézier spline to the path from the current point to position (x3, y3) in user-space coordinates, using (x1, y1) and (x2, y2) as the control points.
- #curve_to(p1 : Point, p2 : Point, p3 : Point)
-
#dash : NamedTuple(dashes: Float64, offset: Float64)
Gets the current dash array.
-
#dash_count : Int32
This function returns the length of the dash array in
Context
(0 if dashing is not currently in effect). -
#device_to_user(p : Point) : Point
Transform a coordinate from device space to user space by multiplying the given point by the inverse of the current transformation matrix (CTM).
-
#device_to_user_distance(d : Point) : Point
Transform a distance vector from device space to user space.
-
#fill
A drawing operator that fills the current path according to the current fill rule, (each sub-path is implicitly closed before being filled).
-
#fill_extents(x1 : Float64, y1 : Float64, x2 : Float64, y2 : Float64)
Computes a bounding box in user coordinates covering the area that would be affected, (the "inked" area), by a
Context#fill
operation given the current path and fill parameters. -
#fill_extents(p1 : Point, p2 : Point)
Computes a bounding box in user coordinates covering the area that would be affected, (the "inked" area), by a
Context#fill
operation given the current path and fill parameters. -
#fill_extents(extents : Extents)
Computes a bounding box in user coordinates covering the area that would be affected, (the "inked" area), by a
Context#fill
operation given the current path and fill parameters. -
#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).
-
#fill_rule : FillRule
Gets the current fill rule, as set by
Contex#fill_rule=
. -
#fill_rule=(fill_rule : FillRule)
Set the current fill rule within the cairo context.
-
#finalize
Decreases the reference count by one.
-
#font_extents : FontExtents
Gets the font extents for the currently selected font.
-
#font_face : FontFace
Gets the current font face for a
Context
. - #font_face=(font_face : FontFace?)
-
#font_matrix : Matrix
Returns the current font matrix.
-
#font_matrix=(matrix : Matrix)
Sets the current font matrix to matrix.
-
#font_options : FontOptions
Retrieves font rendering options set via
Context#font_options=
. -
#font_options=(options : FontOptions)
Sets a set of custom font rendering options for the
Context
. -
#font_size=(size : Float64)
Sets the current font matrix to a scale by a factor of size, replacing any font matrix previously set with
Context#set_font_size=
orContext#font_matrix=
. -
#glyph_extents(glyphs : GlyphArray) : TextExtents
Gets the extents for an array of glyphs.
-
#glyph_path(glyphs : GlyphArray)
Adds closed paths for the glyphs to the current path.
-
#group_target : Surface
Gets the current destination surface for the context.
-
#has_current_point? : Bool
Returns whether a current point is defined on the current path.
-
#identity_matrix
Resets the current transformation matrix (CTM) by setting it equal to the identity matrix.
- #in_clip(x : Float64, y : Float64) : Bool
-
#in_clip(p : Point) : Bool
Tests whether the given point is inside the area that would be visible through the current clip, i.e.
-
#in_fill(x : Float64, y : Float64) : Bool
Tests whether the given point is inside the area that would be affected by a
Context#fill
operation given the current path and filling parameters. -
#in_fill(p : Point) : Bool
Tests whether the given point is inside the area that would be affected by a
Context#fill
operation given the current path and filling parameters. -
#in_stroke(x : Float64, y : Float64) : Bool
Tests whether the given point is inside the area that would be affected by a
Context#stroke
operation given the current path and stroking parameters. - #in_stroke(p : Point) : Bool
- #line(x1 : Float64, y1 : Float64, x2 : Float64, y2 : Float64)
- #line(p1 : Point, p2 : Point)
-
#line_cap : LineCap
Gets the current line cap style, as set by
Context#line_cap=
. -
#line_cap=(line_cap : LineCap)
Sets the current line cap style within the cairo context.
-
#line_join : LineJoin
Gets the current line join style, as set by
Context#line_join=
. -
#line_join=(line_join : LineJoin)
Sets the current line join style within the cairo context.
-
#line_to(x : Float64, y : Float64)
Adds a line to the path from the current point to position (x, y) in user-space coordinates.
- #line_to(p : Point)
-
#line_width : Float64
This function returns the current line width value exactly as set by
Context#line_width=
. -
#line_width=(width : Float64)
Sets the current line width within the cairo context.
-
#mask(pattern : Pattern)
A drawing operator that paints the current source using the alpha channel of pattern as a mask.
-
#mask_surface(surface : Surface, surface_x : Float64, surface_y : Float64)
A drawing operator that paints the current source using the alpha channel of surface as a mask.
-
#matrix : Matrix
Stores the current transformation matrix (CTM) into matrix .
-
#matrix=(matrix : Matrix)
Modifies the current transformation matrix (CTM) by setting it equal to matrix.
-
#miter_limit : Float64
Gets the current miter limit, as set by
Context#miter_limit=
. -
#miter_limit=(limit : Float64)
Sets the current miter limit within the cairo context.
-
#move_to(x : Float64, y : Float64)
Begin a new sub-path.
- #move_to(p : Point)
-
#new_path
Clears the current path.
-
#new_sub_path
Begin a new sub-path.
-
#operator : Operator
Gets the current compositing operator for a cairo context.
-
#operator=(op : Operator)
Sets the compositing operator to be used for all drawing operations.
-
#paint
A drawing operator that paints the current source everywhere within the current clip region.
-
#paint_with_alpha(alpha : Float64)
A drawing operator that paints the current source everywhere within the current clip region using a mask of constant alpha value alpha.
-
#path_extents : Extents
Computes a bounding box in user-space coordinates covering the points on the current path.
-
#pop_group : Pattern
Terminates the redirection begun by a call to
Context#push_group
orContext#push_group_with_content
and returns a new pattern containing the results of all drawing operations performed to the group. -
#pop_group_to_source : Context
Terminates the redirection begun by a call to
Context#push_group
or Context#push_group_with_content` and installs the resulting pattern as the source pattern in the given cairo context. -
#push_group
Temporarily redirects drawing to an intermediate surface known as a group.
-
#push_group_with_content(content : Content)
Temporarily redirects drawing to an intermediate surface known as a group.
-
#rectangle(x : Float64, y : Float64, width : Float64, height : Float64)
Adds a closed sub-path rectangle of the given size to the current path at position (x, y) in user-space coordinates.
-
#reference : Context
Increases the reference count on cr by one.
-
#reference_count : UInt32
Returns the current reference count of context.
-
#rel_curve_to(dx1 : Float64, dy1 : Float64, dx2 : Float64, dy2 : Float64, dx3 : Float64, dy3 : Float64)
Relative-coordinate version of
Context#curve_to
. - #rel_curve_to(d1 : Point, d2 : Point, d3 : Point)
-
#rel_line_to(dx : Float64, dy : Float64)
Relative-coordinate version of
Context#line_to
. - #rel_line_to(d : Point)
-
#rel_move_to(dx : Float64, dy : Float64)
Begin a new sub-path.
- #rel_move_to(d : Point)
-
#reset_clip
Reset the current clip region to its original, unrestricted state.
-
#restore
Restores
Context
to the state saved by a preceding call toContext#save
and removes that state from the stack of saved states. -
#rotate(angle : Float64)
Modifies the current transformation matrix (CTM) by rotating the user-space axes by angle radians.
-
#save
Makes a copy of the current state and saves it on an internal stack of saved states.
-
#scale(sx : Float64, sy : Float64)
Modifies the current transformation matrix (CTM) by scaling the X and Y user-space axes by sx and sy respectively.
-
#scaled_font : ScaledFont
Gets the current scaled font for a
Context
. -
#scaled_font=(scaled_font : ScaledFont)
Replaces the current font face, font matrix, and font options in the
Context
with those of theScaledFont
. -
#select_font_face(family : String, slant : FontSlant, weight : FontWeight)
NOTE The
Context#select_font_face
function call is part of what the cairo designers call the "toy" text API. -
#set_dash(dashes : Array(Float64), offset : Float64)
Sets the dash pattern to be used by
Context#stroke
. -
#set_source_rgb(red : Float64, green : Float64, blue : Float64)
Sets the source pattern within
Context
to an opaque color. -
#set_source_rgba(red : Float64, green : Float64, blue : Float64, alpha : Float64)
Sets the source pattern within cr to a translucent color.
-
#set_source_surface(surface : Surface, x : Float64, y : Float64)
This is a convenience function for creating a pattern from surface and setting it as the source in
Context
withContext#source=
. -
#set_user_data(key : UserDataKey, user_data : Pointer(Void), destroy : LibCairo::DestroyFuncT) : Status
Attach user data to context.
-
#show_glyphs(glyphs : GlyphArray)
A drawing operator that generates the shape from an array of glyphs, rendered according to the current font face, font size (font matrix), and font options.
-
#show_page
Emits and clears the current page for backends that support multiple pages.
-
#show_text(text : String)
A drawing operator that generates the shape from a string of UTF-8 characters, rendered according to the current font_face, font_size (font_matrix), and font_options.
-
#show_text_glyphs(text : String, glyphs : GlyphArray, clusters : TextClusterArray, cluster_flags : TextClusterFlags)
This operation has rendering effects similar to
Context#show_glyphs
but, if the target surface supports it, uses the provided text and cluster mapping to embed the text for the glyphs shown in the output. -
#source : Pattern
Gets the current source pattern
-
#source=(source : Pattern)
Sets the source pattern within
Context
to source. -
#status : Status
Checks whether an error has previously occurred for this context.
-
#stroke
A drawing operator that strokes the current path according to the current line width, line join, line cap, and dash settings.
-
#stroke_extents : Extents
Computes a bounding box in user coordinates covering the area that would be affected, (the "inked" area), by a
Context#stroke
operation given the current path and stroke parameters. -
#stroke_preserve
A drawing operator that strokes the current path according to the current line width, line join, line cap, and dash settings.
-
#tag_begin(tag_name : String, attributes : String)
Marks the beginning of the tag_name structure.
-
#tag_end(tag_name : String)
Marks the end of the tag_name structure.
-
#target : Surface
Gets the target surface for the cairo context as passed to
Context#initialized
. -
#text_extents(text : String) : TextExtents
Gets the extents for a string of text.
-
#text_path(text : String)
Adds closed paths for text to the current path.
- #to_unsafe : LibCairo::PCairoT
-
#tolerance : Float64
Gets the current tolerance value, as set by
Context#tolerance=
. -
#tolerance=(tolerance : Float64)
Sets the tolerance used when converting paths into trapezoids.
-
#transform(matrix : Matrix)
Modifies the current transformation matrix (CTM) by applying matrix as an additional transformation.
-
#translate(tx : Float64, ty : Float64)
Modifies the current transformation matrix (CTM) by translating the user-space origin by (tx, ty).
-
#user_data(key : UserDataKey) : Pointer(Void)
Return user data previously attached to cr using the specified key.
-
#user_to_device(p : Point) : Point
Transform a coordinate from user space to device space by multiplying the given point by the current transformation matrix (CTM).
-
#user_to_device_distance(d : Point) : Point
Transform a distance vector from user space to device space.
Constructor Detail
Creates a new Context
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 Surface#initialite
.
This function references target, so you can immediately call Context#finalize
on it
if you don't need to maintain a separate reference to it.
###Paremeters
- target target surface for the context
###Returns
A newly allocated Context
with a reference count of 1. The initial reference count should be released with Content::finalize
when you are done using the Context
. This function never returns Nil
.
If memory cannot be allocated, a special Context
object will be returned on which Context#status
returns
Status::NoMemory
. If you attempt to target a surface which does not support writing then a Status::WriteError
will be raised.
You can use this object normally, but no drawing will be done.
Class Method Detail
Instance Method Detail
Gets the current shape antialiasing mode, as set by Context#antialias=
.
###Returns The current shape antialiasing mode.
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 Antialias::SubPixel
when drawing shapes.
NOTE that this option does not affect text rendering, instead see FontOptions#antialias=
.
###Parameters
- antialias the new antialiasing mode
Append the path onto the current path. The path may be either the return value from one of Context#cairo_copy_path
or Context#copy_path_flat
or it may be constructed manually. See Path
for details on how the path data structure
should be initialized, and note that Path#status
must be initialized to Status::Success
.
###Parameters
- path path to be appended
Adds a circular arc of the given radius to the current path. The arc is centered at (xc, yc), begins at angle1 and proceeds in the direction of increasing angles to end at angle2. If angle2 is less than angle1 it will be progressively increased by 2*PI until it is greater than angle1.
If there is a current point, an initial line segment will be added to the path to connect the current point to the beginning of the arc.
If this initial line is undesired, it can be avoided by calling Context#new_sub_path
before calling Context#arc
.
Angles are measured in radians. An angle of 0.0 is in the direction of the positive X axis (in user space). An angle of PI/2.0 radians (90 degrees) is in the direction of the positive Y axis (in user space). Angles increase in the direction from the positive X axis toward the positive Y axis. So with the default transformation matrix, angles increase in a clockwise direction.
(To convert from degrees to radians, use (degrees*(PI / 180.0)).)
This function gives the arc in the direction of increasing angles; see Context#arc_negative
to get the arc in the direction of decreasing angles.
The arc is circular in user space. To achieve an elliptical arc, you can scale the current transformation matrix by different amounts in the X and Y directions. For example, to draw an ellipse in the box given by x, y, width, height:
context.save
context.translate(x + width / 2.0, y + height / 2.0)
context.scale(width / 2.0, height / 2.0)
context.arc(0.0, 0.0, 1.0, 0.0, 2.0 * Math::PI)
context.restore
###Parameters
- xc X position of the center of the arc
- yc Y position of the center of the arc
- radius the radius of the arc
- angle1 the start angle, in radians
- angle2 the end angle, in radians
Adds a circular arc of the given radius to the current path. The arc is centered at (xc, yc), begins at angle1 and proceeds in the direction of decreasing angles to end at angle2. If angle2 is greater than angle1 it will be progressively decreased by 2*PI until it is less than angle1.
See Context#arc
for more details. This function differs only in the direction of the arc between the two angles.
###Parameters
- xc X position of the center of the arc
- yc Y position of the center of the arc
- radius the radius of the arc
- angle1 the start angle, in radians
- angle2 the end angle, in radians
Establishes a new clip region by intersecting the current clip region with the current path as it
would be filled by Context#fill
and according to the current fill rule (see Context#fill_rule=
).
After Context#clip
, the current path will be cleared from the cairo context.
The current clip region affects all drawing operations by effectively masking out any changes to the surface that are outside the current clip region.
Calling Context#clip
can only make the clip region smaller, never larger.
But the current clip is part of the graphics state, so a temporary restriction of the clip region
can be achieved by calling Context#clip
within a Context#save
/Context#restore
pair.
The only other means of increasing the size of the clip region is Context#reset_clip
.
Computes a bounding box in user coordinates covering the area inside the current clip.
###Parameters
- x1 left of the resulting extents
- y1 top of the resulting extents
- x2 right of the resulting extents
- y2 bottom of the resulting extents
Establishes a new clip region by intersecting the current clip region with the current path as
it would be filled by Context#fill
and according to the current fill rule (see Context#fill_rule=
).
Unlike Context#clip
, Context#clip_preserve
preserves the path within the cairo context.
The current clip region affects all drawing operations by effectively masking out any changes to the surface that are outside the current clip region.
Calling Context#clip_preserve
can only make the clip region smaller, never larger.
But the current clip is part of the graphics state, so a temporary restriction of the clip region
can be achieved by calling Context#clip_preserve
within a Context#save
/Context#restore
pair.
The only other means of increasing the size of the clip region is Context#reset_clip
.
Adds a line segment to the path from the current point to the beginning of the current sub-path,
(the most recent point passed to Context#move_to
), and closes this sub-path.
After this call the current point will be at the joined endpoint of the sub-path.
The behavior of Context#close_path
is distinct from simply calling Context#line_to
with the equivalent coordinate in the case of stroking. When a closed sub-path is stroked,
there are no caps on the ends of the sub-path. Instead, there is a line join connecting the final and initial segments of the sub-path.
If there is no current point before the call to Context#close_path
, this function will have no effect.
NOTE As of cairo version 1.2.4 any call to Context#close_path
will place an explicit PathDataType::MoveTo
element into the path immediately after the PathDataType::ClosePath
element,
(which can be seen in Context#copy_path
for example). This can simplify path processing in some cases as it may not be necessary
to save the "last move_to point" during processing as the PathDataType::MoveTo
immediately after the PathDataType::ClosePath
will provide that point.
Gets the current clip region as a list of rectangles in user coordinates. Never returns Nil
.
The status in the list may be Status::ClipNotRepresentable
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.
###Returns
The current clip region as a list of rectangles in user coordinates, which should be destroyed using RectangleList#finalize
.
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 Context#show_page
if you want to get an empty page after the emission.
This is a convenience function that simply calls Surface#copy_page
on context's target.
Creates a copy of the current path and returns it to the user as a Path
.
See PathData
for hints on how to iterate over the returned data structure.
This function will always return a valid pointer, but the result will have no data (data==Nil and num_data==0), if either of the following conditions hold:
- If there is insufficient memory to copy the path. In this case
Path#status
will be set toStatus::NoMemory
. - If
Context
is already in an error state. In this casepath.status
will contain the same status that would be returned byContext#status
.
###Returns
The copy of the current path. The caller owns the returned object and should call Path#finalize
when finished with it.
Gets a flattened copy of the current path and returns it to the user as a Path
.
See PathData
for hints on how to iterate over the returned data structure.
This function is like Context#copy_path
except that any curves in the path will be approximated
with piecewise-linear approximations, (accurate to within the current tolerance value).
That is, the result is guaranteed to not have any elements of type PathDataType::CurveTo
which will instead be replaced by a series of PathDataType::LineTo
elements.
This function will always return a valid pointer, but the result will have no data (data==Nil and num_data==0), if either of the following conditions hold:
- If there is insufficient memory to copy the path. In this case
Path#status
will be set toStatus::NoMemory
. - If
Context
is already in an error state. In this casePath#status
will contain the same status that would be returned byContext#status
.
###Returns
The copy of the current path. The caller owns the returned object and should call Path#fnalize
when finished with it.
Gets the current point of the current path, which is conceptually the final point reached by the path so far.
The current point is returned in the user-space coordinate system.
If there is no defined current point or if Context
is in an error status,
x and y will both be set to 0.0. It is possible to check this in advance with Context#has_current_point?
.
Most path construction functions alter the current point.
See the following for details on how they affect the current point: Context#new_path
, Context#new_sub_path
,
Context#append
, Context#close_path
, Context#move_to
, Context#line_to
, Context#curve_to
, Context#rel_move_to
,
Context#rel_line_to
, Context#rel_curve_to
, Context#arc
, Context#arc_negative
, Context#cairo_rectangle
,
Context#text_path
, Context#glyph_path
, Context#stroke_to_path
.
Some functions use and alter the current point but do not otherwise change current path: Context#show_text
.
Some functions unset the current path and as a result, current point: Context#fill
, Context#stroke
.
Adds a cubic Bézier spline to the path from the current point to position (x3, y3) in user-space coordinates, using (x1, y1) and (x2, y2) as the control points. After this call the current point will be (x3, y3).
If there is no current point before the call to Context#curve_to
this function will behave as
if preceded by a call to Context#move_to(x1, y1)
.
###Parameters
- x1 the X coordinate of the first control point
- y1 the Y coordinate of the first control point
- x2 the X coordinate of the second control point
- y2 the Y coordinate of the second control point
- x3 the X coordinate of the end of the curve
- y3 the Y coordinate of the end of the curve
Gets the current dash array. If not empty, dashes should be big enough to hold at least the number of values returned
by Context#dash_count
.
This function returns the length of the dash array in Context
(0 if dashing is not currently in effect).
See also Context#set_dash
and Context#dash
.
###Returns The length of the dash array, or 0 if no dash array set.
Transform a coordinate from device space to user space by multiplying the given point by the inverse of the current transformation matrix (CTM).
###Parameters
- p point to transform
###Returns The transformed point.
Transform a distance vector from device space to user space.
This function is similar to Context#device_to_user
except that the translation components
of the inverse CTM will be ignored when transforming (dx, dy).
###Parameters
- d the distance vector in device space.
###Returns The distance vector is user space.
A drawing operator that fills the current path according to the current fill rule,
(each sub-path is implicitly closed before being filled). After Context#fill
,
the current path will be cleared from the cairo context.
See Context#fill_rule=
and Context#fill_preserve
.
Computes a bounding box in user coordinates covering the area that would be affected,
(the "inked" area), by a Context#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 Context#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 Context#fill_extents
must necessarily do more work to compute the precise inked areas in light of the fill rule,
so Context#path_extents
may be more desirable for sake of performance if the non-inked path extents are desired.
See Context#fill
, Context#fill_rule=
and Context#fill_preserve
.
###Parameters
- x1 left of the resulting extents
- y1 top of the resulting extents
- x2 right of the resulting extents
- y2 bottom of the resulting extents
Computes a bounding box in user coordinates covering the area that would be affected,
(the "inked" area), by a Context#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 Context#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 Context#fill_extents
must necessarily do more work to compute the precise inked areas in light of the fill rule,
so Context#path_extents
may be more desirable for sake of performance if the non-inked path extents are desired.
See Context#fill
, Context#fill_rule=
and Context#fill_preserve
.
###Parameters
- p1 top-left corner of the resulting extents
- p2 bottom-right corner of the resulting extents
Computes a bounding box in user coordinates covering the area that would be affected,
(the "inked" area), by a Context#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 Context#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 Context#fill_extents
must necessarily do more work to compute the precise inked areas in light of the fill rule,
so Context#path_extents
may be more desirable for sake of performance if the non-inked path extents are desired.
See Context#fill
, Context#fill_rule=
and Context#fill_preserve
.
###Parameters
- extents the resulting extents
A drawing operator that fills the current path according to the current fill rule,
(each sub-path is implicitly closed before being filled). Unlike Context#fill
,
Context#fill_preserve
preserves the path within the cairo context.
See Context#fill_rule=
and Context#fill
.
Gets the current fill rule, as set by Contex#fill_rule=
.
###Returns The current 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 Context#fill
and Context#clip
.
See FillRule
for details on the semantics of each available fill rule.
The default fill rule is FillRule::Winding
.
###Parameters
- fill_rule a fill rule
Decreases the reference count by one. If the result is zero, then Context
and all associated resources are freed. See Context#reference
.
Gets the font extents for the currently selected font.
###Returns
A FontExtents
object into which the results will be stored.
Gets the current font face for a Context
.
###Returns
The current font face. This object is owned by cairo. To keep a reference to it, you must call FontFace#reference
.
This function never returns Nil. If memory cannot be allocated, a special "nil" FontFace
object will be
returned on which FontFace#status
returns Status::NoMemory
.
Using this nil object will cause its error state to propagate to other objects it is passed to,
(for example, calling Context#font_face=
with a nil font will trigger an error that will shutdown the Context
object).
Replaces the current FontFace
object in the Context
with font_face.
The replaced font face in the Context
will be destroyed if there are no other references to it.
###Parameters
- font_face a
FontFace
, orNil
to restore to the default font.
Returns the current font matrix. See Context#font_matrix=
.
###Return The matrix.
Sets the current font matrix to matrix. The font matrix gives a transformation from the design space
of the font (in this space, the em-square is 1 unit by 1 unit) to user space.
Normally, a simple scale is used (see Context#font_size=
), but a more complex font matrix can be used
to shear the font or stretch it unequally along the two axes.
###Parameters
- matrix a
Matrix
describing a transform to be applied to the current font.
Retrieves font rendering options set via Context#font_options=
.
NOTE that the returned options do not include any options derived from the underlying surface;
they are literally the options passed to Context#font_options=
.
###Parameters
- options a
FontOptions
object into which to store the retrieved options. All existing values are overwritten.
Sets a set of custom font rendering options for the Context
.
Rendering options are derived by merging these options with the options derived from underlying surface;
if the value in options has a default value (like Antialias::Default), then the value from the surface is used.
###Parameters
- options font options to use
Sets the current font matrix to a scale by a factor of size,
replacing any font matrix previously set with Context#set_font_size=
or Context#font_matrix=
.
This results in a font size of size user space units. (More precisely, this matrix will result in
the font's em-square being a size by size square in user space.)
If text is drawn without a call to Context#font_size=
, (nor Context#font_matrix=
nor Context#scaled_font=
),
the default font size is 10.0.
###Parameters
- size the new font size, in user space units
Gets the extents for an array of glyphs. The extents describe a user-space rectangle that encloses
the "inked" portion of the glyphs, (as they would be drawn by Context#show_glyphs
).
Additionally, the x_advance and y_advance values indicate the amount by which the current point
would be advanced by Context#show_glyphs
.
NOTE that whitespace glyphs do not contribute to the size of the rectangle (extents.width
and extents.height
).
###Parameters
- glyphs an array of
Glyph
objects
###Returns
A TextExtents
object into which the results will be stored.
Adds closed paths for the glyphs to the current path. The generated path if filled,
achieves an effect similar to that of Context#show_glyphs
.
###Parameters
- glyphs array of glyphs to show
Gets the current destination surface for the context. This is either the original target surface as passed to Context#initialize
or the target surface for the current group as started by the most recent call to Context#push_group
or Context#push_group_with_content
.
This function will always return a valid pointer, but the result can be a "nil" surface if Context
is already in an error state,
(ie. Context#status
!= Status::Success
). A Nil surface is indicated by Surface#status
!= Status::Success
.
###Returns
The target surface. This object is owned by cairo. To keep a reference to it, you must call Surface#reference
.
Returns whether a current point is defined on the current path. See Context#current_point
for details on the current point.
###Returns Whether a current point is defined.
Resets the current transformation matrix (CTM) by setting it equal to the identity matrix. That is, the user-space and device-space axes will be aligned and one user-space unit will transform to one device-space unit.
Tests whether the given point is inside the area that would be visible through the current clip,
i.e. the area that would be filled by a Context#paint
operation.
See Context#clip
, and Context#clip_preserve
.
###Parameters
- p the point to test
###Returns true if the point is inside, or false if outside.
Tests whether the given point is inside the area that would be affected by a Context#fill
operation
given the current path and filling parameters. Surface dimensions and clipping are not taken into account.
See Context#fill
, Context#fill_rule=
and Context#fill_preserve
.
###Parameters
- x X coordinate of the point to test
- y Y coordinate of the point to test
###Returns A non-zero value if the point is inside, or zero if outside.
Tests whether the given point is inside the area that would be affected by a Context#fill
operation
given the current path and filling parameters. Surface dimensions and clipping are not taken into account.
See Context#fill
, Context#fill_rule=
and Context#fill_preserve
.
###Parameters
- p the point to test
###Returns A non-zero value if the point is inside, or zero if outside.
Tests whether the given point is inside the area that would be affected by a Context#stroke
operation
given the current path and stroking parameters. Surface dimensions and clipping are not taken into account.
See Context#stroke
, Context#line_width=
, Context#line_join=
, Context#line_cap=
, Context#set_dash
, and Context#stroke_preserve
.
###Parameters
- x X coordinate of the point to test
- y Y coordinate of the point to test
###Returns A non-zero value if the point is inside, or zero if outside.
Gets the current line cap style, as set by Context#line_cap=
.
###Returns The current line cap style.
Sets the current line cap style within the cairo context.
See LineCap
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 Context#stroke
,
Context#stroke_extents
, and Context#stroke_to_path
, but does not have any effect during path construction.
The default line cap style is LineCap::Butt
.
###Parameters
- line_cap a line cap style
Gets the current line join style, as set by Context#line_join=
.
###Returns The current line join style.
Sets the current line join style within the cairo context. See LineJoin
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 Context#stroke
, Context#stroke_extents
,
and Context#stroke_to_path
, but does not have any effect during path construction.
The default line join style is LineJoin::Miter
.
###Parameters
- line_join a line join style
Adds a line to the path from the current point to position (x, y) in user-space coordinates. After this call the current point will be (x, y).
If there is no current point before the call to Context#line_to
this function will behave as Context#move_to(x, y)
.
###Parameters
- x the X coordinate of the end of the new line
- y the Y coordinate of the end of the new line
This function returns the current line width value exactly as set by Context#line_width=
.
NOTE that the value is unchanged even if the CTM has changed between the calls to Context#line_width=
and Context#line_width
.
###Returns The current 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 Context#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 Context#line_width
and the stroking operation, then one can just pass user-space values to Context#line_width=
and ignore this note.
As with the other stroke parameters, the current line width is examined by Context#stroke
, Context#stroke_extents
,
and Context#stroke_to_path
, but does not have any effect during path construction.
The default line width value is 2.0.
###Parameters
- width a line width
A drawing operator that paints the current source using the alpha channel of pattern as a mask. (Opaque areas of pattern are painted with the source, transparent areas are not painted.)
###Parameters
- pattern a
Pattern
A drawing operator that paints the current source using the alpha channel of surface as a mask. (Opaque areas of surface are painted with the source, transparent areas are not painted.)
###Parameters
surface a Surface
surface_x X coordinate at which to place the origin of surface
surface_y Y coordinate at which to place the origin of surface
Stores the current transformation matrix (CTM) into matrix .
###Returns The matrix.
Modifies the current transformation matrix (CTM) by setting it equal to matrix.
###Parameters
- matrix a transformation matrix from user space to device space
Gets the current miter limit, as set by Context#miter_limit=
.
###Returns The current miter limit.
Sets the current miter limit within the cairo context.
If the current line join style is set to LineJoin::Miter
(see Context#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 Context#stroke
, Context#stroke_extents
,
and Context#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
- limit miter limit to set
Begin a new sub-path. After this call the current point will be (x, y).
###Parameters
- x the X coordinate of the new position
- y the Y coordinate of the new position
Begin a new sub-path. NOTE that the existing path is not affected. After this call there will be no current point.
In many cases, this call is not needed since new sub-paths are frequently started with Context#move_to
.
A call to Context#new_sub_path
is particularly useful when beginning a new sub-path with one of the Context#arc
calls.
This makes things easier as it is no longer necessary to manually compute the arc's initial coordinates for a call to Context#move_to
.
Gets the current compositing operator for a cairo context.
###Returns The current compositing operator.
Sets the compositing operator to be used for all drawing operations.
See Operator
for details on the semantics of each available compositing operator.
The default operator is Operator::Over
.
###Parameters
- op a compositing operator, specified as a
Operator
A drawing operator that paints the current source everywhere within the current clip region.
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 Context#paint
,
but the drawing is faded out using the alpha value.
###Parameters
- alpha alpha value, between 0 (transparent) and 1 (opaque)
Computes a bounding box in user-space coordinates covering the points on the current path. If the current path is empty, returns an empty rectangle ((0,0), (0,0)). Stroke parameters, fill rule, surface dimensions and clipping are not taken into account.
Contrast with Context#fill_extents
and Context#stroke_extents
which return the extents of only the area
that would be "inked" by the corresponding drawing operations.
The result of Context#path_extents
is defined as equivalent to the limit of Context#stroke_extents
with LineCap::Round
as the line width approaches 0.0, (but never reaching the empty-rectangle
returned by Context#stroke_extents
for a line width of 0.0).
Specifically, this means that zero-area sub-paths such as Context#move_to
; Context#line_to
segments,
(even degenerate cases where the coordinates to both calls are identical),
will be considered as contributing to the extents. However, a lone Context#move_to
will not contribute
to the results of Context#path_extents
.
###Parameters
- x1 left of the resulting extents
- y1 top of the resulting extents
- x2 right of the resulting extents
- y2 bottom of the resulting extents
Terminates the redirection begun by a call to Context#push_group
or Context#push_group_with_content
and returns a new pattern containing the results of all drawing operations performed to the group.
The Context#pop_group
function calls Context#restore
, (balancing a call to Context#save by the
Context#push_group` function),
so that any changes to the graphics state will not be visible outside the group.
###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 Surface#finalize
when finished with it.
Terminates the redirection begun by a call to Context#push_group
or Context#push_group_with_content`
and installs the resulting pattern as the source pattern in the given cairo context.
The behavior of this function is equivalent to the sequence of operations:
group = context.pop_group
context.set_source(group)
group.finalize
but is more convenient as their is no need for a variable to store the short-lived pointer to the pattern.
The Context#pop_group
function calls Context#restore
, (balancing a call to Context#save
by the Context#push_group
function),
so that any changes to the graphics state will not be visible outside the group.
Temporarily redirects drawing to an intermediate surface known as a group.
The redirection lasts until the group is completed by a call to Context#pop_group
or Context#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.
Groups can be nested arbitrarily deep by making balanced calls to Context#push_group
/Context#pop_group
.
Each call pushes/pops the new target group onto/from a stack.
The Context#push_group
function calls Context#save
so that any changes to the graphics state will not be visible outside the group,
(the pop_group functions call Context#restore
).
By default the intermediate group will have a content type of Content::ColorAlpha
.
Other content types can be chosen for the group by using Context#push_group_with_content
instead.
As an example, here is how one might fill and stroke a path with translucence, but without any portion of the fill being visible under the stroke:
context.push_group
context.set_source(fill_pattern)
context.fill_preserve
context.set_source(stroke_pattern)
context.stroke
context.pop_group_to_source
context.paint_with_alpha(alpha)
Temporarily redirects drawing to an intermediate surface known as a group.
The redirection lasts until the group is completed by a call to Context#pop_group
or Context#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 Context#push_group
which you should see for a more detailed description of group rendering.
###Parameters
- content a
Content
indicating the type of group that will be created.
Adds a closed sub-path rectangle of the given size to the current path at position (x, y) in user-space coordinates.
This function is logically equivalent to:
context
.cairo_move_to(x, y)
.rel_line_to(width, 0)
.rel_line_to(0, height)
.rel_line_to(-width, 0)
.close_path
###Parameters
- x the X coordinate of the top left corner of the rectangle
- y the Y coordinate to the top left corner of the rectangle
- width the width of the rectangle
- height the height of the rectangle
Increases the reference count on cr by one. This prevents cr from being destroyed until a matching call to Context#finalize
is made.
Use Context#reference_count
to get the number of references to a Context
.
###Returns
The referenced Context
.
Returns the current reference count of context.
###Returns The current reference count of context. If the object is a nil object, 0 will be returned.
Relative-coordinate version of Context#curve_to
. All offsets are relative to the current point.
Adds a cubic Bézier spline to the path from the current point to a point offset from the current point by (dx3, dy3),
using points offset by (dx1, dy1) and (dx2, dy2) as the control points.
After this call the current point will be offset by (dx3, dy3).
Given a current point of (x, y), context.rel_curve_to(dx1, dy1, dx2, dy2, dx3, dy3)
is logically equivalent to context.curve_to(x+dx1, y+dy1, x+dx2, y+dy2, x+dx3, y+dy3)
.
It is an error to call this function with no current point. Doing so will cause Context
to shutdown
with a status of Status::NoCurrentPoint
.
###Parameters
- dx1 the X offset to the first control point
- dy1 the Y offset to the first control point
- dx2 the X offset to the second control point
- dy2 the Y offset to the second control point
- dx3 the X offset to the end of the curve
- dy3 the Y offset to the end of the curve
Relative-coordinate version of Context#line_to
. Adds a line to the path from the current point
to a point that is offset from the current point by (dx, dy) in user space.
After this call the current point will be offset by (dx, dy).
Given a current point of (x, y), context.rel_line_to(dx, dy)
is logically equivalent to context.line_to(x + dx , y + dy)
.
It is an error to call this function with no current point. Doing so will cause Context
to shutdown
with a status of Status::NoCurrentPoint
.
###Parameters
- dx the X offset to the end of the new line
- dy the Y offset to the end of the new line
Begin a new sub-path. After this call the current point will offset by (x, y).
Given a current point of (x, y), context.rel_move_to(dx, dy)
is logically equivalent to context.move_to(x + dx, y + dy)
.
It is an error to call this function with no current point. Doing so will cause cr to shutdown with
a status of Status::NoCurrentPoint
.
###Parameters
- dx the X offset
- dy the Y offset
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.
NOTE that code meant to be reusable should not call Context#reset_clip
as it will cause results unexpected by higher-level code
which calls Context#clip
. Consider using Context#save
and Context#restore
around Context#clip
as a more robust means
of temporarily restricting the clip region.
Restores Context
to the state saved by a preceding call to Context#save
and removes that state from the stack of saved states.
Modifies the current transformation matrix (CTM) by rotating the user-space axes by angle radians. The rotation of the axes takes places after any existing transformation of user space. The rotation direction for positive angles is from the positive X axis toward the positive Y axis.
###Parameters
- angle angle (in radians) by which the user-space axes will be rotated
Makes a copy of the current state and saves it on an internal stack of saved states. When Context#restore
is called,
Context
will be restored to the saved state. Multiple calls to Context#save
and Context#restore
can be nested;
each call to Context#restore
restores the state from the matching paired Context#save
.
It isn't necessary to clear all saved states before a Context
is freed. If the reference count
of a Context
drops to zero in response to a call to Context#finalize
, any saved states will be freed along with the Context
.
Modifies the current transformation matrix (CTM) by scaling the X and Y user-space axes by sx and sy respectively. The scaling of the axes takes place after any existing transformation of user space.
###Parameters
- sx scale factor for the X dimension
- sy scale factor for the Y dimension
Gets the current scaled font for a Context
.
###Returns
The current scaled font. This object is owned by cairo. To keep a reference to it, you must call ScaledFont#reference
.
This function never returns Nil. If memory cannot be allocated, a special "nil" ScaledFont
object
will be returned on which ScaledFont#status
returns Status::NoMemory
.
Using this nil object will cause its error state to propagate to other objects it is passed to,
(for example, calling Context#scaled_font=
with a nil font will trigger an error that will shutdown the Context
object).
Replaces the current font face, font matrix, and font options in the Context
with those of the ScaledFont
.
Except for some translation, the current CTM of the Context
should be the same as that of the
ScaledFont
, which can be accessed using ScaledFont#ctm
###Parameters
- scaled_font a
ScaledFont
NOTE The Context#select_font_face
function call is part of what the cairo designers
call the "toy" text API. It is convenient for short demos and simple programs,
but it is not expected to be adequate for serious text-using applications.
Selects a family and style of font from a simplified description as a family name, slant and weight. Cairo provides no operation to list available family names on the system (this is a "toy", remember), but the standard CSS2 generic family names, ("serif", "sans-serif", "cursive", "fantasy", "monospace"), are likely to work as expected.
If family starts with the string "cairo :", or if no native font backends are compiled in, cairo will use an internal font family. The internal font family recognizes many modifiers in the family string, most notably, it recognizes the string "monospace". That is, the family name "cairo :monospace" will use the monospace version of the internal font family.
For "real" font selection, see the font-backend-specific font_face_create functions for the font backend you are using.
(For example, if you are using the freetype-based cairo-ft font backend, see FTFace#create_for_ft_face
or FcPattern#create_for_pattern
.) The resulting font face could then be used with FontFace#scaled_font_create
and Context#scaled_font=
.
Similarly, when using the "real" font support, you can call directly into the underlying font system, (such as fontconfig or freetype), for operations such as listing available fonts, etc.
It is expected that most applications will need to use a more comprehensive font handling and text layout library, (for example, pango), in conjunction with cairo.
If text is drawn without a call to Context#select_font_face
, (nor Context#font_face=
nor Context#scaled_font=
),
the default family is platform-specific, but is essentially "sans-serif". Default slant is
FontSlant::Normal
, and default weight is FontWeight::Normal
.
This function is equivalent to a call to FontFace#initialize(family, slant, weight)
followed by Context#font_face=
.
###Parameters
- family a font family name, encoded in UTF-8
- slant the slant for the font
- weight the weight for the font
Sets the dash pattern to be used by Context#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 LineCap::Round
or LineCap::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 Context#dash
.
If dashes.size
is 0 dashing is disabled.
If dashes.size
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 Context
will be put into an error state
with a status of Status::InvalidDash
.
###Parameters
- dashes an array specifying alternate lengths of on and off stroke portions
- offset an offset into the dash pattern at which the stroke should start
Sets the source pattern within Context
to an opaque color. This opaque color will then be used for any subsequent
drawing operation until a new source pattern is set.
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.
The default source pattern is opaque black, (that is, it is equivalent to `context.set_source_rgb(0.0_f64, 0.0_f64, 0.0_f64)).
###Parameters
- red red component of color
- green green component of color
- blue blue component of color
Sets the source pattern within cr to a translucent color. This color will then be used for any subsequent drawing operation until a new source pattern is set.
The color and alpha components are floating point numbers in the range 0 to 1. If the values passed in are outside that range, they will be clamped.
The default source pattern is opaque black, (that is, it is equivalent `context.set_source_rgba(0.0_f64, 0.0_f64, 0.0_f64, 1.0_f64)).
###Parameters red
- red component of color
- green green component of color
- blue blue component of color
- alpha alpha component of color
This is a convenience function for creating a pattern from surface and setting it as the source in Context
with Context#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.
Other than the initial translation pattern matrix, as described above, all other pattern attributes, (such as its extend mode),
are set to the default values as in Pattern#create_for_surface
. The resulting pattern can be queried with Context#source
so that these attributes can be modified if desired, (eg. to create a repeating pattern with Pattern#extend=
).
###Parameters
- surface a surface to be used to set the source pattern
- x User-space X coordinate for surface origin
- y User-space Y coordinate for surface origin
Attach user data to context. To remove user data from a surface, call this function with the key that was used to set it and Nil
for data.
###Parameters
- key the address of a cairo_user_data_key_t to attach the user data to
- user_data the user data to attach to the
Context
- destroy a
LibCairo::DestroyFuncT
which will be called when theContext
is destroyed or when new user data is attached using the same key.
###Returns
Status::Success
or Status::NoMemory
if a slot could not be allocated for the user data.
A drawing operator that generates the shape from an array of glyphs, rendered according to the current font face, font size (font matrix), and font options.
###Parameters
- glyphs array of glyphs to show
Emits and clears the current page for backends that support multiple pages.
Use Context#copy_page
if you don't want to clear the page.
This is a convenience function that simply calls Surface#show_page
on context's target.
A drawing operator that generates the shape from a string of UTF-8 characters, rendered according to the current font_face, font_size (font_matrix), and font_options.
This function first computes a set of glyphs for the string of text. The first glyph is placed so that its origin is at the current point. The origin of each subsequent glyph is offset from that of the previous glyph by the advance values of the previous glyph.
After this call the current point is moved to the origin of where the next glyph would be placed in this same progression.
That is, the current point will be at the origin of the final glyph offset by its advance values.
This allows for easy display of a single logical string with multiple calls to Context#show_text
.
NOTE The Context#show_text
function call is part of what the cairo designers call the "toy" text API.
It is convenient for short demos and simple programs, but it is not expected to be adequate for serious text-using applications.
See Context#show_glyphs
for the "real" text display API in cairo.
###Parameters
- utf8 a string of text encoded in UTF-8
This operation has rendering effects similar to Context#show_glyphs
but, if the target surface supports it,
uses the provided text and cluster mapping to embed the text for the glyphs shown in the output.
If the target does not support the extended attributes, this function acts like the basic Context#show_glyphs
as if it had been passed glyphs.
The mapping between text and glyphs* is provided by an array of clusters. Each cluster covers a number of text bytes and glyphs, and neighboring clusters cover neighboring areas of text and glyphs. The clusters should collectively cover text and glyphs in entirety.
The first cluster always covers bytes from the beginning of text. If cluster_flags do not have the
TextClusterFlags::Backward
set, the first cluster also covers the beginning of glyphs,
otherwise it covers the end of the glyphs array and following clusters move backward.
See TextCluster
for constraints on valid clusters.
###Parameters
- text a string of text encoded in UTF-8
- glyphs array of glyphs to show
- clusters array of cluster mapping information
- cluster_flags cluster mapping flags
Gets the current source pattern
###Returns
The current source pattern. This object is owned by cairo. To keep a reference to it, you must call Pattern#reference
.
Sets the source pattern within Context
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 Context#source=
.
This means that further modifications of the current transformation matrix will not affect the source pattern.
See Pattern#matrix=
.
The default source pattern is a solid pattern that is opaque black,
(that is, it is equivalent to context.set_source_rgb(0.0_f64, 0.0_f64, 0.0_f64)
).
###Parameters
- source a
Pattern
to be used as the source for subsequent drawing operations.
Checks whether an error has previously occurred for this context.
###Returns
The current status of this context, see Status
.
A drawing operator that strokes the current path according to the current line width, line join,
line cap, and dash settings. After Context#stroke
, the current path will be cleared from the cairo context.
See Context#line_width=
, Context#line_join=
, Context#line_cap=
, Context#set_dash
, and Context#stroke_preserve
.
NOTE Degenerate segments and sub-paths are treated specially and provide a useful result. These can result in two different situations:
- Zero-length "on" segments set in
Context#set_dash
. If the cap style isLineCap::Round
orLineCap::Square
then these segments will be drawn as circular dots or squares respectively. In the case ofLineCap::Square
, the orientation of the squares is determined by the direction of the underlying path. - A sub-path created by
Context#move_to
followed by either aCntext#close_path
or one or more calls toContext#line_to
to the same coordinate as theContext#move_to
. If the cap style isLineCap::Round
then these sub-paths will be drawn as circular dots.
NOTE that in the case of LineCap::Square
a degenerate sub-path will not be drawn at all,
(since the correct orientation is indeterminate).
In no case will a cap style of LineCap::Butt
cause anything to be drawn in the case of either degenerate segments or sub-paths.
Computes a bounding box in user coordinates covering the area that would be affected, (the "inked" area),
by a Context#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 Context#stroke_extents
will return an empty rectangle.
Contrast with Context#path_extents
which can be used to compute the non-empty bounds as the line width approaches zero.
NOTE that Context#stroke_extents
must necessarily do more work to compute the precise inked areas in light of the stroke parameters,
so Context#path_extents
may be more desirable for sake of performance if non-inked path extents are desired.
See Context#stroke
, Context#line_width=
, Context#
line_join=,
Context#line_cap=,
Context#set_dash, and
Context#stroke_preserve`.
###Parameters
- x1 left of the resulting extents
- y1 top of the resulting extents
- x2 right of the resulting extents
- y2 bottom of the resulting extents
A drawing operator that strokes the current path according to the current line width,
line join, line cap, and dash settings. Unlike Context#stroke
, Context#stroke_preserve
preserves the path within the cairo context.
See Context#line_width=
, Context#line_join=
, Context#line_cap=
, Context#set_dash
, and Context#stroke_preserve
.
Marks the beginning of the tag_name structure.
Call Context#tag_end
with the same tag_name to mark the end of the structure.
The attributes string is of the form "key1=value2 key2=value2 ..."
.
Values may be boolean (true/false or 1/0), integer, float, string, or an array.
String values are enclosed in single quotes ('). Single quotes and backslashes inside the string should be escaped with a backslash.
Boolean values may be set to true by only specifying the key. eg the attribute string "key"
is the equivalent to "key=true"
.
Arrays are enclosed in '[]'
. eg "rect=[1.2 4.3 2.0 3.0]"
.
If no attributes are required, attributes can be an empty string.
Invalid nesting of tags or invalid attributes will cause Context
to shutdown with a status of Status::TagError
.
See Context#tag_end
.
###Parameters
- tag_name tag name
- attributes tag attributes
Marks the end of the tag_name structure.
Invalid nesting of tags will cause cr to shutdown with a status of Status::TagError
.
See Context#tag_begin
.
###Parameters
- tag_name tag name
Gets the target surface for the cairo context as passed to Context#initialized
.
This function will always return a valid object, but the result can be a "nil" surface if Context
is already in an error state,
(ie. Context#state
!= State::Success
).
###Returns
The target surface. This object is owned by cairo. To keep a reference to it, you must call Surface#reference
.
Gets the extents for a string of text. The extents describe a user-space rectangle
that encloses the "inked" portion of the text, (as it would be drawn by Context#show_text
).
Additionally, the x_advance and y_advance values indicate the amount by which the current
point would be advanced by Context#show_text
.
NOTE that whitespace characters do not directly contribute to the size of the rectangle
(extents.width
and extents.height
). They do contribute indirectly by changing
the position of non-whitespace characters. In particular, trailing whitespace characters are
likely to not affect the size of the rectangle, though they will affect the x_advance and y_advance values.
###Parameters
- text a string of text encoded in UTF-8
###Returns
A TextExtends
object into which the results will be stored.
Adds closed paths for text to the current path. The generated path if filled,
achieves an effect similar to that of Context#show_text
.
Text conversion and positioning is done similar to Context#show_text
.
Like Context#show_text
, After this call the current point is moved to the origin of where
the next glyph would be placed in this same progression. That is, the current point will be
at the origin of the final glyph offset by its advance values. This allows for chaining multiple
calls to to Context#text_path
without having to set current point in between.
NOTE The Context#text_path
function call is part of what the cairo designers call the "toy" text API.
It is convenient for short demos and simple programs, but it is not expected to be adequate for serious text-using applications.
See Context#glyph_path
for the "real" text path API in cairo.
###Parameters
- text string of text encoded in UTF-8
Gets the current tolerance value, as set by Context#tolerance=
.
###Returns The current tolerance value.
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.
###Parameters
- tolerance the tolerance, in device units (typically pixels)
Modifies the current transformation matrix (CTM) by applying matrix as an additional transformation. The new transformation of user space takes place after any existing transformation.
###Parameters
- matrix a transformation to be applied to the user-space axes
Modifies the current transformation matrix (CTM) by translating the user-space origin by (tx, ty).
This offset is interpreted as a user-space coordinate according to the CTM in place before the new call to Context#translate
.
In other words, the translation of the user-space origin takes place after any existing transformation.
###Parameters
- tx amount to translate in the X direction
- ty amount to translate in the Y direction
Return user data previously attached to cr using the specified key.
If no user data has been attached with the given key this function returns Nil
.
###Parameters
- key the address of the
UserDataKey
the user data was attached to
###Returns
The user data previously attached or Nil
.
Transform a coordinate from user space to device space by multiplying the given point by the current transformation matrix (CTM).
###Parameters
- p point to transform
###Returns The transformed point.
Transform a distance vector from user space to device space. This function is similar to Context#user_to_device
except that the translation components of the CTM will be ignored when transforming (dx, dy).
###Parameters
- d the distance vector in user space.
###Returns The distance vector is device space.