summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2023-06-26 19:15:03 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2023-06-26 22:45:12 +0200
commit930eb99a712a3ad9b76e9edb68bbcea68af36656 (patch)
tree66829fb3b3486e044a42ccf1076196bd1f2ba373
parent897fce4abd0c731bf697ca1e38a8049f66f9ac7c (diff)
tdf#156038, tdf#78232: support css child combinator
Change-Id: I874c368f66db97017357030867f1255551996228 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153626 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r--svgio/inc/svgnode.hxx2
-rw-r--r--svgio/qa/cppunit/SvgImportTest.cxx24
-rw-r--r--svgio/qa/cppunit/data/tdf156038.svg34
-rw-r--r--svgio/source/svgreader/svgnode.cxx98
4 files changed, 158 insertions, 0 deletions
diff --git a/svgio/inc/svgnode.hxx b/svgio/inc/svgnode.hxx
index a85958936d9e..0d8008d41c90 100644
--- a/svgio/inc/svgnode.hxx
+++ b/svgio/inc/svgnode.hxx
@@ -126,6 +126,8 @@ namespace svgio::svgreader
void fillCssStyleVectorUsingHierarchyAndSelectors(
const SvgNode& rCurrent,
const OUString& aConcatenated);
+ void fillCssStyleVectorUsingParent(
+ const SvgNode& rCurrent);
public:
SvgNode(
diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx
index abef91413077..7607a5593256 100644
--- a/svgio/qa/cppunit/SvgImportTest.cxx
+++ b/svgio/qa/cppunit/SvgImportTest.cxx
@@ -344,6 +344,30 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf156034)
assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[8]", "color", "#008000");
}
+CPPUNIT_TEST_FIXTURE(Test, testTdf156038)
+{
+ Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/tdf156038.svg");
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence.getLength()));
+
+ drawinglayer::Primitive2dXmlDump dumper;
+ xmlDocUniquePtr pDocument = dumper.dumpAndParse(aSequence);
+
+ CPPUNIT_ASSERT (pDocument);
+
+ assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[1]", "color", "#0000ff");
+
+ // Without the fix in place, this test would have failed with
+ // - Expected: #008000
+ // - Actual : #0000ff
+ assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[2]", "color", "#008000");
+ assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[3]", "color", "#0000ff");
+ assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[4]", "color", "#008000");
+ assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[5]", "color", "#0000ff");
+ assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[6]", "color", "#008000");
+ assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[7]", "color", "#0000ff");
+ assertXPath(pDocument, "/primitive2D/transform/polypolygoncolor[8]", "color", "#008000");
+}
+
CPPUNIT_TEST_FIXTURE(Test, testTdf156018)
{
Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/tdf156018.svg");
diff --git a/svgio/qa/cppunit/data/tdf156038.svg b/svgio/qa/cppunit/data/tdf156038.svg
new file mode 100644
index 000000000000..9835453e7fdd
--- /dev/null
+++ b/svgio/qa/cppunit/data/tdf156038.svg
@@ -0,0 +1,34 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-0 0 800 800">
+
+ <style>
+ .g1 > rect {fill:green;}
+ #g3 > rect {fill:green;}
+ .g4 > #r1 {fill:green;}
+ #g3 > .r5 {fill:green;}
+ </style>
+
+ <g class="g4 g1">
+ <g class="g2">
+ <rect x="0" y="0" height="50" width="50" fill="blue"></rect>
+ </g>
+ <rect x="60" y="0" height="50" width="50" fill="blue"></rect>
+ </g>
+ <g id="g3">
+ <g id="g4">
+ <rect x="120" y="0" height="50" width="50" fill="blue"></rect>
+ </g>
+ <rect x="180" y="0" height="50" width="50" fill="blue"></rect>
+ </g>
+ <g class="g4 g1">
+ <g>
+ <rect id="r1" x="240" y="0" height="50" width="50" fill="blue"></rect>
+ </g>
+ <rect id="r1" x="300" y="0" height="50" width="50" fill="blue"></rect>
+ </g>
+ <g id="g3">
+ <g id="g4">
+ <rect class="r5" x="360" y="0" height="50" width="50" fill="blue"></rect>
+ </g>
+ <rect class="r5" x="420" y="0" height="50" width="50" fill="blue"></rect>
+ </g>
+</svg>
diff --git a/svgio/source/svgreader/svgnode.cxx b/svgio/source/svgreader/svgnode.cxx
index 399b92231543..37b34deff0f6 100644
--- a/svgio/source/svgreader/svgnode.cxx
+++ b/svgio/source/svgreader/svgnode.cxx
@@ -184,6 +184,100 @@ namespace {
}
}
+ void SvgNode::fillCssStyleVectorUsingParent(const SvgNode& rCurrent)
+ {
+ const SvgDocument& rDocument = getDocument();
+
+ if(!rDocument.hasGlobalCssStyleAttributes())
+ return;
+
+ const SvgNode* pParent = rCurrent.getParent();
+
+ if (!pParent)
+ return;
+
+ OUString sParentId;
+ if (pParent->getId().has_value())
+ {
+ sParentId = pParent->getId().value();
+ }
+ std::vector <OUString> aParentClasses = parseClass(*pParent);
+ OUString sParentType(SVGTokenToStr(pParent->getType()));
+
+ if(rCurrent.getId())
+ {
+ const OUString& rId = *rCurrent.getId();
+
+ if(!rId.isEmpty())
+ {
+ if (!sParentId.isEmpty())
+ {
+ const OUString aConcatenated("#" + sParentId + ">#" + rId);
+ addCssStyle(rDocument, aConcatenated);
+ }
+
+ for(const auto &aParentClass : aParentClasses)
+ {
+ const OUString aConcatenated("." + aParentClass + ">#" + rId);
+ addCssStyle(rDocument, aConcatenated);
+ }
+
+ if (!sParentType.isEmpty())
+ {
+ const OUString aConcatenated(sParentType + ">#" + rId);
+ addCssStyle(rDocument, aConcatenated);
+ }
+ }
+
+ }
+
+ std::vector <OUString> aClasses = parseClass(rCurrent);
+ for(const auto &aClass : aClasses)
+ {
+
+ if (!sParentId.isEmpty())
+ {
+ const OUString aConcatenated("#" + sParentId + ">." + aClass);
+ addCssStyle(rDocument, aConcatenated);
+ }
+
+ for(const auto &aParentClass : aParentClasses)
+ {
+ const OUString aConcatenated("." + aParentClass + ">." + aClass);
+ addCssStyle(rDocument, aConcatenated);
+ }
+
+ if (!sParentType.isEmpty())
+ {
+ const OUString aConcatenated(sParentType + ">." + aClass);
+ addCssStyle(rDocument, aConcatenated);
+ }
+ }
+
+ OUString sCurrentType(SVGTokenToStr(getType()));
+
+ if(!sCurrentType.isEmpty())
+ {
+ if (!sParentId.isEmpty())
+ {
+ const OUString aConcatenated("#" + sParentId + ">" + sCurrentType);
+ addCssStyle(rDocument, aConcatenated);
+ }
+
+ for(const auto &aParentClass : aParentClasses)
+ {
+ const OUString aConcatenated("." + aParentClass + ">" + sCurrentType);
+ addCssStyle(rDocument, aConcatenated);
+ }
+
+ if (!sParentType.isEmpty())
+ {
+ const OUString aConcatenated(sParentType + ">" + sCurrentType);
+ addCssStyle(rDocument, aConcatenated);
+ }
+ }
+ }
+
void SvgNode::fillCssStyleVector(const SvgStyleAttributes& rOriginal)
{
OSL_ENSURE(!mbCssStyleVectorBuilt, "OOps, fillCssStyleVector called double ?!?");
@@ -211,9 +305,13 @@ namespace {
maCssStyleVector.push_back(mpLocalCssStyle.get());
}
+ // tdf#156038 check for child combinator
+ fillCssStyleVectorUsingParent(*this);
+
// check the hierarchy for concatenated patterns of Selectors
fillCssStyleVectorUsingHierarchyAndSelectors(*this, OUString());
+
// 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();