Skip to content

Interface: ICanvasContext2D ​

Hierarchy ​

  • CanvasCompositing

  • CanvasDrawImage

  • CanvasDrawPath

  • CanvasFillStrokeStyles

  • CanvasFilters

  • CanvasImageData

  • CanvasImageSmoothing

  • CanvasPath

  • CanvasPathDrawingStyles

  • CanvasRect

  • CanvasShadowStyles

  • CanvasState

  • CanvasText

  • CanvasTextDrawingStyles

  • CanvasTransform

  • CanvasUserInterface

    ↳ ICanvasContext2D

Table of contents ​

Properties ​

Methods ​

Properties ​

globalAlpha ​

• globalAlpha: number

Inherited from ​

CanvasCompositing.globalAlpha

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:23


globalCompositeOperation ​

• globalCompositeOperation: GlobalCompositeOperation

Inherited from ​

CanvasCompositing.globalCompositeOperation

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:24


fillStyle ​

• fillStyle: string | CanvasGradient | CanvasPattern

Inherited from ​

CanvasFillStrokeStyles.fillStyle

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:49


strokeStyle ​

• strokeStyle: string | CanvasGradient | CanvasPattern

Inherited from ​

CanvasFillStrokeStyles.strokeStyle

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:50


filter ​

• filter: string

Inherited from ​

CanvasFilters.filter

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:58


imageSmoothingEnabled ​

• imageSmoothingEnabled: boolean

Inherited from ​

CanvasImageSmoothing.imageSmoothingEnabled

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:83


imageSmoothingQuality ​

• imageSmoothingQuality: ImageSmoothingQuality

Inherited from ​

CanvasImageSmoothing.imageSmoothingQuality

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:84


lineCap ​

• lineCap: CanvasLineCap

Inherited from ​

CanvasPathDrawingStyles.lineCap

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:101


lineDashOffset ​

• lineDashOffset: number

Inherited from ​

CanvasPathDrawingStyles.lineDashOffset

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:102


lineJoin ​

• lineJoin: CanvasLineJoin

Inherited from ​

CanvasPathDrawingStyles.lineJoin

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:103


lineWidth ​

• lineWidth: number

Inherited from ​

CanvasPathDrawingStyles.lineWidth

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:104


miterLimit ​

• miterLimit: number

Inherited from ​

CanvasPathDrawingStyles.miterLimit

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:105


canvas ​

• Readonly canvas: HTMLCanvasElement

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:138


shadowBlur ​

• shadowBlur: number

Inherited from ​

CanvasShadowStyles.shadowBlur

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:148


shadowColor ​

• shadowColor: string

Inherited from ​

CanvasShadowStyles.shadowColor

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:149


shadowOffsetX ​

• shadowOffsetX: number

Inherited from ​

CanvasShadowStyles.shadowOffsetX

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:150


shadowOffsetY ​

• shadowOffsetY: number

Inherited from ​

CanvasShadowStyles.shadowOffsetY

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:151


direction ​

• direction: CanvasDirection

Inherited from ​

CanvasTextDrawingStyles.direction

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:194


font ​

• font: string

Inherited from ​

CanvasTextDrawingStyles.font

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:195


textAlign ​

• textAlign: CanvasTextAlign

Inherited from ​

CanvasTextDrawingStyles.textAlign

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:196


textBaseline ​

• textBaseline: CanvasTextBaseline

Inherited from ​

CanvasTextDrawingStyles.textBaseline

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:197

Methods ​

drawImage ​

▸ drawImage(image, dx, dy): void

Parameters ​

NameType
imageany
dxnumber
dynumber

Returns ​

void

Inherited from ​

CanvasDrawImage.drawImage

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:29

▸ drawImage(image, dx, dy, dw, dh): void

Parameters ​

NameType
imageany
dxnumber
dynumber
dwnumber
dhnumber

Returns ​

void

Inherited from ​

CanvasDrawImage.drawImage

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:30

▸ drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh): void

Parameters ​

NameType
imageany
sxnumber
synumber
swnumber
shnumber
dxnumber
dynumber
dwnumber
dhnumber

Returns ​

void

Inherited from ​

CanvasDrawImage.drawImage

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:31


beginPath ​

▸ beginPath(): void

Returns ​

void

Inherited from ​

CanvasDrawPath.beginPath

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:35


clip ​

▸ clip(fillRule?): void

Parameters ​

NameType
fillRule?IWindingRule

Returns ​

void

Inherited from ​

CanvasDrawPath.clip

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:36

▸ clip(path, fillRule?): void

Parameters ​

NameType
pathIPath2D
fillRule?IWindingRule

Returns ​

void

Inherited from ​

CanvasDrawPath.clip

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:37


fill ​

▸ fill(fillRule?): void

Parameters ​

NameType
fillRule?IWindingRule

Returns ​

void

Inherited from ​

CanvasDrawPath.fill

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:38

▸ fill(path, fillRule?): void

Parameters ​

NameType
pathIPath2D
fillRule?IWindingRule

Returns ​

void

Inherited from ​

CanvasDrawPath.fill

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:39


