From feb71ff36c537993ffd4aac8d6b61e5f67289422 Mon Sep 17 00:00:00 2001 From: Mira Grudzinska Date: Sun, 27 Jun 2021 16:07:24 +0200 Subject: [PATCH] svg_loader: currentColor - inheritance from a parent The 'currentColor' attribute value was not inherited. Fixed. --- src/loaders/svg/tvgSvgLoader.cpp | 15 ++++++++++++++- src/loaders/svg/tvgSvgLoaderCommon.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/loaders/svg/tvgSvgLoader.cpp b/src/loaders/svg/tvgSvgLoader.cpp index a6402d48..5e6c1349 100644 --- a/src/loaders/svg/tvgSvgLoader.cpp +++ b/src/loaders/svg/tvgSvgLoader.cpp @@ -781,6 +781,7 @@ static void _handlePaintAttr(SvgPaint* paint, const char* value) static void _handleColorAttr(TVG_UNUSED SvgLoaderData* loader, SvgNode* node, const char* value) { SvgStyleProperty* style = node->style; + style->curColorSet = true; _toColor(value, &style->r, &style->g, &style->b, nullptr); } @@ -1034,7 +1035,9 @@ static SvgNode* _createNode(SvgNode* parent, SvgNodeType type) //Default fill opacity is 1 node->style->fill.opacity = 255; node->style->opacity = 255; - + //Default current color is not set + node->style->fill.paint.curColor = false; + node->style->curColorSet = false; //Default fill rule is nonzero node->style->fill.fillRule = SvgFillRule::Winding; @@ -1042,6 +1045,8 @@ static SvgNode* _createNode(SvgNode* parent, SvgNodeType type) node->style->stroke.paint.none = true; //Default stroke opacity is 1 node->style->stroke.opacity = 255; + //Default stroke current color is not set + node->style->stroke.paint.curColor = false; //Default stroke width is 1 node->style->stroke.width = 1; //Default line cap is butt @@ -2287,6 +2292,10 @@ static void _styleInherit(SvgStyleProperty* child, const SvgStyleProperty* paren child->fill.paint.none = parent->fill.paint.none; child->fill.paint.curColor = parent->fill.paint.curColor; if (parent->fill.paint.url) child->fill.paint.url = _copyId(parent->fill.paint.url->c_str()); + } else if (child->fill.paint.curColor && !child->curColorSet) { + child->r = parent->r; + child->g = parent->g; + child->b = parent->b; } if (!((int)child->fill.flags & (int)SvgFillFlags::Opacity)) { child->fill.opacity = parent->fill.opacity; @@ -2302,6 +2311,10 @@ static void _styleInherit(SvgStyleProperty* child, const SvgStyleProperty* paren child->stroke.paint.none = parent->stroke.paint.none; child->stroke.paint.curColor = parent->stroke.paint.curColor; child->stroke.paint.url = parent->stroke.paint.url ? _copyId(parent->stroke.paint.url->c_str()) : nullptr; + } else if (child->stroke.paint.curColor && !child->curColorSet) { + child->r = parent->r; + child->g = parent->g; + child->b = parent->b; } if (!((int)child->stroke.flags & (int)SvgStrokeFlags::Opacity)) { child->stroke.opacity = parent->stroke.opacity; diff --git a/src/loaders/svg/tvgSvgLoaderCommon.h b/src/loaders/svg/tvgSvgLoaderCommon.h index e5ed3d7e..86e2c14e 100644 --- a/src/loaders/svg/tvgSvgLoaderCommon.h +++ b/src/loaders/svg/tvgSvgLoaderCommon.h @@ -289,6 +289,7 @@ struct SvgStyleProperty uint8_t r; uint8_t g; uint8_t b; + bool curColorSet; }; struct SvgNode