diff --git a/ASCOfficeDocFile/DocDocxConverter/DocumentMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/DocumentMapping.cpp index 4a3f4cb504..e3259c3756 100755 --- a/ASCOfficeDocFile/DocDocxConverter/DocumentMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/DocumentMapping.cpp @@ -786,7 +786,16 @@ namespace DocFileFormat { PictureDescriptor oPicture (chpx, m_document->bOlderVersion ? m_document->WordDocumentStream : m_document->DataStream, 0x7fffffff, m_document->bOlderVersion); - if ((oPicture.mfp.mm > 98) && (NULL != oPicture.shapeContainer)) + if (oPicture.embeddedData && oPicture.embeddedDataSize > 0) + { + m_pXmlWriter->WriteNodeBegin (_T("w:pict")); + + VMLPictureMapping oVmlMapper(m_context, m_pXmlWriter, false, _caller); + oPicture.Convert (&oVmlMapper); + + m_pXmlWriter->WriteNodeEnd (_T("w:pict")); + } + else if ((oPicture.mfp.mm > 98) && (NULL != oPicture.shapeContainer)) { m_pXmlWriter->WriteNodeBegin (_T("w:pict")); @@ -1112,7 +1121,7 @@ namespace DocFileFormat for ( std::list::iterator iter = papx->grpprl->begin(); iter != papx->grpprl->end(); iter++ ) { //find the tDef SPRM - if ( iter->OpCode == sprmTDefTable ) + if ( iter->OpCode == sprmTDefTable || iter->OpCode == sprmOldTDefTable) { unsigned char itcMac = iter->Arguments[0]; diff --git a/ASCOfficeDocFile/DocDocxConverter/PictureDescriptor.cpp b/ASCOfficeDocFile/DocDocxConverter/PictureDescriptor.cpp index ba06d34d11..d9949bfd4e 100644 --- a/ASCOfficeDocFile/DocDocxConverter/PictureDescriptor.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/PictureDescriptor.cpp @@ -32,14 +32,22 @@ #include "PictureDescriptor.h" +#ifndef MM_ISOTROPIC + #define MM_ISOTROPIC 7 +#endif + +#ifndef MM_ANISOTROPIC + #define MM_ANISOTROPIC 8 +#endif + namespace DocFileFormat { /// Parses the CHPX for a fcPic an loads the PictureDescriptor at this offset PictureDescriptor::PictureDescriptor(CharacterPropertyExceptions* chpx, POLE::Stream* stream, int size, bool oldVersion) : - dxaGoal(0), dyaGoal(0), mx(0), my(0), Type(jpg), Name( _T( "" ) ), mfp(), dxaCropLeft(0), dyaCropTop(0), + dxaGoal(0), dyaGoal(0), mx(0), my(0), Type(jpg), mfp(), dxaCropLeft(0), dyaCropTop(0), dxaCropRight(0), dyaCropBottom(0), brcTop(NULL), brcLeft(NULL), brcBottom(NULL), brcRight(NULL), dxaOrigin(0), dyaOrigin(0), - cProps(0), shapeContainer(NULL), blipStoreEntry(NULL) + cProps(0), shapeContainer(NULL), blipStoreEntry(NULL), embeddedData(NULL), embeddedDataSize(0) { //Get start and length of the PICT int fc = GetFcPic( chpx ); @@ -64,6 +72,8 @@ namespace DocFileFormat RELEASEOBJECT(shapeContainer); RELEASEOBJECT(blipStoreEntry); + + RELEASEARRAYOBJECTS(embeddedData); } void PictureDescriptor::parse(POLE::Stream* stream, int fc, int sz, bool oldVersion) { @@ -90,14 +100,25 @@ namespace DocFileFormat if (lcb >= 10) { - int cbHeader = reader.ReadUInt16(); + int cbHeader = reader.ReadUInt16(); mfp.mm = reader.ReadInt16(); mfp.xExt = reader.ReadInt16(); mfp.yExt = reader.ReadInt16(); mfp.hMf = reader.ReadInt16(); - if (mfp.mm >= 98 || oldVersion) + if (mfp.mm == MM_ISOTROPIC || mfp.mm == MM_ANISOTROPIC) + { + Type = wmf; + + mx = my = 200; + dxaGoal = mfp.xExt; + dyaGoal = mfp.yExt; + + embeddedDataSize = reader.GetSize() - reader.GetPosition(); //lcb ? + embeddedData = reader.ReadBytes( embeddedDataSize, true ); + } + else if (mfp.mm >= 98) { unsigned char* bytes = reader.ReadBytes(14, true); rcWinMf = std::vector(bytes, (bytes + 14)); @@ -118,7 +139,6 @@ namespace DocFileFormat short brcl = reader.ReadInt16(); // borders - int bytesCount = 4; bytes = reader.ReadBytes( bytesCount, true ); @@ -154,47 +174,21 @@ namespace DocFileFormat } } - if (oldVersion) + shapeContainer = dynamic_cast(RecordFactory::ReadRecord(&reader, 0)); + + long pos = reader.GetPosition(); + + if( pos < ( fc + lcb )) { - ////blipStoreEntry = new BlipStoreEntry(); + Record* rec = RecordFactory::ReadRecord( &reader, 0 ); - //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(RecordFactory::ReadRecord(&reader, 0)); - - long pos = reader.GetPosition(); - - if( pos < ( fc + lcb )) + if ((rec) && ( typeid(*rec) == typeid(BlipStoreEntry) )) { - Record* rec = RecordFactory::ReadRecord( &reader, 0 ); - - if ((rec) && ( typeid(*rec) == typeid(BlipStoreEntry) )) - { - blipStoreEntry = dynamic_cast( rec ); - } - else - { - RELEASEOBJECT(rec); - } + blipStoreEntry = dynamic_cast( rec ); + } + else + { + RELEASEOBJECT(rec); } } } diff --git a/ASCOfficeDocFile/DocDocxConverter/PictureDescriptor.h b/ASCOfficeDocFile/DocDocxConverter/PictureDescriptor.h index 5a31ef7108..2228f6d82b 100644 --- a/ASCOfficeDocFile/DocDocxConverter/PictureDescriptor.h +++ b/ASCOfficeDocFile/DocDocxConverter/PictureDescriptor.h @@ -49,26 +49,26 @@ namespace DocFileFormat struct MetafilePicture { - /// Specifies the mapping mode in which the picture is drawn. + // Specifies the mapping mode in which the picture is drawn. short mm; - /// Specifies the size of the metafile picture for all modes except the MM_ISOTROPIC and MM_ANISOTROPIC modes. - /// (For more information about these modes, see the yExt member.) - /// The x-extent specifies the width of the rectangle within which the picture is drawn. - /// The coordinates are in units that correspond to the mapping mode. + // Specifies the size of the metafile picture for all modes except the MM_ISOTROPIC and MM_ANISOTROPIC modes. + // (For more information about these modes, see the yExt member.) + // The x-extent specifies the width of the rectangle within which the picture is drawn. + // The coordinates are in units that correspond to the mapping mode. short xExt; - /// Specifies the size of the metafile picture for all modes except the MM_ISOTROPIC and MM_ANISOTROPIC modes. - /// The y-extent specifies the height of the rectangle within which the picture is drawn. - /// The coordinates are in units that correspond to the mapping mode. - /// For MM_ISOTROPIC and MM_ANISOTROPIC modes, which can be scaled, the xExt and yExt members - /// contain an optional suggested size in MM_HIMETRIC units. - /// For MM_ANISOTROPIC pictures, xExt and yExt can be zero when no suggested size is supplied. - /// For MM_ISOTROPIC pictures, an aspect ratio must be supplied even when no suggested size is given. - /// (If a suggested size is given, the aspect ratio is implied by the size.) - /// To give an aspect ratio without implying a suggested size, set xExt and yExt to negative values - /// whose ratio is the appropriate aspect ratio. - /// The magnitude of the negative xExt and yExt values is ignored; only the ratio is used. + // Specifies the size of the metafile picture for all modes except the MM_ISOTROPIC and MM_ANISOTROPIC modes. + // The y-extent specifies the height of the rectangle within which the picture is drawn. + // The coordinates are in units that correspond to the mapping mode. + // For MM_ISOTROPIC and MM_ANISOTROPIC modes, which can be scaled, the xExt and yExt members + // contain an optional suggested size in MM_HIMETRIC units. + // For MM_ANISOTROPIC pictures, xExt and yExt can be zero when no suggested size is supplied. + // For MM_ISOTROPIC pictures, an aspect ratio must be supplied even when no suggested size is given. + // (If a suggested size is given, the aspect ratio is implied by the size.) + // To give an aspect ratio without implying a suggested size, set xExt and yExt to negative values + // whose ratio is the appropriate aspect ratio. + // The magnitude of the negative xExt and yExt values is ignored; only the ratio is used. short yExt; - /// Handle to a memory metafile. + // Handle to a memory metafile. short hMf; }; @@ -80,14 +80,15 @@ namespace DocFileFormat friend class NumberingMapping; public: - /// Parses the CHPX for a fcPic an loads the PictureDescriptor at this offset + // Parses the CHPX for a fcPic an loads the PictureDescriptor at this offset PictureDescriptor( CharacterPropertyExceptions* chpx, POLE::Stream* stream, int size, bool oldVersion); virtual ~PictureDescriptor(); private: void parse( POLE::Stream* stream, int fc, int sz, bool oldVersion); - /// Returns the fcPic into the "data" stream, where the PIC begins. - /// Returns -1 if the CHPX has no fcPic. + + // Returns the fcPic into the "data" stream, where the PIC begins. + // Returns -1 if the CHPX has no fcPic. static int GetFcPic( const CharacterPropertyExceptions* chpx ); void Clear(); @@ -95,45 +96,37 @@ namespace DocFileFormat static const short MM_SHAPE = 0x0064; // Shape object static const short MM_SHAPEFILE = 0x0066; // Shape file - /// Rectangle for window origin and extents when metafile is stored (ignored if 0). - std::vector rcWinMf; - /// Horizontal measurement in twips of the rectangle the picture should be imaged within. - short dxaGoal; - /// Vertical measurement in twips of the rectangle the picture should be imaged within. - short dyaGoal; - /// Horizontal scaling factor supplied by user expressed in .001% units - unsigned short mx; - /// Vertical scaling factor supplied by user expressed in .001% units - unsigned short my; - /// The type of the picture - PictureType Type; - /// The name of the picture - std::wstring Name; - /// The data of the windows metafile picture (WMF) - MetafilePicture mfp; - /// The amount the picture has been cropped on the left in twips - short dxaCropLeft; - /// The amount the picture has been cropped on the top in twips - short dyaCropTop; - /// The amount the picture has been cropped on the right in twips - short dxaCropRight; - /// The amount the picture has been cropped on the bottom in twips - short dyaCropBottom; - /// Border above picture - BorderCode *brcTop; - /// Border to the left of the picture - BorderCode *brcLeft; - /// Border below picture - BorderCode *brcBottom; - /// Border to the right of the picture - BorderCode *brcRight; - /// Horizontal offset of hand annotation origin - short dxaOrigin; - /// vertical offset of hand annotation origin - short dyaOrigin; - /// unused + std::vector rcWinMf; // Rectangle for window origin and extents when metafile is stored (ignored if 0). + + short dxaGoal; // Horizontal measurement in twips of the rectangle the picture should be imaged within. + short dyaGoal; // Vertical measurement in twips of the rectangle the picture should be imaged within. + + unsigned short mx; // Horizontal scaling factor supplied by user expressed in .001% units + unsigned short my; // Vertical scaling factor supplied by user expressed in .001% units + + PictureType Type; // The type of the picture + + MetafilePicture mfp; + + short dxaCropLeft; // The amount the picture has been cropped on the left in twips + short dyaCropTop; // The amount the picture has been cropped on the top in twips + short dxaCropRight; // The amount the picture has been cropped on the right in twips + short dyaCropBottom; // The amount the picture has been cropped on the bottom in twips + + BorderCode *brcTop; // Border above picture + BorderCode *brcLeft; // Border to the left of the picture + BorderCode *brcBottom; // Border below picture + BorderCode *brcRight; // Border to the right of the picture + + short dxaOrigin; // horizontal offset of hand annotation origin + short dyaOrigin; // vertical offset of hand annotation origin + short cProps; - ShapeContainer* shapeContainer; - BlipStoreEntry* blipStoreEntry; +//------------------ + ShapeContainer * shapeContainer; + BlipStoreEntry * blipStoreEntry; + + unsigned char *embeddedData; + short embeddedDataSize; }; } diff --git a/ASCOfficeDocFile/DocDocxConverter/PropertyExceptions.cpp b/ASCOfficeDocFile/DocDocxConverter/PropertyExceptions.cpp index c1fd19567d..e39e5912f7 100644 --- a/ASCOfficeDocFile/DocDocxConverter/PropertyExceptions.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/PropertyExceptions.cpp @@ -91,28 +91,32 @@ namespace DocFileFormat //some opCode need special treatment switch ( opCode ) { + case sprmOldTDefTable: + case sprmOldTDefTable10: case sprmTDefTable: case sprmTDefTable10: { //The opSize of the table definition is stored in 2 bytes instead of 1 lenByte = 2; - opSize = FormatUtils::BytesToInt16( bytes, ( sprmStart + 2 ), size ); + opSize = FormatUtils::BytesToInt16( bytes, ( sprmStart + opCodeSize ), size ); //Word adds an additional unsigned char to the opSize to compensate the additional //unsigned char needed for the length opSize--; }break; + case sprmOldPChgTabs: case sprmPChgTabs: { //The tab operand can be bigger than 255 bytes (length unsigned char is set to 255). //In this case a special calculation of the opSize is needed lenByte = 1; - opSize = bytes[sprmStart + 2]; + opSize = bytes[sprmStart + opCodeSize]; if ( opSize == 255 ) { - unsigned char itbdDelMax = bytes[sprmStart + 3]; - unsigned char itbdAddMax = bytes[sprmStart + 3 + 2 * itbdDelMax]; + unsigned char itbdDelMax = bytes[sprmStart + opCodeSize + 1]; + unsigned char itbdAddMax = bytes[sprmStart + opCodeSize + 1 + 2 * itbdDelMax]; + opSize = (short)( ( itbdDelMax * 4 + itbdAddMax * 3 ) - 1 ); } }break; diff --git a/ASCOfficeDocFile/DocDocxConverter/SinglePropertyModifier.cpp b/ASCOfficeDocFile/DocDocxConverter/SinglePropertyModifier.cpp index 99463b2237..915b1b0bf9 100644 --- a/ASCOfficeDocFile/DocDocxConverter/SinglePropertyModifier.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/SinglePropertyModifier.cpp @@ -86,6 +86,8 @@ namespace DocFileFormat { switch ( OpCode ) { + case sprmOldTDefTable: + case sprmOldTDefTable10: case sprmTDefTable: case sprmTDefTable10: { @@ -99,6 +101,7 @@ namespace DocFileFormat } break; + case sprmOldPChgTabs: case sprmPChgTabs: { argumentsSize = bytes[2]; @@ -205,7 +208,7 @@ namespace DocFileFormat } static const unsigned char OldOperandSizeTable[] = { - 0, 0, 2, 255, 1, 1, 1, 1, 1, 1, 1, 1, 255, 1, 1, 255, 2, 2, 2, 2, 4, 2, 2, 255, 1, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 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 }; unsigned char SinglePropertyModifier::GetOldOperandSize(unsigned char code) diff --git a/ASCOfficeDocFile/DocDocxConverter/TableInfo.h b/ASCOfficeDocFile/DocDocxConverter/TableInfo.h index b6df085388..32621baaf1 100644 --- a/ASCOfficeDocFile/DocDocxConverter/TableInfo.h +++ b/ASCOfficeDocFile/DocDocxConverter/TableInfo.h @@ -35,64 +35,73 @@ namespace DocFileFormat { - class TableInfo - { - public: - bool fInTable; - bool fTtp; - bool fInnerTtp; - bool fInnerTableCell; - unsigned int iTap; + class TableInfo + { + public: + bool fInTable; + bool fTtp; + bool fInnerTtp; + bool fInnerTableCell; + unsigned int iTap; - TableInfo( ParagraphPropertyExceptions* papx ): - fInTable(false), fTtp(false), fInnerTtp(false), fInnerTableCell(false), iTap(0) - { - if ( papx != NULL ) + TableInfo( ParagraphPropertyExceptions* papx ): + fInTable(false), fTtp(false), fInnerTtp(false), fInnerTableCell(false), iTap(0) { - for ( std::list::iterator iter = papx->grpprl->begin(); iter != papx->grpprl->end(); iter++ ) - { - if ( iter->OpCode == sprmPFInTable ) - { - this->fInTable = ( iter->Arguments[0] == 1 ) ? (true) : (false); - } - - if ( iter->OpCode == sprmPFTtp ) - { - this->fTtp = ( iter->Arguments[0] == 1 ) ? (true) : (false); - } - - if ( iter->OpCode == sprmPFInnerTableCell ) - { - this->fInnerTableCell = ( iter->Arguments[0] == 1 ) ? (true) : (false); - } - - if ( iter->OpCode == sprmPFInnerTtp ) - { - this->fInnerTtp = ( iter->Arguments[0] == 1 ) ? (true) : (false); - } - - if ( iter->OpCode == sprmPItap ) - { - this->iTap = FormatUtils::BytesToUInt32( iter->Arguments, 0, iter->argumentsSize ); - - if ( this->iTap > 0 ) - { - this->fInTable = true; - } - } - - if ( (int)( iter->OpCode ) == 0x66A ) - { - //add value! - this->iTap = FormatUtils::BytesToUInt32( iter->Arguments, 0, iter->argumentsSize ); + if ( papx != NULL ) + { + for ( std::list::iterator iter = papx->grpprl->begin(); iter != papx->grpprl->end(); iter++ ) + { + switch(iter->OpCode) + { + case sprmOldPFInTable: + case sprmPFInTable: + { + fInTable = ( iter->Arguments[0] == 1 ) ? (true) : (false); + }break; + + //case sprmOldPFTtp: + case sprmOldPTtp: + case sprmPFTtp: + { + fTtp = ( iter->Arguments[0] == 1 ) ? (true) : (false); + }break; - if ( this->iTap > 0 ) - { - this->fInTable = true; - } - } - } + //case sprmOldPFInnerTableCell: + case sprmPFInnerTableCell: + { + fInnerTableCell = ( iter->Arguments[0] == 1 ) ? (true) : (false); + }break; + + //case sprmOldPFInnerTtp: + case sprmPFInnerTtp: + { + fInnerTtp = ( iter->Arguments[0] == 1 ) ? (true) : (false); + }break; + + //case sprmOldPItap: + case sprmPItap: + { + iTap = FormatUtils::BytesToUInt32( iter->Arguments, 0, iter->argumentsSize ); + + if ( iTap > 0 ) + { + fInTable = true; + } + }break; + } + + if ( (int)( iter->OpCode ) == sprmTCnf )//66a + { + //add value! + iTap = FormatUtils::BytesToUInt32( iter->Arguments, 0, iter->argumentsSize ); + + if ( iTap > 0 ) + { + fInTable = true; + } + } + } + } } - } - }; + }; } \ No newline at end of file diff --git a/ASCOfficeDocFile/DocDocxConverter/TableMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/TableMapping.cpp index 75b2e5818f..8d536b7c72 100644 --- a/ASCOfficeDocFile/DocDocxConverter/TableMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/TableMapping.cpp @@ -353,7 +353,7 @@ namespace DocFileFormat } Table::Table( DocumentMapping* _documentMapping, int _cp, unsigned int _depth ): - cpStart(_cp), cpEnd(_cp), depth(_depth), documentMapping(_documentMapping) + cpStart(_cp), cpEnd(_cp), depth(_depth), documentMapping(_documentMapping) { if ( documentMapping != NULL ) { @@ -371,8 +371,8 @@ namespace DocFileFormat TableInfo tai( papx ); - TableRow tableRow( documentMapping, _cp ); - TableCell tableCell( documentMapping, _cp ); + TableRow tableRow ( documentMapping, _cp ); + TableCell tableCell ( documentMapping, _cp ); do { diff --git a/ASCOfficeDocFile/DocDocxConverter/TablePropertyExceptions.h b/ASCOfficeDocFile/DocDocxConverter/TablePropertyExceptions.h index 08e51082c5..1619039a1b 100644 --- a/ASCOfficeDocFile/DocDocxConverter/TablePropertyExceptions.h +++ b/ASCOfficeDocFile/DocDocxConverter/TablePropertyExceptions.h @@ -54,7 +54,7 @@ namespace DocFileFormat /// Extracts the TAPX SPRMs out of a PAPX TablePropertyExceptions (ParagraphPropertyExceptions* papx, POLE::Stream* dataStream, bool oldVersion) : - PropertyExceptions() + PropertyExceptions() { VirtualStreamReader oBinReader(dataStream, 0, oldVersion); @@ -62,7 +62,7 @@ namespace DocFileFormat for (std::list::iterator oSpmIter = papx->grpprl->begin(); oSpmIter != papx->grpprl->end(); ++oSpmIter) { - if (oSpmIter->OpCode == sprmTDefTableShd || oSpmIter->OpCode == sprmTDefTableShd2nd || + if (oSpmIter->OpCode == sprmTDefTableShd || oSpmIter->OpCode == sprmTDefTableShd2nd || oSpmIter->OpCode == sprmTDefTableShd2nd || oSpmIter->OpCode == sprmTDefTableShd3rd) { m_bSkipShading97 = TRUE; @@ -72,7 +72,7 @@ namespace DocFileFormat { grpprl->push_back(*oSpmIter); } - else if ((int)(oSpmIter->OpCode) == sprmPTableProps) + else if (oSpmIter->OpCode == sprmPTableProps) { //there is a native TAP in the data stream unsigned int fc = FormatUtils::BytesToUInt32(oSpmIter->Arguments, 0, oSpmIter->argumentsSize); diff --git a/ASCOfficeDocFile/DocDocxConverter/VMLPictureMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/VMLPictureMapping.cpp index a9045cae8f..f1654358c2 100644 --- a/ASCOfficeDocFile/DocDocxConverter/VMLPictureMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/VMLPictureMapping.cpp @@ -132,149 +132,153 @@ namespace DocFileFormat void VMLPictureMapping::Apply( IVisitable* visited ) { PictureDescriptor* pict = static_cast(visited); + if (!pict) return; + double xScaling = pict->mx / 1000.0; + double yScaling = pict->my / 1000.0; + + TwipsValue width( ( pict->dxaGoal - ( pict->dxaCropLeft + pict->dxaCropRight ) ) * xScaling ); + TwipsValue height( ( pict->dyaGoal - ( pict->dyaCropTop + pict->dyaCropBottom ) ) * yScaling ); + + std::wstring widthString = FormatUtils::DoubleToWideString( width.ToPoints() ); + std::wstring heightString = FormatUtils::DoubleToWideString( height.ToPoints() ); + + std::list options; + + PictureFrameType type; if ((pict->shapeContainer || pict->blipStoreEntry) && pict->shapeContainer->Children.size() > 0) { - Shape* shape = static_cast(*(pict->shapeContainer->Children.begin())); - std::list options = pict->shapeContainer->ExtractOptions(); + Shape* shape = static_cast(*(pict->shapeContainer->Children.begin())); + options = pict->shapeContainer->ExtractOptions(); //v:shapetype - PictureFrameType type; type.SetType(shape->Instance); VMLShapeTypeMapping* vmlShapeTypeMapping = new VMLShapeTypeMapping( m_pXmlWriter, m_isBulletPicture ); type.Convert( vmlShapeTypeMapping ); RELEASEOBJECT( vmlShapeTypeMapping ); - - //v:shape - m_pXmlWriter->WriteNodeBegin( _T( "v:shape" ), true ); - m_pXmlWriter->WriteAttribute( _T( "type" ), ( std::wstring( _T( "#" ) ) + VMLShapeTypeMapping::GenerateTypeId( &type ) ).c_str() ); - - std::wstring style; - - double xScaling = pict->mx / 1000.0; - double yScaling = pict->my / 1000.0; - - TwipsValue width( ( pict->dxaGoal - ( pict->dxaCropLeft + pict->dxaCropRight ) ) * xScaling ); - TwipsValue height( ( pict->dyaGoal - ( pict->dyaCropTop + pict->dyaCropBottom ) ) * yScaling ); - - std::wstring widthString = FormatUtils::DoubleToWideString( width.ToPoints() ); - std::wstring heightString = FormatUtils::DoubleToWideString( height.ToPoints() ); - - style = std::wstring( _T( "width:" ) ) + widthString + std::wstring( _T( "pt;" ) ) + std::wstring( _T( "height:" ) ) + heightString + std::wstring( _T( "pt;" ) ); - - m_pXmlWriter->WriteAttribute( _T( "style" ), style.c_str() ); - - m_pXmlWriter->WriteAttribute( _T( "id" ), m_ShapeId.c_str() ); - - if (m_isOlePreview) - { - m_pXmlWriter->WriteAttribute( _T( "o:ole" ), _T( "" ) ); - } - else if (m_isBulletPicture) - { - m_pXmlWriter->WriteAttribute( _T( "o:bullet" ), _T( "1" ) ); - } - - std::list::iterator end = options.end(); - for (std::list::iterator iter = options.begin(); iter != end; ++iter) - { - switch ( iter->pid ) - { - case wzEquationXML: - { - m_isEquation = true; - m_isEmbedded = true; - - m_embeddedData = std::string((char*)iter->opComplex, iter->op); - - if (ParseEmbeddedEquation( m_embeddedData, m_equationXml)) - { - m_isEmbedded = false; - } - }break; - case metroBlob: - { - //встроенная неведомая хуйня - m_isEmbedded = true; - m_embeddedData = std::string((char*)iter->opComplex, iter->op); - }break; -//BORDERS - case borderBottomColor: - { - RGBColor bottomColor( (int)iter->op, RedFirst ); - m_pXmlWriter->WriteAttribute( _T( "o:borderbottomcolor" ), ( std::wstring( _T( "#" ) ) + bottomColor.SixDigitHexCode ).c_str() ); - } - break; - case borderLeftColor: - { - RGBColor leftColor( (int)iter->op, RedFirst ); - m_pXmlWriter->WriteAttribute( _T( "o:borderleftcolor" ), ( std::wstring( _T( "#" ) ) + leftColor.SixDigitHexCode ).c_str() ); - } - break; - case borderRightColor: - { - RGBColor rightColor( (int)iter->op, RedFirst ); - m_pXmlWriter->WriteAttribute( _T( "o:borderrightcolor" ), ( std::wstring( _T( "#" ) ) + rightColor.SixDigitHexCode ).c_str() ); - } - break; - case borderTopColor: - { - RGBColor topColor( (int)iter->op, RedFirst ); - m_pXmlWriter->WriteAttribute( _T( "o:bordertopcolor" ), ( std::wstring( _T( "#" ) ) + topColor.SixDigitHexCode ).c_str() ); - } - break; -//CROPPING - case cropFromBottom: - { - //cast to signed integer - int cropBottom = (int)iter->op; - appendValueAttribute(m_imageData, _T( "cropbottom" ), ( FormatUtils::IntToWideString( cropBottom ) + std::wstring( _T( "f" ) ) ).c_str() ); - } - break; - case cropFromLeft: - { - //cast to signed integer - int cropLeft = (int)iter->op; - appendValueAttribute(m_imageData, _T( "cropleft" ), ( FormatUtils::IntToWideString( cropLeft ) + std::wstring( _T( "f" ) ) ).c_str()); - } - break; - case cropFromRight: - { - //cast to signed integer - int cropRight = (int)iter->op; - appendValueAttribute(m_imageData, _T( "cropright" ), ( FormatUtils::IntToWideString( cropRight ) + std::wstring( _T( "f" ) ) ).c_str()); - } - break; - case cropFromTop: - { - //cast to signed integer - int cropTop = (int)iter->op; - appendValueAttribute(m_imageData, _T( "croptop" ), ( FormatUtils::IntToWideString( cropTop ) + std::wstring( _T( "f" ) ) ).c_str()); - } - break; - } - } - - m_pXmlWriter->WriteNodeEnd( _T( "" ), TRUE, FALSE ); - - if (CopyPicture(pict->blipStoreEntry)) - { - //v:imageData - appendValueAttribute(m_imageData, _T( "r:id" ), ( std::wstring( _T( "rId" ) ) + FormatUtils::IntToWideString(m_nImageId) ).c_str()); - appendValueAttribute(m_imageData, _T( "o:title" ) , _T( "" )); - m_pXmlWriter->WriteString(m_imageData->GetXMLString().c_str()); - } - - //borders - writePictureBorder( _T( "bordertop" ), pict->brcTop ); - writePictureBorder( _T( "borderleft" ), pict->brcLeft ); - writePictureBorder( _T( "borderbottom" ), pict->brcBottom ); - writePictureBorder( _T( "borderright" ), pict->brcRight ); - - //close v:shape - m_pXmlWriter->WriteNodeEnd( _T( "v:shape" ) ); } + else if (pict->embeddedData) + { + type.SetType(msosptPictureFrame); + } + m_pXmlWriter->WriteNodeBegin( _T( "v:shape" ), true ); + + m_pXmlWriter->WriteAttribute( _T( "type" ), std::wstring( _T( "#" ) + VMLShapeTypeMapping::GenerateTypeId(&type)).c_str()); + + std::wstring style = std::wstring( _T( "width:" ) ) + widthString + std::wstring( _T( "pt;" ) ) + std::wstring( _T( "height:" ) ) + heightString + std::wstring( _T( "pt;" ) ); + + m_pXmlWriter->WriteAttribute( _T( "style" ), style.c_str() ); + + m_pXmlWriter->WriteAttribute( _T( "id" ), m_ShapeId.c_str() ); + + if (m_isOlePreview) + { + m_pXmlWriter->WriteAttribute( _T( "o:ole" ), _T( "" ) ); + } + else if (m_isBulletPicture) + { + m_pXmlWriter->WriteAttribute( _T( "o:bullet" ), _T( "1" ) ); + } + + std::list::iterator end = options.end(); + for (std::list::iterator iter = options.begin(); iter != end; ++iter) + { + switch ( iter->pid ) + { + case wzEquationXML: + { + m_isEquation = true; + m_isEmbedded = true; + + m_embeddedData = std::string((char*)iter->opComplex, iter->op); + + if (ParseEmbeddedEquation( m_embeddedData, m_equationXml)) + { + m_isEmbedded = false; + } + }break; + case metroBlob: + { + //встроенная неведомая хуйня + m_isEmbedded = true; + m_embeddedData = std::string((char*)iter->opComplex, iter->op); + }break; +//BORDERS + case borderBottomColor: + { + RGBColor bottomColor( (int)iter->op, RedFirst ); + m_pXmlWriter->WriteAttribute( _T( "o:borderbottomcolor" ), ( std::wstring( _T( "#" ) ) + bottomColor.SixDigitHexCode ).c_str() ); + } + break; + case borderLeftColor: + { + RGBColor leftColor( (int)iter->op, RedFirst ); + m_pXmlWriter->WriteAttribute( _T( "o:borderleftcolor" ), ( std::wstring( _T( "#" ) ) + leftColor.SixDigitHexCode ).c_str() ); + } + break; + case borderRightColor: + { + RGBColor rightColor( (int)iter->op, RedFirst ); + m_pXmlWriter->WriteAttribute( _T( "o:borderrightcolor" ), ( std::wstring( _T( "#" ) ) + rightColor.SixDigitHexCode ).c_str() ); + } + break; + case borderTopColor: + { + RGBColor topColor( (int)iter->op, RedFirst ); + m_pXmlWriter->WriteAttribute( _T( "o:bordertopcolor" ), ( std::wstring( _T( "#" ) ) + topColor.SixDigitHexCode ).c_str() ); + } + break; +//CROPPING + case cropFromBottom: + { + //cast to signed integer + int cropBottom = (int)iter->op; + appendValueAttribute(m_imageData, _T( "cropbottom" ), ( FormatUtils::IntToWideString( cropBottom ) + std::wstring( _T( "f" ) ) ).c_str() ); + } + break; + case cropFromLeft: + { + //cast to signed integer + int cropLeft = (int)iter->op; + appendValueAttribute(m_imageData, _T( "cropleft" ), ( FormatUtils::IntToWideString( cropLeft ) + std::wstring( _T( "f" ) ) ).c_str()); + } + break; + case cropFromRight: + { + //cast to signed integer + int cropRight = (int)iter->op; + appendValueAttribute(m_imageData, _T( "cropright" ), ( FormatUtils::IntToWideString( cropRight ) + std::wstring( _T( "f" ) ) ).c_str()); + } + break; + case cropFromTop: + { + //cast to signed integer + int cropTop = (int)iter->op; + appendValueAttribute(m_imageData, _T( "croptop" ), ( FormatUtils::IntToWideString( cropTop ) + std::wstring( _T( "f" ) ) ).c_str()); + } + break; + } + } + + m_pXmlWriter->WriteNodeEnd( _T( "" ), TRUE, FALSE ); + + if (CopyPicture(pict)) + { + //v:imageData + appendValueAttribute(m_imageData, _T( "r:id" ), ( std::wstring( _T( "rId" ) ) + FormatUtils::IntToWideString(m_nImageId) ).c_str()); + appendValueAttribute(m_imageData, _T( "o:title" ) , _T( "" )); + m_pXmlWriter->WriteString(m_imageData->GetXMLString().c_str()); + } + + //borders + writePictureBorder( _T( "bordertop" ), pict->brcTop ); + writePictureBorder( _T( "borderleft" ), pict->brcLeft ); + writePictureBorder( _T( "borderbottom" ), pict->brcBottom ); + writePictureBorder( _T( "borderright" ), pict->brcRight ); + + //close v:shape + m_pXmlWriter->WriteNodeEnd( _T( "v:shape" ) ); } std::wstring VMLPictureMapping::GetShapeId () const @@ -283,9 +287,11 @@ namespace DocFileFormat } /// Writes a border element - void VMLPictureMapping::writePictureBorder( const wchar_t* name, const BorderCode* brc ) + void VMLPictureMapping::writePictureBorder( const std::wstring & name, const BorderCode* brc ) { - m_pXmlWriter->WriteNodeBegin( ( std::wstring( _T( "w10:" ) ) + std::wstring( name ) ).c_str(), true ); + if (!brc || name.empty()) return; + + m_pXmlWriter->WriteNodeBegin( ( std::wstring( _T( "w10:" ) ) + name).c_str(), true ); m_pXmlWriter->WriteAttribute( _T( "type" ), getBorderType( brc->brcType ).c_str() ); m_pXmlWriter->WriteAttribute( _T( "width" ), FormatUtils::IntToWideString( brc->dptLineWidth ).c_str() ); m_pXmlWriter->WriteNodeEnd ( _T( "" ), true ); @@ -293,12 +299,20 @@ namespace DocFileFormat /// Copies the picture from the binary stream to the zip archive /// and creates the relationships for the image. - bool VMLPictureMapping::CopyPicture (BlipStoreEntry* oBlipEntry) + bool VMLPictureMapping::CopyPicture (PictureDescriptor* pict) { + if (!pict) return false; bool result = false; - // write the blip - if ((oBlipEntry != NULL) && (oBlipEntry->Blip != NULL)) + BlipStoreEntry* oBlipEntry = pict->blipStoreEntry; + + if (pict->embeddedData && pict->embeddedDataSize > 0) + { + m_ctx->_docx->ImagesList.push_back(ImageFileStructure(GetTargetExt(Global::msoblipWMF), std::vector(pict->embeddedData, pict->embeddedData + pict->embeddedDataSize))); + m_nImageId = m_ctx->_docx->RegisterImage(m_caller, Global::msoblipWMF); + result = true; + } + else if ((oBlipEntry != NULL) && (oBlipEntry->Blip != NULL)) { switch (oBlipEntry->btWin32) { @@ -336,9 +350,7 @@ namespace DocFileFormat default: { - result = false; - - return result; + return false; } break; } diff --git a/ASCOfficeDocFile/DocDocxConverter/VMLPictureMapping.h b/ASCOfficeDocFile/DocDocxConverter/VMLPictureMapping.h index 431a640638..84e81f85ff 100644 --- a/ASCOfficeDocFile/DocDocxConverter/VMLPictureMapping.h +++ b/ASCOfficeDocFile/DocDocxConverter/VMLPictureMapping.h @@ -56,13 +56,13 @@ namespace DocFileFormat private: /// Writes a border element - void writePictureBorder (const wchar_t* name, const BorderCode* brc); + void writePictureBorder (const std::wstring & name, const BorderCode* brc); void appendStyleProperty( std::wstring* b, const std::wstring& propName, const std::wstring& propValue ) const; protected: /// Copies the picture from the binary stream to the zip archive /// and creates the relationships for the image. - bool CopyPicture (BlipStoreEntry* oBlipEntry); + bool CopyPicture (PictureDescriptor* pict); public: