[Libreoffice-commits] core.git: sw/CppunitTest_sw_htmlexport.mk sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Mon Aug 25 05:52:19 PDT 2014


 sw/CppunitTest_sw_htmlexport.mk                     |    2 +
 sw/qa/extras/htmlexport/data/skipimage-embedded.doc |binary
 sw/qa/extras/htmlexport/htmlexport.cxx              |   13 ++++++-
 sw/source/filter/html/htmlplug.cxx                  |   36 ++++++++++++++++++--
 4 files changed, 47 insertions(+), 4 deletions(-)

New commits:
commit 971ffe10583dcdd195f429816760bc0acfb6297f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon Aug 25 14:44:48 2014 +0200

    sw HTML export: avoid loosing embedded objects when skipping images
    
    Change-Id: If795af5430b319922cd8242ca82352e148dd680b

diff --git a/sw/CppunitTest_sw_htmlexport.mk b/sw/CppunitTest_sw_htmlexport.mk
index 59afe0a..70a8c4a 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 0000000..b4b57ec
Binary files /dev/null and b/sw/qa/extras/htmlexport/data/skipimage-embedded.doc differ
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 5fd15ab..6903522 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 b9ca200..3155db1 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;


More information about the Libreoffice-commits mailing list