CanvasRenderingContext2D 인터페이스



interface CanvasRenderingContext2D {
    // 역참조 canvas
    readonly attribute HTMLCanvasElement canvas;

    // state
    void save(); // 스택에 상태저장
    void restore(); // 스택에서 상태를 꺼내와 상태복원

    // 변환
    void scale(in float x, in float y);
    void rotate(in float angle);
    void translate(in float x, in float y);
    void setTransform(in float m11, in float m12, in float m21, in float m22, in float dx, in float dy);

    // 합성
        attribute float globalAlpha; // (default 1.0)
        attribute DOMString globalCompositeOperation; // (default source-over)

    // colors and styles
        attribute any strokeStyle; // (default black)
        attribute any fillStyle; // (default black)
    CanvasGradient createLinearGradient(in float x0, in float y0, in float x1, in float y1);
    CanvasGradient createRadialGradient(in float x0, in float y0, in float r0, in float x1, in float y1, in float r1);
    CanvasPattern createPattern(in HTMLImageElement image, in DOMString repetition);
    CanvasPattern createPattern(in HTMLCanvasElement image, in DOMString repetition);
    CanvasPattern createPattern(in HTMLVideoElement image, in DOMString repetition);

    // 선 (line)
        attribute float lineWidth; // (default 1)
        attribute DOMString lineCap; // "butt", "round", "square" (default "butt")
        attribute DOMString lineJoin; // "round", "bevel", "miter" (default "miter")
        attribute float miterLimit; // (default 10)

    // 그림자 (shadows)
        attribute float shadowOffsetX; // (default 0)
        attribute float shadowOffsetY; // (default 0)
        attribute float shadowBlur; // (default 0)
        attribute DOMString shadowColor; // (default transparent black)

    // 사각형 (rects)
    void clearRect(in float x, in float y, in float w, in float h);
    void fillRect(in float x, in float y, in float w, in float h);
    void strokeRect(in float x, in float y, in float w, in float h);

    // path API
    void beginPath();
    void closePath();
    void moveTo(in float x, in float y);
    void lineTo(in float x, in float y);
    void quadraticCurveTo(in float cpx, in float cpy, in float x, in float y);
    void bezierCurveTo(in float cp1x, in float cp1y, in float cp2x, in float cp2y, in float x, in float y);
    void arcTo(in float x1, in float y1, in float x2, in float y2, in float radius);
    void rect(in float x, in float y, in float w, in float h);
    void arc(in float x, in float y, in float radius, in float startAngle, in float endAngle, in boolean anticlockwise);
    void fill();
    void stroke();
    void clip();
    boolean isPointInPath(in float x, in float y);

    // 포커스 관리
    boolean drawFocusRing(in Element element, in float xCaret, in float yCaret, in optional boolean canDrawCustom);

    // 텍스트
        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")
    void fillText(in DOMString text, in float x, in float y, in optional float maxWidth);
    void strokeText(in DOMString text, in float x, in float y, in optional float maxWidth);
    TextMetric measureText(in DOMString text);

    // 이미지 그리기
    void drawImage(in HTMLImageElement image, in float dx, in float dy, in optional float dw, in float dh);
    void drawImage(in HTMLImageElement image, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh);
    void drawImage(in HTMLCanvasElement image, in float dx, in float dy, in optional float dw, in float dh);
    void drawImage(in HTMLCanvasElement image, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh);
    void drawImage(in HTMLVideoElement image, in float dx, in float dy, in optional float dw, in float dh);
    void drawImage(in HTMLVideoElement image, in float sx, in float sy, in float sw, in float sh, in float dx, in float dy, in float dw, in float dh);

    // 픽셀 
    ImageData createImageData(in float sw, in float sh);
    ImageData createImageData(in ImageData imagedata);
    ImageData getImageData(in float sx, in float sy, in float sw, in float sh);
    void putImageData(in ImageData imagedata, in float dx, in float dy, in optional float dirtyX, in float dirtyY, in float dirtyWidth, in float dirtyHeight);
};

interface CanvasGradient {
    // opaque object
    void addColorStop(in float offset, in DOMString color);
};

interface CanvasPattern {
    // opaque object
};

interface TextMetrics {
    readonly attribute float width;
}

interface ImageData {
    readonly attribute unsigned long width;
    readonly attribute unsigned long height;
    readonly attribute CanvasPixelArray data;
};

interface CanvasPixelArray {
    readonly attribute unsigned long length;
    getter octet (in unsigned long index);
    setter void (in unsigned long index, in octet value);
};
Posted by bloodguy
,