diff --git a/ASCOfficeDocFile/DocDocxConverter/DocumentMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/DocumentMapping.cpp index 57ee1503ea..bdada40d93 100644 --- a/ASCOfficeDocFile/DocDocxConverter/DocumentMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/DocumentMapping.cpp @@ -507,6 +507,7 @@ namespace DocFileFormat std::wstring equation ( _T( " Equation" ) ) ; std::wstring mergeformat( _T( " MERGEFORMAT" ) ); std::wstring quote ( _T( " QUOTE" ) ); + std::wstring chart ( _T( "Chart" ) ); if ( search( f.begin(), f.end(), form.begin(), form.end() ) != f.end() ) { @@ -531,18 +532,13 @@ namespace DocFileFormat this->_fldCharCounter++; } - else if (search( f.begin(), f.end(), quote.begin(), quote.end()) != f.end()) - { - //todooo сохранить docx с формулой мс офис в doc. - //todooo формула там где то храниться !! найти - this->_skipRuns = 3; - } else if (( search( f.begin(), f.end(), mergeformat.begin(), mergeformat.end()) != f.end()) || (( search( f.begin(), f.end(), excel.begin(), excel.end()) != f.end() || search( f.begin(), f.end(), word.begin(), word.end()) != f.end()) && ( search(f.begin(), f.end(), embed.begin(), embed.end()) != f.end() || - search( f.begin(), f.end(), link.begin(), link.end() ) != f.end()) )) + search( f.begin(), f.end(), link.begin(), link.end() ) != f.end()) && + search( f.begin(), f.end(), chart.begin(), chart.end() ) == f.end())) { m_pXmlWriter->WriteNodeBegin( _T( "w:fldChar" ), TRUE ); m_pXmlWriter->WriteAttribute( _T( "w:fldCharType" ), _T( "begin" ) ); @@ -557,7 +553,8 @@ namespace DocFileFormat this->_fldCharCounter++; } else if ( search( f.begin(), f.end(), embed.begin(), embed.end()) != f.end() - || search( f.begin(), f.end(), link.begin(), link.end() ) != f.end()) + || search( f.begin(), f.end(), link.begin(), link.end() ) != f.end() + || search( f.begin(), f.end(), quote.begin(), quote.end()) != f.end()) { int cpPic = searchNextTextMark(m_document->Text, cpFieldStart, TextMark::Picture); int cpFieldSep = searchNextTextMark(m_document->Text, cpFieldStart, TextMark::FieldSeparator); @@ -597,9 +594,18 @@ namespace DocFileFormat int fcFieldSep = m_document->m_PieceTable->FileCharacterPositions->operator []( cpFieldSep ); list* chpxs = m_document->GetCharacterPropertyExceptions( fcFieldSep, ( fcFieldSep + 1 ) ); CharacterPropertyExceptions* chpxSep = chpxs->front(); + OleObject ole ( chpxSep, m_document->GetStorage() ); OleObjectMapping oleObjectMapping( m_pXmlWriter, m_context, &pic, _caller, oVmlMapper.GetShapeId() ); + + if (oVmlMapper.m_isEquation || oVmlMapper.m_isEmbedded) + { + ole.isEquation = oVmlMapper.m_isEquation; + ole.isEmbedded = oVmlMapper.m_isEmbedded; + ole.emeddedData = oVmlMapper.m_embeddedData; + } ole.Convert( &oleObjectMapping ); + RELEASEOBJECT( chpxs ); } @@ -703,12 +709,24 @@ namespace DocFileFormat if (picture) { - VMLPictureMapping oVMLPicture(m_context, m_pXmlWriter, false, _caller); - oPicture.Convert (&oVMLPicture); + VMLPictureMapping oVmlMapper(m_context, m_pXmlWriter, false, _caller); + oPicture.Convert (&oVmlMapper); + + if (oVmlMapper.m_isEquation || oVmlMapper.m_isEmbedded) + { + OleObject ole ( chpx, m_document->GetStorage() ); + OleObjectMapping oleObjectMapping( m_pXmlWriter, m_context, &oPicture, _caller, oVmlMapper.GetShapeId() ); + + ole.isEquation = oVmlMapper.m_isEquation; + ole.isEmbedded = oVmlMapper.m_isEmbedded; + ole.emeddedData = oVmlMapper.m_embeddedData; + + ole.Convert( &oleObjectMapping ); + } }else { - VMLShapeMapping oVmlWriter (m_context, m_pXmlWriter, NULL, &oPicture, _caller); - oPicture.shapeContainer->Convert(&oVmlWriter); + VMLShapeMapping oVmlMapper(m_context, m_pXmlWriter, NULL, &oPicture, _caller); + oPicture.shapeContainer->Convert(&oVmlMapper); } m_pXmlWriter->WriteNodeEnd (_T("w:pict")); diff --git a/ASCOfficeDocFile/DocDocxConverter/OleObject.h b/ASCOfficeDocFile/DocDocxConverter/OleObject.h index 1aab20ec0e..e0ab282ca4 100644 --- a/ASCOfficeDocFile/DocDocxConverter/OleObject.h +++ b/ASCOfficeDocFile/DocDocxConverter/OleObject.h @@ -20,22 +20,28 @@ namespace DocFileFormat OnCall = 3 }; - wstring ObjectId; - 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. - wstring UserType; - wstring ClipboardFormat; - wstring Link; - wstring Program; - LinkUpdateOption updateMode; - wstring UpdateMode; + wstring ObjectId; + 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. + wstring UserType; + wstring ClipboardFormat; + wstring Link; + wstring Program; + LinkUpdateOption updateMode; + wstring UpdateMode; - OleObject( const CharacterPropertyExceptions* chpx, StructuredStorageReader* docStorage ): - fLinked(false), updateMode(NoLink) - { + bool isEquation; + bool isEmbedded; + std::string emeddedData; + + OleObject( const CharacterPropertyExceptions* chpx, StructuredStorageReader* docStorage ) + : fLinked(false), updateMode(NoLink) + { + isEquation = isEmbedded = false; + oleStorage = docStorage->GetStorage(); if ( ( chpx != NULL ) && ( docStorage != NULL ) ) @@ -177,9 +183,9 @@ namespace DocFileFormat //skip the CompObjHeader reader.ReadBytes( 28, false ); - this->UserType = reader.ReadLengthPrefixedAnsiString(); - this->ClipboardFormat = reader.ReadLengthPrefixedAnsiString(); - this->Program = reader.ReadLengthPrefixedAnsiString(); + this->UserType = reader.ReadLengthPrefixedAnsiString(); + this->ClipboardFormat = reader.ReadLengthPrefixedAnsiString(); + this->Program = reader.ReadLengthPrefixedAnsiString(); delete pCompStream; } diff --git a/ASCOfficeDocFile/DocDocxConverter/OleObjectMapping.h b/ASCOfficeDocFile/DocDocxConverter/OleObjectMapping.h index a0e58dd658..b8af7f2638 100644 --- a/ASCOfficeDocFile/DocDocxConverter/OleObjectMapping.h +++ b/ASCOfficeDocFile/DocDocxConverter/OleObjectMapping.h @@ -9,7 +9,8 @@ namespace DocFileFormat class OleObjectMapping: public AbstractOpenXmlMapping, public IMapping { public: - OleObjectMapping(XmlUtils::CXmlWriter* writer, ConversionContext* context, PictureDescriptor* pict, IMapping* caller, const wstring& shapeId) : AbstractOpenXmlMapping(writer), m_context(NULL), _pict(NULL), _caller(NULL), _shapeId(shapeId) + OleObjectMapping(XmlUtils::CXmlWriter* writer, ConversionContext* context, PictureDescriptor* pict, IMapping* caller, const wstring& shapeId) + : AbstractOpenXmlMapping(writer), m_context(NULL), _pict(NULL), _caller(NULL), _shapeId(shapeId) { m_context = context; _pict = pict; @@ -22,6 +23,13 @@ namespace DocFileFormat if ( ole != NULL ) { + if (ole->isEquation || ole->isEmbedded) + { + if (ole->isEquation) ole->ClipboardFormat = L"Equation"; + if (ole->isEmbedded) ole->ClipboardFormat = L"MSWordDocx"; + + ole->Program = L"Word.Document"; + } m_pXmlWriter->WriteNodeBegin( _T( "o:OLEObject" ), TRUE ); //type @@ -48,7 +56,7 @@ namespace DocFileFormat m_pXmlWriter->WriteAttribute( _T( "ProgID" ), ole->Program.c_str() ); //ShapeId - m_pXmlWriter->WriteAttribute( _T( "ShapeID" ), this->_shapeId.c_str() ); + m_pXmlWriter->WriteAttribute( _T( "ShapeID" ), _shapeId.c_str() ); //DrawAspect m_pXmlWriter->WriteAttribute( _T( "DrawAspect" ), _T( "Content" ) ); @@ -78,7 +86,14 @@ namespace DocFileFormat { objectExt = _T( ".ppt" ); } - + else if ( objectType == _T( "MSWordDocx" ) )//??? + { + objectExt = _T( ".docx" ); + } + else if ( objectType == _T( "Equation" ) ) + { + objectExt = _T( ".xml" ); + } return objectExt; } @@ -112,25 +127,28 @@ namespace DocFileFormat //!!!TODO: There is issue with some Office OLE Objects. Word can't open *.xls object (Excel.Chart) with set CLSID and //some Power Point Presentations, and Word Documents. Open Office CAN start this objects!!! - //CLSID clsid = GUID_NULL; wstring clsid; - wstring exelChart = _T( "Excel.Chart" ); if ( search( ole->Program.begin(), ole->Program.end(), exelChart.begin(), exelChart.end() ) == ole->Program.end() ) - { + {//?? clsid = ole->ClassId; } + OleObjectFileStructure object_descr(OleObjectMapping::GetTargetExt( ole->ClipboardFormat ), ole->ObjectId, clsid); - m_context->_docx->OleObjectsList.push_back( OleObjectFileStructure( OleObjectMapping::GetTargetExt( ole->ClipboardFormat ), ole->ObjectId, clsid ) ); + if (ole->isEquation || ole->isEmbedded) + { + object_descr.data = ole->emeddedData; + } + m_context->_docx->OleObjectsList.push_back(object_descr); } } private: ConversionContext* m_context; - PictureDescriptor* _pict; - wstring _shapeId; - IMapping* _caller; + PictureDescriptor* _pict; + std::wstring _shapeId; + IMapping* _caller; }; } diff --git a/ASCOfficeDocFile/DocDocxConverter/OpenXmlPackage.cpp b/ASCOfficeDocFile/DocDocxConverter/OpenXmlPackage.cpp index 5f44b9ce37..5713b1d56a 100644 --- a/ASCOfficeDocFile/DocDocxConverter/OpenXmlPackage.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/OpenXmlPackage.cpp @@ -101,12 +101,16 @@ namespace DocFileFormat } } - + HRESULT OpenXmlPackage::SaveEmbeddedObject( const std::wstring& fileName, const std::string& data ) + { + NSFile::CFileBinary file; + file.CreateFileW(fileName); + file.WriteFile((BYTE*)data.c_str(), data.size()); + file.CloseFile(); + return S_OK; + } HRESULT OpenXmlPackage::SaveOLEObject( const std::wstring& fileName, const OleObjectFileStructure& oleObjectFileStructure ) { - //std::ofstream fileOLE; - //fileOLE.open(fileName.c_str(), std::ios::binary|std::ios::out ); - POLE::Storage *storageOut = new POLE::Storage(fileName.c_str()); if (storageOut == NULL || docFile == NULL) return S_FALSE; @@ -118,13 +122,11 @@ namespace DocFileFormat POLE::Storage *storageInp = docFile->GetStorage()->GetStorage(); - //if (docFile->GetStorage()->GetStorage()->enterDirectory("ObjectPool")) { std::string id(oleObjectFileStructure.objectID.begin(),oleObjectFileStructure.objectID.end()); POLE::Stream* oleStorage = new POLE::Stream(storageInp, id); - //docFile->GetStorage()->GetStorage()->stream(id); - //if(docFile->GetStorage()->GetStorage()->enterDirectory(id)) + if (oleStorage) { std::string path = "ObjectPool/" + id; @@ -153,42 +155,6 @@ namespace DocFileFormat delete stream_inp; delete stream_out; } - - //std::streamsize sz = oleStorage->size(); - //unsigned char *b = new unsigned char[sz]; - - //if (b) - //{ - // sz = oleStorage->read(b,sz); - // - // ppstg->write(b, sz); - //std::vector entries; - // docFile->GetStorage()->GetStorage()->listEntries(entries); - - // for (long i=0; i GetStorage()->GetStorage()->stream(entries[i]->name()); - // - // std::streamsize sz = oleStorage->size(); - // unsigned char *b = new unsigned char[sz]; - // if (b) - // { - // POLE::Stream *new_stream = storageOut->add_stream(entries[i]->name(), sz); - - // //bool res = new_stream->resize(sz); - - // sz = oleStorage->read(b,sz); - - // //fileOLE.write((const char*) b, sz ); - // //storageOut->write(b,sz); - // sz = new_stream->write(b,sz); - // delete b; - // } - // } - // docFile->GetStorage()->GetStorage()->leaveDirectory(); - //} - - //docFile->GetStorage()->GetStorage()->leaveDirectory(); } } diff --git a/ASCOfficeDocFile/DocDocxConverter/OpenXmlPackage.h b/ASCOfficeDocFile/DocDocxConverter/OpenXmlPackage.h index 79a62b467b..d54b6676e6 100644 --- a/ASCOfficeDocFile/DocDocxConverter/OpenXmlPackage.h +++ b/ASCOfficeDocFile/DocDocxConverter/OpenXmlPackage.h @@ -7,9 +7,6 @@ #include "../../Common/DocxFormat/Source/XML/xmlutils.h" -//#include -//#include - namespace DocFileFormat { struct Relationship @@ -69,27 +66,25 @@ namespace DocFileFormat } - std::wstring ext; + std::wstring ext; std::vector data; - Global::BlipType blipType; + Global::BlipType blipType; }; struct OleObjectFileStructure { - wstring ext; - wstring objectID; - wstring clsid; - //CLSID clsid; + std::wstring ext; + std::wstring objectID; + std::wstring clsid; + + std::string data; + + OleObjectFileStructure(){} - OleObjectFileStructure() - { - //this->clsid = GUID_NULL; - } OleObjectFileStructure( const wstring& _ext, const wstring& _objectID, const wstring&/*REFCLSID*/ _clsid ): - ext(_ext), objectID(_objectID), clsid(_clsid) - { - } + ext(_ext), objectID(_objectID), clsid(_clsid){} + }; class OpenXmlPackage @@ -136,7 +131,9 @@ namespace DocFileFormat void WritePackage(); void SaveToFile( const wstring& outputDir, const wstring& fileName, const wstring& XMLContent ); void SaveToFile( const wstring& outputDir, const wstring& fileName, const void* buf, unsigned int size ); - HRESULT SaveOLEObject( const wstring& fileName, const OleObjectFileStructure& oleObjectFileStructure ); + + HRESULT SaveOLEObject ( const wstring& fileName, const OleObjectFileStructure& oleObjectFileStructure ); + HRESULT SaveEmbeddedObject ( const std::wstring& fileName, const std::string& data ); int RegisterDocument(); int RegisterFontTable(); diff --git a/ASCOfficeDocFile/DocDocxConverter/VMLPictureMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/VMLPictureMapping.cpp index af74f76fd6..0a6b73d74b 100644 --- a/ASCOfficeDocFile/DocDocxConverter/VMLPictureMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/VMLPictureMapping.cpp @@ -24,11 +24,14 @@ namespace DocFileFormat VMLPictureMapping::VMLPictureMapping(ConversionContext* ctx, XmlUtils::CXmlWriter* writer, bool olePreview, IMapping* caller, bool isBulletPicture) : PropertiesMapping(writer) { m_ctx = ctx; - m_olePreview = olePreview; + m_isOlePreview = olePreview; m_imageData = NULL; m_nImageId = 0; m_caller = caller; m_isBulletPicture = isBulletPicture; + + m_isEquation = false; + m_isEmbedded = false; m_imageData = new XMLTools::XMLElement( _T( "v:imagedata" ) ); @@ -55,6 +58,7 @@ namespace DocFileFormat //v:shapetype PictureFrameType type; type.SetType(shape->Instance); + VMLShapeTypeMapping* vmlShapeTypeMapping = new VMLShapeTypeMapping( m_pXmlWriter, m_isBulletPicture ); type.Convert( vmlShapeTypeMapping ); RELEASEOBJECT( vmlShapeTypeMapping ); @@ -80,7 +84,7 @@ namespace DocFileFormat m_pXmlWriter->WriteAttribute( _T( "id" ), m_ShapeId.c_str() ); - if (m_olePreview) + if (m_isOlePreview) { m_pXmlWriter->WriteAttribute( _T( "o:ole" ), _T( "" ) ); } @@ -90,38 +94,43 @@ namespace DocFileFormat { switch ( iter->pid ) { - //BORDERS - + case wzEquationXML: + { + m_isEquation = true; + m_embeddedData = std::string((char*)iter->opComplex, iter->op); + }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" ), ( wstring( _T( "#" ) ) + bottomColor.SixDigitHexCode ).c_str() ); } break; - case borderLeftColor: { RGBColor leftColor( (int)iter->op, RedFirst ); m_pXmlWriter->WriteAttribute( _T( "o:borderleftcolor" ), ( wstring( _T( "#" ) ) + leftColor.SixDigitHexCode ).c_str() ); } break; - case borderRightColor: { RGBColor rightColor( (int)iter->op, RedFirst ); m_pXmlWriter->WriteAttribute( _T( "o:borderrightcolor" ), ( wstring( _T( "#" ) ) + rightColor.SixDigitHexCode ).c_str() ); } break; - case borderTopColor: { RGBColor topColor( (int)iter->op, RedFirst ); m_pXmlWriter->WriteAttribute( _T( "o:bordertopcolor" ), ( wstring( _T( "#" ) ) + topColor.SixDigitHexCode ).c_str() ); } break; - - //CROPPING - +//CROPPING case cropFromBottom: { //cast to signed integer @@ -129,7 +138,6 @@ namespace DocFileFormat appendValueAttribute(m_imageData, _T( "cropbottom" ), ( FormatUtils::IntToWideString( cropBottom ) + wstring( _T( "f" ) ) ).c_str() ); } break; - case cropFromLeft: { //cast to signed integer @@ -137,7 +145,6 @@ namespace DocFileFormat appendValueAttribute(m_imageData, _T( "cropleft" ), ( FormatUtils::IntToWideString( cropLeft ) + wstring( _T( "f" ) ) ).c_str()); } break; - case cropFromRight: { //cast to signed integer @@ -145,7 +152,6 @@ namespace DocFileFormat appendValueAttribute(m_imageData, _T( "cropright" ), ( FormatUtils::IntToWideString( cropRight ) + wstring( _T( "f" ) ) ).c_str()); } break; - case cropFromTop: { //cast to signed integer diff --git a/ASCOfficeDocFile/DocDocxConverter/VMLPictureMapping.h b/ASCOfficeDocFile/DocDocxConverter/VMLPictureMapping.h index d2d8559c0d..ba08f38161 100644 --- a/ASCOfficeDocFile/DocDocxConverter/VMLPictureMapping.h +++ b/ASCOfficeDocFile/DocDocxConverter/VMLPictureMapping.h @@ -36,14 +36,20 @@ namespace DocFileFormat static std::wstring GetTargetExt (Global::BlipType nType); static std::wstring GetContentType (Global::BlipType nType); + bool m_isEquation; + bool m_isEmbedded; + std::string m_embeddedData; private: ConversionContext* m_ctx; IMapping* m_caller; int m_nImageId; std::wstring m_ShapeId; - bool m_olePreview; + + bool m_isOlePreview; + bool m_isBulletPicture; XMLTools::XMLElement* m_imageData; + }; } diff --git a/ASCOfficeDocFile/DocDocxConverter/WordprocessingDocument.cpp b/ASCOfficeDocFile/DocDocxConverter/WordprocessingDocument.cpp index 3cde1209c9..16a2a1ca95 100644 --- a/ASCOfficeDocFile/DocDocxConverter/WordprocessingDocument.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/WordprocessingDocument.cpp @@ -184,7 +184,14 @@ namespace DocFileFormat { std::wstring fileName = string2std_string(pathObjects.GetPath()) + FILE_SEPARATOR_STR + _T( "oleObject" ) + FormatUtils::IntToWideString(i++) + iter->ext; - SaveOLEObject( fileName, *iter ); + if (!iter->data.empty()) + { + SaveEmbeddedObject(fileName, iter->data); + } + else + { + SaveOLEObject( fileName, *iter ); + } } }