Groups path commands into single command

This commit is contained in:
Yury Delendik 2014-04-30 09:09:04 -05:00
parent 00453255f4
commit 63d5aae3f6
4 changed files with 68 additions and 24 deletions

View file

@ -959,26 +959,49 @@ var CanvasGraphics = (function CanvasGraphicsClosure() {
},
// Path
moveTo: function CanvasGraphics_moveTo(x, y) {
this.ctx.moveTo(x, y);
this.current.setCurrentPoint(x, y);
},
lineTo: function CanvasGraphics_lineTo(x, y) {
this.ctx.lineTo(x, y);
this.current.setCurrentPoint(x, y);
},
curveTo: function CanvasGraphics_curveTo(x1, y1, x2, y2, x3, y3) {
this.ctx.bezierCurveTo(x1, y1, x2, y2, x3, y3);
this.current.setCurrentPoint(x3, y3);
},
curveTo2: function CanvasGraphics_curveTo2(x2, y2, x3, y3) {
constructPath: function CanvasGraphics_constructPath(ops, args) {
var ctx = this.ctx;
var current = this.current;
this.ctx.bezierCurveTo(current.x, current.y, x2, y2, x3, y3);
current.setCurrentPoint(x3, y3);
},
curveTo3: function CanvasGraphics_curveTo3(x1, y1, x3, y3) {
this.curveTo(x1, y1, x3, y3, x3, y3);
this.current.setCurrentPoint(x3, y3);
var x = current.x, y = current.y;
for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
switch (ops[i] | 0) {
case OPS.moveTo:
x = args[j++];
y = args[j++];
ctx.moveTo(x, y);
break;
case OPS.lineTo:
x = args[j++];
y = args[j++];
ctx.lineTo(x, y);
break;
case OPS.curveTo:
ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
args[j + 4], args[j + 5]);
x = args[j + 4];
y = args[j + 5];
j += 6;
break;
case OPS.curveTo2:
ctx.bezierCurveTo(x, y, args[j], args[j + 1],
args[j + 2], args[j + 3]);
x = args[j + 2];
y = args[j + 3];
j += 4;
break;
case OPS.curveTo3:
ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
args[j + 2], args[j + 3]);
x = args[j + 2];
y = args[j + 3];
j += 4;
break;
case OPS.closePath:
ctx.closePath();
break;
}
}
current.setCurrentPoint(x, y);
},
closePath: function CanvasGraphics_closePath() {
this.ctx.closePath();