[Libreoffice-commits] core.git: Branch 'distro/suse/suse-4.0' - 5 commits - cppcanvas/source xmloff/inc xmloff/source

Thorsten Behrens tbehrens at suse.com
Wed May 15 02:34:12 PDT 2013


 cppcanvas/source/inc/implrenderer.hxx                       |    6 
 cppcanvas/source/mtfrenderer/emfplus.cxx                    |    5 
 cppcanvas/source/mtfrenderer/implrenderer.cxx               |    3 
 xmloff/inc/xmloff/unointerfacetouniqueidentifiermapper.hxx  |   12 +
 xmloff/inc/xmloff/xmlmultiimagehelper.hxx                   |   12 -
 xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx |   85 +++++-------
 xmloff/source/core/xmlmultiimagehelper.cxx                  |   12 +
 xmloff/source/draw/ximpshap.cxx                             |   38 ++++-
 xmloff/source/draw/ximpshap.hxx                             |    2 
 xmloff/source/text/XMLTextFrameContext.cxx                  |    2 
 xmloff/source/text/XMLTextFrameContext.hxx                  |    2 
 11 files changed, 109 insertions(+), 70 deletions(-)

New commits:
commit 588441537cd0e29e9d3e78a5884287cb498f13bd
Author: Thorsten Behrens <tbehrens at suse.com>
Date:   Wed May 15 11:05:45 2013 +0200

    Fix fdo#64512 Handle xml:id correctly on multi-image draw:frames
    
    Fixes a regression from the pick-best-image from draw:frame in ODF,
    where before sometimes the XShape got deleted that the
    UnoInterfaceToUniqueIdentifierMapper::registerReference stored.
    
    For that, added a
    UnoInterfaceToUniqueIdentifierMapper::registerReferenceAlways
    function, which overwrites potentially existing earlier entries
    with the same identifier string.
    
    This fix was originally much more messy, but then dtardon committed
    30b248dfe5bfb8a0649e36f22c943b3feb2f1385 which also fixes this here
    bug. Now only sneaking in slightly less involved interface map
    handling and a safeguard in ximpshap.cxx.
    
    Change-Id: I87501e43518a5fc2fee166c45a4e2f01718f5228

diff --git a/xmloff/inc/xmloff/unointerfacetouniqueidentifiermapper.hxx b/xmloff/inc/xmloff/unointerfacetouniqueidentifiermapper.hxx
index 23f5525..b664f7c 100644
--- a/xmloff/inc/xmloff/unointerfacetouniqueidentifiermapper.hxx
+++ b/xmloff/inc/xmloff/unointerfacetouniqueidentifiermapper.hxx
@@ -24,7 +24,6 @@
 #include "xmloff/dllapi.h"
 #include "sal/types.h"
 
-#include <deque>
 #include <map>
 #include <rtl/ustring.hxx>
 #include <com/sun/star/uno/XInterface.hpp>
@@ -32,12 +31,10 @@
 namespace comphelper
 {
 
-typedef ::std::map< rtl::OUString, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > IdMap_t;
+typedef ::std::map< rtl::OUString, ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > IdMap_t;
 
 class XMLOFF_DLLPUBLIC UnoInterfaceToUniqueIdentifierMapper
 {
-    typedef std::deque< rtl::OUString > Reserved_t;
-
 public:
     UnoInterfaceToUniqueIdentifierMapper();
 
@@ -53,16 +50,12 @@ 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 );
+    /** always registers the given uno object with the given identifier.
 
-    /** 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 );
+        In contrast to registerReference(), this here overwrites any
+        earlier registration of the same identifier
+    */
+    void registerReferenceAlways( 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
@@ -79,12 +72,10 @@ 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 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;
+    void insertReference( const OUString& rIdentifier, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rInterface );
 
     IdMap_t	maEntries;
     sal_Int32 mnNextId;
-    Reserved_t maReserved;
 };
 
 }
diff --git a/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx b/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx
index 87eb2d3..c0ddf8a 100644
--- a/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx
+++ b/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx
@@ -17,8 +17,6 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#include <algorithm>
-
 #include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
 
 using namespace ::com::sun::star;
