[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/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 {