summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/tools/urlobj.hxx5
-rw-r--r--sw/source/filter/html/htmlgrin.cxx20
-rw-r--r--tools/Library_tl.mk1
-rw-r--r--tools/source/fsys/urlobj.cxx43
4 files changed, 60 insertions, 9 deletions
diff --git a/include/tools/urlobj.hxx b/include/tools/urlobj.hxx
index ace1d76ba562..cd10405bf4b0 100644
--- a/include/tools/urlobj.hxx
+++ b/include/tools/urlobj.hxx
@@ -26,6 +26,8 @@
#include <rtl/textenc.h>
#include <sal/types.h>
+class SvMemoryStream;
+
namespace com { namespace sun { namespace star { namespace util {
class XStringWidth;
} } } }
@@ -851,6 +853,9 @@ public:
OUString getFSysPath(FSysStyle eStyle, sal_Unicode * pDelimiter = 0)
const;
+ // Data URLs:
+ SvMemoryStream* getData();
+
// POP3 and URLs:
OUString GetMsgId(DecodeMechanism eMechanism = DECODE_TO_IURI,
diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx
index 30d9dd18164b..18cdf936e5cf 100644
--- a/sw/source/filter/html/htmlgrin.cxx
+++ b/sw/source/filter/html/htmlgrin.cxx
@@ -67,8 +67,8 @@
#include <numrule.hxx>
#include <boost/shared_ptr.hpp>
-#include <sax/tools/converter.hxx>
#include <vcl/graphicfilter.hxx>
+#include <tools/urlobj.hxx>
using namespace ::com::sun::star;
@@ -695,16 +695,18 @@ IMAGE_SETEVENT:
aFrmSet.Put( aFrmSize );
Graphic aEmptyGrf;
- if( sGrfNm.startsWith("data:") )
+ INetURLObject aGraphicURL( sGrfNm );
+ if( aGraphicURL.GetProtocol() == INET_PROT_DATA )
{
- // use embedded base64 encoded data
- ::com::sun::star::uno::Sequence< sal_Int8 > aPass;
- OUString sBase64Data = sGrfNm.replaceAt(0,22,"");
- ::sax::Converter::decodeBase64(aPass, sBase64Data);
- if( aPass.hasElements() )
+ SvMemoryStream* aStream = aGraphicURL.getData();
+ if( aStream )
{
- SvMemoryStream aStream(aPass.getArray(), aPass.getLength(), STREAM_READ);
- GraphicFilter::GetGraphicFilter().ImportGraphic( aEmptyGrf, OUString(), aStream );
+ GraphicFilter::GetGraphicFilter().ImportGraphic( aEmptyGrf, OUString(), *aStream );
+ free( aStream );
+ }
+ else
+ {
+ aEmptyGrf.SetDefaultType();
}
}
else
diff --git a/tools/Library_tl.mk b/tools/Library_tl.mk
index c6ee6cbe8f48..856471bbf7ba 100644
--- a/tools/Library_tl.mk
+++ b/tools/Library_tl.mk
@@ -38,6 +38,7 @@ $(eval $(call gb_Library_use_libraries,tl,\
i18nlangtag \
cppu \
sal \
+ sax \
$(gb_UWINAPI) \
))
diff --git a/tools/source/fsys/urlobj.cxx b/tools/source/fsys/urlobj.cxx
index 69b84a922c0a..08583fb9e4cc 100644
--- a/tools/source/fsys/urlobj.cxx
+++ b/tools/source/fsys/urlobj.cxx
@@ -20,6 +20,7 @@
#include <tools/urlobj.hxx>
#include <tools/debug.hxx>
#include <tools/inetmime.hxx>
+#include <tools/stream.hxx>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/util/XStringWidth.hpp>
#include <osl/diagnose.h>
@@ -37,6 +38,10 @@
#include <string.h>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <sax/tools/converter.hxx>
+#include <rtl/uri.hxx>
+
namespace unnamed_tools_urlobj {} using namespace unnamed_tools_urlobj;
// unnamed namespaces don't work well yet...
@@ -583,6 +588,44 @@ void INetURLObject::setInvalid()
m_aFragment.clear();
}
+SvMemoryStream* INetURLObject::getData()
+{
+ if( GetProtocol() != INET_PROT_DATA )
+ {
+ return NULL;
+ }
+
+ OUString sURLPath = GetURLPath( DECODE_WITH_CHARSET, RTL_TEXTENCODING_ISO_8859_1 );
+ OUString sType, sSubType;
+ OUString sBase64Enc(";base64,");
+
+ INetContentTypeParameterList params;
+ sal_Unicode const * pSkippedMediatype = INetMIME::scanContentType( sURLPath.getStr(), sURLPath.getStr() + sURLPath.getLength(), &sType, &sSubType, &params );
+ sal_Int32 nCharactersSkipped = pSkippedMediatype-sURLPath.getStr();
+ sal_Int32 nCommaIndex = sURLPath.indexOf( ",", nCharactersSkipped );
+ sal_Int32 nBase64Index = sURLPath.indexOf( sBase64Enc, nCharactersSkipped );
+ SvMemoryStream* aStream=NULL;
+
+ if( nBase64Index >= 0 && nBase64Index < nCommaIndex )
+ {
+ // base64 decoding
+ OUString sBase64Data = sURLPath.copy( nBase64Index + sBase64Enc.getLength() );
+ css::uno::Sequence< sal_Int8 > aDecodedData;
+ ::sax::Converter::decodeBase64( aDecodedData, sBase64Data );
+ if( aDecodedData.hasElements() )
+ {
+ aStream = new SvMemoryStream( aDecodedData.getArray(), aDecodedData.getLength(), STREAM_READ );
+ }
+ }
+ else
+ {
+ // URL decoding
+ OUString sURLEncodedData = sURLPath.copy( nCommaIndex+1 );
+ aStream = new SvMemoryStream( const_cast< sal_Char * >(OUStringToOString(sURLEncodedData, RTL_TEXTENCODING_UTF8).getStr()), sURLEncodedData.getLength(), STREAM_READ);
+ }
+ return aStream;
+}
+
namespace unnamed_tools_urlobj {
INetURLObject::FSysStyle guessFSysStyleByCounting(sal_Unicode const * pBegin,