Interface: CanvasRenderingContext2D
Defined in: types/desktop-engine.d.ts:1586
2D rendering context (Canvas2DRenderingContext); largely the same interface as on the web
Properties
canvas
readonly canvas: Canvas | null;Defined in: types/desktop-engine.d.ts:1588
The owning canvas
fillStyle
fillStyle:
| string
| CanvasGradient
| CanvasPattern;Defined in: types/desktop-engine.d.ts:1604
Fill style. Colors: #rgb, #rgba, #rrggbb, #rrggbbaa, rgb()/rgba() and hsl()/hsla() with commas or spaces (rgb(255 0 0 / 50%)), or a CSS color name; invalid colors are ignored, like on the web. Colors read back as an rgba(r,g,b,a) string
font
font: string;Defined in: types/desktop-engine.d.ts:1625
Font, the CSS font shorthand: [italic] [weight] size[/line-height] family[, family…], such as "600 14px system-ui" or "bold 16px 'Avenir Next', Helvetica"; defaults to 10px Helvetica.
- weight:
normal,boldor 1–1000 (400 normal, 700 bold) - size: px or pt; the line height is ignored
- family: the first installed one of the list.
system-ui(also-apple-system,BlinkMacSystemFont,ui-sans-serif) is the system font, San Francisco with PingFang for Chinese;ui-rounded,ui-monospaceandui-serifare its rounded, monospaced and serif (New York) designs;sans-serif,serifandmonospaceare Helvetica, Times and Courier. Without an installed family the font keeps its family
An invalid value is ignored. Reads back as [italic ][weight ]<size>px <family>, e.g. 600 14px system-ui
globalAlpha
globalAlpha: number;Defined in: types/desktop-engine.d.ts:1608
Global alpha
globalCompositeOperation
globalCompositeOperation: GlobalCompositeOperation;Defined in: types/desktop-engine.d.ts:1590
Compositing mode
imageSmoothingEnabled
imageSmoothingEnabled: boolean;Defined in: types/desktop-engine.d.ts:1635
Whether images are smoothed when scaled
letterSpacing
letterSpacing: string;Defined in: types/desktop-engine.d.ts:1631
Space added after each character of fillText, strokeText and measureText, a CSS length: "2px", "0.1em" (of the font's size; rem too), pt, pc, in, cm, mm, q, or "0" without a unit (it reads as "0px"); "0px" by default. Anything else is ignored (API 5)
lineCap
lineCap: CanvasLineCap;Defined in: types/desktop-engine.d.ts:1592
Line cap
lineDashOffset
lineDashOffset: number;Defined in: types/desktop-engine.d.ts:1637
Line dash offset
lineJoin
lineJoin: CanvasLineJoin;Defined in: types/desktop-engine.d.ts:1594
Line join
lineWidth
lineWidth: number;Defined in: types/desktop-engine.d.ts:1610
Line width
miterLimit
miterLimit: number;Defined in: types/desktop-engine.d.ts:1612
Miter limit
shadowBlur
shadowBlur: number;Defined in: types/desktop-engine.d.ts:1641
Shadow blur
shadowColor
shadowColor: string;Defined in: types/desktop-engine.d.ts:1639
Shadow color, as for fillStyle (reads back as an rgba() string)
shadowOffsetX
shadowOffsetX: number;Defined in: types/desktop-engine.d.ts:1643
Shadow x offset
shadowOffsetY
shadowOffsetY: number;Defined in: types/desktop-engine.d.ts:1645
Shadow y offset
strokeStyle
strokeStyle:
| string
| CanvasGradient
| CanvasPattern;Defined in: types/desktop-engine.d.ts:1606
Stroke style, colors as for fillStyle; colors read back as an rgba(r,g,b,a) string
textAlign
textAlign: CanvasTextAlign;Defined in: types/desktop-engine.d.ts:1596
Text alignment
textBaseline
textBaseline: CanvasTextBaseline;Defined in: types/desktop-engine.d.ts:1598
Text baseline
wordSpacing
wordSpacing: string;Defined in: types/desktop-engine.d.ts:1633
Space added after each space (and no-break space) besides letterSpacing, as for letterSpacing (API 5)
Methods
arc()
arc(
x,
y,
radius,
startAngle,
endAngle,
counterclockwise?
): void;Defined in: types/desktop-engine.d.ts:1737
Arc, clockwise unless counterclockwise; angles 2π or more apart draw the whole circle, equal angles nothing. Throws an IndexSizeError for a negative radius
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
radius | number |
startAngle | number |
endAngle | number |
counterclockwise? | boolean |
Returns
void
arcTo()
arcTo(
x1,
y1,
x2,
y2,
radius
): void;Defined in: types/desktop-engine.d.ts:1732
Arc tangent to two lines
Parameters
| Parameter | Type |
|---|---|
x1 | number |
y1 | number |
x2 | number |
y2 | number |
radius | number |
Returns
void
beginPath()
beginPath(): void;Defined in: types/desktop-engine.d.ts:1704
Begins a path
Returns
void
bezierCurveTo()
bezierCurveTo(
cp1x,
cp1y,
cp2x,
cp2y,
x,
y
): void;Defined in: types/desktop-engine.d.ts:1728
Cubic Bézier curve
Parameters
| Parameter | Type |
|---|---|
cp1x | number |
cp1y | number |
cp2x | number |
cp2y | number |
x | number |
y | number |
Returns
void
clearRect()
clearRect(
x,
y,
w,
h
): void;Defined in: types/desktop-engine.d.ts:1685
Clears a rectangle
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
w | number |
h | number |
Returns
void
clip()
Call Signature
clip(fillRule?): void;Defined in: types/desktop-engine.d.ts:1750
Clips to the current path
Parameters
| Parameter | Type |
|---|---|
fillRule? | CanvasFillRule |
Returns
void
Call Signature
clip(path, fillRule?): void;Defined in: types/desktop-engine.d.ts:1752
Clips to a Path2D (API 5)
Parameters
| Parameter | Type |
|---|---|
path | Path2D |
fillRule? | CanvasFillRule |
Returns
void
closePath()
closePath(): void;Defined in: types/desktop-engine.d.ts:1706
Closes the path
Returns
void
createConicGradient()
createConicGradient(
startAngle,
x,
y
): CanvasGradient;Defined in: types/desktop-engine.d.ts:1700
Creates a gradient around a point, starting at startAngle (radians, clockwise from the x axis): the offset of a color stop is the turn (0 to 1) (API 5)
Parameters
| Parameter | Type |
|---|---|
startAngle | number |
x | number |
y | number |
Returns
createImageData()
createImageData(
sw,
sh,
data?
): ImageData;Defined in: types/desktop-engine.d.ts:1689
Creates pixel data, optionally initialized from a Uint8ClampedArray (non-standard third argument)
Parameters
| Parameter | Type |
|---|---|
sw | number |
sh | number |
data? | Uint8ClampedArray<ArrayBufferLike> |
Returns
createLinearGradient()
createLinearGradient(
x0,
y0,
x1,
y1
): CanvasGradient;Defined in: types/desktop-engine.d.ts:1693
Creates a linear gradient
Parameters
| Parameter | Type |
|---|---|
x0 | number |
y0 | number |
x1 | number |
y1 | number |
Returns
createPattern()
createPattern(image, repetition?): CanvasPattern | undefined;Defined in: types/desktop-engine.d.ts:1702
Creates a pattern; defaults to repeat
Parameters
| Parameter | Type |
|---|---|
image | CanvasDrawable |
repetition? | CanvasPatternRepetition |
Returns
CanvasPattern | undefined
createRadialGradient()
createRadialGradient(
x0,
y0,
r0,
x1,
y1,
r1
): CanvasGradient;Defined in: types/desktop-engine.d.ts:1695
Creates a radial gradient
Parameters
| Parameter | Type |
|---|---|
x0 | number |
y0 | number |
r0 | number |
x1 | number |
y1 | number |
r1 | number |
Returns
drawImage()
Call Signature
drawImage(
image,
dx,
dy
): void;Defined in: types/desktop-engine.d.ts:1675
Draws an image at (dx, dy)
Parameters
| Parameter | Type |
|---|---|
image | CanvasDrawable |
dx | number |
dy | number |
Returns
void
Call Signature
drawImage(
image,
dx,
dy,
dw,
dh
): void;Defined in: types/desktop-engine.d.ts:1677
Draws an image into the given rectangle
Parameters
| Parameter | Type |
|---|---|
image | CanvasDrawable |
dx | number |
dy | number |
dw | number |
dh | number |
Returns
void
Call Signature
drawImage(
image,
sx,
sy,
sw,
sh,
dx,
dy,
dw,
dh
): void;Defined in: types/desktop-engine.d.ts:1679
Crops the source rectangle and draws it into the destination rectangle
Parameters
| Parameter | Type |
|---|---|
image | CanvasDrawable |
sx | number |
sy | number |
sw | number |
sh | number |
dx | number |
dy | number |
dw | number |
dh | number |
Returns
void
ellipse()
ellipse(
x,
y,
radiusX,
radiusY,
rotation,
startAngle,
endAngle,
counterclockwise?
): void;Defined in: types/desktop-engine.d.ts:1742
Elliptical arc around (x, y), turned by rotation (radians), its angles as arc's (API 5). Throws an IndexSizeError for a negative radius
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
radiusX | number |
radiusY | number |
rotation | number |
startAngle | number |
endAngle | number |
counterclockwise? | boolean |
Returns
void
fill()
Call Signature
fill(fillRule?): void;Defined in: types/desktop-engine.d.ts:1708
Fills the current path
Parameters
| Parameter | Type |
|---|---|
fillRule? | CanvasFillRule |
Returns
void
Call Signature
fill(path, fillRule?): void;Defined in: types/desktop-engine.d.ts:1710
Fills a Path2D; the current path stays as it is (API 5)
Parameters
| Parameter | Type |
|---|---|
path | Path2D |
fillRule? | CanvasFillRule |
Returns
void
fillRect()
fillRect(
x,
y,
w,
h
): void;Defined in: types/desktop-engine.d.ts:1681
Fills a rectangle
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
w | number |
h | number |
Returns
void
fillText()
fillText(
text,
x,
y,
maxWidth?
): void;Defined in: types/desktop-engine.d.ts:1746
Fills text
Parameters
| Parameter | Type |
|---|---|
text | string |
x | number |
y | number |
maxWidth? | number |
Returns
void
getImageData()
getImageData(
sx,
sy,
sw,
sh
): ImageData;Defined in: types/desktop-engine.d.ts:1687
Reads pixels
Parameters
| Parameter | Type |
|---|---|
sx | number |
sy | number |
sw | number |
sh | number |
Returns
getLineDash()
getLineDash(): number[];Defined in: types/desktop-engine.d.ts:1756
Gets the line dash pattern
Returns
number[]
getTransform()
getTransform(): TransformMatrix;Defined in: types/desktop-engine.d.ts:1671
The transform's matrix, a new object each time (API 5)
Returns
isContextLost()
isContextLost(): boolean;Defined in: types/desktop-engine.d.ts:1648
Whether the context was lost: the GPU stopped its work (see the canvas' contextlost event). It isn't restored
Returns
boolean
isPointInPath()
Call Signature
isPointInPath(
x,
y,
fillRule?
): boolean;Defined in: types/desktop-engine.d.ts:1763
Whether the point (in the canvas' pixels, whatever the transform) is inside the current path filled with the rule, or on its edge (API 5). Curves are flattened to within a fraction of a pixel, as they're drawn
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
fillRule? | CanvasFillRule |
Returns
boolean
Call Signature
isPointInPath(
path,
x,
y,
fillRule?
): boolean;Defined in: types/desktop-engine.d.ts:1765
The same for a Path2D, transformed by the context's transform (API 5)
Parameters
| Parameter | Type |
|---|---|
path | Path2D |
x | number |
y | number |
fillRule? | CanvasFillRule |
Returns
boolean
isPointInStroke()
Call Signature
isPointInStroke(x, y): boolean;Defined in: types/desktop-engine.d.ts:1770
Whether the point (in the canvas' pixels) is on what stroke() would draw of the current path, with the line's width, caps, joins and dash (API 5)
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
Returns
boolean
Call Signature
isPointInStroke(
path,
x,
y
): boolean;Defined in: types/desktop-engine.d.ts:1772
The same for a Path2D (API 5)
Parameters
| Parameter | Type |
|---|---|
path | Path2D |
x | number |
y | number |
Returns
boolean
lineTo()
lineTo(x, y): void;Defined in: types/desktop-engine.d.ts:1716
Draws a straight line
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
Returns
void
measureText()
measureText(text): TextMetrics;Defined in: types/desktop-engine.d.ts:1744
Measures text
Parameters
| Parameter | Type |
|---|---|
text | string |
Returns
moveTo()
moveTo(x, y): void;Defined in: types/desktop-engine.d.ts:1714
Moves the pen
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
Returns
void
putImageData()
putImageData(
imageData,
dx,
dy
): void;Defined in: types/desktop-engine.d.ts:1691
Writes pixels
Parameters
| Parameter | Type |
|---|---|
imageData | ImageData |
dx | number |
dy | number |
Returns
void
quadraticCurveTo()
quadraticCurveTo(
cpx,
cpy,
x,
y
): void;Defined in: types/desktop-engine.d.ts:1730
Quadratic Bézier curve
Parameters
| Parameter | Type |
|---|---|
cpx | number |
cpy | number |
x | number |
y | number |
Returns
void
rect()
rect(
x,
y,
w,
h
): void;Defined in: types/desktop-engine.d.ts:1718
Adds a rectangle to the path
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
w | number |
h | number |
Returns
void
resetClip()
resetClip(): void;Defined in: types/desktop-engine.d.ts:1754
Clears the clip (non-standard)
Returns
void
resetCurrentState()
resetCurrentState(): void;Defined in: types/desktop-engine.d.ts:1654
Resets the current state (non-standard)
Returns
void
resetTransform()
resetTransform(): void;Defined in: types/desktop-engine.d.ts:1673
Resets the transform matrix to the identity
Returns
void
restore()
restore(): void;Defined in: types/desktop-engine.d.ts:1652
Restores the state
Returns
void
rotate()
rotate(angle): void;Defined in: types/desktop-engine.d.ts:1656
Rotates (radians)
Parameters
| Parameter | Type |
|---|---|
angle | number |
Returns
void
roundRect()
roundRect(
x,
y,
w,
h,
radii?
): void;Defined in: types/desktop-engine.d.ts:1726
Adds a rectangle with rounded corners to the path, as a closed subpath, then starts a new one at (x, y) (API 5). radii is one radius or a list of 1 to 4: all corners; top left and bottom right, top right and bottom left; top left, top right and bottom left, bottom right; or each corner clockwise from the top left. A radius is a number, or { x, y } for an elliptical corner. Radii that don't fit are scaled down together. Throws a RangeError for a negative radius or another count
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
w | number |
h | number |
radii? | | number | DOMPointLike | (number | DOMPointLike)[] |
Returns
void
save()
save(): void;Defined in: types/desktop-engine.d.ts:1650
Saves the state
Returns
void
scale()
scale(x, y): void;Defined in: types/desktop-engine.d.ts:1660
Scales
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
Returns
void
setLineDash()
setLineDash(segments): void;Defined in: types/desktop-engine.d.ts:1758
Sets the line dash pattern
Parameters
| Parameter | Type |
|---|---|
segments | (string | number)[] |
Returns
void
setTransform()
Call Signature
setTransform(
a,
b,
c,
d,
e,
f
): void;Defined in: types/desktop-engine.d.ts:1664
Sets the transform matrix; a value that isn't finite leaves the transform as it is
Parameters
| Parameter | Type |
|---|---|
a | number |
b | number |
c | number |
d | number |
e | number |
f | number |
Returns
void
Call Signature
setTransform(transform?): void;Defined in: types/desktop-engine.d.ts:1669
Sets the transform to a matrix, such as one getTransform() gave; without one, to the identity (API 5). Throws a TypeError when a value's two names (a and m11…) differ
Parameters
| Parameter | Type |
|---|---|
transform? | DOMMatrix2DInit | null |
Returns
void
stroke()
stroke(path?): void;Defined in: types/desktop-engine.d.ts:1712
Strokes the current path, or a Path2D (API 5)
Parameters
| Parameter | Type |
|---|---|
path? | Path2D |
Returns
void
strokeRect()
strokeRect(
x,
y,
w,
h
): void;Defined in: types/desktop-engine.d.ts:1683
Strokes a rectangle
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
w | number |
h | number |
Returns
void
strokeText()
strokeText(
text,
x,
y,
maxWidth?
): void;Defined in: types/desktop-engine.d.ts:1748
Strokes text
Parameters
| Parameter | Type |
|---|---|
text | string |
x | number |
y | number |
maxWidth? | number |
Returns
void
transform()
transform(
a,
b,
c,
d,
e,
f
): void;Defined in: types/desktop-engine.d.ts:1662
Multiplies the current transform matrix
Parameters
| Parameter | Type |
|---|---|
a | number |
b | number |
c | number |
d | number |
e | number |
f | number |
Returns
void
translate()
translate(x, y): void;Defined in: types/desktop-engine.d.ts:1658
Translates
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
Returns
void
