blob: 67c13f6b7edfcd5ba82e729f709a78d0d404dfb5 [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*);
fmalitabffc2562016-08-03 10:21:11 -070030
31private:
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*);
fmalita28d5b722016-09-12 17:06:47 -070048 bool parseColorComponentToken(int32_t*);
49 bool parseRGBColorToken(SkColor*);
50 bool parseFuncIRI(SkSVGStringType*);
fmalitabffc2562016-08-03 10:21:11 -070051
fmalitac97796b2016-08-08 12:58:57 -070052 // 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
fmalitabffc2562016-08-03 10:21:11 -070065 // The current position in the input string.
66 const char* fCurPos;
67
68 typedef SkNoncopyable INHERITED;
69};
70
71#endif // SkSVGAttributeParser_DEFINED