writerfilter/qa/cppunittests/rtftok/data/duplicated-image.rtf | 41 ++++++++++ writerfilter/qa/cppunittests/rtftok/rtfdocumentimpl.cxx | 18 ++++ writerfilter/source/rtftok/rtfdocumentimpl.cxx | 2 3 files changed, 61 insertions(+)
New commits: commit f07d4faac47cdf3cd09b036d07b03c6bb8d86372 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Mon Sep 12 20:29:26 2022 +0200 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Tue Sep 13 15:27:37 2022 +0200 tdf#140302 RTF import: fix unexpected repeated image The bugdoc has 2 images, but the resulting doc model had 3 images since commit 7e863504854ae8ab286b32510aba8b363a8e314b (tdf#81943 sw RTF import: fix missing wrap in background for in-table shape, 2018-07-16). The trouble was that shape replay wants to access the current shape at m_aStates.top().aShape, but we only set it, forgot to unset it after replay was done, which can result in duplicated insertions. Fix this by saving the old current shape on the stack, set the current shape to the wanted value and then undo it after replay. This only affects documents that have a \picprop group, since the unwanted insertion happened when popping that group. Change-Id: I088054de2332deb4b45f7e269672fa799dd49c2f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139818 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> (cherry picked from commit b9fcf43a38773f81ef1833897c4e36d8db16c0b1) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139672 Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/writerfilter/qa/cppunittests/rtftok/data/duplicated-image.rtf b/writerfilter/qa/cppunittests/rtftok/data/duplicated-image.rtf new file mode 100644 index 000000000000..f225ff1f248f --- /dev/null +++ b/writerfilter/qa/cppunittests/rtftok/data/duplicated-image.rtf @@ -0,0 +1,41 @@ +{\rtf1 +before table\par +\trowd\cellx4819\cellx9638\pard\plain\intbl +A1 +\cell\pard\plain +{\shp +{\*\shpinst\shpwr1\shpbypara\shpbyignore\shptop113\shpbottom1352\shpbxcolumn\shpbxignore\shpleft-22\shpright4733 +{\sp +{\sn shapeType} +{\sv 75} +} +{\sp +{\sn pib} +{\sv +{\pict\picscalex92\picscaley92\piccropl0\piccropr0\piccropt0\piccropb0\picw341\pich89\picwgoal5115\pichgoal1335\pngblip +89504e470d0a1a0a0000000d4948445200000010000000100403000000eddde25200000030504c54450000008000000080008080000000808000800080808080 +80c0c0c0ff000000ff00ffff000000ffff00ff00ffffffffff7b1fb1c40000005b49444154789c458db10ac03008445d33e5b71d04d764caef3808f99d0604ab +b5a5b778dc933bf057f01bdd650ca98cf8d885ce240d0c3ecf40a41dc9097011f4d67a2ad18ac8f239af44f33255e19c1044ce42e39a60f9469fc06fa01a6b07 +bcd70bc70000000049454e44ae426082 +} +} +} +} +} +\cell\row +\pard\plain after table\par +\pard\plain +{\*\shppict +{\pict +{\*\picprop +} +\picscalex100\picscaley100\piccropl0\piccropr0\piccropt0\piccropb0\picw16\pich16\picwgoal240\pichgoal240\pngblip +89504e470d0a1a0a0000000d4948445200000010000000100403000000eddde25200000030504c54450000008000000080008080000000808000800080808080 +80c0c0c0ff000000ff00ffff000000ffff00ff00ffffffffff7b1fb1c40000005b49444154789c458db10ac03008445d33e5b71d04d764caef3808f99d0604ab +b5a5b778dc933bf057f01bdd650ca98cf8d885ce240d0c3ecf40a41dc9097011f4d67a2ad18ac8f239af44f33255e19c1044ce42e39a60f9469fc06fa01a6b07 +bcd70bc70000000049454e44ae426082 +} +} +end +\par +} diff --git a/writerfilter/qa/cppunittests/rtftok/rtfdocumentimpl.cxx b/writerfilter/qa/cppunittests/rtftok/rtfdocumentimpl.cxx index 1898e0057695..6020453ba783 100644 --- a/writerfilter/qa/cppunittests/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/qa/cppunittests/rtftok/rtfdocumentimpl.cxx @@ -101,6 +101,24 @@ CPPUNIT_TEST_FIXTURE(Test, testCharHiddenInTable) // hidden. CPPUNIT_ASSERT(bCharHidden); } + +CPPUNIT_TEST_FIXTURE(Test, testDuplicatedImage) +{ + // Given a document with 2 images: + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "duplicated-image.rtf"; + + // When importing that document: + getComponent() = loadFromDesktop(aURL); + + // Then make sure no duplicated images are created: + uno::Reference<drawing::XDrawPageSupplier> xTextDocument(getComponent(), uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xDrawPage = xTextDocument->getDrawPage(); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 2 + // - Actual : 3 + // i.e. there was a 3rd, duplicated image. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xDrawPage->getCount()); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index ffcef6178a89..04ab247a540e 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -1772,9 +1772,11 @@ void RTFDocumentImpl::replayBuffer(RTFBuffer_t& rBuffer, RTFSprms* const pSprms, // Set current shape during replay, needed by e.g. wrap in // background. + RTFShape aShape = m_aStates.top().getShape(); m_aStates.top().getShape() = std::get<1>(aTuple)->getShape(); m_pSdrImport->resolve(std::get<1>(aTuple)->getShape(), true, RTFSdrImport::SHAPE); + m_aStates.top().getShape() = aShape; m_aStates.top().setCurrentBuffer(pCurrentBuffer); } else if (std::get<0>(aTuple) == BUFFER_ENDSHAPE)