diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-05-28 16:02:50 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-05-31 10:04:24 +0200 |
commit | 7a5717cb8ad4c6b30d46ad86326fa4274bd84f12 (patch) | |
tree | e6aa11c06d406b694cb5e5e50dc77ba6f6fab2d8 | |
parent | ffbf6916e2bd7de4daa862e11e52c9ff24929260 (diff) |
sw XHTML / reqif export, RTF markup of images: write OLE1 presentation data
With this, images are exported as PBrush OLE objects, to please some
consumers (e.g. IBM Doors).
(cherry picked from commit 5fbd20682f34c817359156889ecbc3ad8290d72c)
Conflicts:
sw/source/filter/html/htmlreqifreader.cxx
Change-Id: I89805cd66709d96cbe71853d65671f76a3fc871f
-rw-r--r-- | sw/qa/extras/htmlexport/htmlexport.cxx | 10 | ||||
-rw-r--r-- | sw/source/filter/html/htmlreqifreader.cxx | 50 |
2 files changed, 43 insertions, 17 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 5074c5e54e0d..50e001c72890 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -152,11 +152,6 @@ OLE1Reader::OLE1Reader(SvStream& rStream) rStream.ReadUInt32(m_nNativeDataSize); rStream.SeekRel(m_nNativeDataSize); - if (!rStream.remainingSize()) - { - return; - } - rStream.ReadUInt32(nData); // OLEVersion for presentation data CPPUNIT_ASSERT(rStream.good()); rStream.ReadUInt32(nData); // FormatID @@ -1492,6 +1487,11 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifImageToOle) // Without the accompanying fix in place, this test would have failed, as aOle1 was empty. OLE1Reader aOle1Reader(aOle1); CPPUNIT_ASSERT(aOle1Reader.m_nNativeDataSize); + + // Make sure that the presentation data byte array is not empty. + // Without the accompanying fix in place, this test would have failed, as aOle1 only contained + // the native data. + CPPUNIT_ASSERT(aOle1Reader.m_nPresentationDataSize); } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/html/htmlreqifreader.cxx b/sw/source/filter/html/htmlreqifreader.cxx index 70b0d697ea4a..8a6101fa93ee 100644 --- a/sw/source/filter/html/htmlreqifreader.cxx +++ b/sw/source/filter/html/htmlreqifreader.cxx @@ -555,18 +555,7 @@ bool WrapGraphicInRtf(const Graphic& rGraphic, const SwFrameFormat& rFormat, SvS aNativeData.Seek(0); aOle1.WriteStream(aNativeData); - // TODO Write Presentation. - - // End objdata. - msfilter::rtfutil::WriteHex(static_cast<const sal_uInt8*>(aOle1.GetData()), aOle1.GetSize(), - &rRtf); - rRtf.WriteCharPtr("}"); - rRtf.WriteOString(SAL_NEWLINE_STRING); - - rRtf.WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_RESULT); - rRtf.WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_PICT); - - // Prepare presendation data. + // Prepare presentation data. const sal_uInt8* pPresentationData = nullptr; sal_uInt64 nPresentationData = 0; SvMemoryStream aGraphicStream; @@ -580,6 +569,43 @@ bool WrapGraphicInRtf(const Graphic& rGraphic, const SwFrameFormat& rFormat, SvS msfilter::rtfutil::StripMetafileHeader(pPresentationData, nPresentationData); } + // Write Presentation. + // OLEVersion. + aOle1.WriteUInt32(0x00000501); + // FormatID: constant means the ClassName field is present. + aOle1.WriteUInt32(0x00000005); + // ClassName: null terminated pascal string. + OString aPresentationClassName("METAFILEPICT"); + aOle1.WriteUInt32(aPresentationClassName.getLength() + 1); + aOle1.WriteOString(aPresentationClassName); + aOle1.WriteChar(0); + const sal_uInt8* pBytes = nullptr; + sal_uInt64 nBytes = 0; + // Take presentation data for OLE1 from RTF. + pBytes = pPresentationData; + nBytes = nPresentationData; + // Width. + aOle1.WriteUInt32(nWidth); + // Height. + aOle1.WriteUInt32(nHeight * -1); + // PresentationDataSize: size of (reserved fields + pBytes). + aOle1.WriteUInt32(8 + nBytes); + // Reserved1-4. + aOle1.WriteUInt16(0x0008); + aOle1.WriteUInt16(0x31b1); + aOle1.WriteUInt16(0x1dd9); + aOle1.WriteUInt16(0x0000); + aOle1.WriteBytes(pBytes, nBytes); + + // End objdata. + msfilter::rtfutil::WriteHex(static_cast<const sal_uInt8*>(aOle1.GetData()), aOle1.GetSize(), + &rRtf); + rRtf.WriteCharPtr("}"); + rRtf.WriteOString(SAL_NEWLINE_STRING); + + rRtf.WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_RESULT); + rRtf.WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_PICT); + Size aMapped(rGraphic.GetPrefSize()); rRtf.WriteCharPtr(OOO_STRING_SVTOOLS_RTF_PICW); rRtf.WriteOString(OString::number(aMapped.Width())); |