Commit 32922220 authored by Alexey Golubev's avatar Alexey Golubev

Merge branch 'release/v4.1.0'

parents 06a7ed6d 21fb5c56
......@@ -2,6 +2,20 @@ build/
dictionaries/
LicenceManager/
Common/boost_1_58_0
Common/3dParty/boost/boost_1_58_0
Common/3dParty/icu/win_64
Common/3dParty/icu/win_32
Common/3dParty/icu/linux_64
Common/3dParty/icu/linux_32
Common/3dParty/icu/mac_64
Common/3dParty/v8/v8
Common/3dParty/v8/depot_tools
Common/3dParty/v8/win_64
Common/3dParty/v8/win_32
Common/3dParty/v8/linux_64
Common/3dParty/v8/linux_32
Common/3dParty/v8/mac_64
**/core_build
**/Release
**/Debug
*.user
......@@ -20,3 +34,7 @@ ASCOfficeXlsFile2/win32/_ASCOfficeXlsFile2_i.c
ASCOfficeXlsFile2/win32/_ASCOfficeXlsFile2_p.c
ASCOfficeXlsFile2/win32/dlldata.c
OfficeUtils/win32/OfficeUtilsLib/OfficeUtilsLib/ReadMe.txt
*.obj
*.pdb
*.tlb
*.idb
......@@ -38,7 +38,7 @@ namespace DocFileFormat
//verison 1995 and earler
sprmOldPIstd = 2,
sprmOldPIstdPermute = 3,
sprmOldPIncLv1 = 4,
sprmOldPIncLvl = 4,
sprmOldPJc = 5,
sprmOldPFSideBySide = 6,
sprmOldPFKeep = 7,
......@@ -98,6 +98,7 @@ namespace DocFileFormat
sprmOldCChse = 73,
sprmOldCSymbol = 74,
sprmOldCFOle2 = 75,
sprmCOldHighlight = 77,
sprmOldCIstd = 80,
sprmOldCIstdPermute = 81,
sprmOldCDefault = 82,
......
......@@ -39,6 +39,25 @@ namespace DocFileFormat
AnnotationReferenceDescriptor *newObject = new AnnotationReferenceDescriptor();
//read the user initials (LPXCharBuffer9)
if (reader->olderVersion)
{
short cch = reader->ReadByte();
unsigned char *chars = reader->ReadBytes(cch, true);
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &(newObject->m_UserInitials), chars, cch , ENCODING_WINDOWS_1250);
newObject->m_AuthorIndex = reader->ReadUInt16();
newObject->m_BookmarkId = reader->ReadInt16();
RELEASEARRAYOBJECTS(chars);
chars = reader->ReadBytes(length - cch - 1 - 4, true);
RELEASEARRAYOBJECTS(chars);
}
else
{
short cch = reader->ReadInt16();
unsigned char *chars = reader->ReadBytes(18, true);
......@@ -51,8 +70,9 @@ namespace DocFileFormat
reader->ReadBytes(4, false);
newObject->m_BookmarkId = reader->ReadInt32();
RELEASEARRAYOBJECTS(chars);
}
return static_cast<ByteStructure*>(newObject);
}
......
......@@ -39,6 +39,12 @@ namespace DocFileFormat
{
public:
static const int STRUCTURE_SIZE = 30;
static const int STRUCTURE_SIZE_OLD = 20;
static const int GetSize(bool bOldVersion)
{
return bOldVersion ? STRUCTURE_SIZE_OLD : STRUCTURE_SIZE;
}
inline std::wstring GetUserInitials() const
{
......
......@@ -301,6 +301,10 @@ namespace DocFileFormat
colorVal->SetValue( rgbColor.GetString() );
}break;
case sprmCOldHighlight:
{
appendValueElement( parent, _T( "highlight" ), FormatUtils::MapValueToWideString( iter->Arguments[1], &Global::ColorIdentifier[0][0], 17, 12 ).c_str(), true );
}break;
case sprmCHighlight:
{
appendValueElement( parent, _T( "highlight" ), FormatUtils::MapValueToWideString( iter->Arguments[0], &Global::ColorIdentifier[0][0], 17, 12 ).c_str(), true );
......
......@@ -70,6 +70,7 @@ namespace OpenXmlContentTypes
static const TCHAR* Png = _T("image/png");
static const TCHAR* Tiff = _T("image/tiff");
static const TCHAR* Wmf = _T("image/x-wmf");
static const TCHAR* Bmp = _T("image/bmp");
}
namespace WordprocessingMLContentTypes
......
......@@ -65,24 +65,11 @@ namespace DocFileFormat
{
ConversionContext context( doc, docx );
//Write numbering.xml
if (doc->listTable)
{
NumberingMapping numberingMapping( &context );
doc->listTable->Convert( &numberingMapping );
}
if ( progress != NULL )
{
progress->OnProgress( progress->caller, DOC_ONPROGRESSEVENT_ID, 810000 );
short cancel = 0;
progress->OnProgressEx( progress->caller, DOC_ONPROGRESSEVENT_ID, 810000, &cancel );
if ( cancel != 0 )
//Write styles.xml
if (doc->Styles)
{
return S_FALSE;
}
StyleSheetMapping styleSheetMapping( &context );
doc->Styles->Convert( &styleSheetMapping );
}
//write document.xml and the header and footers
......@@ -91,10 +78,10 @@ namespace DocFileFormat
if ( progress != NULL )
{
progress->OnProgress( progress->caller, DOC_ONPROGRESSEVENT_ID, 825000 );
progress->OnProgress( progress->caller, DOC_ONPROGRESSEVENT_ID, 810000 );
short cancel = 0;
progress->OnProgressEx( progress->caller, DOC_ONPROGRESSEVENT_ID, 825000, &cancel );
progress->OnProgressEx( progress->caller, DOC_ONPROGRESSEVENT_ID, 810000, &cancel );
if ( cancel != 0 )
{
......@@ -102,11 +89,12 @@ namespace DocFileFormat
}
}
//Write styles.xml
if (doc->Styles)
//Write numbering.xml
if (doc->listTable)
{
StyleSheetMapping styleSheetMapping( &context );
doc->Styles->Convert( &styleSheetMapping );
NumberingMapping numberingMapping( &context );
doc->listTable->Convert( &numberingMapping );
}
if ( progress != NULL )
......
......@@ -142,6 +142,7 @@ namespace DocFileFormat
int _footnoteNr;
int _endnoteNr;
int _commentNr;
bool _isTextBoxContent;
int _isSectionPageBreak; //0 - not set, 1 -page break, 2 - continues
bool _writeInstrText;
bool _writeWebHidden;
......
/*
* (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
*
*/
#include "DrawingPrimitives.h"
#include "VirtualStreamReader.h"
namespace DocFileFormat
{
DrawingPrimitive * DrawingPrimitive::Create(VirtualStreamReader* reader, int length, short dpk)
{
DrawingPrimitive * dp = NULL;
int pos1 = reader->GetPosition();
switch(dpk)
{
case 0x0000:
dp = new DrawingPrimitiveGroup(reader, length, true);
break;
case 0x0001:
dp = new DrawingPrimitiveLine(reader, length);
break;
case 0x0002: //textbox
dp = new DrawingPrimitiveTextBox(reader, length);
break;
case 0x0003: //rectangle
dp = new DrawingPrimitiveRect(reader, length);
break;
case 0x0004: //elipse
dp = new DrawingPrimitiveElipse(reader, length);
break;
case 0x0005: //arc
dp = new DrawingPrimitiveArc(reader, length);
break;
case 0x0006: //polyline
dp = new DrawingPrimitivePolyline(reader, length);
break;
case 0x0007: //callout textbox
dp = new DrawingPrimitiveCTextBox(reader, length);
break;
case 0x0008: //callout textbox
dp = new DrawingPrimitiveGroup(reader, length, false);
break;
case 0x0009: //sample primitive holding default values
default:
dp = new DrawingPrimitive(reader, length);
break;
}
if (dp)
{
dp->type = dpk;
}
int pos2 = reader->GetPosition();
if (pos2 - pos1 < length && dpk != 0 && dpk != 8)
{
int sz = length - (pos2 - pos1);
unsigned char * data = reader->ReadBytes(sz, true);
if (data)
delete []data;
}
return dp;
}
DrawingPrimitive::DrawingPrimitive(VirtualStreamReader *reader, int length) :
lineWeight(0), lineStyle(0), lineColor(0), fillBack(0), fillFore(0), fillPattern(0), shadowX(0), shadowY(0)
{
xa = reader->ReadInt16();
ya = reader->ReadInt16();
dxa = reader->ReadInt16();
dya = reader->ReadInt16();
}
void DrawingPrimitive::read_fill(VirtualStreamReader* reader)
{
fillBack = read_color(reader);
fillFore = read_color(reader);
fillPattern = reader->ReadInt16();
}
void DrawingPrimitive::read_shadow(VirtualStreamReader* reader)
{
shadowInt = reader->ReadInt16();
shadowX = reader->ReadInt16();
shadowY = reader->ReadInt16();
}
void DrawingPrimitive::read_line(VirtualStreamReader* reader)
{
lineColor = read_color(reader);
lineWeight = reader->ReadInt16();
lineStyle = reader->ReadInt16();
}
long DrawingPrimitive::read_color(VirtualStreamReader* reader)
{
//int ind = reader->ReadUInt32();
//return shemeDefaultColor[ind];
unsigned r = reader->ReadByte();
unsigned g = reader->ReadByte();
unsigned b = reader->ReadByte();
unsigned a = reader->ReadByte();
return ( (r<<16) | (g<<8) | (b) );
}
DrawingPrimitiveGroup::DrawingPrimitiveGroup(VirtualStreamReader *reader, int length, bool start) : DrawingPrimitive(reader, length)
{
strVmlType = L"v:group";
bStart = start;
val = reader->ReadInt16();
}
DrawingPrimitiveLine::DrawingPrimitiveLine(VirtualStreamReader *reader, int length, bool read_as_line) : DrawingPrimitive(reader, length)
{
strVmlType = L"v:line";
if (!read_as_line) return;
read_start_end (reader);
read_line(reader);
read_epp(reader);
read_shadow(reader);
}
void DrawingPrimitiveLine::read_epp(VirtualStreamReader* reader)
{
unsigned short f = reader->ReadUInt16();
eppsStart = FormatUtils::BitmaskToInt (f, 0x0003);
eppwStart = FormatUtils::BitmaskToInt (f, 0x000c);
epplStart = FormatUtils::BitmaskToInt (f, 0x0030);
f = reader->ReadUInt16();
eppsEnd = FormatUtils::BitmaskToInt (f, 0x0003);
eppwEnd = FormatUtils::BitmaskToInt (f, 0x000c);
epplEnd = FormatUtils::BitmaskToInt (f, 0x0030);
}
void DrawingPrimitiveLine::read_start_end(VirtualStreamReader* reader)
{
xaStart = reader->ReadInt16();
yaStart = reader->ReadInt16();
xaEnd = reader->ReadInt16();
yaEnd = reader->ReadInt16();
}
DrawingPrimitiveRect::DrawingPrimitiveRect(VirtualStreamReader *reader, int length) : DrawingPrimitive(reader, length)
{
strVmlType = L"v:rect";
read_line(reader);
read_fill(reader);
read_shadow(reader);
unsigned short f = reader->ReadUInt16();
fRoundCorners = FormatUtils::BitmaskToInt (f, 0x0001);
zaShape = FormatUtils::BitmaskToInt (f, 0x000e);
}
DrawingPrimitiveArc::DrawingPrimitiveArc(VirtualStreamReader *reader, int length) : DrawingPrimitive(reader, length)
{
strVmlType = L"v:oval";//L"v:shape";
read_line (reader);
read_fill (reader);
read_shadow (reader);
unsigned short f = reader->ReadUInt16();
fLeft = FormatUtils::BitmaskToInt (f, 0x00ff);
fUp = FormatUtils::BitmaskToInt (f, 0xff00);
}
DrawingPrimitiveElipse::DrawingPrimitiveElipse(VirtualStreamReader *reader, int length) : DrawingPrimitive(reader, length)
{
strVmlType = L"v:oval";
read_line (reader);
read_fill (reader);
read_shadow (reader);
}
DrawingPrimitiveTextBox::DrawingPrimitiveTextBox(VirtualStreamReader *reader, int length) : DrawingPrimitiveRect(reader, length)
{
}
DrawingPrimitiveCTextBox::DrawingPrimitiveCTextBox(VirtualStreamReader *reader, int length) : DrawingPrimitive(reader, length)
{
strVmlType = L"v:rect";
txbx = NULL;
polyline = NULL;
unsigned short f = reader->ReadUInt16();
dzaOffset = reader->ReadUInt16();
dzaDescent = reader->ReadUInt16();
dzaLength = reader->ReadUInt16();
unsigned short dpk_txbx = reader->ReadUInt16();
unsigned short cb_txbx = reader->ReadUInt16();
txbx = new DrawingPrimitiveTextBox(reader, cb_txbx);
unsigned short dpk_polyline = reader->ReadUInt16();
unsigned short cb_polyline = reader->ReadUInt16();
polyline = new DrawingPrimitivePolyline(reader, cb_polyline);
}
DrawingPrimitiveCTextBox::~DrawingPrimitiveCTextBox()
{
if (polyline) delete polyline;
if (txbx) delete txbx;
}
DrawingPrimitivePolyline::DrawingPrimitivePolyline(VirtualStreamReader *reader, int length) : DrawingPrimitiveLine(reader, length, false)
{
strVmlType = L"v:shape";
read_line(reader);
read_fill(reader);
read_epp(reader);
read_shadow(reader);
unsigned short f = reader->ReadUInt16();
fPolygon = FormatUtils::BitmaskToInt (f, 0x0001);
count = FormatUtils::BitmaskToInt (f, 0x00fe);
read_start_end(reader);
for (int i = 0; i < count; i++)
{
std::pair<short, short> point;
point.first = reader->ReadInt16();
point.second = reader->ReadInt16();
arPoints.push_back(point);
}
}
}
/*
* (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
#include <string>
#include <vector>
#include "IVisitable.h"
class VirtualStreamReader;
namespace DocFileFormat
{
class DrawingPrimitive
{
public:
DrawingPrimitive(VirtualStreamReader* reader, int length) ;
virtual ~DrawingPrimitive() {}
short type;
short xa;
short ya;
short dxa;
short dya;
short lineWeight;
short lineStyle;
long lineColor;
long fillBack;
long fillFore;
short fillPattern;
short shadowInt;
short shadowX;
short shadowY;
std::wstring strVmlType;
void read_fill (VirtualStreamReader* reader);
void read_line (VirtualStreamReader* reader);
void read_shadow(VirtualStreamReader* reader);
long read_color (VirtualStreamReader* reader);
static DrawingPrimitive * Create(VirtualStreamReader* reader, int length, short dpk);
};
class DrawingPrimitiveGroup : public DrawingPrimitive
{
public:
DrawingPrimitiveGroup(VirtualStreamReader* reader, int length, bool start);
bool bStart;
short val;
};
class DrawingPrimitiveLine : public DrawingPrimitive
{
public:
DrawingPrimitiveLine(VirtualStreamReader* reader, int length, bool read_as_line = true) ;
void read_epp ( VirtualStreamReader* reader);
void read_start_end (VirtualStreamReader* reader);
short xaStart;
short yaStart;
short xaEnd;
short yaEnd;
short eppsStart; //Start EndPoint Property Style
short eppwStart; //Start EndPoint Property Weight
short epplStart; //Start EndPoint Property length
short eppsEnd; //End EndPoint Property Style
short eppwEnd; //End EndPoint Property Weight
short epplEnd; //End EndPoint Property length
};
class DrawingPrimitiveRect: public DrawingPrimitive
{
public:
DrawingPrimitiveRect(VirtualStreamReader* reader, int length);
bool fRoundCorners;
unsigned short zaShape;
};
class DrawingPrimitiveTextBox: public DrawingPrimitiveRect
{
public:
DrawingPrimitiveTextBox(VirtualStreamReader* reader, int length);
};
class DrawingPrimitiveElipse: public DrawingPrimitive
{
public:
DrawingPrimitiveElipse(VirtualStreamReader* reader, int length);
};
class DrawingPrimitivePolyline: public DrawingPrimitiveLine
{
public:
DrawingPrimitivePolyline(VirtualStreamReader* reader, int length);
bool fPolygon;
short count;
std::vector<std::pair<short, short>> arPoints;
};
class DrawingPrimitiveCTextBox: public DrawingPrimitive
{
public:
DrawingPrimitiveCTextBox(VirtualStreamReader* reader, int length);
virtual ~DrawingPrimitiveCTextBox();
unsigned short dzaOffset;
unsigned short dzaDescent;
unsigned short dzaLength;
DrawingPrimitiveTextBox *txbx;
DrawingPrimitivePolyline *polyline;
};
class DrawingPrimitiveArc: public DrawingPrimitive
{
public:
DrawingPrimitiveArc(VirtualStreamReader* reader, int length);
bool fLeft;
bool fUp;
};
//-------------------------------------------------------------------------------------
class DrawingPrimitives : public IVisitable, public std::vector<DrawingPrimitive*>
{
public:
DrawingPrimitives () {}
};
}
\ No newline at end of file
......@@ -49,46 +49,120 @@ namespace DocFileFormat
if(0x0001 == vMajor) // RC4 encryption header structure
{// fib->m_FibBase.lKey == 52
crypt_data.Salt.b1 = tStream.ReadUInt32();
crypt_data.Salt.b2 = tStream.ReadUInt32();
crypt_data.Salt.b3 = tStream.ReadUInt32();
crypt_data.Salt.b4 = tStream.ReadUInt32();
crypt_data.EncryptedVerifier.b1 = tStream.ReadUInt32();
crypt_data.EncryptedVerifier.b2 = tStream.ReadUInt32();
crypt_data.EncryptedVerifier.b3 = tStream.ReadUInt32();
crypt_data.EncryptedVerifier.b4 = tStream.ReadUInt32();
crypt_data.EncryptedVerifierHash.b1 = tStream.ReadUInt32();
crypt_data.EncryptedVerifierHash.b2 = tStream.ReadUInt32();
crypt_data.EncryptedVerifierHash.b3 = tStream.ReadUInt32();
crypt_data.EncryptedVerifierHash.b4 = tStream.ReadUInt32();
bStandard = true;
crypt_data_rc4.Salt.b1 = tStream.ReadUInt32();
crypt_data_rc4.Salt.b2 = tStream.ReadUInt32();
crypt_data_rc4.Salt.b3 = tStream.ReadUInt32();
crypt_data_rc4.Salt.b4 = tStream.ReadUInt32();
crypt_data_rc4.EncryptedVerifier.b1 = tStream.ReadUInt32();
crypt_data_rc4.EncryptedVerifier.b2 = tStream.ReadUInt32();
crypt_data_rc4.EncryptedVerifier.b3 = tStream.ReadUInt32();
crypt_data_rc4.EncryptedVerifier.b4 = tStream.ReadUInt32();
crypt_data_rc4.EncryptedVerifierHash.b1 = tStream.ReadUInt32();
crypt_data_rc4.EncryptedVerifierHash.b2 = tStream.ReadUInt32();
crypt_data_rc4.EncryptedVerifierHash.b3 = tStream.ReadUInt32();
crypt_data_rc4.EncryptedVerifierHash.b4 = tStream.ReadUInt32();
}
else
{
// unsigned short flags = tStream.ReadUInt16();
// bool fCryptoAPI = GETBIT(flags, 2);
// bool fDocProps = GETBIT(flags, 3);
// bool fExternal = GETBIT(flags, 4);
// bool fAES = GETBIT(flags, 5);
// _UINT32 EncryptionHeaderSize = tStream.ReadUInt32();
////header
//
// tStream.ReadUInt32(); // reserved (SizeExtra)
// _INT32 AlgID = tStream.ReadInt32();
// _INT32 AlgIDHash = tStream.ReadInt32();
// _UINT32 KeySize = tStream.ReadUInt32();
// _UINT32 ProviderType = tStream.ReadUInt32();
// tStream.ReadUInt32();
// tStream.ReadUInt32(); // reserved
//
// //std::wstring CSPName;
// //record >> CSPName;
//// + crypt_data
bStandard = false;
crypt_data_aes.bAgile = false;
unsigned short flags = tStream.ReadUInt32();
unsigned char *pDataRead = NULL;
bool fCryptoAPI = GETBIT(flags, 1);
bool fDocProps = GETBIT(flags, 2);
bool fExternal = GETBIT(flags, 3);
bool fAES = GETBIT(flags, 4);
//EncryptionHeader
int HeaderSize = tStream.ReadUInt32();
int Flags = tStream.ReadUInt32();
int SizeExtra = tStream.ReadUInt32();
int AlgID = tStream.ReadUInt32();
int AlgIDHash = tStream.ReadUInt32();
int KeySize = tStream.ReadUInt32();
int ProviderType= tStream.ReadUInt32();
int Reserved1 = tStream.ReadUInt32();
int Reserved2 = tStream.ReadUInt32();
int pos = tStream.GetPosition();
int size = tStream.GetSize();
std::vector<char> dataCSPName;
while(pos < size - 1)
{
dataCSPName.push_back(tStream.ReadByte());
dataCSPName.push_back(tStream.ReadByte());
if (dataCSPName[dataCSPName.size() - 1] == 0 && dataCSPName[dataCSPName.size() - 2] == 0)
{
break;
}
pos+=2;//unicode null-terminate string
}
//EncryptionVerifier
crypt_data_aes.saltSize = tStream.ReadUInt32();
pDataRead = tStream.ReadBytes(crypt_data_aes.saltSize, true);
if (pDataRead)
{
crypt_data_aes.saltValue = std::string((char*)pDataRead, crypt_data_aes.saltSize);
delete pDataRead;
}
pDataRead = tStream.ReadBytes(0x10, true);
if (pDataRead)
{
crypt_data_aes.encryptedVerifierInput = std::string((char*)pDataRead, 0x10);
delete pDataRead;
}
crypt_data_aes.hashSize = tStream.ReadUInt32();
int szEncryptedVerifierHash = (ProviderType == 0x0001) ? 0x14 : 0x20;
pDataRead = tStream.ReadBytes(szEncryptedVerifierHash, true);
if (pDataRead)
{
crypt_data_aes.encryptedVerifierValue = std::string((char*)pDataRead, szEncryptedVerifierHash);
delete pDataRead;
}
pos = tStream.GetPosition();
//------------------------------------------------------------------------------------------
crypt_data_aes.hashAlgorithm = CRYPT_METHOD::SHA1; //by AlgIDHash -> 0x0000 || 0x8004
crypt_data_aes.spinCount = 50000;
switch(AlgID)
{
case 0x6801:
crypt_data_aes.cipherAlgorithm = CRYPT_METHOD::RC4;
crypt_data_aes.keySize = KeySize / 8;
break;
case 0x660E:
crypt_data_aes.cipherAlgorithm = CRYPT_METHOD::AES_ECB;
crypt_data_aes.keySize = 128 /8;
break;
case 0x660F:
crypt_data_aes.cipherAlgorithm = CRYPT_METHOD::AES_ECB;
crypt_data_aes.keySize = 192 /8;
break;
case 0x6610:
crypt_data_aes.cipherAlgorithm = CRYPT_METHOD::AES_ECB;
crypt_data_aes.keySize = 256 /8;
break;
}
switch(ProviderType)
{
case 0x0001: crypt_data_aes.cipherAlgorithm = CRYPT_METHOD::RC4; break;
case 0x0018: crypt_data_aes.cipherAlgorithm = CRYPT_METHOD::AES_ECB; break;
}
}
//RELEASEARRAYOBJECTS( bytes );
......
......@@ -32,6 +32,7 @@
#pragma once
#include "FileInformationBlock.h"
#include "../../OfficeCryptReader/source/CryptTransform.h"
#include "IVisitable.h"
......@@ -49,6 +50,8 @@ namespace DocFileFormat
EncryptionHeader( FileInformationBlock* fib, POLE::Stream* tableStream );
private:
CRYPT::CryptRC4Data crypt_data;
CRYPT::CryptRC4Data crypt_data_rc4;
CRYPT::ECMADecryptor::_cryptData crypt_data_aes;
bool bStandard;
};
}
......@@ -509,7 +509,6 @@ namespace DocFileFormat
public:
bool m_bOlderVersion;
int m_CodePage;
CRYPT::DecryptorPtr m_Decryptor;
FibBase m_FibBase;
RgW97 m_RgW97;
......
......@@ -52,6 +52,7 @@ namespace DocFileFormat
friend class DocumentMapping;
friend class FontTableMapping;
friend class StyleSheetMapping;
friend class NumberingMapping;
private:
/// When true, font is a TrueType font
......
......@@ -65,7 +65,7 @@ namespace DocFileFormat
//this additional paragraph mark shall not be converted.
cpMax--;
while ( cp < cpMax )
while ( cp < cpMax && cp < (int)m_document->Text->size())
{
int fc = m_document->FindFileCharPos(cp);
if (fc < 0) break;
......
......@@ -179,7 +179,7 @@ namespace DocFileFormat
//there are n offsets and n-1 fkp's in the bin table
if (fib->m_FibBase.fComplex == false)
if (fib->m_bOlderVersion && fib->m_FibBase.fComplex == false)
{
int n = ( ( (int)fib->m_FibWord97.lcbPlcfBtePapx - 8 ) / 6 ) + 1;
......
......@@ -42,7 +42,7 @@ namespace DocFileFormat
if (fib->m_FibWord97.fcPlcfHdd > tableReader.GetSize()) return;
unsigned int tableSize = fib->m_FibWord97.lcbPlcfHdd / (fib->m_bOlderVersion ? 1: 4);
unsigned int tableSize = fib->m_FibWord97.lcbPlcfHdd / 4;//in bytes
if ( ( tableSize > 0 ) && ( fib->m_RgLw97.ccpHdr > 0 ) )
{
......@@ -53,13 +53,14 @@ namespace DocFileFormat
table[i] = tableReader.ReadInt32();
}
int count = ( tableSize - 8 ) / 6;
int initialPos = fib->m_RgLw97.ccpText + fib->m_RgLw97.ccpFtn;
//the first 6 _entries are about footnote and endnote formatting
//so skip these _entries
int pos = 6;
int pos = (fib->m_FibBase.fComplex || !fib->m_bOlderVersion) ? 6 : 0;
int count = ( tableSize - pos - 2) / 6;
for (int i = 0; i < count; ++i)
{
......@@ -123,7 +124,7 @@ namespace DocFileFormat
pos++;
if (pos > tableSize)
if (pos >= tableSize)
break;
//First Page Footers
......
......@@ -65,7 +65,7 @@ namespace DocFileFormat
//this additional paragraph mark shall not be converted.
cpMax--;
while ( cp < cpMax )
while ( cp < cpMax && cp < (int)m_document->Text->size())
{
int fc = m_document->FindFileCharPos(cp);
if (fc < 0) break;
......
......@@ -49,8 +49,6 @@ namespace DocFileFormat
/// 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 );
......@@ -58,10 +56,11 @@ namespace DocFileFormat
{
fMultLinespace = true;
}
}
else
if ( size > 4 )
{
}
}
};
}
\ No newline at end of file
......@@ -33,6 +33,9 @@
#include "ListData.h"
#include <algorithm>
#include <functional>
#include <cctype>
#include <locale>
namespace DocFileFormat
{
......@@ -41,44 +44,152 @@ namespace DocFileFormat
for_each(rglvl->begin(), rglvl->end(), DeleteDynamicObject());
RELEASEOBJECT(rglvl);
RELEASEARRAYOBJECTS(_rawBytes);
}
// Parses the StreamReader to retrieve a ListData
ListData::ListData(VirtualStreamReader* reader, int length) : rglvl(NULL), _rawBytes(NULL)
ListData::ListData(VirtualStreamReader* reader, int length) : rglvl(NULL)
{
long startPos = reader->GetPosition();
this->lsid = reader->ReadInt32();
this->tplc = reader->ReadInt32();
lsid = reader->ReadInt32();
tplc = reader->ReadInt32();
for ( int i = 0; i < 9; i++ )
{
this->rgistd.push_back( reader->ReadInt16() );
rgistd.push_back( reader->ReadInt16() );
}
//parse flagbyte
int flag = (int)reader->ReadByte();
this->fSimpleList = FormatUtils::BitmaskToBool( flag, 0x01 );
fSimpleList = FormatUtils::BitmaskToBool( flag, 0x01 );
if ( this->fSimpleList )
if ( fSimpleList )
{
this->rglvl = new std::vector<ListLevel*>( 1 );
rglvl = new std::vector<ListLevel*>( 1 );
}
else
{
this->rglvl = new std::vector<ListLevel*>( 9 );
rglvl = new std::vector<ListLevel*>( 9 );
}
this->fRestartHdn = FormatUtils::BitmaskToBool( flag, 0x02 );
this->fAutoNum = FormatUtils::BitmaskToBool( flag, 0x04 );
this->fPreRTF = FormatUtils::BitmaskToBool( flag, 0x08 );
this->fHybrid = FormatUtils::BitmaskToBool( flag, 0x10 );
fRestartHdn = FormatUtils::BitmaskToBool( flag, 0x02 );
fAutoNum = FormatUtils::BitmaskToBool( flag, 0x04 );
fPreRTF = FormatUtils::BitmaskToBool( flag, 0x08 );
fHybrid = FormatUtils::BitmaskToBool( flag, 0x10 );
this->grfhic = reader->ReadByte();
grfhic = reader->ReadByte();
}
NumberingDescriptor::NumberingDescriptor( unsigned char * data, int length )
{
nfc = FormatUtils::BytesToUChar(data, 0, length);
cbTextBefore = FormatUtils::BytesToUChar(data, 1, length);
cbTextAfter = FormatUtils::BytesToUChar(data, 2, length);
int flag = FormatUtils::BytesToUChar(data, 3, length);
jc = (unsigned char)( flag & 0x03 );
fPrev = FormatUtils::BitmaskToBool( flag, 0x04 );
fHang = FormatUtils::BitmaskToBool( flag, 0x08 );
fSetBold = FormatUtils::BitmaskToBool( flag, 0x10 );
fSetItalic = FormatUtils::BitmaskToBool( flag, 0x20 );
fSetSmallCaps = FormatUtils::BitmaskToBool( flag, 0x40 );
fSetCaps = FormatUtils::BitmaskToBool( flag, 0x80 );
flag = FormatUtils::BytesToUChar(data, 4, length);;
fSetStrike = FormatUtils::BitmaskToBool( flag, 0x01 );
fSetKul = FormatUtils::BitmaskToBool( flag, 0x02 );
fPrevSpace = FormatUtils::BitmaskToBool( flag, 0x04 );
fBold = FormatUtils::BitmaskToBool( flag, 0x08 );
fItalic = FormatUtils::BitmaskToBool( flag, 0x10 );
fSmallCaps = FormatUtils::BitmaskToBool( flag, 0x20 );
fCaps = FormatUtils::BitmaskToBool( flag, 0x40 );
fStrike = FormatUtils::BitmaskToBool( flag, 0x80 );
flag = FormatUtils::BytesToUChar(data, 5, length);
reader->Seek( startPos, 0/*STREAM_SEEK_SET */);
_rawBytes = reader->ReadBytes( LSTF_LENGTH, true );
kul = FormatUtils::BitmaskToBool( flag, 0x07 );//3 bit
ico = FormatUtils::BitmaskToBool( flag, 0xf1 );//5 bit
ftc = FormatUtils::BytesToInt16 (data, 6, length);
ftc = ftc & 0x0fff; // 0x8001 ???? file(31).doc
hps = FormatUtils::BytesToUInt16(data, 8, length);
iStartAt = FormatUtils::BytesToUInt16(data, 10, length);
dxaIndent = FormatUtils::BytesToUInt16(data, 12, length);
dxaSpace = FormatUtils::BytesToUInt16(data, 14, length);
fNumber1 = FormatUtils::BytesToUChar(data, 16, length);
fNumberAcross = FormatUtils::BytesToUChar(data, 17, length);
fRestartHdn = FormatUtils::BytesToUChar(data, 18, length);
fSpareX = FormatUtils::BytesToUChar(data, 19, length);
// fixed size = 20
//read the number text
short strLen = length - 20;
while (strLen > 0)
{
if (data[strLen + 20 - 1] != 0)
break;
strLen--;
}
if (strLen > 0)
{
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &(xst), data + 20, ( strLen ), ENCODING_WINDOWS_1250);
}
}
OutlineListDescriptor::~OutlineListDescriptor()
{
for (int i = 0 ; i < 9; i++)
{
if (lvl[i]) delete lvl[i];
lvl[i] = NULL;
}
}
OutlineListDescriptor::OutlineListDescriptor( unsigned char * data, int length )
{
int pos = 0;
for (int i = 0 ; i < 9; i++)
{
lvl[i] = new NumberingLevelDescriptor(data + pos, length - pos);
pos += 16;
}
fRestartHdr = FormatUtils::BytesToUChar(data, pos, length); pos += 2;
fSpareOlst2 = FormatUtils::BytesToUChar(data, pos, length); pos += 2;
fSpareOlst3 = FormatUtils::BytesToUChar(data, pos, length); pos += 2;
fSpareOlst4 = FormatUtils::BytesToUChar(data, pos, length); pos += 2;
short strLen = length - pos;
while (strLen > 0)
{
if (data[strLen + 20 - 1] != 0)
break;
strLen--;
}
if (strLen > 0)
{
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &(xst), data + 20, ( strLen ), ENCODING_WINDOWS_1250);
}
}
ByteStructure* OutlineListDescriptor::ConstructObject(VirtualStreamReader* reader, int length)
{
unsigned char *data = reader->ReadBytes(212, true);
OutlineListDescriptor *newObject = new OutlineListDescriptor(data, 212);
delete []data;
return static_cast<ByteStructure*>(newObject);
}
}
......@@ -32,6 +32,7 @@
#pragma once
#include "ListLevel.h"
#include "ByteStructure.h"
namespace DocFileFormat
{
......@@ -65,7 +66,6 @@ namespace DocFileFormat
std::vector<ListLevel*>* rglvl;
/// A grfhic that specifies HTML incompatibilities of the list.
unsigned char grfhic;
unsigned char* _rawBytes;
public:
static const int LSTF_LENGTH = 28;
......@@ -73,7 +73,83 @@ namespace DocFileFormat
static const int VARIABLE_LENGTH = INT_MAX;
virtual ~ListData();
/// Parses the StreamReader to retrieve a ListData
ListData( VirtualStreamReader* reader, int length );
};
class NumberingDescriptor : public IVisitable
{
friend class ListTable;
friend class NumberingMapping;
private:
unsigned char nfc;
unsigned char cbTextBefore;
unsigned char cbTextAfter;
unsigned char jc;
bool fPrev;
bool fHang;
bool fSetBold;
bool fSetItalic;
bool fSetSmallCaps;
bool fSetCaps;
bool fSetStrike;
bool fSetKul;
bool fPrevSpace;
bool fBold;
bool fItalic;
bool fSmallCaps;
bool fCaps;
bool fStrike;
unsigned char kul;
unsigned char ico;
short ftc;
unsigned short hps;
unsigned short iStartAt;
unsigned short dxaIndent;
unsigned short dxaSpace;
unsigned char fNumber1;
unsigned char fNumberAcross;
unsigned char fRestartHdn;
unsigned char fSpareX;
std::wstring xst; //32 chars ansi
public:
virtual ~NumberingDescriptor(){}
// Parses the given StreamReader to retrieve a ANLD struct
NumberingDescriptor( unsigned char * data, int length ); //cbANLD (count of bytes of ANLD) is 52
};
class OutlineListDescriptor : public IVisitable, public ByteStructure
{
friend class ListTable;
friend class NumberingMapping;
private:
NumberingLevelDescriptor *lvl[9];
unsigned char fRestartHdr;
unsigned char fSpareOlst2;
unsigned char fSpareOlst3;
unsigned char fSpareOlst4;
std::wstring xst; //64 chars ansi
public:
static const int STRUCTURE_SIZE = 212;
virtual ByteStructure* ConstructObject( VirtualStreamReader* reader, int length );
virtual ~OutlineListDescriptor();
// Parses the given StreamReader to retrieve a OLST struct
OutlineListDescriptor( unsigned char * data, int length ); //cbOLST(count of bytes of OLST) is 212
OutlineListDescriptor() {}
};
}
\ No newline at end of file
......@@ -36,62 +36,56 @@ namespace DocFileFormat
{
ListLevel::~ListLevel()
{
RELEASEOBJECT( this->grpprlPapx );
RELEASEOBJECT( this->grpprlChpx );
RELEASEARRAYOBJECTS( this->_rawBytes );
RELEASEOBJECT( grpprlPapx );
RELEASEOBJECT( grpprlChpx );
}
/*========================================================================================================*/
/// Parses the given StreamReader to retrieve a LVL struct
ListLevel::ListLevel( VirtualStreamReader* reader, int length ):
grpprlPapx(NULL), grpprlChpx(NULL), _rawBytes(NULL)
grpprlPapx(NULL), grpprlChpx(NULL)
{
long startPos = reader->GetPosition();
//parse the fix part
this->iStartAt = reader->ReadInt32();
this->nfc = reader->ReadByte();
iStartAt = reader->ReadInt32();
nfc = reader->ReadByte();
int flag = reader->ReadByte();
this->jc = (unsigned char)( flag & 0x03 );
this->fLegal = FormatUtils::BitmaskToBool( flag, 0x04 );
this->fNoRestart = FormatUtils::BitmaskToBool( flag, 0x08 );
this->fPrev = FormatUtils::BitmaskToBool( flag, 0x10 );
this->fPrevSpace = FormatUtils::BitmaskToBool( flag, 0x20 );
this->fWord6 = FormatUtils::BitmaskToBool( flag, 0x40 );
jc = (unsigned char)( flag & 0x03 );
fLegal = FormatUtils::BitmaskToBool( flag, 0x04 );
fNoRestart = FormatUtils::BitmaskToBool( flag, 0x08 );
fPrev = FormatUtils::BitmaskToBool( flag, 0x10 );
fPrevSpace = FormatUtils::BitmaskToBool( flag, 0x20 );
fWord6 = FormatUtils::BitmaskToBool( flag, 0x40 );
for ( int i = 0; i < 9; i++ )
{
rgbxchNums.push_back( reader->ReadByte() );
}
this->ixchFollow = (FollowingChar)reader->ReadByte();
ixchFollow = (FollowingChar)reader->ReadByte();
this->dxaSpace = reader->ReadInt32();
this->dxaIndent = reader->ReadInt32();
dxaSpace = reader->ReadInt32();
dxaIndent = reader->ReadInt32();
this->cbGrpprlChpx = reader->ReadByte();
this->cbGrpprlPapx = reader->ReadByte();
cbGrpprlChpx = reader->ReadByte();
cbGrpprlPapx = reader->ReadByte();
this->ilvlRestartLim = reader->ReadByte();
this->grfhic = reader->ReadByte();
ilvlRestartLim = reader->ReadByte();
grfhic = reader->ReadByte();
//parse the variable part
//read the group of papx sprms
//this papx has no istd, so use PX to parse it
unsigned char *bytes = reader->ReadBytes( this->cbGrpprlPapx, true );
unsigned char *bytes = reader->ReadBytes( cbGrpprlPapx, true );
PropertyExceptions* px = new PropertyExceptions( bytes, this->cbGrpprlPapx, reader->olderVersion);
this->grpprlPapx = new ParagraphPropertyExceptions( *(px->grpprl) );
PropertyExceptions* px = new PropertyExceptions( bytes, cbGrpprlPapx, reader->olderVersion);
grpprlPapx = new ParagraphPropertyExceptions( *(px->grpprl) );
RELEASEOBJECT( px );
RELEASEARRAYOBJECTS( bytes );
//read the group of chpx sprms
bytes = reader->ReadBytes( this->cbGrpprlChpx, true );
this->grpprlChpx = new CharacterPropertyExceptions( bytes, this->cbGrpprlChpx, reader->olderVersion );
bytes = reader->ReadBytes( cbGrpprlChpx, true );
grpprlChpx = new CharacterPropertyExceptions( bytes, cbGrpprlChpx, reader->olderVersion );
RELEASEARRAYOBJECTS( bytes );
//read the number text
......@@ -99,12 +93,56 @@ namespace DocFileFormat
if (strLen > 0)//file(14).doc
{
bytes = reader->ReadBytes( ( strLen * 2 ), true );
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &(this->xst), bytes, ( strLen * 2 ), ENCODING_UTF16 );
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &(xst), bytes, ( strLen * 2 ), ENCODING_UTF16 );
RELEASEARRAYOBJECTS( bytes );
}
}
long endPos = reader->GetPosition();
reader->Seek( startPos, 0/*STREAM_SEEK_SET*/ );
_rawBytes = reader->ReadBytes( (int)( endPos - startPos ), true );
NumberingLevelDescriptor::~NumberingLevelDescriptor()
{
}
NumberingLevelDescriptor::NumberingLevelDescriptor( unsigned char * data, int length )
{
nfc = FormatUtils::BytesToUChar(data, 0, length);
cbTextBefore = FormatUtils::BytesToUChar(data, 1, length);
cbTextAfter = FormatUtils::BytesToUChar(data, 2, length);
int flag = FormatUtils::BytesToUChar(data, 3, length);
jc = (unsigned char)( flag & 0x03 );
fPrev = FormatUtils::BitmaskToBool( flag, 0x04 );
fHang = FormatUtils::BitmaskToBool( flag, 0x08 );
fSetBold = FormatUtils::BitmaskToBool( flag, 0x10 );
fSetItalic = FormatUtils::BitmaskToBool( flag, 0x20 );
fSetSmallCaps = FormatUtils::BitmaskToBool( flag, 0x40 );
fSetCaps = FormatUtils::BitmaskToBool( flag, 0x80 );
flag = FormatUtils::BytesToUChar(data, 4, length);;
fSetStrike = FormatUtils::BitmaskToBool( flag, 0x01 );
fSetKul = FormatUtils::BitmaskToBool( flag, 0x02 );
fPrevSpace = FormatUtils::BitmaskToBool( flag, 0x04 );
fBold = FormatUtils::BitmaskToBool( flag, 0x08 );
fItalic = FormatUtils::BitmaskToBool( flag, 0x10 );
fSmallCaps = FormatUtils::BitmaskToBool( flag, 0x20 );
fCaps = FormatUtils::BitmaskToBool( flag, 0x40 );
fStrike = FormatUtils::BitmaskToBool( flag, 0x80 );
flag = FormatUtils::BytesToUChar(data, 5, length);
kul = FormatUtils::BitmaskToBool( flag, 0x07 );//3 bit
ico = FormatUtils::BitmaskToBool( flag, 0xf1 );//5 bit
ftc = FormatUtils::BytesToInt16 (data, 6, length);
hps = FormatUtils::BytesToUInt16(data, 8, length);
iStartAt = FormatUtils::BytesToUInt16(data, 10, length);
dxaIndent = FormatUtils::BytesToUInt16(data, 12, length);
dxaSpace = FormatUtils::BytesToUInt16(data, 14, length);
}
}
......@@ -101,11 +101,48 @@ namespace DocFileFormat
CharacterPropertyExceptions* grpprlChpx;
std::wstring xst;
unsigned char* _rawBytes;
public:
virtual ~ListLevel();
/// Parses the given StreamReader to retrieve a LVL struct
// Parses the given StreamReader to retrieve a LVL struct
ListLevel( VirtualStreamReader* reader, int length );
};
class NumberingLevelDescriptor
{
friend class NumberingMapping;
private:
unsigned char nfc;
unsigned char cbTextBefore;
unsigned char cbTextAfter;
unsigned char jc;
bool fPrev;
bool fHang;
bool fSetBold;
bool fSetItalic;
bool fSetSmallCaps;
bool fSetCaps;
bool fSetStrike;
bool fSetKul;
bool fPrevSpace;
bool fBold;
bool fItalic;
bool fSmallCaps;
bool fCaps;
bool fStrike;
unsigned char kul;
unsigned char ico;
short ftc;
unsigned short hps;
unsigned short iStartAt;
unsigned short dxaIndent;
unsigned short dxaSpace;
public:
virtual ~NumberingLevelDescriptor();
// Parses the given StreamReader to retrieve a ANLV struct
NumberingLevelDescriptor( unsigned char * data, int length ); //cbANLV is 16 bytes
};
}
\ No newline at end of file
......@@ -72,4 +72,10 @@ namespace DocFileFormat
}
}
}
void ListTable::appendNumbering( const NumberingDescriptor & desc )
{
listNumbering.push_back(desc);
}
}
\ No newline at end of file
......@@ -42,8 +42,11 @@ namespace DocFileFormat
{
public:
std::list<ListData*> listData;
std::list<NumberingDescriptor> listNumbering;
virtual ~ListTable();
ListTable( FileInformationBlock* fib, POLE::Stream* tableStream );
void appendNumbering( const NumberingDescriptor & desc );
};
}
\ No newline at end of file
......@@ -32,6 +32,7 @@
#pragma once
#include "IBinaryReader.h"
#include "../Common/FormatUtils.h"
class MemoryStream: public IBinaryReader
{
......
......@@ -62,17 +62,24 @@ namespace DocFileFormat
public:
NumberingMapping(ConversionContext* ctx);
void Apply(IVisitable* visited);
static int FindIndexbyId(const std::list<ListData*>& listData, int id);
/// Converts the number format code of the binary format.
static std::wstring GetNumberFormatWideString(int nfc);
static std::wstring GetNumberFormatWideString(int nfc, bool bOlderVersion = false);
virtual ~NumberingMapping();
private:
// Converts the number text of the binary format to the number text of OOXML.
// OOXML uses different placeholders for the numbers.
std::wstring GetLvlText(const ListLevel* lvl, bool bIsSymbol) const;
std::wstring GetLvlText(const NumberingDescriptor& lvl, bool bIsSymbol, int Before, int After) const;
static bool IsPlaceholder(wchar_t symbol);
void LevelMapping(const ListLevel* lvl, unsigned int level, short styleIndex);
void LevelMapping(const NumberingDescriptor& lvl, unsigned int level);
void PictureBulletsMapping();
void WriteLevelPictureBullet(const CharacterPropertyExceptions* grpprlChpx);
bool IsPictureBullet(const CharacterPropertyExceptions* grpprlChpx);
......
......@@ -70,6 +70,12 @@ public:
public:
CMetaHeader()
{
cbSize = cbSave = 0;
filter = compression = 0;
ptSize.x = ptSize.y = 0;
rcBounds.bottom = rcBounds.left = rcBounds.right = rcBounds.top = 0;
}
......@@ -300,11 +306,11 @@ typedef enum _BlipCompression
Record( _reader, size, typeCode, version, instance ), m_rgbUid(NULL), m_rgbUidPrimary(NULL), m_cb(0), m_cbSave(0),
m_fCompression(BlipCompressionNone), m_fFilter(false), m_pvBits(NULL)
{
this->m_rgbUid = this->Reader->ReadBytes( 16, true );
m_rgbUid = Reader->ReadBytes( 16, true );
if ( ( instance == 0x3D5 ) || ( instance == 0x217 ) || ( instance == 0x543 ) )
{
this->m_rgbUidPrimary = this->Reader->ReadBytes( 16, true );
m_rgbUidPrimary = Reader->ReadBytes( 16, true );
}
oMetaFile.m_bIsValid = TRUE;
......@@ -312,22 +318,22 @@ typedef enum _BlipCompression
CMetaHeader oMetaHeader;
this->m_cb = this->Reader->ReadInt32();
m_cb = Reader->ReadInt32();
this->m_rcBounds.left = this->Reader->ReadInt32();
this->m_rcBounds.top = this->Reader->ReadInt32();
this->m_rcBounds.right = this->Reader->ReadInt32() + this->m_rcBounds.left;
this->m_rcBounds.bottom = this->Reader->ReadInt32() + this->m_rcBounds.top;
m_rcBounds.left = Reader->ReadInt32();
m_rcBounds.top = Reader->ReadInt32();
m_rcBounds.right = Reader->ReadInt32() + m_rcBounds.left;
m_rcBounds.bottom = Reader->ReadInt32() + m_rcBounds.top;
this->m_ptSize.x = this->Reader->ReadInt32();
this->m_ptSize.y = this->Reader->ReadInt32();
m_ptSize.x = Reader->ReadInt32();
m_ptSize.y = Reader->ReadInt32();
this->m_cbSave = this->Reader->ReadInt32();
this->m_fCompression = (BlipCompression)this->Reader->ReadByte();
this->m_fFilter = ( this->Reader->ReadByte() == 1 ) ? (true) : (false);
m_cbSave = Reader->ReadInt32();
m_fCompression = (BlipCompression)Reader->ReadByte();
m_fFilter = ( Reader->ReadByte() == 1 ) ? (true) : (false);
int sz = Reader->GetSize() - Reader->GetPosition();
this->m_pvBits = this->Reader->ReadBytes( sz/*this->m_cbSave*/, true );
m_pvBits = Reader->ReadBytes( sz/*m_cbSave*/, true );
oMetaHeader.rcBounds = m_rcBounds;
oMetaHeader.cbSize = m_cb;
......@@ -369,9 +375,9 @@ typedef enum _BlipCompression
virtual ~MetafilePictBlip()
{
RELEASEARRAYOBJECTS( this->m_rgbUid );
RELEASEARRAYOBJECTS( this->m_rgbUidPrimary );
RELEASEARRAYOBJECTS( this->m_pvBits );
RELEASEARRAYOBJECTS( m_rgbUid );
RELEASEARRAYOBJECTS( m_rgbUidPrimary );
RELEASEARRAYOBJECTS( m_pvBits );
}
virtual Record* NewObject( IBinaryReader* _reader, unsigned int bodySize, unsigned int typeCode, unsigned int version, unsigned int instance )
......@@ -386,9 +392,9 @@ typedef enum _BlipCompression
unsigned long uncomprLen = 0;
if ( this->m_fCompression == BlipCompressionDeflate )
if ( m_fCompression == BlipCompressionDeflate )
{
uncomprLen = this->m_cb;
uncomprLen = m_cb;
*buffer = new unsigned char[uncomprLen];
HRESULT res = S_OK;
......@@ -396,19 +402,19 @@ typedef enum _BlipCompression
if (pOfficeUtils)
{
pOfficeUtils->Uncompress( *buffer, &uncomprLen, this->m_pvBits, this->m_cbSave );
pOfficeUtils->Uncompress( *buffer, &uncomprLen, m_pvBits, m_cbSave );
delete pOfficeUtils;
pOfficeUtils = NULL;
}
}
else if ( this->m_fCompression == BlipCompressionNone )
else if ( m_fCompression == BlipCompressionNone )
{
uncomprLen = this->m_cbSave;
uncomprLen = m_cbSave;
*buffer = new unsigned char[uncomprLen];
memcpy( *buffer, this->m_pvBits , this->m_cbSave );
memcpy( *buffer, m_pvBits , m_cbSave );
}
return uncomprLen;
......
......@@ -35,8 +35,8 @@ namespace DocFileFormat
{
Record::~Record()
{
RELEASEARRAYOBJECTS( this->RawData );
RELEASEOBJECT( this->Reader );
RELEASEARRAYOBJECTS( RawData );
RELEASEOBJECT( Reader );
}
/*========================================================================================================*/
......@@ -53,20 +53,27 @@ namespace DocFileFormat
HeaderSize(0), BodySize(0), RawData(NULL), SiblingIdx(0), TypeCode(0), Version(0), Instance(0), Reader(NULL),
_ParentRecord(NULL)
{
this->BodySize = bodySize;
this->TypeCode = typeCode;
this->Version = version;
this->Instance = instance;
this->HeaderSize = Record::HEADER_SIZE_IN_BYTES;
BodySize = bodySize;
TypeCode = typeCode;
Version = version;
Instance = instance;
HeaderSize = Record::HEADER_SIZE_IN_BYTES;
this->RawData = _reader->ReadBytes( (int)this->BodySize, true );
this->Reader = new MemoryStream( this->RawData, this->BodySize, false );
int real_size = _reader->GetSize() - _reader->GetPosition();
if (real_size < BodySize)
{
BodySize = real_size;
}
RawData = _reader->ReadBytes( BodySize, true );
Reader = new MemoryStream( RawData, BodySize, false );
}
/*========================================================================================================*/
unsigned int Record::GetTotalSize() const
{
return ( this->HeaderSize + this->BodySize );
return ( HeaderSize + BodySize );
}
}
......@@ -74,6 +74,7 @@ namespace DocFileFormat
if (pRecord)
{
result = pRecord->NewObject (reader, size, typeCode, version, instance);
if (result)
result->SiblingIdx = siblingIdx;
RELEASEOBJECT(pRecord);
}
......
......@@ -217,9 +217,18 @@ namespace DocFileFormat
case msosptTextStop : { pShape = new WordArtTextStop(); } break;
case msosptTextArchUpCurve : { pShape = new WordArtTextArchUpCurve(); } break;
case msosptTextPlainText :
//без детализаций - todooo прописать формулы
case msosptTextTriangle :
case msosptTextSlantUp : { pShape = new WordArtTextSlantUp(); } break;
case msosptTextDeflate : { pShape = new WordArtTextDeflate(); } break;
case msosptTextCanDown : { pShape = new WordArtTextCanDown(); } break;
case msosptTextWave1 : { pShape = new WordArtTextWave1(); } break;
case msosptTextWave3 : { pShape = new WordArtTextWave3(); } break;
case msosptTextWave4 : { pShape = new WordArtTextWave4(); } break;
case msosptTextCurveUp : { pShape = new WordArtTextCurveUp(); } break;
case msosptTextFadeUp : { pShape = new WordArtTextFadeUp(); } break;
case msosptTextTriangle : { pShape = new WordArtTextTriangle(); } break;
case msosptTextCascadeUp : { pShape = new WordArtTextCascadeUp(); } break;
case msosptTextDeflateBottom : { pShape = new WordArtTextDeflateBottom(); } break;
case msosptTextTriangleInverted :
case msosptTextChevron :
case msosptTextChevronInverted :
......@@ -232,30 +241,21 @@ namespace DocFileFormat
case msosptTextArchDownPour :
case msosptTextCirclePour :
case msosptTextButtonPour :
case msosptTextCurveUp :
case msosptTextCurveDown :
case msosptTextCascadeUp :
case msosptTextCascadeDown :
case msosptTextWave1 :
case msosptTextWave2 :
case msosptTextWave3 :
case msosptTextWave4 :
case msosptTextInflate :
case msosptTextDeflate :
case msosptTextInflateBottom :
case msosptTextDeflateBottom :
case msosptTextInflateTop :
case msosptTextDeflateTop :
case msosptTextDeflateInflate :
case msosptTextDeflateInflateDeflate :
case msosptTextFadeRight :
case msosptTextFadeLeft :
case msosptTextFadeUp :
case msosptTextFadeDown :
case msosptTextSlantUp :
case msosptTextSlantDown :
case msosptTextCanUp :
case msosptTextCanDown :
case msosptTextPlainText :
{ pShape = new WordArtTextType(TypeCode); } break;
default : { pShape = NULL; } break;
......
......@@ -66,7 +66,7 @@ namespace DocFileFormat
virtual Record* NewObject( IBinaryReader* _reader, unsigned int bodySize, unsigned int typeCode, unsigned int version, unsigned int instance )
{
return new UnknownRecord( _reader, bodySize, typeCode, version, instance );
return NULL;//new UnknownRecord( _reader, bodySize, typeCode, version, instance );
}
};
}
\ No newline at end of file
......@@ -33,6 +33,7 @@
#include "IVisitable.h"
#include "StructuredStorageReader.h"
#include "PictureDescriptor.h"
namespace DocFileFormat
{
......@@ -40,9 +41,6 @@ namespace DocFileFormat
{
friend class OleObjectMapping;
private:
POLE::Storage *oleStorage;
public:
enum LinkUpdateOption
{
......@@ -50,14 +48,13 @@ namespace DocFileFormat
Always = 1,
OnCall = 3
};
bool bOlderVersion;
bool bLinked; // The the value is true, the object is a linked object
std::wstring ObjectId;
std::wstring ClassId;
// CLSID ClassId;
/// The the value is true, the object is a linked object
bool fLinked;
/// Display name of the linked object or embedded object.
std::wstring UserType;
std::wstring UserType; // Display name of the linked object or embedded object.
std::wstring ClipboardFormat;
std::wstring Link;
std::wstring Program;
......@@ -66,10 +63,13 @@ namespace DocFileFormat
bool isEquation;
bool isEmbedded;
std::string emeddedData;
OleObject( const CharacterPropertyExceptions* chpx, StructuredStorageReader* docStorage )
: fLinked(false), updateMode(NoLink)
PictureDescriptor pictureDesciptor;
OleObject( const CharacterPropertyExceptions* chpx, StructuredStorageReader* docStorage, bool bOlderVersion_ )
: bLinked(false), updateMode(NoLink), bOlderVersion(bOlderVersion_)
{
isEquation = isEmbedded = false;
......@@ -86,12 +86,11 @@ namespace DocFileFormat
ObjectId = getOleEntryName( chpx );
std::string sObjectId( ObjectId.begin(), ObjectId.end() );
//if (oleStorage->enterDirectory(sObjectId))
{
std::string name = "ObjectPool/" + sObjectId + "/";
processOleStream( name + "Ole" );
if ( this->fLinked )
if ( bLinked )
{
processLinkInfoStream( name + "LinkInfo" );
}
......@@ -100,15 +99,12 @@ namespace DocFileFormat
processCompObjStream( name + "CompObj" );
}
processPICStream( name + "PIC" );
processEquationNativeStream( name + "Equation Native" );
}
//oleStorage->leaveDirectory();
delete ObjectPoolStorage;
}
//STATSTG stg;
//this->oleStorage->Stat( &stg, STATFLAG_NONAME );
//this->ClassId = stg.clsid;
}
}
......@@ -117,6 +113,8 @@ namespace DocFileFormat
}
private:
POLE::Storage *oleStorage;
void processLinkInfoStream( const std::string& linkStream )
{
try
......@@ -185,8 +183,9 @@ namespace DocFileFormat
unsigned char *Buffer = reader.ReadBytes( sz, true );
if (Buffer)
if (Buffer && sz > 0)
{
isEquation = true;
delete []Buffer;
}
......@@ -198,14 +197,48 @@ namespace DocFileFormat
}
}
void processPICStream( const std::string& picStream )
{
try
{
HRESULT res = S_OK;
POLE::Stream* pPICStream = new POLE::Stream(oleStorage, picStream);
if ( pPICStream )
{
VirtualStreamReader reader( pPICStream, 0, false);
int sz = reader.GetSize();
int cbHeader = reader.ReadUInt32();
reader.ReadBytes(4, false);
int x = reader.ReadUInt32();
int y = reader.ReadUInt32();
pictureDesciptor.dyaGoal = reader.ReadUInt32();
pictureDesciptor.dxaGoal = reader.ReadUInt32();
reader.ReadBytes(20, false);
pictureDesciptor.mx = reader.ReadUInt32();
pictureDesciptor.my = reader.ReadUInt32();
}
}
catch (...)
{
}
}
void processCompObjStream( const std::string& compStream )
{
try
{
POLE::Stream* pCompStream = NULL;
HRESULT res = S_OK;
pCompStream = new POLE::Stream(oleStorage, compStream);
POLE::Stream* pCompStream = new POLE::Stream(oleStorage, compStream);
if ( pCompStream )
{
......@@ -218,16 +251,15 @@ namespace DocFileFormat
if (sz_obj > 4)
{
//todooo сделать по нормальному CompObjHeader - psc3a.doc
//UserType = reader.ReadLengthPrefixedAnsiString();
UserType = reader.ReadLengthPrefixedAnsiString(sz_obj);
//sz_obj = reader.GetSize() - reader.GetPosition();
//if (sz_obj > 4)
// ClipboardFormat = reader.ReadLengthPrefixedAnsiString();
sz_obj = reader.GetSize() - reader.GetPosition();
if (sz_obj > 4)
ClipboardFormat = reader.ReadLengthPrefixedAnsiString(sz_obj);
//sz_obj = reader.GetSize() - reader.GetPosition();
//if (sz_obj > 4)
// Program = reader.ReadLengthPrefixedAnsiString();
sz_obj = reader.GetSize() - reader.GetPosition();
if (sz_obj > 4)
Program = reader.ReadLengthPrefixedAnsiString(sz_obj);
}
delete pCompStream;
}
......@@ -255,7 +287,7 @@ namespace DocFileFormat
//read the embedded/linked flag
int flag = reader.ReadInt32();
this->fLinked = FormatUtils::BitmaskToBool( flag, 0x1 );
bLinked = FormatUtils::BitmaskToBool( flag, 0x1 );
//Link update option
this->updateMode = (LinkUpdateOption)reader.ReadInt32();
......@@ -296,7 +328,7 @@ namespace DocFileFormat
{
for ( std::list<SinglePropertyModifier>::const_iterator iter = chpx->grpprl->begin(); iter != chpx->grpprl->end(); iter++ )
{
if ( iter->OpCode == sprmCPicLocation )
if ( iter->OpCode == sprmCPicLocation || iter->OpCode == sprmOldCPicLocation)
{
ret = ( _T( "_" ) + FormatUtils::IntToWideString( FormatUtils::BytesToUInt32( iter->Arguments, 0, iter->argumentsSize ) ) );
......
......@@ -68,7 +68,7 @@ namespace DocFileFormat
m_pXmlWriter->WriteNodeBegin( _T( "o:OLEObject" ), TRUE );
//type
if ( ole->fLinked )
if ( ole->bLinked )
{
int relID = -1;
......
......@@ -91,7 +91,7 @@ namespace DocFileFormat
XMLTools::XMLElement<wchar_t> spacing ( _T( "w:spacing" ) );
XMLTools::XMLElement<wchar_t>* jc = NULL;
if ( this->_isParagraphStyleNeeded )
if ( _isParagraphStyleNeeded )
{
//append style id , do not append "Normal" style (istd 0)
XMLTools::XMLElement<wchar_t> pStyle( _T( "w:pStyle" ) );
......@@ -99,7 +99,7 @@ namespace DocFileFormat
if ( papx->istd < m_document->Styles->Styles->size() )
{
styleId.SetValue( FormatUtils::XmlEncode(StyleSheetMapping::MakeStyleId( this->m_document->Styles->Styles->at( papx->istd ) )).c_str() );
styleId.SetValue( FormatUtils::XmlEncode(StyleSheetMapping::MakeStyleId( m_document->Styles->Styles->at( papx->istd ) )).c_str() );
}
pStyle.AppendAttribute( styleId );
......@@ -143,10 +143,8 @@ namespace DocFileFormat
case sprmPIpgp:
{
appendValueElement(_pPr, _T( "divId" ), FormatUtils::IntToWideString( FormatUtils::BytesToUInt32(iter->Arguments, 0, iter->argumentsSize)).c_str(), true);
}
break;
}break;
//element flags
case sprmPFAutoSpaceDE:
{
appendFlagElement(_pPr, *iter, _T( "autoSpaceDE" ), true);
......@@ -163,19 +161,18 @@ namespace DocFileFormat
{
appendFlagElement( _pPr, *iter, _T( "bidi" ), true );
_isBidi = true;
}
break;
}break;
case sprmPFContextualSpacing:
{
appendFlagElement( _pPr, *iter, _T( "contextualSpacing" ), true );
}
break;
}break;
case sprmOldPFKeep:
case sprmPFKeep:
{
appendFlagElement( _pPr, *iter, _T( "keepLines" ), true );
break;
}break;
case sprmOldPFKeepFollow:
case sprmPFKeepFollow:
......@@ -315,7 +312,7 @@ namespace DocFileFormat
case sprmPJc:
case sprmPJc80:
{
if (this->_isBidi && (iter->Arguments[0] == 0 || iter->Arguments[0] == 2))
if (_isBidi && (iter->Arguments[0] == 0 || iter->Arguments[0] == 2))
{
iter->Arguments[0] = (iter->Arguments[0] == 0 ? 2 : 0);
}
......@@ -434,11 +431,36 @@ namespace DocFileFormat
break;
//numbering
case sprmOldPAnld:
{
NumberingDescriptor desc( iter->Arguments, iter->argumentsSize );
if (m_document->listTable)
{
m_document->listTable->appendNumbering( desc );
short numId = m_document->listTable->listNumbering.size();
appendValueElement( &numPr, _T( "numId" ), numId, true );
}
}break;
case sprmOldSOlstAnm:
{
OutlineListDescriptor desc( iter->Arguments, iter->argumentsSize );
}break;
case sprmOldPNLvlAnm:
{ short level = FormatUtils::BytesToUChar( iter->Arguments, 0, iter->argumentsSize) - 1;
if (level > 0 && level < 10)
appendValueElement( _pPr, _T( "outlineLvl" ), level, false );
}break; case sprmOldPFNoLineNumb:
{
}break;
case sprmPIlvl:
//Если numbering.xml пустой, то не пищем свойство
{
if(NULL != m_document->listTable && false == m_document->listTable->listData.empty())
appendValueElement( &numPr, _T( "ilvl" ), iter->Arguments[0], true );
break;
}break;
case sprmPIlfo:
{
......@@ -527,7 +549,7 @@ namespace DocFileFormat
tabs.AppendChild( tab );
}
this->_pPr->AppendChild( tabs );
_pPr->AppendChild( tabs );
}
break;
......@@ -545,36 +567,36 @@ namespace DocFileFormat
case sprmOldPWr:
case sprmPWr:
appendValueAttribute( this->_framePr, _T( "w:wrap" ), FormatUtils::MapValueToWideString( iter->Arguments[0], &Global::TextFrameWrapping[0][0], 6, 10 ).c_str() );
appendValueAttribute( _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 ) );
appendValueAttribute( _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 ) );
appendValueAttribute( _framePr, _T( "w:y" ), FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) );
break;
case sprmPWHeightAbs:
appendValueAttribute( this->_framePr, _T( "w:h" ), FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) );
appendValueAttribute( _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 ) );
appendValueAttribute( _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 ) );
appendValueAttribute( _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 ) );
appendValueAttribute( _framePr, _T( "w:vSpace" ), FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize ) );
break;
case sprmOldPDcs:
......@@ -582,18 +604,21 @@ namespace DocFileFormat
{
short pDcs = FormatUtils::BytesToInt16( iter->Arguments, 0, iter->argumentsSize );
appendValueAttribute( this->_framePr, _T( "w:dropCap" ), FormatUtils::MapValueToWideString( ( pDcs & 0x07 ), &Global::TextFrameDropCapLocation[0][0], 3, 7 ).c_str() );
appendValueAttribute( _framePr, _T( "w:dropCap" ), FormatUtils::MapValueToWideString( ( pDcs & 0x07 ), &Global::TextFrameDropCapLocation[0][0], 3, 7 ).c_str() );
appendValueAttribute( this->_framePr, _T( "w:lines" ), (unsigned char)( ( pDcs & 0xF8 ) >> 3 ) );
appendValueAttribute( _framePr, _T( "w:lines" ), (unsigned char)( ( pDcs & 0xF8 ) >> 3 ) );
}
break;
//outline level
case sprmOldPIncLvl: //????
case sprmPOutLvl:
{
appendValueElement( _pPr, _T( "outlineLvl" ), iter->Arguments[0], false );
break;
}break;
default:
{
if (iter->argumentsSize == 2)
{
nProperty = FormatUtils::BytesToUInt16( iter->Arguments, 0, iter->argumentsSize );
......@@ -602,7 +627,7 @@ namespace DocFileFormat
{
nProperty = FormatUtils::BytesToUChar( iter->Arguments, 0, iter->argumentsSize );
}
break;
}break;
}
}
......@@ -617,7 +642,7 @@ namespace DocFileFormat
if ( _sepx != NULL )
{
XMLTools::XMLElement<wchar_t> sectPr( _T( "w:sectPr" ) );
SectionPropertiesMapping* sectionPropertiesMapping = new SectionPropertiesMapping( &sectPr, this->m_context, this->_sectionNr );
SectionPropertiesMapping* sectionPropertiesMapping = new SectionPropertiesMapping( &sectPr, m_context, _sectionNr );
_sepx->Convert( sectionPropertiesMapping );
if (sectionPropertiesMapping->get_section_type() == L"nextPage")
......
......@@ -31,26 +31,40 @@
*/
#include "PictureDescriptor.h"
#include "OfficeDrawing/MetafilePictBlip.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), embeddedDataHeader(NULL)
{
//Get start and length of the PICT
int fc = GetFcPic( chpx );
if ( fc >= 0 )
{
parse( stream, fc, size, oldVersion);
}
}
PictureDescriptor::PictureDescriptor()
:
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), embeddedData(NULL), embeddedDataSize(0), embeddedDataHeader(NULL)
{
}
PictureDescriptor::~PictureDescriptor()
{
Clear();
......@@ -64,6 +78,9 @@ namespace DocFileFormat
RELEASEOBJECT(shapeContainer);
RELEASEOBJECT(blipStoreEntry);
RELEASEARRAYOBJECTS(embeddedData);
RELEASEARRAYOBJECTS(embeddedDataHeader);
}
void PictureDescriptor::parse(POLE::Stream* stream, int fc, int sz, bool oldVersion)
{
......@@ -75,10 +92,12 @@ namespace DocFileFormat
int lcb = reader.ReadInt32();
int pos_start = reader.GetPosition();
if (lcb > 10000000)
return;
if (lcb > sz && sz != 2) //bullet picture с неверным размером
if (lcb > sz && sz != 1 && sz != 2) //bullet picture с неверным размером
{
unsigned char* bytes = reader.ReadBytes(sz - fc - 4, false);
if ( bytes )
......@@ -88,8 +107,9 @@ namespace DocFileFormat
return;
}
if (lcb >= 10)
{
if (lcb < 10)
return;
int cbHeader = reader.ReadUInt16();
mfp.mm = reader.ReadInt16();
......@@ -97,8 +117,6 @@ namespace DocFileFormat
mfp.yExt = reader.ReadInt16();
mfp.hMf = reader.ReadInt16();
if (mfp.mm >= 98 || oldVersion)
{
unsigned char* bytes = reader.ReadBytes(14, true);
rcWinMf = std::vector<unsigned char>(bytes, (bytes + 14));
RELEASEARRAYOBJECTS(bytes);
......@@ -115,30 +133,55 @@ namespace DocFileFormat
dxaCropRight = reader.ReadInt16();
dyaCropBottom = reader.ReadInt16();
short brcl = reader.ReadInt16();
int brcl = reader.ReadInt16();
// borders
int bytesCount = oldVersion ? 2 : 4;
int bytesCount = 4;
bytes = reader.ReadBytes( bytesCount, true );
brcTop = new BorderCode( bytes, bytesCount );
RELEASEARRAYOBJECTS( bytes );
bytes = reader.ReadBytes( bytesCount, true );
brcLeft = new BorderCode( bytes, 4 );
brcLeft = new BorderCode( bytes, bytesCount );
RELEASEARRAYOBJECTS( bytes );
bytes = reader.ReadBytes( bytesCount, true );
brcBottom = new BorderCode( bytes, 4 );
brcBottom = new BorderCode( bytes, bytesCount );
RELEASEARRAYOBJECTS( bytes );
bytes = reader.ReadBytes( bytesCount, true );
brcRight = new BorderCode( bytes, 4 );
brcRight = new BorderCode( bytes, bytesCount );
RELEASEARRAYOBJECTS( bytes );
dxaOrigin = reader.ReadInt16();
dyaOrigin = reader.ReadInt16();
int pos_end = reader.GetPosition();
if (oldVersion)
{
int flag = brcl;
brcl = FormatUtils::BitmaskToBool(flag, 0x000F);
//( 0 single 1 thick 2 double 3 shadow )
bool fFrameEmpty = FormatUtils::BitmaskToBool(flag, 0x0010);// picture consists of a single frame
bool fBitmap = FormatUtils::BitmaskToBool(flag, 0x0020);// ==1, when picture is just a bitmap
bool fDrawHatch = FormatUtils::BitmaskToBool(flag, 0x0040);// ==1, when picture is an active OLE object
bool fError = FormatUtils::BitmaskToBool(flag, 0x0080);// ==1, when picture is just an error message
short bpp = FormatUtils::BitmaskToBool(flag, 0x8000);// bits per pixel
//(0 unknown 1 monochrome 4 VGA)
int sz_hdr = pos_end - pos_start;
int header_size = 114;
embeddedDataSize = lcb - sz_hdr - header_size;
embeddedDataHeader = reader.ReadBytes( header_size, true);
embeddedData = reader.ReadBytes( embeddedDataSize, true );
}
else
{
cProps = reader.ReadInt16();
if (mfp.mm == MM_SHAPEFILE)
......@@ -154,31 +197,6 @@ 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();
//RELEASEARRAYOBJECTS(pPicData);
}
else
{
//Parse the OfficeDrawing Stuff
shapeContainer = dynamic_cast<ShapeContainer*>(RecordFactory::ReadRecord(&reader, 0));
long pos = reader.GetPosition();
......@@ -198,14 +216,12 @@ namespace DocFileFormat
}
}
}
}
}
/// Returns the fcPic into the "data" stream, where the PIC begins.
/// Returns -1 if the CHPX has no fcPic.
int PictureDescriptor::GetFcPic(const CharacterPropertyExceptions* chpx)
{
int ret = -1;
int ret = -1, ret1 = -1;
for ( std::list<SinglePropertyModifier>::const_iterator iter = chpx->grpprl->begin(); iter != chpx->grpprl->end(); iter++ )
{
......@@ -216,6 +232,11 @@ namespace DocFileFormat
ret = FormatUtils::BytesToInt32( iter->Arguments, 0, iter->argumentsSize );
break;
case sprmOldCHps:
case sprmCHps:
ret1 = FormatUtils::BytesToInt32( iter->Arguments, 0, iter->argumentsSize );
break;
case sprmCHsp:
ret = FormatUtils::BytesToInt32( iter->Arguments, 0, iter->argumentsSize );
break;
......
......@@ -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;
};
......@@ -78,16 +78,20 @@ namespace DocFileFormat
friend class VMLPictureMapping;
friend class VMLShapeMapping;
friend class NumberingMapping;
friend class OleObject;
public:
/// Parses the CHPX for a fcPic an loads the PictureDescriptor at this offset
PictureDescriptor( CharacterPropertyExceptions* chpx, POLE::Stream* stream, int size, bool oldVersion);
// Parses the CHPX for a fcPic an loads the PictureDescriptor at this offset
PictureDescriptor ( );
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.
private:
// 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 +99,38 @@ 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)
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;
/// 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
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 *embeddedDataHeader;
unsigned char *embeddedData;
int embeddedDataSize;
};
}
......@@ -62,7 +62,7 @@ namespace DocFileFormat
}
else
{
code_page = ENCODING_UTF16;
code_page = (code_page == ENCODING_WINDOWS_1250 ? ENCODING_UTF16 : code_page_);
this->fc = fcValue;
}
}
......
......@@ -66,12 +66,17 @@ namespace DocFileFormat
while ( goOn )
{
//enough bytes to read?
if ( ( sprmStart + opCodeSize ) < size )
{
OperationCode opCode = oldVersion ? (OperationCode)FormatUtils::BytesToUChar ( bytes, sprmStart, size ) :
(OperationCode)FormatUtils::BytesToUInt16 ( bytes, sprmStart, size ) ;
unsigned short code = oldVersion ? FormatUtils::BytesToUChar ( bytes, sprmStart, size ) :
FormatUtils::BytesToUInt16 ( bytes, sprmStart, size ) ;
if (oldVersion && code == 0)
{
sprmStart++;
continue;
}
OperationCode opCode = (OperationCode)code;
short opSize = -1;
if (oldVersion)
......@@ -91,28 +96,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;
......@@ -133,7 +142,6 @@ namespace DocFileFormat
}
}
//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;
......@@ -144,7 +152,6 @@ namespace DocFileFormat
{
memcpy( sprmBytes, ( bytes + sprmStart ), sprmBytesSize );
//parse
SinglePropertyModifier sprm( sprmBytes, sprmBytesSize, oldVersion );
grpprl->push_back( sprm );
......
......@@ -105,17 +105,28 @@ namespace DocFileFormat
if (pTable)
{
unsigned char fHF = 255; //all headers & footers
for (std::list<SinglePropertyModifier>::iterator iter = sepx->grpprl->begin(); iter != sepx->grpprl->end(); ++iter)
{
switch (iter->OpCode)
{
case sprmOldSGprfIhdt:
case sprmSGprfIhdt:
fHF = FormatUtils::BytesToUChar( iter->Arguments, 0, iter->argumentsSize );
break;
}
}
// Header
WriteSectionStory (pTable->GetEvenHeaders (m_nSelectProperties), std::wstring(L"headerReference"), std::wstring(L"even"));
WriteSectionStory (pTable->GetOddHeaders (m_nSelectProperties), std::wstring(L"headerReference"), std::wstring(L"default"));
WriteSectionStory (pTable->GetFirstHeaders (m_nSelectProperties), std::wstring(L"headerReference"), std::wstring(L"first"));
if (FormatUtils::GetBitFromInt(fHF, 0)) WriteSectionStory (pTable->GetEvenHeaders (m_nSelectProperties), std::wstring(L"headerReference"), std::wstring(L"even"));
if (FormatUtils::GetBitFromInt(fHF, 1)) WriteSectionStory (pTable->GetOddHeaders (m_nSelectProperties), std::wstring(L"headerReference"), std::wstring(L"default"));
if (FormatUtils::GetBitFromInt(fHF, 4)) WriteSectionStory (pTable->GetFirstHeaders (m_nSelectProperties), std::wstring(L"headerReference"), std::wstring(L"first"));
// Footer
WriteSectionStory (pTable->GetEvenFooters (m_nSelectProperties), std::wstring(L"footerReference"), std::wstring(L"even"));
WriteSectionStory (pTable->GetOddFooters (m_nSelectProperties), std::wstring(L"footerReference"), std::wstring(L"default"));
WriteSectionStory (pTable->GetFirstFooters (m_nSelectProperties), std::wstring(L"footerReference"), std::wstring(L"first"));
if (FormatUtils::GetBitFromInt(fHF, 2)) WriteSectionStory (pTable->GetEvenFooters (m_nSelectProperties), std::wstring(L"footerReference"), std::wstring(L"even"));
if (FormatUtils::GetBitFromInt(fHF, 3)) WriteSectionStory (pTable->GetOddFooters (m_nSelectProperties), std::wstring(L"footerReference"), std::wstring(L"default"));
if (FormatUtils::GetBitFromInt(fHF, 5)) WriteSectionStory (pTable->GetFirstFooters (m_nSelectProperties), std::wstring(L"footerReference"), std::wstring(L"first"));
}
//MUST be ignored if the section does not have page number restart enabled.([MS-DOC] — v20101113. стр 152)
......
......@@ -51,6 +51,13 @@ namespace DocFileFormat
opCodeSize = 1;
//first 1 byte are the operation code ...
OpCode = (OperationCode)FormatUtils::BytesToUChar( bytes, 0, size );
if (OpCode == 0 && size == 4)
{
//так записывается rgb цвет (
OpCode = sprmCCv;
opSize = 3;
}
else
opSize = GetOldOperandSize( (unsigned char)OpCode );
}
else
......@@ -86,6 +93,8 @@ namespace DocFileFormat
{
switch ( OpCode )
{
case sprmOldTDefTable:
case sprmOldTDefTable10:
case sprmTDefTable:
case sprmTDefTable10:
{
......@@ -99,6 +108,7 @@ namespace DocFileFormat
}
break;
case sprmOldPChgTabs:
case sprmPChgTabs:
{
argumentsSize = bytes[2];
......@@ -205,7 +215,9 @@ 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, 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
// 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,255,255,4,5,4,2,4,2,2,5,4,0,0,0,0,0,0,0,0
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,2,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,255,255,4,5,4,2,4,2,2,5,4,0,0,0,0,0,0,0,0
};
unsigned char SinglePropertyModifier::GetOldOperandSize(unsigned char code)
......
/*
* (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
*
*/
#include "Spa.h"
#include "VirtualStreamReader.h"
namespace DocFileFormat
{
Spa::Spa() : spid(0), fHdr(0), bx(MARGIN), by(MARGIN), wr(0), wrk(0),
xaLeft(0), yaTop(0), xaRight(0), yaBottom(0),
fRcaSimple(0), fBelowText(0), fAnchorLock(0), cTxbx(0)
{
}
Spa::~Spa()
{
for (int i = 0 ; i < primitives.size(); i++)
{
if (primitives[i]) delete primitives[i];
primitives[i] = NULL;
}
}
void Spa::read_primitives(Spa* pSpa, VirtualStreamReader* reader, int length)
{
if (!pSpa) return;
if (!reader || length < 1) return;
int stream_pos = reader->GetPosition();
int pos = 0;
while (pos < length)
{
reader->Seek(stream_pos + pos, 0);
unsigned short dpk = reader->ReadUInt16();
int shape_type = FormatUtils::BitmaskToInt (dpk, 0x00ff);
short cb_primitive = reader->ReadInt16();
if (pos + cb_primitive > length)
{
reader->Seek(reader->GetPosition() - 4, 0);
break;
}
DrawingPrimitive *dp = DrawingPrimitive::Create(reader, cb_primitive - 4, shape_type);
if (dp)
pSpa->primitives.push_back(dp);
if (shape_type == 0x00)
{
//start group
read_primitives(pSpa, reader, cb_primitive - 4);
}
else if (shape_type == 0x08)
{
//end group
break;
}
pos += cb_primitive;
}
}
ByteStructure* Spa::ConstructObject(VirtualStreamReader* reader, int length)
{
Spa* pSpa = new Spa();
if (!pSpa) return NULL;
if (reader->olderVersion)
{
int fc = reader->ReadInt32();
pSpa->cTxbx = reader->ReadUInt16();
int pos_keep = reader->GetPosition();
reader->Seek(fc, 0);
unsigned short dok = reader->ReadUInt16();
short cb = reader->ReadInt16();
pSpa->bx = (AnchorType)reader->ReadByte();
pSpa->by = (AnchorType)reader->ReadByte();
short height = reader->ReadInt16();
pSpa->fAnchorLock = reader->ReadUInt16();
int pos = 10; //fixed size
read_primitives(pSpa, reader, cb - 10/*_primitive*/);
reader->Seek(pos_keep, 0);
}
else
{
pSpa->spid = reader->ReadInt32();
pSpa->xaLeft = reader->ReadInt32();
pSpa->yaTop = reader->ReadInt32();
pSpa->xaRight = reader->ReadInt32();
pSpa->yaBottom = reader->ReadInt32();
unsigned short flag = reader->ReadUInt16();
pSpa->fHdr = FormatUtils::BitmaskToBool(flag, 0x0001);
pSpa->bx = (AnchorType)FormatUtils::BitmaskToInt(flag, 0x0006);
pSpa->by = (AnchorType)FormatUtils::BitmaskToInt(flag, 0x0018);
pSpa->wr = (unsigned short)FormatUtils::BitmaskToInt(flag, 0x01E0);
pSpa->wrk = (unsigned short)FormatUtils::BitmaskToInt(flag, 0x1E00);
pSpa->fRcaSimple = FormatUtils::BitmaskToBool(flag, 0x2000);
pSpa->fBelowText = FormatUtils::BitmaskToBool(flag, 0x4000);
pSpa->fAnchorLock = FormatUtils::BitmaskToBool(flag, 0x8000);
pSpa->cTxbx = reader->ReadInt32();
}
return static_cast<ByteStructure*>(pSpa);
}
}
......@@ -31,8 +31,10 @@
*/
#pragma once
#include "VirtualStreamReader.h"
#include "ByteStructure.h"
#include "DrawingPrimitives.h"
class VirtualStreamReader;
namespace DocFileFormat
{
......@@ -47,48 +49,21 @@ namespace DocFileFormat
{
public:
friend class VMLShapeMapping;
static const int STRUCTURE_SIZE = 26;
friend class DocumentMapping;
Spa()
{
}
static const int STRUCTURE_SIZE = 26;
static const int STRUCTURE_SIZE_OLD = 6;
virtual ~Spa()
static const int GetSize(bool bOldVersion)
{
return bOldVersion ? STRUCTURE_SIZE_OLD : STRUCTURE_SIZE;
}
virtual ByteStructure* ConstructObject(VirtualStreamReader* reader, int length)
{
Spa* pSpa = new Spa();
if (pSpa)
{
pSpa->spid = reader->ReadInt32();
pSpa->xaLeft = reader->ReadInt32();
pSpa->yaTop = reader->ReadInt32();
pSpa->xaRight = reader->ReadInt32();
pSpa->yaBottom = reader->ReadInt32();
Spa();
unsigned short flag = reader->ReadUInt16();
pSpa->fHdr = FormatUtils::BitmaskToBool(flag, 0x0001);
pSpa->bx = (AnchorType)FormatUtils::BitmaskToInt(flag, 0x0006);
pSpa->by = (AnchorType)FormatUtils::BitmaskToInt(flag, 0x0018);
pSpa->wr = (unsigned short)FormatUtils::BitmaskToInt(flag, 0x01E0);
pSpa->wrk = (unsigned short)FormatUtils::BitmaskToInt(flag, 0x1E00);
pSpa->fRcaSimple = FormatUtils::BitmaskToBool(flag, 0x2000);
pSpa->fBelowText = FormatUtils::BitmaskToBool(flag, 0x4000);
pSpa->fAnchorLock = FormatUtils::BitmaskToBool(flag, 0x8000);
pSpa->cTxbx = reader->ReadInt32();
return static_cast<ByteStructure*>(pSpa);
}
return NULL;
}
virtual ~Spa();
virtual ByteStructure* ConstructObject(VirtualStreamReader* reader, int length);
inline int GetShapeID() const
{
return spid;
......@@ -141,13 +116,12 @@ namespace DocFileFormat
/// forcing the xaLeft, xaRight, yaTop, and yaBottom fields
/// to all be page relative.
bool fRcaSimple;
/// true: shape is below text
/// false: shape is above text
bool fBelowText;
/// true: anchor is locked
/// fasle: anchor is not locked
bool fAnchorLock;
/// Count of textboxes in shape (undo doc only)
int cTxbx;
bool fBelowText; // true: shape is below text
bool fAnchorLock; // true: anchor is locked
int cTxbx; // Count of textboxes in shape (undo doc only)
DrawingPrimitives primitives;
void read_primitives(Spa* pSpa, VirtualStreamReader* reader, int length);
};
}
......@@ -45,6 +45,7 @@ namespace DocFileFormat
friend class FontTableMapping;
friend class StyleSheetMapping;
friend class DocumentMapping;
friend class NumberingMapping;
private:
bool fExtend;
......
......@@ -49,7 +49,19 @@ namespace DocFileFormat
/// Parses the bytes to retrieve a StyleSheetDescription
StyleSheetDescription::StyleSheetDescription (unsigned char* bytes, int size, int cbStdBase, POLE::Stream* dataStream, bool oldVersion) :
papx(NULL), chpx(NULL), tapx(NULL)
papx(NULL), chpx(NULL), tapx(NULL),
fAutoRedef(false),
fHidden(false),
f97LidsSet(false),
fCopyLang(false),
fPersonalCompose(false),
fPersonalReply(false),
fPersonal(false),
fNoHtmlExport(false),
fSemiHidden(false),
fLocked(false),
fInternalUse(false)
{
//parsing the base (fix part)
......@@ -124,7 +136,7 @@ namespace DocFileFormat
{
name = new unsigned char[characterCount];//characters are zero-terminated, so 1 char has 2 bytes:
memcpy( name, ( bytes + cbStdBase + 1 ), ( characterCount ) );
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &(this->xstzName), name, ( characterCount ), ENCODING_WINDOWS_1250 );
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &(xstzName), name, ( characterCount ), ENCODING_WINDOWS_1250 );
upxOffset = cbStdBase + 1 + ( characterCount /** 2*/ ) + 1;
}
else
......@@ -132,14 +144,14 @@ namespace DocFileFormat
name = new unsigned char[characterCount * 2];//characters are zero-terminated, so 1 char has 2 bytes:
memcpy( name, ( bytes + cbStdBase + 2 ), ( characterCount * 2 ) );
//remove zero-termination
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &(this->xstzName), name, ( characterCount * 2 ), ENCODING_UTF16 );
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &(xstzName), name, ( characterCount * 2 ), ENCODING_UTF16 );
//parse the UPX structs
upxOffset = cbStdBase + 1 + ( characterCount * 2 ) + 2;
}
RELEASEARRAYOBJECTS( name );
for ( int i = 0; i < this->cupx; i++ )
for ( int i = 0; i < cupx; i++ )
{
//find the next even unsigned char border
if ( ( upxOffset % 2 ) != 0 )
......@@ -156,7 +168,7 @@ namespace DocFileFormat
unsigned char* upxBytes = new unsigned char[cbUPX];
memcpy( upxBytes, ( bytes + upxOffset + 2 ), cbUPX );
if ( this->stk == table_style )
if ( stk == table_style )
{
//first upx is TAPX; second PAPX, third CHPX
switch ( i )
......@@ -164,68 +176,68 @@ namespace DocFileFormat
case 0:
{
//todooo не реализовано
//RELEASEOBJECT( this->tapx );
//this->tapx = new TablePropertyExceptions( upxBytes, cbUPX, dataStream, oldVersion);
//RELEASEOBJECT( tapx );
//tapx = new TablePropertyExceptions( upxBytes, cbUPX, dataStream, oldVersion);
}
break;
case 1:
{
RELEASEOBJECT( this->papx );
this->papx = new ParagraphPropertyExceptions( upxBytes, cbUPX, dataStream, oldVersion);
RELEASEOBJECT( papx );
papx = new ParagraphPropertyExceptions( upxBytes, cbUPX, dataStream, oldVersion);
}
break;
case 2:
{
RELEASEOBJECT( this->chpx );
this->chpx = new CharacterPropertyExceptions( upxBytes, cbUPX , oldVersion);
RELEASEOBJECT( chpx );
chpx = new CharacterPropertyExceptions( upxBytes, cbUPX , oldVersion);
}
break;
}
}
else if ( this->stk == paragraph_style )
else if ( stk == paragraph_style )
{
//first upx is PAPX, second CHPX
switch ( i )
{
case 0:
{
RELEASEOBJECT( this->papx );
this->papx = new ParagraphPropertyExceptions( upxBytes, cbUPX, dataStream, oldVersion );
RELEASEOBJECT( papx );
papx = new ParagraphPropertyExceptions( upxBytes, cbUPX, dataStream, oldVersion );
}
break;
case 1:
{
RELEASEOBJECT( this->chpx );
this->chpx = new CharacterPropertyExceptions( upxBytes, cbUPX, oldVersion);
RELEASEOBJECT( chpx );
chpx = new CharacterPropertyExceptions( upxBytes, cbUPX, oldVersion);
}
break;
}
}
else if ( this->stk == numbering_style )
else if ( stk == numbering_style )
{
//list styles have only one PAPX
switch ( i )
{
case 0:
{
RELEASEOBJECT( this->papx );
this->papx = new ParagraphPropertyExceptions( upxBytes, cbUPX, dataStream, oldVersion );
RELEASEOBJECT( papx );
papx = new ParagraphPropertyExceptions( upxBytes, cbUPX, dataStream, oldVersion );
}
break;
}
}
else if ( this->stk == character_style )
else if ( stk == character_style )
{
//character styles have only one CHPX
switch ( i )
{
case 0:
{
RELEASEOBJECT( this->chpx );
this->chpx = new CharacterPropertyExceptions( upxBytes, cbUPX, oldVersion);
RELEASEOBJECT( chpx );
chpx = new CharacterPropertyExceptions( upxBytes, cbUPX, oldVersion);
}
break;
}
......
......@@ -51,44 +51,53 @@ namespace DocFileFormat
{
for ( std::list<SinglePropertyModifier>::iterator iter = papx->grpprl->begin(); iter != papx->grpprl->end(); iter++ )
{
if ( iter->OpCode == sprmPFInTable )
switch(iter->OpCode)
{
this->fInTable = ( iter->Arguments[0] == 1 ) ? (true) : (false);
}
case sprmOldPFInTable:
case sprmPFInTable:
{
fInTable = ( iter->Arguments[0] == 1 ) ? (true) : (false);
}break;
if ( iter->OpCode == sprmPFTtp )
//case sprmOldPFTtp:
case sprmOldPTtp:
case sprmPFTtp:
{
this->fTtp = ( iter->Arguments[0] == 1 ) ? (true) : (false);
}
fTtp = ( iter->Arguments[0] == 1 ) ? (true) : (false);
}break;
if ( iter->OpCode == sprmPFInnerTableCell )
//case sprmOldPFInnerTableCell:
case sprmPFInnerTableCell:
{
this->fInnerTableCell = ( iter->Arguments[0] == 1 ) ? (true) : (false);
}
fInnerTableCell = ( iter->Arguments[0] == 1 ) ? (true) : (false);
}break;
if ( iter->OpCode == sprmPFInnerTtp )
//case sprmOldPFInnerTtp:
case sprmPFInnerTtp:
{
this->fInnerTtp = ( iter->Arguments[0] == 1 ) ? (true) : (false);
}
fInnerTtp = ( iter->Arguments[0] == 1 ) ? (true) : (false);
}break;
if ( iter->OpCode == sprmPItap )
//case sprmOldPItap:
case sprmPItap:
{
this->iTap = FormatUtils::BytesToUInt32( iter->Arguments, 0, iter->argumentsSize );
iTap = FormatUtils::BytesToUInt32( iter->Arguments, 0, iter->argumentsSize );
if ( this->iTap > 0 )
if ( iTap > 0 )
{
this->fInTable = true;
fInTable = true;
}
}break;
}
if ( (int)( iter->OpCode ) == 0x66A )
if ( (int)( iter->OpCode ) == sprmTCnf )//66a
{
//add value!
this->iTap = FormatUtils::BytesToUInt32( iter->Arguments, 0, iter->argumentsSize );
iTap = FormatUtils::BytesToUInt32( iter->Arguments, 0, iter->argumentsSize );
if ( this->iTap > 0 )
if ( iTap > 0 )
{
this->fInTable = true;
fInTable = true;
}
}
}
......
......@@ -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
{
......
......@@ -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);
......
......@@ -94,6 +94,7 @@ namespace DocFileFormat
class FTXBXS : public ByteStructure
{
friend class TextboxMapping;
public:
struct FTXBXSReusable
{
......@@ -107,7 +108,6 @@ namespace DocFileFormat
int cTxbxEdit; // This value MUST be zero and MUST be ignored.
};
public:
static const int STRUCTURE_SIZE = 22;
FTXBXS ()
......@@ -124,8 +124,8 @@ namespace DocFileFormat
virtual ByteStructure* ConstructObject (VirtualStreamReader* reader, int length)
{
FTXBXS* pFTXBXS = new FTXBXS();
if (pFTXBXS)
{
if (!pFTXBXS) return NULL;
pFTXBXS->reusable01 = reader->ReadInt32();
pFTXBXS->reusable02 = reader->ReadInt32();
......@@ -138,11 +138,7 @@ namespace DocFileFormat
return static_cast<ByteStructure*>(pFTXBXS);
}
return NULL;
}
private:
int reusable01;
int reusable02;
......
......@@ -114,7 +114,7 @@ namespace DocFileFormat
m_document->FIB->m_RgLw97.ccpFtn +
m_document->FIB->m_RgLw97.ccpHdr +
m_document->FIB->m_RgLw97.ccpAtn +
m_document->FIB->m_RgLw97.ccpEdn;
m_document->FIB->m_RgLw97.ccpEdn ;
if (typeid(*_caller) == typeid(MainDocumentMapping))
{
......@@ -123,11 +123,17 @@ namespace DocFileFormat
bkd = static_cast<Tbkd*>(m_document->TextboxBreakPlex->Elements[m_nTBIndex]);
}
if (m_nTBIndex < m_document->TextboxBreakPlex->CharacterPositions.size() - 1)
if (m_nTBIndex + 1 < m_document->TextboxBreakPlex->CharacterPositions.size())
{
cp = txtbxSubdocStart + m_document->TextboxBreakPlex->CharacterPositions[m_nTBIndex];
cpEnd = txtbxSubdocStart + m_document->TextboxBreakPlex->CharacterPositions[m_nTBIndex + 1];
}
else if (m_nTBIndex + 1 < m_document->TextboxIndividualPlex->CharacterPositions.size())
{
//todooo сделать чище
cp = m_document->TextboxIndividualPlex->CharacterPositions[m_nTBIndex] + 2;
cpEnd = m_document->TextboxIndividualPlex->CharacterPositions[m_nTBIndex + 1];
}
}
else if ((typeid(*_caller) == typeid(HeaderMapping)) || (typeid(*_caller) == typeid(FooterMapping)))
{
......@@ -139,6 +145,8 @@ namespace DocFileFormat
cpEnd = txtbxSubdocStart + m_document->TextboxBreakPlexHeader->CharacterPositions[m_nTBIndex + 1];
}
_isTextBoxContent = true;
//convert the textbox text
_lastValidPapx = (*(m_document->AllPapxFkps->begin()))->grppapx[0];
......@@ -169,6 +177,7 @@ namespace DocFileFormat
cp = writeParagraph( cp );
}
}
_isTextBoxContent = false;
m_pXmlWriter->WriteNodeEnd( _T( "w:txbxContent" ) );
m_pXmlWriter->WriteNodeEnd( _T( "v:textbox" ) );
......
......@@ -44,31 +44,33 @@
namespace DocFileFormat
{
class OleObject;
bool ParseEmbeddedEquation( const std::string & xmlString, std::wstring & newXmlString );
class VMLPictureMapping: public PropertiesMapping, public IMapping
{
public:
VMLPictureMapping( ConversionContext* ctx, XmlUtils::CXmlWriter* writer, bool olePreview, IMapping* caller, bool isBulletPicture = false );
VMLPictureMapping( ConversionContext* ctx, XmlUtils::CXmlWriter* writer, bool olePreview, IMapping* caller, bool isInlinePicture = false );
virtual ~VMLPictureMapping();
virtual void Apply( IVisitable* visited );
std::wstring GetShapeId() const;
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:
static std::wstring GetTargetExt (Global::BlipType nType);
static std::wstring GetContentType (Global::BlipType nType);
bool m_isBullete;
bool m_isEquation;
bool m_isEmbedded;
std::string m_embeddedData;
......@@ -81,8 +83,8 @@ namespace DocFileFormat
std::wstring m_ShapeId;
bool m_isOlePreview;
bool m_isInlinePicture;
bool m_isBulletPicture;
XMLTools::XMLElement<wchar_t>* m_imageData;
};
......
......@@ -63,8 +63,19 @@ namespace DocFileFormat
virtual ~VMLShapeMapping();
virtual void Apply(IVisitable* visited);
static std::wstring mapVerticalPosition (PositionVertical vPos );
static std::wstring mapVerticalPositionRelative (int vRel );
static std::wstring mapHorizontalPosition (PositionHorizontal hPos );
static std::wstring mapHorizontalPositionRelative(int hRel );
bool m_isBullete;
private:
void ApplyPrimitives (DrawingPrimitives * primitives );
int ApplyPrimitive (DrawingPrimitives * primitives, int index);
void WritePrimitiveProps(DrawingPrimitive * primitive, bool root);
// Converts a group of shapes
void WriteGroup(const GroupContainer* pContainer);
// Converts a single shape
......@@ -86,12 +97,7 @@ namespace DocFileFormat
std::wstring getTextboxAnchor( unsigned int anchor ) const;
std::wstring mapVerticalPosition ( PositionVertical vPos ) const;
std::wstring mapVerticalPositionRelative( int vRel ) const;
std::wstring mapHorizontalPosition ( PositionHorizontal hPos ) const;
std::wstring mapHorizontalPositionRelative( int hRel ) const;
void AppendOptionsToStyle( std::wstring* style, const std::list<OptionEntry>& options ) const;
void AppendOptionsToStyle( std::wstring* style, const std::list<OptionEntry>& options, int zIndex ) const;
std::wstring buildStyle ( const Shape* shape, const ChildAnchor* anchor, const std::list<OptionEntry>& options, int zIndex ) const;
std::wstring getLineStyle ( unsigned int p ) const;
......@@ -117,7 +123,7 @@ namespace DocFileFormat
std::vector<CString> GetTextRectangles(const OptionEntry& inscribe) const;
private:
bool m_bBullet;
bool m_isInlineShape;
Spa* m_pSpa;
IMapping* m_pCaller;
BlipStoreContainer* m_pBlipStore;
......
......@@ -32,10 +32,11 @@
#include "VMLShapeTypeMapping.h"
#include "OfficeDrawing/Shapetypes/OvalType.h"
#include "OfficeDrawing/Shapetypes/WordArtText.h"
namespace DocFileFormat
{
VMLShapeTypeMapping::VMLShapeTypeMapping (XmlUtils::CXmlWriter* pWriter, bool isBulletPicture) : PropertiesMapping(pWriter), _lock(NULL), _isBulletPicture(isBulletPicture)
VMLShapeTypeMapping::VMLShapeTypeMapping (XmlUtils::CXmlWriter* pWriter, bool isInlineShape) : PropertiesMapping(pWriter), _lock(NULL), _isInlineShape(isInlineShape)
{
this->_lock = new XMLTools::XMLElement<wchar_t>( _T( "o:lock" ) );
appendValueAttribute( this->_lock, _T( "v:ext" ), _T( "edit" ) );
......@@ -72,7 +73,7 @@ namespace DocFileFormat
// Path
if (!pShape->Path.empty())
m_pXmlWriter->WriteAttribute( _T("path"), pShape->Path.c_str() );
else if (_isBulletPicture)
else if (_isInlineShape)
m_pXmlWriter->WriteAttribute( _T("path"), _T("m@4@5l@4@11@9@11@9@5xe"));
......@@ -87,7 +88,7 @@ namespace DocFileFormat
m_pXmlWriter->WriteAttribute( _T( "stroked" ), _T( "f" ) );
}
if ( _isBulletPicture )
if ( _isInlineShape )
{
m_pXmlWriter->WriteAttribute( _T( "o:preferrelative" ), _T( "t" ) );
}
......@@ -120,7 +121,7 @@ namespace DocFileFormat
m_pXmlWriter->WriteNodeEnd( _T( "v:formulas" ) );
}
else if (_isBulletPicture)
else if (_isInlineShape)
{
m_pXmlWriter->WriteString(_T("<v:formulas><v:f eqn=\"if lineDrawn pixelLineWidth 0\"/>\
<v:f eqn=\"sum @0 1 0\"/><v:f eqn=\"sum 0 0 @1\"/>\
......@@ -134,7 +135,7 @@ namespace DocFileFormat
// Path
m_pXmlWriter->WriteNodeBegin( _T( "v:path" ), true );
if (_isBulletPicture)
if (_isInlineShape)
{
m_pXmlWriter->WriteAttribute( _T( "o:extrusionok" ), _T( "f" ) );
m_pXmlWriter->WriteAttribute( _T( "gradientshapeok" ), _T( "t" ) );
......@@ -160,6 +161,11 @@ namespace DocFileFormat
if (pShape->ConnectorAngles.length())
m_pXmlWriter->WriteAttribute( _T( "o:connectangles" ), pShape->ConnectorAngles.c_str() );
}
WordArtTextType* wordArt = dynamic_cast<WordArtTextType*>(pShape);
if (wordArt)
{
m_pXmlWriter->WriteAttribute( _T( "textpathok" ), _T( "t" ) );
}
m_pXmlWriter->WriteNodeEnd( _T( "" ), true );
......
......@@ -41,10 +41,10 @@ namespace DocFileFormat
{
private:
XMLTools::XMLElement<wchar_t> *_lock;
bool _isBulletPicture;
bool _isInlineShape;
public:
VMLShapeTypeMapping(XmlUtils::CXmlWriter* writer, bool isBulletPicture = false );
VMLShapeTypeMapping(XmlUtils::CXmlWriter* writer, bool isInlineShape = false );
virtual ~VMLShapeTypeMapping();
virtual void Apply( IVisitable* visited );
/// Returns the id of the referenced type
......
......@@ -187,27 +187,34 @@ public:
std::wstring ReadXst()
{
std::wstring wstrResult( _T( "" ) );
if (stream)
if (!stream) return L"";
std::wstring wstrResult;
unsigned char* xstz = NULL;
unsigned char* cch = NULL;
if (olderVersion)
{
int cchSize = 2;
unsigned char* cch = this->ReadBytes( cchSize, true );
int cchSize = 1;
cch = ReadBytes( cchSize, true );
int xstzSize = FormatUtils::BytesToInt16( cch, 0, cchSize ) * 2;
unsigned char* xstz = ReadBytes(xstzSize, true);
int xstzSize = FormatUtils::BytesToUChar( cch, 0, cchSize ) * 1;
xstz = ReadBytes(xstzSize, true);
if (this->olderVersion)
{
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &wstrResult, xstz, xstzSize, ENCODING_WINDOWS_1250 );
}
else
{
int cchSize = 2;
cch = ReadBytes( cchSize, true );
int xstzSize = FormatUtils::BytesToInt16( cch, 0, cchSize ) * 2;
xstz = ReadBytes(xstzSize, true);
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &wstrResult, xstz, xstzSize, ENCODING_UTF16 );
}
RELEASEARRAYOBJECTS(xstz);
RELEASEARRAYOBJECTS(cch);
}
return wstrResult;
}
......@@ -239,21 +246,42 @@ public:
/// The string must have the following structure:
/// unsigned char 1-4: Character count (cch)
/// unsigned char 5-cch+4: ANSI characters terminated by \0
std::wstring ReadLengthPrefixedAnsiString()
std::wstring ReadLengthPrefixedAnsiString(int max_size)
{
std::wstring result;
int cch = this->ReadInt32();
unsigned int cch = ReadUInt32();
unsigned char* stringBytes = NULL;
if (cch > max_size)
{
//error ... skip to 0
int pos_orinal = GetPosition();
int pos = 0;
stringBytes = ReadBytes( max_size, true );
if (stringBytes)
{
while(pos < max_size)
{
if (stringBytes[pos] == 0)
break;
pos++;
}
}
Seek(pos_orinal + pos - 1, 0);
}else
if ( cch > 0 )
{
//dont read the terminating zero
unsigned char* stringBytes = ReadBytes( cch, true );
stringBytes = ReadBytes( cch, true );
FormatUtils::GetSTLCollectionFromBytes<std::wstring>( &result, stringBytes, ( cch - 1 ), ENCODING_WINDOWS_1250);
RELEASEARRAYOBJECTS( stringBytes );
}
RELEASEARRAYOBJECTS( stringBytes );
return result;
}
......
......@@ -60,6 +60,11 @@
#include "IVisitable.h"
#include "../Common/Callback.h"
namespace CRYPT
{
class Decryptor;
}
namespace DocFileFormat
{
class WordDocument: public IVisitable
......@@ -95,8 +100,8 @@ namespace DocFileFormat
int document_code_page;
private:
bool DecryptFile();
bool DecryptStream(std::string streamName, POLE::Storage * storageIn, POLE::Storage * storageOut);
bool DecryptOfficeFile (CRYPT::Decryptor* Decryptor);
bool DecryptStream (CRYPT::Decryptor* Decryptor, std::string streamName, POLE::Storage * storageIn, POLE::Storage * storageOut);
inline StructuredStorageReader* GetStorage() const
{
......@@ -182,16 +187,16 @@ namespace DocFileFormat
Plex<EmptyStructure> *HeaderStoriesPlex; //A plex of the header document
Plex<EmptyStructure> *IndividualCommentsPlex; // A plex with all ATRDPre10 structs
Plex<EmptyStructure> *TextboxIndividualPlex;
Plex<Tbkd> *TextboxBreakPlex; // Describes the breaks inside the textbox subdocument
Plex<Tbkd> *TextboxBreakPlexHeader; // Describes the breaks inside the header textbox subdocument
Plex<OutlineListDescriptor> *OutlineListDescriptorPlex;
Plex<Spa> *OfficeDrawingPlex;
Plex<Spa> *OfficeDrawingPlexHeader;
Plex<SectionDescriptor> *SectionPlex; // A Plex containing all section descriptors
Plex<FTXBXS> *m_arFTBXS; // FOR TEST
Plex<BookmarkFirst> *BookmarkStartPlex;
Plex<EmptyStructure> *BookmarkEndPlex;
......
......@@ -39,7 +39,7 @@
namespace ImageHelper
{
typedef struct ___tagBITMAPINFOHEADER
struct __BITMAPINFOHEADER
{
DWORD biSize;
LONG biWidth;
......@@ -52,44 +52,117 @@ namespace ImageHelper
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} ___BITMAPINFOHEADER;
};
inline static int CompareStrings (const wchar_t* str1, const wchar_t* str2)
struct __BITMAPCOREHEADER
{
CString cstr1; cstr1 = str1;
CString cstr2; cstr2 = str2;
DWORD bcSize; /* used to get to color table */
WORD bcWidth;
WORD bcHeight;
WORD bcPlanes;
WORD bcBitCount;
};
inline Global::_BlipType SaveImageToFileFromDIB(unsigned char* data, int size, const std::wstring& file_name)//without ext
{
Global::_BlipType result = Global::msoblipERROR;
CBgraFrame oFrame;
int offset = 0, biSizeImage = 0;
if (cstr1 == cstr2)
return 0;
__BITMAPINFOHEADER * header = (__BITMAPINFOHEADER*)data;
if (!header) return result;
return 1;
result == Global::msoblipDIB;
if (header->biWidth > 100000 || header->biHeight > 100000 || header->biSize != 40)
{
__BITMAPCOREHEADER * header_core = (__BITMAPCOREHEADER *)data;
if (header_core->bcSize != 12)
{
result = Global::msoblipWMF;
}
inline bool SaveImageToFileFromDIB(unsigned char* buffer, int size, const std::wstring& file)
else
{
bool result = false;
const ___BITMAPINFOHEADER* info = (___BITMAPINFOHEADER*)buffer;
offset = 12; //sizeof(BITMAPCOREHEADER)
oFrame.put_Height (header_core->bcHeight );
oFrame.put_Width (header_core->bcWidth );
int sz_bitmap = header_core->bcHeight * header_core->bcWidth * header_core->bcBitCount/ 8;
if (NULL != info && info->biSize == 40)
//if (header_core->bcWidth % 2 != 0 && sz_bitmap < size - offset)
// header_core->bcWidth++;
///???? todooo непонятно .. в biff5 нужно флипать картинку, в biff8 не ясно ( -
int stride = -(size - offset) / header_core->bcHeight;
oFrame.put_Stride (stride/*header_core->bcBitCount * header_core->bcWidth /8 */);
biSizeImage = size - offset;
if (-stride >= header_core->bcWidth && header_core->bcBitCount >=24 )
{
unsigned char* pBgraData = buffer + sizeof(___BITMAPINFOHEADER);
result = Global::msoblipPNG;
}
}
}
else
{
offset = 40; //sizeof(BITMAPINFOHEADER)
int nWidth = info->biWidth;
int nHeight = info->biHeight;
oFrame.put_Height (header->biHeight );
oFrame.put_Width (header->biWidth );
CBgraFrame oFrame;
oFrame.put_Data (pBgraData);
oFrame.put_Width (nWidth);
oFrame.put_Height (nHeight);
int sz_bitmap = header->biHeight * header->biWidth * header->biBitCount/ 8;
int nStride = info->biSizeImage / nHeight;
oFrame.put_Stride( -nStride );
//if (header->biWidth % 2 != 0 && sz_bitmap < size -offset)
// header->biWidth++;
result = oFrame.SaveFile(file, 4);
int stride = -(size - offset) / header->biHeight;
oFrame.put_Data(NULL);
if (-stride >= header->biWidth && header->biBitCount >= 24)
{
result = Global::msoblipPNG;
}
oFrame.put_Stride (stride/*header->biBitCount * header->biWidth /8*/);
biSizeImage = header->biSizeImage > 0 ? header->biSizeImage : (size - offset);
}
//------------------------------------------------------------------------------------------
if (result == Global::msoblipPNG)
{
oFrame.put_Data((unsigned char*)data + offset);
if (!oFrame.SaveFile(file_name + _T(".png"), 4/*CXIMAGE_FORMAT_PNG*/))
result = Global::msoblipERROR;
oFrame.put_Data(NULL);
}
else if (result == Global::msoblipWMF)
{
NSFile::CFileBinary file;
if (file.CreateFileW(file_name + _T(".wmf")))
{
file.WriteFile((BYTE*)data, size);
file.CloseFile();
}
}
else if (biSizeImage > 0)
{
NSFile::CFileBinary file;
if (file.CreateFileW(file_name + _T(".bmp")))
{
WORD vtType = 0x4D42; file.WriteFile((BYTE*)&vtType, 2);
DWORD dwLen = biSizeImage; file.WriteFile((BYTE*)&dwLen, 4);
DWORD dwRes = 0; file.WriteFile((BYTE*)&dwRes, 4);
DWORD dwOffset = 2; file.WriteFile((BYTE*)&dwOffset, 4);
file.WriteFile((BYTE*)data, size);
file.CloseFile();
}
}
return result;
}
}
......@@ -147,8 +220,8 @@ namespace DocFileFormat
if (Global::msoblipDIB == iter->blipType)
{//user_manual_v52.doc
std::wstring file_name = string2std_string(pathMedia.GetPath()) + FILE_SEPARATOR_STR + _T("image") + FormatUtils::IntToWideString(i++) + iter->ext;
ImageHelper::SaveImageToFileFromDIB(bytes, iter->data.size(), file_name);
std::wstring file_name = string2std_string(pathMedia.GetPath()) + FILE_SEPARATOR_STR + _T("image") + FormatUtils::IntToWideString(i++);
iter->blipType = ImageHelper::SaveImageToFileFromDIB(bytes, iter->data.size(), file_name);
}
else
{
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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