| 779 | #ifdef MSDFGEN_USE_DROPXML |
| 780 | |
| 781 | int parseSvgShape(Shape &output, Shape::Bounds &viewBox, const char *svgData, size_t svgLength) { |
| 782 | |
| 783 | class SvgConsumer : public BaseSvgConsumer { |
| 784 | enum Element { |
| 785 | BEGINNING, |
| 786 | IGNORED, |
| 787 | SVG, |
| 788 | G, |
| 789 | PATH, |
| 790 | RECT, |
| 791 | CIRCLE, |
| 792 | ELLIPSE, |
| 793 | POLYGON |
| 794 | } curElement; |
| 795 | |
| 796 | // Current element attributes |
| 797 | struct ElementData { |
| 798 | StrRange transform, transformOrigin; |
| 799 | Vector2 pos, dims, radius; |
| 800 | StrRange pathDef; |
| 801 | bool fillRuleEvenOdd; |
| 802 | ElementData() : fillRuleEvenOdd(false) { } |
| 803 | } elem; |
| 804 | |
| 805 | int ignoredDepth; |
| 806 | SkMatrix transformation; |
| 807 | std::stack<SkMatrix> transformationStack; |
| 808 | |
| 809 | public: |
| 810 | int flags; |
| 811 | Vector2 dimensions; |
| 812 | Shape::Bounds viewBox; |
| 813 | SkPath fullPath; |
| 814 | |
| 815 | SvgConsumer() : curElement(BEGINNING), ignoredDepth(0), flags(0), viewBox() { } |
| 816 | |
| 817 | bool enterElement(const char *nameStart, const char *nameEnd) { |
| 818 | if (ignoredDepth) { |
| 819 | ++ignoredDepth; |
| 820 | return true; |
| 821 | } |
| 822 | if (curElement == BEGINNING && SVG_NAME_IS("svg")) |
| 823 | curElement = SVG; |
| 824 | else if (SVG_NAME_IS("g")) |
| 825 | curElement = G; |
| 826 | else if (SVG_NAME_IS("path")) |
| 827 | curElement = PATH; |
| 828 | else if (SVG_NAME_IS("rect")) |
| 829 | curElement = RECT; |
| 830 | else if (SVG_NAME_IS("circle")) |
| 831 | curElement = CIRCLE; |
| 832 | else if (SVG_NAME_IS("ellipse")) |
| 833 | curElement = ELLIPSE; |
| 834 | else if (SVG_NAME_IS("polygon")) |
| 835 | curElement = POLYGON; |
| 836 | else { |
| 837 | curElement = IGNORED; |
| 838 | ++ignoredDepth; |
no test coverage detected