cairomm 1.18.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Cairo::Context Class Reference

Context is the main class used to draw in cairomm. More...

#include <cairomm/context.h>

Public Types

enum class  Operator {
  CLEAR = CAIRO_OPERATOR_CLEAR ,
  SOURCE = CAIRO_OPERATOR_SOURCE ,
  OVER = CAIRO_OPERATOR_OVER ,
  IN = CAIRO_OPERATOR_IN ,
  OUT = CAIRO_OPERATOR_OUT ,
  ATOP = CAIRO_OPERATOR_ATOP ,
  DEST = CAIRO_OPERATOR_DEST ,
  DEST_OVER = CAIRO_OPERATOR_DEST_OVER ,
  DEST_IN = CAIRO_OPERATOR_DEST_IN ,
  DEST_OUT = CAIRO_OPERATOR_DEST_OUT ,
  DEST_ATOP = CAIRO_OPERATOR_DEST_ATOP ,
  XOR = CAIRO_OPERATOR_XOR ,
  ADD = CAIRO_OPERATOR_ADD ,
  SATURATE = CAIRO_OPERATOR_SATURATE
}
 Operator is used to set the compositing operator for all cairo drawing operations. More...
 
enum class  FillRule {
  WINDING = CAIRO_FILL_RULE_WINDING ,
  EVEN_ODD = CAIRO_FILL_RULE_EVEN_ODD
}
 FillRule is used to select how paths are filled. More...
 
enum class  LineCap {
  BUTT = CAIRO_LINE_CAP_BUTT ,
  ROUND = CAIRO_LINE_CAP_ROUND ,
  SQUARE = CAIRO_LINE_CAP_SQUARE
}
 Specifies how to render the endpoints of the path when stroking. More...
 
enum class  LineJoin {
  MITER = CAIRO_LINE_JOIN_MITER ,
  ROUND = CAIRO_LINE_JOIN_ROUND ,
  BEVEL = CAIRO_LINE_JOIN_BEVEL
}
 Specifies how to render the junction of two lines when stroking. More...
 
typedef cairo_t cobject
 The base cairo C type that is wrapped by Cairo::Context. More...
 

Public Member Functions

 Context (cairo_t *cobject, bool has_reference=false)
 Create a C++ wrapper for the C instance. More...
 
 Context (const Context &)=delete
 
Contextoperator= (const Context &)=delete
 
virtual ~Context ()
 
void save ()
 Makes a copy of the current state of the Context and saves it on an internal stack of saved states. More...
 
void restore ()
 Restores cr to the state saved by a preceding call to save() and removes that state from the stack of saved states. More...
 
void set_operator (Operator op)
 Sets the compositing operator to be used for all drawing operations. More...
 
void set_source (const RefPtr< const Pattern > & source)
 Sets the source pattern within the Context to source. More...
 
void set_source_rgb (double red, double green, double blue)
 Sets the source pattern within the Context to an opaque color. More...
 
void set_source_rgba (double red, double green, double blue, double alpha)
 Sets the source pattern within the Context to a translucent color. More...
 
void set_source (const RefPtr< Surface > & surface, double x, double y)
 This is a convenience function for creating a pattern from a Surface and setting it as the source. More...
 
void set_tolerance (double tolerance)
 Sets the tolerance used when converting paths into trapezoids. More...
 
void set_antialias (Antialias antialias)
 Set the antialiasing mode of the rasterizer used for drawing shapes. More...
 
void set_fill_rule (FillRule fill_rule)
 Set the current fill rule within the cairo Context. More...
 
void set_line_width (double width)
 Sets the current line width within the cairo Context. More...
 
void set_line_cap (LineCap line_cap)
 Sets the current line cap style within the cairo Context. More...
 
void set_line_join (LineJoin line_join)
 Sets the current line join style within the cairo Context. More...
 
void set_dash (const std::valarray< double > & dashes, double offset)
 Alternate version of set_dash(). More...
 
void set_dash (const std::vector< double > & dashes, double offset)
 Sets the dash pattern to be used by stroke(). More...
 
void unset_dash ()
 This function disables a dash pattern that was set with set_dash() More...
 
void set_miter_limit (double limit)
 Sets the current miter limit within the cairo context. More...
 
void translate (double tx, double ty)
 Modifies the current transformation matrix (CTM) by translating the user-space origin by (tx, ty). More...
 
void scale (double sx, double sy)
 Modifies the current transformation matrix (CTM) by scaling the X and Y user-space axes by sx and sy respectively. More...
 
void rotate (double angle_radians)
 Modifies the current transformation matrix (CTM) by rotating the user-space axes by angle radians. More...
 
void rotate_degrees (double angle_degres)
 A convenience wrapper around rotate() that accepts angles in degrees. More...
 
void transform (const Matrix & matrix)
 Modifies the current transformation matrix (CTM) by applying matrix as an additional transformation. More...
 
void set_matrix (const Matrix & matrix)
 Modifies the current transformation matrix (CTM) by setting it equal to matrix. More...
 
void set_identity_matrix ()
 Resets the current transformation matrix (CTM) by setting it equal to the identity matrix. More...
 
void user_to_device (double & x, double & y) const
 Transform a coordinate from user space to device space by multiplying the given point by the current transformation matrix (CTM). More...
 
void user_to_device_distance (double & dx, double & dy) const
 Transform a distance vector from user space to device space. More...
 
void device_to_user (double & x, double & y) const
 Transform a coordinate from device space to user space by multiplying the given point by the inverse of the current transformation matrix (CTM). More...
 
void device_to_user_distance (double & dx, double & dy) const
 Transform a distance vector from device space to user space. More...
 
void begin_new_path ()
 Clears the current path. More...
 
void begin_new_sub_path ()
 Begin a new subpath. More...
 
void move_to (double x, double y)
 If the current subpath is not empty, begin a new subpath. More...
 
void line_to (double x, double y)
 Adds a line to the path from the current point to position (x, y) in user-space coordinates. More...
 
void curve_to (double x1, double y1, double x2, double y2, double x3, double y3)
 Adds a cubic Bezier 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. More...
 
void arc (double xc, double yc, double radius, double angle1, double angle2)
 Adds a circular arc of the given radius to the current path. More...
 
void arc_negative (double xc, double yc, double radius, double angle1, double angle2)
 Adds a circular arc of the given radius to the current path. More...
 
void rel_move_to (double dx, double dy)
 If the current subpath is not empty, begin a new subpath. More...
 
void rel_line_to (double dx, double dy)
 Relative-coordinate version of line_to(). More...
 
void rel_curve_to (double dx1, double dy1, double dx2, double dy2, double dx3, double dy3)
 Relative-coordinate version of curve_to(). More...
 
