all files / annotations/ annotation.js

28.99% Statements 20/69
0% Branches 0/2
8% Functions 2/25
28.99% Lines 20/69
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                                                                                                                                                                                                                                                              
define(["require", "exports", "./../graphics/pdf-color", "./../drawing/pdf-drawing", "./../primitives/pdf-dictionary", "./../primitives/pdf-array", "./../primitives/pdf-number", "./../primitives/pdf-reference", "./../primitives/pdf-string", "./../input-output/pdf-dictionary-properties", "./../primitives/pdf-name", "./../graphics/brushes/pdf-solid-brush", "./../graphics/fonts/pdf-standard-font", "./../graphics/fonts/enum", "./../graphics/fonts/pdf-string-format", "./../graphics/enum"], function (require, exports, pdf_color_1, pdf_drawing_1, pdf_dictionary_1, pdf_array_1, pdf_number_1, pdf_reference_1, pdf_string_1, pdf_dictionary_properties_1, pdf_name_1, pdf_solid_brush_1, pdf_standard_font_1, enum_1, pdf_string_format_1, enum_2) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PdfAnnotation = (function () {
        function PdfAnnotation(arg1) {
            this.dictionaryProperties = new pdf_dictionary_properties_1.DictionaryProperties();
            this.pdfColor = new pdf_color_1.PdfColor(255, 255, 255);
            this.rectangle = new pdf_drawing_1.RectangleF(0, 0, 0, 0);
            this.pdfPage = null;
            this.textBrush = new pdf_solid_brush_1.PdfSolidBrush(new pdf_color_1.PdfColor(0, 0, 0));
            this.textFont = new pdf_standard_font_1.PdfStandardFont(enum_1.PdfFontFamily.TimesRoman, 10);
            this.format = new pdf_string_format_1.PdfStringFormat(enum_2.PdfTextAlignment.Left);
            this.content = '';
            this.pdfDictionary = new pdf_dictionary_1.PdfDictionary();
            this.internalColor = new pdf_color_1.PdfColor();
            this.darkness = 1.0;
            if (typeof arg1 === 'undefined') {
                this.initialize();
            }
            else {
                this.initialize();
                this.bounds = arg1;
            }
        }
        Object.defineProperty(PdfAnnotation.prototype, "color", {
            get: function () {
                return this.pdfColor;
            },
            set: function (value) {
                this.pdfColor = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfAnnotation.prototype, "innerColor", {
            get: function () {
                return this.internalColor;
            },
            set: function (value) {
                this.internalColor = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfAnnotation.prototype, "bounds", {
            get: function () {
                return this.rectangle;
            },
            set: function (value) {
                this.rectangle = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfAnnotation.prototype, "page", {
            get: function () {
                return this.pdfPage;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfAnnotation.prototype, "font", {
            get: function () {
                return this.textFont;
            },
            set: function (value) {
                this.textFont = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfAnnotation.prototype, "stringFormat", {
            get: function () {
                return this.format;
            },
            set: function (value) {
                this.format = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfAnnotation.prototype, "brush", {
            get: function () {
                return this.textBrush;
            },
            set: function (value) {
                this.textBrush = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfAnnotation.prototype, "text", {
            get: function () {
                return this.content;
            },
            set: function (value) {
                this.content = value;
                this.dictionary.items.setValue(this.dictionaryProperties.contents, new pdf_string_1.PdfString(this.content));
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfAnnotation.prototype, "dictionary", {
            get: function () {
                return this.pdfDictionary;
            },
            set: function (value) {
                this.pdfDictionary = value;
            },
            enumerable: true,
            configurable: true
        });
        PdfAnnotation.prototype.initialize = function () {
            this.pdfDictionary.annotationBeginSave = new pdf_dictionary_1.SaveAnnotationEventHandler(this);
            this.pdfDictionary.items.setValue(this.dictionaryProperties.type, new pdf_name_1.PdfName(this.dictionaryProperties.annot));
        };
        PdfAnnotation.prototype.setPage = function (page) {
            this.pdfPage = page;
            this.pdfDictionary.items.setValue(this.dictionaryProperties.p, new pdf_reference_1.PdfReferenceHolder(this.pdfPage));
        };
        PdfAnnotation.prototype.beginSave = function () {
            this.save();
        };
        PdfAnnotation.prototype.save = function () {
            var nativeRectangle = new pdf_drawing_1.RectangleF(this.rectangle.x, this.rectangle.y, this.rectangle.width, this.rectangle.height);
            var section = this.pdfPage.section;
            var initialHeight = nativeRectangle.height;
            var tempLoacation = section.pointToNativePdf(this.page, new pdf_drawing_1.PointF(nativeRectangle.x, nativeRectangle.y));
            nativeRectangle.x = tempLoacation.x;
            nativeRectangle.width = tempLoacation.x + nativeRectangle.width;
            nativeRectangle.y = (tempLoacation.y - this.page.document.pageSettings.margins.top);
            nativeRectangle.height = nativeRectangle.y - initialHeight;
            this.pdfDictionary.items.setValue(this.dictionaryProperties.rect, pdf_array_1.PdfArray.fromRectangle(nativeRectangle));
            this.dictionary.items.setValue(this.dictionaryProperties.ca, new pdf_number_1.PdfNumber(this.darkness));
        };
        Object.defineProperty(PdfAnnotation.prototype, "element", {
            get: function () {
                return this.pdfDictionary;
            },
            enumerable: true,
            configurable: true
        });
        return PdfAnnotation;
    }());
    exports.PdfAnnotation = PdfAnnotation;
});