diff --git a/ASCOfficeDocxFile2/BinWriter/BinWriters.cpp b/ASCOfficeDocxFile2/BinWriter/BinWriters.cpp index bea2fec2a3..d895438e8c 100644 --- a/ASCOfficeDocxFile2/BinWriter/BinWriters.cpp +++ b/ASCOfficeDocxFile2/BinWriter/BinWriters.cpp @@ -3254,6 +3254,25 @@ void BinaryDocumentTableWriter::WriteAltChunk(OOX::Media& oAltChunkFile) // m_oParamsWriter.m_pFontProcessor->setFontTable(oDocx.m_pFontTable); oBinaryDocumentEmbTableWriter.WriteDocumentContent(oDocx.m_pDocument->m_arrItems); } + else + { + OOX::CDocxFlat oDocxFlat = OOX::CDocxFlat(OOX::CPath(sResultDocxDir)); + if (oDocxFlat.m_pDocument.IsInit()) + { + ParamsDocumentWriter oParamsDocumentWriterEmb(oDocxFlat.m_pDocument.GetPointer()); + + ParamsWriter oParamsWriterEmb( m_oParamsWriter.m_pCBufferedStream, + m_oParamsWriter.m_pFontProcessor, + m_oParamsWriter.m_pOfficeDrawingConverter, + m_oParamsWriter.m_pEmbeddedFontsManager); + + //oParamsWriterEmb.m_poTheme = oDocxFlat.m_pTheme; + //oParamsWriterEmb.m_oSettings = oDocxFlat.m_pSettings; + + BinaryDocumentTableWriter oBinaryDocumentEmbTableWriter(oParamsWriterEmb, oParamsDocumentWriterEmb, &oParamsWriterEmb.m_mapIgnoreComments, NULL); + oBinaryDocumentEmbTableWriter.WriteDocumentContent(oDocxFlat.m_pDocument->m_arrItems); + } + } } NSDirectory::DeleteDirectory(sResultDocxDir); } diff --git a/ASCOfficeOdfFileW/OdfFileWTest/OdfFileWTest.cpp b/ASCOfficeOdfFileW/OdfFileWTest/OdfFileWTest.cpp index 14d79a25ba..f295c6f1b3 100644 --- a/ASCOfficeOdfFileW/OdfFileWTest/OdfFileWTest.cpp +++ b/ASCOfficeOdfFileW/OdfFileWTest/OdfFileWTest.cpp @@ -71,6 +71,7 @@ HRESULT convert_single(std::wstring srcFileName) switch(fileChecker.nFileType) { case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX: + case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX_FLAT: case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCM: dstPath += L"-my.odt"; type = L"text"; break; case AVS_OFFICESTUDIO_FILE_DOCUMENT_DOTX: @@ -102,25 +103,34 @@ HRESULT convert_single(std::wstring srcFileName) // распаковываем исходник во временную директорию COfficeUtils oCOfficeUtils(NULL); if (S_OK != oCOfficeUtils.ExtractToDirectory(srcFileName.c_str(), srcTempPath.c_str(), NULL, 0)) - return S_FALSE; + { + //may be flat + srcTempPath = srcFileName; + } Oox2Odf::Converter converter(srcTempPath, type, L"C:\\Windows\\Fonts", bTemplate); std::wstring sPassword;// = L"password"; - converter.convert(); - converter.write(dstTempPath, srcTempPath, sPassword, L"hiuh56f56tfy7g"); - - NSDirectory::DeleteDirectory(srcTempPath); - - if (hr != S_OK) return hr; + if (false == converter.convert()) + { + return S_FALSE; + } + if (false == converter.write(dstTempPath, srcTempPath, sPassword, L"hiuh56f56tfy7g")) + { + return S_FALSE; + } + if (srcFileName != srcTempPath) + { + NSDirectory::DeleteDirectory(srcTempPath); + } if (S_OK != oCOfficeUtils.CompressFileOrDirectory(dstTempPath.c_str(), dstPath.c_str(), false, sPassword.empty() ? Z_DEFLATED : 0)) return hr; NSDirectory::DeleteDirectory(dstTempPath); - return 0; + return S_OK; } HRESULT convert_directory(std::wstring pathName) { diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.cpp b/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.cpp index d4e2423697..5c0d3d188d 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.cpp +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.cpp @@ -91,22 +91,24 @@ namespace Oox2Odf if (impl_ )delete impl_ ; } - void Converter::convert() + bool Converter::convert() { - if (!impl_)return; - impl_->convertDocument(); + if (!impl_)return false; + + return impl_->convertDocument(); } - void Converter::write(const std::wstring & out_path, const std::wstring & temp_path, const std::wstring & password, const std::wstring & documentID) const + bool Converter::write(const std::wstring & out_path, const std::wstring & temp_path, const std::wstring & password, const std::wstring & documentID) const { - if (!impl_)return; + if (!impl_)return false; + return impl_->write(out_path, temp_path, password, documentID); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////// -void OoxConverter::write(const std::wstring & out_path, const std::wstring & temp_path, const std::wstring & password, const std::wstring & documentID) +bool OoxConverter::write(const std::wstring & out_path, const std::wstring & temp_path, const std::wstring & password, const std::wstring & documentID) { - if (!output_document)return; + if (!output_document)return false; if (false == documentID.empty()) { @@ -129,6 +131,8 @@ void OoxConverter::write(const std::wstring & out_path, const std::wstring & tem NSDirectory::DeleteDirectory(temp_folder); } + + return true; } std::wstring EncodeBase64(const std::string & value) { diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.h b/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.h index cc98a30942..9643ff282e 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.h +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/Converter.h @@ -373,9 +373,9 @@ namespace Oox2Odf class OoxConverter { public: - virtual void convertDocument() = 0; + virtual bool convertDocument() = 0; - void write(const std::wstring & out_path, const std::wstring & temp_path, const std::wstring & password, const std::wstring & documentID); + bool write(const std::wstring & out_path, const std::wstring & temp_path, const std::wstring & password, const std::wstring & documentID); OoxConverter() { diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp b/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp index f380c9f588..8bc2e63fe5 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.cpp @@ -109,6 +109,12 @@ DocxConverter::DocxConverter(const std::wstring & path, bool bTemplate) docx_document = new OOX::CDocx(oox_path); + if (docx_document && !docx_document->m_pDocument) + { + delete docx_document; docx_document = NULL; + docx_flat_document = new OOX::CDocxFlat(oox_path); + } + output_document = new odf_writer::package::odf_document(L"text", bTemplate); odt_context = new odf_writer::odt_conversion_context(output_document); @@ -118,9 +124,10 @@ DocxConverter::DocxConverter(const std::wstring & path, bool bTemplate) } DocxConverter::~DocxConverter() { - if (odt_context) delete odt_context; odt_context = NULL; - if (docx_document) delete docx_document; docx_document = NULL; - if (output_document) delete output_document; output_document = NULL; + if (odt_context) delete odt_context; odt_context = NULL; + if (output_document) delete output_document; output_document = NULL; + if (docx_document) delete docx_document; docx_document = NULL; + if (docx_flat_document) delete docx_flat_document; docx_flat_document = NULL; } odf_writer::odf_conversion_context* DocxConverter::odf_context() { @@ -148,7 +155,7 @@ NSCommon::smart_ptr DocxConverter::find_file_by_id(const std::wstring if (oox_current_child_document) oFile = oox_current_child_document->Find(sId); - else if (docx_document->m_pDocument) + else if ((docx_document) && (docx_document->m_pDocument)) oFile = docx_document->m_pDocument->Find(sId); return oFile; @@ -176,10 +183,10 @@ std::wstring DocxConverter::find_link_by_id (const std::wstring & sId, int type) return ref; } -void DocxConverter::convertDocument() +bool DocxConverter::convertDocument() { - if (!docx_document) return; - if (!odt_context) return; + if (!odt_context) return false; + if (!docx_document && !docx_flat_document) return false; odt_context->start_document(); @@ -191,14 +198,17 @@ void DocxConverter::convertDocument() convert_document(); //удалим уже ненужный документ docx - delete docx_document; docx_document = NULL; + if (docx_document) delete docx_document; docx_document = NULL; + if (docx_flat_document) delete docx_flat_document; docx_flat_document = NULL; odt_context->end_document(); } void DocxConverter::convert_document() { - if (!docx_document->m_pDocument)return; + OOX::CDocument *doc = docx_document ? docx_document->m_pDocument : (docx_flat_document ? docx_flat_document->m_pDocument.GetPointer() : NULL); + + if (!doc)return; std::vector<_section> sections; //---------------------------------------------------------------------------------------------------------- @@ -207,13 +217,13 @@ void DocxConverter::convert_document() OOX::Logic::CSectionProperty* prev = NULL; - for (size_t i = 0; i < docx_document->m_pDocument->m_arrItems.size(); ++i) + for (size_t i = 0; i < doc->m_arrItems.size(); ++i) { - if ((docx_document->m_pDocument->m_arrItems[i]) == NULL) continue; + if ((doc->m_arrItems[i]) == NULL) continue; - if (docx_document->m_pDocument->m_arrItems[i]->getType() == OOX::et_w_p) + if (doc->m_arrItems[i]->getType() == OOX::et_w_p) { - OOX::Logic::CParagraph * para = dynamic_cast(docx_document->m_pDocument->m_arrItems[i]); + OOX::Logic::CParagraph * para = dynamic_cast(doc->m_arrItems[i]); if ((para) && (para->m_oParagraphProperty)) { @@ -236,16 +246,16 @@ void DocxConverter::convert_document() } _section section; - section.props = docx_document->m_pDocument->m_oSectPr.GetPointer(); + section.props = doc->m_oSectPr.GetPointer(); section.start_para = last_section_start; - section.end_para = docx_document->m_pDocument->m_arrItems.size(); + section.end_para = doc->m_arrItems.size(); section.bContinue = compare (prev, section.props); sections.push_back(section); //---------------------------------------------------------------------------------------------------------- - convert(docx_document->m_pDocument->m_oSectPr.GetPointer(), false, L"Standard", true); + convert(doc->m_oSectPr.GetPointer(), false, L"Standard", true); odt_context->text_context()->clear_params(); @@ -255,11 +265,14 @@ void DocxConverter::convert_document() for (size_t i = sections[sect].start_para; i < sections[sect].end_para; ++i) { - convert(docx_document->m_pDocument->m_arrItems[i]); + convert(doc->m_arrItems[i]); } } //----------------------------------------------------------------------------------------------------------------- - OoxConverter::convert (docx_document->m_pJsaProject); + if (docx_document) + { + OoxConverter::convert (docx_document->m_pJsaProject); + } } std::wstring DocxConverter::dump_text(OOX::WritingElement *oox_unknown) { @@ -1921,7 +1934,14 @@ void DocxConverter::convert(OOX::Logic::CSectionProperty *oox_section_pr, bool b //nullable > m_oCode; } - convert(docx_document->m_pDocument->m_oBackground.GetPointer(), 1);//подложка - вот в таком она месте :(, причём одна на все разделы, не как в оо + if (docx_document) + { + convert(docx_document->m_pDocument->m_oBackground.GetPointer(), 1);//подложка - вот в таком она месте :(, причём одна на все разделы, не как в оо + } + else if (docx_flat_document) + { + //convert(docx_flat_document->m_oBgPict.GetPointer(), 1); + } //nullable m_oTextDirection; //nullable > m_oRtlGutter; //nullable m_oVAlign; @@ -3386,6 +3406,7 @@ void DocxConverter::convert(ComplexTypes::Word::CColor *color, _CP_OPT(odf_types PPTX::Logic::ClrMap* DocxConverter::oox_clrMap() { //return current_clrMap; todoooo + if (!docx_document) return NULL; if (!docx_document->m_pSettings) return NULL; return docx_document->m_pSettings->m_oClrSchemeMapping.GetPointer(); @@ -3394,31 +3415,32 @@ void DocxConverter::convert_settings() { if (!odt_context) return; - if (!docx_document->m_pSettings) return; + OOX::CSettings *settings = docx_document ? docx_document->m_pSettings : NULL;/*(docx_flat_document ? docx_flat_document->m_pStyles.GetPointer() : NULL);*/ + if (!settings) return; - if (docx_document->m_pSettings->m_oWriteProtection.IsInit()) + if (settings->m_oWriteProtection.IsInit()) { } - if (docx_document->m_pSettings->m_oZoom.IsInit()) + if (settings->m_oZoom.IsInit()) { } - if (docx_document->m_pSettings->m_oMirrorMargins.IsInit()) + if (settings->m_oMirrorMargins.IsInit()) { odt_context->page_layout_context()->set_pages_mirrored(true); } - odt_context->page_layout_context()->even_and_left_headers_ = docx_document->m_pSettings->m_oEvenAndOddHeaders.IsInit(); + odt_context->page_layout_context()->even_and_left_headers_ = settings->m_oEvenAndOddHeaders.IsInit(); - if (docx_document->m_pSettings->m_oPrintTwoOnOne.IsInit()) + if (settings->m_oPrintTwoOnOne.IsInit()) { - if (docx_document->m_pSettings->m_oGutterAtTop.IsInit()){} //portrait + if (settings->m_oGutterAtTop.IsInit()){} //portrait else {}//landscape } - if (docx_document->m_pSettings->m_oDefaultTabStop.IsInit()) + if (settings->m_oDefaultTabStop.IsInit()) { _CP_OPT(odf_types::length) length; - convert(docx_document->m_pSettings->m_oDefaultTabStop->m_oVal.GetPointer(), length); + convert(settings->m_oDefaultTabStop->m_oVal.GetPointer(), length); odf_writer::odf_style_state_ptr state; if (odt_context->styles_context()->find_odf_default_style_state(odf_types::style_family::Paragraph, state) && state) @@ -3438,7 +3460,7 @@ void DocxConverter::convert_lists_styles() { if (!odt_context) return; - OOX::CNumbering * lists_styles = docx_document->m_pNumbering; + OOX::CNumbering * lists_styles = docx_document ? docx_document->m_pNumbering : NULL; if (!lists_styles)return; @@ -3477,24 +3499,25 @@ void DocxConverter::convert_styles() { if (!odt_context) return; - if (!docx_document->m_pStyles)return; + OOX::CStyles *styles = docx_document ? docx_document->m_pStyles : (docx_flat_document ? docx_flat_document->m_pStyles.GetPointer() : NULL); + if (!styles)return; //nullable m_oLatentStyles; - convert(docx_document->m_pStyles->m_oDocDefaults.GetPointer()); + convert(styles->m_oDocDefaults.GetPointer()); - for (size_t i=0; i< docx_document->m_pStyles->m_arrStyle.size(); i++) + for (size_t i=0; i< styles->m_arrStyle.size(); i++) { - if (docx_document->m_pStyles->m_arrStyle[i] == NULL) continue; + if (styles->m_arrStyle[i] == NULL) continue; if (!current_font_size.empty()) { current_font_size.erase(current_font_size.begin() + 1, current_font_size.end()); } - convert(docx_document->m_pStyles->m_arrStyle[i]); + convert(styles->m_arrStyle[i]); - if (i == 0 && docx_document->m_pStyles->m_arrStyle[i]->m_oDefault.IsInit() && docx_document->m_pStyles->m_arrStyle[i]->m_oDefault->ToBool()) + if (i == 0 && styles->m_arrStyle[i]->m_oDefault.IsInit() && styles->m_arrStyle[i]->m_oDefault->ToBool()) { //NADIE_COMO_TU.docx тут дефолтовый стиль не прописан явно, берем тот что Normal odf_writer::odf_style_state_ptr def_style_state; diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.h b/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.h index 25434ac0df..916450f654 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.h +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/DocxConverter.h @@ -41,6 +41,7 @@ namespace OOX { class CDocx; + class CDocxFlat; class CTheme; class CDocDefaults; class CStyle; @@ -146,7 +147,7 @@ namespace Oox2Odf DocxConverter(const std::wstring & path, bool bTemplate); ~DocxConverter(); - virtual void convertDocument(); + virtual bool convertDocument(); virtual OOX::IFileContainer *current_document(); virtual odf_writer::odf_conversion_context *odf_context(); @@ -167,6 +168,7 @@ namespace Oox2Odf bool bContinue = false; } *current_section_properties; OOX::CDocx *docx_document; + OOX::CDocxFlat *docx_flat_document; odf_writer::odt_conversion_context *odt_context; OOX::Logic::CSectionProperty *last_section_properties; diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/Oox2OdfConverter.h b/ASCOfficeOdfFileW/source/Oox2OdfConverter/Oox2OdfConverter.h index cd7e28d530..8aa2bfc5fc 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/Oox2OdfConverter.h +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/Oox2OdfConverter.h @@ -43,9 +43,9 @@ namespace Oox2Odf Converter(const std::wstring & path, const std::wstring & type, const std::wstring & fontsPath, bool bTemplate); virtual ~Converter(); - void convert(); + bool convert(); - void write(const std::wstring & out_path, const std::wstring & temp_path, const std::wstring & password, const std::wstring & documentID) const; + bool write(const std::wstring & out_path, const std::wstring & temp_path, const std::wstring & password, const std::wstring & documentID) const; OoxConverter * get_ooxConverter() { return impl_; } diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/PptxConverter.cpp b/ASCOfficeOdfFileW/source/Oox2OdfConverter/PptxConverter.cpp index 9e6ebf47c3..0bb955d087 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/PptxConverter.cpp +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/PptxConverter.cpp @@ -173,10 +173,10 @@ std::wstring PptxConverter::find_link_by_id (const std::wstring & sId, int type) return ref; } -void PptxConverter::convertDocument() +bool PptxConverter::convertDocument() { - if (!pptx_document) return; - if (!odp_context) return; + if (!pptx_document) return false; + if (!odp_context) return false; odp_context->start_document(); @@ -189,6 +189,8 @@ void PptxConverter::convertDocument() delete pptx_document; pptx_document = NULL; odp_context->end_document(); + + return true; } void PptxConverter::convert_styles() { diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/PptxConverter.h b/ASCOfficeOdfFileW/source/Oox2OdfConverter/PptxConverter.h index d18d942fa5..1882d0c68e 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/PptxConverter.h +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/PptxConverter.h @@ -116,7 +116,7 @@ namespace Oox2Odf PptxConverter(const std::wstring & path, bool bTemplate); ~PptxConverter(); - virtual void convertDocument(); + virtual bool convertDocument(); virtual OOX::IFileContainer *current_document(); virtual odf_writer::odf_conversion_context *odf_context(); diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/XlsxConverter.cpp b/ASCOfficeOdfFileW/source/Oox2OdfConverter/XlsxConverter.cpp index b9b3688427..80c62e8b26 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/XlsxConverter.cpp +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/XlsxConverter.cpp @@ -135,11 +135,11 @@ std::wstring XlsxConverter::find_link_by_id (const std::wstring & sId, int type) } -void XlsxConverter::convertDocument() +bool XlsxConverter::convertDocument() { - if (!xlsx_document) return; - if (!output_document) return; - if (!ods_context) return; + if (!xlsx_document) return false; + if (!output_document) return false; + if (!ods_context) return false; ods_context->start_document(); @@ -150,6 +150,8 @@ void XlsxConverter::convertDocument() delete xlsx_document; xlsx_document = NULL; ods_context->end_document(); + + return true; } void XlsxConverter::convert_sheets() diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/XlsxConverter.h b/ASCOfficeOdfFileW/source/Oox2OdfConverter/XlsxConverter.h index f237abd028..4f6ef098bd 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/XlsxConverter.h +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/XlsxConverter.h @@ -146,7 +146,7 @@ namespace Oox2Odf XlsxConverter(const std::wstring & path, bool bTemplate); ~XlsxConverter(); - virtual void convertDocument(); + virtual bool convertDocument(); virtual OOX::IFileContainer *current_document(); virtual odf_writer::odf_conversion_context *odf_context(); diff --git a/Common/DocxFormat/Source/DocxFormat/Document.h b/Common/DocxFormat/Source/DocxFormat/Document.h index 7503df161b..4c116a4b08 100644 --- a/Common/DocxFormat/Source/DocxFormat/Document.h +++ b/Common/DocxFormat/Source/DocxFormat/Document.h @@ -192,7 +192,7 @@ namespace OOX //-------------------------------------------------------------------------------- // CDocument 17.2.3 (Part 1) //-------------------------------------------------------------------------------- - class CDocument : public OOX::File, public IFileContainer + class CDocument : public OOX::File, public IFileContainer, public WritingElement { public: CDocument(OOX::Document *pMain) : File(pMain), IFileContainer(pMain) @@ -211,11 +211,32 @@ namespace OOX read( oRootPath, oPath ); } + CDocument(XmlUtils::CXmlNode& oNode) : File(NULL), IFileContainer(NULL) + { + m_bMacroEnabled = false; + + fromXML( oNode ); + } + CDocument(XmlUtils::CXmlLiteReader& oReader) : File(NULL), IFileContainer(NULL) + { + m_bMacroEnabled = false; + + fromXML( oReader ); + } virtual ~CDocument() { ClearItems(); } - + const CDocument& operator =(const XmlUtils::CXmlNode& oNode) + { + fromXML( (XmlUtils::CXmlNode&)oNode ); + return *this; + } + const CDocument& operator =(const XmlUtils::CXmlLiteReader& oReader) + { + fromXML( (XmlUtils::CXmlLiteReader&)oReader ); + return *this; + } virtual void read(const CPath& oPath) { //don't use this. use read(const CPath& oRootPath, const CPath& oFilePath) @@ -333,73 +354,12 @@ namespace OOX std::wstring sName = oReader.GetName(); if ( _T("w:document") == sName || _T("w:wordDocument") == sName) { - ReadAttributes( oReader ); - - if ( !oReader.IsEmptyNode() ) - { - int nDocumentDepth = oReader.GetDepth(); - while ( oReader.ReadNextSiblingNode( nDocumentDepth ) ) - { - sName = oReader.GetName(); - - if ( _T("w:body") == sName && !oReader.IsEmptyNode() ) - { - int nBodyDepth = oReader.GetDepth(); - - CreateElements(oReader, nBodyDepth); - } - else if ( _T("w:background") == sName ) - m_oBackground = oReader; - } - } + fromXML(oReader); } } virtual void write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const { - std::wstring sXml = L""; - - if ( m_oBackground.IsInit() ) - sXml += m_oBackground->toXML(); - - sXml += _T(""); - - for ( size_t i = 0; i < m_arrItems.size(); ++i) - { - if ( m_arrItems[i] ) - { - sXml += m_arrItems[i]->toXML(); - } - } - - if ( m_oSectPr.IsInit() ) - sXml += m_oSectPr->toXML(); - - sXml += _T(""); + std::wstring sXml = toXML(); CDirectory::SaveToFile( oPath.GetPath(), sXml ); @@ -540,27 +500,198 @@ mc:Ignorable=\"w14 w15 wp14\">"; //pPara->AddHyperlink( rId, sText ); } } - - private: void ReadAttributes(XmlUtils::CXmlLiteReader& oReader) { - // Читаем атрибуты WritingElement_ReadAttributes_Start( oReader ) WritingElement_ReadAttributes_ReadSingle( oReader, _T("w:conformance"), m_oConformance ) WritingElement_ReadAttributes_End( oReader ) } - public: + virtual void fromXML(XmlUtils::CXmlNode& oNode) + { + } + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader) + { + ReadAttributes( oReader ); + + if ( oReader.IsEmptyNode() ) + return; + + int nDocumentDepth = oReader.GetDepth(); + while ( oReader.ReadNextSiblingNode( nDocumentDepth ) ) + { + std::wstring sName = oReader.GetName(); + + if ( L"w:body" == sName && !oReader.IsEmptyNode() ) + { + int nBodyDepth = oReader.GetDepth(); + + CreateElements(oReader, nBodyDepth); + } + else if ( L"w:background" == sName ) + { + m_oBackground = oReader; + } + else if ( L"wx:sect" == sName && !oReader.IsEmptyNode() ) + { + int nWxSect = oReader.GetDepth(); + CreateElements(oReader, nWxSect); + } + } + } + virtual std::wstring toXML() const + { + std::wstring sXml = L""; + + if ( m_oBackground.IsInit() ) + sXml += m_oBackground->toXML(); + + sXml += _T(""); + + for ( size_t i = 0; i < m_arrItems.size(); ++i) + { + if ( m_arrItems[i] ) + { + sXml += m_arrItems[i]->toXML(); + } + } + + if ( m_oSectPr.IsInit() ) + sXml += m_oSectPr->toXML(); + + sXml += _T(""); + + return sXml; + } + virtual EElementType getType() const + { + return et_w_document; + } +//--------------------------------------------------------------------------------------------- bool m_bMacroEnabled; CPath m_oReadPath; - // Attributes + SimpleTypes::CConformanceClass m_oConformance; - // Childs - nullable m_oSectPr; - nullable m_oBackground; + nullable m_oSectPr; + nullable m_oBackground; - std::vector m_arrItems; + std::vector m_arrItems; }; +//---------------------------------------------------------------------------------------------------------------- + class CDocxFlat : public OOX::Document, public OOX::File, public WritingElement + { + public: + + CDocxFlat() : OOX::File(dynamic_cast(this)) + { + } + CDocxFlat(const CPath& oFilePath) : OOX::File(this) + { + read( oFilePath ); + } + + virtual void read(const CPath& oFilePath) + { + XmlUtils::CXmlLiteReader oReader; + + if ( !oReader.FromFile( oFilePath.GetPath() ) ) + return; + + if ( !oReader.ReadNextNode() ) + return; + + fromXML(oReader); + } + virtual void write(const CPath& oFilePath, const CPath& oDirectory, CContentTypes& oContent) const + { + std::wstring sXml = toXML(); + + NSFile::CFileBinary file; + file.CreateFileW(oFilePath.GetPath()); + file.WriteStringUTF8(sXml); + file.CloseFile(); + } + virtual const OOX::FileType type() const + { + return FileTypes::DocumentFlat; + } + virtual const CPath DefaultDirectory() const + { + return type().DefaultDirectory(); + } + virtual const CPath DefaultFileName() const + { + return type().DefaultFileName(); + } + virtual void fromXML(XmlUtils::CXmlNode& oNode) + { + } + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader) + { + if ( oReader.IsEmptyNode() ) + return; + + int nStylesDepth = oReader.GetDepth(); + while ( oReader.ReadNextSiblingNode( nStylesDepth ) ) + { + std::wstring sName = oReader.GetName(); + + if ( L"w:body" == sName ) + m_pDocument = oReader; + else if ( L"w:styles" == sName ) + m_pStyles = oReader; + else if ( L"w:bgPict" == sName ) + { + //m_oBgPict = oReader; + } + } + } + virtual std::wstring toXML() const + { + std::wstring sXml = L""; + + return sXml; + } + virtual EElementType getType() const + { + return et_w_wordDocument; + } +//----------------------------------------------------------------------- + + nullable m_pDocument; + nullable m_pStyles; + //nullable m_oBgPict; + //nullable m_pEndnotePr; + //nullable m_pFootnotePr; + //nullable m_pApp; + + }; + } // namespace OOX diff --git a/Common/DocxFormat/Source/DocxFormat/FileTypes.h b/Common/DocxFormat/Source/DocxFormat/FileTypes.h index a4fb4879b5..d605112962 100644 --- a/Common/DocxFormat/Source/DocxFormat/FileTypes.h +++ b/Common/DocxFormat/Source/DocxFormat/FileTypes.h @@ -56,6 +56,8 @@ namespace OOX L"application/vnd.ms-word.document.macroEnabled.main+xml", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"); + const FileType DocumentFlat (L"", L"", L"", L""); + const FileType Theme (L"theme", L"theme.xml", L"application/vnd.openxmlformats-officedocument.theme+xml", L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme", diff --git a/Common/DocxFormat/Source/DocxFormat/Styles.h b/Common/DocxFormat/Source/DocxFormat/Styles.h index 946d66592d..e4334f3c9d 100644 --- a/Common/DocxFormat/Source/DocxFormat/Styles.h +++ b/Common/DocxFormat/Source/DocxFormat/Styles.h @@ -768,10 +768,9 @@ namespace OOX //-------------------------------------------------------------------------------- // Styles 17.7.4.18 (Part 1) //-------------------------------------------------------------------------------- - class CStyles : public OOX::File + class CStyles : public OOX::File, public WritingElement { public: - CStyles(OOX::Document *pMain) : OOX::File(pMain) { CDocx* docx = dynamic_cast(File::m_pMainDocument); @@ -784,6 +783,14 @@ namespace OOX read( oPath ); } + CStyles(XmlUtils::CXmlNode& oNode) : File(NULL) + { + fromXML( oNode ); + } + CStyles(XmlUtils::CXmlLiteReader& oReader) : File(NULL) + { + fromXML( oReader ); + } virtual ~CStyles() { for (unsigned int nIndex = 0; nIndex < m_arrStyle.size(); nIndex++ ) @@ -795,8 +802,17 @@ namespace OOX m_arrStyleNamesMap.clear(); } + const CStyles& operator =(const XmlUtils::CXmlNode& oNode) + { + fromXML( (XmlUtils::CXmlNode&)oNode ); + return *this; + } - public: + const CStyles& operator =(const XmlUtils::CXmlLiteReader& oReader) + { + fromXML( (XmlUtils::CXmlLiteReader&)oReader ); + return *this; + } virtual void read(const CPath& oFilePath) { XmlUtils::CXmlLiteReader oReader; @@ -808,36 +824,63 @@ namespace OOX return; std::wstring sName = oReader.GetName(); - if ( _T("w:styles") == sName && !oReader.IsEmptyNode() ) + if ( _T("w:styles") == sName) { - int nStylesDepth = oReader.GetDepth(); - while ( oReader.ReadNextSiblingNode( nStylesDepth ) ) - { - sName = oReader.GetName(); - - if ( _T("w:style") == sName ) - { - OOX::CStyle *oStyle = new OOX::CStyle (oReader); - if (oStyle) - { - if (oStyle->m_oName.IsInit()) - { - m_arrStyleNamesMap[oStyle->m_oName->ToString()] = (int)m_arrStyle.size(); - } - m_arrStyle.push_back( oStyle ); - } - } - else if ( _T("w:docDefaults") == sName ) - m_oDocDefaults = oReader; - else if ( _T("w:latentStyles") == sName ) - m_oLatentStyles = oReader; - } + fromXML(oReader); } } virtual void write(const CPath& oFilePath, const CPath& oDirectory, CContentTypes& oContent) const { - std::wstring sXml; - sXml = _T(""); + std::wstring sXml = toXML(); + + CDirectory::SaveToFile( oFilePath.GetPath(), sXml ); + } + virtual const OOX::FileType type() const + { + return FileTypes::Style; + } + virtual const CPath DefaultDirectory() const + { + return type().DefaultDirectory(); + } + virtual const CPath DefaultFileName() const + { + return type().DefaultFileName(); + } + virtual void fromXML(XmlUtils::CXmlNode& oNode) + { + } + virtual void fromXML(XmlUtils::CXmlLiteReader& oReader) + { + if ( oReader.IsEmptyNode() ) + return; + + int nStylesDepth = oReader.GetDepth(); + while ( oReader.ReadNextSiblingNode( nStylesDepth ) ) + { + std::wstring sName = oReader.GetName(); + + if ( L"w:style" == sName ) + { + OOX::CStyle *oStyle = new OOX::CStyle (oReader); + if (oStyle) + { + if (oStyle->m_oName.IsInit()) + { + m_arrStyleNamesMap[oStyle->m_oName->ToString()] = (int)m_arrStyle.size(); + } + m_arrStyle.push_back( oStyle ); + } + } + else if ( L"w:docDefaults" == sName ) + m_oDocDefaults = oReader; + else if ( L"w:latentStyles" == sName ) + m_oLatentStyles = oReader; + } + } + virtual std::wstring toXML() const + { + std::wstring sXml = L""; if ( m_oDocDefaults.IsInit() ) sXml += m_oDocDefaults->toXML(); @@ -851,30 +894,18 @@ namespace OOX sXml += m_arrStyle[nIndex]->toXML(); } sXml += _T(""); - - CDirectory::SaveToFile( oFilePath.GetPath(), sXml ); + return sXml; } - - public: - virtual const OOX::FileType type() const + virtual EElementType getType() const { - return FileTypes::Style; - } - virtual const CPath DefaultDirectory() const - { - return type().DefaultDirectory(); - } - virtual const CPath DefaultFileName() const - { - return type().DefaultFileName(); + return et_w_styles; } +//------------------------------------------------------------------------ - public: - - nullable m_oDocDefaults; - nullable m_oLatentStyles; - std::vector m_arrStyle; - std::map m_arrStyleNamesMap; + nullable m_oDocDefaults; + nullable m_oLatentStyles; + std::vector m_arrStyle; + std::map m_arrStyleNamesMap; }; } // namespace OOX diff --git a/Common/DocxFormat/Source/DocxFormat/WritingElement.h b/Common/DocxFormat/Source/DocxFormat/WritingElement.h index 69dd8917dd..a6dbd48a4c 100644 --- a/Common/DocxFormat/Source/DocxFormat/WritingElement.h +++ b/Common/DocxFormat/Source/DocxFormat/WritingElement.h @@ -774,7 +774,10 @@ namespace OOX et_w_smartTag, // et_w_smartTagType, // et_w_softHyphen, // + et_w_wordDocument, // + et_w_document, // et_w_style, // + et_w_styles, // et_w_stylePaneFormatFilter, // et_w_stylePaneSortMethod, // et_w_sym, // diff --git a/Common/OfficeFileFormatChecker.h b/Common/OfficeFileFormatChecker.h index 7389f55966..da5b0517f6 100644 --- a/Common/OfficeFileFormatChecker.h +++ b/Common/OfficeFileFormatChecker.h @@ -76,6 +76,8 @@ public: std::wstring getDocumentID (const std::wstring & fileName); + bool isOOXFlatFormatFile(unsigned char* pBuffer,int dwBytes); + bool isDocFlatFormatFile(unsigned char* pBuffer,int dwBytes); bool isRtfFormatFile (unsigned char* pBuffer,int dwBytes); diff --git a/Common/OfficeFileFormatChecker2.cpp b/Common/OfficeFileFormatChecker2.cpp index aa900aa4f5..f530b3de1d 100644 --- a/Common/OfficeFileFormatChecker2.cpp +++ b/Common/OfficeFileFormatChecker2.cpp @@ -406,7 +406,11 @@ bool COfficeFileFormatChecker::isOfficeFile(const std::wstring & _fileName) file.ReadFile(buffer, MIN_SIZE_BUFFER, dwReadBytes); int sizeRead = (int)dwReadBytes; - if ( isRtfFormatFile(buffer,sizeRead) ) + if ( isOOXFlatFormatFile(buffer,sizeRead) ) + { + //nFileType; + } + else if ( isRtfFormatFile(buffer,sizeRead) ) { nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_RTF; } @@ -773,7 +777,26 @@ bool COfficeFileFormatChecker::isOpenOfficeFlatFormatFile(unsigned char* pBuffer return false; } +bool COfficeFileFormatChecker::isOOXFlatFormatFile(unsigned char* pBuffer,int dwBytes) +{ + std::string xml_string((char*)pBuffer, dwBytes); + const char *docxFormatLine = "xmlns:w=\"http://schemas.microsoft.com/office/word/2003/wordml\""; + //const char *xlsxFormatLine = "xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\""; + + if (std::string::npos != xml_string.find(docxFormatLine)) + { + nFileType = AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX_FLAT; + } + //else if (std::string::npos != xml_string.find(xlsxFormatLine)) + //{ + // nFileType = AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX_FLAT; + //} + + if (nFileType != AVS_OFFICESTUDIO_FILE_UNKNOWN) return true; + + return false; +} std::wstring COfficeFileFormatChecker::GetExtensionByType(int type) { switch (type) diff --git a/Common/OfficeFileFormats.h b/Common/OfficeFileFormats.h index 348076568a..3d4ce6f294 100644 --- a/Common/OfficeFileFormats.h +++ b/Common/OfficeFileFormats.h @@ -50,7 +50,8 @@ #define AVS_OFFICESTUDIO_FILE_DOCUMENT_ODT_FLAT AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x000e #define AVS_OFFICESTUDIO_FILE_DOCUMENT_OTT AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x000f #define AVS_OFFICESTUDIO_FILE_DOCUMENT_DOC_FLAT AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0010 -#define AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML_IN_CONTAINER AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0011 +#define AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX_FLAT AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0011 +#define AVS_OFFICESTUDIO_FILE_DOCUMENT_HTML_IN_CONTAINER AVS_OFFICESTUDIO_FILE_DOCUMENT + 0x0012 #define AVS_OFFICESTUDIO_FILE_PRESENTATION 0x0080 #define AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX AVS_OFFICESTUDIO_FILE_PRESENTATION + 0x0001 @@ -74,6 +75,7 @@ #define AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLTM AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0007 #define AVS_OFFICESTUDIO_FILE_SPREADSHEET_ODS_FLAT AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0008 #define AVS_OFFICESTUDIO_FILE_SPREADSHEET_OTS AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x0009 +#define AVS_OFFICESTUDIO_FILE_SPREADSHEET_XLSX_FLAT AVS_OFFICESTUDIO_FILE_SPREADSHEET + 0x000a #define AVS_OFFICESTUDIO_FILE_CROSSPLATFORM 0x0200 #define AVS_OFFICESTUDIO_FILE_CROSSPLATFORM_PDF AVS_OFFICESTUDIO_FILE_CROSSPLATFORM + 0x0001