diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-05-27 16:54:59 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-05-28 16:20:07 +0200 |
commit | ffbf6916e2bd7de4daa862e11e52c9ff24929260 (patch) | |
tree | 21905f5b2c8d1bf2ce43e25aae1ff57f4f19d6ce | |
parent | 0b4b0fcd873d62bec9e826c174d8334a1d7d3228 (diff) |
sw XHTML / reqif export, RTF markup of images: write objdata
The native data is BMP, presentation data is not yet done.
(cherry picked from commit ff1f80e025a7c235e3960affe1b9db844c89c214)
Change-Id: I30ef9f0c3b4dc7801e600ac751c32179372d5e4e
-rw-r--r-- | sw/qa/extras/htmlexport/htmlexport.cxx | 13 | ||||
-rw-r--r-- | sw/source/filter/html/htmlflywriter.cxx | 2 | ||||
-rw-r--r-- | sw/source/filter/html/htmlreqifreader.cxx | 67 | ||||
-rw-r--r-- | sw/source/filter/html/htmlreqifreader.hxx | 4 |
4 files changed, 79 insertions, 7 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 105d90d39b18..5074c5e54e0d 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -138,6 +138,7 @@ OLE1Reader::OLE1Reader(SvStream& rStream) { // Skip ObjectHeader, see [MS-OLEDS] 2.2.4. rStream.Seek(0); + CPPUNIT_ASSERT(rStream.remainingSize()); sal_uInt32 nData; rStream.ReadUInt32(nData); // OLEVersion rStream.ReadUInt32(nData); // FormatID @@ -151,6 +152,11 @@ 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 @@ -1479,6 +1485,13 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifImageToOle) // - Actual : 0 // i.e. the image was exported as PNG, not as WMF (with a version). CPPUNIT_ASSERT_EQUAL(8, xReader->getWmetafile()); + + // Make sure that the native data byte array is not empty. + SvMemoryStream aOle1; + CPPUNIT_ASSERT(xReader->WriteObjectData(aOle1)); + // Without the accompanying fix in place, this test would have failed, as aOle1 was empty. + OLE1Reader aOle1Reader(aOle1); + CPPUNIT_ASSERT(aOle1Reader.m_nNativeDataSize); } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx index 184c911956a9..e5a3b482bd61 100644 --- a/sw/source/filter/html/htmlflywriter.cxx +++ b/sw/source/filter/html/htmlflywriter.cxx @@ -1881,7 +1881,7 @@ static Writer& OutHTML_FrameFormatGrfNode( Writer& rWrt, const SwFrameFormat& rF aFileName = aURL.GetMainURL(INetURLObject::DecodeMechanism::NONE); SvFileStream aOutStream(aFileName, StreamMode::WRITE); - if (!SwReqIfReader::WrapGraphicInRtf(aGraphic, pGrfNd->GetTwipSize(), aOutStream)) + if (!SwReqIfReader::WrapGraphicInRtf(aGraphic, rFrameFormat, aOutStream)) SAL_WARN("sw.html", "SwReqIfReader::WrapGraphicInRtf() failed"); // Refer to this data. diff --git a/sw/source/filter/html/htmlreqifreader.cxx b/sw/source/filter/html/htmlreqifreader.cxx index 16be43358972..70b0d697ea4a 100644 --- a/sw/source/filter/html/htmlreqifreader.cxx +++ b/sw/source/filter/html/htmlreqifreader.cxx @@ -496,12 +496,73 @@ bool WrapOleInRtf(SvStream& rOle2, SvStream& rRtf, SwOLENode& rOLENode, return true; } -bool WrapGraphicInRtf(const Graphic& rGraphic, const Size& rLogicSize, SvStream& rRtf) +bool WrapGraphicInRtf(const Graphic& rGraphic, const SwFrameFormat& rFormat, SvStream& rRtf) { // Start object. rRtf.WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_OBJECT); rRtf.WriteCharPtr(OOO_STRING_SVTOOLS_RTF_OBJEMB); + // Object size: as used in the document model (not pixel size) + Size aSize = rFormat.GetFrameSize().GetSize(); + sal_uInt32 nWidth = aSize.getWidth(); + sal_uInt32 nHeight = aSize.getHeight(); + rRtf.WriteCharPtr(OOO_STRING_SVTOOLS_RTF_OBJW); + rRtf.WriteOString(OString::number(nWidth)); + rRtf.WriteCharPtr(OOO_STRING_SVTOOLS_RTF_OBJH); + rRtf.WriteOString(OString::number(nHeight)); + rRtf.WriteOString(SAL_NEWLINE_STRING); + + // Start objclass. + rRtf.WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_OBJCLASS " "); + OString aClassName("PBrush"); + rRtf.WriteOString(aClassName); + // End objclass. + rRtf.WriteCharPtr("}"); + rRtf.WriteOString(SAL_NEWLINE_STRING); + + // Start objdata. + rRtf.WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_IGNORE OOO_STRING_SVTOOLS_RTF_OBJDATA " "); + + SvMemoryStream aOle1; + // Write ObjectHeader, see [MS-OLEDS] 2.2.4. + // OLEVersion. + aOle1.WriteUInt32(0x00000501); + + // FormatID is EmbeddedObject. + aOle1.WriteUInt32(0x00000002); + + // ClassName + aOle1.WriteUInt32(aClassName.getLength() + 1); + aOle1.WriteOString(aClassName); + // Null terminated pascal string. + aOle1.WriteChar(0); + + // TopicName. + aOle1.WriteUInt32(0); + + // ItemName. + aOle1.WriteUInt32(0); + + // NativeDataSize + SvMemoryStream aNativeData; + if (GraphicConverter::Export(aNativeData, rGraphic, ConvertDataFormat::BMP) != ERRCODE_NONE) + { + SAL_WARN("sw.html", "WrapGraphicInRtf: bmp conversion failed"); + } + aOle1.WriteUInt32(aNativeData.TellEnd()); + + // Write the actual native data. + 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); @@ -526,9 +587,9 @@ bool WrapGraphicInRtf(const Graphic& rGraphic, const Size& rLogicSize, SvStream& rRtf.WriteOString(OString::number(aMapped.Height())); rRtf.WriteCharPtr(OOO_STRING_SVTOOLS_RTF_PICWGOAL); - rRtf.WriteOString(OString::number(rLogicSize.Width())); + rRtf.WriteOString(OString::number(nWidth)); rRtf.WriteCharPtr(OOO_STRING_SVTOOLS_RTF_PICHGOAL); - rRtf.WriteOString(OString::number(rLogicSize.Height())); + rRtf.WriteOString(OString::number(nHeight)); rRtf.WriteCharPtr(OOO_STRING_SVTOOLS_RTF_WMETAFILE "8"); rRtf.WriteOString(SAL_NEWLINE_STRING); diff --git a/sw/source/filter/html/htmlreqifreader.hxx b/sw/source/filter/html/htmlreqifreader.hxx index 5f757d0fbf1d..84169bb7c087 100644 --- a/sw/source/filter/html/htmlreqifreader.hxx +++ b/sw/source/filter/html/htmlreqifreader.hxx @@ -30,10 +30,8 @@ bool WrapOleInRtf(SvStream& rOle2, SvStream& rRtf, SwOLENode& rOLENode, /** * Wraps an image in an RTF fragment. - * - * @param rLogicSize the size used in the document model (not pixel size) */ -bool WrapGraphicInRtf(const Graphic& rGraphic, const Size& rLogicSize, SvStream& rRtf); +bool WrapGraphicInRtf(const Graphic& rGraphic, const SwFrameFormat& rFormat, SvStream& rRtf); } #endif // INCLUDED_SW_SOURCE_FILTER_HTML_HTMLREQIFREADER_HXX |