MCPcopy Create free account
hub / github.com/VitalAudio/visage / parseSvgPath

Method parseSvgPath

visage_graphics/path.cpp:195–281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

193 }
194
195 Path::CommandList Path::parseSvgPath(const std::string& path) {
196 CommandList commands;
197 size_t i = 0;
198 char command_char = 0;
199 while (i < path.size()) {
200 if (std::isspace(path[i])) {
201 ++i;
202 continue;
203 }
204
205 char new_command = path[i];
206 if (std::isalpha(new_command)) {
207 command_char = new_command;
208 ++i;
209 }
210
211 char type = std::toupper(command_char);
212 bool relative = std::islower(command_char);
213
214 if (type == 'M') {
215 float x = parseNumber(path, i);
216 float y = parseNumber(path, i);
217 commands.moveTo(x, y, relative);
218
219 if (std::isspace(path[i])) {
220 ++i;
221 continue;
222 }
223
224 if (i < path.size() && !std::isalpha(path[i])) {
225 x = parseNumber(path, i);
226 y = parseNumber(path, i);
227 commands.lineTo(x, y, relative);
228 }
229 }
230 else if (type == 'L') {
231 float x = parseNumber(path, i);
232 float y = parseNumber(path, i);
233 commands.lineTo(x, y, relative);
234 }
235 else if (type == 'H')
236 commands.horizontalTo(parseNumber(path, i), relative);
237 else if (type == 'V')
238 commands.verticalTo(parseNumber(path, i), relative);
239 else if (type == 'Z')
240 commands.close();
241 else if (type == 'C') {
242 float cx1 = parseNumber(path, i);
243 float cy1 = parseNumber(path, i);
244 float cx2 = parseNumber(path, i);
245 float cy2 = parseNumber(path, i);
246 float x = parseNumber(path, i);
247 float y = parseNumber(path, i);
248 commands.bezierTo(cx1, cy1, cx2, cy2, x, y, relative);
249 }
250 else if (type == 'S') {
251 float cx = parseNumber(path, i);
252 float cy = parseNumber(path, i);

Callers

nothing calls this directly

Calls 12

parseNumberFunction · 0.70
sizeMethod · 0.45
moveToMethod · 0.45
lineToMethod · 0.45
horizontalToMethod · 0.45
verticalToMethod · 0.45
closeMethod · 0.45
bezierToMethod · 0.45
smoothBezierToMethod · 0.45
quadraticToMethod · 0.45
smoothQuadraticToMethod · 0.45
arcToMethod · 0.45

Tested by

no test coverage detected