svgio/inc/svgtoken.hxx              |    1 +
 svgio/qa/cppunit/SvgImportTest.cxx  |   17 +++++++++++++++++
 svgio/qa/cppunit/data/tdf156018.svg |   11 +++++++++++
 svgio/source/svgreader/svgnode.cxx  |   15 +++++++++++++++
 svgio/source/svgreader/svgtoken.cxx |   13 +++++++++++++
 5 files changed, 57 insertions(+)

New commits:
commit e29f25d3e3894b8febe6a18a1ba896ffb3590dc6
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Thu Jun 22 18:00:01 2023 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Jun 22 22:26:52 2023 +0200

    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 <xiscofa...@libreoffice.org>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153472

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);

Reply via email to