Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Side by Side Diff: experimental/svg/model/SkSVGSVG.cpp

Issue 2222793002: [SVGDom] Add <svg> viewBox support (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: typo Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « experimental/svg/model/SkSVGSVG.h ('k') | experimental/svg/model/SkSVGShape.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCanvas.h"
9 #include "SkSVGRenderContext.h"
8 #include "SkSVGSVG.h" 10 #include "SkSVGSVG.h"
9 #include "SkSVGValue.h" 11 #include "SkSVGValue.h"
10 12
11 SkSVGSVG::SkSVGSVG() : INHERITED(SkSVGTag::kSvg) { } 13 SkSVGSVG::SkSVGSVG() : INHERITED(SkSVGTag::kSvg) { }
12 14
15 bool SkSVGSVG::onPrepareToRender(SkSVGRenderContext* ctx) const {
16 auto viewPortRect = ctx->lengthContext().resolveRect(fX, fY, fWidth, fHeigh t);
17 auto contentMatrix = SkMatrix::MakeTrans(viewPortRect.x(), viewPortRect.y()) ;
18 auto viewPort = SkSize::Make(viewPortRect.width(), viewPortRect.height( ));
19
20 if (fViewBox.isValid()) {
21 const SkRect& viewBox = *fViewBox.get();
22
23 // An empty viewbox disables rendering.
24 if (viewBox.isEmpty()) {
25 return false;
26 }
27
28 // A viewBox overrides the intrinsic viewport.
29 viewPort = SkSize::Make(viewBox.width(), viewBox.height());
30
31 contentMatrix.preConcat(
32 SkMatrix::MakeRectToRect(viewBox, viewPortRect, SkMatrix::kFill_Scal eToFit));
33 }
34
35 if (!contentMatrix.isIdentity()) {
36 ctx->canvas()->save();
37 ctx->canvas()->concat(contentMatrix);
38 }
39
40 if (viewPort != ctx->lengthContext().viewPort()) {
41 ctx->writableLengthContext()->setViewPort(viewPort);
42 }
43
44 return this->INHERITED::onPrepareToRender(ctx);
45 }
46
13 void SkSVGSVG::setX(const SkSVGLength& x) { 47 void SkSVGSVG::setX(const SkSVGLength& x) {
14 fX = x; 48 fX = x;
15 } 49 }
16 50
17 void SkSVGSVG::setY(const SkSVGLength& y) { 51 void SkSVGSVG::setY(const SkSVGLength& y) {
18 fY = y; 52 fY = y;
19 } 53 }
20 54
21 void SkSVGSVG::setWidth(const SkSVGLength& w) { 55 void SkSVGSVG::setWidth(const SkSVGLength& w) {
22 fWidth = w; 56 fWidth = w;
23 } 57 }
24 58
25 void SkSVGSVG::setHeight(const SkSVGLength& h) { 59 void SkSVGSVG::setHeight(const SkSVGLength& h) {
26 fHeight = h; 60 fHeight = h;
27 } 61 }
28 62
63 void SkSVGSVG::setViewBox(const SkSVGViewBoxType& vb) {
64 fViewBox.set(vb);
65 }
66
29 void SkSVGSVG::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) { 67 void SkSVGSVG::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) {
30 switch (attr) { 68 switch (attr) {
31 case SkSVGAttribute::kX: 69 case SkSVGAttribute::kX:
32 if (const auto* x = v.as<SkSVGLengthValue>()) { 70 if (const auto* x = v.as<SkSVGLengthValue>()) {
33 this->setX(*x); 71 this->setX(*x);
34 } 72 }
35 break; 73 break;
36 case SkSVGAttribute::kY: 74 case SkSVGAttribute::kY:
37 if (const auto* y = v.as<SkSVGLengthValue>()) { 75 if (const auto* y = v.as<SkSVGLengthValue>()) {
38 this->setY(*y); 76 this->setY(*y);
39 } 77 }
40 break; 78 break;
41 case SkSVGAttribute::kWidth: 79 case SkSVGAttribute::kWidth:
42 if (const auto* w = v.as<SkSVGLengthValue>()) { 80 if (const auto* w = v.as<SkSVGLengthValue>()) {
43 this->setWidth(*w); 81 this->setWidth(*w);
44 } 82 }
45 break; 83 break;
46 case SkSVGAttribute::kHeight: 84 case SkSVGAttribute::kHeight:
47 if (const auto* h = v.as<SkSVGLengthValue>()) { 85 if (const auto* h = v.as<SkSVGLengthValue>()) {
48 this->setHeight(*h); 86 this->setHeight(*h);
49 } 87 }
50 break; 88 break;
89 case SkSVGAttribute::kViewBox:
90 if (const auto* vb = v.as<SkSVGViewBoxValue>()) {
91 this->setViewBox(*vb);
92 }
93 break;
51 default: 94 default:
52 this->INHERITED::onSetAttribute(attr, v); 95 this->INHERITED::onSetAttribute(attr, v);
53 } 96 }
54 } 97 }
OLDNEW
« no previous file with comments | « experimental/svg/model/SkSVGSVG.h ('k') | experimental/svg/model/SkSVGShape.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698