From 16a153c804e60996743a567f80dba898ae508186 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Mon, 1 Nov 2021 20:28:41 +0100 Subject: [PATCH] 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. --- src/loaders/svg/tvgSvgSceneBuilder.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/loaders/svg/tvgSvgSceneBuilder.cpp b/src/loaders/svg/tvgSvgSceneBuilder.cpp index 6eb5a325..f36d9df2 100644 --- a/src/loaders/svg/tvgSvgSceneBuilder.cpp +++ b/src/loaders/svg/tvgSvgSceneBuilder.cpp @@ -289,11 +289,11 @@ static void _applyProperty(SvgNode* node, Shape* vg, float vx, float vy, float v 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 (auto strokeW = vg->strokeWidth()) { + vx += 0.5f * strokeW; + vy += 0.5f * strokeW; + vw -= strokeW; + 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) //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 (auto strokeW = vg->strokeWidth()) { + vx += 0.5f * strokeW; + vy += 0.5f * strokeW; + vw -= strokeW; + vh -= strokeW; } }