all files / annotations/ annotation-collection.js

18.03% Statements 11/61
0% Branches 0/8
22.22% Functions 2/9
18.03% Lines 11/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                                                                                                                                                                  
define(["require", "exports", "./../primitives/pdf-array", "./../primitives/pdf-reference", "./../input-output/pdf-dictionary-properties", "./../drawing/pdf-drawing", "./../graphics/fonts/string-layouter", "./../graphics/enum"], function (require, exports, pdf_array_1, pdf_reference_1, pdf_dictionary_properties_1, pdf_drawing_1, string_layouter_1, enum_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PdfAnnotationCollection = (function () {
        function PdfAnnotationCollection(page) {
            this.alreadyExistsAnnotationError = 'This annotatation had been already added to page';
            this.missingAnnotationException = 'Annotation is not contained in collection.';
            this.dictionaryProperties = new pdf_dictionary_properties_1.DictionaryProperties();
            this.internalAnnotations = new pdf_array_1.PdfArray();
            this.lists = [];
            if (typeof page !== 'undefined') {
                this.page = page;
            }
        }
        Object.defineProperty(PdfAnnotationCollection.prototype, "annotations", {
            get: function () {
                return this.internalAnnotations;
            },
            set: function (value) {
                this.internalAnnotations = value;
            },
            enumerable: true,
            configurable: true
        });
        PdfAnnotationCollection.prototype.add = function (annotation) {
            this.doAdd(annotation);
        };
        PdfAnnotationCollection.prototype.doAdd = function (annotation) {
            if (typeof annotation.destination !== 'undefined') {
                var layout = new string_layouter_1.PdfStringLayouter();
                var layoutResult = layout.layout(annotation.text, annotation.font, annotation.stringFormat, new pdf_drawing_1.SizeF((annotation.bounds.width), 0), false, new pdf_drawing_1.SizeF(0, 0));
                var lastPosition = annotation.bounds.y;
                if (layoutResult.lines.length === 1) {
                    var size = annotation.font.measureString(layoutResult.lines[0].text);
                    annotation.bounds = new pdf_drawing_1.RectangleF(new pdf_drawing_1.PointF(annotation.bounds.x, lastPosition), size);
                    annotation.text = layoutResult.lines[0].text;
                    this.page.graphics.drawString(annotation.text, annotation.font, null, annotation.brush, annotation.bounds.x, annotation.bounds.y, annotation.bounds.width, annotation.bounds.height, null);
                    annotation.setPage(this.page);
                    this.setColor(annotation);
                    this.internalAnnotations.add(new pdf_reference_1.PdfReferenceHolder(annotation));
                    this.lists.push(annotation);
                }
                else {
                    for (var i = 0; i < layoutResult.lines.length; i++) {
                        var size = annotation.font.measureString(layoutResult.lines[i].text);
                        if (i === 0) {
                            annotation.bounds = new pdf_drawing_1.RectangleF(annotation.bounds.x, lastPosition, size.width, size.height);
                            annotation.text = layoutResult.lines[i].text;
                            this.page.graphics.drawString(annotation.text, annotation.font, null, annotation.brush, annotation.bounds.x, lastPosition, size.width, size.height, null);
                            annotation.setPage(this.page);
                            this.setColor(annotation);
                            this.internalAnnotations.add(new pdf_reference_1.PdfReferenceHolder(annotation));
                            this.lists.push(annotation);
                            lastPosition += annotation.bounds.height;
                        }
                        else {
                            var annot = annotation.clone();
                            annot.bounds = new pdf_drawing_1.RectangleF(new pdf_drawing_1.PointF(annotation.bounds.x, lastPosition), size);
                            annot.text = layoutResult.lines[i].text;
                            this.page.graphics.drawString(annot.text, annot.font, null, annot.brush, annot.bounds.x, annot.bounds.y, annot.bounds.width, annot.bounds.height, null);
                            annot.setPage(this.page);
                            this.setColor(annot);
                            this.internalAnnotations.add(new pdf_reference_1.PdfReferenceHolder(annot));
                            this.lists.push(annot);
                            lastPosition += annot.bounds.height;
                        }
                    }
                }
            }
            else {
                annotation.setPage(this.page);
                this.internalAnnotations.add(new pdf_reference_1.PdfReferenceHolder(annotation));
                return this.lists.push(annotation);
            }
        };
        PdfAnnotationCollection.prototype.setColor = function (annotation) {
            var cs = enum_1.PdfColorSpace.Rgb;
            var colours = annotation.color.toArray(cs);
            annotation.dictionary.items.setValue(this.dictionaryProperties.c, colours);
        };
        Object.defineProperty(PdfAnnotationCollection.prototype, "element", {
            get: function () {
                return this.internalAnnotations;
            },
            enumerable: true,
            configurable: true
        });
        return PdfAnnotationCollection;
    }());
    exports.PdfAnnotationCollection = PdfAnnotationCollection;
});