/*
* (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
*
*/
#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 "../../../DesktopEditor/common/Directory.h"
#include "../Reader/PPTDocumentInfo.h"
#include "ShapeWriter.h"
#include "StylesWriter.h"
#include "Converter.h"
namespace NSPresentationEditor
{
namespace NSPPTXWriterConst
{
static std::wstring g_string_rels_presentation = _T("\
\
\
\
\
");
static std::wstring g_string_core = _T("\
\
Slide 1\
OnlyOffice\
OnlyOffice\
1\
");
}
}
NSPresentationEditor::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();
}
NSPresentationEditor::CPPTXWriter::~CPPTXWriter()
{
RELEASEOBJECT(m_pShapeWriter);
}
void NSPresentationEditor::CPPTXWriter::CreateFile(CPPTUserInfo* pUserInfo )
{
m_pUserInfo = pUserInfo;
m_pDocument = dynamic_cast(pUserInfo);
m_pDocument->m_oInfo.m_lUnitsHor = 36000 * m_pDocument->m_oInfo.m_lMillimetresHor;
m_pDocument->m_oInfo.m_lUnitsVer = 36000 * m_pDocument->m_oInfo.m_lMillimetresVer;
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 NSPresentationEditor::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 NSPresentationEditor::CPPTXWriter::CloseFile()
{
m_oManager.Clear();
}
void NSPresentationEditor::CPPTXWriter::WriteContentTypes()
{
std::wstring strContentTypes = _T("\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
");
strContentTypes += _T("\
\
\
\
\
");
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 NSPresentationEditor::CPPTXWriter::WriteApp(CFile& oFile)
{
std::wstring str1 = _T("\
\
0\
0\
OnlyOffice\
On-screen Show (4:3)\
0");
oFile.WriteStringUTF8(str1);
oFile.WriteStringUTF8(L"" + std::to_wstring(m_pDocument->m_arSlides.size()) + L"");
oFile.WriteStringUTF8(L"" + std::to_wstring(m_pDocument->m_arNotes.size()) + L"");
oFile.WriteStringUTF8(L"0\
2\
false\
\
");
int nCountThemes = (int)m_pDocument->m_arThemes.size();
int nCountSlides = (int)m_pDocument->m_arSlides.size();
std::wstring strThemes = L"Theme" +std::to_wstring(nCountThemes) +
L"";
std::wstring strSlides = L"Slide Titles" +
std::to_wstring(nCountSlides) + L"";
std::wstring strTitles = L"";
oFile.WriteStringUTF8(strThemes + strSlides + strTitles);
std::wstring strMemory = _T("");
for (int i = 1; i <= nCountThemes; ++i)
{
strMemory += L"Theme " + std::to_wstring(i) + L"";
}
for (int i = 1; i <= nCountSlides; ++i)
{
strMemory += L"Slide " + std::to_wstring(i) + L"";
}
std::wstring str5 = _T("\
\
\
false\
false\
false\
4.4000\
");
strMemory += str5;
oFile.WriteStringUTF8(strMemory);
}
void NSPresentationEditor::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"";
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_oInfo.m_lUnitsHor) +
L"\" cy=\"" + std::to_wstring(m_pDocument->m_oInfo.m_lUnitsVer) +
L"\" type=\"screen4x3\" />m_oInfo.m_lUnitsVer) +
L"\" cy=\"" + std::to_wstring(m_pDocument->m_oInfo.m_lUnitsHor) + L"\"/>";
std::wstring strDefaultTextStyle = _T("");
if (m_pDocument->m_arThemes.size() > 0)
{
strDefaultTextStyle += CStylesWriter::ConvertStyles(m_pDocument->m_arThemes[0].m_pStyles[0], m_pDocument->m_oInfo, 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 NSPresentationEditor::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 NSPresentationEditor::CPPTXWriter::WriteThemes()
{
int nStartLayout = 0, nIndexTheme = 0;
for (size_t i = 0; i < m_pDocument->m_arThemes.size(); i++)
{
WriteTheme(&m_pDocument->m_arThemes[i], nIndexTheme, nStartLayout, 1);
}
WriteTheme(m_pDocument->m_pNotesMaster, nIndexTheme, nStartLayout, 2);
WriteTheme(m_pDocument->m_pHandoutMaster, nIndexTheme, nStartLayout, 3);
}
void NSPresentationEditor::CPPTXWriter::WriteTheme(CTheme* pTheme, int & nIndexTheme, int & nStartLayout, int Type)
{
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);
NSPresentationEditor::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 (Type == 1)
{
oWriter.WriteString(L"");
}
else if (Type == 2)
{
oWriter.WriteString(L"");
}
else if (Type == 3)
{
oWriter.WriteString(L"");
}
oWriter.WriteString(L"");
if (pTheme->m_bIsBackground)
{
WriteBackground(oWriter, oRels, pTheme->m_oBackground);
}
oWriter.WriteString(L"\
");
for (size_t nEl = 0; nEl < pTheme->m_arElements.size(); ++nEl)
{
if (isBodyPlaceholder(pTheme->m_arElements[nEl]->m_lPlaceholderType))
pTheme->m_arElements[nEl]->m_lPlaceholderType =100; //body тип прописывать !!
if (pTheme->m_arElements[nEl]->m_bBoundsEnabled == false)
continue;
WriteElement(oWriter, oRels, pTheme->m_arElements[nEl]);
}
oWriter.WriteString(std::wstring(L""));
std::wstring strOverrideColorScheme = _T("");
oWriter.WriteString(strOverrideColorScheme);
if (Type == 1)
{
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"/>"));
}
if (Type == 1)
{
oWriter.WriteString(std::wstring(L""));
oWriter.WriteString(std::wstring(L""));
CStylesWriter::ConvertStyles(pTheme->m_pStyles[1], pTheme->m_oInfo, oWriter, 9);
oWriter.WriteString(std::wstring(L""));
oWriter.WriteString(std::wstring(L""));
CStylesWriter::ConvertStyles(pTheme->m_pStyles[2], pTheme->m_oInfo, oWriter, 9);
oWriter.WriteString(std::wstring(L""));
oWriter.WriteString(std::wstring(L""));
CStylesWriter::ConvertStyles(pTheme->m_pStyles[3], pTheme->m_oInfo, oWriter, 9);
oWriter.WriteString(std::wstring(L""));
oWriter.WriteString(std::wstring(L""));
}
else if (Type == 2)
{
oWriter.WriteString(std::wstring(L""));
CStylesWriter::ConvertStyles(pTheme->m_pStyles[1], pTheme->m_oInfo, oWriter, 9);
oWriter.WriteString(std::wstring(L""));
}
std::wstring strSlideMasterFile;
std::wstring strSlideMasterRelsFile;
if (Type == 1)
{
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 (Type == 2)
{
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 (Type == 3)
{
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 NSPresentationEditor::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 NSPresentationEditor::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 NSPresentationEditor::CPPTXWriter::WriteElement(CStringWriter& oWriter, CRelsGenerator& oRels, IElement* pElement, CLayout* pLayout)
{
if (!pElement) return;
pElement->m_oMetric = m_pDocument->m_oInfo;
pElement->NormalizeCoordsByMetric();
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))
{
IElement* 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_rcBounds.IsEqual(pElLayout->m_rcBounds, 0.5))
pElement->m_bBoundsEnabled = false;
}
break;
}
}
}
}
oWriter.WriteString(m_pShapeWriter->ConvertShape());
}
}
void NSPresentationEditor::CPPTXWriter::WriteLayout(CLayout& oLayout, int nIndexLayout, int nStartLayout, int nIndexTheme)
{
CStringWriter oWriter;
CRelsGenerator oRels(&m_oManager);
oRels.StartLayout(nIndexTheme);
oWriter.WriteString(std::wstring(L""));
oWriter.WriteString(std::wstring(L""));
if (oLayout.m_bIsBackground)
{
WriteBackground(oWriter, oRels, oLayout.m_oBackground);
}
std::wstring strElems = _T("\
");
oWriter.WriteString(strElems);
size_t nElements = oLayout.m_arElements.size();
for (size_t nEl = 0; nEl < nElements; ++nEl)
{
WriteElement(oWriter, oRels, oLayout.m_arElements[nEl]);
}
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 NSPresentationEditor::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"\
"));
for (size_t nEl = 0; nEl < pSlide->m_arElements.size(); ++nEl)
{
WriteElement(oWriter, oRels, pSlide->m_arElements[nEl], &m_pDocument->m_arThemes[pSlide->m_lThemeID].m_arLayouts[pSlide->m_lLayoutID]);
}
oWriter.WriteString(std::wstring(L""));
oWriter.WriteString(std::wstring(L""));
WriteTransition(oWriter, pSlide->m_oSlideShow.m_oTransition);
oWriter.WriteString(std::wstring(L""));
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 NSPresentationEditor::CPPTXWriter::WriteTransition(CStringWriter& oWriter, CTransition& transition)
{
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_value = L"horz"; param_value2 = L"out"; break;
case 1: param_value = L"horz"; param_value2 = L"in"; break;
case 2: param_value = L"vert"; param_value2 = L"out"; break;
case 3: param_value = L"vert"; param_value2 = 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: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)
{
std::wstring rId = m_pShapeWriter->m_pRels->WriteAudio(transition.m_oAudio.m_strAudioFileName);
oWriter.WriteString(std::wstring(L""));
oWriter.WriteString(L"");
oWriter.WriteString(std::wstring(L""));
}
oWriter.WriteString(std::wstring(L""));
}
void NSPresentationEditor::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"\
"));
for (size_t nEl = 0; nEl < pNotes->m_arElements.size(); ++nEl)
{
WriteElement(oWriter, oRels, pNotes->m_arElements[nEl], NULL);
}
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 NSPresentationEditor::CPPTXWriter::WriteSlides()
{
for (size_t nIndexS = 0; nIndexS < m_pDocument->m_arSlides.size(); ++nIndexS)
{
WriteSlide((int)nIndexS);
}
}
void NSPresentationEditor::CPPTXWriter::WriteNotes()
{
for (size_t nIndexS = 0; nIndexS < m_pDocument->m_arNotes.size(); ++nIndexS)
{
WriteNotes((int)nIndexS);
}
}