aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/svg/model/SkSVGAttributeParser.cpp
diff options
context:
space:
mode:
authorGravatar fmalita <fmalita@chromium.org>2016-08-11 09:16:29 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-08-11 09:16:29 -0700
commit2d961e086bb40b371b1a667536fa089794847368 (patch)
tree89c6986af025e9d5c87791e4977838331bbd575b /experimental/svg/model/SkSVGAttributeParser.cpp
parent90b5cc31f373e831c942bfd3113b44486546846b (diff)
[SVGDom] Add more presentation attributes.
Implement proper presentation attribute inheritance, and add support for * fill-opacity * stroke-linecap * stroke-linejoin * stroke-opacity * stroke-width R=robertphillips@google.com,stephana@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2234153002 Review-Url: https://codereview.chromium.org/2234153002
Diffstat (limited to 'experimental/svg/model/SkSVGAttributeParser.cpp')
-rw-r--r--experimental/svg/model/SkSVGAttributeParser.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/experimental/svg/model/SkSVGAttributeParser.cpp b/experimental/svg/model/SkSVGAttributeParser.cpp
index 7a2561cdf7..308eb62ba6 100644
--- a/experimental/svg/model/SkSVGAttributeParser.cpp
+++ b/experimental/svg/model/SkSVGAttributeParser.cpp
@@ -359,3 +359,71 @@ bool SkSVGAttributeParser::parseTransform(SkSVGTransformType* t) {
*t = SkSVGTransformType(matrix);
return true;
}
+
+// https://www.w3.org/TR/SVG/painting.html#SpecifyingPaint
+bool SkSVGAttributeParser::parsePaint(SkSVGPaint* paint) {
+ SkSVGColorType c;
+ bool parsedValue = false;
+ if (this->parseColor(&c)) {
+ *paint = SkSVGPaint(c);
+ parsedValue = true;
+ } else if (this->parseExpectedStringToken("none")) {
+ *paint = SkSVGPaint(SkSVGPaint::Type::kNone);
+ parsedValue = true;
+ } else if (this->parseExpectedStringToken("currentColor")) {
+ *paint = SkSVGPaint(SkSVGPaint::Type::kCurrentColor);
+ parsedValue = true;
+ } else if (this->parseExpectedStringToken("inherit")) {
+ *paint = SkSVGPaint(SkSVGPaint::Type::kInherit);
+ parsedValue = true;
+ }
+ return parsedValue && this->parseEOSToken();
+}
+
+// https://www.w3.org/TR/SVG/painting.html#StrokeLinecapProperty
+bool SkSVGAttributeParser::parseLineCap(SkSVGLineCap* cap) {
+ static const struct {
+ SkSVGLineCap::Type fType;
+ const char* fName;
+ } gCapInfo[] = {
+ { SkSVGLineCap::Type::kButt , "butt" },
+ { SkSVGLineCap::Type::kRound , "round" },
+ { SkSVGLineCap::Type::kSquare , "square" },
+ { SkSVGLineCap::Type::kInherit, "inherit" },
+ };
+
+ bool parsedValue = false;
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gCapInfo); ++i) {
+ if (this->parseExpectedStringToken(gCapInfo[i].fName)) {
+ *cap = SkSVGLineCap(gCapInfo[i].fType);
+ parsedValue = true;
+ break;
+ }
+ }
+
+ return parsedValue && this->parseEOSToken();
+}
+
+// https://www.w3.org/TR/SVG/painting.html#StrokeLinejoinProperty
+bool SkSVGAttributeParser::parseLineJoin(SkSVGLineJoin* join) {
+ static const struct {
+ SkSVGLineJoin::Type fType;
+ const char* fName;
+ } gJoinInfo[] = {
+ { SkSVGLineJoin::Type::kMiter , "miter" },
+ { SkSVGLineJoin::Type::kRound , "round" },
+ { SkSVGLineJoin::Type::kBevel , "bevel" },
+ { SkSVGLineJoin::Type::kInherit, "inherit" },
+ };
+
+ bool parsedValue = false;
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gJoinInfo); ++i) {
+ if (this->parseExpectedStringToken(gJoinInfo[i].fName)) {
+ *join = SkSVGLineJoin(gJoinInfo[i].fType);
+ parsedValue = true;
+ break;
+ }
+ }
+
+ return parsedValue && this->parseEOSToken();
+}