void rectangle (double x, double y, double width, double height)
 Adds a closed-subpath rectangle of the given size to the current path at position (x, y) in user-space coordinates. More...
 
void close_path ()
 Adds a line segment to the path from the current point to the beginning of the current subpath, (the most recent point passed to move_to()), and closes this subpath. More...
 
void paint ()
 A drawing operator that paints the current source everywhere within the current clip region. More...
 
void paint_with_alpha (double alpha)
 A drawing operator that paints the current source everywhere within the current clip region using a mask of constant alpha value alpha. More...
 
void mask (const RefPtr< const Pattern > & pattern)
 A drawing operator that paints the current source using the alpha channel of pattern as a mask. More...
 
void mask (const RefPtr< const Surface > & surface, double surface_x, double surface_y)
 A drawing operator that paints the current source using the alpha channel of surface as a mask. More...
 
void stroke ()
 A drawing operator that strokes the current Path according to the current line width, line join, line cap, and dash settings. More...
 
void stroke_preserve ()
 A drawing operator that strokes the current Path according to the current line width, line join, line cap, and dash settings. More...
 
void fill ()
 A drawing operator that fills the current path according to the current fill rule, (each sub-path is implicitly closed before being filled). More...
 
void 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). More...
 
void 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. More...
 
void show_page ()
 Emits and clears the current page for backends that support multiple pages. More...
 
bool in_stroke (double x, double y) const
 Tests whether the given point is inside the area that would be affected by a stroke() operation given the current path and stroking parameters. More...
 
bool in_fill (double x, double y) const
 Tests whether the given point is inside the area that would be affected by a fill() operation given the current path and filling parameters. More...
 
bool in_clip (double x, double y) const
 Tests whether the given point is inside the area that would be visible through the current clip, i.e. More...
 
void get_stroke_extents (double & x1, double & y1, double & x2, double & y2) const
 Computes a bounding box in user coordinates covering the area that would be affected, (the "inked" area), by a stroke() operation given the current path and stroke parameters. More...
 
void get_fill_extents (double & x1, double & y1, double & x2, double & y2) const
 Computes a bounding box in user coordinates covering the area that would be affected, (the "inked" area), by a fill() operation given the current path and fill parameters. More...
 
void reset_clip ()
 Reset the current clip region to its original, unrestricted state. More...
 
void clip ()
 Establishes a new clip region by intersecting the current clip region with the current Path as it would be filled by fill() and according to the current fill rule. More...
 
void clip_preserve ()
 Establishes a new clip region by intersecting the current clip region with the current path as it would be filled by fill() and according to the current fill rule. More...
 
void get_clip_extents (double & x1, double & y1, double & x2, double & y2) const
 Computes a bounding box in user coordinates covering the area inside the current clip. More...
 
void copy_clip_rectangle_list (std::vector< Rectangle > & rectangles) const
 Returns the current clip region as a list of rectangles in user coordinates. More...
 
void select_font_face (const std::string & family, ToyFontFace::Slant slant, ToyFontFace::Weight weight)
 Selects a family and style of font from a simplified description as a family name, slant and weight. More...
 
void set_font_size (double size)
 Sets the current font matrix to a scale by a factor of size, replacing any font matrix previously set with set_font_size() or set_font_matrix(). More...
 
void set_font_matrix (const Matrix & matrix)
 Sets the current font matrix to @matrix. More...
 
void get_font_matrix (Matrix & matrix) const
 Returns the current font matrix. More...
 
void set_font_options (const FontOptions & options)
 Sets a set of custom font rendering options. More...
 
void get_font_options (FontOptions & options) const
 Retrieves font rendering options set via set_font_options(). More...
 
void set_scaled_font (const RefPtr< const ScaledFont > & scaled_font)
 Replaces the current font face, font matrix, and font options in the context with those of the scaled_font. More...
 
RefPtr< ScaledFontget_scaled_font ()
 Gets the current scaled font. More...
 
void show_text (const std::string & utf8)
 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. More...
 
void show_glyphs (const std::vector< Glyph > & glyphs)
 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. More...
 
void show_text_glyphs (const std::string & utf8, const std::vector< Glyph > & glyphs, const std::vector< TextCluster > & clusters, TextClusterFlags cluster_flags)
 This operation has rendering effects similar to 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. More...
 
void get_font_extents (FontExtents & extents) const
 Gets the font extents for the currently selected font. More...
 
void set_font_face (const RefPtr< const FontFace > & font_face)
 Replaces the current font face in the context with font_face font_face. More...
 
void get_text_extents (const std::string & utf8, TextExtents & extents) const
 Gets the extents for a string of text. More...
 
void get_glyph_extents (const std::vector< Glyph > & glyphs, TextExtents & extents) const
 Gets the extents for an array of glyphs. More...
 
void text_path (const std::string & utf8)
 Adds closed paths for text to the current path. More...
 
void glyph_path (const std::vector< Glyph > & glyphs)
 Adds closed paths for the glyphs to the current path. More...
 
Operator get_operator () const
 Gets the current compositing operator for a cairo Context. More...
 
double get_tolerance () const
 Gets the current tolerance value, as set by set_tolerance() More...
 
Antialias get_antialias () const
 Gets the current shape antialiasing mode, as set by set_antialias() More...
 
void get_current_point (double & x, double & y) const
 Gets the current point of the current path, which is conceptually the final point reached by the path so far. More...
 
bool has_current_point () const
 Checks if there is a current point defined. More...
 
FillRule get_fill_rule () const
 Gets the current fill rule, as set by set_fill_rule(). More...
 
double get_line_width () const
 Gets the current line width, as set by set_line_width(). More...
 
LineCap get_line_cap () const
 Gets the current line cap style, as set by set_line_cap() More...
 
LineJoin get_line_join () const
 Gets the current line join style, as set by set_line_join() More...
 
double get_miter_limit () const
 Gets the current miter limit, as set by set_miter_limit() More...
 
void get_dash (std::vector< double > & dashes, double & offset) const
 Gets the current dash array and offset. More...
 
void get_matrix (Matrix & matrix)
 Stores the current transformation matrix (CTM) into matrix. More...
 
Matrix get_matrix () const
 Returns the current transformation matrix (CTM) More...
 
Pathcopy_path () const
 Creates a copy of the current path and returns it to the user. More...
 
void get_path_extents (double & x1, double & y1, double & x2, double & y2) const
 Computes a bounding box in user-space coordinates covering the points on the current path. More...
 
Pathcopy_path_flat () const
 Gets a flattened copy of the current path and returns it to the user. More...
 
void append_path (const Path & path)
 Append the path onto the current path. More...
 
void push_group ()
 Temporarily redirects drawing to an intermediate surface known as a group. More...
 
void push_group_with_content (Content content)
 Temporarily redirects drawing to an intermediate surface known as a group. More...
 
