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

100% Statements 42/42
100% Branches 2/2
100% Functions 7/7
100% Lines 42/42
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     707× 707× 707×   3128723×   3128719× 3128719× 3128719× 3128719× 3128719× 3128719× 3128719× 3128719× 3128719×   695× 695× 695× 695× 695× 695× 695× 695× 695×          
define(["require", "exports", "../utility/dom-util"], function (require, exports, dom_util_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var BarcodeSVGRenderering = (function () {
        function BarcodeSVGRenderering() {
        }
        BarcodeSVGRenderering.prototype.renderRootElement = function (attribute, backGroundColor) {
            var canvasObj = dom_util_1.createSvgElement('svg', attribute);
            canvasObj.setAttribute('style', 'background:' + backGroundColor);
            return canvasObj;
        };
        BarcodeSVGRenderering.prototype.renderRect = function (svg, attribute) {
            if (attribute.imageSource) {
                return this.renderImage(svg, attribute);
            }
            var rect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
            rect.setAttribute('x', attribute.x.toString());
            rect.setAttribute('y', attribute.y.toString());
            rect.setAttribute('width', attribute.width.toString());
            rect.setAttribute('height', attribute.height.toString());
            rect.setAttribute('fill', attribute.color);
            rect.setAttribute('style', 'shape-rendering: crispEdges');
            svg.appendChild(rect);
            return svg;
        };
        BarcodeSVGRenderering.prototype.renderText = function (svg, attribute) {
            var text = document.createElementNS('http://www.w3.org/2000/svg', 'text');
            text.setAttribute('x', attribute.x.toString());
            text.setAttribute('y', attribute.y.toString());
            text.setAttribute('fill', attribute.color);
            text.style.fontSize = attribute.stringSize.toString() + 'px';
            text.style.fontFamily = attribute.fontStyle;
            text.textContent = attribute.string;
            svg.appendChild(text);
            return svg;
        };
        BarcodeSVGRenderering.prototype.renderImage = function (svg, attribute) {
            var image = document.createElementNS('http://www.w3.org/2000/svg', 'image');
            image.setAttribute('x', attribute.x.toString());
            image.setAttribute('y', attribute.y.toString());
            image.setAttribute('width', attribute.width.toString());
            image.setAttribute('height', attribute.height.toString());
            image.setAttribute('href', attribute.imageSource);
            image.setAttribute('preserveAspectRatio', 'none');
            svg.appendChild(image);
            return svg;
        };
        return BarcodeSVGRenderering;
    }());
    exports.BarcodeSVGRenderering = BarcodeSVGRenderering;
});