Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSVGEllipse.cpp
Go to the documentation of this file.
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
13
14SkSVGEllipse::SkSVGEllipse() : INHERITED(SkSVGTag::kEllipse) {}
15
16bool SkSVGEllipse::parseAndSetAttribute(const char* n, const char* v) {
18 this->setCx(SkSVGAttributeParser::parse<SkSVGLength>("cx", n, v)) ||
19 this->setCy(SkSVGAttributeParser::parse<SkSVGLength>("cy", n, v)) ||
20 this->setRx(SkSVGAttributeParser::parse<SkSVGLength>("rx", n, v)) ||
21 this->setRy(SkSVGAttributeParser::parse<SkSVGLength>("ry", n, v));
22}
23
24SkRect SkSVGEllipse::resolve(const SkSVGLengthContext& lctx) const {
26 const auto cy = lctx.resolve(fCy, SkSVGLengthContext::LengthType::kVertical);
27
28 // https://www.w3.org/TR/SVG2/shapes.html#EllipseElement
29 //
30 // An auto value for either rx or ry is converted to a used value, following the rules given
31 // above for rectangles (but without any clamping based on width or height).
32 const auto [ rx, ry ] = ResolveOptionalRadii(fRx, fRy, lctx);
33
34 // A computed value of zero for either dimension, or a computed value of auto for both
35 // dimensions, disables rendering of the element.
36 return (rx > 0 && ry > 0)
37 ? SkRect::MakeXYWH(cx - rx, cy - ry, rx * 2, ry * 2)
38 : SkRect::MakeEmpty();
39}
40
42 const SkPaint& paint, SkPathFillType) const {
43 canvas->drawOval(this->resolve(lctx), paint);
44}
45
47 SkPath path = SkPath::Oval(this->resolve(ctx.lengthContext()));
48 this->mapToParent(&path);
49
50 return path;
51}
SkPathFillType
Definition SkPathTypes.h:11
#define INHERITED(method,...)
SkSVGTag
Definition SkSVGNode.h:23
std::tuple< float, float > ResolveOptionalRadii(const SkTLazy< SkSVGLength > &opt_rx, const SkTLazy< SkSVGLength > &opt_ry, const SkSVGLengthContext &lctx)
Definition SkSVGRect.cpp:17
void drawOval(const SkRect &oval, const SkPaint &paint)
static SkPath Oval(const SkRect &, SkPathDirection=SkPathDirection::kCW)
Definition SkPath.cpp:3522
bool parseAndSetAttribute(const char *, const char *) override
void onDraw(SkCanvas *, const SkSVGLengthContext &, const SkPaint &, SkPathFillType) const override
SkPath onAsPath(const SkSVGRenderContext &) const override
SkScalar resolve(const SkSVGLength &, LengthType) const
virtual bool parseAndSetAttribute(const char *name, const char *value)
Definition SkSVGNode.cpp:90
const SkSVGLengthContext & lengthContext() const
void mapToParent(SkPath *) const
const Paint & paint
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659