sw/qa/core/doc/data/text-box-word-wrap.docx |binary
 sw/qa/core/doc/doc.cxx                      |   19 +++++++++++++++++++
 sw/qa/extras/layout/data/tdf138951.odt      |binary
 sw/source/core/doc/textboxhelper.cxx        |   14 ++++++++++++++
 4 files changed, 33 insertions(+)

New commits:
commit fcaad2c0fdacaca7c9b8ead4675a137689f2f777
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Aug 5 13:29:37 2024 +0200
Commit:     Aron Budea <aron.bu...@collabora.com>
CommitDate: Mon May 5 08:07:14 2025 +0200

    tdf#162075 sw textbox: map a shape's wordwrap=no to the frame's width type
    
    Regression from commit c761df1e42fd11acc5fc05b0baacd803c3788ca6
    (tdf#84678 DOCX import: fix handling of textbox margins, 2016-10-25),
    the header hape was supposed to have a single line, but it had a
    separate line for each character in the shape text.
    
    What happened is that the nominal size of the shape was not enough to
    provide enough space for the text, now that we handle spacing between
    the frame border and text, and the shape had automatic height set,
    instead of automatic width.
    
    Fix the problem by extending SwTextBoxHelper::create() to map the
    shape's TextWordWrap property to the inner frame's WidthType. As the
    tdf#81567 testcase points out, this requires extending the matching
    shape update code as well, because word wrap is always disabled
    initially, and it's enabled only after the shape's text is processed.
    
    Also adjust sw/qa/extras/layout/data/tdf138951.odt, which expected word
    wrap but didn't request it -- the original tdf#138951 bugdoc keeps
    working after this commit.
    
    Change-Id: I17c896f83731a6653e3a0a1493949e27d5259232
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171475
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172109
    (cherry picked from commit 9478aa91f85545aef89bd6b7e7ab67d95326403b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184949
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Aron Budea <aron.bu...@collabora.com>

diff --git a/sw/qa/core/doc/data/text-box-word-wrap.docx 
b/sw/qa/core/doc/data/text-box-word-wrap.docx
new file mode 100644
index 000000000000..50922ea69fa0
Binary files /dev/null and b/sw/qa/core/doc/data/text-box-word-wrap.docx differ
diff --git a/sw/qa/core/doc/doc.cxx b/sw/qa/core/doc/doc.cxx
index 2fdd062f5c81..67e619fba725 100644
--- a/sw/qa/core/doc/doc.cxx
+++ b/sw/qa/core/doc/doc.cxx
@@ -632,6 +632,25 @@ CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testVirtPageNumReset)
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1), nVirt);
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreDocTest, testTextBoxWordWrap)
+{
+    // Given a document with a shape in the header that extends horizontally 
when there is enough
+    // content:
+    createSwDoc("text-box-word-wrap.docx");
+
+    // When checking the layout size of the shape:
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    auto nFlyHeight
+        = getXPath(pXmlDoc, "//anchored/fly/infos/bounds"_ostr, 
"height"_ostr).toInt32();
+
+    // Then make sure it has a small height, hosting just one line:
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 773
+    // - Actual  : 5183
+    // i.e. the shape had new lines for each character instead of 1 line.
+    CPPUNIT_ASSERT_LESS(static_cast<sal_Int32>(1000), nFlyHeight);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/extras/layout/data/tdf138951.odt 
b/sw/qa/extras/layout/data/tdf138951.odt
index 5cb4940bd5fe..57328bdb496e 100644
Binary files a/sw/qa/extras/layout/data/tdf138951.odt and 
b/sw/qa/extras/layout/data/tdf138951.odt differ
diff --git a/sw/source/core/doc/textboxhelper.cxx 
b/sw/source/core/doc/textboxhelper.cxx
index 538a1ba96a24..deba4053d455 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -196,6 +196,10 @@ void SwTextBoxHelper::create(SwFrameFormat* pShape, 
SdrObject* pObject, bool bCo
                  
xShapePropertySet->getPropertyValue(UNO_NAME_VERT_ORIENT_POSITION), pObject);
     syncProperty(pShape, RES_FRM_SIZE, MID_FRMSIZE_IS_AUTO_HEIGHT,
                  
xShapePropertySet->getPropertyValue(UNO_NAME_TEXT_AUTOGROWHEIGHT), pObject);
+    // tdf#162075 shape word wrap to frame width type on shape creation.
+    bool bTextWordwrap = 
xShapePropertySet->getPropertyValue(UNO_NAME_TEXT_WORDWRAP).get<bool>();
+    syncProperty(pShape, RES_FRM_SIZE, MID_FRMSIZE_WIDTH_TYPE,
+                 uno::Any(bTextWordwrap ? text::SizeType::FIX : 
text::SizeType::MIN), pObject);
     syncProperty(pShape, RES_TEXT_VERT_ADJUST, 0,
                  
xShapePropertySet->getPropertyValue(UNO_NAME_TEXT_VERT_ADJUST), pObject);
     text::WritingMode eMode;
@@ -692,6 +696,16 @@ void SwTextBoxHelper::syncProperty(SwFrameFormat* pShape, 
std::u16string_view rP
         if (rValue >>= eMode2)
             syncProperty(pShape, RES_FRAMEDIR, 0, uno::Any(eMode2), pObj);
     }
+    else if (rPropertyName == u"TextWordWrap")
+    {
+        // tdf#81567 shape word wrap to frame width type on shape update.
+        bool bTextWordwrap{};
+        if (rValue >>= bTextWordwrap)
+        {
+            syncProperty(pShape, RES_FRM_SIZE, MID_FRMSIZE_WIDTH_TYPE,
+                         uno::Any(bTextWordwrap ? text::SizeType::FIX : 
text::SizeType::MIN), pObj);
+        }
+    }
     else
         SAL_INFO("sw.core", "SwTextBoxHelper::syncProperty: unhandled 
property: "
                                 << static_cast<OUString>(rPropertyName));

Reply via email to