RefPtr< Patternpop_group ()
 Terminates the redirection begun by a call to push_group() or push_group_with_content() and returns a new pattern containing the results of all drawing operations performed to the group. More...
 
void pop_group_to_source ()
 Terminates the redirection begun by a call to push_group() or push_group_with_content() and installs the resulting pattern as the source pattern in the given cairo Context. More...
 
RefPtr< Surfaceget_group_target ()
 Gets the target surface for the current group as started by the most recent call to push_group() or push_group_with_content(). More...
 
RefPtr< const Surfaceget_group_target () const
 Same as the non-const version but returns a reference to a const Surface. More...
 
cobjectcobj ()
 Gets a pointer to the base C type that is wrapped by the Context. More...
 
const cobjectcobj () const
 Gets a pointer to the base C type that is wrapped by the Context. More...
 
RefPtr< FontFaceget_font_face ()
 Gets the current font face. More...
 
RefPtr< const FontFaceget_font_face () const
 
RefPtr< Patternget_source ()
 Gets the current source pattern for the Context. More...
 
RefPtr< const Patternget_source () const
 
RefPtr< SurfacePatternget_source_for_surface ()
 Gets the current source surface pattern for the Context, if any. More...
 
RefPtr< const SurfacePatternget_source_for_surface () const
 
RefPtr< Surfaceget_target ()
 Gets the target surface associated with this Context. More...
 
RefPtr< const Surfaceget_target () const
 

Static Public Member Functions

static RefPtr< Contextcreate (const RefPtr< Surface > & target)
 

Protected Member Functions

 Context (const RefPtr< Surface > & target)
 

Protected Attributes

cobjectm_cobject
 

Detailed Description

Context is the main class used to draw in cairomm.

It contains the current state of the rendering device, including coordinates of yet to be drawn shapes.

In the simplest case, create a Context with its target Surface, set its drawing options (line width, color, etc), create shapes with methods like move_to() and line_to(), and then draw the shapes to the Surface using methods such as stroke() or fill().

Context is a reference-counted object that should be used via Cairo::RefPtr.

Member Typedef Documentation

◆ cobject

typedef cairo_t Cairo::Context::cobject

The base cairo C type that is wrapped by Cairo::Context.

Member Enumeration Documentation

◆ FillRule

enum class Cairo::Context::FillRule
strong

FillRule 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.)

The default fill rule is Cairo::FillRule::WINDING.

New entries may be added in future versions.

Enumerator
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.

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.

◆ LineCap

enum class Cairo::Context::LineCap
strong

Specifies how to render the endpoints of the path when stroking.

The default line cap style is Cairo::LineCap::BUTT.

Enumerator
BUTT 

Start(stop) the line exactly at the start(end) point.

ROUND 

Use a round ending, the center of the circle is the end point.

SQUARE 

Use a squared ending, the center of the square is the end point.

◆ LineJoin

enum class Cairo::Context::LineJoin
strong

Specifies how to render the junction of two lines when stroking.

The default line join style is Cairo::LineJoin::MITER.

Enumerator
MITER 

Use a sharp (angled) corner, see Context::set_miter_limit()

ROUND 

Use a rounded join, the center of the circle is the joint point.

BEVEL 

Use cut-off join, the join is cut off at half the line width from the join point.

◆ Operator

enum class Cairo::Context::Operator
strong

Operator is used to set the compositing operator for all cairo drawing operations.

The default operator is Cairo::Operator::OVER.

The operators marked as unbounded modify their destination even outside of the mask layer (that is, their effect is not bound by the mask layer). However, their effect can still be limited by way of clipping.

To keep things simple, the operator descriptions here document the behavior for when both source and destination are either fully transparent or fully opaque. The actual implementation works for translucent layers too. For a more detailed explanation of the effects of each operator, including the mathematical definitions, see this

Enumerator
CLEAR 

Clear destination layer (bounded)

SOURCE 

Replace destination layer (bounded)

OVER 

Draw source layer on top of destination layer (bounded)

IN 

Draw source where there was destination content (unbounded)

OUT 

Draw source where there was no destination content (unbounded)

ATOP 

Draw source on top of destination content and only there.

DEST 

Ignore the source.

DEST_OVER 

Draw destination on top of source.

DEST_IN 

Leave destination only where there was source content (unbounded)

DEST_OUT 

Leave destination only where there was no source content.

DEST_ATOP 

Leave destination on top of source content and only there (unbounded)

XOR 

Source and destination are shown where there is only one of them.

ADD 

Source and destination layers are accumulated.

SATURATE 

Like over, but assuming source and dest are disjoint geometries.

Constructor & Destructor Documentation

◆ Context() [1/3]

Cairo::Context::Context ( const RefPtr< Surface > &  target)
explicitprotected

◆ Context() [2/3]

Cairo::Context::Context ( cairo_t *  cobject,
bool  has_reference = false 
)
explicit

Create a C++ wrapper for the C instance.

This C++ instance should then be given to a RefPtr.

Parameters
cobjectThe C instance.
has_referenceWhether we already have a reference. Otherwise, the constructor will take an extra reference.

◆ Context() [3/3]

Cairo::Context::Context ( const Context )
delete

◆ ~Context()

virtual Cairo::Context::~Context ( )
virtual

Member Function Documentation

◆ append_path()

void Cairo::Context::append_path ( const Path path)

Append the path onto the current path.

The path may be either the return value from one of copy_path() or copy_path_flat() or it may be constructed manually.

Parameters
pathpath to be appended

◆ arc()

void Cairo::Context::arc ( double  xc,
double  yc,
double  radius,
double  angle1,
double  angle2 
)

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*M_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 begin_new_sub_path() before calling arc().

Angles are measured in radians. An angle of 0 is in the direction of the positive X axis (in user-space). An angle of M_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 * (M_PI / 180.0). )

This function gives the arc in the direction of increasing angles; see 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, y);
context->scale(width / 2.0, height / 2.0);
context->arc(0.0, 0.0, 1.0, 0.0, 2 * M_PI);
context->restore();
Parameters
xcX position of the center of the arc
ycY position of the center of the arc
radiusthe radius of the arc
angle1the start angle, in radians
angle2the end angle, in radians

◆ arc_negative()

void Cairo::Context::arc_negative ( double  xc,
double  yc,
double  radius,
double  angle1,
double  angle2 
)

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*M_PI until it is greater than angle1.

See arc() for more details. This function differs only in the direction of the arc between the two angles.

Parameters
xcX position of the center of the arc
ycY position of the center of the arc
radiusthe radius of the arc
angle1the start angle, in radians
angle2the end angle, in radians

◆ begin_new_path()

void Cairo::Context::begin_new_path ( )

Clears the current path.

After this call there will be no current point.

◆ begin_new_sub_path()

void Cairo::Context::begin_new_sub_path ( )

Begin a new subpath.

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 subpaths are frequently started with move_to().

A call to begin_new_sub_path() is particularly useful when beginning a new subpath with one of the arc() calls. This makes things easier as it is no longer necessary to manually compute the arc's initial coordinates for a call to move_to().

Since
1.2

◆ clip()

void Cairo::Context::clip ( )

Establishes a new clip region by intersecting the current clip region with the current Path as it would be filled by fill() and according to the current fill rule.

After 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 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 clip() within a save()/restore() pair. The only other means of increasing the size of the clip region is reset_clip().

See also
set_fill_rule()

◆ clip_preserve()

void Cairo::Context::clip_preserve ( )

Establishes a new clip region by intersecting the current clip region with the current path as it would be filled by fill() and according to the current fill rule.

Unlike clip(), clip_preserve preserves the path within the cairo Context.

See also
clip()
set_fill_rule()

◆ close_path()

void Cairo::Context::close_path ( )

Adds a line segment to the path from the current point to the beginning of the current subpath, (the most recent point passed to move_to()), and closes this subpath.

After this call the current point will be at the joined endpoint of the sub-path.

The behavior of close_path() is distinct from simply calling line_to() with the equivalent coordinate in the case of stroking. When a closed subpath is stroked, there are no caps on the ends of the subpath. Instead, there is a line join connecting the final and initial segments of the subpath.

If there is no current point before the call to close_path(), this function will have no effect.

◆ cobj() [1/2]

cobject * Cairo::Context::cobj ( )
inline

Gets a pointer to the base C type that is wrapped by the Context.

◆ cobj() [2/2]

const cobject * Cairo::Context::cobj ( ) const
inline

Gets a pointer to the base C type that is wrapped by the Context.

◆ copy_clip_rectangle_list()

void Cairo::Context::copy_clip_rectangle_list ( std::vector< Rectangle > &  rectangles) const

Returns the current clip region as a list of rectangles in user coordinates.

This function will throw an exception if the clip region cannot be represented as a list of user-space rectangles.

Parameters
rectanglesa vector to store the rectangles into
Exceptions
Since
1.4

◆ copy_page()

void Cairo::Context::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 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 cr's target.

◆ copy_path()

Path * Cairo::Context::copy_path ( ) const

Creates a copy of the current path and returns it to the user.

Note
The caller owns the Path object returned from this function. The Path object must be freed when you are finished with it.

◆ copy_path_flat()

Path * Cairo::Context::copy_path_flat ( ) const

Gets a flattened copy of the current path and returns it to the user.

This function is like 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 CAIRO_PATH_CURVE_TO which will instead be replaced by a series of CAIRO_PATH_LINE_TO elements.

Note
The caller owns the Path object returned from this function. The Path object must be freed when you are finished with it.

◆ create()

static RefPtr< Context > Cairo::Context::create ( const RefPtr< Surface > &  target)
static

◆ curve_to()

void Cairo::Context::curve_to ( double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3 
)

Adds a cubic Bezier 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 curve_to() this function will behave as if preceded by a call to move_to(x1, y1).

Parameters
x1the X coordinate of the first control point
y1the Y coordinate of the first control point
x2the X coordinate of the second control point
y2the Y coordinate of the second control point
x3the X coordinate of the end of the curve
y3the Y coordinate of the end of the curve

◆ device_to_user()

void Cairo::Context::device_to_user ( double &  x,
double &  y 
) const

Transform a coordinate from device space to user space by multiplying the given point by the inverse of the current transformation matrix (CTM).

Parameters
xX value of coordinate (in/out parameter)
yY value of coordinate (in/out parameter)

◆ device_to_user_distance()

void Cairo::Context::device_to_user_distance ( double &  dx,
double &  dy 
) const

Transform a distance vector from device space to user space.

This function is similar to device_to_user() except that the translation components of the inverse CTM will be ignored when transforming (dx,dy).

Parameters
dxX component of a distance vector (in/out parameter)
dyY component of a distance vector (in/out parameter)

◆ fill()

void Cairo::Context::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 fill(), the current path will be cleared from the cairo context.

See also
set_fill_rule()
fill_preserve()

◆ fill_preserve()

void Cairo::Context::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 fill(), fill_preserve() preserves the path within the cairo Context.

See also
set_fill_rule()
fill().

◆ get_antialias()

Antialias Cairo::Context::get_antialias ( ) const

Gets the current shape antialiasing mode, as set by set_antialias()

◆ get_clip_extents()

void Cairo::Context::get_clip_extents ( double &  x1,
double &  y1,
double &  x2,
double &  y2 
) const

Computes a bounding box in user coordinates covering the area inside the current clip.

Parameters
x1left of the resulting extents
y1top of the resulting extents
x2right of the resulting extents
y2bottom of the resulting extents
Since
1.4

◆ get_current_point()

void Cairo::Context::get_current_point ( double &  x,
double &  y 
) const

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 then x and y will both be set to 0.0. It is possible to check this in advance with has_current_point().

Most path construction functions alter the current point. See the following for details on how they affect the current point: clear_path(), move_to(), line_to(), curve_to(), arc(), rel_move_to(), rel_line_to(), rel_curve_to(), arc(), and text_path()

Some functions use and alter the current point but do not otherwise change current path: show_text().

Some functions unset the current path and as a result, current point: fill(), stroke().

Parameters
xreturn value for X coordinate of the current point
yreturn value for Y coordinate of the current point
See also
has_current_point()

◆ get_dash()

void Cairo::Context::get_dash ( std::vector< double > &  dashes,
double &  offset 
) const

Gets the current dash array and offset.

Parameters
dashesreturn value for the dash array.
offsetreturn value for the current dash offset.
Since
1.4

◆ get_fill_extents()

void Cairo::Context::get_fill_extents ( double &  x1,
double &  y1,
double &  x2,
double &  y2 
) const

Computes a bounding box in user coordinates covering the area that would be affected, (the "inked" area), by a 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 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 fill_extents() must necessarily do more work to compute the precise inked areas in light of the fill rule, so path_extents() may be more desirable for sake of performance if the non-inked path extents are desired.

Parameters
x1left of the resulting extents
y1top of the resulting extents
x2right of the resulting extents
y2bottom of the resulting extents
See also
fill()
set_fill_rule()
full_preserve()

◆ get_fill_rule()

FillRule Cairo::Context::get_fill_rule ( ) const

Gets the current fill rule, as set by set_fill_rule().

◆ get_font_extents()

void Cairo::Context::get_font_extents ( FontExtents extents) const

Gets the font extents for the currently selected font.

Parameters
extentsa Cairo::FontExtents object

◆ get_font_face() [1/2]

RefPtr< FontFace > Cairo::Context::get_font_face ( )

