This commit is contained in:
Elena.Subbotina
2023-12-20 16:56:52 +03:00
parent 086fc272df
commit 0f055f696f
11 changed files with 37 additions and 25 deletions

View File

@ -56,6 +56,7 @@
#include "../../../DesktopEditor/common/Types.h"
#include "../../../OOXML/Base/unicode_util.h"
#include "../../../UnicodeConverter/UnicodeConverter.h"
#include "../../../DesktopEditor/common/File.h"
#include <boost/format.hpp>

View File

@ -46,7 +46,7 @@ namespace DocFileFormat
unsigned char *chars = reader->ReadBytes(cch, true);
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &(newObject->m_UserInitials), chars, cch , ENCODING_WINDOWS_1250);
newObject->m_AuthorIndex = reader->ReadUInt16();
newObject->m_BookmarkId = reader->ReadInt16();
@ -59,19 +59,17 @@ namespace DocFileFormat
else
{
short cch = reader->ReadInt16();
unsigned char *chars = reader->ReadBytes(18, true);
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &(newObject->m_UserInitials), chars, ( cch * 2 ), ENCODING_UTF16);
newObject->m_UserInitials = NSFile::CUtf8Converter::GetWStringFromUTF16((unsigned short*)(chars), cch);
RELEASEARRAYOBJECTS(chars);
newObject->m_AuthorIndex = reader->ReadUInt16();
//skip 4 bytes
unsigned int skip = reader->ReadUInt32();
newObject->m_BookmarkId = reader->ReadInt32(); //-1 - comment is on a length zero text range in the Main Document
RELEASEARRAYOBJECTS(chars);
}

View File

@ -63,13 +63,9 @@ namespace DocFileFormat
this->cchFollowingPunct = FormatUtils::BytesToInt16( bytes, 2, size );
this->cchLeadingPunct = FormatUtils::BytesToInt16( bytes, 4, size );
unsigned char fpunctBytes[202];
memcpy( fpunctBytes, ( bytes + 6 ), 202 );
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &(this->rgxchFPunct), fpunctBytes, 202, ENCODING_UTF16 );
this->rgxchFPunct = NSFile::CUtf8Converter::GetWStringFromUTF16((unsigned short*)(bytes + 6), 202 / 2);
this->rgxchLPunct = NSFile::CUtf8Converter::GetWStringFromUTF16((unsigned short*)(bytes + 208), 102 / 2);
unsigned char lpunctBytes[102];
memcpy( lpunctBytes, ( bytes + 208 ), 102 );
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &(this->rgxchLPunct), lpunctBytes, 102, ENCODING_UTF16 );
}
else
{

View File

@ -111,7 +111,7 @@ namespace DocFileFormat
}
else
{
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &(newObject->xszFtn), bytes, (int)( strEnd - strStart ), ENCODING_UTF16 );
newObject->xszFtn = NSFile::CUtf8Converter::GetWStringFromUTF16((unsigned short*)(bytes), (strEnd - strStart) / 2);
}
if (newObject->xszFtn.length() > 0)
@ -145,7 +145,7 @@ namespace DocFileFormat
}
else
{
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &(newObject->xszAlt), bytes, (int)( strEnd - strStart ), ENCODING_UTF16 );
newObject->xszAlt = NSFile::CUtf8Converter::GetWStringFromUTF16((unsigned short*)(bytes), (strEnd - strStart) / 2);
}
RELEASEARRAYOBJECTS( bytes );
}

View File

@ -93,7 +93,7 @@ namespace DocFileFormat
if (strLen > 0)//file(14).doc
{
bytes = reader->ReadBytes( ( strLen * 2 ), true );
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &(xst), bytes, ( strLen * 2 ), ENCODING_UTF16 );
xst = NSFile::CUtf8Converter::GetWStringFromUTF16((unsigned short*)(bytes), strLen);
RELEASEARRAYOBJECTS( bytes );
}
}

View File

@ -371,7 +371,8 @@ void OleObject::processLinkInfoStream( VirtualStreamReader& reader )
cch = reader.ReadInt16();
str = reader.ReadBytes( ( cch * 2 ), true );
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &this->Link, str, ( cch * 2 ), ENCODING_UTF16 );
this->Link = NSFile::CUtf8Converter::GetWStringFromUTF16((unsigned short*)(str), cch);
RELEASEARRAYOBJECTS( str );
//skip the terminating zero of the Unicode string

View File

@ -188,8 +188,15 @@ namespace DocFileFormat
stream->seek(pcd.fc);
stream->read(bytes, cb);
FormatUtils::GetSTLCollectionFromBytes<std::vector<wchar_t> >(piecePairs, bytes, cb, pcd.code_page);
if (pcd.code_page == ENCODING_UTF16)
{
std::wstring sText = NSFile::CUtf8Converter::GetWStringFromUTF16((unsigned short*)(bytes), cb / 2);
std::copy(sText.begin(), sText.end(), std::back_inserter(*piecePairs));
}
else
{
FormatUtils::GetSTLCollectionFromBytes<std::vector<wchar_t> >(piecePairs, bytes, cb, pcd.code_page);
}
RELEASEARRAYOBJECTS(bytes);
}

View File

@ -145,9 +145,8 @@ namespace DocFileFormat
{
name = new unsigned char[characterCount * 2];//characters are zero-terminated, so 1 char has 2 bytes:
memcpy( name, ( bytes + cbStdBase + 2 ), ( characterCount * 2 ) );
//remove zero-termination
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &(xstzName), name, ( characterCount * 2 ), ENCODING_UTF16 );
xstzName = NSFile::CUtf8Converter::GetWStringFromUTF16((unsigned short*)(name), characterCount);
//parse the UPX structs
upxOffset = cbStdBase + 1 + ( characterCount * 2 ) + 2;
}

View File

@ -204,7 +204,7 @@ std::wstring VirtualStreamReader::ReadXst()
int xstzSize = DocFileFormat::FormatUtils::BytesToInt16( cch, 0, cchSize ) * 2;
xstz = ReadBytes(xstzSize, true);
DocFileFormat::FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &wstrResult, xstz, xstzSize, ENCODING_UTF16 );
wstrResult = NSFile::CUtf8Converter::GetWStringFromUTF16((unsigned short*)(xstz), xstzSize / 2);
}
RELEASEARRAYOBJECTS(xstz);
@ -228,7 +228,7 @@ std::wstring VirtualStreamReader::ReadLengthPrefixedUnicodeString()
//dont read the terminating zero
unsigned char* stringBytes = ReadBytes( ( cch * 2 ), true );
DocFileFormat::FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &result, stringBytes, ( ( cch * 2 ) - 2 ), ENCODING_UTF16 );
result = NSFile::CUtf8Converter::GetWStringFromUTF16((unsigned short*)(stringBytes), cch - 1);
RELEASEARRAYOBJECTS( stringBytes );
}

View File

@ -499,7 +499,17 @@ namespace DocFileFormat
RELEASEOBJECT(Text);
Text = new std::vector<wchar_t>();
FormatUtils::GetSTLCollectionFromBytes<std::vector<wchar_t>>(Text, bytes, cb, nFontsCodePage != ENCODING_WINDOWS_1250 ? nFontsCodePage : nDocumentCodePage);
int coding = nFontsCodePage != ENCODING_WINDOWS_1250 ? nFontsCodePage : nDocumentCodePage;
if (coding == ENCODING_UTF16)
{
std::wstring sText = NSFile::CUtf8Converter::GetWStringFromUTF16((unsigned short*)(bytes), cb / 2);
std::copy(sText.begin(), sText.end(), std::back_inserter(*Text));
}
else
{
FormatUtils::GetSTLCollectionFromBytes<std::vector<wchar_t>>(Text, bytes, cb, coding);
}
RELEASEARRAYOBJECTS(bytes);
}

View File

@ -227,7 +227,7 @@ void CRecordOfficeArtBlip::ReadFromStream(SRecordHeader & oHeader, POLE::Stream*
try
{
CBgraFrame bgraFrame;
if (newData && bgraFrame.OpenFile(m_pCommonInfo->tempPath + FILE_SEPARATOR_STR + strFile))
if (bgraFrame.OpenFile(m_pCommonInfo->tempPath + FILE_SEPARATOR_STR + strFile))
{
NSFile::CFileBinary::Remove(m_pCommonInfo->tempPath + FILE_SEPARATOR_STR + strFile);