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

#-------------------------------------------------------------------------------
#TM:1:get-group-target:
=begin pod
=head2 get-group-target

Gets the current destination surface for the context. This is either the original target surface as passed to C<new(:surface)> or the target surface for the current group as started by the most recent call to C<push-group()> or C<push-group-with-content()>.

This function will always return a valid pointer, but the result can be a "nil" surface if this context is already in an error state, (ie. C<$context.status() ≠ CAIRO_STATUS_SUCCESS>). A nil surface is indicated by C<Gnome::Cairo::Surface.status() ≠ CAIRO_STATUS_SUCCESS>.

Return value: the target surface. This object is owned by cairo. To keep a reference to it, you must call C<surface-reference()>.

  method get-group-target ( --> Gnome::Cairo::Surface )

=end pod

method get-group-target ( --> Any ) {
  self._wrap-native-type(
    'Gnome::Cairo::Surface',
    cairo_get_group_target(self._get-native-object-no-reffing)
  )
}

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

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

Gets the current line cap style, as set by C<set-line-cap()>.

Return value: the current line cap style.

  method get-line-cap ( --> cairo_line_cap_t )

=end pod

method get-line-cap ( --> cairo_line_cap_t ) {
  cairo_line_cap_t(cairo_get_line_cap(self._get-native-object-no-reffing))
}

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

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

Gets the current line join style, as set by C<set-line-join()>.  Return value: the current line join style.

  method get-line-join ( --> cairo_line_join_t )

=end pod

method get-line-join ( --> cairo_line_join_t ) {
  cairo_line_join_t(
    cairo_get_line_join(self._get-native-object-no-reffing)
  )
}

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

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

This function returns the current line width value exactly as set by C<set-line-width()>. Note that the value is unchanged even if the CTM has changed between the calls to C<set-line-width()> and C<get-line-width()>.

Return value: the current line width.

  method get-line-width ( --> Num )

=end pod

method get-line-width ( --> Num ) {
  cairo_get_line_width(self._get-native-object-no-reffing)
}

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

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

Stores the current transformation matrix (CTM) into I<matrix>.

  method get-matrix ( --> Gnome::Cairo::Matrix )

=end pod

method get-matrix ( --> Any ) {
  my cairo_matrix_t $matrix .= new;
  cairo_get_matrix( self._get-native-object-no-reffing, $matrix);
#note $matrix.gist;

  self._wrap-native-type( 'Gnome::Cairo::Matrix', $matrix)
}

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

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

Gets the current miter limit, as set by C<set-miter-limit()>.

Return value: the current miter limit.

  method get-miter-limit ( --> Num )

=end pod

method get-miter-limit ( --> Num ) {
  cairo_get_miter_limit(self._get-native-object-no-reffing)
}

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

#`{{TODO does not exist?
#-------------------------------------------------------------------------------
# TM:0:get-opacity:
=begin pod
=head2 get-opacity

Gets the current compositing opacity for a cairo context.

Return value: the current compositing opacity.

  method get-opacity ( --> Num )

=end pod

method get-opacity ( --> Num ) {
  cairo_get_opacity(self._get-native-object-no-reffing)
}

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

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

Gets the current compositing operator for a cairo context.  Return value: the current compositing operator.

  method get-operator ( --> cairo_operator_t )

=end pod

method get-operator ( --> cairo_operator_t ) {
  cairo_operator_t(
    cairo_get_operator(self._get-native-object-no-reffing)
  )
}

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

#-------------------------------------------------------------------------------
#TM:1:_cairo_get_reference_count:
#`{{
=begin pod
=head2 get-reference-count

Returns the current reference count of this context.

Return value: the current reference count of this context.

If the object is a nil object, 0 will be returned.

  method get-reference-count ( --> Int )

=end pod

method get-reference-count ( --> Int ) {

  cairo_get_reference_count(
    self._get-native-object-no-reffing,
  )
}
}}

sub _cairo_get_reference_count (
  cairo_t $cr --> guint
) is native(&cairo-lib)
  is symbol('cairo_get_reference_count')
  { * }

#-------------------------------------------------------------------------------
#TM:1:get-scaled-font:
=begin pod
=head2 get-scaled-font

