Commit ab2461a5 authored by ElenaSubbotina's avatar ElenaSubbotina

DocFormatReader - format before 1996 - fix formating text

parent 6f9ce15f
This diff is collapsed.
......@@ -33,32 +33,32 @@
namespace TextMark
{
static const wchar_t ParagraphEnd = (wchar_t) 13;
static const wchar_t ParagraphEnd = (wchar_t) 13;
static const wchar_t HardLineBreak = (wchar_t) 11;
static const wchar_t BreakingHyphen = (wchar_t) 4;
static const wchar_t CellOrRowMark = (wchar_t) 7;
static const wchar_t NonRequiredHyphen = (wchar_t) 31;
static const wchar_t NonBreakingHyphen = (wchar_t) 30;
static const wchar_t NonBreakingSpace = (wchar_t) 160;
static const wchar_t NonBreakingSpace = (wchar_t) 160;
static const wchar_t Space = (wchar_t) 32;
static const wchar_t PageBreakOrSectionMark = (wchar_t) 12;
static const wchar_t ColumnBreak = (wchar_t) 14;
static const wchar_t Tab = (wchar_t) 9;
static const wchar_t ColumnBreak = (wchar_t) 14;
static const wchar_t Tab = (wchar_t) 9;
static const wchar_t FieldBeginMark = (wchar_t) 19;
static const wchar_t FieldSeparator = (wchar_t) 20;
static const wchar_t FieldEndMark = (wchar_t) 21;
static const wchar_t FieldEndMark = (wchar_t) 21;
//Special WCHARacters (chp.fSpec == 1)
static const wchar_t CurrentPageNumber = (wchar_t) 0;
static const wchar_t Picture = (wchar_t) 1;
static const wchar_t Picture = (wchar_t) 1;
static const wchar_t AutoNumberedFootnoteReference = (wchar_t) 2;
static const wchar_t AutoNumberedEndnoteReference = (wchar_t) 2;
static const wchar_t AutoNumberedEndnoteReference = (wchar_t) 2;
static const wchar_t FootnoteSeparator = (wchar_t) 3;
static const wchar_t FootnoteContinuation = (wchar_t) 4;
static const wchar_t AnnotationReference = (wchar_t) 5;
static const wchar_t FootnoteContinuation = (wchar_t) 4;
static const wchar_t AnnotationReference = (wchar_t) 5;
static const wchar_t LineNumber = (wchar_t) 6;
static const wchar_t HandAnnotationPicture = (wchar_t) 7;
static const wchar_t DrawnObject = (wchar_t) 8;
static const wchar_t DrawnObject = (wchar_t) 8;
static const wchar_t Symbol = (wchar_t) 40;
}
\ No newline at end of file
......@@ -644,7 +644,7 @@ namespace DocFileFormat
CharacterPropertyExceptions* chpxPic = chpxs->front();
PictureDescriptor pic(chpxPic, m_document->DataStream, 0x7fffffff, m_document->FIB->m_bOlderVersion);
PictureDescriptor pic(chpxPic, m_document->DataStream, 0x7fffffff, m_document->bOlderVersion);
RevisionData oData = RevisionData(chpxPic);
......@@ -782,9 +782,9 @@ namespace DocFileFormat
}
}
}
else if ((TextMark::Picture == c) && fSpec)
else if ((TextMark::Picture == c) && fSpec )
{
PictureDescriptor oPicture (chpx, m_document->DataStream, 0x7fffffff, m_document->FIB->m_bOlderVersion);
PictureDescriptor oPicture (chpx, m_document->bOlderVersion ? m_document->WordDocumentStream : m_document->DataStream, 0x7fffffff, m_document->bOlderVersion);
if ((oPicture.mfp.mm > 98) && (NULL != oPicture.shapeContainer))
{
......@@ -1041,7 +1041,7 @@ namespace DocFileFormat
//find first row end
int fcRowEnd = findRowEndFc( cp, nestingLevel );
TablePropertyExceptions row1Tapx( findValidPapx( fcRowEnd ), m_document->DataStream, m_document->FIB->m_bOlderVersion);
TablePropertyExceptions row1Tapx( findValidPapx( fcRowEnd ), m_document->DataStream, m_document->bOlderVersion);
//start table
m_pXmlWriter->WriteNodeBegin( _T( "w:tbl" ) );
......@@ -1291,7 +1291,7 @@ namespace DocFileFormat
//convert the properties
int fcRowEnd = findRowEndFc( cp, nestingLevel );
TablePropertyExceptions tapx( findValidPapx( fcRowEnd ), m_document->DataStream, m_document->FIB->m_bOlderVersion);
TablePropertyExceptions tapx( findValidPapx( fcRowEnd ), m_document->DataStream, m_document->bOlderVersion);
std::list<CharacterPropertyExceptions*>* chpxs = m_document->GetCharacterPropertyExceptions( fcRowEnd, fcRowEnd + 1 );
TableRowPropertiesMapping* trpMapping = new TableRowPropertiesMapping( m_pXmlWriter, *(chpxs->begin()) );
......@@ -1523,11 +1523,13 @@ namespace DocFileFormat
{
return true;
}
else if (sprmCSymbol == iter->OpCode) // SYMBOL
else if ( sprmCSymbol == iter->OpCode ||
sprmOldCSymbol == iter->OpCode) // SYMBOL
{
return true;
}
else if (sprmCFSpec == iter->OpCode) // SPECIAL OBJECT
else if ( sprmOldCFSpec == iter->OpCode ||
sprmCFSpec == iter->OpCode) // SPECIAL OBJECT
{
return ((0 != iter->Arguments[0]) ? true : false);
}
......
......@@ -52,7 +52,7 @@ namespace DocFileFormat
/*========================================================================================================*/
FormattedDiskPagePAPX::FormattedDiskPagePAPX( POLE::Stream* wordStream, int offset, POLE::Stream* dataStream, bool oldVersion):
FormattedDiskPagePAPX::FormattedDiskPagePAPX( POLE::Stream* wordStream, int offset, POLE::Stream* dataStream, bool oldVersion, bool fComplex):
FormattedDiskPage(), rgbx(NULL), grppapxSize(0), grppapx(NULL)
{
Type = Paragraph;
......@@ -98,54 +98,68 @@ namespace DocFileFormat
unsigned char* papx = NULL;
for ( int i = 0; i < crun; i++ )
{
memcpy( phe, ( bytes + j + 1 ), 12 );
//fill the rgbx array
BX bx;
bx.wordOffset = bytes[j];
bx.phe = ParagraphHeight( phe, 12, false );
for ( int i = 0; i < crun; i++ )
{
BX bx;
bx.wordOffset = bytes[j];
j++;
if (fComplex || !oldVersion)
{
memcpy( phe, ( bytes + j), 12 );
rgbx[i] = bx;
j += 13;
//fill the rgbx array
bx.phe = ParagraphHeight( phe, 12, false );
if ( bx.wordOffset != 0 )
{
//read first unsigned char of PAPX
//PAPX is stored in a FKP; so the first unsigned char is a count of words
unsigned char padbyte = 0;
unsigned char cw = bytes[bx.wordOffset * 2];
//if that unsigned char is zero, it's a pad unsigned char, and the word count is the following unsigned char
if ( cw == 0 )
{
padbyte = 1;
cw = bytes[bx.wordOffset * 2 + 1];
}
j += 12;
}
else
{
memcpy( phe, ( bytes + j), 6);
if ( cw != 0 )
{
//read the bytes for papx
papx = new unsigned char[cw * 2];
memcpy( papx, ( bytes + (bx.wordOffset * 2) + padbyte + 1 ), ( cw * 2 ) );
//fill the rgbx array
bx.phe = ParagraphHeight( phe, 6, false );
//parse PAPX and fill grppapx
grppapx[i] = new ParagraphPropertyExceptions( papx, ( cw * 2 ), dataStream, oldVersion );
j += 6;
}
rgbx[i] = bx;
RELEASEARRAYOBJECTS( papx );
}
}
else
{
//create a PAPX which doesn't modify anything
grppapx[i] = new ParagraphPropertyExceptions();
}
}
if ( bx.wordOffset != 0 )
{
//read first unsigned char of PAPX
//PAPX is stored in a FKP; so the first unsigned char is a count of words
unsigned char padbyte = 0;
unsigned char cw = bytes[bx.wordOffset * 2];
//if that unsigned char is zero, it's a pad unsigned char, and the word count is the following unsigned char
if ( cw == 0 )
{
padbyte = 1;
cw = bytes[bx.wordOffset * 2 + 1];
}
if ( cw != 0 )
{
//read the bytes for papx
papx = new unsigned char[cw * 2];
memcpy( papx, ( bytes + (bx.wordOffset * 2) + padbyte + 1 ), ( cw * 2 ) );
//parse PAPX and fill grppapx
grppapx[i] = new ParagraphPropertyExceptions( papx, ( cw * 2 ), dataStream, oldVersion );
RELEASEARRAYOBJECTS( papx );
}
}
else
{
//create a PAPX which doesn't modify anything
grppapx[i] = new ParagraphPropertyExceptions();
}
}
RELEASEARRAYOBJECTS( phe );
RELEASEARRAYOBJECTS( bytes );
}
RELEASEARRAYOBJECTS( phe );
RELEASEARRAYOBJECTS( bytes );
}
/*========================================================================================================*/
......@@ -188,7 +202,7 @@ namespace DocFileFormat
int offset = fkpnr * 512;
//parse the FKP and add it to the list
PAPXlist->push_back( new FormattedDiskPagePAPX( wordStream, offset, dataStream, fib->m_bOlderVersion) );
PAPXlist->push_back( new FormattedDiskPagePAPX( wordStream, offset, dataStream, fib->m_bOlderVersion, fib->m_FibBase.fComplex) );
}
//if (PAPXlist->back()->rgfc[PAPXlist->back()->rgfcSize-1] < last)
......@@ -212,7 +226,7 @@ namespace DocFileFormat
int offset = fkpnr * 512;
//parse the FKP and add it to the list
PAPXlist->push_back( new FormattedDiskPagePAPX( wordStream, offset, dataStream, fib->m_bOlderVersion) );
PAPXlist->push_back( new FormattedDiskPagePAPX( wordStream, offset, dataStream, fib->m_bOlderVersion, fib->m_FibBase.fComplex) );
}
}
......
......@@ -63,7 +63,7 @@ namespace DocFileFormat
public:
virtual ~FormattedDiskPagePAPX();
FormattedDiskPagePAPX( POLE::Stream* wordStream, int offset, POLE::Stream* dataStream, bool oldVersion);
FormattedDiskPagePAPX( POLE::Stream* wordStream, int offset, POLE::Stream* dataStream, bool oldVersion, bool fComplex);
/// Parses the 0Table (or 1Table) for FKP _entries containing PAPX
static std::list<FormattedDiskPagePAPX*>* GetAllPAPXFKPs( FileInformationBlock* fib, POLE::Stream* wordStream, POLE::Stream* tableStream, POLE::Stream* dataStream);
/// Returns a list of all PAPX FCs between they given boundaries.
......
/*
* (c) Copyright Ascensio System SIA 2010-2016
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
* (c) Copyright Ascensio System SIA 2010-2016
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
#pragma once
namespace DocFileFormat
{
class LineSpacingDescriptor
{
friend class ParagraphPropertiesMapping;
class LineSpacingDescriptor
{
friend class ParagraphPropertiesMapping;
private:
short dyaLine;
bool fMultLinespace;
private:
short dyaLine;
bool fMultLinespace;
public:
/// Creates a new LineSpacingDescriptor with empty values
LineSpacingDescriptor():
dyaLine(0), fMultLinespace(false)
{
}
public:
/// Creates a new LineSpacingDescriptor with empty values
LineSpacingDescriptor(): dyaLine(0), fMultLinespace(false)
{
}
/// Parses the bytes to retrieve a LineSpacingDescriptor
LineSpacingDescriptor( unsigned char* bytes, int size ):
dyaLine(0), fMultLinespace(false)
{
if ( size == 4 )
{
this->dyaLine = FormatUtils::BytesToInt16( bytes, 0, size );
/// Parses the bytes to retrieve a LineSpacingDescriptor
LineSpacingDescriptor( unsigned char* bytes, int size ) : dyaLine(0), fMultLinespace(false)
{
if ( size == 4 )
{
dyaLine = FormatUtils::BytesToInt16( bytes, 0, size );
if ( FormatUtils::BytesToInt16( bytes, 2, size ) == 1 )
{
this->fMultLinespace = true;
}
}
else
{
//throw new ByteParseException("Cannot parse the struct LSPD, the length of the struct doesn't match");
}
}
};
if ( FormatUtils::BytesToInt16( bytes, 2, size ) == 1 )
{
fMultLinespace = true;
}
}
else
{
}
}
};
}
\ No newline at end of file
......@@ -66,7 +66,7 @@ namespace DocFileFormat
//m_pXmlWriter->WriteAttribute(_T("xmlns:wpc"), _T("http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"));
//m_pXmlWriter->WriteAttribute(_T("xmlns:mc"), _T("http://schemas.openxmlformats.org/markup-compatibility/2006"));
//m_pXmlWriter->WriteAttribute(_T("xmlns:wp14"), _T("http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"));
//m_pXmlWriter->WriteAttribute(_T("xmlns:wp14"),_T("http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"));
//m_pXmlWriter->WriteAttribute(_T("xmlns:wp"), _T("http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"));
//m_pXmlWriter->WriteAttribute(_T("xmlns:w14"), _T("http://schemas.microsoft.com/office/word/2010/wordml"));
//m_pXmlWriter->WriteAttribute(_T("xmlns:wpg"), _T("http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"));
......
......@@ -518,14 +518,17 @@ namespace DocFileFormat
for (std::list<SinglePropertyModifier>::const_iterator iter = grpprlChpx->grpprl->begin(); iter != grpprlChpx->grpprl->end(); ++iter)
{
if ((int)(iter->OpCode) == sprmCPbiIBullet)
switch(iter->OpCode)
{
cp = FormatUtils::BytesToUInt32(iter->Arguments, 0, iter->argumentsSize);
}
case sprmCPbiIBullet:
{
cp = FormatUtils::BytesToUInt32(iter->Arguments, 0, iter->argumentsSize);
}break;
if ((int)(iter->OpCode) == sprmCPbiGrf)
{
isPictureBullet = FormatUtils::BitmaskToBool(FormatUtils::BytesToUInt16(iter->Arguments, 0, iter->argumentsSize), 0x1);
case sprmCPbiGrf:
{
isPictureBullet = FormatUtils::BitmaskToBool(FormatUtils::BytesToUInt16(iter->Arguments, 0, iter->argumentsSize), 0x1);
}break;
}
}
......
......@@ -45,52 +45,60 @@ namespace DocFileFormat
ParagraphHeight::ParagraphHeight( unsigned char* bytes, int size, bool fTtpMode )
{
//set default values
setDefaultValues();
//set default values
setDefaultValues();
if ( size == 12 )
{
// The ParagraphHeight is placed in a ParagraphProperties whose fTtp field is set,
//so used another bit setting
if ( fTtpMode )
{
this->fSpare = FormatUtils::BitmaskToBool( FormatUtils::BytesToInt16( bytes, 0, size ), 0x0001 );
this->fUnk = FormatUtils::BitmaskToBool( FormatUtils::BytesToInt16( bytes, 0, size ), 0x0002 );
this->dcpTtpNext = FormatUtils::BytesToInt16( bytes, 0, size );
this->dxaCol = FormatUtils::BytesToInt32( bytes, 4, size );
this->dymTableHeight = FormatUtils::BytesToInt32( bytes, 8, size );
}
else
{
this->fVolatile = FormatUtils::BitmaskToBool( FormatUtils::BytesToInt16( bytes, 0, size ), 0x0001 );
this->fUnk = FormatUtils::BitmaskToBool( FormatUtils::BytesToInt16( bytes, 0, size ), 0x0002 );
this->fDiffLines = FormatUtils::BitmaskToBool( FormatUtils::BytesToInt16( bytes, 0, size ), 0x0004 );
this->clMac = FormatUtils::BytesToUInt16( bytes, 0, size ) & 0x00FF;
// The ParagraphHeight is placed in a ParagraphProperties whose fTtp field is set,
//so used another bit setting
if ( size == 12 )
{
if ( fTtpMode )
{
fSpare = FormatUtils::BitmaskToBool( FormatUtils::BytesToInt16( bytes, 0, size ), 0x0001 );
fUnk = FormatUtils::BitmaskToBool( FormatUtils::BytesToInt16( bytes, 0, size ), 0x0002 );
dcpTtpNext = FormatUtils::BytesToInt16( bytes, 0, size );
dxaCol = FormatUtils::BytesToInt32( bytes, 4, size );
dymTableHeight = FormatUtils::BytesToInt32( bytes, 8, size );
}
else
{
fVolatile = FormatUtils::BitmaskToBool( FormatUtils::BytesToInt16( bytes, 0, size ), 0x0001 );
fUnk = FormatUtils::BitmaskToBool( FormatUtils::BytesToInt16( bytes, 0, size ), 0x0002 );
fDiffLines = FormatUtils::BitmaskToBool( FormatUtils::BytesToInt16( bytes, 0, size ), 0x0004 );
clMac = FormatUtils::BytesToUInt16( bytes, 0, size ) & 0x00FF;
this->dxaCol = FormatUtils::BytesToInt32( bytes, 4, size );
this->dymLine = FormatUtils::BytesToInt32( bytes, 8, size );
this->dymHeight = FormatUtils::BytesToInt32( bytes, 8, size );
}
}
else
{
//throw new ByteParseException("Cannot parse the struct ParagraphHeight, the length of the struct doesn't match");
}
}
dxaCol = FormatUtils::BytesToInt32( bytes, 4, size );
dymLine = FormatUtils::BytesToInt32( bytes, 8, size );
dymHeight = FormatUtils::BytesToInt32( bytes, 8, size );
}
}
else if (size == 6)
{
fVolatile = FormatUtils::BitmaskToBool( FormatUtils::BytesToInt16( bytes, 0, size ), 0x0001 );
fUnk = FormatUtils::BitmaskToBool( FormatUtils::BytesToInt16( bytes, 0, size ), 0x0002 );
fDiffLines = FormatUtils::BitmaskToBool( FormatUtils::BytesToInt16( bytes, 0, size ), 0x0004 );
clMac = FormatUtils::BytesToUChar( bytes, 0, size ) & 0x000F;
dxaCol = FormatUtils::BytesToInt16( bytes, 2, size );
dymLine = FormatUtils::BytesToInt16( bytes, 4, size );
dymHeight = FormatUtils::BytesToInt16( bytes, 4, size );
}
}
/*========================================================================================================*/
void ParagraphHeight::setDefaultValues()
{
this->clMac = 0;
this->dcpTtpNext = 0;
this->dxaCol = 0;
this->dymHeight = 0;
this->dymLine = 0;
this->dymTableHeight = 0;
this->fDiffLines = false;
this->fSpare = false;
this->fUnk = false;
this->fVolatile = false;
clMac = 0;
dcpTtpNext = 0;
dxaCol = 0;
dymHeight = 0;
dymLine = 0;
dymTableHeight = 0;
fDiffLines = false;
fSpare = false;
fUnk = false;
fVolatile = false;
}
}
\ No newline at end of file
......@@ -136,6 +136,8 @@ namespace DocFileFormat
std::list<SinglePropertyModifier>::iterator end = papx->grpprl->end();
for (std::list<SinglePropertyModifier>::iterator iter = papx->grpprl->begin(); iter != end; ++iter)
{
int nProperty = 0; //for unknown test
switch ( iter->OpCode )
{
case sprmPIpgp:
......@@ -170,10 +172,12 @@ namespace DocFileFormat
}
break;
case sprmOldPFKeep:
case sprmPFKeep:
appendFlagElement( _pPr, *iter, _T( "keepLines" ), true );
break;
case sprmOldPFKeepFollow:
case sprmPFKeepFollow:
appendFlagElement( _pPr, *iter, _T( "keepNext" ), true );
break;
......@@ -215,6 +219,8 @@ namespace DocFileFormat
break;
//indentation
case sprmOldPDxaLeft:
case sprmOldPNest:
case sprmPDxaLeft:
case sprmPDxaLeft80:
case sprmPNest:
......@@ -226,6 +232,7 @@ namespace DocFileFormat
appendValueAttribute( &ind, _T( "w:leftChars" ), FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) );
break;
case sprmOldPDxaLeft1:
case sprmPDxaLeft1:
case sprmPDxaLeft180:
{
......@@ -250,6 +257,7 @@ namespace DocFileFormat
appendValueAttribute( &ind, _T( "w:firstLineChars" ), FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) );
break;
case sprmOldPDxaRight:
case sprmPDxaRight:
case sprmPDxaRight80:
appendValueAttribute( &ind, _T( "w:right" ), FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) );
......@@ -260,10 +268,12 @@ namespace DocFileFormat
break;
//spacing
case sprmOldPDyaBefore:
case sprmPDyaBefore:
appendValueAttribute( &spacing, _T( "w:before" ), FormatUtils::BytesToUInt16( iter->Arguments, 0, iter->argumentsSize ) );
break;
case sprmOldPDyaAfter:
case sprmPDyaAfter:
appendValueAttribute( &spacing, _T( "w:after" ), FormatUtils::BytesToUInt16( iter->Arguments, 0, iter->argumentsSize ) );
break;
......@@ -276,6 +286,7 @@ namespace DocFileFormat
appendValueAttribute( &spacing, _T( "w:beforeAutospacing" ), iter->Arguments[0] );
break;
case sprmOldPDyaLine:
case sprmPDyaLine:
{
LineSpacingDescriptor lspd( iter->Arguments, iter->argumentsSize );
......@@ -300,6 +311,7 @@ namespace DocFileFormat
break;
//justification code
case sprmOldPJc:
case sprmPJc:
case sprmPJc80:
{
......@@ -316,6 +328,7 @@ namespace DocFileFormat
//borders
//case 0x461C:
case sprmOldPBrcTop:
case sprmPBrcTop:
//case 0x4424:
case sprmPBrcTop80:
......@@ -331,6 +344,7 @@ namespace DocFileFormat
break;
//case 0x461D:
case sprmOldPBrcLeft:
case sprmPBrcLeft:
//case 0x4425:
case sprmPBrcLeft80:
......@@ -346,6 +360,7 @@ namespace DocFileFormat
break;
//case 0x461E:
case sprmOldPBrcBottom:
case sprmPBrcBottom:
//case 0x4426:
case sprmPBrcBottom80:
......@@ -361,6 +376,7 @@ namespace DocFileFormat
break;
//case 0x461F:
case sprmOldPBrcRight:
case sprmPBrcRight:
//case 0x4427:
case sprmPBrcRight80:
......@@ -376,6 +392,7 @@ namespace DocFileFormat
break;
//case 0x4620:
case sprmOldPBrcBetween:
case sprmPBrcBetween:
//case 0x4428:
case sprmPBrcBetween80:
......@@ -391,6 +408,7 @@ namespace DocFileFormat
break;
//case 0x4621:
case sprmOldPBrcBar:
case sprmPBrcBar:
//case 0x4629:
case sprmPBrcBar80:
......@@ -445,6 +463,7 @@ namespace DocFileFormat
break;
//tabs
case sprmOldPChgTabs:
case sprmPChgTabsPapx:
case sprmPChgTabs:
{
......@@ -513,6 +532,7 @@ namespace DocFileFormat
break;
//frame properties
case sprmOldPPc:
case sprmPPc:
{
//position code
......@@ -523,14 +543,17 @@ namespace DocFileFormat
}
break;
case sprmOldPWr:
case sprmPWr:
appendValueAttribute( this->_framePr, _T( "w:wrap" ), FormatUtils::MapValueToWideString( iter->Arguments[0], &Global::TextFrameWrapping[0][0], 6, 10 ).c_str() );
break;
case sprmOldPDxaAbs:
case sprmPDxaAbs:
appendValueAttribute( this->_framePr, _T( "w:x" ), FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) );
break;
case sprmOldPDyaAbs:
case sprmPDyaAbs:
appendValueAttribute( this->_framePr, _T( "w:y" ), FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) );
break;
......@@ -539,18 +562,22 @@ namespace DocFileFormat
appendValueAttribute( this->_framePr, _T( "w:h" ), FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) );
break;
case sprmOldPDxaWidth:
case sprmPDxaWidth:
appendValueAttribute( this->_framePr, _T( "w:w" ), FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) );
break;
case sprmOldPDxaFromText:
case sprmPDxaFromText:
appendValueAttribute( this->_framePr, _T( "w:hSpace" ), FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) );
break;
case sprmOldPDyaFromText:
case sprmPDyaFromText:
appendValueAttribute( this->_framePr, _T( "w:vSpace" ), FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) );
break;
case sprmOldPDcs:
case sprmPDcs:
{
short pDcs = FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize );
......@@ -567,10 +594,13 @@ namespace DocFileFormat
break;
default:
if (iter->argumentsSize == 2)
{
nProperty = FormatUtils::BytesToUInt16( iter->Arguments, 0, iter->argumentsSize );
}else
if (iter->argumentsSize == 1)
{
#ifdef _DEBUG
// //ATLTRACE (_T("ParagraphPropertiesMapping - UNKNOWN SPRM : 0x%x\n"), iter->OpCode);
#endif
nProperty = FormatUtils::BytesToUChar( iter->Arguments, 0, iter->argumentsSize );
}
break;
}
......
......@@ -39,14 +39,14 @@ namespace DocFileFormat
{
if ( size != 0 )
{
this->istd = FormatUtils::BytesToUInt16( bytes, 0, size );
istd = FormatUtils::BytesToUInt16( bytes, 0, size );
}
VirtualStreamReader *reader = NULL;
//There is a SPRM that points to an offset in the data stream,
//where a list of SPRM is saved.
for ( std::list<SinglePropertyModifier>::iterator iter = this->grpprl->begin(); iter != this->grpprl->end(); iter++ )
for ( std::list<SinglePropertyModifier>::iterator iter = grpprl->begin(); iter != grpprl->end(); iter++ )
{
SinglePropertyModifier sprm( *iter );
......@@ -68,11 +68,11 @@ namespace DocFileFormat
PropertyExceptions externalPx( grpprlBytes, grpprlsize, oldVersion );
//assign the external grpprl
RELEASEOBJECT( this->grpprl );
this->grpprl = new std::list<SinglePropertyModifier>( *(externalPx.grpprl) );
RELEASEOBJECT( grpprl );
grpprl = new std::list<SinglePropertyModifier>( *(externalPx.grpprl) );
//remove the sprmPHugePapx
this->grpprl->remove( sprm );
grpprl->remove( sprm );
RELEASEARRAYOBJECTS( grpprlBytes );
RELEASEOBJECT( reader )
......
......@@ -90,14 +90,14 @@ namespace DocFileFormat
if (lcb >= 10)
{
unsigned short cbHeader = reader.ReadUInt16();
int cbHeader = reader.ReadUInt16();
mfp.mm = reader.ReadInt16();
mfp.xExt = reader.ReadInt16();
mfp.yExt = reader.ReadInt16();
mfp.hMf = reader.ReadInt16();
mfp.mm = reader.ReadInt16();
mfp.xExt = reader.ReadInt16();
mfp.yExt = reader.ReadInt16();
mfp.hMf = reader.ReadInt16();
if (mfp.mm > 98)
if (mfp.mm >= 98 || oldVersion)
{
unsigned char* bytes = reader.ReadBytes(14, true);
rcWinMf = std::vector<unsigned char>(bytes, (bytes + 14));
......@@ -154,22 +154,47 @@ namespace DocFileFormat
}
}
//Parse the OfficeDrawing Stuff
shapeContainer = dynamic_cast<ShapeContainer*>(RecordFactory::ReadRecord(&reader, 0));
if (oldVersion)
{
////blipStoreEntry = new BlipStoreEntry();
//blipStoreEntry = new BlipStoreEntry(&reader,lcb, Global::msoblipDIB,0,0);
//long pos = reader.GetPosition();
//unsigned char* pPicData = reader.ReadBytes(lcb - pos, true);
//int pos1 = 0;
//BITMAPINFOHEADER *bm = (BITMAPINFOHEADER *)(pPicData + pos1);
long pos = reader.GetPosition();
//NSFile::CFileBinary f;
//
//f.CreateFile(L"d:\\test.jpg");
//f.WriteFile(pPicData + pos1, lcb - pos - pos1);
//f.CloseFile();
if( pos < ( fc + lcb ))
//RELEASEARRAYOBJECTS(pPicData);
}
else
{
Record* rec = RecordFactory::ReadRecord( &reader, 0 );
//Parse the OfficeDrawing Stuff
shapeContainer = dynamic_cast<ShapeContainer*>(RecordFactory::ReadRecord(&reader, 0));
if ((rec) && ( typeid(*rec) == typeid(BlipStoreEntry) ))
{
blipStoreEntry = dynamic_cast<BlipStoreEntry*>( rec );
}
else
long pos = reader.GetPosition();
if( pos < ( fc + lcb ))
{
RELEASEOBJECT(rec);
Record* rec = RecordFactory::ReadRecord( &reader, 0 );
if ((rec) && ( typeid(*rec) == typeid(BlipStoreEntry) ))
{
blipStoreEntry = dynamic_cast<BlipStoreEntry*>( rec );
}
else
{
RELEASEOBJECT(rec);
}
}
}
}
......@@ -186,6 +211,7 @@ namespace DocFileFormat
{
switch ( iter->OpCode )
{
case sprmOldCPicLocation:
case sprmCPicLocation:
ret = FormatUtils::BytesToInt32( iter->Arguments, 0, iter->argumentsSize );
break;
......@@ -194,6 +220,7 @@ namespace DocFileFormat
ret = FormatUtils::BytesToInt32( iter->Arguments, 0, iter->argumentsSize );
break;
case sprmOldCFData:
case sprmCFData:
break;
}
......
......@@ -36,107 +36,116 @@
namespace DocFileFormat
{
PropertyExceptions::~PropertyExceptions()
{
RELEASEOBJECT( this->grpprl );
}
/*========================================================================================================*/
PropertyExceptions::PropertyExceptions(): grpprl(NULL)
{
this->grpprl = new std::list<SinglePropertyModifier>();
}
PropertyExceptions::~PropertyExceptions()
{
RELEASEOBJECT( this->grpprl );
}
/*========================================================================================================*/
PropertyExceptions::PropertyExceptions(): grpprl(NULL)
{
this->grpprl = new std::list<SinglePropertyModifier>();
}
PropertyExceptions::PropertyExceptions( const std::list<SinglePropertyModifier>& grpprl )
{
this->grpprl = new std::list<SinglePropertyModifier>( grpprl );
}
PropertyExceptions::PropertyExceptions( const std::list<SinglePropertyModifier>& grpprl )
{
this->grpprl = new std::list<SinglePropertyModifier>( grpprl );
}
/*========================================================================================================*/
PropertyExceptions::PropertyExceptions( unsigned char* bytes, int size, bool oldVersion ) : grpprl(NULL)
{
this->grpprl = new std::list<SinglePropertyModifier>();
PropertyExceptions::PropertyExceptions( unsigned char* bytes, int size, bool oldVersion ): grpprl(NULL)
{
this->grpprl = new std::list<SinglePropertyModifier>();
if ( ( bytes == NULL ) || ( size == 0 ) ) return;
if ( ( bytes == NULL ) || ( size == 0 ) ) return;
//read the sprms
int sprmStart = 0;
bool goOn = true;
//read the sprms
int sprmStart = 0;
bool goOn = true;
int opCodeSize = (oldVersion ? 1 : 2);
while ( goOn )
{
//enough bytes to read?
if ( ( sprmStart + 2 ) < size )
while ( goOn )
{
//make spra
OperationCode opCode = (OperationCode)FormatUtils::BytesToUInt16( bytes, sprmStart, size );
unsigned char spra = (unsigned char)( (int)opCode >> 13 );
//enough bytes to read?
if ( ( sprmStart + opCodeSize ) < size )
{
OperationCode opCode = oldVersion ? (OperationCode)FormatUtils::BytesToUChar ( bytes, sprmStart, size ) :
(OperationCode)FormatUtils::BytesToUInt16 ( bytes, sprmStart, size ) ;
// get size of operand
short opSize = (short)SinglePropertyModifier::GetOperandSize( spra );
unsigned char lenByte = 0;
short opSize = -1;
//operand has variable size
if ( opSize == 255 )
{
//some opCode need special treatment
switch ( opCode )
if (oldVersion)
{
opSize = (short)SinglePropertyModifier::GetOldOperandSize( (unsigned char)opCode );
}
else
{
case sprmTDefTable:
case sprmTDefTable10:
{
//The opSize of the table definition is stored in 2 bytes instead of 1
lenByte = 2;
opSize = FormatUtils::BytesToInt16( bytes, ( sprmStart + 2 ), size );
//Word adds an additional unsigned char to the opSize to compensate the additional
//unsigned char needed for the length
opSize--;
}
break;
case sprmPChgTabs:
{
//The tab operand can be bigger than 255 bytes (length unsigned char is set to 255).
//In this case a special calculation of the opSize is needed
lenByte = 1;
opSize = bytes[sprmStart + 2];
if ( opSize == 255 )
unsigned char spra = (unsigned char)( (int)opCode >> 13 );
opSize = (short)SinglePropertyModifier::GetOperandSize( spra );
}
unsigned char lenByte = 0;
//operand has variable size
if ( opSize == 255 )
{
//some opCode need special treatment
switch ( opCode )
{
unsigned char itbdDelMax = bytes[sprmStart + 3];
unsigned char itbdAddMax = bytes[sprmStart + 3 + 2 * itbdDelMax];
opSize = (short)( ( itbdDelMax * 4 + itbdAddMax * 3 ) - 1 );
case sprmTDefTable:
case sprmTDefTable10:
{
//The opSize of the table definition is stored in 2 bytes instead of 1
lenByte = 2;
opSize = FormatUtils::BytesToInt16( bytes, ( sprmStart + 2 ), size );
//Word adds an additional unsigned char to the opSize to compensate the additional
//unsigned char needed for the length
opSize--;
}break;
case sprmPChgTabs:
{
//The tab operand can be bigger than 255 bytes (length unsigned char is set to 255).
//In this case a special calculation of the opSize is needed
lenByte = 1;
opSize = bytes[sprmStart + 2];
if ( opSize == 255 )
{
unsigned char itbdDelMax = bytes[sprmStart + 3];
unsigned char itbdAddMax = bytes[sprmStart + 3 + 2 * itbdDelMax];
opSize = (short)( ( itbdDelMax * 4 + itbdAddMax * 3 ) - 1 );
}
}break;
case sprmOldPAnld:
{
lenByte = 1;
opSize = bytes[sprmStart + opCodeSize];
}break;
default:
{
//The variable length stand in the unsigned char after the opcode
lenByte = 1;
opSize = bytes[sprmStart + opCodeSize];
}
break;
}
}
break;
default:
{ //The variable length stand in the unsigned char after the opcode
lenByte = 1;
opSize = bytes[sprmStart + 2];
}
break;
}
}
//copy sprm to array
//length is 2byte for the opCode, lenByte for the length, opSize for the length of the operand
int sprmBytesSize = 2 + lenByte + opSize;
unsigned char* sprmBytes = NULL;
sprmBytes = new unsigned char[sprmBytesSize];
//copy sprm to array
//length is 2byte for the opCode, lenByte for the length, opSize for the length of the operand
int sprmBytesSize = opCodeSize + lenByte + opSize;
unsigned char* sprmBytes = NULL;
sprmBytes = new unsigned char[sprmBytesSize];
if ( size >= ( sprmStart + sprmBytesSize ) )
{
memcpy( sprmBytes, ( bytes + sprmStart ), sprmBytesSize );
//parse
SinglePropertyModifier sprm( sprmBytes, sprmBytesSize );
SinglePropertyModifier sprm( sprmBytes, sprmBytesSize, oldVersion );
grpprl->push_back( sprm );
sprmStart += sprmBytesSize;
......@@ -154,4 +163,5 @@ PropertyExceptions::PropertyExceptions( unsigned char* bytes, int size, bool old
}
}
}
}
\ No newline at end of file
......@@ -127,6 +127,7 @@ namespace DocFileFormat
switch (iter->OpCode)
{
//page margins
case sprmOldSDxaLeft:
case sprmSDxaLeft:
{
//left margin
......@@ -135,6 +136,7 @@ namespace DocFileFormat
}
break;
case sprmOldSDxaRight:
case sprmSDxaRight:
{
//right margin
......@@ -143,32 +145,38 @@ namespace DocFileFormat
}
break;
case sprmOldSDyaTop:
case sprmSDyaTop:
//top margin
appendValueAttribute( &pgMar, _T( "w:top" ), FormatUtils::IntToWideString( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ).c_str() );
break;
case sprmOldSDyaBottom:
case sprmSDyaBottom:
//bottom margin
appendValueAttribute( &pgMar, _T( "w:bottom" ), FormatUtils::IntToWideString( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ).c_str() );
break;
case sprmOldSDzaGutter:
case sprmSDzaGutter:
//gutter margin
appendValueAttribute( &pgMar, _T( "w:gutter" ), FormatUtils::IntToWideString( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ).c_str() );
break;
case sprmOldSDyaHdrTop:
case sprmSDyaHdrTop:
//header margin
appendValueAttribute( &pgMar, _T( "w:header"), FormatUtils::IntToWideString( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ).c_str() );
break;
case sprmOldSDyaHdrBottom:
case sprmSDyaHdrBottom:
//footer margin
appendValueAttribute( &pgMar, _T( "w:footer" ), FormatUtils::IntToWideString( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ).c_str() );
break;
//page size and orientation
case sprmOldSXaPage:
case sprmSXaPage:
{
//width
......@@ -177,21 +185,25 @@ namespace DocFileFormat
}
break;
case sprmOldSYaPage:
case sprmSYaPage:
//height
appendValueAttribute( &pgSz, _T( "w:h" ), FormatUtils::IntToWideString( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ).c_str() );
break;
case sprmOldSBOrientation:
case sprmSBOrientation:
//orientation
appendValueAttribute( &pgSz, _T( "w:orient" ), FormatUtils::MapValueToWideString( iter->Arguments[0], &PageOrientationMap[0][0], 3, 10 ).c_str() );
break;
//paper source
case sprmOldSDmBinFirst:
case sprmSDmBinFirst:
appendValueAttribute( &paperSrc, _T( "w:first" ), FormatUtils::IntToWideString( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ).c_str() );
break;
case sprmOldSDmBinOther:
case sprmSDmBinOther:
appendValueAttribute( &paperSrc, _T( "w:other" ), FormatUtils::IntToWideString( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ).c_str() );
break;
......@@ -306,6 +318,7 @@ namespace DocFileFormat
break;
// Columns
case sprmOldSCcolumns:
case sprmSCcolumns:
{
m_nColumns = static_cast<int> (FormatUtils::BytesToInt16 (iter->Arguments, 0, iter->argumentsSize) + 1);
......@@ -317,11 +330,13 @@ namespace DocFileFormat
}
break;
case sprmOldSDxaColumns:
case sprmSDxaColumns:
//evenly spaced columns
appendValueAttribute (&cols, _T( "w:space" ), FormatUtils::IntToWideString( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) ).c_str() );
break;
case sprmOldSDxaColWidth:
case sprmSDxaColWidth:
{
// there is at least one width set, so create the array
......@@ -336,6 +351,7 @@ namespace DocFileFormat
}
break;
case sprmOldSDxaColSpacing:
case sprmSDxaColSpacing:
{
// there is at least one space set, so create the array
......@@ -356,6 +372,7 @@ namespace DocFileFormat
break;
//title page
case sprmOldSFTitlePage:
case sprmSFTitlePage:
appendFlagElement (m_pXmlNode, *iter, _T( "titlePg" ), true );
break;
......@@ -366,6 +383,7 @@ namespace DocFileFormat
break;
//type
case sprmOldSBkc:
case sprmSBkc:
{
this->_type = FormatUtils::MapValueToWideString( iter->Arguments[0], &SectionTypeMap[0][0], 5, 11 );
......@@ -373,25 +391,30 @@ namespace DocFileFormat
break;
//align
case sprmOldSVjc:
case sprmSVjc:
appendValueElement (m_pXmlNode, _T( "vAlign" ), FormatUtils::MapValueToWideString( iter->Arguments[0], &TextVerticalAlignment[0][0], 4, 7 ).c_str(), true );
break;
//pgNumType
case sprmOldSNfcPgn:
case sprmSNfcPgn:
appendValueAttribute( &pgNumType, _T( "w:fmt" ), FormatUtils::MapValueToWideString( iter->Arguments[0], &PageNumberFormatCodeMap[0][0], 42, 29 ).c_str() );
break;
case sprmOldSPgnStart:
case sprmSPgnStart:
wsSprmSPgnStart = FormatUtils::IntToWideString( FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) );
break;
case sprmOldSFPgnRestart:
case sprmSFPgnRestart:
bWasSprmSFPgnRestart = true;
break;
// <w:lnNumType> - Line Numbering Settings
case sprmOldSLnnMin :
case sprmSLnnMin :
{
unsigned short start = FormatUtils::BytesToUInt16 (iter->Arguments, 0, iter->argumentsSize);
......@@ -401,6 +424,7 @@ namespace DocFileFormat
}
break;
case sprmOldSLnc :
case sprmSLnc :
{
SLncOperand mode = (SLncOperand)FormatUtils::BytesToUChar (iter->Arguments, 0, iter->argumentsSize);
......@@ -410,6 +434,7 @@ namespace DocFileFormat
}
break;
case sprmOldSNLnnMod :
case sprmSNLnnMod :
{
short countBy = FormatUtils::BytesToUInt16 (iter->Arguments, 0, iter->argumentsSize);
......
......@@ -36,38 +36,51 @@
namespace DocFileFormat
{
SinglePropertyModifier::SinglePropertyModifier() : Arguments(NULL), OpCode(sprmPIstd), fSpec(false), Type(PAP), argumentsSize(0)
SinglePropertyModifier::SinglePropertyModifier( bool oldVersion_) :
Arguments(NULL), OpCode(sprmPIstd), fSpec(false), Type(PAP), argumentsSize(0), oldVersion (oldVersion_)
{
}
/// parses the unsigned char to retrieve a SPRM
SinglePropertyModifier::SinglePropertyModifier(unsigned char* bytes, int size) : Arguments(NULL), OpCode(sprmPIstd), fSpec(false), Type(PAP), argumentsSize(0)
SinglePropertyModifier::SinglePropertyModifier(unsigned char* bytes, int size, bool oldVersion_) :
Arguments(NULL), OpCode(sprmPIstd), fSpec(false), Type(PAP), argumentsSize(0), oldVersion (oldVersion_)
{
//first 2 bytes are the operation code ...
this->OpCode = (OperationCode)FormatUtils::BytesToUInt16( bytes, 0, size );
//... whereof bit 9 is fSpec ...
unsigned int j = (unsigned int)this->OpCode << 22;
j = j >> 31;
if ( j == 1 )
unsigned char opSize = 0;
unsigned char opCodeSize = 0;
if (oldVersion)
{
this->fSpec = true;
opCodeSize = 1;
//first 1 byte are the operation code ...
OpCode = (OperationCode)FormatUtils::BytesToUChar( bytes, 0, size );
opSize = GetOldOperandSize( (unsigned char)OpCode );
}
else
{
this->fSpec = false;
}
opCodeSize = 2;
//first 2 bytes are the operation code ...
OpCode = (OperationCode)FormatUtils::BytesToUInt16( bytes, 0, size );
//... whereof bit 9 is fSpec ...
unsigned int j = (unsigned int)this->OpCode << 22;
j = j >> 31;
if ( j == 1 )
{
fSpec = true;
}
else
{
fSpec = false;
}
//... and bits 10,11,12 are the type ...
unsigned int i = (unsigned int)this->OpCode << 19;
//... and bits 10,11,12 are the type ...
unsigned int i = (unsigned int)OpCode << 19;
i = i >> 29;
this->Type = (SprmType)i;
i = i >> 29;
Type = (SprmType)i;
//... and last 3 bits are the spra
unsigned char spra = (unsigned char)( (int)this->OpCode >> 13 );
unsigned char opSize = GetOperandSize( spra );
//... and last 3 bits are the spra
unsigned char spra = (unsigned char)( (int)OpCode >> 13 );
opSize = GetOperandSize( spra );
}
if ( opSize == 255 )
{
......@@ -77,31 +90,31 @@ namespace DocFileFormat
case sprmTDefTable10:
{
//the variable length stand in the bytes 2 and 3
short opSizeTable = FormatUtils::BytesToInt16( bytes, 2, size );
this->argumentsSize = opSizeTable-1;
short opSizeTable = FormatUtils::BytesToInt16( bytes, opCodeSize, size );
argumentsSize = opSizeTable-1;
//and the arguments start at the unsigned char after that (byte3)
this->Arguments = new unsigned char[this->argumentsSize];
Arguments = new unsigned char[argumentsSize];
//Arguments start at unsigned char 4
memcpy( this->Arguments, ( bytes + 4 ), this->argumentsSize );
memcpy( Arguments, ( bytes + opCodeSize + 2 ), argumentsSize );
}
break;
case sprmPChgTabs:
{
this->argumentsSize = bytes[2];
this->Arguments = new unsigned char[this->argumentsSize];
memcpy( this->Arguments, ( bytes + 3 ), this->argumentsSize );
argumentsSize = bytes[2];
Arguments = new unsigned char[argumentsSize];
memcpy( Arguments, ( bytes + opCodeSize + 1 ), argumentsSize );
}
break;
default:
{
//the variable length stand in the unsigned char after the opcode (byte2)
opSize = bytes[2];
this->argumentsSize = opSize;
opSize = bytes[opCodeSize];
argumentsSize = opSize;
//and the arguments start at the unsigned char after that (byte3)
this->Arguments = new unsigned char[this->argumentsSize];
memcpy( this->Arguments, ( bytes + 3 ), this->argumentsSize );
Arguments = new unsigned char[argumentsSize];
memcpy( Arguments, ( bytes + opCodeSize + 1 ), argumentsSize );
}
break;
......@@ -109,9 +122,9 @@ namespace DocFileFormat
}
else
{
this->argumentsSize = opSize;
this->Arguments = new unsigned char[this->argumentsSize];
memcpy( this->Arguments, ( bytes + 2 ), this->argumentsSize );
argumentsSize = opSize;
Arguments = new unsigned char[argumentsSize];
memcpy( Arguments, ( bytes + opCodeSize ), argumentsSize );
}
}
......@@ -119,19 +132,20 @@ namespace DocFileFormat
{
if ( spm.Arguments != NULL )
{
this->argumentsSize = spm.argumentsSize;
this->Arguments = new unsigned char[this->argumentsSize];
memcpy( this->Arguments, spm.Arguments, this->argumentsSize );
this->fSpec = spm.fSpec;
this->OpCode = spm.OpCode;
this->Type = spm.Type;
argumentsSize = spm.argumentsSize;
Arguments = new unsigned char[argumentsSize];
memcpy( Arguments, spm.Arguments, argumentsSize );
fSpec = spm.fSpec;
OpCode = spm.OpCode;
Type = spm.Type;
oldVersion = spm.oldVersion;
}
}
bool SinglePropertyModifier::operator == (const SinglePropertyModifier& spm) const
{
if ( ( this->argumentsSize == spm.argumentsSize ) && ( memcmp( this->Arguments, spm.Arguments, this->argumentsSize ) == 0 ) &&
( this->fSpec == spm.fSpec ) && ( this->OpCode == spm.OpCode ) && ( this->Type == spm.Type ) )
if ( ( argumentsSize == spm.argumentsSize ) && ( memcmp( Arguments, spm.Arguments, argumentsSize ) == 0 ) &&
( fSpec == spm.fSpec ) && ( OpCode == spm.OpCode ) && ( Type == spm.Type ) )
{
return true;
}
......@@ -156,9 +170,11 @@ namespace DocFileFormat
fSpec = spm.fSpec;
Type = spm.Type;
argumentsSize = spm.argumentsSize;
oldVersion = spm.oldVersion;
Arguments = new unsigned char[argumentsSize];
memcpy(Arguments, spm.Arguments, spm.argumentsSize);
memcpy(Arguments, spm.Arguments, spm.argumentsSize);
}
return *this;
......@@ -187,4 +203,15 @@ namespace DocFileFormat
default: return 0;
}
}
static const unsigned char OldOperandSizeTable[] =
{
0, 0, 2, 255, 1, 1, 1, 1, 1, 1, 1, 1, 255, 1, 1, 255, 2, 2, 2, 2, 4, 2, 2, 255, 1, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 255, 2, 4, 1, 2, 3, 255, 1, 0, 0, 0, 0, 2, 255, 255, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 3, 2, 2, 1, 1, 1, 1, 1, 255, 1, 255, 255, 2, 255, 2, 2, 0, 0, 0, 0, 0, 0, 1, 1, 1, 255, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 1, 1, 255, 0, 0, 3, 3, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 2, 2, 1, 0, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 1, 1, 12, 255, 2, 0, 0, 4, 5, 4, 2, 4, 2, 2, 5, 4, 0, 0, 0, 0, 0, 0, 0, 0
};
unsigned char SinglePropertyModifier::GetOldOperandSize(unsigned char code)
{
if (code < 2 || code > 207) return -1;
return OldOperandSizeTable [code];
}
}
......@@ -48,6 +48,7 @@ namespace DocFileFormat
class SinglePropertyModifier
{
public:
bool oldVersion;
/// The operation code identifies the property of the
/// PAP/CHP/PIC/SEP/TAP which sould be modified
OperationCode OpCode;
......@@ -60,10 +61,11 @@ namespace DocFileFormat
/// The Arguments size
unsigned int argumentsSize;
SinglePropertyModifier();
SinglePropertyModifier(bool oldVersion);
/// parses the unsigned char to retrieve a SPRM
SinglePropertyModifier( unsigned char* bytes, int size );
SinglePropertyModifier( const SinglePropertyModifier& spm );
SinglePropertyModifier( unsigned char* bytes, int size, bool oldVersion );
SinglePropertyModifier( const SinglePropertyModifier& spm);
bool operator == ( const SinglePropertyModifier& spm ) const;
bool operator != ( const SinglePropertyModifier& spm ) const;
SinglePropertyModifier& operator = ( const SinglePropertyModifier& spm );
......@@ -71,5 +73,6 @@ namespace DocFileFormat
/// Get be used to get the size of the sprm's operand.
/// Returns 0 if the Operation failed and 255 if the size is variable
static unsigned char GetOperandSize( unsigned char spra );
static unsigned char GetOldOperandSize( unsigned char code);
};
}
......@@ -35,14 +35,14 @@
namespace DocFileFormat
{
TablePropertiesMapping::TablePropertiesMapping (XmlUtils::CXmlWriter* pWriter, StyleSheet* styles, std::vector<short>* grid, bool isTableStyleNeeded ):
PropertiesMapping(pWriter), _tblPr(NULL), _tblGrid(NULL), _tblBorders(NULL), _grid(NULL),
brcLeft(NULL), brcTop(NULL), brcBottom(NULL), brcRight(NULL), brcHorz(NULL), brcVert(NULL), _styles(NULL),
_isTableStyleNeeded(isTableStyleNeeded)
PropertiesMapping(pWriter), _tblPr(NULL), _tblGrid(NULL), _tblBorders(NULL), _grid(NULL),
brcLeft(NULL), brcTop(NULL), brcBottom(NULL), brcRight(NULL), brcHorz(NULL), brcVert(NULL), _styles(NULL),
_isTableStyleNeeded(isTableStyleNeeded)
{
_styles = styles;
this->_tblPr = new XMLTools::XMLElement<wchar_t>( _T( "w:tblPr" ) );
this->_tblBorders = new XMLTools::XMLElement<wchar_t>( _T( "w:tblBorders" ) );
this->_grid = grid;
_styles = styles;
_tblPr = new XMLTools::XMLElement<wchar_t>( _T( "w:tblPr" ) );
_tblBorders = new XMLTools::XMLElement<wchar_t>( _T( "w:tblBorders" ) );
_grid = grid;
}
TablePropertiesMapping::~TablePropertiesMapping()
{
......@@ -63,30 +63,32 @@ namespace DocFileFormat
{
TablePropertyExceptions* tapx = static_cast<TablePropertyExceptions*>( visited );
XMLTools::XMLElement<wchar_t> tblCellMar( _T( "w:tblCellMar" ) );
XMLTools::XMLElement<wchar_t> tblLayout( _T( "w:tblLayout" ) );
XMLTools::XMLElement<wchar_t> tblpPr( _T( "w:tblpPr" ) );
XMLTools::XMLAttribute<wchar_t> layoutType( _T( "w:type" ), _T( "fixed" ) );
XMLTools::XMLElement<wchar_t> tblCellMar ( _T( "w:tblCellMar" ) );
XMLTools::XMLElement<wchar_t> tblLayout ( _T( "w:tblLayout" ) );
XMLTools::XMLElement<wchar_t> tblpPr ( _T( "w:tblpPr" ) );
XMLTools::XMLAttribute<wchar_t> layoutType ( _T( "w:type" ), _T( "fixed" ) );
bool bLayoutFixed = true;
short tblIndent = 0;
short gabHalf = 0;
short marginLeft = 0;
short marginRight = 0;
short tblIndent = 0;
short gabHalf = 0;
short marginLeft = 0;
short marginRight = 0;
for ( std::list<SinglePropertyModifier>::iterator iter = tapx->grpprl->begin(); iter != tapx->grpprl->end(); iter++ )
{
switch( iter->OpCode )
{
case sprmTDxaGapHalf:
case sprmOldTDxaGapHalf:
case sprmTDxaGapHalf:
{
gabHalf = FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize );
}
break;
//table definition
case sprmTDefTable:
{
case sprmOldTDefTable:
case sprmTDefTable:
{ //table definition
SprmTDefTable tDef( iter->Arguments, iter->argumentsSize );
//Workaround for retrieving the indent of the table:
//In some files there is a indent but no sprmTWidthIndent is set.
......@@ -97,14 +99,13 @@ namespace DocFileFormat
tblIndent += gabHalf;
//If there follows a real sprmTWidthIndent, this value will be overwritten
///<<<<FIXED
tblIndent = (std::max)((int)tblIndent,0);
}
break;
//preferred table width
case sprmTTableWidth:
{
case sprmTTableWidth:
{ //preferred table width
unsigned char fts = iter->Arguments[0];
short width = FormatUtils::BytesToInt16( iter->Arguments, 1, iter->argumentsSize );
......@@ -120,27 +121,28 @@ namespace DocFileFormat
}
break;
//justification
case sprmTJc:
case sprmTJcRow:
{
case sprmOldTJc:
case sprmTJc:
case sprmTJcRow:
{ //justification
appendValueElement( _tblPr, _T( "jc" ), FormatUtils::MapValueToWideString( iter->Arguments[0], &Global::JustificationCode[0][0], 10, 15 ).c_str(), true );
}
break;
//indent
case sprmTWidthIndent:
{
case sprmTWidthIndent:
{ //indent
tblIndent = FtsWWidth_Indent(iter->Arguments).wWidth;
// tblIndent = FormatUtils::BytesToInt16( iter->Arguments, 1, iter->argumentsSize );
}
break;
//style
case sprmTIstd:
case sprmTIstdPermute:
{
if ( this->_isTableStyleNeeded )
case sprmTIstd:
case sprmTIstdPermute:
{ //style
if ( _isTableStyleNeeded )
{
int ind = FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize );
......@@ -154,24 +156,25 @@ namespace DocFileFormat
}
break;
//bidi
case sprmTFBiDi:
case sprmTFBiDi90:
{
case sprmTFBiDi:
case sprmTFBiDi90:
{ //bidi
appendValueElement( _tblPr, _T( "bidiVisual" ), FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ), true );
}
break;
//table look
case sprmTTlp:
{
case sprmOldTTlp:
case sprmTTlp:
{ //table look
appendValueElement( _tblPr, _T( "tblLook" ), FormatUtils::IntToFormattedWideString( FormatUtils::BytesToInt16( iter->Arguments, 2, iter->argumentsSize ), _T( "%04x" ) ).c_str(), true );
}
break;
//autofit
case sprmTFAutofit:
{
case sprmTFAutofit:
{ //autofit
if ( iter->Arguments[0] == 1 )
{
layoutType.SetValue( _T( "auto" ) );
......@@ -180,11 +183,11 @@ namespace DocFileFormat
}
break;
//default cell padding (margin)
case sprmTCellPadding:
case sprmTCellPaddingDefault:
case sprmTCellPaddingOuter:
{
case sprmTCellPadding:
case sprmTCellPaddingDefault:
case sprmTCellPaddingOuter:
{ //default cell padding (margin)
unsigned char grfbrc = iter->Arguments[2];
short wMar = FormatUtils::BytesToInt16( iter->Arguments, 4, iter->argumentsSize );
std::wstring strValue = FormatUtils::IntToWideString( wMar );
......@@ -211,23 +214,23 @@ namespace DocFileFormat
}
break;
//row count
case sprmTCHorzBands:
{
case sprmTCHorzBands:
{ //row count
appendValueElement( _tblPr, _T( "tblStyleRowBandSize" ), iter->Arguments[0], true );
}
break;
//col count
case sprmTCVertBands:
{
case sprmTCVertBands:
{ //col count
appendValueElement( _tblPr, _T( "tblStyleColBandSize" ), iter->Arguments[0], true );
}
break;
//overlap
case sprmTFNoAllowOverlap:
{
case sprmTFNoAllowOverlap:
{ //overlap
std::wstring tblOverlapVal = std::wstring( _T( "overlap" ) );
if ( iter->Arguments[0] )
......@@ -239,16 +242,17 @@ namespace DocFileFormat
}
break;
//shading
case sprmTSetShdTable:
{
case sprmOldTSetShd :
case sprmTSetShdTable :
{ //shading
appendShading( _tblPr, ShadingDescriptor( iter->Arguments, iter->argumentsSize ) );
}
break;
//borders 80 exceptions
case sprmTTableBorders80:
{
case sprmTTableBorders80:
{ //borders 80 exceptions
const int size = 4;
unsigned char brc80[size];
......@@ -285,7 +289,8 @@ namespace DocFileFormat
break;
//border exceptions
case sprmTTableBorders:
case sprmOldTTableBorders:
case sprmTTableBorders:
{
const int size = 8;
unsigned char brc[size];
......@@ -323,7 +328,7 @@ namespace DocFileFormat
break;
//floating table properties
case sprmTPc:
case sprmTPc:
{
unsigned char flag = ( iter->Arguments[0] & 0x30 ) >> 4;
......@@ -335,37 +340,37 @@ namespace DocFileFormat
}
break;
case sprmTDxaFromText:
case sprmTDxaFromText:
{
appendValueAttribute( &tblpPr, _T( "w:leftFromText" ), FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) );
}
break;
case sprmTDxaFromTextRight:
case sprmTDxaFromTextRight:
{
appendValueAttribute( &tblpPr, _T( "w:rightFromText" ), FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) );
}
break;
case sprmTDyaFromText:
case sprmTDyaFromText:
{
appendValueAttribute( &tblpPr, _T( "w:topFromText" ), FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) );
}
break;
case sprmTDyaFromTextBottom:
case sprmTDyaFromTextBottom:
{
appendValueAttribute( &tblpPr, _T( "w:bottomFromText" ), FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) );
}
break;
case sprmTDxaAbs:
case sprmTDxaAbs:
{
appendValueAttribute( &tblpPr, _T( "w:tblpX" ), FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) );
}
break;
case sprmTDyaAbs:
case sprmTDyaAbs:
{
appendValueAttribute( &tblpPr, _T( "w:tblpY" ), FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) );
}
......
......@@ -54,53 +54,53 @@ namespace DocFileFormat
TablePropertyExceptions* tapx = static_cast<TablePropertyExceptions*>( visited );
//delete infos
RevisionData rev( this->_rowEndChpx );
RevisionData rev( _rowEndChpx );
if ( ( this->_rowEndChpx != NULL ) && ( rev.Type == Deleted ) )
if ( ( _rowEndChpx != NULL ) && ( rev.Type == Deleted ) )
{
XMLTools::XMLElement<wchar_t> del( _T( "w:del" ) );
this->_trPr->AppendChild( del );
_trPr->AppendChild( del );
}
for ( std::list<SinglePropertyModifier>::iterator iter = tapx->grpprl->begin(); iter != tapx->grpprl->end(); iter++ )
{
switch ( iter->OpCode )
{
case sprmTDefTable:
case sprmOldTDefTable:
case sprmTDefTable:
{
//SprmTDefTable tdef = new SprmTDefTable(sprm.Arguments);
}
break;
//header row
case sprmTTableHeader:
{
case sprmOldTTableHeader:
case sprmTTableHeader:
{ //header row
bool fHeader = ( iter->Arguments[0] != 0 ) ? (true) : (false);
if ( fHeader )
{
XMLTools::XMLElement<wchar_t> header( _T( "w:tblHeader" ) );
this->_trPr->AppendChild( header );
_trPr->AppendChild( header );
}
}
break;
//width after
case sprmTWidthAfter:
{
case sprmTWidthAfter:
{ //width after
XMLTools::XMLElement<wchar_t> wAfter( _T( "w:wAfter" ) );
XMLTools::XMLAttribute<wchar_t> wAfterValue( _T( "w:w" ), FormatUtils::IntToWideString( FormatUtils::BytesToInt16( iter->Arguments, 1, iter->argumentsSize ) ).c_str() );
wAfter.AppendAttribute( wAfterValue );
XMLTools::XMLAttribute<wchar_t> wAfterType( _T( "w:type" ), _T( "dxa" ) );
wAfter.AppendAttribute( wAfterType );
this->_trPr->AppendChild( wAfter );
_trPr->AppendChild( wAfter );
}
break;
//width before
case sprmTWidthBefore:
{
case sprmTWidthBefore:
{ //width before
short before = FormatUtils::BytesToInt16( iter->Arguments, 1, iter->argumentsSize );
if ( before != 0 )
......@@ -111,14 +111,14 @@ namespace DocFileFormat
XMLTools::XMLAttribute<wchar_t> wBeforeType( _T( "w:type" ), _T( "dxa" ) );
wBefore.AppendAttribute( wBeforeType );
this->_trPr->AppendChild( wBefore );
_trPr->AppendChild( wBefore );
}
}
break;
//row height
case sprmTDyaRowHeight:
{
case sprmOldTDyaRowHeight:
case sprmTDyaRowHeight:
{ //row height
XMLTools::XMLElement<wchar_t> rowHeight( _T( "w:trHeight" ) );
XMLTools::XMLAttribute<wchar_t> rowHeightVal( _T( "w:val" ) );
XMLTools::XMLAttribute<wchar_t> rowHeightRule( _T( "w:hRule" ) );
......@@ -144,20 +144,22 @@ namespace DocFileFormat
}
rowHeight.AppendAttribute( rowHeightRule );
this->_trPr->AppendChild( rowHeight );
_trPr->AppendChild( rowHeight );
}
break;
//can't split
case sprmOldTFCantSplit:
case sprmTFCantSplit:
case sprmTFCantSplit90:
appendFlagElement( this->_trPr, *iter, _T( "cantSplit" ), true );
break;
{ //can't split
appendFlagElement( _trPr, *iter, _T( "cantSplit" ), true );
}break;
//div id
case sprmTIpgp:
appendValueElement( this->_trPr, _T( "divId" ), FormatUtils::IntToWideString( FormatUtils::BytesToInt32( iter->Arguments, 0, iter->argumentsSize ) ).c_str(), true );
break;
{
appendValueElement( _trPr, _T( "divId" ), FormatUtils::IntToWideString( FormatUtils::BytesToInt32( iter->Arguments, 0, iter->argumentsSize ) ).c_str(), true );
}break;
//borders 80 exceptions
//case SinglePropertyModifier.OperationCode.sprmTTableBorders80:
......@@ -250,15 +252,15 @@ namespace DocFileFormat
//}
//set exceptions
if ( this->_tblPrEx->GetChildCount() > 0 )
if ( _tblPrEx->GetChildCount() > 0 )
{
this->_trPr->AppendChild( *(this->_tblPrEx) );
_trPr->AppendChild( *(_tblPrEx) );
}
//write Properties
if ( ( this->_trPr->GetChildCount() > 0 ) || ( this->_trPr->GetAttributeCount() > 0 ) )
if ( ( _trPr->GetChildCount() > 0 ) || ( _trPr->GetAttributeCount() > 0 ) )
{
m_pXmlWriter->WriteString( this->_trPr->GetXMLString().c_str() );
m_pXmlWriter->WriteString( _trPr->GetXMLString().c_str() );
}
}
}
\ No newline at end of file
......@@ -31,14 +31,15 @@
*/
#include "WordDocument.h"
#include "../../Common/OfficeFileErrorDescription.h"
#include "../../ASCOfficeXlsFile2/source/XlsFormat/Logic/SummaryInformationStream/SummaryInformation.h"
#include "../../ASCOfficeXlsFile2/source/XlsFormat/Binary/CFStream.h"
#include "../../Common/DocxFormat/Source/SystemUtility/FileSystem/Directory.h"
#include "../../DesktopEditor/common/File.h"
namespace DocFileFormat
{
WordDocument::WordDocument (const ProgressCallback* pCallFunc, const std::wstring & sTempFolder ) :
......
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