API Reference / @gtkx/cairo / Context
Class: Context
Defined in: packages/cairo/src/context.ts:300
A cairo drawing context (cairo_t): the object every drawing operation goes through, holding the current path, source, transformation, clip and font state for one target surface. GTK hands one to draw callbacks and snapshots, and new Context(surface) creates one for offscreen drawing.
Constructors
Constructor
new Context(
target):Context
Defined in: packages/cairo/src/context.ts:314
Creates a context drawing onto target, throwing when it cannot be created, such as on a finished surface.
Parameters
target
Returns
Context
Properties
__type__
__type__:
bigint
Defined in: packages/cairo/src/context.ts:311
GType of CairoContext, the boxed type this class is registered under.
Methods
appendPath()
appendPath(
data):void
Defined in: packages/cairo/src/context.ts:860
Appends segments, as returned by copyPath, to the current path.
Parameters
data
PathData[]
Returns
void
arc()
arc(
xc,yc,radius,angle1,angle2):void
Defined in: packages/cairo/src/context.ts:351
Adds a circular arc centred on (xc, yc), drawn clockwise from angle1 to angle2.
Parameters
xc
number
yc
number
radius
number
angle1
number
angle2
number
Returns
void
arcNegative()
arcNegative(
xc,yc,radius,angle1,angle2):void
Defined in: packages/cairo/src/context.ts:356
Adds a circular arc centred on (xc, yc), drawn counter-clockwise from angle1 to angle2.
Parameters
xc
number
yc
number
radius
number
angle1
number
angle2
number
Returns
void
clip()
clip():
void
Defined in: packages/cairo/src/context.ts:411
Intersects the clip with the current path and clears the path.
Returns
void
clipExtents()
clipExtents():
Extents
Defined in: packages/cairo/src/context.ts:673
Returns the bounding box of the current clip.
Returns
clipPreserve()
clipPreserve():
void
Defined in: packages/cairo/src/context.ts:416
Intersects the clip with the current path and keeps the path.
Returns
void
closePath()
closePath():
void
Defined in: packages/cairo/src/context.ts:366
Closes the current sub-path with a line back to its start.
Returns
void
copyClipRectangleList()
copyClipRectangleList():
RectangleData[]
Defined in: packages/cairo/src/context.ts:698
Returns the current clip as a list of rectangles in user space.
Returns
copyPage()
copyPage():
void
Defined in: packages/cairo/src/context.ts:625
Emits the current page without clearing it, on surfaces that support pages.
Returns
void
copyPath()
copyPath():
PathData[]
Defined in: packages/cairo/src/context.ts:850
Returns a copy of the current path as segments.
Returns
PathData[]
copyPathFlat()
copyPathFlat():
PathData[]
Defined in: packages/cairo/src/context.ts:855
Returns a copy of the current path with curves flattened into line segments.
Returns
PathData[]
curveTo()
curveTo(
x1,y1,x2,y2,x3,y3):void
Defined in: packages/cairo/src/context.ts:346
Adds a cubic Bézier curve from the current point through two control points to (x3, y3).
Parameters
x1
number
y1
number
x2
number
y2
number
x3
number
y3
number
Returns
void
deviceToUser()
deviceToUser(
x,y):Point
Defined in: packages/cairo/src/context.ts:750
Maps a point from device space to user space.
Parameters
x
number
y
number
Returns
deviceToUserDistance()
deviceToUserDistance(
dx,dy):Distance
Defined in: packages/cairo/src/context.ts:757
Maps a distance from device space to user space, ignoring translation.
Parameters
dx
number
dy
number
Returns
fill()
fill():
void
Defined in: packages/cairo/src/context.ts:391
Fills the current path with the current fill rule and clears it.
Returns
void
fillExtents()
fillExtents():
Extents
Defined in: packages/cairo/src/context.ts:668
Returns the bounding box a fill of the current path would cover.
Returns
fillPreserve()
fillPreserve():
void
Defined in: packages/cairo/src/context.ts:396
Fills the current path and keeps it.
Returns
void
fontExtents()
fontExtents():
FontExtents
Defined in: packages/cairo/src/context.ts:589
Returns the metrics of the current font.
Returns
getAntialias()
getAntialias():
Antialias
Defined in: packages/cairo/src/context.ts:615
Returns the antialiasing mode.
Returns
getCurrentPoint()
getCurrentPoint():
Point|null
Defined in: packages/cairo/src/context.ts:645
Returns the current point of the path, or null when there is none.
Returns
Point | null
getDash()
getDash():
DashPattern
Defined in: packages/cairo/src/context.ts:481
Returns the dash pattern and its offset.
Returns
getDashCount()
getDashCount():
number
Defined in: packages/cairo/src/context.ts:476
Returns how many lengths the dash pattern has, zero for a solid line.
Returns
number
getFillRule()
getFillRule():
FillRule
Defined in: packages/cairo/src/context.ts:521
Returns the fill rule.
Returns
getFontFace()
getFontFace():
FontFace
Defined in: packages/cairo/src/context.ts:804
Returns the current font face, wrapped as its concrete class.
Returns
getFontMatrix()
getFontMatrix():
Matrix
Defined in: packages/cairo/src/context.ts:814
Returns the matrix mapping font space to user space.
Returns
getFontOptions()
getFontOptions():
FontOptions
Defined in: packages/cairo/src/context.ts:602
Returns a copy of the font rendering options set on the context.
Returns
getGroupTarget()
getGroupTarget():
Surface
Defined in: packages/cairo/src/context.ts:794
Returns the surface drawing currently goes to: the group surface inside a group, else the target.
Returns
getLineCap()
getLineCap():
LineCap
Defined in: packages/cairo/src/context.ts:456
Returns how the ends of stroked lines are drawn.
Returns
getLineJoin()
getLineJoin():
LineJoin
Defined in: packages/cairo/src/context.ts:466
Returns how the corners of stroked lines are joined.
Returns
getLineWidth()
getLineWidth():
number
Defined in: packages/cairo/src/context.ts:446
Returns the width of stroked lines.
Returns
number
getMatrix()
getMatrix():
Matrix
Defined in: packages/cairo/src/context.ts:718
Returns the transformation from user space to device space.
Returns
getMiterLimit()
getMiterLimit():
number
Defined in: packages/cairo/src/context.ts:501
Returns the miter limit.
Returns
number
getOperator()
getOperator():
Operator
Defined in: packages/cairo/src/context.ts:556
Returns the compositing operator.
Returns
getReferenceCount()
getReferenceCount():
number
Defined in: packages/cairo/src/context.ts:769
Returns the reference count of the underlying cairo_t.
Returns
number
getScaledFont()
getScaledFont():
ScaledFont
Defined in: packages/cairo/src/context.ts:827
Returns the scaled font text operations currently use.
Returns
getSource()
getSource():
Pattern
Defined in: packages/cairo/src/context.ts:658
Returns the current source pattern, wrapped as its concrete class.
Returns
getTarget()
getTarget():
Surface
Defined in: packages/cairo/src/context.ts:630
Returns the surface the context was created for, wrapped as its concrete class.
Returns
getTolerance()
getTolerance():
number
Defined in: packages/cairo/src/context.ts:511
Returns the tolerance used when curves are flattened.
Returns
number
glyphExtents()
glyphExtents(
glyphs):TextExtents
Defined in: packages/cairo/src/context.ts:842
Measures positioned glyphs with the current font.
Parameters
glyphs
Returns
glyphPath()
glyphPath(
glyphs):void
Defined in: packages/cairo/src/context.ts:837
Adds the outlines of positioned glyphs to the current path.
Parameters
glyphs
Returns
void
hasCurrentPoint()
hasCurrentPoint():
boolean
Defined in: packages/cairo/src/context.ts:640
Returns whether the path has a current point.
Returns
boolean
identityMatrix()
identityMatrix():
void
Defined in: packages/cairo/src/context.ts:731
Resets the transformation to the identity.
Returns
void
inClip()
inClip(
x,y):boolean
Defined in: packages/cairo/src/context.ts:693
Returns whether (x, y) lies inside the current clip.
Parameters
x
number
y
number
Returns
boolean
inFill()
inFill(
x,y):boolean
Defined in: packages/cairo/src/context.ts:688
Returns whether (x, y) lies inside the area a fill of the current path would cover.
Parameters
x
number
y
number
Returns
boolean
inStroke()
inStroke(
x,y):boolean
Defined in: packages/cairo/src/context.ts:683
Returns whether (x, y) lies inside the area a stroke of the current path would cover.
Parameters
x
number
y
number
Returns
boolean
lineTo()
lineTo(
x,y):void
Defined in: packages/cairo/src/context.ts:326
Adds a straight line from the current point to (x, y).
Parameters
x
number
y
number
Returns
void
mask()
mask(
pattern):void
Defined in: packages/cairo/src/context.ts:703
Paints the current source using the alpha channel of pattern as a mask.
Parameters
pattern
Returns
void
maskSurface()
maskSurface(
surface,x,y):void
Defined in: packages/cairo/src/context.ts:708
Paints the current source using the alpha channel of surface, placed at (x, y), as a mask.
Parameters
surface
x
number
y
number
Returns
void
moveTo()
moveTo(
x,y):void
Defined in: packages/cairo/src/context.ts:321
Begins a new sub-path at (x, y), which becomes the current point.
Parameters
x
number
y
number
Returns
void
newPath()
newPath():
void
Defined in: packages/cairo/src/context.ts:371
Clears the current path.
Returns
void
newSubPath()
newSubPath():
void
Defined in: packages/cairo/src/context.ts:376
Begins a new sub-path without a current point, so the next arc needs no leading moveTo.
Returns
void
paint()
paint():
void
Defined in: packages/cairo/src/context.ts:401
Paints the current source everywhere inside the clip.
Returns
void
paintWithAlpha()
paintWithAlpha(
alpha):void
Defined in: packages/cairo/src/context.ts:406
Paints the current source everywhere inside the clip, faded by alpha.
Parameters
alpha
number
Returns
void
pathExtents()
pathExtents():
Extents
Defined in: packages/cairo/src/context.ts:678
Returns the bounding box of the current path.
Returns
popGroup()
popGroup():
Pattern
Defined in: packages/cairo/src/context.ts:784
Ends the current group and returns what was drawn into it as a pattern.
Returns
popGroupToSource()
popGroupToSource():
void
Defined in: packages/cairo/src/context.ts:789
Ends the current group and installs what was drawn into it as the source.
Returns
void
pushGroup()
pushGroup():
void
Defined in: packages/cairo/src/context.ts:774
Redirects drawing to an intermediate surface until popGroup or popGroupToSource.
Returns
void
pushGroupWithContent()
pushGroupWithContent(
content):void
Defined in: packages/cairo/src/context.ts:779
Redirects drawing to an intermediate surface of the given content.
Parameters
content
Returns
void
rectangle()
rectangle(
x,y,width,height):void
Defined in: packages/cairo/src/context.ts:361
Adds a closed rectangular sub-path.
Parameters
x
number
y
number
width
number
height
number
Returns
void
relCurveTo()
relCurveTo(
dx1,dy1,dx2,dy2,dx3,dy3):void
Defined in: packages/cairo/src/context.ts:341
Adds a cubic Bézier curve whose control points and end point are offsets from the current point.
Parameters
dx1
number
dy1
number
dx2
number
dy2
number
dx3
number
dy3
number
Returns
void
relLineTo()
relLineTo(
dx,dy):void
Defined in: packages/cairo/src/context.ts:336
Adds a straight line from the current point to the point offset by (dx, dy).
Parameters
dx
number
dy
number
Returns
void
relMoveTo()
relMoveTo(
dx,dy):void
Defined in: packages/cairo/src/context.ts:331
Begins a new sub-path offset from the current point by (dx, dy).
Parameters
dx
number
dy
number
Returns
void
resetClip()
resetClip():
void
Defined in: packages/cairo/src/context.ts:421
Removes the clip, so drawing reaches the whole surface again.
Returns
void
restore()
restore():
void
Defined in: packages/cairo/src/context.ts:531
Restores the drawing state saved by the matching save.
Returns
void
rotate()
rotate(
angle):void
Defined in: packages/cairo/src/context.ts:546
Rotates user space by angle radians.
Parameters
angle
number
Returns
void
save()
save():
void
Defined in: packages/cairo/src/context.ts:526
Pushes the current drawing state (source, transformation, clip, line and font settings) onto a stack.
Returns
void
scale()
scale(
sx,sy):void
Defined in: packages/cairo/src/context.ts:541
Scales user space by sx and sy.
Parameters
sx
number
sy
number
Returns
void
selectFontFace()
selectFontFace(
family,slant,weight):void
Defined in: packages/cairo/src/context.ts:561
Selects a toy font face by family name, slant and weight.
Parameters
family
string
slant
weight
Returns
void
setAntialias()
setAntialias(
antialias):void
Defined in: packages/cairo/src/context.ts:610
Sets the antialiasing mode of the rasterizer.
Parameters
antialias
Returns
void
setDash()
setDash(
dashes,offset):void
Defined in: packages/cairo/src/context.ts:471
Sets the dash pattern of strokes as alternating on and off lengths; an empty list draws solid lines.
Parameters
dashes
number[]
offset
number
Returns
void
setFillRule()
setFillRule(
fillRule):void
Defined in: packages/cairo/src/context.ts:516
Sets the rule deciding which areas a self-intersecting path fills.
Parameters
fillRule
Returns
void
setFontFace()
setFontFace(
fontFace):void
Defined in: packages/cairo/src/context.ts:799
Sets the font face used by text operations.
Parameters
fontFace
Returns
void
setFontMatrix()
setFontMatrix(
matrix):void
Defined in: packages/cairo/src/context.ts:809
Sets the matrix mapping font space to user space, which sizes and shapes the glyphs.
Parameters
matrix
Returns
void
setFontOptions()
setFontOptions(
options):void
Defined in: packages/cairo/src/context.ts:597
Sets the font rendering options merged over the surface's defaults.
Parameters
options
Returns
void
setFontSize()
setFontSize(
size):void
Defined in: packages/cairo/src/context.ts:566
Sets the font size in user space, replacing the font matrix with a uniform scale.
Parameters
size
number
Returns
void
setLineCap()
setLineCap(
lineCap):void
Defined in: packages/cairo/src/context.ts:451
Sets how the ends of stroked lines are drawn.
Parameters
lineCap
Returns
void
setLineJoin()
setLineJoin(
lineJoin):void
Defined in: packages/cairo/src/context.ts:461
Sets how the corners of stroked lines are joined.
Parameters
lineJoin
Returns
void
setLineWidth()
setLineWidth(
width):void
Defined in: packages/cairo/src/context.ts:441
Sets the width of stroked lines in user space.
Parameters
width
number
Returns
void
setMatrix()
setMatrix(
matrix):void
Defined in: packages/cairo/src/context.ts:713
Replaces the transformation from user space to device space.
Parameters
matrix
Returns
void
setMiterLimit()
setMiterLimit(
limit):void
Defined in: packages/cairo/src/context.ts:496
Sets the miter limit above which a mitered join is drawn beveled.
Parameters
limit
number
Returns
void
setOperator()
setOperator(
op):void
Defined in: packages/cairo/src/context.ts:551
Sets the compositing operator used by drawing operations.
Parameters
op
Returns
void
setScaledFont()
setScaledFont(
scaledFont):void
Defined in: packages/cairo/src/context.ts:822
Replaces the font face, font matrix and font options with those of scaledFont.
Parameters
scaledFont
Returns
void
setSource()
setSource(
pattern):void
Defined in: packages/cairo/src/context.ts:436
Sets the source pattern drawing operations paint with.
Parameters
pattern
Returns
void
setSourceRgb()
setSourceRgb(
red,green,blue):void
Defined in: packages/cairo/src/context.ts:426
Sets the source to an opaque color with components in the 0 to 1 range.
Parameters
red
number
green
number
blue
number
Returns
void
setSourceRgba()
setSourceRgba(
red,green,blue,alpha):void
Defined in: packages/cairo/src/context.ts:431
Sets the source to a translucent color with components in the 0 to 1 range.
Parameters
red
number
green
number
blue
number
alpha
number
Returns
void
setSourceSurface()
setSourceSurface(
surface,x,y):void
Defined in: packages/cairo/src/context.ts:635
Sets the source to surface placed with its origin at (x, y) in user space.
Parameters
surface
x
number
y
number
Returns
void
setTolerance()
setTolerance(
tolerance):void
Defined in: packages/cairo/src/context.ts:506
Sets the tolerance used when curves are flattened into line segments.
Parameters
tolerance
number
Returns
void
showGlyphs()
showGlyphs(
glyphs):void
Defined in: packages/cairo/src/context.ts:832
Draws positioned glyphs with the current font.
Parameters
glyphs
Returns
void
showPage()
showPage():
void
Defined in: packages/cairo/src/context.ts:620
Emits the current page and clears it, on surfaces that support pages.
Returns
void
showText()
showText(
text):void
Defined in: packages/cairo/src/context.ts:571
Draws text with the current font at the current point.
Parameters
text
string
Returns
void
showTextGlyphs()
showTextGlyphs(
text,glyphs,clusters,clusterFlags):void
Defined in: packages/cairo/src/context.ts:877
Draws glyphs together with the text and clusters they came from, so the backend can keep the text.
Parameters
text
string
glyphs
clusters
clusterFlags
number
Returns
void
status()
status():
Status
Defined in: packages/cairo/src/context.ts:764
Returns the error status of the context, Status.SUCCESS while every operation so far succeeded.
Returns
stroke()
stroke():
void
Defined in: packages/cairo/src/context.ts:381
Strokes the current path with the current line settings and clears it.
Returns
void
strokeExtents()
strokeExtents():
Extents
Defined in: packages/cairo/src/context.ts:663
Returns the bounding box a stroke of the current path would cover.
Returns
strokePreserve()
strokePreserve():
void
Defined in: packages/cairo/src/context.ts:386
Strokes the current path and keeps it.
Returns
void
tagBegin()
tagBegin(
tagName,attributes):void
Defined in: packages/cairo/src/context.ts:867
Opens a tagged structure, such as a link or a destination, on surfaces that record tags.
Parameters
tagName
string
attributes
string
Returns
void
tagEnd()
tagEnd(
tagName):void
Defined in: packages/cairo/src/context.ts:872
Closes the tagged structure opened by the matching tagBegin.
Parameters
tagName
string
Returns
void
textExtents()
textExtents(
text):TextExtents
Defined in: packages/cairo/src/context.ts:581
Measures text with the current font.
Parameters
text
string
Returns
textPath()
textPath(
text):void
Defined in: packages/cairo/src/context.ts:576
Adds the outlines of text to the current path.
Parameters
text
string
Returns
void
transform()
transform(
matrix):void
Defined in: packages/cairo/src/context.ts:726
Applies matrix before the existing transformation.
Parameters
matrix
Returns
void
translate()
translate(
tx,ty):void
Defined in: packages/cairo/src/context.ts:536
Moves the user-space origin by (tx, ty).
Parameters
tx
number
ty
number
Returns
void
userToDevice()
userToDevice(
x,y):Point
Defined in: packages/cairo/src/context.ts:736
Maps a point from user space to device space.
Parameters
x
number
y
number
Returns
userToDeviceDistance()
userToDeviceDistance(
dx,dy):Distance
Defined in: packages/cairo/src/context.ts:743
Maps a distance from user space to device space, ignoring translation.
Parameters
dx
number
dy
number
Returns
create()
staticcreate(target):Context
Defined in: packages/cairo/src/context.ts:306
Creates a context drawing onto target, the same as new Context(target).
Parameters
target
Returns
Context