]> www.fi.muni.cz Git - evince.git/commitdiff
New misc file to do simple drop shadows.
authorJonathan Blandford <jrb@redhat.com>
Wed, 5 Jan 2005 07:35:14 +0000 (07:35 +0000)
committerJonathan Blandford <jrb@src.gnome.org>
Wed, 5 Jan 2005 07:35:14 +0000 (07:35 +0000)
Wed Jan  5 02:33:06 2005  Jonathan Blandford  <jrb@redhat.com>

        * backend/ev-document-misc.[ch]: New misc file to do simple drop
        shadows.

        * pdf/xpdf/pdf-document.cc: use the drop shadows in both types of
        thumbnails..

ChangeLog
backend/Makefile.am
backend/ev-document-misc.c [new file with mode: 0644]
backend/ev-document-misc.h [new file with mode: 0644]
pdf/xpdf/pdf-document.cc
shell/Makefile.am
shell/ev-sidebar-thumbnails.c

index 72838591dd5d73ab1afc43e2ac12d1bdbaed365e..46f733495aba3eeec39ed343b3a3afed1fb4e1a8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Wed Jan  5 02:33:06 2005  Jonathan Blandford  <jrb@redhat.com>
+
+       * backend/ev-document-misc.[ch]: New misc file to do simple drop
+       shadows.
+
+       * pdf/xpdf/pdf-document.cc: use the drop shadows in both types of
+       thumbnails..
+
 Tue Jan  4 22:32:32 2005  Jonathan Blandford  <jrb@redhat.com>
 
        * pdf/xpdf/pdf-document.cc
index 1e77a3535d835d6e74d9a66e134025494583b669..e2c32450e489bcca7831151010ab5f45a70b9d15 100644 (file)
@@ -21,6 +21,8 @@ libevbackend_la_SOURCES=                      \
        ev-document-find.h                      \
        ev-ps-exporter.c                        \
        ev-ps-exporter.h                        \
+       ev-document-misc.h                      \
+       ev-document-misc.c                      \
        $(NULL)
 
 BUILT_SOURCES=                         \
diff --git a/backend/ev-document-misc.c b/backend/ev-document-misc.c
new file mode 100644 (file)
index 0000000..ca818b7
--- /dev/null
@@ -0,0 +1,53 @@
+
+#include "ev-document-misc.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. */
+GdkPixbuf *
+ev_document_misc_get_thumbnail_frame (int        width,
+                                     int        height,
+                                     GdkPixbuf *source_pixbuf)
+{
+       GdkPixbuf *retval;
+       guchar *data;
+       gint rowstride;
+
+       if (source_pixbuf)
+               g_return_val_if_fail (GDK_IS_PIXBUF (source_pixbuf), NULL);
+
+       if (source_pixbuf) {
+               width = gdk_pixbuf_get_width (source_pixbuf);
+               height = gdk_pixbuf_get_height (source_pixbuf);
+       }
+
+       /* make sure no one is passing us garbage */
+       g_assert (width > 0 && height > 0);
+
+       retval = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
+                                TRUE, 8,
+                                width + 4,
+                                height + 4);
+       gdk_pixbuf_fill (retval, 0x000000ff);
+       if (source_pixbuf)
+               gdk_pixbuf_copy_area (source_pixbuf, 0, 0,
+                                     width,
+                                     height,
+                                     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;
+       data [(width + 3) * 4 + (rowstride * 1) + 3] = 0;
+
+       data [(height + 2) * rowstride + 3] = 0;
+       data [(height + 3) * rowstride + 3] = 0;
+       data [(height + 2) * rowstride + 4 + 3] = 0;
+       data [(height + 3) * rowstride + 4 + 3] = 0;
+
+       return retval;
+}
diff --git a/backend/ev-document-misc.h b/backend/ev-document-misc.h
new file mode 100644 (file)
index 0000000..1fae363
--- /dev/null
@@ -0,0 +1,37 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
+/*
+ *  Copyright (C) 2000-2003 Marco Pesenti Gritti
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *  $Id$
+ */
+
+#ifndef EV_DOCUMENT_MISC_H
+#define EV_DOCUMENT_MISC_H
+
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+G_BEGIN_DECLS
+
+
+GdkPixbuf *ev_document_misc_get_thumbnail_frame (int        width,
+                                                int        height,
+                                                GdkPixbuf *source_pixbuf);
+
+G_END_DECLS
+
+#endif /* EV_DOCUMENT_MISC_H */
index 4abe9ff32459f21bdd9a9207a8ce68d65cab231f..76229dbcfedeb9b530d580f2cc30ae46b4db4553 100644 (file)
@@ -25,6 +25,7 @@
 #include "ev-document-find.h"
 #include "gpdf-g-switch.h"
 #include "ev-document-bookmarks.h"
+#include "ev-document-misc.h"
 #include "ev-document-thumbnails.h"
 
 #include "GlobalParams.h"
@@ -1023,8 +1024,6 @@ pdf_document_thumbnails_get_page_pixbuf (PdfDocument *pdf_document,
        GDKSplashOutputDev *output;
        GdkPixbuf *pixbuf;
        GdkPixbuf *shadow;
-       gint rowstride;
-       guchar *data;
 
        pixmap = gdk_pixmap_new (pdf_document->target,
                                 width, height, -1);
@@ -1050,31 +1049,9 @@ pdf_document_thumbnails_get_page_pixbuf (PdfDocument *pdf_document,
        gdk_drawable_unref (pixmap);
        delete output;
 
-       shadow = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
-                                TRUE, 8,
-                                width + 4,
-                                height + 4);
-       gdk_pixbuf_fill (shadow, 0x000000ff);
-       gdk_pixbuf_copy_area (pixbuf, 0, 0,
-                             width,
-                             height,
-                             shadow,
-                             1, 1);
+       shadow = ev_document_misc_get_thumbnail_frame (-1, -1, pixbuf);
        g_object_unref (pixbuf);
 
-       /* Add the corner */
-       data = gdk_pixbuf_get_pixels (shadow);
-       rowstride = gdk_pixbuf_get_rowstride (shadow);
-       data [(width + 2) * 4 + 3] = 0;
-       data [(width + 3) * 4 + 3] = 0;
-       data [(width + 2) * 4 + (rowstride * 1) + 3] = 0;
-       data [(width + 3) * 4 + (rowstride * 1) + 3] = 0;
-
-       data [(height + 2) * rowstride + 3] = 0;
-       data [(height + 3) * rowstride + 3] = 0;
-       data [(height + 2) * rowstride + 4 + 3] = 0;
-       data [(height + 3) * rowstride + 4 + 3] = 0;
-       
        return shadow;
 }
 
@@ -1089,11 +1066,17 @@ pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails
        Object the_thumb;
        Thumb *thumb = NULL;
        gboolean have_ethumbs = FALSE;
+       gdouble page_ratio;
+       gint dest_height;
 
        /* getPage seems to want page + 1 for some reason; */
        the_page = pdf_document->doc->getCatalog ()->getPage (page + 1);
        the_page->getThumb(&the_thumb);
 
+       page_ratio = the_page->getHeight () / the_page->getWidth ();
+       dest_height = (gint) (width * page_ratio);
+
+
        if (!(the_thumb.isNull () || the_thumb.isNone())) {
                /* Build the thumbnail object */
                thumb = new Thumb(pdf_document->doc->getXRef (),
@@ -1107,7 +1090,6 @@ pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails
                GdkPixbuf *tmp_pixbuf;
 
                data = thumb->getPixbufData();
-               /* FISME: scale the image if it's not an appropriate size */
                tmp_pixbuf = gdk_pixbuf_new_from_data (data,
                                                       GDK_COLORSPACE_RGB,
                                                       FALSE,
@@ -1116,24 +1098,19 @@ pdf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document_thumbnails
                                                       thumb->getHeight (),
                                                       thumb->getWidth () * 3,
                                                       NULL, NULL);
-
-               thumbnail = tmp_pixbuf;
+               /* FIXME: do we want to check that the thumb's size isn't ridiculous?? */
+               thumbnail = ev_document_misc_get_thumbnail_frame (-1, -1, tmp_pixbuf);
+               g_object_unref (tmp_pixbuf);
        } else {
-               gdouble page_ratio;
                gdouble scale_factor;
-               gint dest_height;
 
-               page_ratio = the_page->getHeight () / the_page->getWidth ();
                scale_factor = (gdouble)width / the_page->getWidth ();
-               dest_height = (gint) (width * page_ratio);
 
                thumbnail = pdf_document_thumbnails_get_page_pixbuf (pdf_document,
                                                                     scale_factor,
                                                                     page,
                                                                     width,
                                                                     dest_height);
-
-               /* FIXME: Actually get the image... */
        }
 
        return thumbnail;
index b528da90cf5c567671d1dcd63fc3d6b1e1dbb4e3..87ef0f1d12f5113c2da47af34489c652b7742e84 100644 (file)
@@ -41,8 +41,6 @@ evince_SOURCES=                               \
        ev-sidebar-thumbnails.h         \
        ev-stock-icons.c                \
        ev-stock-icons.h                \
-       ev-utils.c                      \
-       ev-utils.h                      \
        main.c                          \
        $(NULL)
 
index a80f24e877ed9c46722d6ad21a5f5d7f337adbf4..4154be3c56ec3f55763e4108266fd022426d28fb 100644 (file)
@@ -33,7 +33,7 @@
 #include "ev-document-thumbnails.h"
 #include "ev-utils.h"
 
-#define THUMBNAIL_WIDTH 96
+#define THUMBNAIL_WIDTH 75
 /* Amount of time we devote to each iteration of the idle, in microseconds */
 #define IDLE_WORK_LENGTH 5000
 
@@ -96,6 +96,7 @@ ev_sidebar_thumbnails_init (EvSidebarThumbnails *ev_sidebar_thumbnails)
 {
        GtkWidget *swindow;
        EvSidebarThumbnailsPrivate *priv;
+       GtkCellRenderer *renderer;
 
        priv = ev_sidebar_thumbnails->priv = EV_SIDEBAR_THUMBNAILS_GET_PRIVATE (ev_sidebar_thumbnails);
 
@@ -103,12 +104,17 @@ ev_sidebar_thumbnails_init (EvSidebarThumbnails *ev_sidebar_thumbnails)
        priv->tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (priv->list_store));
 
        gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (priv->tree_view), FALSE);
+       renderer = g_object_new (GTK_TYPE_CELL_RENDERER_PIXBUF,
+                                "xpad", 2,
+                                "ypad", 2,
+                                NULL);
        gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->tree_view), -1,
-                                                    NULL, gtk_cell_renderer_pixbuf_new (),
-                                                    "pixbuf", 1, NULL);
+                                                    NULL, renderer,
+                                                    "pixbuf", 1,
+                                                    NULL);
        gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (priv->tree_view), -1,
                                                     NULL, gtk_cell_renderer_text_new (),
-                                                    "text", 0, NULL);
+                                                    "markup", 0, NULL);
        
        g_object_unref (priv->list_store);
 
@@ -138,20 +144,13 @@ static gboolean
 do_one_iteration (EvSidebarThumbnails *ev_sidebar_thumbnails)
 {
        EvSidebarThumbnailsPrivate *priv = ev_sidebar_thumbnails->priv;
-       GdkPixbuf *tmp, *pixbuf;
+       GdkPixbuf *pixbuf;
        GtkTreePath *path;
        GtkTreeIter iter;
 
-       tmp = ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (priv->document),
-                                                   priv->current_page, THUMBNAIL_WIDTH);
+       pixbuf = ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (priv->document),
+                                                      priv->current_page, THUMBNAIL_WIDTH);
 
-#if 0
-       /* Don't add the shadow for now, as it's really slow */
-       pixbuf = g_object_ref (tmp);
-#else
-       /* Add shadow */
-       pixbuf = ev_pixbuf_add_shadow (tmp, 5, 0, 0, 0.5);
-#endif
        path = gtk_tree_path_new_from_indices (priv->current_page, -1);
        gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->list_store), &iter, path);
        gtk_tree_path_free (path);
@@ -160,7 +159,6 @@ do_one_iteration (EvSidebarThumbnails *ev_sidebar_thumbnails)
                            COLUMN_PIXBUF, pixbuf,
                            -1);
 
-       g_object_unref (tmp);
        g_object_unref (pixbuf);
        
        priv->current_page++;
@@ -229,7 +227,7 @@ ev_sidebar_thumbnails_set_document (EvSidebarThumbnails *sidebar_thumbnails,
                GtkTreeIter iter;
                gchar *page;
 
-               page = g_strdup_printf ("Page %d", i + 1);
+               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,