mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
svg_loader: handle currentColor inside gradient
@Issue: https://github.com/thorvg/thorvg/issues/2960
This commit is contained in:
parent
b7888c2ff3
commit
511495f6d8
1 changed files with 26 additions and 2 deletions
|
@ -2495,6 +2495,18 @@ static SvgStyleGradient* _createRadialGradient(SvgLoaderData* loader, const char
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static SvgColor* _findLatestColor(const SvgLoaderData* loader)
|
||||||
|
{
|
||||||
|
auto parent = loader->stack.count > 0 ? loader->stack.last() : loader->doc;
|
||||||
|
|
||||||
|
while (parent != nullptr) {
|
||||||
|
if (parent->style->curColorSet) return &parent->style->color;
|
||||||
|
parent = parent->parent;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool _attrParseStopsStyle(void* data, const char* key, const char* value)
|
static bool _attrParseStopsStyle(void* data, const char* key, const char* value)
|
||||||
{
|
{
|
||||||
SvgLoaderData* loader = (SvgLoaderData*)data;
|
SvgLoaderData* loader = (SvgLoaderData*)data;
|
||||||
|
@ -2504,7 +2516,13 @@ static bool _attrParseStopsStyle(void* data, const char* key, const char* value)
|
||||||
stop->a = _toOpacity(value);
|
stop->a = _toOpacity(value);
|
||||||
loader->svgParse->flags = (loader->svgParse->flags | SvgStopStyleFlags::StopOpacity);
|
loader->svgParse->flags = (loader->svgParse->flags | SvgStopStyleFlags::StopOpacity);
|
||||||
} else if (!strcmp(key, "stop-color")) {
|
} else if (!strcmp(key, "stop-color")) {
|
||||||
if (_toColor(value, &stop->r, &stop->g, &stop->b, nullptr)) {
|
if (!strcmp(value, "currentColor")) {
|
||||||
|
if (auto latestColor = _findLatestColor(loader)) {
|
||||||
|
stop->r = latestColor->r;
|
||||||
|
stop->g = latestColor->g;
|
||||||
|
stop->b = latestColor->b;
|
||||||
|
}
|
||||||
|
} else if (_toColor(value, &stop->r, &stop->g, &stop->b, nullptr)) {
|
||||||
loader->svgParse->flags = (loader->svgParse->flags | SvgStopStyleFlags::StopColor);
|
loader->svgParse->flags = (loader->svgParse->flags | SvgStopStyleFlags::StopColor);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -2527,7 +2545,13 @@ static bool _attrParseStops(void* data, const char* key, const char* value)
|
||||||
stop->a = _toOpacity(value);
|
stop->a = _toOpacity(value);
|
||||||
}
|
}
|
||||||
} else if (!strcmp(key, "stop-color")) {
|
} else if (!strcmp(key, "stop-color")) {
|
||||||
if (!(loader->svgParse->flags & SvgStopStyleFlags::StopColor)) {
|
if (!strcmp(value, "currentColor")) {
|
||||||
|
if (auto latestColor = _findLatestColor(loader)) {
|
||||||
|
stop->r = latestColor->r;
|
||||||
|
stop->g = latestColor->g;
|
||||||
|
stop->b = latestColor->b;
|
||||||
|
}
|
||||||
|
} else if (!(loader->svgParse->flags & SvgStopStyleFlags::StopColor)) {
|
||||||
_toColor(value, &stop->r, &stop->g, &stop->b, nullptr);
|
_toColor(value, &stop->r, &stop->g, &stop->b, nullptr);
|
||||||
}
|
}
|
||||||
} else if (!strcmp(key, "style")) {
|
} else if (!strcmp(key, "style")) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue