all files / pages/ pdf-document-page-collection.js

80.26% Statements 61/76
60% Branches 12/20
92.31% Functions 12/13
80.26% Lines 61/76
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       34×           440×         26× 13× 13× 13×     13× 13×     13× 13×   13× 13×     34× 34× 34× 34×   34×   10×   10×     10× 10× 10× 10× 10× 10× 10× 10× 10× 10× 10× 10×       10×   460× 460×       460× 460× 460× 460× 460× 460× 460×               460×                                    
define(["require", "exports", "./pdf-page", "./../collections/dictionary"], function (require, exports, pdf_page_1, dictionary_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PdfDocumentPageCollection = (function () {
        function PdfDocumentPageCollection(document) {
            this.pdfPageCollectionIndex = new dictionary_1.Dictionary();
            this.document = document;
        }
        Object.defineProperty(PdfDocumentPageCollection.prototype, "count", {
            get: function () {
                return this.countPages();
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfDocumentPageCollection.prototype, "pageCollectionIndex", {
            get: function () {
                return this.pdfPageCollectionIndex;
            },
            enumerable: true,
            configurable: true
        });
        PdfDocumentPageCollection.prototype.add = function (page) {
            if (typeof page === 'undefined') {
                var page_1 = new pdf_page_1.PdfPage();
                this.add(page_1);
                return page_1;
            }
            else {
                var section = this.getLastSection();
                section.add(page);
            }
        };
        PdfDocumentPageCollection.prototype.getLastSection = function () {
            var sc = this.document.sections;
            if (sc.section.length === 0) {
                sc.add();
            }
            var section = sc.section[sc.section.length - 1];
            return section;
        };
        PdfDocumentPageCollection.prototype.onPageAdded = function (args) {
        };
        PdfDocumentPageCollection.prototype.countPages = function () {
            var sc = this.document.sections;
            var count = 0;
            for (var index = 0; index < sc.section.length; index++) {
                count += sc.section[index].count;
            }
            return count;
        };
        PdfDocumentPageCollection.prototype.getPageByIndex = function (index) {
            return this.getPage(index);
        };
        PdfDocumentPageCollection.prototype.getPage = function (index) {
            Iif ((index < 0) || (index >= this.count)) {
                throw Error('ArgumentOutOfRangeException("index", "Value can not be less 0")');
            }
            var page = null;
            var sectionStartIndex = 0;
            var sectionCount = 0;
            var pageIndex = 0;
            var length = this.document.sections.count;
            for (var i = 0; i < length; i++) {
                var section = this.document.sections.section[i];
                sectionCount = section.count;
                pageIndex = index - sectionStartIndex;
                Eif ((index >= sectionStartIndex && pageIndex < sectionCount)) {
                    page = section.getPages()[pageIndex];
                    break;
                }
                sectionStartIndex += sectionCount;
            }
            return page;
        };
        PdfDocumentPageCollection.prototype.indexOf = function (page) {
            var index = -1;
            Iif (page == null) {
                throw new Error('ArgumentNullException: page');
            }
            else {
                var numPages = 0;
                for (var i = 0, len = this.document.sections.count; i < len; i++) {
                    var section = this.document.sections.pdfSectionCollection(i);
                    index = section.indexOf(page);
                    Eif (index >= 0) {
                        index += numPages;
                        break;
                    }
                    else {
                        index = -1;
                    }
                    numPages += section.count;
                }
            }
            return index;
        };
        PdfDocumentPageCollection.prototype.remove = function (page) {
            if (page == null) {
                throw Error('ArgumentNullException("page")');
            }
            var section = null;
            var len;
            for (var i = 0, len_1 = this.document.sections.count; i < len_1; i++) {
                section = this.document.sections.pdfSectionCollection(i);
                if (section.pages.contains(page)) {
                    section.pages.remove(page);
                    break;
                }
            }
            return section;
        };
        return PdfDocumentPageCollection;
    }());
    exports.PdfDocumentPageCollection = PdfDocumentPageCollection;
});