Jelajahi Sumber

Exposed buildShapeFromSvgPath

Chlumsky 4 tahun lalu
induk
melakukan
d07fa1d2c8
2 mengubah file dengan 6 tambahan dan 3 penghapusan
  1. 3 3
      ext/import-svg.cpp
  2. 3 0
      ext/import-svg.h

+ 3 - 3
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());
 }
 
 }

+ 3 - 0
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);