sw XHTML import: handle size of replacement graphic of <object>

Similar to how <img src="..."> defaults to the pixel size.

Change-Id: I2c55522366e8635c491b322ca70fc3e2d79617fc
Reviewed-on: https://gerrit.libreoffice.org/50836
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
This commit is contained in:
Miklos Vajna
2018-03-06 13:45:19 +01:00
parent 612fae5c24
commit 970d20a3ab
2 changed files with 31 additions and 0 deletions

View File

@@ -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<drawing::XShape> 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<sal_Int32>(aLogic.getWidth()), aSize.Width);
}
CPPUNIT_PLUGIN_IMPLEMENT();

View File

@@ -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;
}