summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2014-08-25 14:44:48 +0200
committerMichael Meeks <michael.meeks@collabora.com>2014-08-27 10:35:08 -0500
commitf29c5f742e8be13b5ee7d03ebf1bcaf2a4adfef9 (patch)
treecbb17a7ad4c1423f96cbb6a1d7ef63b0380f5f1f /sw
parentfbcb191c4302bcf1c3163fe3ed7a8bb04ffdac50 (diff)
sw HTML export: avoid loosing embedded objects when skipping images
(cherry picked from commit 971ffe10583dcdd195f429816760bc0acfb6297f) Also squash in 3 fixes on top of that: 1) HTML export: avoid invalid output for embedded spreadsheets When the sc document is embedded inside an sw one, then the sc HTML export should just write what's inside the <body>. Add a filter option for that in sc and use it from sw. (cherry picked from commit 1ee98159f7749b2c1ad47de60a9b3057b9e9720e) 2) sw HTML export: avoid <table> directly inside <p> Wrapping the embedded object output in a <span> at least makes the parser errors go away. (cherry picked from commit 58fc5c6a5153b68470f7de8229b76dca04267ab7) 3) CppunitTest_sw_htmlexport: tinderbox says scfilt dependency is missing (cherry picked from commit 9f482b596195a2948a8f7f14664a7a870d348e95) Change-Id: I308e411e4abb938fe08b47aaf21d6fd747bb758e Reviewed-on: https://gerrit.libreoffice.org/11148 Reviewed-by: Michael Meeks <michael.meeks@collabora.com> Tested-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/CppunitTest_sw_htmlexport.mk3
-rw-r--r--sw/qa/extras/htmlexport/data/skipimage-embedded.docbin0 -> 35840 bytes
-rw-r--r--sw/qa/extras/htmlexport/htmlexport.cxx17
-rw-r--r--sw/source/filter/html/htmlplug.cxx42
4 files changed, 58 insertions, 4 deletions
diff --git a/sw/CppunitTest_sw_htmlexport.mk b/sw/CppunitTest_sw_htmlexport.mk
index 3774e925d47c..d1900504a2a1 100644
--- a/sw/CppunitTest_sw_htmlexport.mk
+++ b/sw/CppunitTest_sw_htmlexport.mk
@@ -52,6 +52,7 @@ $(eval $(call gb_CppunitTest_use_ure,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 \
@@ -64,6 +65,8 @@ $(eval $(call gb_CppunitTest_use_components,sw_htmlexport,\
linguistic/source/lng \
oox/util/oox \
package/source/xstor/xstor \
+ sc/util/sc \
+ sc/util/scfilt \
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..fc7f68925718 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,21 @@ 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);
+ // This was 2, the HTML header was in the document two times.
+ assertXPath(pDoc, "//meta[@name='generator']", 1);
+ // This was 0, <table> was directly under <p>, which caused errors in the parser.
+ assertXPath(pDoc, "//span/table", 1);
+}
+
#endif
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx
index 7d3c898fe202..489d28fd83d9 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,13 @@
#include "wrthtml.hxx"
#include "htmlfly.hxx"
#include "swcss1.hxx"
+#include "unocoll.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 +1254,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 +1262,40 @@ 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<drawing::XShape> xShape = SwXFrames::GetObject(const_cast<SwFrmFmt&>(rFrmFmt), FLYCNTTYPE_OLE);
+ uno::Reference<text::XTextContent> xTextContent(xShape, uno::UNO_QUERY);
+ 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["FilterOptions"] <<= OUString("SkipHeaderFooter");
+ aMediaDescriptor["OutputStream"] <<= xOutputStream;
+ xStorable->storeToURL("private:stream", aMediaDescriptor.getAsConstPropertyValueList());
+ OString aData(reinterpret_cast<const char*>(aStream.GetData()), aStream.GetSize());
+ // Wrap output in a <span> tag to avoid 'HTML parser error: Unexpected end tag: p'
+ HTMLOutFuncs::Out_AsciiTag(rWrt.Strm(), OOO_STRING_SVTOOLS_HTML_span);
+ rWrt.Strm().WriteCharPtr(aData.getStr());
+ HTMLOutFuncs::Out_AsciiTag(rWrt.Strm(), OOO_STRING_SVTOOLS_HTML_span, false);
+ }
+
+ return rWrt;
+ }
+
Graphic aGraphic( *pOLENd->GetGraphic() );
sal_uLong nFlags = bInCntnr ? HTML_FRMOPTS_GENIMG_CNTNR
: HTML_FRMOPTS_GENIMG;