Gets the current scaled font for a B<cairo_t>.

Return value: the current scaled font. This object is owned by cairo.
=comment To keep a reference to it, you must call C<scaled-font-reference()>.

This function never returns C<Any>. If memory cannot be allocated, a special "nil" B<cairo_scaled_font_t> object will be returned on which C<scaled-font-status()> returns C<CAIRO_STATUS_NO_MEMORY>. Using this nil object will cause its error state to propagate to other objects it is passed to, (for example, calling C<set-scaled-font()> with a nil font will trigger an error that will shutdown the B<cairo_t> object).

  method get-scaled-font ( --> Gnome::Cairo::ScaledFont )

=end pod

method get-scaled-font ( --> Any ) {
  self._wrap-native-type(
    'Gnome::Cairo::ScaledFont',
    cairo_get_scaled_font(self._get-native-object-no-reffing)
  )
}

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

#-------------------------------------------------------------------------------
#TM:1:get-source:
=begin pod
=head2 get-source

Gets the current source pattern for this context.

Return value: the current source pattern. This object is owned by cairo.
=comment To keep a reference to it, you must call C<pattern-reference()>.

  method get-source ( --> Gnome::Cairo::Pattern )

=end pod

method get-source ( --> Any ) {
  self._wrap-native-type(
    'Gnome::Cairo::Pattern',
    cairo_get_source(self._get-native-object-no-reffing)
  )
}

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

#-------------------------------------------------------------------------------
#TM:1:get-target:
=begin pod
=head2 get-target

Gets the target surface for the cairo context as passed to C<create()>.  This function will always return a valid pointer, but the result can be a "nil" surface if this context is already in an error state, (ie. C<status()> C<!=> C<CAIRO_STATUS_SUCCESS>). A nil surface is indicated by C<surface-status()> C<!=> C<CAIRO_STATUS_SUCCESS>.  Return value: the target surface. This object is owned by cairo. To keep a reference to it, you must call C<surface-reference()>.

  method get-target ( --> Gnome::Cairo::Surface )

=end pod

method get-target ( --> Any ) {
  self._wrap-native-type(
    'Gnome::Cairo::Surface',
    cairo_get_target(self._get-native-object-no-reffing)
  )
}

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

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

Gets the current tolerance value, as set by C<set-tolerance()>.

Return value: the current tolerance value.

  method get-tolerance ( --> Num )

=end pod

method get-tolerance ( --> Num ) {
  cairo_get_tolerance(self._get-native-object-no-reffing)
}

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

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

Return user data previously attached to this context using the specified key.  If no user data has been attached with the given key this function returns C<Any>.  Return value: the user data previously attached or C<Any>.

  method get-user-data ( cairo_user_data_key_t $key )

=item cairo_user_data_key_t $key; a B<cairo_t>
=end pod

method get-user-data ( cairo_user_data_key_t $key ) {

  cairo_get_user_data(
    self._get-native-object-no-reffing, $key
  )
}

sub cairo_get_user_data (
  cairo_t $cr, cairo_user_data_key_t $key
) is native(&cairo-lib)
  { * }
}}

#-------------------------------------------------------------------------------
#TM:0:glyph-extents:
=begin pod
=head2 glyph-extents

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

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

  method glyph-extents (
    cairo_glyph_t $glyphs, Int $num_glyphs,
    cairo_text_extents_t $extents
  )

=item $glyphs; an array of B<glyph-t> objects
=item $num_glyphs; the number of elements in I<glyphs>
=item $extents; a B<text-extents-t> object into which the results will be stored
=end pod

method glyph-extents (
  cairo_glyph_t $glyphs, Int $num_glyphs, cairo_text_extents_t $extents
) {

  cairo_glyph_extents(
    self._get-native-object-no-reffing, $glyphs, $num_glyphs, $extents
  )
}

