From 04d600d4be7c50db4b3b505039eb8bc96856f593 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Tue, 22 May 2012 17:21:13 +0200 Subject: rework getting shape for the .docx import filter This makes both sw/qa/extras/ooxmltok/data/n705956-{1|2}.docx testcases work at the same time. As far as I understand it, the .docx filter calls into oox and at the end if gets the shape, while the shape is removed from the ShapeContainer. In the case of recursion caused by , clearing the whole list is wrong. Also, the OSL_ENSURE seems to suggest that there should not be more than one shape inserted by each read. So simply consider maShapes to be a stack when importing .docx . Change-Id: I7263aeaf74c8d31a05e64c56b880cbc6b00d7dd6 --- oox/inc/oox/vml/vmlshapecontainer.hxx | 6 ++---- oox/source/shape/ShapeContextHandler.cxx | 5 +---- oox/source/vml/vmlshapecontainer.cxx | 11 +++++++---- 3 files changed, 10 insertions(+), 12 deletions(-) (limited to 'oox') diff --git a/oox/inc/oox/vml/vmlshapecontainer.hxx b/oox/inc/oox/vml/vmlshapecontainer.hxx index 288062566a00..9b11c6ca5a0b 100644 --- a/oox/inc/oox/vml/vmlshapecontainer.hxx +++ b/oox/inc/oox/vml/vmlshapecontainer.hxx @@ -92,16 +92,14 @@ public: template< typename Functor > const ShapeBase* findShape( const Functor& rFunctor ) const; - /** Returns the first shape in the collection (Word only). */ - const ShapeBase* getFirstShape() const; + /** Returns and removes the last shape in the collection (Word only). */ + const ShapeBase* takeLastShape(); /** Creates and inserts all UNO shapes into the passed container. */ void convertAndInsert( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, const ShapeParentAnchor* pParentAnchor = 0 ) const; - inline void clearShapes( ) { maShapes.clear( ); } - private: typedef RefVector< ShapeType > ShapeTypeVector; typedef RefVector< ShapeBase > ShapeVector; diff --git a/oox/source/shape/ShapeContextHandler.cxx b/oox/source/shape/ShapeContextHandler.cxx index de27734a89d8..32342380e2f6 100644 --- a/oox/source/shape/ShapeContextHandler.cxx +++ b/oox/source/shape/ShapeContextHandler.cxx @@ -244,11 +244,8 @@ ShapeContextHandler::getShape() throw (uno::RuntimeException) if ( getContextHandler() == getDrawingShapeContext() ) { mpDrawing->finalizeFragmentImport(); - if( const ::oox::vml::ShapeBase* pShape = mpDrawing->getShapes().getFirstShape() ) - { + if( const ::oox::vml::ShapeBase* pShape = mpDrawing->getShapes().takeLastShape() ) xResult = pShape->convertAndInsert( xShapes ); - mpDrawing->getShapes( ).clearShapes( ); - } } else if (mpShape.get() != NULL) { diff --git a/oox/source/vml/vmlshapecontainer.cxx b/oox/source/vml/vmlshapecontainer.cxx index 0309839a9817..144aa78f7c28 100644 --- a/oox/source/vml/vmlshapecontainer.cxx +++ b/oox/source/vml/vmlshapecontainer.cxx @@ -118,11 +118,14 @@ const ShapeBase* ShapeContainer::getShapeById( const OUString& rShapeId, bool bD return 0; } -const ShapeBase* ShapeContainer::getFirstShape() const +const ShapeBase* ShapeContainer::takeLastShape() { - OSL_ENSURE( mrDrawing.getType() == VMLDRAWING_WORD, "ShapeContainer::getFirstShape - illegal call, Word filter only" ); - OSL_ENSURE( maShapes.size() == 1, "ShapeContainer::getFirstShape - single shape expected" ); - return maShapes.get( 0 ).get(); + assert( mrDrawing.getType() == VMLDRAWING_WORD ); + if( maShapes.empty()) + return NULL; + const ShapeBase* ret = maShapes.back().get(); + maShapes.pop_back(); + return ret; } void ShapeContainer::convertAndInsert( const Reference< XShapes >& rxShapes, const ShapeParentAnchor* pParentAnchor ) const -- cgit