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