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
13class SkSVGAttributeParser : public SkNoncopyable {
14public:
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    bool parseVisibility(SkSVGVisibility*);
31    bool parseDashArray(SkSVGDashArray*);
32
33private:
34    // Stack-only
35    void* operator new(size_t) = delete;
36    void* operator new(size_t, void*) = delete;
37
38    template <typename F>
39    bool advanceWhile(F func);
40
41    bool parseWSToken();
42    bool parseEOSToken();
43    bool parseSepToken();
44    bool parseExpectedStringToken(const char*);
45    bool parseScalarToken(SkScalar*);
46    bool parseHexToken(uint32_t*);
47    bool parseLengthUnitToken(SkSVGLength::Unit*);
48    bool parseNamedColorToken(SkColor*);
49    bool parseHexColorToken(SkColor*);
50    bool parseColorComponentToken(int32_t*);
51    bool parseRGBColorToken(SkColor*);
52    bool parseFuncIRI(SkSVGStringType*);
53
54    // Transform helpers
55    bool parseMatrixToken(SkMatrix*);
56    bool parseTranslateToken(SkMatrix*);
57    bool parseScaleToken(SkMatrix*);
58    bool parseRotateToken(SkMatrix*);
59    bool parseSkewXToken(SkMatrix*);
60    bool parseSkewYToken(SkMatrix*);
61
62    // Parses a sequence of 'WS* <prefix> WS* (<nested>)', where the nested sequence
63    // is handled by the passed functor.
64    template <typename Func, typename T>
65    bool parseParenthesized(const char* prefix, Func, T* result);
66
67    // The current position in the input string.
68    const char* fCurPos;
69
70    typedef SkNoncopyable INHERITED;
71};
72
73#endif // SkSVGAttributeParser_DEFINED
74