]> www.fi.muni.cz Git - evince.git/commitdiff
fill in the thumbnail with white. New interface to get the size of a page.
authorJonathan Blandford <jrb@redhat.com>
Thu, 6 Jan 2005 23:56:14 +0000 (23:56 +0000)
committerJonathan Blandford <jrb@src.gnome.org>
Thu, 6 Jan 2005 23:56:14 +0000 (23:56 +0000)
Thu Jan  6 18:48:11 2005  Jonathan Blandford  <jrb@redhat.com>

        * backend/ev-document-misc.c
        (ev_document_misc_get_thumbnail_frame): fill in the thumbnail with
        white.
        * backend/ev-document-thumbnails.h: New interface to get the size
        of a page.

ChangeLog
backend/ev-document-misc.c
backend/ev-document-thumbnails.c
backend/ev-document-thumbnails.h
pdf/xpdf/pdf-document.cc
shell/ev-sidebar-bookmarks.c
shell/ev-sidebar-thumbnails.c

index 22541bf9d413027488607760d843addc51a548cc..f74e941060306b515662f81bed540e522da777ee 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Thu Jan  6 18:48:11 2005  Jonathan Blandford  <jrb@redhat.com>
+
+       * backend/ev-document-misc.c
+       (ev_document_misc_get_thumbnail_frame): fill in the thumbnail with
+       white.
+       * backend/ev-document-thumbnails.h: New interface to get the size
+       of a page.
+
 2005-01-06  Jeremy Katz  <katzj@redhat.com>
 
        * shell/Makefile.am (evince_SOURCES): Add ev-utils.[ch] so that
index ca818b7fdeecfa0182af22bde2844e903478e361..d7d4beb9285aad0b209b058e4b86d6e5d92777b0 100644 (file)
@@ -1,10 +1,13 @@
 
 #include "ev-document-misc.h"
