Commit 3e44b5d8 authored by alexey.musinov's avatar alexey.musinov

Merge branch 'develop' of https://github.com/ONLYOFFICE/core into develop

parents a2016d3f 511a9d02
......@@ -98,6 +98,7 @@ namespace DocFileFormat
sprmOldCChse = 73,
sprmOldCSymbol = 74,
sprmOldCFOle2 = 75,
sprmCOldHighlight = 77,
sprmOldCIstd = 80,
sprmOldCIstdPermute = 81,
sprmOldCDefault = 82,
......
......@@ -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
......
......@@ -268,7 +268,7 @@ namespace DocFileFormat
std::vector<int> bookmarks = searchBookmarks(chpxChars, cp);
//if there are bookmarks in this run, split the run into several runs
if (bookmarks.size())
if (!bookmarks.empty())
{
std::list<std::vector<wchar_t>>* runs = splitCharList(chpxChars, &bookmarks);
if (runs)
......
......@@ -103,8 +103,8 @@ namespace DocFileFormat
void DrawingPrimitive::read_fill(VirtualStreamReader* reader)
{
fillFore = read_color(reader);
fillBack = read_color(reader);
fillFore = read_color(reader);
fillPattern = reader->ReadInt16();
}
void DrawingPrimitive::read_shadow(VirtualStreamReader* reader)
......@@ -225,13 +225,34 @@ namespace DocFileFormat
}
DrawingPrimitiveTextBox::DrawingPrimitiveTextBox(VirtualStreamReader *reader, int length) : DrawingPrimitiveRect(reader, length)
{
strVmlType = L"v:rect";
//strVmlType = L"v:shape";
}
DrawingPrimitiveCTextBox::DrawingPrimitiveCTextBox(VirtualStreamReader *reader, int length) : DrawingPrimitive(reader, length)
{
strVmlType = L"v:shape";
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()
{
}
DrawingPrimitivePolyline::DrawingPrimitivePolyline(VirtualStreamReader *reader, int length) : DrawingPrimitiveLine(reader, length, false)
......
......@@ -121,38 +121,47 @@ namespace DocFileFormat
};
class DrawingPrimitiveCTextBox: public DrawingPrimitive
class DrawingPrimitiveElipse: public DrawingPrimitive
{
public:
DrawingPrimitiveCTextBox(VirtualStreamReader* reader, int length);
DrawingPrimitiveElipse(VirtualStreamReader* reader, int length);
};
class DrawingPrimitiveArc: public DrawingPrimitive
class DrawingPrimitivePolyline: public DrawingPrimitiveLine
{
public:
DrawingPrimitiveArc(VirtualStreamReader* reader, int length);
DrawingPrimitivePolyline(VirtualStreamReader* reader, int length);
bool fLeft;
bool fUp;
bool fPolygon;
short count;
std::vector<std::pair<short, short>> arPoints;
};
class DrawingPrimitiveElipse: public DrawingPrimitive
class DrawingPrimitiveCTextBox: public DrawingPrimitive
{
public:
DrawingPrimitiveElipse(VirtualStreamReader* reader, int length);
DrawingPrimitiveCTextBox(VirtualStreamReader* reader, int length);
virtual ~DrawingPrimitiveCTextBox();
unsigned short dzaOffset;
unsigned short dzaDescent;
unsigned short dzaLength;
DrawingPrimitiveTextBox *txbx;
DrawingPrimitivePolyline *polyline;
};
class DrawingPrimitivePolyline: public DrawingPrimitiveLine
class DrawingPrimitiveArc: public DrawingPrimitive
{
public:
DrawingPrimitivePolyline(VirtualStreamReader* reader, int length);
bool fPolygon;
short count;
DrawingPrimitiveArc(VirtualStreamReader* reader, int length);
std::vector<std::pair<short, short>> arPoints;
bool fLeft;
bool fUp;
};
//-------------------------------------------------------------------------------------
class DrawingPrimitives : public IVisitable, public std::vector<DrawingPrimitive*>
{
......
......@@ -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;
}
......
......@@ -48,7 +48,7 @@ namespace DocFileFormat
:
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)
cProps(0), shapeContainer(NULL), blipStoreEntry(NULL), embeddedData(NULL), embeddedDataSize(0), embeddedDataHeader(NULL)
{
//Get start and length of the PICT
int fc = GetFcPic( chpx );
......@@ -62,7 +62,7 @@ namespace DocFileFormat
:
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)
cProps(0), shapeContainer(NULL), blipStoreEntry(NULL), embeddedData(NULL), embeddedDataSize(0), embeddedDataHeader(NULL)
{
}
PictureDescriptor::~PictureDescriptor()
......@@ -80,6 +80,7 @@ namespace DocFileFormat
RELEASEOBJECT(blipStoreEntry);
RELEASEARRAYOBJECTS(embeddedData);
RELEASEARRAYOBJECTS(embeddedDataHeader);
}
void PictureDescriptor::parse(POLE::Stream* stream, int fc, int sz, bool oldVersion)
{
......@@ -91,6 +92,8 @@ namespace DocFileFormat
int lcb = reader.ReadInt32();
int pos_start = reader.GetPosition();
if (lcb > 10000000)
return;
......@@ -104,8 +107,9 @@ namespace DocFileFormat
return;
}
if (lcb >= 10)
{
if (lcb < 10)
return;
int cbHeader = reader.ReadUInt16();
mfp.mm = reader.ReadInt16();
......@@ -113,25 +117,6 @@ namespace DocFileFormat
mfp.yExt = reader.ReadInt16();
mfp.hMf = reader.ReadInt16();
if (mfp.mm == MM_ISOTROPIC || mfp.mm == MM_ANISOTROPIC)
{
Type = wmf;
mx = my = 200;
dxaGoal = mfp.xExt;
dyaGoal = mfp.yExt;
embeddedDataSize = lcb - 20;//reader.GetSize() - reader.GetPosition(); //lcb ?
embeddedData = reader.ReadBytes( embeddedDataSize, true );
WmfPlaceableFileHeader *header = (WmfPlaceableFileHeader *)embeddedData;
if (header)
{
}
}
else if (mfp.mm >= 98)
{
unsigned char* bytes = reader.ReadBytes(14, true);
rcWinMf = std::vector<unsigned char>(bytes, (bytes + 14));
RELEASEARRAYOBJECTS(bytes);
......@@ -148,29 +133,55 @@ namespace DocFileFormat
dxaCropRight = reader.ReadInt16();
dyaCropBottom = reader.ReadInt16();
short brcl = reader.ReadInt16();
int brcl = reader.ReadInt16();
// borders
int bytesCount = 4;
bytes = reader.ReadBytes( bytesCount, true );
int bytesCount = oldVersion ? 2 : 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)
......@@ -205,7 +216,6 @@ namespace DocFileFormat
}
}
}
}
/// Returns the fcPic into the "data" stream, where the PIC begins.
/// Returns -1 if the CHPX has no fcPic.
......
......@@ -129,6 +129,7 @@ namespace DocFileFormat
ShapeContainer * shapeContainer;
BlipStoreEntry * blipStoreEntry;
unsigned char *embeddedDataHeader;
unsigned char *embeddedData;
int embeddedDataSize;
};
......
......@@ -71,6 +71,11 @@ namespace DocFileFormat
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;
......@@ -137,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;
......@@ -148,7 +152,6 @@ namespace DocFileFormat
{
memcpy( sprmBytes, ( bytes + sprmStart ), sprmBytesSize );
//parse
SinglePropertyModifier sprm( sprmBytes, sprmBytesSize, oldVersion );
grpprl->push_back( sprm );
......
......@@ -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
......@@ -208,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, 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,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)
......
......@@ -130,7 +130,8 @@ namespace DocFileFormat
}
else if (m_nTBIndex + 1 < m_document->TextboxIndividualPlex->CharacterPositions.size())
{
cp = m_document->TextboxIndividualPlex->CharacterPositions[m_nTBIndex];
//todooo сделать чище
cp = m_document->TextboxIndividualPlex->CharacterPositions[m_nTBIndex] + 2;
cpEnd = m_document->TextboxIndividualPlex->CharacterPositions[m_nTBIndex + 1];
}
}
......
......@@ -34,10 +34,13 @@
#include "OfficeDrawing/GeometryBooleanProperties.h"
#include "OfficeDrawing/GeometryTextBooleanProperties.h"
#include "OfficeDrawing/MetafilePictBlip.h"
#include "../../DesktopEditor/common/String.h"
#include "../../Common/DocxFormat/Source/DocxFormat/Document.h"
#include "../../Common/DocxFormat/Source/DocxFormat/Document.h"
#include "../../DesktopEditor/common/File.h"
#include "../../DesktopEditor/raster/BgraFrame.h"
typedef struct
{
......@@ -64,6 +67,73 @@ typedef struct
namespace DocFileFormat
{
struct __BITMAPINFOHEADER
{
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
};
struct __BITMAPCOREHEADER
{
DWORD bcSize; /* used to get to color table */
WORD bcWidth;
WORD bcHeight;
WORD bcPlanes;
WORD bcBitCount;
};
Global::BlipType GetFormatPict(unsigned char* data, int size)
{
Global::BlipType btWin32 = Global::msoblipDIB;
int offset = 0, biSizeImage = 0;
__BITMAPINFOHEADER * header = (__BITMAPINFOHEADER*)data;
if (!header) return btWin32;
if (header->biWidth > 100000 || header->biHeight > 100000 || header->biSize != 40)
{
__BITMAPCOREHEADER * header_core = (__BITMAPCOREHEADER *)data;
if (header_core->bcSize != 12)
{
btWin32 = Global::msoblipWMF;
}
else
{
offset = 12; //sizeof(BITMAPCOREHEADER)
int stride = (size - offset) / header_core->bcHeight;
biSizeImage = size - offset;
if (stride >= header_core->bcWidth && header_core->bcBitCount >=24 )
{
btWin32 = Global::msoblipPNG;
}
}
}
else
{
offset = 40; //sizeof(BITMAPINFOHEADER)
int sz_bitmap = header->biHeight * header->biWidth * header->biBitCount/ 8;
int stride = (size - offset) / header->biHeight;
if (stride >= header->biWidth && header->biBitCount >= 24)
{
btWin32 = Global::msoblipPNG;
}
}
return btWin32;
}
bool ParseEmbeddedEquation( const std::string & xmlString, std::wstring & newXmlString)
{
newXmlString.clear();
......@@ -307,7 +377,6 @@ namespace DocFileFormat
return m_ShapeId;
}
/// Writes a border element
void VMLPictureMapping::writePictureBorder( const std::wstring & name, const BorderCode* brc )
{
if (!brc || name.empty()) return;
......@@ -318,8 +387,6 @@ namespace DocFileFormat
m_pXmlWriter->WriteNodeEnd ( _T( "" ), true );
}
/// Copies the picture from the binary stream to the zip archive
/// and creates the relationships for the image.
bool VMLPictureMapping::CopyPicture (PictureDescriptor* pict)
{
if (!pict) return false;
......@@ -329,47 +396,36 @@ namespace DocFileFormat
if (pict->embeddedData && pict->embeddedDataSize > 0)
{
ENHMETAHEADER3 oHeader;
int w = 0, h = 0;
oHeader.iType = 0x00000001;
oHeader.nSize = sizeof(oHeader);
Global::BlipType btWin32 = GetFormatPict(pict->embeddedData, pict->embeddedDataSize);
oHeader.rclBounds.left = 0;
oHeader.rclBounds.top = 0;
oHeader.rclBounds.right = w;
oHeader.rclBounds.bottom = h;
oHeader.rclFrame.left = 0;
oHeader.rclFrame.top = 0;
oHeader.rclFrame.right = w;
oHeader.rclFrame.bottom = h;
if (btWin32 == Global::msoblipWMF)
{
CMetaHeader oMetaHeader;
oHeader.dSignature = 0x464D4520;
oHeader.nVersion = 0x00010000;
oHeader.nBytes = pict->embeddedDataSize - 176;
oMetaHeader.rcBounds.right = pict->mfp.xExt ;
oMetaHeader.rcBounds.bottom = pict->mfp.yExt ;
oHeader.nRecords = 1;
oHeader.nHandles = 0;
WmfPlaceableFileHeader oWmfHeader = {};
oMetaHeader.ToWMFHeader(&oWmfHeader);
oHeader.sReserved = 0;
int lLenHeader = 114 + 22;
oHeader.nDescription = 0;
oHeader.offDescription = 0;
unsigned char *newData = new unsigned char[pict->embeddedDataSize + lLenHeader];
oHeader.nPalEntries = 0;
memcpy(newData, (unsigned char *)(&oWmfHeader), 22);
memcpy(newData + 22, pict->embeddedDataHeader, 114 );
oHeader.szlDevice.cx = 200;
oHeader.szlDevice.cy = 200;
memcpy(newData + lLenHeader, pict->embeddedData, pict->embeddedDataSize);
oHeader.szlMillimeters.cx = 100;
oHeader.szlMillimeters.cy = 100;
pict->embeddedDataSize += lLenHeader;
delete []pict->embeddedData;
pict->embeddedData = newData;
memcpy(pict->embeddedData, &oHeader, sizeof(oHeader));
}
m_ctx->_docx->ImagesList.push_back(ImageFileStructure(GetTargetExt(Global::msoblipDIB),
std::vector<unsigned char>(pict->embeddedData, (pict->embeddedData + pict->embeddedDataSize)), Global::msoblipDIB));
m_ctx->_docx->ImagesList.push_back(ImageFileStructure(GetTargetExt(Global::msoblipWMF), std::vector<unsigned char>(pict->embeddedData, pict->embeddedData + pict->embeddedDataSize)));
m_nImageId = m_ctx->_docx->RegisterImage(m_caller, Global::msoblipWMF);
m_nImageId = m_ctx->_docx->RegisterImage(m_caller, btWin32);
result = true;
}
else if ((oBlipEntry != NULL) && (oBlipEntry->Blip != NULL))
......@@ -379,7 +435,6 @@ namespace DocFileFormat
case Global::msoblipEMF:
case Global::msoblipWMF:
{
//it's a meta image
MetafilePictBlip* metaBlip = static_cast<MetafilePictBlip*>(oBlipEntry->Blip);
if (metaBlip)
{//decompress inside MetafilePictBlip
......@@ -405,18 +460,15 @@ namespace DocFileFormat
m_ctx->_docx->ImagesList.push_back(ImageFileStructure(GetTargetExt(oBlipEntry->btWin32),
std::vector<unsigned char>(bitBlip->m_pvBits, (bitBlip->m_pvBits + bitBlip->pvBitsSize)), oBlipEntry->btWin32));
}
}
break;
}break;
default:
{
return false;
}
break;
}break;
}
m_nImageId = m_ctx->_docx->RegisterImage(m_caller, oBlipEntry->btWin32);
result = true;
}
......@@ -430,28 +482,16 @@ namespace DocFileFormat
{
switch (nType)
{
//case Global::msoblipDIB:
// return std::wstring( _T( ".bmp" ) );
//case msoblipBMP:
// return wstring( _T( ".bmp" ) );
case Global::msoblipDIB:
return std::wstring(_T(".bmp"));
case Global::msoblipEMF:
return std::wstring(_T(".emf"));
//case msoblipGIF:
// return wstring( _T( ".gif" ) );
//case msoblipICON:
// return wstring( _T( ".ico" ) );
case Global::msoblipJPEG:
case Global::msoblipCMYKJPEG:
return std::wstring(_T(".jpg"));
//case msoblipPCX:
// return wstring( _T( ".pcx" ) );
case Global::msoblipPNG:
return std::wstring(_T(".png"));
......@@ -470,9 +510,6 @@ namespace DocFileFormat
{
switch (nType)
{
//case msoblipBMP:
// return wstring( _T( "image/bmp" ) );
case Global::msoblipEMF:
return std::wstring(OpenXmlContentTypes::Emf);
......@@ -498,6 +535,9 @@ namespace DocFileFormat
case Global::msoblipWMF:
return std::wstring(OpenXmlContentTypes::Wmf);
case Global::msoblipDIB:
return std::wstring(OpenXmlContentTypes::Bmp);
default:
return std::wstring(OpenXmlContentTypes::Png);
}
......
......@@ -95,12 +95,6 @@ namespace DocFileFormat
{
m_pBlipStore = static_cast<BlipStoreContainer*>(recBs);
}
m_offset_x.push_back(0);
m_offset_y.push_back(0);
m_scale_x.push_back(1);
m_scale_y.push_back(1);
}
VMLShapeMapping::~VMLShapeMapping()
......@@ -1333,8 +1327,8 @@ namespace DocFileFormat
{
switch ( _type )
{
//case msoblipBMP:
// return std::wstring( _T( ".bmp" ) );
case Global::msoblipDIB:
return std::wstring( _T( ".bmp" ) );
case Global::msoblipEMF:
return std::wstring( _T( ".emf" ) );
......@@ -2124,6 +2118,63 @@ namespace DocFileFormat
m_pXmlWriter->WriteNodeBegin(primitive->strVmlType.c_str(), TRUE );
if (primitive->type == 0x0007)
{
DrawingPrimitiveCTextBox * callout = dynamic_cast<DrawingPrimitiveCTextBox *>(primitive);
if ((callout) && (callout->txbx))
{
//временно обычный текстбокс
callout->txbx->xa += callout->xa;
callout->txbx->ya += callout->ya;
WritePrimitiveProps(dynamic_cast<DrawingPrimitive*>(callout->txbx), (index==0?true:false));
}
//todooo нарисовать кастомный шейп
}
else
WritePrimitiveProps(primitive, (index==0?true:false));
if (primitive->type == 0x0000)
{
index++;
while(true)
{
if (index > primitives->size() - 1)
break;
primitive = dynamic_cast<DrawingPrimitive *>(primitives->at(index));
if (primitive->type == 0x0008)
{
break;
}
index = ApplyPrimitive(primitives, index);
}
}
if (primitive->type == 0x0002 || primitive->type == 0x0007)
{
int nLTxID = currentTextBoxIndex++;;
if (-1 != nLTxID)
{
TextboxMapping textboxMapping(m_ctx, nLTxID - 1, m_pXmlWriter, m_pCaller);
//textboxMapping.SetInset(ndxTextLeft, ndyTextTop, ndxTextRight, ndyTextBottom);
m_ctx->_doc->Convert(&textboxMapping);
}
}
m_pXmlWriter->WriteNodeEnd( primitive->strVmlType.c_str() );
index++;
return index;
}
void VMLShapeMapping::WritePrimitiveProps (DrawingPrimitive * primitive, bool root)
{
TwipsValue x( primitive->xa );
TwipsValue y( primitive->ya );
TwipsValue w( primitive->dxa );
......@@ -2151,16 +2202,7 @@ namespace DocFileFormat
}
else
{
if (index > 0)
{
strStyle += _T("left:") + FormatUtils::IntToWideString( primitive->xa) + _T(";");
strStyle += _T("top:") + FormatUtils::IntToWideString( primitive->ya) + _T(";");
strStyle += _T("width:") + FormatUtils::IntToWideString( primitive->dxa) + _T(";");
strStyle += _T("height:") + FormatUtils::IntToWideString( primitive->dya) + _T(";");
}
else
if (root)
{
//strStyle += _T("left:") + FormatUtils::IntToWideString( x.ToPoints()) + _T("pt;");
//strStyle += _T("top:") + FormatUtils::IntToWideString( y.ToPoints()) + _T("pt;");
......@@ -2187,7 +2229,17 @@ namespace DocFileFormat
m_pXmlWriter->WriteAttribute( _T("coordsize"), strSize.c_str());
//m_pXmlWriter->WriteAttribute( _T("coordorigin"), strOrigin.c_str());
}
else
{
strStyle += _T("left:") + FormatUtils::IntToWideString( primitive->xa) + _T(";");
strStyle += _T("top:") + FormatUtils::IntToWideString( primitive->ya) + _T(";");
strStyle += _T("width:") + FormatUtils::IntToWideString( primitive->dxa) + _T(";");
strStyle += _T("height:") + FormatUtils::IntToWideString( primitive->dya) + _T(";");
}
}
if (primitive->fillPattern == 0)
m_pXmlWriter->WriteAttribute( _T("filled"), _T("f"));
if (primitive->type > 1)
{
m_pXmlWriter->WriteAttribute( _T("fillColor"), FormatUtils::IntToFormattedWideString(primitive->fillFore, L"#%06x").c_str());
......@@ -2203,14 +2255,11 @@ namespace DocFileFormat
m_pXmlWriter->WriteNodeEnd( _T( "" ), TRUE, FALSE );
if (primitive->type > 1)
if (primitive->type > 1 && primitive->fillPattern > 1)
{
m_pXmlWriter->WriteNodeBegin(_T("v:fill"), TRUE );
m_pXmlWriter->WriteAttribute( _T("color2"), FormatUtils::IntToFormattedWideString(primitive->fillBack, L"#%06x").c_str());
if (primitive->fillPattern > 0)
{
m_pXmlWriter->WriteAttribute( _T("type"), _T("pattern"));
}
m_pXmlWriter->WriteNodeEnd( _T( "" ), TRUE, FALSE );
m_pXmlWriter->WriteNodeEnd( _T("v:fill") );
}
......@@ -2223,51 +2272,6 @@ namespace DocFileFormat
m_pXmlWriter->WriteNodeEnd( _T( "" ), TRUE, FALSE );
m_pXmlWriter->WriteNodeEnd( _T("v:stroke") );
}
if (primitive->type == 0x0000)
{
m_offset_x.push_back(20000. / primitive->xa);
m_offset_y.push_back(20000. / primitive->ya);
m_scale_x.push_back(20000. / primitive->dxa);
m_scale_y.push_back(20000. / primitive->dya);
index++;
while(true)
{
if (index > primitives->size() - 1)
break;
primitive = dynamic_cast<DrawingPrimitive *>(primitives->at(index));
if (primitive->type == 0x0008)
{
m_offset_x.pop_back();
m_offset_y.pop_back();
m_scale_x.pop_back();
m_scale_y.pop_back();
break;
}
index = ApplyPrimitive(primitives, index);
}
}
if (primitive->type == 0x0002 || primitive->type == 0x0007)
{
int nLTxID = currentTextBoxIndex++;;
if (-1 != nLTxID)
{
TextboxMapping textboxMapping(m_ctx, nLTxID - 1, m_pXmlWriter, m_pCaller);
//textboxMapping.SetInset(ndxTextLeft, ndyTextTop, ndxTextRight, ndyTextBottom);
m_ctx->_doc->Convert(&textboxMapping);
}
}
m_pXmlWriter->WriteNodeEnd( primitive->strVmlType.c_str() );
index++;
return index;
}
}
......@@ -65,9 +65,11 @@ namespace DocFileFormat
private:
void ApplyPrimitives(DrawingPrimitives * primitives );
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
......@@ -135,12 +137,5 @@ namespace DocFileFormat
XMLTools::XMLElement<wchar_t> m_imagedata;
XMLTools::XMLElement<wchar_t> m_3dstyle;
XMLTools::XMLElement<wchar_t> m_textpath;
//----------------------------------------------------------------
std::vector<double> m_offset_x;
std::vector<double> m_offset_y;
std::vector<double> m_scale_x;
std::vector<double> m_scale_y;
};
}
......@@ -49,6 +49,7 @@ namespace DocFileFormat
EndnoteReferenceCharactersPlex(NULL), FieldsPlex(NULL), FootnoteDocumentFieldsPlex(NULL),
EndnoteDocumentFieldsPlex(NULL), HeadersAndFootersDocumentFieldsPlex(NULL), HeaderStoriesPlex(NULL),
AnnotationsReferencePlex(NULL), IndividualCommentsPlex(NULL), TextboxBreakPlex(NULL), TextboxBreakPlexHeader(NULL),
TextboxIndividualPlex(NULL),
OfficeDrawingPlex(NULL), OfficeDrawingPlexHeader(NULL), SectionPlex(NULL), BookmarkStartPlex(NULL), BookmarkEndPlex(NULL),
AutoTextPlex(NULL), AllPapxFkps(NULL), AllChpxFkps(NULL), AllPapx(NULL), AllPapxVector(NULL), AllSepx(NULL), Styles(NULL), listTable(NULL),
AnnotationOwners(NULL), DocProperties(NULL), listFormatOverrideTable(NULL), headerAndFooterTable(NULL), encryptionHeader(NULL)
......
......@@ -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
{
......
......@@ -7,7 +7,7 @@
QT -= core
QT -= gui
VERSION = 2.0.2.378
VERSION = 2.0.2.380
DEFINES += INTVER=$$VERSION
mac {
......
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