diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-05-26 17:46:53 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-05-26 19:01:26 +0200 |
commit | 0e459bb3eb840ac1cab14c070973fb3b79bc13d8 (patch) | |
tree | 3e4ae97576f838606d972cda5c4ef48857f3aa9a /sw | |
parent | f75549b4169f327faca88d5ce9d544bc6885bef1 (diff) |
sw XHTML / reqif export, RTF markup of images: write WMF in \pict
Some consumers (e.g. IBM Doors) can only consume the RTF snippet if it's
an OLE object and can't deal with plain images.
Wrap \pict inside \object and unconditionally use WMF as the RTF-level
preview format. The actual \objdata is not yet written.
Change-Id: I203fcd8709b25a4dd543047bd804af8181df9940
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116207
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/htmlexport/htmlexport.cxx | 31 | ||||
-rw-r--r-- | sw/source/filter/html/htmlreqifreader.cxx | 65 |
2 files changed, 58 insertions, 38 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx index 9a08d06b48cd..1fba03321840 100644 --- a/sw/qa/extras/htmlexport/htmlexport.cxx +++ b/sw/qa/extras/htmlexport/htmlexport.cxx @@ -61,12 +61,14 @@ public: bool WriteObjectData(SvStream& rOLE); tools::Long GetObjw() const { return m_nObjw; } tools::Long GetObjh() const { return m_nObjh; } + int getWmetafile() const { return m_nWmetafile; } private: bool m_bInObjData = false; OStringBuffer m_aHex; tools::Long m_nObjw = 0; tools::Long m_nObjh = 0; + int m_nWmetafile = 0; }; TestReqIfRtfReader::TestReqIfRtfReader(SvStream& rStream) @@ -94,6 +96,9 @@ void TestReqIfRtfReader::NextToken(int nToken) case RTF_OBJH: m_nObjh = nTokenValue; break; + case RTF_WMETAFILE: + m_nWmetafile = nTokenValue; + break; } } @@ -1448,6 +1453,32 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testBlockQuoteNoMargin) "string"); } +CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifImageToOle) +{ + // Given a document with an image: + loadURL("private:factory/swriter", nullptr); + OUString aImageURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "ole2.png"; + uno::Sequence<beans::PropertyValue> aArgs = { + comphelper::makePropertyValue("FileName", aImageURL), + }; + dispatchCommand(mxComponent, ".uno:InsertGraphic", aArgs); + + // When exporting to XHTML: + ExportToReqif(); + + // Then make sure we export that PNG as WMF in ReqIF mode: + OUString aRtfUrl = GetOlePath(); + SvMemoryStream aRtf; + HtmlExportTest::wrapRtfFragment(aRtfUrl, aRtf); + tools::SvRef<TestReqIfRtfReader> xReader(new TestReqIfRtfReader(aRtf)); + CPPUNIT_ASSERT(xReader->CallParser() != SvParserState::Error); + // Without the accompanying fix in place, this test would have failed: + // - Expected: 8 + // - Actual : 0 + // i.e. the image was exported as PNG, not as WMF (with a version). + CPPUNIT_ASSERT_EQUAL(8, xReader->getWmetafile()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/html/htmlreqifreader.cxx b/sw/source/filter/html/htmlreqifreader.cxx index 253e3f44cb22..05a3eae5b5b1 100644 --- a/sw/source/filter/html/htmlreqifreader.cxx +++ b/sw/source/filter/html/htmlreqifreader.cxx @@ -498,42 +498,27 @@ bool WrapOleInRtf(SvStream& rOle2, SvStream& rRtf, SwOLENode& rOLENode, bool WrapGraphicInRtf(const Graphic& rGraphic, const Size& rLogicSize, SvStream& rRtf) { + // Start object. + rRtf.WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_OBJECT); + rRtf.WriteCharPtr(OOO_STRING_SVTOOLS_RTF_OBJEMB); + + rRtf.WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_RESULT); rRtf.WriteCharPtr("{" OOO_STRING_SVTOOLS_RTF_PICT); - GfxLink aLink = rGraphic.GetGfxLink(); - const sal_uInt8* pGraphicAry = aLink.GetData(); - sal_uInt64 nSize = aLink.GetDataSize(); - OString aBlipType; - bool bIsWMF = false; - switch (aLink.GetType()) + // Prepare presendation data. + const sal_uInt8* pPresentationData = nullptr; + sal_uInt64 nPresentationData = 0; + SvMemoryStream aGraphicStream; + uno::Sequence<beans::PropertyValue> aFilterData + = { comphelper::makePropertyValue("EmbedEMF", false) }; + FilterConfigItem aConfigItem(&aFilterData); + if (ConvertGraphicToWMF(rGraphic, aGraphicStream, &aConfigItem)) { - case GfxLinkType::NativeBmp: - aBlipType = OOO_STRING_SVTOOLS_RTF_WBITMAP; - break; - case GfxLinkType::NativeJpg: - aBlipType = OOO_STRING_SVTOOLS_RTF_JPEGBLIP; - break; - case GfxLinkType::NativePng: - aBlipType = OOO_STRING_SVTOOLS_RTF_PNGBLIP; - break; - case GfxLinkType::NativeWmf: - if (aLink.IsEMF()) - aBlipType = OOO_STRING_SVTOOLS_RTF_EMFBLIP; - else - { - aBlipType = OOO_STRING_SVTOOLS_RTF_WMETAFILE; - bIsWMF = true; - } - break; - default: - break; + pPresentationData = static_cast<const sal_uInt8*>(aGraphicStream.GetData()); + nPresentationData = aGraphicStream.TellEnd(); + msfilter::rtfutil::StripMetafileHeader(pPresentationData, nPresentationData); } - if (aBlipType.isEmpty()) - return false; - - rRtf.WriteOString(aBlipType); - Size aMapped(rGraphic.GetPrefSize()); rRtf.WriteCharPtr(OOO_STRING_SVTOOLS_RTF_PICW); rRtf.WriteOString(OString::number(aMapped.Width())); @@ -544,19 +529,23 @@ bool WrapGraphicInRtf(const Graphic& rGraphic, const Size& rLogicSize, SvStream& rRtf.WriteOString(OString::number(rLogicSize.Width())); rRtf.WriteCharPtr(OOO_STRING_SVTOOLS_RTF_PICHGOAL); rRtf.WriteOString(OString::number(rLogicSize.Height())); + rRtf.WriteCharPtr(OOO_STRING_SVTOOLS_RTF_WMETAFILE "8"); + rRtf.WriteOString(SAL_NEWLINE_STRING); - if (bIsWMF) + if (pPresentationData) { - rRtf.WriteOString(OString::number(8)); - msfilter::rtfutil::StripMetafileHeader(pGraphicAry, nSize); + msfilter::rtfutil::WriteHex(pPresentationData, nPresentationData, &rRtf); + rRtf.WriteOString(SAL_NEWLINE_STRING); } - rRtf.WriteOString(SAL_NEWLINE_STRING); - - msfilter::rtfutil::WriteHex(pGraphicAry, nSize, &rRtf); - rRtf.WriteOString(SAL_NEWLINE_STRING); // End pict. rRtf.WriteCharPtr("}"); + + // End result. + rRtf.WriteCharPtr("}"); + + // End object. + rRtf.WriteCharPtr("}"); return true; } } |