[Libreoffice-commits] core.git: 2 commits - include/xmloff xmloff/source
David Tardon
dtardon at redhat.com
Fri May 3 01:30:37 PDT 2013
include/xmloff/unointerfacetouniqueidentifiermapper.hxx | 17 ++++
include/xmloff/xmlmultiimagehelper.hxx | 6 +
xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx | 41 +++++++++++
xmloff/source/core/xmlmultiimagehelper.cxx | 6 +
xmloff/source/draw/ximpshap.cxx | 43 +++++++++---
xmloff/source/draw/ximpshap.hxx | 1
6 files changed, 102 insertions(+), 12 deletions(-)
New commits:
commit 30b248dfe5bfb8a0649e36f22c943b3feb2f1385
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/include/xmloff/unointerfacetouniqueidentifiermapper.hxx b/include/xmloff/unointerfacetouniqueidentifiermapper.hxx
index e538cbe..5919296 100644
--- a/include/xmloff/unointerfacetouniqueidentifiermapper.hxx
+++ b/include/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< OUString, const ::com::sun::star::uno::Reference< ::com::sun
class XMLOFF_DLLPUBLIC UnoInterfaceToUniqueIdentifierMapper
{
+ typedef std::deque< rtl::OUString > Reserved_t;
+
public:
UnoInterfaceToUniqueIdentifierMapper();
@@ -50,6 +53,17 @@ public:
*/
bool registerReference( const 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
@@ -65,9 +79,12 @@ 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;
IdMap_t maEntries;
sal_Int32 mnNextId;
+ Reserved_t maReserved;
};
}
diff --git a/include/xmloff/xmlmultiimagehelper.hxx b/include/xmloff/xmlmultiimagehelper.hxx
index cb0a290..bbe9ce1 100644
--- a/include/xmloff/xmlmultiimagehelper.hxx
+++ b/include/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 87e54d7..4b2b9db 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 b1ad7bb..e33c443 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 9074b59..81c91a1 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 );
commit 9918757003ae043ad53a9c3fcea2733696f6eb5c
Author: David Tardon <dtardon at redhat.com>
Date: Fri May 3 09:37:11 2013 +0200
the var. must be persistent over multiple calls
Change-Id: Ieb48dfe85ed16a8123917b30873f301d523ea381
diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx
index 4d6f0eb..9074b59 100644
--- a/xmloff/source/draw/ximpshap.cxx
+++ b/xmloff/source/draw/ximpshap.cxx
@@ -153,6 +153,7 @@ SdXMLShapeContext::SdXMLShapeContext(
, maPosition(0, 0)
, mbVisible(true)
, mbPrintable(true)
+, mbHaveXmlId(false)
{
}
@@ -782,7 +783,6 @@ void SdXMLShapeContext::SetThumbnail()
// this is called from the parent group for each unparsed attribute in the attribute list
void SdXMLShapeContext::processAttribute( sal_uInt16 nPrefix, const OUString& rLocalName, const OUString& rValue )
{
- bool bHaveXmlId( false );
if( (XML_NAMESPACE_DRAW == nPrefix) || (XML_NAMESPACE_DRAW_EXT == nPrefix) )
{
if( IsXMLToken( rLocalName, XML_ZINDEX ) )
@@ -791,7 +791,7 @@ void SdXMLShapeContext::processAttribute( sal_uInt16 nPrefix, const OUString& rL
}
else if( IsXMLToken( rLocalName, XML_ID ) )
{
- if (!bHaveXmlId) { maShapeId = rValue; };
+ if (!mbHaveXmlId) { maShapeId = rValue; };
}
else if( IsXMLToken( rLocalName, XML_NAME ) )
{
@@ -893,7 +893,7 @@ void SdXMLShapeContext::processAttribute( sal_uInt16 nPrefix, const OUString& rL
if( IsXMLToken( rLocalName, XML_ID ) )
{
maShapeId = rValue;
- bHaveXmlId = true;
+ mbHaveXmlId = true;
}
}
}
diff --git a/xmloff/source/draw/ximpshap.hxx b/xmloff/source/draw/ximpshap.hxx
index 951fe90..949c70b 100644
--- a/xmloff/source/draw/ximpshap.hxx
+++ b/xmloff/source/draw/ximpshap.hxx
@@ -78,6 +78,7 @@ protected:
bool mbVisible;
bool mbPrintable;
+ bool mbHaveXmlId;
/** if bSupportsStyle is false, auto styles will be set but not a style */
void SetStyle( bool bSupportsStyle = true );
More information about the Libreoffice-commits
mailing list