Correct and rewrite roundTrip theme

This commit is contained in:
ivaz28
2021-09-14 16:23:34 +03:00
parent 0a702d44e4
commit c5d85bc2b9
5 changed files with 56 additions and 67 deletions

View File

@ -608,9 +608,11 @@ void PPT_FORMAT::CPPTXWriter::WriteAll()
void PPT_FORMAT::CPPTXWriter::WriteThemes()
{
int nStartLayout = 0, nIndexTheme = 0;
auto arrRT = m_pDocument->getArrRoundTripTheme();
auto arrRT = m_pUserInfo->getRoundTripTheme(1);
auto arrRTNote = m_pUserInfo->getRoundTripTheme(2);
auto arrRTHandout = m_pUserInfo->getRoundTripTheme(3);
// if (arrRT.empty()) // - см баг 52046
if (arrRT.empty()) // - см баг 52046
{
for (size_t i = 0; i < m_pDocument->m_arThemes.size(); i++)
{
@ -618,25 +620,26 @@ void PPT_FORMAT::CPPTXWriter::WriteThemes()
WriteTheme(m_pDocument->m_arThemes[i], nIndexTheme, nStartLayout);
m_pShapeWriter->m_pTheme = NULL;
}
}
// else
// {
// WriteRoundTripThemes(arrRT, nIndexTheme, nStartLayout);
// }
WriteTheme(m_pDocument->m_pNotesMaster, nIndexTheme, nStartLayout);
WriteTheme(m_pDocument->m_pHandoutMaster, nIndexTheme, nStartLayout);
WriteTheme(m_pDocument->m_pNotesMaster, nIndexTheme, nStartLayout);
WriteTheme(m_pDocument->m_pHandoutMaster, nIndexTheme, nStartLayout);
}
else
{
WriteRoundTripThemes(arrRT, nIndexTheme, nStartLayout);
WriteRoundTripThemes(arrRTNote, nIndexTheme, nStartLayout);
WriteRoundTripThemes(arrRTHandout, nIndexTheme, nStartLayout);
}
}
void CPPTXWriter::WriteRoundTripThemes(const std::vector<CRecordRoundTripThemeAtom*>& arrRTThemes, int& nIndexTheme, int & nStartLayout)
{
PPT_FORMAT::CRelsGenerator themeRels(&m_oManager);
std::unordered_set<std::string> writedFilesHash;
int i = 0;
for (const auto* pRTT : arrRTThemes)
{
if ((int)m_pDocument->m_arThemes.size() > i)
m_pShapeWriter->m_pTheme = m_pDocument->m_arThemes[i++].get();
if ((int)m_pDocument->m_arThemes.size() >= nIndexTheme)
m_pShapeWriter->m_pTheme = m_pDocument->m_arThemes[nIndexTheme-1].get();
if (pRTT == nullptr)
continue;
@ -700,35 +703,9 @@ void CPPTXWriter::WriteRoundTripThemes(const std::vector<CRecordRoundTripThemeAt
oFile.WriteFile(utf8Data, utf8DataSize);
wasThemeWrite = true;
WriteLayoutAfterTheme(m_pDocument->m_arThemes[nIndexTheme-1], nIndexTheme, nStartLayout);
// clear bytes
writedFilesHash.insert(strHash);
RELEASEOBJECT(utf8Data);
utf8DataSize = 0;
oFile.CloseFile();
}
}
// write themeOverride
UINT nIndexOverride = 0;
for (auto& strOverridePath : arrOverridePaths)
{
// read file bytes
NSFile::CFileBinary::ReadAllBytes(strOverridePath, &utf8Data, utf8DataSize);
// compare hash
auto strHash = CFile::md5(utf8Data, utf8DataSize);
// cp file with new name or write bytes
if (writedFilesHash.find(strHash) == writedFilesHash.end())
{
std::wstring strThemeFile = L"themeOverride" + std::to_wstring(++nIndexOverride) + L".xml";
strThemeFile = strPptDirectory + _T("theme") + FILE_SEPARATOR_STR + strThemeFile;
NSFile::CFileBinary oFile;
oFile.CreateFileW(strThemeFile);
oFile.WriteFile(utf8Data, utf8DataSize);
wasThemeWrite = true;
// need to rewrite layout. To add roundTripCompositeMasterId12Atom
if (nIndexTheme < (int)m_pDocument->m_arThemes.size())
WriteLayoutAfterTheme(m_pDocument->m_arThemes[nIndexTheme-1], nIndexTheme, nStartLayout);
// clear bytes
writedFilesHash.insert(strHash);

View File

@ -1141,6 +1141,40 @@ void CPPTUserInfo::LoadGroupShapeContainer(CRecordGroupShapeContainer* pGroupCon
m_current_elements = m_current_elements->front()->m_pParentElements;
}
}
std::vector<CRecordRoundTripThemeAtom *> CPPTUserInfo::getRoundTripTheme(int type) const
{
std::vector<CRecordRoundTripThemeAtom *> arrRTTheme;
switch (type)
{
case 1:
for (const auto& slideIter : m_mapMasters)
{
auto* slideContainer = slideIter.second;
if (!slideContainer) continue;
slideContainer->GetRecordsByType(&arrRTTheme, false);
}
break;
case 2:
for (const auto& slideIter : m_mapNotesMasters)
{
auto* slideContainer = slideIter.second;
if (!slideContainer) continue;
slideContainer->GetRecordsByType(&arrRTTheme, false);
}
break;
case 3:
for (const auto& slideIter : m_mapHandoutMasters)
{
auto* slideContainer = slideIter.second;
if (!slideContainer) continue;
slideContainer->GetRecordsByType(&arrRTTheme, false);
}
break;
}
return arrRTTheme;
}
CElementPtr CPPTUserInfo::AddLayoutSlidePlaceholder (CSlide *pSlide, int placeholderType, CLayout *pLayout, bool idx_only)
{
CElementPtr pElement;
@ -1633,18 +1667,6 @@ void CPPTUserInfo::LoadMainMaster(_UINT32 dwMasterID)
}
int lLayoutID = AddNewLayout(pTheme, pMaster, false, true);
for (auto& oMaster : m_mapMasters)
if (oMaster.second != nullptr)
oMaster.second->GetRecordsByType(&pTheme->m_arrZipXml, false);
// for (auto& oNoteMaster : m_mapNotesMasters)
// if (oNoteMaster.second != nullptr)
// oNoteMaster.second->GetRecordsByType(&pTheme->m_arrZipXml, false);
// for (auto& oHandoutMaster : m_mapHandoutMasters)
// if (oHandoutMaster.second != nullptr)
// oHandoutMaster.second->GetRecordsByType(&pTheme->m_arrZipXml, false);
if (lLayoutID >= 0 && false == pTheme->m_arLayouts.empty())
{
CLayout *pLayout_ = pTheme->m_arLayouts.back().get();

View File

@ -363,4 +363,8 @@ public:
void LoadGroupShapeContainer(CRecordGroupShapeContainer* pGroup, std::vector<CElementPtr>* pParentElements,
CTheme* pTheme, CLayout* pLayout, CSlideInfo* pThemeWrapper, CSlideInfo* pSlideWrapper, CSlide* pSlide = NULL);
// 1 - master, 2 - note, 3 - handout
std::vector<CRecordRoundTripThemeAtom*> getRoundTripTheme(int type = 1)const;
std::vector<CRecordRoundTripContentMasterInfo12Atom*> getRoundTripLayout();
};

View File

@ -150,17 +150,6 @@ public:
};
}
}
std::vector<CRecordRoundTripThemeAtom*> getArrRoundTripTheme()const
{
std::vector<CRecordRoundTripThemeAtom*> arrRoundTripThemes;
for (const auto& theme : m_arThemes)
{
for (auto* pRoundTripAtom : theme->m_arrZipXml)
arrRoundTripThemes.push_back(pRoundTripAtom);
}
return arrRoundTripThemes;
}
void ResetAutoText(CElementPtr pElement, vector_string const (&placeholdersReplaceString)[3])
{

View File

@ -77,8 +77,6 @@ namespace PPT_FORMAT
std::vector<std::vector<CColor>>m_arExtraColorScheme;
std::vector<CRecordRoundTripThemeAtom*> m_arrZipXml;
bool m_bHasDate;
bool m_bHasSlideNumber;
bool m_bHasFooter;
@ -104,7 +102,6 @@ namespace PPT_FORMAT
m_mapTitleLayout.clear();
m_mapGeomToLayout.clear();
m_mapPlaceholders.clear();
m_arrZipXml.clear();
m_sThemeName = L"Default";