sw/qa/writerfilter/dmapper/DomainMapperTableHandler.cxx       |   25 ++++++++++
 sw/qa/writerfilter/dmapper/data/floattable-nested-layout.docx |binary
 sw/source/writerfilter/dmapper/DomainMapperTableHandler.cxx   |    3 -
 3 files changed, 27 insertions(+), 1 deletion(-)

New commits:
commit 94113befe22a3698f6221efc1d402599b64aa024
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Tue Jan 21 08:19:57 2025 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Jan 22 15:20:55 2025 +0100

    tdf#161001 sw floattable: require in-header/footer for non-follow-text-flow
    
    Open the bugdoc, the in-body floating table has an inner floating table
    which is rendered above the outer table, not inside it.
    
    This went wrong in commit f74a6ef94ac957e4c146fc9923d30ce6bd31b5ce
    (tdf#159453 sw floattable: fix unexpected overlap of in-header fly and
    body text, 2024-02-13), where the use-case was an in-header floating
    table interacting with body text.
    
    The more general case is in-body floating tables interacting with
    in-body text, so fix the problem by restricting the custom
    IsFollowingTextFlow=false property for in-header floating tables.
    
    Change-Id: I902f232e3c840ff0279d8ed6c2329ba48a03b4e1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180534
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins
    (cherry picked from commit 524c266f0f0a3cdccfa9feecfba2a19c9a29b701)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180545
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    (cherry picked from commit 62af1be5b58f69f10fb1aaa300a5106d2382a785)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180585

diff --git a/sw/qa/writerfilter/dmapper/DomainMapperTableHandler.cxx 
b/sw/qa/writerfilter/dmapper/DomainMapperTableHandler.cxx
index 4ae51bfc0758..b9f75a4ac531 100644
--- a/sw/qa/writerfilter/dmapper/DomainMapperTableHandler.cxx
+++ b/sw/qa/writerfilter/dmapper/DomainMapperTableHandler.cxx
@@ -253,6 +253,31 @@ CPPUNIT_TEST_FIXTURE(Test, testTableStyleParaBorderSpacing)
     // i.e. the top and bottom border and its 1pt spacing was not set on the 
in-table paragraph.
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(35), nTopBorderDistance);
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testDOCXFloatingTableNestedLayout)
+{
+    // Given a floating table inside an outer table, both in body text:
+    // When loading that document:
+    loadFromFile(u"floattable-nested-layout.docx");
+
+    // Then make sure the inner table stays inside the outer table:
+    uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
+    css::uno::Reference<qa::XDumper> xDumper(xModel->getCurrentController(), 
uno::UNO_QUERY);
+    OString aDump = xDumper->dump(u"layout"_ustr).toUtf8();
+    auto pCharBuffer = reinterpret_cast<const xmlChar*>(aDump.getStr());
+    xmlDocUniquePtr pXmlDoc(xmlParseDoc(pCharBuffer));
+    sal_Int32 nFlyTop = getXPath(pXmlDoc, "//fly/infos/bounds", 
"top").toInt32();
+    sal_Int32 nFlyBottom = getXPath(pXmlDoc, "//fly/infos/bounds", 
"bottom").toInt32();
+    sal_Int32 nTableTop = getXPath(pXmlDoc, "//page[1]/body/tab/infos/bounds", 
"top").toInt32();
+    sal_Int32 nTableBottom
+        = getXPath(pXmlDoc, "//page[1]/body/tab/infos/bounds", 
"bottom").toInt32();
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected greater than: 1839
+    // - Actual  : 360
+    // i.e. the floating table was outside the outer table.
+    CPPUNIT_ASSERT_GREATER(nTableTop, nFlyTop);
+    CPPUNIT_ASSERT_LESS(nTableBottom, nFlyBottom);
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/qa/writerfilter/dmapper/data/floattable-nested-layout.docx 
b/sw/qa/writerfilter/dmapper/data/floattable-nested-layout.docx
new file mode 100644
index 000000000000..d17a97969f4c
Binary files /dev/null and 
b/sw/qa/writerfilter/dmapper/data/floattable-nested-layout.docx differ
diff --git a/sw/source/writerfilter/dmapper/DomainMapperTableHandler.cxx 
b/sw/source/writerfilter/dmapper/DomainMapperTableHandler.cxx
index 1a366dff4d2c..6c2a72ddeb9e 100644
--- a/sw/source/writerfilter/dmapper/DomainMapperTableHandler.cxx
+++ b/sw/source/writerfilter/dmapper/DomainMapperTableHandler.cxx
@@ -1640,7 +1640,8 @@ void DomainMapperTableHandler::endTable(unsigned int 
nestedTableLevel)
                 if (it != aFrameProperties.end())
                 {
                     it->Value >>= nVertOrientRelation;
-                    if (nVertOrientRelation == 
text::RelOrientation::PAGE_FRAME)
+                    bool bInHeaderFooter = m_rDMapper_Impl.IsInHeaderFooter();
+                    if (nVertOrientRelation == 
text::RelOrientation::PAGE_FRAME && bInHeaderFooter)
                     {
                         // If vertical relation is page, follow-text-flow is 
not useful and causes
                         // unwanted wrap of body text around in-header 
floating table, so avoid it.

Reply via email to