Last active
November 30, 2015 22:34
-
-
Save bfgeek/72c2b26c2ccc8f728daf to your computer and use it in GitHub Desktop.
CanvasRenderingContext2D.idl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef (HTMLImageElement or | |
HTMLVideoElement or | |
HTMLCanvasElement) CanvasImageSource; | |
interface CanvasRenderingContext2D { | |
// back-reference to the canvas | |
readonly attribute HTMLCanvasElement canvas; | |
void drawFocusIfNeeded(Element element); | |
// hit regions | |
void addHitRegion(HitRegionOptions options); | |
void removeHitRegion(DOMString id); | |
void clearHitRegions(); | |
}; | |
CanvasRenderingContext2D implements CanvasDrawingStyles; | |
CanvasRenderingContext2D implements CanvasImageDataMethods; | |
CanvasRenderingContext2D implements CanvasMethods; | |
CanvasRenderingContext2D implements CanvasPathMethods; | |
// TODO bikeshed name. | |
interface OffscreenCanvasRenderingContext2D { | |
}; | |
OffscreenCanvasRenderingContext2D implements CanvasDrawingStyles; | |
OffscreenCanvasRenderingContext2D implements CanvasImageDataMethods; | |
OffscreenCanvasRenderingContext2D implements CanvasMethods; | |
OffscreenCanvasRenderingContext2D implements CanvasPathMethods; | |
// TODO bikeshed name. | |
interface HoudiniCanvasRenderingContext2D { | |
}; | |
HoudiniCanvasRenderingContext2D implements CanvasDrawingStyles; | |
HoudiniCanvasRenderingContext2D implements CanvasMethods; | |
HoudiniCanvasRenderingContext2D implements CanvasPathMethods; | |
[NoInterfaceObject] | |
interface CanvasImageDataMethods { | |
ImageData createImageData(unrestricted double sw, unrestricted double sh); | |
ImageData createImageData(ImageData imagedata); | |
ImageData getImageData(double sx, double sy, double sw, double sh); // NOTE arguably only getImageData should be here. | |
void putImageData(ImageData imagedata, double dx, double dy); | |
void putImageData(ImageData imagedata, double dx, double dy, double dirtyX, double dirtyY, double dirtyWidth, double dirtyHeight); | |
}; | |
// "write-only" methods should go here, i.e. no methods which would force a raster. | |
[NoInterfaceObject] | |
interface CanvasMethods { | |
// state | |
void save(); // push state on state stack | |
void restore(); // pop state stack and restore state | |
// transforms (default: transform is the identity matrix) | |
void scale(unrestricted double x, unrestricted double y); | |
void rotate(unrestricted double angle); | |
void translate(unrestricted double x, unrestricted double y); | |
void transform(unrestricted double a, unrestricted double b, unrestricted double c, unrestricted double d, unrestricted double e, unrestricted double f); | |
void setTransform(unrestricted double a, unrestricted double b, unrestricted double c, unrestricted double d, unrestricted double e, unrestricted double f); | |
// compositing | |
attribute unrestricted double globalAlpha; // (default: 1.0) | |
attribute DOMString globalCompositeOperation; // (default: "source-over") | |
// colors and styles (see also the CanvasDrawingStyles interface) | |
attribute (DOMString or CanvasGradient or CanvasPattern) strokeStyle; // (default: "black") | |
attribute (DOMString or CanvasGradient or CanvasPattern) fillStyle; // (default: "black") | |
CanvasGradient createLinearGradient(double x0, double y0, double x1, double y1); | |
CanvasGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1); | |
CanvasPattern createPattern(CanvasImageSource image, [TreatNullAs=EmptyString] DOMString repetition); | |
// shadows | |
attribute unrestricted double shadowOffsetX; // (default: 0) | |
attribute unrestricted double shadowOffsetY; // (default: 0) | |
attribute unrestricted double shadowBlur; // (default: 0) | |
attribute DOMString shadowColor; // (default: "transparent black") | |
// rects | |
void clearRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h); | |
void fillRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h); | |
void strokeRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h); | |
// path API (see also CanvasPathMethods) | |
void beginPath(); | |
void fill(); | |
void stroke(); | |
void clip(); | |
boolean isPointInPath(unrestricted double x, unrestricted double y); | |
// text (see also the CanvasDrawingStyles interface) | |
void fillText(DOMString text, unrestricted double x, unrestricted double y, optional unrestricted double maxWidth); | |
void strokeText(DOMString text, unrestricted double x, unrestricted double y, optional unrestricted double maxWidth); | |
TextMetrics measureText(DOMString text); | |
// drawing images | |
void drawImage(CanvasImageSource image, unrestricted double dx, unrestricted double dy); | |
void drawImage(CanvasImageSource image, unrestricted double dx, unrestricted double dy, unrestricted double dw, unrestricted double dh); | |
void drawImage(CanvasImageSource image, unrestricted double sx, unrestricted double sy, unrestricted double sw, unrestricted double sh, unrestricted double dx, unrestricted double dy, unrestricted double dw, unrestricted double dh); | |
}; | |
[NoInterfaceObject] | |
interface CanvasDrawingStyles { | |
// line caps/joins | |
attribute unrestricted double lineWidth; // (default: 1) | |
attribute DOMString lineCap; // "butt", "round", "square" (default: "butt") | |
attribute DOMString lineJoin; // "round", "bevel", "miter" (default: "miter") | |
attribute unrestricted double miterLimit; // (default: 10) | |
// dashed lines | |
void setLineDash(sequence<unrestricted double> segments); // (default: empty) | |
sequence<unrestricted double> getLineDash(); | |
attribute unrestricted double lineDashOffset; | |
// text | |
attribute DOMString font; // (default: "10px sans-serif") | |
attribute DOMString textAlign; // "start", "end", "left", "right", "center" (default: "start") | |
attribute DOMString textBaseline; // "top", "hanging", "middle", "alphabetic", "ideographic", "bottom" (default: "alphabetic") | |
}; | |
[NoInterfaceObject] | |
interface CanvasPathMethods { | |
// shared path API methods | |
void closePath(); | |
void moveTo(unrestricted double x, unrestricted double y); | |
void lineTo(unrestricted double x, unrestricted double y); | |
void quadraticCurveTo(unrestricted double cpx, unrestricted double cpy, unrestricted double x, unrestricted double y); | |
void bezierCurveTo(unrestricted double cp1x, unrestricted double cp1y, unrestricted double cp2x, unrestricted double cp2y, unrestricted double x, unrestricted double y); | |
void arcTo(unrestricted double x1, unrestricted double y1, unrestricted double x2, unrestricted double y2, unrestricted double radius); | |
void rect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h); | |
void arc(unrestricted double x, unrestricted double y, unrestricted double radius, unrestricted double startAngle, unrestricted double endAngle, optional boolean counterclockwise = false); | |
}; | |
interface CanvasGradient { | |
// opaque object | |
void addColorStop(double offset, DOMString color); | |
}; | |
interface CanvasPattern { | |
// opaque object | |
}; | |
interface TextMetrics { | |
readonly attribute double width; | |
}; | |
dictionary HitRegionOptions { | |
// dictionary to allow expansion on Hit Regions in Canvas Context 2D Level 2 | |
DOMString id = ""; | |
// for control-backed regions: | |
Element? control = null; | |
}; | |
interface ImageData { | |
readonly attribute unsigned long width; | |
readonly attribute unsigned long height; | |
readonly attribute Uint8ClampedArray data; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment