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 @@ +{\rtf1 +\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 +#include #include #include @@ -18,16 +18,18 @@ #include +#include + 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(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& rFlyFormats = *pDoc->GetSpzFrameFormats(); + CPPUNIT_ASSERT_EQUAL(static_cast(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 e814e13fbc06..6a2477036778 100644 --- a/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx +++ b/sw/source/writerfilter/rtftok/rtfdocumentimpl.cxx @@ -1033,7 +1033,14 @@ void RTFDocumentImpl::resolvePict(bool const bInline, uno::Reference 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)