Skip to content
SiteEmail

CanvasRenderingContext2D

Module: JavaScript DOM API

#include <CanvasRenderingContext2D.Idl>

Name
attribute(DOMString or CanvasGradient or CanvasPattern)
attribute(DOMString or CanvasGradient or CanvasPattern)
CanvasGradientcreateLinearGradient(float x0, float y0, float x1, float y1)
CanvasGradientcreateRadialGradient(float x0, float y0, float r0, float x1, float y1, float r1)
CanvasGradientcreateConicGradient(float startAngle, float x, float y)
CanvasPatterncreatePattern(HTMLCanvasElement image, DOMString repetition)
CanvasPatterncreatePattern(HTMLImageElement image, DOMString repetition)
voidsave()
voidrestore()
voidclearRect(float x, float y, float w, float h)
voidfillRect(float x, float y, float w, float h)
voidstrokeRect(float x, float y, float w, float h)
voidfillText(DOMString text, float x, float y, optional float maxWidth)
voidstrokeText(DOMString text, float x, float y, optional float maxWidth)
TextMetricsmeasureText(DOMString text)
voiddrawImage(HTMLCanvasElement image, float dx, float dy)
voiddrawImage(HTMLCanvasElement image, float dx, float dy, float dw, float dh)
voiddrawImage(HTMLCanvasElement image, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh)
voiddrawImage(HTMLVideoElement image, float dx, float dy)
voiddrawImage(HTMLVideoElement image, float dx, float dy, float dw, float dh)
voiddrawImage(HTMLVideoElement image, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh)
voiddrawImage(HTMLImageElement image, float dx, float dy)
voiddrawImage(HTMLImageElement image, float dx, float dy, float dw, float dh)
voiddrawImage(HTMLImageElement image, float sx, float sy, float sw, float sh, float dx, float dy, float dw, float dh)
voidscale(float x, float y)
voidrotate(float angle)
voidtranslate(float x, float y)
voidtransform(float a, float b, float c, float d, float e, float f)
voidsetTransform(float a, float b, float c, float d, float e, float f)
voidbeginPath()
voidfill()
voidstroke()
voiddrawFocusIfNeeded(Element element)
voidclip()
voidclosePath()
voidmoveTo(float x, float y)
voidlineTo(float x, float y)
voidquadraticCurveTo(float cpx, float cpy, float x, float y)
voidbezierCurveTo(float cp1x, float cp1y, float cp2x, float cp2y, float x, float y)
voidarcTo(float x1, float y1, float x2, float y2, float radius)
voidrect(float x, float y, float w, float h)
voidarc(float x, float y, float radius, float startAngle, float endAngle, optional boolean counterclockwise =false)
Name
readonly attributeHTMLCanvasElementcanvas
attribute floatglobalAlpha
attribute DOMStringglobalCompositeOperation
attribute floatlineWidth
attribute DOMStringlineCap
attribute DOMStringlineJoin
attribute floatmiterLimit
attribute DOMStringfont
Specifies the current text style to use when drawing text. This string uses the same syntax as the CSS font specifier.
attribute DOMStringtextAlign
attribute DOMStringtextBaseline
attribute floatshadowOffsetX
attribute floatshadowOffsetY
attribute floatshadowBlur
attribute DOMStringshadowColor
attribute booleanenableFastLineSegmentDrawing
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
)
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.

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.

attribute DOMString textAlign;
attribute DOMString textBaseline;
attribute float shadowOffsetX;
attribute float shadowOffsetY;
attribute float shadowBlur;
attribute DOMString shadowColor;
attribute boolean enableFastLineSegmentDrawing;