[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
This commit is contained in:
parent
d71fe83ac2
commit
286a8657da
@ -17,6 +17,8 @@ enum class SkSVGAttribute {
|
||||
kD,
|
||||
kFill,
|
||||
kHeight,
|
||||
kRx,
|
||||
kRy,
|
||||
kStroke,
|
||||
kTransform,
|
||||
kViewBox,
|
||||
|
@ -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 }},
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user