diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx index 6a1a2f9b046b..7cdf5f45dc1e 100644 --- a/sw/qa/extras/htmlimport/htmlimport.cxx +++ b/sw/qa/extras/htmlimport/htmlimport.cxx @@ -316,6 +316,15 @@ DECLARE_HTMLIMPORT_TEST(testReqIfOleImg, "reqif-ole-img.xhtml") uno::UNO_QUERY); // This failed, OLE object had no replacement image. CPPUNIT_ASSERT(xObject->getReplacementGraphic().is()); + + uno::Reference xShape(xObject, uno::UNO_QUERY); + OutputDevice* pDevice = Application::GetDefaultDevice(); + Size aPixel(64, 64); + // Expected to be 1693. + Size aLogic(pDevice->PixelToLogic(aPixel, MapMode(MapUnit::Map100thMM))); + awt::Size aSize = xShape->getSize(); + // This was only 1247, size was not set explicitly. + CPPUNIT_ASSERT_EQUAL(static_cast(aLogic.getWidth()), aSize.Width); } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx index 638835931b4e..ca7219baa8d8 100644 --- a/sw/source/filter/html/htmlplug.cxx +++ b/sw/source/filter/html/htmlplug.cxx @@ -434,6 +434,28 @@ void SwHTMLParser::InsertEmbed() return; rObj.SetGraphic(aGraphic, OUString()); + + // Set the size of the OLE frame to the size of the graphic. + OutputDevice* pDevice = Application::GetDefaultDevice(); + if (aSize.getHeight() == USHRT_MAX || aSize.getWidth() == USHRT_MAX) + { + Size aPixelSize = aGraphic.GetSizePixel(pDevice); + if (aSize.getWidth() == USHRT_MAX) + aSize.setWidth(aPixelSize.getWidth()); + if (aSize.getHeight() == USHRT_MAX) + aSize.setHeight(aPixelSize.getHeight()); + } + + SwFrameFormat* pFormat = pOLENode->GetFlyFormat(); + if (!pFormat) + return; + + SwAttrSet aAttrSet(pFormat->GetAttrSet()); + aAttrSet.ClearItem(RES_CNTNT); + Size aTwipSize(pDevice->PixelToLogic(aSize, MapMode(MapUnit::MapTwip))); + SwFormatFrameSize aFrameSize(ATT_FIX_SIZE, aTwipSize.Width(), aTwipSize.Height()); + aAttrSet.Put(aFrameSize); + pOLENode->GetDoc()->SetFlyFrameAttr(*pFormat, aAttrSet); return; }