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 826b20b049449c9c335ce00c781cdb52e4ee0512
Author:     Jaume Pujantell <jaume.pujant...@collabora.com>
AuthorDate: Tue Mar 21 16:03:54 2023 +0100
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Wed Mar 22 16:49:49 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>

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 2669b05fb2a2..f8878ef77bb4 100644
--- a/sw/qa/core/layout/layout.cxx
+++ b/sw/qa/core/layout/layout.cxx
@@ -258,6 +258,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
+    createSwDoc("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 a7c57ec0d609..8675f62e72c9 100644
--- a/sw/source/core/draw/dcontact.cxx
+++ b/sw/source/core/draw/dcontact.cxx
@@ -1975,7 +1975,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 491e860014f2..6dc6cac5d1b2 100644
--- a/sw/source/core/layout/anchoreddrawobject.cxx
+++ b/sw/source/core/layout/anchoreddrawobject.cxx
@@ -32,6 +32,7 @@
 #include <tools/fract.hxx>
 #include <DocumentSettingManager.hxx>
 #include <IDocumentState.hxx>
+#include <IDocumentLayoutAccess.hxx>
 #include <txtfly.hxx>
 #include <viewimp.hxx>
 #include <textboxhelper.hxx>
@@ -516,6 +517,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