diff --git a/DesktopEditor/common/File.cpp b/DesktopEditor/common/File.cpp index 4ff1a98310..6120962763 100644 --- a/DesktopEditor/common/File.cpp +++ b/DesktopEditor/common/File.cpp @@ -886,6 +886,22 @@ namespace NSFile } return sizeUtf16; } + static long GetUtf16SizeFromUnicode(const wchar_t* pUnicodes, LONG lCount, bool bIsBOM = false) + { + if (sizeof(wchar_t) == 4) + { + return GetUtf16SizeFromUnicode_4bytes(pUnicodes, lCount, bIsBOM); + } + else + { + long sizeUtf16 = 2 * lCount; + if (bIsBOM) + { + sizeUtf16 += 3; + } + return sizeUtf16; + } + } std::wstring CUtf8Converter::GetWStringFromUTF16(const CStringUtf16& data) { diff --git a/DesktopEditor/common/File.h b/DesktopEditor/common/File.h index bedd72d345..dfe3ac4170 100644 --- a/DesktopEditor/common/File.h +++ b/DesktopEditor/common/File.h @@ -126,6 +126,7 @@ namespace NSFile static void GetUtf16StringFromUnicode_4bytes(const wchar_t* pUnicodes, LONG lCount, BYTE*& pData, int& lOutputCount, bool bIsBOM = false); static void GetUtf16StringFromUnicode_4bytes2(const wchar_t* pUnicodes, LONG lCount, CStringUtf16& data); static long GetUtf16SizeFromUnicode_4bytes(const wchar_t* pUnicodes, LONG lCount, bool bIsBOM = false); + static long GetUtf16SizeFromUnicode(const wchar_t* pUnicodes, LONG lCount, bool bIsBOM = false); static std::wstring GetWStringFromUTF16(const CStringUtf16& data); static std::wstring GetWStringFromUTF16(const unsigned short* pUtf16, LONG lCount); diff --git a/OOXML/XlsxFormat/SharedStrings/Si.cpp b/OOXML/XlsxFormat/SharedStrings/Si.cpp index 16ee76e6d2..d41c636df4 100644 --- a/OOXML/XlsxFormat/SharedStrings/Si.cpp +++ b/OOXML/XlsxFormat/SharedStrings/Si.cpp @@ -290,7 +290,7 @@ namespace OOX if(OOX::et_x_t == we->getType()) { OOX::Spreadsheet::CText* pText = static_cast(we); - nLen += 4 + 2 * pText->m_sText.length(); + nLen += 4 + NSFile::CUtf8Converter::GetUtf16SizeFromUnicode(pText->m_sText.c_str(), pText->m_sText.length()); } else { @@ -301,7 +301,7 @@ namespace OOX else if(OOX::et_x_t == we->getType()) { OOX::Spreadsheet::CText* pText = static_cast(we); - nLen += 4 + 2 * pText->m_sText.length(); + nLen += 4 + NSFile::CUtf8Converter::GetUtf16SizeFromUnicode(pText->m_sText.c_str(), pText->m_sText.length()); } } return nLen; diff --git a/OOXML/XlsxFormat/SharedStrings/Text.cpp b/OOXML/XlsxFormat/SharedStrings/Text.cpp index d48ce8b7d8..8e892f7e7c 100644 --- a/OOXML/XlsxFormat/SharedStrings/Text.cpp +++ b/OOXML/XlsxFormat/SharedStrings/Text.cpp @@ -66,14 +66,7 @@ namespace OOX } LONG CStringXLSB::getUTF16Size() { - if (sizeof(wchar_t) == 4) - { - return NSFile::CUtf8Converter::GetUtf16SizeFromUnicode_4bytes(m_sBuffer, m_nLen); - } - else - { - return 2 * m_nLen; - } + return NSFile::CUtf8Converter::GetUtf16SizeFromUnicode(m_sBuffer, m_nLen); } void CStringXLSB::checkBufferSize(_UINT32 nRequired) { diff --git a/OOXML/XlsxFormat/Styles/rPr.cpp b/OOXML/XlsxFormat/Styles/rPr.cpp index d52f711c01..192199119e 100644 --- a/OOXML/XlsxFormat/Styles/rPr.cpp +++ b/OOXML/XlsxFormat/Styles/rPr.cpp @@ -1270,7 +1270,11 @@ namespace OOX _UINT32 CRPr::getXLSBSize() const { _UINT32 nLen = 2 + 2 + 2 + 2 + 1 + 1 + 1 + 1 + 1 + 1 + 2 + 4 + 1; - nLen += 4 + 2 * (m_oRFont.IsInit() && m_oRFont->m_sVal.IsInit() ? m_oRFont->m_sVal->length() : 0); + nLen += 4; + if (m_oRFont.IsInit() && m_oRFont->m_sVal.IsInit()) + { + nLen += NSFile::CUtf8Converter::GetUtf16SizeFromUnicode(m_oRFont->m_sVal->c_str(), m_oRFont->m_sVal->length()); + } return nLen; } void CRPr::fromFont(CFont* font)