From 9728a2277b20bd91d04d67f461019f5f8c62ce72 Mon Sep 17 00:00:00 2001 From: Ivan Morozov Date: Tue, 7 Sep 2021 18:44:31 +0300 Subject: [PATCH 01/19] correct RoundTripTheme layouts --- .../PPTFormatLib/PPTXWriter/Converter.cpp | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp index 33e4caacdf..b0e1d66568 100644 --- a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp +++ b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp @@ -609,7 +609,7 @@ void PPT_FORMAT::CPPTXWriter::WriteThemes() int nStartLayout = 0, nIndexTheme = 0; auto arrRT = m_pDocument->getArrRoundTripTheme(); - //if (arrRT.empty()) - см баг 52046 + if (arrRT.empty()) // - см баг 52046 { for (size_t i = 0; i < m_pDocument->m_arThemes.size(); i++) { @@ -618,10 +618,10 @@ void PPT_FORMAT::CPPTXWriter::WriteThemes() m_pShapeWriter->m_pTheme = NULL; } } - //else - //{ - // WriteRoundTripThemes(arrRT, nIndexTheme, nStartLayout); - //} + else + { + WriteRoundTripThemes(arrRT, nIndexTheme, nStartLayout); + } WriteTheme(m_pDocument->m_pNotesMaster, nIndexTheme, nStartLayout); WriteTheme(m_pDocument->m_pHandoutMaster, nIndexTheme, nStartLayout); @@ -660,6 +660,7 @@ void CPPTXWriter::WriteRoundTripThemes(const std::vectorm_arThemes[nIndexTheme-1], nIndexTheme, nStartLayout); + // clear bytes writedFilesHash.insert(strHash); RELEASEOBJECT(utf8Data); @@ -698,6 +701,35 @@ void CPPTXWriter::WriteRoundTripThemes(const std::vectorm_arThemes.empty()) - WriteLayoutAfterTheme(m_pDocument->m_arThemes[0], nIndexTheme, nStartLayout); +// for (auto& oldTheme : m_pDocument->m_arThemes) +// WriteLayoutAfterTheme(oldTheme, nIndexTheme, nStartLayout); } void PPT_FORMAT::CPPTXWriter::WriteTheme(CThemePtr pTheme, int & nIndexTheme, int & nStartLayout) From 4813f1d07adaee415f0ebb512b638ae1900698bf Mon Sep 17 00:00:00 2001 From: Ivan Morozov Date: Wed, 8 Sep 2021 15:17:28 +0300 Subject: [PATCH 02/19] Removed unnecessary theme/_rels/ --- ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp index b0e1d66568..ca0420f63a 100644 --- a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp +++ b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp @@ -671,6 +671,7 @@ void CPPTXWriter::WriteRoundTripThemes(const std::vector Date: Fri, 10 Sep 2021 18:15:52 +0300 Subject: [PATCH 03/19] rewrite grepPaths() std -> boost --- .../PPTFormatLib/PPTXWriter/Converter.cpp | 33 ++++++++++++------- Common/kernel.pro | 4 +++ DesktopEditor/common/Directory.cpp | 8 ++--- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp index ca0420f63a..524afb4ad0 100644 --- a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp +++ b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp @@ -609,7 +609,7 @@ void PPT_FORMAT::CPPTXWriter::WriteThemes() int nStartLayout = 0, nIndexTheme = 0; auto arrRT = m_pDocument->getArrRoundTripTheme(); - if (arrRT.empty()) // - см баг 52046 +// if (arrRT.empty()) // - см баг 52046 { for (size_t i = 0; i < m_pDocument->m_arThemes.size(); i++) { @@ -618,10 +618,10 @@ void PPT_FORMAT::CPPTXWriter::WriteThemes() m_pShapeWriter->m_pTheme = NULL; } } - else - { - WriteRoundTripThemes(arrRT, nIndexTheme, nStartLayout); - } +// else +// { +// WriteRoundTripThemes(arrRT, nIndexTheme, nStartLayout); +// } WriteTheme(m_pDocument->m_pNotesMaster, nIndexTheme, nStartLayout); WriteTheme(m_pDocument->m_pHandoutMaster, nIndexTheme, nStartLayout); @@ -631,8 +631,12 @@ void CPPTXWriter::WriteRoundTripThemes(const std::vector 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 (pRTT == nullptr) continue; @@ -757,6 +761,7 @@ void CPPTXWriter::WriteRoundTripThemes(const std::vectorm_pTheme = NULL; } // for (auto& oldTheme : m_pDocument->m_arThemes) @@ -823,15 +828,21 @@ void PPT_FORMAT::CPPTXWriter::WriteTheme(CThemePtr pTheme, int & nIndexTheme, in ")); oStringWriter.WriteString(std::wstring(L"")); - oStringWriter.WriteString(std::wstring(L"")); - for (size_t i = 0 ; i < pTheme->m_arExtraColorScheme.size(); i++) + if (pTheme->m_arExtraColorScheme.size()) { - 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"")); + + 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"")); + } else + oStringWriter.WriteString(std::wstring(L"")); - oStringWriter.WriteString(std::wstring(L"")); oStringWriter.WriteString(std::wstring(L"")); oFile.WriteStringUTF8(oStringWriter.GetData()); diff --git a/Common/kernel.pro b/Common/kernel.pro index e682462a75..3c2e8ebb2d 100644 --- a/Common/kernel.pro +++ b/Common/kernel.pro @@ -15,6 +15,10 @@ DEFINES += KERNEL_USE_DYNAMIC_LIBRARY_BUILDING # CONFIG HEADERS += ./kernel_config.h +#BOOST +include($$PWD/../../../Common/3dParty/boost/boost.pri) + + CORE_ROOT_DIR = $$PWD/.. PWD_ROOT_DIR = $$PWD include(../Common/base.pri) diff --git a/DesktopEditor/common/Directory.cpp b/DesktopEditor/common/Directory.cpp index b698ea9c29..324be655a8 100644 --- a/DesktopEditor/common/Directory.cpp +++ b/DesktopEditor/common/Directory.cpp @@ -53,7 +53,7 @@ #endif #include -#include +#include #include "Directory.h" namespace NSDirectory @@ -588,11 +588,11 @@ namespace NSDirectory std::vector GrepPaths(const std::vector &paths, const std::wstring &strRegEx) { std::vector filtredPaths; - std::wregex regEx(strRegEx); - std::wsmatch wSmath; + boost::wregex regEx(strRegEx); + boost::wsmatch wSmath; for (const auto& path : paths) { - if (std::regex_match(path, wSmath, regEx)) + if (boost::regex_match(path, wSmath, regEx)) filtredPaths.push_back(path); } From 0a702d44e451a9c1e103debf5ed75528d95c3a23 Mon Sep 17 00:00:00 2001 From: Ivan Morozov Date: Mon, 13 Sep 2021 12:41:50 +0300 Subject: [PATCH 04/19] replace grepPaths() to PPT Converter.h/cpp --- .../PPTFormatLib/PPTXWriter/Converter.cpp | 26 ++++++++++++++++--- .../PPTFormatLib/PPTXWriter/Converter.h | 2 +- Common/kernel.pro | 3 --- DesktopEditor/common/Directory.cpp | 16 ------------ DesktopEditor/common/Directory.h | 1 - 5 files changed, 23 insertions(+), 25 deletions(-) diff --git a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp index 524afb4ad0..e6adb48dd1 100644 --- a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp +++ b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp @@ -64,6 +64,7 @@ #include #include +#include typedef boost::uuids::detail::md5 MD5; @@ -663,14 +664,14 @@ void CPPTXWriter::WriteRoundTripThemes(const std::vector")); } + +std::vector PPT_FORMAT::CPPTXWriter::GrepPaths(const std::vector &paths, const std::wstring &strRegEx) +{ + std::vector filtredPaths; + try + { + boost::wregex regEx(strRegEx); + boost::wsmatch wSmath; + for (const auto& path : paths) + { + if (boost::regex_match(path, wSmath, regEx)) + filtredPaths.push_back(path); + } + } catch(...) {} + + return filtredPaths; +} diff --git a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.h b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.h index 30481e6159..473410cf31 100644 --- a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.h +++ b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.h @@ -92,7 +92,7 @@ namespace PPT_FORMAT void WriteElement (CStringWriter& oWriter, CRelsGenerator& oRels, CElementPtr pElement, CLayout* pLayout = NULL); void WriteGroup (CStringWriter& oWriter, CRelsGenerator& oRels, CElementPtr pElement, CLayout* pLayout = NULL); void WriteTable (CStringWriter& oWriter, CRelsGenerator& oRels, CElementPtr pElement, CLayout* pLayout = NULL); - + static std::vector GrepPaths(const std::vector &paths, const std::wstring &strRegEx); }; } diff --git a/Common/kernel.pro b/Common/kernel.pro index 3c2e8ebb2d..e41d0e5db4 100644 --- a/Common/kernel.pro +++ b/Common/kernel.pro @@ -15,9 +15,6 @@ DEFINES += KERNEL_USE_DYNAMIC_LIBRARY_BUILDING # CONFIG HEADERS += ./kernel_config.h -#BOOST -include($$PWD/../../../Common/3dParty/boost/boost.pri) - CORE_ROOT_DIR = $$PWD/.. PWD_ROOT_DIR = $$PWD diff --git a/DesktopEditor/common/Directory.cpp b/DesktopEditor/common/Directory.cpp index 324be655a8..0f9d33fd70 100644 --- a/DesktopEditor/common/Directory.cpp +++ b/DesktopEditor/common/Directory.cpp @@ -53,7 +53,6 @@ #endif #include -#include #include "Directory.h" namespace NSDirectory @@ -584,19 +583,4 @@ namespace NSDirectory { return Exists(pathName); } - - std::vector GrepPaths(const std::vector &paths, const std::wstring &strRegEx) - { - std::vector filtredPaths; - boost::wregex regEx(strRegEx); - boost::wsmatch wSmath; - for (const auto& path : paths) - { - if (boost::regex_match(path, wSmath, regEx)) - filtredPaths.push_back(path); - } - - return filtredPaths; - } - } diff --git a/DesktopEditor/common/Directory.h b/DesktopEditor/common/Directory.h index f20f2a07ba..7248bff7e6 100644 --- a/DesktopEditor/common/Directory.h +++ b/DesktopEditor/common/Directory.h @@ -68,7 +68,6 @@ namespace NSDirectory KERNEL_DECL void GetFiles2(std::wstring strDirectory, std::vector& oArray, bool bIsRecursion = false); KERNEL_DECL std::vector GetFiles(std::wstring strDirectory, bool bIsRecursion = false); - KERNEL_DECL std::vector GrepPaths(const std::vector& paths, const std::wstring& strRegEx); KERNEL_DECL std::vector GetDirectories(std::wstring strDirectory); KERNEL_DECL bool Exists(const std::wstring& strDirectory); KERNEL_DECL bool CreateDirectory(const std::wstring& strDirectory); From b451472ba3394c468e9aabfbb484ef26af20f155 Mon Sep 17 00:00:00 2001 From: Ivan Morozov Date: Mon, 13 Sep 2021 17:32:46 +0300 Subject: [PATCH 05/19] Correct RoundTrip theme.xml for Note and Handout --- .../PPTFormatLib/PPTXWriter/Converter.cpp | 24 ++++++----- .../Reader/PPTDocumentInfoOneUser.cpp | 15 +++---- ASCOfficePPTXFile/Editor/Drawing/Document.h | 40 +++++++++++++++++-- ASCOfficePPTXFile/Editor/Drawing/Layout.h | 2 +- ASCOfficePPTXFile/Editor/Drawing/Theme.h | 6 ++- 5 files changed, 65 insertions(+), 22 deletions(-) diff --git a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp index e6adb48dd1..f60c6a2217 100644 --- a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp +++ b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp @@ -608,24 +608,29 @@ void PPT_FORMAT::CPPTXWriter::WriteAll() void PPT_FORMAT::CPPTXWriter::WriteThemes() { int nStartLayout = 0, nIndexTheme = 0; - auto arrRT = m_pDocument->getArrRoundTripTheme(); + auto arrRT = m_pDocument->getArrRoundTripTheme(1); + auto arrRTNote = m_pDocument->getArrRoundTripTheme(2); + auto arrRTHandout = m_pDocument->getArrRoundTripTheme(3); -// if (arrRT.empty()) // - см баг 52046 + if (arrRT.empty() && arrRTNote.empty() && arrRTHandout.empty()) // - см баг 52046 { 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); } } -// else -// { -// WriteRoundTripThemes(arrRT, nIndexTheme, nStartLayout); -// } + else + { + WriteRoundTripThemes(arrRT, nIndexTheme, nStartLayout); - WriteTheme(m_pDocument->m_pNotesMaster, nIndexTheme, nStartLayout); - WriteTheme(m_pDocument->m_pHandoutMaster, nIndexTheme, nStartLayout); + WriteRoundTripThemes(arrRTNote, nIndexTheme, nStartLayout); + WriteRoundTripThemes(arrRTHandout, nIndexTheme, nStartLayout); + } } void CPPTXWriter::WriteRoundTripThemes(const std::vector& arrRTThemes, int& nIndexTheme, int & nStartLayout) @@ -700,7 +705,8 @@ void CPPTXWriter::WriteRoundTripThemes(const std::vectorm_arThemes[nIndexTheme-1], nIndexTheme, nStartLayout); + if (m_pDocument->m_arThemes.size() > (UINT)nIndexTheme) + WriteLayoutAfterTheme(m_pDocument->m_arThemes[nIndexTheme-1], nIndexTheme, nStartLayout); // clear bytes writedFilesHash.insert(strHash); diff --git a/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp b/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp index 810df439d8..fb7d51b10d 100644 --- a/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp +++ b/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp @@ -1636,14 +1636,15 @@ void CPPTUserInfo::LoadMainMaster(_UINT32 dwMasterID) 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); + oMaster.second->GetRecordsByType(&pTheme->m_arrZipXmlMaster, false); -// for (auto& oHandoutMaster : m_mapHandoutMasters) -// if (oHandoutMaster.second != nullptr) -// oHandoutMaster.second->GetRecordsByType(&pTheme->m_arrZipXml, false); + for (auto& oNoteMaster : m_mapNotesMasters) + if (oNoteMaster.second != nullptr) + oNoteMaster.second->GetRecordsByType(&pTheme->m_arrZipXmlNote, false); + + for (auto& oHandoutMaster : m_mapHandoutMasters) + if (oHandoutMaster.second != nullptr) + oHandoutMaster.second->GetRecordsByType(&pTheme->m_arrZipXmlHandout, false); if (lLayoutID >= 0 && false == pTheme->m_arLayouts.empty()) { diff --git a/ASCOfficePPTXFile/Editor/Drawing/Document.h b/ASCOfficePPTXFile/Editor/Drawing/Document.h index 21e606e528..0915d110ea 100644 --- a/ASCOfficePPTXFile/Editor/Drawing/Document.h +++ b/ASCOfficePPTXFile/Editor/Drawing/Document.h @@ -150,17 +150,51 @@ public: }; } } - std::vector getArrRoundTripTheme()const + // 1 - master + // 2 - Note + // 3 - Handout + std::vector getArrRoundTripTheme(int type = 1)const { std::vector arrRoundTripThemes; for (const auto& theme : m_arThemes) { - for (auto* pRoundTripAtom : theme->m_arrZipXml) - arrRoundTripThemes.push_back(pRoundTripAtom); + switch (type) + { + case 1: + { + for (auto* pRoundTripAtom : theme->m_arrZipXmlMaster) + arrRoundTripThemes.push_back(pRoundTripAtom); + break; + } + case 2: + { + for (auto* pRoundTripAtom : theme->m_arrZipXmlNote) + arrRoundTripThemes.push_back(pRoundTripAtom); + break; + } + case 3: + { + for (auto* pRoundTripAtom : theme->m_arrZipXmlHandout) + arrRoundTripThemes.push_back(pRoundTripAtom); + break; + } + } + } return arrRoundTripThemes; } +// std::vector getArrRoundTripLayout()const +// { +// std::vector arrRoundTripLayout; +// for (const auto& theme : m_arThemes) +// { +// for (auto* pRoundTripAtom : theme->m_arrZipXmlMaster) +// arrRoundTripLayout.push_back(pRoundTripAtom); +// } + +// return arrRoundTripLayout; +// } void ResetAutoText(CElementPtr pElement, vector_string const (&placeholdersReplaceString)[3]) { diff --git a/ASCOfficePPTXFile/Editor/Drawing/Layout.h b/ASCOfficePPTXFile/Editor/Drawing/Layout.h index 9f71863ea5..1cb29e835c 100644 --- a/ASCOfficePPTXFile/Editor/Drawing/Layout.h +++ b/ASCOfficePPTXFile/Editor/Drawing/Layout.h @@ -32,7 +32,7 @@ #pragma once #include "Element.h" #include "../../../ASCOfficePPTFile/PPTFormatLib/Enums/_includer.h" - +#include "../../../ASCOfficePPTFile/PPTFormatLib/Records/RoundTripCompositeMainMasterId12Atom.h" namespace PPT_FORMAT { diff --git a/ASCOfficePPTXFile/Editor/Drawing/Theme.h b/ASCOfficePPTXFile/Editor/Drawing/Theme.h index 4e0cf044f4..af94a3b60a 100644 --- a/ASCOfficePPTXFile/Editor/Drawing/Theme.h +++ b/ASCOfficePPTXFile/Editor/Drawing/Theme.h @@ -77,7 +77,9 @@ namespace PPT_FORMAT std::vector>m_arExtraColorScheme; - std::vector m_arrZipXml; + std::vector m_arrZipXmlMaster; + std::vector m_arrZipXmlNote; + std::vector m_arrZipXmlHandout; bool m_bHasDate; bool m_bHasSlideNumber; @@ -104,7 +106,7 @@ namespace PPT_FORMAT m_mapTitleLayout.clear(); m_mapGeomToLayout.clear(); m_mapPlaceholders.clear(); - m_arrZipXml.clear(); + m_arrZipXmlMaster.clear(); m_sThemeName = L"Default"; From c5d85bc2b9ca787f71ae70bf4d6293ca3fbda0fb Mon Sep 17 00:00:00 2001 From: ivaz28 Date: Tue, 14 Sep 2021 16:23:34 +0300 Subject: [PATCH 06/19] Correct and rewrite roundTrip theme --- .../PPTFormatLib/PPTXWriter/Converter.cpp | 59 ++++++------------- .../Reader/PPTDocumentInfoOneUser.cpp | 46 +++++++++++---- .../Reader/PPTDocumentInfoOneUser.h | 4 ++ ASCOfficePPTXFile/Editor/Drawing/Document.h | 11 ---- ASCOfficePPTXFile/Editor/Drawing/Theme.h | 3 - 5 files changed, 56 insertions(+), 67 deletions(-) diff --git a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp index e6adb48dd1..72dd0170b2 100644 --- a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp +++ b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp @@ -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& arrRTThemes, int& nIndexTheme, int & nStartLayout) { PPT_FORMAT::CRelsGenerator themeRels(&m_oManager); std::unordered_set 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::vectorm_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); diff --git a/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp b/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp index 810df439d8..48193b15c6 100644 --- a/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp +++ b/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp @@ -1141,6 +1141,40 @@ void CPPTUserInfo::LoadGroupShapeContainer(CRecordGroupShapeContainer* pGroupCon m_current_elements = m_current_elements->front()->m_pParentElements; } } + +std::vector CPPTUserInfo::getRoundTripTheme(int type) const +{ + std::vector 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(); diff --git a/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.h b/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.h index b7c30a1b9f..8ba1a28e83 100644 --- a/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.h +++ b/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.h @@ -363,4 +363,8 @@ public: void LoadGroupShapeContainer(CRecordGroupShapeContainer* pGroup, std::vector* pParentElements, CTheme* pTheme, CLayout* pLayout, CSlideInfo* pThemeWrapper, CSlideInfo* pSlideWrapper, CSlide* pSlide = NULL); + + // 1 - master, 2 - note, 3 - handout + std::vector getRoundTripTheme(int type = 1)const; + std::vector getRoundTripLayout(); }; diff --git a/ASCOfficePPTXFile/Editor/Drawing/Document.h b/ASCOfficePPTXFile/Editor/Drawing/Document.h index 21e606e528..635512f13a 100644 --- a/ASCOfficePPTXFile/Editor/Drawing/Document.h +++ b/ASCOfficePPTXFile/Editor/Drawing/Document.h @@ -150,17 +150,6 @@ public: }; } } - std::vector getArrRoundTripTheme()const - { - std::vector 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]) { diff --git a/ASCOfficePPTXFile/Editor/Drawing/Theme.h b/ASCOfficePPTXFile/Editor/Drawing/Theme.h index 4e0cf044f4..a551b08cfa 100644 --- a/ASCOfficePPTXFile/Editor/Drawing/Theme.h +++ b/ASCOfficePPTXFile/Editor/Drawing/Theme.h @@ -77,8 +77,6 @@ namespace PPT_FORMAT std::vector>m_arExtraColorScheme; - std::vector 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"; From fb5c459e05cd8243066c91c090b699f69cf0ea0a Mon Sep 17 00:00:00 2001 From: ivaz28 Date: Tue, 14 Sep 2021 16:38:28 +0300 Subject: [PATCH 07/19] Starting roundTrip Layout --- .../PPTFormatLib/PPTXWriter/Converter.cpp | 2 ++ .../PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp index 72dd0170b2..336c53b002 100644 --- a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp +++ b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp @@ -612,6 +612,8 @@ void PPT_FORMAT::CPPTXWriter::WriteThemes() auto arrRTNote = m_pUserInfo->getRoundTripTheme(2); auto arrRTHandout = m_pUserInfo->getRoundTripTheme(3); + auto arrRTLayouts = m_pUserInfo->getRoundTripLayout(); + if (arrRT.empty()) // - см баг 52046 { for (size_t i = 0; i < m_pDocument->m_arThemes.size(); i++) diff --git a/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp b/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp index 48193b15c6..e3fbea5df8 100644 --- a/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp +++ b/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp @@ -1175,6 +1175,19 @@ std::vector CPPTUserInfo::getRoundTripTheme(int typ return arrRTTheme; } +std::vector CPPTUserInfo::getRoundTripLayout() +{ + std::vector arrRTLayout; + for (const auto& slideIter : m_mapMasters) + { + auto* slideContainer = slideIter.second; + if (!slideContainer) continue; + slideContainer->GetRecordsByType(&arrRTLayout, false); + } + + return arrRTLayout; +} + CElementPtr CPPTUserInfo::AddLayoutSlidePlaceholder (CSlide *pSlide, int placeholderType, CLayout *pLayout, bool idx_only) { CElementPtr pElement; From 1fcc07708b85d21d3c33036d36cedaea5fd2852c Mon Sep 17 00:00:00 2001 From: Ivan Morozov Date: Wed, 15 Sep 2021 10:41:30 +0300 Subject: [PATCH 08/19] Revert "Correct RoundTrip theme.xml for Note and Handout" This reverts commit b451472ba3394c468e9aabfbb484ef26af20f155. --- .../PPTFormatLib/PPTXWriter/Converter.cpp | 24 +++++------ .../Reader/PPTDocumentInfoOneUser.cpp | 15 ++++--- ASCOfficePPTXFile/Editor/Drawing/Document.h | 40 ++----------------- ASCOfficePPTXFile/Editor/Drawing/Layout.h | 2 +- ASCOfficePPTXFile/Editor/Drawing/Theme.h | 6 +-- 5 files changed, 22 insertions(+), 65 deletions(-) diff --git a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp index f60c6a2217..e6adb48dd1 100644 --- a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp +++ b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp @@ -608,29 +608,24 @@ void PPT_FORMAT::CPPTXWriter::WriteAll() void PPT_FORMAT::CPPTXWriter::WriteThemes() { int nStartLayout = 0, nIndexTheme = 0; - auto arrRT = m_pDocument->getArrRoundTripTheme(1); - auto arrRTNote = m_pDocument->getArrRoundTripTheme(2); - auto arrRTHandout = m_pDocument->getArrRoundTripTheme(3); + auto arrRT = m_pDocument->getArrRoundTripTheme(); - if (arrRT.empty() && arrRTNote.empty() && arrRTHandout.empty()) // - см баг 52046 +// if (arrRT.empty()) // - см баг 52046 { 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); } } - else - { - WriteRoundTripThemes(arrRT, nIndexTheme, nStartLayout); +// else +// { +// WriteRoundTripThemes(arrRT, nIndexTheme, nStartLayout); +// } - WriteRoundTripThemes(arrRTNote, nIndexTheme, nStartLayout); - WriteRoundTripThemes(arrRTHandout, nIndexTheme, nStartLayout); - } + WriteTheme(m_pDocument->m_pNotesMaster, nIndexTheme, nStartLayout); + WriteTheme(m_pDocument->m_pHandoutMaster, nIndexTheme, nStartLayout); } void CPPTXWriter::WriteRoundTripThemes(const std::vector& arrRTThemes, int& nIndexTheme, int & nStartLayout) @@ -705,8 +700,7 @@ void CPPTXWriter::WriteRoundTripThemes(const std::vectorm_arThemes.size() > (UINT)nIndexTheme) - WriteLayoutAfterTheme(m_pDocument->m_arThemes[nIndexTheme-1], nIndexTheme, nStartLayout); + WriteLayoutAfterTheme(m_pDocument->m_arThemes[nIndexTheme-1], nIndexTheme, nStartLayout); // clear bytes writedFilesHash.insert(strHash); diff --git a/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp b/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp index fb7d51b10d..810df439d8 100644 --- a/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp +++ b/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp @@ -1636,15 +1636,14 @@ void CPPTUserInfo::LoadMainMaster(_UINT32 dwMasterID) for (auto& oMaster : m_mapMasters) if (oMaster.second != nullptr) - oMaster.second->GetRecordsByType(&pTheme->m_arrZipXmlMaster, false); + 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& oNoteMaster : m_mapNotesMasters) - if (oNoteMaster.second != nullptr) - oNoteMaster.second->GetRecordsByType(&pTheme->m_arrZipXmlNote, false); - - for (auto& oHandoutMaster : m_mapHandoutMasters) - if (oHandoutMaster.second != nullptr) - oHandoutMaster.second->GetRecordsByType(&pTheme->m_arrZipXmlHandout, 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()) { diff --git a/ASCOfficePPTXFile/Editor/Drawing/Document.h b/ASCOfficePPTXFile/Editor/Drawing/Document.h index 0915d110ea..21e606e528 100644 --- a/ASCOfficePPTXFile/Editor/Drawing/Document.h +++ b/ASCOfficePPTXFile/Editor/Drawing/Document.h @@ -150,51 +150,17 @@ public: }; } } - // 1 - master - // 2 - Note - // 3 - Handout - std::vector getArrRoundTripTheme(int type = 1)const + std::vector getArrRoundTripTheme()const { std::vector arrRoundTripThemes; for (const auto& theme : m_arThemes) { - switch (type) - { - case 1: - { - for (auto* pRoundTripAtom : theme->m_arrZipXmlMaster) - arrRoundTripThemes.push_back(pRoundTripAtom); - break; - } - case 2: - { - for (auto* pRoundTripAtom : theme->m_arrZipXmlNote) - arrRoundTripThemes.push_back(pRoundTripAtom); - break; - } - case 3: - { - for (auto* pRoundTripAtom : theme->m_arrZipXmlHandout) - arrRoundTripThemes.push_back(pRoundTripAtom); - break; - } - } - + for (auto* pRoundTripAtom : theme->m_arrZipXml) + arrRoundTripThemes.push_back(pRoundTripAtom); } return arrRoundTripThemes; } -// std::vector getArrRoundTripLayout()const -// { -// std::vector arrRoundTripLayout; -// for (const auto& theme : m_arThemes) -// { -// for (auto* pRoundTripAtom : theme->m_arrZipXmlMaster) -// arrRoundTripLayout.push_back(pRoundTripAtom); -// } - -// return arrRoundTripLayout; -// } void ResetAutoText(CElementPtr pElement, vector_string const (&placeholdersReplaceString)[3]) { diff --git a/ASCOfficePPTXFile/Editor/Drawing/Layout.h b/ASCOfficePPTXFile/Editor/Drawing/Layout.h index 1cb29e835c..9f71863ea5 100644 --- a/ASCOfficePPTXFile/Editor/Drawing/Layout.h +++ b/ASCOfficePPTXFile/Editor/Drawing/Layout.h @@ -32,7 +32,7 @@ #pragma once #include "Element.h" #include "../../../ASCOfficePPTFile/PPTFormatLib/Enums/_includer.h" -#include "../../../ASCOfficePPTFile/PPTFormatLib/Records/RoundTripCompositeMainMasterId12Atom.h" + namespace PPT_FORMAT { diff --git a/ASCOfficePPTXFile/Editor/Drawing/Theme.h b/ASCOfficePPTXFile/Editor/Drawing/Theme.h index af94a3b60a..4e0cf044f4 100644 --- a/ASCOfficePPTXFile/Editor/Drawing/Theme.h +++ b/ASCOfficePPTXFile/Editor/Drawing/Theme.h @@ -77,9 +77,7 @@ namespace PPT_FORMAT std::vector>m_arExtraColorScheme; - std::vector m_arrZipXmlMaster; - std::vector m_arrZipXmlNote; - std::vector m_arrZipXmlHandout; + std::vector m_arrZipXml; bool m_bHasDate; bool m_bHasSlideNumber; @@ -106,7 +104,7 @@ namespace PPT_FORMAT m_mapTitleLayout.clear(); m_mapGeomToLayout.clear(); m_mapPlaceholders.clear(); - m_arrZipXmlMaster.clear(); + m_arrZipXml.clear(); m_sThemeName = L"Default"; From d1ac7c9e3456fe32f1cfb0e81317445de51b1ef9 Mon Sep 17 00:00:00 2001 From: Ivan Morozov Date: Wed, 15 Sep 2021 17:21:58 +0300 Subject: [PATCH 09/19] add roundTrip Layout --- .../PPTFormatLib/PPTXWriter/Converter.cpp | 119 ++++++++++++++---- .../PPTFormatLib/PPTXWriter/Converter.h | 3 +- 2 files changed, 97 insertions(+), 25 deletions(-) diff --git a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp index 336c53b002..3d2845e046 100644 --- a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp +++ b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp @@ -116,7 +116,7 @@ void PPT_FORMAT::CPPTXWriter::CreateFile(CPPTUserInfo* pUserInfo ) m_pShapeWriter->InitNextId(); NSDirectory::CreateDirectory(m_strTempDirectory); - NSFile::CFileBinary oFile; + NSFile::CFileBinary oFile; std::wstring strMemory = _T(""); // _rels @@ -160,7 +160,7 @@ void PPT_FORMAT::CPPTXWriter::CreateFile(CDocument* pDocument) m_pShapeWriter->InitNextId(); NSDirectory::CreateDirectory(m_strTempDirectory); - NSFile::CFileBinary oFile; + NSFile::CFileBinary oFile; std::wstring strMemory = _T(""); // _rels @@ -286,7 +286,7 @@ void PPT_FORMAT::CPPTXWriter::WriteContentTypes() } strContentTypes += _T(""); - NSFile::CFileBinary oFile; + NSFile::CFileBinary oFile; oFile.CreateFileW(m_strTempDirectory + FILE_SEPARATOR_STR + _T("[Content_Types].xml")); oFile.WriteStringUTF8(strContentTypes); oFile.CloseFile(); @@ -435,7 +435,7 @@ void PPT_FORMAT::CPPTXWriter::WriteApp(NSFile::CFileBinary& oFile) void PPT_FORMAT::CPPTXWriter::WritePresInfo() { - NSFile::CFileBinary oFile; + NSFile::CFileBinary oFile; // tableStyles.xml oFile.CreateFileW(m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR + _T("tableStyles.xml")); @@ -628,9 +628,11 @@ void PPT_FORMAT::CPPTXWriter::WriteThemes() } else { - WriteRoundTripThemes(arrRT, nIndexTheme, nStartLayout); - WriteRoundTripThemes(arrRTNote, nIndexTheme, nStartLayout); - WriteRoundTripThemes(arrRTHandout, nIndexTheme, nStartLayout); + WriteRoundTripThemes(arrRT, nIndexTheme, nStartLayout); + WriteRoundTripThemes(arrRTNote, nIndexTheme, nStartLayout); + WriteRoundTripThemes(arrRTHandout, nIndexTheme, nStartLayout); + + WriteRoundTripLayouts(arrRTLayouts, nStartLayout); } } @@ -700,15 +702,11 @@ void CPPTXWriter::WriteRoundTripThemes(const std::vectorm_arThemes.size()) - WriteLayoutAfterTheme(m_pDocument->m_arThemes[nIndexTheme-1], nIndexTheme, nStartLayout); - // clear bytes writedFilesHash.insert(strHash); RELEASEOBJECT(utf8Data); @@ -739,13 +737,86 @@ void CPPTXWriter::WriteRoundTripThemes(const std::vectorm_pTheme = NULL; } +} -// for (auto& oldTheme : m_pDocument->m_arThemes) -// WriteLayoutAfterTheme(oldTheme, nIndexTheme, nStartLayout); +void CPPTXWriter::WriteRoundTripLayouts(const std::vector &arrRTLayouts, int &nStartLayout) +{ + for (const auto* pRTL : arrRTLayouts) + { + if (pRTL == nullptr) + continue; + + std::wstring strPptDirectory = m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR ; + std::wstring tempPath = NSDirectory::GetTempPath(); + + auto& zipAtom = *pRTL; + BYTE* zipData = zipAtom.data.first.get(); + ULONG zipDataLen = zipAtom.data.second; + + + NSFile::CFileBinary binFile; + std::wstring tempZipPath = tempPath + FILE_SEPARATOR_STR + L"tempLayout.zip"; + if (!binFile.CreateFileW(tempZipPath)) + continue; + + binFile.WriteFile(zipData, zipDataLen); + binFile.CloseFile(); + + COfficeUtils officeUtils(NULL); + std::wstring tempUnZipPath = tempPath + FILE_SEPARATOR_STR + L"tempLayout"; + NSDirectory::CreateDirectory(tempUnZipPath); + officeUtils.ExtractToDirectory(tempZipPath, tempUnZipPath, NULL, 0); + NSFile::CFileBinary::Remove(tempZipPath); + + auto arrPaths = NSDirectory::GetFiles(tempUnZipPath + FILE_SEPARATOR_STR + L"drs" + FILE_SEPARATOR_STR + L"slideLayouts"); + auto arrLayoutsPaths = GrepPaths(arrPaths, L".*slideLayout[0-9]+.xml"); + + BYTE *utf8Data = NULL; + ULONG utf8DataSize = 0; + bool wasThemeWrite = false; + + // write layout + for (auto& strLayoutPath : arrLayoutsPaths) + { + // read file bytes + NSFile::CFileBinary::ReadAllBytes(strLayoutPath, &utf8Data, utf8DataSize); + + std::wstring strLayoutFile = L"slideLayout" + std::to_wstring(++nStartLayout) + L".xml"; + strLayoutFile = strPptDirectory + _T("slideLayouts") + FILE_SEPARATOR_STR + strLayoutFile; + NSFile::CFileBinary oFile; + oFile.CreateFileW(strLayoutFile); + oFile.WriteFile(utf8Data, utf8DataSize); + wasThemeWrite = true; + + // clear bytes + RELEASEOBJECT(utf8Data); + utf8DataSize = 0; + oFile.CloseFile(); + } + } + + + // write _rels +// if (!arrRelsPaths.empty() && needRels) +// { +// std::wstring relsFolder = strPptDirectory + L"theme" + FILE_SEPARATOR_STR + L"_rels" + FILE_SEPARATOR_STR; +// std::wstring relsName = L"theme" + std::to_wstring(nIndexTheme) + L".xml.rels"; +// std::wstring themeRelsPath = arrRelsPaths[0]; +// NSDirectory::CreateDirectory(relsFolder); + +// NSFile::CFileBinary::ReadAllBytes(arrRelsPaths[0], &utf8Data, utf8DataSize); +// NSFile::CFileBinary oFile; +// oFile.CreateFileW(relsFolder + relsName); +// oFile.WriteFile(utf8Data, utf8DataSize); + +// oFile.CloseFile(); +// RELEASEOBJECT(utf8Data); +// utf8DataSize = 0; +// } } void PPT_FORMAT::CPPTXWriter::WriteTheme(CThemePtr pTheme, int & nIndexTheme, int & nStartLayout) @@ -854,7 +925,7 @@ void PPT_FORMAT::CPPTXWriter::WriteTheme(CThemePtr pTheme, int & nIndexTheme, in WriteBackground(oWriter, oRels, pTheme->m_oBackground); } oWriter.WriteString(L"\ -"); + "); CGroupElement *pGroupElement = !pTheme->m_arElements.empty() ? dynamic_cast(pTheme->m_arElements[0].get()) : NULL; @@ -1189,7 +1260,7 @@ void PPT_FORMAT::CPPTXWriter::WriteLayout(CLayoutPtr pLayout, int nIndexLayout, } std::wstring strElems = _T("\ -"); + "); oWriter.WriteString(strElems); size_t start_index = 0; @@ -1223,7 +1294,7 @@ void PPT_FORMAT::CPPTXWriter::WriteLayout(CLayoutPtr pLayout, int nIndexLayout, std::wstring strXml = oWriter.GetData(); std::wstring strFile = L"slideLayout" + std::to_wstring(nIndexLayout + nStartLayout + 1) + L".xml"; - NSFile::CFileBinary oFile; + NSFile::CFileBinary oFile; std::wstring strFileLayoutPath= m_strTempDirectory + FILE_SEPARATOR_STR + _T("ppt") + FILE_SEPARATOR_STR + _T("slideLayouts") + FILE_SEPARATOR_STR; oFile.CreateFileW(strFileLayoutPath + strFile); oFile.WriteStringUTF8(strXml); @@ -1271,7 +1342,7 @@ void PPT_FORMAT::CPPTXWriter::WriteSlide(int nIndexSlide) } oWriter.WriteString(std::wstring(L"\ -")); + ")); CGroupElement *pGroupElement = !pSlide->m_arElements.empty() ? dynamic_cast(pSlide->m_arElements[0].get()) : NULL; @@ -1313,7 +1384,7 @@ void PPT_FORMAT::CPPTXWriter::WriteSlide(int nIndexSlide) 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; - NSFile::CFileBinary oFile; + NSFile::CFileBinary oFile; oFile.CreateFileW(strFileSlidePath + strFile); oFile.WriteStringUTF8(strXml); oFile.CloseFile(); @@ -1525,7 +1596,7 @@ void PPT_FORMAT::CPPTXWriter::WriteNotes(int nIndexNotes) } oWriter.WriteString(std::wstring(L"\ -")); + ")); CGroupElement *pGroupElement = !pNotes->m_arElements.empty() ? dynamic_cast(pNotes->m_arElements[0].get()) : NULL; @@ -1557,7 +1628,7 @@ void PPT_FORMAT::CPPTXWriter::WriteNotes(int nIndexNotes) 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; - NSFile::CFileBinary oFile; + NSFile::CFileBinary oFile; oFile.CreateFileW(strFileSlidePath + strFile); oFile.WriteStringUTF8(strXml); oFile.CloseFile(); @@ -1610,7 +1681,7 @@ void CPPTXWriter::WriteLayoutAfterTheme(CThemePtr pTheme, const int nIndexTheme, WriteBackground(oWriter, oRels, pTheme->m_oBackground); } oWriter.WriteString(L"\ -"); + "); CGroupElement *pGroupElement = !pTheme->m_arElements.empty() ? dynamic_cast(pTheme->m_arElements[0].get()) : NULL; @@ -1755,7 +1826,7 @@ void CPPTXWriter::WriteLayoutAfterTheme(CThemePtr pTheme, const int nIndexTheme, strSlideMasterRelsFile = strPptDirectory + _T("handoutMasters") + FILE_SEPARATOR_STR + _T("_rels") + FILE_SEPARATOR_STR + strSlideMasterRelsFile; } - NSFile::CFileBinary oFile; + NSFile::CFileBinary oFile; oFile.CreateFileW(strSlideMasterFile); std::wstring strMaster = oWriter.GetData(); oFile.WriteStringUTF8(strMaster); diff --git a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.h b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.h index 473410cf31..ccdbd6dfd3 100644 --- a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.h +++ b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.h @@ -76,7 +76,8 @@ namespace PPT_FORMAT void WriteAll (); void WriteThemes (); void WriteRoundTripThemes(const std::vector &arrRTThemes, int& nIndexTheme, int &nStartLayout); - void WriteTheme (CThemePtr pTheme, int & nIndexTheme, int & nStartLayout); + void WriteRoundTripLayouts(const std::vector &arrRTLayouts, int &nStartLayout); + void WriteTheme (CThemePtr pTheme, int & nIndexTheme, int & nStartLayout); void WriteTheme (CRecordRoundTripThemeAtom *pTheme, int &nIndexTheme); void WriteSlides (); void WriteNotes (); From 6c2b1bf1a99397f4dc4241a29076a2d810fa8db4 Mon Sep 17 00:00:00 2001 From: "Elena.Subbotina" Date: Wed, 22 Sep 2021 16:14:58 +0300 Subject: [PATCH 10/19] fix bug #52667 --- ASCOfficePPTXFile/ASCOfficeDrawingConverter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ASCOfficePPTXFile/ASCOfficeDrawingConverter.cpp b/ASCOfficePPTXFile/ASCOfficeDrawingConverter.cpp index 3d8cf142b8..60c731d7b2 100644 --- a/ASCOfficePPTXFile/ASCOfficeDrawingConverter.cpp +++ b/ASCOfficePPTXFile/ASCOfficeDrawingConverter.cpp @@ -3744,7 +3744,7 @@ std::wstring CDrawingConverter::GetDrawingMainProps(XmlUtils::CXmlNode& oNode, P } } - if ((!oNodeWrap.IsValid() || strWrapType.empty()) && zIndex.is_init()) + if (zIndex.is_init()) { if (*zIndex > 0) { From 709360930a018a8c8c525937f127e79657cda9c2 Mon Sep 17 00:00:00 2001 From: "Elena.Subbotina" Date: Wed, 22 Sep 2021 17:17:34 +0300 Subject: [PATCH 11/19] fix . --- .../DocxFormat/Source/Common/SimpleTypes_Drawing.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Common/DocxFormat/Source/Common/SimpleTypes_Drawing.h b/Common/DocxFormat/Source/Common/SimpleTypes_Drawing.h index 21e2734ed7..df7fc0abcc 100644 --- a/Common/DocxFormat/Source/Common/SimpleTypes_Drawing.h +++ b/Common/DocxFormat/Source/Common/SimpleTypes_Drawing.h @@ -6699,7 +6699,7 @@ namespace SimpleTypes parameterId_nodeVertAlign = 16, parameterId_fallback = 17, parameterId_txDir = 18, - parameterId_775_pyraAcctPos = 19, + parameterId_pyraAcctPos = 19, parameterId_pyraAcctTxMar = 20, parameterId_txBlDir = 21, parameterId_txAnchorHorz = 22, @@ -6727,7 +6727,7 @@ namespace SimpleTypes parameterId_lnSpCh = 44, parameterId_lnSpAfChP = 45, parameterId_rtShortDist = 46, - parameterId_lignTx = 47, + parameterId_alignTx = 47, parameterId_pyraLvlNode = 48, parameterId_pyraAcctBkgdNode = 49, parameterId_pyraAcctTxNode = 50, @@ -6763,7 +6763,7 @@ namespace SimpleTypes else if (L"nodeVertAlign" == sValue) this->m_eValue = parameterId_nodeVertAlign; else if (L"fallback" == sValue) this->m_eValue = parameterId_fallback; else if (L"txDir" == sValue) this->m_eValue = parameterId_txDir; - else if (L"77 pyraAcctPos" == sValue) this->m_eValue = parameterId_775_pyraAcctPos; + else if (L"pyraAcctPos" == sValue) this->m_eValue = parameterId_pyraAcctPos; else if (L"pyraAcctTxMar" == sValue) this->m_eValue = parameterId_pyraAcctTxMar; else if (L"txBlDir" == sValue) this->m_eValue = parameterId_txBlDir; else if (L"txAnchorHorz" == sValue) this->m_eValue = parameterId_txAnchorHorz; @@ -6791,7 +6791,7 @@ namespace SimpleTypes else if (L"lnSpCh" == sValue) this->m_eValue = parameterId_lnSpCh; else if (L"lnSpAfChP" == sValue) this->m_eValue = parameterId_lnSpAfChP; else if (L"rtShortDist" == sValue) this->m_eValue = parameterId_rtShortDist; - else if (L"lignTx" == sValue) this->m_eValue = parameterId_lignTx; + else if (L"alignTx" == sValue) this->m_eValue = parameterId_alignTx; else if (L"pyraLvlNode" == sValue) this->m_eValue = parameterId_pyraLvlNode; else if (L"pyraAcctBkgdNode" == sValue) this->m_eValue = parameterId_pyraAcctBkgdNode; else if (L"pyraAcctTxNode" == sValue) this->m_eValue = parameterId_pyraAcctTxNode; @@ -6828,7 +6828,7 @@ namespace SimpleTypes case parameterId_nodeVertAlign: return L"nodeVertAlign"; case parameterId_fallback: return L"fallback"; case parameterId_txDir: return L"txDir"; - case parameterId_775_pyraAcctPos: return L"775 pyraAcctPos"; + case parameterId_pyraAcctPos: return L"pyraAcctPos"; case parameterId_pyraAcctTxMar: return L"pyraAcctTxMar"; case parameterId_txBlDir: return L"txBlDir"; case parameterId_txAnchorHorz: return L"txAnchorHorz"; @@ -6856,7 +6856,7 @@ namespace SimpleTypes case parameterId_lnSpCh: return L"lnSpCh"; case parameterId_lnSpAfChP: return L"lnSpAfChP"; case parameterId_rtShortDist: return L"rtShortDist"; - case parameterId_lignTx: return L"lignTx"; + case parameterId_alignTx: return L"alignTx"; case parameterId_pyraLvlNode: return L"pyraLvlNode"; case parameterId_pyraAcctBkgdNode: return L"pyraAcctBkgdNode"; case parameterId_pyraAcctTxNode: return L"pyraAcctTxNode"; From 931e19048bf1ccf8a7c038e5e9b8db9f4a7ac48c Mon Sep 17 00:00:00 2001 From: "Elena.Subbotina" Date: Thu, 23 Sep 2021 18:02:43 +0300 Subject: [PATCH 12/19] fix bug #52688 --- ASCOfficeDocFile/Common/FormatUtils.h | 3 -- .../TableCellPropertiesMapping.cpp | 6 ++-- .../TablePropertiesMapping.cpp | 35 ++++--------------- 3 files changed, 9 insertions(+), 35 deletions(-) diff --git a/ASCOfficeDocFile/Common/FormatUtils.h b/ASCOfficeDocFile/Common/FormatUtils.h index b7b9dd3440..88fa74e564 100644 --- a/ASCOfficeDocFile/Common/FormatUtils.h +++ b/ASCOfficeDocFile/Common/FormatUtils.h @@ -100,9 +100,6 @@ namespace DocFileFormat typedef std::pair Int_Pair; - static const int gc_nZeroWidth = 222; - - #define ENCODING_UTF16 1200 #define ENCODING_WINDOWS_1250 1250 #define ENCODING_UTF8 65001 diff --git a/ASCOfficeDocFile/DocDocxConverter/TableCellPropertiesMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/TableCellPropertiesMapping.cpp index 4659cdb802..781698ab72 100644 --- a/ASCOfficeDocFile/DocDocxConverter/TableCellPropertiesMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/TableCellPropertiesMapping.cpp @@ -172,9 +172,9 @@ namespace DocFileFormat _gridSpan = 1; nComputedCellWidths += (tdef.rgdxaCenter[ _cellIndex + 1] - tdef.rgdxaCenter[ 0 ]); - nComputedCellWidth += tdef.rgTc80[ _cellIndex].wWidth > 1 ? tdef.rgTc80[ _cellIndex].wWidth : (tdef.rgdxaCenter[ _cellIndex + 1] - tdef.rgdxaCenter[ _cellIndex ]); + nComputedCellWidth += /*tdef.rgTc80[ _cellIndex].wWidth > 1 ? tdef.rgTc80[ _cellIndex].wWidth :*/ // 1bc0f6c0-b226-4bcb-912c-e7f97b009d8a.doc + (tdef.rgdxaCenter[ _cellIndex + 1] - tdef.rgdxaCenter[ _cellIndex ]); //Технические_Требования_1_287_ДИТ.DOC - } if (!IsTableBordersDefined(tapx->grpprl)) @@ -349,7 +349,7 @@ namespace DocFileFormat } XMLTools::XMLElement tcW ( L"w:tcW" ); - + XMLTools::XMLAttribute tcWVal ( L"w:w", FormatUtils::IntToWideString( _width > 1 ? _width : nComputedCellWidth) ); XMLTools::XMLAttribute tcWType ( L"w:type", (_width > 1 || nComputedCellWidth > 0) ? FormatUtils::MapValueToWideString( _ftsWidth, &Global::CellWidthTypeMap[0][0], 4, 5 ) : L"auto"); diff --git a/ASCOfficeDocFile/DocDocxConverter/TablePropertiesMapping.cpp b/ASCOfficeDocFile/DocDocxConverter/TablePropertiesMapping.cpp index 4308e75d2b..b8a9c45501 100644 --- a/ASCOfficeDocFile/DocDocxConverter/TablePropertiesMapping.cpp +++ b/ASCOfficeDocFile/DocDocxConverter/TablePropertiesMapping.cpp @@ -64,11 +64,8 @@ namespace DocFileFormat XMLTools::XMLElement tblCellMar ( L"w:tblCellMar"); XMLTools::XMLElement tblLayout ( L"w:tblLayout"); XMLTools::XMLElement tblpPr ( L"w:tblpPr"); - XMLTools::XMLAttribute layoutType ( L"w:type", L""); + XMLTools::XMLAttribute layoutType ( L"w:type", L"fixed"); - bool bLayoutFixed = true; - //layoutType.SetValue(L"fixed"); - _CP_OPT(short) tblIndent; short gabHalf = 0; short marginLeft = 0; @@ -192,7 +189,6 @@ namespace DocFileFormat if ( iter->Arguments[0] == 1 ) { layoutType.SetValue( L"auto" ); - bLayoutFixed = false; } }break; case sprmTCellPadding: @@ -505,31 +501,12 @@ namespace DocFileFormat //append the grid _tblGrid = new XMLTools::XMLElement( L"w:tblGrid"); - //Если _grid состоит из одних DocFormatUtils::gc_nZeroWidth и layout != "fixed", значит это doc полученный нами при конвертации из html. Таблицу размеров писать не нужно - - bool bWriteGridCol = false; - if (true == bLayoutFixed) - bWriteGridCol = true; - else + for (size_t i = 0; i < _grid->size(); i++) { - for ( size_t i = 0, nSize = _grid->size(); i < nSize; i++ ) - { - if(_grid->at(i) % DocFileFormat::gc_nZeroWidth != 0) - { - bWriteGridCol = true; - break; - } - } - } - if (true == bWriteGridCol) - { - for ( size_t i = 0; i < _grid->size(); i++ ) - { - XMLTools::XMLElement gridCol( L"w:gridCol"); - XMLTools::XMLAttribute gridColW( L"w:w", FormatUtils::IntToWideString( _grid->at( i ) ) ); - gridCol.AppendAttribute( gridColW ); - _tblGrid->AppendChild( gridCol ); - } + XMLTools::XMLElement gridCol(L"w:gridCol"); + XMLTools::XMLAttribute gridColW(L"w:w", FormatUtils::IntToWideString(_grid->at(i))); + gridCol.AppendAttribute(gridColW); + _tblGrid->AppendChild(gridCol); } m_pXmlWriter->WriteString( _tblGrid->GetXMLString() ); From 817b90418f4b61a5fac94cdffcb1975a8dee3bdb Mon Sep 17 00:00:00 2001 From: KirillovIlya Date: Tue, 13 Jul 2021 18:51:14 +0300 Subject: [PATCH 13/19] Implement AutoFit option when saving form to PDF --- .../PdfWriterLibTest/PdfWriterLibTest.cpp | 17 ++++++++++-- PdfWriter/Src/Field.cpp | 26 ++++++++++++++++--- PdfWriter/Src/Field.h | 7 ++++- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.cpp b/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.cpp index 54a370a33f..1040a92827 100644 --- a/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.cpp +++ b/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.cpp @@ -79,13 +79,26 @@ void TestField() CTextField* pField3 = oPdf.CreateTextField(); pField3->SetRequiredFlag(false); pField3->SetCombFlag(true); - pField3->AddPageRect(pPage, TRect(200, 500, 300, 450)); + pField3->AddPageRect(pPage, TRect(000, 500, 300, 450)); pField3->SetFieldName(L"Test123"); pField3->SetFieldHint(L"Hint123"); - pField3->SetMaxLen(10); + //pField3->SetMaxLen(100); pField3->SetTextValue(L"Enter text"); pField3->SetTextAppearance(L"Enter text", NULL, 0, pFont, TRgb(0, 255, 0), 0.5, 40, 1, 14.3); + + CTextField* pField33 = oPdf.CreateTextField(); + pField33->SetRequiredFlag(false); + pField33->SetCombFlag(true); + pField33->AddPageRect(pPage, TRect(000, 400, 300, 350)); + pField33->SetFieldName(L"Test123"); + pField33->SetFieldHint(L"Hint123"); + //pField33->SetMaxLen(100); + pField33->SetAutoFit(true); + pField33->SetTextValue(L"Enter text"); + pField33->SetTextAppearance(L"Enter text", NULL, 0, pFont, TRgb(0, 255, 0), 0.5, 40, 1, 14.3); + + CTextField* pField4 = oPdf.CreateTextField(); pField4->SetRequiredFlag(false); pField4->AddPageRect(pPage, TRect(400, 500, 500, 450)); diff --git a/PdfWriter/Src/Field.cpp b/PdfWriter/Src/Field.cpp index 7120b13f45..271f19e0a7 100644 --- a/PdfWriter/Src/Field.cpp +++ b/PdfWriter/Src/Field.cpp @@ -61,6 +61,8 @@ namespace PdfWriter m_nBorderType = 0; m_dBorderSize = 0; + + m_bAutoFit = false; } void CFieldBase::SetReadOnlyFlag(bool isReadOnly) { @@ -188,9 +190,17 @@ namespace PdfWriter sDA.append(std::to_string(oColor.b)); sDA.append(" rg /"); sDA.append(sFontName); - sDA.append(" "); - sDA.append(std::to_string(dFontSize)); - sDA.append(" Tf"); + + if (IsAutoFit()) + { + sDA.append(" 0 Tf"); + } + else + { + sDA.append(" "); + sDA.append(std::to_string(dFontSize)); + sDA.append(" Tf"); + } const char* sExtGrStateName = NULL; if (fabs(dAlpha - 1.0) > 0.001) @@ -274,12 +284,22 @@ namespace PdfWriter { return m_oBorderColor; } + const bool& CFieldBase::IsAutoFit() const + { + return m_bAutoFit; + } + void CFieldBase::SetAutoFit(const bool& isAutoFit) + { + m_bAutoFit = isAutoFit; + } //---------------------------------------------------------------------------------------- // CTextField //---------------------------------------------------------------------------------------- CTextField::CTextField(CXref* pXref, CDocument* pDocument) : CFieldBase(pXref, pDocument) { Add("FT", "Tx"); + + m_bAutoFit = false; } void CTextField::SetMultilineFlag(bool isMultiLine) { diff --git a/PdfWriter/Src/Field.h b/PdfWriter/Src/Field.h index 896a3e9f97..08247dd98f 100644 --- a/PdfWriter/Src/Field.h +++ b/PdfWriter/Src/Field.h @@ -67,6 +67,8 @@ namespace PdfWriter bool HaveBorder() const; const double& GetBorderSize() const; const TRgb& GetBorderColor() const; + const bool& IsAutoFit() const; + void SetAutoFit(const bool& isAutoFit); protected: @@ -80,6 +82,7 @@ namespace PdfWriter int m_nBorderType; double m_dBorderSize; TRgb m_oBorderColor; + bool m_bAutoFit; }; class CTextField : public CFieldBase @@ -94,13 +97,15 @@ namespace PdfWriter void SetDoNotScrollFlag(bool isDoNotScroll); void SetCombFlag(bool isFlag); void SetRichTextFlag(bool isRichText); - + void SetMaxLen(int nMaxLen); int GetMaxLen() const; bool IsCombFlag() const; private: + + bool m_bAutoFit; }; class CChoiceField : public CFieldBase From e4c1384bbd44ecb780291216c30e9cf05c27a897 Mon Sep 17 00:00:00 2001 From: KirillovIlya Date: Tue, 20 Jul 2021 18:27:28 +0300 Subject: [PATCH 14/19] Add empty functions for future work on field keys --- PdfWriter/Src/Document.cpp | 4 ++++ PdfWriter/Src/Document.h | 2 ++ PdfWriter/Src/Field.cpp | 8 ++++++++ PdfWriter/Src/Field.h | 17 ++++++++++------- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/PdfWriter/Src/Document.cpp b/PdfWriter/Src/Document.cpp index 3b333a6f26..2e2155b6af 100644 --- a/PdfWriter/Src/Document.cpp +++ b/PdfWriter/Src/Document.cpp @@ -919,6 +919,10 @@ namespace PdfWriter ppFields->Add(pField); return pField; + } + void CDocument::CheckFieldName(CFieldBase* pField) + { + } bool CDocument::CheckAcroForm() { diff --git a/PdfWriter/Src/Document.h b/PdfWriter/Src/Document.h index 96c2fa8be0..e26bde0b14 100644 --- a/PdfWriter/Src/Document.h +++ b/PdfWriter/Src/Document.h @@ -83,6 +83,7 @@ namespace PdfWriter class CCheckBoxField; class CRadioGroupField; class CPictureField; + class CFieldBase; //---------------------------------------------------------------------------------------- // CDocument //---------------------------------------------------------------------------------------- @@ -139,6 +140,7 @@ namespace PdfWriter CCheckBoxField* CreateCheckBoxField(); CRadioGroupField* GetRadioGroupField(const std::wstring& wsGroupName); CPictureField* CreatePictureField(); + void CheckFieldName(CFieldBase* pField); private: diff --git a/PdfWriter/Src/Field.cpp b/PdfWriter/Src/Field.cpp index 271f19e0a7..8003f3105a 100644 --- a/PdfWriter/Src/Field.cpp +++ b/PdfWriter/Src/Field.cpp @@ -291,6 +291,14 @@ namespace PdfWriter void CFieldBase::SetAutoFit(const bool& isAutoFit) { m_bAutoFit = isAutoFit; + } + void CFieldBase::SetParent(CFieldBase* pParent) + { + + } + void CFieldBase::AddChild(CFieldBase* pChild) + { + } //---------------------------------------------------------------------------------------- // CTextField diff --git a/PdfWriter/Src/Field.h b/PdfWriter/Src/Field.h index 08247dd98f..a0b07a93b0 100644 --- a/PdfWriter/Src/Field.h +++ b/PdfWriter/Src/Field.h @@ -69,6 +69,8 @@ namespace PdfWriter const TRgb& GetBorderColor() const; const bool& IsAutoFit() const; void SetAutoFit(const bool& isAutoFit); + void SetParent(CFieldBase* pParent); + void AddChild(CFieldBase* pChild); protected: @@ -76,13 +78,14 @@ namespace PdfWriter protected: - CXref* m_pXref; - TRect m_oRect; - CDocument* m_pDocument; - int m_nBorderType; - double m_dBorderSize; - TRgb m_oBorderColor; - bool m_bAutoFit; + CXref* m_pXref; + TRect m_oRect; + CDocument* m_pDocument; + int m_nBorderType; + double m_dBorderSize; + TRgb m_oBorderColor; + bool m_bAutoFit; + CFieldBase* m_pParent; }; class CTextField : public CFieldBase From 00802528e5bc1b74771a145abfcf367512f0fe40 Mon Sep 17 00:00:00 2001 From: KirillovIlya Date: Fri, 3 Sep 2021 02:00:49 +0300 Subject: [PATCH 15/19] Update for PDFWriter --- .../PdfWriterLibTest/PdfWriterLibTest.cpp | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.cpp b/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.cpp index 1040a92827..da086de6ea 100644 --- a/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.cpp +++ b/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.cpp @@ -39,6 +39,8 @@ using namespace PdfWriter; +std::wstring g_wsOutFolder = L"D:\\Work\\Test\\"; + void TestDocument1() { // PageLabels and Encryption @@ -52,7 +54,7 @@ void TestDocument1() oPdf.SetPasswords(L"123", L"qwe"); - oPdf.SaveToFile(L"D:/Test/PDF/Test1.pdf"); + oPdf.SaveToFile(g_wsOutFolder + L"Test1.pdf"); oPdf.Close(); } void TestField() @@ -67,7 +69,7 @@ void TestField() pField1->SetRequiredFlag(true); pField1->AddPageRect(pPage, TRect(0, 100, 100, 0)); pField1->SetFieldName(L"Test"); - pField1->SetFieldHint(L""); + pField1->SetFieldHint(L"Илья"); CTextField* pField2 = oPdf.CreateTextField(); pField2->SetRequiredFlag(false); @@ -114,11 +116,11 @@ void TestField() pComboBox->SetRequiredFlag(false); pComboBox->AddPageRect(pPage, TRect(200, 600, 500, 550)); pComboBox->SetFieldName(L"ComboBox1"); - pComboBox->SetFieldHint(L" "); + pComboBox->SetFieldHint(L"Какой-то текст"); pComboBox->SetTextValue(L"Ilya"); - pComboBox->AddOption(L""); + pComboBox->AddOption(L"Зеленый"); pComboBox->AddOption(L"Green"); - pComboBox->AddOption(L""); + pComboBox->AddOption(L"Зеленый"); pComboBox->SetComboFlag(true); pComboBox->SetEditFlag(false); pComboBox->SetFieldBorder(border_subtype_Solid, TRgb(0, 255, 0), 1, 0, 0, 0); @@ -152,12 +154,12 @@ void TestField() pPictureField->SetRequiredFlag(false); pPictureField->AddPageRect(pPage, TRect(100, 500, 200, 450)); pPictureField->SetFieldName(L"Pic"); - pPictureField->SetFieldHint(L""); + pPictureField->SetFieldHint(L"Картинка"); pPictureField->SetAppearance(); - oPdf.SaveToFile(L"D:/Test/PDF/TestField1.pdf"); + oPdf.SaveToFile(g_wsOutFolder + L"TestField1.pdf"); oPdf.Close(); } void TestDocument2() @@ -189,7 +191,7 @@ void TestDocument2() pOutline11->SetDestination(pDest); - oPdf.SaveToFile(L"D:/Test/PDF/Test2.pdf"); + oPdf.SaveToFile(g_wsOutFolder + L"Test2.pdf"); oPdf.Close(); } void TestDocument3() @@ -358,7 +360,7 @@ void TestDocument3() - oPdf.SaveToFile(L"D:/Test/PDF/Test3.pdf"); + oPdf.SaveToFile(g_wsOutFolder + L"Test3.pdf"); oPdf.Close(); } void TestDocument4() @@ -378,7 +380,7 @@ void TestDocument4() //CAnnotation* pAnnot = oPdf.CreateLinkAnnot(0, TRect(0, 100, 100, 0), pDest); //pAnnot = oPdf.CreateUriLinkAnnot(0, TRect(0, 200, 100, 100), "www.rbc.ru"); - oPdf.SaveToFile(L"D:/Test/PDF/Test4.pdf"); + oPdf.SaveToFile(g_wsOutFolder + L"Test4.pdf"); oPdf.Close(); } void TestDocument5() @@ -522,7 +524,7 @@ void TestDocument5() //pPage->DrawImage(pRawImage, 300, 300, 200, 200); //delete[] pBgra; - oPdf.SaveToFile(L"D:/Test/PDF/Test5.pdf"); + oPdf.SaveToFile(g_wsOutFolder + L"Test5.pdf"); oPdf.Close(); } void TestDocument6() @@ -596,7 +598,7 @@ void TestDocument6() pPage->ClosePath(); pPage->Fill(); - oPdf.SaveToFile(L"D:/Test/PDF/Test6.pdf"); + oPdf.SaveToFile(g_wsOutFolder + L"Test6.pdf"); oPdf.Close(); } void TestDocument7() @@ -661,7 +663,7 @@ void TestDocument7() pPage->EndText(); - oPdf.SaveToFile(L"D:/Test/PDF/Test7.pdf"); + oPdf.SaveToFile(g_wsOutFolder + L"Test7.pdf"); oPdf.Close(); } void TestDocument8() @@ -740,7 +742,7 @@ void TestDocument8() pPage->GrRestore(); - oPdf.SaveToFile(L"D:/Test/PDF/Test8.pdf"); + oPdf.SaveToFile(g_wsOutFolder + L"Test8.pdf"); oPdf.Close(); } void TestDocument9() @@ -768,7 +770,7 @@ void TestDocument9() pPage->GrRestore(); - oPdf.SaveToFile(L"D:/Test/PDF/Test9.pdf"); + oPdf.SaveToFile(g_wsOutFolder + L"Test9.pdf"); oPdf.Close(); } From 9b64445e3e76e5ef344a4a265ca73d2cfbadbb82 Mon Sep 17 00:00:00 2001 From: KirillovIlya Date: Thu, 23 Sep 2021 14:58:40 +0300 Subject: [PATCH 16/19] Rework CFormFieldInfo class and add new parameters --- DesktopEditor/graphics/IRenderer.h | 385 ++++++++++++------ DesktopEditor/graphics/MetafileToRenderer.cpp | 49 ++- 2 files changed, 301 insertions(+), 133 deletions(-) diff --git a/DesktopEditor/graphics/IRenderer.h b/DesktopEditor/graphics/IRenderer.h index 0077e64ccd..dbd8b291dc 100644 --- a/DesktopEditor/graphics/IRenderer.h +++ b/DesktopEditor/graphics/IRenderer.h @@ -307,6 +307,230 @@ public: class CFormFieldInfo { +public: + + enum EScaleType + { + Always = 0x00, + Bigger = 0x01, + Smaller = 0x02, + Never = 0x03 + }; + + class CTextFormPr + { + public: + CTextFormPr() + { + } + void SetTextValue(const std::wstring& wsValue) + { + m_wsTextValue = wsValue; + } + const std::wstring& GetTextValue() const + { + return m_wsTextValue; + } + void SetMaxCharacters(const unsigned int unMax) + { + m_unMaxCharacters = unMax; + } + unsigned int GetMaxCharacters() const + { + return m_unMaxCharacters; + } + void SetComb(const bool& bComb) + { + m_bComb = bComb; + } + bool IsComb() const + { + return m_bComb; + } + void SetAutoFit(const bool& bAutoFit) + { + m_bAutoFit = bAutoFit; + } + bool IsAutoFit() const + { + return m_bAutoFit; + } + void SetMultiLine(const bool& bMultiLine) + { + m_bMultiLine = bMultiLine; + } + bool IsMultiLine() const + { + return m_bMultiLine; + } + + private: + + std::wstring m_wsTextValue; + unsigned int m_unMaxCharacters; + bool m_bComb; + bool m_bAutoFit; + bool m_bMultiLine; + }; + class CDropDownFormPr + { + public: + CDropDownFormPr() + {} + + void SetTextValue(const std::wstring& wsValue) + { + m_wsTextValue = wsValue; + } + const std::wstring& GetTextValue() const + { + return m_wsTextValue; + } + bool IsEditComboBox() const + { + return m_bEditComboBox; + } + void SetEditComboBox(const bool& bEdit) + { + m_bEditComboBox = bEdit; + } + unsigned int GetComboBoxItemsCount() const + { + return m_vComboBoxItems.size(); + } + const std::wstring& GetComboBoxItem(const unsigned int& unIndex) const + { + return m_vComboBoxItems.at(unIndex); + } + void AddComboBoxItem(const std::wstring& wsItem) + { + m_vComboBoxItems.push_back(wsItem); + } + + private: + + std::wstring m_wsTextValue; + bool m_bEditComboBox; + std::vector m_vComboBoxItems; + }; + class CCheckBoxFormPr + { + public: + CCheckBoxFormPr() + {} + bool IsChecked() const + { + return m_bChecked; + } + void SetChecked(const bool& bChecked) + { + m_bChecked = bChecked; + } + unsigned int GetCheckedSymbol() const + { + return m_unCheckedSymbol; + } + void SetCheckedSymbol(const unsigned int& unCheckedSymbol) + { + m_unCheckedSymbol = unCheckedSymbol; + } + unsigned int GetUncheckedSymbol() const + { + return m_unUncheckedSymbol; + } + void SetUncheckedSymbol(const unsigned int& unUncheckedSymbol) + { + m_unUncheckedSymbol = unUncheckedSymbol; + } + void SetCheckedFont(const std::wstring& wsFontName) + { + m_wsCheckedFont = wsFontName; + } + const std::wstring& GetCheckedFontName() const + { + return m_wsCheckedFont; + } + void SetUncheckedFont(const std::wstring& wsFontName) + { + m_wsUncheckedFont = wsFontName; + } + const std::wstring& GetUncheckedFontName() const + { + return m_wsUncheckedFont; + } + bool IsRadioButton() const + { + return (0 == m_wsGroupKey.length()); + } + void SetGroupKey(const std::wstring& wsGroupKey) + { + m_wsGroupKey = wsGroupKey; + } + const std::wstring& GetGroupKey() const + { + return m_wsGroupKey; + } + + private: + + bool m_bChecked; + unsigned int m_unCheckedSymbol; + unsigned int m_unUncheckedSymbol; + std::wstring m_wsCheckedFont; + std::wstring m_wsUncheckedFont; + std::wstring m_wsGroupKey; + }; + class CPictureFormPr + { + public: + CPictureFormPr() + {} + bool IsConstantProportions() const + { + return m_bConstantProportions; + } + void SetConstantProportions(const bool& bConstant) + { + m_bConstantProportions = bConstant; + } + bool IsRespectBorders() const + { + return m_bRespectBorders; + } + void SetRespectBorders(const bool& bRespect) + { + m_bRespectBorders = bRespect; + } + EScaleType GetScaleType() const + { + return m_eScaleType; + } + void SetScaleType(const EScaleType& eType) + { + m_eScaleType = eType; + } + void SetShift(const LONG& lShiftX, const LONG& lShiftY) + { + m_lShiftX = lShiftX; + m_lShiftY = lShiftY; + } + const LONG& GetShiftX() const + { + return m_lShiftX; + } + const LONG& GetShiftY() const + { + return m_lShiftY; + } + + private: + EScaleType m_eScaleType; + bool m_bRespectBorders; + bool m_bConstantProportions; + LONG m_lShiftX; + LONG m_lShiftY; + }; + public: CFormFieldInfo() { @@ -323,6 +547,8 @@ public: m_bPlaceHolder = false; m_nBorderType = 0; + + m_bHaveShd = false; } void SetType(int nType) @@ -410,126 +636,56 @@ public: unG = ((m_lBorderColor >> 8) & 0xFF); unB = ((m_lBorderColor) & 0xFF); } + bool HaveShd() const + { + return m_bHaveShd; + } + void SetShd(const unsigned char& unR, const unsigned char& unG, const unsigned char& unB, const unsigned char& unA) + { + m_bHaveShd = true; + m_lShdColor = (((LONG)(unA << 24)) & 0xFFFFFF) | (((LONG)(unR << 16)) & 0xFFFFFF) | (((LONG)(unG << 8)) & 0xFFFFFF) | (LONG)(unB); + } + void GetShdColor(unsigned char& unR, unsigned char& unG, unsigned char& unB, unsigned char& unA) const + { + unA = ((m_lShdColor >> 24) & 0xFF); + unR = ((m_lShdColor >> 16) & 0xFF); + unG = ((m_lShdColor >> 8) & 0xFF); + unB = ((m_lShdColor) & 0xFF); + } + - // TextFields bool IsTextField() const { return (m_nType == 1); } - void SetTextValue(const std::wstring& wsValue) - { - m_wsTextValue = wsValue; - } - const std::wstring& GetTextValue() const - { - return m_wsTextValue; - } - void SetMaxCharacters(const unsigned int unMax) - { - m_unMaxCharacters = unMax; - } - unsigned int GetMaxCharacters() const - { - return m_unMaxCharacters; - } - void SetComb(const bool& bComb) - { - m_bComb = bComb; - } - bool IsComb() const - { - return m_bComb; - } - - // ComboBox/DropDownList - bool IsComboBox() const + bool IsDropDownList() const { return (m_nType == 2); } - bool IsEditComboBox() const - { - return m_bEditComboBox; - } - void SetEditComboBox(const bool& bEdit) - { - m_bEditComboBox = bEdit; - } - unsigned int GetComboBoxItemsCount() const - { - return m_vComboBoxItems.size(); - } - const std::wstring& GetComboBoxItem(const unsigned int& unIndex) const - { - return m_vComboBoxItems.at(unIndex); - } - void AddComboBoxItem(const std::wstring& wsItem) - { - m_vComboBoxItems.push_back(wsItem); - } - - // CheckBox bool IsCheckBox() const { return (m_nType == 3); } - bool IsChecked() const - { - return m_bChecked; - } - void SetChecked(const bool& bChecked) - { - m_bChecked = bChecked; - } - unsigned int GetCheckedSymbol() const - { - return m_unCheckedSymbol; - } - void SetCheckedSymbol(const unsigned int& unCheckedSymbol) - { - m_unCheckedSymbol = unCheckedSymbol; - } - unsigned int GetUncheckedSymbol() const - { - return m_unUncheckedSymbol; - } - void SetUncheckedSymbol(const unsigned int& unUncheckedSymbol) - { - m_unUncheckedSymbol = unUncheckedSymbol; - } - void SetCheckedFont(const std::wstring& wsFontName) - { - m_wsCheckedFont = wsFontName; - } - const std::wstring& GetCheckedFontName() const - { - return m_wsCheckedFont; - } - void SetUncheckedFont(const std::wstring& wsFontName) - { - m_wsUncheckedFont = wsFontName; - } - const std::wstring& GetUncheckedFontName() const - { - return m_wsUncheckedFont; - } - bool IsRadioButton() const - { - return (0 == m_wsGroupKey.length()); - } - void SetGroupKey(const std::wstring& wsGroupKey) - { - m_wsGroupKey = wsGroupKey; - } - const std::wstring& GetGroupKey() const - { - return m_wsGroupKey; - } - - // Picture bool IsPicture() const { return (m_nType == 4); } + CTextFormPr& GetTextFormPr() + { + return m_oTextPr; + } + CDropDownFormPr& GetDropDownFormPr() + { + return m_oDropDownPr; + } + CCheckBoxFormPr& GetCheckBoxFormPr() + { + return m_oCheckBoxPr; + } + CPictureFormPr& GetPictureFormPr() + { + return m_oPicturePr; + } private: @@ -546,23 +702,14 @@ private: int m_nBorderType; double m_dBorderSize; LONG m_lBorderColor; + bool m_bHaveShd; + LONG m_lShdColor; - // Поля для текстовых форм - std::wstring m_wsTextValue; - unsigned int m_unMaxCharacters; - bool m_bComb; + CTextFormPr m_oTextPr; + CDropDownFormPr m_oDropDownPr; + CCheckBoxFormPr m_oCheckBoxPr; + CPictureFormPr m_oPicturePr; - // Поля для выпадающих списков - bool m_bEditComboBox; - std::vector m_vComboBoxItems; - - // Поля для чекбокса - bool m_bChecked; - unsigned int m_unCheckedSymbol; - unsigned int m_unUncheckedSymbol; - std::wstring m_wsCheckedFont; - std::wstring m_wsUncheckedFont; - std::wstring m_wsGroupKey; }; #define PROPERTY_RENDERER(NameBase, Name, Type) \ diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index 1e0f0ab250..3e9f1f46dd 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -913,47 +913,68 @@ namespace NSOnlineOfficeBinToPdf oInfo.SetBorder(nBorderType, dBorderSize, unR, unG, unB, unA); } + if (nFlags & (1 << 9)) + { + unsigned char unR = ReadByte(current, curindex); + unsigned char unG = ReadByte(current, curindex); + unsigned char unB = ReadByte(current, curindex); + unsigned char unA = ReadByte(current, curindex); + oInfo.SetShd(unR, unG, unB, unA); + } + oInfo.SetType(ReadInt(current, curindex)); if (oInfo.IsTextField()) { - oInfo.SetComb(nFlags & (1 << 20)); + CFormFieldInfo::CTextFormPr oPr = oInfo.GetTextFormPr(); + oPr.SetComb(nFlags & (1 << 20)); if (nFlags & (1 << 21)) - oInfo.SetMaxCharacters(ReadInt(current, curindex)); + oPr.SetMaxCharacters(ReadInt(current, curindex)); if (nFlags & (1 << 22)) - oInfo.SetTextValue(ReadString(current, curindex)); + oPr.SetTextValue(ReadString(current, curindex)); + + oPr.SetAutoFit(nFlags & (1 << 23)); + oPr.SetMultiLine(nFlags & (1 << 24)); } - else if (oInfo.IsComboBox()) + else if (oInfo.IsDropDownList()) { - oInfo.SetEditComboBox(nFlags & (1 << 20)); + CFormFieldInfo::CDropDownFormPr oPr = oInfo.GetDropDownFormPr(); + oPr.SetEditComboBox(nFlags & (1 << 20)); int nItemsCount = ReadInt(current, curindex); for (int nIndex = 0; nIndex < nItemsCount; ++nIndex) { - oInfo.AddComboBoxItem(ReadString(current, curindex)); + oPr.AddComboBoxItem(ReadString(current, curindex)); } int nSelectedIndex = ReadInt(current, curindex); if (nFlags & (1 << 22)) - oInfo.SetTextValue(ReadString(current, curindex)); + oPr.SetTextValue(ReadString(current, curindex)); } else if (oInfo.IsCheckBox()) { - oInfo.SetChecked(nFlags & (1 << 20)); - oInfo.SetCheckedSymbol(ReadInt(current, curindex)); - oInfo.SetCheckedFont(ReadString(current, curindex)); - oInfo.SetUncheckedSymbol(ReadInt(current, curindex)); - oInfo.SetUncheckedFont(ReadString(current, curindex)); + CFormFieldInfo::CCheckBoxFormPr oPr = oInfo.GetCheckBoxFormPr(); + oPr.SetChecked(nFlags & (1 << 20)); + oPr.SetCheckedSymbol(ReadInt(current, curindex)); + oPr.SetCheckedFont(ReadString(current, curindex)); + oPr.SetUncheckedSymbol(ReadInt(current, curindex)); + oPr.SetUncheckedFont(ReadString(current, curindex)); if (nFlags & (1 << 21)) - oInfo.SetGroupKey(ReadString(current, curindex)); + oPr.SetGroupKey(ReadString(current, curindex)); } else if (oInfo.IsPicture()) { - + CFormFieldInfo::CPictureFormPr oPr = oInfo.GetPictureFormPr(); + oPr.SetConstantProportions(nFlags & (1 << 20)); + oPr.SetRespectBorders(nFlags & (1 << 21)); + oPr.SetScaleType(CFormFieldInfo::EScaleType((nFlags >> 24) & 0xF)); + LONG lShiftX = ReadInt(current, curindex); + LONG lShiftY = ReadInt(current, curindex); + oPr.SetShift(lShiftX, lShiftY); } if (oInfo.IsValid()) From bee3ff541a516e9a1b61e307b781f06bb54c21e1 Mon Sep 17 00:00:00 2001 From: KirillovIlya Date: Thu, 23 Sep 2021 15:48:55 +0300 Subject: [PATCH 17/19] Rework PDFWriter on new CFieldInfo class --- DesktopEditor/graphics/IRenderer.h | 33 ++++++++++---- DesktopEditor/graphics/MetafileToRenderer.cpp | 44 +++++++++---------- PdfWriter/PdfRenderer.cpp | 36 ++++++++------- 3 files changed, 68 insertions(+), 45 deletions(-) diff --git a/DesktopEditor/graphics/IRenderer.h b/DesktopEditor/graphics/IRenderer.h index dbd8b291dc..3ec48f0258 100644 --- a/DesktopEditor/graphics/IRenderer.h +++ b/DesktopEditor/graphics/IRenderer.h @@ -670,22 +670,39 @@ public: { return (m_nType == 4); } - CTextFormPr& GetTextFormPr() + CTextFormPr* GetTextFormPr() { - return m_oTextPr; + return &m_oTextPr; } - CDropDownFormPr& GetDropDownFormPr() + const CTextFormPr* GetTextPr() const { - return m_oDropDownPr; + return &m_oTextPr; } - CCheckBoxFormPr& GetCheckBoxFormPr() + CDropDownFormPr* GetDropDownFormPr() { - return m_oCheckBoxPr; + return &m_oDropDownPr; } - CPictureFormPr& GetPictureFormPr() + const CDropDownFormPr* GetDropDownPr() const { - return m_oPicturePr; + return &m_oDropDownPr; } + CCheckBoxFormPr* GetCheckBoxFormPr() + { + return &m_oCheckBoxPr; + } + const CCheckBoxFormPr* GetCheckBoxPr() const + { + return &m_oCheckBoxPr; + } + CPictureFormPr* GetPictureFormPr() + { + return &m_oPicturePr; + } + const CPictureFormPr* GetPicturePr() const + { + return &m_oPicturePr; + } + private: diff --git a/DesktopEditor/graphics/MetafileToRenderer.cpp b/DesktopEditor/graphics/MetafileToRenderer.cpp index 3e9f1f46dd..ad4f4f3691 100644 --- a/DesktopEditor/graphics/MetafileToRenderer.cpp +++ b/DesktopEditor/graphics/MetafileToRenderer.cpp @@ -926,55 +926,55 @@ namespace NSOnlineOfficeBinToPdf if (oInfo.IsTextField()) { - CFormFieldInfo::CTextFormPr oPr = oInfo.GetTextFormPr(); - oPr.SetComb(nFlags & (1 << 20)); + CFormFieldInfo::CTextFormPr* pPr = oInfo.GetTextFormPr(); + pPr->SetComb(nFlags & (1 << 20)); if (nFlags & (1 << 21)) - oPr.SetMaxCharacters(ReadInt(current, curindex)); + pPr->SetMaxCharacters(ReadInt(current, curindex)); if (nFlags & (1 << 22)) - oPr.SetTextValue(ReadString(current, curindex)); + pPr->SetTextValue(ReadString(current, curindex)); - oPr.SetAutoFit(nFlags & (1 << 23)); - oPr.SetMultiLine(nFlags & (1 << 24)); + pPr->SetAutoFit(nFlags & (1 << 23)); + pPr->SetMultiLine(nFlags & (1 << 24)); } else if (oInfo.IsDropDownList()) { - CFormFieldInfo::CDropDownFormPr oPr = oInfo.GetDropDownFormPr(); - oPr.SetEditComboBox(nFlags & (1 << 20)); + CFormFieldInfo::CDropDownFormPr* pPr = oInfo.GetDropDownFormPr(); + pPr->SetEditComboBox(nFlags & (1 << 20)); int nItemsCount = ReadInt(current, curindex); for (int nIndex = 0; nIndex < nItemsCount; ++nIndex) { - oPr.AddComboBoxItem(ReadString(current, curindex)); + pPr->AddComboBoxItem(ReadString(current, curindex)); } int nSelectedIndex = ReadInt(current, curindex); if (nFlags & (1 << 22)) - oPr.SetTextValue(ReadString(current, curindex)); + pPr->SetTextValue(ReadString(current, curindex)); } else if (oInfo.IsCheckBox()) { - CFormFieldInfo::CCheckBoxFormPr oPr = oInfo.GetCheckBoxFormPr(); - oPr.SetChecked(nFlags & (1 << 20)); - oPr.SetCheckedSymbol(ReadInt(current, curindex)); - oPr.SetCheckedFont(ReadString(current, curindex)); - oPr.SetUncheckedSymbol(ReadInt(current, curindex)); - oPr.SetUncheckedFont(ReadString(current, curindex)); + CFormFieldInfo::CCheckBoxFormPr* pPr = oInfo.GetCheckBoxFormPr(); + pPr->SetChecked(nFlags & (1 << 20)); + pPr->SetCheckedSymbol(ReadInt(current, curindex)); + pPr->SetCheckedFont(ReadString(current, curindex)); + pPr->SetUncheckedSymbol(ReadInt(current, curindex)); + pPr->SetUncheckedFont(ReadString(current, curindex)); if (nFlags & (1 << 21)) - oPr.SetGroupKey(ReadString(current, curindex)); + pPr->SetGroupKey(ReadString(current, curindex)); } else if (oInfo.IsPicture()) { - CFormFieldInfo::CPictureFormPr oPr = oInfo.GetPictureFormPr(); - oPr.SetConstantProportions(nFlags & (1 << 20)); - oPr.SetRespectBorders(nFlags & (1 << 21)); - oPr.SetScaleType(CFormFieldInfo::EScaleType((nFlags >> 24) & 0xF)); + CFormFieldInfo::CPictureFormPr* pPr = oInfo.GetPictureFormPr(); + pPr->SetConstantProportions(nFlags & (1 << 20)); + pPr->SetRespectBorders(nFlags & (1 << 21)); + pPr->SetScaleType(CFormFieldInfo::EScaleType((nFlags >> 24) & 0xF)); LONG lShiftX = ReadInt(current, curindex); LONG lShiftY = ReadInt(current, curindex); - oPr.SetShift(lShiftX, lShiftY); + pPr->SetShift(lShiftX, lShiftY); } if (oInfo.IsValid()) diff --git a/PdfWriter/PdfRenderer.cpp b/PdfWriter/PdfRenderer.cpp index 28b327bc96..d1a2b64eb5 100644 --- a/PdfWriter/PdfRenderer.cpp +++ b/PdfWriter/PdfRenderer.cpp @@ -1536,7 +1536,8 @@ HRESULT CPdfRenderer::AddFormField(const CFormFieldInfo &oInfo) bool bRadioButton = false; if (oInfo.IsTextField()) { - std::wstring wsValue = oInfo.GetTextValue(); + const CFormFieldInfo::CTextFormPr* pPr = oInfo.GetTextPr(); + std::wstring wsValue = pPr->GetTextValue(); unsigned int unLen; unsigned int* pUnicodes = WStringToUtf32(wsValue, unLen); @@ -1550,8 +1551,8 @@ HRESULT CPdfRenderer::AddFormField(const CFormFieldInfo &oInfo) pFieldBase->AddPageRect(m_pPage, TRect(MM_2_PT(dX), m_pPage->GetHeight() - MM_2_PT(dY), MM_2_PT(dX + dW), m_pPage->GetHeight() - MM_2_PT(dY + dH))); - pField->SetMaxLen(oInfo.GetMaxCharacters()); - pField->SetCombFlag(oInfo.IsComb()); + pField->SetMaxLen(pPr->GetMaxCharacters()); + pField->SetCombFlag(pPr->IsComb()); if (oInfo.HaveBorder()) { @@ -1563,7 +1564,7 @@ HRESULT CPdfRenderer::AddFormField(const CFormFieldInfo &oInfo) double* pShifts = NULL; unsigned int unShiftsCount = 0; - if (oInfo.IsComb()) + if (pPr->IsComb()) { unShiftsCount = unLen; pShifts = new double[unShiftsCount]; @@ -1604,12 +1605,13 @@ HRESULT CPdfRenderer::AddFormField(const CFormFieldInfo &oInfo) delete[] pCodes; } - else if (oInfo.IsComboBox()) + else if (oInfo.IsDropDownList()) { // Во всех PDF-ридерах кнопка выпадающего списка рисуется внутри поля, поэтому под неё немного места выделяем dW += 5; - std::wstring wsValue = oInfo.GetTextValue(); + const CFormFieldInfo::CDropDownFormPr* pPr = oInfo.GetDropDownPr(); + std::wstring wsValue = pPr->GetTextValue(); unsigned int unLen; unsigned int* pUnicodes = WStringToUtf32(wsValue, unLen); @@ -1635,18 +1637,20 @@ HRESULT CPdfRenderer::AddFormField(const CFormFieldInfo &oInfo) } delete[] pCodes; - for (unsigned int unIndex = 0, unItemsCount = oInfo.GetComboBoxItemsCount(); unIndex < unItemsCount; ++unIndex) + for (unsigned int unIndex = 0, unItemsCount = pPr->GetComboBoxItemsCount(); unIndex < unItemsCount; ++unIndex) { - pField->AddOption(oInfo.GetComboBoxItem(unIndex)); + pField->AddOption(pPr->GetComboBoxItem(unIndex)); } pField->SetComboFlag(true); - pField->SetEditFlag(!oInfo.IsEditComboBox()); + pField->SetEditFlag(!pPr->IsEditComboBox()); } else if (oInfo.IsCheckBox()) { + const CFormFieldInfo::CCheckBoxFormPr* pPr = oInfo.GetCheckBoxPr(); + CCheckBoxField* pField = NULL; - std::wstring wsGroupName = oInfo.GetGroupKey(); + std::wstring wsGroupName = pPr->GetGroupKey(); if (L"" != wsGroupName) { bRadioButton = true; @@ -1664,18 +1668,18 @@ HRESULT CPdfRenderer::AddFormField(const CFormFieldInfo &oInfo) pFieldBase = static_cast(pField); pFieldBase->AddPageRect(m_pPage, TRect(MM_2_PT(dX), m_pPage->GetHeight() - MM_2_PT(dY), MM_2_PT(dX + dW), m_pPage->GetHeight() - MM_2_PT(dY + dH))); - pField->SetValue(oInfo.IsChecked()); + pField->SetValue(pPr->IsChecked()); - CFontCidTrueType* pCheckedFont = GetFont(oInfo.GetCheckedFontName(), false, false); - CFontCidTrueType* pUncheckedFont = GetFont(oInfo.GetUncheckedFontName(), false, false); + CFontCidTrueType* pCheckedFont = GetFont(pPr->GetCheckedFontName(), false, false); + CFontCidTrueType* pUncheckedFont = GetFont(pPr->GetUncheckedFontName(), false, false); if (!pCheckedFont) pCheckedFont = m_pFont; if (!pUncheckedFont) pUncheckedFont = m_pFont; - unsigned int unCheckedSymbol = oInfo.GetCheckedSymbol(); - unsigned int unUncheckedSymbol = oInfo.GetUncheckedSymbol(); + unsigned int unCheckedSymbol = pPr->GetCheckedSymbol(); + unsigned int unUncheckedSymbol = pPr->GetUncheckedSymbol(); unsigned char* pCheckedCodes = pCheckedFont->EncodeString(&unCheckedSymbol, 1); unsigned char* pUncheckedCodes = pUncheckedFont->EncodeString(&unUncheckedSymbol, 1); @@ -1687,6 +1691,8 @@ HRESULT CPdfRenderer::AddFormField(const CFormFieldInfo &oInfo) } else if (oInfo.IsPicture()) { + const CFormFieldInfo::CPictureFormPr* pPr = oInfo.GetPicturePr(); + CPictureField* pField = m_pDocument->CreatePictureField(); pFieldBase = static_cast(pField); pFieldBase->AddPageRect(m_pPage, TRect(MM_2_PT(dX), m_pPage->GetHeight() - MM_2_PT(dY), MM_2_PT(dX + dW), m_pPage->GetHeight() - MM_2_PT(dY + dH))); From 65c35b9af7dc3c1d05713f49c88d65b6a2a16615 Mon Sep 17 00:00:00 2001 From: KirillovIlya Date: Fri, 24 Sep 2021 14:07:33 +0300 Subject: [PATCH 18/19] Implement background color for forms in PDF Also implement new parameters for text forms and picture forms in PDF --- PdfWriter/PdfRenderer.cpp | 30 +++- .../PdfWriterLibTest/PdfWriterLibTest.cpp | 15 +- PdfWriter/Src/Field.cpp | 154 +++++++++++++----- PdfWriter/Src/Field.h | 39 ++++- 4 files changed, 177 insertions(+), 61 deletions(-) diff --git a/PdfWriter/PdfRenderer.cpp b/PdfWriter/PdfRenderer.cpp index d1a2b64eb5..96df25bf21 100644 --- a/PdfWriter/PdfRenderer.cpp +++ b/PdfWriter/PdfRenderer.cpp @@ -1553,14 +1553,8 @@ HRESULT CPdfRenderer::AddFormField(const CFormFieldInfo &oInfo) pField->SetMaxLen(pPr->GetMaxCharacters()); pField->SetCombFlag(pPr->IsComb()); - - if (oInfo.HaveBorder()) - { - unsigned char unR, unG, unB, unA; - oInfo.GetBorderColor(unR, unG, unB, unA); - - pFieldBase->SetFieldBorder(EBorderSubtype::border_subtype_Solid, TRgb(unR, unG, unB), MM_2_PT(oInfo.GetBorderSize()), 0, 0, 0); - } + pField->SetAutoFit(pPr->IsAutoFit()); + pField->SetMultilineFlag(pPr->IsMultiLine()); double* pShifts = NULL; unsigned int unShiftsCount = 0; @@ -1697,10 +1691,30 @@ HRESULT CPdfRenderer::AddFormField(const CFormFieldInfo &oInfo) pFieldBase = static_cast(pField); pFieldBase->AddPageRect(m_pPage, TRect(MM_2_PT(dX), m_pPage->GetHeight() - MM_2_PT(dY), MM_2_PT(dX + dW), m_pPage->GetHeight() - MM_2_PT(dY + dH))); pField->SetAppearance(); + pField->SetConstantProportions(pPr->IsConstantProportions()); + pField->SetRespectBorders(pPr->IsRespectBorders()); + pField->SetScaleType(static_cast(pPr->GetScaleType())); + pField->SetShift(pPr->GetShiftX() / 1000.0, (1000 - pPr->GetShiftY()) / 1000.0); } if (pFieldBase) { + if (oInfo.HaveBorder()) + { + unsigned char unR, unG, unB, unA; + oInfo.GetBorderColor(unR, unG, unB, unA); + + pFieldBase->SetFieldBorder(EBorderSubtype::border_subtype_Solid, TRgb(unR, unG, unB), MM_2_PT(oInfo.GetBorderSize()), 0, 0, 0); + } + + if (oInfo.HaveShd()) + { + unsigned char unR, unG, unB, unA; + oInfo.GetShdColor(unR, unG, unB, unA); + pFieldBase->SetShd(TRgb(unR, unG, unB)); + } + + if (!bRadioButton) { std::wstring wsKey = oInfo.GetKey(); diff --git a/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.cpp b/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.cpp index da086de6ea..5f302ea9c5 100644 --- a/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.cpp +++ b/PdfWriter/PdfWriterLibTest/PdfWriterLibTest.cpp @@ -152,12 +152,15 @@ void TestField() CPictureField* pPictureField = oPdf.CreatePictureField(); pPictureField->SetRequiredFlag(false); - pPictureField->AddPageRect(pPage, TRect(100, 500, 200, 450)); + pPictureField->AddPageRect(pPage, TRect(100, 100, 500, 650)); pPictureField->SetFieldName(L"Pic"); pPictureField->SetFieldHint(L"Картинка"); pPictureField->SetAppearance(); - - + pPictureField->SetShift(0.25, 0.75); + pPictureField->SetScaleType(CPictureField::EScaleType::Smaller); + pPictureField->SetFieldBorder(border_subtype_Solid, TRgb(255, 0, 0), 1, 0, 0, 0); + pPictureField->SetShd(TRgb(0, 0, 255)); + pPictureField->SetRespectBorders(true); oPdf.SaveToFile(g_wsOutFolder + L"TestField1.pdf"); oPdf.Close(); @@ -954,9 +957,9 @@ void TestOnlineBin() } void TestOnlineBin2() { - std::wstring wsFileName = L"111"; - std::wstring wsFolderPath = L"D:/Test/PDF/TextOnline/"; - std::wstring wsTempFolder = L"D:/Test/PDF/TextOnline/Temp/"; + std::wstring wsFileName = L"1234"; + std::wstring wsFolderPath = L"D:/Work/Test/TextOnline/"; + std::wstring wsTempFolder = L"D:/Work/Test/TextOnline/Temp/"; NSFonts::IApplicationFonts* pFonts = NSFonts::NSApplication::Create(); if (!pFonts) diff --git a/PdfWriter/Src/Field.cpp b/PdfWriter/Src/Field.cpp index 8003f3105a..4baba82050 100644 --- a/PdfWriter/Src/Field.cpp +++ b/PdfWriter/Src/Field.cpp @@ -63,6 +63,10 @@ namespace PdfWriter m_dBorderSize = 0; m_bAutoFit = false; + + m_bShd = false; + + m_pMK = NULL; } void CFieldBase::SetReadOnlyFlag(bool isReadOnly) { @@ -260,13 +264,20 @@ namespace PdfWriter case border_subtype_Underlined: pBorderStyleDict->Add("S", "U"); break; } - CDictObject* pMK = new CDictObject(); + if (!m_pMK) + { + m_pMK = new CDictObject(); + Add("MK", m_pMK); + } + + if (!m_pMK) + return; + CArrayObject* pColor = new CArrayObject(); pColor->Add(oColor.r); pColor->Add(oColor.g); pColor->Add(oColor.b); - Add("MK", pMK); - pMK->Add("BC", pColor); + m_pMK->Add("BC", pColor); m_nBorderType = 1; m_dBorderSize = dWidth; @@ -292,6 +303,36 @@ namespace PdfWriter { m_bAutoFit = isAutoFit; } + bool CFieldBase::HaveShd() const + { + return m_bShd; + } + void CFieldBase::SetShd(const TRgb& oRgb) + { + m_oShdColor = oRgb; + + if (!m_pMK) + { + m_pMK = new CDictObject(); + Add("MK", m_pMK); + } + + if (!m_pMK) + return; + + CArrayObject* pBG = new CArrayObject(); + if (pBG) + { + pBG->Add(oRgb.r); + pBG->Add(oRgb.g); + pBG->Add(oRgb.b); + m_pMK->Add("BG", pBG); + } + } + const TRgb& CFieldBase::GetShdColor() const + { + return m_oShdColor; + } void CFieldBase::SetParent(CFieldBase* pParent) { @@ -517,6 +558,9 @@ namespace PdfWriter //---------------------------------------------------------------------------------------- CPictureField::CPictureField(CXref* pXref, CDocument* pDocument) : CFieldBase(pXref, pDocument) { + m_pMK = NULL; + m_pIF = NULL; + Add("FT", "Btn"); SetFlag(true, 1 << 16); Add("H", "I"); @@ -533,43 +577,36 @@ namespace PdfWriter pAction->Add("JS", new CStringObject("event.target.buttonImportIcon();")); } - CDictObject* pMK = new CDictObject(); - if (pMK) + m_pMK = new CDictObject(); + if (!m_pMK) + return; + + pXref->Add(m_pMK); + Add("MK", m_pMK); + + m_pMK->Add("R", 0); + + CArrayObject* pBG = new CArrayObject(); + if (pBG) { - pXref->Add(pMK); - Add("MK", pMK); - - pMK->Add("R", 0); - - CArrayObject* pBG = new CArrayObject(); - if (pBG) - { - pBG->Add(0.909); - pBG->Add(0.941); - pBG->Add(0.992); - pMK->Add("BG", pBG); - } - - pMK->Add("TP", 1); - - CDictObject* pIF = new CDictObject(); - if (pIF) - { - pMK->Add("IF", pIF); - - pMK->Add("SW", "A"); - pMK->Add("S", "P"); - pMK->Add("FB", false); - - CArrayObject* pA = new CArrayObject(); - if (pA) - { - pMK->Add("A", pA); - pA->Add(0.5); - pA->Add(0.5); - } - } + pBG->Add(0.909); + pBG->Add(0.941); + pBG->Add(0.992); + m_pMK->Add("BG", pBG); } + + m_pMK->Add("TP", 1); + + m_pIF = new CDictObject(); + if (!m_pIF) + return; + + m_pMK->Add("IF", m_pIF); + + SetScaleType(EScaleType::Always); + SetRespectBorders(false); + SetConstantProportions(true); + SetShift(0.5, 0.5); } void CPictureField::SetAppearance() { @@ -587,8 +624,49 @@ namespace PdfWriter Add("DA", new CStringObject(sDA.c_str())); pNormal->DrawPicturePlaceholder(); + } + void CPictureField::SetScaleType(const EScaleType& eType) + { + if (!m_pIF) + return; + switch (eType) + { + case EScaleType::Always: m_pIF->Add("SW", "A"); break; + case EScaleType::Bigger: m_pIF->Add("SW", "B"); break; + case EScaleType::Smaller: m_pIF->Add("SW", "S"); break; + case EScaleType::Never: m_pIF->Add("SW", "N"); break; + } + } + void CPictureField::SetConstantProportions(const bool& bConstant) + { + if (!m_pIF) + return; + if (bConstant) + m_pIF->Add("S", "P"); + else + m_pIF->Add("S", "A"); + } + void CPictureField::SetRespectBorders(const bool& bRespectBorders) + { + if (!m_pIF) + return; + + m_pIF->Add("FB", !bRespectBorders); + } + void CPictureField::SetShift(const double& dX, const double& dY) + { + if (!m_pIF) + return; + + CArrayObject* pA = new CArrayObject(); + if (pA) + { + m_pIF->Add("A", pA); + pA->Add(dX); + pA->Add(dY); + } } //---------------------------------------------------------------------------------------- // CAnnotAppearance diff --git a/PdfWriter/Src/Field.h b/PdfWriter/Src/Field.h index a0b07a93b0..83f10815b7 100644 --- a/PdfWriter/Src/Field.h +++ b/PdfWriter/Src/Field.h @@ -71,21 +71,27 @@ namespace PdfWriter void SetAutoFit(const bool& isAutoFit); void SetParent(CFieldBase* pParent); void AddChild(CFieldBase* pChild); + bool HaveShd() const; + void SetShd(const TRgb& oColor); + const TRgb& GetShdColor() const; protected: - void SetFlag(bool isFlag, int nBitPosition); + void SetFlag(bool isFlag, int nBitPosition); protected: - CXref* m_pXref; - TRect m_oRect; - CDocument* m_pDocument; - int m_nBorderType; - double m_dBorderSize; - TRgb m_oBorderColor; - bool m_bAutoFit; - CFieldBase* m_pParent; + CXref* m_pXref; + TRect m_oRect; + CDocument* m_pDocument; + int m_nBorderType; + double m_dBorderSize; + TRgb m_oBorderColor; + bool m_bAutoFit; + CFieldBase* m_pParent; + bool m_bShd; + TRgb m_oShdColor; + CDictObject* m_pMK; }; class CTextField : public CFieldBase @@ -165,11 +171,26 @@ namespace PdfWriter class CPictureField : public CFieldBase { + public: + + enum EScaleType + { + Always = 0x00, + Bigger = 0x01, + Smaller = 0x02, + Never = 0x03 + }; + public: CPictureField(CXref* pXref, CDocument* pDocument); void SetAppearance(); + void SetScaleType(const EScaleType& eType); + void SetConstantProportions(const bool& bConstant); + void SetRespectBorders(const bool& bRespectBorders); + void SetShift(const double& dX, const double& dY); private: + CDictObject* m_pIF; }; class CAnnotAppearance : public CDictObject From 288b0dcb905182360f9faa7f976422271e7cc360 Mon Sep 17 00:00:00 2001 From: Oleg Korshul Date: Sun, 26 Sep 2021 16:39:43 +0300 Subject: [PATCH 19/19] Fix bug with GetProperty method --- DesktopEditor/doctrenderer/docbuilder_p.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/DesktopEditor/doctrenderer/docbuilder_p.cpp b/DesktopEditor/doctrenderer/docbuilder_p.cpp index 86de6f3ade..cac6b068bc 100644 --- a/DesktopEditor/doctrenderer/docbuilder_p.cpp +++ b/DesktopEditor/doctrenderer/docbuilder_p.cpp @@ -308,6 +308,7 @@ namespace NSDoctRenderer } CDocBuilderValue::CDocBuilderValue(const CDocBuilderValue& src) { + m_internal = new CDocBuilderValue_Private(); m_internal->m_value = src.m_internal->m_value; } CDocBuilderValue& CDocBuilderValue::operator=(const CDocBuilderValue& src)