[poppler] 3 commits - glib/demo glib/poppler-annot.cc glib/poppler-page.cc glib/poppler-page.h glib/reference

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Sun May 20 03:09:18 PDT 2012


 glib/demo/annots.c                  |   48 +++++++++++++++++++++++++++-----
 glib/poppler-annot.cc               |   53 ++++++++++++++----------------------
 glib/poppler-page.cc                |   19 ++++++++++++
 glib/poppler-page.h                 |    2 +
 glib/reference/poppler-sections.txt |    1 
 5 files changed, 85 insertions(+), 38 deletions(-)

New commits:
commit 610eb24426d9b36ac7da40a2fceb3dbeeec19a5c
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Sun May 20 12:08:09 2012 +0200

    glib-demo: Add a button to remove annots from the annot view

diff --git a/glib/demo/annots.c b/glib/demo/annots.c
index 290847a..e0b5d91 100644
--- a/glib/demo/annots.c
+++ b/glib/demo/annots.c
@@ -40,6 +40,7 @@ typedef struct {
     PopplerDocument *doc;
     PopplerPage     *page;
 
+    GtkWidget       *tree_view;
     GtkListStore    *model;
     GtkWidget       *annot_view;
     GtkWidget       *timer_label;
@@ -281,6 +282,28 @@ get_free_text_callout_line (PopplerAnnotFreeText *poppler_annot)
 }
 
 static void
+pgd_annots_remove_annot (GtkWidget     *button,
+                         PgdAnnotsDemo *demo)
+{
+    GtkTreeSelection *selection;
+    GtkTreeModel *model;
+    GtkTreeIter   iter;
+
+    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (demo->tree_view));
+
+    if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
+        PopplerAnnot *annot;
+
+        gtk_tree_model_get (model, &iter,
+                            ANNOTS_COLUMN, &annot,
+                           -1);
+        poppler_page_remove_annot (demo->page, annot);
+        g_object_unref (annot);
+        gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
+    }
+}
+
+static void
 pgd_annot_view_set_annot_markup (GtkWidget          *table,
                                  PopplerAnnotMarkup *markup,
                                  gint               *row)
@@ -452,24 +475,25 @@ pgd_annot_view_set_annot_screen (GtkWidget          *table,
 }
 
 static void
-pgd_annot_view_set_annot (GtkWidget    *annot_view,
-                          PopplerAnnot *annot)
+pgd_annot_view_set_annot (PgdAnnotsDemo *demo,
+                          PopplerAnnot  *annot)
 {
     GtkWidget  *alignment;
     GtkWidget  *table;
+    GtkWidget  *button;
     GEnumValue *enum_value;
     gint        row = 0;
     gchar      *text, *warning;
     time_t      timet;
 
-    alignment = gtk_bin_get_child (GTK_BIN (annot_view));
+    alignment = gtk_bin_get_child (GTK_BIN (demo->annot_view));
     if (alignment) {
-        gtk_container_remove (GTK_CONTAINER (annot_view), alignment);
+        gtk_container_remove (GTK_CONTAINER (demo->annot_view), alignment);
     }
 
     alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
     gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 5, 5, 12, 5);
-    gtk_container_add (GTK_CONTAINER (annot_view), alignment);
+    gtk_container_add (GTK_CONTAINER (demo->annot_view), alignment);
     gtk_widget_show (alignment);
 
     if (!annot)
@@ -527,6 +551,13 @@ pgd_annot_view_set_annot (GtkWidget    *annot_view,
           break;
     }
 
+    button = gtk_button_new_from_stock (GTK_STOCK_REMOVE);
+    g_signal_connect (G_OBJECT (button), "clicked",
+                      G_CALLBACK (pgd_annots_remove_annot),
+                      (gpointer) demo);
+    gtk_grid_attach (GTK_GRID (table), button, 0, row, 2, 1);
+    gtk_widget_show (button);
+
     gtk_container_add (GTK_CONTAINER (alignment), table);
     gtk_widget_show (table);
 }
