summaryrefslogtreecommitdiff
path: root/svgio
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2019-09-16 12:54:59 +0200
committerXisco Faulí <xiscofauli@libreoffice.org>2019-09-16 15:38:36 +0200
commit4007ced54d611d1397387f7329a47de5efaca32f (patch)
tree27f0a7a6413703a27d0c013ee90904be72d44353 /svgio
parenta3b03ba1316b1ec0a9b0a3b45b96dc0a49aa9f1f (diff)
tdf#99115: add Css selector '*' style only if the element...
... is on top of the hierarchy Otherwise, we add it for every element on the hierarchy Adapt unittest from https://bugs.documentfoundation.org/show_bug.cgi?id=100198 Provided by Sam Yygier Change-Id: I72c7ae08f3ce0194eff86697b202d5553810abeb Reviewed-on: https://gerrit.libreoffice.org/78997 Tested-by: Jenkins Reviewed-by: Xisco Faulí <xiscofauli@libreoffice.org>
Diffstat (limited to 'svgio')
-rw-r--r--svgio/qa/cppunit/SvgImportTest.cxx68
-rw-r--r--svgio/qa/cppunit/data/tdf99115.svg40
-rw-r--r--svgio/source/svgreader/svgnode.cxx18
3 files changed, 112 insertions, 14 deletions
diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx
index 501df9c21ea1..4fe57b9adc3d 100644
--- a/svgio/qa/cppunit/SvgImportTest.cxx
+++ b/svgio/qa/cppunit/SvgImportTest.cxx
@@ -62,6 +62,7 @@ class Test : public test::BootstrapFixture, public XmlTestTools
void test47446b();
void testMaskText();
void testTdf99994();
+ void testTdf99115();
void testTdf101237();
void testBehaviourWhenWidthAndHeightIsOrIsNotSet();
@@ -92,6 +93,7 @@ public:
CPPUNIT_TEST(test47446b);
CPPUNIT_TEST(testMaskText);
CPPUNIT_TEST(testTdf99994);
+ CPPUNIT_TEST(testTdf99115);
CPPUNIT_TEST(testTdf101237);
CPPUNIT_TEST(testBehaviourWhenWidthAndHeightIsOrIsNotSet);
CPPUNIT_TEST_SUITE_END();
@@ -519,15 +521,15 @@ void Test::testi125329()
CPPUNIT_ASSERT (pDocument);
- assertXPath(pDocument, "/primitive2D/transform/transform/polypolygoncolor", "color", "#c0c0c0"); // rect background color
- assertXPath(pDocument, "/primitive2D/transform/transform/polypolygoncolor/polypolygon", "height", "30"); // rect background height
- assertXPath(pDocument, "/primitive2D/transform/transform/polypolygoncolor/polypolygon", "width", "50"); // rect background width
- assertXPath(pDocument, "/primitive2D/transform/transform/polypolygoncolor/polypolygon", "minx", "15");
- assertXPath(pDocument, "/primitive2D/transform/transform/polypolygoncolor/polypolygon", "miny", "15");
- assertXPath(pDocument, "/primitive2D/transform/transform/polypolygoncolor/polypolygon", "maxx", "65");
- assertXPath(pDocument, "/primitive2D/transform/transform/polypolygoncolor/polypolygon", "maxy", "45");
- assertXPath(pDocument, "/primitive2D/transform/transform/polypolygonstroke/line", "color", "#008000"); // rect stroke color
- assertXPath(pDocument, "/primitive2D/transform/transform/polypolygonstroke/line", "width", "1"); // rect stroke width
+ assertXPath(pDocument, "/primitive2D/transform/transform/objectinfo/polypolygoncolor", "color", "#c0c0c0"); // rect background color
+ assertXPath(pDocument, "/primitive2D/transform/transform/objectinfo/polypolygoncolor/polypolygon", "height", "30"); // rect background height
+ assertXPath(pDocument, "/primitive2D/transform/transform/objectinfo/polypolygoncolor/polypolygon", "width", "50"); // rect background width
+ assertXPath(pDocument, "/primitive2D/transform/transform/objectinfo/polypolygoncolor/polypolygon", "minx", "15");
+ assertXPath(pDocument, "/primitive2D/transform/transform/objectinfo/polypolygoncolor/polypolygon", "miny", "15");
+ assertXPath(pDocument, "/primitive2D/transform/transform/objectinfo/polypolygoncolor/polypolygon", "maxx", "65");
+ assertXPath(pDocument, "/primitive2D/transform/transform/objectinfo/polypolygoncolor/polypolygon", "maxy", "45");
+ assertXPath(pDocument, "/primitive2D/transform/transform/objectinfo/polypolygonstroke/line", "color", "#008000"); // rect stroke color
+ assertXPath(pDocument, "/primitive2D/transform/transform/objectinfo/polypolygonstroke/line", "width", "1"); // rect stroke width
}
void Test::testMaskingPath07b()
@@ -609,6 +611,54 @@ void Test::testTdf99994()
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "familyname", "Sans");
}
+void Test::testTdf99115()
+{
+ //Check that styles are resolved correctly where there is a * css selector
+ Primitive2DSequence aSequenceTdf99115 = parseSvg("/svgio/qa/cppunit/data/tdf99115.svg");
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequenceTdf99115.getLength()));
+
+ drawinglayer::tools::Primitive2dXmlDump dumper;
+ xmlDocPtr pDocument = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequenceTdf99115) );
+
+ CPPUNIT_ASSERT (pDocument);
+
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "text", "red 1");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "fontcolor", "#ff0000");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "height", "18");
+
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "text", "red 2");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "fontcolor", "#ff0000");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "height", "18");
+
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]", "text", "red 3");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]", "fontcolor", "#ff0000");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[3]", "height", "18");
+
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[4]", "text", "blue 4");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[4]", "fontcolor", "#0000ff");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[4]", "height", "18");
+
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[5]", "text", "blue 5");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[5]", "fontcolor", "#0000ff");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[5]", "height", "18");
+
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[6]", "text", "blue 6");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[6]", "fontcolor", "#0000ff");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[6]", "height", "18");
+
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[7]", "text", "green 7");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[7]", "fontcolor", "#008000");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[7]", "height", "18");
+
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[8]", "text", "green 8");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[8]", "fontcolor", "#008000");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[8]", "height", "18");
+
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[9]", "text", "green 9");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[9]", "fontcolor", "#008000");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[9]", "height", "18");
+}
+
void Test::testTdf101237()
{
//Check that fill color, stroke color and stroke-width are inherited from use element
diff --git a/svgio/qa/cppunit/data/tdf99115.svg b/svgio/qa/cppunit/data/tdf99115.svg
new file mode 100644
index 000000000000..6d4b5e9c1b97
--- /dev/null
+++ b/svgio/qa/cppunit/data/tdf99115.svg
@@ -0,0 +1,40 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="200 px" height="100 px">
+<style type="text/css" id="style1">
+* {font-size:18px;}
+#tspan6 {fill:blue}
+.c1 {fill:green}
+.c2 {fill:red}
+#tspan8 {fill:green}
+#text9 {fill:green}
+</style>
+<text id="text1" style="" x="1" y="20" >
+ <tspan id="tspan1" fill="red">red 1</tspan>
+</text>
+<text id="text2" style="fill:red" x="1" y="40" >
+ <tspan id="tspan2">red 2</tspan>
+</text>
+<text id="text3" style="" x="1" y="60" >
+ <tspan id="tspan3" style="fill:red">red 3</tspan>
+</text>
+
+<text id="text4" style="fill:red" x="60" y="20" >
+ <tspan id="tspan4" fill="blue">blue 4</tspan>
+</text>
+<text id="text5" x="60" y="40" >
+ <tspan id="tspan5" style="fill:blue" fill="red">blue 5</tspan>
+</text>
+<text id="text6" style="fill:red" x="60" y="60" >
+ <tspan id="tspan6">blue 6</tspan>
+</text>
+
+<text id="text7" x="130" y="20" >
+ <tspan id="tspan7" class="c1" fill="blue">green 7</tspan>
+</text>
+<text id="text8" x="130" y="40" >
+ <tspan id="tspan8" class="c2" fill="red">green 8</tspan>
+</text>
+<text id="text9" x="130" y="60" class="c2">
+ <tspan id="tspan9">green 9</tspan>
+</text>
+
+</svg>
diff --git a/svgio/source/svgreader/svgnode.cxx b/svgio/source/svgreader/svgnode.cxx
index 4e38b5dc6135..3770efc6eea7 100644
--- a/svgio/source/svgreader/svgnode.cxx
+++ b/svgio/source/svgreader/svgnode.cxx
@@ -174,6 +174,7 @@ namespace svgio
// - 'id' CssStyle
// - 'class' CssStyle(s)
// - type-dependent elements (e..g. 'rect' for all rect elements)
+ // - Css selector '*'
// - local attributes (rOriginal)
// - inherited attributes (up the hierarchy)
// The first four will be collected in maCssStyleVector for the current element
@@ -191,13 +192,20 @@ namespace svgio
// check the hierarchy for concatenated patterns of Selectors
fillCssStyleVectorUsingHierarchyAndSelectors(rClassStr, *this, OUString());
- // #i125329# find Css selector '*', add as last element if found
- const SvgStyleAttributes* pNew = getDocument().findGlobalCssStyleAttributes("*");
+ // tdf#99115, Add css selector '*' style only if the element is on top of the hierarchy
+ // meaning its parent is <svg>
+ const SvgNode* pParent = this->getParent();
- if(pNew)
+ if(pParent && pParent->getType() == SVGTokenSvg)
{
- // add CssStyle for selector '*' if found
- maCssStyleVector.push_back(pNew);
+ // #i125329# find Css selector '*', add as last element if found
+ const SvgStyleAttributes* pNew = getDocument().findGlobalCssStyleAttributes("*");
+
+ if(pNew)
+ {
+ // add CssStyle for selector '*' if found
+ maCssStyleVector.push_back(pNew);
+ }
}
//local attributes