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 "SkRect.h" | 9 #include "SkRect.h" |
10 #include "SkSVGRect.h" | 10 #include "SkSVGRect.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 } | 22 } |
23 | 23 |
24 void SkSVGRect::setWidth(const SkSVGLength& w) { | 24 void SkSVGRect::setWidth(const SkSVGLength& w) { |
25 fWidth = w; | 25 fWidth = w; |
26 } | 26 } |
27 | 27 |
28 void SkSVGRect::setHeight(const SkSVGLength& h) { | 28 void SkSVGRect::setHeight(const SkSVGLength& h) { |
29 fHeight = h; | 29 fHeight = h; |
30 } | 30 } |
31 | 31 |
| 32 void SkSVGRect::setRx(const SkSVGLength& rx) { |
| 33 fRx = rx; |
| 34 } |
| 35 |
| 36 void SkSVGRect::setRy(const SkSVGLength& ry) { |
| 37 fRy = ry; |
| 38 } |
| 39 |
32 void SkSVGRect::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) { | 40 void SkSVGRect::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) { |
33 switch (attr) { | 41 switch (attr) { |
34 case SkSVGAttribute::kX: | 42 case SkSVGAttribute::kX: |
35 if (const auto* x = v.as<SkSVGLengthValue>()) { | 43 if (const auto* x = v.as<SkSVGLengthValue>()) { |
36 this->setX(*x); | 44 this->setX(*x); |
37 } | 45 } |
38 break; | 46 break; |
39 case SkSVGAttribute::kY: | 47 case SkSVGAttribute::kY: |
40 if (const auto* y = v.as<SkSVGLengthValue>()) { | 48 if (const auto* y = v.as<SkSVGLengthValue>()) { |
41 this->setY(*y); | 49 this->setY(*y); |
42 } | 50 } |
43 break; | 51 break; |
44 case SkSVGAttribute::kWidth: | 52 case SkSVGAttribute::kWidth: |
45 if (const auto* w = v.as<SkSVGLengthValue>()) { | 53 if (const auto* w = v.as<SkSVGLengthValue>()) { |
46 this->setWidth(*w); | 54 this->setWidth(*w); |
47 } | 55 } |
48 break; | 56 break; |
49 case SkSVGAttribute::kHeight: | 57 case SkSVGAttribute::kHeight: |
50 if (const auto* h = v.as<SkSVGLengthValue>()) { | 58 if (const auto* h = v.as<SkSVGLengthValue>()) { |
51 this->setHeight(*h); | 59 this->setHeight(*h); |
52 } | 60 } |
53 break; | 61 break; |
| 62 case SkSVGAttribute::kRx: |
| 63 if (const auto* rx = v.as<SkSVGLengthValue>()) { |
| 64 this->setRx(*rx); |
| 65 } |
| 66 break; |
| 67 case SkSVGAttribute::kRy: |
| 68 if (const auto* ry = v.as<SkSVGLengthValue>()) { |
| 69 this->setRy(*ry); |
| 70 } |
| 71 break; |
54 default: | 72 default: |
55 this->INHERITED::onSetAttribute(attr, v); | 73 this->INHERITED::onSetAttribute(attr, v); |
56 } | 74 } |
57 } | 75 } |
58 | 76 |
59 void SkSVGRect::onDraw(SkCanvas* canvas, const SkSVGLengthContext& lctx, | 77 void SkSVGRect::onDraw(SkCanvas* canvas, const SkSVGLengthContext& lctx, |
60 const SkPaint& paint) const { | 78 const SkPaint& paint) const { |
61 canvas->drawRect(lctx.resolveRect(fX, fY, fWidth, fHeight), paint); | 79 const SkRect rect = lctx.resolveRect(fX, fY, fWidth, fHeight); |
| 80 const SkScalar rx = lctx.resolve(fRx, SkSVGLengthContext::LengthType::kHoriz
ontal); |
| 81 const SkScalar ry = lctx.resolve(fRy, SkSVGLengthContext::LengthType::kVerti
cal); |
| 82 |
| 83 if (rx || ry) { |
| 84 canvas->drawRRect(SkRRect::MakeRectXY(rect, rx, ry), paint); |
| 85 } else { |
| 86 canvas->drawRect(rect, paint); |
| 87 } |
62 } | 88 } |
OLD | NEW |