From: Mira Grudzinska <67589014+mgrudzinska@users.noreply.github.com> Date: Tue, 5 Oct 2021 10:04:40 +0000 (+0200) Subject: svg_loader: proper handling width/height units (#851) X-Git-Tag: accepted/tizen/6.5/unified/20211103.015235~120 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c828573ab2a997cfb8d88642bc179cc2ace39618;p=platform%2Fcore%2Fgraphics%2Ftizenvg.git svg_loader: proper handling width/height units (#851) Units of the svg width and height tags were incorrectly assigned. Percentage values will be handled separately. --- diff --git a/src/loaders/svg/tvgSvgLoader.cpp b/src/loaders/svg/tvgSvgLoader.cpp index 4ed8b90..a7b6845 100644 --- a/src/loaders/svg/tvgSvgLoader.cpp +++ b/src/loaders/svg/tvgSvgLoader.cpp @@ -697,6 +697,8 @@ error: } +/* +// TODO - remove? static constexpr struct { const char* tag; @@ -712,7 +714,6 @@ static constexpr struct LENGTH_DEF(in, SvgLengthType::In) }; - static float _parseLength(const char* str, SvgLengthType* type) { float value; @@ -725,7 +726,7 @@ static float _parseLength(const char* str, SvgLengthType* type) value = svgUtilStrtof(str, nullptr); return value; } - +*/ static bool _parseStyleAttr(void* data, const char* key, const char* value); static bool _parseStyleAttr(void* data, const char* key, const char* value, bool style); @@ -736,13 +737,11 @@ static bool _attrParseSvgNode(void* data, const char* key, const char* value) SvgLoaderData* loader = (SvgLoaderData*)data; SvgNode* node = loader->svgParse->node; SvgDocNode* doc = &(node->node.doc); - SvgLengthType type; - //TODO: handle length unit. if (!strcmp(key, "width")) { - doc->w = _parseLength(value, &type); + doc->w = _toFloat(loader->svgParse, value, SvgParserLengthType::Horizontal); } else if (!strcmp(key, "height")) { - doc->h = _parseLength(value, &type); + doc->h = _toFloat(loader->svgParse, value, SvgParserLengthType::Vertical); } else if (!strcmp(key, "viewBox")) { if (_parseNumber(&value, &doc->vx)) { if (_parseNumber(&value, &doc->vy)) { @@ -761,8 +760,8 @@ static bool _attrParseSvgNode(void* data, const char* key, const char* value) return simpleXmlParseW3CAttribute(value, _parseStyleAttr, loader); } #ifdef THORVG_LOG_ENABLED - else if (!strcmp(key, "x") || !strcmp(key, "y")) { - if (0.0f == _parseLength(value, &type)) TVGLOG("SVG", "Unsupported attributes used [Elements type: Svg][Attribute: %s][Value: %s]", key, value); + else if ((!strcmp(key, "x") || !strcmp(key, "y")) && fabsf(svgUtilStrtof(value, nullptr)) > FLT_EPSILON ) { + TVGLOG("SVG", "Unsupported attributes used [Elements type: Svg][Attribute: %s][Value: %s]", key, value); } #endif else { diff --git a/src/loaders/svg/tvgSvgLoaderCommon.h b/src/loaders/svg/tvgSvgLoaderCommon.h index 1854619..645f1b3 100644 --- a/src/loaders/svg/tvgSvgLoaderCommon.h +++ b/src/loaders/svg/tvgSvgLoaderCommon.h @@ -54,6 +54,8 @@ enum class SvgNodeType Unknown }; +/* +// TODO - remove? enum class SvgLengthType { Percent, @@ -64,6 +66,7 @@ enum class SvgLengthType Cm, In, }; +*/ enum class SvgFillFlags {