From 2aadab6feb778de1be1a92f20ba60e44de571199 Mon Sep 17 00:00:00 2001 From: Jonathan Blandford Date: Thu, 6 Jan 2005 23:56:14 +0000 Subject: [PATCH] fill in the thumbnail with white. New interface to get the size of a page. Thu Jan 6 18:48:11 2005 Jonathan Blandford * 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 | 8 ++++++ backend/ev-document-misc.c | 17 ++++++++++--- backend/ev-document-thumbnails.c | 29 ++++++++++++++++++--- backend/ev-document-thumbnails.h | 43 +++++++++++++++++++------------- pdf/xpdf/pdf-document.cc | 34 +++++++++++++++++++++++++ shell/ev-sidebar-bookmarks.c | 5 ++-- shell/ev-sidebar-thumbnails.c | 36 +++++++++++++------------- 7 files changed, 127 insertions(+), 45 deletions(-) diff --git a/ChangeLog b/ChangeLog index 22541bf9..f74e9410 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Thu Jan 6 18:48:11 2005 Jonathan Blandford + + * 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 * shell/Makefile.am (evince_SOURCES): Add ev-utils.[ch] so that diff --git a/backend/ev-document-misc.c b/backend/ev-document-misc.c index ca818b7f..d7d4beb9 100644 --- a/backend/ev-document-misc.c +++ b/backend/ev-document-misc.c @@ -1,10 +1,13 @@ #include "ev-document-misc.h" +#include /* 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; diff --git a/backend/ev-document-thumbnails.c b/backend/ev-document-thumbnails.c index e9c53ab9..ce2f2187 100644 --- a/backend/ev-document-thumbnails.c +++ b/backend/ev-document-thumbnails.c @@ -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); } + diff --git a/backend/ev-document-thumbnails.h b/backend/ev-document-thumbnails.h index fdc1e80a..52ed6c57 100644 --- a/backend/ev-document-thumbnails.h +++ b/backend/ev-document-thumbnails.h @@ -25,31 +25,40 @@ 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 diff --git a/pdf/xpdf/pdf-document.cc b/pdf/xpdf/pdf-document.cc index d3f4ea68..a4049c66 100644 --- a/pdf/xpdf/pdf-document.cc +++ b/pdf/xpdf/pdf-document.cc @@ -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; } diff --git a/shell/ev-sidebar-bookmarks.c b/shell/ev-sidebar-bookmarks.c index a81759c4..b215e1ed 100644 --- a/shell/ev-sidebar-bookmarks.c +++ b/shell/ev-sidebar-bookmarks.c @@ -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); } } diff --git a/shell/ev-sidebar-thumbnails.c b/shell/ev-sidebar-thumbnails.c index 573af695..7d9255f6 100644 --- a/shell/ev-sidebar-thumbnails.c +++ b/shell/ev-sidebar-thumbnails.c @@ -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 ("%d", 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; } -- 2.43.5