diff --git a/sw/inc/textboxhelper.hxx b/sw/inc/textboxhelper.hxx index 0c20711b109c..51261a8f77a3 100644 --- a/sw/inc/textboxhelper.hxx +++ b/sw/inc/textboxhelper.hxx @@ -72,6 +72,8 @@ public: /// Get a property of the underlying TextFrame. static void getProperty(SwFrameFormat const* pShape, sal_uInt16 nWID, sal_uInt8 nMemberID, css::uno::Any& rValue); + /// Get a property of the underlying TextFrame. + static css::uno::Any getProperty(SwFrameFormat const* pShape, OUString sPropName); /// There are two types of enum of anchor type, so this function maps this. static css::text::TextContentAnchorType mapAnchorType(const RndStdIds& rAnchorID); diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx index 3d185a72afb9..cf9781f00606 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx @@ -1067,8 +1067,7 @@ DECLARE_OOXMLIMPORT_TEST(textboxWpsOnly, "textbox-wps-only.docx") if ( nsScreen.frame.size.width * scaleFactor > 4000 ) return; #endif - // Vertically oriented to page due to tdf#135198 - CPPUNIT_ASSERT_EQUAL(sal_Int32(5304), getProperty(xFrame, "VertOrientPosition")); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2805), getProperty(xFrame, "VertOrientPosition")); } DECLARE_OOXMLIMPORT_TEST(testGroupshapeRelsize, "groupshape-relsize.docx") diff --git a/sw/qa/uitest/data/tdf137803.odt b/sw/qa/uitest/data/tdf137803.odt new file mode 100644 index 000000000000..8f2f7d5dc49b Binary files /dev/null and b/sw/qa/uitest/data/tdf137803.odt differ diff --git a/sw/qa/uitest/writer_tests7/tdf137803.py b/sw/qa/uitest/writer_tests7/tdf137803.py new file mode 100644 index 000000000000..249dbbb7cacc --- /dev/null +++ b/sw/qa/uitest/writer_tests7/tdf137803.py @@ -0,0 +1,61 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +from uitest.framework import UITestCase +from libreoffice.uno.propertyvalue import mkPropertyValues +from uitest.uihelper.common import get_state_as_dict +import importlib +import time +import org.libreoffice.unotest +import pathlib + +def get_url_for_data_file(file_name): + return pathlib.Path(org.libreoffice.unotest.makeCopyFromTDOC(file_name)).as_uri() + +class tdf137803(UITestCase): + def test_tdf137803(self): + # load the sample file + self.ui_test.load_file(get_url_for_data_file("tdf137803.odt")) + xWriterDoc = self.xUITest.getTopFocusWindow() + xWriterEdit = xWriterDoc.getChild("writer_edit") + document = self.ui_test.get_component() + + # select the shape + self.xUITest.executeCommand(".uno:JumpToNextFrame") + self.ui_test.wait_until_child_is_available(xWriterEdit, 'metricfield') + + # open textattrs dialog + self.ui_test.execute_dialog_through_command(".uno:TextAttributes") + TextDialog = self.xUITest.getTopFocusWindow(); + + # check autosize on + TSB_AUTOGROW_SIZE = TextDialog.getChild('TSB_AUTOGROW_SIZE') + TSB_AUTOGROW_SIZE.executeAction("CLICK",tuple()) + ok = TextDialog.getChild("ok") + self.ui_test.close_dialog_through_button(ok) + + # get the shape + drawPage = document.getDrawPages().getByIndex(0) + shape = drawPage.getByIndex(0) + + # and the textbox + frame = shape.getText() + + # get the positions + shapeYPos = shape.getPropertyValue("VertOrientPosition") + frameYPos = frame.getPropertyValue("VertOrientPosition") + shpsize = shape.getSize().Height + + xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit') + xToolkit.processEventsToIdle() + + # without the fix, at this point the textbox falls apart so this won't be passed + self.assertLess(frameYPos, shapeYPos + shpsize) + + # close the doc + self.ui_test.close_doc() + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx index 848a8916e293..634685b1b430 100644 --- a/sw/source/core/doc/textboxhelper.cxx +++ b/sw/source/core/doc/textboxhelper.cxx @@ -582,6 +582,21 @@ void SwTextBoxHelper::getProperty(SwFrameFormat const* pShape, sal_uInt16 nWID, } } +css::uno::Any SwTextBoxHelper::getProperty(SwFrameFormat const* pShape, OUString sPropName) +{ + if (!pShape) + return uno::Any(); + + SwFrameFormat* pFormat = getOtherTextBoxFormat(pShape, RES_DRAWFRMFMT); + if (!pFormat) + return uno::Any(); + + uno::Reference const xPropertySet( + SwXTextFrame::CreateXTextFrame(*pFormat->GetDoc(), pFormat), uno::UNO_QUERY); + + return xPropertySet->getPropertyValue(sPropName); +} + void SwTextBoxHelper::syncProperty(SwFrameFormat* pShape, sal_uInt16 nWID, sal_uInt8 nMemberID, const css::uno::Any& rValue) { @@ -663,6 +678,9 @@ void SwTextBoxHelper::syncProperty(SwFrameFormat* pShape, sal_uInt16 nWID, sal_u case RES_FRM_SIZE: switch (nMemberID) { + case MID_FRMSIZE_WIDTH_TYPE: + aPropertyName = UNO_NAME_WIDTH_TYPE; + break; case MID_FRMSIZE_IS_AUTO_HEIGHT: aPropertyName = UNO_NAME_FRAME_ISAUTOMATIC_HEIGHT; break; @@ -1040,9 +1058,15 @@ void SwTextBoxHelper::updateTextBoxMargin(SdrObject* pObj) syncProperty(pParentFormat, UNO_NAME_TEXT_HORZADJUST, xPropertySet->getPropertyValue(UNO_NAME_TEXT_HORZADJUST)); - //FIXME: Sync autogrow: needs repositioning after sync - //syncProperty(pParentFormat, RES_FRM_SIZE, MID_FRMSIZE_IS_AUTO_HEIGHT, - // xPropertySet->getPropertyValue(UNO_NAME_TEXT_AUTOGROWHEIGHT)); + // tdf137803: Sync autogrow: + const bool bIsAutoGrow + = xPropertySet->getPropertyValue(UNO_NAME_TEXT_AUTOGROWHEIGHT).get(); + const bool bIsAutoWrap = xPropertySet->getPropertyValue(UNO_NAME_TEXT_WORDWRAP).get(); + + syncProperty(pParentFormat, RES_FRM_SIZE, MID_FRMSIZE_IS_AUTO_HEIGHT, uno::Any(bIsAutoGrow)); + + syncProperty(pParentFormat, RES_FRM_SIZE, MID_FRMSIZE_WIDTH_TYPE, + uno::Any(bIsAutoWrap ? text::SizeType::FIX : text::SizeType::MIN)); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/layout/flycnt.cxx b/sw/source/core/layout/flycnt.cxx index c139bd864cfa..da79d707ecdf 100644 --- a/sw/source/core/layout/flycnt.cxx +++ b/sw/source/core/layout/flycnt.cxx @@ -47,6 +47,10 @@ #include "objectformattertxtfrm.hxx" #include #include +#include +#include +#include +#include using namespace ::com::sun::star; @@ -379,6 +383,7 @@ void SwFlyAtContentFrame::MakeAll(vcl::RenderContext* pRenderContext) SwRectFnSet aRectFnSet(this); Point aOldPos( aRectFnSet.GetPos(getFrameArea()) ); SwFlyFreeFrame::MakeAll(pRenderContext); + const bool bPosChgDueToOwnFormat = aOldPos != aRectFnSet.GetPos(getFrameArea()); // #i3317# @@ -506,6 +511,28 @@ void SwFlyAtContentFrame::MakeAll(vcl::RenderContext* pRenderContext) } } } + // tdf#137803: Fix the position of the shape during autoSize + SwFrameFormat* pShapeFormat + = SwTextBoxHelper::getOtherTextBoxFormat(GetFormat(), RES_FLYFRMFMT); + // FIXME: According to tdf37153, ignore FollowTextFlow objs, because + // wrong position will applied in that case. FollowTextFlow needs fix. + if (pShapeFormat && !pShapeFormat->GetFollowTextFlow().GetValue() && + SwTextBoxHelper::getProperty(pShapeFormat, + UNO_NAME_FRAME_ISAUTOMATIC_HEIGHT).get() ) + { + // get the text area of the shape + const tools::Rectangle aTextRectangle + = SwTextBoxHelper::getTextRectangle(pShapeFormat, false); + // get the original textframe position + SwFormatHoriOrient aHOri = pShapeFormat->GetHoriOrient(); + SwFormatVertOrient aVOri = pShapeFormat->GetVertOrient(); + // calc the right position of the shape depending on text area + aHOri.SetPos(aHOri.GetPos() + aTextRectangle.getX()); + aVOri.SetPos(aVOri.GetPos() + aTextRectangle.getY()); + // save the new position for the shape + GetFormat()->SetFormatAttr(aHOri); + GetFormat()->SetFormatAttr(aVOri); + } if ( bOsz || bConsiderWrapInfluenceDueToOverlapPrevCol || // #i40444# bConsiderWrapInfluenceDueToMovedFwdAnchor )