Commit ec2901bf authored by ElenaSubbotina's avatar ElenaSubbotina

RtfFormat - fix users file

parent 5f0e6349
...@@ -46,7 +46,14 @@ HRESULT ConvertOle1ToOle2(BYTE *pData, int nSize, std::wstring sOle2Name) ...@@ -46,7 +46,14 @@ HRESULT ConvertOle1ToOle2(BYTE *pData, int nSize, std::wstring sOle2Name)
NSFile::CFileBinary file; NSFile::CFileBinary file;
file.CreateFileW(sOle2Name); file.CreateFileW(sOle2Name);
if (ole1Reader.NativeDataSize > 0)//conv_NI38P7GBIpw1aD84H3k.rtf
{
file.WriteFile(ole1Reader.NativeData, ole1Reader.NativeDataSize); file.WriteFile(ole1Reader.NativeData, ole1Reader.NativeDataSize);
}
else
{
file.WriteFile(pData, nSize);
}
file.CloseFile(); file.CloseFile();
return S_FALSE; return S_FALSE;
} }
...@@ -818,7 +825,6 @@ bool RtfShadingRowCommand::ExecuteCommand(RtfDocument& oDocument, RtfReader& oRe ...@@ -818,7 +825,6 @@ bool RtfShadingRowCommand::ExecuteCommand(RtfDocument& oDocument, RtfReader& oRe
return false; return false;
return true; return true;
} }
bool RtfCharPropsCommand::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader, std::string sCommand, bool hasParameter, int parameter, RtfCharProperty * charProps, bool bLookOnBorder) bool RtfCharPropsCommand::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader, std::string sCommand, bool hasParameter, int parameter, RtfCharProperty * charProps, bool bLookOnBorder)
{ {
if (!charProps) return false; if (!charProps) return false;
...@@ -1645,7 +1651,49 @@ bool RtfFieldInstReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oRead ...@@ -1645,7 +1651,49 @@ bool RtfFieldInstReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oRead
return RtfParagraphPropDestination::ExecuteCommand( oDocument, oReader, (*this), sCommand, hasParameter, parameter ); return RtfParagraphPropDestination::ExecuteCommand( oDocument, oReader, (*this), sCommand, hasParameter, parameter );
} }
} }
bool RtfOleBinReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader, std::string sCommand, bool hasParameter, int parameter)
{
if ( "objdata" == sCommand )
return true;
if ( "bin" == sCommand ) // from RtfOleReader - conv_NI38P7GBIpw1aD84H3k.rtf
{
int nDataSize = 0;
if ( hasParameter )
nDataSize = parameter;
BYTE *pData = NULL;
oReader.m_oLex.ReadBytes( parameter, &pData );
m_arData.push_back(std::string((char*)pData, nDataSize));
RELEASEOBJECT(pData);
}
return true;
}
void RtfOleBinReader::ExecuteText(RtfDocument& oDocument, RtfReader& oReader, std::wstring sText)
{
m_arData.push_back(std::string(sText.begin(), sText.end()));
}
void RtfOleBinReader::GetData( BYTE** ppData, long& nSize)
{
nSize = 0;
for (size_t i = 0; i < m_arData.size(); i++)
{
nSize += m_arData[i].length();
}
(*ppData) = new BYTE[ nSize];
int pos = 0;
for (size_t i = 0; i < m_arData.size(); i++)
{
memcpy((*ppData) + pos, m_arData[i].c_str(), m_arData[i].length());
pos += m_arData[i].length();
}
}
bool RtfOleReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader, std::string sCommand, bool hasParameter, int parameter) bool RtfOleReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader, std::string sCommand, bool hasParameter, int parameter)
{ {
if ( "object" == sCommand ) if ( "object" == sCommand )
...@@ -1663,19 +1711,21 @@ bool RtfOleReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader, st ...@@ -1663,19 +1711,21 @@ bool RtfOleReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader, st
} }
else if ( "objdata" == sCommand ) else if ( "objdata" == sCommand )
{ {
std::wstring sOleData; RtfOleBinReader oBinReader;
TextReader oTextReader( sOleData, false );
StartSubReader( oTextReader, oDocument, oReader ); StartSubReader( oBinReader, oDocument, oReader );
BYTE *pData = NULL; BYTE *pData = NULL;
long nSize = 0; long nSize = 0;
RtfUtility::WriteDataToBinary( sOleData, &pData, nSize );
oBinReader.GetData(&pData, nSize );
if ( 0 != nSize && pData) if ( 0 != nSize && pData)
{ {
HRESULT hRes = S_FALSE; HRESULT hRes = S_FALSE;
//конвертация Ole1 в Ole2 //конвертация Ole1 в Ole2
#if 0//defined(_WIN32) || defined(_WIN64) #if 0 //defined(_WIN32) || defined(_WIN64)
RtfOle1ToOle2Stream oStream; RtfOle1ToOle2Stream oStream;
oStream.lpstbl = new OLESTREAMVTBL(); oStream.lpstbl = new OLESTREAMVTBL();
...@@ -1689,7 +1739,7 @@ bool RtfOleReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader, st ...@@ -1689,7 +1739,7 @@ bool RtfOleReader::ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader, st
std::wstring sOleStorageName = Utils::CreateTempFile( oReader.m_sTempFolder ); std::wstring sOleStorageName = Utils::CreateTempFile( oReader.m_sTempFolder );
IStorage* piMSStorage = NULL; IStorage* piMSStorage = NULL;
if ( SUCCEEDED( StgCreateDocfile( sOleStorageName, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_TRANSACTED/* | STGM_DELETEONRELEASE*/, NULL, &piMSStorage) ) ) if ( SUCCEEDED( StgCreateDocfile( sOleStorageName.c_str(), STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE | STGM_TRANSACTED/* | STGM_DELETEONRELEASE*/, NULL, &piMSStorage) ) )
{ {
hRes = OleConvertOLESTREAMToIStorage( &oStream, piMSStorage, NULL ); hRes = OleConvertOLESTREAMToIStorage( &oStream, piMSStorage, NULL );
piMSStorage->Commit( STGC_DEFAULT ); piMSStorage->Commit( STGC_DEFAULT );
......
...@@ -109,13 +109,13 @@ public: ...@@ -109,13 +109,13 @@ public:
} }
}; };
//class RtfOldList; //class RtfOldList;
class TextReader: public RtfAbstractReader class TextReader : public RtfAbstractReader
{ {
private: private:
std::wstring& m_sName; std::wstring& m_sName;
bool m_bErease; bool m_bErease;
public: public:
TextReader( std::wstring& sName, bool bErease = true ):m_sName(sName),m_bErease(bErease) TextReader( std::wstring& sName, bool bErease = true ) : m_sName(sName), m_bErease(bErease)
{ {
} }
void ExecuteText(RtfDocument& oDocument, RtfReader& oReader, std::wstring sText) void ExecuteText(RtfDocument& oDocument, RtfReader& oReader, std::wstring sText)
...@@ -782,6 +782,20 @@ public: ...@@ -782,6 +782,20 @@ public:
bool ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader, std::string sCommand, bool hasParameter, int parameter); bool ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader, std::string sCommand, bool hasParameter, int parameter);
}; };
class RtfOleBinReader : public RtfAbstractReader
{
private:
std::vector<std::string>/*&*/ m_arData;
public:
RtfOleBinReader()
{
}
bool ExecuteCommand(RtfDocument& oDocument, RtfReader& oReader, std::string sCommand, bool hasParameter, int parameter);
void ExecuteText(RtfDocument& oDocument, RtfReader& oReader, std::wstring sText);
void GetData( BYTE** ppData, long& nSize);
};
class RtfTrackerChangesReader: public RtfAbstractReader class RtfTrackerChangesReader: public RtfAbstractReader
{ {
private: private:
......
...@@ -300,6 +300,7 @@ public: ...@@ -300,6 +300,7 @@ public:
Ole1FormatReader(BYTE *pData, int Size) Ole1FormatReader(BYTE *pData, int Size)
{ {
NativeDataSize = 0;
if (!pData || Size < 8) return; if (!pData || Size < 8) return;
CDataStream stream(pData, Size); CDataStream stream(pData, Size);
......
...@@ -93,10 +93,14 @@ std::wstring RtfOle::RenderToOOX(RenderParameter oRenderParameter) ...@@ -93,10 +93,14 @@ std::wstring RtfOle::RenderToOOX(RenderParameter oRenderParameter)
RenderParameter oNewRenderParameter = oRenderParameter; RenderParameter oNewRenderParameter = oRenderParameter;
oNewRenderParameter.nType = RENDER_TO_OOX_PARAM_SHAPE_WSHAPE2; oNewRenderParameter.nType = RENDER_TO_OOX_PARAM_SHAPE_WSHAPE2;
if (m_oResultPic)
{
m_oResultPic->m_bIsOle = true; m_oResultPic->m_bIsOle = true;
sResult += m_oResultPic->RenderToOOX(oNewRenderParameter); sResult += m_oResultPic->RenderToOOX(oNewRenderParameter);
oNewRenderParameter.nValue = m_oResultPic->m_nID; oNewRenderParameter.nValue = m_oResultPic->m_nID;
}
sResult += RenderToOOXOnlyOle(oNewRenderParameter); sResult += RenderToOOXOnlyOle(oNewRenderParameter);
sResult += L"</w:object>"; sResult += L"</w:object>";
......
...@@ -617,21 +617,6 @@ public: ...@@ -617,21 +617,6 @@ public:
file.CloseFile(); file.CloseFile();
} }
static void WriteDataToBinary( std::wstring sData, BYTE** ppData, long& nSize)
{
wchar_t * buf = (wchar_t *)sData.c_str();
int nLengthText = (int)sData.length();
nSize = nLengthText/2;
BYTE * buf2 = new BYTE[ nSize];
(*ppData) = buf2;
BYTE nByte=0;
for (long i=0; i < nSize ; i++ )
{
nByte = ToByte(buf[ 2*i])<<4;
nByte |= ToByte(buf[ 2*i+1]);
buf2[i] = nByte;
}
}
static std::wstring DecodeHex( std::wstring sText ) static std::wstring DecodeHex( std::wstring sText )
{ {
std::wstring sHexText; std::wstring sHexText;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment