cairo.context
Module for [Context] class
class Context
Types 1
classContext : gobject.boxed.Boxed
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].
Methods
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...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 les...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 gre...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....void clipExtents(out double x1, out double y1, out double x2, out double y2)Computes a bounding box in user coordinates covering the area inside the current clip.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....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 th...cairo.rectangle_list.RectangleList copyClipRectangleList()Gets the current clip region as a list of rectangles in user coordinates. Never returns null.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.showP...cairo.path.Path copyPath()Creates a copy of the current path and returns it to the user as a #cairopatht. See #cairopathdata_t for hints on how to iterate over the returned data structure.cairo.path.Path copyPathFlat()Gets a flattened copy of the current path and returns it to the user as a #cairopatht. See #cairopathdata_t for hints on how to iterate over the returned data structure.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 w...void deviceToUser(out double x, out 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).void deviceToUserDistance(out double dx, out 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 ignor...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 wil...void fillExtents(out double x1, out double y1, out double x2, out 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 ...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.Cont...void fontExtents(out cairo.types.FontExtents extents)Gets the font extents for the currently selected font.cairo.types.Antialias getAntialias()Gets the current shape antialiasing mode, as set by [cairo.context.Context.setAntialias]. Returns: the current shape antialiasing mode.void getCurrentPoint(out double x, out double y)Gets the current point of the current path, which is conceptually the final point reached by the path so far.void getDash(out double dashes, out 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].int getDashCount()This function returns the length of the dash array in cr (0 if dashing is not currently in effect).cairo.types.FillRule getFillRule()Gets the current fill rule, as set by [cairo.context.Context.setFillRule]. Returns: the current fill rule.cairo.font_face.FontFace getFontFace()Gets the current font face for a #cairot. Returns: the current font face. This object is owned by cairo. To keep a reference to it, you must call [cairo.fontface.FontFace.reference].void getFontMatrix(out cairo.matrix.Matrix matrix)Stores the current font matrix into matrix. See [cairo.context.Context.setFontMatrix].void getFontOptions(cairo.font_options.FontOptions options)Retrieves font rendering options set via #cairosetfont_options. Note that the returned options do not include any options derived from the underlying surface; they are literally the options passed ...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 mos...cairo.types.Bool getHairline()Returns whether or not hairline mode is set, as set by [cairo.context.Context.setHairline]. Returns: whether hairline mode is set.cairo.types.LineCap getLineCap()Gets the current line cap style, as set by [cairo.context.Context.setLineCap]. Returns: the current line cap style.cairo.types.LineJoin getLineJoin()Gets the current line join style, as set by [cairo.context.Context.setLineJoin]. Returns: the current line join style.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.c...void getMatrix(out cairo.matrix.Matrix matrix)Stores the current transformation matrix (CTM) into matrix.double getMiterLimit()Gets the current miter limit, as set by [cairo.context.Context.setMiterLimit]. Returns: the current miter limit.cairo.types.Operator getOperator()Gets the current compositing operator for a cairo context. Returns: the current compositing operator.cairo.scaled_font.ScaledFont getScaledFont()Gets the current scaled font for a #cairot. Returns: the current scaled font. This object is owned by cairo. To keep a reference to it, you must call [cairo.scaledfont.ScaledFont.reference].cairo.pattern.Pattern getSource()Gets the current source pattern for cr. Returns: the current source pattern. This object is owned by cairo. To keep a reference to it, you must call [cairo.pattern.Pattern.reference].cairo.surface.Surface getTarget()Gets the target surface for the cairo context as passed to [cairo.global.create].double getTolerance()Gets the current tolerance value, as set by [cairo.context.Context.setTolerance]. Returns: the current tolerance value.void glyphExtents(cairo.glyph.Glyph glyphs, int numGlyphs, out 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])....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].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. Returns: whether a current point is defined.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 on...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.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 ar...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...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`).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.)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.)void moveTo(double x, double y)Begin a new sub-path. After this call the current point will be (`x`, `y`).void newPath()Clears the current path. After this call there will be no path and no current point.void newSubPath()Begin a new sub-path. Note that the existing path is not affected. After this call there will be no current point.void paint()A drawing operator that paints the current source everywhere within the current clip region.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 t...void pathExtents(out double x1, out double y1, out double x2, out 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, sur...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 opera...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...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...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...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.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 ...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 ...void relMoveTo(double dx, double dy)Begin a new sub-path. After this call the current point will offset by (x, y).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 ...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.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 rotatio...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 ca...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.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 expec...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 suppo...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" po...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 affe...void setFontFace(cairo.font_face.FontFace fontFace)Replaces the current #cairofontfacet object in the #cairot with fontface. The replaced font face in the #cairot will be destroyed if there are no other references to it.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...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 ...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...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.void setLineCap(cairo.types.LineCap lineCap)Sets the current line cap style within the cairo context. See #cairolinecap_t for details about how the available line cap styles are drawn.void setLineJoin(cairo.types.LineJoin lineJoin)Sets the current line join style within the cairo context. See #cairolinejoin_t for details about how the available line join styles are drawn.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 ...void setMatrix(cairo.matrix.Matrix matrix)Modifies the current transformation matrix (CTM) by setting it equal to matrix.void setMiterLimit(double limit)Sets the current miter limit within the cairo context.void setOperator(cairo.types.Operator op)Sets the compositing operator to be used for all drawing operations. See #cairooperatort for details on the semantics of each available compositing operator.void setScaledFont(cairo.scaled_font.ScaledFont scaledFont)Replaces the current font face, font matrix, and font options in the #cairot with those of the #cairoscaledfontt. Except for some translation, the current CTM of the #cairot should be the same as ...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.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.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.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].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 i...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.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.void showText(string utf8)A drawing operator that generates the shape from a string of UTF-8 characters, rendered according to the current fontface, fontsize (fontmatrix), and fontoptions.void showTextGlyphs(string utf8, 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 glyph...cairo.types.Status status()Checks whether an error has previously occurred for this context. Returns: the current status of this context, see #cairostatustvoid 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 ...void strokeExtents(out double x1, out double y1, out double x2, out 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....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.strokePre...void tagBegin(string tagName, string attributes)Marks the beginning of the tagname structure. Call [cairo.context.Context.tagEnd] with the same tagname to mark the end of the structure.void tagEnd(string tagName)Marks the end of the tag_name structure.void textExtents(string utf8, out 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]). Additio...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].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.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...void userToDevice(out double x, out double y)Transform a coordinate from user space to device space by multiplying the given point by the current transformation matrix (CTM).void userToDeviceDistance(out double dx, out 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 ...