diff options
author | fmalita <fmalita@chromium.org> | 2016-08-08 11:38:55 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-08 11:38:55 -0700 |
commit | 397a517d1a5774653fcdd08172f9a6b5eea67621 (patch) | |
tree | ab9c9aaa4121a8033a29f259401bcecf7d178203 /experimental/svg/model/SkSVGAttributeParser.cpp | |
parent | f621ff49a288978c272d5ae069a6a1c04c74642b (diff) |
[SVGDom] Add viewBox support
The main feature is <svg> viewBox and proper viewport support, but the CL
touches a few other things:
* refactor SkSVGRenderContext to auto-restore canvas state, and split the
presentation bits into a separate CoW SkSVGPresentationContext
* introduce SkSVGNode::onPrepareToRender(), as a way for nodes to push their
custom state before the actual onRender() call (instead of relying on
non-virtual SkSVGNode to know about all possible state bits)
* add a "Type" suffix to SVG types, to disambiguate (e.g. SkSVGRectType vs.
SkSVGRect)
R=robertphillips@google.com,stephana@google.com
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2222793002
Review-Url: https://codereview.chromium.org/2222793002
Diffstat (limited to 'experimental/svg/model/SkSVGAttributeParser.cpp')
-rw-r--r-- | experimental/svg/model/SkSVGAttributeParser.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/experimental/svg/model/SkSVGAttributeParser.cpp b/experimental/svg/model/SkSVGAttributeParser.cpp index 75e5d12f38..62ca4c8ab2 100644 --- a/experimental/svg/model/SkSVGAttributeParser.cpp +++ b/experimental/svg/model/SkSVGAttributeParser.cpp @@ -149,12 +149,12 @@ bool SkSVGAttributeParser::parseHexColorToken(SkColor* c) { } // https://www.w3.org/TR/SVG/types.html#DataTypeColor -bool SkSVGAttributeParser::parseColor(SkSVGColor* color) { +bool SkSVGAttributeParser::parseColor(SkSVGColorType* color) { SkColor c; // TODO: rgb(...) if (this->parseHexColorToken(&c) || this->parseNamedColorToken(&c)) { - *color = SkSVGColor(c); + *color = SkSVGColorType(c); return true; } @@ -162,13 +162,13 @@ bool SkSVGAttributeParser::parseColor(SkSVGColor* color) { } // https://www.w3.org/TR/SVG/types.html#DataTypeNumber -bool SkSVGAttributeParser::parseNumber(SkSVGNumber* number) { +bool SkSVGAttributeParser::parseNumber(SkSVGNumberType* number) { // consume WS this->parseWSToken(); SkScalar s; if (this->parseScalarToken(&s)) { - *number = SkSVGNumber(s); + *number = SkSVGNumberType(s); // consume trailing separators this->parseSepToken(); return true; @@ -192,3 +192,22 @@ bool SkSVGAttributeParser::parseLength(SkSVGLength* length) { return false; } + +// https://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute +bool SkSVGAttributeParser::parseViewBox(SkSVGViewBoxType* vb) { + SkScalar x, y, w, h; + this->parseWSToken(); + + bool parsedValue = false; + if (this->parseScalarToken(&x) && this->parseSepToken() && + this->parseScalarToken(&y) && this->parseSepToken() && + this->parseScalarToken(&w) && this->parseSepToken() && + this->parseScalarToken(&h)) { + + *vb = SkSVGViewBoxType(SkRect::MakeXYWH(x, y, w, h)); + parsedValue = true; + // consume trailing whitespace + this->parseWSToken(); + } + return parsedValue && this->parseEOSToken(); +} |