Context

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

Cairo contexts, as #cairo_t objects are named, are central to cairo and all drawing with cairo is always done to a #cairo_t object.

Memory management of #cairo_t is done with cairo.global.reference and cairo.global.destroy.

class Context : Boxed {}

Members

Functions

appendPath
void appendPath(cairo.path.Path path)

Append the path onto the current path. The path may be either the return value from one of cairo.context.Context.copyPath or cairo.context.Context.copyPathFlat or it may be constructed manually. See #cairo_path_t for details on how the path data structure should be initialized, and note that <literal>path->status</literal> must be initialized to cairo.types.Status.Success.

arc
void 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 <literal>2*M_PI</literal> until it is greater than angle1.

arcNegative
void arcNegative(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 <literal>2*M_PI</literal> until it is less than angle1.

clip
void clip()

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

clipExtents
void clipExtents(double x1, double y1, double x2, double y2)

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

clipPreserve
void clipPreserve()

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

closePath
void closePath()

Adds a line segment to the path from the current point to the beginning of the current sub-path, (the most recent point passed to cairo.context.Context.moveTo), and closes this sub-path. After this call the current point will be at the joined endpoint of the sub-path.

copyClipRectangleList
cairo.rectangle_list.RectangleList copyClipRectangleList()

Gets the current clip region as a list of rectangles in user coordinates. Never returns null.

copyPage
void copyPage()

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 cairo.context.Context.showPage if you want to get an empty page after the emission.

copyPath
cairo.path.Path copyPath()

Creates a copy of the current path and returns it to the user as a #cairo_path_t. See #cairo_path_data_t for hints on how to iterate over the returned data structure.

copyPathFlat
cairo.path.Path copyPathFlat()

Gets a flattened copy of the current path and returns it to the user as a #cairo_path_t. See #cairo_path_data_t for hints on how to iterate over the returned data structure.

curveTo
void curveTo(double x1, double y1, double x2, double y2, double x3, double y3)

Adds a cubic Bézier spline to the path from the current point to position (x3, y3) in user-space coordinates, using (x1, y1) and (x2, y2) as the control points. After this call the current point will be (x3, y3).

deviceToUser
void deviceToUser(double x, double y)

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

deviceToUserDistance
void deviceToUserDistance(double dx, double dy)

Transform a distance vector from device space to user space. This function is similar to cairo.context.Context.deviceToUser except that the translation components of the inverse CTM will be ignored when transforming (dx,dy).

fill
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). After cairo.context.Context.fill, the current path will be cleared from the cairo context. See cairo.context.Context.setFillRule and cairo.context.Context.fillPreserve.

fillExtents
void fillExtents(double x1, double y1, double x2, double y2)

Computes a bounding box in user coordinates covering the area that would be affected, (the "inked" area), by a cairo.context.Context.fill operation given the current path and fill parameters. If the current path is empty, returns an empty rectangle ((0,0), (0,0)). Surface dimensions and clipping are not taken into account.

fillPreserve
void fillPreserve()

A drawing operator that fills the current path according to the current fill rule, (each sub-path is implicitly closed before being filled). Unlike cairo.context.Context.fill, cairo.context.Context.fillPreserve preserves the path within the cairo context.

fontExtents
void fontExtents(cairo.types.FontExtents extents)

Gets the font extents for the currently selected font.

getAntialias
cairo.types.Antialias getAntialias()

Gets the current shape antialiasing mode, as set by cairo.context.Context.setAntialias.

getCurrentPoint
void getCurrentPoint(double x, double y)

Gets the current point of the current path, which is conceptually the final point reached by the path so far.

getDash
void getDash(double dashes, double offset)

Gets the current dash array. If not null, dashes should be big enough to hold at least the number of values returned by cairo.context.Context.getDashCount.

getDashCount
int getDashCount()

This function returns the length of the dash array in cr (0 if dashing is not currently in effect).

getFillRule
cairo.types.FillRule getFillRule()

Gets the current fill rule, as set by cairo.context.Context.setFillRule.

getFontFace
cairo.font_face.FontFace getFontFace()

Gets the current font face for a #cairo_t.

getFontMatrix
void getFontMatrix(cairo.matrix.Matrix matrix)

