[Libreoffice-commits] core.git: Branch 'libreoffice-4-3' - sc/source sw/CppunitTest_sw_htmlexport.mk sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Wed Aug 27 08:35:34 PDT 2014


 sc/source/filter/html/htmlexp.cxx                   |   19 +++++++--
 sc/source/filter/inc/htmlexp.hxx                    |    2 
 sw/CppunitTest_sw_htmlexport.mk                     |    3 +
 sw/qa/extras/htmlexport/data/skipimage-embedded.doc |binary
 sw/qa/extras/htmlexport/htmlexport.cxx              |   17 +++++++-
 sw/source/filter/html/htmlplug.cxx                  |   42 ++++++++++++++++++--
 6 files changed, 76 insertions(+), 7 deletions(-)

New commits:
commit f29c5f742e8be13b5ee7d03ebf1bcaf2a4adfef9
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
    
    (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 at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/sc/source/filter/html/htmlexp.cxx b/sc/source/filter/html/htmlexp.cxx
index db08610..afd453a 100644
--- a/sc/source/filter/html/htmlexp.cxx
+++ b/sc/source/filter/html/htmlexp.cxx
@@ -218,7 +218,8 @@ ScHTMLExport::ScHTMLExport( SvStream& rStrmP, const OUString& rBaseURL, ScDocume
     bCalcAsShown( pDocP->GetDocOptions().IsCalcAsShown() ),
     bTableDataWidth( true ),
     bTableDataHeight( true ),
-    mbSkipImages ( false )
+    mbSkipImages ( false ),
+    mbSkipHeaderFooter( false )
 {
     strcpy( sIndent, sIndentSource );
     sIndent[0] = 0;
@@ -232,6 +233,10 @@ ScHTMLExport::ScHTMLExport( SvStream& rStrmP, const OUString& rBaseURL, ScDocume
     {
         mbSkipImages = true;
     }
+    else if (rFilterOptions == "SkipHeaderFooter")
+    {
+        mbSkipHeaderFooter = true;
+    }
 
     for ( sal_uInt16 j=0; j < SC_HTML_FONTSIZES; j++ )
     {
@@ -319,14 +324,18 @@ Size ScHTMLExport::MMToPixel( const Size& rSize )
 
 sal_uLong ScHTMLExport::Write()
 {
+    if (!mbSkipHeaderFooter)
+    {
     rStrm.WriteChar( '<' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_doctype ).WriteChar( ' ' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_doctype40 ).WriteChar( '>' )
        .WriteCharPtr( SAL_NEWLINE_STRING ).WriteCharPtr( SAL_NEWLINE_STRING );
     TAG_ON_LF( OOO_STRING_SVTOOLS_HTML_html );
     WriteHeader();
     OUT_LF();
+    }
     WriteBody();
     OUT_LF();
-    TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_html );
+    if (!mbSkipHeaderFooter)
+        TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_html );
 
     return rStrm.GetError();
 }
@@ -562,6 +571,8 @@ void ScHTMLExport::WriteBody()
     const SvxBrushItem* pBrushItem = (const SvxBrushItem*)&rSet.Get( ATTR_BACKGROUND );
 
     // default text color black
+    if (!mbSkipHeaderFooter)
+    {
     rStrm.WriteChar( '<' ).WriteCharPtr( OOO_STRING_SVTOOLS_HTML_body );
 
     if (!mbSkipImages)
@@ -626,13 +637,15 @@ void ScHTMLExport::WriteBody()
     }
 
     rStrm.WriteChar( '>' ); OUT_LF();
+    }
 
     if ( bAll )
         WriteOverview();
 
     WriteTables();
 
-    TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_body );
+    if (!mbSkipHeaderFooter)
+        TAG_OFF_LF( OOO_STRING_SVTOOLS_HTML_body );
 }
 
 
diff --git a/sc/source/filter/inc/htmlexp.hxx b/sc/source/filter/inc/htmlexp.hxx
index d1ff1eb..b71211c 100644
--- a/sc/source/filter/inc/htmlexp.hxx
+++ b/sc/source/filter/inc/htmlexp.hxx
@@ -126,6 +126,8 @@ class ScHTMLExport : public ScExportBase
     bool             bTableDataWidth;
     bool             bTableDataHeight;
     bool             mbSkipImages;
+    /// If HTML header and footer should be written as well, or just the content itself.
+    bool             mbSkipHeaderFooter;
 
     const SfxItemSet& PageDefaults( SCTAB nTab );
 
diff --git a/sw/CppunitTest_sw_htmlexport.mk b/sw/CppunitTest_sw_htmlexport.mk
index 3774e92..d190050 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 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..fc7f6892 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 7d3c898..489d28f 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;


More information about the Libreoffice-commits mailing list