OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkSVGTypes_DEFINED | 8 #ifndef SkSVGTypes_DEFINED |
9 #define SkSVGTypes_DEFINED | 9 #define SkSVGTypes_DEFINED |
10 | 10 |
11 #include "SkColor.h" | 11 #include "SkColor.h" |
12 #include "SkMatrix.h" | 12 #include "SkMatrix.h" |
13 #include "SkRect.h" | 13 #include "SkRect.h" |
14 #include "SkScalar.h" | 14 #include "SkScalar.h" |
15 #include "SkTypes.h" | 15 #include "SkTypes.h" |
16 | 16 |
17 template <typename T> | 17 template <typename T> |
18 class SkSVGPrimitiveTypeWrapper { | 18 class SkSVGPrimitiveTypeWrapper { |
19 public: | 19 public: |
20 SkSVGPrimitiveTypeWrapper() = default; | 20 SkSVGPrimitiveTypeWrapper() = default; |
21 explicit constexpr SkSVGPrimitiveTypeWrapper(T v) : fValue(v) {} | 21 explicit constexpr SkSVGPrimitiveTypeWrapper(T v) : fValue(v) {} |
22 | 22 |
23 SkSVGPrimitiveTypeWrapper(const SkSVGPrimitiveTypeWrapper&) = def
ault; | 23 SkSVGPrimitiveTypeWrapper(const SkSVGPrimitiveTypeWrapper&) = def
ault; |
24 SkSVGPrimitiveTypeWrapper& operator=(const SkSVGPrimitiveTypeWrapper&) = def
ault; | 24 SkSVGPrimitiveTypeWrapper& operator=(const SkSVGPrimitiveTypeWrapper&) = def
ault; |
25 | 25 |
| 26 bool operator==(const SkSVGPrimitiveTypeWrapper<T>& other) const { |
| 27 return fValue == other.fValue; |
| 28 } |
| 29 bool operator!=(const SkSVGPrimitiveTypeWrapper<T>& other) const { |
| 30 return !(*this == other); |
| 31 } |
| 32 |
26 const T& value() const { return fValue; } | 33 const T& value() const { return fValue; } |
27 operator const T&() const { return fValue; } | 34 operator const T&() const { return fValue; } |
28 | 35 |
29 private: | 36 private: |
30 T fValue; | 37 T fValue; |
31 }; | 38 }; |
32 | 39 |
33 using SkSVGColorType = SkSVGPrimitiveTypeWrapper<SkColor >; | 40 using SkSVGColorType = SkSVGPrimitiveTypeWrapper<SkColor >; |
34 using SkSVGNumberType = SkSVGPrimitiveTypeWrapper<SkScalar>; | 41 using SkSVGNumberType = SkSVGPrimitiveTypeWrapper<SkScalar>; |
35 using SkSVGViewBoxType = SkSVGPrimitiveTypeWrapper<SkRect >; | 42 using SkSVGViewBoxType = SkSVGPrimitiveTypeWrapper<SkRect >; |
(...skipping 14 matching lines...) Expand all Loading... |
50 kPT, | 57 kPT, |
51 kPC, | 58 kPC, |
52 }; | 59 }; |
53 | 60 |
54 constexpr SkSVGLength() : fValue(0), fUnit(Unit::kUnknown
) {} | 61 constexpr SkSVGLength() : fValue(0), fUnit(Unit::kUnknown
) {} |
55 explicit constexpr SkSVGLength(SkScalar v, Unit u = Unit::kNumber) | 62 explicit constexpr SkSVGLength(SkScalar v, Unit u = Unit::kNumber) |
56 : fValue(v), fUnit(u) {} | 63 : fValue(v), fUnit(u) {} |
57 SkSVGLength(const SkSVGLength&) = default; | 64 SkSVGLength(const SkSVGLength&) = default; |
58 SkSVGLength& operator=(const SkSVGLength&) = default; | 65 SkSVGLength& operator=(const SkSVGLength&) = default; |
59 | 66 |
| 67 bool operator==(const SkSVGLength& other) const { |
| 68 return fUnit == other.fUnit && fValue == other.fValue; |
| 69 } |
| 70 bool operator!=(const SkSVGLength& other) const { return !(*this == other);
} |
| 71 |
60 const SkScalar& value() const { return fValue; } | 72 const SkScalar& value() const { return fValue; } |
61 const Unit& unit() const { return fUnit; } | 73 const Unit& unit() const { return fUnit; } |
62 | 74 |
63 private: | 75 private: |
64 SkScalar fValue; | 76 SkScalar fValue; |
65 Unit fUnit; | 77 Unit fUnit; |
66 }; | 78 }; |
67 | 79 |
| 80 class SkSVGPaint { |
| 81 public: |
| 82 enum class Type { |
| 83 kNone, |
| 84 kCurrentColor, |
| 85 kColor, |
| 86 kInherit, |
| 87 }; |
| 88 |
| 89 constexpr SkSVGPaint() : fType(Type::kInherit), fColor(SK_ColorBLACK) {} |
| 90 explicit constexpr SkSVGPaint(Type t) : fType(t), fColor(SK_ColorBLACK) {} |
| 91 explicit constexpr SkSVGPaint(const SkSVGColorType& c) : fType(Type::kColor)
, fColor(c) {} |
| 92 |
| 93 SkSVGPaint(const SkSVGPaint&) = default; |
| 94 SkSVGPaint& operator=(const SkSVGPaint&) = default; |
| 95 |
| 96 bool operator==(const SkSVGPaint& other) const { |
| 97 return fType == other.fType && fColor == other.fColor; |
| 98 } |
| 99 bool operator!=(const SkSVGPaint& other) const { return !(*this == other); } |
| 100 |
| 101 Type type() const { return fType; } |
| 102 const SkSVGColorType& color() const { SkASSERT(fType == Type::kColor); retur
n fColor; } |
| 103 |
| 104 private: |
| 105 Type fType; |
| 106 |
| 107 SkSVGColorType fColor; |
| 108 }; |
| 109 |
| 110 class SkSVGLineCap { |
| 111 public: |
| 112 enum class Type { |
| 113 kButt, |
| 114 kRound, |
| 115 kSquare, |
| 116 kInherit, |
| 117 }; |
| 118 |
| 119 constexpr SkSVGLineCap() : fType(Type::kInherit) {} |
| 120 constexpr explicit SkSVGLineCap(Type t) : fType(t) {} |
| 121 |
| 122 SkSVGLineCap(const SkSVGLineCap&) = default; |
| 123 SkSVGLineCap& operator=(const SkSVGLineCap&) = default; |
| 124 |
| 125 bool operator==(const SkSVGLineCap& other) const { return fType == other.fTy
pe; } |
| 126 bool operator!=(const SkSVGLineCap& other) const { return !(*this == other);
} |
| 127 |
| 128 Type type() const { return fType; } |
| 129 |
| 130 private: |
| 131 Type fType; |
| 132 }; |
| 133 |
| 134 class SkSVGLineJoin { |
| 135 public: |
| 136 enum class Type { |
| 137 kMiter, |
| 138 kRound, |
| 139 kBevel, |
| 140 kInherit, |
| 141 }; |
| 142 |
| 143 constexpr SkSVGLineJoin() : fType(Type::kInherit) {} |
| 144 constexpr explicit SkSVGLineJoin(Type t) : fType(t) {} |
| 145 |
| 146 SkSVGLineJoin(const SkSVGLineJoin&) = default; |
| 147 SkSVGLineJoin& operator=(const SkSVGLineJoin&) = default; |
| 148 |
| 149 bool operator==(const SkSVGLineJoin& other) const { return fType == other.fT
ype; } |
| 150 bool operator!=(const SkSVGLineJoin& other) const { return !(*this == other)
; } |
| 151 |
| 152 Type type() const { return fType; } |
| 153 |
| 154 private: |
| 155 Type fType; |
| 156 }; |
| 157 |
68 #endif // SkSVGTypes_DEFINED | 158 #endif // SkSVGTypes_DEFINED |
OLD | NEW |