summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2024-08-05 13:29:37 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2024-08-20 16:38:42 +0200
commit9478aa91f85545aef89bd6b7e7ab67d95326403b (patch)
tree450cd3235e671d905b485d55e30f4482b11174a2
parent4bee213c000e9775101d7bb95fd36d98e8d982e6 (diff)
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 <vmiklos@collabora.com> Tested-by: Jenkins Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172109
-rw-r--r--sw/qa/core/doc/data/text-box-word-wrap.docxbin0 -> 26610 bytes
-rw-r--r--sw/qa/core/doc/doc.cxx19
-rw-r--r--sw/qa/extras/layout/data/tdf138951.odtbin9894 -> 9897 bytes
-rw-r--r--sw/source/core/doc/textboxhelper.cxx14
4 files changed, 33 insertions, 0 deletions
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
--- /dev/null
+++ b/sw/qa/core/doc/data/text-box-word-wrap.docx
Binary files differ
diff --git a/sw/qa/core/doc/doc.cxx b/sw/qa/core/doc/doc.cxx
index 0da481188cbe..5ffbdd113908 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
--- a/sw/qa/extras/layout/data/tdf138951.odt
+++ b/sw/qa/extras/layout/data/tdf138951.odt
Binary files differ
diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index 391a7a2dc63e..31a166738d61 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));