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

22.3% Statements 31/139
15.49% Branches 11/71
32% Functions 8/25
20.59% Lines 28/136
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                                                                                                                                                                                                                                                                                                                                                                                       
/* 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", "../../primitives/pdf-dictionary", "./../../input-output/pdf-dictionary-properties", "../../primitives/pdf-boolean", "./../../primitives/pdf-array", "./../../primitives/pdf-number", "./pdf-color-blend", "./pdf-gradient-brush", "./enum"], function (require, exports, enum_1, pdf_dictionary_1, pdf_dictionary_properties_1, pdf_boolean_1, pdf_array_1, pdf_number_1, pdf_color_blend_1, pdf_gradient_brush_1, enum_2) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PdfRadialGradientBrush = (function (_super) {
        __extends(PdfRadialGradientBrush, _super);
        function PdfRadialGradientBrush(centerStart, radiusStart, centerEnd, radiusEnd, colorStart, colorEnd) {
            var _this = _super.call(this, new pdf_dictionary_1.PdfDictionary()) || this;
            _this.mDictionaryProperties = new pdf_dictionary_properties_1.DictionaryProperties();
            _this.initialize(colorStart, colorEnd);
            if (radiusStart < 0) {
                throw new Error('ArgumentOutOfRangeException : radiusStart - The radius cannot be less then zero.');
            }
            if (radiusEnd < 0) {
                throw new Error('ArgumentOutOfRangeException : radiusEnd - The radius cannpt be less then zero.');
            }
            _this.mPointEnd = centerEnd;
            _this.mPointStart = centerStart;
            _this.mRadiusStart = radiusStart;
            _this.mRadiusEnd = radiusEnd;
            _this.setPoints(_this.mPointStart, _this.mPointEnd, _this.mRadiusStart, _this.mRadiusEnd);
            return _this;
        }
        PdfRadialGradientBrush.prototype.initialize = function (color1, color2) {
            this.mColour = [color1, color2];
            this.mColourBlends = new pdf_color_blend_1.PdfColorBlend(2);
            this.mColourBlends.positions = [0, 1];
            this.mColourBlends.colors = this.mColour;
            this.initShading();
        };
        Object.defineProperty(PdfRadialGradientBrush.prototype, "blend", {
            get: function () {
                return this.mBlend;
            },
            set: function (value) {
                if ((value == null)) {
                    throw new Error('ArgumentNullException : Blend');
                }
                if ((this.mColour == null && typeof this.mColour === 'undefined')) {
                    throw new Error('NotSupportedException : There is no starting and ending colours specified.');
                }
                this.mBlend = value;
                this.mColourBlends = this.mBlend.generateColorBlend(this.mColour, this.colorSpace);
                this.resetFunction();
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfRadialGradientBrush.prototype, "interpolationColors", {
            get: function () {
                return this.mColourBlends;
            },
            set: function (value) {
                if (value == null) {
                    throw new Error('ArgumentNullException : InterpolationColors');
                }
                this.mBlend = null;
                this.mColour = null;
                this.mColourBlends = value;
                this.resetFunction();
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfRadialGradientBrush.prototype, "linearColors", {
            get: function () {
                return this.mColour;
            },
            set: function (value) {
                if ((value == null)) {
                    throw new Error('ArgumentNullException : radial LinearColors');
                }
                if ((value.length < 2)) {
                    throw new Error('ArgumentException : The array is too small LinearColors');
                }
                if ((this.mColour == null && typeof this.mColour === 'undefined')) {
                    this.mColour = [value[0], value[1]];
                }
                else {
                    this.mColour[0] = value[0];
                    this.mColour[1] = value[1];
                }
                if ((this.mBlend == null && typeof this.mBlend === 'undefined')) {
                    this.mColourBlends = new pdf_color_blend_1.PdfColorBlend(2);
                    this.mColourBlends.colors = this.mColour;
                    this.mColourBlends.positions = [0, 1];
                }
                else {
                    this.mColourBlends = this.mBlend.generateColorBlend(this.mColour, this.colorSpace);
                }
                this.resetFunction();
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfRadialGradientBrush.prototype, "rectangle", {
            get: function () {
                return this.mBoundaries;
            },
            set: function (value) {
                this.mBoundaries = value;
                this.bBox = pdf_array_1.PdfArray.fromRectangle(value);
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfRadialGradientBrush.prototype, "extend", {
            get: function () {
                var result1 = enum_2.PdfExtend.None;
                var extend1 = (this.shading.items.getValue(this.mDictionaryProperties.extend));
                if (extend1 !== null && typeof extend1 !== 'undefined') {
                    var extStart = (extend1.items(0));
                    var extEnd = (extend1.items(1));
                    if (extStart.value) {
                        result1 = (result1 | enum_2.PdfExtend.Start);
                    }
                    if (extEnd.value) {
                        result1 = (result1 | enum_2.PdfExtend.End);
                    }
                }
                return result1;
            },
            set: function (value) {
                var extend = (this.shading.items.getValue(this.mDictionaryProperties.extend));
                var extStart;
                var extEnd1;
                if (extend == null && typeof extend === 'undefined') {
                    extStart = new pdf_boolean_1.PdfBoolean(false);
                    extEnd1 = new pdf_boolean_1.PdfBoolean(false);
                    extend = new pdf_array_1.PdfArray();
                    extend.add(extStart);
                    extend.add(extEnd1);
                    this.shading.items.setValue(this.mDictionaryProperties.extend, extend);
                }
                else {
                    extStart = (extend.items(0));
                    extEnd1 = (extend.items(1));
                }
            },
            enumerable: true,
            configurable: true
        });
        PdfRadialGradientBrush.prototype.setPoints = function (pointStart, pointEnd, radiusStart, radiusEnd) {
            var points = new pdf_array_1.PdfArray();
            points.add(new pdf_number_1.PdfNumber(pointStart.x));
            points.add(new pdf_number_1.PdfNumber(this.updateY(pointStart.y)));
            points.add(new pdf_number_1.PdfNumber(radiusStart));
            points.add(new pdf_number_1.PdfNumber(pointEnd.x));
            points.add(new pdf_number_1.PdfNumber(this.updateY(pointEnd.y)));
            if ((radiusStart !== radiusEnd)) {
                points.add(new pdf_number_1.PdfNumber(radiusEnd));
            }
            else {
                points.add(new pdf_number_1.PdfNumber(0));
            }
            this.shading.items.setValue(this.mDictionaryProperties.coords, points);
        };
        PdfRadialGradientBrush.prototype.updateY = function (y) {
            if (y !== 0) {
                return -y;
            }
            else {
                return y;
            }
        };
        PdfRadialGradientBrush.prototype.initShading = function () {
            this.colorSpace = enum_1.PdfColorSpace.Rgb;
            this.function = this.mColourBlends.getFunction(this.colorSpace);
            this.shading.items.setValue(this.mDictionaryProperties.shadingType, new pdf_number_1.PdfNumber((enum_2.ShadingType.Radial)));
        };
        PdfRadialGradientBrush.prototype.clone = function () {
            var rBrush = this;
            rBrush.resetPatternDictionary(new pdf_dictionary_1.PdfDictionary(this.patternDictionary));
            rBrush.shading = new pdf_dictionary_1.PdfDictionary();
            rBrush.initShading();
            rBrush.setPoints(this.mPointStart, this.mPointEnd, this.mRadiusStart, this.mRadiusEnd);
            if (rBrush instanceof PdfRadialGradientBrush) {
                if ((this.matrix !== null && typeof this.matrix !== 'undefined')) {
                    rBrush.matrix = this.matrix.clone();
                }
            }
            if ((this.mColour !== null && typeof this.mColour !== 'undefined')) {
                rBrush.mColour = (this.mColour);
            }
            if ((this.blend !== null && typeof this.blend !== 'undefined')) {
                rBrush.blend = this.blend.clonePdfBlend();
            }
            else if ((this.interpolationColors !== null && typeof this.interpolationColors !== 'undefined')) {
                rBrush.interpolationColors = this.interpolationColors.cloneColorBlend();
            }
            rBrush.extend = this.extend;
            this.cloneBackgroundValue(rBrush);
            this.cloneAntiAliasingValue(rBrush);
            return rBrush;
        };
        PdfRadialGradientBrush.prototype.resetFunction = function () {
            this.function = this.mColourBlends.getFunction(this.colorSpace);
        };
        return PdfRadialGradientBrush;
    }(pdf_gradient_brush_1.PdfGradientBrush));
    exports.PdfRadialGradientBrush = PdfRadialGradientBrush;
});