Kaydet (Commit) 50d48709 authored tarafından Miklos Vajna's avatar Miklos Vajna

tdf#94374 DOCX import: allow insert -> object -> document

Change-Id: I977930d59ef1ae9ae8bd2dfa9a7f3816c46d982c
üst 90cbb22f
...@@ -65,6 +65,8 @@ ...@@ -65,6 +65,8 @@
#include <com/sun/star/style/CaseMap.hpp> #include <com/sun/star/style/CaseMap.hpp>
#include <com/sun/star/style/PageStyleLayout.hpp> #include <com/sun/star/style/PageStyleLayout.hpp>
#include <com/sun/star/util/DateTime.hpp> #include <com/sun/star/util/DateTime.hpp>
#include <com/sun/star/document/XFilter.hpp>
#include <com/sun/star/document/XImporter.hpp>
#include <vcl/bmpacc.hxx> #include <vcl/bmpacc.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <unotest/assertion_traits.hxx> #include <unotest/assertion_traits.hxx>
...@@ -74,6 +76,7 @@ ...@@ -74,6 +76,7 @@
#include <swtypes.hxx> #include <swtypes.hxx>
#include <tools/datetimeutils.hxx> #include <tools/datetimeutils.hxx>
#include <oox/drawingml/drawingmltypes.hxx> #include <oox/drawingml/drawingmltypes.hxx>
#include <unotools/streamwrap.hxx>
#include <bordertest.hxx> #include <bordertest.hxx>
...@@ -95,6 +98,24 @@ public: ...@@ -95,6 +98,24 @@ public:
if (OString(filename) == "smartart.docx" || OString(filename) == "strict-smartart.docx" || OString(filename) == "fdo87488.docx") if (OString(filename) == "smartart.docx" || OString(filename) == "strict-smartart.docx" || OString(filename) == "fdo87488.docx")
SvtFilterOptions::Get().SetSmartArt2Shape(false); SvtFilterOptions::Get().SetSmartArt2Shape(false);
} }
protected:
/// Copy&paste helper.
bool paste(const OUString& rFilename, const uno::Reference<text::XTextRange>& xTextRange)
{
uno::Reference<document::XFilter> xFilter(m_xSFactory->createInstance("com.sun.star.comp.Writer.WriterFilter"), uno::UNO_QUERY_THROW);
uno::Reference<document::XImporter> xImporter(xFilter, uno::UNO_QUERY_THROW);
xImporter->setTargetDocument(mxComponent);
uno::Sequence<beans::PropertyValue> aDescriptor(3);
aDescriptor[0].Name = "InputStream";
SvStream* pStream = utl::UcbStreamHelper::CreateStream(getURLFromSrc("/sw/qa/extras/ooxmlimport/data/") + rFilename, StreamMode::READ);
uno::Reference<io::XStream> xStream(new utl::OStreamWrapper(*pStream));
aDescriptor[0].Value <<= xStream;
aDescriptor[1].Name = "InsertMode";
aDescriptor[1].Value <<= sal_True;
aDescriptor[2].Name = "TextInsertModeRange";
aDescriptor[2].Value <<= xTextRange;
return xFilter->filter(aDescriptor);
}
}; };
class FailTest : public Test class FailTest : public Test
...@@ -2879,6 +2900,15 @@ DECLARE_OOXMLIMPORT_TEST(testTdf89165, "tdf89165.docx") ...@@ -2879,6 +2900,15 @@ DECLARE_OOXMLIMPORT_TEST(testTdf89165, "tdf89165.docx")
// This must not hang in layout // This must not hang in layout
} }
DECLARE_OOXMLIMPORT_TEST(testTdf94374, "hello.docx")
{
uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XTextRange> xText(xTextDocument->getText(), uno::UNO_QUERY);
uno::Reference<text::XTextRange> xEnd = xText->getEnd();
// This failed: it wasn't possible to insert a DOCX document into an existing Writer one.
CPPUNIT_ASSERT(paste("tdf94374.docx", xEnd));
}
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -170,8 +170,9 @@ sal_Bool WriterFilter::filter(const uno::Sequence< beans::PropertyValue >& aDesc ...@@ -170,8 +170,9 @@ sal_Bool WriterFilter::filter(const uno::Sequence< beans::PropertyValue >& aDesc
return sal_False; return sal_False;
writerfilter::dmapper::SourceDocumentType eType = writerfilter::dmapper::SourceDocumentType::OOXML; writerfilter::dmapper::SourceDocumentType eType = writerfilter::dmapper::SourceDocumentType::OOXML;
uno::Reference<text::XTextRange> xInsertTextRange = aMediaDesc.getUnpackedValueOrDefault("TextInsertModeRange", uno::Reference<text::XTextRange>());
writerfilter::Stream::Pointer_t pStream( writerfilter::Stream::Pointer_t pStream(
writerfilter::dmapper::DomainMapperFactory::createMapper(m_xContext, xInputStream, m_xDstDoc, bRepairStorage, eType, uno::Reference<text::XTextRange>(), aMediaDesc)); writerfilter::dmapper::DomainMapperFactory::createMapper(m_xContext, xInputStream, m_xDstDoc, bRepairStorage, eType, xInsertTextRange, aMediaDesc));
//create the tokenizer and domain mapper //create the tokenizer and domain mapper
writerfilter::ooxml::OOXMLStream::Pointer_t pDocStream = writerfilter::ooxml::OOXMLDocumentFactory::createStream(m_xContext, xInputStream, bRepairStorage); writerfilter::ooxml::OOXMLStream::Pointer_t pDocStream = writerfilter::ooxml::OOXMLDocumentFactory::createStream(m_xContext, xInputStream, bRepairStorage);
uno::Reference<task::XStatusIndicator> xStatusIndicator = aMediaDesc.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_STATUSINDICATOR(), uno::Reference<task::XStatusIndicator>()); uno::Reference<task::XStatusIndicator> xStatusIndicator = aMediaDesc.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_STATUSINDICATOR(), uno::Reference<task::XStatusIndicator>());
......
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