From f568b2346c06a82768452fdfb0b3fe9597f8151a Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Thu, 11 Jul 2024 14:22:58 +0200 Subject: tdf#161985: getOpacity is also called from other places Partially revert 56039daae4a436d7ea1b093a02cf0e8ad3bda4a9 "tdf#149673: only check opacity from parent..." to make getOpacity behave as before and move the new behaviour of getOpacity inside add_postProcess Change-Id: If475cddbc4967308fa06adacda621cb3790c6f70 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170350 Tested-by: Jenkins Reviewed-by: Aron Budea --- svgio/qa/cppunit/SvgImportTest.cxx | 13 ++++++++++ svgio/qa/cppunit/data/tdf161985.svg | 14 ++++++++++ svgio/source/svgreader/svgstyleattributes.cxx | 37 +++++++++++++++++++-------- 3 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 svgio/qa/cppunit/data/tdf161985.svg (limited to 'svgio') diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx index 280cffc5c8a5..0f2478860d9b 100644 --- a/svgio/qa/cppunit/SvgImportTest.cxx +++ b/svgio/qa/cppunit/SvgImportTest.cxx @@ -447,6 +447,19 @@ CPPUNIT_TEST_FIXTURE(Test, testFontsizeRelative) assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]"_ostr, "familyname"_ostr, u"DejaVu Serif"_ustr); } +CPPUNIT_TEST_FIXTURE(Test, testTdf161985) +{ + xmlDocUniquePtr pDocument = dumpAndParseSvg(u"/svgio/qa/cppunit/data/tdf161985.svg"); + + // Without the fix in place, this test would have failed with + // - Expected: 0 + // - Actual : 1 + assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor"_ostr, 0); + + assertXPath(pDocument, "/primitive2D/transform/textsimpleportion"_ostr, 1); + assertXPath(pDocument, "/primitive2D/transform/textsimpleportion"_ostr, "text"_ostr, u"This is a test file."_ustr); +} + CPPUNIT_TEST_FIXTURE(Test, testTdf160386) { xmlDocUniquePtr pDocument = dumpAndParseSvg(u"/svgio/qa/cppunit/data/tdf160386.svg"); diff --git a/svgio/qa/cppunit/data/tdf161985.svg b/svgio/qa/cppunit/data/tdf161985.svg new file mode 100644 index 000000000000..781811b15dbf --- /dev/null +++ b/svgio/qa/cppunit/data/tdf161985.svg @@ -0,0 +1,14 @@ + + + + + + + + This is a test file. + + + diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx index 485142240871..5fe78f8b58d0 100644 --- a/svgio/source/svgreader/svgstyleattributes.cxx +++ b/svgio/source/svgreader/svgstyleattributes.cxx @@ -1181,7 +1181,24 @@ namespace svgio::svgreader drawinglayer::primitive2d::Primitive2DContainer&& rSource, const std::optional& pTransform) const { - const double fOpacity(getOpacity().solve(mrOwner)); + // default is 1 + double fOpacity(1.0); + + if(maOpacity.isSet()) + { + fOpacity = maOpacity.solve(mrOwner); + } + else + { + // if opacity is not set, check the css style + if (const SvgStyleAttributes* pSvgStyleAttributes = getCssStyleParent()) + { + if (pSvgStyleAttributes->maOpacity.isSet()) + { + fOpacity = pSvgStyleAttributes->maOpacity.solve(mrOwner); + } + } + } if(basegfx::fTools::equalZero(fOpacity)) { @@ -1303,7 +1320,7 @@ namespace svgio::svgreader maBaselineShift(BaselineShift::Baseline), maBaselineShiftNumber(0), maDominantBaseline(DominantBaseline::Auto), - maResolvingParent(34, 0), + maResolvingParent(35, 0), mbStrokeDasharraySet(false), mbContextFill(false), mbContextStroke(false), @@ -2411,16 +2428,14 @@ namespace svgio::svgreader return maOpacity; } - // 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()) - { - const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); + const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); - if (pSvgStyleAttributes && pSvgStyleAttributes->maOpacity.isSet()) - { - return pSvgStyleAttributes->maOpacity; - } + if (pSvgStyleAttributes && maResolvingParent[34] < nStyleDepthLimit) + { + ++maResolvingParent[34]; + auto ret = pSvgStyleAttributes->getOpacity(); + --maResolvingParent[34]; + return ret; } // default is 1 -- cgit