summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-05-31 17:37:02 +0200
committerMiklos Vajna <vmiklos@collabora.com>2021-06-04 16:25:58 +0200
commitedccdebbde424695766f57c837d1da8de3f0f9d1 (patch)
tree67ca218815b3cedbb443c791b9914880d85fe989
parent7a5717cb8ad4c6b30d46ad86326fa4274bd84f12 (diff)
sw XHTML / reqif export: export PNG images directly, without an OLE wrapper
Do this by default and add a ExportImagesAsOLE=true option for those who want the old behavior. Adapt existing tests to ask for the old behavior and add a new one that depends on the new default. (cherry picked from commit e1546b790763c1004dc2e2e3581c666466d7cf9c) Conflicts: sw/source/filter/html/htmlflywriter.cxx Change-Id: If863215ce267d6accc85b5c8f7bdbd3f2b1e9187
-rw-r--r--sw/qa/extras/htmlexport/htmlexport.cxx120
-rw-r--r--sw/source/filter/html/htmlflywriter.cxx4
-rw-r--r--sw/source/filter/html/wrthtml.cxx10
-rw-r--r--sw/source/filter/html/wrthtml.hxx3
4 files changed, 105 insertions, 32 deletions
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 50e001c72890..d505d3ee521f 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -647,34 +647,55 @@ DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfOleImg, "reqif-ole-img.xhtml")
CPPUNIT_ASSERT(aStream.indexOf("type=\"image/png\"") != -1);
}
-DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(testReqIfPngImg, "reqif-png-img.xhtml")
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqIfPngImg)
{
- uno::Reference<container::XNamed> xShape(getShape(1), uno::UNO_QUERY);
- CPPUNIT_ASSERT(xShape.is());
+ auto verify = [this](bool bExported) {
+ uno::Reference<container::XNamed> xShape(getShape(1), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xShape.is());
- if (!mbExported)
- {
- // Imported PNG image is not an object.
- CPPUNIT_ASSERT_EQUAL(OUString("Image1"), xShape->getName());
- return;
- }
-
- // All images are exported as objects in ReqIF mode.
- CPPUNIT_ASSERT_EQUAL(OUString("Object1"), xShape->getName());
+ if (!bExported)
+ {
+ // Imported PNG image is not an object.
+ CPPUNIT_ASSERT_EQUAL(OUString("Image1"), xShape->getName());
+ return;
+ }
- // This was <img>, not <object>, which is not valid in the reqif-xhtml
- // subset.
- SvStream* pStream = maTempFile.GetStream(StreamMode::READ);
- CPPUNIT_ASSERT(pStream);
- sal_uInt64 nLength = pStream->TellEnd();
- OString aStream(read_uInt8s_ToOString(*pStream, nLength));
- CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:object") != -1);
+ // All images are exported as objects in ReqIF mode.
+ CPPUNIT_ASSERT_EQUAL(OUString("Object1"), xShape->getName());
+
+ // This was <img>, not <object>, which is not valid in the reqif-xhtml
+ // subset.
+ SvStream* pStream = maTempFile.GetStream(StreamMode::READ);
+ CPPUNIT_ASSERT(pStream);
+ sal_uInt64 nLength = pStream->TellEnd();
+ OString aStream(read_uInt8s_ToOString(*pStream, nLength));
+ CPPUNIT_ASSERT(aStream.indexOf("<reqif-xhtml:object") != -1);
+
+ // Make sure that both RTF and PNG versions are written.
+ CPPUNIT_ASSERT(aStream.indexOf("text/rtf") != -1);
+ // This failed when images with a query in their file:// URL failed to
+ // import.
+ CPPUNIT_ASSERT(aStream.indexOf("image/png") != -1);
+ };
- // Make sure that both RTF and PNG versions are written.
- CPPUNIT_ASSERT(aStream.indexOf("text/rtf") != -1);
- // This failed when images with a query in their file:// URL failed to
- // import.
- CPPUNIT_ASSERT(aStream.indexOf("image/png") != -1);
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "reqif-png-img.xhtml";
+ uno::Sequence<beans::PropertyValue> aLoadProperties = {
+ comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")),
+ comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")),
+ };
+ mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", aLoadProperties);
+ verify(/*bExported=*/false);
+ uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> aStoreProperties = {
+ comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")),
+ comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")),
+ comphelper::makePropertyValue("ExportImagesAsOLE", true),
+ };
+ xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
+ mxComponent->dispose();
+ mxComponent
+ = loadFromDesktop(maTempFile.GetURL(), "com.sun.star.text.TextDocument", aLoadProperties);
+ verify(/*bExported=*/true);
}
DECLARE_HTMLEXPORT_TEST(testReqIfJpgImg, "reqif-jpg-img.xhtml")
@@ -858,10 +879,19 @@ DECLARE_HTMLEXPORT_TEST(testTransparentImage, "transparent-image.odt")
CPPUNIT_ASSERT_MESSAGE(aMessage.toUtf8().getStr(), aSource.endsWith(".gif"));
}
-DECLARE_HTMLEXPORT_TEST(testTransparentImageReqIf, "transparent-image.odt")
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testTransparentImageReqIf)
{
+ OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "transparent-image.odt";
+ mxComponent = loadFromDesktop(aURL, "com.sun.star.text.TextDocument", {});
+ uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> aStoreProperties = {
+ comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")),
+ comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")),
+ comphelper::makePropertyValue("ExportImagesAsOLE", true),
+ };
+ xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
SvMemoryStream aStream;
- wrapFragment(maTempFile, aStream);
+ HtmlExportTest::wrapFragment(maTempFile, aStream);
xmlDocUniquePtr pDoc = parseXmlStream(&aStream);
CPPUNIT_ASSERT(pDoc);
@@ -1467,7 +1497,13 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifImageToOle)
dispatchCommand(mxComponent, ".uno:InsertGraphic", aArgs);
// When exporting to XHTML:
- ExportToReqif();
+ uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> aStoreProperties = {
+ comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")),
+ comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")),
+ comphelper::makePropertyValue("ExportImagesAsOLE", true),
+ };
+ xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
// Then make sure we export that PNG as WMF in ReqIF mode:
OUString aRtfUrl = GetOlePath();
@@ -1494,6 +1530,36 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifImageToOle)
CPPUNIT_ASSERT(aOle1Reader.m_nPresentationDataSize);
}
+CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testReqifEmbedPNGDirectly)
+{
+ // 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:
+ uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY);
+ uno::Sequence<beans::PropertyValue> aStoreProperties = {
+ comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")),
+ comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")),
+ };
+ xStorable->storeToURL(maTempFile.GetURL(), aStoreProperties);
+
+ // Then make sure the PNG is embedded directly, without an RTF wrapper:
+ SvMemoryStream aStream;
+ HtmlExportTest::wrapFragment(maTempFile, aStream);
+ xmlDocUniquePtr pXmlDoc = parseXmlStream(&aStream);
+ CPPUNIT_ASSERT(pXmlDoc);
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: image/png
+ // - Actual : text/rtf
+ // i.e. even PNG was wrapped in an RTF.
+ assertXPath(pXmlDoc, "//reqif-xhtml:p/reqif-xhtml:object", "type", "image/png");
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/htmlflywriter.cxx b/sw/source/filter/html/htmlflywriter.cxx
index e5a3b482bd61..e76dd326d085 100644
--- a/sw/source/filter/html/htmlflywriter.cxx
+++ b/sw/source/filter/html/htmlflywriter.cxx
@@ -1866,7 +1866,7 @@ static Writer& OutHTML_FrameFormatGrfNode( Writer& rWrt, const SwFrameFormat& rF
if (xGraphic.is() && aMimeType.isEmpty())
xGraphic->getPropertyValue("MimeType") >>= aMimeType;
- if (rHTMLWrt.mbReqIF)
+ if (rHTMLWrt.mbReqIF && rHTMLWrt.m_bExportImagesAsOLE)
{
// Write the original image as an RTF fragment.
OUString aFileName;
@@ -1896,7 +1896,7 @@ static Writer& OutHTML_FrameFormatGrfNode( Writer& rWrt, const SwFrameFormat& rF
OutHTML_Image( rWrt, rFrameFormat, aGraphicURL, aGraphic, pGrfNd->GetTitle(),
pGrfNd->GetTwipSize(), nFrameFlags, "graphic", nullptr, aMimeType );
- if (rHTMLWrt.mbReqIF)
+ if (rHTMLWrt.mbReqIF && rHTMLWrt.m_bExportImagesAsOLE)
rWrt.Strm().WriteOString("</" + rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_object ">");
return rWrt;
diff --git a/sw/source/filter/html/wrthtml.cxx b/sw/source/filter/html/wrthtml.cxx
index 2f83734aee37..c941d0b38597 100644
--- a/sw/source/filter/html/wrthtml.cxx
+++ b/sw/source/filter/html/wrthtml.cxx
@@ -196,12 +196,16 @@ void SwHTMLWriter::SetupFilterOptions(SfxMedium& rMedium)
comphelper::SequenceAsHashMap aStoreMap(rMedium.GetArgs());
auto it = aStoreMap.find("RTFOLEMimeType");
- if (it == aStoreMap.end())
+ if (it != aStoreMap.end())
{
- return;
+ it->second >>= m_aRTFOLEMimeType;
}
- it->second >>= m_aRTFOLEMimeType;
+ it = aStoreMap.find("ExportImagesAsOLE");
+ if (it != aStoreMap.end())
+ {
+ it->second >>= m_bExportImagesAsOLE;
+ }
}
void SwHTMLWriter::SetupFilterOptions(const OUString& rFilterOptions)
diff --git a/sw/source/filter/html/wrthtml.hxx b/sw/source/filter/html/wrthtml.hxx
index ffc416f22662..e8bfbe25afe9 100644
--- a/sw/source/filter/html/wrthtml.hxx
+++ b/sw/source/filter/html/wrthtml.hxx
@@ -407,6 +407,9 @@ public:
OUString m_aRTFOLEMimeType;
+ /// ReqIF mode: export images as OLE objects.
+ bool m_bExportImagesAsOLE = false;
+
/// Construct an instance of SwHTMLWriter and optionally give it
/// the filter options directly, which can also be set via SetupFilterOptions().
explicit SwHTMLWriter( const OUString& rBaseURL, const OUString& rFilterOptions = "" );