Stores the current font matrix into matrix. See cairo.context.Context.setFontMatrix.

getFontOptions
void getFontOptions(cairo.font_options.FontOptions options)

Retrieves font rendering options set via #cairo_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 cairo.context.Context.setFontOptions.

getGroupTarget
cairo.surface.Surface getGroupTarget()

Gets the current destination surface for the context. This is either the original target surface as passed to cairo.global.create or the target surface for the current group as started by the most recent call to cairo.context.Context.pushGroup or cairo.context.Context.pushGroupWithContent.

getHairline
cairo.types.Bool getHairline()

Returns whether or not hairline mode is set, as set by cairo.context.Context.setHairline.

getLineCap
cairo.types.LineCap getLineCap()

Gets the current line cap style, as set by cairo.context.Context.setLineCap.

getLineJoin
cairo.types.LineJoin getLineJoin()

Gets the current line join style, as set by cairo.context.Context.setLineJoin.

getLineWidth
double getLineWidth()

This function returns the current line width value exactly as set by cairo.context.Context.setLineWidth. Note that the value is unchanged even if the CTM has changed between the calls to cairo.context.Context.setLineWidth and cairo.context.Context.getLineWidth.

getMatrix
void getMatrix(cairo.matrix.Matrix matrix)

Stores the current transformation matrix (CTM) into matrix.

getMiterLimit
double getMiterLimit()

Gets the current miter limit, as set by cairo.context.Context.setMiterLimit.

getOperator
cairo.types.Operator getOperator()

Gets the current compositing operator for a cairo context.

getScaledFont
cairo.scaled_font.ScaledFont getScaledFont()

Gets the current scaled font for a #cairo_t.

getSource
cairo.pattern.Pattern getSource()

Gets the current source pattern for cr.

getTarget
cairo.surface.Surface getTarget()

Gets the target surface for the cairo context as passed to cairo.global.create.

getTolerance
double getTolerance()

Gets the current tolerance value, as set by cairo.context.Context.setTolerance.

glyphExtents
void glyphExtents(cairo.glyph.Glyph glyphs, int numGlyphs, cairo.types.TextExtents 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 cairo.context.Context.showGlyphs). Additionally, the x_advance and y_advance values indicate the amount by which the current point would be advanced by cairo.context.Context.showGlyphs.

glyphPath
void glyphPath(cairo.glyph.Glyph glyphs, int numGlyphs)

Adds closed paths for the glyphs to the current path. The generated path if filled, achieves an effect similar to that of cairo.context.Context.showGlyphs.

hasCurrentPoint
cairo.types.Bool hasCurrentPoint()

Returns whether a current point is defined on the current path. See cairo.context.Context.getCurrentPoint for details on the current point.

identityMatrix
void identityMatrix()

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.

inClip
cairo.types.Bool inClip(double x, double y)

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 cairo.context.Context.paint operation.

inFill
cairo.types.Bool inFill(double x, double y)

Tests whether the given point is inside the area that would be affected by a cairo.context.Context.fill operation given the current path and filling parameters. Surface dimensions and clipping are not taken into account.

inStroke
cairo.types.Bool inStroke(double x, double y)

Tests whether the given point is inside the area that would be affected by a cairo.context.Context.stroke operation given the current path and stroking parameters. Surface dimensions and clipping are not taken into account.

lineTo
void lineTo(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).

mask
void mask(cairo.pattern.Pattern pattern)

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

maskSurface
void maskSurface(cairo.surface.Surface surface, double surfaceX, double surfaceY)

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

moveTo
void moveTo(double x, double y)

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

newPath
void newPath()

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

newSubPath
void newSubPath()

Begin a new sub-path. Note that the existing path is not affected. After this call there will be no current point.

paint
void paint()

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

