From e61857f27d2ded60cf77e142595ce5f680494ea0 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Mon, 17 Apr 2023 13:37:16 +0200 Subject: [PATCH] svg_loader: _applySvgViewFlag refactored --- src/loaders/svg/tvgSvgSceneBuilder.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/loaders/svg/tvgSvgSceneBuilder.cpp b/src/loaders/svg/tvgSvgSceneBuilder.cpp index ace4fd8f..900dfbf8 100644 --- a/src/loaders/svg/tvgSvgSceneBuilder.cpp +++ b/src/loaders/svg/tvgSvgSceneBuilder.cpp @@ -756,19 +756,23 @@ static unique_ptr _sceneBuildHelper(const SvgNode* node, const Box& vBox, static void _applySvgViewFlag(const Scene* scene, float& vx, float& vy, float& vw, float& vh, float& w, float& h, SvgViewFlag viewFlag) { - if (!((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Viewbox)) { + bool noViewbox = !((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Viewbox); + bool noWidth = !((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Width); + bool noHeight = !((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Height); + + if (noViewbox) { float x, y; scene->bounds(&x, &y, &vw, &vh, false); - if (!((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Width) && !((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Height)) { + if (noWidth && noHeight) { vx = x; vy = y; } else { - if ((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Width) vw = w; - if ((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Height) vh = h; + vw = noWidth ? vw : w; + vh = noHeight ? vh : h; } } - if (!((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Width)) w = vw; - if (!((uint32_t)viewFlag & (uint32_t)SvgViewFlag::Height)) h = vh; + w = noWidth ? vw : w; + h = noHeight ? vh : h; } /************************************************************************/