diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2022-07-15 02:14:53 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2022-07-26 11:31:29 +0200 |
commit | 9e18bc8eca8bf340f765d2eb2d8bcad83b4412b3 (patch) | |
tree | e05d546e98845dd7ef0f4a0ced666246bbddbaac | |
parent | tdf#141294 Use DPI scale factor for sidebar width limit in config (diff) | |
download | core-9e18bc8eca8bf340f765d2eb2d8bcad83b4412b3.tar.gz core-9e18bc8eca8bf340f765d2eb2d8bcad83b4412b3.zip |
tdf#97539; if parent is css style, look one level up
if the style attributes are set like
<rect x="10" y="10" width="100" height="100" fill="#00D000"
clip-path="url(#myClip)"/>
it works, however, if it uses a css style like
<rect x="10" y="10" width="100" height="100" style="fill:#00D000"
clip-path="url(#myClip)"/>
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 <xiscofauli@libreoffice.org>
(cherry picked from commit 1eff99718e3cfc01961dc798d708e574f669b200)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137064
Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137217
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
-rw-r--r-- | svgio/inc/svgstyleattributes.hxx | 2 | ||||
-rw-r--r-- | svgio/qa/cppunit/SvgImportTest.cxx | 17 | ||||
-rw-r--r-- | svgio/qa/cppunit/data/ShapeWithClipPathAndCssStyle.svg | 13 | ||||
-rw-r--r-- | svgio/source/svgreader/svgstyleattributes.cxx | 27 |
4 files changed, 53 insertions, 6 deletions
diff --git a/svgio/inc/svgstyleattributes.hxx b/svgio/inc/svgstyleattributes.hxx index 3fbb7a2ff324..8db2fa0676f6 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 8dc8a3989a08..9a78f6a18bae 100644 --- a/svgio/qa/cppunit/SvgImportTest.cxx +++ b/svgio/qa/cppunit/SvgImportTest.cxx @@ -58,6 +58,7 @@ class Test : public test::BootstrapFixture, public XmlTestTools void testNoneColor(); void testTdf97936(); void testTdf149893(); + void testShapeWithClipPathAndCssStyle(); void testClipPathAndParentStyle(); void testClipPathAndStyle(); void testi125329(); @@ -97,6 +98,7 @@ public: CPPUNIT_TEST(testNoneColor); CPPUNIT_TEST(testTdf97936); CPPUNIT_TEST(testTdf149893); + CPPUNIT_TEST(testShapeWithClipPathAndCssStyle); CPPUNIT_TEST(testClipPathAndParentStyle); CPPUNIT_TEST(testClipPathAndStyle); CPPUNIT_TEST(testi125329); @@ -555,6 +557,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<int>(aSequenceClipPathAndStyle.getLength())); + + drawinglayer::Primitive2dXmlDump dumper; + xmlDocUniquePtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<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 @@ +<?xml version="1.0"?> +<svg width="120" height="120" + viewPort="0 0 120 120" version="1.1" + xmlns="http://www.w3.org/2000/svg"> + + <clipPath id="myClip"> + <rect x="30" y="30" width="20" height="20"/> + <rect x="70" y="70" width="20" height="20"/> + </clipPath> + + <rect x="10" y="10" width="100" height="100" style="fill:#00D000" + clip-path="url(#myClip)"/> +</svg> diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx index df200e40f428..891c5ff76c7e 100644 --- a/svgio/source/svgreader/svgstyleattributes.cxx +++ b/svgio/source/svgreader/svgstyleattributes.cxx @@ -1188,11 +1188,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 @@ -1270,7 +1269,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) { @@ -2805,9 +2804,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 |