all files / graphics/ pdf-pen.js

70% Statements 70/100
37.04% Branches 10/27
79.17% Functions 19/24
70% Lines 70/100
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   907× 907× 907× 907× 907× 907× 907× 907× 907× 907×     907× 907×   907×       891×     907×           891×       891×                   891×                 888×     904×                                                           891×     888×           891×                 891×                 6031×             891× 891×                   891× 891× 891×     891× 891× 891× 891× 891× 891×       891× 891× 891× 891×   891× 891× 891× 891× 891×   891× 891× 891×   891×        
define(["require", "exports", "./pdf-color", "./brushes/pdf-solid-brush", "./enum", "./brushes/pdf-brush"], function (require, exports, pdf_color_1, pdf_solid_brush_1, enum_1, pdf_brush_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PdfPen = (function () {
        function PdfPen(arg1, arg2) {
            this.pdfColor = new pdf_color_1.PdfColor(0, 0, 0);
            this.dashOffsetValue = 0;
            this.penDashPattern = [0];
            this.pdfDashStyle = enum_1.PdfDashStyle.Solid;
            this.pdfLineCap = 0;
            this.pdfLineJoin = 0;
            this.penWidth = 1.0;
            this.internalMiterLimit = 0.0;
            this.colorSpace = enum_1.PdfColorSpace.Rgb;
            Iif (arg1 instanceof pdf_brush_1.PdfBrush) {
                this.setBrush(arg1);
            }
            else Eif (arg1 instanceof pdf_color_1.PdfColor) {
                this.color = arg1;
            }
            if (typeof arg2 === 'number') {
                this.width = arg2;
            }
        }
        Object.defineProperty(PdfPen.prototype, "color", {
            get: function () {
                return this.pdfColor;
            },
            set: function (value) {
                this.pdfColor = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfPen.prototype, "dashOffset", {
            get: function () {
                Iif (typeof this.dashOffsetValue === 'undefined' || this.dashOffsetValue == null) {
                    return 0;
                }
                else {
                    return this.dashOffsetValue;
                }
            },
            set: function (value) {
                this.dashOffsetValue = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfPen.prototype, "dashPattern", {
            get: function () {
                return this.penDashPattern;
            },
            set: function (value) {
                this.penDashPattern = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfPen.prototype, "dashStyle", {
            get: function () {
                return this.pdfDashStyle;
            },
            set: function (value) {
                Iif (this.pdfDashStyle !== value) {
                    this.pdfDashStyle = value;
                    switch (this.pdfDashStyle) {
                        case enum_1.PdfDashStyle.Custom:
                            break;
                        case enum_1.PdfDashStyle.Dash:
                            this.penDashPattern = [3, 1];
                            break;
                        case enum_1.PdfDashStyle.Dot:
                            this.penDashPattern = [1, 1];
                            break;
                        case enum_1.PdfDashStyle.DashDot:
                            this.penDashPattern = [3, 1, 1, 1];
                            break;
                        case enum_1.PdfDashStyle.DashDotDot:
                            this.penDashPattern = [3, 1, 1, 1, 1, 1];
                            break;
                        case enum_1.PdfDashStyle.Solid:
                            break;
                        default:
                            this.pdfDashStyle = enum_1.PdfDashStyle.Solid;
                            this.penDashPattern = [0];
                            break;
                    }
                }
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfPen.prototype, "lineCap", {
            get: function () {
                return this.pdfLineCap;
            },
            set: function (value) {
                this.pdfLineCap = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfPen.prototype, "lineJoin", {
            get: function () {
                return this.pdfLineJoin;
            },
            set: function (value) {
                this.pdfLineJoin = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfPen.prototype, "miterLimit", {
            get: function () {
                return this.internalMiterLimit;
            },
            set: function (value) {
                this.internalMiterLimit = value;
            },
            enumerable: true,
            configurable: true
        });
        Object.defineProperty(PdfPen.prototype, "width", {
            get: function () {
                return this.penWidth;
            },
            set: function (value) {
                this.penWidth = value;
            },
            enumerable: true,
            configurable: true
        });
        PdfPen.prototype.clone = function () {
            var pen = this;
            return pen;
        };
        PdfPen.prototype.setBrush = function (brush) {
            var sBrush = brush;
            if ((sBrush != null && sBrush instanceof pdf_solid_brush_1.PdfSolidBrush)) {
                this.color = sBrush.color;
                this.pdfBrush = sBrush;
            }
            this.color = sBrush.color;
            this.pdfBrush = sBrush;
        };
        PdfPen.prototype.monitorChanges = function (currentPen, streamWriter, getResources, saveState, currentColorSpace, matrix) {
            var diff = false;
            saveState = true;
            Iif (currentPen == null) {
                diff = true;
            }
            diff = this.dashControl(currentPen, saveState, streamWriter);
            streamWriter.setLineWidth(this.width);
            streamWriter.setLineJoin(this.lineJoin);
            streamWriter.setLineCap(this.lineCap);
            var miterLimit = this.miterLimit;
            Iif (miterLimit > 0) {
                streamWriter.setMiterLimit(miterLimit);
                diff = true;
            }
            var brush = this.pdfBrush;
            streamWriter.setColorAndSpace(this.color, currentColorSpace, true);
            diff = true;
            return diff;
        };
        PdfPen.prototype.dashControl = function (pen, saveState, streamWriter) {
            saveState = true;
            var lineWidth = this.width;
            var pattern = this.getPattern();
            streamWriter.setLineDashPattern(pattern, this.dashOffset * lineWidth);
            return saveState;
        };
        PdfPen.prototype.getPattern = function () {
            var pattern = this.dashPattern;
            for (var i = 0; i < pattern.length; ++i) {
                pattern[i] *= this.width;
            }
            return pattern;
        };
        return PdfPen;
    }());
    exports.PdfPen = PdfPen;
});