| 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 "SkPoint.h" | 13 #include "SkPoint.h" |
| 14 #include "SkRect.h" | 14 #include "SkRect.h" |
| 15 #include "SkScalar.h" | 15 #include "SkScalar.h" |
| 16 #include "SkString.h" |
| 16 #include "SkTDArray.h" | 17 #include "SkTDArray.h" |
| 17 #include "SkTypes.h" | 18 #include "SkTypes.h" |
| 18 | 19 |
| 19 template <typename T> | 20 template <typename T> |
| 20 class SkSVGPrimitiveTypeWrapper { | 21 class SkSVGPrimitiveTypeWrapper { |
| 21 public: | 22 public: |
| 22 SkSVGPrimitiveTypeWrapper() = default; | 23 SkSVGPrimitiveTypeWrapper() = default; |
| 23 explicit constexpr SkSVGPrimitiveTypeWrapper(T v) : fValue(v) {} | 24 explicit constexpr SkSVGPrimitiveTypeWrapper(T v) : fValue(v) {} |
| 24 | 25 |
| 25 SkSVGPrimitiveTypeWrapper(const SkSVGPrimitiveTypeWrapper&) = def
ault; | 26 SkSVGPrimitiveTypeWrapper(const SkSVGPrimitiveTypeWrapper&) = def
ault; |
| 26 SkSVGPrimitiveTypeWrapper& operator=(const SkSVGPrimitiveTypeWrapper&) = def
ault; | 27 SkSVGPrimitiveTypeWrapper& operator=(const SkSVGPrimitiveTypeWrapper&) = def
ault; |
| 27 SkSVGPrimitiveTypeWrapper& operator=(const T& v) { fValue = v; return *this;
} | 28 SkSVGPrimitiveTypeWrapper& operator=(const T& v) { fValue = v; return *this;
} |
| 28 | 29 |
| 29 bool operator==(const SkSVGPrimitiveTypeWrapper<T>& other) const { | 30 bool operator==(const SkSVGPrimitiveTypeWrapper<T>& other) const { |
| 30 return fValue == other.fValue; | 31 return fValue == other.fValue; |
| 31 } | 32 } |
| 32 bool operator!=(const SkSVGPrimitiveTypeWrapper<T>& other) const { | 33 bool operator!=(const SkSVGPrimitiveTypeWrapper<T>& other) const { |
| 33 return !(*this == other); | 34 return !(*this == other); |
| 34 } | 35 } |
| 35 | 36 |
| 36 const T& value() const { return fValue; } | 37 const T& value() const { return fValue; } |
| 37 operator const T&() const { return fValue; } | 38 operator const T&() const { return fValue; } |
| 38 | 39 |
| 39 private: | 40 private: |
| 40 T fValue; | 41 T fValue; |
| 41 }; | 42 }; |
| 42 | 43 |
| 43 using SkSVGColorType = SkSVGPrimitiveTypeWrapper<SkColor >; | 44 using SkSVGColorType = SkSVGPrimitiveTypeWrapper<SkColor >; |
| 44 using SkSVGNumberType = SkSVGPrimitiveTypeWrapper<SkScalar>; | 45 using SkSVGNumberType = SkSVGPrimitiveTypeWrapper<SkScalar>; |
| 46 using SkSVGStringType = SkSVGPrimitiveTypeWrapper<SkString>; |
| 45 using SkSVGViewBoxType = SkSVGPrimitiveTypeWrapper<SkRect >; | 47 using SkSVGViewBoxType = SkSVGPrimitiveTypeWrapper<SkRect >; |
| 46 using SkSVGTransformType = SkSVGPrimitiveTypeWrapper<SkMatrix>; | 48 using SkSVGTransformType = SkSVGPrimitiveTypeWrapper<SkMatrix>; |
| 47 using SkSVGPointsType = SkSVGPrimitiveTypeWrapper<SkTDArray<SkPoint>>; | 49 using SkSVGPointsType = SkSVGPrimitiveTypeWrapper<SkTDArray<SkPoint>>; |
| 48 | 50 |
| 49 class SkSVGLength { | 51 class SkSVGLength { |
| 50 public: | 52 public: |
| 51 enum class Unit { | 53 enum class Unit { |
| 52 kUnknown, | 54 kUnknown, |
| 53 kNumber, | 55 kNumber, |
| 54 kPercentage, | 56 kPercentage, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 81 Unit fUnit; | 83 Unit fUnit; |
| 82 }; | 84 }; |
| 83 | 85 |
| 84 class SkSVGPaint { | 86 class SkSVGPaint { |
| 85 public: | 87 public: |
| 86 enum class Type { | 88 enum class Type { |
| 87 kNone, | 89 kNone, |
| 88 kCurrentColor, | 90 kCurrentColor, |
| 89 kColor, | 91 kColor, |
| 90 kInherit, | 92 kInherit, |
| 93 kIRI, |
| 91 }; | 94 }; |
| 92 | 95 |
| 93 constexpr SkSVGPaint() : fType(Type::kInherit), fColor(SK_ColorBLACK) {} | 96 SkSVGPaint() : fType(Type::kInherit), fColor(SK_ColorBLACK) {} |
| 94 explicit constexpr SkSVGPaint(Type t) : fType(t), fColor(SK_ColorBLACK) {} | 97 explicit SkSVGPaint(Type t) : fType(t), fColor(SK_ColorBLACK) {} |
| 95 explicit constexpr SkSVGPaint(const SkSVGColorType& c) : fType(Type::kColor)
, fColor(c) {} | 98 explicit SkSVGPaint(const SkSVGColorType& c) : fType(Type::kColor), fColor(c
) {} |
| 99 explicit SkSVGPaint(const SkString& iri) |
| 100 : fType(Type::kIRI), fColor(SK_ColorBLACK), fIRI(iri) {} |
| 96 | 101 |
| 97 SkSVGPaint(const SkSVGPaint&) = default; | 102 SkSVGPaint(const SkSVGPaint&) = default; |
| 98 SkSVGPaint& operator=(const SkSVGPaint&) = default; | 103 SkSVGPaint& operator=(const SkSVGPaint&) = default; |
| 99 | 104 |
| 100 bool operator==(const SkSVGPaint& other) const { | 105 bool operator==(const SkSVGPaint& other) const { |
| 101 return fType == other.fType && fColor == other.fColor; | 106 return fType == other.fType && fColor == other.fColor && fIRI == other.f
IRI; |
| 102 } | 107 } |
| 103 bool operator!=(const SkSVGPaint& other) const { return !(*this == other); } | 108 bool operator!=(const SkSVGPaint& other) const { return !(*this == other); } |
| 104 | 109 |
| 105 Type type() const { return fType; } | 110 Type type() const { return fType; } |
| 106 const SkSVGColorType& color() const { SkASSERT(fType == Type::kColor); retur
n fColor; } | 111 const SkSVGColorType& color() const { SkASSERT(fType == Type::kColor); retur
n fColor; } |
| 112 const SkString& iri() const { SkASSERT(fType == Type::kIRI); return fIRI; } |
| 107 | 113 |
| 108 private: | 114 private: |
| 109 Type fType; | 115 Type fType; |
| 110 | 116 |
| 117 // Logical union. |
| 111 SkSVGColorType fColor; | 118 SkSVGColorType fColor; |
| 119 SkString fIRI; |
| 112 }; | 120 }; |
| 113 | 121 |
| 114 class SkSVGLineCap { | 122 class SkSVGLineCap { |
| 115 public: | 123 public: |
| 116 enum class Type { | 124 enum class Type { |
| 117 kButt, | 125 kButt, |
| 118 kRound, | 126 kRound, |
| 119 kSquare, | 127 kSquare, |
| 120 kInherit, | 128 kInherit, |
| 121 }; | 129 }; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 bool operator==(const SkSVGLineJoin& other) const { return fType == other.fT
ype; } | 161 bool operator==(const SkSVGLineJoin& other) const { return fType == other.fT
ype; } |
| 154 bool operator!=(const SkSVGLineJoin& other) const { return !(*this == other)
; } | 162 bool operator!=(const SkSVGLineJoin& other) const { return !(*this == other)
; } |
| 155 | 163 |
| 156 Type type() const { return fType; } | 164 Type type() const { return fType; } |
| 157 | 165 |
| 158 private: | 166 private: |
| 159 Type fType; | 167 Type fType; |
| 160 }; | 168 }; |
| 161 | 169 |
| 162 #endif // SkSVGTypes_DEFINED | 170 #endif // SkSVGTypes_DEFINED |
| OLD | NEW |