mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
SvgLoader: Support x,y rounded rect
Change-Id: I45d8f7ff3604da0a80c09e2495ed8c0301310094
This commit is contained in:
parent
0d19700b4e
commit
02a0e98596
2 changed files with 26 additions and 2 deletions
|
@ -150,11 +150,28 @@ unique_ptr<tvg::Shape> _shapeBuildHelper(SvgNode* node)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SvgNodeType::Rect: {
|
case SvgNodeType::Rect: {
|
||||||
if (node->node.rect.rx == node->node.rect.ry) {
|
if (node->node.rect.rx == node->node.rect.ry || (node->node.rect.rx == 0 || node->node.rect.ry == 0)) {
|
||||||
shape->appendRect(node->node.rect.x, node->node.rect.y, node->node.rect.w, node->node.rect.h, node->node.rect.rx);
|
shape->appendRect(node->node.rect.x, node->node.rect.y, node->node.rect.w, node->node.rect.h, node->node.rect.rx);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//TODO: Support rounded rectangle
|
float x = node->node.rect.x;
|
||||||
|
float y = node->node.rect.y;
|
||||||
|
float w = node->node.rect.w;
|
||||||
|
float h = node->node.rect.h;
|
||||||
|
float rx = node->node.rect.rx;
|
||||||
|
float ry = node->node.rect.ry;
|
||||||
|
float rhx = rx / 2;
|
||||||
|
float rhy = ry / 2;
|
||||||
|
shape->moveTo(x + rx, y);
|
||||||
|
shape->lineTo(x + w - rx, y);
|
||||||
|
shape->cubicTo(x + w - rx + rhx, y, x + w, y + ry - rhy, x + w, y + ry);
|
||||||
|
shape->lineTo(x + w, y + h - ry);
|
||||||
|
shape->cubicTo(x + w, y + h - ry + rhy, x + w - rx + rhx, y + h, x + w - rx, y + h);
|
||||||
|
shape->lineTo(x + rx, y + h);
|
||||||
|
shape->cubicTo(x + rx - rhx, y + h, x, y + h - ry + rhy, x, y + h - ry);
|
||||||
|
shape->lineTo(x, y + ry);
|
||||||
|
shape->cubicTo(x, y + ry - rhy, x + rx - rhx, y, x + rx, y);
|
||||||
|
shape->close();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
7
test/svgs/rect.svg
Normal file
7
test/svgs/rect.svg
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<svg viewBox="0 0 220 100" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<!-- Simple rectangle -->
|
||||||
|
<rect width="100" height="100" />
|
||||||
|
|
||||||
|
<!-- Rounded corner rectangle -->
|
||||||
|
<rect x="120" width="100" height="100" rx="15" ry="30"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 230 B |
Loading…
Add table
Reference in a new issue