| 1 |
/* |
| 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 SkSVGSVG_DEFINED |
| 9 |
#define SkSVGSVG_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkRefCnt.h" |
| 12 |
#include "include/core/SkSize.h" |
| 13 |
#include "include/private/base/SkAPI.h" |
| 14 |
#include "modules/svg/include/SkSVGContainer.h" |
| 15 |
#include "modules/svg/include/SkSVGNode.h" |
| 16 |
#include "modules/svg/include/SkSVGTypes.h" |
| 17 |
#include "modules/svg/include/SkSVGValue.h" |
| 18 |
|
| 19 |
class SkSVGLengthContext; |
| 20 |
class SkSVGRenderContext; |
| 21 |
enum class SkSVGAttribute; |
| 22 |
|
| 23 |
class SK_API SkSVGSVG : public SkSVGContainer { |
| 24 |
public: |
| 25 |
enum class Type { |
| 26 |
kRoot, |
| 27 |
kInner, |
| 28 |
}; |
| 29 |
static sk_sp<SkSVGSVG> Make(Type t = Type::kInner) { return sk_sp<SkSVGSVG>(new SkSVGSVG(t)); } |
| 30 |
|
| 31 |
SVG_ATTR(X , SkSVGLength, SkSVGLength(0)) |
| 32 |
SVG_ATTR(Y , SkSVGLength, SkSVGLength(0)) |
| 33 |
SVG_ATTR(Width , SkSVGLength, SkSVGLength(100, SkSVGLength::Unit::kPercentage)) |
| 34 |
SVG_ATTR(Height , SkSVGLength, SkSVGLength(100, SkSVGLength::Unit::kPercentage)) |
| 35 |
SVG_ATTR(PreserveAspectRatio, SkSVGPreserveAspectRatio, SkSVGPreserveAspectRatio()) |
| 36 |
|
| 37 |
SVG_OPTIONAL_ATTR(ViewBox, SkSVGViewBoxType) |
| 38 |
|
| 39 |
SkSize intrinsicSize(const SkSVGLengthContext&) const; |
| 40 |
|
| 41 |
void renderNode(const SkSVGRenderContext&, const SkSVGIRI& iri) const; |
| 42 |
|
| 43 |
protected: |
| 44 |
bool onPrepareToRender(SkSVGRenderContext*) const override; |
| 45 |
|
| 46 |
void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override; |
| 47 |
|
| 48 |
private: |
| 49 |
explicit SkSVGSVG(Type t) |
| 50 |
: INHERITED(SkSVGTag::kSvg) |
| 51 |
, fType(t) |
| 52 |
{} |
| 53 |
|
| 54 |
// Some attributes behave differently for the outermost svg element. |
| 55 |
const Type fType; |
| 56 |
|
| 57 |
using INHERITED = SkSVGContainer; |
| 58 |
}; |
| 59 |
|
| 60 |
#endif // SkSVGSVG_DEFINED |