Exposed buildShapeFromSvgPath

This commit is contained in:
Chlumsky 2021-08-22 15:16:22 +02:00
parent 24a3a3021f
commit d07fa1d2c8
2 changed files with 6 additions and 3 deletions

View File

@ -129,7 +129,7 @@ static void addArcApproximate(Contour &contour, Point2 startPoint, Point2 endPoi
}
}
static bool buildFromPath(Shape &shape, const char *pathDef, double size) {
bool buildShapeFromSvgPath(Shape &shape, const char *pathDef, double endpointSnapRange) {
char nodeType = '\0';
char prevNodeType = '\0';
Point2 prevNode(0, 0);
@ -248,7 +248,7 @@ static bool buildFromPath(Shape &shape, const char *pathDef, double size) {
NEXT_CONTOUR:
// Fix contour if it isn't properly closed
if (!contour.edges.empty() && prevNode != startPoint) {
if ((contour.edges.back()->point(1)-contour.edges[0]->point(0)).length() < ENDPOINT_SNAP_RANGE_PROPORTION*size)
if ((contour.edges.back()->point(1)-contour.edges[0]->point(0)).length() < endpointSnapRange)
contour.edges.back()->moveEndPoint(contour.edges[0]->point(0));
else
contour.addEdge(new LinearSegment(prevNode, startPoint));
@ -304,7 +304,7 @@ bool loadSvgShape(Shape &output, const char *filename, int pathIndex, Vector2 *d
}
if (dimensions)
*dimensions = dims;
return buildFromPath(output, pd, dims.length());
return buildShapeFromSvgPath(output, pd, ENDPOINT_SNAP_RANGE_PROPORTION*dims.length());
}
}

View File

@ -6,6 +6,9 @@
namespace msdfgen {
/// Builds a shape from an SVG path string
bool buildShapeFromSvgPath(Shape &shape, const char *pathDef, double endpointSnapRange = 0);
/// Reads the first path found in the specified SVG file and stores it as a Shape in output.
bool loadSvgShape(Shape &output, const char *filename, int pathIndex = 0, Vector2 *dimensions = NULL);