@@ -540,7 +571,7 @@ pgd_annots_get_annots (GtkWidget     *button,
     GTimer      *timer;
 
     gtk_list_store_clear (demo->model);
-    pgd_annot_view_set_annot (demo->annot_view, NULL);
+    pgd_annot_view_set_annot (demo, NULL);
 
     if (demo->page) {
         g_object_unref (demo->page);
@@ -632,8 +663,10 @@ pgd_annots_selection_changed (GtkTreeSelection *treeselection,
         gtk_tree_model_get (model, &iter,
                             ANNOTS_COLUMN, &annot,
                            -1);
-        pgd_annot_view_set_annot (demo->annot_view, annot);
+        pgd_annot_view_set_annot (demo, annot);
         g_object_unref (annot);
+    } else {
+        pgd_annot_view_set_annot (demo, NULL);
     }
 }
 
@@ -825,6 +858,7 @@ pgd_annots_create_widget (PopplerDocument *document)
 				      G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
 				      G_TYPE_OBJECT);
     treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL (demo->model));
+    demo->tree_view = treeview;
 
     renderer = gtk_cell_renderer_text_new ();
     gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
commit 11a3093e093319e88f14af0ab6c15009104d17ee
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Sun May 20 11:22:49 2012 +0200

    glib: Add poppler_page_remove_annot()
    
    https://bugs.freedesktop.org/show_bug.cgi?id=40473

diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc
index 156e2d7..90f9a62 100644
--- a/glib/poppler-page.cc
+++ b/glib/poppler-page.cc
@@ -1431,6 +1431,25 @@ poppler_page_add_annot (PopplerPage  *page,
   page->page->addAnnot (annot->annot);
 }
 