sub cairo_glyph_extents (
  cairo_t $cr, cairo_glyph_t $glyphs, int32 $num_glyphs, cairo_text_extents_t $extents
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:glyph-path:
=begin pod
=head2 glyph-path

Adds closed paths for the glyphs to the current path.  The generated path if filled, achieves an effect similar to that of C<show-glyphs()>.

  method glyph-path ( cairo_glyph_t $glyphs, Int $num_glyphs )

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

method glyph-path ( cairo_glyph_t $glyphs, Int $num_glyphs ) {
  cairo_glyph_path( self._get-native-object-no-reffing, $glyphs, $num_glyphs)
}

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

#-------------------------------------------------------------------------------
#TM:1:has-current-point:
=begin pod
=head2 has-current-point

Returns whether a current point is defined on the current path. See C<get-current-point()> for details on the current point.

Return value: whether a current point is defined.

  method has-current-point ( --> Bool )

=end pod

method has-current-point ( --> Bool ) {
  cairo_has_current_point(self._get-native-object-no-reffing).Bool
}

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

#-------------------------------------------------------------------------------
#TM:1:identity-matrix:
=begin pod
=head2 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.

  method identity-matrix ( )

=end pod

method identity-matrix ( ) {
  cairo_identity_matrix(self._get-native-object-no-reffing)
}

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

#-------------------------------------------------------------------------------
#TM:1:in-clip:
=begin pod
=head2 in-clip

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

See C<clip()>, and C<clip-preserve()>.

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

  method in-clip ( Num() $x, Num() $y --> Bool )

=item $x; X coordinate of the point to test
=item $y; Y coordinate of the point to test
=end pod

method in-clip ( Num() $x, Num() $y --> Bool ) {
  cairo_in_clip( self._get-native-object-no-reffing, $x, $y).Bool
}

sub cairo_in_clip (
  cairo_t $cr, gdouble $x, gdouble $y --> cairo_bool_t
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:in-fill:
=begin pod
=head2 in-fill

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

See C<fill()>, C<set-fill-rule()> and C<fill-preserve()>.

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

  method in-fill ( Num() $x, Num() $y --> Bool )

=item $x; X coordinate of the point to test
=item $y; Y coordinate of the point to test
=end pod

method in-fill ( Num() $x, Num() $y --> Bool ) {
  cairo_in_fill( self._get-native-object-no-reffing, $x, $y).Bool
}

sub cairo_in_fill (
  cairo_t $cr, gdouble $x, gdouble $y --> cairo_bool_t
) is native(&cairo-lib)
  { * }

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

Tests whether the given point is inside the area that would be affected by a C<stroke()> operation given the current path and stroking parameters. Surface dimensions and clipping are not taken into account.  See C<stroke()>, C<set-line-width()>, C<set-line-join()>, C<set-line-cap()>, C<set-dash()>, and C<stroke-preserve()>.  Return value: A non-zero value if the point is inside, or zero if outside.

  method in-stroke ( Num() $x, Num() $y --> Bool )

=item $x; X coordinate of the point to test
=item $y; Y coordinate of the point to test
=end pod

method in-stroke ( Num() $x, Num() $y --> Bool ) {
  cairo_in_stroke( self._get-native-object-no-reffing, $x, $y).Bool
}

sub cairo_in_stroke (
  cairo_t $cr, gdouble $x, gdouble $y --> cairo_bool_t
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:line-to:
=begin pod
=head2 line-to

Adds a line to the path from the current point to position (I<x>, I<y>) in user-space coordinates. After this call the current point will be (I<x>, I<y>).  If there is no current point before the call to C<line-to()> this function will behave as cairo_move_to(this context, I<x>, I<y>).

  method line-to ( Num() $x, Num() $y )

=item $x; the X coordinate of the end of the new line
=item $y; the Y coordinate of the end of the new line
=end pod

method line-to ( Num() $x, Num() $y ) {
  cairo_line_to( self._get-native-object-no-reffing, $x, $y)
}

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

#-------------------------------------------------------------------------------
#TM:4:mask:
=begin pod
=head2 mask

A drawing operator that paints the current source using the alpha channel of I<pattern> as a mask. (Opaque areas of I<pattern> are painted with the source, transparent areas are not painted.)

  method mask ( cairo_pattern_t $pattern )

=item $pattern; a pattern
=end pod

method mask ( $pattern is copy ) {
  $pattern .= get-native-object-no-reffing unless $pattern ~~ cairo_pattern_t;
  cairo_mask( self._get-native-object-no-reffing, $pattern)
}

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

#-------------------------------------------------------------------------------
#TM:0:mask-surface:
=begin pod
=head2 mask-surface

A drawing operator that paints the current source using the alpha channel of I<surface> as a mask. (Opaque areas of I<surface> are painted with the source, transparent areas are not painted.)

  method mask-surface (
    cairo_surface_t $surface, Num() $surface_x, Num() $surface_y
  )

=item $surface; a surface
=item $surface_x; X coordinate at which to place the origin of I<surface>
=item $surface_y; Y coordinate at which to place the origin of I<surface>
=end pod

method mask-surface (
  cairo_surface_t $surface, Num() $surface_x, Num() $surface_y
) {
  cairo_mask_surface(
    self._get-native-object-no-reffing, $surface, $surface_x, $surface_y
  )
}

sub cairo_mask_surface (
  cairo_t $cr, cairo_surface_t $surface, gdouble $surface_x, gdouble $surface_y
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:2:move-to:
=begin pod
=head2 move-to

Begin a new sub-path. After this call the current point will be (I<x>, I<y>).

  method move-to ( Num() $x, Num() $y )

=item $x; the X coordinate of the new position
=item $y; the Y coordinate of the new position
=end pod

method move-to ( Num() $x, Num() $y ) {
  cairo_move_to( self._get-native-object-no-reffing, $x, $y)
}

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

#-------------------------------------------------------------------------------
#TM:2:new-path:
=begin pod
=head2 new-path

Clears the current path. After this call there will be no path and no current point.

  method new-path ( )

=end pod

method new-path ( ) {
  cairo_new_path(self._get-native-object-no-reffing)
}

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

#-------------------------------------------------------------------------------
#TM:0:new-sub-path:
=begin pod
=head2 new-sub-path

Begin a new sub-path.

Note that the existing path is not affected. After this call there will be no current point.

In many cases, this call is not needed since new sub-paths are frequently started with C<move-to()>.

A call to C<new-sub-path()> is particularly useful when beginning a new sub-path with one of the C<arc()> calls. This makes things easier as it is no longer necessary to manually compute the arc's initial coordinates for a call to C<move-to()>.

  method new-sub-path ( )

=end pod

method new-sub-path ( ) {
  cairo_new_sub_path(self._get-native-object-no-reffing)
}

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

#-------------------------------------------------------------------------------
#TM:4:paint:
=begin pod
=head2 paint

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

  method paint ( )

=end pod
method paint ( ) {
  cairo_paint(self._get-native-object-no-reffing)
}

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

#-------------------------------------------------------------------------------
#TM:4:paint-with-alpha:
=begin pod
=head2 paint-with-alpha

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

  method paint-with-alpha ( Num() $alpha )

=item $alpha; alpha value, between 0 (transparent) and 1 (opaque)
=end pod

method paint-with-alpha ( Num() $alpha ) {
  cairo_paint_with_alpha( self._get-native-object-no-reffing, $alpha)
}

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

#-------------------------------------------------------------------------------
#TM:1:path-extents:
=begin pod
=head2 path-extents

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

The result of C<path-extents()> is defined as equivalent to the limit of C<stroke-extents()> with C<CAIRO_LINE_CAP_ROUND> as the line width approaches 0.0, (but never reaching the empty-rectangle returned by C<stroke-extents()> for a line width of 0.0).

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

  method path-extents ( --> List )

List returns;
=item Num; left of the resulting extents
=item Num; top of the resulting extents
=item Num; right of the resulting extents
=item Num; bottom of the resulting extents
=end pod

method path-extents ( --> List ) {

  my gdouble $x1;
  my gdouble $y1;
  my gdouble $x2;
  my gdouble $y2;

  cairo_path_extents( self._get-native-object-no-reffing, $x1, $y1, $x2, $y2);

  ( $x1.Num, $y1.Num, $x2.Num, $y2.Num)
}

sub cairo_path_extents (
  cairo_t $cr, gdouble $x1 is rw, gdouble $y1 is rw,
  gdouble $x2 is rw, gdouble $y2 is rw
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:0:pop-group:
=begin pod
=head2 pop-group

Terminates the redirection begun by a call to C<push-group()> or C<push-group-with-content()> and returns a new pattern containing the results of all drawing operations performed to the group.

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

Return value: a newly created (surface) pattern containing the results of all drawing operations performed to the group. The caller owns the returned object and should call C<clear-object()> when finished with it.

  method pop-group ( --> Gnome::Cairo::Pattern )

=end pod

method pop-group ( --> Any ) {
  self._wrap-native-type(
    'Gnome::Cairo::Pattern',
    cairo_pop_group(self._get-native-object-no-reffing)
  )
}

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

#-------------------------------------------------------------------------------
#TM:0:pop-group-to-source:
=begin pod
=head2 pop-group-to-source

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

  my Gnome::Cairo::Pattern $group = $cairo.pop-group;
  $cairo.set-source($group);
  $group.clear-object;

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

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

  method pop-group-to-source ( )

=end pod

method pop-group-to-source ( ) {
  cairo_pop_group_to_source(self._get-native-object-no-reffing)
}

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

#-------------------------------------------------------------------------------
#TM:0:push-group:
=begin pod
=head2 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 C<pop-group()> or C<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 C<push-group()>/C<pop-group()>. Each call pushes/pops the new target group onto/from a stack.

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

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

=begin code
  my Gnome::Cairo::Pattern $fill-pattern = …
  my Gnome::Cairo::Pattern $stroke-pattern = …
  my Num() $alpha = 0.8;

  with $cairo {
    .push-group;
    .set-source($fill-pattern);
    .fill-preserve;
    .set-source($stroke-pattern);
    .stroke;
    .pop-group-to-source;
    .paint-with-alpha($alpha);
  }
=end code

=begin code
  method push-group ( )
=end code
=end pod

method push-group ( ) {
  cairo_push_group(self._get-native-object-no-reffing)
}

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

#-------------------------------------------------------------------------------
#TM:1:push-group-with-content:
=begin pod
=head2 push-group-with-content

Temporarily redirects drawing to an intermediate surface known as a group. The redirection lasts until the group is completed by a call to C<pop-group()> or C<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 I<$content>. The ability to control this content type is the only distinction between this function and C<push-group()> which you should see for a more detailed description of group rendering.

  method push-group-with-content ( cairo_content_t $content )

=item $content; a B<content-t> indicating the type of group that will be created
=end pod

method push-group-with-content ( cairo_content_t $content ) {
  cairo_push_group_with_content(
    self._get-native-object-no-reffing, $content
  )
}

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

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

Adds a closed sub-path rectangle of the given size to the current path at position (I<$x>, I<$y>) in user-space coordinates. This method is logically equivalent to:

=begin code
  with $cairo {
    .move-to( $x, $y);
    .rel-line-to( $width, 0);
    .rel-line-to( 0, $height);
    .rel-line-to( -$width, 0);
    .close.path;
  }
=end code

=begin code
  method rectangle ( Num() $x, Num() $y, Num() $width, Num() $height )
=end code

=item $x; the X coordinate of the top left corner of the rectangle
=item $y; the Y coordinate to the top left corner of the rectangle
=item $width; the width of the rectangle
=item $height; the height of the rectangle
=end pod

method rectangle ( Num() $x, Num() $y, Num() $width, Num() $height ) {
  cairo_rectangle(
    self._get-native-object-no-reffing, $x, $y, $width, $height
  )
}

sub cairo_rectangle (
  cairo_t $cr, gdouble $x, gdouble $y, gdouble $width, gdouble $height
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:_cairo_reference:
#`{{
=begin pod
=head2 reference

Increases the reference count on this context by one. This prevents this context from being destroyed until a matching call to C<destroy()> is made.  Use C<get-reference-count()> to get the number of references to a B<cairo_t>.  Return value: the referenced B<cairo_t>.

  method reference ( --> cairo_t )

=end pod

method reference ( --> cairo_t ) {

  cairo_reference(
    self._get-native-object-no-reffing,
  )
}
}}

sub _cairo_reference (
  cairo_t $cr --> cairo_t
) is native(&cairo-lib)
  is symbol('cairo_reference')
  { * }

#-------------------------------------------------------------------------------
#TM:0:rel-curve-to:
=begin pod
=head2 rel-curve-to

Relative-coordinate version of C<curve-to()>. All offsets are relative to the current point. Adds a cubic Bézier spline to the path from the current point to a point offset from the current point by (I<$dx3, $dy3>), using points offset by (I<$dx1, $dy1>) and (I<$dx2, $dy2>) as the control points. After this call the current point will be offset by (I<$dx3, $dy3>).

Given a current point of C<($x, $y)>, then C<rel-curve-to( $dx1, $dy1, $dx2, $dy2, $dx3, $dy3)> is logically equivalent to C<curve-to( $x + $dx1, $y + $dy1, $x + $dx2, $y + $dy2, $x + dx3, $y + $dy3)>.

It is an error to call this function with no current point. Doing so will cause this context to shutdown with a status of C<CAIRO_STATUS_NO_CURRENT_POINT>.

  method rel-curve-to (
    Num() $dx1, Num() $dy1, Num() $dx2, Num() $dy2,
    Num() $dx3, Num() $dy3
  )

=item $dx1; the X offset to the first control point
=item $dy1; the Y offset to the first control point
=item $dx2; the X offset to the second control point
=item $dy2; the Y offset to the second control point
=item $dx3; the X offset to the end of the curve
=item $dy3; the Y offset to the end of the curve
=end pod

method rel-curve-to (
  Num() $dx1, Num() $dy1, Num() $dx2, Num() $dy2, Num() $dx3, Num() $dy3
) {
  cairo_rel_curve_to(
    self._get-native-object-no-reffing, $dx1, $dy1, $dx2, $dy2, $dx3, $dy3
  )
}

sub cairo_rel_curve_to (
  cairo_t $cr, gdouble $dx1, gdouble $dy1, gdouble $dx2, gdouble $dy2, gdouble $dx3, gdouble $dy3
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:4:rel-line-to:
=begin pod
=head2 rel-line-to

Relative-coordinate version of C<line-to()>. Adds a line to the path from the current point to a point that is offset from the current point by (I<$dx>, I<$dy>) in user space. After this call the current point will be offset by (I<$dx>, I<$dy>).

Given a current point of C<($x, $y)>, C<rel-line-to( $dx, $dy)> is logically equivalent to C<line_to( $x + $dx, $y + $dy)>.

It is an error to call this function with no current point. Doing so will cause this context to shutdown with a status of C<CAIRO_STATUS_NO_CURRENT_POINT>.

  method rel-line-to ( Num() $dx, Num() $dy )

=item $dx; the X offset to the end of the new line
=item $dy; the Y offset to the end of the new line
=end pod

method rel-line-to ( Num() $dx, Num() $dy ) {
  cairo_rel_line_to( self._get-native-object-no-reffing, $dx, $dy)
}

sub cairo_rel_line_to (
  cairo_t $cr, gdouble $dx, gdouble $dy
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:4:rel-move-to:
=begin pod
=head2 rel-move-to

Begin a new sub-path. After this call the current point will offset by C<( $x, $y)>.  Given a current point of C<($x, $y)>, C<rel-move-to( $dx, $dy)> is logically equivalent to C<move-to( $x + $dx, $y + $dy)>.

It is an error to call this function with no current point. Doing so will cause this context to shutdown with a status of C<CAIRO_STATUS_NO_CURRENT_POINT>.

  method rel-move-to ( Num() $dx, Num() $dy )

=item $dx; the X offset
=item $dy; the Y offset
=end pod

method rel-move-to ( Num() $dx, Num() $dy ) {
  cairo_rel_move_to( self._get-native-object-no-reffing, $dx, $dy)
}

sub cairo_rel_move_to (
  cairo_t $cr, gdouble $dx, gdouble $dy
) is native(&cairo-lib)
  { * }

#-------------------------------------------------------------------------------
#TM:1:reset-clip:
=begin pod
=head2 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 C<reset-clip()> as it will cause results unexpected by higher-level code which calls C<clip()>. Consider using C<save()> and C<restore()> around C<clip()> as a more robust means of temporarily restricting the clip region.

  method reset-clip ( )

=end pod

method reset-clip ( ) {
  cairo_reset_clip(self._get-native-object-no-reffing)
}

sub cairo_reset_clip (
  cairo_t $cr
) is native(&cairo-lib)
  {