|
330 | 330 | }, |
331 | 331 |
|
332 | 332 | bezierCurveTo : function(x1, y1, x2, y2, x, y) { |
333 | | - console.log('bezierCurveTo not implemented'); |
| 333 | + x1 = this._wrapX(x1); |
| 334 | + y1 = this._wrapY(y1); |
| 335 | + x2 = this._wrapX(x2); |
| 336 | + y2 = this._wrapY(y2); |
334 | 337 | x = this._wrapX(x); |
335 | 338 | y = this._wrapY(y); |
336 | 339 | var obj = { |
337 | | - type : 'lt', |
| 340 | + type : 'bct', |
| 341 | + x1 : x1, |
| 342 | + y1 : y1, |
| 343 | + x2 : x2, |
| 344 | + y2 : y2, |
338 | 345 | x : x, |
339 | 346 | y : y |
340 | 347 | }; |
341 | 348 | this.path.push(obj); |
342 | 349 | }, |
343 | 350 |
|
344 | | - quadradicCurveTo : function(x1, y1, x, y) { |
345 | | - console.log('quadradicCurveTo not implemented'); |
| 351 | + quadraticCurveTo : function(x1, y1, x, y) { |
| 352 | + x1 = this._wrapX(x1); |
| 353 | + y1 = this._wrapY(y1); |
346 | 354 | x = this._wrapX(x); |
347 | 355 | y = this._wrapY(y); |
348 | 356 | var obj = { |
349 | | - type : 'lt', |
| 357 | + type : 'qct', |
| 358 | + x1 : x1, |
| 359 | + y1 : y1, |
350 | 360 | x : x, |
351 | 361 | y : y |
352 | 362 | }; |
353 | | - this.path.push(obj); |
354 | | - }, |
| 363 | + this.path.push(obj); }, |
355 | 364 |
|
356 | 365 | arc : function(x,y,radius,startAngle,endAngle,anticlockwise) { |
357 | 366 | x = this._wrapX(x); |
|
412 | 421 | ]; |
413 | 422 | deltas.push(delta); |
414 | 423 | break; |
| 424 | + case 'bct': |
| 425 | + var delta = [ |
| 426 | + pt.x1 - this.path[i - 1].x, pt.y1 - this.path[i - 1].y, |
| 427 | + pt.x2 - this.path[i - 1].x, pt.y2 - this.path[i - 1].y, |
| 428 | + pt.x - this.path[i - 1].x, pt.y - this.path[i - 1].y |
| 429 | + ]; |
| 430 | + deltas.push(delta); |
| 431 | + break; |
| 432 | + case 'qct': |
| 433 | + // convert to bezier |
| 434 | + var x1 = this.path[i - 1].x + 2.0/3.0 * (pt.x1 - this.path[i - 1].x); |
| 435 | + var y1 = this.path[i - 1].y + 2.0/3.0 * (pt.y1 - this.path[i - 1].y); |
| 436 | + var x2 = pt.x + 2.0/3.0 * (pt.x1 - pt.x); |
| 437 | + var y2 = pt.y + 2.0/3.0 * (pt.y1 - pt.y); |
| 438 | + var x3 = pt.x; |
| 439 | + var y3 = pt.y; |
| 440 | + var delta = [ |
| 441 | + x1 - this.path[i - 1].x, y1 - this.path[i - 1].y, |
| 442 | + x2 - this.path[i - 1].x, y2 - this.path[i - 1].y, |
| 443 | + x3 - this.path[i - 1].x, y3 - this.path[i - 1].y |
| 444 | + ]; |
| 445 | + deltas.push(delta); |
| 446 | + break; |
415 | 447 | case 'close': |
416 | 448 | closed = true; |
417 | 449 | break; |
|
456 | 488 | ]; |
457 | 489 | deltas.push(delta); |
458 | 490 | break; |
| 491 | + case 'bct': |
| 492 | + var delta = [ |
| 493 | + pt.x1 - this.path[i - 1].x, pt.y1 - this.path[i - 1].y, |
| 494 | + pt.x2 - this.path[i - 1].x, pt.y2 - this.path[i - 1].y, |
| 495 | + pt.x - this.path[i - 1].x, pt.y - this.path[i - 1].y |
| 496 | + ]; |
| 497 | + deltas.push(delta); |
| 498 | + break; |
| 499 | + case 'qct': |
| 500 | + // convert to bezier |
| 501 | + var x1 = this.path[i - 1].x + 2.0/3.0 * (pt.x1 - this.path[i - 1].x); |
| 502 | + var y1 = this.path[i - 1].y + 2.0/3.0 * (pt.y1 - this.path[i - 1].y); |
| 503 | + var x2 = pt.x + 2.0/3.0 * (pt.x1 - pt.x); |
| 504 | + var y2 = pt.y + 2.0/3.0 * (pt.y1 - pt.y); |
| 505 | + var x3 = pt.x; |
| 506 | + var y3 = pt.y; |
| 507 | + var delta = [ |
| 508 | + x1 - this.path[i - 1].x, y1 - this.path[i - 1].y, |
| 509 | + x2 - this.path[i - 1].x, y2 - this.path[i - 1].y, |
| 510 | + x3 - this.path[i - 1].x, y3 - this.path[i - 1].y |
| 511 | + ]; |
| 512 | + deltas.push(delta); |
| 513 | + break; |
459 | 514 | } |
460 | 515 | } |
461 | 516 |
|
|
0 commit comments