aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/svg/model/SkSVGAttributeParser.h
blob: 7d329c7a2bcbf50c11f5cf48e7b4ea0cd82d4244 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkSVGAttributeParser_DEFINED
#define SkSVGAttributeParser_DEFINED

#include "SkSVGTypes.h"

class SkSVGAttributeParser : public SkNoncopyable {
public:
    SkSVGAttributeParser(const char[]);

    bool parseColor(SkSVGColorType*);
    bool parseClipPath(SkSVGClip*);
    bool parseFillRule(SkSVGFillRule*);
    bool parseNumber(SkSVGNumberType*);
    bool parseLength(SkSVGLength*);
    bool parseViewBox(SkSVGViewBoxType*);
    bool parseTransform(SkSVGTransformType*);
    bool parsePaint(SkSVGPaint*);
    bool parseLineCap(SkSVGLineCap*);
    bool parseLineJoin(SkSVGLineJoin*);
    bool parsePoints(SkSVGPointsType*);
    bool parseIRI(SkSVGStringType*);
    bool parseSpreadMethod(SkSVGSpreadMethod*);
    bool parseVisibility(SkSVGVisibility*);
    bool parseDashArray(SkSVGDashArray*);

private:
    // Stack-only
    void* operator new(size_t) = delete;
    void* operator new(size_t, void*) = delete;

    template <typename F>
    bool advanceWhile(F func);

    bool parseWSToken();
    bool parseEOSToken();
    bool parseSepToken();
    bool parseExpectedStringToken(const char*);
    bool parseScalarToken(SkScalar*);
    bool parseHexToken(uint32_t*);
    bool parseLengthUnitToken(SkSVGLength::Unit*);
    bool parseNamedColorToken(SkColor*);
    bool parseHexColorToken(SkColor*);
    bool parseColorComponentToken(int32_t*);
    bool parseRGBColorToken(SkColor*);
    bool parseFuncIRI(SkSVGStringType*);

    // Transform helpers
    bool parseMatrixToken(SkMatrix*);
    bool parseTranslateToken(SkMatrix*);
    bool parseScaleToken(SkMatrix*);
    bool parseRotateToken(SkMatrix*);
    bool parseSkewXToken(SkMatrix*);
    bool parseSkewYToken(SkMatrix*);

    // Parses a sequence of 'WS* <prefix> WS* (<nested>)', where the nested sequence
    // is handled by the passed functor.
    template <typename Func, typename T>
    bool parseParenthesized(const char* prefix, Func, T* result);

    // The current position in the input string.
    const char* fCurPos;

    typedef SkNoncopyable INHERITED;
};

#endif // SkSVGAttributeParser_DEFINED