Gets the current font face.

◆ get_font_face() [2/2]

RefPtr< const FontFace > Cairo::Context::get_font_face ( ) const

◆ get_font_matrix()

void Cairo::Context::get_font_matrix ( Matrix matrix) const

Returns the current font matrix.

Parameters
matrixa Cairo::Matrix to store the results into (in/out parameter)
See also
set_font_matrix()

◆ get_font_options()

void Cairo::Context::get_font_options ( FontOptions options) const

Retrieves font rendering options set via set_font_options().

Note that the returned options do not include any options derived from the underlying surface; they are literally the options passed to set_font_options().

Parameters
optionsa FontOptions object into which to store the retrieved options. All existing values are overwritten
Since
1.8

◆ get_glyph_extents()

void Cairo::Context::get_glyph_extents ( const std::vector< Glyph > &  glyphs,
TextExtents extents 
) const

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 show_glyphs()). Additionally, the x_advance and y_advance values indicate the amount by which the current point would be advanced by show_glyphs().

Note that whitespace glyphs do not contribute to the size of the rectangle (extents.width and extents.height).

Parameters
glyphsa vector of glyphs
extentsa TextExtents object

◆ get_group_target() [1/2]

RefPtr< Surface > Cairo::Context::get_group_target ( )

Gets the target surface for the current group as started by the most recent call to push_group() or push_group_with_content().

This function will return NULL if called "outside" of any group rendering blocks, (that is, after the last balancing call to pop_group() or pop_group_to_source()).

Exceptions
Since
1.2

◆ get_group_target() [2/2]

RefPtr< const Surface > Cairo::Context::get_group_target ( ) const

Same as the non-const version but returns a reference to a const Surface.

Since
1.2

◆ get_line_cap()

LineCap Cairo::Context::get_line_cap ( ) const

Gets the current line cap style, as set by set_line_cap()

◆ get_line_join()

LineJoin Cairo::Context::get_line_join ( ) const

Gets the current line join style, as set by set_line_join()

◆ get_line_width()

double Cairo::Context::get_line_width ( ) const

Gets the current line width, as set by set_line_width().

Note that the value is unchanged even if the CTM has changed between the calls to set_line_width() and get_line_width().

◆ get_matrix() [1/2]

Matrix Cairo::Context::get_matrix ( ) const

Returns the current transformation matrix (CTM)

Since
1.8

◆ get_matrix() [2/2]

void Cairo::Context::get_matrix ( Matrix matrix)

Stores the current transformation matrix (CTM) into matrix.

Parameters
matrixreturn value for the matrix

◆ get_miter_limit()

double Cairo::Context::get_miter_limit ( ) const

Gets the current miter limit, as set by set_miter_limit()

◆ get_operator()

Operator Cairo::Context::get_operator ( ) const

Gets the current compositing operator for a cairo Context.

◆ get_path_extents()

void Cairo::Context::get_path_extents ( double &  x1,
double &  y1,
double &  x2,
double &  y2 
) const

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 fill_extents() and stroke_extents() which return the extents of only the area that would be "inked" by the corresponding drawing operations.

The result of path_extents() is defined as equivalent to the limit of stroke_extents() with LineCap::ROUND as the line width approaches 0.0, (but never reaching the empty-rectangle returned by stroke_extents() for a line width of 0.0).

Specifically, this means that zero-area sub-paths such as move_to();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 move_to() will not contribute to the results of path_extents().

Parameters
x1left of the resulting extents
y1top of the resulting extents
x2right of the resulting extents
y2bottom of the resulting extents
Since
1.6

◆ get_scaled_font()

RefPtr< ScaledFont > Cairo::Context::get_scaled_font ( )

Gets the current scaled font.

Since
1.8

◆ get_source() [1/2]

RefPtr< Pattern > Cairo::Context::get_source ( )

Gets the current source pattern for the Context.

◆ get_source() [2/2]

RefPtr< const Pattern > Cairo::Context::get_source ( ) const

◆ get_source_for_surface() [1/2]

RefPtr< SurfacePattern > Cairo::Context::get_source_for_surface ( )

Gets the current source surface pattern for the Context, if any.

Returns
The source pattern, if it is a surface pattern, else an empty RefPtr.

◆ get_source_for_surface() [2/2]

RefPtr< const SurfacePattern > Cairo::Context::get_source_for_surface ( ) const

◆ get_stroke_extents()

void Cairo::Context::get_stroke_extents ( double &  x1,
double &  y1,
double &  x2,
double &  y2 
) const

Computes a bounding box in user coordinates covering the area that would be affected, (the "inked" area), by a 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 stroke_extents() will return an empty rectangle. Contrast with path_extents() which can be used to compute the non-empty bounds as the line width approaches zero.

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

Parameters
x1left of the resulting extents
y1top of the resulting extents
x2right of the resulting extents
y2bottom of the resulting extents
See also
stroke()
set_line_width()
set_line_join()
set_line_cap()
set_dash()
stroke_preserve()

◆ get_target() [1/2]

RefPtr< Surface > Cairo::Context::get_target ( )

Gets the target surface associated with this Context.

Exceptions

◆ get_target() [2/2]

RefPtr< const Surface > Cairo::Context::get_target ( ) const

◆ get_text_extents()

void Cairo::Context::get_text_extents ( const std::string utf8,
TextExtents extents 
) const

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 show_text()). Additionally, the x_advance and y_advance values indicate the amount by which the current point would be advanced by 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
utf8a string of text encoded in UTF-8
extentsa TextExtents object

◆ get_tolerance()

double Cairo::Context::get_tolerance ( ) const

Gets the current tolerance value, as set by set_tolerance()

◆ glyph_path()

void Cairo::Context::glyph_path ( const std::vector< Glyph > &  glyphs)

Adds closed paths for the glyphs to the current path.

The generated path if filled, achieves an effect similar to that of show_glyphs().

Parameters
glyphsa vector of glyphs

◆ has_current_point()

bool Cairo::Context::has_current_point ( ) const

Checks if there is a current point defined.

See get_current_point() for details on the current point.

Returns
true if a current point is defined.
Since
1.6

◆ in_clip()

bool Cairo::Context::in_clip ( double  x,
double  y 
) const

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 paint() operation.

Return value: A non-zero value if the point is inside, or zero if outside.

Parameters
xX coordinate of the point to test
yY coordinate of the point to test
See also
clip()
clip_preserve()
Since
1.10

◆ in_fill()

bool Cairo::Context::in_fill ( double  x,
double  y 
) const

Tests whether the given point is inside the area that would be affected by a fill() operation given the current path and filling parameters.

Surface dimensions and clipping are not taken into account.

Parameters
xX coordinate of the point to test
yY coordinate of the point to test
Returns
A non-zero value if the point is inside, or zero if outside.
See also
fill()
set_fill_rule()
fill_preserve()