paintWithAlpha
void paintWithAlpha(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 cairo.context.Context.paint, but the drawing is faded out using the alpha value.

pathExtents
void pathExtents(double x1, double y1, double x2, double y2)

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.

popGroup
cairo.pattern.Pattern popGroup()

Terminates the redirection begun by a call to cairo.context.Context.pushGroup or cairo.context.Context.pushGroupWithContent and returns a new pattern containing the results of all drawing operations performed to the group.

popGroupToSource
void popGroupToSource()

Terminates the redirection begun by a call to cairo.context.Context.pushGroup or cairo.context.Context.pushGroupWithContent and installs the resulting pattern as the source pattern in the given cairo context.

pushGroup
void pushGroup()

Temporarily redirects drawing to an intermediate surface known as a group. The redirection lasts until the group is completed by a call to cairo.context.Context.popGroup or cairo.context.Context.popGroupToSource. 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).

pushGroupWithContent
void pushGroupWithContent(cairo.types.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 cairo.context.Context.popGroup or cairo.context.Context.popGroupToSource. 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).

rectangle
void rectangle(double x, double y, double width, double height)

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

relCurveTo
void relCurveTo(double dx1, double dy1, double dx2, double dy2, double dx3, double dy3)

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

relLineTo
void relLineTo(double dx, double dy)

Relative-coordinate version of cairo.context.Context.lineTo. 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).

relMoveTo
void relMoveTo(double dx, double dy)

Begin a new sub-path. After this call the current point will offset by (x, y).

resetClip
void resetClip()

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.

restore
void restore()

Restores cr to the state saved by a preceding call to cairo.context.Context.save and removes that state from the stack of saved states.

rotate
void rotate(double angle)

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.

save
void save()

Makes a copy of the current state of cr and saves it on an internal stack of saved states for cr. When cairo.context.Context.restore is called, cr will be restored to the saved state. Multiple calls to cairo.context.Context.save and cairo.context.Context.restore can be nested; each call to cairo.context.Context.restore restores the state from the matching paired cairo.context.Context.save.

scale
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. The scaling of the axes takes place after any existing transformation of user space.

selectFontFace
void selectFontFace(string family, cairo.types.FontSlant slant, cairo.types.FontWeight weight)

Note: The cairo.context.Context.selectFontFace 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.

setAntialias
void setAntialias(cairo.types.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.types.Antialias.Subpixel when drawing shapes.

setDash
void setDash(double[] dashes, double offset)

Sets the dash pattern to be used by cairo.context.Context.stroke. A dash pattern is specified by dashes, an array of positive values. Each value provides the length of alternate "on" and "off" portions of the stroke. The offset specifies an offset into the pattern at which the stroke begins.

setFillRule
void setFillRule(cairo.types.FillRule fillRule)

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 cairo.context.Context.fill and cairo.context.Context.clip. See #cairo_fill_rule_t for details on the semantics of each available fill rule.

setFontFace
void setFontFace(cairo.font_face.FontFace fontFace)

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

setFontMatrix
void setFontMatrix(cairo.matrix.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 cairo.context.Context.setFontSize), but a more complex font matrix can be used to shear the font or stretch it unequally along the two axes

setFontOptions
void setFontOptions(cairo.font_options.FontOptions options)

Sets a set of custom font rendering options for the #cairo_t. 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.types.Antialias.Default), then the value from the surface is used.

setFontSize
void setFontSize(double size)

Sets the current font matrix to a scale by a factor of size, replacing any font matrix previously set with cairo.context.Context.setFontSize or cairo.context.Context.setFontMatrix. 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.)

setHairline
void setHairline(cairo.types.Bool setHairline)

Sets lines within the cairo context to be hairlines. Hairlines are logically zero-width lines that are drawn at the thinnest renderable width possible in the current context.

setLineCap
void setLineCap(cairo.types.LineCap lineCap)

Sets the current line cap style within the cairo context. See #cairo_line_cap_t for details about how the available line cap styles are drawn.

setLineJoin
void setLineJoin(cairo.types.LineJoin lineJoin)

Sets the current line join style within the cairo context. See #cairo_line_join_t for details about how the available line join styles are drawn.

setLineWidth
void setLineWidth(double 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).

setMatrix
void setMatrix(cairo.matrix.Matrix matrix)

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

setMiterLimit
void setMiterLimit(double limit)

Sets the current miter limit within the cairo context.

setOperator
void setOperator(cairo.types.Operator op)

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

setScaledFont
void setScaledFont(cairo.scaled_font.ScaledFont scaledFont)

