diff options
author | David Tardon <dtardon@redhat.com> | 2013-05-03 06:15:30 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2013-05-03 10:29:47 +0200 |
commit | 30b248dfe5bfb8a0649e36f22c943b3feb2f1385 (patch) | |
tree | 25a4f5798b08c3d9c93b43924a0779f17cb17131 /xmloff | |
parent | the var. must be persistent over multiple calls (diff) | |
download | core-30b248dfe5bfb8a0649e36f22c943b3feb2f1385.tar.gz core-30b248dfe5bfb8a0649e36f22c943b3feb2f1385.zip |
fdo#60075 open drawings with connector attached to SVG
This problem arises when there is a connector attached to draw:frame
element with multiple draw:image elements in it. The import code expects
that they are different representations of the same image (I have not
found if this is specified in ODF), so it only selects the most
"suitable" for import. To do that, it imports them all and then removes
all but the selected one. The image import context,
SdXMLGraphicObjectShapeContext, shares the parent frame's attributes,
which means that all the images in a frame have got the same ID. in
SdXMLGraphicObjectShapeContext::AddShape, the created css::draw::XShape
is registered with its ID... That means that anything that refers to the
frame's ID, like a draw:connector, will always get the _first_ image in
the frame.
Solution is to extend comphelper::UnoInterfaceToUniqueIdentifierMapper
to allow reserving an identifier and setting an interface for it later.
That way, SdXMLFrameShapeContext can reserve its own ID before it starts
importing the first draw:image, and then set the selected XShape at the
end.
Change-Id: I2e11cfd38e1e3534df2b3c01d85da0d755a266c3
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx | 41 | ||||
-rw-r--r-- | xmloff/source/core/xmlmultiimagehelper.cxx | 6 | ||||
-rw-r--r-- | xmloff/source/draw/ximpshap.cxx | 37 |
3 files changed, 77 insertions, 7 deletions
diff --git a/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx b/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx index 87e54d711e21..4b2b9db6f141 100644 --- a/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx +++ b/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <algorithm> #include <xmloff/unointerfacetouniqueidentifiermapper.hxx> @@ -71,7 +72,7 @@ bool UnoInterfaceToUniqueIdentifierMapper::registerReference( const OUString& rI { return rIdentifier != (*aIter).first; } - else if( findIdentifier( rIdentifier, aIter ) ) + else if( findIdentifier( rIdentifier, aIter ) || findReserved( rIdentifier ) ) { return false; } @@ -173,6 +174,44 @@ bool UnoInterfaceToUniqueIdentifierMapper::findIdentifier( const OUString& rIden return rIter != maEntries.end(); } +bool UnoInterfaceToUniqueIdentifierMapper::reserveIdentifier( const rtl::OUString& rIdentifier ) +{ + if ( findReserved( rIdentifier ) ) + return false; + + maReserved.push_back( rIdentifier ); + return true; +} + +bool UnoInterfaceToUniqueIdentifierMapper::registerReservedReference( + const rtl::OUString& rIdentifier, + const com::sun::star::uno::Reference< com::sun::star::uno::XInterface >& rInterface ) +{ + Reserved_t::const_iterator aIt; + if ( !findReserved( rIdentifier, aIt ) ) + return false; + + Reserved_t::iterator aRemoveIt( maReserved.begin() + ( aIt - maReserved.begin() ) ); + maReserved.erase( aRemoveIt ); + registerReference( rIdentifier, rInterface ); + + return true; +} + +bool UnoInterfaceToUniqueIdentifierMapper::findReserved( const OUString& rIdentifier ) const +{ + Reserved_t::const_iterator aDummy; + return findReserved( rIdentifier, aDummy ); +} + +bool UnoInterfaceToUniqueIdentifierMapper::findReserved( + const OUString& rIdentifier, + Reserved_t::const_iterator& rIter ) const +{ + rIter = std::find( maReserved.begin(), maReserved.end(), rIdentifier ); + return rIter != maReserved.end(); +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/core/xmlmultiimagehelper.cxx b/xmloff/source/core/xmlmultiimagehelper.cxx index b1ad7bb1ae19..e33c4438ee1e 100644 --- a/xmloff/source/core/xmlmultiimagehelper.cxx +++ b/xmloff/source/core/xmlmultiimagehelper.cxx @@ -89,8 +89,9 @@ multiImageImportHelper::~multiImageImportHelper() } } -void multiImageImportHelper::solveMultipleImages() +const SvXMLImportContext* multiImageImportHelper::solveMultipleImages() { + const SvXMLImportContext* pContext(0); if(maImplContextVector.size() > 1) { // multiple child contexts were imported, decide which is the most valuable one @@ -118,6 +119,7 @@ void multiImageImportHelper::solveMultipleImages() // Take out the most valuable one const std::vector< SvXMLImportContextRef* >::iterator aRemove(maImplContextVector.begin() + nIndexOfPreferred); + pContext = **aRemove; delete *aRemove; maImplContextVector.erase(aRemove); @@ -127,6 +129,8 @@ void multiImageImportHelper::solveMultipleImages() removeGraphicFromImportContext(**maImplContextVector[a]); } } + + return pContext; } void multiImageImportHelper::addContent(const SvXMLImportContext& rSvXMLImportContext) diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx index 9074b5959647..81c91a18fdf2 100644 --- a/xmloff/source/draw/ximpshap.cxx +++ b/xmloff/source/draw/ximpshap.cxx @@ -17,6 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <cassert> + #include <tools/debug.hxx> #include <com/sun/star/document/XEventsSupplier.hpp> #include <com/sun/star/container/XNameReplace.hpp> @@ -3453,6 +3455,9 @@ SvXMLImportContext *SdXMLFrameShapeContext::CreateChildContext( sal_uInt16 nPref if(getSupportsMultipleContents() && dynamic_cast< SdXMLGraphicObjectShapeContext* >(pContext)) { + if ( !maShapeId.isEmpty() ) + GetImport().getInterfaceToIdentifierMapper().reserveIdentifier( maShapeId ); + addContent(*mxImplContext); } } @@ -3526,8 +3531,15 @@ void SdXMLFrameShapeContext::StartElement(const uno::Reference< xml::sax::XAttri void SdXMLFrameShapeContext::EndElement() { - /// solve if multiple image child contexts were imported - solveMultipleImages(); + // solve if multiple image child contexts were imported + const SvXMLImportContext* const pSelectedContext(solveMultipleImages()); + const SdXMLGraphicObjectShapeContext* pShapeContext( dynamic_cast<const SdXMLGraphicObjectShapeContext*>( pSelectedContext ) ); + if ( pShapeContext ) + { + assert( mxImplContext.Is() ); + const uno::Reference< uno::XInterface > xShape( pShapeContext->getShape() ); + GetImport().getInterfaceToIdentifierMapper().registerReservedReference( maShapeId, xShape ); + } if( !mxImplContext.Is() ) { @@ -3588,10 +3600,25 @@ void SdXMLFrameShapeContext::EndElement() SdXMLShapeContext::EndElement(); } -void SdXMLFrameShapeContext::processAttribute( sal_uInt16, - const OUString&, const OUString& ) +void SdXMLFrameShapeContext::processAttribute( sal_uInt16 nPrefix, + const OUString& rLocalName, const OUString& rValue ) { - // ignore + bool bId( false ); + + switch ( nPrefix ) + { + case XML_NAMESPACE_DRAW : + case XML_NAMESPACE_DRAW_EXT : + bId = IsXMLToken( rLocalName, XML_ID ); + break; + case XML_NAMESPACE_NONE : + case XML_NAMESPACE_XML : + bId = IsXMLToken( rLocalName, XML_ID ); + break; + } + + if ( bId ) + SdXMLShapeContext::processAttribute( nPrefix, rLocalName, rValue ); } TYPEINIT1( SdXMLCustomShapeContext, SdXMLShapeContext ); |