Correct coding to Utf16

This commit is contained in:
K0R0L
2018-12-11 18:08:25 +03:00
parent 1022754391
commit 82dca18ebc
3 changed files with 30 additions and 3 deletions

View File

@ -283,7 +283,7 @@ namespace NSStringExt
return pUnicodes;
}
unsigned short* CConverter::GetUtf16FromUnicode(const std::wstring& wsUnicodeText, unsigned int& unLen)
unsigned short* CConverter::GetUtf16FromUnicode(const std::wstring& wsUnicodeText, unsigned int& unLen, const bool& bIsLE)
{
unsigned int unTextLen = (unsigned int)wsUnicodeText.size();
if (unTextLen <= 0)
@ -338,6 +338,18 @@ namespace NSStringExt
}
}
if (!bIsLE)
{
unsigned char* pDataReverce = (unsigned char*)pUtf16;
unsigned int unLen2 = unLen << 1;
for (unsigned int i = 0; i < unLen2; i += 2)
{
unsigned char tmp = pDataReverce[i];
pDataReverce[i] = pDataReverce[i + 1];
pDataReverce[i + 1] = tmp;
}
}
return pUtf16;
}
}

View File

@ -131,7 +131,7 @@ namespace NSStringExt
static std::wstring GetUnicodeFromUTF16(const unsigned short* pData, long lCount);
static std::wstring GetUnicodeFromUTF32(const unsigned int* pData, long lCount);
static unsigned int* GetUtf32FromUnicode(const std::wstring& wsUnicodeText, unsigned int& unLen);
static unsigned short* GetUtf16FromUnicode(const std::wstring& wsUnicodeText, unsigned int& unLen);
static unsigned short* GetUtf16FromUnicode(const std::wstring& wsUnicodeText, unsigned int& unLen, const bool& isLE = true);
};
}

View File

@ -39,6 +39,7 @@
#include "../../OfficeUtils/src/OfficeUtils.h"
#include "../../UnicodeConverter/UnicodeConverter.h"
#include "../../DesktopEditor/common/String.h"
#define DEFLATE_BUF_SIZ ((int)(STREAM_BUF_SIZ * 1.1) + 13)
@ -291,13 +292,15 @@ namespace PdfWriter
unsigned int nIndex = 0;
const BYTE* sTxt = sText;
BYTE* sTxt = const_cast<BYTE*>(sText);
unsigned long nRet = 0;
sBuf[nIndex++] = '(';
unsigned short* pUtf16Data = NULL;
if (isUTF16)
{
/*
std::string sUtf8((char*)sText, unLen);
std::wstring sUnicode = UTF8_TO_U(sUtf8);
NSUnicodeConverter::CUnicodeConverter oConverter;
@ -305,6 +308,15 @@ namespace PdfWriter
unLen = (unsigned int)sUtf16BE.length();
sTxt = (BYTE*)sUtf16BE.c_str();
*/
std::string sUtf8((char*)sText, unLen);
std::wstring sUnicode = UTF8_TO_U(sUtf8);
unsigned int unLenUtf16 = 0;
pUtf16Data = NSStringExt::CConverter::GetUtf16FromUnicode(sUnicode, unLenUtf16, false);
sTxt = (BYTE*)pUtf16Data;
unLen = unLenUtf16 << 1;
sBuf[nIndex++] = 0xFE;
sBuf[nIndex++] = 0xFF;
@ -339,6 +351,9 @@ namespace PdfWriter
}
sBuf[nIndex++] = ')';
if (pUtf16Data)
delete []pUtf16Data;
Write((BYTE*)sBuf, nIndex);
}
void CStream::WriteBinary(const BYTE* pData, unsigned int unLen, CEncrypt* pEncrypt)