70 inline std::vector<DtParsedPolyline>
parseSvgPath(
const std::string& d,
73 std::vector<DtParsedPolyline> result;
80 for (
int i = 1; i <= bezierSegs; ++i)
82 double t =
static_cast<double>(i) / bezierSegs;
84 double x = mt*mt*mt*p0.
x + 3.0*mt*mt*t*p1.x
85 + 3.0*mt*t*t*p2.x + t*t*t*p3.x;
86 double y = mt*mt*mt*p0.
y + 3.0*mt*mt*t*p1.y
87 + 3.0*mt*t*t*p2.y + t*t*t*p3.y;
88 current.
points.push_back({ x, y });
96 if (c ==
',') c =
' ';
98 std::istringstream ss(src);
100 double cx = 0.0, cy = 0.0;
101 double spx = 0.0, spy = 0.0;
103 auto readNum = [&](
double& v) ->
bool {
104 return static_cast<bool>(ss >> v);
107 while (ss >> std::ws && !ss.eof())
111 char peek =
static_cast<char>(ss.peek());
112 if (std::isalpha(static_cast<unsigned char>(peek)))
118 if ((newCmd ==
'M' || newCmd ==
'm') && !current.
points.empty())
120 result.push_back(current);
131 if (!readNum(x) || !readNum(y))
continue;
134 current.
points.push_back({ cx, cy });
140 if (!readNum(x) || !readNum(y))
continue;
143 current.
points.push_back({ cx, cy });
149 if (!readNum(x) || !readNum(y))
continue;
151 current.
points.push_back({ cx, cy });
156 if (!readNum(x) || !readNum(y))
continue;
158 current.
points.push_back({ cx, cy });
163 if (!readNum(x))
continue;
165 current.
points.push_back({ cx, cy });
170 if (!readNum(x))
continue;
172 current.
points.push_back({ cx, cy });
177 if (!readNum(y))
continue;
179 current.
points.push_back({ cx, cy });
184 if (!readNum(y))
continue;
186 current.
points.push_back({ cx, cy });
192 double x1, y1, x2, y2, ex, ey;
193 if (!readNum(x1) || !readNum(y1) ||
194 !readNum(x2) || !readNum(y2) ||
195 !readNum(ex) || !readNum(ey))
continue;
196 sampleCubic({ cx, cy }, { x1, y1 }, { x2, y2 }, { ex, ey });
204 double dx1, dy1, dx2, dy2, dx, dy;
205 if (!readNum(dx1) || !readNum(dy1) ||
206 !readNum(dx2) || !readNum(dy2) ||
207 !readNum(dx) || !readNum(dy))
continue;
208 sampleCubic({ cx, cy },
219 result.push_back(current);
230 if (!current.
points.empty())
231 result.push_back(current);
Definition: DtMilStdTypes.h:205
double x
Definition: DtMilStdTypes.h:207
bool closed
True when the sub-path ended with Z/z.
Definition: DtMilStdSvgPathParser.h:59
std::vector< DtParsedPolyline > parseSvgPath(const std::string &d, int bezierSegs=24)
Parse a JSON SVG path d-string into a list of polylines.
Definition: DtMilStdSvgPathParser.h:70
Definition: DtMilStdSvgPathParser.h:56
double y
Definition: DtMilStdTypes.h:208
std::vector< DtPoint > points
Definition: DtMilStdSvgPathParser.h:58