[svg] Parse text attributes
Convert font-family, font-size, font-style and font-weight to
presentation attributes, and add parsing utils.
Bug: skia:10840
Change-Id: I1acdb59bc95fe46e67ed0f499dd0732420016663
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/328436
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Tyler Denniston <tdenniston@google.com>
diff --git a/modules/svg/include/SkSVGNode.h b/modules/svg/include/SkSVGNode.h
index 2e92c6b..8f493d2 100644
--- a/modules/svg/include/SkSVGNode.h
+++ b/modules/svg/include/SkSVGNode.h
@@ -38,6 +38,29 @@
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(); \
+ } \
+ }
+
class SkSVGNode : public SkRefCnt {
public:
~SkSVGNode() override;
@@ -70,6 +93,11 @@
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)
+
protected:
SkSVGNode(SkSVGTag);