summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2013-05-03 06:15:30 +0200
committerThorsten Behrens <tbehrens@suse.com>2013-05-15 11:23:00 +0200
commit7f8ef6795e57713c802d74b4532f9c0addd9b479 (patch)
tree34f059d8f4d5460ad9775ab54bad84980964da5f /xmloff
parent5ce2944df838fca58808c34dd035a7318dfc1b90 (diff)
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/inc/xmloff/unointerfacetouniqueidentifiermapper.hxx19
-rw-r--r--xmloff/inc/xmloff/xmlmultiimagehelper.hxx6
-rw-r--r--xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx41
-rw-r--r--xmloff/source/core/xmlmultiimagehelper.cxx6
-rw-r--r--xmloff/source/draw/ximpshap.cxx37
5 files changed, 99 insertions, 10 deletions
diff --git a/xmloff/inc/xmloff/unointerfacetouniqueidentifiermapper.hxx b/xmloff/inc/xmloff/unointerfacetouniqueidentifiermapper.hxx
index 03d30332c2da..23f552536114 100644
--- a/xmloff/inc/xmloff/unointerfacetouniqueidentifiermapper.hxx
+++ b/xmloff/inc/xmloff/unointerfacetouniqueidentifiermapper.hxx
@@ -24,6 +24,7 @@
#include "xmloff/dllapi.h"
#include "sal/types.h"
+#include <deque>
#include <map>
#include <rtl/ustring.hxx>
#include <com/sun/star/uno/XInterface.hpp>
@@ -35,6 +36,8 @@ typedef ::std::map< rtl::OUString, const ::com::sun::star::uno::Reference< ::com
class XMLOFF_DLLPUBLIC UnoInterfaceToUniqueIdentifierMapper
{
+ typedef std::deque< rtl::OUString > Reserved_t;
+
public:
UnoInterfaceToUniqueIdentifierMapper();
@@ -50,6 +53,17 @@ public:
*/
bool registerReference( const rtl::OUString& rIdentifier, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rInterface );
+ /** reserves an identifier for later registration.
+
+ @returns
+ false, if the identifier already exists
+ */
+ bool reserveIdentifier( const rtl::OUString& rIdentifier );
+
+ /** registers the given uno object with reserved identifier.
+ */
+ bool registerReservedReference( const rtl::OUString& rIdentifier, const com::sun::star::uno::Reference< com::sun::star::uno::XInterface >& rInterface );
+
/** @returns
the identifier for the given uno object. If this uno object is not already
registered, an empty string is returned
@@ -64,10 +78,13 @@ public:
private:
bool findReference( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rInterface, IdMap_t::const_iterator& rIter ) const;
- bool findIdentifier( const rtl::OUString& rIdentifier, IdMap_t::const_iterator& rIter ) const;
+ bool findIdentifier( const OUString& rIdentifier, IdMap_t::const_iterator& rIter ) const;
+ bool findReserved( const OUString& rIdentifier ) const;
+ bool findReserved( const OUString& rIdentifier, Reserved_t::const_iterator& rIter ) const;
IdMap_t maEntries;
sal_Int32 mnNextId;
+ Reserved_t maReserved;
};
}
diff --git a/xmloff/inc/xmloff/xmlmultiimagehelper.hxx b/xmloff/inc/xmloff/xmlmultiimagehelper.hxx
index 4628677d1025..c806dd69b8de 100644
--- a/xmloff/inc/xmloff/xmlmultiimagehelper.hxx
+++ b/xmloff/inc/xmloff/xmlmultiimagehelper.hxx
@@ -41,8 +41,10 @@ public:
virtual ~multiImageImportHelper();
/// solve multiple imported images. The most valuable one is choosen,
- /// see imlementation for evtl. changing weights and/or adding filetypes
- void solveMultipleImages();
+ /// see imlementation for evtl. changing weights and/or adding filetypes.
+ ///
+ /// @returns import context of the selected image
+ const SvXMLImportContext* solveMultipleImages();
/// add a content to the remembered image import contexts
void addContent(const SvXMLImportContext& rSvXMLImportContext);
diff --git a/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx b/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx
index 4b1d1336b8c0..b76b8a849e25 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>
@@ -72,7 +73,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;
}
@@ -174,6 +175,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 c2214f20da70..16b930213cff 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 e52736ce0199..430a5d2f2872 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>
@@ -3455,6 +3457,9 @@ SvXMLImportContext *SdXMLFrameShapeContext::CreateChildContext( sal_uInt16 nPref
if(getSupportsMultipleContents() && dynamic_cast< SdXMLGraphicObjectShapeContext* >(pContext))
{
+ if ( !maShapeId.isEmpty() )
+ GetImport().getInterfaceToIdentifierMapper().reserveIdentifier( maShapeId );
+
addContent(*mxImplContext);
}
}
@@ -3528,8 +3533,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() )
{
@@ -3590,10 +3602,25 @@ void SdXMLFrameShapeContext::EndElement()
SdXMLShapeContext::EndElement();
}
-void SdXMLFrameShapeContext::processAttribute( sal_uInt16,
- const ::rtl::OUString&, const ::rtl::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 );