blob: b9ea6597c5fa19f2e0ee72e704f3379cf9f751ad [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 SkSVGValue_DEFINED
9#define SkSVGValue_DEFINED
10
11#include "include/core/SkColor.h"
12#include "include/core/SkMatrix.h"
13#include "include/core/SkPath.h"
14#include "include/core/SkTypes.h"
15#include "include/private/SkNoncopyable.h"
16#include "modules/svg/include/SkSVGTypes.h"
17
18class SkSVGValue : public SkNoncopyable {
19public:
20 enum class Type {
21 kClip,
22 kColor,
23 kDashArray,
24 kFillRule,
Florin Malita39fe8c82020-10-20 10:43:03 -040025 kFontFamily,
26 kFontSize,
27 kFontStyle,
28 kFontWeight,
Tyler Dennistonab76ab42020-10-21 15:08:45 -040029 kGradientUnits,
Florin Malitab3418102020-10-15 18:10:29 -040030 kLength,
31 kLineCap,
32 kLineJoin,
33 kNumber,
34 kPaint,
35 kPath,
36 kPoints,
Florin Malita385e7442020-10-21 16:55:46 -040037 kPreserveAspectRatio,
Florin Malitab3418102020-10-15 18:10:29 -040038 kSpreadMethod,
39 kStopColor,
40 kString,
41 kTransform,
42 kViewBox,
43 kVisibility,
44 };
45
46 Type type() const { return fType; }
47
48 template <typename T>
49 const T* as() const {
50 return fType == T::TYPE ? static_cast<const T*>(this) : nullptr;
51 }
52
53protected:
54 SkSVGValue(Type t) : fType(t) { }
55
56private:
57 Type fType;
58
59 using INHERITED = SkNoncopyable;
60};
61
62template <typename T, SkSVGValue::Type ValueType>
63class SkSVGWrapperValue final : public SkSVGValue {
64public:
65 static constexpr Type TYPE = ValueType;
66
67 explicit SkSVGWrapperValue(const T& v)
68 : INHERITED(ValueType)
69 , fWrappedValue(v) { }
70
71 operator const T&() const { return fWrappedValue; }
72 const T* operator->() const { return &fWrappedValue; }
73
74private:
75 // Stack-only
76 void* operator new(size_t) = delete;
77 void* operator new(size_t, void*) = delete;
78
79 const T& fWrappedValue;
80
81 using INHERITED = SkSVGValue;
82};
83
84using SkSVGClipValue = SkSVGWrapperValue<SkSVGClip , SkSVGValue::Type::kClip >;
85using SkSVGColorValue = SkSVGWrapperValue<SkSVGColorType , SkSVGValue::Type::kColor >;
86using SkSVGFillRuleValue = SkSVGWrapperValue<SkSVGFillRule , SkSVGValue::Type::kFillRule >;
87using SkSVGLengthValue = SkSVGWrapperValue<SkSVGLength , SkSVGValue::Type::kLength >;
88using SkSVGPathValue = SkSVGWrapperValue<SkPath , SkSVGValue::Type::kPath >;
89using SkSVGTransformValue = SkSVGWrapperValue<SkSVGTransformType, SkSVGValue::Type::kTransform >;
90using SkSVGViewBoxValue = SkSVGWrapperValue<SkSVGViewBoxType , SkSVGValue::Type::kViewBox >;
91using SkSVGPaintValue = SkSVGWrapperValue<SkSVGPaint , SkSVGValue::Type::kPaint >;
92using SkSVGLineCapValue = SkSVGWrapperValue<SkSVGLineCap , SkSVGValue::Type::kLineCap >;
93using SkSVGLineJoinValue = SkSVGWrapperValue<SkSVGLineJoin , SkSVGValue::Type::kLineJoin >;
94using SkSVGNumberValue = SkSVGWrapperValue<SkSVGNumberType , SkSVGValue::Type::kNumber >;
95using SkSVGPointsValue = SkSVGWrapperValue<SkSVGPointsType , SkSVGValue::Type::kPoints >;
96using SkSVGStringValue = SkSVGWrapperValue<SkSVGStringType , SkSVGValue::Type::kString >;
97using SkSVGSpreadMethodValue = SkSVGWrapperValue<SkSVGSpreadMethod ,
98 SkSVGValue::Type::kSpreadMethod>;
99using SkSVGStopColorValue = SkSVGWrapperValue<SkSVGStopColor , SkSVGValue::Type::kStopColor >;
Tyler Dennistonab76ab42020-10-21 15:08:45 -0400100using SkSVGGradientUnitsValue= SkSVGWrapperValue<SkSVGGradientUnits,
101 SkSVGValue::Type::kGradientUnits>;
Florin Malitab3418102020-10-15 18:10:29 -0400102using SkSVGVisibilityValue = SkSVGWrapperValue<SkSVGVisibility , SkSVGValue::Type::kVisibility>;
103using SkSVGDashArrayValue = SkSVGWrapperValue<SkSVGDashArray , SkSVGValue::Type::kDashArray >;
104
Florin Malita39fe8c82020-10-20 10:43:03 -0400105using SkSVGFontFamilyValue = SkSVGWrapperValue<SkSVGFontFamily , SkSVGValue::Type::kFontFamily>;
106using SkSVGFontSizeValue = SkSVGWrapperValue<SkSVGFontSize , SkSVGValue::Type::kFontSize >;
107using SkSVGFontStyleValue = SkSVGWrapperValue<SkSVGFontStyle , SkSVGValue::Type::kFontStyle >;
108using SkSVGFontWeightValue = SkSVGWrapperValue<SkSVGFontWeight , SkSVGValue::Type::kFontWeight>;
109
Florin Malita385e7442020-10-21 16:55:46 -0400110using SkSVGPreserveAspectRatioValue = SkSVGWrapperValue<SkSVGPreserveAspectRatio,
111 SkSVGValue::Type::kPreserveAspectRatio>;
112
Florin Malitab3418102020-10-15 18:10:29 -0400113#endif // SkSVGValue_DEFINED