Debian Codegraph @

modules/svg/src/SkSVGCircle.cpp

raw
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 "modules/svg/include/SkSVGCircle.h"
9
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkPathTypes.h"
12 #include "include/core/SkPoint.h"
13 #include "modules/svg/include/SkSVGAttributeParser.h"
14 #include "modules/svg/include/SkSVGRenderContext.h"
15
16 class SkPaint;
17
18 SkSVGCircle::SkSVGCircle() : INHERITED(SkSVGTag::kCircle) {}
19
20 bool SkSVGCircle::parseAndSetAttribute(const char* n, const char* v) {
21 return INHERITED::parseAndSetAttribute(n, v) ||
22 this->setCx(SkSVGAttributeParser::parse<SkSVGLength>("cx", n, v)) ||
23 this->setCy(SkSVGAttributeParser::parse<SkSVGLength>("cy", n, v)) ||
24 this->setR(SkSVGAttributeParser::parse<SkSVGLength>("r", n, v));
25 }
26
27 std::tuple<SkPoint, SkScalar> SkSVGCircle::resolve(const SkSVGLengthContext& lctx) const {
28 const auto cx = lctx.resolve(fCx, SkSVGLengthContext::LengthType::kHorizontal);
29 const auto cy = lctx.resolve(fCy, SkSVGLengthContext::LengthType::kVertical);
30 const auto r = lctx.resolve(fR , SkSVGLengthContext::LengthType::kOther);
31
32 return std::make_tuple(SkPoint::Make(cx, cy), r);
33 }
34 void SkSVGCircle::onDraw(SkCanvas* canvas, const SkSVGLengthContext& lctx,
35 const SkPaint& paint, SkPathFillType) const {
36 SkPoint pos;
37 SkScalar r;
38 std::tie(pos, r) = this->resolve(lctx);
39
40 if (r > 0) {
41 canvas->drawCircle(pos.x(), pos.y(), r, paint);
42 }
43 }
44
45 SkPath SkSVGCircle::onAsPath(const SkSVGRenderContext& ctx) const {
46 SkPoint pos;
47 SkScalar r;
48 std::tie(pos, r) = this->resolve(ctx.lengthContext());
49
50 return this->mapToParent(SkPath::Circle(pos.x(), pos.y(), r));
51 }
52
53 SkRect SkSVGCircle::onTransformableObjectBoundingBox(const SkSVGRenderContext& ctx) const {
54 const auto [pos, r] = this->resolve(ctx.lengthContext());
55 return SkRect::MakeXYWH(pos.fX - r, pos.fY - r, 2 * r, 2 * r);
56 }