tdf#149673: only check opacity from parent...
... if it has a local css style
Because it's the first in the style stack
Partially reverts 3e0e67a152e9631574e28dacb6e06a96f03ebca2
"tdf#155932: tdf#97717: only apply opacity when primitive"
Change-Id: I6a6bf08a519c84ac58c6111fd7da308cbf8a3021
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154270
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154274
diff --git a/svgio/inc/svgstyleattributes.hxx b/svgio/inc/svgstyleattributes.hxx
index b54e3cd..52876ea 100644
--- a/svgio/inc/svgstyleattributes.hxx
+++ b/svgio/inc/svgstyleattributes.hxx
@@ -293,8 +293,7 @@ namespace svgio::svgreader
void add_postProcess(
drawinglayer::primitive2d::Primitive2DContainer& rTarget,
drawinglayer::primitive2d::Primitive2DContainer&& rSource,
const std::optional<basegfx::B2DHomMatrix>& pTransform,
bool bIsPrimitive) const;
const std::optional<basegfx::B2DHomMatrix>& pTransform) const;
/// helper to set mpCssStyleParent temporarily for CSS style hierarchies
void setCssStyleParent(const SvgStyleAttributes* pNew) { mpCssStyleParent = pNew; }
diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx
index 0378875..5b733e9 100644
--- a/svgio/qa/cppunit/SvgImportTest.cxx
+++ b/svgio/qa/cppunit/SvgImportTest.cxx
@@ -831,6 +831,22 @@ CPPUNIT_TEST_FIXTURE(Test, testRGBColor)
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor/polypolygon", "maxy", "110");
}
CPPUNIT_TEST_FIXTURE(Test, testTdf149673)
{
Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/tdf149673.svg");
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence.getLength()));
drawinglayer::Primitive2dXmlDump dumper;
xmlDocUniquePtr pDocument = dumper.dumpAndParse(Primitive2DContainer(aSequence));
CPPUNIT_ASSERT (pDocument);
assertXPath(pDocument, "/primitive2D/transform/unifiedtransparence", "transparence", "90");
assertXPath(pDocument, "/primitive2D/transform/unifiedtransparence/polypolygoncolor[1]", "color", "#ff0000");
assertXPath(pDocument, "/primitive2D/transform/unifiedtransparence/polypolygoncolor[2]", "color", "#00ff00");
assertXPath(pDocument, "/primitive2D/transform/unifiedtransparence/polypolygoncolor[3]", "color", "#0000ff");
}
CPPUNIT_TEST_FIXTURE(Test, testRGBAColor)
{
Primitive2DSequence aSequenceRGBAColor = parseSvg(u"/svgio/qa/cppunit/data/RGBAColor.svg");
diff --git a/svgio/qa/cppunit/data/tdf149673.svg b/svgio/qa/cppunit/data/tdf149673.svg
new file mode 100644
index 0000000..f73b995
--- /dev/null
+++ b/svgio/qa/cppunit/data/tdf149673.svg
@@ -0,0 +1,7 @@
<svg id="svg1" viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
<g id="g1" opacity=".1">
<circle id="circle1" cx="100" cy="60" fill="#f00" r="40"/>
<circle id="circle2" cx="70" cy="100" fill="#0f0" r="40"/>
<circle id="circle3" cx="130" cy="100" fill="#00f" r="40"/>
</g>
</svg>
diff --git a/svgio/source/svgreader/svganode.cxx b/svgio/source/svgreader/svganode.cxx
index 83dd7c5..e700574 100644
--- a/svgio/source/svgreader/svganode.cxx
+++ b/svgio/source/svgreader/svganode.cxx
@@ -94,7 +94,7 @@ namespace svgio::svgreader
if(!aContent.empty())
{
pStyle->add_postProcess(rTarget, std::move(aContent), getTransform(), true);
pStyle->add_postProcess(rTarget, std::move(aContent), getTransform());
}
}
}
diff --git a/svgio/source/svgreader/svgcirclenode.cxx b/svgio/source/svgreader/svgcirclenode.cxx
index 363e85d..513c128 100644
--- a/svgio/source/svgreader/svgcirclenode.cxx
+++ b/svgio/source/svgreader/svgcirclenode.cxx
@@ -135,7 +135,7 @@ namespace svgio::svgreader
if(!aNewTarget.empty())
{
pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform(), true);
pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform());
}
}
} // end of namespace svgio::svgreader
diff --git a/svgio/source/svgreader/svgellipsenode.cxx b/svgio/source/svgreader/svgellipsenode.cxx
index a822ef7..8f203fc 100644
--- a/svgio/source/svgreader/svgellipsenode.cxx
+++ b/svgio/source/svgreader/svgellipsenode.cxx
@@ -150,7 +150,7 @@ namespace svgio::svgreader
if(!aNewTarget.empty())
{
pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform(), true);
pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform());
}
}
} // end of namespace svgio::svgreader
diff --git a/svgio/source/svgreader/svggnode.cxx b/svgio/source/svgreader/svggnode.cxx
index e59db29..d833a6f 100644
--- a/svgio/source/svgreader/svggnode.cxx
+++ b/svgio/source/svgreader/svggnode.cxx
@@ -97,7 +97,7 @@ namespace svgio::svgreader
if(!aContent.empty())
{
pStyle->add_postProcess(rTarget, std::move(aContent), getTransform(), false);
pStyle->add_postProcess(rTarget, std::move(aContent), getTransform());
}
}
}
diff --git a/svgio/source/svgreader/svgimagenode.cxx b/svgio/source/svgreader/svgimagenode.cxx
index fa7cbe6..2ce6ce4 100644
--- a/svgio/source/svgreader/svgimagenode.cxx
+++ b/svgio/source/svgreader/svgimagenode.cxx
@@ -340,7 +340,7 @@ namespace svgio::svgreader
}
// embed and add to rTarget, take local extra-transform into account
pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform(), true);
pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform());
}
} // end of namespace svgio::svgreader
diff --git a/svgio/source/svgreader/svglinenode.cxx b/svgio/source/svgreader/svglinenode.cxx
index 7f433c7..ea1ab343 100644
--- a/svgio/source/svgreader/svglinenode.cxx
+++ b/svgio/source/svgreader/svglinenode.cxx
@@ -145,7 +145,7 @@ namespace svgio::svgreader
if(!aNewTarget.empty())
{
pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform(), true);
pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform());
}
}
} // end of namespace svgio::svgreader
diff --git a/svgio/source/svgreader/svgpathnode.cxx b/svgio/source/svgreader/svgpathnode.cxx
index f34d4d3..d52114a 100644
--- a/svgio/source/svgreader/svgpathnode.cxx
+++ b/svgio/source/svgreader/svgpathnode.cxx
@@ -108,7 +108,7 @@ namespace svgio::svgreader
if(!aNewTarget.empty())
{
pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform(), true);
pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform());
}
}
}
diff --git a/svgio/source/svgreader/svgpolynode.cxx b/svgio/source/svgreader/svgpolynode.cxx
index 38a908a..74cd722 100644
--- a/svgio/source/svgreader/svgpolynode.cxx
+++ b/svgio/source/svgreader/svgpolynode.cxx
@@ -105,7 +105,7 @@ namespace svgio::svgreader
if(!aNewTarget.empty())
{
pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform(), true);
pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform());
}
}
}
diff --git a/svgio/source/svgreader/svgrectnode.cxx b/svgio/source/svgreader/svgrectnode.cxx
index 782887b..291d854 100644
--- a/svgio/source/svgreader/svgrectnode.cxx
+++ b/svgio/source/svgreader/svgrectnode.cxx
@@ -207,7 +207,7 @@ namespace svgio::svgreader
if(!aNewTarget.empty())
{
pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform(), true);
pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform());
}
}
} // end of namespace svgio::svgreader
diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx
index 9a83c2d..6cc76cbd 100644
--- a/svgio/source/svgreader/svgstyleattributes.cxx
+++ b/svgio/source/svgreader/svgstyleattributes.cxx
@@ -1163,8 +1163,7 @@ namespace svgio::svgreader
void SvgStyleAttributes::add_postProcess(
drawinglayer::primitive2d::Primitive2DContainer& rTarget,
drawinglayer::primitive2d::Primitive2DContainer&& rSource,
const std::optional<basegfx::B2DHomMatrix>& pTransform,
bool bIsPrimitive) const
const std::optional<basegfx::B2DHomMatrix>& pTransform) const
{
const double fOpacity(getOpacity().solve(mrOwner));
@@ -1175,20 +1174,15 @@ namespace svgio::svgreader
drawinglayer::primitive2d::Primitive2DContainer aSource(std::move(rSource));
// tdf#97717: only apply opacity when it's a primitive, otherwise, it might be
// applied more than once, since getOpacity() checks the parents
if (bIsPrimitive)
if(basegfx::fTools::less(fOpacity, 1.0))
{
if(basegfx::fTools::less(fOpacity, 1.0))
{
// embed in UnifiedTransparencePrimitive2D
const drawinglayer::primitive2d::Primitive2DReference xRef(
new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
std::move(aSource),
1.0 - fOpacity));
// embed in UnifiedTransparencePrimitive2D
const drawinglayer::primitive2d::Primitive2DReference xRef(
new drawinglayer::primitive2d::UnifiedTransparencePrimitive2D(
std::move(aSource),
1.0 - fOpacity));
aSource = drawinglayer::primitive2d::Primitive2DContainer { xRef };
}
aSource = drawinglayer::primitive2d::Primitive2DContainer { xRef };
}
if(pTransform)
@@ -1298,7 +1292,7 @@ namespace svgio::svgreader
maClipRule(FillRule::notset),
maBaselineShift(BaselineShift::Baseline),
maBaselineShiftNumber(0),
maResolvingParent(30, 0),
maResolvingParent(29, 0),
mbIsClipPathContent(SVGToken::ClipPathNode == mrOwner.getType()),
mbStrokeDasharraySet(false)
{
@@ -2289,14 +2283,16 @@ namespace svgio::svgreader
return maOpacity;
}
const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
if (pSvgStyleAttributes && maResolvingParent[8] < nStyleDepthLimit)
// This is called from add_postProcess so only check the parent style
// if it has a local css style, because it's the first in the stack
if(mrOwner.hasLocalCssStyle())
{
++maResolvingParent[8];
auto ret = pSvgStyleAttributes->getOpacity();
--maResolvingParent[8];
return ret;
const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
if (pSvgStyleAttributes && pSvgStyleAttributes->maOpacity.isSet())
{
return pSvgStyleAttributes->maOpacity;
}
}
// default is 1
@@ -3082,11 +3078,11 @@ namespace svgio::svgreader
{
const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
if (pSvgStyleAttributes && maResolvingParent[29] < nStyleDepthLimit)
if (pSvgStyleAttributes && maResolvingParent[8] < nStyleDepthLimit)
{
++maResolvingParent[29];
++maResolvingParent[8];
const SvgNumber aParentNumber = pSvgStyleAttributes->getBaselineShiftNumber();
--maResolvingParent[29];
--maResolvingParent[8];
return SvgNumber(
aParentNumber.getNumber() * maBaselineShiftNumber.getNumber() * 0.01,
diff --git a/svgio/source/svgreader/svgtextnode.cxx b/svgio/source/svgreader/svgtextnode.cxx
index 35e130a..5b8cc31 100644
--- a/svgio/source/svgreader/svgtextnode.cxx
+++ b/svgio/source/svgreader/svgtextnode.cxx
@@ -251,7 +251,7 @@ namespace svgio::svgreader
if(!aNewTarget.empty())
{
pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform(), true);
pStyle->add_postProcess(rTarget, std::move(aNewTarget), getTransform());
}
}
diff --git a/svgio/source/svgreader/svgusenode.cxx b/svgio/source/svgreader/svgusenode.cxx
index b0fed16..312f815 100644
--- a/svgio/source/svgreader/svgusenode.cxx
+++ b/svgio/source/svgreader/svgusenode.cxx
@@ -172,7 +172,7 @@ namespace svgio::svgreader
if(fOpacity > 0.0 && Display::None != getDisplay())
{
pStyle->add_postProcess(rTarget, std::move(aNewTarget), aTransform, false);
pStyle->add_postProcess(rTarget, std::move(aNewTarget), aTransform);
}
}
}