| 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 "SkCanvas.h" |
| 9 #include "SkSVGAttribute.h" | 9 #include "SkSVGAttribute.h" |
| 10 #include "SkSVGRenderContext.h" | 10 #include "SkSVGRenderContext.h" |
| 11 #include "SkSVGTypes.h" | 11 #include "SkSVGTypes.h" |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 SkScalar length_size_for_type(const SkSize& viewport, SkSVGLengthContext::Length
Type t) { | 15 SkScalar length_size_for_type(const SkSize& viewport, SkSVGLengthContext::Length
Type t) { |
| 16 switch (t) { | 16 switch (t) { |
| 17 case SkSVGLengthContext::LengthType::kHorizontal: | 17 case SkSVGLengthContext::LengthType::kHorizontal: |
| 18 return viewport.width(); | 18 return viewport.width(); |
| 19 case SkSVGLengthContext::LengthType::kVertical: | 19 case SkSVGLengthContext::LengthType::kVertical: |
| 20 return viewport.height(); | 20 return viewport.height(); |
| 21 case SkSVGLengthContext::LengthType::kOther: | 21 case SkSVGLengthContext::LengthType::kOther: |
| 22 return SkScalarSqrt(viewport.width() * viewport.height()); | 22 return SkScalarSqrt(viewport.width() * viewport.height()); |
| 23 } | 23 } |
| 24 | 24 |
| 25 SkASSERT(false); // Not reached. | 25 SkASSERT(false); // Not reached. |
| 26 return 0; | 26 return 0; |
| 27 } | 27 } |
| 28 | 28 |
| 29 // Multipliers for DPI-relative units. |
| 30 constexpr SkScalar kINMultiplier = 1.00f; |
| 31 constexpr SkScalar kPTMultiplier = kINMultiplier / 72.272f; |
| 32 constexpr SkScalar kPCMultiplier = kPTMultiplier * 12; |
| 33 constexpr SkScalar kMMMultiplier = kINMultiplier / 25.4f; |
| 34 constexpr SkScalar kCMMultiplier = kMMMultiplier * 10; |
| 35 |
| 29 } // anonymous ns | 36 } // anonymous ns |
| 30 | 37 |
| 31 SkScalar SkSVGLengthContext::resolve(const SkSVGLength& l, LengthType t) const { | 38 SkScalar SkSVGLengthContext::resolve(const SkSVGLength& l, LengthType t) const { |
| 32 switch (l.unit()) { | 39 switch (l.unit()) { |
| 33 case SkSVGLength::Unit::kNumber: | 40 case SkSVGLength::Unit::kNumber: |
| 34 // Fall through. | 41 // Fall through. |
| 35 case SkSVGLength::Unit::kPX: | 42 case SkSVGLength::Unit::kPX: |
| 36 return l.value(); | 43 return l.value(); |
| 37 case SkSVGLength::Unit::kPercentage: | 44 case SkSVGLength::Unit::kPercentage: |
| 38 return l.value() * length_size_for_type(fViewport, t) / 100; | 45 return l.value() * length_size_for_type(fViewport, t) / 100; |
| 46 case SkSVGLength::Unit::kCM: |
| 47 return l.value() * fDPI * kCMMultiplier; |
| 48 case SkSVGLength::Unit::kMM: |
| 49 return l.value() * fDPI * kMMMultiplier; |
| 50 case SkSVGLength::Unit::kIN: |
| 51 return l.value() * fDPI * kINMultiplier; |
| 52 case SkSVGLength::Unit::kPT: |
| 53 return l.value() * fDPI * kPTMultiplier; |
| 54 case SkSVGLength::Unit::kPC: |
| 55 return l.value() * fDPI * kPCMultiplier; |
| 39 default: | 56 default: |
| 40 SkDebugf("unsupported unit type: <%d>\n", l.unit()); | 57 SkDebugf("unsupported unit type: <%d>\n", l.unit()); |
| 41 return 0; | 58 return 0; |
| 42 } | 59 } |
| 43 } | 60 } |
| 44 | 61 |
| 45 SkRect SkSVGLengthContext::resolveRect(const SkSVGLength& x, const SkSVGLength&
y, | 62 SkRect SkSVGLengthContext::resolveRect(const SkSVGLength& x, const SkSVGLength&
y, |
| 46 const SkSVGLength& w, const SkSVGLength&
h) const { | 63 const SkSVGLength& w, const SkSVGLength&
h) const { |
| 47 return SkRect::MakeXYWH( | 64 return SkRect::MakeXYWH( |
| 48 this->resolve(x, SkSVGLengthContext::LengthType::kHorizontal), | 65 this->resolve(x, SkSVGLengthContext::LengthType::kHorizontal), |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 | 254 |
| 238 const SkPaint* SkSVGRenderContext::fillPaint() const { | 255 const SkPaint* SkSVGRenderContext::fillPaint() const { |
| 239 const SkSVGPaint::Type paintType = fPresentationContext->fInherited.fFill.ge
t()->type(); | 256 const SkSVGPaint::Type paintType = fPresentationContext->fInherited.fFill.ge
t()->type(); |
| 240 return paintType != SkSVGPaint::Type::kNone ? &fPresentationContext->fFillPa
int : nullptr; | 257 return paintType != SkSVGPaint::Type::kNone ? &fPresentationContext->fFillPa
int : nullptr; |
| 241 } | 258 } |
| 242 | 259 |
| 243 const SkPaint* SkSVGRenderContext::strokePaint() const { | 260 const SkPaint* SkSVGRenderContext::strokePaint() const { |
| 244 const SkSVGPaint::Type paintType = fPresentationContext->fInherited.fStroke.
get()->type(); | 261 const SkSVGPaint::Type paintType = fPresentationContext->fInherited.fStroke.
get()->type(); |
| 245 return paintType != SkSVGPaint::Type::kNone ? &fPresentationContext->fStroke
Paint : nullptr; | 262 return paintType != SkSVGPaint::Type::kNone ? &fPresentationContext->fStroke
Paint : nullptr; |
| 246 } | 263 } |
| OLD | NEW |