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.

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