Commit e5f9ea50 authored by ElenaSubbotina's avatar ElenaSubbotina Committed by Alexander Trofimov

DocFormat - правка багов (файлы com-сервера)

parent 9db24f8e
......@@ -256,7 +256,8 @@ namespace DocFileFormat
if( nIndex < _doc->FontTable->cData )
{
FontFamilyName* ffn = static_cast<FontFamilyName*>( _doc->FontTable->operator [] ( nIndex ) );
this->m_sDefaultFont = ffn->xszFtn;
if (ffn)
this->m_sDefaultFont = ffn->xszFtn;
}
}break;
case sprmCHpsBi :
......
......@@ -61,6 +61,7 @@ namespace DocFileFormat
while ( ( cp - m_document->FIB->m_RgLw97.ccpText - m_document->FIB->m_RgLw97.ccpFtn - m_document->FIB->m_RgLw97.ccpHdr ) < (*m_document->IndividualCommentsPlex)[index + 1] )
{
int fc = m_document->FindFileCharPos(cp);
if (fc < 0) break;
ParagraphPropertyExceptions* papx = findValidPapx(fc);
TableInfo tai(papx);
......
......@@ -126,6 +126,9 @@ namespace DocFileFormat
int cp = initialCp;
int fc = m_document->FindFileCharPos(cp);
int fcEnd = m_document->FindFileCharPos(cpEnd);
if (fc < 0 || fcEnd < 0)
return 0;
ParagraphPropertyExceptions* papx = findValidPapx(fc);
......@@ -515,6 +518,7 @@ namespace DocFileFormat
std::wstring mergeformat( _T( " MERGEFORMAT" ) );
std::wstring quote ( _T( " QUOTE" ) );
std::wstring chart ( _T( "Chart" ) );
std::wstring PBrush ( _T( " PBrush" ) );
if ( search( f.begin(), f.end(), form.begin(), form.end() ) != f.end() )
{
......@@ -1039,6 +1043,7 @@ namespace DocFileFormat
TableInfo tai( papx );
int fcRowEnd = findRowEndFc( cp, cp, nestingLevel );
ParagraphPropertyExceptions* papx_prev = NULL;
while ( tai.fInTable )
{
......@@ -1073,6 +1078,10 @@ namespace DocFileFormat
papx = findValidPapx( fcRowEnd );
tai = TableInfo( papx );
fcRowEnd = findRowEndFc( cp, cp, nestingLevel );
if (papx_prev && papx_prev == papx )
break;//file(12).doc
papx_prev = papx;
}
//build the grid based on the boundaries
......@@ -1123,8 +1132,12 @@ namespace DocFileFormat
//Search the "table trailer paragraph"
while ( ( tai.fTtp == false ) && ( tai.fInTable == true ) )
{
while ( m_document->Text->at( cp ) != TextMark::CellOrRowMark )
while ( true )
{
if (cp >= m_document->Text->size())
break;
if (m_document->Text->at( cp ) == TextMark::CellOrRowMark)
break;
cp++;
}
......
......@@ -45,6 +45,7 @@ namespace DocFileFormat
while ( ( cp - m_document->FIB->m_RgLw97.ccpText - m_document->FIB->m_RgLw97.ccpFtn - m_document->FIB->m_RgLw97.ccpHdr - m_document->FIB->m_RgLw97.ccpAtn ) < (*m_document->IndividualEndnotesPlex)[id + 1] )
{
int fc = m_document->FindFileCharPos(cp);
if (fc < 0) break;
ParagraphPropertyExceptions* papx = findValidPapx( fc );
TableInfo tai( papx );
......
......@@ -37,6 +37,8 @@ namespace DocFileFormat
while ( cp < cpMax )
{
int fc = m_document->FindFileCharPos(cp);
if (fc < 0) break;
ParagraphPropertyExceptions* papx = findValidPapx( fc );
TableInfo tai( papx );
......
......@@ -45,6 +45,8 @@ namespace DocFileFormat
while ( ( cp - m_document->FIB->m_RgLw97.ccpText ) < (*m_document->IndividualFootnotesPlex)[id + 1] )
{
int fc = m_document->FindFileCharPos(cp);
if (fc < 0) break;
ParagraphPropertyExceptions* papx = findValidPapx( fc );
TableInfo tai( papx );
......
......@@ -37,6 +37,8 @@ namespace DocFileFormat
while ( cp < cpMax )
{
int fc = m_document->FindFileCharPos(cp);
if (fc < 0) break;
ParagraphPropertyExceptions* papx = findValidPapx( fc );
TableInfo tai( papx );
......
......@@ -63,9 +63,12 @@ namespace DocFileFormat
//read the number text
short strLen = reader->ReadInt16();
bytes = reader->ReadBytes( ( strLen * 2 ), true );
FormatUtils::GetSTLCollectionFromBytes<wstring>( &(this->xst), bytes, ( strLen * 2 ), ENCODING_UNICODE );
RELEASEARRAYOBJECTS( bytes );
if (strLen > 0)//file(14).doc
{
bytes = reader->ReadBytes( ( strLen * 2 ), true );
FormatUtils::GetSTLCollectionFromBytes<wstring>( &(this->xst), bytes, ( strLen * 2 ), ENCODING_UNICODE );
RELEASEARRAYOBJECTS( bytes );
}
long endPos = reader->GetPosition();
reader->Seek( startPos, 0/*STREAM_SEEK_SET*/ );
......
......@@ -65,6 +65,7 @@ namespace DocFileFormat
while (cp < countText)
{
fc = m_document->FindFileCharPos(cp);
if (fc < 0) break;
papx = findValidPapx(fc);
......@@ -96,6 +97,8 @@ namespace DocFileFormat
int fc = m_document->FindFileCharPos(0);
int fcEnd = m_document->FindFileCharPos(countTextRel);
if (fc < 0 || fcEnd < 0) break;
// Read the chars
vector<wchar_t>* chpxChars = m_document->m_PieceTable->GetEncodingChars (fc, fcEnd, m_document->WordDocumentStream); //<! NEED OPTIMIZE
......
......@@ -443,6 +443,8 @@ namespace DocFileFormat
int fc = m_document->FindFileCharPos(iter->second);
int fcEnd = m_document->FindFileCharPos(iter->second + 1);
if (fc < 0 || fcEnd < 0 ) break;
list<CharacterPropertyExceptions*>* chpxs = m_document->GetCharacterPropertyExceptions(fc, fcEnd);
if ((chpxs != NULL) && (!chpxs->empty()))
......
......@@ -123,7 +123,7 @@ namespace DocFileFormat
}
//Parse the OfficeDrawing Stuff
shapeContainer = static_cast<ShapeContainer*>(RecordFactory::ReadRecord(&reader, 0));
shapeContainer = dynamic_cast<ShapeContainer*>(RecordFactory::ReadRecord(&reader, 0));
long pos = reader.GetPosition();
......
......@@ -43,7 +43,7 @@ namespace DocFileFormat
m_pXmlWriter->WriteNodeEnd( _T( "w:docDefaults" ) );
//write the default styles
if ( sheet->Styles->at( 11 ) == NULL )
if ( (sheet->Styles->size() < 12) || (sheet->Styles->at( 11 ) == NULL ))
{
//NormalTable
writeNormalTableStyle();
......@@ -210,16 +210,20 @@ namespace DocFileFormat
m_pXmlWriter->WriteNodeBegin( _T( "w:rFonts" ), TRUE );
FontFamilyName* ffnAscii = static_cast<FontFamilyName*>( m_document->FontTable->operator [] ( sheet->stshi->rgftcStandardChpStsh[0] ) );
m_pXmlWriter->WriteAttribute( _T( "w:ascii" ), FormatUtils::XmlEncode(ffnAscii->xszFtn).c_str() );
if (ffnAscii)
m_pXmlWriter->WriteAttribute( _T( "w:ascii" ), FormatUtils::XmlEncode(ffnAscii->xszFtn).c_str() );
FontFamilyName* ffnAsia = static_cast<FontFamilyName*>( m_document->FontTable->operator [] ( sheet->stshi->rgftcStandardChpStsh[1] ) );
m_pXmlWriter->WriteAttribute( _T( "w:eastAsia" ), FormatUtils::XmlEncode(ffnAsia->xszFtn).c_str() );
if (ffnAsia)
m_pXmlWriter->WriteAttribute( _T( "w:eastAsia" ), FormatUtils::XmlEncode(ffnAsia->xszFtn).c_str() );
FontFamilyName* ffnAnsi = static_cast<FontFamilyName*>( m_document->FontTable->operator [] ( sheet->stshi->rgftcStandardChpStsh[2] ) );
m_pXmlWriter->WriteAttribute( _T( "w:hAnsi" ), FormatUtils::XmlEncode(ffnAnsi->xszFtn).c_str() );
if (ffnAnsi)
m_pXmlWriter->WriteAttribute( _T( "w:hAnsi" ), FormatUtils::XmlEncode(ffnAnsi->xszFtn).c_str() );
FontFamilyName* ffnComplex = static_cast<FontFamilyName*>( m_document->FontTable->operator [] ( sheet->stshi->rgftcStandardChpStsh[3] ) );
m_pXmlWriter->WriteAttribute( _T( "w:cs" ), FormatUtils::XmlEncode(ffnComplex->xszFtn).c_str() );
if (ffnComplex)
m_pXmlWriter->WriteAttribute( _T( "w:cs" ), FormatUtils::XmlEncode(ffnComplex->xszFtn).c_str() );
m_pXmlWriter->WriteNodeEnd( _T( "" ), TRUE, FALSE );
m_pXmlWriter->WriteNodeEnd( _T( "w:rFonts" ) );
......
......@@ -264,6 +264,7 @@ namespace DocFileFormat
bool Table::IsCellMarker(int _cp)
{
int fc = documentMapping->m_document->FindFileCharPos(_cp);
if (fc < 0) return false;
ParagraphPropertyExceptions* papx = NULL;
......@@ -280,6 +281,7 @@ namespace DocFileFormat
bool Table::IsRowMarker( int _cp )
{
int fc = documentMapping->m_document->FindFileCharPos(_cp);
if (fc < 0) return false;
ParagraphPropertyExceptions* papx = NULL;
......@@ -296,6 +298,7 @@ namespace DocFileFormat
bool Table::IsParagraphMarker( int _cp )
{
int fc = documentMapping->m_document->FindFileCharPos(_cp);
if (fc < 0) return false;
ParagraphPropertyExceptions* papx = NULL;
......@@ -318,6 +321,7 @@ namespace DocFileFormat
SectionPropertyExceptions* sepxBackup = this->documentMapping->_lastValidSepx;
int fc = documentMapping->m_document->FindFileCharPos(_cp);
if (fc < 0) return;
ParagraphPropertyExceptions* papx = NULL;
......@@ -331,6 +335,7 @@ namespace DocFileFormat
do
{
fc = documentMapping->m_document->FindFileCharPos(_cp);
if (fc < 0) break;
papx = this->documentMapping->findValidPapx( fc );
......@@ -345,6 +350,7 @@ namespace DocFileFormat
_cp = innerTable.GetCPEnd();
fc = documentMapping->m_document->FindFileCharPos(_cp);
if (fc < 0) break;
papx = this->documentMapping->findValidPapx( fc );
......
......@@ -83,10 +83,16 @@ namespace DocFileFormat
if (typeid(*_caller) == typeid(MainDocumentMapping))
{
bkd = static_cast<Tbkd*>(m_document->TextboxBreakPlex->Elements[m_nTBIndex]);
cp = txtbxSubdocStart + m_document->TextboxBreakPlex->CharacterPositions[m_nTBIndex];
cpEnd = txtbxSubdocStart + m_document->TextboxBreakPlex->CharacterPositions[m_nTBIndex + 1];
if (m_nTBIndex < m_document->TextboxBreakPlex->Elements.size() )//file(21).doc
{
bkd = static_cast<Tbkd*>(m_document->TextboxBreakPlex->Elements[m_nTBIndex]);
}
if (m_nTBIndex < m_document->TextboxBreakPlex->CharacterPositions.size() - 1)
{
cp = txtbxSubdocStart + m_document->TextboxBreakPlex->CharacterPositions[m_nTBIndex];
cpEnd = txtbxSubdocStart + m_document->TextboxBreakPlex->CharacterPositions[m_nTBIndex + 1];
}
}
else if ((typeid(*_caller) == typeid(HeaderMapping)) || (typeid(*_caller) == typeid(FooterMapping)))
{
......@@ -101,11 +107,17 @@ namespace DocFileFormat
//convert the textbox text
_lastValidPapx = (*(m_document->AllPapxFkps->begin()))->grppapx[0];
ParagraphPropertyExceptions* papx_prev = NULL;
while (cp < cpEnd)
{
int fc = m_document->FindFileCharPos(cp);
if (fc < 0) break;
ParagraphPropertyExceptions* papx = findValidPapx( fc );
if (papx_prev && papx_prev == papx)//file(21).doc
break;
papx_prev = papx;
TableInfo tai( papx );
if ( tai.fInTable )
......
......@@ -27,7 +27,7 @@ public:
{
unsigned short rdUShort = 0;
if ( stream != NULL )
if (( stream != NULL ) && (position + 2 < stream->size()))
{
stream->seek( position );
stream->read((unsigned char*)(&rdUShort), sizeof( rdUShort ));
......@@ -42,7 +42,7 @@ public:
{
short rdShort = 0;
if ( stream != NULL )
if (( stream != NULL ) && (position + 2 < stream->size()))
{
stream->seek( position );
stream->read((unsigned char*)(&rdShort), sizeof( rdShort ));
......@@ -57,7 +57,7 @@ public:
{
int rdInt = 0;
if ( stream != NULL )
if (( stream != NULL ) && (position + 4 < stream->size()))
{
stream->seek( position );
stream->read( (unsigned char*) &rdInt, sizeof( rdInt ) );
......@@ -72,7 +72,7 @@ public:
{
int rdUInt = 0;
if ( stream != NULL )
if (( stream != NULL ) && (position + 4 < stream->size()))
{
stream->seek( position );
stream->read((unsigned char*) &rdUInt, sizeof( rdUInt ) );
......@@ -87,7 +87,7 @@ public:
{
unsigned char rdByte = 0;
if ( this->stream != NULL )
if (( stream != NULL ) && (position + 1 < stream->size()))
{
stream->seek( position);
stream->read( (unsigned char*)&rdByte, sizeof( rdByte ) );
......@@ -105,6 +105,11 @@ public:
if ( ( stream != NULL ) && ( count > 0 ) && isResultNeeded )
{
if (position + count > stream->size())
{
if (position > stream->size()) count = 0;
else count = stream->size() - position;
}
rdBytes = new unsigned char[count];
if ( rdBytes != NULL )
......
......@@ -179,7 +179,10 @@ namespace DocFileFormat
}
if (FIB->m_FibBase.fEncrypted)
{
Clear();
return AVS_ERROR_DRM;
}
// Get the streams
if (FIB->m_FibBase.fWhichTblStm)
......
......@@ -72,7 +72,8 @@ namespace DocFileFormat
inline int FindFileCharPos(int cp)
{
return m_PieceTable->FileCharacterPositions->find(cp)->second;
std::map<int, int>::iterator it = m_PieceTable->FileCharacterPositions->find(cp);
return (it != m_PieceTable->FileCharacterPositions->end()) ? it->second : -1;
}
private:
......
......@@ -24,14 +24,14 @@ int _tmain(int argc, _TCHAR* argv[])
HRESULT hRes = docFile.LoadFromFile( sSrcDoc, dstTempPath, NULL);
if (hRes != S_OK)return 2;
COfficeUtils oCOfficeUtils(NULL);
if (S_OK != oCOfficeUtils.CompressFileOrDirectory(dstTempPath.c_str(), sDstDocx, -1))
return 1;
if (hRes == S_OK)
{
COfficeUtils oCOfficeUtils(NULL);
hRes = oCOfficeUtils.CompressFileOrDirectory(dstTempPath.c_str(), sDstDocx, -1);
}
FileSystem::Directory::DeleteDirectory(dstTempPath);
return 0;
return hRes;
}
......@@ -3,7 +3,7 @@
ProjectType="Visual C++"
Version="8,00"
Name="ASCOfficeDocFile"
ProjectGUID="{da13d6d4-39b5-49db-b5d7-d1afdbb7c320}"
ProjectGUID="{DA13D6D4-39B5-49DB-B5D7-D1AFDBB7C320}"
RootNamespace="ASCOfficeDocFile"
Keyword="AtlProj"
>
......
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