add a test for "fit to frame" text rendering

Change-Id: If304f12e1f1fbe3afea4885975302b77b428567f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142187
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:
Tomaž Vajngerl 2022-11-02 22:48:35 +01:00 committed by Tomaž Vajngerl
parent 21c6547302
commit 14175b130f
3 changed files with 28 additions and 1 deletions

Binary file not shown.

View file

@ -292,6 +292,28 @@ CPPUNIT_TEST_FIXTURE(SdLayoutTest, testBnc480256)
assertXPath(pXmlDoc, "/metafile/push[1]/push[1]/push[8]/linecolor[1]", "color", "#ff0000");
}
CPPUNIT_TEST_FIXTURE(SdLayoutTest, testFitToFrameTextFitting)
{
// This test checks that the text fitting is working correctly when
// the textbox is set to "fit to frame" by stretching the text to or
// near the textbox boundary. The problem is especially complicated
// when the font size is set to a higher number (like 999)
//
// The text fitting behaviour when "fit by frame" is enabled is to
// always fit the text into the text box (without forcing the text
// into new line) by shrinking or expanding the text horizontally
// and vertically.
xmlDocUniquePtr pXmlDoc = load("odg/FitToFrameText.odg");
assertXPath(pXmlDoc, "/metafile/push[1]/push[1]/textarray[1]", "x", "0");
assertXPath(pXmlDoc, "/metafile/push[1]/push[1]/textarray[1]", "y", "406");
assertXPath(pXmlDoc, "/metafile/push[1]/push[1]/textarray[1]/dxarray", "first", "114");
#ifndef _WIN32 // Windows seems to differ in text layouting, so ignore for now
assertXPath(pXmlDoc, "/metafile/push[1]/push[1]/textarray[1]/dxarray", "last", "7010");
#endif
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -811,11 +811,16 @@ void MetafileXmlDump::writeXml(const GDIMetaFile& rMetaFile, tools::XmlWriter& r
if (!pMetaTextArrayAction->GetDXArray().empty())
{
auto & rArray = pMetaTextArrayAction->GetDXArray();
rWriter.startElement("dxarray");
if (aIndex < o3tl::narrowing<sal_Int32>(rArray.size()))
rWriter.attribute("first", rArray[aIndex]);
if (aIndex + aLength - 1 < o3tl::narrowing<sal_Int32>(rArray.size()))
rWriter.attribute("last", rArray[aIndex + aLength - 1]);
OUStringBuffer sDxLengthString;
for (sal_Int32 i = 0; i < aLength - aIndex; ++i)
{
sDxLengthString.append(pMetaTextArrayAction->GetDXArray()[aIndex + i]);
sDxLengthString.append(rArray[aIndex + i]);
sDxLengthString.append(" ");
}
rWriter.content(sDxLengthString);