| 453 | } |
| 454 | |
| 455 | protected parsePathData(path: PathElement) { |
| 456 | this.pathLength = -1 // reset path length |
| 457 | |
| 458 | if (!path) { |
| 459 | return [] |
| 460 | } |
| 461 | |
| 462 | const pathCommands: IPathCommand[] = [] |
| 463 | const { pathParser } = path |
| 464 | |
| 465 | pathParser.reset() |
| 466 | |
| 467 | // convert l, H, h, V, and v to L |
| 468 | while (!pathParser.isEnd()) { |
| 469 | const { current } = pathParser |
| 470 | const startX = current ? current.x : 0 |
| 471 | const startY = current ? current.y : 0 |
| 472 | const command = pathParser.next() |
| 473 | let nextCommandType: CommandType = command.type |
| 474 | let points: number[] = [] |
| 475 | |
| 476 | switch (command.type) { |
| 477 | case PathParser.MOVE_TO: |
| 478 | this.pathM(pathParser, points) |
| 479 | break |
| 480 | |
| 481 | case PathParser.LINE_TO: |
| 482 | nextCommandType = this.pathL(pathParser, points) |
| 483 | break |
| 484 | |
| 485 | case PathParser.HORIZ_LINE_TO: |
| 486 | nextCommandType = this.pathH(pathParser, points) |
| 487 | break |
| 488 | |
| 489 | case PathParser.VERT_LINE_TO: |
| 490 | nextCommandType = this.pathV(pathParser, points) |
| 491 | break |
| 492 | |
| 493 | case PathParser.CURVE_TO: |
| 494 | this.pathC(pathParser, points) |
| 495 | break |
| 496 | |
| 497 | case PathParser.SMOOTH_CURVE_TO: |
| 498 | nextCommandType = this.pathS(pathParser, points) |
| 499 | break |
| 500 | |
| 501 | case PathParser.QUAD_TO: |
| 502 | this.pathQ(pathParser, points) |
| 503 | break |
| 504 | |
| 505 | case PathParser.SMOOTH_QUAD_TO: |
| 506 | nextCommandType = this.pathT(pathParser, points) |
| 507 | break |
| 508 | |
| 509 | case PathParser.ARC: |
| 510 | points = this.pathA(pathParser) |
| 511 | break |
| 512 | |