◆ in_stroke()

bool Cairo::Context::in_stroke ( double  x,
double  y 
) const

Tests whether the given point is inside the area that would be affected by a stroke() operation given the current path and stroking parameters.

Surface dimensions and clipping are not taken into account.

Parameters
xX coordinate of the point to test
yY coordinate of the point to test
Returns
A non-zero value if the point is inside, or zero if outside.
See also
stroke()
set_line_width()
set_line_join()
set_line_cap()
set_dash()
stroke_preserve().

◆ line_to()

void Cairo::Context::line_to ( double  x,
double  y 
)

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 line_to() this function will behave as move_to(x, y).

Parameters
xthe X coordinate of the end of the new line
ythe Y coordinate of the end of the new line

◆ mask() [1/2]

void Cairo::Context::mask ( const RefPtr< const Pattern > &  pattern)

A drawing operator that paints the current source using the alpha channel of pattern as a mask.

(Opaque areas of mask are painted with the source, transparent areas are not painted.)

Parameters
patterna Pattern

◆ mask() [2/2]

void Cairo::Context::mask ( const RefPtr< const Surface > &  surface,
double  surface_x,
double  surface_y 
)

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
surfacea Surface
surface_xX coordinate at which to place the origin of surface
surface_yY coordinate at which to place the origin of surface

◆ move_to()

void Cairo::Context::move_to ( double  x,
double  y 
)

If the current subpath is not empty, begin a new subpath.

After this call the current point will be (x, y).

Parameters
xthe X coordinate of the new position
ythe Y coordinate of the new position

◆ operator=()

Context & Cairo::Context::operator= ( const Context )
delete

◆ paint()

void Cairo::Context::paint ( )

A drawing operator that paints the current source everywhere within the current clip region.

◆ paint_with_alpha()

void Cairo::Context::paint_with_alpha ( double  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 paint(), but the drawing is faded out using the alpha value.

Parameters
alphaan alpha value, between 0 (transparent) and 1 (opaque)

◆ pop_group()

RefPtr< Pattern > Cairo::Context::pop_group ( )

Terminates the redirection begun by a call to push_group() or push_group_with_content() and returns a new pattern containing the results of all drawing operations performed to the group.

The pop_group() function calls restore(), (balancing a call to save() by the push_group function), so that any changes to the graphics state will not be visible outside the group.

Returns
a (surface) pattern containing the results of all drawing operations performed to the group.
Since
1.2

◆ pop_group_to_source()

void Cairo::Context::pop_group_to_source ( )

Terminates the redirection begun by a call to push_group() or 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:

RefPtr<Pattern> group = cr->pop_group();
cr->set_source(group);

but is more convenient as their is no need for a variable to store the short-lived pointer to the pattern.

The pop_group() function calls restore(), (balancing a call to save() by the push_group function), so that any changes to the graphics state will not be visible outside the group.

Since
1.2

◆ push_group()

void Cairo::Context::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 pop_group() or 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 push_group()/pop_group(). Each call pushes/pops the new target group onto/from a stack.

The push_group() function calls save() so that any changes to the graphics state will not be visible outside the group, (the pop_group functions call restore()).

By default the intermediate group will have a content type of CONTENT_COLOR_ALPHA. Other content types can be chosen for the group by using 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:

cr->push_group();
cr->set_source(fill_pattern);
cr->fill_preserve();
cr->set_source(stroke_pattern);
cr->stroke();
cr->pop_group_to_source();
cr->paint_with_alpha(alpha);
Since
1.2

◆ push_group_with_content()

void Cairo::Context::push_group_with_content ( Content  content)

Temporarily redirects drawing to an intermediate surface known as a group.

The redirection lasts until the group is completed by a call to pop_group() or 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 push_group() which you should see for a more detailed description of group rendering.

Parameters
contentindicates the type of group that will be created
Since
1.2

◆ rectangle()

void Cairo::Context::rectangle ( double  x,
double  y,
double  width,
double  height 
)

Adds a closed-subpath rectangle of the given size to the current path at position (x, y) in user-space coordinates.

This function is logically equivalent to:

context->move_to(x, y);
context->rel_line_to(width, 0);
context->rel_line_to(0, height);
context->rel_line_to(-width, 0);
context->close_path();
Parameters
xthe X coordinate of the top left corner of the rectangle
ythe Y coordinate to the top left corner of the rectangle
widththe width of the rectangle
heightthe height of the rectangle

◆ rel_curve_to()

void Cairo::Context::rel_curve_to ( double  dx1,
double  dy1,
double  dx2,
double  dy2,
double  dx3,
double  dy3 
)

Relative-coordinate version of curve_to().

All offsets are relative to the current point. Adds a cubic Bezier 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),

rel_curve_to(dx1, dy1, dx2, dy2, dx3, dy3)
void rel_curve_to(double dx1, double dy1, double dx2, double dy2, double dx3, double dy3)
Relative-coordinate version of curve_to().

is logically equivalent to

curve_to(x + dx1, y + dy1, x + dx2, y + dy2, x + dx3, y + dy3).
void curve_to(double x1, double y1, double x2, double y2, double x3, double y3)
Adds a cubic Bezier spline to the path from the current point to position (x3, y3) in user-space coor...
Parameters
dx1the X offset to the first control point
dy1the Y offset to the first control point
dx2the X offset to the second control point
dy2the Y offset to the second control point
dx3the X offset to the end of the curve
dy3the Y offset to the end of the curve

It is an error to call this function with no current point. Doing so will cause this to shutdown with a status of CAIRO_STATUS_NO_CURRENT_POINT. Cairomm will then throw an exception.

◆ rel_line_to()

void Cairo::Context::rel_line_to ( double  dx,
double  dy 
)

Relative-coordinate version of 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),

rel_line_to(dx, dy)
void rel_line_to(double dx, double dy)
Relative-coordinate version of line_to().

is logically equivalent to

line_to(x + dx, y + dy).
void line_to(double x, double y)
Adds a line to the path from the current point to position (x, y) in user-space coordinates.
Parameters
dxthe X offset to the end of the new line
dythe Y offset to the end of the new line

It is an error to call this function with no current point. Doing so will cause this to shutdown with a status of CAIRO_STATUS_NO_CURRENT_POINT. Cairomm will then throw an exception.

◆ rel_move_to()

void Cairo::Context::rel_move_to ( double  dx,
double  dy 
)

If the current subpath is not empty, begin a new subpath.

After this call the current point will offset by (x, y).

Given a current point of (x, y),

rel_move_to(dx, dy)
void rel_move_to(double dx, double dy)
If the current subpath is not empty, begin a new subpath.

is logically equivalent to

