Kaydet (Commit) 971ffe10 authored tarafından Miklos Vajna's avatar Miklos Vajna

sw HTML export: avoid loosing embedded objects when skipping images

Change-Id: If795af5430b319922cd8242ca82352e148dd680b
üst 24065627
...@@ -53,6 +53,7 @@ $(eval $(call gb_CppunitTest_use_vcl,sw_htmlexport)) ...@@ -53,6 +53,7 @@ $(eval $(call gb_CppunitTest_use_vcl,sw_htmlexport))
$(eval $(call gb_CppunitTest_use_components,sw_htmlexport,\ $(eval $(call gb_CppunitTest_use_components,sw_htmlexport,\
basic/util/sb \ basic/util/sb \
canvas/source/factory/canvasfactory \
comphelper/util/comphelp \ comphelper/util/comphelp \
configmgr/source/configmgr \ configmgr/source/configmgr \
embeddedobj/util/embobj \ embeddedobj/util/embobj \
...@@ -65,6 +66,7 @@ $(eval $(call gb_CppunitTest_use_components,sw_htmlexport,\ ...@@ -65,6 +66,7 @@ $(eval $(call gb_CppunitTest_use_components,sw_htmlexport,\
linguistic/source/lng \ linguistic/source/lng \
oox/util/oox \ oox/util/oox \
package/source/xstor/xstor \ package/source/xstor/xstor \
sc/util/sc \
package/util/package2 \ package/util/package2 \
sax/source/expatwrap/expwrap \ sax/source/expatwrap/expwrap \
sw/util/sw \ sw/util/sw \
......
This diff was suppressed by a .gitattributes entry.
...@@ -46,7 +46,7 @@ private: ...@@ -46,7 +46,7 @@ private:
void preTest(const char* filename) SAL_OVERRIDE void preTest(const char* filename) SAL_OVERRIDE
{ {
if (getTestName() == "testExportOfImagesWithSkipImageEnabled") if (getTestName().indexOf("SkipImage") != -1)
setFilterOptions("SkipImages"); setFilterOptions("SkipImages");
else else
setFilterOptions(""); setFilterOptions("");
...@@ -134,6 +134,17 @@ DECLARE_HTMLEXPORT_TEST(testExportOfImagesWithSkipImageEnabled, "textAndImage.do ...@@ -134,6 +134,17 @@ DECLARE_HTMLEXPORT_TEST(testExportOfImagesWithSkipImageEnabled, "textAndImage.do
assertXPath(pDoc, "/html/body/p/img", 0); 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 #endif
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
......
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
#include <frmfmt.hxx> #include <frmfmt.hxx>
#include <svl/ownlist.hxx> #include <svl/ownlist.hxx>
#include <unotools/mediadescriptor.hxx>
#include <unotools/streamwrap.hxx>
#include "pam.hxx" #include "pam.hxx"
#include "doc.hxx" #include "doc.hxx"
#include "ndtxt.hxx" #include "ndtxt.hxx"
...@@ -51,10 +53,12 @@ ...@@ -51,10 +53,12 @@
#include "wrthtml.hxx" #include "wrthtml.hxx"
#include "htmlfly.hxx" #include "htmlfly.hxx"
#include "swcss1.hxx" #include "swcss1.hxx"
#include "unoframe.hxx"
#include <com/sun/star/embed/XClassifiedObject.hpp> #include <com/sun/star/embed/XClassifiedObject.hpp>
#include <com/sun/star/embed/EmbedStates.hpp> #include <com/sun/star/embed/EmbedStates.hpp>
#include <com/sun/star/embed/Aspects.hpp> #include <com/sun/star/embed/Aspects.hpp>
#include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/frame/XStorable.hpp>
#include <comphelper/embeddedobjectcontainer.hxx> #include <comphelper/embeddedobjectcontainer.hxx>
#include <comphelper/classids.hxx> #include <comphelper/classids.hxx>
...@@ -1249,9 +1253,6 @@ Writer& OutHTML_FrmFmtOLENodeGrf( Writer& rWrt, const SwFrmFmt& rFrmFmt, ...@@ -1249,9 +1253,6 @@ Writer& OutHTML_FrmFmtOLENodeGrf( Writer& rWrt, const SwFrmFmt& rFrmFmt,
{ {
SwHTMLWriter& rHTMLWrt = static_cast<SwHTMLWriter&>(rWrt); SwHTMLWriter& rHTMLWrt = static_cast<SwHTMLWriter&>(rWrt);
if (rHTMLWrt.mbSkipImages)
return rWrt;
const SwFmtCntnt& rFlyCntnt = rFrmFmt.GetCntnt(); const SwFmtCntnt& rFlyCntnt = rFrmFmt.GetCntnt();
sal_uLong nStt = rFlyCntnt.GetCntntIdx()->GetIndex()+1; sal_uLong nStt = rFlyCntnt.GetCntntIdx()->GetIndex()+1;
SwOLENode *pOLENd = rHTMLWrt.pDoc->GetNodes()[ nStt ]->GetOLENode(); SwOLENode *pOLENd = rHTMLWrt.pDoc->GetNodes()[ nStt ]->GetOLENode();
...@@ -1260,6 +1261,35 @@ Writer& OutHTML_FrmFmtOLENodeGrf( Writer& rWrt, const SwFrmFmt& rFrmFmt, ...@@ -1260,6 +1261,35 @@ Writer& OutHTML_FrmFmtOLENodeGrf( Writer& rWrt, const SwFrmFmt& rFrmFmt,
if( !pOLENd ) if( !pOLENd )
return rWrt; 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() ); Graphic aGraphic( *pOLENd->GetGraphic() );
sal_uLong nFlags = bInCntnr ? HTML_FRMOPTS_GENIMG_CNTNR sal_uLong nFlags = bInCntnr ? HTML_FRMOPTS_GENIMG_CNTNR
: HTML_FRMOPTS_GENIMG; : HTML_FRMOPTS_GENIMG;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment