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 "SkCanvas.h" | |
8 #include "SkSVGRenderContext.h" | 9 #include "SkSVGRenderContext.h" |
9 #include "SkSVGTypes.h" | 10 #include "SkSVGTypes.h" |
10 | 11 |
11 namespace { | 12 namespace { |
12 | 13 |
13 SkScalar length_size_for_type(const SkSize& viewport, SkSVGLengthContext::Length Type t) { | 14 SkScalar length_size_for_type(const SkSize& viewport, SkSVGLengthContext::Length Type t) { |
14 switch (t) { | 15 switch (t) { |
15 case SkSVGLengthContext::LengthType::kHorizontal: | 16 case SkSVGLengthContext::LengthType::kHorizontal: |
16 return viewport.width(); | 17 return viewport.width(); |
17 case SkSVGLengthContext::LengthType::kVertical: | 18 case SkSVGLengthContext::LengthType::kVertical: |
(...skipping 17 matching lines...) Expand all Loading... | |
35 return l.value() * length_size_for_type(fViewport, t) / 100; | 36 return l.value() * length_size_for_type(fViewport, t) / 100; |
36 break; | 37 break; |
37 default: | 38 default: |
38 SkDebugf("unsupported unit type: <%d>\n", l.unit()); | 39 SkDebugf("unsupported unit type: <%d>\n", l.unit()); |
39 break; | 40 break; |
40 } | 41 } |
41 | 42 |
42 return 0; | 43 return 0; |
43 } | 44 } |
44 | 45 |
45 SkSVGRenderContext::SkSVGRenderContext(const SkSize& initialViewport) | 46 SkRect SkSVGLengthContext::resolveRect(const SkSVGLength& x, const SkSVGLength& y, |
46 : fLengthContext(initialViewport) {} | 47 const SkSVGLength& w, const SkSVGLength& h) const { |
48 return SkRect::MakeXYWH( | |
49 this->resolve(x, SkSVGLengthContext::LengthType::kHorizontal), | |
50 this->resolve(y, SkSVGLengthContext::LengthType::kVertical), | |
51 this->resolve(w, SkSVGLengthContext::LengthType::kHorizontal), | |
52 this->resolve(h, SkSVGLengthContext::LengthType::kVertical)); | |
53 } | |
47 | 54 |
48 SkSVGRenderContext& SkSVGRenderContext::operator=(const SkSVGRenderContext& othe r) { | 55 SkSVGPresentationContext::SkSVGPresentationContext() {} |
56 | |
57 SkSVGPresentationContext::SkSVGPresentationContext(const SkSVGPresentationContex t& o) { | |
58 this->initFrom(o); | |
59 } | |
60 | |
61 SkSVGPresentationContext& SkSVGPresentationContext::operator=(const SkSVGPresent ationContext& o) { | |
62 this->initFrom(o); | |
63 return *this; | |
64 } | |
65 | |
66 void SkSVGPresentationContext::initFrom(const SkSVGPresentationContext& other) { | |
49 if (other.fFill.isValid()) { | 67 if (other.fFill.isValid()) { |
50 fFill.set(*other.fFill.get()); | 68 fFill.set(*other.fFill.get()); |
51 } else { | 69 } else { |
52 fFill.reset(); | 70 fFill.reset(); |
53 } | 71 } |
54 | 72 |
55 if (other.fStroke.isValid()) { | 73 if (other.fStroke.isValid()) { |
56 fStroke.set(*other.fStroke.get()); | 74 fStroke.set(*other.fStroke.get()); |
57 } else { | 75 } else { |
58 fStroke.reset(); | 76 fStroke.reset(); |
59 } | 77 } |
60 | |
61 return *this; | |
62 } | 78 } |
63 | 79 |
64 SkPaint& SkSVGRenderContext::ensureFill() { | 80 SkPaint& SkSVGPresentationContext::ensureFill() { |
65 if (!fFill.isValid()) { | 81 if (!fFill.isValid()) { |
66 fFill.init(); | 82 fFill.init(); |
67 fFill.get()->setStyle(SkPaint::kFill_Style); | 83 fFill.get()->setStyle(SkPaint::kFill_Style); |
68 fFill.get()->setAntiAlias(true); | 84 fFill.get()->setAntiAlias(true); |
69 } | 85 } |
70 return *fFill.get(); | 86 return *fFill.get(); |
71 } | 87 } |
72 | 88 |
73 SkPaint& SkSVGRenderContext::ensureStroke() { | 89 SkPaint& SkSVGPresentationContext::ensureStroke() { |
74 if (!fStroke.isValid()) { | 90 if (!fStroke.isValid()) { |
75 fStroke.init(); | 91 fStroke.init(); |
76 fStroke.get()->setStyle(SkPaint::kStroke_Style); | 92 fStroke.get()->setStyle(SkPaint::kStroke_Style); |
77 fStroke.get()->setAntiAlias(true); | 93 fStroke.get()->setAntiAlias(true); |
78 } | 94 } |
79 return *fStroke.get(); | 95 return *fStroke.get(); |
80 } | 96 } |
81 | 97 |
82 void SkSVGRenderContext::setFillColor(SkColor color) { | 98 void SkSVGPresentationContext::setFillColor(SkColor color) { |
83 this->ensureFill().setColor(color); | 99 this->ensureFill().setColor(color); |
84 } | 100 } |
85 | 101 |
86 void SkSVGRenderContext::setStrokeColor(SkColor color) { | 102 void SkSVGPresentationContext::setStrokeColor(SkColor color) { |
87 this->ensureStroke().setColor(color); | 103 this->ensureStroke().setColor(color); |
88 } | 104 } |
105 | |
106 SkSVGRenderContext::SkSVGRenderContext(SkCanvas* canvas, | |
107 const SkSVGLengthContext& lctx, | |
108 const SkSVGPresentationContext& pctx) | |
109 : fLengthContext(lctx) | |
110 , fPresentationContext(pctx) | |
111 , fCanvas(canvas) | |
112 , fCanvasSaveCount(canvas->getSaveCount()) {} | |
113 | |
robertphillips
2016/08/08 17:56:10
Depending on what semantics you expect, the new Sk
f(malita)
2016/08/08 18:12:03
Indeed, that's intentional: the original save coun
| |
114 SkSVGRenderContext::SkSVGRenderContext(const SkSVGRenderContext& other) | |
115 : SkSVGRenderContext(other.canvas(), | |
116 other.lengthContext(), | |
117 other.presentationContext()) {} | |
118 | |
119 SkSVGRenderContext::~SkSVGRenderContext() { | |
120 fCanvas->restoreToCount(fCanvasSaveCount); | |
121 } | |
OLD | NEW |