@@ -65,42 +63,25 @@ bool UnoInterfaceToUniqueIdentifierMapper::registerReference( const OUString& rI
     {
         return rIdentifier != (*aIter).first;
     }
-    else if( findIdentifier( rIdentifier, aIter ) || findReserved( rIdentifier ) )
+    else if( findIdentifier( rIdentifier, aIter ) )
     {
         return false;
     }
     else
     {
-        maEntries.insert( IdMap_t::value_type( rIdentifier, xRef ) );
-
-        // see if this is a reference like something we would generate in the future
-        const sal_Unicode *p = rIdentifier.getStr();
-        sal_Int32 nLength = rIdentifier.getLength();
-
-        // see if the identifier is 'id' followed by a pure integer value
-        if( nLength < 2 || p[0] != 'i' || p[1] != 'd' )
-            return true;
-
-        nLength -= 2;
-        p += 2;
-
-        while(nLength--)
-        {
-            if( (*p < '0') || (*p > '9') )
-                return true; // a custom id, that will never conflict with genereated id's
+        insertReference( rIdentifier, xRef );
+    }
 
-            p++;
-        }
+    return true;
+}
 
-        // the identifier is a pure integer value
-        // so we make sure we will never generate
-        // an integer value like this one
-        sal_Int32 nId = rIdentifier.copy(2).toInt32();
-        if( mnNextId <= nId )
-            mnNextId = nId + 1;
+void UnoInterfaceToUniqueIdentifierMapper::registerReferenceAlways( const OUString& rIdentifier, const Reference< XInterface >& rInterface )
+{
+    // Be certain that the references we store in our table are to the
+    // leading / primary XInterface - cf. findReference
+    uno::Reference< uno::XInterface > xRef( rInterface, uno::UNO_QUERY );
 
-        return true;
-    }
+    insertReference( rIdentifier, xRef );
 }
 
 const OUString& UnoInterfaceToUniqueIdentifierMapper::getIdentifier( const Reference< XInterface >& rInterface ) const
@@ -159,42 +140,35 @@ bool UnoInterfaceToUniqueIdentifierMapper::findIdentifier( const OUString& rIden
     return rIter != maEntries.end();
 }
 
-bool UnoInterfaceToUniqueIdentifierMapper::reserveIdentifier( const rtl::OUString& rIdentifier )
+void UnoInterfaceToUniqueIdentifierMapper::insertReference( const OUString& rIdentifier, const Reference< XInterface >& rInterface )
 {
-    if ( findReserved( rIdentifier ) )
-        return false;
+    maEntries[rIdentifier] = rInterface;
 
-    maReserved.push_back( rIdentifier );
-    return true;
-}
+    // see if this is a reference like something we would generate in the future
+    const sal_Unicode *p = rIdentifier.getStr();
+    sal_Int32 nLength = rIdentifier.getLength();
 
-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;
+    // see if the identifier is 'id' followed by a pure integer value
+    if( nLength < 2 || p[0] != 'i' || p[1] != 'd' )
+        return;
 
-    Reserved_t::iterator aRemoveIt( maReserved.begin() + ( aIt - maReserved.begin() ) );
-    maReserved.erase( aRemoveIt );
-    registerReference( rIdentifier, rInterface );
+    nLength -= 2;
+    p += 2;
 
-    return true;
-}
+    while(nLength--)
+    {
+        if( (*p < '0') || (*p > '9') )
+            return; // a custom id, that will never conflict with genereated id's
 
-bool UnoInterfaceToUniqueIdentifierMapper::findReserved( const OUString& rIdentifier ) const
-{
-    Reserved_t::const_iterator aDummy;
-    return findReserved( rIdentifier, aDummy );
-}
+        p++;
+    }
 
-bool UnoInterfaceToUniqueIdentifierMapper::findReserved(
-        const OUString& rIdentifier,
-        Reserved_t::const_iterator& rIter ) const
-{
-    rIter = std::find( maReserved.begin(), maReserved.end(), rIdentifier );
-    return rIter != maReserved.end();
+    // the identifier is a pure integer value
+    // so we make sure we will never generate
+    // an integer value like this one
+    sal_Int32 nId = rIdentifier.copy(2).toInt32();
+    if( mnNextId <= nId )
+        mnNextId = nId + 1;
 }
 
 }
diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx
index e4a07c9..f0307c9 100644
--- a/xmloff/source/draw/ximpshap.cxx
+++ b/xmloff/source/draw/ximpshap.cxx
@@ -3457,9 +3457,6 @@ SvXMLImportContext *SdXMLFrameShapeContext::CreateChildContext( sal_uInt16 nPref
 
         if(getSupportsMultipleContents() && dynamic_cast< SdXMLGraphicObjectShapeContext* >(pContext))
         {
-            if ( !maShapeId.isEmpty() )
-                GetImport().getInterfaceToIdentifierMapper().reserveIdentifier( maShapeId );
-
             addContent(*mxImplContext);
         }
     }
