[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - sw/CppunitTest_sw_core_layout.mk sw/Module_sw.mk sw/qa sw/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Mon Feb 17 10:38:38 UTC 2020


 sw/CppunitTest_sw_core_layout.mk              |   72 ++++++++++++++++++++++++++
 sw/Module_sw.mk                               |    1 
 sw/qa/core/layout/data/table-fly-overlap.docx |binary
 sw/qa/core/layout/layout.cxx                  |   48 +++++++++++++++++
 sw/source/core/layout/tabfrm.cxx              |   30 ++++++++++
 5 files changed, 149 insertions(+), 2 deletions(-)

New commits:
commit 63211894e28aa43e2c54eb9a5d6c3e7669a02142
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Feb 14 16:29:44 2020 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Feb 17 11:38:01 2020 +0100

    sw: fix handling of table vs fly overlaps in the AddVerticalFlyOffsets case
    
    When a table overlaps with a fly frame, Writer creates a fly portion
    inside the relevant cell frame (increasing its height), and Word shifts
    the table down. Both are valid approaches, but the rendering result is
    different in case the table has a border.
    
    So keep the default unchanged, but in case the AddVerticalFlyOffsets
    compat flag (set by the Word importers) is set, avoid the overlap the
    Word way.
    
    Note that the table frame uses the full width (available in the body)
    even for e.g. 50% width tables, so check for the overlap using the print
    area, which does not always overlap.
    
    Finally, don't always require a valid frame area definition from the fly
    frame:
    
    - the mentioned i#46807 bugdoc currently doesn't need that check
    
    - the fly frame area definition becomes valid only after already
      positioning the table, leading to an overlap
    
    Keep that check for the non-compat case, though.
    
    (cherry picked from commit fd7749fddc5a767461dfced55369af48e5a6d561)
    
    Conflicts:
            sw/Module_sw.mk
    
    Change-Id: I9202050befebf2efdbb5395ded6fcb52b378d8e7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88851
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/sw/CppunitTest_sw_core_layout.mk b/sw/CppunitTest_sw_core_layout.mk
new file mode 100644
index 000000000000..28db99cfbece
--- /dev/null
+++ b/sw/CppunitTest_sw_core_layout.mk
@@ -0,0 +1,72 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# 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/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,sw_core_layout))
+
+$(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 \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sw_core_layout, \
+    comphelper \
+    cppu \
+    cppuhelper \
+    sal \
+    sfx \
+    sw \
+    test \
+    unotest \
+    utl \
+    vcl \
+    svt \
+    tl \
+    svl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_core_layout,\
+    boost_headers \
+    libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_core_layout,\
+    -I$(SRCDIR)/sw/inc \
+    -I$(SRCDIR)/sw/source/core/inc \
+    -I$(SRCDIR)/sw/source/uibase/inc \
+    -I$(SRCDIR)/sw/qa/extras/inc \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sw_core_layout,\
+	udkapi \
+	offapi \
+	oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_core_layout))
+$(eval $(call gb_CppunitTest_use_vcl,sw_core_layout))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_core_layout,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,sw_core_layout,\
+    officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_core_layout))
+
+$(eval $(call gb_CppunitTest_use_uiconfigs,sw_core_layout, \
+    modules/swriter \
+))
+
+$(eval $(call gb_CppunitTest_use_more_fonts,sw_core_layout))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 67cfa7792f0d..1e4c723043c5 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -100,6 +100,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
     CppunitTest_sw_unowriter \
     CppunitTest_sw_core_doc \
     CppunitTest_sw_uibase_shells \
+    CppunitTest_sw_core_layout \
 ))
 
 ifneq ($(DISABLE_GUI),TRUE)
diff --git a/sw/qa/core/layout/data/table-fly-overlap.docx b/sw/qa/core/layout/data/table-fly-overlap.docx
new file mode 100644
index 000000000000..a819e855b2eb
Binary files /dev/null and b/sw/qa/core/layout/data/table-fly-overlap.docx differ
diff --git a/sw/qa/core/layout/layout.cxx b/sw/qa/core/layout/layout.cxx
new file mode 100644
index 000000000000..cbea578be4cc
--- /dev/null
+++ b/sw/qa/core/layout/layout.cxx
@@ -0,0 +1,48 @@
+/* -*- 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>
+
+#include <vcl/gdimtf.hxx>
+#include <comphelper/classids.hxx>
+#include <tools/globname.hxx>
+#include <svtools/embedhlp.hxx>
+
+#include <wrtsh.hxx>
+#include <fmtanchr.hxx>
+
+static char const DATA_DIRECTORY[] = "/sw/qa/core/layout/data/";
+
+/// Covers sw/source/core/layout/ fixes.
+class SwCoreLayoutTest : public SwModelTestBase
+{
+};
+
+CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testTableFlyOverlap)
+{
+    // Load a document that has an image anchored in the header.
+    // It also has a table which has the wrap around the image.
+    load(DATA_DIRECTORY, "table-fly-overlap.docx");
+    SwTwips nFlyTop = parseDump("//header/txt/anchored/fly/infos/bounds", "top").toInt32();
+    SwTwips nFlyHeight = parseDump("//header/txt/anchored/fly/infos/bounds", "height").toInt32();
+    SwTwips nFlyBottom = nFlyTop + nFlyHeight;
+    SwTwips nTableFrameTop = parseDump("//tab/infos/bounds", "top").toInt32();
+    SwTwips nTablePrintTop = parseDump("//tab/infos/prtBounds", "top").toInt32();
+    SwTwips nTableTop = nTableFrameTop + nTablePrintTop;
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected greater or equal than: 3579
+    // - Actual  : 2210
+    // i.e. the table's top border overlapped with the image, even if the image's wrap mode was set
+    // to parallel.
+    CPPUNIT_ASSERT_GREATEREQUAL(nFlyBottom, nTableTop);
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/tabfrm.cxx b/sw/source/core/layout/tabfrm.cxx
index a379e71dbaed..05aff953313f 100644
--- a/sw/source/core/layout/tabfrm.cxx
+++ b/sw/source/core/layout/tabfrm.cxx
@@ -35,6 +35,7 @@
 #include <editeng/ulspitem.hxx>
 #include <editeng/brushitem.hxx>
 #include <editeng/boxitem.hxx>
+#include <basegfx/range/b1drange.hxx>
 #include <fmtlsplt.hxx>
 #include <fmtrowsplt.hxx>
 #include <fmtsrnd.hxx>
@@ -2707,6 +2708,9 @@ bool SwTabFrame::CalcFlyOffsets( SwTwips& rUpper,
         long nYDiff = aRectFnSet.YDiff( aRectFnSet.GetTop(getFramePrintArea()), rUpper );
         if( nYDiff > 0 )
             aRectFnSet.AddBottom( aRect, -nYDiff );
+
+        bool bAddVerticalFlyOffsets = rIDSA.get(DocumentSettingId::ADD_VERTICAL_FLY_OFFSETS);
+
         for ( size_t i = 0; i < pPage->GetSortedObjs()->size(); ++i )
         {
             SwAnchoredObject* pAnchoredObj = (*pPage->GetSortedObjs())[i];
@@ -2734,7 +2738,7 @@ bool SwTabFrame::CalcFlyOffsets( SwTwips& rUpper,
                 bool bConsiderFly =
                     // #i46807# - do not consider invalid
                     // Writer fly frames.
-                    pFly->isFrameAreaDefinitionValid() &&
+                    (pFly->isFrameAreaDefinitionValid() || bAddVerticalFlyOffsets) &&
                     // fly anchored at character
                     pFly->IsFlyAtContentFrame() &&
                     // fly overlaps with corresponding table rectangle
@@ -2778,7 +2782,29 @@ bool SwTabFrame::CalcFlyOffsets( SwTwips& rUpper,
                 {
                     const SwFormatSurround   &rSur = pFly->GetFormat()->GetSurround();
                     const SwFormatHoriOrient &rHori= pFly->GetFormat()->GetHoriOrient();
-                    if ( css::text::WrapTextMode_NONE == rSur.GetSurround() )
+                    bool bShiftDown = css::text::WrapTextMode_NONE == rSur.GetSurround();
+                    if (!bShiftDown && bAddVerticalFlyOffsets)
+                    {
+                        if (rSur.GetSurround() == text::WrapTextMode_PARALLEL
+                            && rHori.GetHoriOrient() == text::HoriOrientation::NONE)
+                        {
+                            // We know that wrapping was requested and the table frame overlaps with
+                            // the fly frame. Check if the print area overlaps with the fly frame as
+                            // well (in case the table does not use all the available width).
+                            basegfx::B1DRange aTabRange(
+                                aRectFnSet.GetLeft(aRect) + aRectFnSet.GetLeft(getFramePrintArea()),
+                                aRectFnSet.GetLeft(aRect) + aRectFnSet.GetLeft(getFramePrintArea())
+                                    + aRectFnSet.GetWidth(getFramePrintArea()));
+                            basegfx::B1DRange aFlyRange(aRectFnSet.GetLeft(aFlyRect),
+                                                        aRectFnSet.GetRight(aFlyRect));
+                            // If it does, shift the table down. Do this only in the compat case,
+                            // normally an SwFlyPortion is created instead that increases the height
+                            // of the first table row.
+                            bShiftDown = aTabRange.overlaps(aFlyRange);
+                        }
+                    }
+
+                    if (bShiftDown)
                     {
                         long nBottom = aRectFnSet.GetBottom(aFlyRect);
                         if( aRectFnSet.YDiff( nPrtPos, nBottom ) < 0 )


More information about the Libreoffice-commits mailing list