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

68.75% Statements 55/80
42.42% Branches 14/33
55.56% Functions 10/18
68.75% Lines 55/80
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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159   15× 15× 15× 15× 15× 15×     15× 15× 15× 15×                                 15×           1975×                                   15×                             93× 15×   93×                                           30× 30×                 15× 15× 15× 15× 15× 15× 15× 15× 15× 15×     15× 15× 15×       15× 15× 15× 15× 15×           15×     15×              
define(["require", "exports", "./../primitives/pdf-stream", "./../graphics/pdf-graphics", "./pdf-page-layer-collection", "./../input-output/pdf-dictionary-properties", "./../graphics/enum"], function (require, exports, pdf_stream_1, pdf_graphics_1, pdf_page_layer_collection_1, pdf_dictionary_properties_1, enum_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PdfPageLayer = (function () {
        function PdfPageLayer(page, streamClipPageTemplates) {
            this.pdfColorSpace = enum_1.PdfColorSpace.Rgb;
            this.isVisible = true;
            this.sublayer = false;
            this.contentLength = 0;
            this.dictionaryProperties = new pdf_dictionary_properties_1.DictionaryProperties();
            Iif (page === null) {
                throw new Error('ArgumentNullException:page');
            }
            this.pdfPage = page;
            this.clipPageTemplates = true;
            Eif (typeof streamClipPageTemplates === 'undefined') {
                this.content = new pdf_stream_1.PdfStream();
            }
            else if (streamClipPageTemplates instanceof pdf_stream_1.PdfStream || streamClipPageTemplates === null) {
                if (streamClipPageTemplates === null) {
                    throw new Error('ArgumentNullException:stream');
                }
                this.content = streamClipPageTemplates;
            }
            else {
                this.content = new pdf_stream_1.PdfStream();
                this.clipPageTemplates = streamClipPageTemplates;
            }
        }
        Object.defineProperty(PdfPageLayer.prototype, "colorSpace", {
            get: function () {
                return this.pdfColorSpace;
            },
            set: function (value) {
                this.pdfColorSpace = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfPageLayer.prototype, "page", {
            get: function () {
                return this.pdfPage;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfPageLayer.prototype, "layerId", {
            get: function () {
                return this.layerid;
            },
            set: function (value) {
                this.layerid = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfPageLayer.prototype, "name", {
            get: function () {
                return this.layerName;
            },
            set: function (value) {
                this.layerName = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfPageLayer.prototype, "visible", {
            get: function () {
                return this.isVisible;
            },
            set: function (value) {
                this.isVisible = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfPageLayer.prototype, "graphics", {
            get: function () {
                if ((this.pdfGraphics == null)) {
                    this.initializeGraphics(this.page);
                }
                return this.pdfGraphics;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfPageLayer.prototype, "layers", {
            get: function () {
                if (this.layer == null) {
                    this.layer = new pdf_page_layer_collection_1.PdfPageLayerCollection(this.page);
                    this.layer.sublayer = true;
                    return this.layer;
                }
                else {
                    return this.layer;
                }
            },
            enumerable: true,
            configurable: true
        });
        PdfPageLayer.prototype.add = function () {
            var layer = new PdfPageLayer(this.pdfPage);
            layer.name = '';
            return layer;
        };
        PdfPageLayer.prototype.sign = function (number) {
            Eif (number === 0) {
                return 0;
            }
            else if (number > 0) {
                return 1;
            }
            else {
                return -1;
            }
        };
        PdfPageLayer.prototype.initializeGraphics = function (page) {
            var oPage = page;
            var gr = new pdf_graphics_1.GetResourceEventHandler(this.page);
            var cropBox = null;
            this.pdfGraphics = new pdf_graphics_1.PdfGraphics(page.size, gr, this.content);
            this.pdfGraphics.mediaBoxUpperRightBound = 0;
            Eif (oPage != null) {
                var sc = oPage.section.parent;
                Eif (sc != null) {
                    this.pdfGraphics.colorSpace = sc.document.colorSpace;
                    this.colorSpace = sc.document.colorSpace;
                }
            }
            var isSame = (this.sign(page.origin.y) === this.sign(page.origin.x));
            Eif (page.origin.x >= 0 && page.origin.y >= 0 || !(isSame)) {
                this.pdfGraphics.initializeCoordinates();
            }
            else {
            }
            var clipRect = oPage.section.getActualBounds(oPage, true);
            var margins = oPage.section.pageSettings.margins;
            Eif (this.clipPageTemplates) {
                Eif (page.origin.x >= 0 && page.origin.y >= 0) {
                    this.pdfGraphics.clipTranslateMargins(clipRect);
                }
            }
            else {
                this.graphics.clipTranslateMargins(clipRect.x, clipRect.y, margins.left, margins.top, margins.right, margins.bottom);
            }
            this.pdfGraphics.setLayer(this);
        };
        Object.defineProperty(PdfPageLayer.prototype, "element", {
            get: function () {
                return this.content;
            },
            enumerable: true,
            configurable: true
        });
        return PdfPageLayer;
    }());
    exports.PdfPageLayer = PdfPageLayer;
});