[Xfce4-commits] <tumbler:master> Add poppler-based PDF/PS thumbnailer plugin. New error code NO_CONTENT.

Jannis Pohlmann noreply at xfce.org
Fri Jul 16 16:22:01 CEST 2010


Updating branch refs/heads/master
         to 7285f9ef7882c2b531464fa3f7b4b3bed09d3c2c (commit)
       from ef32c8cc68d277e8b86ce3081a4aa6a12f5ba377 (commit)

commit 7285f9ef7882c2b531464fa3f7b4b3bed09d3c2c
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Fri Jul 16 16:19:46 2010 +0200

    Add poppler-based PDF/PS thumbnailer plugin. New error code NO_CONTENT.
    
    This commit introduces a simple PDF/PS thumbnailer based on
    poppler-glib. It also adds a new error code TUMBLER_ERROR_NO_CONTENT for
    documents that are not empty files but do not contain thumbnailable
    content.

 acinclude.m4                                       |   24 +++++
 configure.ac                                       |    7 ++
 plugins/Makefile.am                                |    1 +
 .../Makefile.am                                    |   30 +++---
 .../poppler-thumbnailer-plugin.c}                  |   14 ++--
 .../poppler-thumbnailer-provider.c}                |   57 ++++++------
 .../poppler-thumbnailer-provider.h                 |   43 +++++++++
 .../poppler-thumbnailer.c}                         |   98 +++++++++++++-------
 plugins/poppler-thumbnailer/poppler-thumbnailer.h  |   43 +++++++++
 tumbler/tumbler-error.h                            |    1 +
 10 files changed, 234 insertions(+), 84 deletions(-)

diff --git a/acinclude.m4 b/acinclude.m4
index ca93400..e2d374b 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -145,6 +145,30 @@ AC_MSG_RESULT([$ac_tumbler_ffmpeg_thumbnailer])
 
 
 
