• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "include/core/SkCanvas.h"
9 #include "modules/svg/include/SkSVGEllipse.h"
10 #include "modules/svg/include/SkSVGRenderContext.h"
11 #include "modules/svg/include/SkSVGValue.h"
12 
SkSVGEllipse()13 SkSVGEllipse::SkSVGEllipse() : INHERITED(SkSVGTag::kEllipse) {}
14 
parseAndSetAttribute(const char * n,const char * v)15 bool SkSVGEllipse::parseAndSetAttribute(const char* n, const char* v) {
16     return INHERITED::parseAndSetAttribute(n, v) ||
17            this->setCx(SkSVGAttributeParser::parse<SkSVGLength>("cx", n, v)) ||
18            this->setCy(SkSVGAttributeParser::parse<SkSVGLength>("cy", n, v)) ||
19            this->setRx(SkSVGAttributeParser::parse<SkSVGLength>("rx", n, v)) ||
20            this->setRy(SkSVGAttributeParser::parse<SkSVGLength>("ry", n, v));
21 }
22 
resolve(const SkSVGLengthContext & lctx) const23 SkRect SkSVGEllipse::resolve(const SkSVGLengthContext& lctx) const {
24     const auto cx = lctx.resolve(fCx, SkSVGLengthContext::LengthType::kHorizontal);
25     const auto cy = lctx.resolve(fCy, SkSVGLengthContext::LengthType::kVertical);
26     const auto rx = lctx.resolve(fRx, SkSVGLengthContext::LengthType::kHorizontal);
27     const auto ry = lctx.resolve(fRy, SkSVGLengthContext::LengthType::kVertical);
28 
29     return (rx > 0 && ry > 0)
30         ? SkRect::MakeXYWH(cx - rx, cy - ry, rx * 2, ry * 2)
31         : SkRect::MakeEmpty();
32 }
33 
onDraw(SkCanvas * canvas,const SkSVGLengthContext & lctx,const SkPaint & paint,SkPathFillType) const34 void SkSVGEllipse::onDraw(SkCanvas* canvas, const SkSVGLengthContext& lctx,
35                           const SkPaint& paint, SkPathFillType) const {
36     canvas->drawOval(this->resolve(lctx), paint);
37 }
38 
onAsPath(const SkSVGRenderContext & ctx) const39 SkPath SkSVGEllipse::onAsPath(const SkSVGRenderContext& ctx) const {
40     SkPath path = SkPath::Oval(this->resolve(ctx.lengthContext()));
41     this->mapToParent(&path);
42 
43     return path;
44 }
45