OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "SkCanvas.h" |
| 9 #include "SkSVGCircle.h" |
| 10 #include "SkSVGRenderContext.h" |
| 11 #include "SkSVGValue.h" |
| 12 |
| 13 SkSVGCircle::SkSVGCircle() : INHERITED(SkSVGTag::kCircle) {} |
| 14 |
| 15 void SkSVGCircle::setCx(const SkSVGLength& cx) { |
| 16 fCx = cx; |
| 17 } |
| 18 |
| 19 void SkSVGCircle::setCy(const SkSVGLength& cy) { |
| 20 fCy = cy; |
| 21 } |
| 22 |
| 23 void SkSVGCircle::setR(const SkSVGLength& r) { |
| 24 fR = r; |
| 25 } |
| 26 |
| 27 void SkSVGCircle::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) { |
| 28 switch (attr) { |
| 29 case SkSVGAttribute::kCx: |
| 30 if (const auto* cx = v.as<SkSVGLengthValue>()) { |
| 31 this->setCx(*cx); |
| 32 } |
| 33 break; |
| 34 case SkSVGAttribute::kCy: |
| 35 if (const auto* cy = v.as<SkSVGLengthValue>()) { |
| 36 this->setCy(*cy); |
| 37 } |
| 38 break; |
| 39 case SkSVGAttribute::kR: |
| 40 if (const auto* r = v.as<SkSVGLengthValue>()) { |
| 41 this->setR(*r); |
| 42 } |
| 43 break; |
| 44 default: |
| 45 this->INHERITED::onSetAttribute(attr, v); |
| 46 } |
| 47 } |
| 48 |
| 49 void SkSVGCircle::onDraw(SkCanvas* canvas, const SkSVGLengthContext& lctx, |
| 50 const SkPaint& paint) const { |
| 51 const auto cx = lctx.resolve(fCx, SkSVGLengthContext::LengthType::kHorizonta
l); |
| 52 const auto cy = lctx.resolve(fCy, SkSVGLengthContext::LengthType::kVertical)
; |
| 53 const auto r = lctx.resolve(fR , SkSVGLengthContext::LengthType::kOther); |
| 54 |
| 55 if (r > 0) { |
| 56 canvas->drawCircle(cx, cy, r, paint); |
| 57 } |
| 58 } |
OLD | NEW |