Home | History | Annotate | Download | only in model
      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 "SkSVGTypes.h"
     12 
     13 class SkSVGAttributeParser : public SkNoncopyable {
     14 public:
     15     SkSVGAttributeParser(const char[]);
     16 
     17     bool parseColor(SkSVGColorType*);
     18     bool parseClipPath(SkSVGClip*);
     19     bool parseFillRule(SkSVGFillRule*);
     20     bool parseNumber(SkSVGNumberType*);
     21     bool parseLength(SkSVGLength*);
     22     bool parseViewBox(SkSVGViewBoxType*);
     23     bool parseTransform(SkSVGTransformType*);
     24     bool parsePaint(SkSVGPaint*);
     25     bool parseLineCap(SkSVGLineCap*);
     26     bool parseLineJoin(SkSVGLineJoin*);
     27     bool parsePoints(SkSVGPointsType*);
     28     bool parseIRI(SkSVGStringType*);
     29     bool parseSpreadMethod(SkSVGSpreadMethod*);
     30 
     31 private:
     32     // Stack-only
     33     void* operator new(size_t) = delete;
     34     void* operator new(size_t, void*) = delete;
     35 
     36     template <typename F>
     37     bool advanceWhile(F func);
     38 
     39     bool parseWSToken();
     40     bool parseEOSToken();
     41     bool parseSepToken();
     42     bool parseExpectedStringToken(const char*);
     43     bool parseScalarToken(SkScalar*);
     44     bool parseHexToken(uint32_t*);
     45     bool parseLengthUnitToken(SkSVGLength::Unit*);
     46     bool parseNamedColorToken(SkColor*);
     47     bool parseHexColorToken(SkColor*);
     48     bool parseColorComponentToken(int32_t*);
     49     bool parseRGBColorToken(SkColor*);
     50     bool parseFuncIRI(SkSVGStringType*);
     51 
     52     // Transform helpers
     53     bool parseMatrixToken(SkMatrix*);
     54     bool parseTranslateToken(SkMatrix*);
     55     bool parseScaleToken(SkMatrix*);
     56     bool parseRotateToken(SkMatrix*);
     57     bool parseSkewXToken(SkMatrix*);
     58     bool parseSkewYToken(SkMatrix*);
     59 
     60     // Parses a sequence of 'WS* <prefix> WS* (<nested>)', where the nested sequence
     61     // is handled by the passed functor.
     62     template <typename Func, typename T>
     63     bool parseParenthesized(const char* prefix, Func, T* result);
     64 
     65     // The current position in the input string.
     66     const char* fCurPos;
     67 
     68     typedef SkNoncopyable INHERITED;
     69 };
     70 
     71 #endif // SkSVGAttributeParser_DEFINED
     72