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 #ifndef SkSVGRenderContext_DEFINED | 8 #ifndef SkSVGRenderContext_DEFINED |
9 #define SkSVGRenderContext_DEFINED | 9 #define SkSVGRenderContext_DEFINED |
10 | 10 |
| 11 #include "SkSize.h" |
11 #include "SkPaint.h" | 12 #include "SkPaint.h" |
12 #include "SkTLazy.h" | 13 #include "SkTLazy.h" |
13 | 14 |
14 class SkPaint; | 15 class SkPaint; |
| 16 class SkSVGLength; |
| 17 |
| 18 class SkSVGLengthContext { |
| 19 public: |
| 20 SkSVGLengthContext(const SkSize& viewport) : fViewport(viewport) {} |
| 21 |
| 22 enum class LengthType { |
| 23 kHorizontal, |
| 24 kVertical, |
| 25 kOther, |
| 26 }; |
| 27 |
| 28 void setViewPort(const SkSize& viewport) { fViewport = viewport; } |
| 29 |
| 30 SkScalar resolve(const SkSVGLength&, LengthType) const; |
| 31 |
| 32 private: |
| 33 SkSize fViewport; |
| 34 }; |
15 | 35 |
16 class SkSVGRenderContext { | 36 class SkSVGRenderContext { |
17 public: | 37 public: |
18 SkSVGRenderContext(); | 38 explicit SkSVGRenderContext(const SkSize& initialViewport); |
19 SkSVGRenderContext(const SkSVGRenderContext&) = default; | 39 SkSVGRenderContext(const SkSVGRenderContext&) = default; |
20 SkSVGRenderContext& operator=(const SkSVGRenderContext&); | 40 SkSVGRenderContext& operator=(const SkSVGRenderContext&); |
21 | 41 |
| 42 const SkSVGLengthContext& lengthContext() const { return fLengthContext; } |
| 43 |
22 const SkPaint* fillPaint() const { return fFill.getMaybeNull(); } | 44 const SkPaint* fillPaint() const { return fFill.getMaybeNull(); } |
23 const SkPaint* strokePaint() const { return fStroke.getMaybeNull(); } | 45 const SkPaint* strokePaint() const { return fStroke.getMaybeNull(); } |
24 | 46 |
25 void setFillColor(SkColor); | 47 void setFillColor(SkColor); |
26 void setStrokeColor(SkColor); | 48 void setStrokeColor(SkColor); |
27 | 49 |
28 private: | 50 private: |
29 SkPaint& ensureFill(); | 51 SkPaint& ensureFill(); |
30 SkPaint& ensureStroke(); | 52 SkPaint& ensureStroke(); |
31 | 53 |
32 SkTLazy<SkPaint> fFill; | 54 SkSVGLengthContext fLengthContext; |
33 SkTLazy<SkPaint> fStroke; | 55 SkTLazy<SkPaint> fFill; |
| 56 SkTLazy<SkPaint> fStroke; |
34 }; | 57 }; |
35 | 58 |
36 #endif // SkSVGRenderContext_DEFINED | 59 #endif // SkSVGRenderContext_DEFINED |
OLD | NEW |