"experimental/svg/model/SkSVGAttribute.cpp",
"experimental/svg/model/SkSVGAttributeParser.cpp",
"experimental/svg/model/SkSVGContainer.cpp",
+ "experimental/svg/model/SkSVGCircle.cpp",
"experimental/svg/model/SkSVGDOM.cpp",
+ "experimental/svg/model/SkSVGEllipse.cpp",
"experimental/svg/model/SkSVGNode.cpp",
"experimental/svg/model/SkSVGPath.cpp",
"experimental/svg/model/SkSVGPoly.cpp",
class SkSVGRenderContext;
enum class SkSVGAttribute {
+ kCx, // <circle>,<ellipse>: center x position
+ kCy, // <circle>,<ellipse>: center y position
kD,
kFill,
kFillOpacity,
kHeight,
kOpacity,
kPoints,
- kRx,
- kRy,
+ kR, // <circle>: radius
+ kRx, // <ellipse>,<rect>: horizontal (corner) radius
+ kRy, // <ellipse>,<rect>: vertical (corner) radius
kStroke,
kStrokeOpacity,
kStrokeLineCap,
--- /dev/null
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkCanvas.h"
+#include "SkSVGCircle.h"
+#include "SkSVGRenderContext.h"
+#include "SkSVGValue.h"
+
+SkSVGCircle::SkSVGCircle() : INHERITED(SkSVGTag::kCircle) {}
+
+void SkSVGCircle::setCx(const SkSVGLength& cx) {
+ fCx = cx;
+}
+
+void SkSVGCircle::setCy(const SkSVGLength& cy) {
+ fCy = cy;
+}
+
+void SkSVGCircle::setR(const SkSVGLength& r) {
+ fR = r;
+}
+
+void SkSVGCircle::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
+ switch (attr) {
+ case SkSVGAttribute::kCx:
+ if (const auto* cx = v.as<SkSVGLengthValue>()) {
+ this->setCx(*cx);
+ }
+ break;
+ case SkSVGAttribute::kCy:
+ if (const auto* cy = v.as<SkSVGLengthValue>()) {
+ this->setCy(*cy);
+ }
+ break;
+ case SkSVGAttribute::kR:
+ if (const auto* r = v.as<SkSVGLengthValue>()) {
+ this->setR(*r);
+ }
+ break;
+ default:
+ this->INHERITED::onSetAttribute(attr, v);
+ }
+}
+
+void SkSVGCircle::onDraw(SkCanvas* canvas, const SkSVGLengthContext& lctx,
+ const SkPaint& paint) const {
+ const auto cx = lctx.resolve(fCx, SkSVGLengthContext::LengthType::kHorizontal);
+ const auto cy = lctx.resolve(fCy, SkSVGLengthContext::LengthType::kVertical);
+ const auto r = lctx.resolve(fR , SkSVGLengthContext::LengthType::kOther);
+
+ if (r > 0) {
+ canvas->drawCircle(cx, cy, r, paint);
+ }
+}
--- /dev/null
+/*
+ * 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 SkSVGCircle_DEFINED
+#define SkSVGCircle_DEFINED
+
+#include "SkSVGShape.h"
+#include "SkSVGTypes.h"
+
+class SkSVGCircle final : public SkSVGShape {
+public:
+ virtual ~SkSVGCircle() = default;
+ static sk_sp<SkSVGCircle> Make() { return sk_sp<SkSVGCircle>(new SkSVGCircle()); }
+
+ void setCx(const SkSVGLength&);
+ void setCy(const SkSVGLength&);
+ void setR(const SkSVGLength&);
+
+protected:
+ void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
+
+ void onDraw(SkCanvas*, const SkSVGLengthContext&, const SkPaint&) const override;
+
+private:
+ SkSVGCircle();
+
+ SkSVGLength fCx = SkSVGLength(0);
+ SkSVGLength fCy = SkSVGLength(0);
+ SkSVGLength fR = SkSVGLength(0);
+
+ typedef SkSVGShape INHERITED;
+};
+
+#endif // SkSVGCircle_DEFINED
#include "SkParsePath.h"
#include "SkString.h"
#include "SkSVGAttributeParser.h"
+#include "SkSVGCircle.h"
#include "SkSVGDOM.h"
+#include "SkSVGEllipse.h"
#include "SkSVGG.h"
#include "SkSVGNode.h"
#include "SkSVGPath.h"
};
SortedDictionaryEntry<AttrParseInfo> gAttributeParseInfo[] = {
+ { "cx" , { SkSVGAttribute::kCx , SetLengthAttribute }},
+ { "cy" , { SkSVGAttribute::kCy , SetLengthAttribute }},
{ "d" , { SkSVGAttribute::kD , SetPathDataAttribute }},
{ "fill" , { SkSVGAttribute::kFill , SetPaintAttribute }},
{ "fill-opacity" , { SkSVGAttribute::kFillOpacity , SetNumberAttribute }},
{ "height" , { SkSVGAttribute::kHeight , SetLengthAttribute }},
{ "opacity" , { SkSVGAttribute::kOpacity , SetNumberAttribute }},
{ "points" , { SkSVGAttribute::kPoints , SetPointsAttribute }},
+ { "r" , { SkSVGAttribute::kR , SetLengthAttribute }},
{ "rx" , { SkSVGAttribute::kRx , SetLengthAttribute }},
{ "ry" , { SkSVGAttribute::kRy , SetLengthAttribute }},
{ "stroke" , { SkSVGAttribute::kStroke , SetPaintAttribute }},
};
SortedDictionaryEntry<sk_sp<SkSVGNode>(*)()> gTagFactories[] = {
+ { "circle" , []() -> sk_sp<SkSVGNode> { return SkSVGCircle::Make(); }},
+ { "ellipse" , []() -> sk_sp<SkSVGNode> { return SkSVGEllipse::Make(); }},
{ "g" , []() -> sk_sp<SkSVGNode> { return SkSVGG::Make(); }},
{ "path" , []() -> sk_sp<SkSVGNode> { return SkSVGPath::Make(); }},
{ "polygon" , []() -> sk_sp<SkSVGNode> { return SkSVGPoly::MakePolygon(); }},
--- /dev/null
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkCanvas.h"
+#include "SkSVGEllipse.h"
+#include "SkSVGRenderContext.h"
+#include "SkSVGValue.h"
+
+SkSVGEllipse::SkSVGEllipse() : INHERITED(SkSVGTag::kEllipse) {}
+
+void SkSVGEllipse::setCx(const SkSVGLength& cx) {
+ fCx = cx;
+}
+
+void SkSVGEllipse::setCy(const SkSVGLength& cy) {
+ fCy = cy;
+}
+
+void SkSVGEllipse::setRx(const SkSVGLength& rx) {
+ fRx = rx;
+}
+
+void SkSVGEllipse::setRy(const SkSVGLength& ry) {
+ fRy = ry;
+}
+
+void SkSVGEllipse::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
+ switch (attr) {
+ case SkSVGAttribute::kCx:
+ if (const auto* cx = v.as<SkSVGLengthValue>()) {
+ this->setCx(*cx);
+ }
+ break;
+ case SkSVGAttribute::kCy:
+ if (const auto* cy = v.as<SkSVGLengthValue>()) {
+ this->setCy(*cy);
+ }
+ break;
+ case SkSVGAttribute::kRx:
+ if (const auto* rx = v.as<SkSVGLengthValue>()) {
+ this->setRx(*rx);
+ }
+ break;
+ case SkSVGAttribute::kRy:
+ if (const auto* ry = v.as<SkSVGLengthValue>()) {
+ this->setRy(*ry);
+ }
+ break;
+ default:
+ this->INHERITED::onSetAttribute(attr, v);
+ }
+}
+
+void SkSVGEllipse::onDraw(SkCanvas* canvas, const SkSVGLengthContext& lctx,
+ const SkPaint& paint) const {
+ const auto cx = lctx.resolve(fCx, SkSVGLengthContext::LengthType::kHorizontal);
+ const auto cy = lctx.resolve(fCy, SkSVGLengthContext::LengthType::kVertical);
+ const auto rx = lctx.resolve(fRx, SkSVGLengthContext::LengthType::kHorizontal);
+ const auto ry = lctx.resolve(fRy, SkSVGLengthContext::LengthType::kVertical);
+
+ if (rx > 0 && ry > 0) {
+ canvas->drawOval(SkRect::MakeXYWH(cx - rx / 2, cy - ry / 2, rx * 2, ry * 2), paint);
+ }
+}
--- /dev/null
+/*
+ * 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 SkSVGEllipse_DEFINED
+#define SkSVGEllipse_DEFINED
+
+#include "SkSVGShape.h"
+#include "SkSVGTypes.h"
+
+class SkSVGEllipse final : public SkSVGShape {
+public:
+ virtual ~SkSVGEllipse() = default;
+ static sk_sp<SkSVGEllipse> Make() { return sk_sp<SkSVGEllipse>(new SkSVGEllipse()); }
+
+ void setCx(const SkSVGLength&);
+ void setCy(const SkSVGLength&);
+ void setRx(const SkSVGLength&);
+ void setRy(const SkSVGLength&);
+
+protected:
+ void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
+
+ void onDraw(SkCanvas*, const SkSVGLengthContext&, const SkPaint&) const override;
+
+private:
+ SkSVGEllipse();
+
+ SkSVGLength fCx = SkSVGLength(0);
+ SkSVGLength fCy = SkSVGLength(0);
+ SkSVGLength fRx = SkSVGLength(0);
+ SkSVGLength fRy = SkSVGLength(0);
+
+ typedef SkSVGShape INHERITED;
+};
+
+#endif // SkSVGEllipse_DEFINED
class SkSVGValue;
enum class SkSVGTag {
+ kCircle,
+ kEllipse,
kG,
kPath,
kPolygon,
'../experimental/svg/model/SkSVGAttribute.cpp',
'../experimental/svg/model/SkSVGAttributeParser.h',
'../experimental/svg/model/SkSVGAttributeParser.cpp',
+ '../experimental/svg/model/SkSVGCircle.h',
+ '../experimental/svg/model/SkSVGCircle.cpp',
'../experimental/svg/model/SkSVGContainer.h',
'../experimental/svg/model/SkSVGContainer.cpp',
'../experimental/svg/model/SkSVGDOM.h',
'../experimental/svg/model/SkSVGDOM.cpp',
+ '../experimental/svg/model/SkSVGEllipse.h',
+ '../experimental/svg/model/SkSVGEllipse.cpp',
'../experimental/svg/model/SkSVGG.h',
'../experimental/svg/model/SkSVGNode.h',
'../experimental/svg/model/SkSVGNode.cpp',