isPointInPath ​

▸ isPointInPath(x, y, fillRule?): boolean

Parameters ​

NameType
xnumber
ynumber
fillRule?IWindingRule

Returns ​

boolean

Inherited from ​

CanvasDrawPath.isPointInPath

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:40

▸ isPointInPath(path, x, y, fillRule?): boolean

Parameters ​

NameType
pathIPath2D
xnumber
ynumber
fillRule?IWindingRule

Returns ​

boolean

Inherited from ​

CanvasDrawPath.isPointInPath

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:41


isPointInStroke ​

▸ isPointInStroke(x, y): boolean

Parameters ​

NameType
xnumber
ynumber

Returns ​

boolean

Inherited from ​

CanvasDrawPath.isPointInStroke

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:42

▸ isPointInStroke(path, x, y): boolean

Parameters ​

NameType
pathIPath2D
xnumber
ynumber

Returns ​

boolean

Inherited from ​

CanvasDrawPath.isPointInStroke

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:43


stroke ​

▸ stroke(): void

Returns ​

void

Inherited from ​

CanvasDrawPath.stroke

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:44

▸ stroke(path): void

Parameters ​

NameType
pathIPath2D

Returns ​

void

Inherited from ​

CanvasDrawPath.stroke

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:45


createConicGradient ​

▸ createConicGradient(startAngle, x, y): CanvasGradient

Parameters ​

NameType
startAnglenumber
xnumber
ynumber

Returns ​

CanvasGradient

Inherited from ​

CanvasFillStrokeStyles.createConicGradient

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:51


createLinearGradient ​

▸ createLinearGradient(x0, y0, x1, y1): CanvasGradient

Parameters ​

NameType
x0number
y0number
x1number
y1number

Returns ​

CanvasGradient

Inherited from ​

CanvasFillStrokeStyles.createLinearGradient

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:52


createPattern ​

▸ createPattern(image, repetition): CanvasPattern

Parameters ​

NameType
imageany
repetitionstring

Returns ​

CanvasPattern

Inherited from ​

CanvasFillStrokeStyles.createPattern

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:53


createRadialGradient ​

▸ createRadialGradient(x0, y0, r0, x1, y1, r1): CanvasGradient

Parameters ​

NameType
x0number
y0number
r0number
x1number
y1number
r1number

Returns ​

CanvasGradient

Inherited from ​

CanvasFillStrokeStyles.createRadialGradient

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:54


createImageData ​

▸ createImageData(sw, sh, settings?): ImageData

Parameters ​

NameType
swnumber
shnumber
settings?ImageDataSettings

Returns ​

ImageData

Inherited from ​

CanvasImageData.createImageData

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:75

▸ createImageData(imagedata): ImageData

Parameters ​

NameType
imagedataImageData

Returns ​

ImageData

Inherited from ​

CanvasImageData.createImageData

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:76


getImageData ​

▸ getImageData(sx, sy, sw, sh, settings?): ImageData

Parameters ​

NameType
sxnumber
synumber
swnumber
shnumber
settings?ImageDataSettings

Returns ​

ImageData

Inherited from ​

CanvasImageData.getImageData

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:77


putImageData ​

▸ putImageData(imagedata, dx, dy): void

Parameters ​

NameType
imagedataImageData
dxnumber
dynumber

Returns ​

void

Inherited from ​

CanvasImageData.putImageData

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:78

▸ putImageData(imagedata, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight): void

Parameters ​

NameType
imagedataImageData
dxnumber
dynumber
dirtyXnumber
dirtyYnumber
dirtyWidthnumber
dirtyHeightnumber

Returns ​

void

Inherited from ​

CanvasImageData.putImageData

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:79


arc ​

▸ arc(x, y, radius, startAngle, endAngle, anticlockwise?): void

Parameters ​

NameType
xnumber
ynumber
radiusnumber
startAnglenumber
endAnglenumber
anticlockwise?boolean

Returns ​

void

Inherited from ​

CanvasPath.arc

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:88


arcTo ​

▸ arcTo(x1, y1, x2, y2, radius): void

Parameters ​

NameType
x1number
y1number
x2number
y2number
radiusnumber

Returns ​

void

Inherited from ​

CanvasPath.arcTo

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:89


bezierCurveTo ​

▸ bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y): void

Parameters ​

NameType
cp1xnumber
cp1ynumber
cp2xnumber
cp2ynumber
xnumber
ynumber

Returns ​

void

Inherited from ​

CanvasPath.bezierCurveTo

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:90


closePath ​

▸ closePath(): void

Returns ​

void

Inherited from ​

CanvasPath.closePath

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:91


ellipse ​

▸ ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise?): void

Parameters ​

NameType
xnumber
ynumber
radiusXnumber
radiusYnumber
rotationnumber
startAnglenumber
endAnglenumber
anticlockwise?boolean

Returns ​

void

Inherited from ​

CanvasPath.ellipse

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:92


lineTo ​

▸ lineTo(x, y): void

Parameters ​

NameType
xnumber
ynumber

Returns ​

void

