quadraticCurveTo fix

15 views
Skip to first unread message

nathan...@gmail.com

unread,
Jan 9, 2007, 5:10:53 PM1/9/07
to google-excanvas
Firefox appears to have fixed their problem with quadraticCurveTo - I
thought it would be helpful to post a patch which fixes excanvas.js.
Here it is (patch is against the version to download on sf - not the
latest in svn...):

--- excanvas.js.orig 2006-03-21 09:41:56.000000000 -0800
+++ excanvas.js 2007-01-09 14:09:09.000000000 -0800
@@ -251,10 +251,14 @@ if (!window.CanvasRenderingContext2D) {

contextPrototype.moveTo = function(aX, aY) {
this.currentPath_.push({type: "moveTo", x: aX, y: aY});
+ this.currentX_ = aX;
+ this.currentY_ = aY;
};

contextPrototype.lineTo = function(aX, aY) {
this.currentPath_.push({type: "lineTo", x: aX, y: aY});
+ this.currentX_ = aX;
+ this.currentY_ = aY;
};

contextPrototype.bezierCurveTo = function(aCP1x, aCP1y,
@@ -267,12 +271,18 @@ if (!window.CanvasRenderingContext2D) {
cp2y: aCP2y,
x: aX,
y: aY});
+ this.currentX_ = aX;
+ this.currentY_ = aY;
};

contextPrototype.quadraticCurveTo = function(aCPx, aCPy, aX, aY) {
- // VML's qb produces different output to Firefox's
- // FF's behaviour seems to have changed in 1.5.0.1, check this
- this.bezierCurveTo(aCPx, aCPy, aCPx, aCPy, aX, aY);
+ // the following is lifted almost directly from
+ //
http://developer.mozilla.org/en/docs/Canvas_tutorial:Drawing_shapes
+ var cp1x = this.currentX_ + 2.0/3.0*(aCPx - this.currentX_);
+ var cp1y = this.currentY_ + 2.0/3.0*(aCPy - this.currentY_);
+ var cp2x = cp1x + (aX - this.currentX_)/3.0;
+ var cp2y = cp1y + (aY - this.currentY_)/3.0;
+ this.bezierCurveTo( cp1x, cp1y, cp2x, cp2y, aX, aY );
};

contextPrototype.arc = function(aX, aY, aRadius,

Reply all
Reply to author
Forward
0 new messages