all files / general/ pdf-cache-collection.js

67.44% Statements 29/43
14.29% Branches 2/14
87.5% Functions 7/8
67.44% Lines 29/43
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                                                                    
define(["require", "exports", "./../collections/dictionary"], function (require, exports, dictionary_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PdfCacheCollection = (function () {
        function PdfCacheCollection() {
            this.referenceObjects = [];
            this.pdfFontCollection = new dictionary_1.Dictionary();
        }
        PdfCacheCollection.prototype.search = function (obj) {
            var result = null;
            var group = this.getGroup(obj);
            Eif (group == null) {
                group = this.createNewGroup();
            }
            else if (group.length > 0) {
                result = group[0];
            }
            group.push(obj);
            return result;
        };
        PdfCacheCollection.prototype.createNewGroup = function () {
            var group = [];
            this.referenceObjects.push(group);
            return group;
        };
        PdfCacheCollection.prototype.getGroup = function (result) {
            var group = null;
            Eif (result !== null) {
                var len = this.referenceObjects.length;
                for (var i = 0; i < len; i++) {
                    if (this.referenceObjects.length > 0) {
                        var tGroup = this.referenceObjects[i];
                        if (tGroup.length > 0) {
                            var representative = tGroup[0];
                            if (result.equalsTo(representative)) {
                                group = tGroup;
                                break;
                            }
                        }
                        else {
                            this.removeGroup(tGroup);
                        }
                    }
                    len = this.referenceObjects.length;
                }
            }
            return group;
        };
        PdfCacheCollection.prototype.removeGroup = function (group) {
            if (group !== null) {
                var index = this.referenceObjects.indexOf(group);
                this.referenceObjects.slice(index, index + 1);
            }
        };
        PdfCacheCollection.prototype.destroy = function () {
            this.pdfFontCollection = undefined;
            this.referenceObjects = undefined;
        };
        return PdfCacheCollection;
    }());
    exports.PdfCacheCollection = PdfCacheCollection;
});