sw/qa/extras/htmlexport/htmlexport.cxx | 13 +++++ sw/source/filter/html/htmlflywriter.cxx | 2 sw/source/filter/html/htmlreqifreader.cxx | 67 ++++++++++++++++++++++++++++-- sw/source/filter/html/htmlreqifreader.hxx | 4 - 4 files changed, 79 insertions(+), 7 deletions(-)
New commits: commit ff1f80e025a7c235e3960affe1b9db844c89c214 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Thu May 27 16:54:59 2021 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu May 27 18:20:43 2021 +0200 sw XHTML / reqif export, RTF markup of images: write objdata The native data is BMP, presentation data is not yet done. Change-Id: I30ef9f0c3b4dc7801e600ac751c32179372d5e4e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116266 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Jenkins diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 1fba03321840..9ff771a7d43c 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -149,6 +149,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 @@ -162,6 +163,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 @@ -1477,6 +1483,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 725ec85f8393..d2ab65efc7dc 100644 --- a/sw/source/filter/html/htmlflywriter.cxx +++ b/sw/source/filter/html/htmlflywriter.cxx @@ -1878,7 +1878,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 8dd62d25d831..81f980b8ca37 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 _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits