svg_loader: shape's bounds without a stroke

A shape's bounds used for a gradient transformation shouldn't take
a stroke into account.
This commit is contained in:
Mira Grudzinska 2021-10-27 02:55:22 +02:00 committed by Mira Grudzinska
parent 71324e2e1d
commit ba25cb80eb

View file

@ -271,7 +271,17 @@ static void _applyProperty(SvgNode* node, Shape* vg, float vx, float vy, float v
if (style->fill.paint.none) {
//Do nothing
} else if (style->fill.paint.gradient) {
if (!style->fill.paint.gradient->userSpace) vg->bounds(&vx, &vy, &vw, &vh, false);
if (!style->fill.paint.gradient->userSpace) {
vg->bounds(&vx, &vy, &vw, &vh, false);
//According to: https://www.w3.org/TR/SVG11/coords.html#ObjectBoundingBoxUnits (the last paragraph)
//a stroke width should be ignored for bounding box calculations
if (auto strokeHalfW = 0.5f * vg->strokeWidth()) {
vx += strokeHalfW;
vy += strokeHalfW;
vw -= strokeHalfW;
vh -= strokeHalfW;
}
}
if (style->fill.paint.gradient->type == SvgGradientType::Linear) {
auto linear = _applyLinearGradientProperty(style->fill.paint.gradient, vg, vx, vy, vw, vh, style->fill.opacity);
@ -310,7 +320,17 @@ static void _applyProperty(SvgNode* node, Shape* vg, float vx, float vy, float v
if (style->stroke.paint.none) {
//Do nothing
} else if (style->stroke.paint.gradient) {
if (!style->stroke.paint.gradient->userSpace) vg->bounds(&vx, &vy, &vw, &vh, false);
if (!style->stroke.paint.gradient->userSpace) {
//According to: https://www.w3.org/TR/SVG11/coords.html#ObjectBoundingBoxUnits (the last paragraph)
//a stroke width should be ignored for bounding box calculations
vg->bounds(&vx, &vy, &vw, &vh, false);
if (auto strokeHalfW = 0.5f * vg->strokeWidth()) {
vx += strokeHalfW;
vy += strokeHalfW;
vw -= strokeHalfW;
vh -= strokeHalfW;
}
}
if (style->stroke.paint.gradient->type == SvgGradientType::Linear) {
auto linear = _applyLinearGradientProperty(style->stroke.paint.gradient, vg, vx, vy, vw, vh, style->stroke.opacity);