sw/CppunitTest_sw_writerfilter_rtftok.mk | 12 +++ sw/qa/writerfilter/rtftok/data/image-size-in-shape-text.rtf | 37 ++++++++++++ sw/qa/writerfilter/rtftok/rtfdocumentimpl.cxx | 29 ++++++++- sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx | 9 ++ 4 files changed, 83 insertions(+), 4 deletions(-)
New commits: commit b942ea1eb66c2639fd8255c78c4c367a5dd415b1 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Tue Jun 17 08:47:09 2025 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Wed Jun 18 10:13:09 2025 +0200 tdf#167044 sw RTF import: fix bad image size in shape text Regression from commit 57d9cc81b058757421cd082e5dbe32a919716807 (tdf#127806: RTF import: use shape dimensions for pib picture, 2022-09-01), open the bugdoc, the icon image inside the shape should be about 0.37cm x 0.37cm, is about 14.98 cm x 12.66 cm. What happens is that \pict was assumed to be inside the property value of a shape, in which case both the shape and the picture can have a size, and the old use-case requires to ignore the inner size. The new use-case is two user-visible shapes: an outer text frame and an inner small icon image, inside shape text. The different sizes are wanted in this case. Fix the problem by conditionally going back to the old behavior of not inheriting size for the inner shape. The name of the destination at the top of the parser stack is different for the "in property value" and the "in shape text" cases, so this keeps the old use-case working while restores the wanted small size for the new use-case. Here the difference between the old and new size was so large that the end-user saw this as "the image was not visible previously". Change-Id: Ife93089b967fc26b7180775db8fc507a896d160b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186602 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins (cherry picked from commit e0e415ba89925a933f8a07e4a2524269bd5c7495) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186627 (cherry picked from commit d81328b59856d2b370110dd1d92a9cce27af34f0) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/186642 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/sw/CppunitTest_sw_writerfilter_rtftok.mk b/sw/CppunitTest_sw_writerfilter_rtftok.mk index 67207f27a9ae..63b01292448e 100644 --- a/sw/CppunitTest_sw_writerfilter_rtftok.mk +++ b/sw/CppunitTest_sw_writerfilter_rtftok.mk @@ -31,9 +31,13 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_writerfilter_rtftok, \ comphelper \ cppu \ cppuhelper \ + editeng \ oox \ sal \ subsequenttest \ + svl \ + sw \ + swqahelper \ test \ unotest \ utl \ @@ -41,6 +45,14 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_writerfilter_rtftok, \ vcl \ )) +$(eval $(call gb_CppunitTest_set_include,sw_writerfilter_rtftok,\ + -I$(SRCDIR)/sw/inc \ + -I$(SRCDIR)/sw/source/core/inc \ + -I$(SRCDIR)/sw/source/uibase/inc \ + -I$(SRCDIR)/sw/qa/inc \ + $$(INCLUDE) \ +)) + $(eval $(call gb_CppunitTest_use_sdk_api,sw_writerfilter_rtftok)) $(eval $(call gb_CppunitTest_use_ure,sw_writerfilter_rtftok)) diff --git a/sw/qa/writerfilter/rtftok/data/image-size-in-shape-text.rtf b/sw/qa/writerfilter/rtftok/data/image-size-in-shape-text.rtf new file mode 100644 index 000000000000..2499e319916b --- /dev/null +++ b/sw/qa/writerfilter/rtftok/data/image-size-in-shape-text.rtf @@ -0,0 +1,37 @@ +{ tf1 +\paperw11907\paperh16840\margl1588\margr1588\margt1276\margb1276 +{\shp +{\*\shpinst\shpleft56\shptop50\shpright8864\shpbottom8198\shpfhdr0\shpbxcolumn\shpbxignore\shpbypara\shpbyignore\shpwr3\shpwrk0\shpfblwtxt0\shpz0\shplid1026 +{\sp +{\sn shapeType} +{\sv 202} +} +{\shptxt before\par +\pard +{\*\shppict +{\pict +{\*\picprop\shplid1025 +{\sp +{\sn shapeType} +{\sv 75} +} +} +\picscalex82\picscaley82\picw450\pich450\picwgoal255\pichgoal255\pngblip +89504e470d0a1a0a0000000d49484452000000110000001108030000000cb3b7c800000001735247420240c07dc500000171504c544500000000000800001300 +000703003a00003d0400550f006a2019112214723130613f2fab453d1f493b3d493b4e5a4f4c5a564c514d54514d56554f574543654e496d5c566f5e59715e5a +715f5a705e5970484772464d96635344645e6e665f6b665f6d6161467374b582772497978f94919ead921bb2af01a9a019beb713d5bd0ed3b710c4b700c2aa1c +ceae12dedb06dece0eeebf00e9d200ead202e8cc05ecce03ffdf00f3d606e8c300fcdf0effd900e7d300ecc602ffd700ffde00ebc61ef7cb00ffdf01f7c400f8 +c600f9c600ffd100fecc00ffd300fcc700f8c500ffce00ffd500eed035efca32f2e500ffff00f5f314ece902eae300ffff09ffff1dfff703eae407fbeb04ffff +06ffff03fff60cffff12fff40afffb06ffff05f8e30affeb05fffc00faf202fffe10ffed0effea00fffa00fff400fff40dffe407ffec00ffed00fff500fff900 +fffe12ffe50cffe800fff000fff800fff902fffd05ffe000ffe900ffe400ffe703ffe700ffff2df031d6100000000174524e530040e6d8660000000970485973 +00000ec400000ec401952b0e1b0000001974455874536f667477617265004d6963726f736f6674204f66666963657fed3571000000b74944415428cf6360c001 +fcfc55d00402aa02955044828243fc15519484eaab0787212bf20b6664e1f7174012088f6062e38b344028328af2e761978df617842b318ef157e6548e8dd382 +2932894f48d4e0d54c4a4e14822a314d314b35574b4bcf88d08628b2b0ccb4cab2d6c9cec9cdcb15062bb1c9b7b52b6066d52d2c2a2ed10329b27770b42a2de3 +e0f629b02aafa814018af81a3a39bbb8dabab97b387b7a797381b4a98a8a894bc8c94b8a8b4b2948cb600b18005842252806b751530000000049454e44ae426082} +} + after\par +} +} +} +\par +} diff --git a/sw/qa/writerfilter/rtftok/rtfdocumentimpl.cxx b/sw/qa/writerfilter/rtftok/rtfdocumentimpl.cxx index e7ef9548078e..d89ffe382206 100644 --- a/sw/qa/writerfilter/rtftok/rtfdocumentimpl.cxx +++ b/sw/qa/writerfilter/rtftok/rtfdocumentimpl.cxx @@ -7,7 +7,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <test/unoapi_test.hxx> +#include <swmodeltestbase.hxx> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/drawing/XDrawPageSupplier.hpp> @@ -18,16 +18,18 @@ #include <vcl/graph.hxx> +#include <fmtfsize.hxx> + using namespace ::com::sun::star; namespace { /// Tests for sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx. -class Test : public UnoApiTest +class Test : public SwModelTestBase { public: Test() - : UnoApiTest(u"/sw/qa/writerfilter/rtftok/data/"_ustr) + : SwModelTestBase(u"/sw/qa/writerfilter/rtftok/data/"_ustr) { } }; @@ -111,6 +113,27 @@ CPPUNIT_TEST_FIXTURE(Test, testOldParaNumLeftMargin) // i.e. the left indent was 0, not 1191 twips (from the file) in mm100. CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2101), nParaLeftMargin); } + +CPPUNIT_TEST_FIXTURE(Test, testImageSizeInShapeText) +{ + // Given an RTF document with a shape and an icon image inside that: + // When loading this document: + createSwDoc("image-size-in-shape-text.rtf"); + + // Then make sure that the icon image has the correct (small) size: + SwDoc* pDoc = getSwDoc(); + const sw::FrameFormats<sw::SpzFrameFormat*>& rFlyFormats = *pDoc->GetSpzFrameFormats(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rFlyFormats.size()); + const sw::SpzFrameFormat& rImageFlyFormat = *rFlyFormats[1]; + const SwFormatFrameSize& rImageSize = rImageFlyFormat.GetFrameSize(); + // 255 * 0.82 in the RTF file. + SwTwips nExpected = 209; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 209 + // - Actual : 8808 + // i.e. the size of the icon was inherited from the containing shape, losing the own size. + CPPUNIT_ASSERT_EQUAL(nExpected, rImageSize.GetWidth()); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx b/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx index 82e01d409183..820535395ff3 100644 --- a/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx +++ b/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx @@ -1034,7 +1034,14 @@ void RTFDocumentImpl::resolvePict(bool const bInline, uno::Reference<drawing::XS } uno::Reference<drawing::XShape> xShape(rShape); - if (m_aStates.top().getInShape() && xShape.is()) + + // \pict may be inside a shape property value, in which case the current destination is + // SHAPEINSTRUCTION. Or we may be inside shape text, when \pict is processed immediately. + bool bInShapeText = m_aStates.top().getDestination() == Destination::PICT; + + // Only ignore the inner size for a shape property value, not for an inline shape inside shape + // text: + if (m_aStates.top().getInShape() && xShape.is() && !bInShapeText) { awt::Size aSize = xShape->getSize(); if (aSize.Width || aSize.Height)