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

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

Issue 2202053002: [SVGDom/experimental] Initial SVGLength support (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: review 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/SkSVGRenderContext.h ('k') | experimental/svg/model/SkSVGSVG.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 "SkSVGRenderContext.h" 8 #include "SkSVGRenderContext.h"
9 #include "SkSVGTypes.h"
9 10
10 SkSVGRenderContext::SkSVGRenderContext() { } 11 namespace {
12
13 SkScalar length_size_for_type(const SkSize& viewport, SkSVGLengthContext::Length Type t) {
14 switch (t) {
15 case SkSVGLengthContext::LengthType::kHorizontal:
16 return viewport.width();
17 case SkSVGLengthContext::LengthType::kVertical:
18 return viewport.height();
19 case SkSVGLengthContext::LengthType::kOther:
20 return SkScalarSqrt(viewport.width() * viewport.height());
21 }
22
23 SkASSERT(false); // Not reached.
24 return 0;
25 }
26
27 } // anonymous ns
28
29 SkScalar SkSVGLengthContext::resolve(const SkSVGLength& l, LengthType t) const {
30 switch (l.unit()) {
31 case SkSVGLength::Unit::kNumber:
32 return l.value();
33 break;
34 case SkSVGLength::Unit::kPercentage:
35 return l.value() * length_size_for_type(fViewport, t) / 100;
36 break;
37 default:
38 SkDebugf("unsupported unit type: <%d>\n", l.unit());
39 break;
40 }
41
42 return 0;
43 }
44
45 SkSVGRenderContext::SkSVGRenderContext(const SkSize& initialViewport)
46 : fLengthContext(initialViewport) {}
11 47
12 SkSVGRenderContext& SkSVGRenderContext::operator=(const SkSVGRenderContext& othe r) { 48 SkSVGRenderContext& SkSVGRenderContext::operator=(const SkSVGRenderContext& othe r) {
13 if (other.fFill.isValid()) { 49 if (other.fFill.isValid()) {
14 fFill.set(*other.fFill.get()); 50 fFill.set(*other.fFill.get());
15 } else { 51 } else {
16 fFill.reset(); 52 fFill.reset();
17 } 53 }
18 54
19 if (other.fStroke.isValid()) { 55 if (other.fStroke.isValid()) {
20 fStroke.set(*other.fStroke.get()); 56 fStroke.set(*other.fStroke.get());
(...skipping 22 matching lines...) Expand all
43 return *fStroke.get(); 79 return *fStroke.get();
44 } 80 }
45 81
46 void SkSVGRenderContext::setFillColor(SkColor color) { 82 void SkSVGRenderContext::setFillColor(SkColor color) {
47 this->ensureFill().setColor(color); 83 this->ensureFill().setColor(color);
48 } 84 }
49 85
50 void SkSVGRenderContext::setStrokeColor(SkColor color) { 86 void SkSVGRenderContext::setStrokeColor(SkColor color) {
51 this->ensureStroke().setColor(color); 87 this->ensureStroke().setColor(color);
52 } 88 }
OLDNEW
« no previous file with comments | « experimental/svg/model/SkSVGRenderContext.h ('k') | experimental/svg/model/SkSVGSVG.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698