diff options
author | Michael Brauer <mib@openoffice.org> | 2001-06-19 14:08:23 +0000 |
---|---|---|
committer | Michael Brauer <mib@openoffice.org> | 2001-06-19 14:08:23 +0000 |
commit | 10763f3a937772e924a9bb5198aa57921b3edaa5 (patch) | |
tree | a1a16a68d36ef1c96ff140983118cdf3bb5d913e /xmloff/source/text | |
parent | 41a51f5f23bddc4265293eb62eac4d40ab30e8f3 (diff) |
#87313#: embedded images as base64
Diffstat (limited to 'xmloff/source/text')
-rw-r--r-- | xmloff/source/text/XMLTextFrameContext.cxx | 119 | ||||
-rw-r--r-- | xmloff/source/text/XMLTextFrameContext.hxx | 11 | ||||
-rw-r--r-- | xmloff/source/text/txtparae.cxx | 15 |
3 files changed, 102 insertions, 43 deletions
diff --git a/xmloff/source/text/XMLTextFrameContext.cxx b/xmloff/source/text/XMLTextFrameContext.cxx index c2b231907579..49bd60949ebe 100644 --- a/xmloff/source/text/XMLTextFrameContext.cxx +++ b/xmloff/source/text/XMLTextFrameContext.cxx @@ -2,9 +2,9 @@ * * $RCSfile: XMLTextFrameContext.cxx,v $ * - * $Revision: 1.42 $ + * $Revision: 1.43 $ * - * last change: $Author: mib $ $Date: 2001-05-18 13:50:59 $ + * last change: $Author: mib $ $Date: 2001-06-19 15:01:30 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -96,6 +96,9 @@ #ifndef _XMLOFF_XMLIMP_HXX #include "xmlimp.hxx" #endif +#ifndef _XMLOFF_XMLTOKEN_HXX +#include "xmltoken.hxx" +#endif #ifndef _XMLOFF_XMLNMSPE_HXX #include "xmlnmspe.hxx" #endif @@ -114,6 +117,9 @@ #ifndef _XMLOFF_XMLEMBEDDEDOBJECTIMPORTCONTEXT_HXX #include "XMLEmbeddedObjectImportContext.hxx" #endif +#ifndef _XMLOFF_XMLBASE64IMPORTCONTEXT_HXX +#include "XMLBase64ImportContext.hxx" +#endif #ifndef _XMLOFF_PRSTYLEI_HXX_ #include "prstylei.hxx" #endif @@ -376,7 +382,7 @@ XMLTextFrameContourContext_Impl::~XMLTextFrameContourContext_Impl() TYPEINIT1( XMLTextFrameContext, SvXMLImportContext ); -void XMLTextFrameContext::Create( sal_Bool bLinked ) +void XMLTextFrameContext::Create( sal_Bool bHRefOrBase64 ) { UniReference < XMLTextImportHelper > xTxtImport = GetImport().GetTextImport(); @@ -385,7 +391,7 @@ void XMLTextFrameContext::Create( sal_Bool bLinked ) { case XML_TEXT_FRAME_OBJECT: case XML_TEXT_FRAME_OBJECT_OLE: - if( bLinked ) + if( bHRefOrBase64 ) { OUString sURL( GetImport().ResolveEmbeddedObjectURL( sHRef, OUString() ) ); @@ -562,13 +568,24 @@ void XMLTextFrameContext::Create( sal_Bool bLinked ) if( XML_TEXT_FRAME_GRAPHIC == nType ) { // URL + OSL_ENSURE( sHRef.getLength() > 0 || xBase64Stream.is(), + "neither URL nor base64 image data given" ); UniReference < XMLTextImportHelper > xTxtImport = GetImport().GetTextImport(); - sal_Bool bForceLoad = xTxtImport->IsInsertMode() || - xTxtImport->IsBlockMode() || - xTxtImport->IsStylesOnlyMode() || - xTxtImport->IsOrganizerMode(); - aAny <<= GetImport().ResolveGraphicObjectURL( sHRef, !bForceLoad ); + if( sHRef.getLength() ) + { + sal_Bool bForceLoad = xTxtImport->IsInsertMode() || + xTxtImport->IsBlockMode() || + xTxtImport->IsStylesOnlyMode() || + xTxtImport->IsOrganizerMode(); + sHRef = GetImport().ResolveGraphicObjectURL( sHRef, !bForceLoad ); + } + else if( xBase64Stream.is() ) + { + sHRef = GetImport().ResolveGraphicObjectURLFromBase64( xBase64Stream ); + xBase64Stream = 0; + } + aAny <<= sHRef; xPropSet->setPropertyValue( sGraphicURL, aAny ); // filter name @@ -655,7 +672,8 @@ XMLTextFrameContext::XMLTextFrameContext( bMinHeight = sal_False; bSyncWidth = sal_False; bSyncHeight = sal_False; - bCreateOLEStreamFailed = sal_False; + bCreateBase64StreamFailed = sal_False; + bOwnBase64Stream = sal_False; UniReference < XMLTextImportHelper > xTxtImport = GetImport().GetTextImport(); @@ -860,10 +878,12 @@ XMLTextFrameContext::~XMLTextFrameContext() void XMLTextFrameContext::EndElement() { - if( XML_TEXT_FRAME_OBJECT_OLE == nType && !xPropSet.is() && - xOLEStream.is() ) + if( ( XML_TEXT_FRAME_OBJECT_OLE == nType || + XML_TEXT_FRAME_GRAPHIC == nType ) + && !xPropSet.is() && xBase64Stream.is() ) { - xOLEStream->closeOutput(); + if( bOwnBase64Stream ) + xBase64Stream->closeOutput(); Create( sal_True ); } @@ -936,23 +956,47 @@ SvXMLImportContext *XMLTextFrameContext::CreateChildContext( rLocalName, xPropSet ); } } - else if( (XML_NAMESPACE_OFFICE == nPrefix) && - rLocalName.equalsAsciiL(sXML_events, sizeof(sXML_events)-1) ) + else if( (XML_NAMESPACE_OFFICE == nPrefix) ) { - // do we still have the frame object? - if (xPropSet.is()) + if( rLocalName.equalsAsciiL(sXML_events, sizeof(sXML_events)-1) ) + { + // do we still have the frame object? + if (xPropSet.is()) + { + // is it an event supplier? + Reference<XEventsSupplier> xEventsSupplier(xPropSet, UNO_QUERY); + if (xEventsSupplier.is()) + { + // OK, we have the events, so create the context + pContext = new XMLEventsImportContext(GetImport(), nPrefix, + rLocalName, xEventsSupplier); + } + // else: no events, no event import + } + // else: no object, no event import + } + else if( xmloff::token::IsXMLToken( rLocalName, + xmloff::token::XML_BINARY_DATA ) ) { - // is it an event supplier? - Reference<XEventsSupplier> xEventsSupplier(xPropSet, UNO_QUERY); - if (xEventsSupplier.is()) + if( !xPropSet.is() && !xBase64Stream.is() ) { - // OK, we have the events, so create the context - pContext = new XMLEventsImportContext(GetImport(), nPrefix, - rLocalName, xEventsSupplier); + switch( nType ) + { + case XML_TEXT_FRAME_GRAPHIC: + xBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64(); + break; + case XML_TEXT_FRAME_OBJECT_OLE: + sHRef = OUString( RTL_CONSTASCII_USTRINGPARAM( "#Obj12345678" ) ); + xBase64Stream = + GetImport().ResolveEmbeddedObjectURLFromBase64( sHRef ); + break; + } + if( xBase64Stream.is() ) + pContext = new XMLBase64ImportContext( GetImport(), nPrefix, + rLocalName, xAttrList, + xBase64Stream ); } - // else: no events, no event import } - // else: no object, no event import } else if( XML_TEXT_FRAME_OBJECT == nType && (XML_NAMESPACE_OFFICE == nPrefix && @@ -994,18 +1038,29 @@ SvXMLImportContext *XMLTextFrameContext::CreateChildContext( void XMLTextFrameContext::Characters( const OUString& rChars ) { - if( XML_TEXT_FRAME_OBJECT_OLE == nType && !xPropSet.is() ) + if( ( XML_TEXT_FRAME_OBJECT_OLE == nType || + XML_TEXT_FRAME_GRAPHIC == nType) && + !xPropSet.is() ) { OUString sTrimmedChars( rChars. trim() ); if( sTrimmedChars.getLength() ) { - if( !xOLEStream.is() && !bCreateOLEStreamFailed ) + if( !xBase64Stream.is() && !bCreateBase64StreamFailed ) { - sHRef = OUString( RTL_CONSTASCII_USTRINGPARAM( "#Obj12345678" ) ); - xOLEStream = - GetImport().ResolveEmbeddedObjectURLFromBase64( sHRef ); + if( XML_TEXT_FRAME_GRAPHIC == nType ) + { + xBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64(); + } + else + { + sHRef = OUString( RTL_CONSTASCII_USTRINGPARAM( "#Obj12345678" ) ); + xBase64Stream = + GetImport().ResolveEmbeddedObjectURLFromBase64( sHRef ); + } + if( xBase64Stream.is() ) + bOwnBase64Stream = sal_True; } - if( xOLEStream.is() ) + if( bOwnBase64Stream && xBase64Stream.is() ) { OUString sChars; if( sBase64CharsLeft ) @@ -1022,7 +1077,7 @@ void XMLTextFrameContext::Characters( const OUString& rChars ) sal_Int32 nCharsDecoded = GetImport().GetMM100UnitConverter(). decodeBase64SomeChars( aBuffer, sChars ); - xOLEStream->writeBytes( aBuffer ); + xBase64Stream->writeBytes( aBuffer ); if( nCharsDecoded != sChars.getLength() ) sBase64CharsLeft = sChars.copy( nCharsDecoded ); } diff --git a/xmloff/source/text/XMLTextFrameContext.hxx b/xmloff/source/text/XMLTextFrameContext.hxx index 2a8659f76b82..98df1cac4144 100644 --- a/xmloff/source/text/XMLTextFrameContext.hxx +++ b/xmloff/source/text/XMLTextFrameContext.hxx @@ -2,9 +2,9 @@ * * $RCSfile: XMLTextFrameContext.hxx,v $ * - * $Revision: 1.12 $ + * $Revision: 1.13 $ * - * last change: $Author: mib $ $Date: 2001-05-18 13:54:59 $ + * last change: $Author: mib $ $Date: 2001-06-19 15:01:30 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -112,7 +112,7 @@ class XMLTextFrameContext : public SvXMLImportContext ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySet > xPropSet; ::com::sun::star::uno::Reference < - ::com::sun::star::io::XOutputStream > xOLEStream; + ::com::sun::star::io::XOutputStream > xBase64Stream; const ::rtl::OUString sWidth; const ::rtl::OUString sRelativeWidth; @@ -168,9 +168,10 @@ class XMLTextFrameContext : public SvXMLImportContext sal_Bool bMinHeight : 1; sal_Bool bSyncWidth : 1; sal_Bool bSyncHeight : 1; - sal_Bool bCreateOLEStreamFailed : 1; + sal_Bool bCreateBase64StreamFailed : 1; + sal_Bool bOwnBase64Stream : 1; - void Create( sal_Bool bLinked ); + void Create( sal_Bool bHRefOrBase64 ); public: diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index 886e8dd82b2a..9dea9b3d1397 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -2,9 +2,9 @@ * * $RCSfile: txtparae.cxx,v $ * - * $Revision: 1.82 $ + * $Revision: 1.83 $ * - * last change: $Author: dvo $ $Date: 2001-06-07 13:15:50 $ + * last change: $Author: mib $ $Date: 2001-06-19 15:01:30 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -2118,13 +2118,13 @@ void XMLTextParagraphExport::_exportTextGraphic( addTextFrameAttributes( rPropSet, sal_False ); // xlink:href - OUString sURL; + OUString sOrigURL; aAny = rPropSet->getPropertyValue( sGraphicURL ); - aAny >>= sURL; - sURL = GetExport().AddEmbeddedGraphicObject( sURL ); + aAny >>= sOrigURL; + OUString sURL = GetExport().AddEmbeddedGraphicObject( sOrigURL ); setTextEmbeddedGraphicURL( rPropSet, sURL ); - // If there still is no url, then teh graphic is empty + // If there still is no url, then then graphic is empty if( sURL.getLength() ) { GetExport().AddAttribute(XML_NAMESPACE_XLINK, sXML_href, sURL ); @@ -2162,6 +2162,9 @@ void XMLTextParagraphExport::_exportTextGraphic( SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_DRAW, sXML_image, sal_False, sal_True ); + // optional office:binary-data + GetExport().AddEmbeddedGraphicObjectAsBase64( sOrigURL ); + // script:events Reference<XEventsSupplier> xEventsSupp( rPropSet, UNO_QUERY ); GetExport().GetEventExport().Export(xEventsSupp); |