svg_loader: proper handling width/height units (#851)
authorMira Grudzinska <67589014+mgrudzinska@users.noreply.github.com>
Tue, 5 Oct 2021 10:04:40 +0000 (12:04 +0200)
committerJunsuChoi <jsuya.choi@samsung.com>
Wed, 6 Oct 2021 03:03:14 +0000 (12:03 +0900)
Units of the svg width and height tags were incorrectly assigned.
Percentage values will be handled separately.

src/loaders/svg/tvgSvgLoader.cpp
src/loaders/svg/tvgSvgLoaderCommon.h

index 4ed8b90..a7b6845 100644 (file)
@@ -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 {
index 1854619..645f1b3 100644 (file)
@@ -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
 {