+dnl TUMBLER_POPPLER_THUMBNAILER()
+dnl
+dnl Check whether to build and install the poppler PDF/PS thumbnailer plugin.
+dnl
+AC_DEFUN([TUMBLER_POPPLER_THUMBNAILER],
+[
+AC_ARG_ENABLE([poppler-thumbnailer], [AC_HELP_STRING([--disable-poppler-thumbnailer], [Don't build the poppler PDF/PS thumbnailer plugin])],
+  [ac_tumbler_poppler_thumbnailer=$enableval], [ac_tumbler_poppler_thumbnailer=yes])
+if test x"$ac_tumbler_poppler_thumbnailer" = x"yes"; then
+  dnl Check for gdk-pixbuf
+  PKG_CHECK_MODULES([GDK_PIXBUF], [gdk-pixbuf-2.0 >= 2.14], 
+  [
+    dnl Check for poppler-glib
+    PKG_CHECK_MODULES([POPPLER_GLIB], [poppler-glib >= 0.12.0], [], [ac_tumbler_poppler_thumbnailer=no])
+  ], [ac_tumbler_poppler_thumbnailer=no])
+fi
+
+AC_MSG_CHECKING([whether to build the poppler PDF/PS thumbnailer plugin])
+AM_CONDITIONAL([TUMBLER_POPPLER_THUMBNAILER], [test x"$ac_tumbler_poppler_thumbnailer" = x"yes"])
+AC_MSG_RESULT([$ac_tumbler_poppler_thumbnailer])
+])
+
+
+
 dnl TUMBLER_XDG_CACHE()
 dnl
 dnl Check whether to build and install the freedesktop.org cache plugin.
diff --git a/configure.ac b/configure.ac
index 599ccc8..23b5fc7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -154,6 +154,7 @@ TUMBLER_FONT_THUMBNAILER()
 TUMBLER_JPEG_THUMBNAILER()
 TUMBLER_PIXBUF_THUMBNAILER()
 TUMBLER_FFMPEG_THUMBNAILER()
+TUMBLER_POPPLER_THUMBNAILER()
 TUMBLER_XDG_CACHE()
 
 dnl ***********************************
@@ -183,6 +184,7 @@ plugins/font-thumbnailer/Makefile
 plugins/jpeg-thumbnailer/Makefile
 plugins/pixbuf-thumbnailer/Makefile
 plugins/ffmpeg-thumbnailer/Makefile
+plugins/poppler-thumbnailer/Makefile
 plugins/xdg-cache/Makefile
 po/Makefile.in
 tumbler/Makefile
@@ -221,6 +223,11 @@ echo "  * Video thumbnailer plugin using ffmpegthumbnailer: yes"
 else
 echo "  * Video thumbnailer plugin using ffmpegthumbnailer: no"
 fi
+if test x"$ac_tumbler_poppler_thumbnailer" = x"yes"; then
+echo "  * PDF/PS thumbnailer plugin using poppler:          yes"
+else
+echo "  * PDF/PS thumbnailer plugin using poppler:          no"
+fi
 if test x"$ac_tumbler_xdg_cache" = x"yes"; then
 echo "  * Freedesktop.org cache plugin:                     yes"
 else
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 1320b14..7894a05 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -22,4 +22,5 @@ SUBDIRS =								\
 	jpeg-thumbnailer						\
 	pixbuf-thumbnailer						\
 	ffmpeg-thumbnailer						\
+	poppler-thumbnailer						\
 	xdg-cache
diff --git a/plugins/jpeg-thumbnailer/Makefile.am b/plugins/poppler-thumbnailer/Makefile.am
similarity index 69%
copy from plugins/jpeg-thumbnailer/Makefile.am
copy to plugins/poppler-thumbnailer/Makefile.am
index d4d88a5..eaa352e 100644
--- a/plugins/jpeg-thumbnailer/Makefile.am
+++ b/plugins/poppler-thumbnailer/Makefile.am
@@ -1,6 +1,6 @@
 # vi:set ts=8 sw=8 noet ai nocindent:
 # -
-# Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+# Copyright (c) 2010 Jannis Pohlmann <jannis at xfce.org>
 # 
 # This program is free software; you can redistribute it and/or 
 # modify it under the terms of the GNU General Public License as
@@ -17,42 +17,42 @@
 # Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 # Boston, MA 02110-1301, USA.
 
-if TUMBLER_JPEG_THUMBNAILER
+if TUMBLER_POPPLER_THUMBNAILER
 
 tumbler_plugindir = $(libdir)/tumbler-$(TUMBLER_VERSION_API)/plugins
 tumbler_plugin_LTLIBRARIES =						\
-	tumbler-jpeg-thumbnailer.la
+	tumbler-poppler-thumbnailer.la
 
-tumbler_jpeg_thumbnailer_la_SOURCES =					\
-	jpeg-thumbnailer-plugin.c					\
-	jpeg-thumbnailer-provider.c					\
-	jpeg-thumbnailer-provider.h					\
-	jpeg-thumbnailer.c						\
-	jpeg-thumbnailer.h
+tumbler_poppler_thumbnailer_la_SOURCES =				\
+	poppler-thumbnailer-plugin.c					\
+	poppler-thumbnailer-provider.c					\
+	poppler-thumbnailer-provider.h					\
+	poppler-thumbnailer.c						\
+	poppler-thumbnailer.h
 
-tumbler_jpeg_thumbnailer_la_CFLAGS =					\
+tumbler_poppler_thumbnailer_la_CFLAGS =					\
 	-I$(top_builddir)						\
 	-I$(top_builddir)/plugins					\
 	-I$(top_srcdir)							\
 	-I$(top_srcdir)/plugins						\
-	-DG_LOG_DOMAIN=\"tumbler-jpeg-thumbnailer\"			\
+	-DG_LOG_DOMAIN=\"tumbler-poppler-thumbnailer\"			\
 	-DPACKAGE_LOCALE_DIR=\"$(localedir)\"				\
 	$(GDK_PIXBUF_CFLAGS)						\
 	$(GIO_CFLAGS)							\
 	$(GLIB_CFLAGS)							\
-	$(LIBJPEG_CFLAGS)						\
+	$(POPPLER_GLIB_CFLAGS)						\
 	$(PLATFORM_CPPFLAGS)
 
-tumbler_jpeg_thumbnailer_la_LDFLAGS =					\
+tumbler_poppler_thumbnailer_la_LDFLAGS =				\
 	-avoid-version							\
 	-export-dynamic							\
 	-module								\
 	$(PLATFORM_LDFLAGS)
 
-tumbler_jpeg_thumbnailer_la_LIBADD =					\
+tumbler_poppler_thumbnailer_la_LIBADD =					\
 	$(GDK_PIXBUF_LIBS)						\
 	$(GIO_LIBS)							\
 	$(GLIB_LIBS)							\
-	$(LIBJPEG_LIBS)
+	$(POPPLER_GLIB_LIBS)
 
 endif
diff --git a/plugins/jpeg-thumbnailer/jpeg-thumbnailer-plugin.c b/plugins/poppler-thumbnailer/poppler-thumbnailer-plugin.c
similarity index 84%
copy from plugins/jpeg-thumbnailer/jpeg-thumbnailer-plugin.c
copy to plugins/poppler-thumbnailer/poppler-thumbnailer-plugin.c
index 3665291..6567de1 100644
--- a/plugins/jpeg-thumbnailer/jpeg-thumbnailer-plugin.c
+++ b/plugins/poppler-thumbnailer/poppler-thumbnailer-plugin.c
@@ -1,6 +1,6 @@
 /* vi:set et ai sw=2 sts=2 ts=2: */
 /*-
- * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ * Copyright (c) 2010 Jannis Pohlmann <jannis at xfce.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -28,8 +28,8 @@
 
 #include <tumbler/tumbler.h>
 
-#include <jpeg-thumbnailer/jpeg-thumbnailer-provider.h>
-#include <jpeg-thumbnailer/jpeg-thumbnailer.h>
+#include <poppler-thumbnailer/poppler-thumbnailer-provider.h>
+#include <poppler-thumbnailer/poppler-thumbnailer.h>
 
 
 
@@ -59,15 +59,15 @@ tumbler_plugin_initialize (TumblerProviderPlugin *plugin)
     }
 
 #ifdef DEBUG
-  g_message (_("Initializing the Tumbler Pixbuf Thumbnailer plugin"));
+  g_message (_("Initializing the Tumbler Poppler PDF/PS Thumbnailer plugin"));
 #endif
 
   /* register the types provided by this plugin */
-  jpeg_thumbnailer_register (plugin);
-  jpeg_thumbnailer_provider_register (plugin);
+  poppler_thumbnailer_register (plugin);
+  poppler_thumbnailer_provider_register (plugin);
 
   /* set up the plugin provider type list */
-  type_list[0] = TYPE_JPEG_THUMBNAILER_PROVIDER;
+  type_list[0] = TYPE_POPPLER_THUMBNAILER_PROVIDER;
 }
 
 
diff --git a/plugins/font-thumbnailer/font-thumbnailer-provider.c b/plugins/poppler-thumbnailer/poppler-thumbnailer-provider.c
similarity index 53%
copy from plugins/font-thumbnailer/font-thumbnailer-provider.c
copy to plugins/poppler-thumbnailer/poppler-thumbnailer-provider.c
index 65158a5..a049cee 100644
--- a/plugins/font-thumbnailer/font-thumbnailer-provider.c
+++ b/plugins/poppler-thumbnailer/poppler-thumbnailer-provider.c
@@ -1,6 +1,6 @@
 /* vi:set et ai sw=2 sts=2 ts=2: */
 /*-
- * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ * Copyright (c) 2010 Jannis Pohlmann <jannis at xfce.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -29,47 +29,47 @@
 
 #include <tumbler/tumbler.h>
 
-#include <font-thumbnailer/font-thumbnailer-provider.h>
-#include <font-thumbnailer/font-thumbnailer.h>
+#include <poppler-thumbnailer/poppler-thumbnailer-provider.h>
+#include <poppler-thumbnailer/poppler-thumbnailer.h>
 
 
 
-static void   font_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface);
-static GList *font_thumbnailer_provider_get_thumbnailers          (TumblerThumbnailerProvider      *provider);
+static void   poppler_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface);
+static GList *poppler_thumbnailer_provider_get_thumbnailers          (TumblerThumbnailerProvider      *provider);
 
 
 
-struct _FontThumbnailerProviderClass
+struct _PopplerThumbnailerProviderClass
 {
   GObjectClass __parent__;
 };
 
-struct _FontThumbnailerProvider
+struct _PopplerThumbnailerProvider
 {
   GObject __parent__;
 };
 
 
 
-G_DEFINE_DYNAMIC_TYPE_EXTENDED (FontThumbnailerProvider,
-                                font_thumbnailer_provider,
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (PopplerThumbnailerProvider,
+                                poppler_thumbnailer_provider,
                                 G_TYPE_OBJECT,
                                 0,
                                 TUMBLER_ADD_INTERFACE (TUMBLER_TYPE_THUMBNAILER_PROVIDER,
-                                                       font_thumbnailer_provider_thumbnailer_provider_init));
+                                                       poppler_thumbnailer_provider_thumbnailer_provider_init));
 
 
 
 void
-font_thumbnailer_provider_register (TumblerProviderPlugin *plugin)
+poppler_thumbnailer_provider_register (TumblerProviderPlugin *plugin)
 {
-  font_thumbnailer_provider_register_type (G_TYPE_MODULE (plugin));
+  poppler_thumbnailer_provider_register_type (G_TYPE_MODULE (plugin));
 }
 
 
 
 static void
-font_thumbnailer_provider_class_init (FontThumbnailerProviderClass *klass)
+poppler_thumbnailer_provider_class_init (PopplerThumbnailerProviderClass *klass)
 {
   GObjectClass *gobject_class;
 
@@ -79,54 +79,53 @@ font_thumbnailer_provider_class_init (FontThumbnailerProviderClass *klass)
 
 
 static void
-font_thumbnailer_provider_class_finalize (FontThumbnailerProviderClass *klass)
+poppler_thumbnailer_provider_class_finalize (PopplerThumbnailerProviderClass *klass)
 {
 }
 
 
 
 static void
-font_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface)
+poppler_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface)
 {
-  iface->get_thumbnailers = font_thumbnailer_provider_get_thumbnailers;
+  iface->get_thumbnailers = poppler_thumbnailer_provider_get_thumbnailers;
 }
 
 
 
 static void
-font_thumbnailer_provider_init (FontThumbnailerProvider *provider)
+poppler_thumbnailer_provider_init (PopplerThumbnailerProvider *provider)
 {
 }
 
 
 
 static GList *
-font_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider)
+poppler_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider)
 {
+  PopplerThumbnailer *thumbnailer;
+  GList              *thumbnailers = NULL;
   static const gchar *mime_types[] = 
-  { 
-    "application/x-font-otf",
-    "application/x-font-pcf",
-    "application/x-font-ttf",
-    "application/x-font-type1",
-    NULL,
+  {
+    "application/pdf",
+    "application/postscript",
+    NULL
   };
-  FontThumbnailer    *thumbnailer;
-  GList              *thumbnailers = NULL;
   GStrv               uri_schemes;
+  guint               n;
 
-  /* determine the URI schemes supported by GIO */
+  /* determine which URI schemes are supported by GIO */
   uri_schemes = tumbler_util_get_supported_uri_schemes ();
 
   /* create the pixbuf thumbnailer */
-  thumbnailer = g_object_new (TYPE_FONT_THUMBNAILER, 
+  thumbnailer = g_object_new (TYPE_POPPLER_THUMBNAILER, 
                               "uri-schemes", uri_schemes, "mime-types", mime_types, 
                               NULL);
 
   /* add the thumbnailer to the list */
   thumbnailers = g_list_append (thumbnailers, thumbnailer);
 
-  /* free URI schemes */
+  /* free URI schemes and MIME types */
   g_strfreev (uri_schemes);
 
   return thumbnailers;
diff --git a/plugins/poppler-thumbnailer/poppler-thumbnailer-provider.h b/plugins/poppler-thumbnailer/poppler-thumbnailer-provider.h
new file mode 100644
index 0000000..1596940
--- /dev/null
+++ b/plugins/poppler-thumbnailer/poppler-thumbnailer-provider.h
@@ -0,0 +1,43 @@
+/* vi:set et ai sw=2 sts=2 ts=2: */
+/*-
+ * Copyright (c) 2010 Jannis Pohlmann <jannis at xfce.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General 
+ * Public License along with this library; if not, write to the 
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __POPPLER_THUMBNAILER_PROVIDER_H__
+#define __POPPLER_THUMBNAILER_PROVIDER_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS;
+
+#define TYPE_POPPLER_THUMBNAILER_PROVIDER            (poppler_thumbnailer_provider_get_type ())
+#define POPPLER_THUMBNAILER_PROVIDER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_POPPLER_THUMBNAILER_PROVIDER, PopplerThumbnailerProvider))
+#define POPPLER_THUMBNAILER_PROVIDER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_POPPLER_THUMBNAILER_PROVIDER, PopplerThumbnailerProviderClass))
+#define IS_POPPLER_THUMBNAILER_PROVIDER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_POPPLER_THUMBNAILER_PROVIDER))
+#define IS_POPPLER_THUMBNAILER_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_POPPLER_THUMBNAILER_PROVIDER)
+#define POPPLER_THUMBNAILER_PROVIDER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_POPPLER_THUMBNAILER_PROVIDER, PopplerThumbnailerProviderClass))
+
+typedef struct _PopplerThumbnailerProviderClass PopplerThumbnailerProviderClass;
+typedef struct _PopplerThumbnailerProvider      PopplerThumbnailerProvider;
+
+GType poppler_thumbnailer_provider_get_type (void) G_GNUC_CONST;
+void  poppler_thumbnailer_provider_register (TumblerProviderPlugin *plugin);
+
+G_END_DECLS;
+
+#endif /* !__POPPLER_THUMBNAILER_PROVIDER_H__ */
diff --git a/plugins/pixbuf-thumbnailer/pixbuf-thumbnailer.c b/plugins/poppler-thumbnailer/poppler-thumbnailer.c
similarity index 61%
copy from plugins/pixbuf-thumbnailer/pixbuf-thumbnailer.c
copy to plugins/poppler-thumbnailer/poppler-thumbnailer.c
index 37ea1dc..5824581 100644
--- a/plugins/pixbuf-thumbnailer/pixbuf-thumbnailer.c
+++ b/plugins/poppler-thumbnailer/poppler-thumbnailer.c
@@ -1,6 +1,6 @@
 /* vi:set et ai sw=2 sts=2 ts=2: */
 /*-
- * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ * Copyright (c) 2010 Jannis Pohlmann <jannis at xfce.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -25,68 +25,71 @@
 #include <math.h>
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <glib-object.h>
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
 
+#include <poppler.h>
+
 #include <tumbler/tumbler.h>
 
-#include <pixbuf-thumbnailer/pixbuf-thumbnailer.h>
+#include <poppler-thumbnailer/poppler-thumbnailer.h>
 
 
 
-static void pixbuf_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
-                                       GCancellable               *cancellable,
-                                       TumblerFileInfo            *info);
+static void poppler_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
+                                        GCancellable               *cancellable,
+                                        TumblerFileInfo            *info);
 
 
 
-struct _PixbufThumbnailerClass
+struct _PopplerThumbnailerClass
 {
   TumblerAbstractThumbnailerClass __parent__;
 };
 
-struct _PixbufThumbnailer
+struct _PopplerThumbnailer
 {
   TumblerAbstractThumbnailer __parent__;
 };
 
 
 
-G_DEFINE_DYNAMIC_TYPE (PixbufThumbnailer, 
-                       pixbuf_thumbnailer,
+G_DEFINE_DYNAMIC_TYPE (PopplerThumbnailer, 
+                       poppler_thumbnailer,
                        TUMBLER_TYPE_ABSTRACT_THUMBNAILER);
 
 
 
 void
-pixbuf_thumbnailer_register (TumblerProviderPlugin *plugin)
+poppler_thumbnailer_register (TumblerProviderPlugin *plugin)
 {
-  pixbuf_thumbnailer_register_type (G_TYPE_MODULE (plugin));
+  poppler_thumbnailer_register_type (G_TYPE_MODULE (plugin));
 }
 
 
 
 static void
-pixbuf_thumbnailer_class_init (PixbufThumbnailerClass *klass)
+poppler_thumbnailer_class_init (PopplerThumbnailerClass *klass)
 {
   TumblerAbstractThumbnailerClass *abstractthumbnailer_class;
 
   abstractthumbnailer_class = TUMBLER_ABSTRACT_THUMBNAILER_CLASS (klass);
-  abstractthumbnailer_class->create = pixbuf_thumbnailer_create;
+  abstractthumbnailer_class->create = poppler_thumbnailer_create;
 }
 
 
 
 static void
-pixbuf_thumbnailer_class_finalize (PixbufThumbnailerClass *klass)
+poppler_thumbnailer_class_finalize (PopplerThumbnailerClass *klass)
 {
 }
 
 
 
 static void
-pixbuf_thumbnailer_init (PixbufThumbnailer *thumbnailer)
+poppler_thumbnailer_init (PopplerThumbnailer *thumbnailer)
 {
 }
 
@@ -133,21 +136,27 @@ generate_pixbuf (GdkPixbuf              *source,
 
 
 static void
-pixbuf_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
-                           GCancellable               *cancellable,
-                           TumblerFileInfo            *info)
+poppler_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
+                            GCancellable               *cancellable,
+                            TumblerFileInfo            *info)
 {
   TumblerThumbnailFlavor *flavor;
   GFileInputStream       *stream;
   TumblerImageData        data;
   TumblerThumbnail       *thumbnail;
+  PopplerDocument        *document;
+  PopplerPage            *page;
   const gchar            *uri;
   GdkPixbuf              *source_pixbuf;
   GdkPixbuf              *pixbuf;
   GError                 *error = NULL;
+  gdouble                 page_width;
+  gdouble                 page_height;
   GFile                  *file;
+  gint                    width;
+  gint                    height;
 
-  g_return_if_fail (IS_PIXBUF_THUMBNAILER (thumbnailer));
+  g_return_if_fail (IS_POPPLER_THUMBNAILER (thumbnailer));
   g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
   g_return_if_fail (TUMBLER_IS_FILE_INFO (info));
 
@@ -155,37 +164,59 @@ pixbuf_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
   if (g_cancellable_is_cancelled (cancellable)) 
     return;
 
+  /* try to load the poppler document */
   uri = tumbler_file_info_get_uri (info);
+  document = poppler_document_new_from_file (uri, NULL, &error);
 
-  /* try to open the source file for reading */
-  file = g_file_new_for_uri (uri);
-  stream = g_file_read (file, NULL, &error);
-  g_object_unref (file);
-
-  if (stream == NULL)
+  if (document == NULL)
     {
-      g_signal_emit_by_name (thumbnailer, "error", uri, error->code, error->message);
+      g_signal_emit_by_name (thumbnailer, "error", uri, TUMBLER_ERROR_UNSUPPORTED, error->message);
       g_error_free (error);
       return;
     }
 
-  source_pixbuf = gdk_pixbuf_new_from_stream (G_INPUT_STREAM (stream), 
-                                              cancellable, &error);
-  g_object_unref (stream);
+  /* check if the document has content */
+  if (poppler_document_get_n_pages (document) <= 0)
+    {
+      g_signal_emit_by_name (thumbnailer, "error", uri, TUMBLER_ERROR_NO_CONTENT, 
+                             _("The document is empty"));
+      g_object_unref (document);
+      return;
+    }
+
+  /* get the first page of the document */
+  page = poppler_document_get_page (document, 0);
 
-  if (source_pixbuf == NULL)
+  if (page == NULL)
     {
-      g_signal_emit_by_name (thumbnailer, "error", uri, error->code, error->message);
-      g_error_free (error);
+      g_signal_emit_by_name (thumbnailer, "error", uri, TUMBLER_ERROR_NO_CONTENT,
+                             _("First page of the document could not be read"));
+      g_object_unref (document);
       return;
     }
 
   thumbnail = tumbler_file_info_get_thumbnail (info);
-
   g_assert (thumbnail != NULL);
 
   /* generate a pixbuf for the thumbnail */
   flavor = tumbler_thumbnail_get_flavor (thumbnail);
+
+  /* try to extract the embedded thumbnail */
+  source_pixbuf = poppler_page_get_thumbnail_pixbuf (page);
+
+  if (source_pixbuf == NULL)
+    {
+      /* fall back to rendering the page ourselves */
+      poppler_page_get_size (page, &page_width, &page_height);
+      source_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, page_width, page_height);
+      poppler_page_render_to_pixbuf (page, 0, 0, page_width, page_height, 1.0, 0, source_pixbuf);
+    }
+
+  /* release allocated poppler data */
+  g_object_unref (page);
+  g_object_unref (document);
+
+  /* generate the final pixbuf (involves rescaling etc.) */
   pixbuf = generate_pixbuf (source_pixbuf, flavor);
   g_object_unref (flavor);
 
@@ -213,6 +244,7 @@ pixbuf_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
       g_signal_emit_by_name (thumbnailer, "ready", uri);
     }
 
+
   g_object_unref (thumbnail);
   g_object_unref (pixbuf);
   g_object_unref (source_pixbuf);
diff --git a/plugins/poppler-thumbnailer/poppler-thumbnailer.h b/plugins/poppler-thumbnailer/poppler-thumbnailer.h
new file mode 100644
index 0000000..0f072e2
--- /dev/null
+++ b/plugins/poppler-thumbnailer/poppler-thumbnailer.h
@@ -0,0 +1,43 @@
+/* vi:set et ai sw=2 sts=2 ts=2: */
+/*-
+ * Copyright (c) 2010 Jannis Pohlmann <jannis at xfce.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ * GNU Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General 
+ * Public License along with this library; if not, write to the 
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __POPPLER_THUMBNAILER_H__
+#define __POPPLER_THUMBNAILER_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS;
+
+#define TYPE_POPPLER_THUMBNAILER            (poppler_thumbnailer_get_type ())
+#define POPPLER_THUMBNAILER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_POPPLER_THUMBNAILER, PopplerThumbnailer))
+#define POPPLER_THUMBNAILER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_POPPLER_THUMBNAILER, PopplerThumbnailerClass))
+#define IS_POPPLER_THUMBNAILER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_POPPLER_THUMBNAILER))
+#define IS_POPPLER_THUMBNAILER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_POPPLER_THUMBNAILER)
+#define POPPLER_THUMBNAILER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_POPPLER_THUMBNAILER, PopplerThumbnailerClass))
+
+typedef struct _PopplerThumbnailerClass   PopplerThumbnailerClass;
+typedef struct _PopplerThumbnailer        PopplerThumbnailer;
+
+GType poppler_thumbnailer_get_type (void) G_GNUC_CONST;
+void  poppler_thumbnailer_register (TumblerProviderPlugin *plugin);
+
+G_END_DECLS;
+
+#endif /* !__POPPLER_THUMBNAILER_H__ */
diff --git a/tumbler/tumbler-error.h b/tumbler/tumbler-error.h
index df2ec6b..c6a1573 100644
--- a/tumbler/tumbler-error.h
+++ b/tumbler/tumbler-error.h
@@ -46,6 +46,7 @@ typedef enum /*< enum >*/
   TUMBLER_ERROR_IS_THUMBNAIL,
   TUMBLER_ERROR_SAVE_FAILED,
   TUMBLER_ERROR_UNSUPPORTED_FLAVOR,
+  TUMBLER_ERROR_NO_CONTENT,
 } TumblerErrorEnum;
 
 G_END_DECLS



More information about the Xfce4-commits mailing list