summaryrefslogtreecommitdiff
path: root/svgio
diff options
context:
space:
mode:
authorHossein <hossein@libreoffice.org>2021-12-20 05:44:23 +0100
committerXisco Fauli <xiscofauli@libreoffice.org>2021-12-24 19:35:15 +0100
commit8e1aea537ffe35311cc6d43d4b0cef3f4ec82367 (patch)
tree0cc23a76177dbbe3da842143e181153a2ed37d10 /svgio
parentefa20d38fa51675e738ce50d6894b5df75debea0 (diff)
tdf#97663 SVGIO: Fix line spacing for <tspan>
tdf#97663 is a regression caused by the commit 701324a1e1f7e0c181ff1a50956ced686785ea53. The previous patch caused LO to forget the size of the font which was needed to calculate line height based on em units. em, px, pt, cm, in... https://www.w3.org/Style/Examples/007/units.en.html Accompanied with this fix is a unit test provided to avoid this issue in the future. The fix can be tested with: make CPPUNIT_TEST_NAME="testTdf97663" -sr \ CppunitTest_svgio The em_units.svg is opened with Firefox, Chrome and Inkscape and the rendering in LibreOffice is compatible with the rendering in these applications. Change-Id: Idaecd9fb18101f7925fe2a917f7fc3fe7257ebc5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127130 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de> (cherry picked from commit 4e2e57b530544736804ab663f832173ba1d78559) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127376 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'svgio')
-rw-r--r--svgio/inc/svgnode.hxx2
-rw-r--r--svgio/inc/svgtextnode.hxx2
-rw-r--r--svgio/inc/svgtspannode.hxx2
-rw-r--r--svgio/qa/cppunit/SvgImportTest.cxx20
-rw-r--r--svgio/qa/cppunit/data/em_units.svg14
-rw-r--r--svgio/source/svgreader/svgtextnode.cxx4
6 files changed, 36 insertions, 8 deletions
diff --git a/svgio/inc/svgnode.hxx b/svgio/inc/svgnode.hxx
index 63c6b2318406..58b1682506f2 100644
--- a/svgio/inc/svgnode.hxx
+++ b/svgio/inc/svgnode.hxx
@@ -159,7 +159,7 @@ namespace svgio::svgreader
virtual double getCurrentFontSizeInherited() const override;
virtual double getCurrentXHeightInherited() const override;
- virtual double getCurrentFontSize() const;
+ double getCurrentFontSize() const;
double getCurrentXHeight() const;
/// Id access
diff --git a/svgio/inc/svgtextnode.hxx b/svgio/inc/svgtextnode.hxx
index b72d1043b8c0..37983ad31531 100644
--- a/svgio/inc/svgtextnode.hxx
+++ b/svgio/inc/svgtextnode.hxx
@@ -58,8 +58,6 @@ namespace svgio::svgreader
virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override;
virtual void decomposeSvgNode(drawinglayer::primitive2d::Primitive2DContainer& rTarget, bool bReferenced) const override;
- virtual double getCurrentFontSize() const override;
-
/// transform content, set if found in current context
const std::optional<basegfx::B2DHomMatrix>& getTransform() const { return mpaTransform; }
void setTransform(const std::optional<basegfx::B2DHomMatrix>& pMatrix) { mpaTransform = pMatrix; }
diff --git a/svgio/inc/svgtspannode.hxx b/svgio/inc/svgtspannode.hxx
index af4ae8268b5c..10a7b7ee16a9 100644
--- a/svgio/inc/svgtspannode.hxx
+++ b/svgio/inc/svgtspannode.hxx
@@ -42,7 +42,7 @@ namespace svgio::svgreader
virtual const SvgStyleAttributes* getSvgStyleAttributes() const override;
virtual void parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent) override;
- virtual double getCurrentFontSize() const override;
+ double getCurrentFontSize() const;
/// access to SvgTextPositions
const SvgTextPositions& getSvgTextPositions() const { return maSvgTextPositions; }
diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx
index 25baf76fdad8..3034c997015e 100644
--- a/svgio/qa/cppunit/SvgImportTest.cxx
+++ b/svgio/qa/cppunit/SvgImportTest.cxx
@@ -69,6 +69,7 @@ class Test : public test::BootstrapFixture, public XmlTestTools
void testTdf101237();
void testTdf94765();
void testBehaviourWhenWidthAndHeightIsOrIsNotSet();
+ void testTdf97663();
Primitive2DSequence parseSvg(std::u16string_view aSource);
@@ -104,6 +105,7 @@ public:
CPPUNIT_TEST(testTdf101237);
CPPUNIT_TEST(testTdf94765);
CPPUNIT_TEST(testBehaviourWhenWidthAndHeightIsOrIsNotSet);
+ CPPUNIT_TEST(testTdf97663);
CPPUNIT_TEST_SUITE_END();
};
@@ -804,6 +806,24 @@ void Test::testBehaviourWhenWidthAndHeightIsOrIsNotSet()
}
}
+void Test::testTdf97663()
+{
+ Primitive2DSequence aSequence = parseSvg(u"/svgio/qa/cppunit/data/em_units.svg");
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence.getLength()));
+
+ drawinglayer::Primitive2dXmlDump dumper;
+ // This can be dumped to a file using dumper.dump(container, file_url)
+ Primitive2DContainer container = comphelper::sequenceToContainer<Primitive2DContainer>(aSequence);
+ xmlDocUniquePtr pDocument = dumper.dumpAndParse(container);
+
+ CPPUNIT_ASSERT (pDocument);
+
+ // tdf#97663: Without the fix in place, this test would have failed with
+ // - Expected: 236
+ // - Actual : 204
+ assertXPath(pDocument, "/primitive2D/transform/textsimpleportion[2]", "y", "236");
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
}
diff --git a/svgio/qa/cppunit/data/em_units.svg b/svgio/qa/cppunit/data/em_units.svg
new file mode 100644
index 000000000000..1ad4d3e3a769
--- /dev/null
+++ b/svgio/qa/cppunit/data/em_units.svg
@@ -0,0 +1,14 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="10cm" height="10cm">
+
+ <style>
+ text {font-family: sans-serif; font-size: 36pt;}
+ new {font-family: sans-serif; font-size: 1em;}
+ </style>
+
+ <line x1="5cm" y1="5cm" x2="8cm" y2="5cm" stroke="black" />
+ <!-- 0.5in = 1.27cm = 36pt !-->
+ <line x1="5cm" y1="6.27cm" x2="8cm" y2="6.27cm" stroke="black" />
+ <text x="5cm" y="5cm" class="new">AWlll<tspan x="5cm" dy="1em">AWlll</tspan>
+ </text>
+</svg>
+
diff --git a/svgio/source/svgreader/svgtextnode.cxx b/svgio/source/svgreader/svgtextnode.cxx
index 25ad066e9bbc..a7c8cae8b8ce 100644
--- a/svgio/source/svgreader/svgtextnode.cxx
+++ b/svgio/source/svgreader/svgtextnode.cxx
@@ -255,10 +255,6 @@ namespace svgio::svgreader
}
}
- double SvgTextNode::getCurrentFontSize() const
- {
- return getCurrentFontSizeInherited();
- }
} // end of namespace svgio::svgreader
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */