Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1496 lines
52KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. class SVGState
  18. {
  19. public:
  20. //==============================================================================
  21. explicit SVGState (const XmlElement* const topLevel)
  22. : topLevelXml (topLevel, nullptr),
  23. width (512), height (512),
  24. viewBoxW (0), viewBoxH (0)
  25. {
  26. }
  27. struct XmlPath
  28. {
  29. XmlPath (const XmlElement* e, const XmlPath* p) noexcept : xml (e), parent (p) {}
  30. const XmlElement& operator*() const noexcept { jassert (xml != nullptr); return *xml; }
  31. const XmlElement* operator->() const noexcept { return xml; }
  32. XmlPath getChild (const XmlElement* e) const noexcept { return XmlPath (e, this); }
  33. template <typename OperationType>
  34. bool applyOperationToChildWithID (const String& id, OperationType& op) const
  35. {
  36. forEachXmlChildElement (*xml, e)
  37. {
  38. XmlPath child (e, this);
  39. if (e->compareAttribute ("id", id))
  40. {
  41. op (child);
  42. return true;
  43. }
  44. if (child.applyOperationToChildWithID (id, op))
  45. return true;
  46. }
  47. return false;
  48. }
  49. const XmlElement* xml;
  50. const XmlPath* parent;
  51. };
  52. //==============================================================================
  53. struct UsePathOp
  54. {
  55. const SVGState* state;
  56. Path* targetPath;
  57. void operator() (const XmlPath& xmlPath)
  58. {
  59. state->parsePathElement (xmlPath, *targetPath);
  60. }
  61. };
  62. struct GetClipPathOp
  63. {
  64. const SVGState* state;
  65. Drawable* target;
  66. void operator() (const XmlPath& xmlPath)
  67. {
  68. state->applyClipPath (*target, xmlPath);
  69. }
  70. };
  71. struct SetGradientStopsOp
  72. {
  73. const SVGState* state;
  74. ColourGradient* gradient;
  75. void operator() (const XmlPath& xml)
  76. {
  77. state->addGradientStopsIn (*gradient, xml);
  78. }
  79. };
  80. struct GetFillTypeOp
  81. {
  82. const SVGState* state;
  83. const Path* path;
  84. float opacity;
  85. FillType fillType;
  86. void operator() (const XmlPath& xml)
  87. {
  88. if (xml->hasTagNameIgnoringNamespace ("linearGradient")
  89. || xml->hasTagNameIgnoringNamespace ("radialGradient"))
  90. fillType = state->getGradientFillType (xml, *path, opacity);
  91. }
  92. };
  93. //==============================================================================
  94. Drawable* parseSVGElement (const XmlPath& xml)
  95. {
  96. DrawableComposite* const drawable = new DrawableComposite();
  97. setCommonAttributes (*drawable, xml);
  98. SVGState newState (*this);
  99. if (xml->hasAttribute ("transform"))
  100. newState.addTransform (xml);
  101. newState.width = getCoordLength (xml->getStringAttribute ("width", String (newState.width)), viewBoxW);
  102. newState.height = getCoordLength (xml->getStringAttribute ("height", String (newState.height)), viewBoxH);
  103. if (newState.width <= 0) newState.width = 100;
  104. if (newState.height <= 0) newState.height = 100;
  105. Point<float> viewboxXY;
  106. if (xml->hasAttribute ("viewBox"))
  107. {
  108. const String viewBoxAtt (xml->getStringAttribute ("viewBox"));
  109. String::CharPointerType viewParams (viewBoxAtt.getCharPointer());
  110. Point<float> vwh;
  111. if (parseCoords (viewParams, viewboxXY, true)
  112. && parseCoords (viewParams, vwh, true)
  113. && vwh.x > 0
  114. && vwh.y > 0)
  115. {
  116. newState.viewBoxW = vwh.x;
  117. newState.viewBoxH = vwh.y;
  118. const int placementFlags = parsePlacementFlags (xml->getStringAttribute ("preserveAspectRatio").trim());
  119. if (placementFlags != 0)
  120. newState.transform = RectanglePlacement (placementFlags)
  121. .getTransformToFit (Rectangle<float> (viewboxXY.x, viewboxXY.y, vwh.x, vwh.y),
  122. Rectangle<float> (newState.width, newState.height))
  123. .followedBy (newState.transform);
  124. }
  125. }
  126. else
  127. {
  128. if (viewBoxW == 0) newState.viewBoxW = newState.width;
  129. if (viewBoxH == 0) newState.viewBoxH = newState.height;
  130. }
  131. newState.parseSubElements (xml, *drawable);
  132. drawable->setContentArea (RelativeRectangle (RelativeCoordinate (viewboxXY.x),
  133. RelativeCoordinate (viewboxXY.x + newState.viewBoxW),
  134. RelativeCoordinate (viewboxXY.y),
  135. RelativeCoordinate (viewboxXY.y + newState.viewBoxH)));
  136. drawable->resetBoundingBoxToContentArea();
  137. return drawable;
  138. }
  139. //==============================================================================
  140. void parsePathString (Path& path, const String& pathString) const
  141. {
  142. String::CharPointerType d (pathString.getCharPointer().findEndOfWhitespace());
  143. Point<float> subpathStart, last, last2, p1, p2, p3;
  144. juce_wchar currentCommand = 0, previousCommand = 0;
  145. bool isRelative = true;
  146. bool carryOn = true;
  147. while (! d.isEmpty())
  148. {
  149. if (CharPointer_ASCII ("MmLlHhVvCcSsQqTtAaZz").indexOf (*d) >= 0)
  150. {
  151. currentCommand = d.getAndAdvance();
  152. isRelative = currentCommand >= 'a';
  153. }
  154. switch (currentCommand)
  155. {
  156. case 'M':
  157. case 'm':
  158. case 'L':
  159. case 'l':
  160. if (parseCoordsOrSkip (d, p1, false))
  161. {
  162. if (isRelative)
  163. p1 += last;
  164. if (currentCommand == 'M' || currentCommand == 'm')
  165. {
  166. subpathStart = p1;
  167. path.startNewSubPath (p1);
  168. currentCommand = 'l';
  169. }
  170. else
  171. path.lineTo (p1);
  172. last2 = last;
  173. last = p1;
  174. }
  175. break;
  176. case 'H':
  177. case 'h':
  178. if (parseCoord (d, p1.x, false, true))
  179. {
  180. if (isRelative)
  181. p1.x += last.x;
  182. path.lineTo (p1.x, last.y);
  183. last2.x = last.x;
  184. last.x = p1.x;
  185. }
  186. else
  187. {
  188. ++d;
  189. }
  190. break;
  191. case 'V':
  192. case 'v':
  193. if (parseCoord (d, p1.y, false, false))
  194. {
  195. if (isRelative)
  196. p1.y += last.y;
  197. path.lineTo (last.x, p1.y);
  198. last2.y = last.y;
  199. last.y = p1.y;
  200. }
  201. else
  202. {
  203. ++d;
  204. }
  205. break;
  206. case 'C':
  207. case 'c':
  208. if (parseCoordsOrSkip (d, p1, false)
  209. && parseCoordsOrSkip (d, p2, false)
  210. && parseCoordsOrSkip (d, p3, false))
  211. {
  212. if (isRelative)
  213. {
  214. p1 += last;
  215. p2 += last;
  216. p3 += last;
  217. }
  218. path.cubicTo (p1, p2, p3);
  219. last2 = p2;
  220. last = p3;
  221. }
  222. break;
  223. case 'S':
  224. case 's':
  225. if (parseCoordsOrSkip (d, p1, false)
  226. && parseCoordsOrSkip (d, p3, false))
  227. {
  228. if (isRelative)
  229. {
  230. p1 += last;
  231. p3 += last;
  232. }
  233. p2 = last + (last - last2);
  234. path.cubicTo (p2, p1, p3);
  235. last2 = p1;
  236. last = p3;
  237. }
  238. break;
  239. case 'Q':
  240. case 'q':
  241. if (parseCoordsOrSkip (d, p1, false)
  242. && parseCoordsOrSkip (d, p2, false))
  243. {
  244. if (isRelative)
  245. {
  246. p1 += last;
  247. p2 += last;
  248. }
  249. path.quadraticTo (p1, p2);
  250. last2 = p1;
  251. last = p2;
  252. }
  253. break;
  254. case 'T':
  255. case 't':
  256. if (parseCoordsOrSkip (d, p1, false))
  257. {
  258. if (isRelative)
  259. p1 += last;
  260. p2 = CharPointer_ASCII ("QqTt").indexOf (previousCommand) >= 0 ? last + (last - last2)
  261. : p1;
  262. path.quadraticTo (p2, p1);
  263. last2 = p2;
  264. last = p1;
  265. }
  266. break;
  267. case 'A':
  268. case 'a':
  269. if (parseCoordsOrSkip (d, p1, false))
  270. {
  271. String num;
  272. if (parseNextNumber (d, num, false))
  273. {
  274. const float angle = degreesToRadians (num.getFloatValue());
  275. if (parseNextNumber (d, num, false))
  276. {
  277. const bool largeArc = num.getIntValue() != 0;
  278. if (parseNextNumber (d, num, false))
  279. {
  280. const bool sweep = num.getIntValue() != 0;
  281. if (parseCoordsOrSkip (d, p2, false))
  282. {
  283. if (isRelative)
  284. p2 += last;
  285. if (last != p2)
  286. {
  287. double centreX, centreY, startAngle, deltaAngle;
  288. double rx = p1.x, ry = p1.y;
  289. endpointToCentreParameters (last.x, last.y, p2.x, p2.y,
  290. angle, largeArc, sweep,
  291. rx, ry, centreX, centreY,
  292. startAngle, deltaAngle);
  293. path.addCentredArc ((float) centreX, (float) centreY,
  294. (float) rx, (float) ry,
  295. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  296. false);
  297. path.lineTo (p2);
  298. }
  299. last2 = last;
  300. last = p2;
  301. }
  302. }
  303. }
  304. }
  305. }
  306. break;
  307. case 'Z':
  308. case 'z':
  309. path.closeSubPath();
  310. last = last2 = subpathStart;
  311. d = d.findEndOfWhitespace();
  312. currentCommand = 'M';
  313. break;
  314. default:
  315. carryOn = false;
  316. break;
  317. }
  318. if (! carryOn)
  319. break;
  320. previousCommand = currentCommand;
  321. }
  322. // paths that finish back at their start position often seem to be
  323. // left without a 'z', so need to be closed explicitly..
  324. if (path.getCurrentPosition() == subpathStart)
  325. path.closeSubPath();
  326. }
  327. private:
  328. //==============================================================================
  329. const XmlPath topLevelXml;
  330. float width, height, viewBoxW, viewBoxH;
  331. AffineTransform transform;
  332. String cssStyleText;
  333. static void setCommonAttributes (Drawable& d, const XmlPath& xml)
  334. {
  335. String compID (xml->getStringAttribute ("id"));
  336. d.setName (compID);
  337. d.setComponentID (compID);
  338. if (xml->getStringAttribute ("display") == "none")
  339. d.setVisible (false);
  340. }
  341. //==============================================================================
  342. void parseSubElements (const XmlPath& xml, DrawableComposite& parentDrawable)
  343. {
  344. forEachXmlChildElement (*xml, e)
  345. parentDrawable.addAndMakeVisible (parseSubElement (xml.getChild (e)));
  346. }
  347. Drawable* parseSubElement (const XmlPath& xml)
  348. {
  349. {
  350. Path path;
  351. if (parsePathElement (xml, path))
  352. return parseShape (xml, path);
  353. }
  354. const String tag (xml->getTagNameWithoutNamespace());
  355. if (tag == "g") return parseGroupElement (xml);
  356. if (tag == "svg") return parseSVGElement (xml);
  357. if (tag == "text") return parseText (xml, true);
  358. if (tag == "switch") return parseSwitch (xml);
  359. if (tag == "a") return parseLinkElement (xml);
  360. if (tag == "style") parseCSSStyle (xml);
  361. return nullptr;
  362. }
  363. bool parsePathElement (const XmlPath& xml, Path& path) const
  364. {
  365. const String tag (xml->getTagNameWithoutNamespace());
  366. if (tag == "path") { parsePath (xml, path); return true; }
  367. if (tag == "rect") { parseRect (xml, path); return true; }
  368. if (tag == "circle") { parseCircle (xml, path); return true; }
  369. if (tag == "ellipse") { parseEllipse (xml, path); return true; }
  370. if (tag == "line") { parseLine (xml, path); return true; }
  371. if (tag == "polyline") { parsePolygon (xml, true, path); return true; }
  372. if (tag == "polygon") { parsePolygon (xml, false, path); return true; }
  373. if (tag == "use") { parseUse (xml, path); return true; }
  374. return false;
  375. }
  376. DrawableComposite* parseSwitch (const XmlPath& xml)
  377. {
  378. if (const XmlElement* const group = xml->getChildByName ("g"))
  379. return parseGroupElement (xml.getChild (group));
  380. return nullptr;
  381. }
  382. DrawableComposite* parseGroupElement (const XmlPath& xml)
  383. {
  384. DrawableComposite* const drawable = new DrawableComposite();
  385. setCommonAttributes (*drawable, xml);
  386. if (xml->hasAttribute ("transform"))
  387. {
  388. SVGState newState (*this);
  389. newState.addTransform (xml);
  390. newState.parseSubElements (xml, *drawable);
  391. }
  392. else
  393. {
  394. parseSubElements (xml, *drawable);
  395. }
  396. drawable->resetContentAreaAndBoundingBoxToFitChildren();
  397. return drawable;
  398. }
  399. DrawableComposite* parseLinkElement (const XmlPath& xml)
  400. {
  401. return parseGroupElement (xml); // TODO: support for making this clickable
  402. }
  403. //==============================================================================
  404. void parsePath (const XmlPath& xml, Path& path) const
  405. {
  406. parsePathString (path, xml->getStringAttribute ("d"));
  407. if (getStyleAttribute (xml, "fill-rule").trim().equalsIgnoreCase ("evenodd"))
  408. path.setUsingNonZeroWinding (false);
  409. }
  410. void parseRect (const XmlPath& xml, Path& rect) const
  411. {
  412. const bool hasRX = xml->hasAttribute ("rx");
  413. const bool hasRY = xml->hasAttribute ("ry");
  414. if (hasRX || hasRY)
  415. {
  416. float rx = getCoordLength (xml, "rx", viewBoxW);
  417. float ry = getCoordLength (xml, "ry", viewBoxH);
  418. if (! hasRX)
  419. rx = ry;
  420. else if (! hasRY)
  421. ry = rx;
  422. rect.addRoundedRectangle (getCoordLength (xml, "x", viewBoxW),
  423. getCoordLength (xml, "y", viewBoxH),
  424. getCoordLength (xml, "width", viewBoxW),
  425. getCoordLength (xml, "height", viewBoxH),
  426. rx, ry);
  427. }
  428. else
  429. {
  430. rect.addRectangle (getCoordLength (xml, "x", viewBoxW),
  431. getCoordLength (xml, "y", viewBoxH),
  432. getCoordLength (xml, "width", viewBoxW),
  433. getCoordLength (xml, "height", viewBoxH));
  434. }
  435. }
  436. void parseCircle (const XmlPath& xml, Path& circle) const
  437. {
  438. const float cx = getCoordLength (xml, "cx", viewBoxW);
  439. const float cy = getCoordLength (xml, "cy", viewBoxH);
  440. const float radius = getCoordLength (xml, "r", viewBoxW);
  441. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  442. }
  443. void parseEllipse (const XmlPath& xml, Path& ellipse) const
  444. {
  445. const float cx = getCoordLength (xml, "cx", viewBoxW);
  446. const float cy = getCoordLength (xml, "cy", viewBoxH);
  447. const float radiusX = getCoordLength (xml, "rx", viewBoxW);
  448. const float radiusY = getCoordLength (xml, "ry", viewBoxH);
  449. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  450. }
  451. void parseLine (const XmlPath& xml, Path& line) const
  452. {
  453. const float x1 = getCoordLength (xml, "x1", viewBoxW);
  454. const float y1 = getCoordLength (xml, "y1", viewBoxH);
  455. const float x2 = getCoordLength (xml, "x2", viewBoxW);
  456. const float y2 = getCoordLength (xml, "y2", viewBoxH);
  457. line.startNewSubPath (x1, y1);
  458. line.lineTo (x2, y2);
  459. }
  460. void parsePolygon (const XmlPath& xml, const bool isPolyline, Path& path) const
  461. {
  462. const String pointsAtt (xml->getStringAttribute ("points"));
  463. String::CharPointerType points (pointsAtt.getCharPointer());
  464. Point<float> p;
  465. if (parseCoords (points, p, true))
  466. {
  467. Point<float> first (p), last;
  468. path.startNewSubPath (first);
  469. while (parseCoords (points, p, true))
  470. {
  471. last = p;
  472. path.lineTo (p);
  473. }
  474. if ((! isPolyline) || first == last)
  475. path.closeSubPath();
  476. }
  477. }
  478. void parseUse (const XmlPath& xml, Path& path) const
  479. {
  480. const String link (xml->getStringAttribute ("xlink:href"));
  481. if (link.startsWithChar ('#'))
  482. {
  483. const String linkedID = link.substring (1);
  484. UsePathOp op = { this, &path };
  485. topLevelXml.applyOperationToChildWithID (linkedID, op);
  486. }
  487. }
  488. static String parseURL (const String& str)
  489. {
  490. if (str.startsWithIgnoreCase ("url"))
  491. return str.fromFirstOccurrenceOf ("#", false, false)
  492. .upToLastOccurrenceOf (")", false, false).trim();
  493. return String();
  494. }
  495. //==============================================================================
  496. Drawable* parseShape (const XmlPath& xml, Path& path,
  497. const bool shouldParseTransform = true) const
  498. {
  499. if (shouldParseTransform && xml->hasAttribute ("transform"))
  500. {
  501. SVGState newState (*this);
  502. newState.addTransform (xml);
  503. return newState.parseShape (xml, path, false);
  504. }
  505. DrawablePath* dp = new DrawablePath();
  506. setCommonAttributes (*dp, xml);
  507. dp->setFill (Colours::transparentBlack);
  508. path.applyTransform (transform);
  509. dp->setPath (path);
  510. dp->setFill (getPathFillType (path, xml, "fill",
  511. getStyleAttribute (xml, "fill-opacity"),
  512. getStyleAttribute (xml, "opacity"),
  513. pathContainsClosedSubPath (path) ? Colours::black
  514. : Colours::transparentBlack));
  515. const String strokeType (getStyleAttribute (xml, "stroke"));
  516. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase ("none"))
  517. {
  518. dp->setStrokeFill (getPathFillType (path, xml, "stroke",
  519. getStyleAttribute (xml, "stroke-opacity"),
  520. getStyleAttribute (xml, "opacity"),
  521. Colours::transparentBlack));
  522. dp->setStrokeType (getStrokeFor (xml));
  523. }
  524. const String strokeDashArray (getStyleAttribute (xml, "stroke-dasharray"));
  525. if (strokeDashArray.isNotEmpty())
  526. parseDashArray (strokeDashArray, *dp);
  527. parseClipPath (xml, *dp);
  528. return dp;
  529. }
  530. static bool pathContainsClosedSubPath (const Path& path) noexcept
  531. {
  532. for (Path::Iterator iter (path); iter.next();)
  533. if (iter.elementType == Path::Iterator::closePath)
  534. return true;
  535. return false;
  536. }
  537. void parseDashArray (const String& dashList, DrawablePath& dp) const
  538. {
  539. if (dashList.equalsIgnoreCase ("null") || dashList.equalsIgnoreCase ("none"))
  540. return;
  541. Array<float> dashLengths;
  542. for (String::CharPointerType t = dashList.getCharPointer();;)
  543. {
  544. float value;
  545. if (! parseCoord (t, value, true, true))
  546. break;
  547. dashLengths.add (value);
  548. t = t.findEndOfWhitespace();
  549. if (*t == ',')
  550. ++t;
  551. }
  552. if (dashLengths.size() > 0)
  553. {
  554. float* const dashes = dashLengths.getRawDataPointer();
  555. for (int i = 0; i < dashLengths.size(); ++i)
  556. {
  557. if (dashes[i] <= 0) // SVG uses zero-length dashes to mean a dotted line
  558. {
  559. if (dashLengths.size() == 1)
  560. return;
  561. const float nonZeroLength = 0.001f;
  562. dashes[i] = nonZeroLength;
  563. const int pairedIndex = i ^ 1;
  564. if (isPositiveAndBelow (pairedIndex, dashLengths.size())
  565. && dashes[pairedIndex] > nonZeroLength)
  566. dashes[pairedIndex] -= nonZeroLength;
  567. }
  568. }
  569. dp.setDashLengths (dashLengths);
  570. }
  571. }
  572. void parseClipPath (const XmlPath& xml, Drawable& d) const
  573. {
  574. const String clipPath (getStyleAttribute (xml, "clip-path"));
  575. if (clipPath.isNotEmpty())
  576. {
  577. String urlID = parseURL (clipPath);
  578. if (urlID.isNotEmpty())
  579. {
  580. GetClipPathOp op = { this, &d };
  581. topLevelXml.applyOperationToChildWithID (urlID, op);
  582. }
  583. }
  584. }
  585. void applyClipPath (Drawable& target, const XmlPath& xmlPath) const
  586. {
  587. if (xmlPath->hasTagNameIgnoringNamespace ("clipPath"))
  588. {
  589. // TODO: implement clipping..
  590. ignoreUnused (target);
  591. }
  592. }
  593. void addGradientStopsIn (ColourGradient& cg, const XmlPath& fillXml) const
  594. {
  595. if (fillXml.xml != nullptr)
  596. {
  597. forEachXmlChildElementWithTagName (*fillXml, e, "stop")
  598. {
  599. Colour col (parseColour (fillXml.getChild (e), "stop-color", Colours::black));
  600. const String opacity (getStyleAttribute (fillXml.getChild (e), "stop-opacity", "1"));
  601. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  602. double offset = e->getDoubleAttribute ("offset");
  603. if (e->getStringAttribute ("offset").containsChar ('%'))
  604. offset *= 0.01;
  605. cg.addColour (jlimit (0.0, 1.0, offset), col);
  606. }
  607. }
  608. }
  609. FillType getGradientFillType (const XmlPath& fillXml,
  610. const Path& path,
  611. const float opacity) const
  612. {
  613. ColourGradient gradient;
  614. {
  615. const String id (fillXml->getStringAttribute ("xlink:href"));
  616. if (id.startsWithChar ('#'))
  617. {
  618. SetGradientStopsOp op = { this, &gradient, };
  619. topLevelXml.applyOperationToChildWithID (id.substring (1), op);
  620. }
  621. }
  622. addGradientStopsIn (gradient, fillXml);
  623. if (int numColours = gradient.getNumColours())
  624. {
  625. if (gradient.getColourPosition (0) > 0)
  626. gradient.addColour (0.0, gradient.getColour (0));
  627. if (gradient.getColourPosition (numColours - 1) < 1.0)
  628. gradient.addColour (1.0, gradient.getColour (numColours - 1));
  629. }
  630. else
  631. {
  632. gradient.addColour (0.0, Colours::black);
  633. gradient.addColour (1.0, Colours::black);
  634. }
  635. if (opacity < 1.0f)
  636. gradient.multiplyOpacity (opacity);
  637. jassert (gradient.getNumColours() > 0);
  638. gradient.isRadial = fillXml->hasTagNameIgnoringNamespace ("radialGradient");
  639. float gradientWidth = viewBoxW;
  640. float gradientHeight = viewBoxH;
  641. float dx = 0.0f;
  642. float dy = 0.0f;
  643. const bool userSpace = fillXml->getStringAttribute ("gradientUnits").equalsIgnoreCase ("userSpaceOnUse");
  644. if (! userSpace)
  645. {
  646. const Rectangle<float> bounds (path.getBounds());
  647. dx = bounds.getX();
  648. dy = bounds.getY();
  649. gradientWidth = bounds.getWidth();
  650. gradientHeight = bounds.getHeight();
  651. }
  652. if (gradient.isRadial)
  653. {
  654. if (userSpace)
  655. gradient.point1.setXY (dx + getCoordLength (fillXml->getStringAttribute ("cx", "50%"), gradientWidth),
  656. dy + getCoordLength (fillXml->getStringAttribute ("cy", "50%"), gradientHeight));
  657. else
  658. gradient.point1.setXY (dx + gradientWidth * getCoordLength (fillXml->getStringAttribute ("cx", "50%"), 1.0f),
  659. dy + gradientHeight * getCoordLength (fillXml->getStringAttribute ("cy", "50%"), 1.0f));
  660. const float radius = getCoordLength (fillXml->getStringAttribute ("r", "50%"), gradientWidth);
  661. gradient.point2 = gradient.point1 + Point<float> (radius, 0.0f);
  662. //xxx (the fx, fy focal point isn't handled properly here..)
  663. }
  664. else
  665. {
  666. if (userSpace)
  667. {
  668. gradient.point1.setXY (dx + getCoordLength (fillXml->getStringAttribute ("x1", "0%"), gradientWidth),
  669. dy + getCoordLength (fillXml->getStringAttribute ("y1", "0%"), gradientHeight));
  670. gradient.point2.setXY (dx + getCoordLength (fillXml->getStringAttribute ("x2", "100%"), gradientWidth),
  671. dy + getCoordLength (fillXml->getStringAttribute ("y2", "0%"), gradientHeight));
  672. }
  673. else
  674. {
  675. gradient.point1.setXY (dx + gradientWidth * getCoordLength (fillXml->getStringAttribute ("x1", "0%"), 1.0f),
  676. dy + gradientHeight * getCoordLength (fillXml->getStringAttribute ("y1", "0%"), 1.0f));
  677. gradient.point2.setXY (dx + gradientWidth * getCoordLength (fillXml->getStringAttribute ("x2", "100%"), 1.0f),
  678. dy + gradientHeight * getCoordLength (fillXml->getStringAttribute ("y2", "0%"), 1.0f));
  679. }
  680. if (gradient.point1 == gradient.point2)
  681. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  682. }
  683. FillType type (gradient);
  684. const AffineTransform gradientTransform (parseTransform (fillXml->getStringAttribute ("gradientTransform"))
  685. .followedBy (transform));
  686. if (gradient.isRadial)
  687. {
  688. type.transform = gradientTransform;
  689. }
  690. else
  691. {
  692. // Transform the perpendicular vector into the new coordinate space for the gradient.
  693. // This vector is now the slope of the linear gradient as it should appear in the new coord space
  694. const Point<float> perpendicular (Point<float> (gradient.point2.y - gradient.point1.y,
  695. gradient.point1.x - gradient.point2.x)
  696. .transformedBy (gradientTransform.withAbsoluteTranslation (0, 0)));
  697. const Point<float> newGradPoint1 (gradient.point1.transformedBy (gradientTransform));
  698. const Point<float> newGradPoint2 (gradient.point2.transformedBy (gradientTransform));
  699. // Project the transformed gradient vector onto the transformed slope of the linear
  700. // gradient as it should appear in the new coordinate space
  701. const float scale = perpendicular.getDotProduct (newGradPoint2 - newGradPoint1)
  702. / perpendicular.getDotProduct (perpendicular);
  703. type.gradient->point1 = newGradPoint1;
  704. type.gradient->point2 = newGradPoint2 - perpendicular * scale;
  705. }
  706. return type;
  707. }
  708. FillType getPathFillType (const Path& path,
  709. const XmlPath& xml,
  710. StringRef fillAttribute,
  711. const String& fillOpacity,
  712. const String& overallOpacity,
  713. const Colour defaultColour) const
  714. {
  715. float opacity = 1.0f;
  716. if (overallOpacity.isNotEmpty())
  717. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  718. if (fillOpacity.isNotEmpty())
  719. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  720. String fill (getStyleAttribute (xml, fillAttribute));
  721. String urlID = parseURL (fill);
  722. if (urlID.isNotEmpty())
  723. {
  724. GetFillTypeOp op = { this, &path, opacity, FillType() };
  725. if (topLevelXml.applyOperationToChildWithID (urlID, op))
  726. return op.fillType;
  727. }
  728. if (fill.equalsIgnoreCase ("none"))
  729. return Colours::transparentBlack;
  730. return parseColour (xml, fillAttribute, defaultColour).withMultipliedAlpha (opacity);
  731. }
  732. static PathStrokeType::JointStyle getJointStyle (const String& join) noexcept
  733. {
  734. if (join.equalsIgnoreCase ("round")) return PathStrokeType::curved;
  735. if (join.equalsIgnoreCase ("bevel")) return PathStrokeType::beveled;
  736. return PathStrokeType::mitered;
  737. }
  738. static PathStrokeType::EndCapStyle getEndCapStyle (const String& cap) noexcept
  739. {
  740. if (cap.equalsIgnoreCase ("round")) return PathStrokeType::rounded;
  741. if (cap.equalsIgnoreCase ("square")) return PathStrokeType::square;
  742. return PathStrokeType::butt;
  743. }
  744. float getStrokeWidth (const String& strokeWidth) const noexcept
  745. {
  746. return transform.getScaleFactor() * getCoordLength (strokeWidth, viewBoxW);
  747. }
  748. PathStrokeType getStrokeFor (const XmlPath& xml) const
  749. {
  750. return PathStrokeType (getStrokeWidth (getStyleAttribute (xml, "stroke-width", "1")),
  751. getJointStyle (getStyleAttribute (xml, "stroke-linejoin")),
  752. getEndCapStyle (getStyleAttribute (xml, "stroke-linecap")));
  753. }
  754. //==============================================================================
  755. Drawable* parseText (const XmlPath& xml, bool shouldParseTransform)
  756. {
  757. if (shouldParseTransform && xml->hasAttribute ("transform"))
  758. {
  759. SVGState newState (*this);
  760. newState.addTransform (xml);
  761. return newState.parseText (xml, false);
  762. }
  763. Array<float> xCoords, yCoords, dxCoords, dyCoords;
  764. getCoordList (xCoords, getInheritedAttribute (xml, "x"), true, true);
  765. getCoordList (yCoords, getInheritedAttribute (xml, "y"), true, false);
  766. getCoordList (dxCoords, getInheritedAttribute (xml, "dx"), true, true);
  767. getCoordList (dyCoords, getInheritedAttribute (xml, "dy"), true, false);
  768. const Font font (getFont (xml));
  769. const String anchorStr = getStyleAttribute(xml, "text-anchor");
  770. DrawableComposite* dc = new DrawableComposite();
  771. setCommonAttributes (*dc, xml);
  772. forEachXmlChildElement (*xml, e)
  773. {
  774. if (e->isTextElement())
  775. {
  776. const String text (e->getText().trim());
  777. DrawableText* dt = new DrawableText();
  778. dc->addAndMakeVisible (dt);
  779. dt->setText (text);
  780. dt->setFont (font, true);
  781. dt->setTransform (transform);
  782. dt->setColour (parseColour (xml, "fill", Colours::black)
  783. .withMultipliedAlpha (getStyleAttribute (xml, "fill-opacity", "1").getFloatValue()));
  784. Rectangle<float> bounds (xCoords[0], yCoords[0] - font.getAscent(),
  785. font.getStringWidthFloat (text), font.getHeight());
  786. if (anchorStr == "middle") bounds.setX (bounds.getX() - bounds.getWidth() / 2.0f);
  787. else if (anchorStr == "end") bounds.setX (bounds.getX() - bounds.getWidth());
  788. dt->setBoundingBox (bounds);
  789. }
  790. else if (e->hasTagNameIgnoringNamespace ("tspan"))
  791. {
  792. dc->addAndMakeVisible (parseText (xml.getChild (e), true));
  793. }
  794. }
  795. return dc;
  796. }
  797. Font getFont (const XmlPath& xml) const
  798. {
  799. const float fontSize = getCoordLength (getStyleAttribute (xml, "font-size"), 1.0f);
  800. int style = getStyleAttribute (xml, "font-style").containsIgnoreCase ("italic") ? Font::italic : Font::plain;
  801. if (getStyleAttribute (xml, "font-weight").containsIgnoreCase ("bold"))
  802. style |= Font::bold;
  803. const String family (getStyleAttribute (xml, "font-family"));
  804. return family.isEmpty() ? Font (fontSize, style)
  805. : Font (family, fontSize, style);
  806. }
  807. //==============================================================================
  808. void addTransform (const XmlPath& xml)
  809. {
  810. transform = parseTransform (xml->getStringAttribute ("transform"))
  811. .followedBy (transform);
  812. }
  813. //==============================================================================
  814. bool parseCoord (String::CharPointerType& s, float& value, const bool allowUnits, const bool isX) const
  815. {
  816. String number;
  817. if (! parseNextNumber (s, number, allowUnits))
  818. {
  819. value = 0;
  820. return false;
  821. }
  822. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  823. return true;
  824. }
  825. bool parseCoords (String::CharPointerType& s, Point<float>& p, const bool allowUnits) const
  826. {
  827. return parseCoord (s, p.x, allowUnits, true)
  828. && parseCoord (s, p.y, allowUnits, false);
  829. }
  830. bool parseCoordsOrSkip (String::CharPointerType& s, Point<float>& p, const bool allowUnits) const
  831. {
  832. if (parseCoords (s, p, allowUnits))
  833. return true;
  834. if (! s.isEmpty()) ++s;
  835. return false;
  836. }
  837. float getCoordLength (const String& s, const float sizeForProportions) const noexcept
  838. {
  839. float n = s.getFloatValue();
  840. const int len = s.length();
  841. if (len > 2)
  842. {
  843. const float dpi = 96.0f;
  844. const juce_wchar n1 = s [len - 2];
  845. const juce_wchar n2 = s [len - 1];
  846. if (n1 == 'i' && n2 == 'n') n *= dpi;
  847. else if (n1 == 'm' && n2 == 'm') n *= dpi / 25.4f;
  848. else if (n1 == 'c' && n2 == 'm') n *= dpi / 2.54f;
  849. else if (n1 == 'p' && n2 == 'c') n *= 15.0f;
  850. else if (n2 == '%') n *= 0.01f * sizeForProportions;
  851. }
  852. return n;
  853. }
  854. float getCoordLength (const XmlPath& xml, const char* attName, const float sizeForProportions) const noexcept
  855. {
  856. return getCoordLength (xml->getStringAttribute (attName), sizeForProportions);
  857. }
  858. void getCoordList (Array<float>& coords, const String& list, bool allowUnits, const bool isX) const
  859. {
  860. String::CharPointerType text (list.getCharPointer());
  861. float value;
  862. while (parseCoord (text, value, allowUnits, isX))
  863. coords.add (value);
  864. }
  865. //==============================================================================
  866. void parseCSSStyle (const XmlPath& xml)
  867. {
  868. cssStyleText = xml->getAllSubText() + "\n" + cssStyleText;
  869. }
  870. static String::CharPointerType findStyleItem (String::CharPointerType source, String::CharPointerType name)
  871. {
  872. const int nameLength = (int) name.length();
  873. while (! source.isEmpty())
  874. {
  875. if (source.getAndAdvance() == '.'
  876. && CharacterFunctions::compareIgnoreCaseUpTo (source, name, nameLength) == 0)
  877. {
  878. String::CharPointerType endOfName ((source + nameLength).findEndOfWhitespace());
  879. if (*endOfName == '{')
  880. return endOfName;
  881. }
  882. }
  883. return source;
  884. }
  885. String getStyleAttribute (const XmlPath& xml, StringRef attributeName,
  886. const String& defaultValue = String()) const
  887. {
  888. if (xml->hasAttribute (attributeName))
  889. return xml->getStringAttribute (attributeName, defaultValue);
  890. const String styleAtt (xml->getStringAttribute ("style"));
  891. if (styleAtt.isNotEmpty())
  892. {
  893. const String value (getAttributeFromStyleList (styleAtt, attributeName, String()));
  894. if (value.isNotEmpty())
  895. return value;
  896. }
  897. else if (xml->hasAttribute ("class"))
  898. {
  899. String::CharPointerType openBrace = findStyleItem (cssStyleText.getCharPointer(),
  900. xml->getStringAttribute ("class").getCharPointer());
  901. if (! openBrace.isEmpty())
  902. {
  903. String::CharPointerType closeBrace = CharacterFunctions::find (openBrace, (juce_wchar) '}');
  904. if (closeBrace != openBrace)
  905. {
  906. const String value (getAttributeFromStyleList (String (openBrace + 1, closeBrace),
  907. attributeName, defaultValue));
  908. if (value.isNotEmpty())
  909. return value;
  910. }
  911. }
  912. }
  913. if (xml.parent != nullptr)
  914. return getStyleAttribute (*xml.parent, attributeName, defaultValue);
  915. return defaultValue;
  916. }
  917. String getInheritedAttribute (const XmlPath& xml, StringRef attributeName) const
  918. {
  919. if (xml->hasAttribute (attributeName))
  920. return xml->getStringAttribute (attributeName);
  921. if (xml.parent != nullptr)
  922. return getInheritedAttribute (*xml.parent, attributeName);
  923. return String();
  924. }
  925. static int parsePlacementFlags (const String& align) noexcept
  926. {
  927. if (align.isEmpty())
  928. return 0;
  929. if (align.containsIgnoreCase ("none"))
  930. return RectanglePlacement::stretchToFit;
  931. return (align.containsIgnoreCase ("slice") ? RectanglePlacement::fillDestination : 0)
  932. | (align.containsIgnoreCase ("xMin") ? RectanglePlacement::xLeft
  933. : (align.containsIgnoreCase ("xMax") ? RectanglePlacement::xRight
  934. : RectanglePlacement::xMid))
  935. | (align.containsIgnoreCase ("yMin") ? RectanglePlacement::yTop
  936. : (align.containsIgnoreCase ("yMax") ? RectanglePlacement::yBottom
  937. : RectanglePlacement::yMid));
  938. }
  939. //==============================================================================
  940. static bool isIdentifierChar (const juce_wchar c)
  941. {
  942. return CharacterFunctions::isLetter (c) || c == '-';
  943. }
  944. static String getAttributeFromStyleList (const String& list, StringRef attributeName, const String& defaultValue)
  945. {
  946. int i = 0;
  947. for (;;)
  948. {
  949. i = list.indexOf (i, attributeName);
  950. if (i < 0)
  951. break;
  952. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  953. && ! isIdentifierChar (list [i + attributeName.length()]))
  954. {
  955. i = list.indexOfChar (i, ':');
  956. if (i < 0)
  957. break;
  958. int end = list.indexOfChar (i, ';');
  959. if (end < 0)
  960. end = 0x7ffff;
  961. return list.substring (i + 1, end).trim();
  962. }
  963. ++i;
  964. }
  965. return defaultValue;
  966. }
  967. //==============================================================================
  968. static bool isStartOfNumber (juce_wchar c) noexcept
  969. {
  970. return CharacterFunctions::isDigit (c) || c == '-' || c == '+';
  971. }
  972. static bool parseNextNumber (String::CharPointerType& text, String& value, const bool allowUnits)
  973. {
  974. String::CharPointerType s (text);
  975. while (s.isWhitespace() || *s == ',')
  976. ++s;
  977. String::CharPointerType start (s);
  978. if (isStartOfNumber (*s))
  979. ++s;
  980. while (s.isDigit())
  981. ++s;
  982. if (*s == '.')
  983. {
  984. ++s;
  985. while (s.isDigit())
  986. ++s;
  987. }
  988. if ((*s == 'e' || *s == 'E') && isStartOfNumber (s[1]))
  989. {
  990. s += 2;
  991. while (s.isDigit())
  992. ++s;
  993. }
  994. if (allowUnits)
  995. while (s.isLetter())
  996. ++s;
  997. if (s == start)
  998. {
  999. text = s;
  1000. return false;
  1001. }
  1002. value = String (start, s);
  1003. while (s.isWhitespace() || *s == ',')
  1004. ++s;
  1005. text = s;
  1006. return true;
  1007. }
  1008. //==============================================================================
  1009. Colour parseColour (const XmlPath& xml, StringRef attributeName, const Colour defaultColour) const
  1010. {
  1011. const String text (getStyleAttribute (xml, attributeName));
  1012. if (text.startsWithChar ('#'))
  1013. {
  1014. uint32 hex[6] = { 0 };
  1015. int numChars = 0;
  1016. String::CharPointerType s = text.getCharPointer();
  1017. while (numChars < 6)
  1018. {
  1019. const int hexValue = CharacterFunctions::getHexDigitValue (*++s);
  1020. if (hexValue >= 0)
  1021. hex [numChars++] = (uint32) hexValue;
  1022. else
  1023. break;
  1024. }
  1025. if (numChars <= 3)
  1026. return Colour ((uint8) (hex[0] * 0x11),
  1027. (uint8) (hex[1] * 0x11),
  1028. (uint8) (hex[2] * 0x11));
  1029. return Colour ((uint8) ((hex[0] << 4) + hex[1]),
  1030. (uint8) ((hex[2] << 4) + hex[3]),
  1031. (uint8) ((hex[4] << 4) + hex[5]));
  1032. }
  1033. if (text.startsWith ("rgb"))
  1034. {
  1035. const int openBracket = text.indexOfChar ('(');
  1036. const int closeBracket = text.indexOfChar (openBracket, ')');
  1037. if (openBracket >= 3 && closeBracket > openBracket)
  1038. {
  1039. StringArray tokens;
  1040. tokens.addTokens (text.substring (openBracket + 1, closeBracket), ",", "");
  1041. tokens.trim();
  1042. tokens.removeEmptyStrings();
  1043. if (tokens[0].containsChar ('%'))
  1044. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  1045. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  1046. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  1047. return Colour ((uint8) tokens[0].getIntValue(),
  1048. (uint8) tokens[1].getIntValue(),
  1049. (uint8) tokens[2].getIntValue());
  1050. }
  1051. }
  1052. if (text == "inherit")
  1053. {
  1054. for (const XmlPath* p = xml.parent; p != nullptr; p = p->parent)
  1055. if (getStyleAttribute (*p, attributeName).isNotEmpty())
  1056. return parseColour (*p, attributeName, defaultColour);
  1057. }
  1058. return Colours::findColourForName (text, defaultColour);
  1059. }
  1060. static AffineTransform parseTransform (String t)
  1061. {
  1062. AffineTransform result;
  1063. while (t.isNotEmpty())
  1064. {
  1065. StringArray tokens;
  1066. tokens.addTokens (t.fromFirstOccurrenceOf ("(", false, false)
  1067. .upToFirstOccurrenceOf (")", false, false),
  1068. ", ", "");
  1069. tokens.removeEmptyStrings (true);
  1070. float numbers[6];
  1071. for (int i = 0; i < numElementsInArray (numbers); ++i)
  1072. numbers[i] = tokens[i].getFloatValue();
  1073. AffineTransform trans;
  1074. if (t.startsWithIgnoreCase ("matrix"))
  1075. {
  1076. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  1077. numbers[1], numbers[3], numbers[5]);
  1078. }
  1079. else if (t.startsWithIgnoreCase ("translate"))
  1080. {
  1081. trans = AffineTransform::translation (numbers[0], numbers[1]);
  1082. }
  1083. else if (t.startsWithIgnoreCase ("scale"))
  1084. {
  1085. trans = AffineTransform::scale (numbers[0], numbers[tokens.size() > 1 ? 1 : 0]);
  1086. }
  1087. else if (t.startsWithIgnoreCase ("rotate"))
  1088. {
  1089. trans = AffineTransform::rotation (degreesToRadians (numbers[0]), numbers[1], numbers[2]);
  1090. }
  1091. else if (t.startsWithIgnoreCase ("skewX"))
  1092. {
  1093. trans = AffineTransform::shear (std::tan (degreesToRadians (numbers[0])), 0.0f);
  1094. }
  1095. else if (t.startsWithIgnoreCase ("skewY"))
  1096. {
  1097. trans = AffineTransform::shear (0.0f, std::tan (degreesToRadians (numbers[0])));
  1098. }
  1099. result = trans.followedBy (result);
  1100. t = t.fromFirstOccurrenceOf (")", false, false).trimStart();
  1101. }
  1102. return result;
  1103. }
  1104. static void endpointToCentreParameters (const double x1, const double y1,
  1105. const double x2, const double y2,
  1106. const double angle,
  1107. const bool largeArc, const bool sweep,
  1108. double& rx, double& ry,
  1109. double& centreX, double& centreY,
  1110. double& startAngle, double& deltaAngle) noexcept
  1111. {
  1112. const double midX = (x1 - x2) * 0.5;
  1113. const double midY = (y1 - y2) * 0.5;
  1114. const double cosAngle = std::cos (angle);
  1115. const double sinAngle = std::sin (angle);
  1116. const double xp = cosAngle * midX + sinAngle * midY;
  1117. const double yp = cosAngle * midY - sinAngle * midX;
  1118. const double xp2 = xp * xp;
  1119. const double yp2 = yp * yp;
  1120. double rx2 = rx * rx;
  1121. double ry2 = ry * ry;
  1122. const double s = (xp2 / rx2) + (yp2 / ry2);
  1123. double c;
  1124. if (s <= 1.0)
  1125. {
  1126. c = std::sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  1127. / (( rx2 * yp2) + (ry2 * xp2))));
  1128. if (largeArc == sweep)
  1129. c = -c;
  1130. }
  1131. else
  1132. {
  1133. const double s2 = std::sqrt (s);
  1134. rx *= s2;
  1135. ry *= s2;
  1136. c = 0;
  1137. }
  1138. const double cpx = ((rx * yp) / ry) * c;
  1139. const double cpy = ((-ry * xp) / rx) * c;
  1140. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  1141. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  1142. const double ux = (xp - cpx) / rx;
  1143. const double uy = (yp - cpy) / ry;
  1144. const double vx = (-xp - cpx) / rx;
  1145. const double vy = (-yp - cpy) / ry;
  1146. const double length = juce_hypot (ux, uy);
  1147. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  1148. if (uy < 0)
  1149. startAngle = -startAngle;
  1150. startAngle += double_Pi * 0.5;
  1151. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  1152. / (length * juce_hypot (vx, vy))));
  1153. if ((ux * vy) - (uy * vx) < 0)
  1154. deltaAngle = -deltaAngle;
  1155. if (sweep)
  1156. {
  1157. if (deltaAngle < 0)
  1158. deltaAngle += double_Pi * 2.0;
  1159. }
  1160. else
  1161. {
  1162. if (deltaAngle > 0)
  1163. deltaAngle -= double_Pi * 2.0;
  1164. }
  1165. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  1166. }
  1167. SVGState& operator= (const SVGState&) JUCE_DELETED_FUNCTION;
  1168. };
  1169. //==============================================================================
  1170. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  1171. {
  1172. if (! svgDocument.hasTagNameIgnoringNamespace ("svg"))
  1173. return nullptr;
  1174. SVGState state (&svgDocument);
  1175. return state.parseSVGElement (SVGState::XmlPath (&svgDocument, nullptr));
  1176. }
  1177. Path Drawable::parseSVGPath (const String& svgPath)
  1178. {
  1179. SVGState state (nullptr);
  1180. Path p;
  1181. state.parsePathString (p, svgPath);
  1182. return p;
  1183. }