svg_loader: requested changes applied
authorMira Grudzinska <m.grudzinska@samsung.com>
Sat, 23 Oct 2021 00:16:40 +0000 (02:16 +0200)
committerHermet Park <chuneon.park@samsung.com>
Tue, 26 Oct 2021 04:12:00 +0000 (13:12 +0900)
src/loaders/svg/tvgSvgLoader.cpp
src/loaders/svg/tvgSvgLoaderCommon.h

index b595712..bc4fbd5 100644 (file)
@@ -139,16 +139,16 @@ static float _toFloat(const SvgParser* svgParse, const char* str, SvgParserLengt
 }
 
 
-static float _gradientToFloat(const SvgParser* svgParse, const char* str, SvgParserLengthType type, uint8_t& pct)
+static float _gradientToFloat(const SvgParser* svgParse, const char* str, bool& isPercentage)
 {
     char* end = nullptr;
 
     float parsedValue = svgUtilStrtof(str, &end);
-    pct = 0;
+    isPercentage = false;
 
     if (strstr(str, "%")) {
         parsedValue = parsedValue / 100.0;
-        pct = 1;
+        isPercentage = true;
     }
     else if (strstr(str, "cm")) parsedValue = parsedValue * 35.43307;
     else if (strstr(str, "mm")) parsedValue = parsedValue * 3.543307;
@@ -1926,72 +1926,72 @@ FillSpread _parseSpreadValue(const char* value)
 
 static void _handleRadialCxAttr(SvgLoaderData* loader, SvgRadialGradient* radial, const char* value)
 {
-    radial->cx = _gradientToFloat(loader->svgParse, value, SvgParserLengthType::Horizontal, radial->cxPct);
+    radial->cx = _gradientToFloat(loader->svgParse, value, radial->isCxPercentage);
     if (!loader->svgParse->gradient.parsedFx) {
         radial->fx = radial->cx;
-        radial->fxPct = radial->cxPct;
+        radial->isFxPercentage = radial->isCxPercentage;
     }
 }
 
 
 static void _handleRadialCyAttr(SvgLoaderData* loader, SvgRadialGradient* radial, const char* value)
 {
-    radial->cy = _gradientToFloat(loader->svgParse, value, SvgParserLengthType::Vertical, radial->cyPct);
+    radial->cy = _gradientToFloat(loader->svgParse, value, radial->isCyPercentage);
     if (!loader->svgParse->gradient.parsedFy) {
         radial->fy = radial->cy;
-        radial->fyPct = radial->cyPct;
+        radial->isFyPercentage = radial->isCyPercentage;
     }
 }
 
 
 static void _handleRadialFxAttr(SvgLoaderData* loader, SvgRadialGradient* radial, const char* value)
 {
-    radial->fx = _gradientToFloat(loader->svgParse, value, SvgParserLengthType::Horizontal, radial->fxPct);
+    radial->fx = _gradientToFloat(loader->svgParse, value, radial->isFxPercentage);
     loader->svgParse->gradient.parsedFx = true;
 }
 
 
 static void _handleRadialFyAttr(SvgLoaderData* loader, SvgRadialGradient* radial, const char* value)
 {
-    radial->fy = _gradientToFloat(loader->svgParse, value, SvgParserLengthType::Vertical, radial->fyPct);
+    radial->fy = _gradientToFloat(loader->svgParse, value, radial->isFyPercentage);
     loader->svgParse->gradient.parsedFy = true;
 }
 
 
 static void _handleRadialRAttr(SvgLoaderData* loader, SvgRadialGradient* radial, const char* value)
 {
-    radial->r = _gradientToFloat(loader->svgParse, value, SvgParserLengthType::Other, radial->rPct);
+    radial->r = _gradientToFloat(loader->svgParse, value, radial->isRPercentage);
 }
 
 
 static void _recalcRadialCxAttr(SvgLoaderData* loader, SvgRadialGradient* radial, bool userSpace)
 {
-    if (userSpace && radial->cxPct == 0) radial->cx = radial->cx / loader->svgParse->global.w;
+    if (userSpace && !radial->isCxPercentage) radial->cx = radial->cx / loader->svgParse->global.w;
 }
 
 
 static void _recalcRadialCyAttr(SvgLoaderData* loader, SvgRadialGradient* radial, bool userSpace)
 {
-    if (userSpace && radial->cyPct == 0) radial->cy = radial->cy / loader->svgParse->global.h;
+    if (userSpace && !radial->isCyPercentage) radial->cy = radial->cy / loader->svgParse->global.h;
 }
 
 
 static void _recalcRadialFxAttr(SvgLoaderData* loader, SvgRadialGradient* radial, bool userSpace)
 {
-    if (userSpace && radial->fxPct == 0) radial->fx = radial->fx / loader->svgParse->global.w;
+    if (userSpace && !radial->isFxPercentage) radial->fx = radial->fx / loader->svgParse->global.w;
 }
 
 
 static void _recalcRadialFyAttr(SvgLoaderData* loader, SvgRadialGradient* radial, bool userSpace)
 {
-    if (userSpace && radial->fyPct == 0) radial->fy = radial->fy / loader->svgParse->global.h;
+    if (userSpace && !radial->isFyPercentage) radial->fy = radial->fy / loader->svgParse->global.h;
 }
 
 
 static void _recalcRadialRAttr(SvgLoaderData* loader, SvgRadialGradient* radial, bool userSpace)
 {
     // scaling factor based on the Units paragraph from : https://www.w3.org/TR/2015/WD-SVG2-20150915/coords.html
-    if (userSpace && radial->rPct == 0) radial->r = radial->r / (sqrtf(pow(loader->svgParse->global.h, 2) + pow(loader->svgParse->global.w, 2)) / sqrtf(2.0));
+    if (userSpace && !radial->isRPercentage) radial->r = radial->r / (sqrtf(pow(loader->svgParse->global.h, 2) + pow(loader->svgParse->global.w, 2)) / sqrtf(2.0));
 }
 
 
@@ -2074,11 +2074,11 @@ static SvgStyleGradient* _createRadialGradient(SvgLoaderData* loader, const char
     grad->radial->fx = 0.5f / loader->svgParse->global.w;
     grad->radial->fy = 0.5f / loader->svgParse->global.h;
     grad->radial->r = 0.5f / (sqrtf(pow(loader->svgParse->global.h, 2) + pow(loader->svgParse->global.w, 2)) / sqrtf(2.0f));
-    grad->radial->cxPct = 1;
-    grad->radial->cyPct = 1;
-    grad->radial->fxPct = 1;
-    grad->radial->fyPct = 1;
-    grad->radial->rPct = 1;
+    grad->radial->isCxPercentage = true;
+    grad->radial->isCyPercentage = true;
+    grad->radial->isFxPercentage = true;
+    grad->radial->isFyPercentage = true;
+    grad->radial->isRPercentage = true;
 
     loader->svgParse->gradient.parsedFx = false;
     loader->svgParse->gradient.parsedFy = false;
@@ -2139,49 +2139,49 @@ static bool _attrParseStops(void* data, const char* key, const char* value)
 
 static void _handleLinearX1Attr(SvgLoaderData* loader, SvgLinearGradient* linear, const char* value)
 {
-    linear->x1 = _gradientToFloat(loader->svgParse, value, SvgParserLengthType::Horizontal, linear->x1Pct);
+    linear->x1 = _gradientToFloat(loader->svgParse, value, linear->isX1Percentage);
 }
 
 
 static void _handleLinearY1Attr(SvgLoaderData* loader, SvgLinearGradient* linear, const char* value)
 {
-    linear->y1 = _gradientToFloat(loader->svgParse, value, SvgParserLengthType::Vertical, linear->y1Pct);
+    linear->y1 = _gradientToFloat(loader->svgParse, value, linear->isY1Percentage);
 }
 
 
 static void _handleLinearX2Attr(SvgLoaderData* loader, SvgLinearGradient* linear, const char* value)
 {
-    linear->x2 = _gradientToFloat(loader->svgParse, value, SvgParserLengthType::Horizontal, linear->x2Pct);
+    linear->x2 = _gradientToFloat(loader->svgParse, value, linear->isX2Percentage);
 }
 
 
 static void _handleLinearY2Attr(SvgLoaderData* loader, SvgLinearGradient* linear, const char* value)
 {
-    linear->y2 = _gradientToFloat(loader->svgParse, value, SvgParserLengthType::Vertical, linear->y2Pct);
+    linear->y2 = _gradientToFloat(loader->svgParse, value, linear->isY2Percentage);
 }
 
 
 static void _recalcLinearX1Attr(SvgLoaderData* loader, SvgLinearGradient* linear, bool userSpace)
 {
-    if (userSpace && linear->x1Pct == 0) linear->x1 = linear->x1 / loader->svgParse->global.w;
+    if (userSpace && !linear->isX1Percentage) linear->x1 = linear->x1 / loader->svgParse->global.w;
 }
 
 
 static void _recalcLinearY1Attr(SvgLoaderData* loader, SvgLinearGradient* linear, bool userSpace)
 {
-    if (userSpace && linear->y1Pct == 0) linear->y1 = linear->y1 / loader->svgParse->global.h;
+    if (userSpace && !linear->isY1Percentage) linear->y1 = linear->y1 / loader->svgParse->global.h;
 }
 
 
 static void _recalcLinearX2Attr(SvgLoaderData* loader, SvgLinearGradient* linear, bool userSpace)
 {
-    if (userSpace && linear->x2Pct == 0) linear->x2 = linear->x2 / loader->svgParse->global.w;
+    if (userSpace && !linear->isX2Percentage) linear->x2 = linear->x2 / loader->svgParse->global.w;
 }
 
 
 static void _recalcLinearY2Attr(SvgLoaderData* loader, SvgLinearGradient* linear, bool userSpace)
 {
-    if (userSpace && linear->y2Pct == 0) linear->y2 = linear->y2 / loader->svgParse->global.h;
+    if (userSpace && !linear->isY2Percentage) linear->y2 = linear->y2 / loader->svgParse->global.h;
 }
 
 
@@ -2259,7 +2259,7 @@ static SvgStyleGradient* _createLinearGradient(SvgLoaderData* loader, const char
     * Default value of x2 is 100% - transformed to the global percentage
     */
     grad->linear->x2 = 1.0f / loader->svgParse->global.w;
-    grad->linear->x2Pct = 1;
+    grad->linear->isX2Percentage = true;
 
     simpleXmlParseAttributes(buf, bufLength, _attrParseLinearGradientNode, loader);
 
index e8c1ab3..ae08d5c 100644 (file)
@@ -216,10 +216,10 @@ struct SvgLinearGradient
     float y1;
     float x2;
     float y2;
-    uint8_t x1Pct;
-    uint8_t y1Pct;
-    uint8_t x2Pct;
-    uint8_t y2Pct;
+    bool isX1Percentage;
+    bool isY1Percentage;
+    bool isX2Percentage;
+    bool isY2Percentage;
 
 };
 
@@ -230,11 +230,11 @@ struct SvgRadialGradient
     float fx;
     float fy;
     float r;
-    uint8_t cxPct;
-    uint8_t cyPct;
-    uint8_t fxPct;
-    uint8_t fyPct;
-    uint8_t rPct;
+    bool isCxPercentage;
+    bool isCyPercentage;
+    bool isFxPercentage;
+    bool isFyPercentage;
+    bool isRPercentage;
 };
 
 struct SvgComposite