diff --git a/PdfFile/PdfFile.cpp b/PdfFile/PdfFile.cpp index 73c8afecd1..0ee483a02a 100644 --- a/PdfFile/PdfFile.cpp +++ b/PdfFile/PdfFile.cpp @@ -909,7 +909,6 @@ bool CPdfFile::EditAnnot(int nPageIndex, int nID) RELEASEOBJECT(pXref); return false; } - bool CPdfFile::DeleteAnnot(int nID) { // Проверка режима редактирования @@ -938,18 +937,33 @@ bool CPdfFile::DeleteAnnot(int nID) } pageRefObj.free(); pageObj.free(); - Object oAnnotRef, oAnnot, oPopupRef; + bool bRes = false; for (int i = 0; i < oAnnots.arrayGetLength(); ++i) { + Object oAnnotRef, oAnnot; if (oAnnots.arrayGetNF(i, &oAnnotRef)->isRef() && oAnnotRef.getRefNum() == nID) - break; - oAnnotRef.free(); + { + bRes = m_pInternal->pWriter->m_pDocument->DeleteAnnot(oAnnotRef.getRefNum(), oAnnotRef.getRefGen()); + if (oAnnotRef.fetch(xref, &oAnnot)->isDict()) + { + Object oPopupRef; + if (oAnnot.dictLookupNF("Popup", &oPopupRef)->isRef()) + m_pInternal->pWriter->m_pDocument->DeleteAnnot(oPopupRef.getRefNum(), oPopupRef.getRefGen()); + oPopupRef.free(); + } + } + else if (oAnnots.arrayGet(i, &oAnnot)->isDict()) + { + Object oIRTRef; + if (oAnnot.dictLookupNF("IRT", &oIRTRef)->isRef() && oIRTRef.getRefNum() == nID) + DeleteAnnot(oAnnotRef.getRefNum()); + oIRTRef.free(); + } + oAnnotRef.free(); oAnnot.free(); } oAnnots.free(); - if (oAnnotRef.isRef() && oAnnotRef.fetch(xref, &oAnnot)->isDict() && oAnnot.dictLookupNF("Popup", &oPopupRef)->isRef()) - m_pInternal->pWriter->m_pDocument->DeleteAnnot(oPopupRef.getRefNum()); - return m_pInternal->pWriter->m_pDocument->DeleteAnnot(nID); + return bRes; } #endif // BUILDING_WASM_MODULE diff --git a/PdfFile/SrcWriter/Annotation.cpp b/PdfFile/SrcWriter/Annotation.cpp index e51ef2653e..a9d0e023a6 100644 --- a/PdfFile/SrcWriter/Annotation.cpp +++ b/PdfFile/SrcWriter/Annotation.cpp @@ -220,6 +220,7 @@ namespace PdfWriter CPopupAnnotation* CMarkupAnnotation::CreatePopup() { CPopupAnnotation* pAnnot = new CPopupAnnotation(m_pXref); + m_pXref->Add(pAnnot); Add("Popup", pAnnot); pAnnot->SetOpen(false); @@ -348,6 +349,8 @@ namespace PdfWriter } Add("State", new CStringObject(sValue.c_str())); + if (!Get("C")) + SetC({ 1.0, 0.8, 0.0 }); } void CTextAnnotation::SetStateModel(BYTE nStateModel) { diff --git a/PdfFile/SrcWriter/Document.cpp b/PdfFile/SrcWriter/Document.cpp index 8fc613f9f4..ede4881e54 100644 --- a/PdfFile/SrcWriter/Document.cpp +++ b/PdfFile/SrcWriter/Document.cpp @@ -1289,13 +1289,11 @@ namespace PdfWriter return true; } - bool CDocument::DeleteAnnot(int nID) + bool CDocument::DeleteAnnot(int nObjNum, int nObjGen) { - if (m_pCurPage) + if (m_pCurPage && m_pCurPage->DeleteAnnotation(nObjNum)) { - m_pCurPage->DeleteAnnotation(nID); - - CXref* pXref = new CXref(this, nID, 0); + CXref* pXref = new CXref(this, nObjNum, nObjGen); if (!pXref) return false; diff --git a/PdfFile/SrcWriter/Document.h b/PdfFile/SrcWriter/Document.h index 273c2d991d..eff9e96b3a 100644 --- a/PdfFile/SrcWriter/Document.h +++ b/PdfFile/SrcWriter/Document.h @@ -182,7 +182,7 @@ namespace PdfWriter std::wstring GetEditPdfPath() { return m_wsFilePath; } bool EditAnnot (CXref* pXref, CAnnotation* pAnnot, int nID); bool EditParent(CXref* pXref, CDictObject* pParent, int nID); - bool DeleteAnnot(int nID); + bool DeleteAnnot(int nObjNum, int nObjGen); CAnnotation* GetAnnot(int nID); CPage* GetCurPage() { return m_pCurPage; } void SetCurPage(CPage* pPage) { m_pCurPage = pPage; } diff --git a/PdfFile/SrcWriter/Pages.cpp b/PdfFile/SrcWriter/Pages.cpp index e5125ce7de..9654560dc1 100644 --- a/PdfFile/SrcWriter/Pages.cpp +++ b/PdfFile/SrcWriter/Pages.cpp @@ -1136,11 +1136,11 @@ namespace PdfWriter return pArray->Add(pAnnot); } - void CPage::DeleteAnnotation(unsigned int nID) + bool CPage::DeleteAnnotation(unsigned int nID) { CArrayObject* pArray = (CArrayObject*)Get("Annots"); if (!pArray) - return; + return false; for (int i = 0; i < pArray->GetCount(); i++) { @@ -1149,9 +1149,11 @@ namespace PdfWriter { CObjectBase* pDelete = pArray->Remove(i); RELEASEOBJECT(pDelete); + return true; break; } } + return false; } void CPage::BeginText() { diff --git a/PdfFile/SrcWriter/Pages.h b/PdfFile/SrcWriter/Pages.h index 13ad7eb549..8989cff8c1 100644 --- a/PdfFile/SrcWriter/Pages.h +++ b/PdfFile/SrcWriter/Pages.h @@ -134,7 +134,7 @@ namespace PdfWriter void SetTransform(double dM11, double dM12, double dM21, double dM22, double dX, double dY); void SetExtGrState(CExtGrState* pExtGrState); void AddAnnotation(CDictObject* pAnnot); - void DeleteAnnotation(unsigned int nID); + bool DeleteAnnotation(unsigned int nID); void DrawShading(CShading* pShading); void SetStrokeAlpha(unsigned char unAlpha); void SetFillAlpha(unsigned char unAlpha);