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

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

Issue 2259473002: [SVGDom] Add support for assorted absolute units (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: 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 | « no previous file | no next file » | 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 "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
robertphillips 2016/08/17 18:39:03 // These all assume a 90dpi display device. Do we
f(malita) 2016/08/17 21:04:17 Done.
29 // https://www.w3.org/TR/SVG/coords.html#Units
30 constexpr SkScalar kPXMultiplier = 1.00f;
robertphillips 2016/08/17 18:39:03 Isn't the pt multiplier supposed to be DPI/72.272
f(malita) 2016/08/17 21:04:17 Done.
31 constexpr SkScalar kPTMultiplier = 1.25f;
32 constexpr SkScalar kPCMultiplier = 15.00f;
33 constexpr SkScalar kINMultiplier = 90.00f;
34 constexpr SkScalar kMMMultiplier = 3.543307f;
35 constexpr SkScalar kCMMultiplier = kMMMultiplier * 10;
36
29 } // anonymous ns 37 } // anonymous ns
30 38
31 SkScalar SkSVGLengthContext::resolve(const SkSVGLength& l, LengthType t) const { 39 SkScalar SkSVGLengthContext::resolve(const SkSVGLength& l, LengthType t) const {
32 switch (l.unit()) { 40 switch (l.unit()) {
33 case SkSVGLength::Unit::kNumber: 41 case SkSVGLength::Unit::kNumber:
34 // Fall through.
35 case SkSVGLength::Unit::kPX:
36 return l.value(); 42 return l.value();
37 case SkSVGLength::Unit::kPercentage: 43 case SkSVGLength::Unit::kPercentage:
38 return l.value() * length_size_for_type(fViewport, t) / 100; 44 return l.value() * length_size_for_type(fViewport, t) / 100;
45 case SkSVGLength::Unit::kPX:
46 return l.value() * kPXMultiplier;
47 case SkSVGLength::Unit::kCM:
48 return l.value() * kCMMultiplier;
49 case SkSVGLength::Unit::kMM:
50 return l.value() * kMMMultiplier;
51 case SkSVGLength::Unit::kIN:
52 return l.value() * kINMultiplier;
53 case SkSVGLength::Unit::kPT:
54 return l.value() * kPTMultiplier;
55 case SkSVGLength::Unit::kPC:
56 return l.value() * kPCMultiplier;
39 default: 57 default:
40 SkDebugf("unsupported unit type: <%d>\n", l.unit()); 58 SkDebugf("unsupported unit type: <%d>\n", l.unit());
41 return 0; 59 return 0;
42 } 60 }
43 } 61 }
44 62
45 SkRect SkSVGLengthContext::resolveRect(const SkSVGLength& x, const SkSVGLength& y, 63 SkRect SkSVGLengthContext::resolveRect(const SkSVGLength& x, const SkSVGLength& y,
46 const SkSVGLength& w, const SkSVGLength& h) const { 64 const SkSVGLength& w, const SkSVGLength& h) const {
47 return SkRect::MakeXYWH( 65 return SkRect::MakeXYWH(
48 this->resolve(x, SkSVGLengthContext::LengthType::kHorizontal), 66 this->resolve(x, SkSVGLengthContext::LengthType::kHorizontal),
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 255
238 const SkPaint* SkSVGRenderContext::fillPaint() const { 256 const SkPaint* SkSVGRenderContext::fillPaint() const {
239 const SkSVGPaint::Type paintType = fPresentationContext->fInherited.fFill.ge t()->type(); 257 const SkSVGPaint::Type paintType = fPresentationContext->fInherited.fFill.ge t()->type();
240 return paintType != SkSVGPaint::Type::kNone ? &fPresentationContext->fFillPa int : nullptr; 258 return paintType != SkSVGPaint::Type::kNone ? &fPresentationContext->fFillPa int : nullptr;
241 } 259 }
242 260
243 const SkPaint* SkSVGRenderContext::strokePaint() const { 261 const SkPaint* SkSVGRenderContext::strokePaint() const {
244 const SkSVGPaint::Type paintType = fPresentationContext->fInherited.fStroke. get()->type(); 262 const SkSVGPaint::Type paintType = fPresentationContext->fInherited.fStroke. get()->type();
245 return paintType != SkSVGPaint::Type::kNone ? &fPresentationContext->fStroke Paint : nullptr; 263 return paintType != SkSVGPaint::Type::kNone ? &fPresentationContext->fStroke Paint : nullptr;
246 } 264 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698