blob: 7d329c7a2bcbf50c11f5cf48e7b4ea0cd82d4244 [file] [log] [blame]
fmalitabffc2562016-08-03 10:21:11 -07001/*
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
fmalita397a5172016-08-08 11:38:55 -070017 bool parseColor(SkSVGColorType*);
Florin Malitace8840e2016-12-08 09:26:47 -050018 bool parseClipPath(SkSVGClip*);
Florin Malitae932d4b2016-12-01 13:35:11 -050019 bool parseFillRule(SkSVGFillRule*);
fmalita397a5172016-08-08 11:38:55 -070020 bool parseNumber(SkSVGNumberType*);
fmalitabffc2562016-08-03 10:21:11 -070021 bool parseLength(SkSVGLength*);
fmalita397a5172016-08-08 11:38:55 -070022 bool parseViewBox(SkSVGViewBoxType*);
fmalitac97796b2016-08-08 12:58:57 -070023 bool parseTransform(SkSVGTransformType*);
fmalita2d961e02016-08-11 09:16:29 -070024 bool parsePaint(SkSVGPaint*);
25 bool parseLineCap(SkSVGLineCap*);
26 bool parseLineJoin(SkSVGLineJoin*);
fmalita5b31f322016-08-12 12:15:33 -070027 bool parsePoints(SkSVGPointsType*);
fmalita28d5b722016-09-12 17:06:47 -070028 bool parseIRI(SkSVGStringType*);
fmalitacecd6172016-09-13 12:56:11 -070029 bool parseSpreadMethod(SkSVGSpreadMethod*);
Florin Malitaffe6ae42017-10-12 11:33:28 -040030 bool parseVisibility(SkSVGVisibility*);
Florin Malitaf543a602017-10-13 14:07:44 -040031 bool parseDashArray(SkSVGDashArray*);
fmalitabffc2562016-08-03 10:21:11 -070032
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*);
fmalita28d5b722016-09-12 17:06:47 -070050 bool parseColorComponentToken(int32_t*);
51 bool parseRGBColorToken(SkColor*);
52 bool parseFuncIRI(SkSVGStringType*);
fmalitabffc2562016-08-03 10:21:11 -070053
fmalitac97796b2016-08-08 12:58:57 -070054 // 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
fmalitabffc2562016-08-03 10:21:11 -070067 // The current position in the input string.
68 const char* fCurPos;
69
70 typedef SkNoncopyable INHERITED;
71};
72
73#endif // SkSVGAttributeParser_DEFINED