From d07fa1d2c8088f87463182a05cab9bee29844e70 Mon Sep 17 00:00:00 2001 From: Chlumsky Date: Sun, 22 Aug 2021 15:16:22 +0200 Subject: [PATCH] Exposed buildShapeFromSvgPath --- ext/import-svg.cpp | 6 +++--- ext/import-svg.h | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ext/import-svg.cpp b/ext/import-svg.cpp index ce686b8..c92384f 100644 --- a/ext/import-svg.cpp +++ b/ext/import-svg.cpp @@ -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()); } } diff --git a/ext/import-svg.h b/ext/import-svg.h index cd69d2f..88e7ebd 100644 --- a/ext/import-svg.h +++ b/ext/import-svg.h @@ -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);