Revert "tdf#137881 sw: fix text box size regression"

This reverts commit f2eef84ff03660cbb46a76c317e640e054ed0a56.

Reason for revert: https://bugs.documentfoundation.org/show_bug.cgi?id=135198#c9

This also reverts part of 768cfcee178b284be6d96d384364e59e40ecb375
without breaking tdf#137960 nor tdf#137964

Change-Id: Ifa418e66b8a45c6204babfae6513ca67aed93289
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105545
Reviewed-by: Dániel Arató <arato.daniel@nisz.hu>
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Tested-by: Xisco Fauli <xiscofauli@libreoffice.org>
diff --git a/sw/qa/core/layout/data/bottom-textbox-size.docx b/sw/qa/core/layout/data/bottom-textbox-size.docx
deleted file mode 100644
index a1c700f..0000000
--- a/sw/qa/core/layout/data/bottom-textbox-size.docx
+++ /dev/null
Binary files differ
diff --git a/sw/qa/core/layout/layout.cxx b/sw/qa/core/layout/layout.cxx
index ff33932..a992a32 100644
--- a/sw/qa/core/layout/layout.cxx
+++ b/sw/qa/core/layout/layout.cxx
@@ -196,21 +196,6 @@ CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testTextBoxStaysInsideShape)
                           nTextBoxTopAfter < nTextBoxTopBefore);
}

CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testTextBoxSizeAtBottomOfPage)
{
    // tdf#137881: check whether text box at the bottom of the page stays the right size
    load(DATA_DIRECTORY, "bottom-textbox-size.docx");
    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
    SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
    SdrObject* pTextBoxObj = pPage->GetObj(0);

    uno::Reference<drawing::XShape> xShape(pTextBoxObj->getUnoShape(), uno::UNO_QUERY_THROW);
    const sal_Int32 nHeight = xShape->getSize().Height;
    CPPUNIT_ASSERT_EQUAL_MESSAGE("text box was not supposed to be resized on fileopen",
                                 static_cast<sal_Int32>(2200), nHeight);
}

CPPUNIT_PLUGIN_IMPLEMENT();

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 5919d1a..ec680a6 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -1065,7 +1065,8 @@ DECLARE_OOXMLIMPORT_TEST(textboxWpsOnly, "textbox-wps-only.docx")
    if ( nsScreen.frame.size.width * scaleFactor > 4000 )
        return;
#endif
    CPPUNIT_ASSERT_EQUAL(sal_Int32(2805), getProperty<sal_Int32>(xFrame, "VertOrientPosition"));
    // Vertically oriented to page due to tdf#135198
    CPPUNIT_ASSERT_EQUAL(sal_Int32(5304), getProperty<sal_Int32>(xFrame, "VertOrientPosition"));
}

DECLARE_OOXMLIMPORT_TEST(testGroupshapeRelsize, "groupshape-relsize.docx")
diff --git a/sw/source/core/layout/objectformattertxtfrm.cxx b/sw/source/core/layout/objectformattertxtfrm.cxx
index e3a9b4e..8531383 100644
--- a/sw/source/core/layout/objectformattertxtfrm.cxx
+++ b/sw/source/core/layout/objectformattertxtfrm.cxx
@@ -355,41 +355,24 @@ bool SwObjectFormatterTextFrame::DoFormatObjs()
                SwFrameFormat& rFormat = pObj->GetFrameFormat();
                if (SwTextBoxHelper::isTextBox(&rFormat, RES_DRAWFRMFMT))
                {
                    const SwFrameFormat* pOtherFormat = SwTextBoxHelper::getOtherTextBoxFormat(&rFormat, RES_DRAWFRMFMT);
                    if (rFormat.GetVertOrient().GetPos() != pOtherFormat->GetVertOrient().GetPos() ||
                        rFormat.GetAnchor().GetAnchorId() != pOtherFormat->GetAnchor().GetAnchorId())
                    if (const SwPageFrame* pPageFrame = pObj->GetPageFrame())
                    {
                        if (const SwPageFrame* pPageFrame = pObj->GetPageFrame())
                        {
                            SwDoc* pDoc = rFormat.GetDoc();
                        SwDoc* pDoc = rFormat.GetDoc();

                            // avoid Undo creation,
                            ::sw::UndoGuard const ug(pDoc->GetIDocumentUndoRedo());
                        // avoid Undo creation,
                        ::sw::UndoGuard const ug(pDoc->GetIDocumentUndoRedo());

                            SfxItemSet aSet(pDoc->GetAttrPool(),
                                            svl::Items<RES_VERT_ORIENT, RES_ANCHOR>{});
                        SfxItemSet aSet(pDoc->GetAttrPool(),
                                        svl::Items<RES_VERT_ORIENT, RES_ANCHOR>{});

                            const SwRect& rPageFrameArea = pPageFrame->getFrameArea();
                            if (rFormat.GetVertOrient().GetPos() != pOtherFormat->GetVertOrient().GetPos())
                            {
                                aSet.Put(SwFormatVertOrient(pObj->GetObjRect().Top() - rPageFrameArea.Top(),
                                                            text::VertOrientation::NONE,
                                                            text::RelOrientation::PAGE_FRAME));
                            }
                            if (rFormat.GetHoriOrient().GetPos() != pOtherFormat->GetHoriOrient().GetPos())
                            {
                                aSet.Put(rFormat.GetHoriOrient());
                            }
                            if (rFormat.GetAnchor().GetAnchorId() != pOtherFormat->GetAnchor().GetAnchorId())
                            {
                                aSet.Put(SwFormatAnchor(RndStdIds::FLY_AT_PAGE, pObj->GetPageFrame()->GetPhyPageNum()));
                            }
                        const SwRect& rPageFrameArea = pPageFrame->getFrameArea();
                        aSet.Put(SwFormatVertOrient(pObj->GetObjRect().Top() - rPageFrameArea.Top(),
                                                    text::VertOrientation::NONE,
                                                    text::RelOrientation::PAGE_FRAME));

                            if (aSet.Count())
                            {
                                SwTextBoxHelper::syncFlyFrameAttr(rFormat, aSet);
                            }
                        }
                        aSet.Put(SwFormatAnchor(RndStdIds::FLY_AT_PAGE, pObj->GetPageFrame()->GetPhyPageNum()));

                        SwTextBoxHelper::syncFlyFrameAttr(rFormat, aSet);
                    }
                }
            }