diff options
author | fmalita <fmalita@chromium.org> | 2016-08-10 17:11:29 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-10 17:11:29 -0700 |
commit | 286a8657da0364006e95cb0988477cc3a5f0e112 (patch) | |
tree | 80ae24ff27cdb50099cfa542ce9c4e9d322195e9 /experimental | |
parent | d71fe83ac211a1fef77d122d39c33fdfe7010f86 (diff) |
[SVGDom] Add rx/ry support for <rect>
R=stephana@google.com,robertphillips@google.com
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2234863002
Review-Url: https://codereview.chromium.org/2234863002
Diffstat (limited to 'experimental')
-rw-r--r-- | experimental/svg/model/SkSVGAttribute.h | 2 | ||||
-rw-r--r-- | experimental/svg/model/SkSVGDOM.cpp | 2 | ||||
-rw-r--r-- | experimental/svg/model/SkSVGRect.cpp | 28 | ||||
-rw-r--r-- | experimental/svg/model/SkSVGRect.h | 7 | ||||
-rw-r--r-- | experimental/svg/model/SkSVGShape.cpp | 1 |
5 files changed, 39 insertions, 1 deletions
diff --git a/experimental/svg/model/SkSVGAttribute.h b/experimental/svg/model/SkSVGAttribute.h index d05737b69f..1d7c96eb22 100644 --- a/experimental/svg/model/SkSVGAttribute.h +++ b/experimental/svg/model/SkSVGAttribute.h @@ -17,6 +17,8 @@ enum class SkSVGAttribute { kD, kFill, kHeight, + kRx, + kRy, kStroke, kTransform, kViewBox, diff --git a/experimental/svg/model/SkSVGDOM.cpp b/experimental/svg/model/SkSVGDOM.cpp index face3b4a01..2d1972b92f 100644 --- a/experimental/svg/model/SkSVGDOM.cpp +++ b/experimental/svg/model/SkSVGDOM.cpp @@ -163,6 +163,8 @@ SortedDictionaryEntry<AttrParseInfo> gAttributeParseInfo[] = { { "d" , { SkSVGAttribute::kD , SetPathDataAttribute }}, { "fill" , { SkSVGAttribute::kFill , SetPaintAttribute }}, { "height" , { SkSVGAttribute::kHeight , SetLengthAttribute }}, + { "rx" , { SkSVGAttribute::kRx , SetLengthAttribute }}, + { "ry" , { SkSVGAttribute::kRy , SetLengthAttribute }}, { "stroke" , { SkSVGAttribute::kStroke , SetPaintAttribute }}, { "style" , { SkSVGAttribute::kUnknown , SetStyleAttributes }}, { "transform", { SkSVGAttribute::kTransform, SetTransformAttribute }}, diff --git a/experimental/svg/model/SkSVGRect.cpp b/experimental/svg/model/SkSVGRect.cpp index b65c2b9974..cbb18306a5 100644 --- a/experimental/svg/model/SkSVGRect.cpp +++ b/experimental/svg/model/SkSVGRect.cpp @@ -29,6 +29,14 @@ void SkSVGRect::setHeight(const SkSVGLength& h) { fHeight = h; } +void SkSVGRect::setRx(const SkSVGLength& rx) { + fRx = rx; +} + +void SkSVGRect::setRy(const SkSVGLength& ry) { + fRy = ry; +} + void SkSVGRect::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) { switch (attr) { case SkSVGAttribute::kX: @@ -51,6 +59,16 @@ void SkSVGRect::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) { this->setHeight(*h); } break; + case SkSVGAttribute::kRx: + if (const auto* rx = v.as<SkSVGLengthValue>()) { + this->setRx(*rx); + } + break; + case SkSVGAttribute::kRy: + if (const auto* ry = v.as<SkSVGLengthValue>()) { + this->setRy(*ry); + } + break; default: this->INHERITED::onSetAttribute(attr, v); } @@ -58,5 +76,13 @@ void SkSVGRect::onSetAttribute(SkSVGAttribute attr, const SkSVGValue& v) { void SkSVGRect::onDraw(SkCanvas* canvas, const SkSVGLengthContext& lctx, const SkPaint& paint) const { - canvas->drawRect(lctx.resolveRect(fX, fY, fWidth, fHeight), paint); + const SkRect rect = lctx.resolveRect(fX, fY, fWidth, fHeight); + const SkScalar rx = lctx.resolve(fRx, SkSVGLengthContext::LengthType::kHorizontal); + const SkScalar ry = lctx.resolve(fRy, SkSVGLengthContext::LengthType::kVertical); + + if (rx || ry) { + canvas->drawRRect(SkRRect::MakeRectXY(rect, rx, ry), paint); + } else { + canvas->drawRect(rect, paint); + } } diff --git a/experimental/svg/model/SkSVGRect.h b/experimental/svg/model/SkSVGRect.h index b4cd363d77..0da248c4eb 100644 --- a/experimental/svg/model/SkSVGRect.h +++ b/experimental/svg/model/SkSVGRect.h @@ -20,6 +20,8 @@ public: void setY(const SkSVGLength&); void setWidth(const SkSVGLength&); void setHeight(const SkSVGLength&); + void setRx(const SkSVGLength&); + void setRy(const SkSVGLength&); protected: void onSetAttribute(SkSVGAttribute, const SkSVGValue&) override; @@ -34,6 +36,11 @@ private: SkSVGLength fWidth = SkSVGLength(0); SkSVGLength fHeight = SkSVGLength(0); + // The x radius for rounded rects. + SkSVGLength fRx = SkSVGLength(0); + // The y radius for rounded rects. + SkSVGLength fRy = SkSVGLength(0); + typedef SkSVGShape INHERITED; }; diff --git a/experimental/svg/model/SkSVGShape.cpp b/experimental/svg/model/SkSVGShape.cpp index ad4b5cedae..516d4a2925 100644 --- a/experimental/svg/model/SkSVGShape.cpp +++ b/experimental/svg/model/SkSVGShape.cpp @@ -11,6 +11,7 @@ SkSVGShape::SkSVGShape(SkSVGTag t) : INHERITED(t) {} void SkSVGShape::onRender(const SkSVGRenderContext& ctx) const { + // TODO: this approach forces duplicate geometry resolution in onDraw(); refactor to avoid. if (const SkPaint* fillPaint = ctx.presentationContext().fillPaint()) { this->onDraw(ctx.canvas(), ctx.lengthContext(), *fillPaint); } |