### ----------------------------------------------------
### -- Gnome::Cairo
### -- Licenses: Artistic-2.0
### -- Authors: Marcel Timmerman
### -- File: lib/Gnome/Cairo.rakumod
### ----------------------------------------------------
### -- Chunk 3 of 4
 * }

#-------------------------------------------------------------------------------
#TM:1:restore:
=begin pod
=head2 restore

Restores this context to the state saved by a preceding call to C<save()> and removes that state from the stack of saved states.

  method restore ( )

=end pod

method restore ( ) {
  cairo_restore(self._get-native-object-no-reffing)
}

sub cairo_restore (
  cairo_t $cr
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:rotate:
=begin pod
=head2 rotate

Modifies the current transformation matrix (CTM) by rotating the user-space axes by I<$angle> radians. The rotation of the axes takes place after any existing transformation of user space. The rotation direction for positive angles is from the positive X axis toward the positive Y axis.

  method rotate ( Num() $angle )

=item $angle; Angle to rotate in radians
=end pod

method rotate ( Num() $angle ) {
  cairo_rotate( self._get-native-object-no-reffing, $angle)
}

sub cairo_rotate (
  cairo_t $cr, gdouble $angle
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:save:
=begin pod
=head2 save

Makes a copy of the current state of this context and saves it on an internal stack of saved states for this context. When C<restore()> is called, this context will be restored to the saved state.

Multiple calls to C<save()> and C<restore()> can be nested; each call to C<restore()> restores the state from the matching paired C<save()>.

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

  method save ( )

=end pod

method save ( ) {
  cairo_save(self._get-native-object-no-reffing)
}

sub cairo_save (
  cairo_t $cr
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:scale:
=begin pod
=head2 scale

Modifies the current transformation matrix (CTM) by scaling the X and Y user-space axes by I<sx> and I<sy> respectively. The scaling of the axes takes place after any existing transformation of user space.

  method scale ( Num() $sx, Num() $sy )

=item $sx; scale factor for the X dimension
=item $sy; scale factor for the Y dimension
=end pod

method scale ( Num() $sx, Num() $sy ) {
  cairo_scale(
    self._get-native-object-no-reffing, $sx, $sy
  )
}

sub cairo_scale (
  cairo_t $cr, gdouble $sx, gdouble $sy
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:4:select-font-face:
=begin pod
=head2 select-font-face

Note: The C<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 I<$family> starts with the string "C<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 I<$family> string, most notably, it recognizes the string "monospace". That is, the family name "I<cairo>:monospace" will use the monospace version of the internal font family.

=comment For "real" font selection, see the font-backend-specific font_face_create functions for the font backend you are using.
=comment (For example, if you are using the freetype-based cairo-ft font backend, see C<ft_font-face-create-for-ft-face()> or C<ft-font-face-create-for-pattern()>.) The resulting font face could then be used with C<scaled-font-create()> and C<set-scaled-font()>.

=comment 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 C<select-font-face()>, (nor C<set-font-face()> nor C<set-scaled-font()>), the default family is platform-specific, but is essentially "sans-serif". Default slant is C<CAIRO_FONT_SLANT_NORMAL>, and default weight is C<CAIRO_FONT_WEIGHT_NORMAL>.

=comment This function is equivalent to a call to C<toy-font-face-create()> followed by C<set-font-face()>.

  method select-font-face (
    Str $family, cairo_font_slant_t $slant,
    cairo_font_weight_t $weight
  )

=item $family; a font family name, encoded in UTF-8
=item $slant; the slant for the font
=item $weight; the weight for the font
=end pod

method select-font-face ( Str $family, Int $slant, Int $weight ) {
  cairo_select_font_face(
    self._get-native-object-no-reffing, $family, $slant, $weight
  )
}

sub cairo_select_font_face (
  cairo_t $cr, gchar-ptr $family, GEnum $slant, GEnum $weight
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:set-antialias:
=begin pod
=head2 set-antialias

Set the antialiasing mode of the rasterizer used for drawing shapes. This value is a hint, and a particular backend may or may not support a particular value.

At the current time, no backend supports C<CAIRO_ANTIALIAS_SUBPIXEL> when drawing shapes.

Note that this option does not affect text rendering, instead see C<font-options-set-antialias()>.

  method set-antialias ( cairo_antialias_t $antialias )

=item $antialias; the new antialiasing mode
=end pod

method set-antialias ( cairo_antialias_t $antialias ) {
  cairo_set_antialias( self._get-native-object-no-reffing, $antialias)
}

sub cairo_set_antialias (
  cairo_t $cr, GEnum $antialias
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:set-dash:
=begin pod
=head2 set-dash

Sets the dash pattern to be used by C<stroke()>. A dash pattern is specified by I<$dashes>, an array of positive values. Each value provides the length of alternate "on" and "off" portions of the stroke. The I<$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 C<CAIRO_LINE_CAP_ROUND> or C<CAIRO_LINE_CAP_SQUARE> in order to distributed dots or squares along a path.

Note: The length values are in user-space units as evaluated at the time of stroking. This is not necessarily the same as the user space at the time of C<set-dash()>.  If I<$num_dashes> is 0 dashing is disabled.  If I<num_dashes> is 1 a symmetric pattern is assumed with alternating on and off portions of the size specified by the single value in I<$dashes>.

If any value in I<$dashes> is negative, or if all values are 0, then this context will be put into an error state with a status of C<CAIRO_STATUS_INVALID_DASH>.

  method set-dash ( Array $dashes, Num() $offset )

=item $dashes; an array specifying alternate lengths of on and off stroke portions
=item $offset; an offset into the dash pattern at which the stroke should start
=end pod

method set-dash ( Array $dashes, Num() $offset ) {
  my $d = CArray[gdouble].new;
  my Int $c = 0;
  for @$dashes -> $dnum {
    $d[$c++] = Num($dnum);
  }

  my int32 $num_dashes = $dashes.elems;
  cairo_set_dash(
    self._get-native-object-no-reffing, $d, $num_dashes, $offset
  )
}

sub cairo_set_dash (
  cairo_t $cr, CArray[gdouble] $dashes, int32 $num_dashes, gdouble $offset
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:set-fill-rule:
=begin pod
=head2 set-fill-rule

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

The default fill rule is C<CAIRO_FILL_RULE_WINDING>.

  method set-fill-rule ( cairo_fill_rule_t $fill_rule )

=item $fill_rule; a fill rule type
=end pod

method set-fill-rule ( cairo_fill_rule_t $fill_rule ) {
  cairo_set_fill_rule(
    self._get-native-object-no-reffing, $fill_rule
  )
}

sub cairo_set_fill_rule (
  cairo_t $cr, GEnum $fill_rule
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:set-font-face:
=begin pod
=head2 set-font-face

Replaces the current B<cairo_font_face_t> object in the B<cairo_t> with I<font_face>. The replaced font face in the B<cairo_t> will be destroyed if there are no other references to it.

  method set-font-face ( cairo_font_face_t $font_face )

=item $font_face; a B<font-face-t>, or C<Any> to restore to the default font
=end pod

method set-font-face ( cairo_font_face_t $font_face ) {
  cairo_set_font_face( self._get-native-object-no-reffing, $font_face)
}

sub cairo_set_font_face (
  cairo_t $cr, cairo_font_face_t $font_face
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:set-font-matrix:
=begin pod
=head2 set-font-matrix

Sets the current font matrix to I<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 C<set-font-size()>), but a more complex font matrix can be used to shear the font or stretch it unequally along the two axes

  method set-font-matrix ( cairo_matrix_t $matrix )

=item $matrix; a B<matrix-t> describing a transform to be applied to the current font.
=end pod

method set-font-matrix ( $matrix is copy ) {
  $matrix .= _get-native-object-no-reffing unless $matrix ~~ cairo_matrix_t;
  cairo_set_font_matrix( self._get-native-object-no-reffing, $matrix)
}

sub cairo_set_font_matrix (
  cairo_t $cr, cairo_matrix_t $matrix
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:set-font-options:
=begin pod
=head2 set-font-options

Sets a set of custom font rendering options for the B<cairo_t>. Rendering options are derived by merging these options with the options derived from underlying surface; if the value in I<options> has a default value (like C<CAIRO_ANTIALIAS_DEFAULT>), then the value from the surface is used.

  method set-font-options ( cairo_font_options_t $options )

=item $options; font options to use
=end pod

method set-font-options ( $options is copy ) {
  $options .= _get-native-object-no-reffing
    unless $options ~~ cairo_font_options_t;

  cairo_set_font_options( self._get-native-object-no-reffing, $options)
}

sub cairo_set_font_options (
  cairo_t $cr, cairo_font_options_t $options
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:4:set-font-size:
=begin pod
=head2 set-font-size

Sets the current font matrix to a scale by a factor of I<size>, replacing any font matrix previously set with C<set-font-size()> or C<set-font-matrix()>. This results in a font size of I<size> user space units. (More precisely, this matrix will result in the font's em-square being a I<$size> by I<$size> square in user space.)

If text is drawn without a call to C<set-font-size()>, (nor C<set-font-matrix()> nor C<cset-scaled-font()>), the default font size is 10.0.

  method set-font-size ( Num() $size )

=item $size; The size of the current font
=end pod

method set-font-size ( Num() $size ) {
  cairo_set_font_size( self._get-native-object-no-reffing, $size)
}

sub cairo_set_font_size (
  cairo_t $cr, gdouble $size
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:set-line-cap:
=begin pod
=head2 set-line-cap

Sets the current line cap style within the cairo context. See B<cairo_line_cap_t> for details about how the available line cap styles are drawn.  As with the other stroke parameters, the current line cap style is examined by C<stroke()>, C<stroke-extents()>, and C<stroke-to-path()>, but does not have any effect during path construction.  The default line cap style is C<CAIRO_LINE_CAP_BUTT>.

  method set-line-cap ( Int $line_cap )

=item $line_cap; a line cap style
=end pod

method set-line-cap ( Int $line_cap ) {
  cairo_set_line_cap( self._get-native-object-no-reffing, $line_cap)
}

sub cairo_set_line_cap (
  cairo_t $cr, gint32 $line_cap
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:set-line-join:
=begin pod
=head2 set-line-join

Sets the current line join style within the cairo context. See B<cairo_line_join_t> for details about how the available line join styles are drawn.  As with the other stroke parameters, the current line join style is examined by C<stroke()>, C<stroke-extents()>, and C<stroke-to-path()>, but does not have any effect during path construction.  The default line join style is C<CAIRO_LINE_JOIN_MITER>.

  method set-line-join ( Int $line_join )

=item $line_join; a line join style
=end pod

method set-line-join ( Int $line_join ) {
  cairo_set_line_join( self._get-native-object-no-reffing, $line_join)
}

sub cairo_set_line_join (
  cairo_t $cr, gint32 $line_join
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:set-line-width:
=begin pod
=head2 set-line-width

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

Note: When the description above refers to user space and CTM it refers to the user space and CTM in effect at the time of the stroking operation, not the user space and CTM in effect at the time of the call to C<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 C<set-line-width()> and the stroking operation, then one can just pass user-space values to C<set-line-width()> and ignore this note.

As with the other stroke parameters, the current line width is examined by C<stroke()>, C<stroke-extents()>, and C<stroke-to-path()>, but does not have any effect during path construction.

The default line width value is 2.0.

  method set-line-width ( Num() $width )

=item $width; a line width
=end pod

method set-line-width ( Num() $width ) {
  cairo_set_line_width( self._get-native-object-no-reffing, $width)
}

sub cairo_set_line_width (
  cairo_t $cr, gdouble $width
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:set-matrix:
=begin pod
=head2 set-matrix

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

  method set-matrix ( cairo_matrix_t $matrix )

=item $matrix; a transformation matrix from user space to device space
=end pod

method set-matrix ( $matrix is copy ) {
  $matrix .= get-native-object-no-reffing unless $matrix ~~ cairo_matrix_t;
  cairo_set_matrix( self._get-native-object-no-reffing, $matrix);
}

sub cairo_set_matrix (
  cairo_t $cr, cairo_matrix_t $matrix
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:set-miter-limit:
=begin pod
=head2 set-miter-limit

Sets the current miter limit within the cairo context.

If the current line join style is set to C<CAIRO_LINE_JOIN_MITER> (see C<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 C<stroke()>, C<stroke-extents()>, and C<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: C<miter limit = 1/sin(angle/2)>.

  method set-miter-limit ( Num() $limit )

=item $limit; a cairo context
=end pod

method set-miter-limit ( Num() $limit ) {
  cairo_set_miter_limit( self._get-native-object-no-reffing, $limit)
}

sub cairo_set_miter_limit (
  cairo_t $cr, gdouble $limit
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:set-operator:
=begin pod
=head2 set-operator

Sets the compositing operator to be used for all drawing operations. See B<cairo_operator_t> for details on the semantics of each available compositing operator.

The default operator is C<CAIRO_OPERATOR_OVER>.

  method set-operator ( cairo_operator_t $op )

=item $op; a compositing operator
=end pod

method set-operator ( Int $op ) {
  cairo_set_operator( self._get-native-object-no-reffing, $op)
}

sub cairo_set_operator (
  cairo_t $cr, gint32 $op
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:set-scaled-font:
=begin pod
=head2 set-scaled-font

Replaces the current font face, font matrix, and font options in the B<cairo_t> with those of the B<cairo_scaled_font_t>.  Except for some translation, the current CTM of the B<cairo_t> should be the same as that of the B<cairo_scaled_font_t>, which can be accessed using C<scaled-font-get-ctm()>.

  method set-scaled-font ( cairo_scaled_font_t $scaled_font )

=item $scaled_font; a scaled font
=end pod

method set-scaled-font ( $scaled_font is copy ) {
  $scaled_font .= _get-native-object-no-reffing
    unless $scaled_font ~~ cairo_scaled_font_t;

  cairo_set_scaled_font( self._get-native-object-no-reffing, $scaled_font)
}

sub cairo_set_scaled_font (
  cairo_t $cr, cairo_scaled_font_t $scaled_font
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:4:set-source:
=begin pod
=head2 set-source

Sets the source pattern within this context to I<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 C<set-source()>. This means that further modifications of the current transformation matrix will not affect the source pattern. See C<pattern-set-matrix()>.

The default source pattern is a solid pattern that is opaque black, (that is, it is equivalent to C<set-source-rgb( 0.0, 0.0, 0.0))>.

  method set-source ( cairo_pattern_t $source )

=item $source; a pattern type to be used as the source for subsequent drawing operations.
=end pod

method set-source ( $source is copy ) {
  $source .= _get-native-object-no-reffing
    unless $source ~~ cairo_pattern_t;
  cairo_set_source( self._get-native-object-no-reffing, $source);
}

sub cairo_set_source (
  cairo_t $cr, cairo_pattern_t $source
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TN:4:set-source-pixbuf:
=begin pod
=head2 set-source-pixbuf

Sets the given pixbuf as the source pattern for this context.

=comment The pattern has an extend mode of cairo_extend_none and

The image is aligned so that the origin of the I<$pixbuf> is C<($x, $y)>.

  method set-source-pixbuf( $pixbuf is copy, Num() $x, Num() $y ) {

=item $pixbuf; The pixel buffer
=item $x; x origin
=item $y; y origin

=end pod

method set-source-pixbuf( $pixbuf is copy, Num() $x, Num() $y ) {
  $pixbuf .= get-native-object-no-reffing unless $pixbuf ~~ N-GObject;
  cairo_set_source_pixbuf( $pixbuf, $x, $y);
}

sub cairo_set_source_pixbuf (
  cairo_t $cr, N-GObject $pixbuf, gdouble $x, gdouble $y
#) is native(&cairo-lib)
) is native(&gdk-pixbuf-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:4:set-source-rgb:
=begin pod
=head2 set-source-rgb

Sets the source pattern within this 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 C<set-source-rgb( 0.0, 0.0, 0.0)>).

  method set-source-rgb ( Num() $red, Num() $green, Num() $blue )

=item $red; red component of color
=item $green; green component of color
=item $blue; blue component of color
=end pod

method set-source-rgb ( Num() $red, Num() $green, Num() $blue ) {
  cairo_set_source_rgb(
    self._get-native-object-no-reffing, $red, $green, $blue
  )
}

sub cairo_set_source_rgb (
  cairo_t $cr, gdouble $red, gdouble $green, gdouble $blue
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:4:set-source-rgba:
=begin pod
=head2 set-source-rgba

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

The default source pattern is opaque black, (that is, it is equivalent to C<set-source-rgba( 0.0, 0.0, 0.0, 1.0))>.

  method set-source-rgba (
    Num() $red, Num() $green, Num() $blue, Num() $alpha
  )

=item $red; red component of color
=item $green; green component of color
=item $blue; blue component of color
=item $alpha; alpha component of color
=end pod

method set-source-rgba ( Num() $red, Num() $green, Num() $blue, Num() $alpha ) {
  cairo_set_source_rgba(
    self._get-native-object-no-reffing, $red, $green, $blue, $alpha
  )
}

sub cairo_set_source_rgba (
  cairo_t $cr, gdouble $red, gdouble $green, gdouble $blue, gdouble $alpha
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:set-source-surface:
=begin pod
=head2 set-source-surface

This is a convenience function for creating a pattern from I<$surface> and setting it as the source in this context with C<set-source()>.

The I<$x> and I<$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 I<$x> and I<$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 C<Gnome::Cairo::Pattern.new(:surface)>. The resulting pattern can be queried with C<get-source()> so that these attributes can be modified if desired, (eg. to create a repeating pattern with C<Gnome::Cairo::Pattern.set-extend()>).

  method set-source-surface ( cairo_surface_t $surface, Num() $x, Num() $y )

=item $surface; a surface to be used to set the source pattern
=item $x; User-space X coordinate for surface origin
=item $y; User-space Y coordinate for surface origin
=end pod

method set-source-surface ( $surface is copy, Num() $x, Num() $y ) {
  $surface .= _get-native-object-no-reffing unless $surface ~~ cairo_surface_t;

  cairo_set_source_surface(
    self._get-native-object-no-reffing, $surface, $x, $y
  )
}

sub cairo_set_source_surface (
  cairo_t $cr, cairo_surface_t $surface, gdouble $x, gdouble $y
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:set-tolerance:
=begin pod
=head2 set-tolerance

Sets the tolerance used when converting paths into trapezoids. Curved segments of the path will be subdivided until the maximum deviation between the original path and the polygonal approximation is less than I<$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 I<$tolerance> is restricted to the smallest representable internal value.

  method set-tolerance ( Num() $tolerance )

=item $tolerance; the tolerance, in device units
=end pod

method set-tolerance ( Num() $tolerance ) {
  cairo_set_tolerance( self._get-native-object-no-reffing, $tolerance)
}

sub cairo_set_tolerance (
  cairo_t $cr, gdouble $tolerance
) is native(&cairo-lib)
  { * }

#`{{
#-------------------------------------------------------------------------------
# TM:0:set-user-data:
=begin pod
=head2 set-user-data

Attach user data to this context.  To remove user data from a surface, call this function with the key that was used to set it and C<Any> for I<data>.  Return value: C<CAIRO_STATUS_SUCCESS> or C<CAIRO_STATUS_NO_MEMORY> if a slot could not be allocated for the user data.

  method set-user-data ( cairo_user_data_key_t $key, void-ptr $user_data, cairo_destroy_func_t $destroy --> Int )

=item cairo_user_data_key_t $key; a B<cairo_t>
=item void-ptr $user_data; the address of a B<cairo_user_data_key_t> to attach the user data to
=item cairo_destroy_func_t $destroy; the user data to attach to the B<cairo_t>
=end pod

method set-user-data ( cairo_user_data_key_t $key, void-ptr $user_data, cairo_destroy_func_t $destroy --> Int ) {

  cairo_set_user_data(
    self._get-native-object-no-reffing, $key, $user_data, $destroy
  )
}

sub cairo_set_user_data (
  cairo_t $cr, cairo_user_data_key_t $key, void-ptr $user_data, cairo_destroy_func_t $destroy --> gint32
) is native(&cairo-lib)
  { * }
}}

#-------------------------------------------------------------------------------
#TM:0:show-glyphs:
=begin pod
=head2 show-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.

  method show-glyphs ( Array $glyphs )

=item $glyphs; array of glyphs to show
=item $num_glyphs; number of glyphs to show
=end pod

method show-glyphs ( Array $glyphs ) {
  my $gls = CArray[cairo_glyph_t].new;
  my int32 $num_glyphs = $glyphs.elems;

  my Int $i = 0;
  for @$glyphs -> $g {
    $gls[$i++] = $g;
  }

  cairo_show_glyphs(
    self._get-native-object-no-reffing, $gls, $num_glyphs
  );
}

sub cairo_show_glyphs (
  cairo_t $cr, CArray[cairo_glyph_t] $glyphs, int32 $num_glyphs
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:show-page:
=begin pod
=head2 show-page

Emits and clears the current page for backends that support multiple pages.  Use C<copy-page()> if you don't want to clear the page.

This is a convenience function that simply calls C<Gnome::Cairo::Surface.show-page()> on this context's target surface.

  method show-page ( )

=end pod

method show-page ( ) {
  cairo_show_page(self._get-native-object-no-reffing)
}

sub cairo_show_page (
  cairo_t $cr
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:4:show-text:
=begin pod
=head2 show-text

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 C<show-text()>.

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

  method show-text ( Str $utf8-string )

=item $utf8-string; a string to show
=end pod

method show-text ( Str $utf8-string ) {
  cairo_show_text( self._get-native-object-no-reffing, $utf8-string)
}

sub cairo_show_text (
  cairo_t $cr, gchar-ptr $utf8-string
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:show-text-glyphs:
=begin pod
=head2 show-text-glyphs

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

The mapping between I<utf8> and I<glyphs> is provided by an array of I<clusters>.  Each cluster covers a number of text bytes and glyphs, and neighboring clusters cover neighboring areas of I<utf8> and I<glyphs>.

The clusters should collectively cover I<utf8> and I<glyphs> in entirety.

The first cluster always covers bytes from the beginning of I<utf8>. If I<cluster_flags> do not have the C<CAIRO_TEXT_CLUSTER_FLAG_BACKWARD> set, the first cluster also covers the beginning of I<glyphs>, otherwise it covers the end of the I<glyphs> array and following clusters move backward.

See B<cairo_text_cluster_t> for constraints on valid clusters.

  method show-text-glyphs (
    Str $utf8, Array $glyphs, Array $clusters,
    cairo_text_cluster_flags_t $cluster_flags
  )

=item $utf8; a string of text encoded in UTF-8.
=item $glyphs; array of glyphs to show. Element type cairo_glyph_t.
=item $clusters; array of cluster mapping information. Element type cairo_text_cluster_t.
=item $cluster_flags; cluster mapping flags.
=end pod

method show-text-glyphs (
  Str $utf8, $glyphs, $clusters, Int $cluster_flags
) {
  my $gls = CArray[cairo_glyph_t].new;
  my $cls = CArray[cairo_text_cluster_t].new;
  my int32 $utf8_len = -1;
  my int32 $num_glyphs = $glyphs.elems;
  my int32 $num_clusters = $clusters.elems;

  loop ( my $i = 0; $i < $num_glyphs; $i++ ) {
    $gls[$i] = $glyphs[$i];
  }

  loop ( $i = 0; $i < $num_clusters; $i++ ) {
    $cls[$i] = $clusters[$i];
  }

  cairo_show_text_glyphs(
    self._get-native-object-no-reffing, $utf8, $utf8_len,
    $gls, $num_glyphs, $cls, $num_clusters, $cluster_flags
  )
}

sub cairo_show_text_glyphs (
  cairo_t $cr, gchar-ptr $utf8, int32 $utf8_len, CArray[cairo_glyph_t] $glyphs, int32 $num_glyphs, CArray[cairo_text_cluster_t] $clusters, int32 $num_clusters, GEnum $cluster_flags
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:status:
=begin pod
=head2 status

Checks whether an error has previously occurred for this context.

Returns: the current status of this context, see B<cairo_status_t>

  method status ( --> cairo_status_t )

=end pod

method status ( --> cairo_status_t ) {
  cairo_status_t(cairo_status(self._get-native-object-no-reffing))
}

sub cairo_status (
  cairo_t $cr --> gint32
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:status-to-string:
=begin pod
=head2 status-to-string

Provides a human-readable description of a cairo_status_t.

  method status-to-string ( cairo_status_t $status --> Str )

=end pod

method status-to-string ( cairo_status_t $status --> Str ) {
  cairo_status_to_string($status.value)
}

sub cairo_status_to_string ( int32 $status --> Str )
  is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:stroke:
=begin pod
=head2 stroke

A drawing operator that strokes the current path according to the