The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

1505 lines
51KB

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