summaryrefslogtreecommitdiff
path: root/svgio
diff options
context:
space:
mode:
authorXisco Fauli <anistenis@gmail.com>2016-02-05 00:25:58 +0100
committerXisco Faulí <anistenis@gmail.com>2016-02-11 17:17:06 +0000
commitb6a62f07557fe4ae0931e0f3e0f306d2f69b116b (patch)
tree10539ba9812c0048bb23684c9502a424b67f2c0a /svgio
parent54e3ea8a86a309990f5edf78948bfe18dd2de96b (diff)
tdf#97542: SVGIO: First check the current fill attribute
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 <ci@libreoffice.org> Reviewed-by: Jochen Nitschke <j.nitschke+logerrit@ok.de> Reviewed-by: Xisco Faulí <anistenis@gmail.com>
Diffstat (limited to 'svgio')
-rw-r--r--svgio/qa/cppunit/SvgImportTest.cxx32
-rw-r--r--svgio/qa/cppunit/data/tdf97542_1.svg15
-rw-r--r--svgio/qa/cppunit/data/tdf97542_2.svg15
-rw-r--r--svgio/source/svgreader/svgstyleattributes.cxx15
4 files changed, 71 insertions, 6 deletions
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<Primitive2DContainer>(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<Primitive2DContainer>(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 @@
+<?xml version="1.0"?>
+<svg width="200" height="50" xmlns="http://www.w3.org/2000/svg">
+ <!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
+ <defs>
+ <radialGradient id="svg_2" cx="0.5" cy="0.5" r="0.5">
+ <stop offset="0" stop-color="#ff0000"/>
+ <stop offset="1" stop-color="#000000"/>
+ </radialGradient>
+ </defs>
+ <g fill="url(#svg_2)" >
+ <title>Layer 1</title>
+ <rect id="svg_1" height="50" width="200" y="0" x="0"/>
+ <text x="50" y="40" id="svg_12" font-size="48" font-family="serif" fill="#ffff00">Text</text>
+ </g>
+</svg>
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 @@
+<?xml version="1.0"?>
+<svg width="200" height="50" xmlns="http://www.w3.org/2000/svg">
+ <!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
+ <defs>
+ <radialGradient id="svg_2" cx="1" cy="1" r="3">
+ <stop offset="0" stop-color="#ff0000"/>
+ <stop offset="1" stop-color="#000000"/>
+ </radialGradient>
+ </defs>
+ <g fill="#ffff00">
+ <title>Layer 1</title>
+ <rect id="svg_1" height="50" width="200" y="0" x="0" />
+ <text x="50" y="40" id="svg_12" font-size="48" font-family="serif" fill="url(#svg_2)">Text</text>
+ </g>
+</svg>
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)