fmalita | bffc256 | 2016-08-03 10:21:11 -0700 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkCanvas.h" |
| 9 | #include "include/core/SkRect.h" |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 10 | #include "modules/svg/include/SkSVGRect.h" |
| 11 | #include "modules/svg/include/SkSVGRenderContext.h" |
| 12 | #include "modules/svg/include/SkSVGValue.h" |
fmalita | bffc256 | 2016-08-03 10:21:11 -0700 | [diff] [blame] | 13 | |
| 14 | SkSVGRect::SkSVGRect() : INHERITED(SkSVGTag::kRect) {} |
| 15 | |
Tyler Denniston | 52d9475 | 2021-02-05 10:23:34 -0500 | [diff] [blame^] | 16 | bool 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)); |
fmalita | bffc256 | 2016-08-03 10:21:11 -0700 | [diff] [blame] | 24 | } |
| 25 | |
Florin Malita | ce8840e | 2016-12-08 09:26:47 -0500 | [diff] [blame] | 26 | SkRRect SkSVGRect::resolve(const SkSVGLengthContext& lctx) const { |
fmalita | 286a865 | 2016-08-10 17:11:29 -0700 | [diff] [blame] | 27 | 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 Malita | ce8840e | 2016-12-08 09:26:47 -0500 | [diff] [blame] | 31 | return SkRRect::MakeRectXY(rect, rx ,ry); |
| 32 | } |
| 33 | |
| 34 | void SkSVGRect::onDraw(SkCanvas* canvas, const SkSVGLengthContext& lctx, |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 35 | const SkPaint& paint, SkPathFillType) const { |
Florin Malita | ce8840e | 2016-12-08 09:26:47 -0500 | [diff] [blame] | 36 | canvas->drawRRect(this->resolve(lctx), paint); |
| 37 | } |
| 38 | |
| 39 | SkPath SkSVGRect::onAsPath(const SkSVGRenderContext& ctx) const { |
Mike Reed | 58cc97a | 2020-08-24 15:15:01 -0400 | [diff] [blame] | 40 | SkPath path = SkPath::RRect(this->resolve(ctx.lengthContext())); |
Florin Malita | ce8840e | 2016-12-08 09:26:47 -0500 | [diff] [blame] | 41 | |
| 42 | this->mapToParent(&path); |
| 43 | |
| 44 | return path; |
fmalita | bffc256 | 2016-08-03 10:21:11 -0700 | [diff] [blame] | 45 | } |
Tyler Denniston | f548a02 | 2020-10-27 15:02:02 -0400 | [diff] [blame] | 46 | |
| 47 | SkRect SkSVGRect::onObjectBoundingBox(const SkSVGRenderContext& ctx) const { |
| 48 | return ctx.lengthContext().resolveRect(fX, fY, fWidth, fHeight); |
| 49 | } |