Skip to content

Commit

Permalink
fixed the index out of range exception and added web pic to loadShap…
Browse files Browse the repository at this point in the history
…e9.html [#798]
  • Loading branch information
annasob committed Aug 11, 2010
1 parent 490a271 commit 064a626
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 24 deletions.
1 change: 1 addition & 0 deletions examples/seneca/loadShape/loadShape9.html
Expand Up @@ -57,6 +57,7 @@
}
</script><canvas id="display" ></canvas>
<div> The actual shape: <img src="t.jpg"></div>
<div> The shape on the WEB: <img src="tweb.jpg"></div>
</body>
</html>

Binary file added examples/seneca/loadShape/tweb.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 68 additions & 24 deletions processing.js
Expand Up @@ -1829,6 +1829,7 @@
var str = "";
var tmpArray =[];
var flag = false;
var lastInstruction;
while (i< pathData.length) {
valOf = pathData[i].valueOf();
if ((valOf >= 65 && valOf <= 90) || (valOf >= 97 && valOf <= 122)) { // if its a letter
Expand Down Expand Up @@ -1889,6 +1890,7 @@
}
}
}
lastInstruction = "M";
break;
case 109: // m - move to (relative)
if (tmpArray.length >= 2 && tmpArray.length % 2 === 0) { // need one+ pairs of co-ordinates
Expand All @@ -1902,6 +1904,7 @@
}
}
}
lastInstruction = "m";
break;
case 76: // L
if (tmpArray.length >= 2 && tmpArray.length % 2 === 0) { // need one+ pairs of co-ordinates
Expand All @@ -1911,6 +1914,7 @@
this.parsePathLineto(cx,cy);
}
}
lastInstruction = "L";
break;

case 108: // l
Expand All @@ -1921,34 +1925,39 @@
this.parsePathLineto(cx,cy);
}
}
lastInstruction = "l";
break;

case 72: // horizontal lineto absolute
for (j = 0; j < tmpArray.length; j++) { // multiple x co-ordinates can be provided
cx = tmpArray[j];
this.parsePathLineto(cx, cy);
}
lastInstruction ="h";
break;

case 104: // horizontal lineto relative
for (j = 0; j < tmpArray.length; j++) { // multiple x co-ordinates can be provided
cx += tmpArray[j];
this.parsePathLineto(cx, cy);
}
lastInstruction = "H";
break;

case 86:
for (j = 0; j < tmpArray.length; j++) { // multiple y co-ordinates can be provided
cy = tmpArray[j];
this.parsePathLineto(cx, cy);
}
lastInstruction = "V";
break;

case 118:
for (j = 0; j < tmpArray.length; j++) { // multiple y co-ordinates can be provided
cy += tmpArray[j];
this.parsePathLineto(cx, cy);
}
lastInstruction = "v";
break;

case 67: // C - curve to (absolute)
Expand All @@ -1965,6 +1974,7 @@
cy = endY;
}
}
lastInstruction = "C";
break;

case 99: // c - curve to (relative)
Expand All @@ -1981,17 +1991,24 @@
cy = endY;
}
}
lastInstruction = "c";
break;

case 83: // S - curve to shorthand (absolute)
if (tmpArray.length >= 4 && tmpArray.length % 4 === 0) { // need one+ multiples of 4 co-ordinates
for (j = 0; j < tmpArray.length; j+=4) {
ppx = this.vertices[ this.vertices.length-2 ][0];
ppy = this.vertices[ this.vertices.length-2 ][1];
px = this.vertices[ this.vertices.length-1 ][0];
py = this.vertices[ this.vertices.length-1 ][1];
ctrlX1 = px + (px - ppx);
ctrlY1 = py + (py - ppy);
if (lastInstruction.toLowerCase() === "c" || lastInstruction.toLowerCase() === "s") {
ppx = this.vertices[ this.vertices.length-2 ][0];
ppy = this.vertices[ this.vertices.length-2 ][1];
px = this.vertices[ this.vertices.length-1 ][0];
py = this.vertices[ this.vertices.length-1 ][1];
ctrlX1 = px + (px - ppx);
ctrlY1 = py + (py - ppy);
} else {
//If there is no previous curve, the current point will be used as the first control point.
ctrlX1 = this.vertices[this.vertices.length-1][0];
ctrlY1 = this.vertices[this.vertices.length-1][1];
}
ctrlX2 = tmpArray[j];
ctrlY2 = tmpArray[j + 1];
endX = tmpArray[j + 2];
Expand All @@ -2001,17 +2018,24 @@
cy = endY;
}
}
lastInstruction = "S";
break;

