modify the expose handling to get the shadows.
authorJonathan Blandford <jrb@redhat.com>
Sun, 29 May 2005 07:27:23 +0000 (07:27 +0000)
committerJonathan Blandford <jrb@src.gnome.org>
Sun, 29 May 2005 07:27:23 +0000 (07:27 +0000)
Sat May 28 07:38:03 2005  Jonathan Blandford  <jrb@redhat.com>

        * shell/ev-view.c (draw_one_page): modify the expose handling to
        get the shadows.

        * shell/ev-window.c (update_action_sensitivity): Respect
        permissions field.  Kowtow to the man.

        * pdf/ev-poppler.cc: Get the permissions field.

        * tiff/*c: Make a tiny bit more robust.

13 files changed:
ChangeLog
TODO
backend/ev-document-info.h
backend/ev-document.h
backend/ev-page-cache.c
backend/ev-page-cache.h
pdf/ev-poppler.cc
shell/Makefile.am
shell/ev-pixbuf-cache.c
shell/ev-view.c
shell/ev-window.c
thumbnailer/Makefile.am
tiff/tiff-document.c

index d16b617d158bf37ba6223fa672257106d5707a62..541ba77d5b0f5b12ff14f3f38cd3b1e316a2bb20 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Sat May 28 07:38:03 2005  Jonathan Blandford  <jrb@redhat.com>
+
+       * shell/ev-view.c (draw_one_page): modify the expose handling to
+       get the shadows.
+
+       * shell/ev-window.c (update_action_sensitivity): Respect
+       permissions field.  Kowtow to the man.
+
+       * pdf/ev-poppler.cc: Get the permissions field.
+
+       * tiff/*c: Make a tiny bit more robust.
+
 2005-05-26  Nickolay V. Shmyrev <nshmyrev@yandex.ru>
 
        * djvu/djvu-document.c:
diff --git a/TODO b/TODO
index b8c83c4d6730eb0f3cbf05292ea986d354ae72cf..576f2abc52e377aacc16070bb3c9f1e6c2654495 100644 (file)
--- a/TODO
+++ b/TODO
@@ -4,7 +4,6 @@ Improve Find system
        Display location of results in thumbnails?
        Only display thumbnails of pages found?
 
-
 Sidebar improvements for ps/pixbuf, or PDF files without a TOC.                bug 164811
 
 Improve Printing Support: (libgnomeprintui?)
@@ -14,16 +13,6 @@ Improve Printing Support: (libgnomeprintui?)
 
 Document Properties Dialog for document meta-data                      bug 164843
 
-Make an object that handles the page count.
-
-Move to having three sizing types:
-
- * Free zooming
- * constrain to width
- * constrain to height
- * also, maybe add a 1-1 button.  Possibly dubious, though.
-
-
 Add some code to sanity check documents, including:
 
  * n_pages > 0
@@ -43,3 +32,8 @@ Move to three page views:
  * Single page (prolly default for some backends)
  * Continuous scrolling                                                        bug 164597
  * Side-by-side continuous scrolling
+Make an object that handles the page count.
+Move to having three sizing types:
+ * Free zooming
+ * constrain to width
+ * constrain to height
index 15d27d03c796faf842d3cf7d67bc165db7be3b6c..02ea5b110035a085da893800b188cb60a78b312f 100644 (file)
@@ -60,6 +60,19 @@ typedef enum
        EV_DOCUMENT_UI_HINT_DIRECTION_RTL = 1 << 6,
 } EvDocumentUIHints;
 
+
+typedef enum
+{
+       EV_DOCUMENT_PERMISSIONS_OK_TO_PRINT = 1 << 0,
+       EV_DOCUMENT_PERMISSIONS_OK_TO_MODIFY = 1 << 1,
+       EV_DOCUMENT_PERMISSIONS_OK_TO_COPY = 1 << 2,
+       EV_DOCUMENT_PERMISSIONS_OK_TO_ADD_NOTES = 1 << 3,
+       EV_DOCUMENT_PERMISSIONS_FULL = (EV_DOCUMENT_PERMISSIONS_OK_TO_PRINT
+                                       | EV_DOCUMENT_PERMISSIONS_OK_TO_MODIFY
+                                       | EV_DOCUMENT_PERMISSIONS_OK_TO_COPY
+                                       | EV_DOCUMENT_PERMISSIONS_OK_TO_ADD_NOTES),
+} EvDocumentPermissions;
+
 typedef enum
 {
        EV_DOCUMENT_INFO_TITLE = 1 << 0,
@@ -71,6 +84,7 @@ typedef enum
        EV_DOCUMENT_INFO_START_MODE = 1 << 6,
        EV_DOCUMENT_INFO_CREATION_DATE = 1 << 7,
        EV_DOCUMENT_INFO_UI_HINTS = 1 << 8,
+       EV_DOCUMENT_INFO_PERMISSIONS = 1 << 9,
 } EvDocumentInfoFields;
 
 struct _EvDocumentInfo
@@ -84,6 +98,7 @@ struct _EvDocumentInfo
        EvDocumentMode mode;
        GDate creation_date;
        guint ui_hints;
+       guint permissions;
 
        /* Mask of all the valid fields */
        guint fields_mask;
