CanvasRenderingContext2D
Module: JavaScript DOM API
#include <CanvasRenderingContext2D.Idl>
Public Functions
Section titled “Public Functions”| Name | |
|---|---|
| attribute(DOMString or CanvasGradient or CanvasPattern) | |
| attribute(DOMString or CanvasGradient or CanvasPattern) | |
| CanvasGradient | createLinearGradient(float x0, float y0, float x1, float y1) |
| CanvasGradient | createRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1) |
| CanvasGradient | createConicGradient(float startAngle, float x, float y) |
| CanvasPattern | createPattern(HTMLCanvasElement image, DOMString repetition) |
| CanvasPattern | createPattern(HTMLImageElement image, DOMString repetition) |
| void | save() |
| void | restore() |
| void | clearRect(float x, float y, float w, float h) |
| void | fillRect(float x, float y, float w, float h) |
| void | strokeRect(float x, float y, float w, float h) |
| void | fillText(DOMString text, float x, float y, optional float maxWidth) |
| void | strokeText(DOMString text, float x, float y, optional float maxWidth) |
| TextMetrics | measureText(DOMString text) |
| void | drawImage(HTMLCanvasElement image, float dx, float dy) |
| void | drawImage(HTMLCanvasElement image, float dx, float dy, float dw, float dh) |
| void | drawImage(HTMLCanvasElement image, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) |
| void | drawImage(HTMLVideoElement image, float dx, float dy) |
| void | drawImage(HTMLVideoElement image, float dx, float dy, float dw, float dh) |
| void | drawImage(HTMLVideoElement image, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) |
| void | drawImage(HTMLImageElement image, float dx, float dy) |
| void | drawImage(HTMLImageElement image, float dx, float dy, float dw, float dh) |
| void | drawImage(HTMLImageElement image, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh) |
| void | scale(float x, float y) |
| void | rotate(float angle) |
| void | translate(float x, float y) |
| void | transform(float a, float b, float c, float d, float e, float f) |
| void | setTransform(float a, float b, float c, float d, float e, float f) |
| void | beginPath() |
| void | fill() |
| void | stroke() |
| void | drawFocusIfNeeded(Element element) |
| void | clip() |
| void | closePath() |
| void | moveTo(float x, float y) |
| void | lineTo(float x, float y) |
| void | quadraticCurveTo(float cpx, float cpy, float x, float y) |
| void | bezierCurveTo(float cp1x, float cp1y, float cp2x, float cp2y, float x, float y) |
| void | arcTo(float x1, float y1, float x2, float y2, float radius) |
| void | rect(float x, float y, float w, float h) |
| void | arc(float x, float y, float radius, float startAngle, float endAngle, optional boolean counterclockwise =false) |
Public Attributes
Section titled “Public Attributes”| Name | |
|---|---|
| readonly attributeHTMLCanvasElement | canvas |
| attribute float | globalAlpha |
| attribute DOMString | globalCompositeOperation |
| attribute float | lineWidth |
| attribute DOMString | lineCap |
| attribute DOMString | lineJoin |
| attribute float | miterLimit |
| attribute DOMString | font Specifies the current text style to use when drawing text. This string uses the same syntax as the CSS font specifier. |
| attribute DOMString | textAlign |
| attribute DOMString | textBaseline |
| attribute float | shadowOffsetX |
| attribute float | shadowOffsetY |
| attribute float | shadowBlur |
| attribute DOMString | shadowColor |
| attribute boolean | enableFastLineSegmentDrawing |
Public Functions Documentation
Section titled “Public Functions Documentation”function attribute
Section titled “function attribute”attribute( DOMString or CanvasGradient or CanvasPattern)function attribute
Section titled “function attribute”attribute( DOMString or CanvasGradient or CanvasPattern)function createLinearGradient
Section titled “function createLinearGradient”CanvasGradient createLinearGradient( float x0, float y0, float x1, float y1)function createRadialGradient
Section titled “function createRadialGradient”CanvasGradient createRadialGradient( float x0, float y0, float r0, float x1, float y1, float r1)function createConicGradient
Section titled “function createConicGradient”CanvasGradient createConicGradient( float startAngle, float x, float y)function createPattern
Section titled “function createPattern”CanvasPattern createPattern( HTMLCanvasElement image, DOMString repetition)function createPattern
Section titled “function createPattern”CanvasPattern createPattern( HTMLImageElement image, DOMString repetition)function save
Section titled “function save”void save()function restore
Section titled “function restore”void restore()function clearRect
Section titled “function clearRect”void clearRect( float x, float y, float w, float h)function fillRect
Section titled “function fillRect”void fillRect( float x, float y, float w, float h)function strokeRect
Section titled “function strokeRect”void strokeRect( float x, float y, float w, float h)function fillText
Section titled “function fillText”void fillText( DOMString text, float x, float y, optional float maxWidth)function strokeText
Section titled “function strokeText”void strokeText( DOMString text, float x, float y, optional float maxWidth)function measureText
Section titled “function measureText”TextMetrics measureText( DOMString text)function drawImage
Section titled “function drawImage”void drawImage( HTMLCanvasElement image, float dx, float dy)function drawImage
Section titled “function drawImage”void drawImage( HTMLCanvasElement image, float dx, float dy, float dw, float dh)function drawImage
Section titled “function drawImage”void drawImage( HTMLCanvasElement image, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh)function drawImage
Section titled “function drawImage”void drawImage( HTMLVideoElement image, float dx, float dy)function drawImage
Section titled “function drawImage”void drawImage( HTMLVideoElement image, float dx, float dy, float dw, float dh)function drawImage
Section titled “function drawImage”void drawImage( HTMLVideoElement image, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh)function drawImage
Section titled “function drawImage”void drawImage( HTMLImageElement image, float dx, float dy)function drawImage
Section titled “function drawImage”void drawImage( HTMLImageElement image, float dx, float dy, float dw, float dh)function drawImage
Section titled “function drawImage”void drawImage( HTMLImageElement image, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh)function scale
Section titled “function scale”void scale( float x, float y)function rotate
Section titled “function rotate”void rotate( float angle)function translate
Section titled “function translate”void translate( float x, float y)function transform
Section titled “function transform”void transform( float a, float b, float c, float d, float e, float f)function setTransform
Section titled “function setTransform”void setTransform( float a, float b, float c, float d, float e, float f)function beginPath
Section titled “function beginPath”void beginPath()function fill
Section titled “function fill”void fill()function stroke
Section titled “function stroke”void stroke()function drawFocusIfNeeded
Section titled “function drawFocusIfNeeded”void drawFocusIfNeeded( Element element)function clip
Section titled “function clip”void clip()function closePath
Section titled “function closePath”void closePath()function moveTo
Section titled “function moveTo”void moveTo( float x, float y)function lineTo
Section titled “function lineTo”void lineTo( float x, float y)function quadraticCurveTo
Section titled “function quadraticCurveTo”void quadraticCurveTo( float cpx, float cpy, float x, float y)function bezierCurveTo
Section titled “function bezierCurveTo”void bezierCurveTo( float cp1x, float cp1y, float cp2x, float cp2y, float x, float y)function arcTo
Section titled “function arcTo”void arcTo( float x1, float y1, float x2, float y2, float radius)function rect
Section titled “function rect”void rect( float x, float y, float w, float h)function arc
Section titled “function arc”void arc( float x, float y, float radius, float startAngle, float endAngle, optional boolean counterclockwise =false)Public Attributes Documentation
Section titled “Public Attributes Documentation”variable canvas
Section titled “variable canvas”readonly attributeHTMLCanvasElement canvas;variable globalAlpha
Section titled “variable globalAlpha”attribute float globalAlpha;variable globalCompositeOperation
Section titled “variable globalCompositeOperation”attribute DOMString globalCompositeOperation;variable lineWidth
Section titled “variable lineWidth”attribute float lineWidth;variable lineCap
Section titled “variable lineCap”attribute DOMString lineCap;variable lineJoin
Section titled “variable lineJoin”attribute DOMString lineJoin;variable miterLimit
Section titled “variable miterLimit”attribute float miterLimit;variable font
Section titled “variable font”attribute DOMString font;Specifies the current text style to use when drawing text. This string uses the same syntax as the CSS font specifier.
Note: Currently supports only “bold”, “italic”, font-size in pixels and a single font-family. Font fallback is not supported.
Warning: Canvas can only draw with already loaded fonts.
variable textAlign
Section titled “variable textAlign”attribute DOMString textAlign;variable textBaseline
Section titled “variable textBaseline”attribute DOMString textBaseline;variable shadowOffsetX
Section titled “variable shadowOffsetX”attribute float shadowOffsetX;variable shadowOffsetY
Section titled “variable shadowOffsetY”attribute float shadowOffsetY;variable shadowBlur
Section titled “variable shadowBlur”attribute float shadowBlur;variable shadowColor
Section titled “variable shadowColor”attribute DOMString shadowColor;variable enableFastLineSegmentDrawing
Section titled “variable enableFastLineSegmentDrawing”attribute boolean enableFastLineSegmentDrawing;© 2026 Coherent Labs. All rights reserved.