drawinglayer/source/tools/primitive2dxmldump.cxx | 17 ++++ svgio/inc/svgstyleattributes.hxx | 5 + svgio/qa/cppunit/SvgImportTest.cxx | 23 +++++- svgio/qa/cppunit/data/tdf94765.svg | 14 +++ svgio/source/svgreader/svgstyleattributes.cxx | 83 +++++++++++++++-------- 5 files changed, 110 insertions(+), 32 deletions(-)
New commits: commit 92267cdb1a45e1f40199136849feb692f7e06d0e Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Thu Sep 19 11:45:20 2019 +0200 Commit: Michael Stahl <michael.st...@cib.de> CommitDate: Wed Sep 25 10:34:04 2019 +0200 tdf#94765: SVGIO: Look for gradient/pattern ids once the file... ... is completely parsed it might happen the element's id the url points to hasn't been parsed yet Reviewed-on: https://gerrit.libreoffice.org/79118 Tested-by: Jenkins Reviewed-by: Xisco FaulĂ <xiscofa...@libreoffice.org> (cherry picked from commit ab1479956568b0d9a6022133cf651f846293aa46) Change-Id: Ia92c9188de5d23f2f992846aa91f3f936aeefacb Reviewed-on: https://gerrit.libreoffice.org/79130 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@cib.de> diff --git a/drawinglayer/source/tools/primitive2dxmldump.cxx b/drawinglayer/source/tools/primitive2dxmldump.cxx index c5d66771343f..65170ae096f2 100644 --- a/drawinglayer/source/tools/primitive2dxmldump.cxx +++ b/drawinglayer/source/tools/primitive2dxmldump.cxx @@ -303,8 +303,21 @@ void Primitive2dXmlDump::decomposeAndWrite( basegfx::B2DPoint aFocusAttribute = rSvgRadialGradientPrimitive2D.getFocal(); rWriter.attribute("radius", OString::number(rSvgRadialGradientPrimitive2D.getRadius())); - rWriter.attribute("x", aFocusAttribute.getX()); - rWriter.attribute("y", aFocusAttribute.getY()); + rWriter.attribute("focusx", aFocusAttribute.getX()); + rWriter.attribute("focusy", aFocusAttribute.getY()); + + rWriter.endElement(); + } + break; + + case PRIMITIVE2D_ID_SVGLINEARGRADIENTPRIMITIVE2D: + { + const SvgLinearGradientPrimitive2D& rSvgLinearGradientPrimitive2D = dynamic_cast<const SvgLinearGradientPrimitive2D&>(*pBasePrimitive); + rWriter.startElement("svglineargradient"); + basegfx::B2DPoint aEndAttribute = rSvgLinearGradientPrimitive2D.getEnd(); + + rWriter.attribute("endx", aEndAttribute.getX()); + rWriter.attribute("endy", aEndAttribute.getY()); rWriter.endElement(); } diff --git a/svgio/inc/svgstyleattributes.hxx b/svgio/inc/svgstyleattributes.hxx index 91eb882135fc..5c89295dec0a 100644 --- a/svgio/inc/svgstyleattributes.hxx +++ b/svgio/inc/svgstyleattributes.hxx @@ -242,6 +242,10 @@ namespace svgio // #121221# Defines if evtl. an empty array *is* set bool mbStrokeDasharraySet : 1; + // tdf#94765 Check id references in gradient/pattern getters + OUString maNodeFillURL; + OUString maNodeStrokeURL; + /// internal helpers void add_fillGradient( const basegfx::B2DPolyPolygon& rPath, @@ -276,6 +280,7 @@ namespace svgio drawinglayer::primitive2d::Primitive2DContainer& rTarget, const basegfx::utils::PointIndexSet* pHelpPointIndices) const; + public: /// local attribute scanner void parseStyleAttribute(SVGToken aSVGToken, const OUString& rContent, diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx index b3ef8abdd4d4..23e6a7ccd445 100644 --- a/svgio/qa/cppunit/SvgImportTest.cxx +++ b/svgio/qa/cppunit/SvgImportTest.cxx @@ -63,6 +63,7 @@ class Test : public test::BootstrapFixture, public XmlTestTools void testMaskText(); void testTdf99994(); void testTdf101237(); + void testTdf94765(); void testBehaviourWhenWidthAndHeightIsOrIsNotSet(); Primitive2DSequence parseSvg(const OUString& aSource); @@ -93,6 +94,7 @@ public: CPPUNIT_TEST(testMaskText); CPPUNIT_TEST(testTdf99994); CPPUNIT_TEST(testTdf101237); + CPPUNIT_TEST(testTdf94765); CPPUNIT_TEST(testBehaviourWhenWidthAndHeightIsOrIsNotSet); CPPUNIT_TEST_SUITE_END(); }; @@ -396,8 +398,8 @@ void Test::testTdf97542_2() CPPUNIT_ASSERT (pDocument); - assertXPath(pDocument, "/primitive2D/transform/objectinfo/svgradialgradient[1]", "x", "1"); - assertXPath(pDocument, "/primitive2D/transform/objectinfo/svgradialgradient[1]", "y", "1"); + assertXPath(pDocument, "/primitive2D/transform/objectinfo/svgradialgradient[1]", "focusx", "1"); + assertXPath(pDocument, "/primitive2D/transform/objectinfo/svgradialgradient[1]", "focusy", "1"); assertXPath(pDocument, "/primitive2D/transform/objectinfo/svgradialgradient[1]", "radius", "3"); } @@ -634,6 +636,23 @@ void Test::testTdf101237() assertXPath(pDocument, "/primitive2D/transform/polypolygonstroke/line", "width", "5"); } +void Test::testTdf94765() +{ + Primitive2DSequence aSequenceTdf94765 = parseSvg("/svgio/qa/cppunit/data/tdf94765.svg"); + CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceTdf94765.getLength())); + + drawinglayer::tools::Primitive2dXmlDump dumper; + xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceTdf94765)); + + CPPUNIT_ASSERT (pDocument); + + //Check that both rectangles use the gradient as fill + assertXPath(pDocument, "/primitive2D/transform/transform/svglineargradient[1]", "endx", "2"); + assertXPath(pDocument, "/primitive2D/transform/transform/svglineargradient[1]", "endy", "1"); + assertXPath(pDocument, "/primitive2D/transform/transform/svglineargradient[2]", "endx", "0"); + assertXPath(pDocument, "/primitive2D/transform/transform/svglineargradient[2]", "endy", "0"); +} + void Test::testBehaviourWhenWidthAndHeightIsOrIsNotSet() { // This test checks the behaviour when width and height attributes diff --git a/svgio/qa/cppunit/data/tdf94765.svg b/svgio/qa/cppunit/data/tdf94765.svg new file mode 100644 index 000000000000..009bfc8ed1e4 --- /dev/null +++ b/svgio/qa/cppunit/data/tdf94765.svg @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8"?> +<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" + width="841.9px" height="595.3px" viewBox="0 0 841.9 595.3" style="enable-background:new 0 0 841.9 595.3;" xml:space="preserve" + > +<style type="text/css"> + .st1{fill:url(#SVGID_1_);stroke:#000000;stroke-miterlimit:10;} +</style> +<linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="432.1587" y1="340.3492" x2="770.254" y2="340.3492"> + <stop offset="0" style="stop-color:#DBDBDB"/> + <stop offset="1" style="stop-color:#737373"/> +</linearGradient> +<rect x="70.3" y="48.3" fill="url(#SVGID_1_)" width="338.1" height="252.4"/> +<rect x="432.2" y="214.2" class="st1" width="338.1" height="252.4"/> +</svg> diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx index 9b6b81cbcdb2..cd3d14159aa0 100644 --- a/svgio/source/svgreader/svgstyleattributes.cxx +++ b/svgio/source/svgreader/svgstyleattributes.cxx @@ -1336,19 +1336,7 @@ namespace svgio } else if(!aURL.isEmpty()) { - const SvgNode* pNode = mrOwner.getDocument().findSvgNodeById(aURL); - - if(pNode) - { - if(SVGTokenLinearGradient == pNode->getType() || SVGTokenRadialGradient == pNode->getType()) - { - mpSvgGradientNodeFill = static_cast< const SvgGradientNode* >(pNode); - } - else if(SVGTokenPattern == pNode->getType()) - { - mpSvgPatternNodeFill = static_cast< const SvgPatternNode* >(pNode); - } - } + maNodeFillURL = aURL; } break; } @@ -1393,19 +1381,7 @@ namespace svgio } else if(!aURL.isEmpty()) { - const SvgNode* pNode = mrOwner.getDocument().findSvgNodeById(aURL); - - if(pNode) - { - if(SVGTokenLinearGradient == pNode->getType() || SVGTokenRadialGradient == pNode->getType()) - { - mpSvgGradientNodeStroke = static_cast< const SvgGradientNode* >(pNode); - } - else if(SVGTokenPattern == pNode->getType()) - { - mpSvgPatternNodeStroke = static_cast< const SvgPatternNode* >(pNode); - } - } + maNodeStrokeURL = aURL; } break; } @@ -2031,7 +2007,7 @@ namespace svgio return &maFill.getBColor(); } } - else if (!mpSvgGradientNodeFill && !mpSvgPatternNodeFill) + else if (maNodeFillURL.isEmpty()) { const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); @@ -2076,7 +2052,7 @@ namespace svgio return &maStroke.getBColor(); } } - else if (!mpSvgGradientNodeStroke && !mpSvgPatternNodeStroke) + else if (maNodeStrokeURL.isEmpty()) { const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); @@ -2112,6 +2088,18 @@ namespace svgio } else if (!maFill.isSet() && !mpSvgPatternNodeFill) { + if (!maNodeFillURL.isEmpty()) + { + const SvgNode* pNode = mrOwner.getDocument().findSvgNodeById(maNodeFillURL); + + if(pNode) + { + if(SVGTokenLinearGradient == pNode->getType() || SVGTokenRadialGradient == pNode->getType()) + { + return static_cast< const SvgGradientNode* >(pNode); + } + } + } const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); if (pSvgStyleAttributes && maResolvingParent[2] < nStyleDepthLimit) @@ -2134,6 +2122,19 @@ namespace svgio } else if (!maStroke.isSet() && !mpSvgPatternNodeStroke) { + if(!maNodeStrokeURL.isEmpty()) + { + const SvgNode* pNode = mrOwner.getDocument().findSvgNodeById(maNodeStrokeURL); + + if(pNode) + { + if(SVGTokenLinearGradient == pNode->getType() || SVGTokenRadialGradient == pNode->getType()) + { + return static_cast< const SvgGradientNode* >(pNode); + } + } + } + const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); if (pSvgStyleAttributes && maResolvingParent[3] < nStyleDepthLimit) @@ -2156,6 +2157,19 @@ namespace svgio } else if (!maFill.isSet() && !mpSvgGradientNodeFill) { + if (!maNodeFillURL.isEmpty()) + { + const SvgNode* pNode = mrOwner.getDocument().findSvgNodeById(maNodeFillURL); + + if(pNode) + { + if(SVGTokenPattern == pNode->getType()) + { + return static_cast< const SvgPatternNode* >(pNode); + } + } + } + const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); if (pSvgStyleAttributes && maResolvingParent[4] < nStyleDepthLimit) @@ -2178,6 +2192,19 @@ namespace svgio } else if (!maStroke.isSet() && !mpSvgGradientNodeStroke) { + if(!maNodeStrokeURL.isEmpty()) + { + const SvgNode* pNode = mrOwner.getDocument().findSvgNodeById(maNodeStrokeURL); + + if(pNode) + { + if(SVGTokenPattern == pNode->getType()) + { + return static_cast< const SvgPatternNode* >(pNode); + } + } + } + const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); if (pSvgStyleAttributes && maResolvingParent[5] < nStyleDepthLimit) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits