mirror of https://github.com/Chlumsky/msdfgen.git
Exposed buildShapeFromSvgPath
This commit is contained in:
parent
24a3a3021f
commit
d07fa1d2c8
|
|
@ -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 nodeType = '\0';
|
||||||
char prevNodeType = '\0';
|
char prevNodeType = '\0';
|
||||||
Point2 prevNode(0, 0);
|
Point2 prevNode(0, 0);
|
||||||
|
|
@ -248,7 +248,7 @@ static bool buildFromPath(Shape &shape, const char *pathDef, double size) {
|
||||||
NEXT_CONTOUR:
|
NEXT_CONTOUR:
|
||||||
// Fix contour if it isn't properly closed
|
// Fix contour if it isn't properly closed
|
||||||
if (!contour.edges.empty() && prevNode != startPoint) {
|
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));
|
contour.edges.back()->moveEndPoint(contour.edges[0]->point(0));
|
||||||
else
|
else
|
||||||
contour.addEdge(new LinearSegment(prevNode, startPoint));
|
contour.addEdge(new LinearSegment(prevNode, startPoint));
|
||||||
|
|
@ -304,7 +304,7 @@ bool loadSvgShape(Shape &output, const char *filename, int pathIndex, Vector2 *d
|
||||||
}
|
}
|
||||||
if (dimensions)
|
if (dimensions)
|
||||||
*dimensions = dims;
|
*dimensions = dims;
|
||||||
return buildFromPath(output, pd, dims.length());
|
return buildShapeFromSvgPath(output, pd, ENDPOINT_SNAP_RANGE_PROPORTION*dims.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,9 @@
|
||||||
|
|
||||||
namespace msdfgen {
|
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.
|
/// 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);
|
bool loadSvgShape(Shape &output, const char *filename, int pathIndex = 0, Vector2 *dimensions = NULL);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue