summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2014-08-25 14:44:48 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2014-08-25 14:51:46 +0200
commit971ffe10583dcdd195f429816760bc0acfb6297f (patch)
tree2261a4215b2c979820ccdb15719e3aa6e0c45bc5
parent2406562733f62b96dd8e6537e1bf4bef147ef50c (diff)
sw HTML export: avoid loosing embedded objects when skipping images
Change-Id: If795af5430b319922cd8242ca82352e148dd680b
-rw-r--r--sw/CppunitTest_sw_htmlexport.mk2
-rw-r--r--sw/qa/extras/htmlexport/data/skipimage-embedded.docbin0 -> 35840 bytes
-rw-r--r--sw/qa/extras/htmlexport/htmlexport.cxx13
-rw-r--r--sw/source/filter/html/htmlplug.cxx36
4 files changed, 47 insertions, 4 deletions
diff --git a/sw/CppunitTest_sw_htmlexport.mk b/sw/CppunitTest_sw_htmlexport.mk
index 59afe0aa1589..70a8c4a555c8 100644
--- a/sw/CppunitTest_sw_htmlexport.mk
+++ b/sw/CppunitTest_sw_htmlexport.mk
@@ -53,6 +53,7 @@ $(eval $(call gb_CppunitTest_use_vcl,sw_htmlexport))
$(eval $(call gb_CppunitTest_use_components,sw_htmlexport,\
basic/util/sb \
+ canvas/source/factory/canvasfactory \
comphelper/util/comphelp \
configmgr/source/configmgr \
embeddedobj/util/embobj \
@@ -65,6 +66,7 @@ $(eval $(call gb_CppunitTest_use_components,sw_htmlexport,\
linguistic/source/lng \
oox/util/oox \
package/source/xstor/xstor \
+ sc/util/sc \
package/util/package2 \
sax/source/expatwrap/expwrap \
sw/util/sw \
diff --git a/sw/qa/extras/htmlexport/data/skipimage-embedded.doc b/sw/qa/extras/htmlexport/data/skipimage-embedded.doc
new file mode 100644
index 000000000000..b4b57ec5f5d9
--- /dev/null
+++ b/sw/qa/extras/htmlexport/data/skipimage-embedded.doc
Binary files differ
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 5fd15abd5c02..69035224f65b 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -46,7 +46,7 @@ private:
void preTest(const char* filename) SAL_OVERRIDE
{
- if (getTestName() == "testExportOfImagesWithSkipImageEnabled")
+ if (getTestName().indexOf("SkipImage") != -1)
setFilterOptions("SkipImages");
else
setFilterOptions("");
@@ -134,6 +134,17 @@ DECLARE_HTMLEXPORT_TEST(testExportOfImagesWithSkipImageEnabled, "textAndImage.do
assertXPath(pDoc, "/html/body/p/img", 0);
}
+DECLARE_HTMLEXPORT_TEST(testSkipImageEmbedded, "skipimage-embedded.doc")
+{
+ // Embedded spreadsheet was exported as image, so content was lost. Make
+ // sure it's exported as HTML instead.
+ htmlDocPtr pDoc = parseHtml(maTempFile);
+ CPPUNIT_ASSERT(pDoc);
+
+ // This was 0.
+ assertXPath(pDoc, "//table", 1);
+}
+
#endif
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx
index b9ca200d6c73..3155db1103a5 100644
--- a/sw/source/filter/html/htmlplug.cxx
+++ b/sw/source/filter/html/htmlplug.cxx
@@ -41,6 +41,8 @@
#include <frmfmt.hxx>
#include <svl/ownlist.hxx>
+#include <unotools/mediadescriptor.hxx>
+#include <unotools/streamwrap.hxx>
#include "pam.hxx"
#include "doc.hxx"
#include "ndtxt.hxx"
@@ -51,10 +53,12 @@
#include "wrthtml.hxx"
#include "htmlfly.hxx"
#include "swcss1.hxx"
+#include "unoframe.hxx"
#include <com/sun/star/embed/XClassifiedObject.hpp>
#include <com/sun/star/embed/EmbedStates.hpp>
#include <com/sun/star/embed/Aspects.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/frame/XStorable.hpp>
#include <comphelper/embeddedobjectcontainer.hxx>
#include <comphelper/classids.hxx>
@@ -1249,9 +1253,6 @@ Writer& OutHTML_FrmFmtOLENodeGrf( Writer& rWrt, const SwFrmFmt& rFrmFmt,
{
SwHTMLWriter& rHTMLWrt = static_cast<SwHTMLWriter&>(rWrt);
- if (rHTMLWrt.mbSkipImages)
- return rWrt;
-
const SwFmtCntnt& rFlyCntnt = rFrmFmt.GetCntnt();
sal_uLong nStt = rFlyCntnt.GetCntntIdx()->GetIndex()+1;
SwOLENode *pOLENd = rHTMLWrt.pDoc->GetNodes()[ nStt ]->GetOLENode();
@@ -1260,6 +1261,35 @@ Writer& OutHTML_FrmFmtOLENodeGrf( Writer& rWrt, const SwFrmFmt& rFrmFmt,
if( !pOLENd )
return rWrt;
+ if (rHTMLWrt.mbSkipImages)
+ {
+ // If we skip images, embedded objects would be completely lost.
+ // Instead, try to use the HTML export of the embedded object.
+ uno::Reference<text::XTextContent> xTextContent = SwXTextEmbeddedObject::CreateXTextEmbeddedObject(*rHTMLWrt.pDoc, const_cast<SwFrmFmt*>(&rFrmFmt));
+ uno::Reference<document::XEmbeddedObjectSupplier2> xEmbeddedObjectSupplier(xTextContent, uno::UNO_QUERY);
+ uno::Reference<frame::XStorable> xStorable(xEmbeddedObjectSupplier->getEmbeddedObject(), uno::UNO_QUERY);
+
+ // Figure out what is the filter name of the embedded object.
+ uno::Reference<lang::XServiceInfo> xServiceInfo(xStorable, uno::UNO_QUERY);
+ OUString aFilter;
+ if (xServiceInfo->supportsService("com.sun.star.sheet.SpreadsheetDocument"))
+ aFilter = "HTML (StarCalc)";
+
+ if (!aFilter.isEmpty())
+ {
+ SvMemoryStream aStream;
+ uno::Reference<io::XOutputStream> xOutputStream(new utl::OStreamWrapper(aStream));
+ utl::MediaDescriptor aMediaDescriptor;
+ aMediaDescriptor["FilterName"] <<= aFilter;
+ aMediaDescriptor["OutputStream"] <<= xOutputStream;
+ xStorable->storeToURL("private:stream", aMediaDescriptor.getAsConstPropertyValueList());
+ OString aData(reinterpret_cast<const char*>(aStream.GetData()), aStream.GetSize());
+ rWrt.Strm().WriteCharPtr(aData.getStr());
+ }
+
+ return rWrt;
+ }
+
Graphic aGraphic( *pOLENd->GetGraphic() );
sal_uLong nFlags = bInCntnr ? HTML_FRMOPTS_GENIMG_CNTNR
: HTML_FRMOPTS_GENIMG;