From 33dcd5f61e1966accf9b68c662bac7cb70352ca1 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 13 Apr 2018 15:09:53 +0200 Subject: tdf#116985 sw: fix geometry of textbox of shape with relative size Relative size of shapes are calculated by the layout, so the normal doc model-level synchronization between the shape and its textbox was not enough. Change-Id: Ia6f460132efaf03a7ba3a023cf751f6fff74404d Reviewed-on: https://gerrit.libreoffice.org/52831 Reviewed-by: Miklos Vajna Tested-by: Jenkins (cherry picked from commit c8b976ac64c9cac360f7c4fd9844fcfac7ba25a8) Reviewed-on: https://gerrit.libreoffice.org/52971 Reviewed-by: Mike Kaganski --- sw/qa/extras/ooxmlexport/data/tdf116985.docx | Bin 0 -> 13508 bytes sw/qa/extras/ooxmlexport/ooxmlexport11.cxx | 10 ++++++++++ sw/source/core/layout/anchoreddrawobject.cxx | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 sw/qa/extras/ooxmlexport/data/tdf116985.docx diff --git a/sw/qa/extras/ooxmlexport/data/tdf116985.docx b/sw/qa/extras/ooxmlexport/data/tdf116985.docx new file mode 100644 index 000000000000..2a8e2023884d Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf116985.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx index 4dbf3c1bd83f..bc7c15524778 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport11.cxx @@ -208,6 +208,16 @@ DECLARE_OOXMLEXPORT_TEST(testTdf116976, "tdf116976.docx") getProperty(getShape(1), "RelativeWidth")); } +DECLARE_OOXMLEXPORT_TEST(testTdf116985, "tdf116985.docx") +{ + // Body frame width is 10800, 40% is the requested relative width, with 144 + // spacing to text on the left/right side. So ideal width would be 4032, + // was 3431. Allow one pixel tolerance, though. + sal_Int32 nWidth + = parseDump("/root/page[1]/body/txt[1]/anchored/fly/infos/bounds", "width").toInt32(); + CPPUNIT_ASSERT(nWidth > 4000); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/layout/anchoreddrawobject.cxx b/sw/source/core/layout/anchoreddrawobject.cxx index dfbdce3021bb..ca5014f7e9b5 100644 --- a/sw/source/core/layout/anchoreddrawobject.cxx +++ b/sw/source/core/layout/anchoreddrawobject.cxx @@ -32,6 +32,8 @@ #include #include #include +#include +#include using namespace ::com::sun::star; @@ -661,9 +663,22 @@ const SwRect SwAnchoredDrawObject::GetObjBoundRect() const bool bEnableSetModified = pDoc->getIDocumentState().IsEnableSetModified(); pDoc->getIDocumentState().SetEnableSetModified(false); - const_cast< SdrObject* >( GetDrawObj() )->Resize( aCurrObjRect.TopLeft(), + auto pObject = const_cast(GetDrawObj()); + pObject->Resize( aCurrObjRect.TopLeft(), Fraction( nTargetWidth, aCurrObjRect.GetWidth() ), Fraction( nTargetHeight, aCurrObjRect.GetHeight() ), false ); + + if (SwFrameFormat* pFrameFormat = FindFrameFormat(pObject)) + { + if (SwTextBoxHelper::isTextBox(pFrameFormat, RES_DRAWFRMFMT)) + { + // Shape has relative size and also a textbox, update its text area as well. + uno::Reference xShape(pObject->getUnoShape(), uno::UNO_QUERY); + SwTextBoxHelper::syncProperty(pFrameFormat, RES_FRM_SIZE, MID_FRMSIZE_SIZE, + uno::makeAny(xShape->getSize())); + } + } + pDoc->getIDocumentState().SetEnableSetModified(bEnableSetModified); } } -- cgit v1.2.3