Replaces the current font face, font matrix, and font options in the #cairo_t with those of the #cairo_scaled_font_t. Except for some translation, the current CTM of the #cairo_t should be the same as that of the #cairo_scaled_font_t, which can be accessed using cairo.scaled_font.ScaledFont.getCtm.

setSource
void setSource(cairo.pattern.Pattern source)

Sets the source pattern within cr to source. This pattern will then be used for any subsequent drawing operation until a new source pattern is set.

setSourceRgb
void setSourceRgb(double red, double green, double blue)

Sets the source pattern within cr to an opaque color. This opaque color will then be used for any subsequent drawing operation until a new source pattern is set.

setSourceRgba
void setSourceRgba(double red, double green, double blue, double alpha)

Sets the source pattern within cr to a translucent color. This color will then be used for any subsequent drawing operation until a new source pattern is set.

setSourceSurface
void setSourceSurface(cairo.surface.Surface surface, double x, double y)

This is a convenience function for creating a pattern from surface and setting it as the source in cr with cairo.context.Context.setSource.

setTolerance
void setTolerance(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.

showGlyphs
void showGlyphs(cairo.glyph.Glyph glyphs, int numGlyphs)

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.

showPage
void showPage()

Emits and clears the current page for backends that support multiple pages. Use cairo.context.Context.copyPage if you don't want to clear the page.

showText
void showText(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.

showTextGlyphs
void showTextGlyphs(string utf8, int utf8Len, cairo.glyph.Glyph glyphs, int numGlyphs, cairo.text_cluster.TextCluster clusters, int numClusters, cairo.types.TextClusterFlags clusterFlags)

This operation has rendering effects similar to cairo.context.Context.showGlyphs 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 cairo.context.Context.showGlyphs as if it had been passed glyphs and num_glyphs.

status
cairo.types.Status status()

Checks whether an error has previously occurred for this context.

stroke
void stroke()

A drawing operator that strokes the current path according to the current line width, line join, line cap, and dash settings. After cairo.context.Context.stroke, the current path will be cleared from the cairo context. See cairo.context.Context.setLineWidth, cairo.context.Context.setLineJoin, cairo.context.Context.setLineCap, cairo.context.Context.setDash, and cairo.context.Context.strokePreserve.

strokeExtents
void strokeExtents(double x1, double y1, double x2, double y2)

Computes a bounding box in user coordinates covering the area that would be affected, (the "inked" area), by a cairo.context.Context.stroke operation given the current path and stroke parameters. If the current path is empty, returns an empty rectangle ((0,0), (0,0)). Surface dimensions and clipping are not taken into account.

strokePreserve
void strokePreserve()

A drawing operator that strokes the current path according to the current line width, line join, line cap, and dash settings. Unlike cairo.context.Context.stroke, cairo.context.Context.strokePreserve preserves the path within the cairo context.

tagBegin
void tagBegin(string tagName, string attributes)

Marks the beginning of the tag_name structure. Call cairo.context.Context.tagEnd with the same tag_name to mark the end of the structure.

tagEnd
void tagEnd(string tagName)

Marks the end of the tag_name structure.

textExtents
void textExtents(string utf8, cairo.types.TextExtents extents)

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

textPath
void textPath(string utf8)

Adds closed paths for text to the current path. The generated path if filled, achieves an effect similar to that of cairo.context.Context.showText.

transform
void transform(cairo.matrix.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.

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

userToDevice
void userToDevice(double x, double y)

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

userToDeviceDistance
void userToDeviceDistance(double dx, double dy)

Transform a distance vector from user space to device space. This function is similar to cairo.context.Context.userToDevice except that the translation components of the CTM will be ignored when transforming (dx,dy).

Inherited Members

From Boxed

cInstancePtr
void* cInstancePtr;

Pointer to the C boxed value

getType
GType getType()

Get the GType of this boxed type.

gType
GType gType [@property getter]

Boxed GType property.

self
Boxed self()

Convenience method to return this cast to a type. For use in D with statements.

copy_
void* copy_()

Make a copy of the wrapped C boxed data.

boxedCopy
void* boxedCopy(void* cBoxed)

Copy a C boxed value using g_boxed_copy.

boxedFree
void boxedFree(void* cBoxed)

Free a C boxed value using g_boxed_free.