[svg] Refactor <polygon> and <polyline> to use new parsing

Change-Id: I7cc2dcce4a645326dcacadd28cbe1b3ea5f4ae36
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/367877
Commit-Queue: Tyler Denniston <tdenniston@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Tyler Denniston 2021-02-08 15:07:03 -05:00
parent 52d9475b05
commit c683482e58
6 changed files with 17 additions and 33 deletions

View File

@ -20,7 +20,6 @@ public:
bool parseInteger(SkSVGIntegerType*);
bool parseViewBox(SkSVGViewBoxType*);
bool parsePoints(SkSVGPointsType*);
bool parsePreserveAspectRatio(SkSVGPreserveAspectRatio*);
// TODO: Migrate all parse*() functions to this style (and delete the old version)

View File

@ -22,10 +22,10 @@ public:
return sk_sp<SkSVGPoly>(new SkSVGPoly(SkSVGTag::kPolyline));
}
void setPoints(const SkSVGPointsType&);
SVG_ATTR(Points, SkSVGPointsType, SkSVGPointsType())
protected:
void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override;
bool parseAndSetAttribute(const char*, const char*) override;
void onDraw(SkCanvas*, const SkSVGLengthContext&, const SkPaint&,
SkPathFillType) const override;

View File

@ -24,7 +24,6 @@ public:
kNumber,
kObjectBoundingBoxUnits,
kPath,
kPoints,
kPreserveAspectRatio,
kStopColor,
kString,
@ -76,7 +75,6 @@ using SkSVGPathValue = SkSVGWrapperValue<SkPath , SkSVGValue:
using SkSVGTransformValue = SkSVGWrapperValue<SkSVGTransformType, SkSVGValue::Type::kTransform >;
using SkSVGViewBoxValue = SkSVGWrapperValue<SkSVGViewBoxType , SkSVGValue::Type::kViewBox >;
using SkSVGNumberValue = SkSVGWrapperValue<SkSVGNumberType , SkSVGValue::Type::kNumber >;
using SkSVGPointsValue = SkSVGWrapperValue<SkSVGPointsType , SkSVGValue::Type::kPoints >;
using SkSVGStringValue = SkSVGWrapperValue<SkSVGStringType , SkSVGValue::Type::kString >;
using SkSVGStopColorValue = SkSVGWrapperValue<SkSVGStopColor , SkSVGValue::Type::kStopColor >;

View File

@ -640,7 +640,8 @@ bool SkSVGAttributeParser::parse(SkSVGObjectBoundingBoxUnits* objectBoundingBoxU
}
// https://www.w3.org/TR/SVG11/shapes.html#PolygonElementPointsAttribute
bool SkSVGAttributeParser::parsePoints(SkSVGPointsType* points) {
template <>
bool SkSVGAttributeParser::parse(SkSVGPointsType* points) {
SkTDArray<SkPoint> pts;
// Skip initial wsp.

View File

@ -127,18 +127,6 @@ bool SetObjectBoundingBoxUnitsAttribute(const sk_sp<SkSVGNode>& node,
return true;
}
bool SetPointsAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
const char* stringValue) {
SkSVGPointsType points;
SkSVGAttributeParser parser(stringValue);
if (!parser.parsePoints(&points)) {
return false;
}
node->setAttribute(attr, SkSVGPointsValue(points));
return true;
}
bool SetPreserveAspectRatioAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
const char* stringValue) {
SkSVGPreserveAspectRatio par;
@ -240,7 +228,6 @@ SortedDictionaryEntry<AttrParseInfo> gAttributeParseInfo[] = {
{ "height" , { SkSVGAttribute::kHeight , SetLengthAttribute }},
{ "offset" , { SkSVGAttribute::kOffset , SetLengthAttribute }},
{ "patternTransform" , { SkSVGAttribute::kPatternTransform , SetTransformAttribute }},
{ "points" , { SkSVGAttribute::kPoints , SetPointsAttribute }},
{ "preserveAspectRatio", { SkSVGAttribute::kPreserveAspectRatio,
SetPreserveAspectRatioAttribute }},
{ "r" , { SkSVGAttribute::kR , SetLengthAttribute }},

View File

@ -13,21 +13,20 @@
SkSVGPoly::SkSVGPoly(SkSVGTag t) : INHERITED(t) {}
void SkSVGPoly::setPoints(const SkSVGPointsType& pts) {
fPath = SkPath::Polygon(pts.begin(), pts.count(),
this->tag() == SkSVGTag::kPolygon); // only polygons are auto-closed
}
void SkSVGPoly::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
switch (attr) {
case SkSVGAttribute::kPoints:
if (const auto* pts = v.as<SkSVGPointsValue>()) {
this->setPoints(*pts);
}
break;
default:
this->INHERITED::onSetAttribute(attr, v);
bool SkSVGPoly::parseAndSetAttribute(const char* n, const char* v) {
if (INHERITED::parseAndSetAttribute(n, v)) {
return true;
}
if (this->setPoints(SkSVGAttributeParser::parse<SkSVGPointsType>("points", n, v))) {
// TODO: we can likely just keep the points array and create the SkPath when needed.
fPath = SkPath::Polygon(
fPoints.begin(), fPoints.count(),
this->tag() == SkSVGTag::kPolygon); // only polygons are auto-closed
}
// No other attributes on this node
return false;
}
void SkSVGPoly::onDraw(SkCanvas* canvas, const SkSVGLengthContext&, const SkPaint& paint,