svg_loader: fix bounds for gradient

In the case when bounds should not include a stroke width, width
and height values were reduced by half of a stroke width, instead
of the full width.
This commit is contained in:
Mira Grudzinska 2021-11-01 20:28:41 +01:00 committed by Mira Grudzinska
parent 26f99372b0
commit 16a153c804

View file

@ -289,11 +289,11 @@ static void _applyProperty(SvgNode* node, Shape* vg, float vx, float vy, float v
vg->bounds(&vx, &vy, &vw, &vh, false); vg->bounds(&vx, &vy, &vw, &vh, false);
//According to: https://www.w3.org/TR/SVG11/coords.html#ObjectBoundingBoxUnits (the last paragraph) //According to: https://www.w3.org/TR/SVG11/coords.html#ObjectBoundingBoxUnits (the last paragraph)
//a stroke width should be ignored for bounding box calculations //a stroke width should be ignored for bounding box calculations
if (auto strokeHalfW = 0.5f * vg->strokeWidth()) { if (auto strokeW = vg->strokeWidth()) {
vx += strokeHalfW; vx += 0.5f * strokeW;
vy += strokeHalfW; vy += 0.5f * strokeW;
vw -= strokeHalfW; vw -= strokeW;
vh -= strokeHalfW; vh -= strokeW;
} }
} }
@ -338,11 +338,11 @@ static void _applyProperty(SvgNode* node, Shape* vg, float vx, float vy, float v
//According to: https://www.w3.org/TR/SVG11/coords.html#ObjectBoundingBoxUnits (the last paragraph) //According to: https://www.w3.org/TR/SVG11/coords.html#ObjectBoundingBoxUnits (the last paragraph)
//a stroke width should be ignored for bounding box calculations //a stroke width should be ignored for bounding box calculations
vg->bounds(&vx, &vy, &vw, &vh, false); vg->bounds(&vx, &vy, &vw, &vh, false);
if (auto strokeHalfW = 0.5f * vg->strokeWidth()) { if (auto strokeW = vg->strokeWidth()) {
vx += strokeHalfW; vx += 0.5f * strokeW;
vy += strokeHalfW; vy += 0.5f * strokeW;
vw -= strokeHalfW; vw -= strokeW;
vh -= strokeHalfW; vh -= strokeW;
} }
} }