blob: 0144a70d704e8e3c2a63f20ba7c72c97a93e3526 [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,
Florin Malitab3418102020-10-15 18:10:29 -040029 kLength,
30 kLineCap,
31 kLineJoin,
32 kNumber,
33 kPaint,
34 kPath,
35 kPoints,
36 kSpreadMethod,
37 kStopColor,
38 kString,
39 kTransform,
40 kViewBox,
41 kVisibility,
42 };
43
44 Type type() const { return fType; }
45
46 template <typename T>
47 const T* as() const {
48 return fType == T::TYPE ? static_cast<const T*>(this) : nullptr;
49 }
50
51protected:
52 SkSVGValue(Type t) : fType(t) { }
53
54private:
55 Type fType;
56
57 using INHERITED = SkNoncopyable;
58};
59
60template <typename T, SkSVGValue::Type ValueType>
61class SkSVGWrapperValue final : public SkSVGValue {
62public:
63 static constexpr Type TYPE = ValueType;
64
65 explicit SkSVGWrapperValue(const T& v)
66 : INHERITED(ValueType)
67 , fWrappedValue(v) { }
68
69 operator const T&() const { return fWrappedValue; }
70 const T* operator->() const { return &fWrappedValue; }
71
72private:
73 // Stack-only
74 void* operator new(size_t) = delete;
75 void* operator new(size_t, void*) = delete;
76
77 const T& fWrappedValue;
78
79 using INHERITED = SkSVGValue;
80};
81
82using SkSVGClipValue = SkSVGWrapperValue<SkSVGClip , SkSVGValue::Type::kClip >;
83using SkSVGColorValue = SkSVGWrapperValue<SkSVGColorType , SkSVGValue::Type::kColor >;
84using SkSVGFillRuleValue = SkSVGWrapperValue<SkSVGFillRule , SkSVGValue::Type::kFillRule >;
85using SkSVGLengthValue = SkSVGWrapperValue<SkSVGLength , SkSVGValue::Type::kLength >;
86using SkSVGPathValue = SkSVGWrapperValue<SkPath , SkSVGValue::Type::kPath >;
87using SkSVGTransformValue = SkSVGWrapperValue<SkSVGTransformType, SkSVGValue::Type::kTransform >;
88using SkSVGViewBoxValue = SkSVGWrapperValue<SkSVGViewBoxType , SkSVGValue::Type::kViewBox >;
89using SkSVGPaintValue = SkSVGWrapperValue<SkSVGPaint , SkSVGValue::Type::kPaint >;
90using SkSVGLineCapValue = SkSVGWrapperValue<SkSVGLineCap , SkSVGValue::Type::kLineCap >;
91using SkSVGLineJoinValue = SkSVGWrapperValue<SkSVGLineJoin , SkSVGValue::Type::kLineJoin >;
92using SkSVGNumberValue = SkSVGWrapperValue<SkSVGNumberType , SkSVGValue::Type::kNumber >;
93using SkSVGPointsValue = SkSVGWrapperValue<SkSVGPointsType , SkSVGValue::Type::kPoints >;
94using SkSVGStringValue = SkSVGWrapperValue<SkSVGStringType , SkSVGValue::Type::kString >;
95using SkSVGSpreadMethodValue = SkSVGWrapperValue<SkSVGSpreadMethod ,
96 SkSVGValue::Type::kSpreadMethod>;
97using SkSVGStopColorValue = SkSVGWrapperValue<SkSVGStopColor , SkSVGValue::Type::kStopColor >;
98using SkSVGVisibilityValue = SkSVGWrapperValue<SkSVGVisibility , SkSVGValue::Type::kVisibility>;
99using SkSVGDashArrayValue = SkSVGWrapperValue<SkSVGDashArray , SkSVGValue::Type::kDashArray >;
100
Florin Malita39fe8c82020-10-20 10:43:03 -0400101using SkSVGFontFamilyValue = SkSVGWrapperValue<SkSVGFontFamily , SkSVGValue::Type::kFontFamily>;
102using SkSVGFontSizeValue = SkSVGWrapperValue<SkSVGFontSize , SkSVGValue::Type::kFontSize >;
103using SkSVGFontStyleValue = SkSVGWrapperValue<SkSVGFontStyle , SkSVGValue::Type::kFontStyle >;
104using SkSVGFontWeightValue = SkSVGWrapperValue<SkSVGFontWeight , SkSVGValue::Type::kFontWeight>;
105
Florin Malitab3418102020-10-15 18:10:29 -0400106#endif // SkSVGValue_DEFINED