summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-05-26 17:46:53 +0200
committerMiklos Vajna <vmiklos@collabora.com>2021-05-28 16:12:38 +0200
commit0b4b0fcd873d62bec9e826c174d8334a1d7d3228 (patch)
treefee1c9717c4c9668f91ee180ff267898bf07d0f3 /sw
parentf6a92e61558ee9134d20da5dce96e5e3b11702a8 (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. (cherry picked from commit 0e459bb3eb840ac1cab14c070973fb3b79bc13d8) Conflicts: sw/qa/extras/htmlexport/htmlexport.cxx Change-Id: I203fcd8709b25a4dd543047bd804af8181df9940
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/htmlexport/htmlexport.cxx31
-rw-r--r--sw/source/filter/html/htmlreqifreader.cxx65
2 files changed, 58 insertions, 38 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index ad64b6404007..105d90d39b18 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -50,12 +50,14 @@ public:
bool WriteObjectData(SvStream& rOLE);
long GetObjw() const { return m_nObjw; }
long GetObjh() const { return m_nObjh; }
+ int getWmetafile() const { return m_nWmetafile; }
private:
bool m_bInObjData = false;
OStringBuffer m_aHex;
long m_nObjw = 0;
long m_nObjh = 0;
+ int m_nWmetafile = 0;
};
TestReqIfRtfReader::TestReqIfRtfReader(SvStream& rStream)
@@ -83,6 +85,9 @@ void TestReqIfRtfReader::NextToken(int nToken)
case RTF_OBJH:
m_nObjh = nTokenValue;
break;
+ case RTF_WMETAFILE:
+ m_nWmetafile = nTokenValue;
+ break;
}
}
@@ -1450,6 +1455,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 47cf2341e1e5..16be43358972 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;
}
}