sw/qa/core/layout/flycnt.cxx     |   42 +++++++++++++++++++++++++++++++++++++++
 sw/source/core/layout/flycnt.cxx |    7 ++++++
 2 files changed, 49 insertions(+)

New commits:
commit cdd6849307eef61cad63c4f03983028e7d1ae343
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon Nov 27 08:36:37 2023 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Tue Nov 28 17:25:05 2023 +0100

    sw floattable, per-frame wrap-on-all-pages mode: add layout
    
    The anchor text of a floating table is normally wrapped around the table
    only on the last page of the table. This property requests to wrap on
    all pages instead for this frame.
    
    Commit 7d7ca347fafa7a06094b00e8fb0d0452c4c81366 (sw floattable, wrap on
    all pages: add layout, 2023-10-13) already arranged the layout code to
    go via the per-frame SwFlyAtContentFrame::IsWrapOnAllPages(), so only
    that needs updating.
    
    Instead of always deciding this at a per-doc level, first check if the
    frame itself requests the on-all-pages behavior. Otherwise keep deciding
    this on a per-doc level. This is meant to please what the OASIS/ODT
    proposal wants and also keeps the Word-style per-doc setting.
    
    The ODT filter still needs doing.
    
    (cherry picked from commit 272c3548c4d2362eb737947c8cbb017e2d55aae1)
    
    Change-Id: Ibf10b5f016d70e6fe948d5273cc1fb1d98495586
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160018
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sw/qa/core/layout/flycnt.cxx b/sw/qa/core/layout/flycnt.cxx
index 557d94eee63c..9fb2e2ed0f4f 100644
--- a/sw/qa/core/layout/flycnt.cxx
+++ b/sw/qa/core/layout/flycnt.cxx
@@ -31,6 +31,7 @@
 #include <ndtxt.hxx>
 #include <dflyobj.hxx>
 #include <IDocumentSettingAccess.hxx>
+#include <formatwraptextatflystart.hxx>
 
 namespace
 {
@@ -1221,6 +1222,47 @@ CPPUNIT_TEST_FIXTURE(Test, testSplitFlyWrapOnAllPages)
     CPPUNIT_ASSERT(!pPage2Anchor->GetFollow());
     CPPUNIT_ASSERT_EQUAL(OUString("didn't bode well."), aAnchor2Text);
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testSplitFlyPerFrameWrapOnAllPages)
+{
+    // Given a document where we want to wrap on all pages, around a split 
floating table:
+    createSwDoc("floattable-wrap-on-all-pages.docx");
+    SwDoc* pDoc = getSwDoc();
+    SwFrameFormats& rFlys = *pDoc->GetSpzFrameFormats();
+    SwFrameFormat* pFly = rFlys[0];
+    SfxItemSet aSet(pFly->GetAttrSet());
+    SwFormatWrapTextAtFlyStart aItem(true);
+    aSet.Put(aItem);
+    pDoc->SetFlyFrameAttr(*pFly, aSet);
+
+    // When formatting that document:
+    SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
+    pWrtShell->Reformat();
+
+    // Then make sure that the anchor text is also split between page 1 and 
page 2:
+    SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
+    auto pPage1 = pLayout->Lower()->DynCastPageFrame();
+    CPPUNIT_ASSERT(pPage1);
+    auto pPage1Anchor = pPage1->FindLastBodyContent()->DynCastTextFrame();
+    CPPUNIT_ASSERT(pPage1Anchor);
+    OUString aAnchor1Text(pPage1Anchor->GetText().subView(
+        static_cast<sal_Int32>(pPage1Anchor->GetOffset()),
+        static_cast<sal_Int32>(pPage1Anchor->GetFollow()->GetOffset()
+                               - pPage1Anchor->GetOffset())));
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: He heard quiet steps behind him. That
+    // - Actual  :
+    // i.e. the first page had no anchor text, only the second.
+    CPPUNIT_ASSERT_EQUAL(OUString("He heard quiet steps behind him. That "), 
aAnchor1Text);
+    auto pPage2 = pPage1->GetNext()->DynCastPageFrame();
+    CPPUNIT_ASSERT(pPage2);
+    auto pPage2Anchor = pPage2->FindLastBodyContent()->DynCastTextFrame();
+    CPPUNIT_ASSERT(pPage2Anchor);
+    OUString aAnchor2Text(
+        
pPage2Anchor->GetText().subView(static_cast<sal_Int32>(pPage2Anchor->GetOffset())));
+    CPPUNIT_ASSERT(!pPage2Anchor->GetFollow());
+    CPPUNIT_ASSERT_EQUAL(OUString("didn't bode well."), aAnchor2Text);
+}
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/layout/flycnt.cxx b/sw/source/core/layout/flycnt.cxx
index 38a2ae6927df..0e0d198f5d3f 100644
--- a/sw/source/core/layout/flycnt.cxx
+++ b/sw/source/core/layout/flycnt.cxx
@@ -52,6 +52,7 @@
 #include <unoprnms.hxx>
 #include <rootfrm.hxx>
 #include <bodyfrm.hxx>
+#include <formatwraptextatflystart.hxx>
 
 using namespace ::com::sun::star;
 
@@ -1786,6 +1787,12 @@ void SwFlyAtContentFrame::DelEmpty()
 
 bool SwFlyAtContentFrame::IsWrapOnAllPages() const
 {
+    const SwFormatWrapTextAtFlyStart& rWrapTextAtFlyStart = 
GetFormat()->GetWrapTextAtFlyStart();
+    if (rWrapTextAtFlyStart.GetValue())
+    {
+        return true;
+    }
+
     const SwRootFrame* pRootFrame = getRootFrame();
     if (!pRootFrame)
     {

Reply via email to