sd/qa/unit/data/odg/FitToFrameText.odg |binary
 sd/qa/unit/layout-tests.cxx            |   22 ++++++++++++++++++++++
 vcl/source/gdi/mtfxmldump.cxx          |    7 ++++++-
 3 files changed, 28 insertions(+), 1 deletion(-)

New commits:
commit 14175b130ff97c5576ff872dcf3163954c6f80f8
Author:     Tomaž Vajngerl <[email protected]>
AuthorDate: Wed Nov 2 22:48:35 2022 +0100
Commit:     Tomaž Vajngerl <[email protected]>
CommitDate: Fri Nov 4 15:18:39 2022 +0100

    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 <[email protected]>

diff --git a/sd/qa/unit/data/odg/FitToFrameText.odg 
b/sd/qa/unit/data/odg/FitToFrameText.odg
new file mode 100644
index 000000000000..e65b0a3a2102
Binary files /dev/null and b/sd/qa/unit/data/odg/FitToFrameText.odg differ
diff --git a/sd/qa/unit/layout-tests.cxx b/sd/qa/unit/layout-tests.cxx
index 2a7c0e0a200b..d2bf22622885 100644
--- a/sd/qa/unit/layout-tests.cxx
+++ b/sd/qa/unit/layout-tests.cxx
@@ -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: */
diff --git a/vcl/source/gdi/mtfxmldump.cxx b/vcl/source/gdi/mtfxmldump.cxx
index 2dc7e7b9d3e1..5319c2834686 100644
--- a/vcl/source/gdi/mtfxmldump.cxx
+++ b/vcl/source/gdi/mtfxmldump.cxx
@@ -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);

Reply via email to