all files / barcode/rendering/ canvas-renderer.js

96.77% Statements 30/31
100% Branches 2/2
87.5% Functions 7/8
96.77% Lines 30/31
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     12×   20× 20× 20× 20× 20×   3422× 3422×         3421× 3421×   3422×   33× 33× 33× 33× 33× 33×        
define(["require", "exports", "../utility/dom-util"], function (require, exports, dom_util_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var BarcodeCanvasRenderer = (function () {
        function BarcodeCanvasRenderer() {
        }
        BarcodeCanvasRenderer.getContext = function (canvas) {
            return canvas.getContext('2d');
        };
        BarcodeCanvasRenderer.prototype.renderRootElement = function (attribute, backGroundColor, width, height) {
            var canvasObj = dom_util_1.createHtmlElement('canvas', attribute);
            var ctx = canvasObj.getContext('2d');
            ctx.fillStyle = backGroundColor;
            ctx.fillRect(0, 0, width, height);
            return canvasObj;
        };
        BarcodeCanvasRenderer.prototype.renderRect = function (canvas, attribute) {
            var ctx = canvas.getContext('2d');
            if (attribute.imageSource) {
                var image_1 = new Image();
                image_1.src = attribute.imageSource;
                image_1.onload = function () {
                    ctx.drawImage(image_1, attribute.x, attribute.y, attribute.width, attribute.height);
                };
            }
            else {
                ctx.fillStyle = attribute.color;
                ctx.fillRect(attribute.x, attribute.y, attribute.width, attribute.height);
            }
            return canvas;
        };
        BarcodeCanvasRenderer.prototype.renderText = function (canvas, attribute) {
            var ctx = canvas.getContext('2d');
            ctx.save();
            ctx.font = (attribute.stringSize) + 'px ' + attribute.fontStyle;
            ctx.fillStyle = attribute.color;
            ctx.fillText(attribute.string, attribute.x, attribute.y);
            return canvas;
        };
        return BarcodeCanvasRenderer;
    }());
    exports.BarcodeCanvasRenderer = BarcodeCanvasRenderer;
});