Browse Source

Merge pull request #61047 from akien-mga/thorvg-0.8.1

Rémi Verschelde 3 years ago
parent
commit
e8520044e7

+ 1 - 1
thirdparty/README.md

@@ -625,7 +625,7 @@ instead of `miniz.h` as an external dependency.
 ## thorvg
 
 - Upstream: https://github.com/Samsung/thorvg
-- Version: 0.8.0 (41093c17b3cac440bdcc53f8b69abeb5734696b5, 2022)
+- Version: 0.8.1 (c4ccb1078f4390ec749ab8e05ba7e9e35f81285f, 2022)
 - License: MIT
 
 Files extracted from upstream source:

+ 1 - 1
thirdparty/thorvg/inc/config.h

@@ -13,5 +13,5 @@
 
 #define THORVG_JPG_LOADER_SUPPORT 1
 
-#define THORVG_VERSION_STRING "0.8.0"
+#define THORVG_VERSION_STRING "0.8.1"
 #endif

+ 3 - 3
thirdparty/thorvg/src/lib/sw_engine/tvgSwCommon.h

@@ -99,9 +99,9 @@ struct SwSize
 struct SwOutline
 {
     SwPoint*      pts;              //the outline's points
-    uint16_t      ptsCnt;           //number of points in the glyph
-    uint16_t      reservedPtsCnt;
-    uint16_t*     cntrs;            //the contour end points
+    uint32_t      ptsCnt;           //number of points in the glyph
+    uint32_t      reservedPtsCnt;
+    uint32_t*     cntrs;            //the contour end points
     uint16_t      cntrsCnt;         //number of contours in glyph
     uint16_t      reservedCntrsCnt;
     uint8_t*      types;            //curve type

+ 1 - 1
thirdparty/thorvg/src/lib/sw_engine/tvgSwImage.cpp

@@ -46,7 +46,7 @@ static bool _genOutline(SwImage* image, const Matrix* transform, SwMpool* mpool,
 
     if (outline->reservedCntrsCnt < 1) {
         outline->reservedCntrsCnt = 1;
-        outline->cntrs = static_cast<uint16_t*>(realloc(outline->cntrs, outline->reservedCntrsCnt * sizeof(uint16_t)));
+        outline->cntrs = static_cast<uint32_t*>(realloc(outline->cntrs, outline->reservedCntrsCnt * sizeof(uint32_t)));
         outline->closed = static_cast<bool*>(realloc(outline->closed, outline->reservedCntrsCnt * sizeof(bool)));
         outline->closed[0] = true;
     }

+ 1 - 1
thirdparty/thorvg/src/lib/sw_engine/tvgSwShape.cpp

@@ -64,7 +64,7 @@ static bool _growOutlineContour(SwOutline& outline, uint32_t n)
 {
     if (outline.reservedCntrsCnt >= outline.cntrsCnt + n) return false;
     outline.reservedCntrsCnt = outline.cntrsCnt + n;
-    outline.cntrs = static_cast<uint16_t*>(realloc(outline.cntrs, outline.reservedCntrsCnt * sizeof(uint16_t)));
+    outline.cntrs = static_cast<uint32_t*>(realloc(outline.cntrs, outline.reservedCntrsCnt * sizeof(uint32_t)));
     return true;
 }
 

+ 2 - 2
thirdparty/thorvg/src/lib/sw_engine/tvgSwStroke.cpp

@@ -780,7 +780,7 @@ static void _exportBorderOutline(const SwStroke& stroke, SwOutline* outline, uin
     auto src = border->tags;
     auto tags = outline->types + outline->ptsCnt;
     auto cntrs = outline->cntrs + outline->cntrsCnt;
-    uint16_t idx = outline->ptsCnt;
+    auto idx = outline->ptsCnt;
 
     while (cnt > 0) {
 
@@ -921,7 +921,7 @@ SwOutline* strokeExportOutline(SwStroke* stroke, SwMpool* mpool, unsigned tid)
         outline->reservedPtsCnt = ptsCnt;
     }
     if (outline->reservedCntrsCnt < cntrsCnt) {
-        outline->cntrs = static_cast<uint16_t*>(realloc(outline->cntrs, sizeof(uint16_t) * cntrsCnt));
+        outline->cntrs = static_cast<uint32_t*>(realloc(outline->cntrs, sizeof(uint32_t) * cntrsCnt));
         outline->reservedCntrsCnt = cntrsCnt;
     }
 

+ 16 - 3
thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.cpp

@@ -337,7 +337,10 @@ static unsigned char _parserColor(const char* value, char** end)
 
     r = svgUtilStrtof(value, end);
     *end = _skipSpace(*end, nullptr);
-    if (**end == '%') r = 255 * r / 100;
+    if (**end == '%') {
+        r = 255 * r / 100;
+        (*end)++;
+    }
     *end = _skipSpace(*end, nullptr);
 
     if (r < 0 || r > 255) {
@@ -1145,10 +1148,13 @@ static bool _attrParseSymbolNode(void* data, const char* key, const char* value)
     if (!strcmp(key, "viewBox")) {
         if (!_parseNumber(&value, &symbol->vx) || !_parseNumber(&value, &symbol->vy)) return false;
         if (!_parseNumber(&value, &symbol->vw) || !_parseNumber(&value, &symbol->vh)) return false;
+        symbol->hasViewBox = true;
     } else if (!strcmp(key, "width")) {
         symbol->w = _toFloat(loader->svgParse, value, SvgParserLengthType::Horizontal);
+        symbol->hasWidth = true;
     } else if (!strcmp(key, "height")) {
         symbol->h = _toFloat(loader->svgParse, value, SvgParserLengthType::Vertical);
+        symbol->hasHeight = true;
     } else if (!strcmp(key, "preserveAspectRatio")) {
         if (!strcmp(value, "none")) symbol->preserveAspect = false;
     } else if (!strcmp(key, "overflow")) {
@@ -1306,6 +1312,12 @@ static SvgNode* _createSymbolNode(SvgLoaderData* loader, SvgNode* parent, const
     loader->svgParse->node->node.symbol.preserveAspect = true;
     loader->svgParse->node->node.symbol.overflowVisible = false;
 
+    loader->svgParse->node->node.symbol.hasViewBox = false;
+    loader->svgParse->node->node.symbol.hasWidth = false;
+    loader->svgParse->node->node.symbol.hasHeight = false;
+    loader->svgParse->node->node.symbol.vx = 0.0f;
+    loader->svgParse->node->node.symbol.vy = 0.0f;
+
     func(buf, bufLength, _attrParseSymbolNode, loader);
 
     return loader->svgParse->node;
@@ -2722,6 +2734,7 @@ static void _svgLoaderParserXmlOpen(SvgLoaderData* loader, const char* content,
         }
         /* default value for opacity */
         loader->svgParse->gradStop = {0.0f, 0, 0, 0, 255};
+        loader->svgParse->flags = SvgStopStyleFlags::StopDefault;
         simpleXmlParseAttributes(attrs, attrsLength, _attrParseStops, loader);
         loader->latestGradient->stops.push(loader->svgParse->gradStop);
     } else if (!isIgnoreUnsupportedLogElements(tagName)) {
@@ -2865,7 +2878,7 @@ static SvgStyleGradient* _gradientDup(Array<SvgStyleGradient*>* gradients, const
     auto gradList = gradients->data;
 
     for (uint32_t i = 0; i < gradients->count; ++i) {
-        if (!strcmp((*gradList)->id, id)) {
+        if ((*gradList)->id && !strcmp((*gradList)->id, id)) {
             result = _cloneGradient(*gradList);
             break;
         }
@@ -2875,7 +2888,7 @@ static SvgStyleGradient* _gradientDup(Array<SvgStyleGradient*>* gradients, const
     if (result && result->ref) {
         gradList = gradients->data;
         for (uint32_t i = 0; i < gradients->count; ++i) {
-            if (!strcmp((*gradList)->id, result->ref)) {
+            if ((*gradList)->id && !strcmp((*gradList)->id, result->ref)) {
                 if (result->stops.count == 0) _cloneGradStops(result->stops, (*gradList)->stops);
                 //TODO: Properly inherit other property
                 break;

+ 3 - 0
thirdparty/thorvg/src/loaders/svg/tvgSvgLoaderCommon.h

@@ -173,6 +173,9 @@ struct SvgSymbolNode
     float vx, vy, vw, vh;
     bool preserveAspect;
     bool overflowVisible;
+    bool hasViewBox;
+    bool hasWidth;
+    bool hasHeight;
 };
 
 struct SvgUseNode

+ 9 - 7
thirdparty/thorvg/src/loaders/svg/tvgSvgSceneBuilder.cpp

@@ -576,15 +576,17 @@ static unique_ptr<Scene> _useBuildHelper(const SvgNode* node, const Box& vBox, c
     if (node->node.use.symbol) {
         auto symbol = node->node.use.symbol->node.symbol;
 
-        auto width = symbol.w;
+        auto width = (symbol.hasWidth ? symbol.w : vBox.w);
         if (node->node.use.isWidthSet) width = node->node.use.w;
-        auto height = symbol.h;
+        auto height = (symbol.hasHeight ? symbol.h : vBox.h);;
         if (node->node.use.isHeightSet) height = node->node.use.h;
+        auto vw = (symbol.hasViewBox ? symbol.vw : width);
+        auto vh = (symbol.hasViewBox ? symbol.vh : height);
 
         Matrix mViewBox = {1, 0, 0, 0, 1, 0, 0, 0, 1};
-        if ((!mathEqual(width, symbol.vw) || !mathEqual(height, symbol.vh)) && symbol.vw > 0 && symbol.vh > 0) {
-            auto sx = width / symbol.vw;
-            auto sy = height / symbol.vh;
+        if ((!mathEqual(width, vw) || !mathEqual(height, vh)) && vw > 0 && vh > 0) {
+            auto sx = width / vw;
+            auto sy = height / vh;
             if (symbol.preserveAspect) {
                 if (sx < sy) sy = sx;
                 else sx = sy;
@@ -592,8 +594,8 @@ static unique_ptr<Scene> _useBuildHelper(const SvgNode* node, const Box& vBox, c
 
             auto tvx = symbol.vx * sx;
             auto tvy = symbol.vy * sy;
-            auto tvw = symbol.vw * sx;
-            auto tvh = symbol.vh * sy;
+            auto tvw = vw * sx;
+            auto tvh = vh * sy;
             tvy -= (symbol.h - tvh) * 0.5f;
             tvx -= (symbol.w - tvw) * 0.5f;
             mViewBox = {sx, 0, -tvx, 0, sy, -tvy, 0, 0, 1};

+ 2 - 0
thirdparty/thorvg/src/loaders/svg/tvgXmlParser.cpp

@@ -26,6 +26,8 @@
 
 #ifdef _WIN32
     #include <malloc.h>
+#elif __FreeBSD__
+    #include<stdlib.h>
 #else
     #include <alloca.h>
 #endif

+ 1 - 1
thirdparty/thorvg/update-thorvg.sh

@@ -1,4 +1,4 @@
-VERSION=0.8.0
+VERSION=0.8.1
 rm -rf AUTHORS inc LICENSE src *.zip
 curl -L -O https://github.com/Samsung/thorvg/archive/refs/tags/v$VERSION.zip
 bsdtar --strip-components=1 -xvf *.zip