diff options
author | Armin Le Grand <alg@apache.org> | 2011-12-19 15:41:21 +0000 |
---|---|---|
committer | Armin Le Grand <alg@apache.org> | 2011-12-19 15:41:21 +0000 |
commit | e2e16715893229b5d0ad2da6c8e84464e0c43a2e (patch) | |
tree | 79d1c632784b3de16fc82c1dfc27c1796a9ef451 /xmloff | |
parent | ea4f454ed956e08be47783b3bddd7789f905e350 (diff) |
Svg: Reintegrated Svg replacement from /branches/alg/svgreplavement to trunk, first version of Svg stable and done
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/Library_xo.mk | 1 | ||||
-rw-r--r-- | xmloff/Package_inc.mk | 1 | ||||
-rw-r--r-- | xmloff/inc/xmloff/txtparae.hxx | 1 | ||||
-rw-r--r-- | xmloff/inc/xmloff/xmlmultiimagehelper.hxx | 62 | ||||
-rw-r--r-- | xmloff/source/core/xmlmultiimagehelper.cxx | 146 | ||||
-rw-r--r-- | xmloff/source/draw/shapeexport2.cxx | 25 | ||||
-rw-r--r-- | xmloff/source/draw/ximpshap.cxx | 93 | ||||
-rw-r--r-- | xmloff/source/draw/ximpshap.hxx | 8 | ||||
-rw-r--r-- | xmloff/source/text/XMLTextFrameContext.cxx | 66 | ||||
-rw-r--r-- | xmloff/source/text/XMLTextFrameContext.hxx | 8 | ||||
-rw-r--r-- | xmloff/source/text/txtparae.cxx | 29 |
11 files changed, 428 insertions, 12 deletions
diff --git a/xmloff/Library_xo.mk b/xmloff/Library_xo.mk index 0544171dbfbd..0e23b7dea241 100644 --- a/xmloff/Library_xo.mk +++ b/xmloff/Library_xo.mk @@ -119,6 +119,7 @@ $(eval $(call gb_Library_add_exception_objects,xo,\ xmloff/source/core/xmltkmap \ xmloff/source/core/xmltoken \ xmloff/source/core/xmluconv \ + xmloff/source/core/xmlmultiimagehelper \ xmloff/source/draw/EnhancedCustomShapeToken \ xmloff/source/draw/XMLGraphicsDefaultStyle \ xmloff/source/draw/XMLImageMapContext \ diff --git a/xmloff/Package_inc.mk b/xmloff/Package_inc.mk index 4e11c2b4b5d9..a71da5fe617e 100644 --- a/xmloff/Package_inc.mk +++ b/xmloff/Package_inc.mk @@ -129,3 +129,4 @@ $(eval $(call gb_Package_add_file,xmloff_inc,inc/xmloff/xmltkmap.hxx,xmloff/xmlt $(eval $(call gb_Package_add_file,xmloff_inc,inc/xmloff/xmltoken.hxx,xmloff/xmltoken.hxx)) $(eval $(call gb_Package_add_file,xmloff_inc,inc/xmloff/xmltypes.hxx,xmloff/xmltypes.hxx)) $(eval $(call gb_Package_add_file,xmloff_inc,inc/xmloff/xmluconv.hxx,xmloff/xmluconv.hxx)) +$(eval $(call gb_Package_add_file,xmloff_inc,inc/xmloff/xmlmultiimagehelper.hxx,xmloff/xmlmultiimagehelper.hxx)) diff --git a/xmloff/inc/xmloff/txtparae.hxx b/xmloff/inc/xmloff/txtparae.hxx index a83d24d15d0c..01e1ba9cbff9 100644 --- a/xmloff/inc/xmloff/txtparae.hxx +++ b/xmloff/inc/xmloff/txtparae.hxx @@ -146,6 +146,7 @@ protected: const ::rtl::OUString sGraphicFilter; const ::rtl::OUString sGraphicRotation; const ::rtl::OUString sGraphicURL; + const ::rtl::OUString sReplacementGraphicURL; const ::rtl::OUString sHeight; const ::rtl::OUString sHoriOrient; const ::rtl::OUString sHoriOrientPosition; diff --git a/xmloff/inc/xmloff/xmlmultiimagehelper.hxx b/xmloff/inc/xmloff/xmlmultiimagehelper.hxx new file mode 100644 index 000000000000..c7ce4bae7570 --- /dev/null +++ b/xmloff/inc/xmloff/xmlmultiimagehelper.hxx @@ -0,0 +1,62 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +#ifndef _XMLOFF_XMLMULTIIMAGEHELPER_HXX +#define _XMLOFF_XMLMULTIIMAGEHELPER_HXX + +#include <sal/types.h> +#include <xmloff/xmlimp.hxx> + +////////////////////////////////////////////////////////////////////////////// + +class multiImageImportHelper +{ +private: + std::vector< SvXMLImportContextRef* > maImplContextVector; + bool mbSupportsMultipleContents; + +protected: + /// helper to get the created xShape instance, needs to be overloaded + virtual rtl::OUString getGraphicURLFromImportContext(const SvXMLImportContext& rContext) const = 0; + virtual void removeGraphicFromImportContext(const SvXMLImportContext& rContext) const = 0; + +public: + multiImageImportHelper(); + ~multiImageImportHelper(); + + /// solve multiple imported images. The most valuable one is choosen, + /// see imlementation for evtl. changing weights and/or adding filetypes + void solveMultipleImages(); + + /// add a content to the remembered image import contexts + void addContent(const SvXMLImportContext& rSvXMLImportContext); + + /// read/write access to boolean switch + bool getSupportsMultipleContents() const { return mbSupportsMultipleContents; } + void setSupportsMultipleContents(bool bNew) { mbSupportsMultipleContents = bNew; } +}; + +////////////////////////////////////////////////////////////////////////////// + +#endif // _XMLOFF_XMLMULTIIMAGEHELPER_HXX + +////////////////////////////////////////////////////////////////////////////// +// eof diff --git a/xmloff/source/core/xmlmultiimagehelper.cxx b/xmloff/source/core/xmlmultiimagehelper.cxx new file mode 100644 index 000000000000..9047ac9d125c --- /dev/null +++ b/xmloff/source/core/xmlmultiimagehelper.cxx @@ -0,0 +1,146 @@ +/************************************************************** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + *************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_xmloff.hxx" + +#include <xmloff/xmlmultiimagehelper.hxx> +#include <rtl/ustring.hxx> + +////////////////////////////////////////////////////////////////////////////// + +using namespace ::com::sun::star; + +////////////////////////////////////////////////////////////////////////////// + +namespace +{ + sal_uInt32 getQualityIndex(const rtl::OUString& rString) + { + sal_uInt32 nRetval(0); + + // pixel formats first + if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".bmp"))) + { + return 10; + } + if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".gif"))) + { + return 20; + } + if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".jpg"))) + { + return 30; + } + if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".png"))) + { + return 40; + } + + // vector formats, prefer always + if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".svm"))) + { + return 1000; + } + if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".wmf"))) + { + return 1010; + } + if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".emf"))) + { + return 1020; + } + else if(rString.endsWithAsciiL(RTL_CONSTASCII_STRINGPARAM(".svg"))) + { + return 1030; + } + + return nRetval; + } +} + +////////////////////////////////////////////////////////////////////////////// + +multiImageImportHelper::multiImageImportHelper() +: maImplContextVector(), + mbSupportsMultipleContents(false) +{ +} + +multiImageImportHelper::~multiImageImportHelper() +{ + while(!maImplContextVector.empty()) + { + delete *(maImplContextVector.end() - 1); + maImplContextVector.pop_back(); + } +} + +void multiImageImportHelper::solveMultipleImages() +{ + if(maImplContextVector.size() > 1) + { + // multiple child contexts were imported, decide which is the most valuable one + // and remove the rest + sal_uInt32 nIndexOfPreferred(maImplContextVector.size()); + sal_uInt32 nBestQuality(0), a(0); + + for(a = 0; a < maImplContextVector.size(); a++) + { + const rtl::OUString aStreamURL(getGraphicURLFromImportContext(**maImplContextVector[a])); + const sal_uInt32 nNewQuality(getQualityIndex(aStreamURL)); + + if(nNewQuality > nBestQuality) + { + nBestQuality = nNewQuality; + nIndexOfPreferred = a; + } + } + + // correct if needed, default is to use the last entry + if(nIndexOfPreferred >= maImplContextVector.size()) + { + nIndexOfPreferred = maImplContextVector.size() - 1; + } + + // Take out the most valuable one + const std::vector< SvXMLImportContextRef* >::iterator aRemove(maImplContextVector.begin() + nIndexOfPreferred); + delete *aRemove; + maImplContextVector.erase(aRemove); + + // remove the rest from parent + for(a = 0; a < maImplContextVector.size(); a++) + { + removeGraphicFromImportContext(**maImplContextVector[a]); + } + } +} + +void multiImageImportHelper::addContent(const SvXMLImportContext& rSvXMLImportContext) +{ + if(dynamic_cast< const SvXMLImportContext* >(&rSvXMLImportContext)) + { + maImplContextVector.push_back(new SvXMLImportContextRef(const_cast< SvXMLImportContext* >(&rSvXMLImportContext))); + } +} + +////////////////////////////////////////////////////////////////////////////// +//eof diff --git a/xmloff/source/draw/shapeexport2.cxx b/xmloff/source/draw/shapeexport2.cxx index f9b0989825fa..ded603f7801c 100644 --- a/xmloff/source/draw/shapeexport2.cxx +++ b/xmloff/source/draw/shapeexport2.cxx @@ -1156,6 +1156,29 @@ void XMLShapeExport::ImpExportGraphicObjectShape( { if( !bIsEmptyPresObj ) { + OUString aReplacementUrl; + xPropSet->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("ReplacementGraphicURL"))) >>= aReplacementUrl; + + // If there is no url, then then graphic is empty + if(aReplacementUrl.getLength()) + { + const OUString aStr = mrExport.AddEmbeddedGraphicObject(aReplacementUrl); + + if(aStr.getLength()) + { + mrExport.AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, aStr); + mrExport.AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE ); + mrExport.AddAttribute(XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED ); + mrExport.AddAttribute(XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD ); + + // xlink:href for replacement, only written for Svg content + SvXMLElementExport aOBJ(mrExport, XML_NAMESPACE_DRAW, XML_IMAGE, sal_True, sal_True); + + // optional office:binary-data + mrExport.AddEmbeddedGraphicObjectAsBase64(aReplacementUrl); + } + } + OUString aStreamURL; OUString aStr; @@ -1189,7 +1212,7 @@ void XMLShapeExport::ImpExportGraphicObjectShape( { if( aStr[ 0 ] == '#' ) { - aStreamURL = OUString::createFromAscii( "vnd.sun.star.Package:" ); + aStreamURL = sPackageURL; aStreamURL = aStreamURL.concat( aStr.copy( 1, aStr.getLength() - 1 ) ); } diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx index 11c399ff3ec6..79bcbe026c51 100644 --- a/xmloff/source/draw/ximpshap.cxx +++ b/xmloff/source/draw/ximpshap.cxx @@ -82,6 +82,7 @@ #include <basegfx/matrix/b2dhommatrix.hxx> #include <tools/string.hxx> #include <com/sun/star/drawing/XEnhancedCustomShapeDefaulter.hpp> +#include <com/sun/star/container/XChild.hpp> // --> OD 2006-02-22 #b6382898# #include <com/sun/star/text/XTextDocument.hpp> @@ -3328,7 +3329,10 @@ 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 ), - mbSupportsReplacement( sal_False ) + multiImageImportHelper(), + mbSupportsReplacement( sal_False ), + mxImplContext(), + mxReplImplContext() { uno::Reference < util::XCloneable > xClone( xAttrList, uno::UNO_QUERY ); if( xClone.is() ) @@ -3342,6 +3346,67 @@ SdXMLFrameShapeContext::~SdXMLFrameShapeContext() { } +void SdXMLFrameShapeContext::removeGraphicFromImportContext(const SvXMLImportContext& rContext) const +{ + const SdXMLGraphicObjectShapeContext* pSdXMLGraphicObjectShapeContext = dynamic_cast< const SdXMLGraphicObjectShapeContext* >(&rContext); + + if(pSdXMLGraphicObjectShapeContext) + { + try + { + uno::Reference< container::XChild > xChild(pSdXMLGraphicObjectShapeContext->getShape(), uno::UNO_QUERY_THROW); + + if(xChild.is()) + { + uno::Reference< drawing::XShapes > xParent(xChild->getParent(), uno::UNO_QUERY_THROW); + + if(xParent.is()) + { + // remove from parent + xParent->remove(pSdXMLGraphicObjectShapeContext->getShape()); + + // dispose + uno::Reference< lang::XComponent > xComp(pSdXMLGraphicObjectShapeContext->getShape(), UNO_QUERY); + + if(xComp.is()) + { + xComp->dispose(); + } + } + } + } + catch( uno::Exception& ) + { + DBG_ERROR( "Error in cleanup of multiple graphic object import (!)" ); + } + } +} + +rtl::OUString SdXMLFrameShapeContext::getGraphicURLFromImportContext(const SvXMLImportContext& rContext) const +{ + rtl::OUString aRetval; + const SdXMLGraphicObjectShapeContext* pSdXMLGraphicObjectShapeContext = dynamic_cast< const SdXMLGraphicObjectShapeContext* >(&rContext); + + if(pSdXMLGraphicObjectShapeContext) + { + try + { + const uno::Reference< beans::XPropertySet > xPropSet(pSdXMLGraphicObjectShapeContext->getShape(), uno::UNO_QUERY_THROW); + + if(xPropSet.is()) + { + xPropSet->getPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GraphicStreamURL"))) >>= aRetval; + } + } + catch( uno::Exception& ) + { + DBG_ERROR( "Error in cleanup of multiple graphic object import (!)" ); + } + } + + return aRetval; +} + SvXMLImportContext *SdXMLFrameShapeContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const uno::Reference< xml::sax::XAttributeList>& xAttrList ) @@ -3351,11 +3416,28 @@ SvXMLImportContext *SdXMLFrameShapeContext::CreateChildContext( sal_uInt16 nPref if( !mxImplContext.Is() ) { pContext = GetImport().GetShapeImport()->CreateFrameChildContext( - GetImport(), nPrefix, rLocalName, xAttrList, mxShapes, mxAttrList ); + GetImport(), nPrefix, rLocalName, xAttrList, mxShapes, mxAttrList); + + mxImplContext = pContext; + mbSupportsReplacement = IsXMLToken(rLocalName, XML_OBJECT ) || IsXMLToken(rLocalName, XML_OBJECT_OLE); + setSupportsMultipleContents(IsXMLToken(rLocalName, XML_IMAGE)); + if(getSupportsMultipleContents() && dynamic_cast< SdXMLGraphicObjectShapeContext* >(pContext)) + { + addContent(*mxImplContext); + } + } + else if(getSupportsMultipleContents() && XML_NAMESPACE_DRAW == nPrefix && IsXMLToken(rLocalName, XML_IMAGE)) + { + // read another image + pContext = GetImport().GetShapeImport()->CreateFrameChildContext( + GetImport(), nPrefix, rLocalName, xAttrList, mxShapes, mxAttrList); mxImplContext = pContext; - mbSupportsReplacement = IsXMLToken( rLocalName, XML_OBJECT ) || - IsXMLToken( rLocalName, XML_OBJECT_OLE ); + + if(dynamic_cast< SdXMLGraphicObjectShapeContext* >(pContext)) + { + addContent(*mxImplContext); + } } else if( mbSupportsReplacement && !mxReplImplContext && XML_NAMESPACE_DRAW == nPrefix && @@ -3415,6 +3497,9 @@ void SdXMLFrameShapeContext::StartElement(const uno::Reference< xml::sax::XAttri void SdXMLFrameShapeContext::EndElement() { + /// solve if multiple image child contexts were imported + solveMultipleImages(); + if( !mxImplContext.Is() ) { // now check if this is an empty presentation object diff --git a/xmloff/source/draw/ximpshap.hxx b/xmloff/source/draw/ximpshap.hxx index 1423f7a4b5d7..e8fe3725312f 100644 --- a/xmloff/source/draw/ximpshap.hxx +++ b/xmloff/source/draw/ximpshap.hxx @@ -38,6 +38,7 @@ #include <vector> #include <xmloff/shapeimport.hxx> +#include <xmloff/xmlmultiimagehelper.hxx> ////////////////////////////////////////////////////////////////////////////// // common shape context @@ -573,13 +574,18 @@ public: ////////////////////////////////////////////////////////////////////////////// // draw:-frame -class SdXMLFrameShapeContext : public SdXMLShapeContext +class SdXMLFrameShapeContext : public SdXMLShapeContext, public multiImageImportHelper { private: sal_Bool mbSupportsReplacement; SvXMLImportContextRef mxImplContext; SvXMLImportContextRef mxReplImplContext; +protected: + /// helper to get the created xShape instance, needs to be overloaded + virtual rtl::OUString getGraphicURLFromImportContext(const SvXMLImportContext& rContext) const; + virtual void removeGraphicFromImportContext(const SvXMLImportContext& rContext) const; + public: TYPEINFO(); diff --git a/xmloff/source/text/XMLTextFrameContext.cxx b/xmloff/source/text/XMLTextFrameContext.cxx index 1548387ffc04..3e741e2f65f9 100644 --- a/xmloff/source/text/XMLTextFrameContext.cxx +++ b/xmloff/source/text/XMLTextFrameContext.cxx @@ -433,6 +433,7 @@ public: TYPEINFO(); sal_Bool CreateIfNotThere(); + const OUString& GetHRef() const { return sHRef; } XMLTextFrameContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx, @@ -466,7 +467,7 @@ public: ::com::sun::star::text::TextContentAnchorType GetAnchorType() const { return eAnchorType; } const ::com::sun::star::uno::Reference < - ::com::sun::star::beans::XPropertySet >& GetPropSet() { return xPropSet; } + ::com::sun::star::beans::XPropertySet >& GetPropSet() const { return xPropSet; } }; TYPEINIT1( XMLTextFrameContext_Impl, SvXMLImportContext ); @@ -759,8 +760,6 @@ void XMLTextFrameContext_Impl::Create( sal_Bool /*bHRefOrBase64*/ ) xTextImportHelper->InsertTextContent( xTxtCntnt ); } - Reference < XShape > xShape( xPropSet, UNO_QUERY ); - // #107848# // Make adding the shepe to Z-Ordering dependent from if we are // inside a inside_deleted_section (redlining). That is necessary @@ -770,6 +769,8 @@ void XMLTextFrameContext_Impl::Create( sal_Bool /*bHRefOrBase64*/ ) if(!GetImport().HasTextImport() || !GetImport().GetTextImport()->IsInsideDeleteContext()) { + Reference < XShape > xShape( xPropSet, UNO_QUERY ); + GetImport().GetShapeImport()->shapeWithZIndexAdded( xShape, nZIndex ); } @@ -1308,6 +1309,42 @@ void XMLTextFrameContext_Impl::SetDesc( const OUString& rDesc ) TYPEINIT1( XMLTextFrameContext, SvXMLImportContext ); +void XMLTextFrameContext::removeGraphicFromImportContext(const SvXMLImportContext& rContext) const +{ + const XMLTextFrameContext_Impl* pXMLTextFrameContext_Impl = dynamic_cast< const XMLTextFrameContext_Impl* >(&rContext); + + if(pXMLTextFrameContext_Impl) + { + try + { + // just dispose to delete + uno::Reference< lang::XComponent > xComp(pXMLTextFrameContext_Impl->GetPropSet(), UNO_QUERY); + + if(xComp.is()) + { + xComp->dispose(); + } + } + catch( uno::Exception& ) + { + DBG_ERROR( "Error in cleanup of multiple graphic object import (!)" ); + } + } +} + +rtl::OUString XMLTextFrameContext::getGraphicURLFromImportContext(const SvXMLImportContext& rContext) const +{ + rtl::OUString aRetval; + const XMLTextFrameContext_Impl* pXMLTextFrameContext_Impl = dynamic_cast< const XMLTextFrameContext_Impl* >(&rContext); + + if(pXMLTextFrameContext_Impl) + { + return pXMLTextFrameContext_Impl->GetHRef(); + } + + return aRetval; +} + sal_Bool XMLTextFrameContext::CreateIfNotThere() { sal_Bool bRet = sal_False; @@ -1339,6 +1376,7 @@ XMLTextFrameContext::XMLTextFrameContext( const Reference< XAttributeList > & xAttrList, TextContentAnchorType eATyp ) : SvXMLImportContext( rImport, nPrfx, rLName ) +, multiImageImportHelper() , m_xAttrList( new SvXMLAttributeList( xAttrList ) ) , m_pHyperlink( 0 ) // --> OD 2009-07-22 #i73249# @@ -1401,6 +1439,9 @@ XMLTextFrameContext::~XMLTextFrameContext() void XMLTextFrameContext::EndElement() { + /// solve if multiple image child contexts were imported + solveMultipleImages(); + SvXMLImportContext *pContext = &m_xImplContext; XMLTextFrameContext_Impl *pImpl = PTR_CAST( XMLTextFrameContext_Impl, pContext ); if( pImpl ) @@ -1505,6 +1546,10 @@ SvXMLImportContext *XMLTextFrameContext::CreateChildContext( { m_bSupportsReplacement = sal_True; } + else if(XML_TEXT_FRAME_GRAPHIC == nFrameType) + { + setSupportsMultipleContents(IsXMLToken(rLocalName, XML_IMAGE)); + } if( !pContext ) { @@ -1517,9 +1562,24 @@ SvXMLImportContext *XMLTextFrameContext::CreateChildContext( } m_xImplContext = pContext; + + if(getSupportsMultipleContents() && XML_TEXT_FRAME_GRAPHIC == nFrameType) + { + addContent(*m_xImplContext); + } } } } + else if(getSupportsMultipleContents() && XML_NAMESPACE_DRAW == p_nPrefix && IsXMLToken(rLocalName, XML_IMAGE)) + { + // read another image + pContext = new XMLTextFrameContext_Impl( + GetImport(), p_nPrefix, rLocalName, xAttrList, + m_eDefaultAnchorType, XML_TEXT_FRAME_GRAPHIC, m_xAttrList); + + m_xImplContext = pContext; + addContent(*m_xImplContext); + } else if( m_bSupportsReplacement && !m_xReplImplContext && XML_NAMESPACE_DRAW == p_nPrefix && IsXMLToken( rLocalName, XML_IMAGE ) ) diff --git a/xmloff/source/text/XMLTextFrameContext.hxx b/xmloff/source/text/XMLTextFrameContext.hxx index e8d660ced4a8..0cac2a59e23b 100644 --- a/xmloff/source/text/XMLTextFrameContext.hxx +++ b/xmloff/source/text/XMLTextFrameContext.hxx @@ -28,6 +28,7 @@ #include <com/sun/star/text/TextContentAnchorType.hpp> #endif #include <xmloff/xmlictxt.hxx> +#include <xmloff/xmlmultiimagehelper.hxx> namespace com { namespace sun { namespace star { namespace text { class XTextCursor; class XTextContent; } @@ -36,7 +37,7 @@ namespace com { namespace sun { namespace star { class SvXMLAttributeList; class XMLTextFrameContextHyperlink_Impl; -class XMLTextFrameContext : public SvXMLImportContext +class XMLTextFrameContext : public SvXMLImportContext, public multiImageImportHelper { ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > m_xAttrList; @@ -66,6 +67,11 @@ class XMLTextFrameContext : public SvXMLImportContext sal_Bool CreateIfNotThere( ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySet >& rPropSet ); +protected: + /// helper to get the created xShape instance, needs to be overloaded + virtual rtl::OUString getGraphicURLFromImportContext(const SvXMLImportContext& rContext) const; + virtual void removeGraphicFromImportContext(const SvXMLImportContext& rContext) const; + public: TYPEINFO(); diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index 290b5099ed3c..ecc672b257ee 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -1223,6 +1223,7 @@ XMLTextParagraphExport::XMLTextParagraphExport( sGraphicFilter(RTL_CONSTASCII_USTRINGPARAM("GraphicFilter")), sGraphicRotation(RTL_CONSTASCII_USTRINGPARAM("GraphicRotation")), sGraphicURL(RTL_CONSTASCII_USTRINGPARAM("GraphicURL")), + sReplacementGraphicURL(RTL_CONSTASCII_USTRINGPARAM("ReplacementGraphicURL")), sHeight(RTL_CONSTASCII_USTRINGPARAM("Height")), sHoriOrient(RTL_CONSTASCII_USTRINGPARAM("HoriOrient")), sHoriOrientPosition(RTL_CONSTASCII_USTRINGPARAM("HoriOrientPosition")), @@ -3018,9 +3019,33 @@ void XMLTextParagraphExport::_exportTextGraphic( sRet.makeStringAndClear() ); } + // original content + SvXMLElementExport aElem(GetExport(), XML_NAMESPACE_DRAW, XML_FRAME, sal_False, sal_True); - SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_DRAW, - XML_FRAME, sal_False, sal_True ); + // replacement graphic for backwards compatibility, but + // only for SVG currently + OUString sReplacementOrigURL; + rPropSet->getPropertyValue( sReplacementGraphicURL ) >>= sReplacementOrigURL; + + if(sReplacementOrigURL.getLength()) + { + const OUString sReplacementURL(GetExport().AddEmbeddedGraphicObject( sReplacementOrigURL )); + + // If there is no url, then then graphic is empty + if(sReplacementURL.getLength()) + { + GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sReplacementURL); + GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE); + GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED); + GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD); + + // xlink:href for replacement, only written for Svg content + SvXMLElementExport aElement(GetExport(), XML_NAMESPACE_DRAW, XML_IMAGE, sal_False, sal_True); + + // optional office:binary-data + GetExport().AddEmbeddedGraphicObjectAsBase64(sReplacementURL); + } + } // xlink:href OUString sOrigURL; |