OLD | NEW |
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 Loading... |
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 } |
OLD | NEW |