sw/qa/extras/layout/data/tdf141220.docx |binary
 sw/qa/extras/layout/layout2.cxx         |   12 ++++++++++++
 sw/source/core/draw/dcontact.cxx        |    6 +++---
 3 files changed, 15 insertions(+), 3 deletions(-)

New commits:
commit 7163450024000c01d2454aa7aad7f15a425f7ff2
Author:     Daniel Arato (NISZ) <arato.dan...@nisz.hu>
AuthorDate: Mon Sep 27 12:49:57 2021 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Mon Oct 4 13:44:19 2021 +0200

    tdf#141220 sw: fix textbox popped out of off-page shape
    
    When you moved it downwards off the page it was anchored to,
    the textbox inside a shape used to appear exactly one page above
    the shape it was supposed to follow. This is hopefully fixed by
    the present commit.
    
    Regression from c9eb53f200225f2ee6ca695e1326843a487aee51
    (tdf#135198 sw editing: text box fell out of its shape).
    
    Change-Id: Ib388292ca26444daa1900417347824059ee03f07
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122687
    Reviewed-by: László Németh <nem...@numbertext.org>
    Reviewed-by: Balazs Varga <varga.bala...@nisz.hu>
    Tested-by: Balazs Varga <varga.bala...@nisz.hu>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123040
    Tested-by: Jenkins

diff --git a/sw/qa/extras/layout/data/tdf141220.docx 
b/sw/qa/extras/layout/data/tdf141220.docx
new file mode 100644
index 000000000000..a65bdd4b8a51
Binary files /dev/null and b/sw/qa/extras/layout/data/tdf141220.docx differ
diff --git a/sw/qa/extras/layout/layout2.cxx b/sw/qa/extras/layout/layout2.cxx
index 1db5f1e69214..3586afe23d3d 100644
--- a/sw/qa/extras/layout/layout2.cxx
+++ b/sw/qa/extras/layout/layout2.cxx
@@ -1445,6 +1445,18 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf127118)
     assertXPath(pXmlDoc, "/root/page[2]/body/tab/row[1]/cell[1]/txt[1]", 
"WritingMode", "VertBTLR");
 }
 
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf141220)
+{
+    createSwDoc(DATA_DIRECTORY, "tdf141220.docx");
+
+    xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+    sal_Int32 nShapeTop
+        = getXPath(pXmlDoc, "//anchored/SwAnchoredDrawObject/bounds", 
"top").toInt32();
+    sal_Int32 nTextBoxTop = getXPath(pXmlDoc, "//anchored/fly/infos/bounds", 
"top").toInt32();
+    // Make sure the textbox stays inside the shape.
+    CPPUNIT_ASSERT_LESS(static_cast<sal_Int32>(15), nTextBoxTop - nShapeTop);
+}
+
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf121509)
 {
     auto pDoc = createSwDoc(DATA_DIRECTORY, "Tdf121509.odt");
diff --git a/sw/source/core/draw/dcontact.cxx b/sw/source/core/draw/dcontact.cxx
index 1f0632850ad2..d2554e0ab5ae 100644
--- a/sw/source/core/draw/dcontact.cxx
+++ b/sw/source/core/draw/dcontact.cxx
@@ -1337,7 +1337,6 @@ void SwDrawContact::Changed_( const SdrObject& rObj,
             }
 
             // tdf#135198: keep text box together with its shape
-            SwRect aObjRect(rObj.GetSnapRect());
             const SwPageFrame* rPageFrame = pAnchoredDrawObj->GetPageFrame();
             if (rPageFrame && rPageFrame->isFrameAreaPositionValid())
             {
@@ -1352,10 +1351,11 @@ void SwDrawContact::Changed_( const SdrObject& rObj,
 
                 SfxItemSet aSyncSet(pDoc->GetAttrPool(),
                                     svl::Items<RES_VERT_ORIENT, RES_ANCHOR>{});
-                aSyncSet.Put(SwFormatVertOrient(aObjRect.Top() - 
rPageFrame->getFrameArea().Top(),
+                bool bRelToTableCell(false);
+                
aSyncSet.Put(SwFormatVertOrient(pAnchoredDrawObj->GetRelPosToPageFrame(false, 
bRelToTableCell).getY(),
                                                 text::VertOrientation::NONE,
                                                 
text::RelOrientation::PAGE_FRAME));
-                aSyncSet.Put(SwFormatAnchor(RndStdIds::FLY_AT_PAGE, 
pAnchoredDrawObj->GetPageFrame()->GetPhyPageNum()));
+                aSyncSet.Put(SwFormatAnchor(RndStdIds::FLY_AT_PAGE, 
rPageFrame->GetPhyPageNum()));
 
                 SwTextBoxHelper::syncFlyFrameAttr(*GetFormat(), aSyncSet);
 

Reply via email to