mirror of https://github.com/Chlumsky/msdfgen.git
Merge branch 'graceful_close'
* graceful_close: Better handling of whitespace at end of input stream.
This commit is contained in:
commit
a4f4fdb447
|
|
@ -17,10 +17,11 @@ namespace msdfgen {
|
|||
#endif
|
||||
|
||||
|
||||
static bool readNodeType(char &output, const char *&pathDef) {
|
||||
static bool readNodeType(char &output, bool &haveInput, const char *&pathDef) {
|
||||
int shift;
|
||||
char nodeType;
|
||||
if (sscanf(pathDef, " %c%n", &nodeType, &shift) == 1 && nodeType != '+' && nodeType != '-' && nodeType != '.' && nodeType != ',' && (nodeType < '0' || nodeType > '9')) {
|
||||
haveInput = sscanf(pathDef, " %c%n", &nodeType, &shift) == 1;
|
||||
if ( haveInput && nodeType != '+' && nodeType != '-' && nodeType != '.' && nodeType != ',' && (nodeType < '0' || nodeType > '9')) {
|
||||
pathDef += shift;
|
||||
output = nodeType;
|
||||
return true;
|
||||
|
|
@ -220,7 +221,8 @@ static Point2 handleArc(const char *&pathDef, char nodeType, Point2 prevNode, Co
|
|||
static bool buildFromPath(Shape &shape, const char *pathDef) {
|
||||
char nodeType;
|
||||
Point2 prevNode(0, 0);
|
||||
while (readNodeType(nodeType, pathDef)) {
|
||||
bool haveInput = pathDef && *pathDef;
|
||||
while (haveInput && readNodeType(nodeType, haveInput, pathDef)) {
|
||||
Contour &contour = shape.addContour();
|
||||
bool contourStart = true;
|
||||
|
||||
|
|
@ -228,7 +230,7 @@ static bool buildFromPath(Shape &shape, const char *pathDef) {
|
|||
Point2 controlPoint[2];
|
||||
Point2 node;
|
||||
|
||||
while (*pathDef) {
|
||||
while (haveInput) {
|
||||
switch (nodeType) {
|
||||
case 'M': case 'm':
|
||||
REQUIRE(contourStart);
|
||||
|
|
@ -304,7 +306,7 @@ static bool buildFromPath(Shape &shape, const char *pathDef) {
|
|||
}
|
||||
contourStart &= nodeType == 'M' || nodeType == 'm';
|
||||
prevNode = node;
|
||||
readNodeType(nodeType, pathDef);
|
||||
readNodeType(nodeType, haveInput, pathDef);
|
||||
}
|
||||
NEXT_CONTOUR:;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue