diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-03-17 17:30:52 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-03-17 21:41:56 +0100 |
commit | 5c7255d3a98568a2965f840b76371cf03eb0d99a (patch) | |
tree | 148671841be8ad7dd36946e018351048193c4757 /sw | |
parent | 840b05f519a3cbc35842b0af7825e516771ce44d (diff) |
sw reqif-xhtml export: make sure OLE1 preview is WMF-only
reqif-xhtml has previews for embedded objects at 4 levels:
- png preview
- RTF preview
- OLE1 preview
- OLE2 preview
The OLE1 preview has to be a WMF one, and in case our WMF export tries
to inject EMF into it, Word will refuse to open the embedded object. So
add a new flag to allow opting out of the EMF embedding for reqif-xhtml
export purposes.
The other option would be what Word does to just omit the OLE1 preview,
but then this would break reqif-xhtml consumers who take the preview
from the OLE1 data.
Change-Id: Ia8d4626aefb6309743c9f4023f289c9a7b872035
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112648
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/htmlexport/data/ole1-pres-data-wmf.odt | bin | 0 -> 41595 bytes | |||
-rw-r--r-- | sw/qa/extras/htmlexport/htmlexport.cxx | 93 | ||||
-rw-r--r-- | sw/source/filter/html/htmlreqifreader.cxx | 11 |
3 files changed, 72 insertions, 32 deletions
diff --git a/sw/qa/extras/htmlexport/data/ole1-pres-data-wmf.odt b/sw/qa/extras/htmlexport/data/ole1-pres-data-wmf.odt Binary files differnew file mode 100644 index 000000000000..9bcca729bc52 --- /dev/null +++ b/sw/qa/extras/htmlexport/data/ole1-pres-data-wmf.odt diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index f749c363880e..295acb34f04c 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -119,6 +119,43 @@ bool TestReqIfRtfReader::WriteObjectData(SvStream& rOLE) rOLE.WriteStream(aStream); return true; } + +/// Parser for [MS-OLEDS] 2.2.5 EmbeddedObject, aka OLE1. +struct OLE1Reader +{ + sal_uInt32 m_nNativeDataSize; + sal_uInt32 m_nPresentationDataSize; + + OLE1Reader(SvStream& rStream); +}; + +OLE1Reader::OLE1Reader(SvStream& rStream) +{ + // Skip ObjectHeader, see [MS-OLEDS] 2.2.4. + rStream.Seek(0); + sal_uInt32 nData; + rStream.ReadUInt32(nData); // OLEVersion + rStream.ReadUInt32(nData); // FormatID + rStream.ReadUInt32(nData); // ClassName + rStream.SeekRel(nData); + rStream.ReadUInt32(nData); // TopicName + rStream.SeekRel(nData); + rStream.ReadUInt32(nData); // ItemName + rStream.SeekRel(nData); + + rStream.ReadUInt32(m_nNativeDataSize); + rStream.SeekRel(m_nNativeDataSize); + + rStream.ReadUInt32(nData); // OLEVersion for presentation data + CPPUNIT_ASSERT(rStream.good()); + rStream.ReadUInt32(nData); // FormatID + rStream.ReadUInt32(nData); // ClassName + rStream.SeekRel(nData); + rStream.ReadUInt32(nData); // Width + rStream.ReadUInt32(nData); // Height + rStream.ReadUInt32(nData); // PresentationDataSize + m_nPresentationDataSize = nData; +} } class HtmlExportTest : public SwModelTestBase, public HtmlTestTools @@ -1080,25 +1117,14 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifOle1PDF) ParseOle1FromRtfUrl(aRtfUrl, aOle1); // Check the content of the ole1 data. - // Skip ObjectHeader, see [MS-OLEDS] 2.2.4. - aOle1.Seek(0); - sal_uInt32 nData; - aOle1.ReadUInt32(nData); // OLEVersion - aOle1.ReadUInt32(nData); // FormatID - aOle1.ReadUInt32(nData); // ClassName - aOle1.SeekRel(nData); - aOle1.ReadUInt32(nData); // TopicName - aOle1.SeekRel(nData); - aOle1.ReadUInt32(nData); // ItemName - aOle1.SeekRel(nData); - aOle1.ReadUInt32(nData); // NativeDataSize + OLE1Reader aOle1Reader(aOle1); // Without the accompanying fix in place, this test would have failed with: // - Expected: 39405 // - Actual : 43008 // i.e. we did not work with the Ole10Native stream, rather created an OLE1 wrapper around the // OLE1-in-OLE2 data, resulting in additional size. - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(0x99ed), nData); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(0x99ed), aOle1Reader.m_nNativeDataSize); // Now import this back and check the ODT result. mxComponent->dispose(); @@ -1285,26 +1311,33 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifOle1PresDataNoOle2) ParseOle1FromRtfUrl(aRtfUrl, aOle1); // Check the content of the ole1 data. - // Skip ObjectHeader, see [MS-OLEDS] 2.2.4. - aOle1.Seek(0); - sal_uInt32 nData; - aOle1.ReadUInt32(nData); // OLEVersion - aOle1.ReadUInt32(nData); // FormatID - aOle1.ReadUInt32(nData); // ClassName - aOle1.SeekRel(nData); - aOle1.ReadUInt32(nData); // TopicName - aOle1.SeekRel(nData); - aOle1.ReadUInt32(nData); // ItemName - aOle1.SeekRel(nData); - aOle1.ReadUInt32(nData); // NativeDataSize - aOle1.SeekRel(nData); - - aOle1.ReadUInt32(nData); // OLEVersion for presentation data - // Without the accompanying fix in place, this test would have failed as there was no // presentation data after the native data in the OLE1 container. The result was not editable in // Word. - CPPUNIT_ASSERT(aOle1.good()); + OLE1Reader aOle1Reader(aOle1); +} + +CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifOle1PresDataWmfOnly) +{ + // Save to reqif-xhtml. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "ole1-pres-data-wmf.odt"; + mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", {}); + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + uno::Sequence<beans::PropertyValue> aStoreProperties = { + comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")), + comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")), + }; + xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties); + OUString aRtfUrl = GetOlePath(); + SvMemoryStream aOle1; + ParseOle1FromRtfUrl(aRtfUrl, aOle1); + + OLE1Reader aOle1Reader(aOle1); + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 135660 + // - Actual : 272376 + // i.e. we wrote some additional EMF data into the WMF output, which broke Word. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(135660), aOle1Reader.m_nPresentationDataSize); } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/html/htmlreqifreader.cxx b/sw/source/filter/html/htmlreqifreader.cxx index d656f51bc0cb..40c932ad6332 100644 --- a/sw/source/filter/html/htmlreqifreader.cxx +++ b/sw/source/filter/html/htmlreqifreader.cxx @@ -21,6 +21,11 @@ #include <vcl/cvtgrf.hxx> #include <ndole.hxx> #include <sal/log.hxx> +#include <vcl/FilterConfigItem.hxx> +#include <vcl/wmf.hxx> +#include <comphelper/propertyvalue.hxx> + +using namespace com::sun::star; namespace { @@ -431,8 +436,10 @@ bool WrapOleInRtf(SvStream& rOle2, SvStream& rRtf, SwOLENode& rOLENode) SvMemoryStream aGraphicStream; if (pGraphic) { - if (GraphicConverter::Export(aGraphicStream, *pGraphic, ConvertDataFormat::WMF) - == ERRCODE_NONE) + uno::Sequence<beans::PropertyValue> aFilterData + = { comphelper::makePropertyValue("EmbedEMF", false) }; + FilterConfigItem aConfigItem(&aFilterData); + if (ConvertGraphicToWMF(*pGraphic, aGraphicStream, &aConfigItem)) { pPresentationData = static_cast<const sal_uInt8*>(aGraphicStream.GetData()); nPresentationData = aGraphicStream.TellEnd(); |