diff options
author | 2016-08-08 11:38:55 -0700 | |
---|---|---|
committer | 2016-08-08 11:38:55 -0700 | |
commit | 397a517d1a5774653fcdd08172f9a6b5eea67621 (patch) | |
tree | ab9c9aaa4121a8033a29f259401bcecf7d178203 /experimental/svg/model/SkSVGDOM.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/SkSVGDOM.cpp')
-rw-r--r-- | experimental/svg/model/SkSVGDOM.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/experimental/svg/model/SkSVGDOM.cpp b/experimental/svg/model/SkSVGDOM.cpp index df589230e0..13d67b9cfe 100644 --- a/experimental/svg/model/SkSVGDOM.cpp +++ b/experimental/svg/model/SkSVGDOM.cpp @@ -73,7 +73,7 @@ SkMatrix ParseTransform(const char* str) { bool SetPaintAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, const char* stringValue) { - SkSVGColor color; + SkSVGColorType color; SkSVGAttributeParser parser(stringValue); if (!parser.parseColor(&color)) { return false; @@ -112,6 +112,18 @@ bool SetLengthAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, return true; } +bool SetViewBoxAttribute(const sk_sp<SkSVGNode>& node, SkSVGAttribute attr, + const char* stringValue) { + SkSVGViewBoxType viewBox; + SkSVGAttributeParser parser(stringValue); + if (!parser.parseViewBox(&viewBox)) { + return false; + } + + node->setAttribute(attr, SkSVGViewBoxValue(viewBox)); + return true; +} + // Breaks a "foo: bar; baz: ..." string into key:value pairs. class StyleIterator { public: @@ -184,6 +196,7 @@ SortedDictionaryEntry<AttrParseInfo> gAttributeParseInfo[] = { { "stroke" , { SkSVGAttribute::kStroke , SetPaintAttribute }}, { "style" , { SkSVGAttribute::kUnknown , SetStyleAttributes }}, { "transform", { SkSVGAttribute::kTransform, SetTransformAttribute }}, + { "viewBox" , { SkSVGAttribute::kViewBox , SetViewBoxAttribute }}, { "width" , { SkSVGAttribute::kWidth , SetLengthAttribute }}, { "x" , { SkSVGAttribute::kX , SetLengthAttribute }}, { "y" , { SkSVGAttribute::kY , SetLengthAttribute }}, @@ -292,8 +305,10 @@ sk_sp<SkSVGDOM> SkSVGDOM::MakeFromStream(SkStream& svgStream, const SkSize& cont void SkSVGDOM::render(SkCanvas* canvas) const { if (fRoot) { - SkSVGRenderContext ctx(fContainerSize); - fRoot->render(canvas, ctx); + SkSVGRenderContext ctx(canvas, + SkSVGLengthContext(fContainerSize), + SkSVGPresentationContext()); + fRoot->render(ctx); } } |