@@ -3536,11 +3533,13 @@ void SdXMLFrameShapeContext::EndElement()
     // solve if multiple image child contexts were imported
     const SvXMLImportContext* const pSelectedContext(solveMultipleImages());
     const SdXMLGraphicObjectShapeContext* pShapeContext( dynamic_cast<const SdXMLGraphicObjectShapeContext*>( pSelectedContext ) );
-    if ( pShapeContext )
+    if ( pShapeContext && !maShapeId.isEmpty() )
     {
+        // fdo#64512 and fdo#60075 - make sure *this* shape is
+        // registered for given ID
         assert( mxImplContext.Is() );
         const uno::Reference< uno::XInterface > xShape( pShapeContext->getShape() );
-        GetImport().getInterfaceToIdentifierMapper().registerReservedReference( maShapeId, xShape );
+        GetImport().getInterfaceToIdentifierMapper().registerReferenceAlways( maShapeId, xShape );
     }
 
     if( !mxImplContext.Is() )
commit b7913a75da20269dddebe737715b7a9c9a2ecdf2
Author: Thorsten Behrens <tbehrens at suse.com>
Date:   Wed May 15 02:58:22 2013 +0200

    Remove redundant doxygen doc strings.
    
    This is already (identically) documented in the header file.
    
    Change-Id: I4a10cb0c1d1b1eee80fd828ab95829fb8128433f

diff --git a/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx b/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx
index b76b8a8..87eb2d3 100644
--- a/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx
+++ b/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx
@@ -34,9 +34,6 @@ UnoInterfaceToUniqueIdentifierMapper::UnoInterfaceToUniqueIdentifierMapper()
 {
 }
 
-/** returns a unique identifier for the given uno object. IF a uno object is
-    registered more than once, the returned identifier is always the same.
-*/
 const OUString& UnoInterfaceToUniqueIdentifierMapper::registerReference( const Reference< XInterface >& rInterface )
 {
     // Be certain that the references we store in our table are to the
@@ -56,11 +53,6 @@ const OUString& UnoInterfaceToUniqueIdentifierMapper::registerReference( const R
     }
 }
 
-/** registers the given uno object with the given identifier.
-
-    @returns
-        false, if the given identifier already exists and is not associated with the given interface
-*/
 bool UnoInterfaceToUniqueIdentifierMapper::registerReference( const OUString& rIdentifier, const Reference< XInterface >& rInterface )
 {
     IdMap_t::const_iterator aIter;
@@ -111,10 +103,6 @@ bool UnoInterfaceToUniqueIdentifierMapper::registerReference( const OUString& rI
     }
 }
 
-/** @returns
-        the identifier for the given uno object. If this uno object is not already
-        registered, an empty string is returned
-*/
 const OUString& UnoInterfaceToUniqueIdentifierMapper::getIdentifier( const Reference< XInterface >& rInterface ) const
 {
     IdMap_t::const_iterator aIter;
@@ -129,10 +117,6 @@ const OUString& UnoInterfaceToUniqueIdentifierMapper::getIdentifier( const Refer
     }
 }
 
