From c71b1378df924c38be607e7322fab7dc59925a94 Mon Sep 17 00:00:00 2001 From: Jim Rodovich Date: Thu, 8 Jan 2015 09:46:10 -0600 Subject: [PATCH] Make corresponding fixes for relative curve bounding box calculations. --- src/shapes/path.class.js | 60 +++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/src/shapes/path.class.js b/src/shapes/path.class.js index 05c09599..c465723d 100644 --- a/src/shapes/path.class.js +++ b/src/shapes/path.class.js @@ -357,8 +357,7 @@ ); x = tempX; y = tempY; - controlX = x + current[1]; - controlY = y + current[2]; + break; case 'T': @@ -613,8 +612,6 @@ controlY = 0, // current control point y tempX, tempY, - tempControlX, - tempControlY, bounds; for (var i = 0, len = this.path.length; i < len; ++i) { @@ -709,9 +706,17 @@ tempX = x + current[3]; tempY = y + current[4]; - // calculate reflection of previous control points - controlX = controlX ? (2 * x - controlX) : x; - controlY = controlY ? (2 * y - controlY) : y; + if (previous[0].match(/[CcSs]/) === null) { + // If there is no previous command or if the previous command was not a C, c, S, or s, + // the control point is coincident with the current point + controlX = x; + controlY = y; + } + else { + // calculate reflection of previous control points + controlX = 2 * x - controlX; + controlY = 2 * y - controlY; + } bounds = fabric.util.getBoundsOfCurve(x, y, controlX, @@ -734,9 +739,17 @@ case 'S': // shorthand cubic bezierCurveTo, absolute tempX = current[3]; tempY = current[4]; - // calculate reflection of previous control points - controlX = 2 * x - controlX; - controlY = 2 * y - controlY; + if (previous[0].match(/[CcSs]/) === null) { + // If there is no previous command or if the previous command was not a C, c, S, or s, + // the control point is coincident with the current point + controlX = x; + controlY = y; + } + else { + // calculate reflection of previous control points + controlX = 2 * x - controlX; + controlY = 2 * y - controlY; + } bounds = fabric.util.getBoundsOfCurve(x, y, controlX, controlY, @@ -798,20 +811,12 @@ controlX = x; controlY = y; } - else if (previous[0] === 't') { - // calculate reflection of previous control points for t - controlX = 2 * x - tempControlX; - controlY = 2 * y - tempControlY; - } - else if (previous[0] === 'q') { - // calculate reflection of previous control points for q + else { + // calculate reflection of previous control point controlX = 2 * x - controlX; controlY = 2 * y - controlY; } - tempControlX = controlX; - tempControlY = controlY; - bounds = fabric.util.getBoundsOfCurve(x, y, controlX, controlY, @@ -828,9 +833,18 @@ case 'T': tempX = current[1]; tempY = current[2]; - // calculate reflection of previous control points - controlX = 2 * x - controlX; - controlY = 2 * y - controlY; + + if (previous[0].match(/[QqTt]/) === null) { + // If there is no previous command or if the previous command was not a Q, q, T or t, + // assume the control point is coincident with the current point + controlX = x; + controlY = y; + } + else { + // calculate reflection of previous control point + controlX = 2 * x - controlX; + controlY = 2 * y - controlY; + } bounds = fabric.util.getBoundsOfCurve(x, y, controlX, controlY,