blob: 4f5404cc7d6518056c957c9eb847211aeac7f629 [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*);
Tyler Dennistonb3cafbc2020-10-30 15:00:48 -040021 bool parseFilter(SkSVGFilterType*);
Florin Malitab3418102020-10-15 18:10:29 -040022 bool parseNumber(SkSVGNumberType*);
Tyler Dennistondada9602020-11-03 10:04:25 -050023 bool parseInteger(SkSVGIntegerType*);
Florin Malitab3418102020-10-15 18:10:29 -040024 bool parseLength(SkSVGLength*);
25 bool parseViewBox(SkSVGViewBoxType*);
26 bool parseTransform(SkSVGTransformType*);
27 bool parsePaint(SkSVGPaint*);
28 bool parseLineCap(SkSVGLineCap*);
29 bool parseLineJoin(SkSVGLineJoin*);
30 bool parsePoints(SkSVGPointsType*);
31 bool parseIRI(SkSVGStringType*);
32 bool parseSpreadMethod(SkSVGSpreadMethod*);
33 bool parseStopColor(SkSVGStopColor*);
Tyler Denniston30e327e2020-10-29 16:29:22 -040034 bool parseObjectBoundingBoxUnits(SkSVGObjectBoundingBoxUnits*);
Florin Malitab3418102020-10-15 18:10:29 -040035 bool parseVisibility(SkSVGVisibility*);
36 bool parseDashArray(SkSVGDashArray*);
Florin Malita385e7442020-10-21 16:55:46 -040037 bool parsePreserveAspectRatio(SkSVGPreserveAspectRatio*);
Florin Malitab3418102020-10-15 18:10:29 -040038
Tyler Dennistondada9602020-11-03 10:04:25 -050039 bool parseFeTurbulenceBaseFrequency(SkSVGFeTurbulenceBaseFrequency*);
40 bool parseFeTurbulenceType(SkSVGFeTurbulenceType*);
41
Florin Malita39fe8c82020-10-20 10:43:03 -040042 bool parseFontFamily(SkSVGFontFamily*);
43 bool parseFontSize(SkSVGFontSize*);
44 bool parseFontStyle(SkSVGFontStyle*);
45 bool parseFontWeight(SkSVGFontWeight*);
Florin Malita056385b2020-10-27 22:57:56 -040046 bool parseTextAnchor(SkSVGTextAnchor*);
Florin Malita39fe8c82020-10-20 10:43:03 -040047
Florin Malitab3418102020-10-15 18:10:29 -040048private:
49 // Stack-only
50 void* operator new(size_t) = delete;
51 void* operator new(size_t, void*) = delete;
52
53 template <typename F>
54 bool advanceWhile(F func);
55
56 bool parseWSToken();
57 bool parseEOSToken();
58 bool parseSepToken();
59 bool parseCommaWspToken();
60 bool parseExpectedStringToken(const char*);
61 bool parseScalarToken(SkScalar*);
Tyler Dennistondada9602020-11-03 10:04:25 -050062 bool parseInt32Token(int32_t*);
Florin Malitab3418102020-10-15 18:10:29 -040063 bool parseHexToken(uint32_t*);
64 bool parseLengthUnitToken(SkSVGLength::Unit*);
65 bool parseNamedColorToken(SkColor*);
66 bool parseHexColorToken(SkColor*);
67 bool parseColorComponentToken(int32_t*);
68 bool parseRGBColorToken(SkColor*);
69 bool parseFuncIRI(SkSVGStringType*);
70
71 // Transform helpers
72 bool parseMatrixToken(SkMatrix*);
73 bool parseTranslateToken(SkMatrix*);
74 bool parseScaleToken(SkMatrix*);
75 bool parseRotateToken(SkMatrix*);
76 bool parseSkewXToken(SkMatrix*);
77 bool parseSkewYToken(SkMatrix*);
78
79 // Parses a sequence of 'WS* <prefix> WS* (<nested>)', where the nested sequence
80 // is handled by the passed functor.
81 template <typename Func, typename T>
82 bool parseParenthesized(const char* prefix, Func, T* result);
83
Florin Malita39fe8c82020-10-20 10:43:03 -040084 template <typename T, typename TArray>
85 bool parseEnumMap(const TArray& arr, T* result);
86
Florin Malitab3418102020-10-15 18:10:29 -040087 // The current position in the input string.
88 const char* fCurPos;
89
90 using INHERITED = SkNoncopyable;
91};
92
93#endif // SkSVGAttributeParser_DEFINED