summaryrefslogtreecommitdiff
path: root/svgio
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2023-06-22 18:00:01 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2023-06-22 19:50:25 +0200
commit079cd3429ace2f9568d42368bb0c56487335d44d (patch)
tree15403b01294390eb03184733ccf91dbfad12b0af /svgio
parent83ff25f09c4b897a19b9de14980c83c1236813c1 (diff)
tdf#156018: check if there is a css style with element inside element
Change-Id: I54fa5bea42560eec5ae51dd7ba07de11f418c75c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153466 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'svgio')
-rw-r--r--svgio/inc/svgtoken.hxx1
-rw-r--r--svgio/qa/cppunit/SvgImportTest.cxx17
-rw-r--r--svgio/qa/cppunit/data/tdf156018.svg11
-rw-r--r--svgio/source/svgreader/svgnode.cxx15
-rw-r--r--svgio/source/svgreader/svgtoken.cxx13
5 files changed, 57 insertions, 0 deletions
diff --git a/svgio/inc/svgtoken.hxx b/svgio/inc/svgtoken.hxx
index a28be73df50a..9c28674b1cfb 100644
--- a/svgio/inc/svgtoken.hxx
+++ b/svgio/inc/svgtoken.hxx
@@ -187,6 +187,7 @@ namespace svgio::svgreader
};
SVGToken StrToSVGToken(const OUString& rStr, bool bCaseIndependent);
+ OUString SVGTokenToStr(const SVGToken& rToken);
OUString getStrTitle();
OUString getStrDesc();
diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx
index df1337090ff3..d29cc30bf41c 100644
--- a/svgio/qa/cppunit/SvgImportTest.cxx
+++ b/svgio/qa/cppunit/SvgImportTest.cxx
@@ -320,6 +320,23 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf145896)
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[3]", "color", "#0000ff");
}
+CPPUNIT_TEST_FIXTURE(Test, testTdf156018)
+{
+ Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/tdf156018.svg");
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence.getLength()));
+
+ drawinglayer::Primitive2dXmlDump dumper;
+ xmlDocUniquePtr pDocument = dumper.dumpAndParse(aSequence);
+
+ CPPUNIT_ASSERT (pDocument);
+
+ // Without the fix in place, this test would have failed with
+ // - Expected: #008000
+ // - Actual : #0000ff
+ assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[1]", "color", "#008000");
+ assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[2]", "color", "#0000ff");
+}
+
CPPUNIT_TEST_FIXTURE(Test, testTdf155932)
{
Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/tdf155932.svg");
diff --git a/svgio/qa/cppunit/data/tdf156018.svg b/svgio/qa/cppunit/data/tdf156018.svg
new file mode 100644
index 000000000000..cff3f924a589
--- /dev/null
+++ b/svgio/qa/cppunit/data/tdf156018.svg
@@ -0,0 +1,11 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-0 0 300 300">
+
+ <style id="style2">
+ g rect {fill:green;}
+ </style>
+
+ <g>
+ <rect x="00" y="0" height="50" width="50" fill="blue"></rect>
+ </g>
+ <rect x="60" y="0" height="50" width="50" fill="blue"></rect>
+</svg>
diff --git a/svgio/source/svgreader/svgnode.cxx b/svgio/source/svgreader/svgnode.cxx
index d45624d3edc6..2137209d5599 100644
--- a/svgio/source/svgreader/svgnode.cxx
+++ b/svgio/source/svgreader/svgnode.cxx
@@ -160,6 +160,21 @@ namespace svgio::svgreader
// add CssStyle if found
maCssStyleVector.push_back(pNew);
}
+
+ // check if there is a css style with element inside element
+ if(pParent)
+ {
+ OUString sParentType(SVGTokenToStr(pParent->getType()));
+
+ aNewConcatenated = sParentType + rClassStr;
+ pNew = rDocument.findGlobalCssStyleAttributes(aNewConcatenated);
+
+ if(pNew)
+ {
+ // add CssStyle if found
+ maCssStyleVector.push_back(pNew);
+ }
+ }
}
void SvgNode::fillCssStyleVector(const OUString& rClassStr, const SvgStyleAttributes& rOriginal)
diff --git a/svgio/source/svgreader/svgtoken.cxx b/svgio/source/svgreader/svgtoken.cxx
index 45af658b1ebd..ed50612323e5 100644
--- a/svgio/source/svgreader/svgtoken.cxx
+++ b/svgio/source/svgreader/svgtoken.cxx
@@ -243,6 +243,19 @@ SVGToken StrToSVGToken(const OUString& rStr, bool bCaseIndependent)
}
}
+OUString SVGTokenToStr(const SVGToken& rToken)
+{
+ for (auto it = aSVGTokenMapperList.begin(); it != aSVGTokenMapperList.end(); ++it)
+ {
+ if (it->second == rToken)
+ {
+ OUString aFirst(it->first);
+ return aFirst;
+ }
+ }
+ return OUString();
+}
+
OUString getStrTitle()
{
return OUString(constToken_Title);