+/**
+ * poppler_page_remove_annot:
+ * @page: a #PopplerPage
+ * @annot: a #PopplerAnnot to remove
+ *
+ * Removes annotation @annot from @page
+ *
+ * Since: 0.22
+ */
+void
+poppler_page_remove_annot (PopplerPage  *page,
+                           PopplerAnnot *annot)
+{
+  g_return_if_fail (POPPLER_IS_PAGE (page));
+  g_return_if_fail (POPPLER_IS_ANNOT (annot));
+
+  page->page->removeAnnot (annot->annot);
+}
+
 /* PopplerRectangle type */
 
 POPPLER_DEFINE_BOXED_TYPE (PopplerRectangle, poppler_rectangle,
diff --git a/glib/poppler-page.h b/glib/poppler-page.h
index 7b36843..6064ac5 100644
--- a/glib/poppler-page.h
+++ b/glib/poppler-page.h
@@ -89,6 +89,8 @@ GList                 *poppler_page_get_annot_mapping    (PopplerPage        *pa
 void                   poppler_page_free_annot_mapping   (GList              *list);
 void                   poppler_page_add_annot            (PopplerPage        *page,
 							  PopplerAnnot       *annot);
+void                   poppler_page_remove_annot         (PopplerPage        *page,
+                                                          PopplerAnnot       *annot);
 void 		      poppler_page_get_crop_box 	 (PopplerPage        *page,
 							  PopplerRectangle   *rect);
 gboolean               poppler_page_get_text_layout      (PopplerPage        *page,
diff --git a/glib/reference/poppler-sections.txt b/glib/reference/poppler-sections.txt
index 6efef6a..76abf4c 100644
--- a/glib/reference/poppler-sections.txt
+++ b/glib/reference/poppler-sections.txt
@@ -47,6 +47,7 @@ poppler_page_free_form_field_mapping
 poppler_page_get_annot_mapping
 poppler_page_free_annot_mapping
 poppler_page_add_annot
+poppler_page_remove_annot
 poppler_rectangle_new
 poppler_rectangle_copy
 poppler_rectangle_free
commit 0dd157ae7f19cd91ea425a607b968f08addc3a40
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Sun May 20 10:37:47 2012 +0200

    glib: Take a reference of the core annotation when creating a PopplerAnnot
    
    This way if the annotation is removed from the page, the core annotation
    object is not destroyed. Also, a new PopplerAnnot that is never added to
    a page doesn't leak the core annotation anymore.

diff --git a/glib/poppler-annot.cc b/glib/poppler-annot.cc
index 2a544f1..728e64b 100644
--- a/glib/poppler-annot.cc
+++ b/glib/poppler-annot.cc
@@ -114,12 +114,27 @@ G_DEFINE_TYPE (PopplerAnnotFileAttachment, poppler_annot_file_attachment, POPPLE
 G_DEFINE_TYPE (PopplerAnnotMovie, poppler_annot_movie, POPPLER_TYPE_ANNOT)
 G_DEFINE_TYPE (PopplerAnnotScreen, poppler_annot_screen, POPPLER_TYPE_ANNOT)
 
+static PopplerAnnot *
+_poppler_create_annot (GType annot_type, Annot *annot)
+{
+  PopplerAnnot *poppler_annot;
+
+  poppler_annot = POPPLER_ANNOT (g_object_new (annot_type, NULL));
+  poppler_annot->annot = annot;
+  annot->incRefCnt();
+
+  return poppler_annot;
+}
+
 static void
 poppler_annot_finalize (GObject *object)
 {
   PopplerAnnot *poppler_annot = POPPLER_ANNOT (object);
 
-  poppler_annot->annot = NULL;
+  if (poppler_annot->annot) {
+    poppler_annot->annot->decRefCnt();
+    poppler_annot->annot = NULL;
+  }
 
   G_OBJECT_CLASS (poppler_annot_parent_class)->finalize (object);
 }
@@ -140,12 +155,7 @@ poppler_annot_class_init (PopplerAnnotClass *klass)
 PopplerAnnot *
 _poppler_annot_new (Annot *annot)
 {
-  PopplerAnnot *poppler_annot;
-
-  poppler_annot = POPPLER_ANNOT (g_object_new (POPPLER_TYPE_ANNOT, NULL));
-  poppler_annot->annot = annot;
-
-  return poppler_annot;
+  return _poppler_create_annot (POPPLER_TYPE_ANNOT, annot);
 }
 
 static void
@@ -171,12 +181,7 @@ poppler_annot_text_class_init (PopplerAnnotTextClass *klass)
 PopplerAnnot *
 _poppler_annot_text_new (Annot *annot)
 {
-  PopplerAnnot *poppler_annot;
-
-  poppler_annot = POPPLER_ANNOT (g_object_new (POPPLER_TYPE_ANNOT_TEXT, NULL));
-  poppler_annot->annot = annot;
-
-  return poppler_annot;
+  return _poppler_create_annot (POPPLER_TYPE_ANNOT_TEXT, annot);
 }
 
 /**
@@ -218,12 +223,7 @@ poppler_annot_free_text_class_init (PopplerAnnotFreeTextClass *klass)
 PopplerAnnot *
 _poppler_annot_free_text_new (Annot *annot)
 {
-  PopplerAnnot *poppler_annot;
-
-  poppler_annot = POPPLER_ANNOT (g_object_new (POPPLER_TYPE_ANNOT_FREE_TEXT, NULL));
-  poppler_annot->annot = annot;
-
-  return poppler_annot;
+  return _poppler_create_annot (POPPLER_TYPE_ANNOT_FREE_TEXT, annot);
 }
 
 static void
@@ -239,12 +239,7 @@ poppler_annot_file_attachment_class_init (PopplerAnnotFileAttachmentClass *klass
 PopplerAnnot *
 _poppler_annot_file_attachment_new (Annot *annot)
 {
-  PopplerAnnot *poppler_annot;
-
-  poppler_annot = POPPLER_ANNOT (g_object_new (POPPLER_TYPE_ANNOT_FILE_ATTACHMENT, NULL));
-  poppler_annot->annot = annot;
-
-  return poppler_annot;
+  return _poppler_create_annot (POPPLER_TYPE_ANNOT_FILE_ATTACHMENT, annot);
 }
 
 
@@ -280,9 +275,7 @@ _poppler_annot_movie_new (Annot *annot)
   PopplerAnnot *poppler_annot;
   AnnotMovie   *annot_movie;
 
-  poppler_annot = POPPLER_ANNOT (g_object_new (POPPLER_TYPE_ANNOT_MOVIE, NULL));
-  poppler_annot->annot = annot;
-
+  poppler_annot = _poppler_create_annot (POPPLER_TYPE_ANNOT_MOVIE, annot);
   annot_movie = static_cast<AnnotMovie *>(poppler_annot->annot);
   POPPLER_ANNOT_MOVIE (poppler_annot)->movie = _poppler_movie_new (annot_movie->getMovie());
 
@@ -322,9 +315,7 @@ _poppler_annot_screen_new (Annot *annot)
   AnnotScreen  *annot_screen;
   LinkAction   *action;
 
-  poppler_annot = POPPLER_ANNOT (g_object_new (POPPLER_TYPE_ANNOT_SCREEN, NULL));
-  poppler_annot->annot = annot;
-
+  poppler_annot = _poppler_create_annot (POPPLER_TYPE_ANNOT_SCREEN, annot);
   annot_screen = static_cast<AnnotScreen *>(poppler_annot->annot);
   action = annot_screen->getAction();
   if (action)


More information about the poppler mailing list