tdf#160594: Use the recommended fallback of 0.5em for ex in font-size
This fixes the error of identical treatment of em and ex in font-size, which violated https://drafts.csswg.org/css-values-4/#font-relative-length. The fix uses the fallback of 0.5em for ex, similar to the code used in SvgNumber::solveNonPercentage. A follow-up should implement the correct use of "x-height of the first available font". Change-Id: Id9d581994e158d629d9752299ad93ac7e9fe4cad Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166234 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
@@ -1677,6 +1677,22 @@ CPPUNIT_TEST_FIXTURE(Test, testDyInEms)
|
|||||||
assertXPath(pDocument, "//textsimpleportion[2]"_ostr, "y"_ostr, u"32"_ustr);
|
assertXPath(pDocument, "//textsimpleportion[2]"_ostr, "y"_ostr, u"32"_ustr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CPPUNIT_TEST_FIXTURE(Test, testExs)
|
||||||
|
{
|
||||||
|
// tdf#160594 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);
|
||||||
|
|
||||||
|
sal_Int32 nSize = getXPath(pDocument, "//textsimpleportion[2]"_ostr, "height"_ostr).toInt32();
|
||||||
|
// Without the accompanying fix in place, this test would have failed with:
|
||||||
|
// - Expected less than: 16
|
||||||
|
// - Actual : 16
|
||||||
|
// i.e. the parent font-size was used, instead of its x-size.
|
||||||
|
CPPUNIT_ASSERT_LESS(sal_Int32(16), nSize);
|
||||||
|
}
|
||||||
|
|
||||||
CPPUNIT_PLUGIN_IMPLEMENT();
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
7
svgio/qa/cppunit/data/dy_in_exs.svg
Normal file
7
svgio/qa/cppunit/data/dy_in_exs.svg
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="1in" height="1in" viewBox="0 0 100% 100%">
|
||||||
|
|
||||||
|
<text x="5" y="20" style="font-size:16px;font-family:Liberation Sans">foo
|
||||||
|
<tspan x="5" dy="3ex" style="font-size:1ex">bar</tspan></text>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 293 B |
@@ -2642,11 +2642,11 @@ namespace svgio::svgreader
|
|||||||
if(pSvgStyleAttributes)
|
if(pSvgStyleAttributes)
|
||||||
{
|
{
|
||||||
const SvgNumber aParentNumber = pSvgStyleAttributes->getFontSizeNumber();
|
const SvgNumber aParentNumber = pSvgStyleAttributes->getFontSizeNumber();
|
||||||
|
double n = aParentNumber.getNumber() * maFontSizeNumber.getNumber();
|
||||||
|
if (SvgUnit::ex == maFontSizeNumber.getUnit())
|
||||||
|
n *= 0.5; // FIXME: use "x-height of the first available font"
|
||||||
|
|
||||||
return SvgNumber(
|
return SvgNumber(n, aParentNumber.getUnit());
|
||||||
aParentNumber.getNumber() * maFontSizeNumber.getNumber(),
|
|
||||||
aParentNumber.getUnit(),
|
|
||||||
true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user