-/** @returns
-    the uno object that is registered with the given identifier. If no uno object
-    is registered with the given identifier, an empty reference is returned.
-*/
 const Reference< XInterface >& UnoInterfaceToUniqueIdentifierMapper::getReference( const OUString& rIdentifier ) const
 {
     IdMap_t::const_iterator aIter;
commit 732be8f926c2f7f41317b4ce8ff7315ee23e0c40
Author: Thorsten Behrens <tbehrens at suse.com>
Date:   Wed May 15 09:31:38 2013 +0200

    Use upper camel case for class names in xmloff.
    
    Align multiimagehelper with module standard.
    
    Change-Id: I70a4dbc66a0d127b9bf04d1e8db694d3526b21d7

diff --git a/xmloff/inc/xmloff/xmlmultiimagehelper.hxx b/xmloff/inc/xmloff/xmlmultiimagehelper.hxx
index c806dd6..3d7d647 100644
--- a/xmloff/inc/xmloff/xmlmultiimagehelper.hxx
+++ b/xmloff/inc/xmloff/xmlmultiimagehelper.hxx
@@ -25,7 +25,7 @@
 
 //////////////////////////////////////////////////////////////////////////////
 
-class multiImageImportHelper
+class MultiImageImportHelper
 {
 private:
     std::vector< SvXMLImportContextRef* >       maImplContextVector;
@@ -37,8 +37,8 @@ protected:
     virtual void removeGraphicFromImportContext(const SvXMLImportContext& rContext) const = 0;
 
 public:
-    multiImageImportHelper();
-    virtual ~multiImageImportHelper();
+    MultiImageImportHelper();
+    virtual ~MultiImageImportHelper();
 
     /// solve multiple imported images. The most valuable one is choosen,
     /// see imlementation for evtl. changing weights and/or adding filetypes.
diff --git a/xmloff/source/core/xmlmultiimagehelper.cxx b/xmloff/source/core/xmlmultiimagehelper.cxx
index 16b9302..b8cb4a6 100644
--- a/xmloff/source/core/xmlmultiimagehelper.cxx
+++ b/xmloff/source/core/xmlmultiimagehelper.cxx
@@ -74,13 +74,13 @@ namespace
 
 //////////////////////////////////////////////////////////////////////////////
 
-multiImageImportHelper::multiImageImportHelper()
+MultiImageImportHelper::MultiImageImportHelper()
 :   maImplContextVector(),
     mbSupportsMultipleContents(false)
 {
 }
 
-multiImageImportHelper::~multiImageImportHelper()
+MultiImageImportHelper::~MultiImageImportHelper()
 {
     while(!maImplContextVector.empty())
     {
@@ -89,7 +89,7 @@ multiImageImportHelper::~multiImageImportHelper()
     }
 }
 
-const SvXMLImportContext* multiImageImportHelper::solveMultipleImages()
+const SvXMLImportContext* MultiImageImportHelper::solveMultipleImages()
 {
     const SvXMLImportContext* pContext(0);
     if(maImplContextVector.size() > 1)
@@ -133,7 +133,7 @@ const SvXMLImportContext* multiImageImportHelper::solveMultipleImages()
     return pContext;
 }
 
-void multiImageImportHelper::addContent(const SvXMLImportContext& rSvXMLImportContext)
+void MultiImageImportHelper::addContent(const SvXMLImportContext& rSvXMLImportContext)
 {
     if(dynamic_cast< const SvXMLImportContext* >(&rSvXMLImportContext))
     {
diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx
index 430a5d2..e4a07c9 100644
--- a/xmloff/source/draw/ximpshap.cxx
+++ b/xmloff/source/draw/ximpshap.cxx
@@ -3349,7 +3349,7 @@ SdXMLFrameShapeContext::SdXMLFrameShapeContext( SvXMLImport& rImport, sal_uInt16
         com::sun::star::uno::Reference< com::sun::star::drawing::XShapes >& rShapes,
         sal_Bool bTemporaryShape)
 : SdXMLShapeContext( rImport, nPrfx, rLocalName, xAttrList, rShapes, bTemporaryShape ),
-    multiImageImportHelper(),
+    MultiImageImportHelper(),
     mbSupportsReplacement( sal_False ),
     mxImplContext(),
     mxReplImplContext()
diff --git a/xmloff/source/draw/ximpshap.hxx b/xmloff/source/draw/ximpshap.hxx
index 56c428c..4fc9120 100644
--- a/xmloff/source/draw/ximpshap.hxx
+++ b/xmloff/source/draw/ximpshap.hxx
@@ -569,7 +569,7 @@ public:
 //////////////////////////////////////////////////////////////////////////////
 // draw:-frame
 
-class SdXMLFrameShapeContext : public SdXMLShapeContext, public multiImageImportHelper
+class SdXMLFrameShapeContext : public SdXMLShapeContext, public MultiImageImportHelper
 {
 private:
     sal_Bool mbSupportsReplacement;
diff --git a/xmloff/source/text/XMLTextFrameContext.cxx b/xmloff/source/text/XMLTextFrameContext.cxx
index 6e8fc2e2..c850e67 100644
--- a/xmloff/source/text/XMLTextFrameContext.cxx
+++ b/xmloff/source/text/XMLTextFrameContext.cxx
@@ -1342,7 +1342,7 @@ XMLTextFrameContext::XMLTextFrameContext(
         const Reference< XAttributeList > & xAttrList,
         TextContentAnchorType eATyp )
 :   SvXMLImportContext( rImport, nPrfx, rLName )
-,   multiImageImportHelper()
+,   MultiImageImportHelper()
 ,   m_xAttrList( new SvXMLAttributeList( xAttrList ) )
 ,   m_pHyperlink( 0 )
     // Implement Title/Description Elements UI (#i73249#)
diff --git a/xmloff/source/text/XMLTextFrameContext.hxx b/xmloff/source/text/XMLTextFrameContext.hxx
index 2a4adfb..e3da71b 100644
--- a/xmloff/source/text/XMLTextFrameContext.hxx
+++ b/xmloff/source/text/XMLTextFrameContext.hxx
@@ -30,7 +30,7 @@ namespace com { namespace sun { namespace star {
 
 class XMLTextFrameContextHyperlink_Impl;
 
-class XMLTextFrameContext : public SvXMLImportContext, public multiImageImportHelper
+class XMLTextFrameContext : public SvXMLImportContext, public MultiImageImportHelper
 {
     ::com::sun::star::uno::Reference<
         ::com::sun::star::xml::sax::XAttributeList > m_xAttrList;
commit 7f8ef6795e57713c802d74b4532f9c0addd9b479
Author: David Tardon <dtardon at redhat.com>
Date:   Fri May 3 06:15:30 2013 +0200

    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

diff --git a/xmloff/inc/xmloff/unointerfacetouniqueidentifiermapper.hxx b/xmloff/inc/xmloff/unointerfacetouniqueidentifiermapper.hxx
index 03d3033..23f5525 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 4628677..c806dd6 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 4b1d133..b76b8a8 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 c2214f2..16b9302 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 e52736c..430a5d2 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 );
commit 5ce2944df838fca58808c34dd035a7318dfc1b90
Author: Thorsten Behrens <tbehrens at suse.com>
Date:   Wed May 8 20:37:45 2013 +0200

    Don't leak all of the EMF+ graphic objects.
    
    Change-Id: I7951a9d25da5feec997dd0643f8579f5bcd0ee0f
    (cherry picked from commit 569f6b41c6d7dcdcc65a2d6a75018a3266936532)

diff --git a/cppcanvas/source/inc/implrenderer.hxx b/cppcanvas/source/inc/implrenderer.hxx
index 4537368..4d5918b 100644
--- a/cppcanvas/source/inc/implrenderer.hxx
+++ b/cppcanvas/source/inc/implrenderer.hxx
@@ -54,9 +54,13 @@ namespace cppcanvas
     {
         struct OutDevState;
         struct ActionFactoryParameters;
-        struct EMFPObject;
         struct XForm;
 
+        struct EMFPObject
+        {
+            virtual ~EMFPObject() {}
+        };
+
         // state stack of OutputDevice, to correctly handle
         // push/pop actions
         class VectorOfOutDevStates
diff --git a/cppcanvas/source/mtfrenderer/emfplus.cxx b/cppcanvas/source/mtfrenderer/emfplus.cxx
index 2c80e1d..4c0aca6 100644
--- a/cppcanvas/source/mtfrenderer/emfplus.cxx
+++ b/cppcanvas/source/mtfrenderer/emfplus.cxx
@@ -117,11 +117,6 @@ namespace cppcanvas
             s.Seek (pos);
         });
 
-        struct EMFPObject
-        {
-            virtual ~EMFPObject() {}
-        };
-
         struct EMFPPath : public EMFPObject
         {
             ::basegfx::B2DPolyPolygon    aPolygon;
diff --git a/cppcanvas/source/mtfrenderer/implrenderer.cxx b/cppcanvas/source/mtfrenderer/implrenderer.cxx
index 1f3872b..5d697bb 100644
--- a/cppcanvas/source/mtfrenderer/implrenderer.cxx
+++ b/cppcanvas/source/mtfrenderer/implrenderer.cxx
@@ -3044,6 +3044,9 @@ namespace cppcanvas
 
         ImplRenderer::~ImplRenderer()
         {
+            // don't leak EMFPObjects
+            for(unsigned int i=0; i<SAL_N_ELEMENTS(aObjects); ++i)
+                delete aObjects[i];
         }
 
         bool ImplRenderer::drawSubset( sal_Int32    nStartIndex,


More information about the Libreoffice-commits mailing list