From 21ec043636b6ddaf36c6b323f9d559dc64b6790b Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Mon, 7 Apr 2025 13:24:33 +0300 Subject: [PATCH] Fix merge Fields AcroForm --- .../pro/js/wasm/src/drawingfile_test.cpp | 1 - PdfFile/PdfEditor.cpp | 37 +++++++++++++------ PdfFile/SrcReader/PdfAnnot.cpp | 8 ++-- PdfFile/SrcReader/PdfAnnot.h | 2 +- PdfFile/SrcWriter/Document.cpp | 4 -- 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp index ceba41e746..bb2036d67a 100644 --- a/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp +++ b/DesktopEditor/graphics/pro/js/wasm/src/drawingfile_test.cpp @@ -309,7 +309,6 @@ void ReadInteractiveForms(BYTE* pWidgets, int& i) nPathLength = READ_INT(pWidgets + i); i += 4; - std::cout << "Flags " << nPathLength << ", "; int nFlags = nPathLength; if (nFlags & (1 << 0)) diff --git a/PdfFile/PdfEditor.cpp b/PdfFile/PdfEditor.cpp index 7e7cc8604a..177dd732b0 100644 --- a/PdfFile/PdfEditor.cpp +++ b/PdfFile/PdfEditor.cpp @@ -466,14 +466,27 @@ void AddWidgetParent(PdfWriter::CDocument* pDoc, CObjectsManager* pManager, PdfW { if (pObj->GetType() != PdfWriter::object_type_DICT) return; - PdfWriter::CDictObject* pDict = (PdfWriter::CDictObject*)pObj; - if (pDict->GetDictType() != PdfWriter::dict_type_UNKNOWN) + PdfWriter::CDictObject* pDict = dynamic_cast(pObj); + if (!pDict) return; int nID = pManager->FindObj(pObj); - if (pDoc->GetParent(nID)) + if (nID < 0) + return; + + if (pDict->GetDictType() == PdfWriter::dict_type_UNKNOWN) + { + if (pDoc->GetParent(nID)) + return; + pDoc->AddParent(nID, pDict); + } + + PdfWriter::CObjectBase* pObjParent = pDict->Get("Parent"); + if (pObjParent && pObjParent->GetType() == PdfWriter::object_type_DICT) + AddWidgetParent(pDoc, pManager, pObjParent); + + if (pDict->GetDictType() != PdfWriter::dict_type_UNKNOWN) return; - pDoc->AddParent(nID, pDict); PdfWriter::CObjectBase* pObjKids = pDict->Get("Kids"); if (!pObjKids || pObjKids->GetType() != PdfWriter::object_type_ARRAY) @@ -1697,16 +1710,16 @@ bool CPdfEditor::SplitPages(const int* arrPageIndex, unsigned int unLength, PDFD for (int nIndex = 0; nIndex < oTemp.arrayGetLength(); ++nIndex) { Object oRes; + PdfWriter::CObjectBase* pObj = NULL; if (oTemp.arrayGetNF(nIndex, &oRes)->isRef()) + pObj = m_mObjManager.GetObj(oRes.getRefNum() + nStartRefID); + if (pObj) { - PdfWriter::CObjectBase* pObj = m_mObjManager.GetObj(oRes.getRefNum() + nStartRefID); - if (pObj) - { - pFields->Add(pObj); - m_mObjManager.IncRefCount(oRes.getRefNum() + nStartRefID); - AddWidgetParent(pDoc, &m_mObjManager, pObj); - continue; - } + pFields->Add(pObj); + m_mObjManager.IncRefCount(oRes.getRefNum() + nStartRefID); + AddWidgetParent(pDoc, &m_mObjManager, pObj); + oRes.free(); + continue; } oRes.free(); } diff --git a/PdfFile/SrcReader/PdfAnnot.cpp b/PdfFile/SrcReader/PdfAnnot.cpp index e2a477f930..eb517821ed 100644 --- a/PdfFile/SrcReader/PdfAnnot.cpp +++ b/PdfFile/SrcReader/PdfAnnot.cpp @@ -2442,7 +2442,7 @@ CAnnots::CAnnots(PDFDoc* pdfDoc, NSFonts::IFontManager* pFontManager, CPdfFontLi // Родители Object oParentRefObj; if (oField.dictLookupNF("Parent", &oParentRefObj)->isRef()) - getParents(xref, &oParentRefObj, nStartRefID); + getParents(pdfDoc, &oParentRefObj, nStartRefID); oParentRefObj.free(); oField.free(); oFieldRef.free(); @@ -2497,9 +2497,9 @@ CAnnots::~CAnnots() for (int i = 0; i < m_arrAnnots.size(); ++i) RELEASEOBJECT(m_arrAnnots[i]); } -void CAnnots::getParents(XRef* xref, Object* oFieldRef, int nStartRefID) +void CAnnots::getParents(PDFDoc* pdfDoc, Object* oFieldRef, int nStartRefID) { - if (!oFieldRef || !xref || !oFieldRef->isRef() || + if (!oFieldRef || !pdfDoc || !oFieldRef->isRef() || std::find_if(m_arrParents.begin(), m_arrParents.end(), [oFieldRef, nStartRefID] (CAnnotParent* pAP) { return oFieldRef->getRefNum() + nStartRefID == pAP->unRefNum; }) != m_arrParents.end()) return; @@ -2672,7 +2672,7 @@ void CAnnots::getParents(XRef* xref, Object* oFieldRef, int nStartRefID) { pAnnotParent->unFlags |= (1 << 4); pAnnotParent->unRefNumParent = oParentRefObj.getRefNum() + nStartRefID; - getParents(xref, &oParentRefObj, nStartRefID); + getParents(pdfDoc, &oParentRefObj, nStartRefID); } oParentRefObj.free(); diff --git a/PdfFile/SrcReader/PdfAnnot.h b/PdfFile/SrcReader/PdfAnnot.h index 1cedfdfd09..2b57ca5a95 100644 --- a/PdfFile/SrcReader/PdfAnnot.h +++ b/PdfFile/SrcReader/PdfAnnot.h @@ -621,7 +621,7 @@ private: std::string sDV; }; - void getParents(XRef* xref, Object* oFieldRef, int nStartRefID); + void getParents(PDFDoc* pdfDoc, Object* oFieldRef, int nStartRefID); std::vector m_arrCO; // Порядок вычислений - CO std::vector m_arrParents; // Родительские Fields diff --git a/PdfFile/SrcWriter/Document.cpp b/PdfFile/SrcWriter/Document.cpp index d0e04c5540..2e4d48bb17 100644 --- a/PdfFile/SrcWriter/Document.cpp +++ b/PdfFile/SrcWriter/Document.cpp @@ -1643,10 +1643,6 @@ namespace PdfWriter return ((CNameObject*)pFT)->Get(); return ""; } - CPage* CDocument::CreateFakePage() - { - return new CPage(this, NULL); - } bool CDocument::EditCO(const std::vector& arrCO) { if (arrCO.empty())