#pragma once
#include "../OfficeDrawing/Document.h"
#include "../../Common/DocxFormat/Source/SystemUtility/File.h"
#include "../../Common/DocxFormat/Source/SystemUtility/FileSystem/Directory.h"
#include "../../ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfo.h"
#include "ShapeWriter.h"
#include "StylesWriter.h"
#include "../../Common/DocxFormat/Source/SystemUtility/SystemUtility.h"
#include "../../ASCOfficePPTXFile/Editor/DefaultNotesMaster.h"
#include "../../ASCOfficePPTXFile/Editor/DefaultNotesTheme.h"
#include "Converter.h"
namespace NSPresentationEditor
{
namespace NSPPTXWriterConst
{
static CString g_string_rels_presentation = _T("\
\
\
\
\
");
static CString g_string_core = _T("\
\
Slide 1\
OnlyOffice\
OnlyOffice\
1\
");
}
};
NSPresentationEditor::CPPTXWriter::CPPTXWriter()
{
m_strTempDirectory = FileSystem::Directory::GetTempPath() + FILE_SEPARATOR_STR + _T("TempPPTX");
m_strDstFileName = FileSystem::Directory::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();
FileSystem::Directory::CreateDirectory(m_strTempDirectory);
CFile oFile;
CString strMemory = _T("");
// _rels
FileSystem::Directory::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
FileSystem::Directory::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
FileSystem::Directory::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();
FileSystem::Directory::CreateDirectory(m_strTempDirectory);
CFile oFile;
CString strMemory = _T("");
// _rels
FileSystem::Directory::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
FileSystem::Directory::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
FileSystem::Directory::CreateDirectory(m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt"));
WritePresInfo();
WriteAll();
}
void NSPresentationEditor::CPPTXWriter::CloseFile()
{
m_oManager.Clear();
}
void NSPresentationEditor::CPPTXWriter::WriteContentTypes()
{
CString strContentTypes = _T("\
\
\
\
\
\
\
\
\
\
\
");
strContentTypes += _T("\
\
\
\
\
");
int nThemes = (int)m_pDocument->m_arThemes.size();
int nIndexLayout = 0;
for (int nT = 0; nT < nThemes; ++nT)
{
CString strTheme = _T("");
strTheme.Format(_T("\
"),
nT + 1, nT + 1);
strContentTypes += strTheme;
int nCountL = (int)m_pDocument->m_arThemes[nT].m_arLayouts.size();
for (int nL = 0; nL < nCountL; ++nL, ++nIndexLayout)
{
CString strL = _T("");
strL.Format(_T(""), nIndexLayout + 1);
strContentTypes += strL;
}
}
CString strNotesTheme = _T("");
strNotesTheme.Format(_T(""),
nThemes + 1);
strContentTypes += strNotesTheme;
strContentTypes += _T("");
int nCountS = (int)m_pDocument->m_arSlides.size();
for (int nS = 0; nS < nCountS; ++nS)
{
CString strS = _T("");
strS.Format(_T(""), nS + 1);
strContentTypes += strS;
CString strN = _T("");
strN.Format(_T(""), nS + 1);
strContentTypes += strN;
}
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)
{
CString str1 = _T("\
\
0\
0\
OnlyOffice\
On-screen Show (4:3)\
0");
oFile.WriteStringUTF8(str1);
CString str2 = _T("");
str2.Format(_T("%d"), (int)m_pDocument->m_arSlides.size());
oFile.WriteStringUTF8(str2);
CString str3 = _T("0\
0\
2\
false\
\
");
oFile.WriteStringUTF8(str3);
int nCountThemes = (int)m_pDocument->m_arThemes.size();
int nCountSlides = (int)m_pDocument->m_arSlides.size();
CString strThemes = _T("");
strThemes.Format(_T("Theme%d"), nCountThemes);
CString strSlides = _T("");
strSlides.Format(_T("Slide Titles%d"), nCountSlides);
CString str4 = _T("");
str4.Format(_T(""), nCountSlides + nCountThemes);
str4 = strThemes + strSlides + str4;
oFile.WriteStringUTF8(str4);
CString strMemory = _T("");
for (int i = 1; i <= nCountThemes; ++i)
{
CString strMem = _T("");
strMem.Format(_T("Theme %d"), i);
strMemory += strMem;
}
for (int i = 1; i <= nCountSlides; ++i)
{
CString strMem = _T("");
strMem.Format(_T("Slide %d"), i);
strMemory += strMem;
}
CString str5 = _T("\
\
\
false\
false\
false\
1.0000\
");
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"));
CString str = _T("\
");
oFile.WriteStringUTF8(str);
oFile.CloseFile();
// presProps.xml
str = _T("\
\
\
\
\
\
");
oFile.CreateFile(m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR + _T("presProps.xml"));
oFile.WriteStringUTF8(str);
oFile.CloseFile();
// viewProps.xml
str = _T("\
\
\
\
\
");
oFile.CreateFile(m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR + _T("viewProps.xml"));
oFile.WriteStringUTF8(str);
oFile.CloseFile();
// presentation.xml + _rels/presentation.xml.rels
CString strPresRels;
CString strPresMasters = _T("");
CString strPresSlides = _T("");
size_t nCountLayouts = 0;
size_t nCountThemes = m_pDocument->m_arThemes.size();
for (size_t nIndexTheme = 0; nIndexTheme < nCountThemes; ++nIndexTheme)
{
CString strRels = _T("");
strRels.Format(_T(""), 2 * nIndexTheme + 1, nIndexTheme + 1);
strPresRels += strRels;
strRels = _T("");
strRels.Format(_T(""), 2 * nIndexTheme + 2, nIndexTheme + 1);
strPresRels += strRels;
strRels = _T("");
strRels.Format(_T(""), 0x80000000 + nCountLayouts, 2 * nIndexTheme + 1);
nCountLayouts += m_pDocument->m_arThemes[nIndexTheme].m_arLayouts.size();
nCountLayouts += 1;
strPresMasters += strRels;
}
int nCurrentRels = (int)(2 * nCountThemes + 1);
size_t nCountSlides = m_pDocument->m_arSlides.size();
for (size_t nIndexSlide = 0; nIndexSlide < nCountSlides; ++nIndexSlide, ++nCurrentRels)
{
CString strRels = _T("");
strRels.Format(_T(""), nCurrentRels, nIndexSlide + 1);
strPresRels += strRels;
strRels = _T("");
strRels.Format(_T(""), 256 + nIndexSlide, nCurrentRels);
strPresSlides += strRels;
}
CString strNotesIDs = _T("");
strNotesIDs.Format(_T(""), nCurrentRels);
CString strRels0 = _T("");
strRels0.Format(_T(""), nCurrentRels);
++nCurrentRels;
CString strRels1 = _T("");
strRels1.Format(_T(""), nCurrentRels++);
CString strRels2 = _T("");
strRels2.Format(_T(""), nCurrentRels++);
CString strRels3 = _T("");
strRels3.Format(_T(""), nCurrentRels++);
strPresRels = _T("") + strPresRels + strRels0 + strRels1 + strRels2 + strRels3 + _T("");
CString strPptRels = m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR + _T("_rels");
FileSystem::Directory::CreateDirectory(strPptRels);
oFile.CreateFile(strPptRels + FILE_SEPARATOR_STR + _T("presentation.xml.rels"));
oFile.WriteStringUTF8(strPresRels);
oFile.CloseFile();
CString strSizePres = _T("");
strSizePres.Format(_T(""),
m_pDocument->m_oInfo.m_lUnitsHor, m_pDocument->m_oInfo.m_lUnitsVer, m_pDocument->m_oInfo.m_lUnitsVer, m_pDocument->m_oInfo.m_lUnitsHor);
CString 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("");
CString strPres = _T("");
strPres += _T("m_bRtl))
{
strPres += _T(" rtl=\"1\"");
}
strPres += _T(">");
strPres += _T("") + strPresMasters + _T("");
strPres += strNotesIDs ;
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()
{
CString strPptDirectory = m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR ;
FileSystem::Directory::CreateDirectory(strPptDirectory + _T("media"));
FileSystem::Directory::CreateDirectory(strPptDirectory + _T("theme"));
FileSystem::Directory::CreateDirectory(strPptDirectory + _T("slideMasters"));
FileSystem::Directory::CreateDirectory(strPptDirectory + _T("slideMasters") + FILE_SEPARATOR_STR + _T("_rels"));
FileSystem::Directory::CreateDirectory(strPptDirectory + _T("slideLayouts"));
FileSystem::Directory::CreateDirectory(strPptDirectory + _T("slideLayouts") + FILE_SEPARATOR_STR + _T("_rels"));
FileSystem::Directory::CreateDirectory(strPptDirectory + _T("slides"));
FileSystem::Directory::CreateDirectory(strPptDirectory + _T("slides") + FILE_SEPARATOR_STR + _T("_rels"));
FileSystem::Directory::CreateDirectory(strPptDirectory + _T("notesMasters"));
FileSystem::Directory::CreateDirectory(strPptDirectory + _T("notesMasters") + FILE_SEPARATOR_STR + _T("_rels"));
FileSystem::Directory::CreateDirectory(strPptDirectory + _T("notesSlides"));
FileSystem::Directory::CreateDirectory(strPptDirectory + _T("notesSlides") + FILE_SEPARATOR_STR + _T("_rels"));
CString strNotesTheme = _T("");
strNotesTheme.Format(_T("theme%d.xml"), (int)m_pDocument->m_arThemes.size() + 1);
strNotesTheme = strPptDirectory + _T("theme") + FILE_SEPARATOR_STR + strNotesTheme;
Writers::DefaultNotesThemeWriter writerNotesTheme;
writerNotesTheme.Write( strNotesTheme);
CString strNotesMaster = strPptDirectory + _T("notesMasters") + FILE_SEPARATOR_STR + _T("notesMaster1.xml");
Writers::DefaultNotesMasterWriter writerNotesMaster;
writerNotesMaster.Write(strNotesMaster);
CString strNotesMasterRels = strPptDirectory + _T("notesMasters") + FILE_SEPARATOR_STR +_T("_rels");
FileSystem::Directory::CreateDirectory(strNotesMasterRels);
CString strThemeNotesNum = _T("");
strThemeNotesNum.Format(_T("%d"), (int)m_pDocument->m_arThemes.size() + 1);
CString strVal = _T("\
\
");
CString strNotesMasterRelsFile = strNotesMasterRels+ FILE_SEPARATOR_STR + _T("notesMaster1.xml.rels");
CFile oFileRels;
oFileRels.CreateFile(strNotesMasterRelsFile);
oFileRels.WriteStringUTF8(strVal);
oFileRels.CloseFile();
// -----------------------------------------------------
WriteThemes();
WriteSlides();
}
void NSPresentationEditor::CPPTXWriter::WriteThemes()
{
CString strPptDirectory = m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR ;
int nCount = (int)m_pDocument->m_arThemes.size();
int nStartLayout = 0;
for (int nIndexTheme = 0; nIndexTheme < nCount; ++nIndexTheme)
{
CTheme* pTheme = &m_pDocument->m_arThemes[nIndexTheme];
CString strThemeFile;
strThemeFile.Format(_T("theme%d.xml"), nIndexTheme + 1);
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 (int i = 0 ; i < pTheme->m_arExtraColorScheme.size(); i++)
{
CString str;
str.Format(_T(" %d"), i + 1);
WriteColorScheme(oStringWriter, pTheme->m_sThemeName + string2std_string(str), pTheme->m_arExtraColorScheme[i], true); //extra
}
oStringWriter.WriteString(std::wstring(L""));
oStringWriter.WriteString(std::wstring(L""));
oFile.WriteStringUTF8(oStringWriter.GetData());
oFile.CloseFile();
// теперь masterslide
CRelsGenerator oRels(&m_oManager);
int nCountLayouts = (int)pTheme->m_arLayouts.size();
oRels.StartMaster(nIndexTheme, nStartLayout, nCountLayouts);
CStringWriter oWriter;
CString str1 = _T("\
\
");
oWriter.WriteString(str1);
if (pTheme->m_bIsBackground)
{
WriteBackground(oWriter, oRels, pTheme->m_oBackground);
}
CString strElems = _T("\
");
oWriter.WriteString(strElems);
size_t nElements = pTheme->m_arElements.size();
for (size_t nEl = 0; nEl < nElements; ++nEl)
{
if (isBodyPlaceholder(pTheme->m_arElements[nEl]->m_lPlaceholderType))
pTheme->m_arElements[nEl]->m_lPlaceholderType =100; //body тип прописывать !!
WriteElement(oWriter, oRels, pTheme->m_arElements[nEl]);
}
oWriter.WriteString(std::wstring(L""));
CString strOverrideColorScheme = _T("");
oWriter.WriteString(strOverrideColorScheme);
oWriter.WriteString(std::wstring(L""));
size_t __nCountLayouts = 0;
for (int nIndexLayout = 0; nIndexLayout < nCountLayouts; ++nIndexLayout)
{
CString strMasterLayout = _T("");
strMasterLayout.Format(_T(""), 0x80000000 + nIndexTheme + 1 + nStartLayout + nIndexLayout, nIndexLayout + 1);
oWriter.WriteString(strMasterLayout);
WriteLayout(pTheme->m_arLayouts[nIndexLayout], nIndexLayout, nStartLayout, nIndexTheme);
}
oWriter.WriteString(std::wstring(L""));
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""));
CString strSlideMasterFile;
strSlideMasterFile.Format(_T("slideMaster%d.xml"), nIndexTheme + 1);
strSlideMasterFile = strPptDirectory + _T("slideMasters") + FILE_SEPARATOR_STR + strSlideMasterFile;
oFile.CreateFile(strSlideMasterFile);
CString strMaster = oWriter.GetData();
oFile.WriteStringUTF8(strMaster);
oFile.CloseFile();
oRels.CloseRels();
CString strSlideMasterRelsFile;
strSlideMasterRelsFile.Format(_T("slideMaster%d.xml.rels"), nIndexTheme + 1);
strSlideMasterRelsFile = strPptDirectory + _T("slideMasters") + FILE_SEPARATOR_STR + _T("_rels") + FILE_SEPARATOR_STR + strSlideMasterRelsFile;
oRels.SaveRels(strSlideMasterRelsFile);
nStartLayout += nCountLayouts;
}
}
void NSPresentationEditor::CPPTXWriter::WriteColorScheme(CStringWriter& oStringWriter, const std::wstring & name, const std::vector & colors, bool extra)
{
if (colors.size() < 1)
{
oStringWriter.WriteString(std::wstring(L"\
\
\
\
\
"));
return;
}
if (extra)
oStringWriter.WriteString(std::wstring(L""));
oStringWriter.WriteString(std::wstring(L""));
CString strVal;
strVal.Format(_T(""), colors[14].GetLONG_RGB());
oStringWriter.WriteString(strVal);
strVal.Format(_T(""), colors[13].GetLONG_RGB());
oStringWriter.WriteString(strVal);
strVal.Format(_T(""), colors[16].GetLONG_RGB());
oStringWriter.WriteString(strVal);
strVal.Format(_T(""), colors[15].GetLONG_RGB());
oStringWriter.WriteString(strVal);
strVal.Format(_T(""), colors[5].GetLONG_RGB());
oStringWriter.WriteString(strVal);
strVal.Format(_T(""), colors[6].GetLONG_RGB());
oStringWriter.WriteString(strVal);
strVal.Format(_T(""), colors[7].GetLONG_RGB());
oStringWriter.WriteString(strVal);
strVal.Format(_T(""), colors[8].GetLONG_RGB());
oStringWriter.WriteString(strVal);
strVal.Format(_T(""), colors[9].GetLONG_RGB());
oStringWriter.WriteString(strVal);
strVal.Format(_T(""), colors[10].GetLONG_RGB());
oStringWriter.WriteString(strVal);
strVal.Format(_T(""), colors[11].GetLONG_RGB());
oStringWriter.WriteString(strVal);
strVal.Format(_T(""), colors[12].GetLONG_RGB());
oStringWriter.WriteString(strVal);
oStringWriter.WriteString(std::wstring(L""));
if (extra)
{
oStringWriter.WriteString(std::wstring(L""));
oStringWriter.WriteString(std::wstring(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)
{
CImageElement* pImageElem = dynamic_cast(pElement);
if (pImageElem)
{
pImageElem->m_oMetric = m_pDocument->m_oInfo;
pImageElem->NormalizeCoordsByMetric();
m_pShapeWriter->SetShape(pImageElem);
}
CShapeElement* pShapeElem = dynamic_cast(pElement);
if (pShapeElem)
{
pShapeElem->m_oMetric = m_pDocument->m_oInfo;
pShapeElem->NormalizeCoordsByMetric();
m_pShapeWriter->SetShape(pShapeElem);
}
if (pImageElem || pShapeElem)
{
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);
}
CString 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();
CString strXml = oWriter.GetData();
CString strFile = _T("");
strFile.Format(_T("slideLayout%d.xml"), nIndexLayout + nStartLayout + 1);
CFile oFile;
CString 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 = _T("");
strFile.Format(_T("slideLayout%d.xml.rels"), nIndexLayout + nStartLayout + 1);
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, nIndexSlide);
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, nIndexSlide);
}
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""));
oWriter.WriteString(std::wstring(L""));
oWriter.WriteString(std::wstring(L""));
oRels.CloseRels();
CString strXml = oWriter.GetData();
CString strFile = _T("");
strFile.Format(_T("slide%d.xml"), nIndexSlide + 1);
CString 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 = _T("");
strFile.Format(_T("slide%d.xml.rels"), nIndexSlide + 1);
oRels.SaveRels(strFileSlidePath + _T("_rels") + FILE_SEPARATOR_STR + strFile);
}
void NSPresentationEditor::CPPTXWriter::WriteSlides()
{
size_t nCountSlides = m_pDocument->m_arSlides.size();
for (size_t nIndexS = 0; nIndexS < nCountSlides; ++nIndexS)
{
CRelsGenerator::StartNotes((int)nIndexS, m_strTempDirectory, m_pDocument->m_arSlides[nIndexS]->m_strComment);
WriteSlide((int)nIndexS);
}
}