From 514424a8589af51a709022bccad475abee09dd35 Mon Sep 17 00:00:00 2001 From: Philipp Reinkemeier Date: Fri, 13 Feb 2015 19:29:00 +0100 Subject: [PATCH] Fixed adding annotation of Subtype Popup to pdf page. - Annotations of Subtype Popup are automatically added to the same pdf page, when its associated Markup annotation is added to a pdf page using Page::addAnnot(..). - When a new Popup annotation is created and associated to a Markup annotation by means of AnnotMarkup::setPopup(..), then this Popup annotation is added to the same pdf page as the Markup annotation (if it already was added to a page). If the Markup annotation already had some previous Popup annotation that was associated with a pdf page, then the old Popup annotation is removed from that page before it gets overwritten by the new Popup annotation. - Note: When a markup annotation is removed from a pdf page, its referenced Popup annotation is automatically removed from that pdf page already without this patch. --- poppler/Annot.cc | 19 +++++++++++++++++++ poppler/Page.cc | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/poppler/Annot.cc b/poppler/Annot.cc index d7769a0..b06a5d2 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); + if (pageobj) { + pageobj->addAnnot(popup); + } + } } else { popup = NULL; } diff --git a/poppler/Page.cc b/poppler/Page.cc index 98c13c1..c1266dc 100644 --- a/poppler/Page.cc +++ b/poppler/Page.cc @@ -444,6 +444,14 @@ void Page::addAnnot(Annot *annot) { 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