sw/CppunitTest_sw_core_layout.mk                  |    1 
 sw/qa/core/layout/data/table-print-area-left.docx |binary
 sw/qa/core/layout/tabfrm.cxx                      |   38 ++++++++++++++++++++++
 sw/source/core/layout/tabfrm.cxx                  |    7 ++--
 4 files changed, 44 insertions(+), 2 deletions(-)

New commits:
commit 3b92f905115cd789a4dafb4e2ee8ee6043693ea8
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed May 10 23:28:03 2023 +0100
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Mon Jun 3 10:27:47 2024 +0500

    tdf#154775 sw layout: fix unexpected large table print area left margin
    
    The bugdoc had 2 pages, but the second page's content was mostly a
    table. This table was rendered outside the page frame, so it was
    practically invisible.
    
    This started after commit fd7749fddc5a767461dfced55369af48e5a6d561 (sw:
    fix handling of table vs fly overlaps in the AddVerticalFlyOffsets case,
    2020-02-14), and that behavior is still wanted to have correct table
    borders, but that change introduced an inconsistent case: we started to
    always accept an invalid frame area definition of the fly, but we only
    shifted the content down in the text::HoriOrientation::NONE case.
    
    Fix the problem by limiting the "accept invalid frame area definition"
    based on the horizontal orientation, so we either both ignore the
    validity flag & shift down or do none of this. This keeps the original
    bug fixed, but addresses the new "no visible table" problem.
    
    Note that this only fixes the regression part; once the image from the
    header is removed and undo is invoked, a similar problem still happens.
    But that is a pre-existing, separate problem.
    
    Change-Id: Id752c169b7c7fb6b75e6603ad29aaafbb676b8a5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151652
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/CppunitTest_sw_core_layout.mk b/sw/CppunitTest_sw_core_layout.mk
index 9a7a4710dfb7..1c991f8c19ba 100644
--- a/sw/CppunitTest_sw_core_layout.mk
+++ b/sw/CppunitTest_sw_core_layout.mk
@@ -15,6 +15,7 @@ $(eval $(call 
gb_CppunitTest_use_common_precompiled_header,sw_core_layout))
 
 $(eval $(call gb_CppunitTest_add_exception_objects,sw_core_layout, \
     sw/qa/core/layout/layout \
+    sw/qa/core/layout/tabfrm \
 ))
 
 $(eval $(call gb_CppunitTest_use_libraries,sw_core_layout, \
diff --git a/sw/qa/core/layout/data/table-print-area-left.docx 
b/sw/qa/core/layout/data/table-print-area-left.docx
new file mode 100644
index 000000000000..e326bed82f39
Binary files /dev/null and b/sw/qa/core/layout/data/table-print-area-left.docx 
differ
diff --git a/sw/qa/core/layout/tabfrm.cxx b/sw/qa/core/layout/tabfrm.cxx
new file mode 100644
index 000000000000..4b991c27dbf8
--- /dev/null
+++ b/sw/qa/core/layout/tabfrm.cxx
@@ -0,0 +1,38 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <swmodeltestbase.hxx>
+
+/// Covers sw/source/core/layout/tabfrm.cxx fixes.
+class Test : public SwModelTestBase
+{
+public:
+    Test()
+        : SwModelTestBase("/sw/qa/core/layout/data/")
+    {
+    }
+};
+
+CPPUNIT_TEST_FIXTURE(Test, testTablePrintAreaLeft)
+{
+    // Given a document with a header containing an image, and also with an 
overlapping table:
+    createSwDoc("table-print-area-left.docx");
+
+    // When laying out that document & parsing the left margin of the table:
+    SwTwips nTablePrintLeft = parseDump("//tab/infos/prtBounds", 
"left").toInt32();
+
+    // Then make sure it has ~no left margin:
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: 5
+    // - Actual  : 10646
+    // i.e. the table was shifted outside the page, was invisible.
+    CPPUNIT_ASSERT_EQUAL(static_cast<SwTwips>(5), nTablePrintLeft);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index d2e4618bf317..abf9fa1bb4f0 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -2860,10 +2860,14 @@ bool SwTabFrame::CalcFlyOffsets( SwTwips& rUpper,
                 //   at the page frame, the table is on, but it's anchor 
character
                 //   text frame has already changed its page.
                 const SwTextFrame* pAnchorCharFrame = 
pFly->FindAnchorCharFrame();
+                const SwFormatHoriOrient& rHori = 
pFly->GetFormat()->GetHoriOrient();
+                // Only consider invalid Writer fly frames if they'll be 
shifted down.
+                bool bIgnoreFlyValidity
+                    = bAddVerticalFlyOffsets && rHori.GetHoriOrient() == 
text::HoriOrientation::NONE;
                 bool bConsiderFly =
                     // #i46807# - do not consider invalid
                     // Writer fly frames.
-                    (pFly->isFrameAreaDefinitionValid() || 
bAddVerticalFlyOffsets) &&
+                    (pFly->isFrameAreaDefinitionValid() || bIgnoreFlyValidity) 
&&
                     // fly anchored at character or at paragraph
                     pFly->IsFlyAtContentFrame() &&
                     // fly overlaps with corresponding table rectangle
@@ -2907,7 +2911,6 @@ bool SwTabFrame::CalcFlyOffsets( SwTwips& rUpper,
                 if ( bConsiderFly )
                 {
                     const SwFormatSurround   &rSur = 
pFly->GetFormat()->GetSurround();
-                    const SwFormatHoriOrient &rHori= 
pFly->GetFormat()->GetHoriOrient();
                     bool bShiftDown = css::text::WrapTextMode_NONE == 
rSur.GetSurround();
                     if (!bShiftDown && bAddVerticalFlyOffsets)
                     {

Reply via email to