[svg] Refactor <path> to use new parsing
Change-Id: Ib33111e1b00f05d32f8c6add512c38b5a6197af8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/367884
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Tyler Denniston <tdenniston@google.com>
diff --git a/modules/svg/include/SkSVGAttribute.h b/modules/svg/include/SkSVGAttribute.h
index eb2f382..c27bce6 100644
--- a/modules/svg/include/SkSVGAttribute.h
+++ b/modules/svg/include/SkSVGAttribute.h
@@ -20,7 +20,6 @@
kColorInterpolationFilters,
kCx, // <circle>, <ellipse>, <radialGradient>: center x position
kCy, // <circle>, <ellipse>, <radialGradient>: center y position
- kD,
kFill,
kFillOpacity,
kFillRule,
diff --git a/modules/svg/include/SkSVGPath.h b/modules/svg/include/SkSVGPath.h
index 7723bfd..24f97d4 100644
--- a/modules/svg/include/SkSVGPath.h
+++ b/modules/svg/include/SkSVGPath.h
@@ -15,10 +15,10 @@
public:
static sk_sp<SkSVGPath> Make() { return sk_sp<SkSVGPath>(new SkSVGPath()); }
- void setPath(const SkPath& path) { fPath = path; }
+ SVG_ATTR(Path, SkPath, SkPath())
protected:
- void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
+ bool parseAndSetAttribute(const char*, const char*) override;
void onDraw(SkCanvas*, const SkSVGLengthContext&, const SkPaint&,
SkPathFillType) const override;
@@ -30,8 +30,6 @@
private:
SkSVGPath();
- mutable SkPath fPath; // mutated in onDraw(), to apply inherited fill types.
-
using INHERITED = SkSVGShape;
};
diff --git a/modules/svg/include/SkSVGValue.h b/modules/svg/include/SkSVGValue.h
index 26d7b67..eb1977f 100644
--- a/modules/svg/include/SkSVGValue.h
+++ b/modules/svg/include/SkSVGValue.h
@@ -23,7 +23,6 @@
kLength,
kNumber,
kObjectBoundingBoxUnits,
- kPath,
kPreserveAspectRatio,
kStopColor,
kString,
@@ -71,7 +70,6 @@
using SkSVGColorValue = SkSVGWrapperValue<SkSVGColorType , SkSVGValue::Type::kColor >;
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 SkSVGNumberValue = SkSVGWrapperValue<SkSVGNumberType , SkSVGValue::Type::kNumber >;
diff --git a/modules/svg/src/SkSVGDOM.cpp b/modules/svg/src/SkSVGDOM.cpp
index 12a1918..7915654 100644
--- a/modules/svg/src/SkSVGDOM.cpp
+++ b/modules/svg/src/SkSVGDOM.cpp
@@ -9,7 +9,6 @@
#include "include/core/SkFontMgr.h"
#include "include/core/SkString.h"
#include "include/private/SkTo.h"
-#include "include/utils/SkParsePath.h"
#include "modules/svg/include/SkSVGAttributeParser.h"
#include "modules/svg/include/SkSVGCircle.h"
#include "modules/svg/include/SkSVGClipPath.h"
@@ -62,17 +61,6 @@
return true;
}
-bool SetPathDataAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
- const char* stringValue) {
- SkPath path;
- if (!SkParsePath::FromSVGString(stringValue, &path)) {
- return false;
- }
-
- node->setAttribute(attr, SkSVGPathValue(path));
- return true;
-}
-
bool SetStringAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
const char* stringValue) {
SkString str(stringValue, strlen(stringValue));
@@ -219,7 +207,6 @@
SortedDictionaryEntry<AttrParseInfo> gAttributeParseInfo[] = {
{ "cx" , { SkSVGAttribute::kCx , SetLengthAttribute }},
{ "cy" , { SkSVGAttribute::kCy , SetLengthAttribute }},
- { "d" , { SkSVGAttribute::kD , SetPathDataAttribute }},
{ "filterUnits" , { SkSVGAttribute::kFilterUnits ,
SetObjectBoundingBoxUnitsAttribute }},
// focal point x & y
diff --git a/modules/svg/src/SkSVGPath.cpp b/modules/svg/src/SkSVGPath.cpp
index 256feb8..a250cea 100644
--- a/modules/svg/src/SkSVGPath.cpp
+++ b/modules/svg/src/SkSVGPath.cpp
@@ -7,29 +7,29 @@
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
+#include "include/utils/SkParsePath.h"
#include "modules/svg/include/SkSVGPath.h"
#include "modules/svg/include/SkSVGRenderContext.h"
#include "modules/svg/include/SkSVGValue.h"
SkSVGPath::SkSVGPath() : INHERITED(SkSVGTag::kPath) { }
-void SkSVGPath::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
- switch (attr) {
- case SkSVGAttribute::kD:
- if (const auto* path = v.as<SkSVGPathValue>()) {
- this->setPath(*path);
- }
- break;
- default:
- this->INHERITED::onSetAttribute(attr, v);
- }
+bool SkSVGPath::parseAndSetAttribute(const char* n, const char* v) {
+ return INHERITED::parseAndSetAttribute(n, v) ||
+ this->setPath(SkSVGAttributeParser::parse<SkPath>("d", n, v));
+}
+
+template <>
+bool SkSVGAttributeParser::parse<SkPath>(SkPath* path) {
+ return SkParsePath::FromSVGString(fCurPos, path);
}
void SkSVGPath::onDraw(SkCanvas* canvas, const SkSVGLengthContext&, const SkPaint& paint,
SkPathFillType fillType) const {
// the passed fillType follows inheritance rules and needs to be applied at draw time.
- fPath.setFillType(fillType);
- canvas->drawPath(fPath, paint);
+ SkPath path = fPath; // Note: point and verb data are CoW
+ path.setFillType(fillType);
+ canvas->drawPath(path, paint);
}
SkPath SkSVGPath::onAsPath(const SkSVGRenderContext& ctx) const {