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() ); diff --git a/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp b/ASCOfficePPTFile/PPTFormatLib/PPTXWriter/Converter.cpp index 33e4caacdf..3d2845e046 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; @@ -115,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 @@ -159,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 @@ -285,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(); @@ -434,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")); @@ -607,9 +608,13 @@ 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 + auto arrRTLayouts = m_pUserInfo->getRoundTripLayout(); + + if (arrRT.empty()) // - см баг 52046 { for (size_t i = 0; i < m_pDocument->m_arThemes.size(); i++) { @@ -617,14 +622,18 @@ 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); + + WriteRoundTripLayouts(arrRTLayouts, nStartLayout); + } } void CPPTXWriter::WriteRoundTripThemes(const std::vector& arrRTThemes, int& nIndexTheme, int & nStartLayout) @@ -633,6 +642,9 @@ void CPPTXWriter::WriteRoundTripThemes(const std::vector writedFilesHash; for (const auto* pRTT : arrRTThemes) { + if ((int)m_pDocument->m_arThemes.size() >= nIndexTheme) + m_pShapeWriter->m_pTheme = m_pDocument->m_arThemes[nIndexTheme-1].get(); + if (pRTT == nullptr) continue; @@ -659,17 +671,19 @@ void CPPTXWriter::WriteRoundTripThemes(const std::vectorm_pTheme = NULL; + } +} + +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(); } } - if (!m_pDocument->m_arThemes.empty()) - WriteLayoutAfterTheme(m_pDocument->m_arThemes[0], nIndexTheme, nStartLayout); + + // 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) @@ -788,15 +879,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()); @@ -828,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; @@ -1163,7 +1260,7 @@ void PPT_FORMAT::CPPTXWriter::WriteLayout(CLayoutPtr pLayout, int nIndexLayout, } std::wstring strElems = _T("\ -"); + "); oWriter.WriteString(strElems); size_t start_index = 0; @@ -1197,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); @@ -1245,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; @@ -1287,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(); @@ -1499,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; @@ -1531,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(); @@ -1584,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; @@ -1729,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); @@ -1779,3 +1876,20 @@ void PPT_FORMAT::CPPTXWriter::WriteTiming(CStringWriter& oWriter, CRelsGenerator //oWriter.WriteString(std::wstring(L"")); } + +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..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 (); @@ -92,7 +93,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/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp b/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp index 810df439d8..e3fbea5df8 100644 --- a/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp +++ b/ASCOfficePPTFile/PPTFormatLib/Reader/PPTDocumentInfoOneUser.cpp @@ -1141,6 +1141,53 @@ 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; +} + +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; @@ -1633,18 +1680,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/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) { 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"; 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"; diff --git a/Common/kernel.pro b/Common/kernel.pro index e682462a75..e41d0e5db4 100644 --- a/Common/kernel.pro +++ b/Common/kernel.pro @@ -15,6 +15,7 @@ DEFINES += KERNEL_USE_DYNAMIC_LIBRARY_BUILDING # CONFIG HEADERS += ./kernel_config.h + 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 ccca4cd93b..c981cb128f 100644 --- a/DesktopEditor/common/Directory.cpp +++ b/DesktopEditor/common/Directory.cpp @@ -53,7 +53,6 @@ #endif #include -#include #include "Directory.h" namespace NSDirectory @@ -588,19 +587,4 @@ namespace NSDirectory { return Exists(pathName); } - - std::vector GrepPaths(const std::vector &paths, const std::wstring &strRegEx) - { - std::vector filtredPaths; - std::wregex regEx(strRegEx); - std::wsmatch wSmath; - for (const auto& path : paths) - { - if (std::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); 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) diff --git a/DesktopEditor/graphics/IRenderer.h b/DesktopEditor/graphics/IRenderer.h index 0077e64ccd..3ec48f0258 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,73 @@ 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; + } + const CTextFormPr* GetTextPr() const + { + return &m_oTextPr; + } + CDropDownFormPr* GetDropDownFormPr() + { + return &m_oDropDownPr; + } + const CDropDownFormPr* GetDropDownPr() const + { + 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: @@ -546,23 +719,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..ad4f4f3691 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* pPr = oInfo.GetTextFormPr(); + pPr->SetComb(nFlags & (1 << 20)); if (nFlags & (1 << 21)) - oInfo.SetMaxCharacters(ReadInt(current, curindex)); + pPr->SetMaxCharacters(ReadInt(current, curindex)); if (nFlags & (1 << 22)) - oInfo.SetTextValue(ReadString(current, curindex)); + pPr->SetTextValue(ReadString(current, curindex)); + + pPr->SetAutoFit(nFlags & (1 << 23)); + pPr->SetMultiLine(nFlags & (1 << 24)); } - else if (oInfo.IsComboBox()) + else if (oInfo.IsDropDownList()) { - oInfo.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) { - oInfo.AddComboBoxItem(ReadString(current, curindex)); + pPr->AddComboBoxItem(ReadString(current, curindex)); } int nSelectedIndex = ReadInt(current, curindex); if (nFlags & (1 << 22)) - oInfo.SetTextValue(ReadString(current, curindex)); + pPr->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* 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)) - oInfo.SetGroupKey(ReadString(current, curindex)); + pPr->SetGroupKey(ReadString(current, curindex)); } else if (oInfo.IsPicture()) { - + 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); + pPr->SetShift(lShiftX, lShiftY); } if (oInfo.IsValid()) diff --git a/PdfWriter/PdfRenderer.cpp b/PdfWriter/PdfRenderer.cpp index 28b327bc96..96df25bf21 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,20 +1551,14 @@ 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()); - - 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->SetMaxLen(pPr->GetMaxCharacters()); + pField->SetCombFlag(pPr->IsComb()); + pField->SetAutoFit(pPr->IsAutoFit()); + pField->SetMultilineFlag(pPr->IsMultiLine()); double* pShifts = NULL; unsigned int unShiftsCount = 0; - if (oInfo.IsComb()) + if (pPr->IsComb()) { unShiftsCount = unLen; pShifts = new double[unShiftsCount]; @@ -1604,12 +1599,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 +1631,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 +1662,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,14 +1685,36 @@ 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))); 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 54a370a33f..5f302ea9c5 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); @@ -79,13 +81,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)); @@ -101,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); @@ -137,14 +152,17 @@ 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->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(L"D:/Test/PDF/TestField1.pdf"); + oPdf.SaveToFile(g_wsOutFolder + L"TestField1.pdf"); oPdf.Close(); } void TestDocument2() @@ -176,7 +194,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() @@ -345,7 +363,7 @@ void TestDocument3() - oPdf.SaveToFile(L"D:/Test/PDF/Test3.pdf"); + oPdf.SaveToFile(g_wsOutFolder + L"Test3.pdf"); oPdf.Close(); } void TestDocument4() @@ -365,7 +383,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() @@ -509,7 +527,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() @@ -583,7 +601,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() @@ -648,7 +666,7 @@ void TestDocument7() pPage->EndText(); - oPdf.SaveToFile(L"D:/Test/PDF/Test7.pdf"); + oPdf.SaveToFile(g_wsOutFolder + L"Test7.pdf"); oPdf.Close(); } void TestDocument8() @@ -727,7 +745,7 @@ void TestDocument8() pPage->GrRestore(); - oPdf.SaveToFile(L"D:/Test/PDF/Test8.pdf"); + oPdf.SaveToFile(g_wsOutFolder + L"Test8.pdf"); oPdf.Close(); } void TestDocument9() @@ -755,7 +773,7 @@ void TestDocument9() pPage->GrRestore(); - oPdf.SaveToFile(L"D:/Test/PDF/Test9.pdf"); + oPdf.SaveToFile(g_wsOutFolder + L"Test9.pdf"); oPdf.Close(); } @@ -939,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/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 7120b13f45..4baba82050 100644 --- a/PdfWriter/Src/Field.cpp +++ b/PdfWriter/Src/Field.cpp @@ -61,6 +61,12 @@ namespace PdfWriter m_nBorderType = 0; m_dBorderSize = 0; + + m_bAutoFit = false; + + m_bShd = false; + + m_pMK = NULL; } void CFieldBase::SetReadOnlyFlag(bool isReadOnly) { @@ -188,9 +194,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) @@ -250,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; @@ -273,6 +294,52 @@ namespace PdfWriter const TRgb& CFieldBase::GetBorderColor() const { return m_oBorderColor; + } + const bool& CFieldBase::IsAutoFit() const + { + return m_bAutoFit; + } + void CFieldBase::SetAutoFit(const bool& isAutoFit) + { + 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) + { + + } + void CFieldBase::AddChild(CFieldBase* pChild) + { + } //---------------------------------------------------------------------------------------- // CTextField @@ -280,6 +347,8 @@ namespace PdfWriter CTextField::CTextField(CXref* pXref, CDocument* pDocument) : CFieldBase(pXref, pDocument) { Add("FT", "Tx"); + + m_bAutoFit = false; } void CTextField::SetMultilineFlag(bool isMultiLine) { @@ -489,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"); @@ -505,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() { @@ -559,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 896a3e9f97..83f10815b7 100644 --- a/PdfWriter/Src/Field.h +++ b/PdfWriter/Src/Field.h @@ -67,19 +67,31 @@ namespace PdfWriter bool HaveBorder() const; const double& GetBorderSize() const; const TRgb& GetBorderColor() const; + const bool& IsAutoFit() const; + 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; + 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 @@ -94,13 +106,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 @@ -157,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