diff options
Diffstat (limited to 'thirdparty/thorvg/src/loaders')
4 files changed, 30 insertions, 10 deletions
diff --git a/thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.cpp b/thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.cpp index a842b7fa8b..42bfd4de70 100644 --- a/thirdparty/thorvg/src/loaders/svg/tvgSvgLoader.cpp +++ b/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; diff --git a/thirdparty/thorvg/src/loaders/svg/tvgSvgLoaderCommon.h b/thirdparty/thorvg/src/loaders/svg/tvgSvgLoaderCommon.h index 1f25e82adc..dc9ed558c3 100644 --- a/thirdparty/thorvg/src/loaders/svg/tvgSvgLoaderCommon.h +++ b/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 diff --git a/thirdparty/thorvg/src/loaders/svg/tvgSvgSceneBuilder.cpp b/thirdparty/thorvg/src/loaders/svg/tvgSvgSceneBuilder.cpp index 90705f2523..a3f34fd46b 100644 --- a/thirdparty/thorvg/src/loaders/svg/tvgSvgSceneBuilder.cpp +++ b/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}; diff --git a/thirdparty/thorvg/src/loaders/svg/tvgXmlParser.cpp b/thirdparty/thorvg/src/loaders/svg/tvgXmlParser.cpp index a12689c7dd..245bc7603a 100644 --- a/thirdparty/thorvg/src/loaders/svg/tvgXmlParser.cpp +++ b/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 |