2016-07-27 01:46:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkSVGValue_DEFINED
|
|
|
|
#define SkSVGValue_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "experimental/svg/model/SkSVGTypes.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "include/private/SkNoncopyable.h"
|
2016-07-27 01:46:34 +00:00
|
|
|
|
|
|
|
class SkSVGValue : public SkNoncopyable {
|
|
|
|
public:
|
|
|
|
enum class Type {
|
2016-12-08 14:26:47 +00:00
|
|
|
kClip,
|
2016-08-03 17:21:11 +00:00
|
|
|
kColor,
|
2017-10-13 18:07:44 +00:00
|
|
|
kDashArray,
|
2016-12-01 18:35:11 +00:00
|
|
|
kFillRule,
|
2016-08-03 17:21:11 +00:00
|
|
|
kLength,
|
2016-08-11 16:16:29 +00:00
|
|
|
kLineCap,
|
|
|
|
kLineJoin,
|
|
|
|
kNumber,
|
|
|
|
kPaint,
|
2016-08-03 17:21:11 +00:00
|
|
|
kPath,
|
2016-08-12 19:15:33 +00:00
|
|
|
kPoints,
|
2016-09-13 19:56:11 +00:00
|
|
|
kSpreadMethod,
|
2016-09-13 00:06:47 +00:00
|
|
|
kString,
|
2016-08-03 17:21:11 +00:00
|
|
|
kTransform,
|
2016-08-08 18:38:55 +00:00
|
|
|
kViewBox,
|
2017-10-12 15:33:28 +00:00
|
|
|
kVisibility,
|
2016-07-27 01:46:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Type type() const { return fType; }
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
const T* as() const {
|
|
|
|
return fType == T::TYPE ? static_cast<const T*>(this) : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkSVGValue(Type t) : fType(t) { }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Type fType;
|
2016-08-03 17:21:11 +00:00
|
|
|
|
|
|
|
typedef SkNoncopyable INHERITED;
|
2016-07-27 01:46:34 +00:00
|
|
|
};
|
|
|
|
|
2016-08-08 18:38:55 +00:00
|
|
|
template <typename T, SkSVGValue::Type ValueType>
|
2016-07-27 01:46:34 +00:00
|
|
|
class SkSVGWrapperValue final : public SkSVGValue {
|
|
|
|
public:
|
|
|
|
static constexpr Type TYPE = ValueType;
|
|
|
|
|
2016-08-08 18:38:55 +00:00
|
|
|
explicit SkSVGWrapperValue(const T& v)
|
2016-07-27 01:46:34 +00:00
|
|
|
: INHERITED(ValueType)
|
|
|
|
, fWrappedValue(v) { }
|
|
|
|
|
2016-08-08 18:38:55 +00:00
|
|
|
operator const T&() const { return fWrappedValue; }
|
2016-08-11 16:16:29 +00:00
|
|
|
const T* operator->() const { return &fWrappedValue; }
|
2016-07-27 01:46:34 +00:00
|
|
|
|
|
|
|
private:
|
2016-08-08 18:38:55 +00:00
|
|
|
// Stack-only
|
|
|
|
void* operator new(size_t) = delete;
|
|
|
|
void* operator new(size_t, void*) = delete;
|
|
|
|
|
|
|
|
const T& fWrappedValue;
|
2016-07-27 01:46:34 +00:00
|
|
|
|
2016-08-03 17:21:11 +00:00
|
|
|
typedef SkSVGValue INHERITED;
|
2016-07-27 01:46:34 +00:00
|
|
|
};
|
|
|
|
|
2017-10-12 15:33:28 +00:00
|
|
|
using SkSVGClipValue = SkSVGWrapperValue<SkSVGClip , SkSVGValue::Type::kClip >;
|
|
|
|
using SkSVGColorValue = SkSVGWrapperValue<SkSVGColorType , SkSVGValue::Type::kColor >;
|
|
|
|
using SkSVGFillRuleValue = SkSVGWrapperValue<SkSVGFillRule , SkSVGValue::Type::kFillRule >;
|
|
|
|
using SkSVGLengthValue = SkSVGWrapperValue<SkSVGLength , SkSVGValue::Type::kLength >;
|
|
|
|
using SkSVGPathValue = SkSVGWrapperValue<SkPath , SkSVGValue::Type::kPath >;
|
|
|
|
using SkSVGTransformValue = SkSVGWrapperValue<SkSVGTransformType, SkSVGValue::Type::kTransform >;
|
|
|
|
using SkSVGViewBoxValue = SkSVGWrapperValue<SkSVGViewBoxType , SkSVGValue::Type::kViewBox >;
|
|
|
|
using SkSVGPaintValue = SkSVGWrapperValue<SkSVGPaint , SkSVGValue::Type::kPaint >;
|
|
|
|
using SkSVGLineCapValue = SkSVGWrapperValue<SkSVGLineCap , SkSVGValue::Type::kLineCap >;
|
|
|
|
using SkSVGLineJoinValue = SkSVGWrapperValue<SkSVGLineJoin , SkSVGValue::Type::kLineJoin >;
|
|
|
|
using SkSVGNumberValue = SkSVGWrapperValue<SkSVGNumberType , SkSVGValue::Type::kNumber >;
|
|
|
|
using SkSVGPointsValue = SkSVGWrapperValue<SkSVGPointsType , SkSVGValue::Type::kPoints >;
|
|
|
|
using SkSVGStringValue = SkSVGWrapperValue<SkSVGStringType , SkSVGValue::Type::kString >;
|
2016-09-13 19:56:11 +00:00
|
|
|
using SkSVGSpreadMethodValue = SkSVGWrapperValue<SkSVGSpreadMethod ,
|
|
|
|
SkSVGValue::Type::kSpreadMethod>;
|
2017-10-12 15:33:28 +00:00
|
|
|
using SkSVGVisibilityValue = SkSVGWrapperValue<SkSVGVisibility , SkSVGValue::Type::kVisibility>;
|
2017-10-13 18:07:44 +00:00
|
|
|
using SkSVGDashArrayValue = SkSVGWrapperValue<SkSVGDashArray , SkSVGValue::Type::kDashArray >;
|
2016-07-27 01:46:34 +00:00
|
|
|
|
|
|
|
#endif // SkSVGValue_DEFINED
|