Hi,
SVG export filter has own Base64 encoder in FastString class.
But we have several more generic Base64 encoders in the code tree. e.g.
* Converter::encodeBase64
http://opengrok.go-oo.org/xref/libs-gui/sax/source/tools/converter.cxx#encodeBase64
* SvXMLUnitConverter::encodeBase64
http://opengrok.go-oo.org/xref/libs-core/xmloff/source/core/xmluconv.cxx#encodeBase64
* Base64Codec::encodeBase64
http://opengrok.go-oo.org/xref/filters/filter/source/placeware/Base64Codec.cxx#encodeBase64
* Base64Codec::encodeBase64
http://opengrok.go-oo.org/xref/components/package/source/manifest/Base64Codec.cxx#133
We can replace FastString's encoder by an another.
The patche uses SvXMLUnitConverter's because SVG Import filter also
uses SvXMLUnitConverter::decodeBase64.
The patch is under the LGPLv3+ / MPL.
Cheers,
--
KUROSAWA Takeshi <taken.spc@gmail.com>
From e30307dd55c5e8472943daa0d34b7f3d3e931dda Mon Sep 17 00:00:00 2001
From: Takeshi Kurosawa <taken.spc@gmail.com>
Date: Wed, 2 Feb 2011 12:39:36 +0900
Subject: [PATCH] Use SvXMLUnitConverter's base64 encoder
SVGActionWriter uses FastString class to encode an image to a base64 string.
But there are several more generic encoders. We can use one of them.
---
filter/source/svg/svgwriter.cxx | 168 +++------------------------------------
filter/source/svg/svgwriter.hxx | 4 +-
2 files changed, 14 insertions(+), 158 deletions(-)
diff --git a/filter/source/svg/svgwriter.cxx b/filter/source/svg/svgwriter.cxx
index 7765ea5..b33e84a 100644
--- a/filter/source/svg/svgwriter.cxx
+++ b/filter/source/svg/svgwriter.cxx
@@ -68,19 +68,6 @@ static const char aXMLAttrHeight[] = "height";
static const char aXMLAttrPoints[] = "points";
static const char aXMLAttrXLinkHRef[] = "xlink:href";
-static const sal_Unicode pBase64[] =
-{
- //0 1 2 3 4 5 6 7
- 'A','B','C','D','E','F','G','H', // 0
- 'I','J','K','L','M','N','O','P', // 1
- 'Q','R','S','T','U','V','W','X', // 2
- 'Y','Z','a','b','c','d','e','f', // 3
- 'g','h','i','j','k','l','m','n', // 4
- 'o','p','q','r','s','t','u','v', // 5
- 'w','x','y','z','0','1','2','3', // 6
- '4','5','6','7','8','9','+','/' // 7
-};
-
// --------------
// - FastString -
// --------------
@@ -98,64 +85,6 @@ FastString::FastString( sal_uInt32 nInitLen, sal_uInt32 nIncrement ) :
// -----------------------------------------------------------------------------
-FastString::FastString( sal_Char* pBufferForBase64Encoding, sal_uInt32 nBufLen ) :
- mnBufInc( 2048 ),
- mnPartPos( 0 )
-{
- DBG_ASSERT( pBufferForBase64Encoding && nBufLen, "invalid arguments" );
-
- const sal_uInt32 nQuadCount = nBufLen / 3;
- const sal_uInt32 nRest = nBufLen % 3;
-
- if( nQuadCount || nRest )
- {
- mnBufLen = mnCurLen = ( ( nQuadCount + ( nRest ? 1 : 0 ) ) << 2 );
- mpBuffer = new sal_Unicode[ mnBufLen * sizeof( sal_Unicode ) ];
-
- sal_Char* pTmpSrc = pBufferForBase64Encoding;
- sal_Unicode* pTmpDst = mpBuffer;
-
- for( sal_uInt32 i = 0; i < nQuadCount; i++ )
- {
- const sal_Int32 nA = *pTmpSrc++;
- const sal_Int32 nB = *pTmpSrc++;
- const sal_Int32 nC = *pTmpSrc++;
-
- *pTmpDst++ = pBase64[ ( nA >> 2 ) & 0x3f ];
- *pTmpDst++ = pBase64[ ( ( nA << 4 ) & 0x30 ) + ( ( nB >> 4 ) & 0xf ) ];
- *pTmpDst++ = pBase64[ ( ( nB << 2 ) & 0x3c ) + ( ( nC >> 6 ) & 0x3 ) ];
- *pTmpDst++ = pBase64[ nC & 0x3f ];
- }
-
- if( 1 == nRest )
- {
- const sal_Int32 nA = *pTmpSrc;
-
- *pTmpDst++ = pBase64[ ( nA >> 2 ) & 0x3f ];
- *pTmpDst++ = pBase64[ ( nA << 4 ) & 0x30 ];
- *pTmpDst++ = '=';
- *pTmpDst = '=';
- }
- else if( 2 == nRest )
- {
- const sal_Int32 nA = *pTmpSrc++;
- const sal_Int32 nB = *pTmpSrc;
-
- *pTmpDst++ = pBase64[ ( nA >> 2 ) & 0x3f ];
- *pTmpDst++ = pBase64[ ( ( nA << 4 ) & 0x30 ) + ( ( nB >> 4 ) & 0xf ) ];
- *pTmpDst++ = pBase64[ ( nB << 2 ) & 0x3c ];
- *pTmpDst = '=';
- }
- }
- else
- {
- mpBuffer = new sal_Unicode[ ( mnBufLen = 1 ) * sizeof( sal_Unicode ) ];
- mnCurLen = 0;
- }
-}
-
-// -----------------------------------------------------------------------------
-
FastString::~FastString()
{
delete[] mpBuffer;
@@ -198,39 +127,6 @@ const NMSP_RTL::OUString& FastString::GetString() const
return maString;
}
-// -----------------------------------------------------------------------------
-
-sal_Bool FastString::GetFirstPartString( const sal_uInt32 nPartLen, NMSP_RTL::OUString&
rPartString )
-{
- const sal_uInt32 nLength = Min( mnCurLen, nPartLen );
-
- mnPartPos = 0;
-
- if( nLength )
- {
- rPartString = NMSP_RTL::OUString( mpBuffer, nLength );
- mnPartPos = nLength;
- }
-
- return( rPartString.getLength() > 0 );
-}
-
-// -----------------------------------------------------------------------------
-
-sal_Bool FastString::GetNextPartString( const sal_uInt32 nPartLen, NMSP_RTL::OUString& rPartString
)
-{
- if( mnPartPos < mnCurLen )
- {
- const sal_uInt32 nLength = Min( mnCurLen - mnPartPos, nPartLen );
- rPartString = NMSP_RTL::OUString( mpBuffer + mnPartPos, nLength );
- mnPartPos += nLength;
- }
- else
- rPartString = NMSP_RTL::OUString();
-
- return( rPartString.getLength() > 0 );
-}
-
// ----------------------
// - SVGAttributeWriter -
// ----------------------
@@ -1106,59 +1002,21 @@ void SVGActionWriter::ImplWriteBmp( const BitmapEx& rBmpEx,
if( GraphicConverter::Export( aOStm, rBmpEx, CVT_PNG ) == ERRCODE_NONE )
{
- const Point
aPt( ImplMap( rPt ) );
- const Size
aSz( ImplMap( rSz ) );
- FastString
aImageData( (sal_Char*) aOStm.GetData(), aOStm.Tell() );
- REF( NMSP_SAX::XExtendedDocumentHandler ) xExtDocHandler(
mrExport.GetDocHandler(), NMSP_UNO::UNO_QUERY );
+ const Point aPt( ImplMap( rPt ) );
+ const Size aSz( ImplMap( rSz ) );
+ Sequence< sal_Int8 > aSeq( (sal_Int8*) aOStm.GetData(), aOStm.Tell() );
+ NMSP_RTL::OUStringBuffer aBuffer;
+ aBuffer.appendAscii( "data:image/png;base64," );
+ SvXMLUnitConverter::encodeBase64( aBuffer, aSeq );
+
+ mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrX, GetValueString( aPt.X() ) );
+ mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrY, GetValueString( aPt.Y() ) );
+ mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrWidth, GetValueString(
aSz.Width() ) );
+ mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrHeight, GetValueString(
aSz.Height() ) );
+ mrExport.AddAttribute( XML_NAMESPACE_NONE, aXMLAttrXLinkHRef,
aBuffer.makeStringAndClear() );
- if( xExtDocHandler.is() )
{
- static const sal_uInt32 nPartLen = 64;
- const NMSP_RTL::OUString aSpace( ' ' );
- const NMSP_RTL::OUString aLineFeed( NMSP_RTL::OUString::valueOf(
(sal_Unicode) 0x0a ) );
- NMSP_RTL::OUString aString;
- NMSP_RTL::OUString aImageString;
-
- aString = aLineFeed;
- aString += B2UCONST( "<" );
- aString += NMSP_RTL::OUString::createFromAscii( aXMLElemImage );
- aString += aSpace;
-
- aString += NMSP_RTL::OUString::createFromAscii( aXMLAttrX );
- aString += B2UCONST( "=\"" );
- aString += GetValueString( aPt.X() );
- aString += B2UCONST( "\" " );
-
- aString += NMSP_RTL::OUString::createFromAscii( aXMLAttrY );
- aString += B2UCONST( "=\"" );
- aString += GetValueString( aPt.Y() );
- aString += B2UCONST( "\" " );
-
- aString += NMSP_RTL::OUString::createFromAscii( aXMLAttrWidth );
- aString += B2UCONST( "=\"" );
- aString += GetValueString( aSz.Width() );
- aString += B2UCONST( "\" " );
-
- aString += NMSP_RTL::OUString::createFromAscii( aXMLAttrHeight );
- aString += B2UCONST( "=\"" );
- aString += GetValueString( aSz.Height() );
- aString += B2UCONST( "\" " );
-
- aString += NMSP_RTL::OUString::createFromAscii( aXMLAttrXLinkHRef );
- aString += B2UCONST( "=\"data:image/png;base64," );
-
- if( aImageData.GetFirstPartString( nPartLen, aImageString ) )
- {
- xExtDocHandler->unknown( aString += aImageString );
-
- while( aImageData.GetNextPartString( nPartLen, aImageString ) )
- {
- xExtDocHandler->unknown( aLineFeed );
- xExtDocHandler->unknown( aImageString );
- }
- }
-
- xExtDocHandler->unknown( B2UCONST( "\"/>" ) );
+ SvXMLElementExport aElem( mrExport, XML_NAMESPACE_NONE, aXMLElemImage, TRUE,
TRUE );
}
}
}
diff --git a/filter/source/svg/svgwriter.hxx b/filter/source/svg/svgwriter.hxx
index e1467c3..dfdc559 100644
--- a/filter/source/svg/svgwriter.hxx
+++ b/filter/source/svg/svgwriter.hxx
@@ -44,6 +44,7 @@
#include <vcl/cvtgrf.hxx>
#include <xmloff/xmlexp.hxx>
#include <xmloff/nmspmap.hxx>
+#include <xmloff/xmluconv.hxx>
#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/uno/RuntimeException.hpp>
@@ -102,14 +103,11 @@ private:
public:
FastString( sal_uInt32 nInitLen = 2048, sal_uInt32 nIncrement =
2048 );
- FastString( sal_Char* pBufferForBase64Encoding, sal_uInt32 nBufLen
);
~FastString();
FastString& operator+=( const ::rtl::OUString& rStr );
const ::rtl::OUString& GetString() const;
- sal_Bool GetFirstPartString( const sal_uInt32 nPartLen,
::rtl::OUString& rPartString );
- sal_Bool GetNextPartString( const sal_uInt32 nPartLen,
::rtl::OUString& rPartString );
sal_uInt32 GetLength() const { return mnCurLen; }
void Clear() { mnCurLen = 0, maString =
::rtl::OUString(); }
--
1.7.1
Context
- [Libreoffice] [PATCH] Use generic base64 encoder · KUROSAWA, Takeshi
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.