[poppler] glib/poppler-page.cc glib/poppler-private.h glib/test-poppler-glib.cc

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Thu Mar 20 03:42:49 PDT 2008


 glib/poppler-page.cc      |   60 ++++++++++++++++++++++++++--------------------
 glib/poppler-private.h    |    3 --
 glib/test-poppler-glib.cc |    9 ++++++
 3 files changed, 43 insertions(+), 29 deletions(-)

New commits:
commit 21fa476ac384256c15a954b708e009f2b336b06f
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Thu Mar 20 11:42:32 2008 +0100

    [glib] Do not cache image_dev in poppler page.
    
    Thanks to Kouhei Sutou who caught the problem.

diff --git a/glib/poppler-page.cc b/glib/poppler-page.cc
index 5cbc5a8..e393601 100644
--- a/glib/poppler-page.cc
+++ b/glib/poppler-page.cc
@@ -75,10 +75,6 @@ poppler_page_finalize (GObject *object)
     delete page->gfx;
   if (page->text_dev != NULL)
     delete page->text_dev;
-#if defined (HAVE_CAIRO)
-  if (page->image_dev != NULL)
-    delete page->image_dev;
-#endif
   /* page->page is owned by the document */
 }
 
@@ -1195,28 +1191,28 @@ poppler_page_get_image_output_dev (PopplerPage *page,
 				   GBool (*imgDrawDeviceCbk)(int img_id, void *data),
 				   void *imgDrawCbkData)
 {
-  if (page->image_dev == NULL) {
-    page->image_dev = new CairoImageOutputDev ();
-
-    if (imgDrawDeviceCbk) {
-      page->image_dev->setImageDrawDecideCbk (imgDrawDeviceCbk,
-					      imgDrawCbkData);
-    }
+  CairoImageOutputDev *image_dev;
+  Gfx *gfx;
+  
+  image_dev = new CairoImageOutputDev ();
 
-    if (page->gfx)
-      delete page->gfx;
-    page->gfx = page->page->createGfx(page->image_dev,
-				      72.0, 72.0, 0,
-				      gFalse, /* useMediaBox */
-				      gTrue, /* Crop */
-				      -1, -1, -1, -1,
-				      gFalse, /* printing */
-				      page->document->doc->getCatalog (),
-				      NULL, NULL, NULL, NULL);
-    page->page->display(page->gfx);
+  if (imgDrawDeviceCbk) {
+    image_dev->setImageDrawDecideCbk (imgDrawDeviceCbk,
+				      imgDrawCbkData);
   }
 
-  return page->image_dev;
+  gfx = page->page->createGfx(image_dev,
+			      72.0, 72.0, 0,
+			      gFalse, /* useMediaBox */
+			      gTrue, /* Crop */
+			      -1, -1, -1, -1,
+			      gFalse, /* printing */
+			      page->document->doc->getCatalog (),
+			      NULL, NULL, NULL, NULL);
+  page->page->display(gfx);
+  delete gfx;
+
+  return image_dev;
 }
 
 /**
@@ -1261,6 +1257,8 @@ poppler_page_get_image_mapping (PopplerPage *page)
     map_list = g_list_prepend (map_list, mapping);
   }
 
+  delete out;
+
   return map_list;	
 }
 
@@ -1292,11 +1290,23 @@ poppler_page_get_image (PopplerPage *page,
 					   image_draw_decide_cb,
 					   GINT_TO_POINTER (image_id));
 
-  if (image_id >= out->getNumImages ())
+  if (image_id >= out->getNumImages ()) {
+    delete out;
+    
     return NULL;
+  }
 
   image = out->getImage (image_id)->getImage ();
-  return image ? cairo_surface_reference (image) : NULL;
+  if (!image) {
+    delete out;
+
+    return NULL;
+  }
+
+  cairo_surface_reference (image);
+  delete out;
+  
+  return image;
 }
 
 /**
diff --git a/glib/poppler-private.h b/glib/poppler-private.h
index 2d21285..539714c 100644
--- a/glib/poppler-private.h
+++ b/glib/poppler-private.h
@@ -59,9 +59,6 @@ struct _PopplerPage
   TextOutputDev *text_dev;
   Gfx *gfx;
   Annots *annots;
-#if defined (HAVE_CAIRO)
-  CairoImageOutputDev *image_dev;
-#endif
 };
 
 struct _PopplerFormField
diff --git a/glib/test-poppler-glib.cc b/glib/test-poppler-glib.cc
index 1b2f89b..65d4516 100644
--- a/glib/test-poppler-glib.cc
+++ b/glib/test-poppler-glib.cc
@@ -447,13 +447,20 @@ int main (int argc, char *argv[])
   for (l = list; l != NULL; l = l->next)
     {
       PopplerImageMapping *mapping;
-      
+#if defined (HAVE_CAIRO)
+      cairo_surface_t     *image;
+#endif
       mapping = (PopplerImageMapping *)l->data;
       printf ("\t\t(%f, %f) - (%f, %f)\n",
 	      mapping->area.x1,
 	      mapping->area.y1,
 	      mapping->area.x2,
 	      mapping->area.y2);
+#if defined (HAVE_CAIRO)
+      image = poppler_page_get_image (page, mapping->image_id);
+      printf ("\t\tImage: %p\n", image);
+      cairo_surface_destroy (image);
+#endif
     }
   poppler_page_free_image_mapping (list);
 


More information about the poppler mailing list