CanvasRenderingContext2D

Module: JavaScript DOM API

#include <CanvasRenderingContext2D.Idl>

Public Functions

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)

Public Attributes

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

Public Functions Documentation

function attribute

attribute(
    DOMString or CanvasGradient or CanvasPattern
)

function attribute

attribute(
    DOMString or CanvasGradient or CanvasPattern
)

function createLinearGradient

CanvasGradient createLinearGradient(
    float x0,
    float y0,
    float x1,
    float y1
)

function createRadialGradient

CanvasGradient createRadialGradient(
    float x0,
    float y0,
    float r0,
    float x1,
    float y1,
    float r1
)

function createConicGradient

CanvasGradient createConicGradient(
    float startAngle,
    float x,
    float y
)

function createPattern

CanvasPattern createPattern(
    HTMLCanvasElement image,
    DOMString repetition
)

function createPattern

CanvasPattern createPattern(
    HTMLImageElement image,
    DOMString repetition
)

function save

void save()

function restore

void restore()

function clearRect

void clearRect(
    float x,
    float y,
    float w,
    float h
)

function fillRect

void fillRect(
    float x,
    float y,
    float w,
    float h
)

function strokeRect

void strokeRect(
    float x,
    float y,
    float w,
    float h
)

function fillText

void fillText(
    DOMString text,
    float x,
    float y,
    optional float maxWidth
)

function strokeText

void strokeText(
    DOMString text,
    float x,
    float y,
    optional float maxWidth
)

function measureText

TextMetrics measureText(
    DOMString text
)

function drawImage

void drawImage(
    HTMLCanvasElement image,
    float dx,
    float dy
)

function drawImage

void drawImage(
    HTMLCanvasElement image,
    float dx,
    float dy,
    float dw,
    float dh
)

function drawImage

void drawImage(
    HTMLCanvasElement image,
    float sx,
    float sy,
    float sw,
    float sh,
    float dx,
    float dy,
    float dw,
    float dh
)

function drawImage

void drawImage(
    HTMLVideoElement image,
    float dx,
    float dy
)

function drawImage

void drawImage(
    HTMLVideoElement image,
    float dx,
    float dy,
    float dw,
    float dh
)

function drawImage

void drawImage(
    HTMLVideoElement image,
    float sx,
    float sy,
    float sw,
    float sh,
    float dx,
    float dy,
    float dw,
    float dh
)

function drawImage

void drawImage(
    HTMLImageElement image,
    float dx,
    float dy
)

function drawImage

void drawImage(
    HTMLImageElement image,
    float dx,
    float dy,
    float dw,
    float dh
)

function drawImage

void drawImage(
    HTMLImageElement image,
    float sx,
    float sy,
    float sw,
    float sh,
    float dx,
    float dy,
    float dw,
    float dh
)

function scale

void scale(
    float x,
    float y
)

function rotate

void rotate(
    float angle
)

function translate

void translate(
    float x,
    float y
)

function transform

void transform(
    float a,
    float b,
    float c,
    float d,
    float e,
    float f
)

function setTransform

void setTransform(
    float a,
    float b,
    float c,
    float d,
    float e,
    float f
)

function beginPath

void beginPath()

function fill

void fill()

function stroke

void stroke()

function drawFocusIfNeeded

void drawFocusIfNeeded(
    Element element
)

function clip

void clip()

function closePath

void closePath()

function moveTo

void moveTo(
    float x,
    float y
)

function lineTo

void lineTo(
    float x,
    float y
)

function quadraticCurveTo

void quadraticCurveTo(
    float cpx,
    float cpy,
    float x,
    float y
)

function bezierCurveTo

void bezierCurveTo(
    float cp1x,
    float cp1y,
    float cp2x,
    float cp2y,
    float x,
    float y
)

function arcTo

void arcTo(
    float x1,
    float y1,
    float x2,
    float y2,
    float radius
)

function rect

void rect(
    float x,
    float y,
    float w,
    float h
)

function arc

void arc(
    float x,
    float y,
    float radius,
    float startAngle,
    float endAngle,
    optional boolean counterclockwise =false
)

Public Attributes Documentation

variable canvas

readonly attributeHTMLCanvasElement canvas;

variable globalAlpha

attribute float globalAlpha;

variable globalCompositeOperation

attribute DOMString globalCompositeOperation;

variable lineWidth

attribute float lineWidth;

variable lineCap

attribute DOMString lineCap;

variable lineJoin

attribute DOMString lineJoin;

variable miterLimit

attribute float miterLimit;

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

attribute DOMString textAlign;

variable textBaseline

attribute DOMString textBaseline;

variable shadowOffsetX

attribute float shadowOffsetX;

variable shadowOffsetY

attribute float shadowOffsetY;

variable shadowBlur

attribute float shadowBlur;

variable shadowColor

attribute DOMString shadowColor;

variable enableFastLineSegmentDrawing

attribute boolean enableFastLineSegmentDrawing;