all files / core/graphics/images/ pdf-image.js

27.5% Statements 11/40
0% Branches 0/19
20% Functions 2/10
27.5% Lines 11/40
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                                                                                                                            
define(["require", "exports", "./../../enumerator", "./../../graphics/pdf-graphics"], function (require, exports, enumerator_1, pdf_graphics_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PdfImage = (function () {
        function PdfImage() {
        }
        Object.defineProperty(PdfImage.prototype, "width", {
            get: function () {
                return this._imageWidth;
            },
            set: function (value) {
                this._imageWidth = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfImage.prototype, "height", {
            get: function () {
                return this._imageHeight;
            },
            set: function (value) {
                this._imageHeight = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfImage.prototype, "physicalDimension", {
            get: function () {
                this._imagePhysicalDimension = this._getPointSize(this.width, this.height, this._horizontalResolution);
                return { width: this.width, height: this.height };
            },
            enumerable: true,
            configurable: true
        });
        PdfImage.prototype.draw = function (graphics, location) {
            if (location && (location.x === null || typeof location.x === 'undefined') && (location.y === null || typeof location.y === 'undefined')) {
                location.x = 0;
                location.y = 0;
            }
            var needSave;
            if (location) {
                needSave = (location.x !== 0 || location.y !== 0);
            }
            var state = null;
            if (needSave) {
                state = graphics.save();
                graphics.translateTransform(location);
            }
            graphics.drawImage(this, { x: 0, y: 0 });
            if (needSave) {
                graphics.restore(state);
            }
        };
        PdfImage.prototype._getPointSize = function (width, height, horizontalResolution) {
            if ((horizontalResolution === null || typeof horizontalResolution === 'undefined')) {
                var dpiX = 96;
                var size = this._getPointSize(width, height, dpiX);
                return size;
            }
            else {
                var ucX = new pdf_graphics_1._PdfUnitConvertor();
                var ucY = new pdf_graphics_1._PdfUnitConvertor();
                var ptWidth = ucX._convertUnits(width, enumerator_1._PdfGraphicsUnit.pixel, enumerator_1._PdfGraphicsUnit.point);
                var ptHeight = ucY._convertUnits(height, enumerator_1._PdfGraphicsUnit.pixel, enumerator_1._PdfGraphicsUnit.point);
                var size = [ptWidth, ptHeight];
                return size;
            }
        };
        return PdfImage;
    }());
    exports.PdfImage = PdfImage;
});