svx/source/xoutdev/_xoutbmp.cxx | 9 +++-- sw/qa/extras/htmlexport/data/tdf162282.odt |binary sw/qa/extras/htmlexport/htmlexport.cxx | 44 +++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-)
New commits: commit bf1c928f447f2c5f5c5a020826df2667d07cafa7 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Thu Aug 1 18:21:00 2024 +0500 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Fri Aug 2 00:09:58 2024 +0500 tdf#162282: restore correct handling of EMF Commit 166a16594eb4e7e78f3f5b00a1432637d109bf8d (Simplify logic in XOutBitmap::WriteGraphic a bit, 2023-04-01) changed the logic, so that when the graphic's data reported VectorGraphicDataType::Wmf type, it wasn't further checked if its link's IsEMF returns true. That made isKnownVectorFormat return false for such EMFs, and so the graphic was exported to a new EMF, instead of using its data. This restores the original behavior. Change-Id: I68b807e735e501de6bf37172390623938e401e6f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171377 Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Tested-by: Jenkins diff --git a/svx/source/xoutdev/_xoutbmp.cxx b/svx/source/xoutdev/_xoutbmp.cxx index b6a84fb44d60..581d9716764e 100644 --- a/svx/source/xoutdev/_xoutbmp.cxx +++ b/svx/source/xoutdev/_xoutbmp.cxx @@ -127,6 +127,10 @@ static OUString isKnownVectorFormat(const Graphic& rGraphic, std::u16string_view if (!pData || pData->getBinaryDataContainer().getSize() == 0) return {}; + if (FORMAT_EMF.equalsIgnoreAsciiCase(rFilter) + && (pData->getType() == VectorGraphicDataType::Emf || rGraphic.GetGfxLink().IsEMF())) + return FORMAT_EMF; + // Does the filter name match the original format? switch (pData->getType()) { @@ -135,14 +139,11 @@ static OUString isKnownVectorFormat(const Graphic& rGraphic, std::u16string_view case VectorGraphicDataType::Wmf: return match(rFilter, FORMAT_WMF, false); case VectorGraphicDataType::Emf: - return match(rFilter, FORMAT_EMF, false); + break; case VectorGraphicDataType::Pdf: return match(rFilter, FORMAT_PDF, false); } - if (rGraphic.GetGfxLink().IsEMF()) - return match(rFilter, FORMAT_EMF, false); - return {}; } diff --git a/sw/qa/extras/htmlexport/data/tdf162282.odt b/sw/qa/extras/htmlexport/data/tdf162282.odt new file mode 100644 index 000000000000..b67fd119bc28 Binary files /dev/null and b/sw/qa/extras/htmlexport/data/tdf162282.odt differ diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 27c92d8f3b67..03ae9e6fe260 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -3369,6 +3369,50 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testHTML_exportRelativeURLs) CPPUNIT_ASSERT(url.endsWith(".gif")); } +CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIF_162282) +{ + // Given a document with an embedded metafile: + createSwDoc("tdf162282.odt"); + ExportToReqif(); + xmlDocUniquePtr pDoc = WrapReqifFromTempFile(); + + // Check that the exported EMF is exactly the same as in the ODF package + assertXPath(pDoc, "//reqif-xhtml:p/reqif-xhtml:object"_ostr, "type"_ostr, u"image/x-emf"_ustr); + OUString imgName = getXPath(pDoc, "//reqif-xhtml:p/reqif-xhtml:object"_ostr, "data"_ostr); + CPPUNIT_ASSERT(imgName.endsWith(".emf")); + INetURLObject aUrl(maTempFile.GetURL()); + aUrl.setName(imgName); + SvFileStream aEmfStream(aUrl.GetMainURL(INetURLObject::DecodeMechanism::NONE), + StreamMode::READ); + + // without the fix, this would fail with + // - Expected: 220 + // - Actual : 111260 + CPPUNIT_ASSERT_EQUAL(sal_uInt64(220), aEmfStream.TellEnd()); + + css::uno::Sequence<sal_uInt8> emfData(220); + aEmfStream.ReadBytes(emfData.getArray(), emfData.getLength()); + + const css::uno::Sequence<sal_uInt8> correctData{ + 0x01, 0x00, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xF4, 0x01, 0x00, 0x00, 0xF4, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x88, 0x13, 0x00, 0x00, 0x88, 0x13, 0x00, 0x00, 0x20, 0x45, 0x4D, 0x46, 0x00, + 0x00, 0x01, 0x00, 0xDC, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x07, 0x00, + 0x00, 0x38, 0x04, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x00, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF4, 0x01, 0x00, 0x00, 0xF4, + 0x01, 0x00, 0x00, 0x39, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x2D, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x96, 0x00, 0x00, + 0x00, 0xFA, 0x00, 0x00, 0x00, 0x2C, 0x01, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x14, 0x00, + 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x2F, 0x00, 0x00, 0x00, 0x28, + 0x00, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x2C, 0x01, 0x00, 0x00, + 0x2C, 0x01, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x2C, 0x01, 0x00, + 0x00, 0xC8, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + }; + CPPUNIT_ASSERT_EQUAL(correctData, emfData); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */