all files / graphics/brushes/ pdf-gradient-brush.js

77.6% Statements 97/125
61.54% Branches 32/52
75.76% Functions 25/33
77.05% Lines 94/122
11 statements, 6 functions, 9 branches Ignored     
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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228                                                                                                                                                                                    19×                                                                                        
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "./../enum", "./../pdf-color", "./pdf-brush", "../../primitives/pdf-dictionary", "./../../input-output/pdf-dictionary-properties", "./../../primitives/pdf-boolean", "./../../primitives/pdf-array", "../../primitives/pdf-name", "../../primitives/pdf-number", "../../primitives/pdf-reference"], function (require, exports, enum_1, pdf_color_1, pdf_brush_1, pdf_dictionary_1, pdf_dictionary_properties_1, pdf_boolean_1, pdf_array_1, pdf_name_1, pdf_number_1, pdf_reference_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PdfGradientBrush = (function (_super) {
        __extends(PdfGradientBrush, _super);
        function PdfGradientBrush(shading) {
            var _this = _super.call(this) || this;
            _this.mbackground = new pdf_color_1.PdfColor(255, 255, 255);
            _this.mbStroking = false;
            _this.mfunction = null;
            _this.dictionaryProperties = new pdf_dictionary_properties_1.DictionaryProperties();
            _this.mpatternDictionary = new pdf_dictionary_1.PdfDictionary();
            _this.mpatternDictionary.items.setValue(_this.dictionaryProperties.type, new pdf_name_1.PdfName(_this.dictionaryProperties.pattern));
            _this.mpatternDictionary.items.setValue(_this.dictionaryProperties.patternType, new pdf_number_1.PdfNumber(2));
            _this.shading = shading;
            _this.colorSpace = enum_1.PdfColorSpace.Rgb;
            return _this;
        }
        Object.defineProperty(PdfGradientBrush.prototype, "background", {
            get: function () {
                return this.mbackground;
            },
            set: function (value) {
                this.mbackground = value;
                var sh = this.shading;
                Iif (value.isEmpty) {
                    sh.remove(this.dictionaryProperties.background);
                }
                else {
                    sh.items.setValue(this.dictionaryProperties.background, value.toArray(this.colorSpace));
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfGradientBrush.prototype, "antiAlias", {
            get: function () {
                var sh = this.shading;
                var aa = (sh.items.getValue(this.dictionaryProperties.antiAlias));
                return aa.value;
            },
            set: function (value) {
                var sh = this.shading;
                var aa = (sh.items.getValue(this.dictionaryProperties.antiAlias));
                if ((aa == null && typeof aa === 'undefined')) {
                    aa = new pdf_boolean_1.PdfBoolean(value);
                    sh.items.setValue(this.dictionaryProperties.antiAlias, aa);
                }
                else {
                    aa.value = value;
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfGradientBrush.prototype, "function", {
            get: function () {
                return this.mfunction;
            },
            set: function (value) {
                this.mfunction = value;
                Eif (value != null && typeof value !== 'undefined') {
                    this.shading.items.setValue(this.dictionaryProperties.function, new pdf_reference_1.PdfReferenceHolder(this.mfunction));
                }
                else {
                    this.shading.remove(this.dictionaryProperties.function);
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfGradientBrush.prototype, "bBox", {
            get: function () {
                var sh = this.shading;
                var box = (sh.items.getValue(this.dictionaryProperties.bBox));
                return box;
            },
            set: function (value) {
                var sh = this.shading;
                if (value == null && typeof value === 'undefined') {
                    sh.remove(this.dictionaryProperties.bBox);
                }
                else {
                    sh.items.setValue(this.dictionaryProperties.bBox, value);
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfGradientBrush.prototype, "colorSpace", {
            get: function () {
                return this.mcolorSpace;
            },
            set: function (value) {
                var colorSpace = this.shading.items.getValue(this.dictionaryProperties.colorSpace);
                if ((value !== this.mcolorSpace) || (colorSpace == null)) {
                    this.mcolorSpace = value;
                    var csValue = this.colorSpaceToDeviceName(value);
                    this.shading.items.setValue(this.dictionaryProperties.colorSpace, new pdf_name_1.PdfName(csValue));
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfGradientBrush.prototype, "stroking", {
            get: function () {
                return this.mbStroking;
            },
            set: function (value) {
                this.mbStroking = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfGradientBrush.prototype, "patternDictionary", {
            get: function () {
                Iif (this.mpatternDictionary == null) {
                    this.mpatternDictionary = new pdf_dictionary_1.PdfDictionary();
                }
                return this.mpatternDictionary;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfGradientBrush.prototype, "shading", {
            get: function () {
                return this.mshading;
            },
            set: function (value) {
                Iif (value == null) {
                    throw new Error('ArgumentNullException : Shading');
                }
                Eif (value !== this.mshading) {
                    this.mshading = value;
                    this.patternDictionary.items.setValue(this.dictionaryProperties.shading, new pdf_reference_1.PdfReferenceHolder(this.mshading));
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfGradientBrush.prototype, "matrix", {
            get: function () {
                return this.mmatrix;
            },
            set: function (value) {
                Iif (value == null) {
                    throw new Error('ArgumentNullException : Matrix');
                }
                Eif (value !== this.mmatrix) {
                    this.mmatrix = value.clone();
                    var m = new pdf_array_1.PdfArray(this.mmatrix.matrix.elements);
                    this.mpatternDictionary.items.setValue(this.dictionaryProperties.matrix, m);
                }
            },
            enumerable: true,
            configurable: true
        });
        PdfGradientBrush.prototype.monitorChanges = function (brush, streamWriter, getResources, saveChanges, currentColorSpace) {
            var diff = false;
            Eif (brush instanceof PdfGradientBrush) {
                Iif ((this.colorSpace !== currentColorSpace)) {
                    this.colorSpace = currentColorSpace;
                    this.resetFunction();
                }
                streamWriter.setColorSpace('Pattern', this.mbStroking);
                var resources = getResources.getResources();
                var name_1 = resources.getName(this);
                streamWriter.setColourWithPattern(null, name_1, this.mbStroking);
                diff = true;
            }
            return diff;
        };
        PdfGradientBrush.prototype.resetChanges = function (streamWriter) {
        };
        PdfGradientBrush.prototype.colorSpaceToDeviceName = function (colorSpace) {
            var result;
            switch (colorSpace) {
                case enum_1.PdfColorSpace.Rgb:
                    result = 'DeviceRGB';
                    break;
            }
            return result;
        };
        PdfGradientBrush.prototype.resetPatternDictionary = function (dictionary) {
            this.mpatternDictionary = dictionary;
        };
        PdfGradientBrush.prototype.cloneAntiAliasingValue = function (brush) {
            Iif ((brush == null)) {
                throw new Error('ArgumentNullException : brush');
            }
            var sh = this.shading;
            var aa = (sh.items.getValue(this.dictionaryProperties.antiAlias));
            Iif ((aa != null)) {
                brush.shading.items.setValue(this.dictionaryProperties.antiAlias, new pdf_boolean_1.PdfBoolean(aa.value));
            }
        };
        PdfGradientBrush.prototype.cloneBackgroundValue = function (brush) {
            var background = this.background;
            Eif (!background.isEmpty) {
                brush.background = background;
            }
        };
        Object.defineProperty(PdfGradientBrush.prototype, "element", {
            get: function () {
                return this.patternDictionary;
            },
            enumerable: true,
            configurable: true
        });
        return PdfGradientBrush;
    }(pdf_brush_1.PdfBrush));
    exports.PdfGradientBrush = PdfGradientBrush;
});