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
|
|
|
|
|
|
|
|
#include "SkColor.h"
|
|
|
|
#include "SkMatrix.h"
|
|
|
|
#include "SkPath.h"
|
2016-08-03 17:21:11 +00:00
|
|
|
#include "SkSVGTypes.h"
|
2016-07-27 01:46:34 +00:00
|
|
|
#include "SkTypes.h"
|
|
|
|
|
|
|
|
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,
|
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,
|
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
|
|
|
};
|
|
|
|
|
2016-12-08 14:26:47 +00:00
|
|
|
using SkSVGClipValue = SkSVGWrapperValue<SkSVGClip , SkSVGValue::Type::kClip >;
|
2016-09-13 19:56:11 +00:00
|
|
|
using SkSVGColorValue = SkSVGWrapperValue<SkSVGColorType , SkSVGValue::Type::kColor >;
|
2016-12-01 18:35:11 +00:00
|
|
|
using SkSVGFillRuleValue = SkSVGWrapperValue<SkSVGFillRule , SkSVGValue::Type::kFillRule >;
|
2016-09-13 19:56:11 +00:00
|
|
|
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 >;
|
|
|
|
using SkSVGSpreadMethodValue = SkSVGWrapperValue<SkSVGSpreadMethod ,
|
|
|
|
SkSVGValue::Type::kSpreadMethod>;
|
2016-07-27 01:46:34 +00:00
|
|
|
|
|
|
|
#endif // SkSVGValue_DEFINED
|