sw/qa/core/layout/data/table-print-area-left.docx |binary
 sw/qa/core/layout/tabfrm.cxx                      |   16 ++++++++++++++++
 sw/source/core/layout/tabfrm.cxx                  |    7 +++++--
 3 files changed, 21 insertions(+), 2 deletions(-)

New commits:
commit 5e0534ca76d3e666e7516ec7a9b05afdbfe4b056
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed May 10 23:28:03 2023 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Wed Dec 6 20:47:51 2023 +0100

    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.
    
    (cherry picked from commit 1b5bc2ae2f19a190bf588a5a26c4d125c3960991)
    
    Conflicts:
            sw/CppunitTest_sw_core_layout.mk
            sw/qa/core/layout/tabfrm.cxx
            sw/source/core/layout/tabfrm.cxx
    
    Change-Id: Id752c169b7c7fb6b75e6603ad29aaafbb676b8a5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160395
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

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
index 7642c3d29ea6..84f7ba48c572 100644
--- a/sw/qa/core/layout/tabfrm.cxx
+++ b/sw/qa/core/layout/tabfrm.cxx
@@ -30,6 +30,22 @@ public:
     }
 };
 
+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);
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testTableMissingJoin)
 {
     // Given a document with a table on page 2:
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index d7f3d303289c..87ab7c05c26f 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -3071,10 +3071,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
@@ -3127,7 +3131,6 @@ bool SwTabFrame::CalcFlyOffsets( SwTwips& rUpper,
                     else if (!bWrapThrough && nSurround == 
text::WrapTextMode_THROUGH)
                         nSurround = text::WrapTextMode_PARALLEL;
 
-                    const SwFormatHoriOrient &rHori= 
pFly->GetFormat()->GetHoriOrient();
                     bool bShiftDown = css::text::WrapTextMode_NONE == 
nSurround;
                     if (!bShiftDown && bAddVerticalFlyOffsets)
                     {

Reply via email to