diff options
author | Attila Bakos <bakos.attilakaroly@nisz.hu> | 2020-05-26 10:09:51 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2020-06-19 15:12:34 +0200 |
commit | 2479ae3ee20fc5f3cbb0c88eb09110a36e86710c (patch) | |
tree | af7d4db4f2376746c9c8b144164506bd3f2832f4 | |
parent | c1c93987acbb83d8352656d77ee515e98c63d46b (diff) |
tdf#130805 SwTextBoxHelper::create: fix frame position in shape
Text frame added by menu option "Add Text Box" of a shape
was misplaced if there were more paragraphs after the
shape anchor position.
Co-authored-by: Tibor Nagy (NISZ)
Change-Id: I8a47aff57d3a60f7dbd2a1b75296e2664a1f745f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94822
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
(cherry picked from commit 06e2cbb31d0ea703df872b91eb8eacdcaced7653)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95976
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r-- | sw/qa/extras/uiwriter/data3/tdf130805.odt | bin | 0 -> 9392 bytes | |||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter3.cxx | 31 | ||||
-rw-r--r-- | sw/source/core/doc/textboxhelper.cxx | 14 |
3 files changed, 43 insertions, 2 deletions
diff --git a/sw/qa/extras/uiwriter/data3/tdf130805.odt b/sw/qa/extras/uiwriter/data3/tdf130805.odt Binary files differnew file mode 100644 index 000000000000..12e215123aa3 --- /dev/null +++ b/sw/qa/extras/uiwriter/data3/tdf130805.odt diff --git a/sw/qa/extras/uiwriter/uiwriter3.cxx b/sw/qa/extras/uiwriter/uiwriter3.cxx index 2ba1db6974d2..cdb1e5c3bb41 100644 --- a/sw/qa/extras/uiwriter/uiwriter3.cxx +++ b/sw/qa/extras/uiwriter/uiwriter3.cxx @@ -13,6 +13,10 @@ #include <com/sun/star/text/TextContentAnchorType.hpp> #include <comphelper/propertysequence.hxx> #include <boost/property_tree/json_parser.hpp> +#include <frameformats.hxx> +#include <textboxhelper.hxx> +#include <fmtanchr.hxx> +#include <o3tl/safeint.hxx> #include <wrtsh.hxx> @@ -525,6 +529,33 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf80663) CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTextTable->getColumns()->getCount()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf130805) +{ + load(DATA_DIRECTORY, "tdf130805.odt"); + SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + + SwWrtShell* pWrtSh = pTextDoc->GetDocShell()->GetWrtShell(); + CPPUNIT_ASSERT(pWrtSh); + + const SwFrameFormats& rFrmFormats = *pWrtSh->GetDoc()->GetSpzFrameFormats(); + CPPUNIT_ASSERT(rFrmFormats.size() >= size_t(o3tl::make_unsigned(1))); + auto pShape = rFrmFormats.front(); + CPPUNIT_ASSERT(pShape); + + SwTextBoxHelper::create(pShape); + auto pTxBxFrm = SwTextBoxHelper::getOtherTextBoxFormat(getShape(1)); + CPPUNIT_ASSERT(pTxBxFrm); + + auto pTxAnch = pTxBxFrm->GetAnchor().GetContentAnchor(); + auto pShpAnch = pShape->GetAnchor().GetContentAnchor(); + CPPUNIT_ASSERT(pTxAnch); + CPPUNIT_ASSERT(pShpAnch); + + CPPUNIT_ASSERT_EQUAL_MESSAGE("The textbox got apart!", pTxAnch->nNode, pShpAnch->nNode); + //CPPUNIT_ASSERT_EQUAL_MESSAGE("", xShp->getPosition().Y, xShp2->getPosition().Y); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest3, testTdf96067) { mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"); diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx index e2b1e9fa6498..ae7084605e4c 100644 --- a/sw/source/core/doc/textboxhelper.cxx +++ b/sw/source/core/doc/textboxhelper.cxx @@ -63,8 +63,18 @@ void SwTextBoxHelper::create(SwFrameFormat* pShape) pShape->GetDoc()->GetDocShell()->GetBaseModel(), uno::UNO_QUERY); uno::Reference<text::XTextContentAppend> xTextContentAppend(xTextDocument->getText(), uno::UNO_QUERY); - - xTextContentAppend->appendTextContent(xTextFrame, uno::Sequence<beans::PropertyValue>()); + try + { + SdrObject* pSourceSDRShape = pShape->FindRealSdrObject(); + uno::Reference<text::XTextContent> XSourceShape(pSourceSDRShape->getUnoShape(), + uno::UNO_QUERY_THROW); + xTextContentAppend->insertTextContentWithProperties( + xTextFrame, uno::Sequence<beans::PropertyValue>(), XSourceShape->getAnchor()); + } + catch (uno::Exception&) + { + xTextContentAppend->appendTextContent(xTextFrame, uno::Sequence<beans::PropertyValue>()); + } // Link FLY and DRAW formats, so it becomes a text box (needed for syncProperty calls). uno::Reference<text::XTextFrame> xRealTextFrame(xTextFrame, uno::UNO_QUERY); auto pTextFrame = dynamic_cast<SwXTextFrame*>(xRealTextFrame.get()); |