Inherited from ​

CanvasPath.lineTo

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:93


moveTo ​

▸ moveTo(x, y): void

Parameters ​

NameType
xnumber
ynumber

Returns ​

void

Inherited from ​

CanvasPath.moveTo

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:94


quadraticCurveTo ​

▸ quadraticCurveTo(cpx, cpy, x, y): void

Parameters ​

NameType
cpxnumber
cpynumber
xnumber
ynumber

Returns ​

void

Inherited from ​

CanvasPath.quadraticCurveTo

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:95


rect ​

▸ rect(x, y, w, h): void

Parameters ​

NameType
xnumber
ynumber
wnumber
hnumber

Returns ​

void

Inherited from ​

CanvasPath.rect

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:96


roundRect ​

▸ roundRect(x, y, width, height, radius?): void

Parameters ​

NameType
xnumber
ynumber
widthnumber
heightnumber
radius?number | number[]

Returns ​

void

Inherited from ​

CanvasPath.roundRect

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:97


getLineDash ​

▸ getLineDash(): number[]

Returns ​

number[]

Inherited from ​

CanvasPathDrawingStyles.getLineDash

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:106


setLineDash ​

▸ setLineDash(segments): void

Parameters ​

NameType
segmentsnumber[]

Returns ​

void

Inherited from ​

CanvasPathDrawingStyles.setLineDash

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:107


clearRect ​

▸ clearRect(x, y, w, h): void

Parameters ​

NameType
xnumber
ynumber
wnumber
hnumber

Returns ​

void

Inherited from ​

CanvasRect.clearRect

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:122


fillRect ​

▸ fillRect(x, y, w, h): void

Parameters ​

NameType
xnumber
ynumber
wnumber
hnumber

Returns ​

void

Inherited from ​

CanvasRect.fillRect

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:123


strokeRect ​

▸ strokeRect(x, y, w, h): void

Parameters ​

NameType
xnumber
ynumber
wnumber
hnumber

Returns ​

void

Inherited from ​

CanvasRect.strokeRect

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:124


getContextAttributes ​

▸ getContextAttributes(): ICanvasRenderingContext2DSettings

Returns ​

ICanvasRenderingContext2DSettings

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:139


restore ​

▸ restore(): void

Returns ​

void

Inherited from ​

CanvasState.restore

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:155


save ​

▸ save(): void

Returns ​

void

Inherited from ​

CanvasState.save

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:156


drawFocusIfNeeded ​

▸ drawFocusIfNeeded(element): void

Parameters ​

NameType
elementany

Returns ​

void

Inherited from ​

CanvasUserInterface.drawFocusIfNeeded

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:160

▸ drawFocusIfNeeded(path, element): void

Parameters ​

NameType
pathIPath2D
elementany

Returns ​

void

Inherited from ​

CanvasUserInterface.drawFocusIfNeeded

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:161


fillText ​

▸ fillText(text, x, y, maxWidth?): void

Parameters ​

NameType
textstring
xnumber
ynumber
maxWidth?number

Returns ​

void

Inherited from ​

CanvasText.fillText

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:188


measureText ​

▸ measureText(text): ITextMetrics

Parameters ​

NameType
textstring

Returns ​

ITextMetrics

Inherited from ​

CanvasText.measureText

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:189


strokeText ​

▸ strokeText(text, x, y, maxWidth?): void

Parameters ​

NameType
textstring
xnumber
ynumber
maxWidth?number

Returns ​

void

Inherited from ​

CanvasText.strokeText

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:190


getTransform ​

▸ getTransform(): DOMMatrix

Returns ​

DOMMatrix

Inherited from ​

CanvasTransform.getTransform

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:201


resetTransform ​

▸ resetTransform(): void

Returns ​

void

Inherited from ​

CanvasTransform.resetTransform

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:202


rotate ​

▸ rotate(angle): void

Parameters ​

NameType
anglenumber

Returns ​

void

Inherited from ​

CanvasTransform.rotate

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:203


scale ​

▸ scale(x, y): void

Parameters ​

NameType
xnumber
ynumber

Returns ​

void

Inherited from ​

CanvasTransform.scale

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:204


setTransform ​

▸ setTransform(a, b, c, d, e, f): void

Parameters ​

NameType
anumber
bnumber
cnumber
dnumber
enumber
fnumber

Returns ​

void

Inherited from ​

CanvasTransform.setTransform

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:205

▸ setTransform(transform?): void

Parameters ​

NameType
transform?DOMMatrix2DInit

Returns ​

void

Inherited from ​

CanvasTransform.setTransform

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:206


transform ​

▸ transform(a, b, c, d, e, f): void

Parameters ​

NameType
anumber
bnumber
cnumber
dnumber
enumber
fnumber

Returns ​

void

Inherited from ​

CanvasTransform.transform

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:207


translate ​

▸ translate(x, y): void

Parameters ​

NameType
xnumber
ynumber

Returns ​

void

Inherited from ​

CanvasTransform.translate

Defined in ​

leafer/packages/interface/src/canvas/ICanvas.ts:208

Released under the MIT License.