[svg] Convert most presentation attributes to new style parsing
Change-Id: Ib430ce05f7e336ae82a51ee45194338e90d77c58 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/332751 Commit-Queue: Florin Malita <fmalita@chromium.org> Commit-Queue: Florin Malita <fmalita@google.com> Reviewed-by: Tyler Denniston <tdenniston@google.com>
This commit is contained in:
parent
b06301ee12
commit
8c42567377
@ -14,7 +14,6 @@
|
||||
class SkSVGRenderContext;
|
||||
|
||||
enum class SkSVGAttribute {
|
||||
kClipPath,
|
||||
kClipRule,
|
||||
kColor,
|
||||
kCx, // <circle>, <ellipse>, <radialGradient>: center x position
|
||||
|
@ -17,32 +17,19 @@ public:
|
||||
SkSVGAttributeParser(const char[]);
|
||||
|
||||
bool parseColor(SkSVGColorType*);
|
||||
bool parseClipPath(SkSVGClip*);
|
||||
bool parseFillRule(SkSVGFillRule*);
|
||||
bool parseFilter(SkSVGFilterType*);
|
||||
bool parseNumber(SkSVGNumberType*);
|
||||
bool parseInteger(SkSVGIntegerType*);
|
||||
bool parseLength(SkSVGLength*);
|
||||
bool parseViewBox(SkSVGViewBoxType*);
|
||||
bool parseTransform(SkSVGTransformType*);
|
||||
bool parsePaint(SkSVGPaint*);
|
||||
bool parseLineCap(SkSVGLineCap*);
|
||||
bool parseLineJoin(SkSVGLineJoin*);
|
||||
bool parsePoints(SkSVGPointsType*);
|
||||
bool parseIRI(SkSVGStringType*);
|
||||
bool parseSpreadMethod(SkSVGSpreadMethod*);
|
||||
bool parseStopColor(SkSVGStopColor*);
|
||||
bool parseObjectBoundingBoxUnits(SkSVGObjectBoundingBoxUnits*);
|
||||
bool parseVisibility(SkSVGVisibility*);
|
||||
bool parseDashArray(SkSVGDashArray*);
|
||||
bool parsePreserveAspectRatio(SkSVGPreserveAspectRatio*);
|
||||
|
||||
bool parseFontFamily(SkSVGFontFamily*);
|
||||
bool parseFontSize(SkSVGFontSize*);
|
||||
bool parseFontStyle(SkSVGFontStyle*);
|
||||
bool parseFontWeight(SkSVGFontWeight*);
|
||||
bool parseTextAnchor(SkSVGTextAnchor*);
|
||||
|
||||
// TODO: Migrate all parse*() functions to this style (and delete the old version)
|
||||
// so they can be used by parse<T>():
|
||||
bool parse(SkSVGNumberType* v) { return parseNumber(v); }
|
||||
|
@ -43,27 +43,33 @@ enum class SkSVGTag {
|
||||
kUse
|
||||
};
|
||||
|
||||
#define SVG_PRES_ATTR(attr_name, attr_type, attr_inherited) \
|
||||
const attr_type* get##attr_name() const { \
|
||||
return fPresentationAttributes.f##attr_name.getMaybeNull(); \
|
||||
} \
|
||||
void set##attr_name(const attr_type& v) { \
|
||||
if (!attr_inherited || v.type() != attr_type::Type::kInherit) { \
|
||||
fPresentationAttributes.f##attr_name.set(v); \
|
||||
} else { \
|
||||
/* kInherited values are semantically equivalent to \
|
||||
the absence of a local presentation attribute.*/ \
|
||||
fPresentationAttributes.f##attr_name.reset(); \
|
||||
} \
|
||||
} \
|
||||
void set##attr_name(attr_type&& v) { \
|
||||
if (!attr_inherited || v.type() != attr_type::Type::kInherit) { \
|
||||
fPresentationAttributes.f##attr_name.set(std::move(v)); \
|
||||
} else { \
|
||||
/* kInherited values are semantically equivalent to \
|
||||
the absence of a local presentation attribute.*/ \
|
||||
fPresentationAttributes.f##attr_name.reset(); \
|
||||
} \
|
||||
#define SVG_PRES_ATTR(attr_name, attr_type, attr_inherited) \
|
||||
private: \
|
||||
bool set##attr_name(SkSVGAttributeParser::ParseResult<attr_type>&& pr) { \
|
||||
if (pr.isValid()) { this->set##attr_name(std::move(*pr)); } \
|
||||
return pr.isValid(); \
|
||||
} \
|
||||
public: \
|
||||
const attr_type* get##attr_name() const { \
|
||||
return fPresentationAttributes.f##attr_name.getMaybeNull(); \
|
||||
} \
|
||||
void set##attr_name(const attr_type& v) { \
|
||||
if (!attr_inherited || v.type() != attr_type::Type::kInherit) { \
|
||||
fPresentationAttributes.f##attr_name.set(v); \
|
||||
} else { \
|
||||
/* kInherited values are semantically equivalent to \
|
||||
the absence of a local presentation attribute.*/ \
|
||||
fPresentationAttributes.f##attr_name.reset(); \
|
||||
} \
|
||||
} \
|
||||
void set##attr_name(attr_type&& v) { \
|
||||
if (!attr_inherited || v.type() != attr_type::Type::kInherit) { \
|
||||
fPresentationAttributes.f##attr_name.set(std::move(v)); \
|
||||
} else { \
|
||||
/* kInherited values are semantically equivalent to \
|
||||
the absence of a local presentation attribute.*/ \
|
||||
fPresentationAttributes.f##attr_name.reset(); \
|
||||
} \
|
||||
}
|
||||
|
||||
class SkSVGNode : public SkRefCnt {
|
||||
@ -85,29 +91,32 @@ public:
|
||||
// TODO: consolidate with existing setAttribute
|
||||
virtual bool parseAndSetAttribute(const char* name, const char* value);
|
||||
|
||||
void setClipPath(const SkSVGClip&);
|
||||
void setClipRule(const SkSVGFillRule&);
|
||||
void setColor(const SkSVGColorType&);
|
||||
void setFill(const SkSVGPaint&);
|
||||
void setFillOpacity(const SkSVGNumberType&);
|
||||
void setFillRule(const SkSVGFillRule&);
|
||||
void setOpacity(const SkSVGNumberType&);
|
||||
void setStroke(const SkSVGPaint&);
|
||||
void setStrokeDashArray(const SkSVGDashArray&);
|
||||
void setStrokeDashOffset(const SkSVGLength&);
|
||||
void setStrokeOpacity(const SkSVGNumberType&);
|
||||
void setStrokeLineCap(const SkSVGLineCap&);
|
||||
void setStrokeLineJoin(const SkSVGLineJoin&);
|
||||
void setStrokeMiterLimit(const SkSVGNumberType&);
|
||||
void setStrokeWidth(const SkSVGLength&);
|
||||
void setVisibility(const SkSVGVisibility&);
|
||||
|
||||
SVG_PRES_ATTR(FontFamily, SkSVGFontFamily, true)
|
||||
SVG_PRES_ATTR(FontStyle , SkSVGFontStyle , true)
|
||||
SVG_PRES_ATTR(FontSize , SkSVGFontSize , true)
|
||||
SVG_PRES_ATTR(FontWeight, SkSVGFontWeight, true)
|
||||
SVG_PRES_ATTR(TextAnchor, SkSVGTextAnchor, true)
|
||||
SVG_PRES_ATTR(Filter , SkSVGFilterType, false)
|
||||
// inherited
|
||||
SVG_PRES_ATTR(ClipRule , SkSVGFillRule , true)
|
||||
SVG_PRES_ATTR(FillRule , SkSVGFillRule , true)
|
||||
SVG_PRES_ATTR(Fill , SkSVGPaint , true)
|
||||
SVG_PRES_ATTR(FontFamily , SkSVGFontFamily, true)
|
||||
SVG_PRES_ATTR(FontSize , SkSVGFontSize , true)
|
||||
SVG_PRES_ATTR(FontStyle , SkSVGFontStyle , true)
|
||||
SVG_PRES_ATTR(FontWeight , SkSVGFontWeight, true)
|
||||
SVG_PRES_ATTR(Stroke , SkSVGPaint , true)
|
||||
SVG_PRES_ATTR(StrokeDashArray, SkSVGDashArray , true)
|
||||
SVG_PRES_ATTR(StrokeLineCap , SkSVGLineCap , true)
|
||||
SVG_PRES_ATTR(StrokeLineJoin , SkSVGLineJoin , true)
|
||||
SVG_PRES_ATTR(TextAnchor , SkSVGTextAnchor, true)
|
||||
SVG_PRES_ATTR(Visibility , SkSVGVisibility, true)
|
||||
|
||||
// not inherited
|
||||
SVG_PRES_ATTR(ClipPath , SkSVGClip , false)
|
||||
SVG_PRES_ATTR(Filter , SkSVGFilterType, false)
|
||||
|
||||
protected:
|
||||
SkSVGNode(SkSVGTag);
|
||||
|
@ -18,31 +18,19 @@
|
||||
class SkSVGValue : public SkNoncopyable {
|
||||
public:
|
||||
enum class Type {
|
||||
kClip,
|
||||
kColor,
|
||||
kDashArray,
|
||||
kFillRule,
|
||||
kFilter,
|
||||
kFontFamily,
|
||||
kFontSize,
|
||||
kFontStyle,
|
||||
kFontWeight,
|
||||
kLength,
|
||||
kLineCap,
|
||||
kLineJoin,
|
||||
kNumber,
|
||||
kObjectBoundingBoxUnits,
|
||||
kPaint,
|
||||
kPath,
|
||||
kPoints,
|
||||
kPreserveAspectRatio,
|
||||
kSpreadMethod,
|
||||
kStopColor,
|
||||
kString,
|
||||
kTextAnchor,
|
||||
kTransform,
|
||||
kViewBox,
|
||||
kVisibility,
|
||||
};
|
||||
|
||||
Type type() const { return fType; }
|
||||
@ -83,31 +71,18 @@ private:
|
||||
using INHERITED = SkSVGValue;
|
||||
};
|
||||
|
||||
using SkSVGClipValue = SkSVGWrapperValue<SkSVGClip , SkSVGValue::Type::kClip >;
|
||||
using SkSVGColorValue = SkSVGWrapperValue<SkSVGColorType , SkSVGValue::Type::kColor >;
|
||||
using SkSVGFillRuleValue = SkSVGWrapperValue<SkSVGFillRule , SkSVGValue::Type::kFillRule >;
|
||||
using SkSVGFilterValue = SkSVGWrapperValue<SkSVGFilterType , SkSVGValue::Type::kFilter >;
|
||||
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 SkSVGPaintValue = SkSVGWrapperValue<SkSVGPaint , SkSVGValue::Type::kPaint >;
|
||||
using SkSVGLineCapValue = SkSVGWrapperValue<SkSVGLineCap , SkSVGValue::Type::kLineCap >;
|
||||
using SkSVGLineJoinValue = SkSVGWrapperValue<SkSVGLineJoin , SkSVGValue::Type::kLineJoin >;
|
||||
using SkSVGNumberValue = SkSVGWrapperValue<SkSVGNumberType , SkSVGValue::Type::kNumber >;
|
||||
using SkSVGPointsValue = SkSVGWrapperValue<SkSVGPointsType , SkSVGValue::Type::kPoints >;
|
||||
using SkSVGStringValue = SkSVGWrapperValue<SkSVGStringType , SkSVGValue::Type::kString >;
|
||||
using SkSVGSpreadMethodValue = SkSVGWrapperValue<SkSVGSpreadMethod ,
|
||||
SkSVGValue::Type::kSpreadMethod>;
|
||||
using SkSVGStopColorValue = SkSVGWrapperValue<SkSVGStopColor , SkSVGValue::Type::kStopColor >;
|
||||
using SkSVGVisibilityValue = SkSVGWrapperValue<SkSVGVisibility , SkSVGValue::Type::kVisibility>;
|
||||
using SkSVGDashArrayValue = SkSVGWrapperValue<SkSVGDashArray , SkSVGValue::Type::kDashArray >;
|
||||
|
||||
using SkSVGFontFamilyValue = SkSVGWrapperValue<SkSVGFontFamily , SkSVGValue::Type::kFontFamily>;
|
||||
using SkSVGFontSizeValue = SkSVGWrapperValue<SkSVGFontSize , SkSVGValue::Type::kFontSize >;
|
||||
using SkSVGFontStyleValue = SkSVGWrapperValue<SkSVGFontStyle , SkSVGValue::Type::kFontStyle >;
|
||||
using SkSVGFontWeightValue = SkSVGWrapperValue<SkSVGFontWeight , SkSVGValue::Type::kFontWeight>;
|
||||
using SkSVGTextAnchorValue = SkSVGWrapperValue<SkSVGTextAnchor , SkSVGValue::Type::kTextAnchor>;
|
||||
|
||||
using SkSVGPreserveAspectRatioValue = SkSVGWrapperValue<SkSVGPreserveAspectRatio,
|
||||
SkSVGValue::Type::kPreserveAspectRatio>;
|
||||
|
@ -483,7 +483,8 @@ bool SkSVGAttributeParser::parseTransform(SkSVGTransformType* t) {
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/SVG11/painting.html#SpecifyingPaint
|
||||
bool SkSVGAttributeParser::parsePaint(SkSVGPaint* paint) {
|
||||
template <>
|
||||
bool SkSVGAttributeParser::parse(SkSVGPaint* paint) {
|
||||
SkSVGColorType c;
|
||||
SkSVGStringType iri;
|
||||
bool parsedValue = false;
|
||||
@ -507,7 +508,8 @@ bool SkSVGAttributeParser::parsePaint(SkSVGPaint* paint) {
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/SVG11/masking.html#ClipPathProperty
|
||||
bool SkSVGAttributeParser::parseClipPath(SkSVGClip* clip) {
|
||||
template <>
|
||||
bool SkSVGAttributeParser::parse(SkSVGClip* clip) {
|
||||
SkSVGStringType iri;
|
||||
bool parsedValue = false;
|
||||
|
||||
@ -526,7 +528,8 @@ bool SkSVGAttributeParser::parseClipPath(SkSVGClip* clip) {
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/SVG11/painting.html#StrokeLinecapProperty
|
||||
bool SkSVGAttributeParser::parseLineCap(SkSVGLineCap* cap) {
|
||||
template <>
|
||||
bool SkSVGAttributeParser::parse(SkSVGLineCap* cap) {
|
||||
static const struct {
|
||||
SkSVGLineCap::Type fType;
|
||||
const char* fName;
|
||||
@ -550,7 +553,8 @@ bool SkSVGAttributeParser::parseLineCap(SkSVGLineCap* cap) {
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/SVG11/painting.html#StrokeLinejoinProperty
|
||||
bool SkSVGAttributeParser::parseLineJoin(SkSVGLineJoin* join) {
|
||||
template <>
|
||||
bool SkSVGAttributeParser::parse(SkSVGLineJoin* join) {
|
||||
static const struct {
|
||||
SkSVGLineJoin::Type fType;
|
||||
const char* fName;
|
||||
@ -678,7 +682,8 @@ bool SkSVGAttributeParser::parsePoints(SkSVGPointsType* points) {
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/SVG11/painting.html#FillRuleProperty
|
||||
bool SkSVGAttributeParser::parseFillRule(SkSVGFillRule* fillRule) {
|
||||
template <>
|
||||
bool SkSVGAttributeParser::parse(SkSVGFillRule* fillRule) {
|
||||
static const struct {
|
||||
SkSVGFillRule::Type fType;
|
||||
const char* fName;
|
||||
@ -720,7 +725,8 @@ bool SkSVGAttributeParser::parseFilter(SkSVGFilterType* filter) {
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/SVG11/painting.html#VisibilityProperty
|
||||
bool SkSVGAttributeParser::parseVisibility(SkSVGVisibility* visibility) {
|
||||
template <>
|
||||
bool SkSVGAttributeParser::parse(SkSVGVisibility* visibility) {
|
||||
static const struct {
|
||||
SkSVGVisibility::Type fType;
|
||||
const char* fName;
|
||||
@ -744,7 +750,8 @@ bool SkSVGAttributeParser::parseVisibility(SkSVGVisibility* visibility) {
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/SVG11/painting.html#StrokeDasharrayProperty
|
||||
bool SkSVGAttributeParser::parseDashArray(SkSVGDashArray* dashArray) {
|
||||
template <>
|
||||
bool SkSVGAttributeParser::parse(SkSVGDashArray* dashArray) {
|
||||
bool parsedValue = false;
|
||||
if (this->parseExpectedStringToken("none")) {
|
||||
*dashArray = SkSVGDashArray(SkSVGDashArray::Type::kNone);
|
||||
@ -774,7 +781,8 @@ bool SkSVGAttributeParser::parseDashArray(SkSVGDashArray* dashArray) {
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/SVG11/text.html#FontFamilyProperty
|
||||
bool SkSVGAttributeParser::parseFontFamily(SkSVGFontFamily* family) {
|
||||
template <>
|
||||
bool SkSVGAttributeParser::parse(SkSVGFontFamily* family) {
|
||||
bool parsedValue = false;
|
||||
if (this->parseExpectedStringToken("inherit")) {
|
||||
*family = SkSVGFontFamily();
|
||||
@ -794,7 +802,8 @@ bool SkSVGAttributeParser::parseFontFamily(SkSVGFontFamily* family) {
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/SVG11/text.html#FontSizeProperty
|
||||
bool SkSVGAttributeParser::parseFontSize(SkSVGFontSize* size) {
|
||||
template <>
|
||||
bool SkSVGAttributeParser::parse(SkSVGFontSize* size) {
|
||||
bool parsedValue = false;
|
||||
if (this->parseExpectedStringToken("inherit")) {
|
||||
*size = SkSVGFontSize();
|
||||
@ -811,7 +820,8 @@ bool SkSVGAttributeParser::parseFontSize(SkSVGFontSize* size) {
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/SVG11/text.html#FontStyleProperty
|
||||
bool SkSVGAttributeParser::parseFontStyle(SkSVGFontStyle* style) {
|
||||
template <>
|
||||
bool SkSVGAttributeParser::parse(SkSVGFontStyle* style) {
|
||||
static constexpr std::tuple<const char*, SkSVGFontStyle::Type> gStyleMap[] = {
|
||||
{ "normal" , SkSVGFontStyle::Type::kNormal },
|
||||
{ "italic" , SkSVGFontStyle::Type::kItalic },
|
||||
@ -831,7 +841,8 @@ bool SkSVGAttributeParser::parseFontStyle(SkSVGFontStyle* style) {
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/SVG11/text.html#FontWeightProperty
|
||||
bool SkSVGAttributeParser::parseFontWeight(SkSVGFontWeight* weight) {
|
||||
template <>
|
||||
bool SkSVGAttributeParser::parse(SkSVGFontWeight* weight) {
|
||||
static constexpr std::tuple<const char*, SkSVGFontWeight::Type> gWeightMap[] = {
|
||||
{ "normal" , SkSVGFontWeight::Type::kNormal },
|
||||
{ "bold" , SkSVGFontWeight::Type::kBold },
|
||||
@ -861,7 +872,8 @@ bool SkSVGAttributeParser::parseFontWeight(SkSVGFontWeight* weight) {
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/SVG11/text.html#TextAnchorProperty
|
||||
bool SkSVGAttributeParser::parseTextAnchor(SkSVGTextAnchor* anchor) {
|
||||
template <>
|
||||
bool SkSVGAttributeParser::parse(SkSVGTextAnchor* anchor) {
|
||||
static constexpr std::tuple<const char*, SkSVGTextAnchor::Type> gAnchorMap[] = {
|
||||
{ "start" , SkSVGTextAnchor::Type::kStart },
|
||||
{ "middle" , SkSVGTextAnchor::Type::kMiddle },
|
||||
|
@ -39,18 +39,6 @@
|
||||
|
||||
namespace {
|
||||
|
||||
bool SetPaintAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
const char* stringValue) {
|
||||
SkSVGPaint paint;
|
||||
SkSVGAttributeParser parser(stringValue);
|
||||
if (!parser.parsePaint(&paint)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
node->setAttribute(attr, SkSVGPaintValue(paint));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetColorAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
const char* stringValue) {
|
||||
SkSVGColorType color;
|
||||
@ -75,19 +63,6 @@ bool SetIRIAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetClipPathAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
const char* stringValue) {
|
||||
SkSVGClip clip;
|
||||
SkSVGAttributeParser parser(stringValue);
|
||||
if (!parser.parseClipPath(&clip)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
node->setAttribute(attr, SkSVGClipValue(clip));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool SetPathDataAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
const char* stringValue) {
|
||||
SkPath path;
|
||||
@ -155,30 +130,6 @@ bool SetViewBoxAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetLineCapAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
const char* stringValue) {
|
||||
SkSVGLineCap lineCap;
|
||||
SkSVGAttributeParser parser(stringValue);
|
||||
if (!parser.parseLineCap(&lineCap)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
node->setAttribute(attr, SkSVGLineCapValue(lineCap));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetLineJoinAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
const char* stringValue) {
|
||||
SkSVGLineJoin lineJoin;
|
||||
SkSVGAttributeParser parser(stringValue);
|
||||
if (!parser.parseLineJoin(&lineJoin)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
node->setAttribute(attr, SkSVGLineJoinValue(lineJoin));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetSpreadMethodAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
const char* stringValue) {
|
||||
SkSVGSpreadMethod spread;
|
||||
@ -228,18 +179,6 @@ bool SetPointsAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetFillRuleAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
const char* stringValue) {
|
||||
SkSVGFillRule fillRule;
|
||||
SkSVGAttributeParser parser(stringValue);
|
||||
if (!parser.parseFillRule(&fillRule)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
node->setAttribute(attr, SkSVGFillRuleValue(fillRule));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetFilterAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
const char* stringValue) {
|
||||
SkSVGFilterType filter;
|
||||
@ -252,91 +191,6 @@ bool SetFilterAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetVisibilityAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
const char* stringValue) {
|
||||
SkSVGVisibility visibility;
|
||||
SkSVGAttributeParser parser(stringValue);
|
||||
if (!parser.parseVisibility(&visibility)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
node->setAttribute(attr, SkSVGVisibilityValue(visibility));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetDashArrayAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
const char* stringValue) {
|
||||
SkSVGDashArray dashArray;
|
||||
SkSVGAttributeParser parser(stringValue);
|
||||
if (!parser.parseDashArray(&dashArray)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
node->setAttribute(attr, SkSVGDashArrayValue(dashArray));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetFontFamilyAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
const char* stringValue) {
|
||||
SkSVGFontFamily family;
|
||||
SkSVGAttributeParser parser(stringValue);
|
||||
if (!parser.parseFontFamily(&family)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
node->setAttribute(attr, SkSVGFontFamilyValue(family));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetFontSizeAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
const char* stringValue) {
|
||||
SkSVGFontSize size;
|
||||
SkSVGAttributeParser parser(stringValue);
|
||||
if (!parser.parseFontSize(&size)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
node->setAttribute(attr, SkSVGFontSizeValue(size));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetFontStyleAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
const char* stringValue) {
|
||||
SkSVGFontStyle style;
|
||||
SkSVGAttributeParser parser(stringValue);
|
||||
if (!parser.parseFontStyle(&style)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
node->setAttribute(attr, SkSVGFontStyleValue(style));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetFontWeightAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
const char* stringValue) {
|
||||
SkSVGFontWeight weight;
|
||||
SkSVGAttributeParser parser(stringValue);
|
||||
if (!parser.parseFontWeight(&weight)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
node->setAttribute(attr, SkSVGFontWeightValue(weight));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetTextAnchorAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
const char* stringValue) {
|
||||
SkSVGTextAnchor anchor;
|
||||
SkSVGAttributeParser parser(stringValue);
|
||||
|
||||
if (!parser.parseTextAnchor(&anchor)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
node->setAttribute(attr, SkSVGTextAnchorValue(anchor));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SetPreserveAspectRatioAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr,
|
||||
const char* stringValue) {
|
||||
SkSVGPreserveAspectRatio par;
|
||||
@ -427,22 +281,14 @@ struct AttrParseInfo {
|
||||
};
|
||||
|
||||
SortedDictionaryEntry<AttrParseInfo> gAttributeParseInfo[] = {
|
||||
{ "clip-path" , { SkSVGAttribute::kClipPath , SetClipPathAttribute }},
|
||||
{ "clip-rule" , { SkSVGAttribute::kClipRule , SetFillRuleAttribute }},
|
||||
{ "color" , { SkSVGAttribute::kColor , SetColorAttribute }},
|
||||
{ "cx" , { SkSVGAttribute::kCx , SetLengthAttribute }},
|
||||
{ "cy" , { SkSVGAttribute::kCy , SetLengthAttribute }},
|
||||
{ "d" , { SkSVGAttribute::kD , SetPathDataAttribute }},
|
||||
{ "fill" , { SkSVGAttribute::kFill , SetPaintAttribute }},
|
||||
{ "fill-opacity" , { SkSVGAttribute::kFillOpacity , SetNumberAttribute }},
|
||||
{ "fill-rule" , { SkSVGAttribute::kFillRule , SetFillRuleAttribute }},
|
||||
{ "filter" , { SkSVGAttribute::kFilter , SetFilterAttribute }},
|
||||
{ "filterUnits" , { SkSVGAttribute::kFilterUnits ,
|
||||
SetObjectBoundingBoxUnitsAttribute }},
|
||||
{ "font-family" , { SkSVGAttribute::kFontFamily , SetFontFamilyAttribute }},
|
||||
{ "font-size" , { SkSVGAttribute::kFontSize , SetFontSizeAttribute }},
|
||||
{ "font-style" , { SkSVGAttribute::kFontStyle , SetFontStyleAttribute }},
|
||||
{ "font-weight" , { SkSVGAttribute::kFontWeight , SetFontWeightAttribute }},
|
||||
// focal point x & y
|
||||
{ "fx" , { SkSVGAttribute::kFx , SetLengthAttribute }},
|
||||
{ "fy" , { SkSVGAttribute::kFy , SetLengthAttribute }},
|
||||
@ -462,20 +308,14 @@ SortedDictionaryEntry<AttrParseInfo> gAttributeParseInfo[] = {
|
||||
{ "spreadMethod" , { SkSVGAttribute::kSpreadMethod , SetSpreadMethodAttribute }},
|
||||
{ "stop-color" , { SkSVGAttribute::kStopColor , SetStopColorAttribute }},
|
||||
{ "stop-opacity" , { SkSVGAttribute::kStopOpacity , SetNumberAttribute }},
|
||||
{ "stroke" , { SkSVGAttribute::kStroke , SetPaintAttribute }},
|
||||
{ "stroke-dasharray" , { SkSVGAttribute::kStrokeDashArray , SetDashArrayAttribute }},
|
||||
{ "stroke-dashoffset" , { SkSVGAttribute::kStrokeDashOffset , SetLengthAttribute }},
|
||||
{ "stroke-linecap" , { SkSVGAttribute::kStrokeLineCap , SetLineCapAttribute }},
|
||||
{ "stroke-linejoin" , { SkSVGAttribute::kStrokeLineJoin , SetLineJoinAttribute }},
|
||||
{ "stroke-miterlimit" , { SkSVGAttribute::kStrokeMiterLimit , SetNumberAttribute }},
|
||||
{ "stroke-opacity" , { SkSVGAttribute::kStrokeOpacity , SetNumberAttribute }},
|
||||
{ "stroke-width" , { SkSVGAttribute::kStrokeWidth , SetLengthAttribute }},
|
||||
{ "style" , { SkSVGAttribute::kUnknown , SetStyleAttributes }},
|
||||
{ "text" , { SkSVGAttribute::kText , SetStringAttribute }},
|
||||
{ "text-anchor" , { SkSVGAttribute::kTextAnchor , SetTextAnchorAttribute }},
|
||||
{ "transform" , { SkSVGAttribute::kTransform , SetTransformAttribute }},
|
||||
{ "viewBox" , { SkSVGAttribute::kViewBox , SetViewBoxAttribute }},
|
||||
{ "visibility" , { SkSVGAttribute::kVisibility , SetVisibilityAttribute }},
|
||||
{ "width" , { SkSVGAttribute::kWidth , SetLengthAttribute }},
|
||||
{ "x" , { SkSVGAttribute::kX , SetLengthAttribute }},
|
||||
{ "x1" , { SkSVGAttribute::kX1 , SetLengthAttribute }},
|
||||
|
@ -65,10 +65,6 @@ void SkSVGNode::setAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
|
||||
this->onSetAttribute(attr, v);
|
||||
}
|
||||
|
||||
void SkSVGNode::setClipPath(const SkSVGClip& clip) {
|
||||
fPresentationAttributes.fClipPath.set(clip);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void SetInheritedByDefault(SkTLazy<T>& presentation_attribute, const T& value) {
|
||||
if (value.type() != T::Type::kInherit) {
|
||||
@ -80,39 +76,19 @@ void SetInheritedByDefault(SkTLazy<T>& presentation_attribute, const T& value) {
|
||||
}
|
||||
}
|
||||
|
||||
void SkSVGNode::setClipRule(const SkSVGFillRule& clipRule) {
|
||||
SetInheritedByDefault(fPresentationAttributes.fClipRule, clipRule);
|
||||
}
|
||||
|
||||
void SkSVGNode::setColor(const SkSVGColorType& color) {
|
||||
// TODO: Color should be inherited by default
|
||||
fPresentationAttributes.fColor.set(color);
|
||||
}
|
||||
|
||||
void SkSVGNode::setFill(const SkSVGPaint& svgPaint) {
|
||||
SetInheritedByDefault(fPresentationAttributes.fFill, svgPaint);
|
||||
}
|
||||
|
||||
void SkSVGNode::setFillOpacity(const SkSVGNumberType& opacity) {
|
||||
fPresentationAttributes.fFillOpacity.set(SkSVGNumberType(SkTPin<SkScalar>(opacity, 0, 1)));
|
||||
}
|
||||
|
||||
void SkSVGNode::setFillRule(const SkSVGFillRule& fillRule) {
|
||||
SetInheritedByDefault(fPresentationAttributes.fFillRule, fillRule);
|
||||
}
|
||||
|
||||
void SkSVGNode::setOpacity(const SkSVGNumberType& opacity) {
|
||||
fPresentationAttributes.fOpacity.set(SkSVGNumberType(SkTPin<SkScalar>(opacity, 0, 1)));
|
||||
}
|
||||
|
||||
void SkSVGNode::setStroke(const SkSVGPaint& svgPaint) {
|
||||
SetInheritedByDefault(fPresentationAttributes.fStroke, svgPaint);
|
||||
}
|
||||
|
||||
void SkSVGNode::setStrokeDashArray(const SkSVGDashArray& dashArray) {
|
||||
SetInheritedByDefault(fPresentationAttributes.fStrokeDashArray, dashArray);
|
||||
}
|
||||
|
||||
void SkSVGNode::setStrokeDashOffset(const SkSVGLength& dashOffset) {
|
||||
fPresentationAttributes.fStrokeDashOffset.set(dashOffset);
|
||||
}
|
||||
@ -121,14 +97,6 @@ void SkSVGNode::setStrokeOpacity(const SkSVGNumberType& opacity) {
|
||||
fPresentationAttributes.fStrokeOpacity.set(SkSVGNumberType(SkTPin<SkScalar>(opacity, 0, 1)));
|
||||
}
|
||||
|
||||
void SkSVGNode::setStrokeLineCap(const SkSVGLineCap& lc) {
|
||||
SetInheritedByDefault(fPresentationAttributes.fStrokeLineCap, lc);
|
||||
}
|
||||
|
||||
void SkSVGNode::setStrokeLineJoin(const SkSVGLineJoin& lj) {
|
||||
SetInheritedByDefault(fPresentationAttributes.fStrokeLineJoin, lj);
|
||||
}
|
||||
|
||||
void SkSVGNode::setStrokeMiterLimit(const SkSVGNumberType& ml) {
|
||||
fPresentationAttributes.fStrokeMiterLimit.set(ml);
|
||||
}
|
||||
@ -137,82 +105,28 @@ void SkSVGNode::setStrokeWidth(const SkSVGLength& strokeWidth) {
|
||||
fPresentationAttributes.fStrokeWidth.set(strokeWidth);
|
||||
}
|
||||
|
||||
void SkSVGNode::setVisibility(const SkSVGVisibility& visibility) {
|
||||
SetInheritedByDefault(fPresentationAttributes.fVisibility, visibility);
|
||||
}
|
||||
|
||||
void SkSVGNode::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
|
||||
switch (attr) {
|
||||
case SkSVGAttribute::kClipPath:
|
||||
if (const SkSVGClipValue* clip = v.as<SkSVGClipValue>()) {
|
||||
this->setClipPath(*clip);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kClipRule:
|
||||
if (const SkSVGFillRuleValue* clipRule = v.as<SkSVGFillRuleValue>()) {
|
||||
this->setClipRule(*clipRule);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kColor:
|
||||
if (const SkSVGColorValue* color = v.as<SkSVGColorValue>()) {
|
||||
this->setColor(*color);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kFill:
|
||||
if (const SkSVGPaintValue* paint = v.as<SkSVGPaintValue>()) {
|
||||
this->setFill(*paint);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kFillOpacity:
|
||||
if (const SkSVGNumberValue* opacity = v.as<SkSVGNumberValue>()) {
|
||||
this->setFillOpacity(*opacity);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kFillRule:
|
||||
if (const SkSVGFillRuleValue* fillRule = v.as<SkSVGFillRuleValue>()) {
|
||||
this->setFillRule(*fillRule);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kFilter:
|
||||
if (const SkSVGFilterValue* filter = v.as<SkSVGFilterValue>()) {
|
||||
this->setFilter(*filter);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kFontFamily:
|
||||
if (const SkSVGFontFamilyValue* family = v.as<SkSVGFontFamilyValue>()) {
|
||||
this->setFontFamily(*family);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kFontSize:
|
||||
if (const SkSVGFontSizeValue* size = v.as<SkSVGFontSizeValue>()) {
|
||||
this->setFontSize(*size);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kFontStyle:
|
||||
if (const SkSVGFontStyleValue* style = v.as<SkSVGFontStyleValue>()) {
|
||||
this->setFontStyle(*style);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kFontWeight:
|
||||
if (const SkSVGFontWeightValue* style = v.as<SkSVGFontWeightValue>()) {
|
||||
this->setFontWeight(*style);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kOpacity:
|
||||
if (const SkSVGNumberValue* opacity = v.as<SkSVGNumberValue>()) {
|
||||
this->setOpacity(*opacity);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kStroke:
|
||||
if (const SkSVGPaintValue* paint = v.as<SkSVGPaintValue>()) {
|
||||
this->setStroke(*paint);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kStrokeDashArray:
|
||||
if (const SkSVGDashArrayValue* dashArray = v.as<SkSVGDashArrayValue>()) {
|
||||
this->setStrokeDashArray(*dashArray);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kStrokeDashOffset:
|
||||
if (const SkSVGLengthValue* dashOffset= v.as<SkSVGLengthValue>()) {
|
||||
this->setStrokeDashOffset(*dashOffset);
|
||||
@ -223,16 +137,6 @@ void SkSVGNode::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
|
||||
this->setStrokeOpacity(*opacity);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kStrokeLineCap:
|
||||
if (const SkSVGLineCapValue* lineCap = v.as<SkSVGLineCapValue>()) {
|
||||
this->setStrokeLineCap(*lineCap);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kStrokeLineJoin:
|
||||
if (const SkSVGLineJoinValue* lineJoin = v.as<SkSVGLineJoinValue>()) {
|
||||
this->setStrokeLineJoin(*lineJoin);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kStrokeMiterLimit:
|
||||
if (const SkSVGNumberValue* miterLimit = v.as<SkSVGNumberValue>()) {
|
||||
this->setStrokeMiterLimit(*miterLimit);
|
||||
@ -243,16 +147,6 @@ void SkSVGNode::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
|
||||
this->setStrokeWidth(*strokeWidth);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kTextAnchor:
|
||||
if (const SkSVGTextAnchorValue* anchor = v.as<SkSVGTextAnchorValue>()) {
|
||||
this->setTextAnchor(*anchor);
|
||||
}
|
||||
break;
|
||||
case SkSVGAttribute::kVisibility:
|
||||
if (const SkSVGVisibilityValue* visibility = v.as<SkSVGVisibilityValue>()) {
|
||||
this->setVisibility(*visibility);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
#if defined(SK_VERBOSE_SVG_PARSING)
|
||||
SkDebugf("attribute ID <%d> ignored for node <%d>\n", attr, fTag);
|
||||
@ -261,7 +155,27 @@ void SkSVGNode::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
|
||||
}
|
||||
}
|
||||
|
||||
bool SkSVGNode::parseAndSetAttribute(const char* name, const char* value) {
|
||||
// TODO: move SkSVGNode attribute parsing (incl. presentation attributes) here.
|
||||
return false;
|
||||
bool SkSVGNode::parseAndSetAttribute(const char* n, const char* v) {
|
||||
return this->setClipPath(SkSVGAttributeParser::parse<SkSVGClip> ("clip-path" , n, v))
|
||||
|| this->setClipRule(SkSVGAttributeParser::parse<SkSVGFillRule> ("clip-rule" , n, v))
|
||||
|| this->setFill (SkSVGAttributeParser::parse<SkSVGPaint> ("fill" , n, v))
|
||||
|| this->setFillRule(SkSVGAttributeParser::parse<SkSVGFillRule> ("fill-rule" , n, v))
|
||||
|| this->setFontFamily
|
||||
(SkSVGAttributeParser::parse<SkSVGFontFamily> ("font-family" , n, v))
|
||||
|| this->setFontSize(SkSVGAttributeParser::parse<SkSVGFontSize> ("font-size" , n, v))
|
||||
|| this->setFontStyle
|
||||
(SkSVGAttributeParser::parse<SkSVGFontStyle>("font-style" , n, v))
|
||||
|| this->setFontWeight
|
||||
(SkSVGAttributeParser::parse<SkSVGFontWeight>("font-weight" , n, v))
|
||||
|| this->setStroke (SkSVGAttributeParser::parse<SkSVGPaint> ("stroke" , n, v))
|
||||
|| this->setStrokeDashArray
|
||||
(SkSVGAttributeParser::parse<SkSVGDashArray>("stroke-dasharray", n, v))
|
||||
|| this->setStrokeLineCap
|
||||
(SkSVGAttributeParser::parse<SkSVGLineCap> ("stroke-linecap" , n ,v))
|
||||
|| this->setStrokeLineJoin
|
||||
(SkSVGAttributeParser::parse<SkSVGLineJoin> ("stroke-linejoin" , n ,v))
|
||||
|| this->setTextAnchor
|
||||
(SkSVGAttributeParser::parse<SkSVGTextAnchor>("text-anchor" , n, v))
|
||||
|| this->setVisibility
|
||||
(SkSVGAttributeParser::parse<SkSVGVisibility>("visibility" , n, v));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user