case 115: // s - curve to shorthand (relative)
if (tmpArray.length >= 4 && tmpArray.length % 4 === 0) { // need one+ multiples of 4 co-ordinates
for (j = 0; j < tmpArray.length; j+=4) {
ppx = this.vertices[this.vertices.length-2][0];
ppy = this.vertices[this.vertices.length-2][1];
px = this.vertices[this.vertices.length-1][0];
py = this.vertices[this.vertices.length-1][1];
ctrlX1 = px + (px - ppx);
ctrlY1 = py + (py - ppy);
if (lastInstruction.toLowerCase() === "c" || lastInstruction.toLowerCase() === "s") {
ppx = this.vertices[this.vertices.length-2][0];
ppy = this.vertices[this.vertices.length-2][1];
px = this.vertices[this.vertices.length-1][0];
py = this.vertices[this.vertices.length-1][1];
ctrlX1 = px + (px - ppx);
ctrlY1 = py + (py - ppy);
} else {
//If there is no previous curve, the current point will be used as the first control point.
ctrlX1 = this.vertices[this.vertices.length-1][0];
ctrlY1 = this.vertices[this.vertices.length-1][1];
}
ctrlX2 = cx + tmpArray[j];
ctrlY2 = cy + tmpArray[j + 1];
endX = cx + tmpArray[j + 2];
Expand All @@ -2021,6 +2045,7 @@
cy = endY;
}
}
lastInstruction = "s";
break;

case 81: // Q - quadratic curve to (absolute)
Expand All @@ -2035,6 +2060,7 @@
cy = endY;
}
}
lastInstruction = "Q";
break;

case 113: // q - quadratic curve to (relative)
Expand All @@ -2049,6 +2075,7 @@
cy = endY;
}
}
lastInstruction = "q";
break;

// T - quadratic curve to shorthand (absolute)
Expand All @@ -2060,42 +2087,59 @@
case 84:
if (tmpArray.length >= 2 && tmpArray.length % 2 === 0) { // need one+ pairs of co-ordinates
for (j = 0; j < tmpArray.length; j+=2) {
ppx = this.vertices[this.vertices.length-2][0];
ppy = this.vertices[this.vertices.length-2][1];
px = this.vertices[this.vertices.length-1][0];
py = this.vertices[this.vertices.length-1][1];
ctrlX = px + (px - ppx);
ctrlY = py + (py - ppy);
if (lastInstruction.toLowerCase() === "q" || lastInstruction.toLowerCase() === "t") {
ppx = this.vertices[this.vertices.length-2][0];
ppy = this.vertices[this.vertices.length-2][1];
px = this.vertices[this.vertices.length-1][0];
py = this.vertices[this.vertices.length-1][1];
ctrlX = px + (px - ppx);
ctrlY = py + (py - ppy);
} else {
// 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.
ctrlX = cx;
ctrlY = cy;
}
endX = tmpArray[j];
endY = tmpArray[j + 1];
this.parsePathQuadto(cx, cy, ctrlX, ctrlY, endX, endY);
cx = endX;
cy = endY;
}
}
lastInstruction = "T";
break;

case 116: // t - quadratic curve to shorthand (relative)
if (tmpArray.length >= 2 && tmpArray.length % 2 === 0) { // need one+ pairs of co-ordinates
for (j = 0; j < tmpArray.length; j+=2) {
ppx = this.vertices[this.vertices.length-2][0];
ppy = this.vertices[this.vertices.length-2][1];
px = this.vertices[this.vertices.length-1][0];
py = this.vertices[this.vertices.length-1][1];
ctrlX = px + (px - ppx);
ctrlY = py + (py - ppy);
if (lastInstruction.toLowerCase() === "q" || lastInstruction.toLowerCase() === "t") {
ppx = this.vertices[this.vertices.length-2][0];
ppy = this.vertices[this.vertices.length-2][1];
px = this.vertices[this.vertices.length-1][0];
py = this.vertices[this.vertices.length-1][1];
ctrlX = px + (px - ppx);
ctrlY = py + (py - ppy);
} else {
// 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.
ctrlX = cx;
ctrlY = cy;
}
endX = cx + tmpArray[j];
endY = cy + tmpArray[j + 1];
this.parsePathQuadto(cx, cy, ctrlX, ctrlY, endX, endY);
cx = endX;
cy = endY;
}
}
lastInstruction = "t";
break;

case 90: //Z
case 122: //z
this.close = true;
lastInstruction = "z";
break;
}
} else { i++;}
Expand Down

0 comments on commit 064a626

Please sign in to comment.