summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorLászló Németh <laszlo.nemeth@collabora.com>2015-03-23 16:16:28 +0100
committerNémeth László <nemeth@numbertext.org>2015-03-24 07:38:04 +0000
commit9b0e09dedc76a3bc4fd7a128a3a115b328727e00 (patch)
treeea05f0ca70cf559c679f5f3bb0b7d2a107bae443 /writerfilter
parent799a7878fd5b3a5a01b59d0a4139a2b0908ccc43 (diff)
SkipImages option for document import
This option allows images and drawings to be skipped while importing DOC and DOCX, for text-only conversion or indexing. Change-Id: Id4bfbbe48d8a8e970b1cb5922187768bf94dc918 Reviewed-on: https://gerrit.libreoffice.org/14733 Reviewed-by: Németh László <nemeth@numbertext.org> Tested-by: Németh László <nemeth@numbertext.org>
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/inc/ooxml/OOXMLDocument.hxx4
-rw-r--r--writerfilter/source/filter/WriterFilter.cxx3
-rw-r--r--writerfilter/source/ooxml/OOXMLDocumentImpl.cxx11
-rw-r--r--writerfilter/source/ooxml/OOXMLDocumentImpl.hxx4
-rw-r--r--writerfilter/source/ooxml/OOXMLFastContextHandler.cxx5
5 files changed, 18 insertions, 9 deletions
diff --git a/writerfilter/inc/ooxml/OOXMLDocument.hxx b/writerfilter/inc/ooxml/OOXMLDocument.hxx
index c533e359eb86..d9b76e29c634 100644
--- a/writerfilter/inc/ooxml/OOXMLDocument.hxx
+++ b/writerfilter/inc/ooxml/OOXMLDocument.hxx
@@ -260,7 +260,9 @@ public:
createStream(OOXMLStream::Pointer_t pStream, const OUString & rId);
static OOXMLDocument *
- createDocument(OOXMLStream::Pointer_t pStream, const css::uno::Reference<css::task::XStatusIndicator>& xStatusIndicator);
+ createDocument(OOXMLStream::Pointer_t pStream,
+ const css::uno::Reference<css::task::XStatusIndicator>& xStatusIndicator,
+ bool bSkipImage);
};
diff --git a/writerfilter/source/filter/WriterFilter.cxx b/writerfilter/source/filter/WriterFilter.cxx
index 1a968d98fc43..327477b57d20 100644
--- a/writerfilter/source/filter/WriterFilter.cxx
+++ b/writerfilter/source/filter/WriterFilter.cxx
@@ -154,6 +154,7 @@ sal_Bool WriterFilter::filter(const uno::Sequence< beans::PropertyValue >& aDesc
{
utl::MediaDescriptor aMediaDesc(aDescriptor);
bool bRepairStorage = aMediaDesc.getUnpackedValueOrDefault("RepairPackage", false);
+ bool bSkipImages = aMediaDesc.getUnpackedValueOrDefault("FilterOptions", OUString("")) == "SkipImages";
uno::Reference< io::XInputStream > xInputStream;
try
@@ -175,7 +176,7 @@ sal_Bool WriterFilter::filter(const uno::Sequence< beans::PropertyValue >& aDesc
//create the tokenizer and domain mapper
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>());
- writerfilter::ooxml::OOXMLDocument::Pointer_t pDocument(writerfilter::ooxml::OOXMLDocumentFactory::createDocument(pDocStream, xStatusIndicator));
+ writerfilter::ooxml::OOXMLDocument::Pointer_t pDocument(writerfilter::ooxml::OOXMLDocumentFactory::createDocument(pDocStream, xStatusIndicator, bSkipImages));
uno::Reference<frame::XModel> xModel(m_xDstDoc, uno::UNO_QUERY_THROW);
pDocument->setModel(xModel);
diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
index 097bdfeab3dd..d15d59e81352 100644
--- a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
+++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
@@ -48,13 +48,14 @@ namespace writerfilter {
namespace ooxml
{
-OOXMLDocumentImpl::OOXMLDocumentImpl(OOXMLStream::Pointer_t pStream, const uno::Reference<task::XStatusIndicator>& xStatusIndicator)
+OOXMLDocumentImpl::OOXMLDocumentImpl(OOXMLStream::Pointer_t pStream, const uno::Reference<task::XStatusIndicator>& xStatusIndicator, bool bSkipImages)
: mpStream(pStream)
, mxStatusIndicator(xStatusIndicator)
, mnXNoteId(0)
, mXNoteType(0)
, mxThemeDom(nullptr)
, mbIsSubstream(false)
+ , mbSkipImages(bSkipImages)
, mnPercentSize(0)
, mnProgressLastPos(0)
, mnProgressCurrentPos(0)
@@ -268,7 +269,7 @@ OOXMLDocumentImpl::getSubStream(const OUString & rId)
OOXMLDocumentImpl * pTemp;
// Do not pass status indicator to sub-streams: they are typically marginal in size, so we just track the main document for now.
- writerfilter::Reference<Stream>::Pointer_t pRet( pTemp = new OOXMLDocumentImpl(pStream, uno::Reference<task::XStatusIndicator>()) );
+ writerfilter::Reference<Stream>::Pointer_t pRet( pTemp = new OOXMLDocumentImpl(pStream, uno::Reference<task::XStatusIndicator>(), mbSkipImages ));
pTemp->setModel(mxModel);
pTemp->setDrawPage(mxDrawPage);
pTemp->setIsSubstream( true );
@@ -282,7 +283,7 @@ OOXMLDocumentImpl::getXNoteStream(OOXMLStream::StreamType_t nType, const Id & rT
OOXMLStream::Pointer_t pStream =
(OOXMLDocumentFactory::createStream(mpStream, nType));
// See above, no status indicator for the note stream, either.
- OOXMLDocumentImpl * pDocument = new OOXMLDocumentImpl(pStream, uno::Reference<task::XStatusIndicator>());
+ OOXMLDocumentImpl * pDocument = new OOXMLDocumentImpl(pStream, uno::Reference<task::XStatusIndicator>(), mbSkipImages);
pDocument->setXNoteId(nId);
pDocument->setXNoteType(rType);
@@ -950,9 +951,9 @@ uno::Sequence<beans::PropertyValue > OOXMLDocumentImpl::getEmbeddingsList( )
OOXMLDocument *
OOXMLDocumentFactory::createDocument
-(OOXMLStream::Pointer_t pStream, const uno::Reference<task::XStatusIndicator>& xStatusIndicator)
+(OOXMLStream::Pointer_t pStream, const uno::Reference<task::XStatusIndicator>& xStatusIndicator, bool mbSkipImages)
{
- return new OOXMLDocumentImpl(pStream, xStatusIndicator);
+ return new OOXMLDocumentImpl(pStream, xStatusIndicator, mbSkipImages);
}
}}
diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx
index 8f9cb2ad8490..507a3ad23b85 100644
--- a/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx
+++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx
@@ -55,6 +55,7 @@ class OOXMLDocumentImpl : public OOXMLDocument
css::uno::Sequence < css::beans::PropertyValue > mxEmbeddingsList;
std::vector<css::beans::PropertyValue> mxEmbeddingsListTemp;
bool mbIsSubstream;
+ bool mbSkipImages;
/// How many paragraphs equal to 1 percent?
sal_Int32 mnPercentSize;
/// Position progress when it was last updated, possibly not after every paragraph in case of large documents.
@@ -90,7 +91,7 @@ protected:
void resolveGlossaryStream(Stream & rStream);
void resolveEmbeddingsStream(OOXMLStream::Pointer_t pStream);
public:
- OOXMLDocumentImpl(OOXMLStream::Pointer_t pStream, const css::uno::Reference<css::task::XStatusIndicator>& xStatusIndicator);
+ OOXMLDocumentImpl(OOXMLStream::Pointer_t pStream, const css::uno::Reference<css::task::XStatusIndicator>& xStatusIndicator, bool bSkipImages);
virtual ~OOXMLDocumentImpl();
virtual void resolve(Stream & rStream) SAL_OVERRIDE;
@@ -140,6 +141,7 @@ public:
virtual css::uno::Sequence<css::beans::PropertyValue > getEmbeddingsList() SAL_OVERRIDE;
void incrementProgress();
+ bool IsSkipImages() { return mbSkipImages; };
};
}}
#endif // OOXML_DOCUMENT_IMPL_HXX
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index 3a47a8a7c572..9a9c841a6b6f 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -1826,9 +1826,12 @@ OOXMLFastContextHandlerWrapper::lcl_createFastChildContext
// filter out a single token. Just hardwire the wrap token here till we
// need a more generic solution.
bool bIsWrap = Element == static_cast<sal_Int32>(NMSP_vmlWord | XML_wrap);
+ bool bSkipImages = getDocument()->IsSkipImages() && oox::getNamespace(Element) == static_cast<sal_Int32>(NMSP_dml) &&
+ !((oox::getBaseToken(Element) == XML_linkedTxbx) || (oox::getBaseToken(Element) == XML_txbx));
+
if ( bInNamespaces && (!bIsWrap || static_cast<OOXMLFastContextHandlerShape*>(mpParent)->isShapeSent()) )
xResult.set(OOXMLFactory::getInstance()->createFastChildContextFromStart(this, Element));
- else if (mxContext.is())
+ else if (mxContext.is() && !bSkipImages)
{
OOXMLFastContextHandlerWrapper * pWrapper =
new OOXMLFastContextHandlerWrapper