+#include <string.h>
 
 /* Returns a new GdkPixbuf that is suitable for placing in the thumbnail view.
  * It is four pixels wider and taller than the source.  If source_pixbuf is not
  * NULL, then it will fill the return pixbuf with the contents of
- * source_pixbuf. */
+ * source_pixbuf.
+ */
+
 GdkPixbuf *
 ev_document_misc_get_thumbnail_frame (int        width,
                                      int        height,
@@ -13,6 +16,7 @@ ev_document_misc_get_thumbnail_frame (int        width,
        GdkPixbuf *retval;
        guchar *data;
        gint rowstride;
+       int i;
 
        if (source_pixbuf)
                g_return_val_if_fail (GDK_IS_PIXBUF (source_pixbuf), NULL);
@@ -29,7 +33,16 @@ ev_document_misc_get_thumbnail_frame (int        width,
                                 TRUE, 8,
                                 width + 4,
                                 height + 4);
+
+       /* make it black and fill in the middle */
+       data = gdk_pixbuf_get_pixels (retval);
+       rowstride = gdk_pixbuf_get_rowstride (retval);
+
        gdk_pixbuf_fill (retval, 0x000000ff);
+       for (i = 1; i < height + 1; i++)
+               memset (data + (rowstride * i) + 4, 0xffffffff, width * 4);
+
+       /* copy the source pixbuf */
        if (source_pixbuf)
                gdk_pixbuf_copy_area (source_pixbuf, 0, 0,
                                      width,
@@ -37,8 +50,6 @@ ev_document_misc_get_thumbnail_frame (int        width,
                                      retval,
                                      1, 1);
        /* Add the corner */
-       data = gdk_pixbuf_get_pixels (retval);
-       rowstride = gdk_pixbuf_get_rowstride (retval);
        data [(width + 2) * 4 + 3] = 0;
        data [(width + 3) * 4 + 3] = 0;
        data [(width + 2) * 4 + (rowstride * 1) + 3] = 0;
index e9c53ab99555e5c3a2d4c3746a57b28e43cb05ee..ce2f21874860df356af9b456edb7a03000cbc8ec 100644 (file)
@@ -47,9 +47,30 @@ ev_document_thumbnails_get_type (void)
 GdkPixbuf *
 ev_document_thumbnails_get_thumbnail (EvDocumentThumbnails   *document,
                                      gint                    page,
-                                     gint                    width)
+                                     gint                    suggested_width)
 {
-       EvDocumentThumbnailsIface *iface = EV_DOCUMENT_THUMBNAILS_GET_IFACE (document);
-       
-       return iface->get_thumbnail (document, page, width);
+       EvDocumentThumbnailsIface *iface;
+
+       g_return_val_if_fail (EV_IS_DOCUMENT_THUMBNAILS (document), NULL);
+
+       iface = EV_DOCUMENT_THUMBNAILS_GET_IFACE (document);
+       return iface->get_thumbnail (document, page, suggested_width);
+}
+
+void
+ev_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
+                                      gint                  page,
+                                      gint                  suggested_width,
+                                      gint                 *width,
+                                      gint                 *height)
+{
+       EvDocumentThumbnailsIface *iface;
+
+       g_return_if_fail (EV_IS_DOCUMENT_THUMBNAILS (document));
+       g_return_if_fail (width != NULL);
+       g_return_if_fail (height != NULL);
+
+       iface = EV_DOCUMENT_THUMBNAILS_GET_IFACE (document);
+       iface->get_dimensions (document, page, suggested_width, width, height);
 }
+
index fdc1e80aae9f9486b54a5576beeef334b74a9eb3..52ed6c57329ebe80e87155a0ccc8cf87272ce54f 100644 (file)
 
 G_BEGIN_DECLS
 
-#define EV_TYPE_DOCUMENT_THUMBNAILS        (ev_document_thumbnails_get_type ())
-#define EV_DOCUMENT_THUMBNAILS(o)                  (G_TYPE_CHECK_INSTANCE_CAST ((o), EV_TYPE_DOCUMENT_THUMBNAILS, EvDocumentThumbnails))
-#define EV_DOCUMENT_THUMBNAILS_IFACE(k)            (G_TYPE_CHECK_CLASS_CAST((k), EV_TYPE_DOCUMENT_THUMBNAILS, EvDocumentThumbnailsIface))
-#define EV_IS_DOCUMENT_THUMBNAILS(o)       (G_TYPE_CHECK_INSTANCE_TYPE ((o), EV_TYPE_DOCUMENT_THUMBNAILS))
-#define EV_IS_DOCUMENT_THUMBNAILS_IFACE(k)         (G_TYPE_CHECK_CLASS_TYPE ((k), EV_TYPE_DOCUMENT_THUMBNAILS))
+#define EV_TYPE_DOCUMENT_THUMBNAILS         (ev_document_thumbnails_get_type ())
+#define EV_DOCUMENT_THUMBNAILS(o)                   (G_TYPE_CHECK_INSTANCE_CAST ((o), EV_TYPE_DOCUMENT_THUMBNAILS, EvDocumentThumbnails))
+#define EV_DOCUMENT_THUMBNAILS_IFACE(k)     (G_TYPE_CHECK_CLASS_CAST((k), EV_TYPE_DOCUMENT_THUMBNAILS, EvDocumentThumbnailsIface))
+#define EV_IS_DOCUMENT_THUMBNAILS(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), EV_TYPE_DOCUMENT_THUMBNAILS))
+#define EV_IS_DOCUMENT_THUMBNAILS_IFACE(k)          (G_TYPE_CHECK_CLASS_TYPE ((k), EV_TYPE_DOCUMENT_THUMBNAILS))
 #define EV_DOCUMENT_THUMBNAILS_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), EV_TYPE_DOCUMENT_THUMBNAILS, EvDocumentThumbnailsIface))
 
-typedef struct _EvDocumentThumbnails   EvDocumentThumbnails;
-typedef struct _EvDocumentThumbnailsIface      EvDocumentThumbnailsIface;
+typedef struct _EvDocumentThumbnails    EvDocumentThumbnails;
+typedef struct _EvDocumentThumbnailsIface       EvDocumentThumbnailsIface;
 
 struct _EvDocumentThumbnailsIface
 {
-       GTypeInterface base_iface;
+        GTypeInterface base_iface;
 
-       /* Methods  */
-       GdkPixbuf *  (* get_thumbnail) (EvDocumentThumbnails   *document,
-                                       gint                    page,
-                                       gint                    width);
+        /* Methods  */
+        GdkPixbuf *  (* get_thumbnail)  (EvDocumentThumbnails *document,
+                                         gint                  page,
+                                         gint                  width);
+        void         (* get_dimensions) (EvDocumentThumbnails *document,
+                                        gint                  page,
+                                        gint                  suggested_width,
+                                        gint                 *width,
+                                        gint                 *height);
 };
 
-GType ev_document_thumbnails_get_type (void);
-
-GdkPixbuf *ev_document_thumbnails_get_thumbnail (EvDocumentThumbnails   *document,
-                                                gint                    page,
-                                                gint                    width);
+GType      ev_document_thumbnails_get_type       (void);
+GdkPixbuf *ev_document_thumbnails_get_thumbnail  (EvDocumentThumbnails *document,
+                                                  gint                  page,
+                                                  gint                  suggested_width);
+void       ev_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
+                                                  gint                  page,
+                                                  gint                  suggested_width,
+                                                  gint                 *width,
+                                                  gint                 *height);
 
 G_END_DECLS
 
index d3f4ea68375ef4df60af99837c0c2a28f6e02261..a4049c664cf6ff510038bb7868a39205227d4ea5 100644 (file)
@@ -1138,6 +1138,39 @@ pdf_document_thumbnails_get_page_pixbuf (PdfDocument *pdf_document,
        return pixbuf;
 }
 
+static void
+pdf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document_thumbnails,
+                                       gint                  page,
+                                       gint                  suggested_width,
+                                       gint                 *width,
+                                       gint                 *height)
+{
+       PdfDocument *pdf_document = PDF_DOCUMENT (document_thumbnails);
+       Page *the_page;
+       Object the_thumb;
+       Thumb *thumb = NULL;
+       gdouble page_ratio;
+
+       /* getPage seems to want page + 1 for some reason; */
+       the_page = pdf_document->doc->getCatalog ()->getPage (page + 1);
+       the_page->getThumb (&the_thumb);
+
+
+
+       if (!(the_thumb.isNull () || the_thumb.isNone())) {
+               /* Build the thumbnail object */
+               thumb = new Thumb(pdf_document->doc->getXRef (),
+                                 &the_thumb);
+
+               *width = thumb->getWidth ();
+               *height = thumb->getHeight ();
+       } else {
+               page_ratio = the_page->getHeight () / the_page->getWidth ();
+               *width = suggested_width;
+               *height = (gint) (suggested_width * page_ratio);
+       }
+}
+
 static GdkPixbuf *
 pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails,
                                       gint                  page,
@@ -1202,6 +1235,7 @@ static void
 pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
 {
        iface->get_thumbnail = pdf_document_thumbnails_get_thumbnail;
+       iface->get_dimensions = pdf_document_thumbnails_get_dimensions;
 }
 
 
index a81759c4eac1d42814cb906598674af6b733452d..b215e1ed62debc091fa13ff58673c999da0a58ac 100644 (file)
@@ -203,7 +203,6 @@ stack_data_free (IdleStackData       *stack_data,
        g_free (stack_data);
 }
 
-#if 0
 static gboolean
 do_one_iteration (EvSidebarBookmarks *ev_sidebar_bookmarks)
 {
@@ -299,7 +298,7 @@ populate_bookmarks_idle (gpointer data)
 #endif
        return TRUE;
 }
-#endif
+
 void
 ev_sidebar_bookmarks_clear_document (EvSidebarBookmarks *sidebar_bookmarks)
 {
@@ -350,7 +349,7 @@ ev_sidebar_bookmarks_set_document (EvSidebarBookmarks *sidebar_bookmarks,
                stack_data->tree_iter = NULL;
 
                priv->idle_stack = g_list_prepend (priv->idle_stack, stack_data);
-               //priv->idle_id = g_idle_add (populate_bookmarks_idle, sidebar_bookmarks);
+               priv->idle_id = g_idle_add (populate_bookmarks_idle, sidebar_bookmarks);
        }
 }
 
index 573af69510946ec0f272a308994e26ab9b625117..7d9255f6474c085b9771f0f06e587a4d9c93116c 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "ev-sidebar-thumbnails.h"
 #include "ev-document-thumbnails.h"
+#include "ev-document-misc.h"
 #include "ev-utils.h"
 
 #define THUMBNAIL_WIDTH 75
@@ -224,9 +225,13 @@ void
 ev_sidebar_thumbnails_set_document (EvSidebarThumbnails *sidebar_thumbnails,
                                    EvDocument          *document)
 {
-       GtkIconTheme *theme;
        GdkPixbuf *loading_icon;
        gint i, n_pages;
+       GtkTreeIter iter;
+       gchar *page;
+       gint width = THUMBNAIL_WIDTH;
+       gint height = THUMBNAIL_WIDTH;
+
        EvSidebarThumbnailsPrivate *priv = sidebar_thumbnails->priv;
        
        g_return_if_fail (EV_IS_DOCUMENT_THUMBNAILS (document));
@@ -234,32 +239,27 @@ ev_sidebar_thumbnails_set_document (EvSidebarThumbnails *sidebar_thumbnails,
        if (priv->idle_id != 0) {
                g_source_remove (priv->idle_id);
        }
-       
-       theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (sidebar_thumbnails)));
+       n_pages = ev_document_get_n_pages (document);
+
+       priv->document = document;
+       priv->idle_id = g_idle_add (populate_thumbnails_idle, sidebar_thumbnails);
+       priv->n_pages = n_pages;
+       priv->current_page = 0;
 
-       loading_icon = gtk_icon_theme_load_icon (theme, "gnome-fs-loading-icon",
-                                                THUMBNAIL_WIDTH, 0, NULL);
+       /* We get the dimensions of the first doc so that   */
+       ev_document_thumbnails_get_dimensions (EV_DOCUMENT_THUMBNAILS (priv->document),
+                                              0, THUMBNAIL_WIDTH, &width, &height);
+       loading_icon = ev_document_misc_get_thumbnail_frame (width, height, NULL);
 
-       n_pages = ev_document_get_n_pages (document);
-       
        for (i = 0; i < n_pages; i++) {
-               GtkTreeIter iter;
-               gchar *page;
-
                page = g_strdup_printf ("<i>%d</i>", i + 1);
-               gtk_list_store_append (sidebar_thumbnails->priv->list_store,
-                                      &iter);
-               gtk_list_store_set (sidebar_thumbnails->priv->list_store,
-                                   &iter,
+               gtk_list_store_append (priv->list_store, &iter);
+               gtk_list_store_set (priv->list_store, &iter,
                                    COLUMN_PAGE_STRING, page,
                                    COLUMN_PIXBUF, loading_icon,
                                    -1);
                g_free (page);
        }
 
-       priv->document = document;
-       priv->idle_id = g_idle_add (populate_thumbnails_idle, sidebar_thumbnails);
-       priv->n_pages = n_pages;
-       priv->current_page = 0;
 }