svg: fix opacity percentage value parsing
authorMichal Maciola <m.maciola@samsung.com>
Thu, 19 Aug 2021 07:37:57 +0000 (09:37 +0200)
committerJunsuChoi <jsuya.choi@samsung.com>
Fri, 27 Aug 2021 05:10:25 +0000 (14:10 +0900)
Percentage values wasn't handled by _toOpacity() function. Other incorrect values
was handled wrongly. Now fixed.

src/loaders/svg/tvgSvgLoader.cpp

index 052035dc18f949a295eb6af47de35745d8ef0f2f..d517fe7f97a1c7cf76dd53717a127c1d3ec7c221 100644 (file)
@@ -163,11 +163,13 @@ static float _toOffset(const char* str)
 static int _toOpacity(const char* str)
 {
     char* end = nullptr;
-    int a = 0;
     float opacity = svgUtilStrtof(str, &end);
 
-    if (end && (*end == '\0')) a = lrint(opacity * 255);
-    return a;
+    if (end) {
+        if (end[0] == '%' && end[1] == '\0') return lrint(opacity * 2.55f);
+        else if (*end == '\0') return lrint(opacity * 255);
+    }
+    return 255;
 }