/* * (c) Copyright Ascensio System SIA 2010-2019 * * 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 20A-12 Ernesta Birznieka-Upisha * street, Riga, Latvia, EU, LV-1050. * * 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 * */ #pragma once #include "../../../ASCOfficePPTXFile/Editor/Drawing/Document.h" #include "../../../ASCOfficePPTXFile/Editor/DefaultNotesMaster.h" #include "../../../ASCOfficePPTXFile/Editor/DefaultNotesTheme.h" #include "../../../Common/DocxFormat/Source/SystemUtility/SystemUtility.h" #include "../../../ASCOfficeXlsFile2/source/Common/simple_xml_writer.h" #include "../../../DesktopEditor/common/Directory.h" #include "../../../DesktopEditor/common/SystemUtils.h" #include "../Reader/PPTDocumentInfo.h" #include "ShapeWriter.h" #include "StylesWriter.h" #include "Converter.h" namespace PPT_FORMAT { namespace NSPPTXWriterConst { static std::wstring g_string_rels_presentation = _T("\ \ \ \ \ "); static std::wstring g_string_core = _T("\ \ Slide 1\ 1\ "); } } PPT_FORMAT::CPPTXWriter::CPPTXWriter() { m_strTempDirectory = NSDirectory::GetTempPath() + FILE_SEPARATOR_STR + _T("TempPPTX"); m_strDstFileName = NSDirectory::GetTempPath() + FILE_SEPARATOR_STR + _T("Test.pptx"); m_pDocument = NULL; m_pUserInfo = NULL; m_pShapeWriter = new CShapeWriter(); } PPT_FORMAT::CPPTXWriter::~CPPTXWriter() { RELEASEOBJECT(m_pShapeWriter); } void PPT_FORMAT::CPPTXWriter::CreateFile(CPPTUserInfo* pUserInfo ) { m_pUserInfo = pUserInfo; m_pDocument = dynamic_cast(pUserInfo); m_oManager.Clear(); m_oManager.SetDstMedia(m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR + _T("media") + FILE_SEPARATOR_STR); m_pShapeWriter->InitNextId(); NSDirectory::CreateDirectory(m_strTempDirectory); CFile oFile; std::wstring strMemory = _T(""); // _rels NSDirectory::CreateDirectory(m_strTempDirectory + FILE_SEPARATOR_STR + _T("_rels")); oFile.CreateFile(m_strTempDirectory + FILE_SEPARATOR_STR + _T("_rels") + FILE_SEPARATOR_STR + _T(".rels")); strMemory = NSPPTXWriterConst::g_string_rels_presentation; oFile.WriteStringUTF8(strMemory); oFile.CloseFile(); // docProps NSDirectory::CreateDirectory(m_strTempDirectory + FILE_SEPARATOR_STR + _T("docProps")); // core oFile.CreateFile(m_strTempDirectory + FILE_SEPARATOR_STR + _T("docProps") + FILE_SEPARATOR_STR + _T("core.xml")); strMemory = NSPPTXWriterConst::g_string_core; oFile.WriteStringUTF8(strMemory); oFile.CloseFile(); // app oFile.CreateFile(m_strTempDirectory + FILE_SEPARATOR_STR + _T("docProps") + FILE_SEPARATOR_STR + _T("app.xml")); WriteApp(oFile); oFile.CloseFile(); // content types WriteContentTypes(); // ppt NSDirectory::CreateDirectory(m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt")); WritePresInfo(); WriteAll(); } void PPT_FORMAT::CPPTXWriter::CreateFile(CDocument* pDocument) { m_pDocument = pDocument; m_oManager.Clear(); m_oManager.SetDstMedia(m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR + _T("media") + FILE_SEPARATOR_STR); m_pShapeWriter->InitNextId(); NSDirectory::CreateDirectory(m_strTempDirectory); CFile oFile; std::wstring strMemory = _T(""); // _rels NSDirectory::CreateDirectory(m_strTempDirectory + FILE_SEPARATOR_STR + _T("_rels")); oFile.CreateFile(m_strTempDirectory + FILE_SEPARATOR_STR + _T("_rels") + FILE_SEPARATOR_STR + _T(".rels")); strMemory = NSPPTXWriterConst::g_string_rels_presentation; oFile.WriteStringUTF8(strMemory); oFile.CloseFile(); // docProps NSDirectory::CreateDirectory(m_strTempDirectory + FILE_SEPARATOR_STR + _T("docProps")); // core oFile.CreateFile(m_strTempDirectory + FILE_SEPARATOR_STR + _T("docProps") + FILE_SEPARATOR_STR + _T("core.xml")); strMemory = NSPPTXWriterConst::g_string_core; oFile.WriteStringUTF8(strMemory); oFile.CloseFile(); // app oFile.CreateFile(m_strTempDirectory + FILE_SEPARATOR_STR + _T("docProps") + FILE_SEPARATOR_STR + _T("app.xml")); WriteApp(oFile); oFile.CloseFile(); // content types WriteContentTypes(); // ppt NSDirectory::CreateDirectory(m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt")); WritePresInfo(); WriteAll(); } void PPT_FORMAT::CPPTXWriter::CloseFile() { m_oManager.Clear(); } void PPT_FORMAT::CPPTXWriter::WriteContentTypes() { std::wstring strContentTypes = L"\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ "; if (m_pDocument->m_bMacros) { strContentTypes += L"\ "; } else { strContentTypes += L""; } strContentTypes += L"\ \ \ \ "; int nIndexLayout = 1, nIndexTheme = 1; for (size_t nT = 0; nT < m_pDocument->m_arThemes.size(); nT++, nIndexTheme++) { strContentTypes += L""; strContentTypes += L""; for (size_t nL = 0; nL < m_pDocument->m_arThemes[nT]->m_arLayouts.size(); nL++, nIndexLayout++) { strContentTypes += L""; } } if (m_pDocument->m_pNotesMaster) { strContentTypes += L""; strContentTypes += L""; } if (m_pDocument->m_pHandoutMaster) { strContentTypes += L""; strContentTypes += L""; } for (size_t nS = 0; nS < m_pDocument->m_arSlides.size(); ++nS) { strContentTypes += L""; } for (size_t nS = 0; nS < m_pDocument->m_arNotes.size(); ++nS) { strContentTypes += L""; } strContentTypes += _T(""); CFile oFile; oFile.CreateFile(m_strTempDirectory + FILE_SEPARATOR_STR + _T("[Content_Types].xml")); oFile.WriteStringUTF8(strContentTypes); oFile.CloseFile(); } void PPT_FORMAT::CPPTXWriter::WriteApp(CFile& oFile) { std::wstringstream strm; CP_XML_WRITER(strm) { CP_XML_NODE(L"Properties") { CP_XML_ATTR(L"xmlns", L"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"); CP_XML_ATTR(L"xmlns:vt", L"http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"); CP_XML_NODE(L"TotalTime") { CP_XML_STREAM() << 0; } CP_XML_NODE(L"Words") { CP_XML_STREAM() << 0; } std::wstring sApplication = NSSystemUtils::GetEnvVariable(NSSystemUtils::gc_EnvApplicationName); if (sApplication.empty()) sApplication = NSSystemUtils::gc_EnvApplicationNameDefault; #if defined(INTVER) std::string s = VALUE2STR(INTVER); sApplication += L"/" + std::wstring(s.begin(), s.end()); #endif CP_XML_NODE(L"Application") { CP_XML_STREAM() << sApplication; } //CP_XML_NODE(L"AppVersion") //{ // CP_XML_STREAM() << L"1.0"; //} CP_XML_NODE(L"Paragraphs") { CP_XML_STREAM() << 0; } CP_XML_NODE(L"PresentationFormat") { CP_XML_STREAM() << L"On-screen Show (4:3)"; } CP_XML_NODE(L"Slides") { CP_XML_STREAM() << m_pDocument->m_arSlides.size(); } CP_XML_NODE(L"Notes") { CP_XML_STREAM() << m_pDocument->m_arNotes.size(); } CP_XML_NODE(L"HiddenSlides") { CP_XML_STREAM() << 0; } CP_XML_NODE(L"MMClips") { CP_XML_STREAM() << 0; } CP_XML_NODE(L"ScaleCrop") { CP_XML_STREAM() << L"false"; } CP_XML_NODE(L"HeadingPairs") { CP_XML_NODE(L"vt:vector") { CP_XML_ATTR(L"size", 4); CP_XML_ATTR(L"baseType", L"variant"); CP_XML_NODE(L"vt:variant") { CP_XML_NODE(L"vt:lpstr") { CP_XML_STREAM() << L"Theme"; } } CP_XML_NODE(L"vt:variant") { CP_XML_NODE(L"vt:i4") { CP_XML_STREAM() << m_pDocument->m_arThemes.size(); } } CP_XML_NODE(L"vt:variant") { CP_XML_NODE(L"vt:lpstr") { CP_XML_STREAM() << L"Slide Titles"; } } CP_XML_NODE(L"vt:variant") { CP_XML_NODE(L"vt:i4") CP_XML_STREAM() << m_pDocument->m_arSlides.size(); } } } CP_XML_NODE(L"TitlesOfParts") { CP_XML_NODE(L"vt:vector") { CP_XML_ATTR(L"size", m_pDocument->m_arSlides.size() + m_pDocument->m_arThemes.size()); CP_XML_ATTR(L"baseType", L"lpstr"); for (size_t i = 1; i <= m_pDocument->m_arThemes.size(); ++i) { CP_XML_NODE(L"vt:lpstr") { CP_XML_STREAM() << L"Theme " << i; } } for (size_t i = 1; i <= m_pDocument->m_arSlides.size(); ++i) { CP_XML_NODE(L"vt:lpstr") { CP_XML_STREAM() << L"Slide " << i; } } } } //CP_XML_NODE(L"Company"); CP_XML_NODE(L"LinksUpToDate") { CP_XML_STREAM() << L"false"; } CP_XML_NODE(L"SharedDoc") { CP_XML_STREAM() << L"false"; } CP_XML_NODE(L"HyperlinksChanged") { CP_XML_STREAM() << L"false"; } } } oFile.WriteStringUTF8(L""); oFile.WriteStringUTF8(strm.str()); } void PPT_FORMAT::CPPTXWriter::WritePresInfo() { CFile oFile; // tableStyles.xml oFile.CreateFile(m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR + _T("tableStyles.xml")); oFile.WriteStringUTF8(L"\ "); oFile.CloseFile(); // presProps.xml oFile.CreateFile(m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR + _T("presProps.xml")); oFile.WriteStringUTF8(L"\ \ \ \ \ \ "); oFile.CloseFile(); // viewProps.xml oFile.CreateFile(m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR + _T("viewProps.xml")); oFile.WriteStringUTF8(L"\ \ \ \ \ "); oFile.CloseFile(); // presentation.xml + _rels/presentation.xml.rels std::wstring strPresRels; std::wstring strPresMasters; std::wstring strPresSlides; std::wstring strNotesIDs; std::wstring strHandoutIDs; size_t nCountLayouts = 0; for (size_t nIndexTheme = 0; nIndexTheme < m_pDocument->m_arThemes.size(); ++nIndexTheme) { strPresRels += L""; strPresRels += L""; strPresMasters += L""; nCountLayouts += m_pDocument->m_arThemes[nIndexTheme]->m_arLayouts.size(); nCountLayouts += 1; } int nCurrentRels = (int)(2 * m_pDocument->m_arThemes.size() + 1); if (m_pDocument->m_pNotesMaster) { strNotesIDs = L""; strPresRels += L""; ++nCurrentRels; } if (m_pDocument->m_pHandoutMaster) { strHandoutIDs = L""; strPresRels += L""; ++nCurrentRels; } for (size_t nIndexSlide = 0; nIndexSlide < m_pDocument->m_arSlides.size(); ++nIndexSlide, ++nCurrentRels) { strPresRels += L""; strPresSlides += L""; } strPresRels += L""; strPresRels += L""; strPresRels += L""; if (m_pDocument->m_bMacros) { std::wstring strVbaProject = m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR + _T("vbaProject.bin"); if (CDirectory::CopyFile(m_pDocument->m_sVbaProjectFile, strVbaProject)) { strPresRels += L""; } } strPresRels = L"" + strPresRels + L""; std::wstring strPptRels = m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR + _T("_rels"); NSDirectory::CreateDirectory(strPptRels); oFile.CreateFile(strPptRels + FILE_SEPARATOR_STR + _T("presentation.xml.rels")); oFile.WriteStringUTF8(strPresRels); oFile.CloseFile(); std::wstring strSizePres = L"m_lSlideWidth) + L"\" cy=\"" + std::to_wstring(m_pDocument->m_lSlideHeight) + L"\" type=\"screen4x3\" />m_lNotesWidth) + L"\" cy=\"" + std::to_wstring(m_pDocument->m_lNotesHeight) + L"\"/>"; std::wstring strDefaultTextStyle = _T(""); if (false == m_pDocument->m_arThemes.empty()) { CStylesWriter styleWriter(m_pDocument->m_arThemes[0].get()); strDefaultTextStyle += styleWriter.ConvertStyles(m_pDocument->m_arThemes[0]->m_pStyles[0], 9); } strDefaultTextStyle += _T(""); std::wstring strPres = _T(""); strPres += _T("m_bRtl)) { strPres += _T(" rtl=\"1\""); } strPres += _T(">"); strPres += _T("") + strPresMasters + _T(""); strPres += strNotesIDs ; strPres += strHandoutIDs ; strPres +=_T("") + strPresSlides + _T(""); strPres += strSizePres; strPres += strDefaultTextStyle; strPres +=_T(""); oFile.CreateFile(m_strTempDirectory+ FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR + _T("presentation.xml")); oFile.WriteStringUTF8(strPres); oFile.CloseFile(); } void PPT_FORMAT::CPPTXWriter::WriteAll() { std::wstring strPptDirectory = m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR ; NSDirectory::CreateDirectory(strPptDirectory + _T("media")); NSDirectory::CreateDirectory(strPptDirectory + _T("theme")); NSDirectory::CreateDirectory(strPptDirectory + _T("slideMasters")); NSDirectory::CreateDirectory(strPptDirectory + _T("slideMasters") + FILE_SEPARATOR_STR + _T("_rels")); NSDirectory::CreateDirectory(strPptDirectory + _T("slideLayouts")); NSDirectory::CreateDirectory(strPptDirectory + _T("slideLayouts") + FILE_SEPARATOR_STR + _T("_rels")); NSDirectory::CreateDirectory(strPptDirectory + _T("slides")); NSDirectory::CreateDirectory(strPptDirectory + _T("slides") + FILE_SEPARATOR_STR + _T("_rels")); if (m_pDocument->m_pHandoutMaster) { NSDirectory::CreateDirectory(strPptDirectory + _T("handoutMasters")); NSDirectory::CreateDirectory(strPptDirectory + _T("handoutMasters") + FILE_SEPARATOR_STR + _T("_rels")); } if (m_pDocument->m_pNotesMaster) { NSDirectory::CreateDirectory(strPptDirectory + _T("notesMasters")); NSDirectory::CreateDirectory(strPptDirectory + _T("notesMasters") + FILE_SEPARATOR_STR + _T("_rels")); } if (!m_pDocument->m_arNotes.empty()) { NSDirectory::CreateDirectory(strPptDirectory + _T("notesSlides")); NSDirectory::CreateDirectory(strPptDirectory + _T("notesSlides") + FILE_SEPARATOR_STR + _T("_rels")); } WriteThemes(); WriteSlides(); WriteNotes(); } void PPT_FORMAT::CPPTXWriter::WriteThemes() { int nStartLayout = 0, nIndexTheme = 0; for (size_t i = 0; i < m_pDocument->m_arThemes.size(); i++) { m_pShapeWriter->m_pTheme = m_pDocument->m_arThemes[i].get(); WriteTheme(m_pDocument->m_arThemes[i], nIndexTheme, nStartLayout); m_pShapeWriter->m_pTheme = NULL; } WriteTheme(m_pDocument->m_pNotesMaster, nIndexTheme, nStartLayout); WriteTheme(m_pDocument->m_pHandoutMaster, nIndexTheme, nStartLayout); } void PPT_FORMAT::CPPTXWriter::WriteTheme(CThemePtr pTheme, int & nIndexTheme, int & nStartLayout) { if (!pTheme) return; std::wstring strPptDirectory = m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR ; std::wstring strThemeFile = L"theme" + std::to_wstring(nIndexTheme + 1) + L".xml"; strThemeFile = strPptDirectory + _T("theme") + FILE_SEPARATOR_STR + strThemeFile; CFile oFile; oFile.CreateFile(strThemeFile); PPT_FORMAT::CStringWriter oStringWriter; oStringWriter.WriteString(std::wstring(L"m_sThemeName); oStringWriter.WriteString(std::wstring(L"\">")); WriteColorScheme(oStringWriter, L"Default", pTheme->m_arColorScheme); oStringWriter.WriteString(std::wstring(L"m_arFonts[0].Name); oStringWriter.WriteString(std::wstring(L"\"/>")); oStringWriter.WriteString(std::wstring(L"m_arFonts.size() > 1 ) oStringWriter.WriteString (pTheme->m_arFonts[1].Name); else oStringWriter.WriteStringXML(pTheme->m_arFonts[0].Name); oStringWriter.WriteString(std::wstring(L"\"/>")); oStringWriter.WriteString(std::wstring(L"")); oStringWriter.WriteString(std::wstring(L"\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ ")); oStringWriter.WriteString(std::wstring(L"")); oStringWriter.WriteString(std::wstring(L"")); for (size_t i = 0 ; i < pTheme->m_arExtraColorScheme.size(); i++) { std::wstring str = L" " + std::to_wstring(i + 1); WriteColorScheme(oStringWriter, pTheme->m_sThemeName + str, pTheme->m_arExtraColorScheme[i], true); //extra } oStringWriter.WriteString(std::wstring(L"")); oStringWriter.WriteString(std::wstring(L"")); oFile.WriteStringUTF8(oStringWriter.GetData()); oFile.CloseFile(); CRelsGenerator oRels(&m_oManager); int nCountLayouts = (int)pTheme->m_arLayouts.size(); oRels.StartMaster(nIndexTheme, nStartLayout, nCountLayouts); CStringWriter oWriter; oWriter.WriteString(L""); if (pTheme->m_eType == typeMaster) { oWriter.WriteString(L""); } else if (pTheme->m_eType == typeNotesMaster) { oWriter.WriteString(L""); } else if (pTheme->m_eType == typeHandoutMaster) { oWriter.WriteString(L""); } oWriter.WriteString(L""); if (pTheme->m_bIsBackground) { WriteBackground(oWriter, oRels, pTheme->m_oBackground); } oWriter.WriteString(L"\ "); CGroupElement *pGroupElement = !pTheme->m_arElements.empty() ? dynamic_cast(pTheme->m_arElements[0].get()) : NULL; size_t start_index = 0; if (pGroupElement) { for (size_t i = 0; i < pGroupElement->m_pChildElements.size(); ++i) { if (isBodyPlaceholder(pGroupElement->m_pChildElements[i]->m_lPlaceholderType)) pGroupElement->m_pChildElements[i]->m_lPlaceholderType = 100; //body тип прописывать !! //if (pGroupElement->m_pChildElements[i]->m_bAnchorEnabled == false && // pGroupElement->m_pChildElements[i]->m_bChildAnchorEnabled == false) // continue; //if (pTheme->m_eType == typeNotesMaster) //{ // pGroupElement->m_pChildElements[i]->m_lPlaceholderID = -1; //} //else if (pTheme->m_eType == typeHandoutMaster) //{ // pGroupElement->m_pChildElements[i]->m_lPlaceholderID = -1; // pGroupElement->m_pChildElements[i]->m_lPlaceholderSizePreset = -1; //} WriteElement(oWriter, oRels, pGroupElement->m_pChildElements[i]); } start_index = 1; } for (size_t i = start_index; i < pTheme->m_arElements.size(); ++i) { if (isBodyPlaceholder(pTheme->m_arElements[i]->m_lPlaceholderType)) pTheme->m_arElements[i]->m_lPlaceholderType = 100; //body тип прописывать !! //if (pTheme->m_arElements[i]->m_bAnchorEnabled == false && // pTheme->m_arElements[i]->m_bChildAnchorEnabled == false) // continue; //if (pTheme->m_eType == typeNotesMaster) //{ // pTheme->m_arElements[i]->m_lPlaceholderID = -1; //} //else if (pTheme->m_eType == typeHandoutMaster) //{ // pTheme->m_arElements[i]->m_lPlaceholderID = -1; // pTheme->m_arElements[i]->m_lPlaceholderSizePreset = -1; //} WriteElement(oWriter, oRels, pTheme->m_arElements[i]); } oWriter.WriteString(std::wstring(L"")); std::wstring strOverrideColorScheme = _T(""); oWriter.WriteString(strOverrideColorScheme); if (pTheme->m_eType == typeMaster) { oWriter.WriteString(std::wstring(L"")); size_t __nCountLayouts = 0; for (int nIndexLayout = 0; nIndexLayout < nCountLayouts; ++nIndexLayout) { oWriter.WriteString(L""); WriteLayout(pTheme->m_arLayouts[nIndexLayout], nIndexLayout, nStartLayout, nIndexTheme); } oWriter.WriteString(std::wstring(L"")); } if (pTheme->m_bHasDate || pTheme->m_bHasFooter || pTheme->m_bHasSlideNumber) { oWriter.WriteString(std::wstring(L"m_bHasDate) oWriter.WriteString(std::wstring(L" dt=\"0\"")); if (!pTheme->m_bHasSlideNumber) oWriter.WriteString(std::wstring(L" sldNum=\"0\"")); oWriter.WriteString(std::wstring(L" hdr=\"0\"")); if (!pTheme->m_bHasFooter) oWriter.WriteString(std::wstring(L" ftr=\"0\"")); oWriter.WriteString(std::wstring(L"/>")); } CStylesWriter styleWriter; styleWriter.m_pTheme = pTheme.get(); if (pTheme->m_eType == typeMaster) { oWriter.WriteString(std::wstring(L"")); oWriter.WriteString(std::wstring(L"")); styleWriter.ConvertStyles(pTheme->m_pStyles[1], oWriter, 9); oWriter.WriteString(std::wstring(L"")); oWriter.WriteString(std::wstring(L"")); styleWriter.ConvertStyles(pTheme->m_pStyles[2], oWriter, 9); oWriter.WriteString(std::wstring(L"")); oWriter.WriteString(std::wstring(L"")); styleWriter.ConvertStyles(pTheme->m_pStyles[3], oWriter, 9); oWriter.WriteString(std::wstring(L"")); oWriter.WriteString(std::wstring(L"")); } else if (pTheme->m_eType == typeNotesMaster) { oWriter.WriteString(std::wstring(L"")); styleWriter.ConvertStyles(pTheme->m_pStyles[1], oWriter, 9); oWriter.WriteString(std::wstring(L"")); } std::wstring strSlideMasterFile; std::wstring strSlideMasterRelsFile; if (pTheme->m_eType == typeMaster) { oWriter.WriteString(std::wstring(L"")); strSlideMasterFile = L"slideMaster" + std::to_wstring(nIndexTheme + 1) + L".xml"; strSlideMasterFile = strPptDirectory + _T("slideMasters") + FILE_SEPARATOR_STR + strSlideMasterFile; strSlideMasterRelsFile = L"slideMaster" + std::to_wstring(nIndexTheme + 1) + L".xml.rels"; strSlideMasterRelsFile = strPptDirectory + _T("slideMasters") + FILE_SEPARATOR_STR + _T("_rels") + FILE_SEPARATOR_STR + strSlideMasterRelsFile; } else if (pTheme->m_eType == typeNotesMaster) { oWriter.WriteString(std::wstring(L"")); strSlideMasterFile = L"notesMaster1.xml"; strSlideMasterFile = strPptDirectory + _T("notesMasters") + FILE_SEPARATOR_STR + strSlideMasterFile; strSlideMasterRelsFile = L"notesMaster1.xml.rels"; strSlideMasterRelsFile = strPptDirectory + _T("notesMasters") + FILE_SEPARATOR_STR + _T("_rels") + FILE_SEPARATOR_STR + strSlideMasterRelsFile; } else if (pTheme->m_eType == typeHandoutMaster) { oWriter.WriteString(std::wstring(L"")); strSlideMasterFile = L"handoutMaster1.xml"; strSlideMasterFile = strPptDirectory + _T("handoutMasters") + FILE_SEPARATOR_STR + strSlideMasterFile; strSlideMasterRelsFile = L"handoutMaster1.xml.rels"; strSlideMasterRelsFile = strPptDirectory + _T("handoutMasters") + FILE_SEPARATOR_STR + _T("_rels") + FILE_SEPARATOR_STR + strSlideMasterRelsFile; } oFile.CreateFile(strSlideMasterFile); std::wstring strMaster = oWriter.GetData(); oFile.WriteStringUTF8(strMaster); oFile.CloseFile(); oRels.CloseRels(); oRels.SaveRels(strSlideMasterRelsFile); nStartLayout += nCountLayouts; nIndexTheme++; } void PPT_FORMAT::CPPTXWriter::WriteColorScheme(CStringWriter& oStringWriter, const std::wstring & name, const std::vector & colors, bool extra) { if (colors.size() < 1) { oStringWriter.WriteString(L"\ \ \ \ \ "); return; } if (extra) oStringWriter.WriteString(L""); oStringWriter.WriteString(L""); oStringWriter.WriteString(L""); oStringWriter.WriteString(L""); oStringWriter.WriteString(L""); oStringWriter.WriteString(L""); oStringWriter.WriteString(L""); oStringWriter.WriteString(L""); oStringWriter.WriteString(L""); oStringWriter.WriteString(L""); oStringWriter.WriteString(L""); oStringWriter.WriteString(L""); oStringWriter.WriteString(L""); oStringWriter.WriteString(L""); oStringWriter.WriteString(L""); if (extra) { oStringWriter.WriteString(L""); oStringWriter.WriteString(L""); } } void PPT_FORMAT::CPPTXWriter::WriteBackground(CStringWriter& oWriter, CRelsGenerator& oRels, CBrush& oBackground) { oWriter.WriteString(std::wstring(L"")); m_pShapeWriter->SetRelsGenerator(&oRels); { oWriter.WriteString(m_pShapeWriter->ConvertBrush(oBackground)); } oWriter.WriteString(std::wstring(L"")); } void PPT_FORMAT::CPPTXWriter::WriteGroup(CStringWriter& oWriter, CRelsGenerator& oRels, CElementPtr pElement, CLayout* pLayout) { CGroupElement *pGroupElement = dynamic_cast(pElement.get()); m_pShapeWriter->SetElement(pElement); oWriter.WriteString(m_pShapeWriter->ConvertGroup()); for (size_t i = 0; i < pGroupElement->m_pChildElements.size(); i++) { WriteElement(oWriter, oRels, pGroupElement->m_pChildElements[i], pLayout); } oWriter.WriteString(L""); } void PPT_FORMAT::CPPTXWriter::WriteElement(CStringWriter& oWriter, CRelsGenerator& oRels, CElementPtr pElement, CLayout* pLayout) { if (!pElement) return; CGroupElement *pGroupElement = dynamic_cast(pElement.get()); if (pGroupElement) { return WriteGroup(oWriter, oRels, pElement, pLayout); } bool bObject = m_pShapeWriter->SetElement(pElement); if (bObject) { m_pShapeWriter->SetRelsGenerator(&oRels); if (NULL != pLayout) { if (-1 != pElement->m_lPlaceholderType) { size_t nCountElements = pLayout->m_arElements.size(); for (size_t nIndex = 0; nIndex < nCountElements; ++nIndex) { if ((pElement->m_lPlaceholderType == pLayout->m_arElements[nIndex]->m_lPlaceholderType) && (pElement->m_lPlaceholderID == pLayout->m_arElements[nIndex]->m_lPlaceholderID)) { CElementPtr pElLayout = pLayout->m_arElements[nIndex]; bool bIsEqualTransform = ((pElement->m_dRotate == pElLayout->m_dRotate) && (pElement->m_bFlipH == pElLayout->m_bFlipH) && (pElement->m_bFlipV == pElLayout->m_bFlipV)); if (bIsEqualTransform) { if (pElement->m_bAnchorEnabled == pElLayout->m_bAnchorEnabled && pElLayout->m_bAnchorEnabled == true) { if (pElement->m_rcAnchor.IsEqual(pElLayout->m_rcAnchor, 0.5)) pElement->m_bAnchorEnabled = false; } if (pElement->m_bChildAnchorEnabled == pElLayout->m_bChildAnchorEnabled && pElLayout->m_bChildAnchorEnabled == true) { if (pElement->m_rcChildAnchor.IsEqual(pElLayout->m_rcChildAnchor, 0.5)) pElement->m_bChildAnchorEnabled = false; } } break; } } } } oWriter.WriteString(m_pShapeWriter->ConvertShape()); } } void PPT_FORMAT::CPPTXWriter::WriteLayout(CLayoutPtr pLayout, int nIndexLayout, int nStartLayout, int nIndexTheme) { if (!pLayout) return; CStringWriter oWriter; CRelsGenerator oRels(&m_oManager); oRels.StartLayout(nIndexTheme); oWriter.WriteString(std::wstring(L"")); oWriter.WriteString(std::wstring(L"m_strLayoutType + _T("\"")); oWriter.WriteString(std::wstring(L" showMasterSp=\"") + (pLayout->m_bShowMasterShapes ? _T("1") : _T("0"))); oWriter.WriteString(std::wstring(L"\" preserve=\"1\">m_sName.empty() == false) oWriter.WriteString(std::wstring(L" name=\"") + pLayout->m_sName + std::wstring(L"\"")); oWriter.WriteString(std::wstring(L">")); if (pLayout->m_bIsBackground) { WriteBackground(oWriter, oRels, pLayout->m_oBackground); } std::wstring strElems = _T("\ "); oWriter.WriteString(strElems); size_t start_index = 0; if (pLayout->m_bIsTitleMaster) { CGroupElement *pGroupElement = (!pLayout->m_arElements.empty()) ? dynamic_cast(pLayout->m_arElements[0].get()) : NULL; if (pGroupElement) { for (size_t i = 0; i < pGroupElement->m_pChildElements.size(); ++i) { WriteElement(oWriter, oRels, pGroupElement->m_pChildElements[i]); } start_index = 1; } } for (size_t i = start_index; i < pLayout->m_arElements.size(); ++i) { WriteElement(oWriter, oRels, pLayout->m_arElements[i]); } oWriter.WriteString(std::wstring(L"")); oWriter.WriteString(std::wstring(L"")); oWriter.WriteString(std::wstring(L"")); oRels.CloseRels(); std::wstring strXml = oWriter.GetData(); std::wstring strFile = L"slideLayout" + std::to_wstring(nIndexLayout + nStartLayout + 1) + L".xml"; CFile oFile; std::wstring strFileLayoutPath= m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR + _T("slideLayouts") + FILE_SEPARATOR_STR; oFile.CreateFile(strFileLayoutPath + strFile); oFile.WriteStringUTF8(strXml); oFile.CloseFile(); strFile = L"slideLayout" + std::to_wstring(nIndexLayout + nStartLayout + 1) + L".xml.rels"; oRels.SaveRels(strFileLayoutPath + _T("_rels") + FILE_SEPARATOR_STR + strFile); } void PPT_FORMAT::CPPTXWriter::WriteSlide(int nIndexSlide) { CStringWriter oWriter; CRelsGenerator oRels(&m_oManager); CSlide* pSlide = m_pDocument->m_arSlides[nIndexSlide]; if (0 == pSlide->m_lThemeID) oRels.StartSlide(pSlide->m_lLayoutID, pSlide->m_lNotesID); else { int nLayout = pSlide->m_lLayoutID; for (int i = 0; i < pSlide->m_lThemeID; ++i) { nLayout += (int)m_pDocument->m_arThemes[i]->m_arLayouts.size(); } oRels.StartSlide(nLayout, pSlide->m_lNotesID); } oWriter.WriteString(std::wstring(L"")); oWriter.WriteString(std::wstring(L"m_bShowMasterShapes) oWriter.WriteString(std::wstring(L" showMasterSp=\"0\"")); oWriter.WriteString(std::wstring(L">")); oWriter.WriteString(std::wstring(L"m_sName.empty() == false) oWriter.WriteString(std::wstring(L" name=\"") + pSlide->m_sName + std::wstring(L"\"")); oWriter.WriteString(std::wstring(L">")); if (pSlide->m_bIsBackground) { WriteBackground(oWriter, oRels, pSlide->m_oBackground); } oWriter.WriteString(std::wstring(L"\ ")); CGroupElement *pGroupElement = !pSlide->m_arElements.empty() ? dynamic_cast(pSlide->m_arElements[0].get()) : NULL; size_t start_index = 0; if (pGroupElement) { for (size_t i = 0; i < pGroupElement->m_pChildElements.size(); ++i) { WriteElement(oWriter, oRels, pGroupElement->m_pChildElements[i]); } start_index = 1; } for (size_t i = start_index; i < pSlide->m_arElements.size(); ++i) { WriteElement(oWriter, oRels, pSlide->m_arElements[i]); } oWriter.WriteString(std::wstring(L"")); oWriter.WriteString(std::wstring(L"")); WriteTransition(oWriter, pSlide->m_oSlideShow); // TODO write new method and class for timing auto slide_iter = m_pUserInfo->m_mapSlides.find(m_pUserInfo->m_arrSlidesOrder[nIndexSlide]); CRecordSlideProgTagsContainer& progTag = *(slide_iter->second->m_pSlideProgTagsContainer); CRecordPP10SlideBinaryTagExtension* pPP10SlideBinaryTag = progTag.getPP10SlideBinaryTagExtension(); if (pPP10SlideBinaryTag) { Animation animation(*pPP10SlideBinaryTag); std::vector sound; m_pUserInfo->m_oDocument.GetRecordsByType(&sound, false); if (!sound.empty()) { animation.m_pSoundContainer = sound[0]; } m_oManager.m_ridManager.setRIDfromAnimation(animation); m_oManager.m_ridManager.setRID(oRels.getRId()); auto paths = m_oManager.m_ridManager.getPathesForSlideRels(); for (auto& path : paths) { oRels.WriteHyperlinkMedia(path, false, false, L"http://schemas.openxmlformats.org/officeDocument/2006/relationships/audio"); } animation.Convert(pSlide->m_oTiming); WriteTiming(oWriter, pSlide->m_oTiming); } oWriter.WriteString(std::wstring(L"")); oRels.CloseRels(); std::wstring strXml = oWriter.GetData(); std::wstring strFile = L"slide" + std::to_wstring(nIndexSlide + 1) + L".xml"; std::wstring strFileSlidePath= m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR + _T("slides") + FILE_SEPARATOR_STR; CFile oFile; oFile.CreateFile(strFileSlidePath + strFile); oFile.WriteStringUTF8(strXml); oFile.CloseFile(); strFile = L"slide" + std::to_wstring(nIndexSlide + 1) + L".xml.rels"; oRels.SaveRels(strFileSlidePath + _T("_rels") + FILE_SEPARATOR_STR + strFile); } void PPT_FORMAT::CPPTXWriter::WriteTransition(CStringWriter& oWriter, CSlideShowInfo &oSSInfo) { CTransition& transition = oSSInfo.m_oTransition; if (transition.m_nEffectType == 0xFF) return; std::wstring type; std::wstring param_name, param_value; std::wstring param_name2, param_value2; switch(transition.m_nEffectType) { case 0: { type = L"p:cut"; param_name = L"thruBlk"; param_value = transition.m_nEffectDirection ? L"true" : L"false"; }break; case 1: { type = L"p:random"; }break; case 2: { type = L"p:blinds"; param_name = L"dir"; param_value = transition.m_nEffectDirection ? L"vert" : L"horz"; }break; case 3: { type = L"p:checker"; param_name = L"dir"; param_value = transition.m_nEffectDirection ? L"vert" : L"horz"; }break; case 5: { type = L"p:dissolve"; param_name = L"thruBlk"; param_value = transition.m_nEffectDirection ? L"true" : L"false"; }break; case 6: { type = L"p:fade"; param_name = L"thruBlk"; param_value = transition.m_nEffectDirection ? L"true" : L"false"; }break; case 4: case 7: { if (transition.m_nEffectType == 4) type = L"p:cover"; if (transition.m_nEffectType == 7) type = L"p:pull"; param_name = L"dir"; switch(transition.m_nEffectDirection) { case 0: param_value = L"r"; break; case 1: param_value = L"b"; break; case 2: param_value = L"l"; break; case 3: param_value = L"t"; break; case 4: param_value = L"br"; break; case 5: param_value = L"bl"; break; case 6: param_value = L"tr"; break; case 7: param_value = L"tl"; break; } }break; case 8: { type = L"p:randomBars"; param_name = L"dir"; param_value = transition.m_nEffectDirection ? L"vert" : L"horz"; }break; case 9: { type = L"p:strips"; param_name = L"dir"; switch(transition.m_nEffectDirection) { case 0: param_value = L"ru"; break; case 1: param_value = L"lu"; break; case 2: param_value = L"rd"; break; case 3: param_value = L"ld"; break; } }break; case 10: case 20: { if (transition.m_nEffectType == 10) type = L"p:wipe"; if (transition.m_nEffectType == 20) type = L"p:push"; param_name = L"dir"; switch(transition.m_nEffectDirection) { case 0: param_value = L"l"; break; case 1: param_value = L"u"; break; case 2: param_value = L"r"; break; case 3: param_value = L"d"; break; } }break; case 11: { type = L"p:zoom"; param_name = L"dir"; param_value = transition.m_nEffectDirection ? L"in" : L"out"; }break; case 13: { type = L"p:split"; param_name = L"dir"; param_name2 = L"orient"; switch(transition.m_nEffectDirection) { case 0: param_value2 = L"horz"; param_value = L"out"; break; case 1: param_value2 = L"horz"; param_value = L"in"; break; case 2: param_value2 = L"vert"; param_value = L"out"; break; case 3: param_value2 = L"vert"; param_value = L"in"; break; } }break; case 17: { type = L"p:diamond"; }break; case 18: { type = L"p:plus"; }break; case 19: { type = L"p:wedge"; }break; case 21: { type = L"p:comb"; param_name = L"dir"; param_value = transition.m_nEffectDirection ? L"vert" : L"horz"; }break; case 22: { type = L"p:newsflash"; }break; case 23: { type = L"p:fade"; // p:alphaFade }break; case 26: { type = L"p:wheel"; param_name = L"spokes"; param_value = std::to_wstring(transition.m_nEffectDirection); }break; case 27: { type = L"p:circle"; }break; default: break; } if (type.empty()) return; oWriter.WriteString(std::wstring(L""); oWriter.WriteString(L"<" + type); if (!param_name.empty() && !param_value.empty()) { oWriter.WriteString(L" " + param_name + L"=\"" + param_value + L"\""); } if (!param_name2.empty() && !param_value2.empty()) { oWriter.WriteString(L" " + param_name2 + L"=\"" + param_value2 + L"\""); } oWriter.WriteString(L"/>"); if (transition.m_bAudioPresent) { bool bExternal = false; std::wstring rId = m_pShapeWriter->m_pRels->WriteAudio(transition.m_oAudio.m_strAudioFileName, bExternal); oWriter.WriteString(std::wstring(L"")); oWriter.WriteString(L""); oWriter.WriteString(std::wstring(L"")); } oWriter.WriteString(std::wstring(L"")); } void PPT_FORMAT::CPPTXWriter::WriteNotes(int nIndexNotes) { CStringWriter oWriter; CRelsGenerator oRels(&m_oManager); CSlide* pNotes = m_pDocument->m_arNotes[nIndexNotes]; oRels.StartNotes(pNotes->m_lSlideID, m_pDocument->m_pNotesMaster != NULL); oWriter.WriteString(std::wstring(L"")); oWriter.WriteString(std::wstring(L"m_bShowMasterShapes) oWriter.WriteString(std::wstring(L" showMasterSp=\"0\"")); oWriter.WriteString(std::wstring(L">")); oWriter.WriteString(std::wstring(L"")); if (pNotes->m_bIsBackground) { WriteBackground(oWriter, oRels, pNotes->m_oBackground); } oWriter.WriteString(std::wstring(L"\ ")); CGroupElement *pGroupElement = !pNotes->m_arElements.empty() ? dynamic_cast(pNotes->m_arElements[0].get()) : NULL; size_t start_index = 0; if (pGroupElement) { for (size_t i = 0; i < pGroupElement->m_pChildElements.size(); ++i) { WriteElement(oWriter, oRels, pGroupElement->m_pChildElements[i]); } start_index = 1; } for (size_t i = start_index; i < pNotes->m_arElements.size(); ++i) { WriteElement(oWriter, oRels, pNotes->m_arElements[i]); } oWriter.WriteString(std::wstring(L"")); oWriter.WriteString(std::wstring(L"")); oWriter.WriteString(std::wstring(L"")); oRels.CloseRels(); std::wstring strXml = oWriter.GetData(); std::wstring strFile = L"notesSlide" + std::to_wstring(nIndexNotes + 1) + L".xml"; std::wstring strFileSlidePath = m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR + _T("notesSlides") + FILE_SEPARATOR_STR; CFile oFile; oFile.CreateFile(strFileSlidePath + strFile); oFile.WriteStringUTF8(strXml); oFile.CloseFile(); strFile = L"notesSlide" + std::to_wstring(nIndexNotes + 1) + L".xml.rels"; oRels.SaveRels(strFileSlidePath + _T("_rels") + FILE_SEPARATOR_STR + strFile); } void PPT_FORMAT::CPPTXWriter::WriteSlides() { m_oManager.WriteAudioCollection(m_pUserInfo->m_oExMedia.m_arAudioCollection); for (size_t nIndexS = 0; nIndexS < m_pDocument->m_arSlides.size(); ++nIndexS) { WriteSlide((int)nIndexS); } } void PPT_FORMAT::CPPTXWriter::WriteNotes() { for (size_t nIndexS = 0; nIndexS < m_pDocument->m_arNotes.size(); ++nIndexS) { WriteNotes((int)nIndexS); } } void PPT_FORMAT::CPPTXWriter::WriteTiming(CStringWriter& oWriter, PPTX::Logic::Timing &oTiming) { oWriter.WriteString(oTiming.toXML()); //oWriter.WriteString(std::wstring(L"")); }