From 82c0a363abbceac6464b62c3571aa3225415c7db Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Fri, 15 Jul 2022 02:14:53 +0200 Subject: tdf#97539; if parent is css style, look one level up if the style attributes are set like it works, however, if it uses a css style like it fails to get the clipPath from the parent, because the css style is the direct parent, thus, check one level up Change-Id: Iff6df95c9fa9da4c2f1a986cca0ad82ab1494353 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137094 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- svgio/inc/svgstyleattributes.hxx | 2 +- svgio/qa/cppunit/SvgImportTest.cxx | 17 ++++++++++++++ .../cppunit/data/ShapeWithClipPathAndCssStyle.svg | 13 +++++++++++ svgio/source/svgreader/svgstyleattributes.cxx | 27 ++++++++++++++++++---- 4 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 svgio/qa/cppunit/data/ShapeWithClipPathAndCssStyle.svg diff --git a/svgio/inc/svgstyleattributes.hxx b/svgio/inc/svgstyleattributes.hxx index 87c17647eeb8..8489430b7546 100644 --- a/svgio/inc/svgstyleattributes.hxx +++ b/svgio/inc/svgstyleattributes.hxx @@ -411,7 +411,7 @@ namespace svgio::svgreader const OUString& getDesc() const { return maDesc; } // ClipPathXLink content - OUString const & getClipPathXLink() const; + OUString getClipPathXLink() const; const SvgClipPathNode* accessClipPathXLink() const; // MaskXLink content diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx index 13f135460017..4724b3a6c8eb 100644 --- a/svgio/qa/cppunit/SvgImportTest.cxx +++ b/svgio/qa/cppunit/SvgImportTest.cxx @@ -59,6 +59,7 @@ class Test : public test::BootstrapFixture, public XmlTestTools void testNoneColor(); void testTdf97936(); void testTdf149893(); + void testShapeWithClipPathAndCssStyle(); void testClipPathAndParentStyle(); void testClipPathAndStyle(); void testShapeWithClipPath(); @@ -101,6 +102,7 @@ public: CPPUNIT_TEST(testNoneColor); CPPUNIT_TEST(testTdf97936); CPPUNIT_TEST(testTdf149893); + CPPUNIT_TEST(testShapeWithClipPathAndCssStyle); CPPUNIT_TEST(testClipPathAndParentStyle); CPPUNIT_TEST(testClipPathAndStyle); CPPUNIT_TEST(testShapeWithClipPath); @@ -598,6 +600,21 @@ void Test::testTdf149893() assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor", "color", "#008000"); } +void Test::testShapeWithClipPathAndCssStyle() +{ + // tdf#97539: Check there is a mask and 3 polygons + Primitive2DSequence aSequenceClipPathAndStyle = parseSvg(u"/svgio/qa/cppunit/data/ShapeWithClipPathAndCssStyle.svg"); + CPPUNIT_ASSERT_EQUAL(1, static_cast(aSequenceClipPathAndStyle.getLength())); + + drawinglayer::Primitive2dXmlDump dumper; + xmlDocUniquePtr pDocument = dumper.dumpAndParse(Primitive2DContainer(aSequenceClipPathAndStyle)); + + CPPUNIT_ASSERT (pDocument); + + assertXPath(pDocument, "/primitive2D/transform/mask/polypolygon/polygon", 2); + assertXPath(pDocument, "/primitive2D/transform/mask/polypolygoncolor/polypolygon/polygon", 1); +} + void Test::testClipPathAndParentStyle() { //Check that fill color, stroke color and stroke-width are inherited from use element diff --git a/svgio/qa/cppunit/data/ShapeWithClipPathAndCssStyle.svg b/svgio/qa/cppunit/data/ShapeWithClipPathAndCssStyle.svg new file mode 100644 index 000000000000..4b6455c64930 --- /dev/null +++ b/svgio/qa/cppunit/data/ShapeWithClipPathAndCssStyle.svg @@ -0,0 +1,13 @@ + + + + + + + + + + diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx index 822ea4c65994..6b676cd952f7 100644 --- a/svgio/source/svgreader/svgstyleattributes.cxx +++ b/svgio/source/svgreader/svgstyleattributes.cxx @@ -1196,11 +1196,10 @@ namespace svgio::svgreader } const SvgClipPathNode* pClip = accessClipPathXLink(); - while(pClip) + if(pClip) { // #i124852# transform may be needed when SvgUnits::userSpaceOnUse pClip->apply(aSource, pTransform); - pClip = pClip->getSvgStyleAttributes()->accessClipPathXLink(); } if(!aSource.empty()) // test again, applied clipPath may have lead to empty geometry @@ -1278,7 +1277,7 @@ namespace svgio::svgreader maClipRule(FillRule::nonzero), maBaselineShift(BaselineShift::Baseline), maBaselineShiftNumber(0), - maResolvingParent(30, 0), + maResolvingParent(31, 0), mbIsClipPathContent(SVGToken::ClipPathNode == mrOwner.getType()), mbStrokeDasharraySet(false) { @@ -2812,9 +2811,27 @@ namespace svgio::svgreader return nullptr; } - OUString const & SvgStyleAttributes::getClipPathXLink() const + OUString SvgStyleAttributes::getClipPathXLink() const { - return maClipPathXLink; + if(!maClipPathXLink.isEmpty()) + { + return maClipPathXLink; + } + + if(getCssStyleParent()) + { + const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); + + if (pSvgStyleAttributes && maResolvingParent[30] < nStyleDepthLimit) + { + ++maResolvingParent[30]; + auto ret = pSvgStyleAttributes->getClipPathXLink(); + --maResolvingParent[30]; + return ret; + } + } + + return OUString(); } const SvgClipPathNode* SvgStyleAttributes::accessClipPathXLink() const -- cgit v1.2.3