Class

Gjsgjs/cairodefaultContext

The main Cairo drawing context

A Cairo context is used to draw to surfaces and perform drawing operations. When you're done with a context, you must call $dispose() to free memory.

Hierarchy (View Summary)

Index

Constructors

Methods

  • Free a Cairo.Context and all associated memory

    Unlike other objects in GJS, Cairo contexts must be explicitly disposed to avoid memory leaks.

    Returns void

  • Adds a circular arc of the given radius to the current path

    Parameters

    • xc: number

      X coordinate of the center of the arc

    • yc: number

      Y coordinate of the center of the arc

    • radius: number

      Radius of the arc

    • angle1: number

      Starting angle in radians

    • angle2: number

      End angle in radians

    Returns void

  • Adds a circular arc of the given radius to the current path, but draws the arc in the opposite direction from arc()

    Parameters

    • xc: number

      X coordinate of the center of the arc

    • yc: number

      Y coordinate of the center of the arc

    • radius: number

      Radius of the arc

    • angle1: number

      Starting angle in radians

    • angle2: number

      End angle in radians

    Returns void

  • Establishes a new clip region by intersecting the current clip region with the current path, then clearing the current path

    Returns void

  • Returns the current clip extents as [x1, y1, x2, y2]

    Returns [number, number, number, number]

    An array with [x1, y1, x2, y2] clip extents

  • Like clip() but preserves the current path

    Returns void

  • Closes the current path by drawing a line to the beginning of the current subpath

    Returns void

  • Emits the current page, but doesn't clear it

    Returns void

  • Adds a cubic Bézier spline to the current path

    Parameters

    • x1: number

      X coordinate of the first control point

    • y1: number

      Y coordinate of the first control point

    • x2: number

      X coordinate of the second control point

    • y2: number

      Y coordinate of the second control point

    • x3: number

      X coordinate of the end point

    • y3: number

      Y coordinate of the end point

    Returns void

  • Transforms a coordinate from device space to user space

    Parameters

    • x: number

      X coordinate

    • y: number

      Y coordinate

    Returns [number, number]

    An array with [x, y] transformed coordinates

  • Transforms a distance vector from device space to user space

    Parameters

    • x: number

      X component of the distance vector

    • y: number

      Y component of the distance vector

    Returns [number, number]

    An array with [x, y] transformed distance vector

  • Fills the current path using the current fill rule, then clears the path

    Returns void

  • Returns the current fill extents as [x1, y1, x2, y2]

    Returns [number, number, number, number]

    An array with [x1, y1, x2, y2] fill extents

  • Fills the current path using the current fill rule, but doesn't clear the path

    Returns void

  • Gets the current antialiasing mode

    Returns Antialias

    The current antialiasing mode

  • Gets the current point of the current path

    Returns [number, number]

    An array with [x, y] coordinates of the current point

  • Gets the current dash count

    Returns number

    The number of elements in the current dash pattern

  • Gets the current fill rule

    Returns FillRule

    The current fill rule

  • Gets the current line cap style

    Returns LineCap

    The current line cap style

  • Gets the current line join style

    Returns LineJoin

    The current line join style

  • Gets the current line width

    Returns number

    The current line width

  • Gets the current miter limit

    Returns number

    The current miter limit

  • Gets the current compositing operator

    Returns Operator

    The current compositing operator

  • Gets the current tolerance value

    Returns number

    The current tolerance value

  • Checks if there is a current point defined

    Returns boolean

    True if there is a current point

  • Resets the current transformation matrix to the identity matrix

    Returns void

  • Tests whether the given point is inside the area filled by the current path

    Parameters

    • x: number

      X coordinate of the point to test

    • y: number

      Y coordinate of the point to test

    Returns boolean

    True if the point is inside the path

  • Tests whether the given point is inside the area that would be inked by the current path with the current line width and stroke parameters

    Parameters

    • x: number

      X coordinate of the point to test

    • y: number

      Y coordinate of the point to test

    Returns boolean

    True if the point would be inked

  • Adds a line to the current path from the current point to the given point

    Parameters

    • x: number

      X coordinate of the end point

    • y: number

      Y coordinate of the end point

    Returns void

  • Sets the current mask to a surface

    Parameters

    • surface: default.Surface

      A surface to use as mask

    • x: number

      X coordinate at which to place the origin of the surface

    • y: number

      Y coordinate at which to place the origin of the surface

    Returns void

  • Begins a new subpath at the given point

    Parameters

    • x: number

      X coordinate of the new position

    • y: number

      Y coordinate of the new position

    Returns void

  • Clears the current path and begins a new path

    Returns void

  • Begins a new subpath without changing the current point

    Returns void

  • Paints the current source everywhere within the current clip region

    Returns void

  • Paints the current source everywhere within the current clip region using the given alpha value

    Parameters

    • alpha: number

      Alpha value to use, between 0 and 1

    Returns void

  • Returns the current path extents as [x1, y1, x2, y2]

    Returns [number, number, number, number]

    An array with [x1, y1, x2, y2] path extents

  • Terminates the current pattern group and makes it the current source pattern

    Returns void

  • Temporarily redirects drawing to an intermediate surface

    Returns void

  • Temporarily redirects drawing to an intermediate surface with the given content

    Parameters

    • content: Content

      The content type for the group

    Returns void

  • Adds a rectangle to the current path

    Parameters

    • x: number

      X coordinate of the top-left corner

    • y: number

      Y coordinate of the top-left corner

    • width: number

      Width of the rectangle

    • height: number

      Height of the rectangle

    Returns void

  • Adds a cubic Bézier spline to the current path using relative coordinates

    Parameters

    • dx1: number

      X offset to the first control point from current point

    • dy1: number

      Y offset to the first control point from current point

    • dx2: number

      X offset to the second control point from current point

    • dy2: number

      Y offset to the second control point from current point

    • dx3: number

      X offset to the end point from current point

    • dy3: number

      Y offset to the end point from current point

    Returns void

  • Adds a line to the current path relative to the current point

    Parameters

    • dx: number

      X offset from the current point

    • dy: number

      Y offset from the current point

    Returns void

  • Begins a new subpath relative to the current point

    Parameters

    • dx: number

      X offset from the current point

    • dy: number

      Y offset from the current point

    Returns void

  • Resets the current clip region to its original, unrestricted state

    Returns void

  • Restores the context state from the stack

    Returns void

  • Rotates the current transformation matrix

    Parameters

    • angle: number

      Angle of rotation in radians

    Returns void

  • Saves the current context state to the stack

    Returns void

  • Scales the current transformation matrix

    Parameters

    • sx: number

      Scale factor for the X dimension

    • sy: number

      Scale factor for the Y dimension

    Returns void

  • Selects a font face

    Parameters

    • family: string

      A font family name

    • slant: number

      A font slant

    • weight: number

      A font weight

    Returns void

  • Sets the antialiasing mode

    Parameters

    • antialias: Antialias

      The new antialiasing mode

    Returns void

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

    Parameters

    • dashes: number[]

      Array of dash lengths

    • offset: number

      Offset into the dash pattern

    Returns void

  • Sets the current fill rule

    Parameters

    • fillRule: FillRule

      The new fill rule

    Returns void

  • Sets the current font size in user space units

    Parameters

    • size: number

      Font size in user space units

    Returns void

  • Sets the current line cap style

    Parameters

    • lineCap: LineCap

      The new line cap style

    Returns void

  • Sets the current line join style

    Parameters

    • lineJoin: LineJoin

      The new line join style

    Returns void

  • Sets the current line width

    Parameters

    • width: number

      The new line width

    Returns void

  • Sets the current miter limit

    Parameters

    • limit: number

      The new miter limit

    Returns void

  • Sets the current compositing operator

    Parameters

    • op: Operator

      The new compositing operator

    Returns void

  • Sets the source pattern to an RGB opaque color

    Parameters

    • red: number

      Red component, between 0 and 1

    • green: number

      Green component, between 0 and 1

    • blue: number

      Blue component, between 0 and 1

    Returns void

  • Sets the source pattern to an RGBA color

    Parameters

    • red: number

      Red component, between 0 and 1

    • green: number

      Green component, between 0 and 1

    • blue: number

      Blue component, between 0 and 1

    • alpha: number

      Alpha component, between 0 and 1

    Returns void

  • Sets the source pattern to the given surface

    Parameters

    • surface: default.Surface

      The new source surface

    • x: number

      X coordinate where to place the surface origin

    • y: number

      Y coordinate where to place the surface origin

    Returns void

  • Sets the tolerance used when converting paths to trapezoids

    Parameters

    • tolerance: number

      The new tolerance value

    Returns void

  • Emits the current page and clears it

    Returns void

  • Draws text at the current position

    Parameters

    • utf8: string

      A string of text encoded in UTF-8

    Returns void

  • Renders glyphs with embedded text and cluster mapping (e.g. for PDF/PS)

    Parameters

    • utf8: string

      UTF-8 text string

    • glyphs: default.Glyph[]

      Array of glyphs

    • clusters: TextCluster[]

      Cluster mapping (bytes to glyphs)

    • clusterFlags: TextClusterFlags

      Direction of cluster mapping

    Returns void

  • Strokes the current path using the current line width, line join, line cap, and dash settings, then clears the path

    Returns void

  • Returns the current stroke extents as [x1, y1, x2, y2]

    Returns [number, number, number, number]

    An array with [x1, y1, x2, y2] stroke extents

  • Like stroke() but preserves the current path

    Returns void

  • Gets the extents of the given text if it were drawn at the current point

    Parameters

    • utf8: string

      A string of text encoded in UTF-8

    Returns TextExtents

    Text extents information

  • Translates the current transformation matrix

    Parameters

    • tx: number

      Translation in the X direction

    • ty: number

      Translation in the Y direction

    Returns void

  • Transforms a coordinate from user space to device space

    Parameters

    • x: number

      X coordinate

    • y: number

      Y coordinate

    Returns [number, number]

    An array with [x, y] transformed coordinates

  • Transforms a distance vector from user space to device space

    Parameters

    • x: number

      X component of the distance vector

    • y: number

      Y component of the distance vector

    Returns [number, number]

    An array with [x, y] transformed distance vector