From 28db0e5ecfe2d3776b9f78ce58e9d9f1fdd31e09 Mon Sep 17 00:00:00 2001 From: Philipp Reinkemeier Date: Mon, 16 Feb 2015 09:11:58 +0100 Subject: [PATCH] Fixed adding annotation of Subtype Popup to pdf page Bug #89136 --- poppler/Annot.cc | 19 +++++++++++++++++++ poppler/Page.cc | 12 +++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/poppler/Annot.cc b/poppler/Annot.cc index d7769a0..9c4cb0b 100644 --- a/poppler/Annot.cc +++ b/poppler/Annot.cc @@ -2089,6 +2089,16 @@ void AnnotMarkup::setLabel(GooString *new_label) { } void AnnotMarkup::setPopup(AnnotPopup *new_popup) { + // If there exists an old popup annotation that is already + // associated with a page, then we need to remove that + // popup annotation from the page. Otherwise we would have + // dangling references to it. + if (popup != NULL && popup->getPageNum() != 0) { + Page *pageobj = popup->getDoc()->getPage(popup->getPageNum()); + if (pageobj) { + pageobj->removeAnnot(popup); + } + } delete popup; if (new_popup) { @@ -2100,6 +2110,15 @@ void AnnotMarkup::setPopup(AnnotPopup *new_popup) { new_popup->setParent(this); popup = new_popup; + + // If this annotation is already added to a page, then we + // add the new popup annotation to the same page. + if (page != 0) { + Page *pageobj = doc->getPage(page); + assert(pageobj != NULL); // pageobj should exist in doc (see setPage()) + + pageobj->addAnnot(popup); + } } else { popup = NULL; } diff --git a/poppler/Page.cc b/poppler/Page.cc index 98c13c1..56e9679 100644 --- a/poppler/Page.cc +++ b/poppler/Page.cc @@ -442,8 +442,18 @@ void Page::addAnnot(Annot *annot) { obj1.free(); } - annots->appendAnnot(annot); + if (annot->getType() != Annot::typePopup) { + annots->appendAnnot(annot); + } annot->setPage(num, gTrue); + + AnnotMarkup *annot_markup = dynamic_cast(annot); + if (annot_markup) { + AnnotPopup *annot_popup = annot_markup->getPopup(); + if (annot_popup) { + this->addAnnot(annot_popup); + } + } } void Page::removeAnnot(Annot *annot) { -- 2.3.0