Commit 467dadc5 authored by ElenaSubbotina's avatar ElenaSubbotina

DocFormat - fix tables world95

parent 1b3a36f3
......@@ -786,7 +786,16 @@ namespace DocFileFormat
{
PictureDescriptor oPicture (chpx, m_document->bOlderVersion ? m_document->WordDocumentStream : m_document->DataStream, 0x7fffffff, m_document->bOlderVersion);
if ((oPicture.mfp.mm > 98) && (NULL != oPicture.shapeContainer))
if (oPicture.embeddedData && oPicture.embeddedDataSize > 0)
{
m_pXmlWriter->WriteNodeBegin (_T("w:pict"));
VMLPictureMapping oVmlMapper(m_context, m_pXmlWriter, false, _caller);
oPicture.Convert (&oVmlMapper);
m_pXmlWriter->WriteNodeEnd (_T("w:pict"));
}
else if ((oPicture.mfp.mm > 98) && (NULL != oPicture.shapeContainer))
{
m_pXmlWriter->WriteNodeBegin (_T("w:pict"));
......@@ -1112,7 +1121,7 @@ namespace DocFileFormat
for ( std::list<SinglePropertyModifier>::iterator iter = papx->grpprl->begin(); iter != papx->grpprl->end(); iter++ )
{
//find the tDef SPRM
if ( iter->OpCode == sprmTDefTable )
if ( iter->OpCode == sprmTDefTable || iter->OpCode == sprmOldTDefTable)
{
unsigned char itcMac = iter->Arguments[0];
......
......@@ -32,14 +32,22 @@
#include "PictureDescriptor.h"
#ifndef MM_ISOTROPIC
#define MM_ISOTROPIC 7
#endif
#ifndef MM_ANISOTROPIC
#define MM_ANISOTROPIC 8
#endif
namespace DocFileFormat
{
/// Parses the CHPX for a fcPic an loads the PictureDescriptor at this offset
PictureDescriptor::PictureDescriptor(CharacterPropertyExceptions* chpx, POLE::Stream* stream, int size, bool oldVersion)
:
dxaGoal(0), dyaGoal(0), mx(0), my(0), Type(jpg), Name( _T( "" ) ), mfp(), dxaCropLeft(0), dyaCropTop(0),
dxaGoal(0), dyaGoal(0), mx(0), my(0), Type(jpg), mfp(), dxaCropLeft(0), dyaCropTop(0),
dxaCropRight(0), dyaCropBottom(0), brcTop(NULL), brcLeft(NULL), brcBottom(NULL), brcRight(NULL), dxaOrigin(0), dyaOrigin(0),
cProps(0), shapeContainer(NULL), blipStoreEntry(NULL)
cProps(0), shapeContainer(NULL), blipStoreEntry(NULL), embeddedData(NULL), embeddedDataSize(0)
{
//Get start and length of the PICT
int fc = GetFcPic( chpx );
......@@ -64,6 +72,8 @@ namespace DocFileFormat
RELEASEOBJECT(shapeContainer);
RELEASEOBJECT(blipStoreEntry);
RELEASEARRAYOBJECTS(embeddedData);
}
void PictureDescriptor::parse(POLE::Stream* stream, int fc, int sz, bool oldVersion)
{
......@@ -90,14 +100,25 @@ namespace DocFileFormat
if (lcb >= 10)
{
int cbHeader = reader.ReadUInt16();
int cbHeader = reader.ReadUInt16();
mfp.mm = reader.ReadInt16();
mfp.xExt = reader.ReadInt16();
mfp.yExt = reader.ReadInt16();
mfp.hMf = reader.ReadInt16();
if (mfp.mm >= 98 || oldVersion)
if (mfp.mm == MM_ISOTROPIC || mfp.mm == MM_ANISOTROPIC)
{
Type = wmf;
mx = my = 200;
dxaGoal = mfp.xExt;
dyaGoal = mfp.yExt;
embeddedDataSize = reader.GetSize() - reader.GetPosition(); //lcb ?
embeddedData = reader.ReadBytes( embeddedDataSize, true );
}
else if (mfp.mm >= 98)
{
unsigned char* bytes = reader.ReadBytes(14, true);
rcWinMf = std::vector<unsigned char>(bytes, (bytes + 14));
......@@ -118,7 +139,6 @@ namespace DocFileFormat
short brcl = reader.ReadInt16();
// borders
int bytesCount = 4;
bytes = reader.ReadBytes( bytesCount, true );
......@@ -154,47 +174,21 @@ namespace DocFileFormat
}
}
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);
//NSFile::CFileBinary f;
//
//f.CreateFile(L"d:\\test.jpg");
//f.WriteFile(pPicData + pos1, lcb - pos - pos1);
//f.CloseFile();
shapeContainer = dynamic_cast<ShapeContainer*>(RecordFactory::ReadRecord(&reader, 0));
//RELEASEARRAYOBJECTS(pPicData);
long pos = reader.GetPosition();
}
else
if( pos < ( fc + lcb ))
{
//Parse the OfficeDrawing Stuff
shapeContainer = dynamic_cast<ShapeContainer*>(RecordFactory::ReadRecord(&reader, 0));
long pos = reader.GetPosition();
Record* rec = RecordFactory::ReadRecord( &reader, 0 );
if( pos < ( fc + lcb ))
if ((rec) && ( typeid(*rec) == typeid(BlipStoreEntry) ))
{
blipStoreEntry = dynamic_cast<BlipStoreEntry*>( rec );
}
else
{
Record* rec = RecordFactory::ReadRecord( &reader, 0 );
if ((rec) && ( typeid(*rec) == typeid(BlipStoreEntry) ))
{
blipStoreEntry = dynamic_cast<BlipStoreEntry*>( rec );
}
else
{
RELEASEOBJECT(rec);
}
RELEASEOBJECT(rec);
}
}
}
......
......@@ -49,26 +49,26 @@ namespace DocFileFormat
struct MetafilePicture
{
/// Specifies the mapping mode in which the picture is drawn.
// Specifies the mapping mode in which the picture is drawn.
short mm;
/// Specifies the size of the metafile picture for all modes except the MM_ISOTROPIC and MM_ANISOTROPIC modes.
/// (For more information about these modes, see the yExt member.)
/// The x-extent specifies the width of the rectangle within which the picture is drawn.
/// The coordinates are in units that correspond to the mapping mode.
// Specifies the size of the metafile picture for all modes except the MM_ISOTROPIC and MM_ANISOTROPIC modes.
// (For more information about these modes, see the yExt member.)
// The x-extent specifies the width of the rectangle within which the picture is drawn.
// The coordinates are in units that correspond to the mapping mode.
short xExt;
/// Specifies the size of the metafile picture for all modes except the MM_ISOTROPIC and MM_ANISOTROPIC modes.
/// The y-extent specifies the height of the rectangle within which the picture is drawn.
/// The coordinates are in units that correspond to the mapping mode.
/// For MM_ISOTROPIC and MM_ANISOTROPIC modes, which can be scaled, the xExt and yExt members
/// contain an optional suggested size in MM_HIMETRIC units.
/// For MM_ANISOTROPIC pictures, xExt and yExt can be zero when no suggested size is supplied.
/// For MM_ISOTROPIC pictures, an aspect ratio must be supplied even when no suggested size is given.
/// (If a suggested size is given, the aspect ratio is implied by the size.)
/// To give an aspect ratio without implying a suggested size, set xExt and yExt to negative values
/// whose ratio is the appropriate aspect ratio.
/// The magnitude of the negative xExt and yExt values is ignored; only the ratio is used.
// Specifies the size of the metafile picture for all modes except the MM_ISOTROPIC and MM_ANISOTROPIC modes.
// The y-extent specifies the height of the rectangle within which the picture is drawn.
// The coordinates are in units that correspond to the mapping mode.
// For MM_ISOTROPIC and MM_ANISOTROPIC modes, which can be scaled, the xExt and yExt members
// contain an optional suggested size in MM_HIMETRIC units.
// For MM_ANISOTROPIC pictures, xExt and yExt can be zero when no suggested size is supplied.
// For MM_ISOTROPIC pictures, an aspect ratio must be supplied even when no suggested size is given.
// (If a suggested size is given, the aspect ratio is implied by the size.)
// To give an aspect ratio without implying a suggested size, set xExt and yExt to negative values
// whose ratio is the appropriate aspect ratio.
// The magnitude of the negative xExt and yExt values is ignored; only the ratio is used.
short yExt;
/// Handle to a memory metafile.
// Handle to a memory metafile.
short hMf;
};
......@@ -80,14 +80,15 @@ namespace DocFileFormat
friend class NumberingMapping;
public:
/// Parses the CHPX for a fcPic an loads the PictureDescriptor at this offset
// Parses the CHPX for a fcPic an loads the PictureDescriptor at this offset
PictureDescriptor( CharacterPropertyExceptions* chpx, POLE::Stream* stream, int size, bool oldVersion);
virtual ~PictureDescriptor();
private:
void parse( POLE::Stream* stream, int fc, int sz, bool oldVersion);
/// Returns the fcPic into the "data" stream, where the PIC begins.
/// Returns -1 if the CHPX has no fcPic.
// Returns the fcPic into the "data" stream, where the PIC begins.
// Returns -1 if the CHPX has no fcPic.
static int GetFcPic( const CharacterPropertyExceptions* chpx );
void Clear();
......@@ -95,45 +96,37 @@ namespace DocFileFormat
static const short MM_SHAPE = 0x0064; // Shape object
static const short MM_SHAPEFILE = 0x0066; // Shape file
/// Rectangle for window origin and extents when metafile is stored (ignored if 0).
std::vector<unsigned char> rcWinMf;
/// Horizontal measurement in twips of the rectangle the picture should be imaged within.
short dxaGoal;
/// Vertical measurement in twips of the rectangle the picture should be imaged within.
short dyaGoal;
/// Horizontal scaling factor supplied by user expressed in .001% units
unsigned short mx;
/// Vertical scaling factor supplied by user expressed in .001% units
unsigned short my;
/// The type of the picture
PictureType Type;
/// The name of the picture
std::wstring Name;
/// The data of the windows metafile picture (WMF)
MetafilePicture mfp;
/// The amount the picture has been cropped on the left in twips
short dxaCropLeft;
/// The amount the picture has been cropped on the top in twips
short dyaCropTop;
/// The amount the picture has been cropped on the right in twips
short dxaCropRight;
/// The amount the picture has been cropped on the bottom in twips
short dyaCropBottom;
/// Border above picture
BorderCode *brcTop;
/// Border to the left of the picture
BorderCode *brcLeft;
/// Border below picture
BorderCode *brcBottom;
/// Border to the right of the picture
BorderCode *brcRight;
/// Horizontal offset of hand annotation origin
short dxaOrigin;
/// vertical offset of hand annotation origin
short dyaOrigin;
/// unused
std::vector<unsigned char> rcWinMf; // Rectangle for window origin and extents when metafile is stored (ignored if 0).
short dxaGoal; // Horizontal measurement in twips of the rectangle the picture should be imaged within.
short dyaGoal; // Vertical measurement in twips of the rectangle the picture should be imaged within.
unsigned short mx; // Horizontal scaling factor supplied by user expressed in .001% units
unsigned short my; // Vertical scaling factor supplied by user expressed in .001% units
PictureType Type; // The type of the picture
MetafilePicture mfp;
short dxaCropLeft; // The amount the picture has been cropped on the left in twips
short dyaCropTop; // The amount the picture has been cropped on the top in twips
short dxaCropRight; // The amount the picture has been cropped on the right in twips
short dyaCropBottom; // The amount the picture has been cropped on the bottom in twips
BorderCode *brcTop; // Border above picture
BorderCode *brcLeft; // Border to the left of the picture
BorderCode *brcBottom; // Border below picture
BorderCode *brcRight; // Border to the right of the picture
short dxaOrigin; // horizontal offset of hand annotation origin
short dyaOrigin; // vertical offset of hand annotation origin
short cProps;
ShapeContainer* shapeContainer;
BlipStoreEntry* blipStoreEntry;
//------------------
ShapeContainer * shapeContainer;
BlipStoreEntry * blipStoreEntry;
unsigned char *embeddedData;
short embeddedDataSize;
};
}
......@@ -91,28 +91,32 @@ namespace DocFileFormat
//some opCode need special treatment
switch ( opCode )
{
case sprmOldTDefTable:
case sprmOldTDefTable10:
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 );
opSize = FormatUtils::BytesToInt16( bytes, ( sprmStart + opCodeSize ), size );
//Word adds an additional unsigned char to the opSize to compensate the additional
//unsigned char needed for the length
opSize--;
}break;
case sprmOldPChgTabs:
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];
opSize = bytes[sprmStart + opCodeSize];
if ( opSize == 255 )
{
unsigned char itbdDelMax = bytes[sprmStart + 3];
unsigned char itbdAddMax = bytes[sprmStart + 3 + 2 * itbdDelMax];
unsigned char itbdDelMax = bytes[sprmStart + opCodeSize + 1];
unsigned char itbdAddMax = bytes[sprmStart + opCodeSize + 1 + 2 * itbdDelMax];
opSize = (short)( ( itbdDelMax * 4 + itbdAddMax * 3 ) - 1 );
}
}break;
......
......@@ -86,6 +86,8 @@ namespace DocFileFormat
{
switch ( OpCode )
{
case sprmOldTDefTable:
case sprmOldTDefTable10:
case sprmTDefTable:
case sprmTDefTable10:
{
......@@ -99,6 +101,7 @@ namespace DocFileFormat
}
break;
case sprmOldPChgTabs:
case sprmPChgTabs:
{
argumentsSize = bytes[2];
......@@ -205,7 +208,7 @@ namespace DocFileFormat
}
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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4, 5, 4, 2, 4, 2, 2, 5, 4, 0, 0, 0, 0, 0, 0, 0, 0
};
unsigned char SinglePropertyModifier::GetOldOperandSize(unsigned char code)
......
......@@ -35,64 +35,73 @@
namespace DocFileFormat
{
class TableInfo
{
public:
bool fInTable;
bool fTtp;
bool fInnerTtp;
bool fInnerTableCell;
unsigned int iTap;
class TableInfo
{
public:
bool fInTable;
bool fTtp;
bool fInnerTtp;
bool fInnerTableCell;
unsigned int iTap;
TableInfo( ParagraphPropertyExceptions* papx ):
fInTable(false), fTtp(false), fInnerTtp(false), fInnerTableCell(false), iTap(0)
{
if ( papx != NULL )
TableInfo( ParagraphPropertyExceptions* papx ):
fInTable(false), fTtp(false), fInnerTtp(false), fInnerTableCell(false), iTap(0)
{
for ( std::list<SinglePropertyModifier>::iterator iter = papx->grpprl->begin(); iter != papx->grpprl->end(); iter++ )
{
if ( iter->OpCode == sprmPFInTable )
{
this->fInTable = ( iter->Arguments[0] == 1 ) ? (true) : (false);
}
if ( iter->OpCode == sprmPFTtp )
{
this->fTtp = ( iter->Arguments[0] == 1 ) ? (true) : (false);
}
if ( iter->OpCode == sprmPFInnerTableCell )
{
this->fInnerTableCell = ( iter->Arguments[0] == 1 ) ? (true) : (false);
}
if ( iter->OpCode == sprmPFInnerTtp )
{
this->fInnerTtp = ( iter->Arguments[0] == 1 ) ? (true) : (false);
}
if ( iter->OpCode == sprmPItap )
{
this->iTap = FormatUtils::BytesToUInt32( iter->Arguments, 0, iter->argumentsSize );
if ( this->iTap > 0 )
{
this->fInTable = true;
}
}
if ( (int)( iter->OpCode ) == 0x66A )
{
//add value!
this->iTap = FormatUtils::BytesToUInt32( iter->Arguments, 0, iter->argumentsSize );
if ( papx != NULL )
{
for ( std::list<SinglePropertyModifier>::iterator iter = papx->grpprl->begin(); iter != papx->grpprl->end(); iter++ )
{
switch(iter->OpCode)
{
case sprmOldPFInTable:
case sprmPFInTable:
{
fInTable = ( iter->Arguments[0] == 1 ) ? (true) : (false);
}break;
//case sprmOldPFTtp:
case sprmOldPTtp:
case sprmPFTtp:
{
fTtp = ( iter->Arguments[0] == 1 ) ? (true) : (false);
}break;
if ( this->iTap > 0 )
{
this->fInTable = true;
}
}
}
//case sprmOldPFInnerTableCell:
case sprmPFInnerTableCell:
{
fInnerTableCell = ( iter->Arguments[0] == 1 ) ? (true) : (false);
}break;
//case sprmOldPFInnerTtp:
case sprmPFInnerTtp:
{
fInnerTtp = ( iter->Arguments[0] == 1 ) ? (true) : (false);
}break;
//case sprmOldPItap:
case sprmPItap:
{
iTap = FormatUtils::BytesToUInt32( iter->Arguments, 0, iter->argumentsSize );
if ( iTap > 0 )
{
fInTable = true;
}
}break;
}
if ( (int)( iter->OpCode ) == sprmTCnf )//66a
{
//add value!
iTap = FormatUtils::BytesToUInt32( iter->Arguments, 0, iter->argumentsSize );
if ( iTap > 0 )
{
fInTable = true;
}
}
}
}
}
}
};
};
}
\ No newline at end of file
......@@ -353,7 +353,7 @@ namespace DocFileFormat
}
Table::Table( DocumentMapping* _documentMapping, int _cp, unsigned int _depth ):
cpStart(_cp), cpEnd(_cp), depth(_depth), documentMapping(_documentMapping)
cpStart(_cp), cpEnd(_cp), depth(_depth), documentMapping(_documentMapping)
{
if ( documentMapping != NULL )
{
......@@ -371,8 +371,8 @@ namespace DocFileFormat
TableInfo tai( papx );
TableRow tableRow( documentMapping, _cp );
TableCell tableCell( documentMapping, _cp );
TableRow tableRow ( documentMapping, _cp );
TableCell tableCell ( documentMapping, _cp );
do
{
......
......@@ -54,7 +54,7 @@ namespace DocFileFormat
/// Extracts the TAPX SPRMs out of a PAPX
TablePropertyExceptions (ParagraphPropertyExceptions* papx, POLE::Stream* dataStream, bool oldVersion) :
PropertyExceptions()
PropertyExceptions()
{
VirtualStreamReader oBinReader(dataStream, 0, oldVersion);
......@@ -62,7 +62,7 @@ namespace DocFileFormat
for (std::list<SinglePropertyModifier>::iterator oSpmIter = papx->grpprl->begin(); oSpmIter != papx->grpprl->end(); ++oSpmIter)
{
if (oSpmIter->OpCode == sprmTDefTableShd || oSpmIter->OpCode == sprmTDefTableShd2nd ||
if (oSpmIter->OpCode == sprmTDefTableShd || oSpmIter->OpCode == sprmTDefTableShd2nd ||
oSpmIter->OpCode == sprmTDefTableShd2nd || oSpmIter->OpCode == sprmTDefTableShd3rd)
{
m_bSkipShading97 = TRUE;
......@@ -72,7 +72,7 @@ namespace DocFileFormat
{
grpprl->push_back(*oSpmIter);
}
else if ((int)(oSpmIter->OpCode) == sprmPTableProps)
else if (oSpmIter->OpCode == sprmPTableProps)
{
//there is a native TAP in the data stream
unsigned int fc = FormatUtils::BytesToUInt32(oSpmIter->Arguments, 0, oSpmIter->argumentsSize);
......
......@@ -56,13 +56,13 @@ namespace DocFileFormat
private:
/// Writes a border element
void writePictureBorder (const wchar_t* name, const BorderCode* brc);
void writePictureBorder (const std::wstring & name, const BorderCode* brc);
void appendStyleProperty( std::wstring* b, const std::wstring& propName, const std::wstring& propValue ) const;
protected:
/// Copies the picture from the binary stream to the zip archive
/// and creates the relationships for the image.
bool CopyPicture (BlipStoreEntry* oBlipEntry);
bool CopyPicture (PictureDescriptor* pict);
public:
......
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