move_to(x + dx, y + dy)
void move_to(double x, double y)
If the current subpath is not empty, begin a new subpath.
Parameters
dxthe X offset
dythe Y offset

It is an error to call this function with no current point. Doing so will cause this to shutdown with a status of CAIRO_STATUS_NO_CURRENT_POINT. Cairomm will then throw an exception.

◆ reset_clip()

void Cairo::Context::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.

Note that code meant to be reusable should not call reset_clip() as it will cause results unexpected by higher-level code which calls clip(). Consider using save() and restore() around clip() as a more robust means of temporarily restricting the clip region.

◆ restore()

void Cairo::Context::restore ( )

Restores cr to the state saved by a preceding call to save() and removes that state from the stack of saved states.

See also
save(), SaveGuard

◆ rotate()

void Cairo::Context::rotate ( double  angle_radians)

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
angleangle (in radians) by which the user-space axes will be rotated

◆ rotate_degrees()

void Cairo::Context::rotate_degrees ( double  angle_degres)

A convenience wrapper around rotate() that accepts angles in degrees.

Parameters
angle_degreesangle (in degrees) by which the user-space axes should be rotated

◆ save()

void Cairo::Context::save ( )

Makes a copy of the current state of the Context and saves it on an internal stack of saved states.

When restore() is called, it will be restored to the saved state. Multiple calls to save() and restore() can be nested; each call to restore() restores the state from the matching paired save().

It isn't necessary to clear all saved states before a cairo_t is freed. Any saved states will be freed when the Context is destroyed.

See also
restore(), SaveGuard

◆ scale()

void Cairo::Context::scale ( double  sx,
double  sy 
)

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
sxscale factor for the X dimension
syscale factor for the Y dimension

◆ select_font_face()

void Cairo::Context::select_font_face ( const std::string family,
ToyFontFace::Slant  slant,
ToyFontFace::Weight  weight 
)

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.

Note: The 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.

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 Cairo::FontFace::create functions for the font backend you are using. (For example, if you are using the freetype-based cairo-ft font backend, see Cairo::FtFontFace::create().) The resulting font face could then be used with Cairo::ScaledFont::create() and set_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 select_font_face(), (nor set_font_face() nor set_scaled_font()), the default family is platform-specific, but is essentially "sans-serif". Default slant is Cairo::FONT_SLANT_NORMAL, and default weight is Cairo::FONT_WEIGHT_NORMAL.

This function is equivalent to a call to Cairo::ToyFontFace::create() followed by set_font_face().

Parameters
familya font family name, encoded in UTF-8
slantthe slant for the font
weightthe weight for the font

◆ set_antialias()

void Cairo::Context::set_antialias ( Antialias  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.

Note that this option does not affect text rendering, instead see FontOptions::set_antialias().

Parameters
antialiasthe new antialiasing mode

◆ set_dash() [1/2]

void Cairo::Context::set_dash ( const std::valarray< double > &  dashes,
double  offset 
)

Alternate version of set_dash().

You'll probably want to use the one that takes a std::vector argument instead.

◆ set_dash() [2/2]

void Cairo::Context::set_dash ( const std::vector< double > &  dashes,
double  offset 
)

Sets the dash pattern to be used by stroke().

A dash pattern is specified by dashes, an array of positive values. Each value provides the user-space length of altenate "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::LineCap::ROUND or Cairo::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 set_dash().

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

It is invalid for any value in dashes to be negative, or for all values to be 0. If this is the case, an exception will be thrown

Parameters
dashesan array specifying alternate lengths of on and off portions
offsetan offset into the dash pattern at which the stroke should start
Exceptions

◆ set_fill_rule()

void Cairo::Context::set_fill_rule ( FillRule  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 fill() and clip(). See FillRule for details on the semantics of each available fill rule.

The default fill rule is Cairo::FILL_RULE_WINDING.

Parameters
fill_rulea fill rule, specified as a FillRule

◆ set_font_face()

void Cairo::Context::set_font_face ( const RefPtr< const FontFace > &  font_face)

Replaces the current font face in the context with font_face font_face.

The replaced font face in the context will be destroyed if there are no other references to it.

Parameters
font_facea font face

◆ set_font_matrix()

void Cairo::Context::set_font_matrix ( const Matrix 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 set_font_size()), but a more complex font matrix can be used to shear the font or stretch it unequally along the two axes

Parameters
matrixa Cairo::Matrix describing a transform to be applied to the current font.

◆ set_font_options()

void Cairo::Context::set_font_options ( const FontOptions options)

Sets a set of custom font rendering options.

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 Cairo::ANTIALIAS_DEFAULT), then the value from the surface is used.

Parameters
optionsfont options to use

◆ set_font_size()

void Cairo::Context::set_font_size ( double  size)

Sets the current font matrix to a scale by a factor of size, replacing any font matrix previously set with set_font_size() or set_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 set_font_size(), (nor set_font_matrix() nor set_scaled_font()), the default font size is 10.0.

Parameters
sizethe new font size, in user space units)

◆ set_identity_matrix()

void Cairo::Context::set_identity_matrix ( )

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.

◆ set_line_cap()

void Cairo::Context::set_line_cap ( LineCap  line_cap)

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 stroke(), stroke_extents(), and stroke_to_path(), but does not have any effect during path construction.

The default line cap style is Cairo::LineCap::BUTT.

Parameters
line_capa line cap style, as a LineCap

◆ set_line_join()

void Cairo::Context::set_line_join ( LineJoin  line_join)

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 stroke(), stroke_extents(), and stroke_to_path(), but does not have any effect during path construction.

The default line join style is Cairo::LineJoin::MITER.

Parameters
line_joina line joint style, as a LineJoin

◆ set_line_width()

void Cairo::Context::set_line_width ( double  width)

Sets the current line width within the cairo Context.

The line width 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 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 set_line_width() and the stroking operation, then one can just pass user-space values to set_line_width() and ignore this note.

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

The default line width value is 2.0.

Parameters
widtha line width, as a user-space value

◆ set_matrix()

void Cairo::Context::set_matrix ( const Matrix matrix)

Modifies the current transformation matrix (CTM) by setting it equal to matrix.

Parameters
matrixa transformation matrix from user space to device space

◆ set_miter_limit()

void Cairo::Context::set_miter_limit ( double  limit)

Sets the current miter limit within the cairo context.

If the current line join style is set to Cairo::LineJoin::MITER (see 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 stroke(), stroke_extents(), and 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
limitmiter limit to set

◆ set_operator()

void Cairo::Context::set_operator ( Operator  op)

Sets the compositing operator to be used for all drawing operations.

See Operator for details on the semantics of each available compositing operator.

Parameters
opa compositing operator, specified as a Operator

◆ set_scaled_font()

void Cairo::Context::set_scaled_font ( const RefPtr< const ScaledFont > &  scaled_font)

Replaces the current font face, font matrix, and font options in the context with those of the scaled_font.

Except for some translation, the current CTM of the context should be the same as that of the #cairo_scaled_font_t, which can be accessed using Cairo::ScaledFont::get_ctm().

Parameters
scaled_fonta scaled font
Since
1.8

◆ set_source() [1/2]

void Cairo::Context::set_source ( const RefPtr< const Pattern > &  source)

Sets the source pattern within the 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 set_source(). This means that further modifications of the current transformation matrix will not affect the source pattern.

Parameters
sourcea Pattern to be used as the source for subsequent drawing operations.
See also
Pattern::set_matrix()
set_source_rgb()
set_source_rgba()
set_source(const RefPtr<Surface>& surface, double x, double y)

◆ set_source() [2/2]

void Cairo::Context::set_source ( const RefPtr< Surface > &  surface,
double  x,
double  y 
)

This is a convenience function for creating a pattern from a Surface and setting it as the 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 patterns 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 Context::create(const RefPtr<Surface>& target). The resulting pattern can be queried with get_source() so that these attributes can be modified if desired, (eg. to create a repeating pattern with Pattern::set_extend()).

Parameters
surfacea Surface to be used to set the source pattern
xUser-space X coordinate for surface origin
yUser-space Y coordinate for surface origin

◆ set_source_rgb()

void Cairo::Context::set_source_rgb ( double  red,
double  green,
double  blue 
)

Sets the source pattern within the 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.

Parameters
redred component of color
greengreen component of color
blueblue component of color
See also
set_source_rgba()
set_source()

◆ set_source_rgba()

void Cairo::Context::set_source_rgba ( double  red,
double  green,
double  blue,
double  alpha 
)

Sets the source pattern within the Context 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.

Parameters
redred component of color
greengreen component of color
blueblue component of color
alphaalpha component of color
See also
set_source_rgb()
set_source()

◆ set_tolerance()

void Cairo::Context::set_tolerance ( double  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.

Parameters
tolerancethe tolerance, in device units (typically pixels)

◆ show_glyphs()

void Cairo::Context::show_glyphs ( const std::vector< Glyph > &  glyphs)

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
glyphsvector of glyphs to show
num_glyphsnumber of glyphs to show

◆ show_page()

void Cairo::Context::show_page ( )

Emits and clears the current page for backends that support multiple pages.

Use copy_page() if you don't want to clear the page.

This is a convenience function that simply calls Surface::show_page() on cr's target.

◆ show_text()

void Cairo::Context::show_text ( const std::string utf8)

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 show_text().

Note: The 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 show_glyphs() for the "real" text display API in cairo.

Parameters
utf8a string containing text encoded in UTF-8

◆ show_text_glyphs()

void Cairo::Context::show_text_glyphs ( const std::string utf8,
const std::vector< Glyph > &  glyphs,
const std::vector< TextCluster > &  clusters,
TextClusterFlags  cluster_flags 
)

This operation has rendering effects similar to 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 show_glyphs() as if it had been passed glyphs and num_glyphs.

The mapping between utf8 and glyphs is provided by an array of <firstterm>clusters</firstterm>. Each cluster covers a number of text bytes and glyphs, and neighboring clusters cover neighboring areas of utf8 and glyphs. The clusters should collectively cover utf8 and glyphs in entirety.

The first cluster always covers bytes from the beginning of utf8. If cluster_flags do not have the Cairo::TEXT_CLUSTER_FLAG_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 Cairo::TextCluster for constraints on valid clusters.

Parameters
utf8a string of text encoded in UTF-8
glyphsvector of glyphs to show
clustersvector of cluster mapping information
cluster_flagscluster mapping flags
Since
1.8

◆ stroke()

void Cairo::Context::stroke ( )

A drawing operator that strokes the current Path according to the current line width, line join, line cap, and dash settings.

After stroke(), the current Path will be cleared from the cairo Context.

See also
set_line_width()
set_line_join()
set_line_cap()
set_dash()
stroke_preserve().

Note: Degenerate segments and sub-paths are treated specially and provide a useful result. These can result in two different situations:

  1. Zero-length "on" segments set in set_dash(). If the cap style is Cairo::LineCap::ROUND or Cairo::LineCap::SQUARE then these segments will be drawn as circular dots or squares respectively. In the case of Cairo::LineCap::SQUARE, the orientation of the squares is determined by the direction of the underlying path.
  2. A sub-path created by move_to() followed by either a close_path() or one or more calls to line_to() to the same coordinate as the move_to(). If the cap style is Cairo::LineCap::ROUND then these sub-paths will be drawn as circular dots. Note that in the case of Cairo::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 Cairo::LineCap::BUTT cause anything to be drawn in the case of either degenerate segments or sub-paths.

◆ stroke_preserve()

void Cairo::Context::stroke_preserve ( )

A drawing operator that strokes the current Path according to the current line width, line join, line cap, and dash settings.

Unlike stroke(), stroke_preserve() preserves the Path within the cairo Context.

See also
set_line_width()
set_line_join()
set_line_cap()
set_dash()
stroke_preserve().

◆ text_path()

void Cairo::Context::text_path ( const std::string utf8)

Adds closed paths for text to the current path.

The generated path if filled, achieves an effect similar to that of show_text().

Text conversion and positioning is done similar to show_text().

Like 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 text_path() without having to set current point in between.

Note: The 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 glyph_path() for the "real" text path API in cairo.

Parameters
utf8a string of text encoded in UTF-8

◆ transform()

void Cairo::Context::transform ( const Matrix matrix)

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
matrixa transformation to be applied to the user-space axes

◆ translate()

void Cairo::Context::translate ( double  tx,
double  ty 
)

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 translate. In other words, the translation of the user-space origin takes place after any existing transformation.

Parameters
txamount to translate in the X direction
tyamount to translate in the Y direction

◆ unset_dash()

void Cairo::Context::unset_dash ( )

This function disables a dash pattern that was set with set_dash()

◆ user_to_device()

void Cairo::Context::user_to_device ( double &  x,
double &  y 
) const

Transform a coordinate from user space to device space by multiplying the given point by the current transformation matrix (CTM).

Parameters
xX value of coordinate (in/out parameter)
yY value of coordinate (in/out parameter)

◆ user_to_device_distance()

void Cairo::Context::user_to_device_distance ( double &  dx,
double &  dy 
) const

Transform a distance vector from user space to device space.

This function is similar to user_to_device() except that the translation components of the CTM will be ignored when transforming (dx,dy).

Parameters
dxX component of a distance vector (in/out parameter)
dyY component of a distance vector (in/out parameter)

Member Data Documentation

◆ m_cobject

cobject* Cairo::Context::m_cobject
protected

The documentation for this class was generated from the following file: