+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
#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,
GdkPixbuf *retval;
guchar *data;
gint rowstride;
+ int i;
if (source_pixbuf)
g_return_val_if_fail (GDK_IS_PIXBUF (source_pixbuf), NULL);
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,
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;
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);
}
+
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
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,
pdf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
{
iface->get_thumbnail = pdf_document_thumbnails_get_thumbnail;
+ iface->get_dimensions = pdf_document_thumbnails_get_dimensions;
}
g_free (stack_data);
}
-#if 0
static gboolean
do_one_iteration (EvSidebarBookmarks *ev_sidebar_bookmarks)
{
#endif
return TRUE;
}
-#endif
+
void
ev_sidebar_bookmarks_clear_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);
}
}
#include "ev-sidebar-thumbnails.h"
#include "ev-document-thumbnails.h"
+#include "ev-document-misc.h"
#include "ev-utils.h"
#define THUMBNAIL_WIDTH 75
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));
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;
}