mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-01 10:34:42 +00:00
Merge pull request #1919 from rodovich/fix-reflected-curves
Fix bugs with reflected curve path elements
This commit is contained in:
commit
5a1ff427d2
1 changed files with 73 additions and 46 deletions
|
|
@ -130,8 +130,6 @@
|
|||
controlY = 0, // current control point y
|
||||
tempX,
|
||||
tempY,
|
||||
tempControlX,
|
||||
tempControlY,
|
||||
l = -this.pathOffset.x,
|
||||
t = -this.pathOffset.y;
|
||||
|
||||
|
|
@ -234,9 +232,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;
|
||||
}
|
||||
|
||||
ctx.bezierCurveTo(
|
||||
controlX + l,
|
||||
|
|
@ -260,9 +266,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;
|
||||
}
|
||||
ctx.bezierCurveTo(
|
||||
controlX + l,
|
||||
controlY + t,
|
||||
|
|
@ -329,20 +343,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;
|
||||
|
||||
ctx.quadraticCurveTo(
|
||||
controlX + l,
|
||||
controlY + t,
|
||||
|
|
@ -351,17 +357,24 @@
|
|||
);
|
||||
x = tempX;
|
||||
y = tempY;
|
||||
controlX = x + current[1];
|
||||
controlY = y + current[2];
|
||||
|
||||
break;
|
||||
|
||||
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;
|
||||
}
|
||||
ctx.quadraticCurveTo(
|
||||
controlX + l,
|
||||
controlY + t,
|
||||
|
|
@ -599,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) {
|
||||
|
|
@ -695,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,
|
||||
|
|
@ -720,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,
|
||||
|
|
@ -784,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,
|
||||
|
|
@ -808,16 +827,24 @@
|
|||
);
|
||||
x = tempX;
|
||||
y = tempY;
|
||||
controlX = x + current[1];
|
||||
controlY = y + current[2];
|
||||
|
||||
break;
|
||||
|
||||
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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue