From 9bffb65dcbbd68b1dc4fb6379541f2de87fa3ce6 Mon Sep 17 00:00:00 2001 From: ElenaSubbotina Date: Mon, 29 Jan 2018 15:46:08 +0300 Subject: [PATCH] x2t 2.4.512 --- .../DocFormatLib/Win32/DocFormatLib.vcproj | 1 + ASCOfficeDocxFile2/BinWriter/BinWriters.h | 94 ++-- ASCOfficeOdfFile/win32/cpcommon.vcproj | 2 +- ASCOfficeOdfFile/win32/cpodf.vcproj | 2 +- ASCOfficeOdfFile/win32/cpxml.vcproj | 2 +- ASCOfficeOdfFile/win32/formulasconvert.vcproj | 2 +- .../source/Oox2OdfConverter/DocxConverter.cpp | 129 +++--- .../source/Oox2OdfConverter/XlsxConverter.cpp | 3 +- .../source/win32/OdfFormat.vcproj | 2 +- .../source/win32/Oox2OdfConverter.vcproj | 1 + .../Records/Drawing/ShapeContainer.h | 6 +- .../PPTFormatLib/Records/TextSpecInfoAtom.h | 4 +- .../PPTFormatLib/Win32/PPTFormatLib.vcproj | 1 + .../PPTXFormat/FileContainer.cpp | 65 ++- ASCOfficePPTXFile/PPTXFormat/FileContainer.h | 32 +- ASCOfficePPTXFile/PPTXFormat/Folder.cpp | 24 +- ASCOfficePPTXFile/PPTXFormat/Folder.h | 4 +- .../PPTXFormat/Logic/Fills/Blip.cpp | 10 +- ASCOfficePPTXFile/PPTXFormat/Logic/Pic.cpp | 14 +- ASCOfficePPTXFile/PPTXFormat/Presentation.h | 2 - ASCOfficePPTXFile/PPTXLib/PPTXFormat.vcproj | 1 + .../RtfFormatLib/Win32/RtfFormatLib.vcproj | 1 + .../source/Reader/OOXHeaderReader.cpp | 2 +- .../RtfFormatLib/source/Reader/OOXReader.cpp | 52 +-- .../source/Reader/OOXShapeReader.cpp | 15 +- .../Source/ConvertDocx2Txt.cpp | 124 +++-- .../Win32/TxtXmlFormatLib.vcproj | 1 + .../source/win32/XlsFormat.vcproj | 1 + .../source/win32/XlsXlsxConverter.vcproj | 1 + Common/3dParty/cryptopp/cryptlib.vcproj | 1 + .../DocxFormatLib/DocxFormatLib.pro | 2 + .../DocxFormatLib/docxformatlib_logic.cpp | 10 +- .../DocxFormat/Projects/DocxFormat2005.vcproj | 9 + .../DocxFormat/Source/DocxFormat/Document.h | 12 +- Common/DocxFormat/Source/DocxFormat/Docx.h | 109 +---- .../Source/DocxFormat/IFileContainer.cpp | 95 +--- .../Source/DocxFormat/IFileContainer.h | 26 +- .../Source/DocxFormat/Media/VbaProject.cpp | 132 ++++++ .../Source/DocxFormat/Media/VbaProject.h | 74 +-- .../Source/XlsxFormat/Comments/Comments.h | 19 +- .../XlsxFormat/FileFactory_Spreadsheet.cpp | 12 +- .../Source/XlsxFormat/Workbook/Workbook.h | 6 +- .../Source/XlsxFormat/WorkbookComments.h | 79 ++-- .../XlsxFormat/Worksheets/Worksheet.cpp | 430 ++++++++++++++++++ .../Source/XlsxFormat/Worksheets/Worksheet.h | 405 +---------------- Common/DocxFormat/Source/XlsxFormat/Xlsx.cpp | 11 +- Common/DocxFormat/Source/XlsxFormat/Xlsx.h | 13 +- Common/base.pri | 2 +- DesktopEditor/agg-2.4/agg_vs2005.vcproj | 1 + .../cximage/CxImage/cximage_vs2005.vcproj | 1 + .../cximage/jasper/jasper_vs2005.vcproj | 1 + DesktopEditor/cximage/jpeg/Jpeg_vs2005.vcproj | 1 + .../cximage/libpsd/libpsd_vs2005.vcproj | 1 + DesktopEditor/cximage/mng/mng_vs2005.vcproj | 1 + DesktopEditor/cximage/png/png_vs2005.vcproj | 1 + .../cximage/raw/libdcr_vs2005.vcproj | 1 + DesktopEditor/cximage/tiff/Tiff_vs2005.vcproj | 1 + DesktopEditor/fontengine/ApplicationFonts.cpp | 2 +- .../fontengine/font_engine_vs2005.vcproj | 1 + .../builds/windows/vc2005/freetype.vcproj | 1 + DesktopEditor/graphics/graphics_vs2005.vcproj | 1 + DesktopEditor/raster/JBig2/win32/jbig2.vcproj | 1 + DesktopEditor/raster/raster_vs2005.vcproj | 1 + .../win32/ECMACryptReader.vcproj | 1 + OfficeUtils/win32/OfficeUtilsLib.vcproj | 1 + X2tConverter/test/win32Test/X2tTest.vcproj | 1 + XlsxSerializerCom/Reader/BinaryWriter.h | 89 ++-- .../Reader/ChartFromToBinary.cpp | 20 +- XlsxSerializerCom/Writer/BinaryReader.h | 25 +- 69 files changed, 1137 insertions(+), 1061 deletions(-) create mode 100644 Common/DocxFormat/Source/DocxFormat/Media/VbaProject.cpp create mode 100644 Common/DocxFormat/Source/XlsxFormat/Worksheets/Worksheet.cpp diff --git a/ASCOfficeDocFile/DocFormatLib/Win32/DocFormatLib.vcproj b/ASCOfficeDocFile/DocFormatLib/Win32/DocFormatLib.vcproj index af0c526908..a31c1c62fc 100644 --- a/ASCOfficeDocFile/DocFormatLib/Win32/DocFormatLib.vcproj +++ b/ASCOfficeDocFile/DocFormatLib/Win32/DocFormatLib.vcproj @@ -52,6 +52,7 @@ WarningLevel="3" Detect64BitPortabilityProblems="true" DebugInformationFormat="4" + DisableSpecificWarnings="4005;4311;4312" /> * mapIgnoreComments, BinaryHeaderFooterTableWriter* oBinaryHeaderFooterTableWriter): - m_oParamsWriter(oParamsWriter), m_oParamsDocumentWriter(oParamsDocumentWriter),m_oBcw(oParamsWriter),bpPrs(oParamsWriter, oBinaryHeaderFooterTableWriter),brPrs(oParamsWriter),btblPrs(oParamsWriter),m_oSettings(oParamsWriter.m_oSettings),m_pOfficeDrawingConverter(oParamsWriter.m_pOfficeDrawingConverter),m_mapIgnoreComments(mapIgnoreComments) + m_oParamsWriter(oParamsWriter), m_oParamsDocumentWriter(oParamsDocumentWriter), m_oBcw(oParamsWriter),bpPrs(oParamsWriter, oBinaryHeaderFooterTableWriter),brPrs(oParamsWriter),btblPrs(oParamsWriter),m_oSettings(oParamsWriter.m_oSettings),m_pOfficeDrawingConverter(oParamsWriter.m_pOfficeDrawingConverter),m_mapIgnoreComments(mapIgnoreComments) { pBackground = NULL; pSectPr = NULL; @@ -3131,23 +3131,6 @@ namespace BinDocxRW m_oBcw.WriteItemEnd(nCurPos); } } - //Write JsaProject - if (NULL != poDocument) - { - smart_ptr pFile = poDocument->Get(OOX::FileTypes::JsaProject); - if (pFile.IsInit() && OOX::FileTypes::JsaProject == pFile->type()) - { - OOX::JsaProject& jsaProject = pFile.as(); - BYTE* pData = NULL; - DWORD nBytesCount; - if(NSFile::CFileBinary::ReadAllBytes(jsaProject.filename().GetPath(), &pData, nBytesCount)) - { - nCurPos = m_oBcw.WriteItemStart(c_oSerParType::JsaProject); - m_oBcw.m_oStream.WriteBYTEArray(pData, nBytesCount); - m_oBcw.WriteItemEnd(nCurPos); - } - } - } } void WriteBackground (OOX::Logic::CBackground* pBackground) { @@ -7864,101 +7847,91 @@ namespace BinDocxRW OOX::CDocx oDocx = OOX::CDocx(OOX::CPath(sDir)); - m_oParamsWriter.m_poTheme = oDocx.GetTheme(); - m_oParamsWriter.m_oSettings = oDocx.GetSettings(); + m_oParamsWriter.m_poTheme = oDocx.m_pTheme; + m_oParamsWriter.m_oSettings = oDocx.m_pSettings; - *oBufferedStream.m_pTheme = smart_ptr(oDocx.GetTheme()); + *oBufferedStream.m_pTheme = smart_ptr(oDocx.m_pTheme); oBufferedStream.m_pTheme->AddRef(); - OOX::CFontTable* pFontTable = oDocx.GetFontTable(); - - if(NULL != pFontTable) - m_oParamsWriter.m_pFontProcessor->setFontTable(pFontTable); + if(NULL != oDocx.m_pFontTable) + m_oParamsWriter.m_pFontProcessor->setFontTable(oDocx.m_pFontTable); //ищем первый SectPr и расставляем pageBreak - OOX::CDocument* poDocument = oDocx.GetDocument(); - if (poDocument == NULL) return; - OOX::Logic::CSectionProperty* pFirstSectPr = poDocument->m_oSectPr.GetPointer(); + if (oDocx.m_pDocument == NULL) return; + OOX::Logic::CSectionProperty* pFirstSectPr = oDocx.m_pDocument->m_oSectPr.GetPointer(); this->WriteMainTableStart(); int nCurPos = 0; //Write Settings - OOX::CSettings* pSettings = oDocx.GetSettings(); - if(NULL != pSettings) + if(NULL != oDocx.m_pSettings) { BinDocxRW::BinarySettingsTableWriter oBinarySettingsTableWriter(m_oParamsWriter); int nCurPos = this->WriteTableStart(BinDocxRW::c_oSerTableTypes::Settings); - oBinarySettingsTableWriter.Write(*pSettings); + oBinarySettingsTableWriter.Write(*oDocx.m_pSettings); this->WriteTableEnd(nCurPos); } //Write Comments - OOX::CComments* pComments = oDocx.GetComments(); - OOX::CCommentsExt* pCommentsExt = oDocx.GetCommentsExt(); - OOX::CPeople* pPeople = oDocx.GetPeople(); - if(NULL != pComments) + if(NULL != oDocx.m_pComments) { BinDocxRW::BinaryCommentsTableWriter oBinaryCommentsTableWriter(m_oParamsWriter); int nCurPos = this->WriteTableStart(BinDocxRW::c_oSerTableTypes::Comments); - oBinaryCommentsTableWriter.Write(*pComments, pCommentsExt, pPeople, m_oParamsWriter.m_mapIgnoreComments); + oBinaryCommentsTableWriter.Write(*oDocx.m_pComments, oDocx.m_pCommentsExt, oDocx.m_pPeople, m_oParamsWriter.m_mapIgnoreComments); this->WriteTableEnd(nCurPos); } //Write StyleTable - OOX::CStyles* pStyles = oDocx.GetStyles(); BinDocxRW::BinaryStyleTableWriter oBinaryStyleTableWriter(m_oParamsWriter); - if(NULL != pStyles) + if(NULL != oDocx.m_pStyles) { int nCurPos = this->WriteTableStart(BinDocxRW::c_oSerTableTypes::Style); - oBinaryStyleTableWriter.Write(*pStyles); + oBinaryStyleTableWriter.Write(*oDocx.m_pStyles); this->WriteTableEnd(nCurPos); } //Write Numbering - OOX::CNumbering* pNumbering = oDocx.GetNumbering(); BinDocxRW::BinaryNumberingTableWriter oBinaryNumberingTableWriter(m_oParamsWriter); - if(NULL != pNumbering) + if(NULL != oDocx.m_pNumbering) { nCurPos = this->WriteTableStart(BinDocxRW::c_oSerTableTypes::Numbering); - oBinaryNumberingTableWriter.Write(*pNumbering); + oBinaryNumberingTableWriter.Write(*oDocx.m_pNumbering); this->WriteTableEnd(nCurPos); } BinDocxRW::BinaryNotesTableWriter oBinaryNotesWriter(m_oParamsWriter); //Write Footnotes - OOX::CFootnotes* pFootnotes = oDocx.GetFootnotes(); - if(NULL != pFootnotes) + if(NULL != oDocx.m_pFootnotes) { nCurPos = this->WriteTableStart(BinDocxRW::c_oSerTableTypes::Footnotes); - oBinaryNotesWriter.WriteFootnotes(*pFootnotes); + oBinaryNotesWriter.WriteFootnotes(*oDocx.m_pFootnotes); this->WriteTableEnd(nCurPos); } //Write Endnotes - OOX::CEndnotes* pEndnotes = oDocx.GetEndnotes(); - if(NULL != pEndnotes) + if(NULL != oDocx.m_pEndnotes) { nCurPos = this->WriteTableStart(BinDocxRW::c_oSerTableTypes::Endnotes); - oBinaryNotesWriter.WriteEndnotes(*pEndnotes); + oBinaryNotesWriter.WriteEndnotes(*oDocx.m_pEndnotes); this->WriteTableEnd(nCurPos); } - BinDocxRW::BinaryHeaderFooterTableWriter oBinaryHeaderFooterTableWriter(m_oParamsWriter, poDocument, &m_oParamsWriter.m_mapIgnoreComments); + BinDocxRW::BinaryHeaderFooterTableWriter oBinaryHeaderFooterTableWriter(m_oParamsWriter, oDocx.m_pDocument, &m_oParamsWriter.m_mapIgnoreComments); //Write DocumentTable - ParamsDocumentWriter oParamsDocumentWriter(poDocument); + ParamsDocumentWriter oParamsDocumentWriter(oDocx.m_pDocument); m_oParamsWriter.m_pCurRels = oParamsDocumentWriter.m_pRels; //DocumentTable всегда пишем последней, чтобы сначала заполнить все вспомогательные структуры, а при заполении документа, вызывать методы типа Style_Add... BinDocxRW::BinaryDocumentTableWriter oBinaryDocumentTableWriter(m_oParamsWriter, oParamsDocumentWriter, &m_oParamsWriter.m_mapIgnoreComments, &oBinaryHeaderFooterTableWriter); - oBinaryDocumentTableWriter.prepareOfficeDrawingConverter(m_oParamsWriter.m_pOfficeDrawingConverter, oParamsDocumentWriter.m_pRels, poDocument->m_arrShapeTypes); + oBinaryDocumentTableWriter.prepareOfficeDrawingConverter(m_oParamsWriter.m_pOfficeDrawingConverter, oParamsDocumentWriter.m_pRels, oDocx.m_pDocument->m_arrShapeTypes); oBinaryDocumentTableWriter.pSectPr = pFirstSectPr; - oBinaryDocumentTableWriter.pBackground = poDocument->m_oBackground.GetPointer(); - oBinaryDocumentTableWriter.poDocument = poDocument; + oBinaryDocumentTableWriter.pBackground = oDocx.m_pDocument->m_oBackground.GetPointer(); + oBinaryDocumentTableWriter.poDocument = oDocx.m_pDocument; oBinaryDocumentTableWriter.m_bWriteSectPr = true; + //Write Vba if(NULL != oDocx.m_pVbaProject) { @@ -7966,9 +7939,22 @@ namespace BinDocxRW oBinaryDocumentTableWriter.WriteVbaProject(*oDocx.m_pVbaProject); this->WriteTableEnd(nCurPos); } + //Write JsaProject + if (NULL != oDocx.m_pJsaProject) + { + BYTE* pData = NULL; + DWORD nBytesCount; + if(NSFile::CFileBinary::ReadAllBytes(oDocx.m_pJsaProject->filename().GetPath(), &pData, nBytesCount)) + { + nCurPos = m_oBcw.WriteItemStart(c_oSerParType::JsaProject); + m_oBcw.m_oStream.WriteBYTEArray(pData, nBytesCount); + m_oBcw.WriteItemEnd(nCurPos); + } + } + // Write content nCurPos = this->WriteTableStart(BinDocxRW::c_oSerTableTypes::Document); - oBinaryDocumentTableWriter.Write(poDocument->m_arrItems); + oBinaryDocumentTableWriter.Write(oDocx.m_pDocument->m_arrItems); this->WriteTableEnd(nCurPos); nCurPos = this->WriteTableStart(BinDocxRW::c_oSerTableTypes::HdrFtr); diff --git a/ASCOfficeOdfFile/win32/cpcommon.vcproj b/ASCOfficeOdfFile/win32/cpcommon.vcproj index 33e39e5289..8178dadd1b 100644 --- a/ASCOfficeOdfFile/win32/cpcommon.vcproj +++ b/ASCOfficeOdfFile/win32/cpcommon.vcproj @@ -53,7 +53,7 @@ WarningLevel="3" Detect64BitPortabilityProblems="true" DebugInformationFormat="4" - DisableSpecificWarnings="4311;4267;4996;4172" + DisableSpecificWarnings="4005;4311;4312" /> GetTheme(); + return docx_document->m_pTheme; else return NULL; } @@ -151,22 +151,17 @@ OOX::IFileContainer* DocxConverter::current_document() return oox_current_child_document; else { - OOX::CDocument *oox_doc = docx_document->GetDocument(); - return dynamic_cast(oox_doc); + return dynamic_cast(docx_document->m_pDocument); } } NSCommon::smart_ptr DocxConverter::find_file_by_id(std::wstring sId) { - OOX::CDocument *oox_doc = docx_document->GetDocument(); - smart_ptr oFile; - if (oox_doc) - { - if (oox_current_child_document) - oFile = oox_current_child_document->Find(sId); - else - oFile = oox_doc->Find(sId); - } + + if (oox_current_child_document) + oFile = oox_current_child_document->Find(sId); + else if (docx_document->m_pDocument) + oFile = docx_document->m_pDocument->Find(sId); return oFile; } @@ -185,10 +180,9 @@ std::wstring DocxConverter::find_link_by_id (std::wstring sId, int type) } if (!ref.empty()) return ref; - OOX::CDocument *oox_doc = docx_document->GetDocument(); - if (oox_doc == NULL) return L""; + if (docx_document->m_pDocument == NULL) return L""; - oFile = oox_doc->Find(sId); + oFile = docx_document->m_pDocument->Find(sId); ref = OoxConverter::find_link_by(oFile, type); return ref; @@ -221,8 +215,7 @@ void DocxConverter::convertDocument() void DocxConverter::convert_document() { - const OOX::CDocument* document = docx_document->GetDocument(); - if (!document)return; + if (!docx_document->m_pDocument)return; std::vector<_section> sections; //---------------------------------------------------------------------------------------------------------- @@ -231,13 +224,13 @@ void DocxConverter::convert_document() OOX::Logic::CSectionProperty* prev = NULL; - for (size_t i = 0; i < document->m_arrItems.size(); ++i) + for (size_t i = 0; i < docx_document->m_pDocument->m_arrItems.size(); ++i) { - if ((document->m_arrItems[i]) == NULL) continue; + if ((docx_document->m_pDocument->m_arrItems[i]) == NULL) continue; - if (document->m_arrItems[i]->getType() == OOX::et_w_p) + if (docx_document->m_pDocument->m_arrItems[i]->getType() == OOX::et_w_p) { - OOX::Logic::CParagraph * para = dynamic_cast(document->m_arrItems[i]); + OOX::Logic::CParagraph * para = dynamic_cast(docx_document->m_pDocument->m_arrItems[i]); if ((para) && (para->m_oParagraphProperty)) { @@ -260,9 +253,9 @@ void DocxConverter::convert_document() } _section section; - section.props = document->m_oSectPr.GetPointer(); + section.props = docx_document->m_pDocument->m_oSectPr.GetPointer(); section.start_para = last_section_start; - section.end_para = document->m_arrItems.size(); + section.end_para = docx_document->m_pDocument->m_arrItems.size(); section.bContinue = compare (prev, section.props); sections.push_back(section); @@ -277,7 +270,7 @@ void DocxConverter::convert_document() for (size_t i = sections[sect].start_para; i < sections[sect].end_para; ++i) { - convert(document->m_arrItems[i]); + convert(docx_document->m_pDocument->m_arrItems[i]); } } } @@ -1572,7 +1565,7 @@ void DocxConverter::convert(OOX::Logic::CSectionProperty *oox_section_pr, bool b //nullable > m_oCode; } - convert(docx_document->GetDocument()->m_oBackground.GetPointer(), 1);//подложка - вот в таком она месте :(, причём одна на все разделы, не как в оо + convert(docx_document->m_pDocument->m_oBackground.GetPointer(), 1);//подложка - вот в таком она месте :(, причём одна на все разделы, не как в оо //nullable m_oTextDirection; //nullable > m_oRtlGutter; //nullable m_oVAlign; @@ -1621,7 +1614,7 @@ void DocxConverter::convert(OOX::Logic::CSectionProperty *oox_section_pr, bool b if (s->m_arrHeaderReference[i]->m_oId.IsInit()) { convert_hdr_ftr(s->m_arrHeaderReference[i]->m_oId->GetValue()); - convert(docx_document->GetDocument()->m_oBackground.GetPointer(), 2); + convert(docx_document->m_pDocument->m_oBackground.GetPointer(), 2); } odt_context->end_header_footer(); @@ -1649,7 +1642,7 @@ void DocxConverter::convert(OOX::Logic::CSectionProperty *oox_section_pr, bool b if (s->m_arrFooterReference[i]->m_oId.IsInit()) { convert_hdr_ftr(s->m_arrFooterReference[i]->m_oId->GetValue()); - convert(docx_document->GetDocument()->m_oBackground.GetPointer(), 3); + convert(docx_document->m_pDocument->m_oBackground.GetPointer(), 3); } odt_context->end_header_footer(); @@ -2335,8 +2328,7 @@ void DocxConverter::convert(SimpleTypes::CTheme<>* oox_font_theme, _CP_OPT(std:: { if (oox_font_theme == NULL) return; - PPTX::Theme * docx_theme= docx_document->GetTheme(); - if (docx_theme == NULL) return; + if (docx_document->m_pTheme == NULL) return; std::wstring font; @@ -2344,23 +2336,23 @@ void DocxConverter::convert(SimpleTypes::CTheme<>* oox_font_theme, _CP_OPT(std:: { case SimpleTypes::themeMajorAscii: case SimpleTypes::themeMajorHAnsi : - font = docx_theme->themeElements.fontScheme.majorFont.latin.typeface; + font = docx_document->m_pTheme->themeElements.fontScheme.majorFont.latin.typeface; break; case SimpleTypes::themeMajorBidi: - font = docx_theme->themeElements.fontScheme.majorFont.cs.typeface; + font = docx_document->m_pTheme->themeElements.fontScheme.majorFont.cs.typeface; break; case SimpleTypes::themeMajorEastAsia: - font = docx_theme->themeElements.fontScheme.majorFont.ea.typeface; + font = docx_document->m_pTheme->themeElements.fontScheme.majorFont.ea.typeface; break; case SimpleTypes::themeMinorAscii: case SimpleTypes::themeMinorHAnsi: - font = docx_theme->themeElements.fontScheme.minorFont.latin.typeface; + font = docx_document->m_pTheme->themeElements.fontScheme.minorFont.latin.typeface; break; case SimpleTypes::themeMinorBidi: - font = docx_theme->themeElements.fontScheme.minorFont.cs.typeface; + font = docx_document->m_pTheme->themeElements.fontScheme.minorFont.cs.typeface; break; case SimpleTypes::themeMinorEastAsia: - font = docx_theme->themeElements.fontScheme.minorFont.ea.typeface; + font = docx_document->m_pTheme->themeElements.fontScheme.minorFont.ea.typeface; break; } if (!font.empty()) odf_font_name = font; @@ -2867,11 +2859,9 @@ void DocxConverter::convert(SimpleTypes::CHexColor<> *color, } if(theme_color && result == false) { - PPTX::Theme * docx_theme= docx_document->GetTheme(); - - std::map::iterator pFind = docx_theme->themeElements.clrScheme.Scheme.find(theme_color->ToString()); + std::map::iterator pFind = docx_document->m_pTheme->themeElements.clrScheme.Scheme.find(theme_color->ToString()); - if (pFind != docx_theme->themeElements.clrScheme.Scheme.end()) + if (pFind != docx_document->m_pTheme->themeElements.clrScheme.Scheme.end()) { PPTX::Logic::UniColor & color = pFind->second; @@ -2890,38 +2880,36 @@ void DocxConverter::convert(ComplexTypes::Word::CColor *color, _CP_OPT(odf_types PPTX::Logic::ClrMap* DocxConverter::oox_clrMap() { //return current_clrMap; todoooo - OOX::CSettings * docx_settings = docx_document->GetSettings(); - if (!docx_settings) return NULL; + if (!docx_document->m_pSettings) return NULL; - return docx_settings->m_oClrSchemeMapping.GetPointer(); + return docx_document->m_pSettings->m_oClrSchemeMapping.GetPointer(); } void DocxConverter::convert_settings() { if (!odt_context) return; - OOX::CSettings * docx_settings = docx_document->GetSettings(); - if (!docx_settings) return; + if (!docx_document->m_pSettings) return; - if (docx_settings->m_oZoom.IsInit()) + if (docx_document->m_pSettings->m_oZoom.IsInit()) { } - if (docx_settings->m_oMirrorMargins.IsInit()) + if (docx_document->m_pSettings->m_oMirrorMargins.IsInit()) { odt_context->page_layout_context()->set_pages_mirrored(true); } - odt_context->page_layout_context()->even_and_left_headers_ = docx_settings->m_oEvenAndOddHeaders.IsInit(); + odt_context->page_layout_context()->even_and_left_headers_ = docx_document->m_pSettings->m_oEvenAndOddHeaders.IsInit(); - if (docx_settings->m_oPrintTwoOnOne.IsInit()) + if (docx_document->m_pSettings->m_oPrintTwoOnOne.IsInit()) { - if (docx_settings->m_oGutterAtTop.IsInit()){} //portrait + if (docx_document->m_pSettings->m_oGutterAtTop.IsInit()){} //portrait else {}//landscape } - if (docx_settings->m_oDefaultTabStop.IsInit()) + if (docx_document->m_pSettings->m_oDefaultTabStop.IsInit()) { _CP_OPT(odf_types::length) length; - convert(docx_settings->m_oDefaultTabStop->m_oVal.GetPointer(), length); + convert(docx_document->m_pSettings->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) @@ -2941,7 +2929,7 @@ void DocxConverter::convert_lists_styles() { if (!odt_context) return; - OOX::CNumbering * lists_styles = docx_document->GetNumbering(); + OOX::CNumbering * lists_styles = docx_document->m_pNumbering; if (!lists_styles)return; @@ -2979,27 +2967,25 @@ void DocxConverter::convert_lists_styles() void DocxConverter::convert_styles() { if (!odt_context) return; - - OOX::CStyles * docx_styles = docx_document->GetStyles(); - if (!docx_styles)return; + if (!docx_document->m_pStyles)return; //nullable m_oLatentStyles; - convert(docx_styles->m_oDocDefaults.GetPointer()); + convert(docx_document->m_pStyles->m_oDocDefaults.GetPointer()); - for (size_t i=0; i< docx_styles->m_arrStyle.size(); i++) + for (size_t i=0; i< docx_document->m_pStyles->m_arrStyle.size(); i++) { - if (docx_styles->m_arrStyle[i] == NULL) continue; + if (docx_document->m_pStyles->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_styles->m_arrStyle[i]); + convert(docx_document->m_pStyles->m_arrStyle[i]); - if (i == 0 && docx_styles->m_arrStyle[i]->m_oDefault.IsInit() && docx_styles->m_arrStyle[i]->m_oDefault->ToBool()) + if (i == 0 && docx_document->m_pStyles->m_arrStyle[i]->m_oDefault.IsInit() && docx_document->m_pStyles->m_arrStyle[i]->m_oDefault->ToBool()) { //NADIE_COMO_TU.docx тут дефолтовый стиль не прописан явно, берем тот что Normal odf_writer::odf_style_state_ptr def_style_state; @@ -3285,7 +3271,7 @@ void DocxConverter::convert(OOX::Numbering::CLvl* oox_num_lvl) if (oox_num_lvl->m_oLvlPicBulletId.IsInit() && oox_num_lvl->m_oLvlPicBulletId->m_oVal.IsInit()) { int id = oox_num_lvl->m_oLvlPicBulletId->m_oVal->GetValue(); - OOX::CNumbering * lists_styles = docx_document->GetNumbering(); + OOX::CNumbering * lists_styles = docx_document->m_pNumbering; for (size_t i = 0; (lists_styles) && (i < lists_styles->m_arrNumPicBullet.size()); i++) { @@ -3582,12 +3568,11 @@ void DocxConverter::convert(OOX::Logic::CEndnoteReference* oox_ref) } void DocxConverter::convert_comment(int oox_comm_id) { - OOX::CComments * docx_comments = docx_document->GetComments(); - if (!docx_comments)return; + if (!docx_document->m_pComments)return; - for (size_t comm = 0 ; comm < docx_comments->m_arrComments.size(); comm++) + for (size_t comm = 0 ; comm < docx_document->m_pComments->m_arrComments.size(); comm++) { - OOX::CComment* oox_comment = docx_comments->m_arrComments[comm]; + OOX::CComment* oox_comment = docx_document->m_pComments->m_arrComments[comm]; if (oox_comment == NULL) continue; if (oox_comment->m_oId.IsInit() == false) continue; @@ -3611,14 +3596,13 @@ void DocxConverter::convert_comment(int oox_comm_id) } void DocxConverter::convert_footnote(int oox_ref_id) { - OOX::CFootnotes * footnotes = docx_document->GetFootnotes(); - if (!footnotes)return; + if (!docx_document->m_pFootnotes)return; odt_context->start_note(oox_ref_id, 1); - for (size_t n = 0 ; n < footnotes->m_arrFootnote.size(); n++) + for (size_t n = 0 ; n < docx_document->m_pFootnotes->m_arrFootnote.size(); n++) { - OOX::CFtnEdn* oox_note = footnotes->m_arrFootnote[n]; + OOX::CFtnEdn* oox_note = docx_document->m_pFootnotes->m_arrFootnote[n]; if (oox_note == NULL) continue; if (oox_note->m_oId.IsInit() == false) continue; @@ -3639,14 +3623,13 @@ void DocxConverter::convert_footnote(int oox_ref_id) } void DocxConverter::convert_endnote(int oox_ref_id) { - OOX::CEndnotes * endnotes = docx_document->GetEndnotes(); - if (!endnotes)return; + if (!docx_document->m_pEndnotes)return; odt_context->start_note(oox_ref_id, 2); - for (size_t n = 0 ; n < endnotes->m_arrEndnote.size(); n++) + for (size_t n = 0 ; n < docx_document->m_pEndnotes->m_arrEndnote.size(); n++) { - OOX::CFtnEdn* oox_note = endnotes->m_arrEndnote[n]; + OOX::CFtnEdn* oox_note = docx_document->m_pEndnotes->m_arrEndnote[n]; if (oox_note == NULL) continue; if (oox_note->m_oId.IsInit() == false) continue; diff --git a/ASCOfficeOdfFileW/source/Oox2OdfConverter/XlsxConverter.cpp b/ASCOfficeOdfFileW/source/Oox2OdfConverter/XlsxConverter.cpp index fe32efbf5a..e83dd298b0 100644 --- a/ASCOfficeOdfFileW/source/Oox2OdfConverter/XlsxConverter.cpp +++ b/ASCOfficeOdfFileW/source/Oox2OdfConverter/XlsxConverter.cpp @@ -32,9 +32,10 @@ #include "XlsxConverter.h" #include "../../../Common/DocxFormat/Source/XlsxFormat/Xlsx.h" #include "../../../Common/DocxFormat/Source/XlsxFormat/Workbook/Workbook.h" +#include "../../../Common/DocxFormat/Source/XlsxFormat/Worksheets/Worksheet.h" +#include "../../../Common/DocxFormat/Source/XlsxFormat/Comments/Comments.h" #include "../../../Common/DocxFormat/Source/XlsxFormat/SharedStrings/SharedStrings.h" #include "../../../Common/DocxFormat/Source/XlsxFormat/Styles/Styles.h" -#include "../../../Common/DocxFormat/Source/XlsxFormat/Worksheets/Worksheet.h" #include "../../../Common/DocxFormat/Source/XlsxFormat/CalcChain/CalcChain.h" #include "../../../Common/DocxFormat/Source/XlsxFormat/ExternalLinks/ExternalLinks.h" #include "../../../Common/DocxFormat/Source/XlsxFormat/ExternalLinks/ExternalLinkPath.h" diff --git a/ASCOfficeOdfFileW/source/win32/OdfFormat.vcproj b/ASCOfficeOdfFileW/source/win32/OdfFormat.vcproj index a80e7f85bc..82b7a14075 100644 --- a/ASCOfficeOdfFileW/source/win32/OdfFormat.vcproj +++ b/ASCOfficeOdfFileW/source/win32/OdfFormat.vcproj @@ -53,7 +53,7 @@ WarningLevel="3" Detect64BitPortabilityProblems="true" DebugInformationFormat="4" - DisableSpecificWarnings="4996" + DisableSpecificWarnings="4005;4311;4312" /> m_ePID - NSOfficeDrawing::adjustValue; - if (lIndexAdj >= 0 && lIndexAdj < pShape->m_arAdjustments.size()) + if (lIndexAdj >= 0 && lIndexAdj < (LONG)pShape->m_arAdjustments.size()) { pShape->m_oCustomVML.LoadAdjusts(lIndexAdj, (LONG)pProperty->m_lValue); } @@ -1639,7 +1639,7 @@ public: } //------ shape properties ---------------------------------------------------------------------------------------- - for (int nIndexProp = 0; nIndexProp < oArrayOptions.size(); ++nIndexProp) + for (size_t nIndexProp = 0; nIndexProp < oArrayOptions.size(); ++nIndexProp) { CPPTElement oElement; oElement.SetUpProperties(pElement, pTheme, pSlideWrapper, pSlide, &oArrayOptions[nIndexProp]->m_oProperties); @@ -1756,7 +1756,7 @@ public: } else {//image, audio, video .... - for (int nIndexProp = 0; nIndexProp < oArrayOptions.size(); ++nIndexProp) + for (size_t nIndexProp = 0; nIndexProp < oArrayOptions.size(); ++nIndexProp) { CPPTElement oElement; oElement.SetUpProperties(pElement, pTheme, pSlideWrapper, pSlide, &oArrayOptions[nIndexProp]->m_oProperties); diff --git a/ASCOfficePPTFile/PPTFormatLib/Records/TextSpecInfoAtom.h b/ASCOfficePPTFile/PPTFormatLib/Records/TextSpecInfoAtom.h index d483ae7adc..0068f5c628 100644 --- a/ASCOfficePPTFile/PPTFormatLib/Records/TextSpecInfoAtom.h +++ b/ASCOfficePPTFile/PPTFormatLib/Records/TextSpecInfoAtom.h @@ -70,7 +70,7 @@ public: int sz = pStream->tell() - m_lOffsetInStream; - if (sz >= m_oHeader.RecLen) + if (sz >= (int)m_oHeader.RecLen) break; } @@ -85,7 +85,7 @@ public: if (m_arrSIs.size() < 1) return; int pos_text = 0, pos_si = 0; - int ind = 0; + size_t ind = 0; for (size_t i = 0; i < pText->m_arParagraphs.size(); i++) { diff --git a/ASCOfficePPTFile/PPTFormatLib/Win32/PPTFormatLib.vcproj b/ASCOfficePPTFile/PPTFormatLib/Win32/PPTFormatLib.vcproj index 5129984dee..140d116010 100644 --- a/ASCOfficePPTFile/PPTFormatLib/Win32/PPTFormatLib.vcproj +++ b/ASCOfficePPTFile/PPTFormatLib/Win32/PPTFormatLib.vcproj @@ -65,6 +65,7 @@ WarningLevel="3" Detect64BitPortabilityProblems="false" DebugInformationFormat="4" + DisableSpecificWarnings="4005;4311;4312" /> namespace PPTX @@ -87,12 +89,71 @@ namespace PPTX void FileContainer::read(const OOX::CPath& filename) { - //OOX::IFileContainer::read(filename); } void FileContainer::read(const OOX::CRels& rels, const OOX::CPath& path) { } + const bool FileContainer::IsExist(const OOX::FileType& oType) const + { + for (size_t i = 0; i < m_arContainer.size(); ++i) + { + smart_ptr pFile = m_arContainer[i]; + + if (oType == pFile->type()) + return true; + } + + return false; + } + smart_ptr FileContainer::Get(const OOX::FileType& oType) + { + for (size_t i = 0; i < m_arContainer.size(); ++i) + { + smart_ptr &pFile = m_arContainer[i]; + if (oType == pFile->type()) + return pFile; + } + + return smart_ptr(new OOX::UnknowTypeFile( m_oUnknown )); + } + + void FileContainer::Get(const OOX::FileType& oType, std::vector> & files) + { + for (size_t i = 0; i < m_arContainer.size(); ++i) + { + smart_ptr &pFile = m_arContainer[i]; + + if ( oType == pFile->type() ) + files.push_back(pFile); + } + } + std::wstring FileContainer::GetImagePathNameFromRId(const OOX::RId& rid)const + { + smart_ptr p = IFileContainer::Get(rid); + if (!p.is_init()) + return _T(""); + return p->filename().m_strFilename; + } + std::wstring FileContainer::GetLinkFromRId(const OOX::RId& rid)const + { + smart_ptr pExt = Find(rid).smart_dynamic_cast(); + if (pExt.IsInit()) + return pExt->Uri().m_strFilename; + + smart_ptr pMedia = Find(rid).smart_dynamic_cast(); + if (pMedia.IsInit()) + return pMedia->filename().m_strFilename; + + return _T(""); + } + std::wstring FileContainer::GetOleFromRId(const OOX::RId& rid)const + { + smart_ptr p = IFileContainer::Get(rid); + if (!p.is_init()) + return _T(""); + return p->filename().m_strFilename; + } void FileContainer::read(const OOX::CRels& rels, const OOX::CPath& path, FileMap& map, IPPTXEvent* Event) { bool bIsSlide = false; diff --git a/ASCOfficePPTXFile/PPTXFormat/FileContainer.h b/ASCOfficePPTXFile/PPTXFormat/FileContainer.h index 0c3a01669b..6c3fae2ea1 100644 --- a/ASCOfficePPTXFile/PPTXFormat/FileContainer.h +++ b/ASCOfficePPTXFile/PPTXFormat/FileContainer.h @@ -55,32 +55,14 @@ namespace PPTX virtual ~FileContainer() { } - virtual std::wstring GetImagePathNameFromRId(const OOX::RId& rid)const - { - smart_ptr p = Get(rid); - if (!p.is_init()) - return _T(""); - return p->filename().m_strFilename; - } - virtual std::wstring GetLinkFromRId(const OOX::RId& rid)const - { - smart_ptr pExt = Find(rid).smart_dynamic_cast(); - if (pExt.IsInit()) - return pExt->Uri().m_strFilename; + const bool IsExist(const OOX::FileType& oType) const; - smart_ptr pMedia = Find(rid).smart_dynamic_cast(); - if (pMedia.IsInit()) - return pMedia->filename().m_strFilename; - - return _T(""); - } - virtual std::wstring GetOleFromRId(const OOX::RId& rid)const - { - smart_ptr p = Get(rid); - if (!p.is_init()) - return _T(""); - return p->filename().m_strFilename; - } + smart_ptr Get(const OOX::FileType& oType); + void Get(const OOX::FileType& oType, std::vector> & files); + + virtual std::wstring GetImagePathNameFromRId(const OOX::RId& rid)const; + virtual std::wstring GetLinkFromRId (const OOX::RId& rid)const; + virtual std::wstring GetOleFromRId (const OOX::RId& rid)const; protected: void read(const OOX::CPath& filename); void read(const OOX::CRels& rels, const OOX::CPath& path); diff --git a/ASCOfficePPTXFile/PPTXFormat/Folder.cpp b/ASCOfficePPTXFile/PPTXFormat/Folder.cpp index 3b02e3b0d4..c771ea4d5d 100644 --- a/ASCOfficePPTXFile/PPTXFormat/Folder.cpp +++ b/ASCOfficePPTXFile/PPTXFormat/Folder.cpp @@ -79,11 +79,11 @@ namespace PPTX if (_presentation->IsExist(OOX::FileTypes::VbaProject)) { _presentation->m_bMacroEnabled = true; - _presentation->m_pVbaProject = _presentation->Get(OOX::FileTypes::VbaProject).smart_dynamic_cast(); + _presentation->m_pVbaProject = _presentation->Get(OOX::FileTypes::VbaProject).smart_dynamic_cast(); } if (_presentation->IsExist(OOX::FileTypes::JsaProject)) { - _presentation->m_pJsaProject = _presentation->Get(OOX::FileTypes::JsaProject).smart_dynamic_cast(); + _presentation->m_pJsaProject = _presentation->Get(OOX::FileTypes::JsaProject).smart_dynamic_cast(); } _presentation->comments = _presentation->Get(OOX::Presentation::FileTypes::SlideComments).smart_dynamic_cast(); } @@ -191,17 +191,17 @@ namespace PPTX return true;//FileContainer::exist(OOX::Presentation::FileTypes::Presentation); } - void Document::extractPictures(const OOX::CPath& path) - { - OOX::CSystemUtility::CreateDirectories(path); - FileContainer::ExtractPictures(path); - } + //void Document::extractPictures(const OOX::CPath& path) + //{ + // OOX::CSystemUtility::CreateDirectories(path); + // FileContainer::ExtractPictures(path); + //} - void Document::extractPictures(const OOX::CPath& source, const OOX::CPath& path) - { - //read(source); - extractPictures(path); - } + //void Document::extractPictures(const OOX::CPath& source, const OOX::CPath& path) + //{ + // //read(source); + // extractPictures(path); + //} long Document::CountFiles(const OOX::CPath& path) { diff --git a/ASCOfficePPTXFile/PPTXFormat/Folder.h b/ASCOfficePPTXFile/PPTXFormat/Folder.h index 927d211131..6dc0768c5c 100644 --- a/ASCOfficePPTXFile/PPTXFormat/Folder.h +++ b/ASCOfficePPTXFile/PPTXFormat/Folder.h @@ -50,8 +50,8 @@ namespace PPTX const bool isValid(const OOX::CPath& path) const; - void extractPictures(const OOX::CPath& path); - void extractPictures(const OOX::CPath& source, const OOX::CPath& path); + //void extractPictures(const OOX::CPath& path); + //void extractPictures(const OOX::CPath& source, const OOX::CPath& path); private: long CountFiles(const OOX::CPath& path); }; diff --git a/ASCOfficePPTXFile/PPTXFormat/Logic/Fills/Blip.cpp b/ASCOfficePPTXFile/PPTXFormat/Logic/Fills/Blip.cpp index 24a18c3911..404351224f 100644 --- a/ASCOfficePPTXFile/PPTXFormat/Logic/Fills/Blip.cpp +++ b/ASCOfficePPTXFile/PPTXFormat/Logic/Fills/Blip.cpp @@ -135,8 +135,14 @@ namespace PPTX { smart_ptr pOleObject; - if (pRels != NULL) pOleObject = pRels->Get(oRId); - else if(parentFileIs()) pOleObject = parentFileAs().Get(oRId); + if (pRels != NULL) + pOleObject = pRels->Get(oRId); + else + { + OOX::IFileContainer* pContainer = dynamic_cast(const_cast(parentFile)); + if (pContainer) + pOleObject = pContainer->Get(oRId); + } if (pOleObject.IsInit()) return pOleObject->filename().m_strFilename; diff --git a/ASCOfficePPTXFile/PPTXFormat/Logic/Pic.cpp b/ASCOfficePPTXFile/PPTXFormat/Logic/Pic.cpp index 57dcfc39cd..abdad7d5bd 100644 --- a/ASCOfficePPTXFile/PPTXFormat/Logic/Pic.cpp +++ b/ASCOfficePPTXFile/PPTXFormat/Logic/Pic.cpp @@ -503,12 +503,14 @@ namespace PPTX smart_ptr ole_file = m_OleObjectFile; if (ole_file.IsInit() == false) { - if (pRels != NULL) ole_file = pRels->Get(oRId); - - else if(parentFileIs()) ole_file = parentFileAs().Get(oRId); - else if(parentFileIs()) ole_file = parentFileAs().Get(oRId); - else if(parentFileIs()) ole_file = parentFileAs().Get(oRId); - else if(parentFileIs()) ole_file = parentFileAs().Get(oRId); + if (pRels != NULL) + ole_file = pRels->Get(oRId); + else + { + OOX::IFileContainer* pContainer = dynamic_cast(const_cast(parentFile)); + if (pContainer) + ole_file = pContainer->Get(oRId); + } } return ole_file; } diff --git a/ASCOfficePPTXFile/PPTXFormat/Presentation.h b/ASCOfficePPTXFile/PPTXFormat/Presentation.h index 682fbd5f96..cc05e44395 100644 --- a/ASCOfficePPTXFile/PPTXFormat/Presentation.h +++ b/ASCOfficePPTXFile/PPTXFormat/Presentation.h @@ -73,8 +73,6 @@ namespace PPTX } virtual void read(const OOX::CPath& filename, FileMap& map) { - //FileContainer::read(filename, map); - XmlUtils::CXmlNode oNode; oNode.FromXmlFile(filename.m_strFilename); diff --git a/ASCOfficePPTXFile/PPTXLib/PPTXFormat.vcproj b/ASCOfficePPTXFile/PPTXLib/PPTXFormat.vcproj index 76f01cb800..4b142e809c 100644 --- a/ASCOfficePPTXFile/PPTXLib/PPTXFormat.vcproj +++ b/ASCOfficePPTXFile/PPTXLib/PPTXFormat.vcproj @@ -54,6 +54,7 @@ WarningLevel="3" Detect64BitPortabilityProblems="true" DebugInformationFormat="4" + DisableSpecificWarnings="4005;4311;4312" /> m_currentContainer = dynamic_cast(oParam.oDocx->GetDocument()); + oParam.oReader->m_currentContainer = dynamic_cast(oParam.oDocx->m_pDocument); return true; } diff --git a/ASCOfficeRtfFile/RtfFormatLib/source/Reader/OOXReader.cpp b/ASCOfficeRtfFile/RtfFormatLib/source/Reader/OOXReader.cpp index 93d421fdf4..abf63d9bf9 100644 --- a/ASCOfficeRtfFile/RtfFormatLib/source/Reader/OOXReader.cpp +++ b/ASCOfficeRtfFile/RtfFormatLib/source/Reader/OOXReader.cpp @@ -59,75 +59,65 @@ bool OOXReader::Parse() oReaderParameter.oRtf = &m_oDocument; oReaderParameter.oReader = this; - OOX::CSettings* settings = inputDocxFile.GetSettings(); - if (settings) + if (inputDocxFile.m_pSettings) { //важно чтобы первыми читались именно settings (например для footnote) - OOXSettingsReader oSettingsReader( settings ); + OOXSettingsReader oSettingsReader( inputDocxFile.m_pSettings ); oSettingsReader.Parse( oReaderParameter ); } - OOX::CFontTable* fontTable = inputDocxFile.GetFontTable(); - if (fontTable) + if (inputDocxFile.m_pFontTable) { - OOXFontTableReader oFontTableReader( fontTable ); + OOXFontTableReader oFontTableReader( inputDocxFile.m_pFontTable ); oFontTableReader.Parse( oReaderParameter ); } - PPTX::Theme* theme = inputDocxFile.GetTheme(); - if (theme) + if (inputDocxFile.m_pTheme) { - OOXThemeReader oThemeReader( theme ); + OOXThemeReader oThemeReader( inputDocxFile.m_pTheme ); oThemeReader.Parse( oReaderParameter ); } - OOX::CNumbering* numbering = inputDocxFile.GetNumbering(); - if (numbering) + if (inputDocxFile.m_pNumbering) { - OOXNumberingReader oNumberingReader( numbering ); + OOXNumberingReader oNumberingReader( inputDocxFile.m_pNumbering ); oNumberingReader.Parse(oReaderParameter ); } - OOX::CStyles* styles = inputDocxFile.GetStyles(); - if (styles) + if (inputDocxFile.m_pStyles) { - OOXStyleTableReader oStyleTableReader( styles ); + OOXStyleTableReader oStyleTableReader( inputDocxFile.m_pStyles ); oStyleTableReader.Parse( oReaderParameter ); } - OOX::CApp* app = inputDocxFile.GetApp(); - if (app) + if (inputDocxFile.m_pApp) { - OOXAppReader oDocPropAppReader( app ); + OOXAppReader oDocPropAppReader( inputDocxFile.m_pApp ); oDocPropAppReader.Parse( oReaderParameter ); } - OOX::CCore* core = inputDocxFile.GetCore(); - if (core) + if (inputDocxFile.m_pCore) { - OOXCoreReader oDocPropCoreReader( core); + OOXCoreReader oDocPropCoreReader( inputDocxFile.m_pCore ); oDocPropCoreReader.Parse(oReaderParameter ); } - OOX::CFootnotes* footnotes = inputDocxFile.GetFootnotes(); - if (footnotes) + if (inputDocxFile.m_pFootnotes) { - OOXFootnotesReader oFootnotesReader( footnotes ); + OOXFootnotesReader oFootnotesReader( inputDocxFile.m_pFootnotes ); oFootnotesReader.Parse( oReaderParameter); } - OOX::CEndnotes* endnotes = inputDocxFile.GetEndnotes(); - if (endnotes) + if (inputDocxFile.m_pEndnotes) { - OOXFootnotesReader oEndnotesReader( endnotes ); + OOXFootnotesReader oEndnotesReader( inputDocxFile.m_pEndnotes ); oEndnotesReader.Parse( oReaderParameter); } - OOX::CDocument* document = inputDocxFile.GetDocument(); - if (document) + if (inputDocxFile.m_pDocument) { - m_currentContainer = dynamic_cast(document); + m_currentContainer = dynamic_cast(inputDocxFile.m_pDocument); - OOXDocumentReader oDocReader( document ); + OOXDocumentReader oDocReader( inputDocxFile.m_pDocument ); oDocReader.Parse( oReaderParameter ); } diff --git a/ASCOfficeRtfFile/RtfFormatLib/source/Reader/OOXShapeReader.cpp b/ASCOfficeRtfFile/RtfFormatLib/source/Reader/OOXShapeReader.cpp index 83660f1471..5b6486ea11 100644 --- a/ASCOfficeRtfFile/RtfFormatLib/source/Reader/OOXShapeReader.cpp +++ b/ASCOfficeRtfFile/RtfFormatLib/source/Reader/OOXShapeReader.cpp @@ -979,8 +979,7 @@ void OOXShapeReader::Parse( ReaderParameter oParam, RtfShapePtr& pOutput, PPTX:: int fmt_index = style_ref->idx.get() -1; - PPTX::Theme *theme = oParam.oDocx->GetTheme(); - if (!theme || fmt_index <0) return; + if (!oParam.oDocx->m_pTheme || fmt_index <0) return; if (style_ref->Color.is() == false) return; @@ -990,21 +989,21 @@ void OOXShapeReader::Parse( ReaderParameter oParam, RtfShapePtr& pOutput, PPTX:: if (type == 1) { - if (fmt_index < 1000 && fmt_index < theme->themeElements.fmtScheme.fillStyleLst.size()) + if (fmt_index < 1000 && fmt_index < oParam.oDocx->m_pTheme->themeElements.fmtScheme.fillStyleLst.size()) { - Parse(oParam, pOutput, &theme->themeElements.fmtScheme.fillStyleLst[fmt_index], &color); + Parse(oParam, pOutput, &oParam.oDocx->m_pTheme->themeElements.fmtScheme.fillStyleLst[fmt_index], &color); } - else if (fmt_index > 1000 && ((fmt_index-1000) < theme->themeElements.fmtScheme.bgFillStyleLst.size())) + else if (fmt_index > 1000 && ((fmt_index-1000) < oParam.oDocx->m_pTheme->themeElements.fmtScheme.bgFillStyleLst.size())) { fmt_index -= 1000; - Parse(oParam, pOutput, &theme->themeElements.fmtScheme.bgFillStyleLst[fmt_index], &color); + Parse(oParam, pOutput, &oParam.oDocx->m_pTheme->themeElements.fmtScheme.bgFillStyleLst[fmt_index], &color); } } - if (type == 2 && fmt_index < theme->themeElements.fmtScheme.lnStyleLst.size()) + if (type == 2 && fmt_index < oParam.oDocx->m_pTheme->themeElements.fmtScheme.lnStyleLst.size()) { - Parse(oParam, pOutput, &theme->themeElements.fmtScheme.lnStyleLst[fmt_index], &color); + Parse(oParam, pOutput, &oParam.oDocx->m_pTheme->themeElements.fmtScheme.lnStyleLst[fmt_index], &color); } //if (style_matrix_ref->getType() == OOX::et_a_effectRef && fmt_index < theme->m_oThemeElements.m_oFmtScheme.m_oEffectStyleLst.m_arrEffectStyle.size()) diff --git a/ASCOfficeTxtFile/TxtXmlFormatLib/Source/ConvertDocx2Txt.cpp b/ASCOfficeTxtFile/TxtXmlFormatLib/Source/ConvertDocx2Txt.cpp index dff13078ba..2341ceeb10 100644 --- a/ASCOfficeTxtFile/TxtXmlFormatLib/Source/ConvertDocx2Txt.cpp +++ b/ASCOfficeTxtFile/TxtXmlFormatLib/Source/ConvertDocx2Txt.cpp @@ -169,58 +169,48 @@ namespace Docx2Txt void Converter_Impl::convert(TxtXml::ITxtXmlEvent& Event) { - OOX::CDocument *pDocument = NULL; - OOX::CStyles *pStyles = NULL; - OOX::CNumbering *pNumbering = NULL; - m_lPercent = 100000; m_bCancelled = Event.Progress(0, m_lPercent); if(m_bCancelled) return; - smart_ptr pFileD = m_inputFile.Find(OOX::FileTypes::Document); - if (pFileD.IsInit() && OOX::FileTypes::Document == pFileD->type()) - pDocument = (OOX::CDocument*)pFileD.operator->(); - - smart_ptr pFileS = pDocument->Find(OOX::FileTypes::Style); - if (pFileS.IsInit() && OOX::FileTypes::Style == pFileS->type()) - pStyles = (OOX::CStyles*)pFileS.operator->(); + OOX::CDocument *pDocument = m_inputFile.m_pDocument; + OOX::CStyles *pStyles = m_inputFile.m_pStyles; + OOX::CNumbering *pNumbering = m_inputFile.m_pNumbering; - smart_ptr pFileN = pDocument->Find(OOX::FileTypes::Numbering); - if (pFileN.IsInit() && OOX::FileTypes::Numbering == pFileN->type()) + if (pNumbering) { - pNumbering = (OOX::CNumbering*)pFileN.operator->(); - ListCount = pNumbering->m_arrNum.size(); Lists = new int[9 * ListCount]; if(Lists == NULL) return; - for(int i = 0; i < 9 * ListCount; i++) + for (int i = 0; i < 9 * ListCount; i++) Lists[i] = 0; } - if(pDocument->m_arrItems.size() > 0) - { - m_lAddition = 800000; - Notes.clear(); - - convert(pDocument->m_arrItems, m_outputFile.m_listContent, Event, true, pDocument, pNumbering, pStyles); - if(NoteCount != 0) + if (!pDocument) return; + if (pDocument->m_arrItems.empty()) return; + + m_lAddition = 800000; + Notes.clear(); + + convert(pDocument->m_arrItems, m_outputFile.m_listContent, Event, true, pDocument, pNumbering, pStyles); + + if(NoteCount != 0) + { + m_outputFile.m_listContent.push_back(L""); + m_outputFile.m_listContent.push_back(L"---------------------------"); + + for(std::map>::const_iterator iter_map = Notes.begin(); iter_map != Notes.end(); iter_map++) { - m_outputFile.m_listContent.push_back(L""); - m_outputFile.m_listContent.push_back(L"---------------------------"); + bool bFirst = true; - for(std::map>::const_iterator iter_map = Notes.begin(); iter_map != Notes.end(); iter_map++) + for(std::vector::const_iterator iter = iter_map->second.begin(); iter != iter_map->second.end(); iter++) { - bool bFirst = true; + if (bFirst) m_outputFile.m_listContent.push_back(iter_map->first + L" " + *iter); + else m_outputFile.m_listContent.push_back(*iter); - for(std::vector::const_iterator iter = iter_map->second.begin(); iter != iter_map->second.end(); iter++) - { - if (bFirst) m_outputFile.m_listContent.push_back(iter_map->first + L" " + *iter); - else m_outputFile.m_listContent.push_back(*iter); - - bFirst = false; - } + bFirst = false; } } } @@ -473,22 +463,21 @@ namespace Docx2Txt bool inField = false; - for (std::vector::iterator it = pParagraph->m_arrItems.begin(); - it != pParagraph->m_arrItems.end(); ++it) + for (size_t i = 0; i < pParagraph->m_arrItems.size(); ++i) { - if (*it== NULL) continue; + if (pParagraph->m_arrItems[i] == NULL) continue; - if ((*it)->getType() == OOX::et_w_r) + if (pParagraph->m_arrItems[i]->getType() == OOX::et_w_r) { - OOX::Logic::CRun *run = dynamic_cast(*it); + OOX::Logic::CRun *run = dynamic_cast(pParagraph->m_arrItems[i]); - for (std::vector::iterator jt = run->m_arrItems.begin(); jt != run->m_arrItems.end(); jt++) + for (size_t j = 0; j < run->m_arrItems.size(); ++j) { - if (*jt== NULL) continue; + if (run->m_arrItems[j] == NULL) continue; - if ((*jt)->getType() == OOX::et_w_fldChar) + if (run->m_arrItems[j]->getType() == OOX::et_w_fldChar) { - OOX::Logic::CFldChar *fldChar = dynamic_cast(*jt); + OOX::Logic::CFldChar *fldChar = dynamic_cast(run->m_arrItems[j]); if ((fldChar) && (fldChar->m_oFldCharType.IsInit())) { @@ -503,13 +492,13 @@ namespace Docx2Txt if ((run->m_oRunProperty) && (run->m_oRunProperty->m_oCaps.Init()) && (run->m_oRunProperty->m_oCaps->m_oVal.ToBool())) caps = true; std::wstring wstr; - if ((*jt)->getType() == OOX::et_w_tab) + if (run->m_arrItems[j]->getType() == OOX::et_w_tab) { wstr = L"\x09"; } - else if ((*jt)->getType() == OOX::et_w_t) + else if (run->m_arrItems[j]->getType() == OOX::et_w_t) { - OOX::Logic::CText* text = dynamic_cast(*jt); + OOX::Logic::CText* text = dynamic_cast(run->m_arrItems[j]); wstr = text->m_sText; if(caps) { @@ -518,49 +507,38 @@ namespace Docx2Txt } } - if ((*jt)->getType() == OOX::et_w_footnoteReference || (*it)->getType() == OOX::et_w_endnoteReference) + if (run->m_arrItems[j]->getType() == OOX::et_w_footnoteReference || + pParagraph->m_arrItems[i]->getType() == OOX::et_w_endnoteReference) {// todooo Ref ???? std::vector notes_content; - OOX::Logic::CFootnoteReference* footnote_ref = dynamic_cast(*jt); - OOX::Logic::CEndnoteReference* endnote_ref = dynamic_cast(*jt); + OOX::Logic::CFootnoteReference* footnote_ref = dynamic_cast(run->m_arrItems[j]); + OOX::Logic::CEndnoteReference* endnote_ref = dynamic_cast(run->m_arrItems[j]); NoteCount++; - if (footnote_ref) - { - smart_ptr pFile = pDocument->Find(OOX::FileTypes::FootNote); - if (pFile.IsInit()) + if (footnote_ref && m_inputFile.m_pFootnotes) + { + for (size_t r = 0; r < m_inputFile.m_pFootnotes->m_arrFootnote.size(); r++) { - OOX::CFootnotes *pFootnotes = (OOX::CFootnotes*)pFile.operator->(); - - for (size_t r = 0; r < pFootnotes->m_arrFootnote.size(); r++) - { - OOX::CFtnEdn* note = dynamic_cast(pFootnotes->m_arrFootnote[r]); + OOX::CFtnEdn* note = dynamic_cast(m_inputFile.m_pFootnotes->m_arrFootnote[r]); - if (note && note->m_oId == footnote_ref->m_oId) - { - convert(pFootnotes->m_arrFootnote[r]->m_arrItems, notes_content, Event, false, pDocument, pNumbering, pStyles); - } + if (note && note->m_oId == footnote_ref->m_oId) + { + convert(m_inputFile.m_pFootnotes->m_arrFootnote[r]->m_arrItems, notes_content, Event, false, pDocument, pNumbering, pStyles); } } Notes.insert(std::make_pair(ToWString(NoteCount), notes_content)); } - if (endnote_ref) + if (endnote_ref && m_inputFile.m_pEndnotes) { - smart_ptr pFile = pDocument->Find(OOX::FileTypes::EndNote); - if (pFile.IsInit()) + for (size_t r =0; r < m_inputFile.m_pEndnotes->m_arrEndnote.size(); r++) { - OOX::CEndnotes *pEndnotes = (OOX::CEndnotes*)pFile.operator->(); + OOX::CFtnEdn* note = dynamic_cast(m_inputFile.m_pEndnotes->m_arrEndnote[r]); - for (size_t r =0; r < pEndnotes->m_arrEndnote.size(); r++) + if (note && note->m_oId == endnote_ref->m_oId) { - OOX::CFtnEdn* note = dynamic_cast(pEndnotes->m_arrEndnote[r]); - - if (note && note->m_oId == endnote_ref->m_oId) - { - convert(pEndnotes->m_arrEndnote[r]->m_arrItems, notes_content, Event, false, pDocument, pNumbering, pStyles); - } + convert(m_inputFile.m_pEndnotes->m_arrEndnote[r]->m_arrItems, notes_content, Event, false, pDocument, pNumbering, pStyles); } } Notes.insert(std::make_pair(ToWString(NoteCount), notes_content)); diff --git a/ASCOfficeTxtFile/TxtXmlFormatLib/Win32/TxtXmlFormatLib.vcproj b/ASCOfficeTxtFile/TxtXmlFormatLib/Win32/TxtXmlFormatLib.vcproj index c9af14818b..959baf1781 100644 --- a/ASCOfficeTxtFile/TxtXmlFormatLib/Win32/TxtXmlFormatLib.vcproj +++ b/ASCOfficeTxtFile/TxtXmlFormatLib/Win32/TxtXmlFormatLib.vcproj @@ -52,6 +52,7 @@ WarningLevel="3" Detect64BitPortabilityProblems="true" DebugInformationFormat="4" + DisableSpecificWarnings="4005;4311;4312" /> + + @@ -1679,6 +1684,10 @@ RelativePath="..\Source\XlsxFormat\Worksheets\SheetData.h" > + + diff --git a/Common/DocxFormat/Source/DocxFormat/Document.h b/Common/DocxFormat/Source/DocxFormat/Document.h index 389979155b..cf5dc5e65f 100644 --- a/Common/DocxFormat/Source/DocxFormat/Document.h +++ b/Common/DocxFormat/Source/DocxFormat/Document.h @@ -203,14 +203,14 @@ namespace OOX { m_bMacroEnabled = false; - CDocx* docx = dynamic_cast(File::m_pMainDocument); + CDocx* docx = dynamic_cast(pMain); if (docx) docx->m_pDocument = this; } CDocument(OOX::Document *pMain, const CPath& oRootPath, const CPath& oPath) : File(pMain), IFileContainer(pMain) { m_bMacroEnabled = false; - CDocx* docx = dynamic_cast(File::m_pMainDocument); + CDocx* docx = dynamic_cast(pMain); if (docx) docx->m_pDocument = this; read( oRootPath, oPath ); @@ -320,12 +320,14 @@ namespace OOX m_oReadPath = oPath; IFileContainer::Read( oRootPath, oPath ); - if (IFileContainer::IsExist(OOX::FileTypes::VbaProject)) + CDocx* docx = dynamic_cast(File::m_pMainDocument); + if ( (docx ) && (docx->m_pVbaProject) ) { m_bMacroEnabled = true; - } + } + #ifdef USE_LITE_READER - Common::readAllShapeTypes(oPath, m_arrShapeTypes); + Common::readAllShapeTypes(oPath, m_arrShapeTypes);//todooo перенести на уровень OOX::Documet чтоли - при чтении xml XmlUtils::CXmlLiteReader oReader; diff --git a/Common/DocxFormat/Source/DocxFormat/Docx.h b/Common/DocxFormat/Source/DocxFormat/Docx.h index 69338f0c7a..2118565bfe 100644 --- a/Common/DocxFormat/Source/DocxFormat/Docx.h +++ b/Common/DocxFormat/Source/DocxFormat/Docx.h @@ -61,6 +61,7 @@ namespace OOX class CCommentsExt; class CPeople; class VbaProject; + class JsaProject; class CHdrFtr; class CDocx : public OOX::Document, public OOX::IFileContainer @@ -69,41 +70,13 @@ namespace OOX CDocx() : OOX::IFileContainer(dynamic_cast(this)) { - m_pDocument = NULL; - m_pFontTable = NULL; - m_pNumbering = NULL; - m_pStyles = NULL; - m_pApp = NULL; - m_pCore = NULL; - m_pEndnotes = NULL; - m_pFootnotes = NULL; - m_pSettings = NULL; - m_pTheme = NULL; - m_pComments = NULL; - m_pCommentsExt = NULL; - m_pPeople = NULL; - m_pVbaProject = NULL; + init(); } CDocx(const CPath& oFilePath) : OOX::IFileContainer(this) { - m_pDocument = NULL; - m_pFontTable = NULL; - m_pNumbering = NULL; - m_pStyles = NULL; - m_pApp = NULL; - m_pCore = NULL; - m_pEndnotes = NULL; - m_pFootnotes = NULL; - m_pSettings = NULL; - m_pTheme = NULL; - m_pComments = NULL; - m_pCommentsExt = NULL; - m_pPeople = NULL; - m_pVbaProject = NULL; - + init(); Read( oFilePath ); } - bool Read(const CPath& oFilePath); bool Write(const CPath& oFilePath) { @@ -130,62 +103,7 @@ namespace OOX return true; } - OOX::CDocument *GetDocument () const - { - return m_pDocument; - } - OOX::CFontTable *GetFontTable() const - { - return m_pFontTable; - } - OOX::CNumbering *GetNumbering() const - { - return m_pNumbering; - } - OOX::CStyles *GetStyles () const - { - return m_pStyles; - } - OOX::CEndnotes *GetEndnotes () const - { - return m_pEndnotes; - } - OOX::CFootnotes *GetFootnotes() const - { - return m_pFootnotes; - } - OOX::CApp *GetApp () const - { - return m_pApp; - } - OOX::CCore *GetCore () const - { - return m_pCore; - } - OOX::CSettings *GetSettings () const - { - return m_pSettings; - } - OOX::CComments *GetComments () const - { - return m_pComments; - } - OOX::CCommentsExt *GetCommentsExt () const - { - return m_pCommentsExt; - } - OOX::CPeople *GetPeople () const - { - return m_pPeople; - } - - PPTX::Theme *GetTheme () const - { - return m_pTheme; - } - OOX::CHdrFtr *GetHeaderOrFooter(const OOX::RId& rId) const; - OOX::CApp *m_pApp; OOX::CCore *m_pCore; @@ -200,10 +118,31 @@ namespace OOX OOX::CComments *m_pComments; // word/comments.xml OOX::CCommentsExt *m_pCommentsExt;// word/commentsExtended.xml OOX::CPeople *m_pPeople; // word/people.xml + OOX::VbaProject *m_pVbaProject; + OOX::JsaProject *m_pJsaProject; PPTX::Theme *m_pTheme; +private: + void init() + { + m_pDocument = NULL; + m_pFontTable = NULL; + m_pNumbering = NULL; + m_pStyles = NULL; + m_pApp = NULL; + m_pCore = NULL; + m_pEndnotes = NULL; + m_pFootnotes = NULL; + m_pSettings = NULL; + m_pTheme = NULL; + m_pComments = NULL; + m_pCommentsExt = NULL; + m_pPeople = NULL; + m_pVbaProject = NULL; + m_pJsaProject = NULL; + } }; } // OOX diff --git a/Common/DocxFormat/Source/DocxFormat/IFileContainer.cpp b/Common/DocxFormat/Source/DocxFormat/IFileContainer.cpp index 18abb2ad30..e57351e99c 100644 --- a/Common/DocxFormat/Source/DocxFormat/IFileContainer.cpp +++ b/Common/DocxFormat/Source/DocxFormat/IFileContainer.cpp @@ -50,7 +50,7 @@ namespace OOX { boost::unordered_map IFileContainer::m_mapEnumeratedGlobal; - UnknowTypeFile IFileContainer::Unknown(NULL); + UnknowTypeFile IFileContainer::m_oUnknown(NULL); IFileContainer::IFileContainer(OOX::Document* pMain) : m_pMainDocument(pMain) { @@ -238,39 +238,7 @@ namespace OOX } } - void IFileContainer::ExtractPictures (const OOX::CPath& oPath) const - { - for (size_t i = 0; i < m_arContainer.size(); ++i) - { - smart_ptr pFile = m_arContainer[i]; - smart_ptr pImage = pFile.smart_dynamic_cast(); - if ( pImage.is_init() ) - { - pImage->copy_to( oPath ); - continue; - } - - smart_ptr pExt = pFile.smart_dynamic_cast(); - if ( pExt.is_init() ) - { - pExt->ExtractPictures( oPath ); - continue; - } - } - } - const bool IFileContainer::IsExist(const FileType& oType) const - { - for (size_t i = 0; i < m_arContainer.size(); ++i) - { - smart_ptr pFile = m_arContainer[i]; - - if (oType == pFile->type()) - return true; - } - - return false; - } const bool IFileContainer::IsExist(const RId& rId) const { boost::unordered_map>::const_iterator pFind = m_mapContainer.find(rId.get()); @@ -283,17 +251,15 @@ namespace OOX T oFile; return IsExist( oFile.type() ); } - std::wstring IFileContainer::IsExistHyperlink(smart_ptr& pHyperLink) + std::wstring IFileContainer::IsExistHyperlink(const std::wstring & href) { - for ( boost::unordered_map>::const_iterator pPair = m_mapContainer.begin(); pPair != m_mapContainer.end(); ++pPair) + boost::unordered_map::const_iterator pFind = m_mapHyperlinks.find(href); + + if (pFind != m_mapHyperlinks.end()) { - if(OOX::FileTypes::HyperLink == pPair->second->type()) - { - smart_ptr pCurHyperlink = pPair->second.smart_dynamic_cast(); - if(pCurHyperlink->Uri().GetPath() == pHyperLink->Uri().GetPath()) - return pPair->first; - } + return pFind->second; } + return std::wstring(); } const bool IFileContainer::IsExternal(const OOX::RId& rId) const @@ -316,28 +282,7 @@ namespace OOX return true; } - smart_ptr IFileContainer::Get(const FileType& oType) - { - for (size_t i = 0; i < m_arContainer.size(); ++i) - { - smart_ptr &pFile = m_arContainer[i]; - if (oType == pFile->type()) - return pFile; - } - return smart_ptr(new UnknowTypeFile( Unknown )); - } - - void IFileContainer::Get(const FileType& oType, std::vector> & files) - { - for (size_t i = 0; i < m_arContainer.size(); ++i) - { - smart_ptr &pFile = m_arContainer[i]; - - if ( oType == pFile->type() ) - files.push_back(pFile); - } - } const RId IFileContainer::Add(smart_ptr& pFile) { const RId rId = GetMaxRId().next(); @@ -347,8 +292,8 @@ namespace OOX void IFileContainer::Add (const OOX::RId& rId, smart_ptr& pFile) { - bool bEnumerated = pFile->type().Enumerated(); - bool bEnumeratedGlobal = pFile->type().EnumeratedGlobal(); + bool bEnumerated = pFile->type().Enumerated(); + bool bEnumeratedGlobal = pFile->type().EnumeratedGlobal(); if(true == bEnumeratedGlobal || true == bEnumerated) { @@ -396,6 +341,12 @@ namespace OOX m_arContainer.push_back(pFile); m_mapContainer [rId.get()] = pFile; + + smart_ptr oHyperlinkFile = pFile.smart_dynamic_cast(); + if (oHyperlinkFile.IsInit()) + { + m_mapHyperlinks.insert(std::make_pair( oHyperlinkFile->Uri().GetPath(), rId.get() )); + } } const RId IFileContainer::AddNoWrite(const smart_ptr& pFile, const std::wstring& oDefDir) @@ -415,16 +366,6 @@ namespace OOX m_mNoWriteContainer[rId.get()] = oDefDir; } - smart_ptr IFileContainer::Find(const FileType& oType) const - { - for (size_t i = 0; i < m_arContainer.size(); ++i) - { - if ( oType == m_arContainer[i]->type() ) - return m_arContainer[i]; - } - return smart_ptr( (OOX::File*)new UnknowTypeFile(m_pMainDocument) ); - } - smart_ptr IFileContainer::Find(const OOX::RId& rId) const { boost::unordered_map>::const_iterator pPair = m_mapContainer.find(rId.get()); @@ -449,12 +390,6 @@ namespace OOX return smart_ptr( (OOX::File*)new UnknowTypeFile(m_pMainDocument) ); } - - smart_ptr IFileContainer::operator [](const FileType& oType) - { - return Find( oType ); - } - const RId IFileContainer::GetMaxRId() { return RId( m_lMaxRid ); diff --git a/Common/DocxFormat/Source/DocxFormat/IFileContainer.h b/Common/DocxFormat/Source/DocxFormat/IFileContainer.h index a3d8330d23..bb798b07e5 100644 --- a/Common/DocxFormat/Source/DocxFormat/IFileContainer.h +++ b/Common/DocxFormat/Source/DocxFormat/IFileContainer.h @@ -65,6 +65,7 @@ namespace OOX OOX::Document* m_pMainDocument; smart_ptr m_pCurRels; protected: + static UnknowTypeFile m_oUnknown; std::vector> m_arContainer; boost::unordered_map> m_mapContainer; @@ -81,7 +82,6 @@ namespace OOX public: void Read (const OOX::CPath& oRootPath, const OOX::CPath& oPath); - void ExtractPictures(const OOX::CPath& oPath) const; template smart_ptr Get (const RId& rId) const @@ -91,40 +91,36 @@ namespace OOX return smart_ptr(); return pFind->second.smart_dynamic_cast(); } + + std::vector>& GetContainer() {return m_arContainer;} template const bool IsExist() const; - const bool IsExist(const FileType& oType) const; const bool IsExist(const OOX::RId& rId) const; const bool IsExternal(const OOX::RId& rId) const; - std::wstring IsExistHyperlink(smart_ptr& pHyperLink); - - smart_ptr Get(const FileType& oType); - void Get(const FileType& oType, std::vector> & files); - + + std::wstring IsExistHyperlink(const std::wstring & href); + const RId Add(smart_ptr& pFile); void Add(const OOX::RId& rId, smart_ptr& pFile); + const RId AddNoWrite(const smart_ptr& pFile, const std::wstring& oDefDir); void AddNoWrite(const OOX::RId& rId, const smart_ptr& pFile, const std::wstring& oDefDir); template T& Find(); - smart_ptr Find(const FileType& type) const; smart_ptr Find(const OOX::RId& type) const; - void FindAllByType(const FileType& oType, boost::unordered_map>& aOutput) const; - smart_ptr operator [](const OOX::RId rId); smart_ptr operator [](const FileType& oType); void SetGlobalNumberByType(const std::wstring& sOverrideType, int val); int GetGlobalNumberByType(const std::wstring& sOverrideType); - protected: - static UnknowTypeFile Unknown; private: - boost::unordered_map m_mapAddNamePair; - - const RId GetMaxRId(); + const RId GetMaxRId(); + + boost::unordered_map m_mapAddNamePair; + boost::unordered_map m_mapHyperlinks; }; } // namespace OOX diff --git a/Common/DocxFormat/Source/DocxFormat/Media/VbaProject.cpp b/Common/DocxFormat/Source/DocxFormat/Media/VbaProject.cpp new file mode 100644 index 0000000000..2ec48b7220 --- /dev/null +++ b/Common/DocxFormat/Source/DocxFormat/Media/VbaProject.cpp @@ -0,0 +1,132 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2017 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, + * EU, LV-1021. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ +#include "VbaProject.h" + +#include "../Docx.h" +#include "../../XlsxFormat/Xlsx.h" + +#include "Media.h" +#include "../../../../../ASCOfficePPTXFile/Editor/BinaryFileReaderWriter.h" +#include "../../../../../ASCOfficePPTXFile/Editor/imagemanager.h" + +#include "../IFileContainer.h" +#include "../../XlsxFormat/FileTypes_Spreadsheet.h" + +namespace OOX +{ + VbaProject::VbaProject( OOX::Document *pMain ) : Media(pMain), OOX::IFileContainer(pMain) + { + OOX::CDocx* docx = dynamic_cast(pMain); + if (docx) + { + docx->m_pVbaProject = this; + } + else + { + OOX::Spreadsheet::CXlsx* xlsx = dynamic_cast(pMain); + if (xlsx) + { + xlsx->m_pVbaProject = this; + } + } + } + VbaProject::VbaProject(OOX::Document *pMain, const CPath& oRootPath, const CPath& filename) : Media(pMain), OOX::IFileContainer(pMain) + { + OOX::CDocx* docx = dynamic_cast(pMain); + if (docx) + { + docx->m_pVbaProject = this; + } + else + { + OOX::Spreadsheet::CXlsx* xlsx = dynamic_cast(pMain); + if (xlsx) + { + xlsx->m_pVbaProject = this; + } + } + read( oRootPath, filename ); + } + void VbaProject::read(const CPath& oRootPath, const CPath& oPath) + { + IFileContainer::Read( oRootPath, oPath ); + + Media::read(oPath); + } + void VbaProject::write(const OOX::CPath& filename, const OOX::CPath& directory, CContentTypes& content) const + { + content.Registration( type().OverrideType(), directory, filename.GetFilename() ); + IFileContainer::Write( filename, directory, content ); + } + void VbaProject::toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const + { + pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeStart); + + pWriter->WriteString1(0, m_filename.GetFilename()); + + pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd); + + copy_to(pWriter->m_pCommon->m_pMediaManager->m_strDstMedia); + } + void VbaProject::fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) + { + LONG _end_rec = pReader->GetPos() + pReader->GetLong() + 4; + + pReader->Skip(1); // start attributes + while (true) + { + BYTE _at = pReader->GetUChar_TypeNode(); + if (_at == NSBinPptxRW::g_nodeAttributeEnd) + break; + + switch (_at) + { + case 0: + { + std::wstring file_name = pReader->GetString2(); + + OOX::CPath inputPath = pReader->m_strFolder + FILE_SEPARATOR_STR + _T("media") + FILE_SEPARATOR_STR + file_name; + OOX::CPath outputPath = pReader->m_pRels->m_pManager->GetDstFolder() + FILE_SEPARATOR_STR + _T("vbaProject.bin"); + + NSFile::CFileBinary::Copy(inputPath.GetPath(), outputPath.GetPath()); + + set_filename(outputPath.GetPath(), false); + + }break; + + default: + break; + } + } + pReader->Seek(_end_rec); + } +} // namespace OOX diff --git a/Common/DocxFormat/Source/DocxFormat/Media/VbaProject.h b/Common/DocxFormat/Source/DocxFormat/Media/VbaProject.h index 067d62de11..2caa8f3238 100644 --- a/Common/DocxFormat/Source/DocxFormat/Media/VbaProject.h +++ b/Common/DocxFormat/Source/DocxFormat/Media/VbaProject.h @@ -33,7 +33,7 @@ #ifndef OOX_VBA_PROJECT_INCLUDE_H_ #define OOX_VBA_PROJECT_INCLUDE_H_ -#include "../Docx.h" + #include "Media.h" #include "../../../../../ASCOfficePPTXFile/Editor/BinaryFileReaderWriter.h" #include "../../../../../ASCOfficePPTXFile/Editor/imagemanager.h" @@ -46,29 +46,11 @@ namespace OOX class VbaProject : public Media, public OOX::IFileContainer { public: - VbaProject( OOX::Document *pMain ) : Media(pMain), OOX::IFileContainer(pMain) - { - CDocx* docx = dynamic_cast(File::m_pMainDocument); - if (docx) docx->m_pVbaProject = this; - } - VbaProject(OOX::Document *pMain, const CPath& oRootPath, const CPath& filename) : Media(pMain), OOX::IFileContainer(pMain) - { - CDocx* docx = dynamic_cast(File::m_pMainDocument); - if (docx) docx->m_pVbaProject = this; + VbaProject( OOX::Document *pMain ); + VbaProject(OOX::Document *pMain, const CPath& oRootPath, const CPath& filename); + virtual void read(const CPath& oRootPath, const CPath& oPath); + virtual void write(const OOX::CPath& filename, const OOX::CPath& directory, CContentTypes& content) const ; - read( oRootPath, filename ); - } - virtual void read(const CPath& oRootPath, const CPath& oPath) - { - IFileContainer::Read( oRootPath, oPath ); - - Media::read(oPath); - } - virtual void write(const OOX::CPath& filename, const OOX::CPath& directory, CContentTypes& content) const - { - content.Registration( type().OverrideType(), directory, filename.GetFilename() ); - IFileContainer::Write( filename, directory, content ); - } virtual const FileType type() const { return OOX::FileTypes::VbaProject; @@ -81,50 +63,8 @@ namespace OOX { return m_filename.GetFilename(); } - virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const - { - pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeStart); - - pWriter->WriteString1(0, m_filename.GetFilename()); - - pWriter->WriteBYTE(NSBinPptxRW::g_nodeAttributeEnd); - - copy_to(pWriter->m_pCommon->m_pMediaManager->m_strDstMedia); - } - virtual void fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader) - { - LONG _end_rec = pReader->GetPos() + pReader->GetLong() + 4; - - pReader->Skip(1); // start attributes - while (true) - { - BYTE _at = pReader->GetUChar_TypeNode(); - if (_at == NSBinPptxRW::g_nodeAttributeEnd) - break; - - switch (_at) - { - case 0: - { - std::wstring file_name = pReader->GetString2(); - - OOX::CPath inputPath = pReader->m_strFolder + FILE_SEPARATOR_STR + _T("media") + FILE_SEPARATOR_STR + file_name; - OOX::CPath outputPath = pReader->m_pRels->m_pManager->GetDstFolder() + FILE_SEPARATOR_STR + _T("vbaProject.bin"); - - NSFile::CFileBinary::Copy(inputPath.GetPath(), outputPath.GetPath()); - - set_filename(outputPath.GetPath(), false); - - }break; - - default: - break; - } - } - pReader->Seek(_end_rec); - } - - protected: + virtual void toPPTY(NSBinPptxRW::CBinaryFileWriter* pWriter) const; + virtual void fromPPTY(NSBinPptxRW::CBinaryFileReader* pReader); }; } // namespace OOX diff --git a/Common/DocxFormat/Source/XlsxFormat/Comments/Comments.h b/Common/DocxFormat/Source/XlsxFormat/Comments/Comments.h index 80ab719e2a..b7bbc2f653 100644 --- a/Common/DocxFormat/Source/XlsxFormat/Comments/Comments.h +++ b/Common/DocxFormat/Source/XlsxFormat/Comments/Comments.h @@ -33,13 +33,10 @@ #ifndef OOX_XLSXCOMMENTS_FILE_INCLUDE_H_ #define OOX_XLSXCOMMENTS_FILE_INCLUDE_H_ -#include "../CommonInclude.h" +#include "../Xlsx.h" +#include "../Worksheets/Worksheet.h" #include "../SharedStrings/Si.h" -#include "../../DocxFormat/IFileContainer.h" - -#include - namespace OOX { namespace Spreadsheet @@ -271,10 +268,22 @@ namespace OOX CComments(OOX::Document* pMain) : OOX::FileGlobalEnumerated(pMain), OOX::IFileContainer(pMain) { m_bSpreadsheets = true; + + CXlsx* xlsx = dynamic_cast(pMain); + if ((xlsx) && (!xlsx->m_arWorksheets.empty())) + { + xlsx->m_arWorksheets.back()->m_pComments = this; + } } CComments(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath) : OOX::FileGlobalEnumerated(pMain), OOX::IFileContainer(pMain) { m_bSpreadsheets = true; + + CXlsx* xlsx = dynamic_cast(pMain); + if ((xlsx) && (!xlsx->m_arWorksheets.empty())) + { + xlsx->m_arWorksheets.back()->m_pComments = this; + } read( oRootPath, oPath ); } virtual ~CComments() diff --git a/Common/DocxFormat/Source/XlsxFormat/FileFactory_Spreadsheet.cpp b/Common/DocxFormat/Source/XlsxFormat/FileFactory_Spreadsheet.cpp index 296fe265b4..b75fba6957 100644 --- a/Common/DocxFormat/Source/XlsxFormat/FileFactory_Spreadsheet.cpp +++ b/Common/DocxFormat/Source/XlsxFormat/FileFactory_Spreadsheet.cpp @@ -32,6 +32,7 @@ #include "CommonInclude.h" #include "FileTypes_Spreadsheet.h" +#include "Xlsx.h" #include "../../../../ASCOfficePPTXFile/PPTXFormat/Theme.h" #include "../DocxFormat/VmlDrawing.h" @@ -135,14 +136,21 @@ namespace OOX return smart_ptr(new CWorksheet( pMain, oRootPath, oFileName, pRelation->rId().ToString() )); else if ( pRelation->Type() == OOX::FileTypes::Theme ) { + smart_ptr pFile; if(NSFile::CFileBinary::Exists(oFileName.GetPath())) { - return smart_ptr(new PPTX::Theme( pMain, oFileName )); + pFile = smart_ptr(new PPTX::Theme( pMain, oFileName )); } else { - return smart_ptr( new UnknowTypeFile(pMain) ); + pFile = smart_ptr( new UnknowTypeFile(pMain) ); } + CXlsx* xlsx = dynamic_cast(pMain); + if (xlsx) + { + xlsx->m_pTheme = pFile.smart_dynamic_cast(); + } + return pFile; } else if ( pRelation->Type() == OOX::FileTypes::ThemeOverride ) return smart_ptr(new PPTX::Theme( pMain, oFileName )); diff --git a/Common/DocxFormat/Source/XlsxFormat/Workbook/Workbook.h b/Common/DocxFormat/Source/XlsxFormat/Workbook/Workbook.h index d45f48ee62..ed8a211ba6 100644 --- a/Common/DocxFormat/Source/XlsxFormat/Workbook/Workbook.h +++ b/Common/DocxFormat/Source/XlsxFormat/Workbook/Workbook.h @@ -70,7 +70,7 @@ namespace OOX m_bMacroEnabled = false; m_bSpreadsheets = true; - CXlsx* xlsx = dynamic_cast(File::m_pMainDocument); + CXlsx* xlsx = dynamic_cast(pMain); if ((xlsx) && (!xlsx->m_pWorkbook)) { xlsx->m_pWorkbook = this; @@ -103,7 +103,8 @@ namespace OOX m_oReadPath = oPath; IFileContainer::Read( oRootPath, oPath ); - if (IFileContainer::IsExist(OOX::FileTypes::VbaProject)) + CXlsx* xlsx = dynamic_cast(File::m_pMainDocument); + if ( (xlsx ) && (xlsx->m_pVbaProject) ) { m_bMacroEnabled = true; } @@ -235,6 +236,7 @@ namespace OOX nullable m_oWorkbookPr; nullable m_oExternalReferences; nullable m_oPivotCachesXml; + bool m_bMacroEnabled; }; } //Spreadsheet diff --git a/Common/DocxFormat/Source/XlsxFormat/WorkbookComments.h b/Common/DocxFormat/Source/XlsxFormat/WorkbookComments.h index bbbf976726..6f8148b2d6 100644 --- a/Common/DocxFormat/Source/XlsxFormat/WorkbookComments.h +++ b/Common/DocxFormat/Source/XlsxFormat/WorkbookComments.h @@ -34,6 +34,7 @@ #define OOX_ONLY_WORKBOOK_COMMENTS_INCLUDE_H_ #include "CommonInclude.h" +#include "Xlsx.h" namespace OOX { @@ -41,46 +42,54 @@ namespace OOX { class WorkbookComments : public OOX::File, public IFileContainer { - public: + public: WorkbookComments(OOX::Document* pMain) : OOX::File(pMain), OOX::IFileContainer(pMain) { - } + CXlsx* xlsx = dynamic_cast(pMain); + if (xlsx) + { + xlsx->m_pWorkbookComments = this; + } + } WorkbookComments(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath) : OOX::File(pMain), OOX::IFileContainer(pMain) { - read( oRootPath, oPath ); - } - virtual ~WorkbookComments() - { - } - virtual void read(const CPath& oPath) - { - //don't use this. use read(const CPath& oRootPath, const CPath& oFilePath) - CPath oRootPath; - read(oRootPath, oPath); - } - virtual void read(const CPath& oRootPath, const CPath& oPath) - { - m_oReadPath = oPath; - IFileContainer::Read( oRootPath, oPath ); - } - virtual void write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const - { - } - virtual const FileType type() const - { - return Spreadsheet::FileTypes::WorkbookComments; - } - virtual const CPath DefaultDirectory() const - { - return type().DefaultDirectory(); - } - virtual const CPath DefaultFileName() const - { - return type().DefaultFileName(); - } + CXlsx* xlsx = dynamic_cast(pMain); + if (xlsx) + { + xlsx->m_pWorkbookComments = this; + } + read( oRootPath, oPath ); + } + virtual ~WorkbookComments() + { + } + virtual void read(const CPath& oPath) + { + //don't use this. use read(const CPath& oRootPath, const CPath& oFilePath) + CPath oRootPath; + read(oRootPath, oPath); + } + virtual void read(const CPath& oRootPath, const CPath& oPath) + { + m_oReadPath = oPath; + IFileContainer::Read( oRootPath, oPath ); + } + virtual void write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const + { + } + virtual const FileType type() const + { + return Spreadsheet::FileTypes::WorkbookComments; + } + virtual const CPath DefaultDirectory() const + { + return type().DefaultDirectory(); + } + virtual const CPath DefaultFileName() const + { + return type().DefaultFileName(); + } - - public: CPath m_oReadPath; }; } diff --git a/Common/DocxFormat/Source/XlsxFormat/Worksheets/Worksheet.cpp b/Common/DocxFormat/Source/XlsxFormat/Worksheets/Worksheet.cpp new file mode 100644 index 0000000000..6b9e025748 --- /dev/null +++ b/Common/DocxFormat/Source/XlsxFormat/Worksheets/Worksheet.cpp @@ -0,0 +1,430 @@ +/* + * (c) Copyright Ascensio System SIA 2010-2017 + * + * This program is a free software product. You can redistribute it and/or + * modify it under the terms of the GNU Affero General Public License (AGPL) + * version 3 as published by the Free Software Foundation. In accordance with + * Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect + * that Ascensio System SIA expressly excludes the warranty of non-infringement + * of any third-party rights. + * + * This program is distributed WITHOUT ANY WARRANTY; without even the implied + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For + * details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html + * + * You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, + * EU, LV-1021. + * + * The interactive user interfaces in modified source and object code versions + * of the Program must display Appropriate Legal Notices, as required under + * Section 5 of the GNU AGPL version 3. + * + * Pursuant to Section 7(b) of the License you must retain the original Product + * logo when distributing the program. Pursuant to Section 7(e) we decline to + * grant you any rights under trademark law for use of our trademarks. + * + * All the Product's GUI elements, including illustrations and icon sets, as + * well as technical writing content are licensed under the terms of the + * Creative Commons Attribution-ShareAlike 4.0 International. See the License + * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + * + */ +#include "../Xlsx.h" +#include "Worksheet.h" + +#include "../Comments/Comments.h" + +#include "../../DocxFormat/External/HyperLink.h" +#include "../../DocxFormat/Media/Image.h" +#include "../../DocxFormat/VmlDrawing.h" + +namespace OOX +{ + namespace Spreadsheet + { + CWorksheet::CWorksheet(OOX::Document* pMain) : OOX::File(pMain), OOX::IFileContainer(pMain) + { + m_bSpreadsheets = true; + + m_pComments = NULL; + + CXlsx* xlsx = dynamic_cast(pMain); + if (xlsx) + { + m_bPrepareForBinaryWriter = true; // подготовка для бинарника при чтении + + xlsx->m_arWorksheets.push_back( this ); + //xlsx->m_mapWorksheets.insert( std::make_pair(rId, this) ); + } + else + m_bPrepareForBinaryWriter = false; + } + CWorksheet::CWorksheet(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath, const std::wstring & rId) : OOX::File(pMain), OOX::IFileContainer(pMain) + { + m_bSpreadsheets = true; + + m_pComments = NULL; + + CXlsx* xlsx = dynamic_cast(pMain); + if (xlsx) + { + m_bPrepareForBinaryWriter = true; + + xlsx->m_arWorksheets.push_back( this ); + xlsx->m_mapWorksheets.insert( std::make_pair(rId, this) ); + } + else + m_bPrepareForBinaryWriter = false; + + read( oRootPath, oPath ); + } + CWorksheet::~CWorksheet() + { + ClearItems(); + } + void CWorksheet::read(const CPath& oRootPath, const CPath& oPath) + { + m_oReadPath = oPath; + IFileContainer::Read( oRootPath, oPath ); + + XmlUtils::CXmlLiteReader oReader; + + if ( !oReader.FromFile( oPath.GetPath() ) ) + return; + + if ( !oReader.ReadNextNode() ) + return; + + std::wstring sName = XmlUtils::GetNameNoNS(oReader.GetName()); + if ( _T("worksheet") == sName || _T("chartsheet") == sName) + { + if ( !oReader.IsEmptyNode() ) + { + int nDocumentDepth = oReader.GetDepth(); + while ( oReader.ReadNextSiblingNode( nDocumentDepth ) ) + { + sName = XmlUtils::GetNameNoNS(oReader.GetName()); + + if ( _T("cols") == sName ) + m_oCols = oReader; + else if ( _T("dimension") == sName ) + m_oDimension = oReader; + else if ( _T("drawing") == sName ) + m_oDrawing = oReader; + else if ( _T("hyperlinks") == sName ) + m_oHyperlinks = oReader; + else if ( _T("mergeCells") == sName ) + m_oMergeCells = oReader; + else if ( _T("pageMargins") == sName ) + m_oPageMargins = oReader; + else if ( _T("pageSetup") == sName ) + m_oPageSetup = oReader; + else if ( _T("printOptions") == sName ) + m_oPrintOptions = oReader; + else if ( _T("sheetData") == sName ) + { + m_oSheetData.Init(); + m_oSheetData->m_pMainDocument = OOX::File::m_pMainDocument; //todooo передалать на неявное + m_oSheetData->fromXML(oReader); + } + else if (_T("conditionalFormatting") == sName) + m_arrConditionalFormatting.push_back(new CConditionalFormatting(oReader)); + else if ( _T("sheetFormatPr") == sName ) + m_oSheetFormatPr = oReader; + else if ( _T("sheetViews") == sName ) + m_oSheetViews = oReader; + else if ( _T("autoFilter") == sName ) + m_oAutofilter = oReader; + else if ( _T("tableParts") == sName ) + m_oTableParts = oReader; + else if ( _T("legacyDrawing") == sName ) + m_oLegacyDrawing = oReader; + else if ( _T("legacyDrawingHF") == sName ) + m_oLegacyDrawingHF = oReader; + else if ( _T("oleObjects") == sName ) + m_oOleObjects = oReader; + else if ( _T("controls") == sName ) + m_oControls = oReader; + else if ( _T("headerFooter") == sName ) + m_oHeaderFooter = oReader; + else if (_T("sheetPr") == sName) + m_oSheetPr = oReader; + else if (_T("extLst") == sName) + m_oExtLst = oReader; + else if (_T("picture") == sName) + m_oPicture = oReader; + } + } + if(m_oLegacyDrawing.IsInit() && m_oLegacyDrawing->m_oId.IsInit()) + { + OOX::RId oRId(m_oLegacyDrawing->m_oId->GetValue()); + + smart_ptr oVmlDrawing = IFileContainer::Find(oRId); + + if (m_pComments && oVmlDrawing.IsInit() && OOX::FileTypes::VmlDrawing == oVmlDrawing->type()) + { + OOX::CVmlDrawing* pVmlDrawing = static_cast(oVmlDrawing.operator->()); + + PrepareComments(m_pComments, pVmlDrawing); + } + } + if (m_oHeaderFooter.IsInit() && m_oLegacyDrawing.IsInit() && m_oLegacyDrawing.IsInit()) + { + } + } + } + + void CWorksheet::PrepareComments(OOX::Spreadsheet::CComments* pComments, OOX::CVmlDrawing* pVmlDrawing) + { + std::vector & arAuthors = pComments->m_oAuthors->m_arrItems; + + if(pComments->m_oCommentList.IsInit()) + { + std::vector & aComments = pComments->m_oCommentList->m_arrItems; + + for ( size_t i = 0; i < aComments.size(); ++i) + { + OOX::Spreadsheet::CComment* pComment = aComments[i]; + + if (!pComment) continue; + + if(pComment->m_oRef.IsInit() && pComment->m_oAuthorId.IsInit()) + { + int nRow, nCol; + if(CCell::parseRef(pComment->m_oRef->GetValue(), nRow, nCol)) + { + CCommentItem* pCommentItem = new CCommentItem(); + pCommentItem->m_nRow = nRow - 1; + pCommentItem->m_nCol = nCol - 1; + + unsigned int nAuthorId = pComment->m_oAuthorId->GetValue(); + + if (nAuthorId >= 0 && nAuthorId < arAuthors.size()) + { + pCommentItem->m_sAuthor = arAuthors[nAuthorId]; + } + + OOX::Spreadsheet::CSi* pSi = pComment->m_oText.GetPointerEmptyNullable(); + if(NULL != pSi) + pCommentItem->m_oText.reset(pSi); + std::wstring sNewId = std::to_wstring(pCommentItem->m_nRow.get()) + L"-" + std::to_wstring(pCommentItem->m_nCol.get()); + m_mapComments [sNewId] = pCommentItem; + } + } + } + } + + for ( size_t i = 0; i < pVmlDrawing->m_arrItems.size(); ++i) + { + OOX::Vml::CShape* pShape = dynamic_cast(pVmlDrawing->m_arrItems[i]); + + if (pShape == NULL) continue; + + if (pShape->m_sId.IsInit()) + {//mark shape as used + boost::unordered_map::iterator pFind = pVmlDrawing->m_mapShapes.find(pShape->m_sId.get()); + if (pFind != pVmlDrawing->m_mapShapes.end()) + { + pFind->second.bUsed = true; + } + } + for ( size_t j = 0; j < pShape->m_arrItems.size(); ++j) + { + OOX::WritingElement* pElem = pShape->m_arrItems[j]; + + if ( !pElem ) continue; + + if( OOX::et_v_ClientData == pElem->getType()) + { + OOX::Vml::CClientData* pClientData = static_cast(pElem); + if(pClientData->m_oRow.IsInit() && pClientData->m_oColumn.IsInit()) + { + int nRow = pClientData->m_oRow->GetValue(); + int nCol = pClientData->m_oColumn->GetValue(); + std::wstring sId = std::to_wstring(nRow) + L"-" + std::to_wstring(nCol); + + boost::unordered_map::const_iterator pPair = m_mapComments.find(sId); + if(pPair != m_mapComments.end()) + { + CCommentItem* pCommentItem = pPair->second; + if(pShape->m_sGfxData.IsInit()) + pCommentItem->m_sGfxdata = pShape->m_sGfxData.get2(); + std::vector m_aAnchor; + pClientData->getAnchorArray(m_aAnchor); + if(8 == m_aAnchor.size()) + { + pCommentItem->m_nLeft = m_aAnchor[0]; + pCommentItem->m_nLeftOffset = m_aAnchor[1]; + pCommentItem->m_nTop = m_aAnchor[2]; + pCommentItem->m_nTopOffset = m_aAnchor[3]; + pCommentItem->m_nRight = m_aAnchor[4]; + pCommentItem->m_nRightOffset = m_aAnchor[5]; + pCommentItem->m_nBottom = m_aAnchor[6]; + pCommentItem->m_nBottomOffset = m_aAnchor[7]; + } + + if(pClientData->m_oMoveWithCells.IsInit()) + pCommentItem->m_bMove = pClientData->m_oMoveWithCells->ToBool(); + if(pClientData->m_oSizeWithCells.IsInit()) + pCommentItem->m_bSize = pClientData->m_oSizeWithCells->ToBool(); + + for(size_t k = 0 ,length3 = pShape->m_oStyle->m_arrProperties.size(); k < length3; ++k) + { + if (pShape->m_oStyle->m_arrProperties[k] == NULL) continue; + + SimpleTypes::Vml::CCssProperty *oProperty = pShape->m_oStyle->m_arrProperties[k].get(); + if(SimpleTypes::Vml::cssptMarginLeft == oProperty->get_Type()) + { + SimpleTypes::Vml::UCssValue oUCssValue= oProperty->get_Value(); + if(SimpleTypes::Vml::cssunitstypeUnits == oUCssValue.oValue.eType) + { + SimpleTypes::CPoint oPoint; + oPoint.FromPoints(oUCssValue.oValue.dValue); + pCommentItem->m_dLeftMM = oPoint.ToMm(); + } + } + else if(SimpleTypes::Vml::cssptMarginTop == oProperty->get_Type()) + { + SimpleTypes::Vml::UCssValue oUCssValue= oProperty->get_Value(); + if(SimpleTypes::Vml::cssunitstypeUnits == oUCssValue.oValue.eType) + { + SimpleTypes::CPoint oPoint; + oPoint.FromPoints(oUCssValue.oValue.dValue); + pCommentItem->m_dTopMM = oPoint.ToMm(); + } + } + else if(SimpleTypes::Vml::cssptWidth == oProperty->get_Type()) + { + SimpleTypes::Vml::UCssValue oUCssValue= oProperty->get_Value(); + if(SimpleTypes::Vml::cssunitstypeUnits == oUCssValue.oValue.eType) + { + SimpleTypes::CPoint oPoint; + oPoint.FromPoints(oUCssValue.oValue.dValue); + pCommentItem->m_dWidthMM = oPoint.ToMm(); + } + } + else if(SimpleTypes::Vml::cssptHeight == oProperty->get_Type()) + { + SimpleTypes::Vml::UCssValue oUCssValue= oProperty->get_Value(); + if(SimpleTypes::Vml::cssunitstypeUnits == oUCssValue.oValue.eType) + { + SimpleTypes::CPoint oPoint; + oPoint.FromPoints(oUCssValue.oValue.dValue); + pCommentItem->m_dHeightMM = oPoint.ToMm(); + } + } + } + } + } + } + } + } + } + void CWorksheet::PrepareToWrite() + { + if(false == m_oSheetFormatPr.IsInit()) + m_oSheetFormatPr.Init(); + if(false == m_oSheetFormatPr->m_oDefaultRowHeight.IsInit()) + { + m_oSheetFormatPr->m_oDefaultRowHeight.Init(); + m_oSheetFormatPr->m_oDefaultRowHeight->SetValue(15); + } + if(false == m_oSheetViews.IsInit()) + m_oSheetViews.Init(); + + if(m_oSheetViews->m_arrItems.empty()) + m_oSheetViews->m_arrItems.push_back(new CSheetView()); + + CSheetView* pSheetView = m_oSheetViews->m_arrItems.front(); + + if(false == pSheetView->m_oWorkbookViewId.IsInit()) + { + pSheetView->m_oWorkbookViewId.Init(); + pSheetView->m_oWorkbookViewId->SetValue(0); + } + } + void CWorksheet::write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const + { + NSStringUtils::CStringBuilder sXml; + sXml.WriteString(_T("")); + if(m_oSheetPr.IsInit()) + m_oSheetPr->toXML(sXml); + if(m_oSheetViews.IsInit()) + m_oSheetViews->toXML(sXml); + if(m_oSheetFormatPr.IsInit()) + m_oSheetFormatPr->toXML(sXml); + if(m_oCols.IsInit()) + m_oCols->toXML(sXml); + if(m_oSheetData.IsInit()) + m_oSheetData->toXML(sXml); + if(m_oAutofilter.IsInit()) + m_oAutofilter->toXML(sXml); + if(m_oMergeCells.IsInit()) + m_oMergeCells->toXML(sXml); + for (size_t nIndex = 0, nLength = m_arrConditionalFormatting.size(); nIndex < nLength; ++nIndex) + m_arrConditionalFormatting[nIndex]->toXML(sXml); + if(m_oHyperlinks.IsInit()) + m_oHyperlinks->toXML(sXml); + if(m_oPrintOptions.IsInit()) + m_oPrintOptions->toXML(sXml); + if(m_oPageMargins.IsInit()) + m_oPageMargins->toXML(sXml); + if(m_oPageSetup.IsInit()) + m_oPageSetup->toXML(sXml); + if(m_oDrawing.IsInit()) + m_oDrawing->toXML(sXml); + if(m_oLegacyDrawing.IsInit()) + m_oLegacyDrawing->toXML(sXml); + if(m_oLegacyDrawingHF.IsInit()) + m_oLegacyDrawingHF->toXML(sXml); + if(m_oOleObjects.IsInit()) + m_oOleObjects->toXML(sXml); + if (m_oControls.IsInit()) + m_oControls->toXML(sXml); + if(m_oTableParts.IsInit()) + m_oTableParts->toXML(sXml); + if(m_oExtLst.IsInit()) + { + sXml.WriteString(m_oExtLst->toXMLWithNS(_T(""))); + } + sXml.WriteString(_T("")); + + NSFile::CFileBinary::SaveToFile(oPath.GetPath(), sXml.GetData()); + + oContent.Registration( type().OverrideType(), oDirectory, oPath.GetFilename() ); + IFileContainer::Write( oPath, oDirectory, oContent ); + } + + const OOX::RId CWorksheet::AddHyperlink (std::wstring& sHref) + { + std::wstring sExistRId = IsExistHyperlink(sHref); + if(sExistRId.empty()) + { + smart_ptr oHyperlinkFile = smart_ptr( new OOX::HyperLink( File::m_pMainDocument, OOX::CPath(sHref, false) ) ); + const OOX::RId rId = Add( oHyperlinkFile ); + return rId; + } + else + { + const OOX::RId rId(sExistRId); + return rId; + } + } + void CWorksheet::ClearItems() + { + for (boost::unordered_map::const_iterator it = m_mapComments.begin(); it != m_mapComments.end(); ++it) + { + delete it->second; + } + + m_mapComments.clear(); + + // delete Conditional Formatting + for (size_t nIndex = 0, nLength = m_arrConditionalFormatting.size(); nIndex < nLength; ++nIndex) + { + delete m_arrConditionalFormatting[nIndex]; + } + m_arrConditionalFormatting.clear(); + } + } +} \ No newline at end of file diff --git a/Common/DocxFormat/Source/XlsxFormat/Worksheets/Worksheet.h b/Common/DocxFormat/Source/XlsxFormat/Worksheets/Worksheet.h index 9a8bc6ae63..51aebab120 100644 --- a/Common/DocxFormat/Source/XlsxFormat/Worksheets/Worksheet.h +++ b/Common/DocxFormat/Source/XlsxFormat/Worksheets/Worksheet.h @@ -35,10 +35,6 @@ #include "../CommonInclude.h" -#include "../../DocxFormat/External/HyperLink.h" -#include "../../DocxFormat/Media/Image.h" -#include "../../DocxFormat/VmlDrawing.h" - #include "SheetData.h" #include "Cols.h" #include "Hyperlinks.h" @@ -49,16 +45,18 @@ #include "../Drawing/Drawing.h" #include "../Chart/Chart.h" #include "../Table/Table.h" -#include "../Comments/Comments.h" #include "../Ole/OleObjects.h" #include "../Controls/Controls.h" -#include "../../../../../DesktopEditor/common/String.h" - namespace OOX { + class CVmlDrawing; + namespace Spreadsheet { + class CComments; + class CCommentItem; + class CLegacyDrawingWorksheet; //необработанные child: // // @@ -79,361 +77,19 @@ namespace OOX class CWorksheet : public OOX::File, public OOX::IFileContainer { public: - CWorksheet(OOX::Document* pMain) : OOX::File(pMain), OOX::IFileContainer(pMain) - { - m_bSpreadsheets = true; - - CXlsx* xlsx = dynamic_cast(File::m_pMainDocument); - if (xlsx) - { - m_bPrepareForBinaryWriter = true; // подготовка для бинарника при чтении - - xlsx->m_arWorksheets.push_back( this ); - //xlsx->m_mapWorksheets.insert( std::make_pair(rId, this) ); - } - else - m_bPrepareForBinaryWriter = false; - } - CWorksheet(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath, const std::wstring & rId) : OOX::File(pMain), OOX::IFileContainer(pMain) - { - m_bSpreadsheets = true; - - CXlsx* xlsx = dynamic_cast(File::m_pMainDocument); - if (xlsx) - { - m_bPrepareForBinaryWriter = true; - - xlsx->m_arWorksheets.push_back( this ); - xlsx->m_mapWorksheets.insert( std::make_pair(rId, this) ); - } - else - m_bPrepareForBinaryWriter = false; - - read( oRootPath, oPath ); - } - virtual ~CWorksheet() - { - ClearItems(); - } + CWorksheet(OOX::Document* pMain); + CWorksheet(OOX::Document* pMain, const CPath& oRootPath, const CPath& oPath, const std::wstring & rId); + virtual ~CWorksheet(); virtual void read(const CPath& oPath) { //don't use this. instead use read(const CPath& oRootPath, const CPath& oFilePath) CPath oRootPath; read(oRootPath, oPath); } - virtual void read(const CPath& oRootPath, const CPath& oPath) - { - m_oReadPath = oPath; - IFileContainer::Read( oRootPath, oPath ); - - XmlUtils::CXmlLiteReader oReader; - - if ( !oReader.FromFile( oPath.GetPath() ) ) - return; - - if ( !oReader.ReadNextNode() ) - return; - - std::wstring sName = XmlUtils::GetNameNoNS(oReader.GetName()); - if ( _T("worksheet") == sName || _T("chartsheet") == sName) - { - if ( !oReader.IsEmptyNode() ) - { - int nDocumentDepth = oReader.GetDepth(); - while ( oReader.ReadNextSiblingNode( nDocumentDepth ) ) - { - sName = XmlUtils::GetNameNoNS(oReader.GetName()); - - if ( _T("cols") == sName ) - m_oCols = oReader; - else if ( _T("dimension") == sName ) - m_oDimension = oReader; - else if ( _T("drawing") == sName ) - m_oDrawing = oReader; - else if ( _T("hyperlinks") == sName ) - m_oHyperlinks = oReader; - else if ( _T("mergeCells") == sName ) - m_oMergeCells = oReader; - else if ( _T("pageMargins") == sName ) - m_oPageMargins = oReader; - else if ( _T("pageSetup") == sName ) - m_oPageSetup = oReader; - else if ( _T("printOptions") == sName ) - m_oPrintOptions = oReader; - else if ( _T("sheetData") == sName ) - { - m_oSheetData.Init(); - m_oSheetData->m_pMainDocument = OOX::File::m_pMainDocument; //todooo передалать на неявное - m_oSheetData->fromXML(oReader); - } - else if (_T("conditionalFormatting") == sName) - m_arrConditionalFormatting.push_back(new CConditionalFormatting(oReader)); - else if ( _T("sheetFormatPr") == sName ) - m_oSheetFormatPr = oReader; - else if ( _T("sheetViews") == sName ) - m_oSheetViews = oReader; - else if ( _T("autoFilter") == sName ) - m_oAutofilter = oReader; - else if ( _T("tableParts") == sName ) - m_oTableParts = oReader; - else if ( _T("legacyDrawing") == sName ) - m_oLegacyDrawing = oReader; - else if ( _T("legacyDrawingHF") == sName ) - m_oLegacyDrawingHF = oReader; - else if ( _T("oleObjects") == sName ) - m_oOleObjects = oReader; - else if ( _T("controls") == sName ) - m_oControls = oReader; - else if ( _T("headerFooter") == sName ) - m_oHeaderFooter = oReader; - else if (_T("sheetPr") == sName) - m_oSheetPr = oReader; - else if (_T("extLst") == sName) - m_oExtLst = oReader; - else if (_T("picture") == sName) - m_oPicture = oReader; - } - } - if(m_oLegacyDrawing.IsInit() && m_oLegacyDrawing->m_oId.IsInit()) - { - OOX::RId oRId(m_oLegacyDrawing->m_oId->GetValue()); - - smart_ptr oVmlDrawing = IFileContainer::Find(oRId); - smart_ptr oComments = IFileContainer::Get(FileTypes::Comments); - - if (oComments.IsInit() && FileTypes::Comments == oComments->type() && oVmlDrawing.IsInit() && OOX::FileTypes::VmlDrawing == oVmlDrawing->type()) - { - OOX::Spreadsheet::CComments* pComments = static_cast(oComments.operator->()); - OOX::CVmlDrawing* pVmlDrawing = static_cast(oVmlDrawing.operator->()); - - PrepareComments(pComments, pVmlDrawing); - } - } - if (m_oHeaderFooter.IsInit() && m_oLegacyDrawing.IsInit() && m_oLegacyDrawing.IsInit()) - { - } - } - } - void PrepareComments(OOX::Spreadsheet::CComments* pComments, OOX::CVmlDrawing* pVmlDrawing) - { - std::vector & arAuthors = pComments->m_oAuthors->m_arrItems; - - if(pComments->m_oCommentList.IsInit()) - { - std::vector & aComments = pComments->m_oCommentList->m_arrItems; - - for ( size_t i = 0; i < aComments.size(); ++i) - { - OOX::Spreadsheet::CComment* pComment = aComments[i]; - - if (!pComment) continue; - - if(pComment->m_oRef.IsInit() && pComment->m_oAuthorId.IsInit()) - { - int nRow, nCol; - if(CCell::parseRef(pComment->m_oRef->GetValue(), nRow, nCol)) - { - CCommentItem* pCommentItem = new CCommentItem(); - pCommentItem->m_nRow = nRow - 1; - pCommentItem->m_nCol = nCol - 1; - - unsigned int nAuthorId = pComment->m_oAuthorId->GetValue(); - - if (nAuthorId >= 0 && nAuthorId < arAuthors.size()) - { - pCommentItem->m_sAuthor = arAuthors[nAuthorId]; - } - - OOX::Spreadsheet::CSi* pSi = pComment->m_oText.GetPointerEmptyNullable(); - if(NULL != pSi) - pCommentItem->m_oText.reset(pSi); - std::wstring sNewId = std::to_wstring(pCommentItem->m_nRow.get()) + L"-" + std::to_wstring(pCommentItem->m_nCol.get()); - m_mapComments [sNewId] = pCommentItem; - } - } - } - } - - for ( size_t i = 0; i < pVmlDrawing->m_arrItems.size(); ++i) - { - OOX::Vml::CShape* pShape = dynamic_cast(pVmlDrawing->m_arrItems[i]); - - if (pShape == NULL) continue; - - if (pShape->m_sId.IsInit()) - {//mark shape as used - boost::unordered_map::iterator pFind = pVmlDrawing->m_mapShapes.find(pShape->m_sId.get()); - if (pFind != pVmlDrawing->m_mapShapes.end()) - { - pFind->second.bUsed = true; - } - } - for ( size_t j = 0; j < pShape->m_arrItems.size(); ++j) - { - OOX::WritingElement* pElem = pShape->m_arrItems[j]; - - if ( !pElem ) continue; - - if( OOX::et_v_ClientData == pElem->getType()) - { - OOX::Vml::CClientData* pClientData = static_cast(pElem); - if(pClientData->m_oRow.IsInit() && pClientData->m_oColumn.IsInit()) - { - int nRow = pClientData->m_oRow->GetValue(); - int nCol = pClientData->m_oColumn->GetValue(); - std::wstring sId = std::to_wstring(nRow) + L"-" + std::to_wstring(nCol); - - boost::unordered_map::const_iterator pPair = m_mapComments.find(sId); - if(pPair != m_mapComments.end()) - { - CCommentItem* pCommentItem = pPair->second; - if(pShape->m_sGfxData.IsInit()) - pCommentItem->m_sGfxdata = pShape->m_sGfxData.get2(); - std::vector m_aAnchor; - pClientData->getAnchorArray(m_aAnchor); - if(8 == m_aAnchor.size()) - { - pCommentItem->m_nLeft = m_aAnchor[0]; - pCommentItem->m_nLeftOffset = m_aAnchor[1]; - pCommentItem->m_nTop = m_aAnchor[2]; - pCommentItem->m_nTopOffset = m_aAnchor[3]; - pCommentItem->m_nRight = m_aAnchor[4]; - pCommentItem->m_nRightOffset = m_aAnchor[5]; - pCommentItem->m_nBottom = m_aAnchor[6]; - pCommentItem->m_nBottomOffset = m_aAnchor[7]; - } - - if(pClientData->m_oMoveWithCells.IsInit()) - pCommentItem->m_bMove = pClientData->m_oMoveWithCells->ToBool(); - if(pClientData->m_oSizeWithCells.IsInit()) - pCommentItem->m_bSize = pClientData->m_oSizeWithCells->ToBool(); - - for(size_t k = 0 ,length3 = pShape->m_oStyle->m_arrProperties.size(); k < length3; ++k) - { - if (pShape->m_oStyle->m_arrProperties[k] == NULL) continue; - - SimpleTypes::Vml::CCssProperty *oProperty = pShape->m_oStyle->m_arrProperties[k].get(); - if(SimpleTypes::Vml::cssptMarginLeft == oProperty->get_Type()) - { - SimpleTypes::Vml::UCssValue oUCssValue= oProperty->get_Value(); - if(SimpleTypes::Vml::cssunitstypeUnits == oUCssValue.oValue.eType) - { - SimpleTypes::CPoint oPoint; - oPoint.FromPoints(oUCssValue.oValue.dValue); - pCommentItem->m_dLeftMM = oPoint.ToMm(); - } - } - else if(SimpleTypes::Vml::cssptMarginTop == oProperty->get_Type()) - { - SimpleTypes::Vml::UCssValue oUCssValue= oProperty->get_Value(); - if(SimpleTypes::Vml::cssunitstypeUnits == oUCssValue.oValue.eType) - { - SimpleTypes::CPoint oPoint; - oPoint.FromPoints(oUCssValue.oValue.dValue); - pCommentItem->m_dTopMM = oPoint.ToMm(); - } - } - else if(SimpleTypes::Vml::cssptWidth == oProperty->get_Type()) - { - SimpleTypes::Vml::UCssValue oUCssValue= oProperty->get_Value(); - if(SimpleTypes::Vml::cssunitstypeUnits == oUCssValue.oValue.eType) - { - SimpleTypes::CPoint oPoint; - oPoint.FromPoints(oUCssValue.oValue.dValue); - pCommentItem->m_dWidthMM = oPoint.ToMm(); - } - } - else if(SimpleTypes::Vml::cssptHeight == oProperty->get_Type()) - { - SimpleTypes::Vml::UCssValue oUCssValue= oProperty->get_Value(); - if(SimpleTypes::Vml::cssunitstypeUnits == oUCssValue.oValue.eType) - { - SimpleTypes::CPoint oPoint; - oPoint.FromPoints(oUCssValue.oValue.dValue); - pCommentItem->m_dHeightMM = oPoint.ToMm(); - } - } - } - } - } - } - } - } - } - void PrepareToWrite() - { - if(false == m_oSheetFormatPr.IsInit()) - m_oSheetFormatPr.Init(); - if(false == m_oSheetFormatPr->m_oDefaultRowHeight.IsInit()) - { - m_oSheetFormatPr->m_oDefaultRowHeight.Init(); - m_oSheetFormatPr->m_oDefaultRowHeight->SetValue(15); - } - if(false == m_oSheetViews.IsInit()) - m_oSheetViews.Init(); - - if(m_oSheetViews->m_arrItems.empty()) - m_oSheetViews->m_arrItems.push_back(new CSheetView()); - - CSheetView* pSheetView = m_oSheetViews->m_arrItems.front(); - - if(false == pSheetView->m_oWorkbookViewId.IsInit()) - { - pSheetView->m_oWorkbookViewId.Init(); - pSheetView->m_oWorkbookViewId->SetValue(0); - } - } - virtual void write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const - { - NSStringUtils::CStringBuilder sXml; - sXml.WriteString(_T("")); - if(m_oSheetPr.IsInit()) - m_oSheetPr->toXML(sXml); - if(m_oSheetViews.IsInit()) - m_oSheetViews->toXML(sXml); - if(m_oSheetFormatPr.IsInit()) - m_oSheetFormatPr->toXML(sXml); - if(m_oCols.IsInit()) - m_oCols->toXML(sXml); - if(m_oSheetData.IsInit()) - m_oSheetData->toXML(sXml); - if(m_oAutofilter.IsInit()) - m_oAutofilter->toXML(sXml); - if(m_oMergeCells.IsInit()) - m_oMergeCells->toXML(sXml); - for (size_t nIndex = 0, nLength = m_arrConditionalFormatting.size(); nIndex < nLength; ++nIndex) - m_arrConditionalFormatting[nIndex]->toXML(sXml); - if(m_oHyperlinks.IsInit()) - m_oHyperlinks->toXML(sXml); - if(m_oPrintOptions.IsInit()) - m_oPrintOptions->toXML(sXml); - if(m_oPageMargins.IsInit()) - m_oPageMargins->toXML(sXml); - if(m_oPageSetup.IsInit()) - m_oPageSetup->toXML(sXml); - if(m_oDrawing.IsInit()) - m_oDrawing->toXML(sXml); - if(m_oLegacyDrawing.IsInit()) - m_oLegacyDrawing->toXML(sXml); - if(m_oLegacyDrawingHF.IsInit()) - m_oLegacyDrawingHF->toXML(sXml); - if(m_oOleObjects.IsInit()) - m_oOleObjects->toXML(sXml); - if (m_oControls.IsInit()) - m_oControls->toXML(sXml); - if(m_oTableParts.IsInit()) - m_oTableParts->toXML(sXml); - if(m_oExtLst.IsInit()) - { - sXml.WriteString(m_oExtLst->toXMLWithNS(_T(""))); - } - sXml.WriteString(_T("")); - - NSFile::CFileBinary::SaveToFile(oPath.GetPath(), sXml.GetData()); - - oContent.Registration( type().OverrideType(), oDirectory, oPath.GetFilename() ); - IFileContainer::Write( oPath, oDirectory, oContent ); - } + virtual void read(const CPath& oRootPath, const CPath& oPath); + void PrepareComments(OOX::Spreadsheet::CComments* pComments, OOX::CVmlDrawing* pVmlDrawing); + void PrepareToWrite(); + virtual void write(const CPath& oPath, const CPath& oDirectory, CContentTypes& oContent) const; virtual const OOX::FileType type() const { return OOX::Spreadsheet::FileTypes::Worksheet; @@ -450,38 +106,8 @@ namespace OOX { return m_oReadPath; } - const OOX::RId AddHyperlink (std::wstring& sHref) - { - smart_ptr oHyperlink = smart_ptr( new OOX::HyperLink( File::m_pMainDocument, OOX::CPath(sHref, false) ) ); - std::wstring sExistRId = IsExistHyperlink(oHyperlink); - if(sExistRId.empty()) - { - smart_ptr oHyperlinkFile = oHyperlink.smart_dynamic_cast(); - const OOX::RId rId = Add( oHyperlinkFile ); - return rId; - } - else - { - const OOX::RId rId(sExistRId); - return rId; - } - } - void ClearItems() - { - for (boost::unordered_map::const_iterator it = m_mapComments.begin(); it != m_mapComments.end(); ++it) - { - delete it->second; - } - - m_mapComments.clear(); - - // delete Conditional Formatting - for (size_t nIndex = 0, nLength = m_arrConditionalFormatting.size(); nIndex < nLength; ++nIndex) - { - delete m_arrConditionalFormatting[nIndex]; - } - m_arrConditionalFormatting.clear(); - } + const OOX::RId AddHyperlink (std::wstring& sHref); + void ClearItems(); CPath m_oReadPath; public: @@ -511,6 +137,9 @@ namespace OOX nullable m_oPicture; nullable m_oExtLst; + +//-------------------------------------------------------------------------------------------- + CComments *m_pComments; }; } //Spreadsheet } // namespace OOX diff --git a/Common/DocxFormat/Source/XlsxFormat/Xlsx.cpp b/Common/DocxFormat/Source/XlsxFormat/Xlsx.cpp index fa683ef90e..e04fd606f1 100644 --- a/Common/DocxFormat/Source/XlsxFormat/Xlsx.cpp +++ b/Common/DocxFormat/Source/XlsxFormat/Xlsx.cpp @@ -47,7 +47,12 @@ OOX::Spreadsheet::CXlsx::~CXlsx() { - for (size_t i = 0; i < m_arWorksheets.size(); ++i) + if(bDeleteWorkbook) RELEASEOBJECT(m_pWorkbook); + if(bDeleteSharedStrings) RELEASEOBJECT(m_pSharedStrings); + if(bDeleteStyles) RELEASEOBJECT(m_pStyles); + if(bDeleteCalcChain) RELEASEOBJECT(m_pCalcChain); + + for (size_t i = 0; i < m_arWorksheets.size(); ++i) { if (bDeleteWorksheets && m_arWorksheets[i]) { @@ -66,8 +71,8 @@ bool OOX::Spreadsheet::CXlsx::Read(const CPath& oFilePath) if (!m_pWorkbook) return false; //Theme - smart_ptr pFile = m_pWorkbook->Find(OOX::FileTypes::Theme); - m_pTheme = pFile.smart_dynamic_cast(); + //smart_ptr pFile = m_pWorkbook->Find(OOX::FileTypes::Theme); + //m_pTheme = pFile.smart_dynamic_cast(); for (size_t i = 0; i < m_arWorksheets.size(); i++) { diff --git a/Common/DocxFormat/Source/XlsxFormat/Xlsx.h b/Common/DocxFormat/Source/XlsxFormat/Xlsx.h index ec89fb9277..6acabb6c8e 100644 --- a/Common/DocxFormat/Source/XlsxFormat/Xlsx.h +++ b/Common/DocxFormat/Source/XlsxFormat/Xlsx.h @@ -49,6 +49,7 @@ namespace OOX class CSharedStrings; class CStyles; class CCalcChain; + class WorkbookComments; class CXlsx : public OOX::Document, public OOX::IFileContainer { @@ -82,12 +83,16 @@ namespace OOX { return (PPTX::Theme *)(m_pTheme.operator->()); } + smart_ptr m_pTheme; CWorkbook* m_pWorkbook; CSharedStrings* m_pSharedStrings; CStyles* m_pStyles; CCalcChain* m_pCalcChain; - smart_ptr m_pTheme; + OOX::VbaProject* m_pVbaProject; + OOX::JsaProject* m_pJsaProject; + + WorkbookComments* m_pWorkbookComments; std::vector m_arWorksheets; //order as is std::map m_mapWorksheets; //copy, for fast find - order by rId(name) @@ -101,12 +106,16 @@ namespace OOX m_pSharedStrings = NULL; m_pStyles = NULL; m_pCalcChain = NULL; + m_pVbaProject = NULL; + m_pJsaProject = NULL; bDeleteWorkbook = false; bDeleteSharedStrings = false; bDeleteStyles = false; bDeleteCalcChain = false; bDeleteWorksheets = false; + bDeleteVbaProject = false; + bDeleteJsaProject = false; } boost::unordered_map m_mapXlsxEnumeratedGlobal; @@ -116,6 +125,8 @@ namespace OOX bool bDeleteStyles; bool bDeleteCalcChain; bool bDeleteWorksheets; + bool bDeleteVbaProject; + bool bDeleteJsaProject; }; } //Spreadsheet diff --git a/Common/base.pri b/Common/base.pri index 4958b2a52a..36a636d733 100644 --- a/Common/base.pri +++ b/Common/base.pri @@ -1,4 +1,4 @@ -VERSION = 2.4.511.0 +VERSION = 2.4.512.0 DEFINES += INTVER=$$VERSION # CONFIGURATION diff --git a/DesktopEditor/agg-2.4/agg_vs2005.vcproj b/DesktopEditor/agg-2.4/agg_vs2005.vcproj index 05288881d0..2d9e043d26 100644 --- a/DesktopEditor/agg-2.4/agg_vs2005.vcproj +++ b/DesktopEditor/agg-2.4/agg_vs2005.vcproj @@ -62,6 +62,7 @@ WarningLevel="3" SuppressStartupBanner="true" DebugInformationFormat="4" + DisableSpecificWarnings="4005;4311;4312" /> & oArray, int nFlag) BYTE* pDataFontFile = new BYTE[nMaxFontSize]; - for (int nIndex = 0; nIndex < nCount; ++nIndex) + for (size_t nIndex = 0; nIndex < nCount; ++nIndex) { if ((nFlag & 2) != 0) { diff --git a/DesktopEditor/fontengine/font_engine_vs2005.vcproj b/DesktopEditor/fontengine/font_engine_vs2005.vcproj index 2c49fe57a9..57604eb6ad 100644 --- a/DesktopEditor/fontengine/font_engine_vs2005.vcproj +++ b/DesktopEditor/fontengine/font_engine_vs2005.vcproj @@ -207,6 +207,7 @@ WarningLevel="3" SuppressStartupBanner="true" DebugInformationFormat="4" + DisableSpecificWarnings="4005;4311;4312" /> fileVbaProject = workbook.Get(OOX::FileTypes::VbaProject); - if (fileVbaProject.IsInit() && OOX::FileTypes::VbaProject == fileVbaProject->type()) + //Write VbaProject + if (NULL != m_oXlsx.m_pVbaProject) { nCurPos = m_oBcw.WriteItemStart(c_oSerWorkbookTypes::VbaProject); - smart_ptr vbaProject = fileVbaProject.smart_dynamic_cast(); - - m_oBcw.m_oStream.StartRecord(0); - vbaProject->toPPTY(&m_oBcw.m_oStream); + m_oBcw.m_oStream.StartRecord(0); + m_oXlsx.m_pVbaProject->toPPTY(&m_oBcw.m_oStream); m_oBcw.m_oStream.EndRecord(); m_oBcw.WriteItemWithLengthEnd(nCurPos); } - //Write JsaProject - smart_ptr fileJsaProject = workbook.Get(OOX::FileTypes::JsaProject); - if (fileJsaProject.IsInit() && OOX::FileTypes::JsaProject == fileJsaProject->type()) + //Write JsaProject + if (NULL != m_oXlsx.m_pJsaProject) { - smart_ptr jsaProject = fileJsaProject.smart_dynamic_cast(); BYTE* pData = NULL; DWORD nBytesCount; - if(NSFile::CFileBinary::ReadAllBytes(jsaProject->filename().GetPath(), &pData, nBytesCount)) + if(NSFile::CFileBinary::ReadAllBytes(m_oXlsx.m_pJsaProject->filename().GetPath(), &pData, nBytesCount)) { nCurPos = m_oBcw.WriteItemStart(c_oSerWorkbookTypes::JsaProject); m_oBcw.m_oStream.WriteBYTEArray(pData, nBytesCount); m_oBcw.WriteItemWithLengthEnd(nCurPos); } } - //Workbook Comments - smart_ptr fileWorkbookComments = workbook.Get(OOX::Spreadsheet::FileTypes::WorkbookComments); - if (fileWorkbookComments.IsInit() && OOX::Spreadsheet::FileTypes::WorkbookComments == fileWorkbookComments->type()) + //Workbook Comments + if (NULL != m_oXlsx.m_pWorkbookComments) { - smart_ptr workbookComments = fileWorkbookComments.smart_dynamic_cast(); BYTE* pData = NULL; DWORD nBytesCount; - if(NSFile::CFileBinary::ReadAllBytes(workbookComments->m_oReadPath.GetPath(), &pData, nBytesCount)) + if(NSFile::CFileBinary::ReadAllBytes(m_oXlsx.m_pWorkbookComments->m_oReadPath.GetPath(), &pData, nBytesCount)) { nCurPos = m_oBcw.WriteItemStart(c_oSerWorkbookTypes::Comments); m_oBcw.m_oStream.WriteBYTEArray(pData, nBytesCount); @@ -1568,14 +1565,14 @@ namespace BinXlsxRW } void WriteWorkbookPr(const OOX::Spreadsheet::CWorkbookPr& workbookPr) { - //Date1904 + //Date1904 if(workbookPr.m_oDate1904.IsInit()) { m_oBcw.m_oStream.WriteBYTE(c_oSerWorkbookPrTypes::Date1904); m_oBcw.m_oStream.WriteBYTE(c_oSerPropLenType::Byte); m_oBcw.m_oStream.WriteBOOL(workbookPr.m_oDate1904->ToBool()); } - //DateCompatibility + //DateCompatibility if(workbookPr.m_oDateCompatibility.IsInit()) { m_oBcw.m_oStream.WriteBYTE(c_oSerWorkbookPrTypes::DateCompatibility); @@ -1600,7 +1597,7 @@ namespace BinXlsxRW int nCurPos; if(bookViews.m_arrItems.size() > 0) { - //WorkbookView + //WorkbookView OOX::Spreadsheet::CWorkbookView* pWorkbookView = static_cast(bookViews.m_arrItems[0]); nCurPos = m_oBcw.WriteItemStart(c_oSerWorkbookTypes::WorkbookView); WriteWorkbookView(*pWorkbookView); @@ -1609,7 +1606,7 @@ namespace BinXlsxRW } void WriteWorkbookView(const OOX::Spreadsheet::CWorkbookView& workbookView) { - //ActiveTab + //ActiveTab if(workbookView.m_oActiveTab.IsInit()) { m_oBcw.m_oStream.WriteBYTE(c_oSerWorkbookViewTypes::ActiveTab); @@ -1635,7 +1632,7 @@ namespace BinXlsxRW for(size_t i = 0, length = externalReferences.m_arrItems.size(); i < length; ++i) { OOX::Spreadsheet::CExternalReference* pExternalReference = externalReferences.m_arrItems[i]; - //ExternalReference + //ExternalReference if(pExternalReference->m_oRid.IsInit()) { @@ -4430,7 +4427,7 @@ namespace BinXlsxRW if(oXlsx.m_pWorkbook) { nCurPos = WriteTableStart(c_oSerTableTypes::Workbook); - BinaryWorkbookTableWriter oBinaryWorkbookTableWriter(oBufferedStream); + BinaryWorkbookTableWriter oBinaryWorkbookTableWriter(oBufferedStream, oXlsx); oBinaryWorkbookTableWriter.Write(*oXlsx.m_pWorkbook); WriteTableEnd(nCurPos); diff --git a/XlsxSerializerCom/Reader/ChartFromToBinary.cpp b/XlsxSerializerCom/Reader/ChartFromToBinary.cpp index 1c07846262..3362c83a44 100644 --- a/XlsxSerializerCom/Reader/ChartFromToBinary.cpp +++ b/XlsxSerializerCom/Reader/ChartFromToBinary.cpp @@ -6153,14 +6153,20 @@ namespace BinXlsxRW WriteCT_extLst(*oVal.m_extLst); m_oBcw.WriteItemEnd(nCurPos); } - smart_ptr pFile = oChartSpace.Find(OOX::FileTypes::ThemeOverride); - if (pFile.IsInit() && OOX::FileTypes::ThemeOverride == pFile->type()) + + std::vector>& container =oChartSpace.GetContainer(); + + for (size_t i = 0; i < container.size(); ++i) { - PPTX::Theme* pThemeOverride = dynamic_cast(pFile.operator->()); - - int nCurPos = m_oBcw.WriteItemStart(c_oserct_chartspaceTHEMEOVERRIDE); - pThemeOverride->toPPTY(&m_oBcw.m_oStream); - m_oBcw.WriteItemEnd(nCurPos); + if (OOX::FileTypes::ThemeOverride == container[i]->type()) + { + PPTX::Theme* pThemeOverride = dynamic_cast(container[i].operator->()); + + int nCurPos = m_oBcw.WriteItemStart(c_oserct_chartspaceTHEMEOVERRIDE); + pThemeOverride->toPPTY(&m_oBcw.m_oStream); + m_oBcw.WriteItemEnd(nCurPos); + break; + } } } void BinaryChartWriter::WriteCT_Boolean(CT_Boolean& oVal) diff --git a/XlsxSerializerCom/Writer/BinaryReader.h b/XlsxSerializerCom/Writer/BinaryReader.h index 96c33780f7..2af82033fa 100644 --- a/XlsxSerializerCom/Writer/BinaryReader.h +++ b/XlsxSerializerCom/Writer/BinaryReader.h @@ -35,7 +35,6 @@ #include "../../Common/Base64.h" #include "../../Common/ATLDefine.h" - #include "../../DesktopEditor/common/Path.h" #include "../../DesktopEditor/common/Directory.h" @@ -47,17 +46,15 @@ #include "../../ASCOfficeDocxFile2/BinReader/DefaultThemeWriter.h" -#include "../../Common/DocxFormat/Source/XlsxFormat/Worksheets/Sparkline.h" -#include "../../Common/DocxFormat/Source/DocxFormat/Media/VbaProject.h" -#include "../../Common/DocxFormat/Source/DocxFormat/Media/JsaProject.h" - -#include "../../Common/DocxFormat/Source/XlsxFormat/Drawing/Drawing.h" #include "../../../../ASCOfficePPTXFile/PPTXFormat/Theme.h" #include "../../Common/DocxFormat/Source/XlsxFormat/Workbook/Workbook.h" +#include "../../Common/DocxFormat/Source/XlsxFormat/Worksheets/Worksheet.h" +#include "../../Common/DocxFormat/Source/XlsxFormat/Worksheets/Sparkline.h" +#include "../../Common/DocxFormat/Source/XlsxFormat/Drawing/Drawing.h" +#include "../../Common/DocxFormat/Source/XlsxFormat/Comments/Comments.h" #include "../../Common/DocxFormat/Source/XlsxFormat/SharedStrings/SharedStrings.h" #include "../../Common/DocxFormat/Source/XlsxFormat/Styles/Styles.h" -#include "../../Common/DocxFormat/Source/XlsxFormat/Worksheets/Worksheet.h" #include "../../Common/DocxFormat/Source/XlsxFormat/CalcChain/CalcChain.h" #include "../../Common/DocxFormat/Source/XlsxFormat/ExternalLinks/ExternalLinks.h" #include "../../Common/DocxFormat/Source/XlsxFormat/ExternalLinks/ExternalLinkPath.h" @@ -66,6 +63,10 @@ #include "../../Common/DocxFormat/Source/XlsxFormat/Pivot/PivotCacheRecords.h" #include "../../Common/DocxFormat/Source/XlsxFormat/WorkbookComments.h" +#include "../../Common/DocxFormat/Source/DocxFormat/Media/VbaProject.h" +#include "../../Common/DocxFormat/Source/DocxFormat/Media/JsaProject.h" +#include "../../Common/DocxFormat/Source/DocxFormat/VmlDrawing.h" + namespace BinXlsxRW { @@ -1523,10 +1524,10 @@ namespace BinXlsxRW }; class BinaryWorkbookTableReader : public Binary_CommonReader { - OOX::Spreadsheet::CWorkbook& m_oWorkbook; - boost::unordered_map>& m_mapPivotCacheDefinitions; - const std::wstring& m_sDestinationDir; - NSBinPptxRW::CDrawingConverter* m_pOfficeDrawingConverter; + OOX::Spreadsheet::CWorkbook & m_oWorkbook; + boost::unordered_map> & m_mapPivotCacheDefinitions; + const std::wstring & m_sDestinationDir; + NSBinPptxRW::CDrawingConverter * m_pOfficeDrawingConverter; public: BinaryWorkbookTableReader(NSBinPptxRW::CBinaryFileReader& oBufferedStream, OOX::Spreadsheet::CWorkbook& oWorkbook, boost::unordered_map>& mapPivotCacheDefinitions, const std::wstring& sDestinationDir, NSBinPptxRW::CDrawingConverter* pOfficeDrawingConverter) : Binary_CommonReader(oBufferedStream), m_oWorkbook(oWorkbook), m_mapPivotCacheDefinitions(mapPivotCacheDefinitions), m_sDestinationDir(sDestinationDir), m_pOfficeDrawingConverter(pOfficeDrawingConverter) @@ -3571,7 +3572,7 @@ namespace BinXlsxRW { int nValue = _wtoi(pCell->m_oValue->ToString().c_str()); - if (nValue >= 0 && nValue < m_pSharedStrings->m_arrItems.size()) + if (nValue >= 0 && nValue < (int)m_pSharedStrings->m_arrItems.size()) { OOX::Spreadsheet::CSi *pSi = m_pSharedStrings->m_arrItems[nValue]; if(NULL != pSi && !pSi->m_arrItems.empty())