1 /* 2 * Copyright 2016 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkSVGAttributeParser_DEFINED 9 #define SkSVGAttributeParser_DEFINED 10 11 #include "SkNoncopyable.h" 12 #include "SkSVGTypes.h" 13 14 class SkSVGAttributeParser : public SkNoncopyable { 15 public: 16 SkSVGAttributeParser(const char[]); 17 18 bool parseColor(SkSVGColorType*); 19 bool parseClipPath(SkSVGClip*); 20 bool parseFillRule(SkSVGFillRule*); 21 bool parseNumber(SkSVGNumberType*); 22 bool parseLength(SkSVGLength*); 23 bool parseViewBox(SkSVGViewBoxType*); 24 bool parseTransform(SkSVGTransformType*); 25 bool parsePaint(SkSVGPaint*); 26 bool parseLineCap(SkSVGLineCap*); 27 bool parseLineJoin(SkSVGLineJoin*); 28 bool parsePoints(SkSVGPointsType*); 29 bool parseIRI(SkSVGStringType*); 30 bool parseSpreadMethod(SkSVGSpreadMethod*); 31 bool parseVisibility(SkSVGVisibility*); 32 bool parseDashArray(SkSVGDashArray*); 33 34 private: 35 // Stack-only 36 void* operator new(size_t) = delete; 37 void* operator new(size_t, void*) = delete; 38 39 template <typename F> 40 bool advanceWhile(F func); 41 42 bool parseWSToken(); 43 bool parseEOSToken(); 44 bool parseSepToken(); 45 bool parseExpectedStringToken(const char*); 46 bool parseScalarToken(SkScalar*); 47 bool parseHexToken(uint32_t*); 48 bool parseLengthUnitToken(SkSVGLength::Unit*); 49 bool parseNamedColorToken(SkColor*); 50 bool parseHexColorToken(SkColor*); 51 bool parseColorComponentToken(int32_t*); 52 bool parseRGBColorToken(SkColor*); 53 bool parseFuncIRI(SkSVGStringType*); 54 55 // Transform helpers 56 bool parseMatrixToken(SkMatrix*); 57 bool parseTranslateToken(SkMatrix*); 58 bool parseScaleToken(SkMatrix*); 59 bool parseRotateToken(SkMatrix*); 60 bool parseSkewXToken(SkMatrix*); 61 bool parseSkewYToken(SkMatrix*); 62 63 // Parses a sequence of 'WS* <prefix> WS* (<nested>)', where the nested sequence 64 // is handled by the passed functor. 65 template <typename Func, typename T> 66 bool parseParenthesized(const char* prefix, Func, T* result); 67 68 // The current position in the input string. 69 const char* fCurPos; 70 71 typedef SkNoncopyable INHERITED; 72 }; 73 74 #endif // SkSVGAttributeParser_DEFINED 75