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;
});
|