all files / document-editor/implementation/viewer/ document-canvas.js

91.6% Statements 109/119
83.33% Branches 10/12
77.78% Functions 28/36
91.6% Lines 109/119
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203     31239×   15×         60×                       3335×           695×                     2963×                       3175×           680×                     12× 12× 12× 12× 12× 12×   12×   12×   12×     1241×   289×       645×   787×   729×   661×   289×           278×   30×   3252×   3252×   2963× 2963× 2110×                   2963×        
define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var GLOBAL_ALPHA = 'GA';
    var GLOBAL_COMPOSITE_OPERATION = 'GCP';
    var FILL_STYLE = 'FS';
    var STROKE_STYLE = 'SS';
    var DIRECTION = 'Dir';
    var FONT = 'Fn';
    var TEXT_ALIGN = 'TA';
    var TEXT_BASE_LINE = 'TBL';
    var LINE_WIDTH = 'LW';
    var LINE_CAP = 'LC';
    var MAX_WIDTH = 'MW';
    var BEGIN_PATH = 'BP';
    var CLOSE_PATH = 'CP';
    var CLIP = 'Cl';
    var FILL = 'Fl';
    var STROKE = 'Stk';
    var LINE_TO = 'LT';
    var MOVE_TO = 'MT';
    var SEGMENTS = 'Sgm';
    var RECT = 'Rt';
    var CLEAR_RECT = 'CR';
    var FILL_RECT = 'FR';
    var STROKE_RECT = 'SR';
    var RESTORE = 'RES';
    var SAVE = 'S';
    var FILL_TEXT = 'FT';
    var STROKE_TEXT = 'ST';
    var SCALE = 'SC';
    var DocumentCanvasElement = (function () {
        function DocumentCanvasElement() {
            this.style = {};
            this.context = new DocumentCanvasRenderingContext2D();
        }
        DocumentCanvasElement.prototype.getContext = function (contextId, options) {
            return this.context;
        };
        DocumentCanvasElement.prototype.toDataURL = function (type, quality) {
            return this.context.renderedPath;
        };
        return DocumentCanvasElement;
    }());
    exports.DocumentCanvasElement = DocumentCanvasElement;
    var DocumentCanvasRenderingContext2D = (function () {
        function DocumentCanvasRenderingContext2D() {
            this.renderedPath = '';
        }
        Object.defineProperty(DocumentCanvasRenderingContext2D.prototype, "globalAlpha", {
            set: function (value) {
                this.renderedPath += (GLOBAL_ALPHA + ':' + value + ';');
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DocumentCanvasRenderingContext2D.prototype, "globalCompositeOperation", {
            set: function (value) {
                this.renderedPath += (GLOBAL_COMPOSITE_OPERATION + ':' + value + ';');
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DocumentCanvasRenderingContext2D.prototype, "fillStyle", {
            set: function (value) {
                this.renderedPath += (FILL_STYLE + ':' + value + ';');
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DocumentCanvasRenderingContext2D.prototype, "strokeStyle", {
            set: function (value) {
                this.renderedPath += (STROKE_STYLE + ':' + value + ';');
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DocumentCanvasRenderingContext2D.prototype, "direction", {
            set: function (value) {
                this.renderedPath += (DIRECTION + ':' + value + ';');
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DocumentCanvasRenderingContext2D.prototype, "font", {
            set: function (value) {
                this.renderedPath += (FONT + ':' + value + ';');
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DocumentCanvasRenderingContext2D.prototype, "textAlign", {
            set: function (value) {
                this.renderedPath += (TEXT_ALIGN + ':' + value + ';');
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DocumentCanvasRenderingContext2D.prototype, "textBaseline", {
            set: function (value) {
                this.renderedPath += (TEXT_BASE_LINE + ':' + value + ';');
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DocumentCanvasRenderingContext2D.prototype, "lineWidth", {
            set: function (value) {
                this.renderedPath += (LINE_WIDTH + ':' + value + ';');
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(DocumentCanvasRenderingContext2D.prototype, "lineCap", {
            set: function (value) {
                this.renderedPath += (LINE_CAP + ':' + value + ';');
            },
            enumerable: true,
            configurable: true
        });
        DocumentCanvasRenderingContext2D.prototype.drawImage = function (image, sx, sy, sw, sh, dx, dy, dw, dh) {
            this.renderedPath += (LINE_CAP + ':' + image.src + ';');
            this.renderedPath += ('sx:' + sx + ';');
            this.renderedPath += ('sy:' + sy + ';');
            this.renderedPath += ('sw:' + sw + ';');
            this.renderedPath += ('sh:' + sh + ';');
            if (dx) {
                this.renderedPath += ('dx:' + dx + ';');
            }
            if (dy) {
                this.renderedPath += ('dy:' + dy + ';');
            }
            if (dw) {
                this.renderedPath += ('dw:' + dw + ';');
            }
            if (dh) {
                this.renderedPath += ('dh:' + dh + ';');
            }
        };
        DocumentCanvasRenderingContext2D.prototype.beginPath = function () {
            this.renderedPath += (BEGIN_PATH + ';');
        };
        DocumentCanvasRenderingContext2D.prototype.clip = function (fillRule) {
            this.renderedPath += (CLIP + ';');
        };
        DocumentCanvasRenderingContext2D.prototype.fill = function (fillRule) {
            this.renderedPath += (FILL + ';');
        };
        DocumentCanvasRenderingContext2D.prototype.stroke = function () {
            this.renderedPath += (STROKE + ';');
        };
        DocumentCanvasRenderingContext2D.prototype.closePath = function () {
            this.renderedPath += (CLOSE_PATH + ';');
        };
        DocumentCanvasRenderingContext2D.prototype.lineTo = function (x, y) {
            this.renderedPath += (LINE_TO + ':' + 'x:' + x + ';' + 'y:' + y + ';');
        };
        DocumentCanvasRenderingContext2D.prototype.moveTo = function (x, y) {
            this.renderedPath += (MOVE_TO + ':' + 'x:' + x + ';' + 'y:' + y + ';');
        };
        DocumentCanvasRenderingContext2D.prototype.rect = function (x, y, w, h) {
            this.renderedPath += (RECT + ':' + 'x:' + x + ';' + 'y:' + y + ';' + 'w:' + w + ';' + 'h:' + h + ';');
        };
        DocumentCanvasRenderingContext2D.prototype.setLineDash = function (segments) {
            this.renderedPath += (SEGMENTS + ':' + segments.toString() + ';');
        };
        DocumentCanvasRenderingContext2D.prototype.clearRect = function (x, y, w, h) {
            this.renderedPath += (CLEAR_RECT + ':' + 'x:' + x + ';' + 'y:' + y + ';' + 'w:' + w + ';' + 'h:' + h + ';');
        };
        DocumentCanvasRenderingContext2D.prototype.fillRect = function (x, y, w, h) {
            this.renderedPath += (FILL_RECT + ':' + 'x:' + x + ';' + 'y:' + y + ';' + 'w:' + w + ';' + 'h:' + h + ';');
        };
        DocumentCanvasRenderingContext2D.prototype.strokeRect = function (x, y, w, h) {
            this.renderedPath += (STROKE_RECT + ':' + 'x:' + x + ';' + 'y:' + y + ';' + 'w:' + w + ';' + 'h:' + h + ';');
        };
        DocumentCanvasRenderingContext2D.prototype.restore = function () {
            this.renderedPath += (RESTORE + ';');
        };
        DocumentCanvasRenderingContext2D.prototype.save = function () {
            this.renderedPath += (SAVE + ';');
        };
        DocumentCanvasRenderingContext2D.prototype.fillText = function (text, x, y, maxWidth) {
            this.renderedPath += (FILL_TEXT + ':' + text + ';' + 'x:' + x + ';' + 'y:' + y + ';');
            if (maxWidth) {
                this.renderedPath += (MAX_WIDTH + ':' + maxWidth + ';');
            }
        };
        DocumentCanvasRenderingContext2D.prototype.measureText = function (text) {
            return { width: 30 };
        };
        DocumentCanvasRenderingContext2D.prototype.strokeText = function (text, x, y, maxWidth) {
            this.renderedPath += (STROKE_TEXT + ':' + text + ';' + 'x:' + x + ';' + 'y:' + y + ';');
            if (maxWidth) {
                this.renderedPath += (MAX_WIDTH + ':' + maxWidth + ';');
            }
        };
        DocumentCanvasRenderingContext2D.prototype.scale = function (x, y) {
            this.renderedPath += (SCALE + ':' + 'x:' + x + ';' + 'y:' + y + ';');
        };
        return DocumentCanvasRenderingContext2D;
    }());
    exports.DocumentCanvasRenderingContext2D = DocumentCanvasRenderingContext2D;
});