index da38283263abb8b8a3ee00429037d517c12c7803..6ff356f97975a946c04ef2cc406195135f289335 100644 (file)
@@ -99,6 +99,7 @@ EvPageCache    *ev_document_get_page_cache (EvDocument     *document);
 GMutex        *ev_document_get_doc_mutex  (void);
 void            ev_document_doc_mutex_lock (void);
 void            ev_document_doc_mutex_unlock (void);
+
 EvDocumentInfo *ev_document_get_info      (EvDocument     *document);
 gboolean       ev_document_load           (EvDocument     *document,
                                            const char     *uri,
index 6302c42e03b973fcc8b79bdd8cdaf62d3b6d1346..36adf93dfee35272b1711cf6a92e084977520da5 100644 (file)
@@ -32,6 +32,7 @@ struct _EvPageCache
        double max_height_page_height;
 
        EvPageCacheInfo *size_cache;
+       EvDocumentInfo *page_info;
 };
 
 struct _EvPageCacheClass
@@ -91,6 +92,7 @@ ev_page_cache_finalize (GObject *object)
 
        g_free (page_cache->title);
        g_free (page_cache->size_cache);
+       ev_document_info_free (page_cache->page_info);
 }
 
 EvPageCache *
@@ -180,6 +182,8 @@ _ev_page_cache_new (EvDocument *document)
                }
        }
 
+       page_cache->page_info = ev_document_get_info (document);
+
        /* make some sanity check assertions */
        if (! page_cache->uniform)
                g_assert (page_cache->size_cache != NULL);
@@ -366,6 +370,15 @@ ev_page_cache_has_nonnumeric_page_labels (EvPageCache *page_cache)
        return page_cache->has_labels;
 }
 
+const EvDocumentInfo *
+ev_page_cache_get_info (EvPageCache *page_cache)
+{
+       g_return_val_if_fail (EV_IS_PAGE_CACHE (page_cache), NULL);
+
+       return page_cache->page_info;
+}
+
+
 gboolean
 ev_page_cache_next_page (EvPageCache *page_cache)
 {
index 6b9db536a658f69b0405aa262a11f475137a6424..fc1111b5662d2d3778bda704c36d3e97e592af4d 100644 (file)
@@ -50,6 +50,7 @@ void           ev_page_cache_get_max_height_size (EvPageCache *page_cache,
 char          *ev_page_cache_get_page_label      (EvPageCache *page_cache,
                                                  gint         page);
 gboolean       ev_page_cache_has_nonnumeric_page_labels (EvPageCache *page_cache);
+const EvDocumentInfo *ev_page_cache_get_info            (EvPageCache *page_cache);
 
 /* Navigation */
 gint           ev_page_cache_get_current_page    (EvPageCache *page_cache);
index bd3151a6bc9d5e3c8b399ff7821ce351443a73fe..dbc81d2d180e627569ec7685ed35019cf80e3adf 100644 (file)
@@ -305,6 +305,7 @@ pdf_document_get_info (EvDocument *document)
        PopplerPageLayout layout;
        PopplerPageMode mode;
        PopplerViewerPreferences view_prefs;
+       PopplerPermissions permissions;
 
        info = g_new0 (EvDocumentInfo, 1);
 
@@ -316,6 +317,7 @@ pdf_document_get_info (EvDocument *document)
                            EV_DOCUMENT_INFO_LAYOUT |
                            EV_DOCUMENT_INFO_START_MODE |
                            /* Missing EV_DOCUMENT_INFO_CREATION_DATE | */
+                           EV_DOCUMENT_INFO_PERMISSIONS |
                            EV_DOCUMENT_INFO_UI_HINTS;
 
 
@@ -328,6 +330,7 @@ pdf_document_get_info (EvDocument *document)
                      "page-mode", &mode,
                      "page-layout", &layout,
                      "viewer-preferences", &view_prefs,
+                     "permissions", &permissions,
                      NULL);
 
        switch (layout) {
@@ -394,6 +397,19 @@ pdf_document_get_info (EvDocument *document)
                info->ui_hints |=  EV_DOCUMENT_UI_HINT_DIRECTION_RTL;
        }
 
+       info->permissions = 0;
+       if (permissions & POPPLER_PERMISSIONS_OK_TO_PRINT) {
+               info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_PRINT;
+       }
+       if (permissions & POPPLER_PERMISSIONS_OK_TO_MODIFY) {
+               info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_MODIFY;
+       }
+       if (permissions & POPPLER_PERMISSIONS_OK_TO_COPY) {
+               info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_COPY;
+       }
+       if (permissions & POPPLER_PERMISSIONS_OK_TO_ADD_NOTES) {
+               info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_ADD_NOTES;
+       }
        return info;
 }
 
index 3e1c2b775514f4581317c15f94cf335af19acbe2..bd104e868e4431b4825869d6f84915ede0dc9c6e 100644 (file)
@@ -96,6 +96,7 @@ evince_LDADD=                                                         \
        $(top_builddir)/cut-n-paste/zoom-control/libephywidgets.la      \
        $(top_builddir)/cut-n-paste/toolbar-editor/libtoolbareditor.la  \
        $(top_builddir)/lib/libev.la                                    \
+       -ltiff -lz                                                      \
        libevbackendfactory.la                                          \
        $(NULL)
 
index b5227eef8d8c95be9eff947b3aea789d8f2bfdbd..083825a4102d87a981b320d5fa95d3680cd21b84 100644 (file)
@@ -73,7 +73,7 @@ ev_pixbuf_cache_init (EvPixbufCache *pixbuf_cache)
        pixbuf_cache->end_page = 0;
        pixbuf_cache->job_list = g_new0 (CacheJobInfo, PAGE_CACHE_LEN (pixbuf_cache));
 
-       pixbuf_cache->preload_cache_size = 1;
+       pixbuf_cache->preload_cache_size = 2;
        pixbuf_cache->prev_job = g_new0 (CacheJobInfo, pixbuf_cache->preload_cache_size);
        pixbuf_cache->next_job = g_new0 (CacheJobInfo, pixbuf_cache->preload_cache_size);
 }
index 9f66d8acba3b8ff9219ff7934072a454169899f9..3eea568d39adc4abead8519f405ad74385336cf5 100644 (file)
@@ -900,8 +900,8 @@ get_page_extents (EvView       *view,
                        y = view->spacing;
 
                        /* Adjust for extra allocation */
-                       x = x + MAX (0, widget->allocation.width - (width + view->spacing * 2))/2;
-                       y = y + MAX (0, widget->allocation.height - (height + view->spacing * 2))/2;
+                       x = x + MAX (0, widget->allocation.width - (width + border->left + border->right + view->spacing * 2))/2;
+                       y = y + MAX (0, widget->allocation.height - (height + border->top + border->bottom +  view->spacing * 2))/2;
                }
 
                page_area->x = x;
