Fix handling of [Ss] command’s control point calculation

This commit is contained in:
Christopher Kohnert 2017-06-09 11:04:23 -07:00
parent c2ab38d9e5
commit 5827e10bdd
1 changed files with 10 additions and 5 deletions

View File

@ -139,15 +139,16 @@ static bool buildFromPath(Shape &shape, const char *pathDef, double size) {
char nodeType; char nodeType;
Point2 prevNode(0, 0); Point2 prevNode(0, 0);
bool nodeTypePreread = false; bool nodeTypePreread = false;
Point2 startPoint;
Point2 controlPoint[2];
Point2 node;
char prevNodeType = '\0';
while (nodeTypePreread || readNodeType(nodeType, pathDef)) { while (nodeTypePreread || readNodeType(nodeType, pathDef)) {
nodeTypePreread = false; nodeTypePreread = false;
Contour &contour = shape.addContour(); Contour &contour = shape.addContour();
bool contourStart = true; bool contourStart = true;
Point2 startPoint;
Point2 controlPoint[2];
Point2 node;
while (*pathDef) { while (*pathDef) {
switch (nodeType) { switch (nodeType) {
case 'M': case 'm': case 'M': case 'm':
@ -213,6 +214,9 @@ static bool buildFromPath(Shape &shape, const char *pathDef, double size) {
contour.addEdge(new CubicSegment(prevNode, controlPoint[0], controlPoint[1], node)); contour.addEdge(new CubicSegment(prevNode, controlPoint[0], controlPoint[1], node));
break; break;
case 'S': case 's': case 'S': case 's':
if (prevNodeType != 'c' && prevNodeType != 'C' && prevNodeType != 's' && prevNodeType != 'S')
controlPoint[0] = node;
else
controlPoint[0] = node+node-controlPoint[1]; controlPoint[0] = node+node-controlPoint[1];
REQUIRE(readCoord(controlPoint[1], pathDef)); REQUIRE(readCoord(controlPoint[1], pathDef));
consumeOptionalComma(pathDef); consumeOptionalComma(pathDef);
@ -260,6 +264,7 @@ static bool buildFromPath(Shape &shape, const char *pathDef, double size) {
else else
contour.addEdge(new LinearSegment(prevNode, startPoint)); contour.addEdge(new LinearSegment(prevNode, startPoint));
} }
prevNodeType = nodeType;
prevNode = startPoint; prevNode = startPoint;
} }
return true; return true;