From 4599067bee8a1f761ed4b9d64884e6335e04bf6a Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Wed, 3 May 2023 23:58:33 +0200 Subject: [PATCH] svg_loader: fixing percent. calculations of width/height The conversion to percentages was applied twice. Additionally, when a viewbox value was provided before the width/height, incorrect scaling occurred. @Issue: https://github.com/thorvg/thorvg/issues/1414 --- src/loaders/svg/tvgSvgLoader.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/loaders/svg/tvgSvgLoader.cpp b/src/loaders/svg/tvgSvgLoader.cpp index c1f55554..f9f08cdb 100644 --- a/src/loaders/svg/tvgSvgLoader.cpp +++ b/src/loaders/svg/tvgSvgLoader.cpp @@ -861,17 +861,15 @@ static bool _attrParseSvgNode(void* data, const char* key, const char* value) if (!strcmp(key, "width")) { doc->w = _toFloat(loader->svgParse, value, SvgParserLengthType::Horizontal); - if (strstr(value, "%")) { + if (strstr(value, "%") && !(doc->viewFlag & SvgViewFlag::Viewbox)) { doc->viewFlag = (doc->viewFlag | SvgViewFlag::WidthInPercent); - doc->w /= 100.0f; } else { doc->viewFlag = (doc->viewFlag | SvgViewFlag::Width); } } else if (!strcmp(key, "height")) { doc->h = _toFloat(loader->svgParse, value, SvgParserLengthType::Vertical); - if (strstr(value, "%")) { + if (strstr(value, "%") && !(doc->viewFlag & SvgViewFlag::Viewbox)) { doc->viewFlag = (doc->viewFlag | SvgViewFlag::HeightInPercent); - doc->h /= 100.0f; } else { doc->viewFlag = (doc->viewFlag | SvgViewFlag::Height); }