From 4d9dda3fd096b9bffba5a07243a86208affd893f Mon Sep 17 00:00:00 2001 From: Patrick Jaap Date: Fri, 21 Sep 2018 11:53:19 +0200 Subject: tdf#115094 part I: do not move graphic nodes Do not move graphic nodes in SwXText::convertToTextFrame() since it is not reasonable (they are anchored to something that already moved) and hence it causes errors. A static function checks wether the current node is a graphic. A small change in writerfilter was done since a unit test failed: The condition "m_nAnchorType != 0" was removed since it is not reasonable at this place. Change-Id: I8f27985f6f6c8329483370a7b8baaf9949513f1b Reviewed-on: https://gerrit.libreoffice.org/60860 Tested-by: Jenkins Reviewed-by: Miklos Vajna --- sw/qa/extras/ooxmlimport/data/tdf115094.docx | Bin 0 -> 15064 bytes sw/qa/extras/ooxmlimport/ooxmlimport2.cxx | 20 ++++++++++++++++++++ sw/source/core/unocore/unotext.cxx | 18 +++++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 sw/qa/extras/ooxmlimport/data/tdf115094.docx (limited to 'sw') diff --git a/sw/qa/extras/ooxmlimport/data/tdf115094.docx b/sw/qa/extras/ooxmlimport/data/tdf115094.docx new file mode 100644 index 000000000000..38d84d88ed86 Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/tdf115094.docx differ diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx index 7f548f47e65d..6fe7784cd062 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx @@ -223,6 +223,26 @@ DECLARE_OOXMLIMPORT_TEST(testTdf119200, "tdf119200.docx") CPPUNIT_ASSERT_EQUAL(OUString(u" size 12{ func \u2287 } {}"), getFormula(getRun(xPara, 7))); } +DECLARE_OOXMLIMPORT_TEST(testTdf115094, "tdf115094.docx") +{ + // anchor of graphic has to be the text in the text frame + // xray ThisComponent.DrawPage(1).Anchor.Text + uno::Reference xDrawPageSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xDrawPage(xDrawPageSupplier->getDrawPage(), + uno::UNO_QUERY); + uno::Reference xShape(xDrawPage->getByIndex(1), uno::UNO_QUERY); + uno::Reference xText1(xShape->getAnchor()->getText(), uno::UNO_QUERY); + + // xray ThisComponent.TextTables(0).getCellByName("A1") + uno::Reference xTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xTables(xTablesSupplier->getTextTables(), + uno::UNO_QUERY); + uno::Reference xTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference xText2(xTable->getCellByName("A1"), uno::UNO_QUERY); + + CPPUNIT_ASSERT_EQUAL(xText1.get(), xText2.get()); +} + // tests should only be added to ooxmlIMPORT *if* they fail round-tripping in ooxmlEXPORT CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/core/unocore/unotext.cxx b/sw/source/core/unocore/unotext.cxx index dbf00411ece5..e27630e16445 100644 --- a/sw/source/core/unocore/unotext.cxx +++ b/sw/source/core/unocore/unotext.cxx @@ -1487,6 +1487,20 @@ SwXText::appendTextContent( return insertTextContentWithProperties(xTextContent, rCharacterAndParagraphProperties, xInsertPosition); } +// determine wether SwFrameFormat is a graphic node +static bool isGraphicNode(const SwFrameFormat* pFrameFormat) +{ + // safety + if( !pFrameFormat->GetContent().GetContentIdx() ) + { + return false; + } + auto index = *pFrameFormat->GetContent().GetContentIdx(); + // consider the next node -> there is the graphic stored + index++; + return index.GetNode().IsGrfNode(); +} + // move previously appended paragraphs into a text frames // to support import filters uno::Reference< text::XTextContent > SAL_CALL @@ -1632,13 +1646,15 @@ SwXText::convertToTextFrame( // see if there are frames already anchored to this node // we have to work with the SdrObjects, as unique name is not guaranteed in their frame format + // tdf#115094: do nothing if we have a graphic node std::set aAnchoredObjectsByPtr; std::set aAnchoredObjectsByName; for (size_t i = 0; i < m_pImpl->m_pDoc->GetSpzFrameFormats()->size(); ++i) { const SwFrameFormat* pFrameFormat = (*m_pImpl->m_pDoc->GetSpzFrameFormats())[i]; const SwFormatAnchor& rAnchor = pFrameFormat->GetAnchor(); - if ((RndStdIds::FLY_AT_PARA == rAnchor.GetAnchorId() || RndStdIds::FLY_AT_CHAR == rAnchor.GetAnchorId()) && + if ( !isGraphicNode(pFrameFormat) && + (RndStdIds::FLY_AT_PARA == rAnchor.GetAnchorId() || RndStdIds::FLY_AT_CHAR == rAnchor.GetAnchorId()) && aStartPam.Start()->nNode.GetIndex() <= rAnchor.GetContentAnchor()->nNode.GetIndex() && aStartPam.End()->nNode.GetIndex() >= rAnchor.GetContentAnchor()->nNode.GetIndex()) { -- cgit