| 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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× | /* 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", "./../brushes/pdf-brush", "./../pdf-pen", "./../figures/base/element-layouter", "./../../drawing/pdf-drawing", "./enum", "./../figures/base/fill-element", "./../enum"], function (require, exports, pdf_brush_1, pdf_pen_1, element_layouter_1, pdf_drawing_1, enum_1, fill_element_1, enum_2) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var PdfPath = (function (_super) { __extends(PdfPath, _super); function PdfPath(arg1, arg2, arg3, arg4) { var _this = _super.call(this) || this; _this.mpoints = null; _this.mpathTypes = null; _this.mStartFigure = true; _this.mfillMode = enum_2.PdfFillMode.Alternate; _this.isBeziers3 = false; _this.isXps = false; if (typeof arg1 === 'undefined') { } else if (arg1 instanceof pdf_pen_1.PdfPen) { _this = _super.call(this, arg1) || this; if (arg2 instanceof pdf_brush_1.PdfBrush) { _this = _super.call(this, arg1, arg2) || this; _this.fillMode = arg3; } else if (arg2 !== null && typeof arg2 !== 'undefined' && arg3 !== null && typeof arg3 !== 'undefined') { _this.addPath(arg2, arg3); } } else if (arg1 instanceof pdf_brush_1.PdfBrush) { _this = _super.call(this, arg1) || this; if (arg2 !== null && typeof arg2 !== 'undefined') { _this.fillMode = arg2; } if (arg3 !== null && typeof arg3 !== 'undefined' && arg4 !== null && typeof arg4 !== 'undefined') { _this.addPath(arg3, arg4); } } else { _this.addPath(arg1, arg2); } return _this; } Object.defineProperty(PdfPath.prototype, "fillMode", { get: function () { return this.mfillMode; }, set: function (value) { this.mfillMode = value; }, enumerable: true, configurable: true }); Object.defineProperty(PdfPath.prototype, "pathPoints", { get: function () { return this.points; }, enumerable: true, configurable: true }); Object.defineProperty(PdfPath.prototype, "pathTypes", { get: function () { return this.types; }, enumerable: true, configurable: true }); Object.defineProperty(PdfPath.prototype, "pointCount", { get: function () { var count = 0; if ((this.mpoints != null)) { count = this.mpoints.length; } return count; }, enumerable: true, configurable: true }); Object.defineProperty(PdfPath.prototype, "lastPoint", { get: function () { return this.getLastPoint(); }, enumerable: true, configurable: true }); Object.defineProperty(PdfPath.prototype, "points", { get: function () { if ((this.mpoints == null)) { this.mpoints = []; } return this.mpoints; }, enumerable: true, configurable: true }); Object.defineProperty(PdfPath.prototype, "types", { get: function () { if ((this.mpathTypes == null)) { this.mpathTypes = []; } return this.mpathTypes; }, enumerable: true, configurable: true }); PdfPath.prototype.draw = function (arg1, arg2, arg3, arg4) { if (arg2 instanceof pdf_drawing_1.PointF && typeof arg2.width === 'undefined' && typeof arg3 === 'undefined') { return this.drawHelper(arg1, arg2.x, arg2.y); } else if (arg2 instanceof pdf_drawing_1.RectangleF && typeof arg2.width !== 'undefined' && typeof arg3 === 'undefined') { return this.drawHelper(arg1, arg2, null); } else if (typeof arg2 === 'number' && typeof arg3 === 'number' && typeof arg4 === 'undefined') { return this.drawHelper(arg1, arg2, arg3, null); } else if (arg2 instanceof pdf_drawing_1.PointF && arg3 instanceof element_layouter_1.PdfLayoutFormat) { return this.drawHelper(arg1, arg2.x, arg2.y, arg3); } else if (typeof arg2 === 'number' && (arg4 instanceof element_layouter_1.PdfLayoutFormat || arg4 == null) && typeof arg3 === 'number') { var widthValue = (arg1.graphics.clientSize.width - arg2); var layoutRect = new pdf_drawing_1.RectangleF(arg2, arg3, widthValue, 0); return this.drawHelper(arg1, layoutRect, arg4); } else if (arg2 instanceof pdf_drawing_1.RectangleF && arg3 instanceof element_layouter_1.PdfLayoutFormat) { return this.drawHelper(arg1, arg2, arg3); } else { return this.drawHelper(arg1, arg2, arg3); } }; PdfPath.prototype.addArc = function (arg1, arg2, arg3, arg4, arg5, arg6) { if (arg1 instanceof pdf_drawing_1.RectangleF) { this.addArc(arg1.x, arg1.y, arg1.width, arg1.height, arg2, arg3); } else { var points = this.getBezierArcPoints(arg1, arg2, (arg2 + arg3), (arg2 + arg4), arg5, arg6); for (var i = 0; i < points.length; i = i + 8) { var point = [points[i], points[i + 1], points[i + 2], points[i + 3], points[i + 4], points[i + 5], points[i + 6], points[i + 7]]; this.addPoints(point, enum_1.PathPointType.Bezier3); } } }; PdfPath.prototype.addBezier = function (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) { if (arg1 instanceof pdf_drawing_1.PointF && arg2 instanceof pdf_drawing_1.PointF && arg3 instanceof pdf_drawing_1.PointF && arg4 instanceof pdf_drawing_1.PointF) { this.addBezier(arg1.x, arg1.y, arg2.x, arg2.y, arg3.x, arg3.y, arg4.x, arg4.y); } else { var points = []; points.push(arg1); points.push(arg2); points.push(arg3); points.push(arg4); points.push(arg5); points.push(arg6); points.push(arg7); points.push(arg8); this.addPoints(points, enum_1.PathPointType.Bezier3); } }; PdfPath.prototype.addEllipse = function (arg1, arg2, arg3, arg4) { if (arg1 instanceof pdf_drawing_1.RectangleF) { this.addEllipse(arg1.x, arg1.y, arg1.width, arg1.height); } else { this.startFigure(); this.addArc(arg1, arg2, arg3, arg4, 0, 360); this.closeFigure(); } }; PdfPath.prototype.addLine = function (arg1, arg2, arg3, arg4) { if (arg1 instanceof pdf_drawing_1.PointF && arg2 instanceof pdf_drawing_1.PointF) { this.addLine(arg1.x, arg1.y, arg2.x, arg2.y); } else { var points = []; points.push(arg1); points.push(arg2); points.push(arg3); points.push(arg4); this.addPoints(points, enum_1.PathPointType.Line); } }; PdfPath.prototype.addPath = function (arg1, arg2) { if (arg1 instanceof PdfPath) { this.addPath(arg1.pathPoints, arg1.pathTypes); } else { if ((arg1 == null)) { throw new Error('ArgumentNullException:pathPoints'); } if ((arg2 == null)) { throw new Error('ArgumentNullException:pathTypes'); } var count = arg1.length; if ((count !== arg2.length)) { throw new Error('The argument arrays should be of equal length.'); } } }; PdfPath.prototype.addPie = function (arg1, arg2, arg3, arg4, arg5, arg6) { if (arg1 instanceof pdf_drawing_1.RectangleF) { this.addPie(arg1.x, arg1.y, arg1.width, arg1.height, arg2, arg3); } else { this.startFigure(); this.addArc(arg1, arg2, arg3, arg4, arg5, arg6); this.addPoint(new pdf_drawing_1.PointF((arg1 + (arg3 / 2)), (arg2 + (arg4 / 2))), enum_1.PathPointType.Line); this.closeFigure(); } }; PdfPath.prototype.addPolygon = function (points) { var count = (points.length * 2); var p = []; this.startFigure(); for (var i = 0; i < points.length; i++) { p.push(points[i].x); p.push(points[i].y); } this.addPoints(p, enum_1.PathPointType.Line); this.closeFigure(); }; PdfPath.prototype.addRectangle = function (arg1, y, width, height) { if (arg1 instanceof pdf_drawing_1.RectangleF) { this.addRectangle(arg1.x, arg1.y, arg1.width, arg1.height); } else { var points = []; this.startFigure(); points.push(arg1); points.push(y); points.push((arg1 + width)); points.push(y); points.push((arg1 + width)); points.push((y + height)); points.push(arg1); points.push((y + height)); this.addPoints(points, enum_1.PathPointType.Line); this.closeFigure(); } }; PdfPath.prototype.startFigure = function () { this.mStartFigure = true; }; PdfPath.prototype.closeAllFigures = function () { var startPath = this.pathPoints[0]; for (var i = 0; i < this.mpathTypes.length; i++) { var pt = ((this.types[i])); var flag = false; if (((i !== 0) && (pt === enum_1.PathPointType.Start))) { this.closeFigure((i - 1)); flag = true; } else if (((i === (this.mpathTypes.length - 1)) && (!flag && this.isXps))) { if ((startPath.x === this.pathPoints[i].y)) { this.closeFigure(i); } } } }; PdfPath.prototype.getLastPoint = function () { var lastPoint = new pdf_drawing_1.PointF(0, 0); var count = this.pointCount; if (((count > 0) && (this.mpoints != null))) { lastPoint.x = this.mpoints[(count - 1)].x; lastPoint.y = this.mpoints[(count - 1)].y; } return lastPoint; }; PdfPath.prototype.getBezierArcPoints = function (x1, y1, x2, y2, s1, e1) { if ((x1 > x2)) { var tmp = void 0; tmp = x1; x1 = x2; x2 = tmp; } if ((y2 > y1)) { var tmp = void 0; tmp = y1; y1 = y2; y2 = tmp; } var fragAngle; var numFragments; if ((Math.abs(e1) <= 90)) { fragAngle = e1; numFragments = 1; } else { numFragments = (Math.ceil((Math.abs(e1) / 90))); fragAngle = (e1 / numFragments); } var xcen = ((x1 + x2) / 2); var ycen = ((y1 + y2) / 2); var rx = ((x2 - x1) / 2); var ry = ((y2 - y1) / 2); var halfAng = ((fragAngle * (Math.PI / 360))); var kappa = (Math.abs(4.0 / 3.0 * (1.0 - Math.cos(halfAng)) / Math.sin(halfAng))); var pointList = []; for (var i = 0; (i < numFragments); i++) { var theta0 = (((s1 + (i * fragAngle)) * (Math.PI / 180))); var theta1 = (((s1 + ((i + 1) * fragAngle)) * (Math.PI / 180))); var cos0 = (Math.cos(theta0)); var cos1 = (Math.cos(theta1)); var sin0 = (Math.sin(theta0)); var sin1 = (Math.sin(theta1)); if ((fragAngle > 0)) { pointList.push((xcen + (rx * cos0)), (ycen - (ry * sin0)), (xcen + (rx * (cos0 - (kappa * sin0)))), (ycen - (ry * (sin0 + (kappa * cos0)))), (xcen + (rx * (cos1 + (kappa * sin1)))), (ycen - (ry * (sin1 - (kappa * cos1)))), (xcen + (rx * cos1)), (ycen - (ry * sin1))); } else { pointList.push((xcen + (rx * cos0)), (ycen - (ry * sin0)), (xcen + (rx * (cos0 + (kappa * sin0)))), (ycen - (ry * (sin0 - (kappa * cos0)))), (xcen + (rx * (cos1 - (kappa * sin1)))), (ycen - (ry * (sin1 + (kappa * cos1)))), (xcen + (rx * cos1)), (ycen - (ry * sin1))); } } return pointList; }; PdfPath.prototype.getBoundsInternal = function () { var points = this.pathPoints; var bounds = new pdf_drawing_1.RectangleF(0, 0, 0, 0); if ((points.length > 0)) { var xmin = points[0].x; var xmax = points[0].x; var ymin = points[0].y; var ymax = points[0].y; for (var i = 1; i < points.length; i++) { var point = points[i]; xmin = Math.min(point.x, xmin); xmax = Math.max(point.x, xmax); ymin = Math.min(point.y, ymin); ymax = Math.max(point.y, ymax); } bounds = new pdf_drawing_1.RectangleF(xmin, ymin, (xmax - xmin), (ymax - ymin)); } return bounds; }; PdfPath.prototype.drawInternal = function (graphics) { if ((graphics == null)) { throw new Error('ArgumentNullException :graphics'); } graphics.drawPath(this.obtainPen(), this.brush, this); }; PdfPath.prototype.addPoints = function (points, pointType, startIndex, endIndex) { if (typeof startIndex === 'undefined' && typeof endIndex === 'undefined') { this.addPoints(points, pointType, 0, points.length); } else { for (var i = startIndex; i < endIndex; i++) { var point = new pdf_drawing_1.PointF(points[i], points[(i + 1)]); if ((i === startIndex)) { if (((this.pointCount <= 0) || this.mStartFigure)) { this.addPoint(point, enum_1.PathPointType.Start); this.mStartFigure = false; } else if (((point.x !== this.lastPoint.x) && (point.y !== this.lastPoint.y) && !this.isBeziers3)) { this.addPoint(point, enum_1.PathPointType.Line); } else if ((point.x !== this.lastPoint.x) && (point.y !== this.lastPoint.y)) { this.addPoint(point, enum_1.PathPointType.Bezier3); } } else { this.addPoint(point, pointType); } i++; } } }; PdfPath.prototype.addPoint = function (point, pointType) { this.points.push(point); this.types.push((pointType)); }; PdfPath.prototype.closeFigure = function (index) { if (typeof index === 'undefined') { if ((this.pointCount > 0)) { this.closeFigure(this.pointCount - 1); } this.startFigure(); } else { if ((index < 0)) { throw new Error('IndexOutOfRangeException()'); } var pt = ((this.types[index])); pt = (pt | enum_1.PathPointType.CloseSubpath); this.types[index] = (pt); } }; return PdfPath; }(fill_element_1.PdfFillElement)); exports.PdfPath = PdfPath; }); |