From b6a62f07557fe4ae0931e0f3e0f306d2f69b116b Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Fri, 5 Feb 2016 00:25:58 +0100 Subject: tdf#97542: SVGIO: First check the current fill attribute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Differenciate when gradient is defined in the text element or in its parents Add unit tests Change-Id: I85b09f72fbb1a3c8d2fa7350b4396b5bf924277f Reviewed-on: https://gerrit.libreoffice.org/22131 Tested-by: Jenkins Reviewed-by: Jochen Nitschke Reviewed-by: Xisco FaulĂ­ --- svgio/qa/cppunit/SvgImportTest.cxx | 32 +++++++++++++++++++++++++++ svgio/qa/cppunit/data/tdf97542_1.svg | 15 +++++++++++++ svgio/qa/cppunit/data/tdf97542_2.svg | 15 +++++++++++++ svgio/source/svgreader/svgstyleattributes.cxx | 15 ++++++++----- 4 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 svgio/qa/cppunit/data/tdf97542_1.svg create mode 100644 svgio/qa/cppunit/data/tdf97542_2.svg (limited to 'svgio') diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx index 50a7ef7231f2..921422387f5f 100644 --- a/svgio/qa/cppunit/SvgImportTest.cxx +++ b/svgio/qa/cppunit/SvgImportTest.cxx @@ -45,6 +45,8 @@ class Test : public test::BootstrapFixture, public XmlTestTools void testTdf45771(); void testTdf85770(); void testTdf79163(); + void testTdf97542_1(); + void testTdf97542_2(); Primitive2DSequence parseSvg(const char* aSource); @@ -60,6 +62,8 @@ public: CPPUNIT_TEST(testTdf45771); CPPUNIT_TEST(testTdf85770); CPPUNIT_TEST(testTdf79163); + CPPUNIT_TEST(testTdf97542_1); + CPPUNIT_TEST(testTdf97542_2); CPPUNIT_TEST_SUITE_END(); }; @@ -237,6 +241,34 @@ void Test::testTdf79163() assertXPath(pDocument, "/primitive2D/transform/mask/unifiedtransparence", "transparence", "0"); } +void Test::testTdf97542_1() +{ + Primitive2DSequence aSequenceTdf97542_1 = parseSvg("/svgio/qa/cppunit/data/tdf97542_1.svg"); + CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceTdf97542_1.getLength()); + + Primitive2dXmlDump dumper; + xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer(aSequenceTdf97542_1)); + + CPPUNIT_ASSERT (pDocument); + + assertXPath(pDocument, "/primitive2D/transform/objectinfo/textsimpleportion", "fontcolor", "#ffff00"); +} + +void Test::testTdf97542_2() +{ + Primitive2DSequence aSequenceTdf97542_2 = parseSvg("/svgio/qa/cppunit/data/tdf97542_2.svg"); + CPPUNIT_ASSERT_EQUAL(1, (int)aSequenceTdf97542_2.getLength()); + + Primitive2dXmlDump dumper; + xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer(aSequenceTdf97542_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]", "radius", "3"); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Test); } diff --git a/svgio/qa/cppunit/data/tdf97542_1.svg b/svgio/qa/cppunit/data/tdf97542_1.svg new file mode 100644 index 000000000000..328bd971ac8e --- /dev/null +++ b/svgio/qa/cppunit/data/tdf97542_1.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + Layer 1 + + Text + + diff --git a/svgio/qa/cppunit/data/tdf97542_2.svg b/svgio/qa/cppunit/data/tdf97542_2.svg new file mode 100644 index 000000000000..03cee9683e0b --- /dev/null +++ b/svgio/qa/cppunit/data/tdf97542_2.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + Layer 1 + + Text + + diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx index 2ae8a06054a4..1f592e7d73d7 100644 --- a/svgio/source/svgreader/svgstyleattributes.cxx +++ b/svgio/source/svgreader/svgstyleattributes.cxx @@ -263,6 +263,9 @@ namespace svgio // dismantle to geometry and add needed primitives const basegfx::BColor* pFill = getFill(); const SvgGradientNode* pFillGradient = getSvgGradientNodeFill(); + const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle(); + const SvgGradientNode* pParentFillGradient = + pSvgStyleAttributes ? pSvgStyleAttributes->getSvgGradientNodeFill() : nullptr; const SvgPatternNode* pFillPattern = getSvgPatternNodeFill(); const basegfx::BColor* pStroke = getStroke(); const SvgGradientNode* pStrokeGradient = getSvgGradientNodeStroke(); @@ -303,20 +306,20 @@ namespace svgio const bool bStrokeUsed(pStroke || pStrokeGradient || pStrokePattern); + if(pFill && (!pFillGradient || pParentFillGradient)) + { + // add the already prepared primitives for single color fill + rTarget.append(rSource); + } // add fill. Use geometry even for simple color fill when stroke // is used, else text rendering and the geometry-based stroke will // normally not really match optically due to diverse system text // renderers - if(aMergedArea.count() && (pFillGradient || pFillPattern || bStrokeUsed)) + else if(aMergedArea.count() && (pFillGradient || pFillPattern || bStrokeUsed)) { // create text fill content based on geometry add_fill(aMergedArea, rTarget, aMergedArea.getB2DRange()); } - else if(pFill) - { - // add the already prepared primitives for single color fill - rTarget.append(rSource); - } // add stroke if(aMergedArea.count() && bStrokeUsed) -- cgit