sw/qa/core/layout/data/header-textbox.docx   |binary
 sw/qa/core/layout/layout.cxx                 |   15 +++++++++++++++
 sw/source/core/draw/dcontact.cxx             |    9 ++++++++-
 sw/source/core/layout/anchoreddrawobject.cxx |    8 ++++++++
 4 files changed, 31 insertions(+), 1 deletion(-)

New commits:
commit 87c1d93fd2b192f341112a609c741370561879a2
Author:     Jaume Pujantell <jaume.pujant...@collabora.com>
AuthorDate: Tue Mar 21 16:03:54 2023 +0100
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Thu Mar 23 07:10:06 2023 +0000

    Fix wrong layout of textbox in header
    
    In some cases the text box wasn't properly moved afeter it's position
    had been calculated. Also now when the shape and text element are
    brought together in the Z ordering, the one with higher Z moves down.
    
    Change-Id: I0512db4b6466532b5af4e3c091fd65bd0a416381
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149221
    Tested-by: Jenkins
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>
    (cherry picked from commit 826b20b049449c9c335ce00c781cdb52e4ee0512)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149305
    Tested-by: Andras Timar <andras.ti...@collabora.com>

diff --git a/sw/qa/core/layout/data/header-textbox.docx 
b/sw/qa/core/layout/data/header-textbox.docx
new file mode 100644
index 000000000000..4df72cccd3e7
Binary files /dev/null and b/sw/qa/core/layout/data/header-textbox.docx differ
diff --git a/sw/qa/core/layout/layout.cxx b/sw/qa/core/layout/layout.cxx
index abd77b3e217d..3bdeabe9b9f7 100644
--- a/sw/qa/core/layout/layout.cxx
+++ b/sw/qa/core/layout/layout.cxx
@@ -238,6 +238,21 @@ CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, 
testTextboxModification)
     CPPUNIT_ASSERT(!pDocShell->IsModified());
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testTextBoxInHeaderIsPositioned)
+{
+    // Load a document with a floating text box in the header
+    load(DATA_DIRECTORY, "header-textbox.docx");
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    CPPUNIT_ASSERT(pXmlDoc);
+
+    // Without the fix in place, this test would have failed with
+    // - Expected: 8051
+    // - Actual  : 1418
+    // Comparison with 7000 chosen due to variability between devices
+    CPPUNIT_ASSERT_GREATEREQUAL(
+        double(7000), getXPath(pXmlDoc, "//anchored/fly/infos/bounds", 
"left").toDouble());
+}
+
 CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testBtlrNestedCell)
 {
     // Load a document with a nested table, the inner A1 cell has a btlr text 
direction.
diff --git a/sw/source/core/draw/dcontact.cxx b/sw/source/core/draw/dcontact.cxx
index 63011f0171a8..8a6871373ccf 100644
--- a/sw/source/core/draw/dcontact.cxx
+++ b/sw/source/core/draw/dcontact.cxx
@@ -1965,7 +1965,14 @@ void SwDrawContact::ConnectToLayout( const 
SwFormatAnchor* pAnch )
                                             if (pDrawPage)
                                             {
                                                 sal_uInt32 nOrdNum = 
pAnchoredObj->GetDrawObj()->GetOrdNum();
-                                                
pDrawPage->SetObjectOrdNum(maAnchoredDrawObj.GetDrawObj()->GetOrdNumDirect(), 
nOrdNum);
+                                                if 
(maAnchoredDrawObj.GetDrawObj()->GetOrdNum() >= nOrdNum)
+                                                {
+                                                    
pDrawPage->SetObjectOrdNum(maAnchoredDrawObj.GetDrawObj()->GetOrdNumDirect(), 
nOrdNum);
+                                                }
+                                                else
+                                                {
+                                                    
pDrawPage->SetObjectOrdNum(nOrdNum, 
maAnchoredDrawObj.GetDrawObj()->GetOrdNumDirect() + 1);
+                                                }
                                                 break;
                                             }
                                         }
diff --git a/sw/source/core/layout/anchoreddrawobject.cxx 
b/sw/source/core/layout/anchoreddrawobject.cxx
index 3e37961dffd6..6cc597ef9a64 100644
--- a/sw/source/core/layout/anchoreddrawobject.cxx
+++ b/sw/source/core/layout/anchoreddrawobject.cxx
@@ -30,6 +30,7 @@
 #include <tools/fract.hxx>
 #include <DocumentSettingManager.hxx>
 #include <IDocumentState.hxx>
+#include <IDocumentLayoutAccess.hxx>
 #include <txtfly.hxx>
 #include <viewimp.hxx>
 #include <textboxhelper.hxx>
@@ -512,6 +513,13 @@ void SwAnchoredDrawObject::SetDrawObjAnchor()
         DrawObj()->SetAnchorPos( aNewAnchorPos );
         // correct object position, caused by setting new anchor position
         DrawObj()->Move( aMove );
+        // Sync textbox if it wasn't done at move
+        if ( SwTextBoxHelper::isTextBox(&GetFrameFormat(), RES_DRAWFRMFMT) && 
GetFrameFormat().GetDoc() &&
+            
GetFrameFormat().GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell() &&
+            
GetFrameFormat().GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell()->IsInConstructor())
+        {
+            SwTextBoxHelper::changeAnchor(&GetFrameFormat(), 
GetFrameFormat().FindRealSdrObject());
+        }
         // --> #i70122# - missing invalidation
         InvalidateObjRectWithSpaces();
     }

Reply via email to