blob: 49bd582f848797b4bc1e49c0a10824c79b37dac1 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "experimental/svg/model/SkSVGTypes.h"
12#include "include/private/SkNoncopyable.h"
fmalitabffc2562016-08-03 10:21:11 -070013
14class SkSVGAttributeParser : public SkNoncopyable {
15public:
16 SkSVGAttributeParser(const char[]);
17
fmalita397a5172016-08-08 11:38:55 -070018 bool parseColor(SkSVGColorType*);
Florin Malitace8840e2016-12-08 09:26:47 -050019 bool parseClipPath(SkSVGClip*);
Florin Malitae932d4b2016-12-01 13:35:11 -050020 bool parseFillRule(SkSVGFillRule*);
fmalita397a5172016-08-08 11:38:55 -070021 bool parseNumber(SkSVGNumberType*);
fmalitabffc2562016-08-03 10:21:11 -070022 bool parseLength(SkSVGLength*);
fmalita397a5172016-08-08 11:38:55 -070023 bool parseViewBox(SkSVGViewBoxType*);
fmalitac97796b2016-08-08 12:58:57 -070024 bool parseTransform(SkSVGTransformType*);
fmalita2d961e02016-08-11 09:16:29 -070025 bool parsePaint(SkSVGPaint*);
26 bool parseLineCap(SkSVGLineCap*);
27 bool parseLineJoin(SkSVGLineJoin*);
fmalita5b31f322016-08-12 12:15:33 -070028 bool parsePoints(SkSVGPointsType*);
fmalita28d5b722016-09-12 17:06:47 -070029 bool parseIRI(SkSVGStringType*);
fmalitacecd6172016-09-13 12:56:11 -070030 bool parseSpreadMethod(SkSVGSpreadMethod*);
Florin Malitaffe6ae42017-10-12 11:33:28 -040031 bool parseVisibility(SkSVGVisibility*);
Florin Malitaf543a602017-10-13 14:07:44 -040032 bool parseDashArray(SkSVGDashArray*);
fmalitabffc2562016-08-03 10:21:11 -070033
34private:
35 // Stack-only
36 void* operator new(size_t) = delete;
37 void* operator new(size_t, void*) = delete;
38
39 template <typename F>
40 bool advanceWhile(F func);
41
42 bool parseWSToken();
43 bool parseEOSToken();
44 bool parseSepToken();
45 bool parseExpectedStringToken(const char*);
46 bool parseScalarToken(SkScalar*);
47 bool parseHexToken(uint32_t*);
48 bool parseLengthUnitToken(SkSVGLength::Unit*);
49 bool parseNamedColorToken(SkColor*);
50 bool parseHexColorToken(SkColor*);
fmalita28d5b722016-09-12 17:06:47 -070051 bool parseColorComponentToken(int32_t*);
52 bool parseRGBColorToken(SkColor*);
53 bool parseFuncIRI(SkSVGStringType*);
fmalitabffc2562016-08-03 10:21:11 -070054
fmalitac97796b2016-08-08 12:58:57 -070055 // Transform helpers
56 bool parseMatrixToken(SkMatrix*);
57 bool parseTranslateToken(SkMatrix*);
58 bool parseScaleToken(SkMatrix*);
59 bool parseRotateToken(SkMatrix*);
60 bool parseSkewXToken(SkMatrix*);
61 bool parseSkewYToken(SkMatrix*);
62
63 // Parses a sequence of 'WS* <prefix> WS* (<nested>)', where the nested sequence
64 // is handled by the passed functor.
65 template <typename Func, typename T>
66 bool parseParenthesized(const char* prefix, Func, T* result);
67
fmalitabffc2562016-08-03 10:21:11 -070068 // The current position in the input string.
69 const char* fCurPos;
70
71 typedef SkNoncopyable INHERITED;
72};
73
74#endif // SkSVGAttributeParser_DEFINED