From d80d6c4168fca09b29fc9e1cf653c852d2db0977 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Wed, 23 Apr 2025 11:10:49 +0300 Subject: [PATCH] Fix bug 74175 --- .../graphics/commands/AnnotField.cpp | 10 +++++-- DesktopEditor/graphics/commands/AnnotField.h | 6 ++-- PdfFile/PdfEditor.cpp | 29 +++++++++++++++---- PdfFile/SrcWriter/Document.cpp | 14 ++++++--- PdfFile/SrcWriter/Document.h | 2 +- 5 files changed, 47 insertions(+), 14 deletions(-) diff --git a/DesktopEditor/graphics/commands/AnnotField.cpp b/DesktopEditor/graphics/commands/AnnotField.cpp index 72a159a22e..00d31e3310 100644 --- a/DesktopEditor/graphics/commands/AnnotField.cpp +++ b/DesktopEditor/graphics/commands/AnnotField.cpp @@ -1067,15 +1067,21 @@ CWidgetsInfo::~CWidgetsInfo() for (int i = 0; i < m_arrParents.size(); ++i) RELEASEOBJECT(m_arrParents[i]); } -const std::vector& CWidgetsInfo::GetCO() { return m_arrCO; } +const std::vector< std::pair >& CWidgetsInfo::GetCO() { return m_arrCO; } const std::vector& CWidgetsInfo::GetButtonImg() { return m_arrButtonImg; } const std::vector& CWidgetsInfo::GetParents() { return m_arrParents; } +void CWidgetsInfo::ChangeCO(int i, int nNum, int nGen) +{ + if (i < 0 || i > m_arrCO.size() - 1) + return; + m_arrCO[i] = std::make_pair(nNum, nGen); +} bool CWidgetsInfo::Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafileToRenderter* pCorrector) { int n = pReader->ReadInt(); m_arrCO.reserve(n); for (int i = 0; i < n; ++i) - m_arrCO.push_back(pReader->ReadInt()); + m_arrCO.push_back(std::make_pair(pReader->ReadInt(), -1)); n = pReader->ReadInt(); m_arrParents.reserve(n); diff --git a/DesktopEditor/graphics/commands/AnnotField.h b/DesktopEditor/graphics/commands/AnnotField.h index e546fa0cb3..52a204d8e3 100644 --- a/DesktopEditor/graphics/commands/AnnotField.h +++ b/DesktopEditor/graphics/commands/AnnotField.h @@ -584,14 +584,16 @@ public: CWidgetsInfo(); virtual ~CWidgetsInfo(); - const std::vector& GetCO(); + const std::vector< std::pair >& GetCO(); const std::vector& GetButtonImg(); const std::vector& GetParents(); + void ChangeCO(int i, int nNum, int nGen); + bool Read(NSOnlineOfficeBinToPdf::CBufferReader* pReader, IMetafileToRenderter* pCorrector); private: - std::vector m_arrCO; + std::vector< std::pair > m_arrCO; std::vector m_arrButtonImg; std::vector m_arrParents; }; diff --git a/PdfFile/PdfEditor.cpp b/PdfFile/PdfEditor.cpp index 27af531880..33bd31504e 100644 --- a/PdfFile/PdfEditor.cpp +++ b/PdfFile/PdfEditor.cpp @@ -596,7 +596,7 @@ HRESULT _ChangePassword(const std::wstring& wsPath, const std::wstring& wsPasswo } Object oTemp; - xref->fetch(i, pEntry->gen, &oTemp); + xref->fetch(i, pEntry->type == xrefEntryCompressed ? 0 : pEntry->gen, &oTemp); PdfWriter::CObjectBase* pObj = NULL; switch (oTemp.getType()) @@ -2110,7 +2110,7 @@ bool CPdfEditor::DeletePage(int nPageIndex) { XRefEntry* pEntry = pPDFDocument->getXRef()->getEntry(nRefID); Object oRef; - oRef.initRef(nRefID, pEntry->gen); + oRef.initRef(nRefID, pEntry->type == xrefEntryCompressed ? 0 : pEntry->gen); m_mObjManager.DeleteObjTree(&oRef, pPDFDocument->getXRef(), nStartRefID); } pPage->SetHidden(); @@ -2446,7 +2446,7 @@ bool CPdfEditor::DeleteAnnot(int nID, Object* oAnnots) { XRefEntry* pEntry = pPDFDocument->getXRef()->getEntry(nRefID); Object oRef; - oRef.initRef(nRefID, pEntry->gen); + oRef.initRef(nRefID, pEntry->type == xrefEntryCompressed ? 0 : pEntry->gen); m_mObjManager.DeleteObjTree(&oRef, pPDFDocument->getXRef(), nStartRefID); } pObj->SetHidden(); @@ -2686,7 +2686,26 @@ bool CPdfEditor::EditWidgets(IAdvancedCommand* pCommand) CWidgetsInfo* pFieldInfo = (CWidgetsInfo*)pCommand; PdfWriter::CDocument* pDoc = m_pWriter->GetDocument(); - std::vector arrParents = pFieldInfo->GetParents(); + const std::vector< std::pair >& arrCO = pFieldInfo->GetCO(); + for (int i = 0; i < arrCO.size(); ++i) + { + int nObjNum = arrCO[i].first; + if (pDoc->GetParent(nObjNum)) + continue; + if (pDoc->GetAnnot(nObjNum)) + continue; + + PDFDoc* pPDFDocument = NULL; + int nStartRefID = 0; + int nRefID = m_pReader->FindRefNum(nObjNum, &pPDFDocument, &nStartRefID); + if (nRefID < 0) + continue; + + XRefEntry* pEntry = pPDFDocument->getXRef()->getEntry(nRefID); + pFieldInfo->ChangeCO(i, nRefID, pEntry->type == xrefEntryCompressed ? 0 : pEntry->gen); + } + + const std::vector& arrParents = pFieldInfo->GetParents(); for (CWidgetsInfo::CParent* pParent : arrParents) { PdfWriter::CDictObject* pDParent = pDoc->GetParent(pParent->nID); @@ -2701,7 +2720,7 @@ bool CPdfEditor::EditWidgets(IAdvancedCommand* pCommand) XRefEntry* pEntry = pPDFDocument->getXRef()->getEntry(nRefID); Object oParentRef; - oParentRef.initRef(nRefID, pEntry->gen); + oParentRef.initRef(nRefID, pEntry->type == xrefEntryCompressed ? 0 : pEntry->gen); GetWidgetParent(pPDFDocument, pDoc, &oParentRef, nStartRefID); // TODO перевыставить детей oParentRef.free(); diff --git a/PdfFile/SrcWriter/Document.cpp b/PdfFile/SrcWriter/Document.cpp index 64b786f96c..5c19883933 100644 --- a/PdfFile/SrcWriter/Document.cpp +++ b/PdfFile/SrcWriter/Document.cpp @@ -1628,7 +1628,7 @@ namespace PdfWriter return ((CNameObject*)pFT)->Get(); return ""; } - bool CDocument::EditCO(const std::vector& arrCO) + bool CDocument::EditCO(const std::vector< std::pair >& arrCO) { if (arrCO.empty()) return true; @@ -1642,16 +1642,22 @@ namespace PdfWriter m_pAcroForm->Add("CO", pArray); - for (int CO : arrCO) + for (std::pair CO : arrCO) { - CDictObject* pObj = GetParent(CO); + CDictObject* pObj = GetParent(CO.first); if (pObj) pArray->Add(pObj); else { - CAnnotation* pAnnot = m_mAnnotations[CO]; + CAnnotation* pAnnot = GetAnnot(CO.first); if (pAnnot) pArray->Add(pAnnot); + else if (CO.second >= 0) + { + PdfWriter::CObjectBase* pBase = new PdfWriter::CObjectBase(); + pBase->SetRef(CO.first, CO.second); + pArray->Add(new PdfWriter::CProxyObject(pBase, true)); + } } } diff --git a/PdfFile/SrcWriter/Document.h b/PdfFile/SrcWriter/Document.h index 7e447ce993..4f8fa22bc7 100644 --- a/PdfFile/SrcWriter/Document.h +++ b/PdfFile/SrcWriter/Document.h @@ -198,7 +198,7 @@ namespace PdfWriter CDictObject* GetParent(int nID); CPage* GetCurPage() { return m_pCurPage; } void SetCurPage(CPage* pPage) { m_pCurPage = pPage; } - bool EditCO(const std::vector& arrCO); + bool EditCO(const std::vector< std::pair >& arrCO); std::string SetParentKids(int nParentID); const std::map& GetAnnots() { return m_mAnnotations; } const std::map& GetParents() { return m_mParents; }