blob: bccb23db982020c2110659e8efc61defe8e0dd66 [file] [log] [blame]
fmalitabffc2562016-08-03 10:21:11 -07001/*
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkCanvas.h"
9#include "include/core/SkRect.h"
Florin Malitab3418102020-10-15 18:10:29 -040010#include "modules/svg/include/SkSVGRect.h"
11#include "modules/svg/include/SkSVGRenderContext.h"
12#include "modules/svg/include/SkSVGValue.h"
fmalitabffc2562016-08-03 10:21:11 -070013
14SkSVGRect::SkSVGRect() : INHERITED(SkSVGTag::kRect) {}
15
Tyler Denniston52d94752021-02-05 10:23:34 -050016bool SkSVGRect::parseAndSetAttribute(const char* n, const char* v) {
17 return INHERITED::parseAndSetAttribute(n, v) ||
18 this->setX(SkSVGAttributeParser::parse<SkSVGLength>("x", n, v)) ||
19 this->setY(SkSVGAttributeParser::parse<SkSVGLength>("y", n, v)) ||
20 this->setWidth(SkSVGAttributeParser::parse<SkSVGLength>("width", n, v)) ||
21 this->setHeight(SkSVGAttributeParser::parse<SkSVGLength>("height", n, v)) ||
22 this->setRx(SkSVGAttributeParser::parse<SkSVGLength>("rx", n, v)) ||
23 this->setRy(SkSVGAttributeParser::parse<SkSVGLength>("ry", n, v));
fmalitabffc2562016-08-03 10:21:11 -070024}
25
Florin Malitace8840e2016-12-08 09:26:47 -050026SkRRect SkSVGRect::resolve(const SkSVGLengthContext& lctx) const {
fmalita286a8652016-08-10 17:11:29 -070027 const SkRect rect = lctx.resolveRect(fX, fY, fWidth, fHeight);
28 const SkScalar rx = lctx.resolve(fRx, SkSVGLengthContext::LengthType::kHorizontal);
29 const SkScalar ry = lctx.resolve(fRy, SkSVGLengthContext::LengthType::kVertical);
30
Florin Malitace8840e2016-12-08 09:26:47 -050031 return SkRRect::MakeRectXY(rect, rx ,ry);
32}
33
34void SkSVGRect::onDraw(SkCanvas* canvas, const SkSVGLengthContext& lctx,
Mike Reed7d34dc72019-11-26 12:17:17 -050035 const SkPaint& paint, SkPathFillType) const {
Florin Malitace8840e2016-12-08 09:26:47 -050036 canvas->drawRRect(this->resolve(lctx), paint);
37}
38
39SkPath SkSVGRect::onAsPath(const SkSVGRenderContext& ctx) const {
Mike Reed58cc97a2020-08-24 15:15:01 -040040 SkPath path = SkPath::RRect(this->resolve(ctx.lengthContext()));
Florin Malitace8840e2016-12-08 09:26:47 -050041
42 this->mapToParent(&path);
43
44 return path;
fmalitabffc2562016-08-03 10:21:11 -070045}
Tyler Dennistonf548a022020-10-27 15:02:02 -040046
47SkRect SkSVGRect::onObjectBoundingBox(const SkSVGRenderContext& ctx) const {
48 return ctx.lengthContext().resolveRect(fX, fY, fWidth, fHeight);
49}