hwpfilter/source/hcode.cxx | 58 +++++++---------------------------------- hwpfilter/source/hcode.h | 6 +++- hwpfilter/source/hwpreader.cxx | 12 ++------ 3 files changed, 20 insertions(+), 56 deletions(-)
New commits: commit 176a9dfcce7c10d1c5fd3e091f10a1d57d309b24 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Fri Mar 4 09:29:04 2022 +0300 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Fri Mar 4 08:23:41 2022 +0100 Use comphelper::Base64 in hwpfilter Change-Id: Id5c0a3d33ccda517473c8cbf96cb6e7b86ade57d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130945 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/hwpfilter/source/hcode.cxx b/hwpfilter/source/hcode.cxx index e901fbbb3a58..c8c31a14085d 100644 --- a/hwpfilter/source/hcode.cxx +++ b/hwpfilter/source/hcode.cxx @@ -23,10 +23,17 @@ * Hanja johap code => ks code => unicode * Special johap code => ks code => unicode */ + +#include <sal/config.h> + #include "precompile.h" +#include <comphelper/base64.hxx> +#include <comphelper/sequence.hxx> #include <basegfx/numeric/ftools.hxx> +#include <rtl/strbuf.hxx> #include <sal/types.h> #include <sal/macros.h> + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -1385,54 +1392,11 @@ char *hcolor2str(uchar color, uchar shade, char *buf, bool bIsChar) } #endif -char* base64_encode_string( const uchar *buf, unsigned int len ) +OUString base64_encode_string( const uchar *buf, unsigned int len ) { - char basis_64[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - char * out; - int inPos = 0; - int outPos = 0; - int c1, c2; - unsigned int i; - - out=static_cast<char *>(malloc( (len*4/3)+8 )); - -/* Get three characters at a time and encode them. */ - for (i=0; i < len/3; ++i) - { - c1 = buf[inPos++] & 0xFF; - c2 = buf[inPos++] & 0xFF; - int c3 = buf[inPos++] & 0xFF; - out[outPos++] = basis_64[(c1 & 0xFC) >> 2]; - out[outPos++] = basis_64[((c1 & 0x03) << 4) | ((c2 & 0xF0) >> 4)]; - out[outPos++] = basis_64[((c2 & 0x0F) << 2) | ((c3 & 0xC0) >> 6)]; - out[outPos++] = basis_64[c3 & 0x3F]; - } - -/* Encode the remaining one or two characters. */ - - switch (len % 3) - { - case 0: - break; - case 1: - c1 = buf[inPos] & 0xFF; - out[outPos++] = basis_64[(c1 & 0xFC) >> 2]; - out[outPos++] = basis_64[((c1 & 0x03) << 4)]; - out[outPos++] = '='; - out[outPos++] = '='; - break; - case 2: - c1 = buf[inPos++] & 0xFF; - c2 = buf[inPos] & 0xFF; - out[outPos++] = basis_64[(c1 & 0xFC) >> 2]; - out[outPos++] = basis_64[((c1 & 0x03) << 4) | ((c2 & 0xF0) >> 4)]; - out[outPos++] = basis_64[((c2 & 0x0F) << 2)]; - out[outPos++] = '='; - break; - } - out[outPos] = 0; - return out; + OStringBuffer aBuf; + comphelper::Base64::encode(aBuf, comphelper::arrayToSequence<sal_Int8>(buf, len)); + return OUString::createFromAscii(aBuf); } double calcAngle(int x1, int y1, int x2, int y2) diff --git a/hwpfilter/source/hcode.h b/hwpfilter/source/hcode.h index 3fb2da528ef7..e560911b74c6 100644 --- a/hwpfilter/source/hcode.h +++ b/hwpfilter/source/hcode.h @@ -19,6 +19,10 @@ #pragma once +#include <sal/config.h> + +#include <rtl/ustring.hxx> + #include "hwplib.h" /** @@ -66,7 +70,7 @@ DLLEXPORT char* Int2Str(int value, const char *format, char *buf); */ DLLEXPORT char *hcolor2str(uchar color, uchar shade, char *buf, bool bIsChar = false); -DLLEXPORT char *base64_encode_string( const uchar *buf, unsigned int len ); +DLLEXPORT OUString base64_encode_string( const uchar *buf, unsigned int len ); DLLEXPORT double calcAngle(int x1, int y1, int x2, int y2); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx index a8272d82746e..205edf757c12 100644 --- a/hwpfilter/source/hwpreader.cxx +++ b/hwpfilter/source/hwpreader.cxx @@ -542,8 +542,7 @@ void HwpReader::makeDrawMiscStyle( HWPDrawingObject *hdo ) if (emp) { rstartEl("office:binary-data", mxList); - std::shared_ptr<char> pStr(base64_encode_string(emp->data.get(), emp->size), Free<char>()); - rchars(ascii(pStr.get())); + rchars(base64_encode_string(emp->data.get(), emp->size)); rendEl("office:binary-data"); } rendEl( "draw:fill-image"); @@ -1723,8 +1722,7 @@ void HwpReader::makePageStyle() if( hwpinfo.back_info.type == 2 ){ rstartEl("office:binary-data", mxList); mxList->clear(); - std::shared_ptr<char> pStr(base64_encode_string(reinterpret_cast<unsigned char *>(hwpinfo.back_info.data.data()), hwpinfo.back_info.size ), Free<char>()); - rchars(ascii(pStr.get())); + rchars(base64_encode_string(reinterpret_cast<unsigned char*>(hwpinfo.back_info.data.data()), hwpinfo.back_info.size)); rendEl("office:binary-data"); } rendEl("style:background-image"); @@ -3876,8 +3874,7 @@ void HwpReader::makePicture(Picture * hbox) EmPicture *emp = hwpfile.GetEmPicture(hbox); if( emp ) { - std::shared_ptr<char> pStr(base64_encode_string( emp->data.get(), emp->size ), Free<char>()); - rchars(ascii(pStr.get())); + rchars(base64_encode_string(emp->data.get(), emp->size)); } } else{ @@ -3900,8 +3897,7 @@ void HwpReader::makePicture(Picture * hbox) rchars(""); } else{ - std::shared_ptr<char> pStr(base64_encode_string( reinterpret_cast<uchar *>(pObj), strlen(reinterpret_cast<char *>(pObj))), Free<char>()); - rchars(ascii(pStr.get())); + rchars(base64_encode_string(reinterpret_cast<uchar*>(pObj), strlen(reinterpret_cast<char*>(pObj)))); pObj->Release(); srcsto->Release(); }