From e1d2bd77b926c619b2d06b5ac87b5aba29a5b913 Mon Sep 17 00:00:00 2001 From: Philipp Reinkemeier Date: Fri, 13 Feb 2015 09:57:26 +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. - When a new Popup annotation is created and associated to a Markup annotation by means of poppler_annot_markup_set_popup(..), 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. --- glib/poppler-annot.cc | 19 +++++++++++++++++++ glib/poppler-page.cc | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc index e87bce3..4a418c9 100644 --- a/glib/poppler-annot.cc +++ b/glib/poppler-annot.cc @@ -1157,8 +1157,27 @@ poppler_annot_markup_set_popup (PopplerAnnotMarkup *poppler_annot, g_return_if_fail (POPPLER_IS_ANNOT_MARKUP (poppler_annot)); annot = static_cast(POPPLER_ANNOT (poppler_annot)->annot); + // 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. + popup = annot->getPopup(); + if (popup != NULL && popup->getPageNum() != 0) { + Page *pageobj = popup->getDoc()->getPage(popup->getPageNum()); + if (pageobj) { + pageobj->removeAnnot(popup); + } + } popup = new AnnotPopup (annot->getDoc(), &pdf_rect); annot->setPopup (popup); + // If "annot" is already added to a page, then we + // add "popup" to the same page. + if (annot->getPageNum() != 0) { + Page *pageobj = annot->getDoc()->getPage(annot->getPageNum()); + if (pageobj) { + pageobj->addAnnot(popup); + } + } } /** diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc index db2387a..1d7f4db 100644 --- a/glib/poppler-page.cc +++ b/glib/poppler-page.cc @@ -1500,6 +1500,14 @@ poppler_page_add_annot (PopplerPage *page, g_return_if_fail (POPPLER_IS_ANNOT (annot)); page->page->addAnnot (annot->annot); + + if (POPPLER_IS_ANNOT_MARKUP(annot)) { + AnnotMarkup * annot_markup = static_cast(annot->annot); + AnnotPopup * annot_popup = annot_markup->getPopup(); + if (annot_popup) { + page->page->addAnnot(annot_popup); + } + } } /** -- 2.2.2