summaryrefslogtreecommitdiff
path: root/svgio
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2023-08-21 14:15:56 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2023-08-21 15:49:15 +0200
commit56a360328790eb009efed6fce94a795f6fe0a7d2 (patch)
tree9a3cbee0494c85994a29282b6d303d1469a615a5 /svgio
parent0a17e45e3fed13c240629fdf0dbb00b8908f5acc (diff)
tdf#156837: check baseline-shift from parent too
Change-Id: I6e62d794dd4410447db3bee26c1e18fe9dad6a9c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155895 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'svgio')
-rw-r--r--svgio/inc/svgstyleattributes.hxx2
-rw-r--r--svgio/qa/cppunit/SvgImportTest.cxx25
-rw-r--r--svgio/qa/cppunit/data/tdf156837.svg13
-rw-r--r--svgio/source/svgreader/svgstyleattributes.cxx22
4 files changed, 60 insertions, 2 deletions
diff --git a/svgio/inc/svgstyleattributes.hxx b/svgio/inc/svgstyleattributes.hxx
index 4ada2e687ee9..751ee6014e41 100644
--- a/svgio/inc/svgstyleattributes.hxx
+++ b/svgio/inc/svgstyleattributes.hxx
@@ -436,7 +436,7 @@ namespace svgio::svgreader
// BaselineShift
void setBaselineShift(const BaselineShift aBaselineShift) { maBaselineShift = aBaselineShift; }
- BaselineShift getBaselineShift() const { return maBaselineShift; }
+ BaselineShift getBaselineShift() const;
SvgNumber getBaselineShiftNumber() const;
};
diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx
index 2297367ee778..95cbc0bcda6a 100644
--- a/svgio/qa/cppunit/SvgImportTest.cxx
+++ b/svgio/qa/cppunit/SvgImportTest.cxx
@@ -1740,6 +1740,31 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf156283)
assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "dx2", "63");
}
+CPPUNIT_TEST_FIXTURE(Test, testTdf156837)
+{
+ Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/tdf156837.svg");
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence.getLength()));
+
+ drawinglayer::Primitive2dXmlDump dumper;
+ xmlDocUniquePtr pDocument = dumper.dumpAndParse(Primitive2DContainer(aSequence));
+
+ CPPUNIT_ASSERT (pDocument);
+
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion", 2);
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "x", "114");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "y", "103");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "height", "16");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[1]", "text", "x");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "x", "122");
+
+ // Without the fix in place, this test would have failed with
+ // - Expected: 94
+ // - Actual : 103
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "y", "94");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "height", "10");
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "text", "3");
+}
+
CPPUNIT_TEST_FIXTURE(Test, testTdf156271)
{
Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/tdf156271.svg");
diff --git a/svgio/qa/cppunit/data/tdf156837.svg b/svgio/qa/cppunit/data/tdf156837.svg
new file mode 100644
index 000000000000..f04cb015d313
--- /dev/null
+++ b/svgio/qa/cppunit/data/tdf156837.svg
@@ -0,0 +1,13 @@
+<svg viewBox="0 0 500 500" xmlns="http://www.w3.org/2000/svg">
+
+<defs><style type="text/css">
+.super{
+ font-size: 65%;
+}
+</style></defs>
+
+ <text>
+ <tspan x="114" y="103">x </tspan>
+ <tspan class="super" baseline-shift="super">3</tspan>
+ </text>
+</svg>
diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx
index fd4482057f17..68e8b59d76c2 100644
--- a/svgio/source/svgreader/svgstyleattributes.cxx
+++ b/svgio/source/svgreader/svgstyleattributes.cxx
@@ -1285,7 +1285,7 @@ namespace svgio::svgreader
maClipRule(FillRule::notset),
maBaselineShift(BaselineShift::Baseline),
maBaselineShiftNumber(0),
- maResolvingParent(29, 0),
+ maResolvingParent(30, 0),
mbIsClipPathContent(SVGToken::ClipPathNode == mrOwner.getType()),
mbStrokeDasharraySet(false)
{
@@ -3062,6 +3062,26 @@ namespace svgio::svgreader
return maBaselineShiftNumber;
}
+
+ BaselineShift SvgStyleAttributes::getBaselineShift() const
+ {
+ if(maBaselineShift != BaselineShift::Baseline)
+ {
+ return maBaselineShift;
+ }
+
+ const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
+
+ if (pSvgStyleAttributes && maResolvingParent[29] < nStyleDepthLimit)
+ {
+ ++maResolvingParent[29];
+ auto ret = pSvgStyleAttributes->getBaselineShift();
+ --maResolvingParent[29];
+ return ret;
+ }
+
+ return BaselineShift::Baseline;
+ }
} // end of namespace svgio
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */