diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-05-10 09:16:17 +0200 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2016-05-18 11:38:55 +0000 |
commit | 7879b89da30025c8efb812bb31a88f9e382b42a5 (patch) | |
tree | a929635e95f4a3bb090522175e28abe60de57bed | |
parent | 853df7a5fa2b48f62a350c0e9eb1be3f6014dedc (diff) |
tdf#96275 RTF import: fix anchor of shapes inside tables
Table text is buffered, so buffer the shape import as well, otherwise
the anchor will precede the buffered text -> incorrect anchor position.
(cherry picked from commit 015fd55c94b7b650ed8e572cafaf3b0f903b01b9)
Conflicts:
writerfilter/source/rtftok/rtfdocumentimpl.cxx
Change-Id: I527b898e2cd5fafaf122a20e11df66ba8d3185cf
Reviewed-on: https://gerrit.libreoffice.org/24937
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | sw/qa/extras/rtfimport/data/tdf96275.rtf | 18 | ||||
-rw-r--r-- | sw/qa/extras/rtfimport/rtfimport.cxx | 9 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 11 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.hxx | 4 |
4 files changed, 40 insertions, 2 deletions
diff --git a/sw/qa/extras/rtfimport/data/tdf96275.rtf b/sw/qa/extras/rtfimport/data/tdf96275.rtf new file mode 100644 index 000000000000..aec13d195206 --- /dev/null +++ b/sw/qa/extras/rtfimport/data/tdf96275.rtf @@ -0,0 +1,18 @@ +{\rtf1 +\ltrrow\trowd \cellx4703\cellx9514\pard\plain \intbl +{A +\par B +\par } +{\shp +{\*\shpinst\shpleft1418\shptop104\shpright2903\shpbottom629\shpfhdr0\shpbxcolumn\shpbxignore\shpbypara\shpbyignore\shpwr3\shpwrk0 +{\sp +{\sn shapeType} +{\sv 3} +} +} +} +{C\cell \cell } +\pard\plain \intbl +{\row} +\pard\plain\par +} diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index dfbc21d52b0d..ae7af23b3ee0 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -2559,6 +2559,15 @@ DECLARE_RTFIMPORT_TEST(testTdf95707, "tdf95707.rtf") CPPUNIT_ASSERT(getProperty<OUString>(getShape(1), "GraphicURL") != "vnd.sun.star.GraphicObject:0000000000000000000000000000000000000000"); } +DECLARE_RTFIMPORT_TEST(testTdf96275, "tdf96275.rtf") +{ + uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), uno::UNO_QUERY); + uno::Reference<text::XTextRange> xCell(xTable->getCellByName("A1"), uno::UNO_QUERY); + uno::Reference<text::XTextRange> xParagraph = getParagraphOfText(3, xCell->getText()); + // This was text: the shape's frame was part of the 1st paragraph instead of the 3rd one. + CPPUNIT_ASSERT_EQUAL(OUString("Frame"), getProperty<OUString>(getRun(xParagraph, 1), "TextPortionType")); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 2e1e350fde94..2f1737bae972 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -1515,6 +1515,8 @@ void RTFDocumentImpl::replayBuffer(RTFBuffer_t& rBuffer, parBreak(); else if (boost::get<0>(aTuple) == BUFFER_STARTSHAPE) m_pSdrImport->resolve(boost::get<1>(aTuple)->getShape(), false, RTFSdrImport::SHAPE); + else if (boost::get<0>(aTuple) == BUFFER_RESOLVESHAPE) + m_pSdrImport->resolve(boost::get<1>(aTuple)->getShape(), true, RTFSdrImport::SHAPE); else if (boost::get<0>(aTuple) == BUFFER_ENDSHAPE) m_pSdrImport->close(); else if (boost::get<0>(aTuple) == BUFFER_RESOLVESUBSTREAM) @@ -5331,7 +5333,14 @@ RTFError RTFDocumentImpl::popState() { // Don't trigger a shape import in case we're only leaving the \shpinst of the groupshape itself. RTFSdrImport::ShapeOrPict eType = (aState.eDestination == Destination::SHAPEINSTRUCTION) ? RTFSdrImport::SHAPE : RTFSdrImport::PICT; - m_pSdrImport->resolve(m_aStates.top().aShape, true, eType); + if (!m_aStates.top().pCurrentBuffer || eType != RTFSdrImport::SHAPE) + m_pSdrImport->resolve(m_aStates.top().aShape, true, eType); + else + { + // Shape inside table: buffer the import to have correct anchor position. + auto pValue = std::make_shared<RTFValue>(m_aStates.top().aShape); + m_aStates.top().pCurrentBuffer->push_back(Buf_t(BUFFER_RESOLVESHAPE, pValue, nullptr)); + } } else if (aState.bInShapeGroup && !aState.bInShape) { diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index e089f01436f8..17318c4fd47a 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -44,7 +44,7 @@ enum class RTFBorderState CHARACTER }; -/// Minimalistic buffer of elements for nested cells. +/// Different kind of buffers for table cell contents. enum RTFBufferTypes { BUFFER_PROPS, @@ -56,6 +56,8 @@ enum RTFBufferTypes BUFFER_ENDRUN, BUFFER_PAR, BUFFER_STARTSHAPE, + /// Imports a shape. + BUFFER_RESOLVESHAPE, BUFFER_ENDSHAPE, BUFFER_RESOLVESUBSTREAM }; |