diff options
-rw-r--r-- | svgio/inc/SvgNumber.hxx | 4 | ||||
-rw-r--r-- | svgio/inc/svgnode.hxx | 4 | ||||
-rw-r--r-- | svgio/qa/cppunit/SvgImportTest.cxx | 14 | ||||
-rw-r--r-- | svgio/qa/cppunit/SvgNumberTest.cxx | 2 | ||||
-rw-r--r-- | svgio/source/svgreader/SvgNumber.cxx | 2 | ||||
-rw-r--r-- | svgio/source/svgreader/svgnode.cxx | 21 |
6 files changed, 22 insertions, 25 deletions
diff --git a/svgio/inc/SvgNumber.hxx b/svgio/inc/SvgNumber.hxx index 6e371ba94b26..3509200ea392 100644 --- a/svgio/inc/SvgNumber.hxx +++ b/svgio/inc/SvgNumber.hxx @@ -39,8 +39,8 @@ public: virtual basegfx::B2DRange getCurrentViewPort() const = 0; /// return font size of node, either set here or inherited from parents virtual double getCurrentFontSize() const = 0; - /// return xheight of node inherited from parents - virtual double getCurrentXHeightInherited() const = 0; + /// return xheight of node, either set here or inherited from parents + virtual double getCurrentXHeight() const = 0; }; enum class SvgUnit diff --git a/svgio/inc/svgnode.hxx b/svgio/inc/svgnode.hxx index 6732e8bb142d..727006b3ee18 100644 --- a/svgio/inc/svgnode.hxx +++ b/svgio/inc/svgnode.hxx @@ -165,9 +165,7 @@ namespace svgio::svgreader /// InfoProvider support for %, em and ex values virtual basegfx::B2DRange getCurrentViewPort() const override; virtual double getCurrentFontSize() const override; - virtual double getCurrentXHeightInherited() const override; - - double getCurrentXHeight() const; + virtual double getCurrentXHeight() const override; /// Id access std::optional<OUString> const & getId() const { return mpId; } diff --git a/svgio/qa/cppunit/SvgImportTest.cxx b/svgio/qa/cppunit/SvgImportTest.cxx index dd53d4e28a19..fe7c51d11324 100644 --- a/svgio/qa/cppunit/SvgImportTest.cxx +++ b/svgio/qa/cppunit/SvgImportTest.cxx @@ -1679,11 +1679,12 @@ CPPUNIT_TEST_FIXTURE(Test, testDyInEms) CPPUNIT_TEST_FIXTURE(Test, testExs) { - // tdf#160594 given an SVG file with <tspan dy="3ex" style="font-size:1ex">: + // tdf#160594, tdf#160717 given an SVG file with <tspan dy="3ex" style="font-size:1ex">: xmlDocUniquePtr pDocument = dumpAndParseSvg(u"/svgio/qa/cppunit/data/dy_in_exs.svg"); assertXPath(pDocument, "//textsimpleportion"_ostr, 2); assertXPath(pDocument, "//textsimpleportion[1]"_ostr, "height"_ostr, u"16"_ustr); + assertXPath(pDocument, "//textsimpleportion[1]"_ostr, "y"_ostr, u"20"_ustr); sal_Int32 nSize = getXPath(pDocument, "//textsimpleportion[2]"_ostr, "height"_ostr).toInt32(); // Without the accompanying fix in place, this test would have failed with: @@ -1691,6 +1692,17 @@ CPPUNIT_TEST_FIXTURE(Test, testExs) // - Actual : 16 // i.e. the parent font-size was used, instead of its x-size. CPPUNIT_ASSERT_LESS(sal_Int32(16), nSize); + + sal_Int32 nYPos = getXPath(pDocument, "//textsimpleportion[2]"_ostr, "y"_ostr).toInt32(); + // Then make sure that the vertical offset is based on x-size of tspan, not of its parent. + // Given the tspan's font-size is nSize, its x-size is less than nSize, and the expected + // vertical offset is less than 3 * nSize, which means that the resulting y is expected + // to be strictly less than 20 + 3 * nSize. + // Without the accompanying fix in place, this test would have failed with: + // - Expected less than: 44 + // - Actual : 44 + // i.e. the parent x-size (or current font-size) was used, instead of current x-size. + CPPUNIT_ASSERT_LESS(sal_Int32(20 + 3 * nSize), nYPos); } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/svgio/qa/cppunit/SvgNumberTest.cxx b/svgio/qa/cppunit/SvgNumberTest.cxx index 9b12e52bf956..49e1394bcef2 100644 --- a/svgio/qa/cppunit/SvgNumberTest.cxx +++ b/svgio/qa/cppunit/SvgNumberTest.cxx @@ -40,7 +40,7 @@ public: double getCurrentFontSize() const override { return 12.0; } - double getCurrentXHeightInherited() const override { return 5.0; } + double getCurrentXHeight() const override { return 5.0; } }; void TestNumber::testSetting() diff --git a/svgio/source/svgreader/SvgNumber.cxx b/svgio/source/svgreader/SvgNumber.cxx index 4a48ffbfb4e9..72a44dbdd032 100644 --- a/svgio/source/svgreader/SvgNumber.cxx +++ b/svgio/source/svgreader/SvgNumber.cxx @@ -39,7 +39,7 @@ double SvgNumber::solveNonPercentage(const InfoProvider& rInfoProvider) const case SvgUnit::em: return mfNumber * rInfoProvider.getCurrentFontSize(); case SvgUnit::ex: - return mfNumber * rInfoProvider.getCurrentXHeightInherited() * 0.5; + return mfNumber * rInfoProvider.getCurrentXHeight(); case SvgUnit::px: return mfNumber; case SvgUnit::pt: diff --git a/svgio/source/svgreader/svgnode.cxx b/svgio/source/svgreader/svgnode.cxx index a46fc1f76ccb..80d727a2c697 100644 --- a/svgio/source/svgreader/svgnode.cxx +++ b/svgio/source/svgreader/svgnode.cxx @@ -703,25 +703,12 @@ namespace { return 0.0; } - double SvgNode::getCurrentXHeightInherited() const - { - if(getParent()) - { - return getParent()->getCurrentXHeight(); - } - else - { - return 0.0; - } - } - double SvgNode::getCurrentXHeight() const { - if(getSvgStyleAttributes()) - // for XHeight, use FontSize currently - return getSvgStyleAttributes()->getFontSizeNumber().solve(*this, NumberType::ycoordinate); - - return getCurrentXHeightInherited(); + // https://drafts.csswg.org/css-values-4/#ex + // for XHeight, use 0.5em fallback currently + // FIXME: use "x-height of the first available font" + return getCurrentFontSize() * 0.5; } void SvgNode::setId(OUString const & rId) |