[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>
This commit is contained in:
Tyler Denniston 2021-02-08 13:58:44 -05:00 committed by Skia Commit-Bot
parent 54f0049ddc
commit c505e435d4
5 changed files with 14 additions and 32 deletions

View File

@ -20,7 +20,6 @@ enum class SkSVGAttribute {
kColorInterpolationFilters,
kCx, // <circle>, <ellipse>, <radialGradient>: center x position
kCy, // <circle>, <ellipse>, <radialGradient>: center y position
kD,
kFill,
kFillOpacity,
kFillRule,

View File

@ -15,10 +15,10 @@ class SkSVGPath final : public SkSVGShape {
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 @@ protected:
private:
SkSVGPath();
mutable SkPath fPath; // mutated in onDraw(), to apply inherited fill types.
using INHERITED = SkSVGShape;
};

View File

@ -23,7 +23,6 @@ public:
kLength,
kNumber,
kObjectBoundingBoxUnits,
kPath,
kPreserveAspectRatio,
kStopColor,
kString,
@ -71,7 +70,6 @@ private:
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 >;

View File

@ -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<SkSVGNode>& node, SkSVGAttribute attr,
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 @@ struct AttrParseInfo {
SortedDictionaryEntry<AttrParseInfo> gAttributeParseInfo[] = {
{ "cx" , { SkSVGAttribute::kCx , SetLengthAttribute }},
{ "cy" , { SkSVGAttribute::kCy , SetLengthAttribute }},
{ "d" , { SkSVGAttribute::kD , SetPathDataAttribute }},
{ "filterUnits" , { SkSVGAttribute::kFilterUnits ,
SetObjectBoundingBoxUnitsAttribute }},
// focal point x & y

View File

@ -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 {