@@ -1607,11 +1607,12 @@ draw_one_page (EvView       *view,
        GdkRectangle real_page_area;
 
        g_assert (view->document);
+       if (! gdk_rectangle_intersect (page_area, expose_area, &overlap))
+               return;
 
        ev_page_cache_get_size (view->page_cache,
                                page, view->scale,
                                &width, &height);
-
        /* Render the document itself */
        real_page_area = *page_area;
 
@@ -1620,38 +1621,37 @@ draw_one_page (EvView       *view,
        real_page_area.width -= (border->left + border->right);
        real_page_area.height -= (border->top + border->bottom);
 
-       if (! gdk_rectangle_intersect (&real_page_area, expose_area, &overlap))
-               return;
-
        ev_document_misc_paint_one_page (GTK_WIDGET(view)->window,
                                         GTK_WIDGET (view),
                                         page_area, border);
 
-       current_pixbuf = ev_pixbuf_cache_get_pixbuf (view->pixbuf_cache, page);
+       if (gdk_rectangle_intersect (&real_page_area, expose_area, &overlap)) {
+               current_pixbuf = ev_pixbuf_cache_get_pixbuf (view->pixbuf_cache, page);
 
-       if (current_pixbuf == NULL)
-               scaled_image = NULL;
-       else if (width == gdk_pixbuf_get_width (current_pixbuf) &&
-                height == gdk_pixbuf_get_height (current_pixbuf))
-               scaled_image = g_object_ref (current_pixbuf);
-       else
-               /* FIXME: We don't want to scale the whole area, just the right
-                * area of it */
-               scaled_image = gdk_pixbuf_scale_simple (current_pixbuf,
-                                                       width, height,
-                                                       GDK_INTERP_NEAREST);
-
-       if (scaled_image) {
-               gdk_draw_pixbuf (GTK_WIDGET(view)->window,
-                                GTK_WIDGET (view)->style->fg_gc[GTK_STATE_NORMAL],
-                                scaled_image,
-                                overlap.x - real_page_area.x,
-                                overlap.y - real_page_area.y,
-                                overlap.x, overlap.y,
-                                overlap.width, overlap.height,
-                                GDK_RGB_DITHER_NORMAL,
-                                0, 0);
-               g_object_unref (scaled_image);
+               if (current_pixbuf == NULL)
+                       scaled_image = NULL;
+               else if (width == gdk_pixbuf_get_width (current_pixbuf) &&
+                        height == gdk_pixbuf_get_height (current_pixbuf))
+                       scaled_image = g_object_ref (current_pixbuf);
+               else
+                       /* FIXME: We don't want to scale the whole area, just the right
+                        * area of it */
+                       scaled_image = gdk_pixbuf_scale_simple (current_pixbuf,
+                                                               width, height,
+                                                               GDK_INTERP_NEAREST);
+
+               if (scaled_image) {
+                       gdk_draw_pixbuf (GTK_WIDGET(view)->window,
+                                        GTK_WIDGET (view)->style->fg_gc[GTK_STATE_NORMAL],
+                                        scaled_image,
+                                        overlap.x - real_page_area.x,
+                                        overlap.y - real_page_area.y,
+                                        overlap.x, overlap.y,
+                                        overlap.width, overlap.height,
+                                        GDK_RGB_DITHER_NORMAL,
+                                        0, 0);
+                       g_object_unref (scaled_image);
+               }
        }
 }
 
@@ -1895,7 +1895,7 @@ ev_view_init (EvView *view)
 {
        GTK_WIDGET_SET_FLAGS (view, GTK_CAN_FOCUS);
 
-       view->spacing = 10;
+       view->spacing = 5;
        view->scale = 1.0;
        view->current_page = 0;
        view->pressed_button = -1;
index 4671e4edbd0d122e0b421b0f906450acf8795975..c5cfac688cbaa6ee77ebf3c07b3bb6f01af17929 100644 (file)
@@ -190,12 +190,17 @@ update_action_sensitivity (EvWindow *ev_window)
 {
        EvView *view;
        EvDocument *document;
+       const EvDocumentInfo *info = NULL;
        EvWindowPageMode page_mode;
        gboolean sensitive, has_pages = FALSE, has_document;
        int n_pages = 0, page = -1;
+       gboolean ok_to_print = TRUE;
+       gboolean ok_to_copy = TRUE;
 
        view = EV_VIEW (ev_window->priv->view);
        document = ev_window->priv->document;
+       if (document)
+               info = ev_page_cache_get_info (ev_window->priv->page_cache);
        page_mode = ev_window->priv->page_mode;
        has_document = document != NULL;
        if (has_document && ev_window->priv->page_cache) {
@@ -204,17 +209,22 @@ update_action_sensitivity (EvWindow *ev_window)
                has_pages = has_document && n_pages > 0;
        }
 
+       if (info && info->fields_mask & EV_DOCUMENT_INFO_PERMISSIONS) {
+               ok_to_print = (info->permissions & EV_DOCUMENT_PERMISSIONS_OK_TO_PRINT);
+               ok_to_copy = (info->permissions & EV_DOCUMENT_PERMISSIONS_OK_TO_COPY);
+       }
+
        /* File menu */
        /* "FileOpen": always sensitive */
-       set_action_sensitive (ev_window, "FileSaveAs", has_document);
-       set_action_sensitive (ev_window, "FilePrint", has_pages);
+       set_action_sensitive (ev_window, "FileSaveAs", has_document && ok_to_copy);
+       set_action_sensitive (ev_window, "FilePrint", has_pages && ok_to_print);
        /* "FileCloseWindow": always sensitive */
 
         /* Edit menu */
 
        sensitive = has_pages && ev_document_can_get_text (document);
-       set_action_sensitive (ev_window, "EditCopy", sensitive);
-       set_action_sensitive (ev_window, "EditSelectAll", sensitive);
+       set_action_sensitive (ev_window, "EditCopy", sensitive && ok_to_copy);
+       set_action_sensitive (ev_window, "EditSelectAll", sensitive && ok_to_copy);
        set_action_sensitive (ev_window, "EditFind",
                              has_pages && EV_IS_DOCUMENT_FIND (document));
        set_action_sensitive (ev_window, "Slash",
@@ -581,7 +591,7 @@ update_document_mode (EvWindow *window, EvDocumentMode mode)
 static void
 ev_window_setup_document (EvWindow *ev_window)
 {
-       EvDocumentInfo *info;
+       const EvDocumentInfo *info;
        EvDocument *document;
        EvView *view = EV_VIEW (ev_window->priv->view);
        EvSidebar *sidebar = EV_SIDEBAR (ev_window->priv->sidebar);
@@ -615,9 +625,8 @@ ev_window_setup_document (EvWindow *ev_window)
        ev_page_action_set_document (EV_PAGE_ACTION (action), document);
        update_action_sensitivity (ev_window);
 
-       info = ev_document_get_info (document);
+       info = ev_page_cache_get_info (ev_window->priv->page_cache);
        update_document_mode (ev_window, info->mode);
-       ev_document_info_free (info);
 }
 
 static void
index ea9dc345e546bd37d641190445cc5b429073a01c..8a4e9334af21da576b506026fe0cf675e9c0145e 100644 (file)
@@ -25,6 +25,7 @@ evince_thumbnailer_LDADD=                             \
        $(LIBTIFF)                                      \
        $(top_builddir)/lib/libev.la                    \
        $(top_builddir)/shell/libevbackendfactory.la    \
+       -ltiff -lz                                      \
        $(NULL)
 
 pixmapdir = $(pkgdatadir)
index 5c8cc8d4bac0ea3c22e6d4de64206ba387b2467d..9605c16eacaf281ed04507ad87c7972a060e3192 100644 (file)
@@ -167,6 +167,8 @@ tiff_document_render_pixbuf (EvDocument  *document, int page, double scale)
 {
   TiffDocument *tiff_document = TIFF_DOCUMENT (document);
   int width, height;
+  gint rowstride, bytes;
+  guchar *pixels = NULL;
   GdkPixbuf *pixbuf;
   GdkPixbuf *scaled_pixbuf;
 
@@ -180,8 +182,41 @@ tiff_document_render_pixbuf (EvDocument  *document, int page, double scale)
       return NULL;
     }
 
-  TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGEWIDTH, &width);
-  TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGELENGTH, &height);
+  if (!TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGEWIDTH, &width))
+    {
+      pop_handlers ();
+      return NULL;
+    }
+
+  if (! TIFFGetField (tiff_document->tiff, TIFFTAG_IMAGELENGTH, &height))
+    {
+      pop_handlers ();
+      return NULL;
+    }
+
+  pop_handlers ();
+
+  /* Sanity check the doc */
+  if (width <= 0 || height <= 0)
+    return NULL;                
+        
+  rowstride = width * 4;
+  if (rowstride / 4 != width)
+    /* overflow */
+    return NULL;                
+        
+  bytes = height * rowstride;
+  if (bytes / rowstride != height)
+    /* overflow */
+    return NULL;                
+
+  pixels = g_try_malloc (bytes);
+  if (!pixels)
+    return NULL;
+
+  pixbuf = gdk_pixbuf_new_from_data (pixels, GDK_COLORSPACE_RGB, TRUE, 8, 
+                                    width, height, rowstride,
+                                    (GdkPixbufDestroyNotify) g_free, NULL);
 
   pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, width, height);
   TIFFReadRGBAImageOriented (tiff_document->tiff, width, height, (uint32 *)gdk_pixbuf_get_pixels (pixbuf), ORIENTATION_TOPLEFT, 1);