all files / pages/ pdf-page-settings.js

54.1% Statements 33/61
12.5% Branches 1/8
42.86% Functions 9/21
54.1% Lines 33/61
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         73×                                       115×                                                     94×                                                                                          
define(["require", "exports", "./../drawing/pdf-drawing", "./pdf-page-size", "./enum", "./../graphics/pdf-margins"], function (require, exports, pdf_drawing_1, pdf_page_size_1, enum_1, pdf_margins_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PdfPageSettings = (function () {
        function PdfPageSettings(margins) {
            this.pageMargins = new pdf_margins_1.PdfMargins();
            this.pageSize = pdf_page_size_1.PdfPageSize.a4;
            this.rotateAngle = enum_1.PdfPageRotateAngle.RotateAngle0;
            this.pageOrientation = enum_1.PdfPageOrientation.Portrait;
            this.pageOrigin = new pdf_drawing_1.PointF(0, 0);
            this.isRotation = false;
            Eif (typeof margins === 'number') {
                this.pageMargins.setMargins(margins);
            }
        }
        Object.defineProperty(PdfPageSettings.prototype, "size", {
            get: function () {
                return this.pageSize;
            },
            set: function (value) {
                this.setSize(value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfPageSettings.prototype, "orientation", {
            get: function () {
                return this.pageOrientation;
            },
            set: function (orientation) {
                if (this.pageOrientation !== orientation) {
                    this.pageOrientation = orientation;
                    this.updateSize(orientation);
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfPageSettings.prototype, "margins", {
            get: function () {
                return this.pageMargins;
            },
            set: function (value) {
                this.pageMargins = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfPageSettings.prototype, "width", {
            get: function () {
                return this.pageSize.width;
            },
            set: function (value) {
                this.pageSize.width = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfPageSettings.prototype, "height", {
            get: function () {
                return this.pageSize.height;
            },
            set: function (value) {
                this.pageSize.height = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfPageSettings.prototype, "origin", {
            get: function () {
                return this.pageOrigin;
            },
            set: function (value) {
                this.pageOrigin = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfPageSettings.prototype, "rotate", {
            get: function () {
                return this.rotateAngle;
            },
            set: function (value) {
                this.rotateAngle = value;
                this.isRotation = true;
            },
            enumerable: true,
            configurable: true
        });
        PdfPageSettings.prototype.updateSize = function (orientation) {
            var min = Math.min(this.pageSize.width, this.pageSize.height);
            var max = Math.max(this.pageSize.width, this.pageSize.height);
            switch (orientation) {
                case enum_1.PdfPageOrientation.Portrait:
                    this.pageSize = new pdf_drawing_1.SizeF(min, max);
                    break;
                case enum_1.PdfPageOrientation.Landscape:
                    this.pageSize = new pdf_drawing_1.SizeF(max, min);
                    break;
            }
        };
        PdfPageSettings.prototype.clone = function () {
            var settings = this;
            settings.pageMargins = this.pageMargins.clone();
            return settings;
        };
        PdfPageSettings.prototype.getActualSize = function () {
            var width = this.width - (this.margins.left + this.margins.right);
            var height = this.height - (this.margins.top + this.margins.bottom);
            var size = new pdf_drawing_1.SizeF(width, height);
            return size;
        };
        PdfPageSettings.prototype.setSize = function (size) {
            var min = Math.min(size.width, size.height);
            var max = Math.max(size.width, size.height);
            if (this.orientation === enum_1.PdfPageOrientation.Portrait) {
                this.pageSize = new pdf_drawing_1.SizeF(min, max);
            }
            else {
                this.pageSize = new pdf_drawing_1.SizeF(max, min);
            }
        };
        return PdfPageSettings;
    }());
    exports.PdfPageSettings = PdfPageSettings;
});