From c505e435d44ae3dbcd95809389818f388d2ab6f1 Mon Sep 17 00:00:00 2001 From: Tyler Denniston Date: Mon, 8 Feb 2021 13:58:44 -0500 Subject: [PATCH] [svg] Refactor to use new parsing Change-Id: Ib33111e1b00f05d32f8c6add512c38b5a6197af8 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/367884 Reviewed-by: Florin Malita Commit-Queue: Tyler Denniston --- modules/svg/include/SkSVGAttribute.h | 1 - modules/svg/include/SkSVGPath.h | 6 ++---- modules/svg/include/SkSVGValue.h | 2 -- modules/svg/src/SkSVGDOM.cpp | 13 ------------- modules/svg/src/SkSVGPath.cpp | 24 ++++++++++++------------ 5 files changed, 14 insertions(+), 32 deletions(-) diff --git a/modules/svg/include/SkSVGAttribute.h b/modules/svg/include/SkSVGAttribute.h index eb2f382a13..c27bce6907 100644 --- a/modules/svg/include/SkSVGAttribute.h +++ b/modules/svg/include/SkSVGAttribute.h @@ -20,7 +20,6 @@ enum class SkSVGAttribute { kColorInterpolationFilters, kCx, // , , : center x position kCy, // , , : center y position - kD, kFill, kFillOpacity, kFillRule, diff --git a/modules/svg/include/SkSVGPath.h b/modules/svg/include/SkSVGPath.h index 7723bfdbab..24f97d4de4 100644 --- a/modules/svg/include/SkSVGPath.h +++ b/modules/svg/include/SkSVGPath.h @@ -15,10 +15,10 @@ class SkSVGPath final : public SkSVGShape { public: static sk_sp Make() { return sk_sp(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 @@ protected: 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 26d7b67705..eb1977feb3 100644 --- a/modules/svg/include/SkSVGValue.h +++ b/modules/svg/include/SkSVGValue.h @@ -23,7 +23,6 @@ public: kLength, kNumber, kObjectBoundingBoxUnits, - kPath, kPreserveAspectRatio, kStopColor, kString, @@ -71,7 +70,6 @@ private: using SkSVGColorValue = SkSVGWrapperValue; using SkSVGLengthValue = SkSVGWrapperValue; -using SkSVGPathValue = SkSVGWrapperValue; using SkSVGTransformValue = SkSVGWrapperValue; using SkSVGViewBoxValue = SkSVGWrapperValue; using SkSVGNumberValue = SkSVGWrapperValue; diff --git a/modules/svg/src/SkSVGDOM.cpp b/modules/svg/src/SkSVGDOM.cpp index 12a1918d0d..7915654963 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 @@ bool SetIRIAttribute(const sk_sp& node, SkSVGAttribute attr, return true; } -bool SetPathDataAttribute(const sk_sp& 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& node, SkSVGAttribute attr, const char* stringValue) { SkString str(stringValue, strlen(stringValue)); @@ -219,7 +207,6 @@ struct AttrParseInfo { SortedDictionaryEntry 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 256feb8997..a250ceaf68 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()) { - 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("d", n, v)); +} + +template <> +bool SkSVGAttributeParser::parse(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 {