sw/qa/extras/htmlimport/data/reqif-ole-img.png |binary sw/qa/extras/htmlimport/data/reqif-ole-img.xhtml | 6 ++++++ sw/qa/extras/htmlimport/htmlimport.cxx | 12 ++++++++++++ sw/source/filter/html/htmlplug.cxx | 23 +++++++++++++++++++++++ sw/source/filter/html/swhtml.cxx | 5 +++++ sw/source/filter/html/swhtml.hxx | 7 +++++++ 6 files changed, 53 insertions(+)
New commits: commit 62eb6d3f964e78fa210bba4af81ebf63ba8a16a9 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Tue Mar 6 11:01:52 2018 +0100 sw XHTML import: map nested <object> to replacement graphic Handle the case when the native data is the outer element and the replacement image is the inner one. Change-Id: Ifc3c8b8bc8c0903562a4dab1f0bf15e9de5c98ac Reviewed-on: https://gerrit.libreoffice.org/50812 Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk> Tested-by: Jenkins <c...@libreoffice.org> diff --git a/sw/qa/extras/htmlimport/data/reqif-ole-img.png b/sw/qa/extras/htmlimport/data/reqif-ole-img.png new file mode 100644 index 000000000000..fdad35484e7c Binary files /dev/null and b/sw/qa/extras/htmlimport/data/reqif-ole-img.png differ diff --git a/sw/qa/extras/htmlimport/data/reqif-ole-img.xhtml b/sw/qa/extras/htmlimport/data/reqif-ole-img.xhtml new file mode 100644 index 000000000000..05abc7721d24 --- /dev/null +++ b/sw/qa/extras/htmlimport/data/reqif-ole-img.xhtml @@ -0,0 +1,6 @@ +<reqif-xhtml:div><reqif-xhtml:br/> + <reqif-xhtml:object data="reqif-ole-data.ole" type="text/rtf"> + <reqif-xhtml:object data="reqif-ole-img.png" type="image/png"/> + </reqif-xhtml:object> +</reqif-xhtml:div> + diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx b/sw/qa/extras/htmlimport/htmlimport.cxx index 03d500850edd..6a1a2f9b046b 100644 --- a/sw/qa/extras/htmlimport/htmlimport.cxx +++ b/sw/qa/extras/htmlimport/htmlimport.cxx @@ -13,6 +13,7 @@ #include <com/sun/star/graphic/GraphicType.hpp> #include <com/sun/star/drawing/FillStyle.hpp> #include <com/sun/star/drawing/BitmapMode.hpp> +#include <com/sun/star/document/XEmbeddedObjectSupplier2.hpp> #include <tools/datetime.hxx> #include <unotools/datetime.hxx> #include <vcl/GraphicNativeTransform.hxx> @@ -306,6 +307,17 @@ DECLARE_HTMLIMPORT_TEST(testReqIfOleData, "reqif-ole-data.xhtml") CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xObjects->getCount()); } +DECLARE_HTMLIMPORT_TEST(testReqIfOleImg, "reqif-ole-img.xhtml") +{ + uno::Reference<text::XTextEmbeddedObjectsSupplier> xSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xObjects(xSupplier->getEmbeddedObjects(), + uno::UNO_QUERY); + uno::Reference<document::XEmbeddedObjectSupplier2> xObject(xObjects->getByIndex(0), + uno::UNO_QUERY); + // This failed, OLE object had no replacement image. + CPPUNIT_ASSERT(xObject->getReplacementGraphic().is()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx index 3ebef3437dde..638835931b4e 100644 --- a/sw/source/filter/html/htmlplug.cxx +++ b/sw/source/filter/html/htmlplug.cxx @@ -65,6 +65,7 @@ #include <comphelper/classids.hxx> #include <rtl/uri.hxx> #include <comphelper/storagehelper.hxx> +#include <vcl/graphicfilter.hxx> using namespace com::sun::star; @@ -423,6 +424,19 @@ void SwHTMLParser::InsertEmbed() if( !bHasURL && !bHasType && !bHasData ) return; + if (!m_aEmbeds.empty()) + { + // Nested XHTML <object> element: points to replacement graphic. + SwOLENode* pOLENode = m_aEmbeds.top(); + svt::EmbeddedObjectRef& rObj = pOLENode->GetOLEObj().GetObject(); + Graphic aGraphic; + if (GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aURLObj) != ERRCODE_NONE) + return; + + rObj.SetGraphic(aGraphic, OUString()); + return; + } + // create the plug-in comphelper::EmbeddedObjectContainer aCnt; OUString aObjName; @@ -513,6 +527,15 @@ void SwHTMLParser::InsertEmbed() // character-bound frame, here we must create the frames by hand. RegisterFlyFrame( pFlyFormat ); } + + if (!bHasData) + return; + + SwOLENode* pOLENode = pNoTextNd->GetOLENode(); + if (!pOLENode) + return; + + m_aEmbeds.push(pOLENode); } #if HAVE_FEATURE_JAVA diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx index d798f0ba0a51..af3e3c65c003 100644 --- a/sw/source/filter/html/swhtml.cxx +++ b/sw/source/filter/html/swhtml.cxx @@ -1424,6 +1424,11 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken ) #endif break; + case HtmlTokenId::OBJECT_OFF: + if (!m_aEmbeds.empty()) + m_aEmbeds.pop(); + break; + case HtmlTokenId::APPLET_ON: #if HAVE_FEATURE_JAVA InsertApplet(); diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx index ffbb42d334aa..911042defa20 100644 --- a/sw/source/filter/html/swhtml.hxx +++ b/sw/source/filter/html/swhtml.hxx @@ -36,6 +36,7 @@ #include <memory> #include <vector> #include <deque> +#include <stack> class SfxMedium; class SfxViewFrame; @@ -506,6 +507,12 @@ class SwHTMLParser : public SfxHTMLParser, public SwClient bool m_bXHTML = false; + /** + * Non-owning pointers to already inserted OLE nodes, matching opened + * <object> XHTML elements. + */ + std::stack<SwOLENode*> m_aEmbeds; + void DeleteFormImpl(); void DocumentDetected(); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits