Patch for document type handling
- From: David Malcolm <dmalcolm redhat com>
- To: "evince-list gnome org" <evince-list gnome org>
- Subject: Patch for document type handling
- Date: Thu, 07 Apr 2005 20:43:15 -0400
I had a go at cleaning up Evince's document type handling code, and it's
not yet ready to commit, but I wanted to get feedback...
So attached is a dump of my current diff against CVS: not especially
clean right now :-)
I created new files: shell/ev-document-types.[ch]
This handles the logic for looking up a mimetype and getting the
corresponding backend (if any); it gets used by shell/ev-window.c to
handle file opening, and by the Nautilus thumbnailer (not yet tested) -
so that in theory the thumbnailer should be able to work for any backend
for which the thumbnailing interface is implemented.
Since this is shared between evince and the thumbnailer, I created a new
library: shell/libevbackendfactory.la
Unfortunately by autotool-fu is weak; I couldn't persuade
automake/libtool to have a shared library linking to shared libraries
for the backends. So right now the patch makes everything statically
linked (ugh)
Is this the right direction to go in?
I also had to turn off the recent document saving; it was locking up
evince for some reason.
There are also some warning fixes in the DVI code (where did this code
come from? shouldn't we simply link to a separate library?)
? fix-warnings.patch
? get-pixbuf-working.patch
? tmp
? shell/ev-document-types.c
? shell/ev-document-types.h
Index: dvi/pixbuf-device.c
===================================================================
RCS file: /cvs/gnome/evince/dvi/pixbuf-device.c,v
retrieving revision 1.1
diff -u -p -r1.1 pixbuf-device.c
--- dvi/pixbuf-device.c 7 Apr 2005 15:28:03 -0000 1.1
+++ dvi/pixbuf-device.c 8 Apr 2005 00:32:10 -0000
@@ -50,7 +50,7 @@ static void dvi_pixbuf_draw_rule(DviCont
{
DviPixbufDevice *c_device = (DviPixbufDevice *) dvi->device.device_data;
gint rowstride;
- gchar *p;
+ guchar *p;
gint i, j;
x += c_device->xmargin; y += c_device->ymargin;
@@ -131,7 +131,7 @@ static void dvi_pixbuf_free_image(void *
static void dvi_pixbuf_put_pixel(void *image, int x, int y, Ulong color)
{
- gchar *p;
+ guchar *p;
p = gdk_pixbuf_get_pixels (GDK_PIXBUF(image)) + y * gdk_pixbuf_get_rowstride(GDK_PIXBUF(image)) + x * 4;
Index: dvi/mdvi-lib/fontmap.c
===================================================================
RCS file: /cvs/gnome/evince/dvi/mdvi-lib/fontmap.c,v
retrieving revision 1.1
diff -u -p -r1.1 fontmap.c
--- dvi/mdvi-lib/fontmap.c 7 Apr 2005 15:28:04 -0000 1.1
+++ dvi/mdvi-lib/fontmap.c 8 Apr 2005 00:32:10 -0000
@@ -872,8 +872,8 @@ void mdvi_flush_fontmaps(void)
void ps_init_default_paths(void)
{
- char *kppath = mdvi_getenv("MDVI_PS_LIBPATH");
- char *kfpath = mdvi_getenv("MDVI_PS_FONTPATH");
+ char *kppath = getenv("MDVI_PS_LIBPATH");
+ char *kfpath = getenv("MDVI_PS_FONTPATH");
ASSERT(psinitialized == 0);
if(kppath == NULL)
Index: dvi/mdvi-lib/sp-epsf.c
===================================================================
RCS file: /cvs/gnome/evince/dvi/mdvi-lib/sp-epsf.c,v
retrieving revision 1.1
diff -u -p -r1.1 sp-epsf.c
--- dvi/mdvi-lib/sp-epsf.c 7 Apr 2005 15:28:04 -0000 1.1
+++ dvi/mdvi-lib/sp-epsf.c 8 Apr 2005 00:32:10 -0000
@@ -235,7 +235,7 @@ void epsf_special(DviContext *dvi, char
{
char *file;
char *special;
- EpsfBox box;
+ EpsfBox box = {0,0,0,0};
int x, y;
int w, h;
double xf, vf;
Index: dvi/mdvi-lib/tfmfile.c
===================================================================
RCS file: /cvs/gnome/evince/dvi/mdvi-lib/tfmfile.c,v
retrieving revision 1.1
diff -u -p -r1.1 tfmfile.c
--- dvi/mdvi-lib/tfmfile.c 7 Apr 2005 15:28:04 -0000 1.1
+++ dvi/mdvi-lib/tfmfile.c 8 Apr 2005 00:32:10 -0000
@@ -514,7 +514,6 @@ static int ofm_load_file(const char *fil
}
fread(info->coding, 39, 1, in);
info->coding[n] = 0;
- ptr += i;
} else
strcpy(info->coding, "FontSpecific");
/* get the font family */
Index: shell/Makefile.am
===================================================================
RCS file: /cvs/gnome/evince/shell/Makefile.am,v
retrieving revision 1.28
diff -u -p -r1.28 Makefile.am
--- shell/Makefile.am 7 Apr 2005 15:28:06 -0000 1.28
+++ shell/Makefile.am 8 Apr 2005 00:32:10 -0000
@@ -18,6 +18,36 @@ INCLUDES= \
$(NULL)
bin_PROGRAMS=evince
+lib_LTLIBRARIES = libevbackendfactory.la
+
+libevbackendfactory_la_SOURCES= \
+ ev-document-types.c \
+ ev-document-types.h
+
+libevbackendfactory_la_LIBADD = \
+ $(top_builddir)/pdf/libpdfdocument.la \
+ $(top_builddir)/pixbuf/libpixbufdocument.la \
+ $(top_builddir)/ps/libgtkgs.la \
+ $(top_builddir)/backend/libevbackend.la \
+ $(NULL)
+
+if ENABLE_DJVU
+libevbackendfactory_la_LIBADD += \
+ -ldjvulibre \
+ -lpthread \
+ $(top_builddir)/djvu/libgtkdjvu.la \
+ $(NULL)
+endif
+
+if ENABLE_DVI
+libevbackendfactory_la_LIBADD += \
+ $(top_builddir)/dvi/libgtkdvi.la \
+ $(NULL)
+endif
+
+if WITH_TYPE1_FONTS
+libevbackendfactory_la_LIBADD += -lt1lib
+endif
evince_SOURCES= \
dummy.cc \
@@ -58,29 +88,8 @@ evince_LDADD= \
$(SHELL_LIBS) \
$(top_builddir)/cut-n-paste/recent-files/librecent.la \
$(top_builddir)/lib/libev.la \
- $(top_builddir)/pdf/libpdfdocument.la \
- $(top_builddir)/pixbuf/libpixbufdocument.la \
- $(top_builddir)/ps/libgtkgs.la \
- $(top_builddir)/backend/libevbackend.la \
- $(NULL)
-
-if ENABLE_DJVU
-evince_LDADD += \
- -ldjvulibre \
- -lpthread \
- $(top_builddir)/djvu/libgtkdjvu.la \
- $(NULL)
-endif
-
-if ENABLE_DVI
-evince_LDADD += \
- $(top_builddir)/dvi/libgtkdvi.la \
+ libevbackendfactory.la \
$(NULL)
-endif
-
-if WITH_TYPE1_FONTS
-evince_LDADD += -lt1lib
-endif
BUILT_SOURCES = ev-marshal.h ev-marshal.c
Index: shell/ev-window.c
===================================================================
RCS file: /cvs/gnome/evince/shell/ev-window.c,v
retrieving revision 1.91
diff -u -p -r1.91 ev-window.c
--- shell/ev-window.c 7 Apr 2005 15:28:06 -0000 1.91
+++ shell/ev-window.c 8 Apr 2005 00:32:10 -0000
@@ -39,6 +39,7 @@
#include "ev-print-job.h"
#include "ev-document-thumbnails.h"
#include "ev-document-links.h"
+#include "ev-document-types.h"
#include "ev-document-find.h"
#include "ev-document-security.h"
#include "ev-job-queue.h"
@@ -47,16 +48,6 @@
#include "egg-recent-view.h"
#include "egg-recent-model.h"
-#include "ev-poppler.h"
-#include "pixbuf-document.h"
-#include "ps-document.h"
-#ifdef ENABLE_DVI
-#include "dvi-document.h"
-#endif
-#ifdef ENABLE_DJVU
-#include "djvu-document.h"
-#endif
-
#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <gnome.h>
@@ -163,7 +154,7 @@ static gboolean start_loading_document
static void ev_window_set_sizing_mode (EvWindow *ev_window,
EvSizingMode sizing_mode);
-static void ev_window_add_recent (EvWindow *window, const char *filename);
+//static void ev_window_add_recent (EvWindow *window, const char *filename);
G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
@@ -398,44 +389,6 @@ unable_to_load (EvWindow *ev_window,
gtk_widget_destroy (dialog);
}
-/* Would be nice to have this in gdk-pixbuf */
-static gboolean
-mime_type_supported_by_gdk_pixbuf (const gchar *mime_type)
-{
- GSList *formats, *list;
- gboolean retval = FALSE;
-
- formats = gdk_pixbuf_get_formats ();
-
- list = formats;
- while (list) {
- GdkPixbufFormat *format = list->data;
- int i;
- gchar **mime_types;
-
- if (gdk_pixbuf_format_is_disabled (format))
- continue;
-
- mime_types = gdk_pixbuf_format_get_mime_types (format);
-
- for (i = 0; mime_types[i] != NULL; i++) {
- if (strcmp (mime_types[i], mime_type) == 0) {
- retval = TRUE;
- break;
- }
- }
-
- if (retval)
- break;
-
- list = list->next;
- }
-
- g_slist_free (formats);
-
- return retval;
-}
-
static void
update_window_title (EvDocument *document, GParamSpec *pspec, EvWindow *ev_window)
{
@@ -671,7 +624,7 @@ start_loading_document (EvWindow *ev_w
ev_window->priv->document = g_object_ref (document);
ev_window_setup_document (ev_window);
- ev_window_add_recent (ev_window, uri);
+ //ev_window_add_recent (ev_window, uri);
return TRUE;
}
@@ -701,33 +654,6 @@ start_loading_document (EvWindow *ev_w
return FALSE;
}
-static gboolean
-is_file_supported (const gchar *mime_type)
-{
- static char *supported_types [] = {
- "application/pdf",
- "application/postscript",
- "application/x-dvi",
- "image/vnd.djvu",
- "application/x-gzpostscript",
- "image/x-eps",
- NULL
- };
- gint i;
-
- g_return_val_if_fail (mime_type != NULL, FALSE);
-
- if (mime_type_supported_by_gdk_pixbuf (mime_type))
- return TRUE;
-
- for (i = 0; supported_types[i] != NULL; i++) {
- if (g_ascii_strcasecmp (mime_type, supported_types[i]) == 0)
- return TRUE;
- }
-
- return FALSE;
-}
-
void
ev_window_open (EvWindow *ev_window, const char *uri)
{
@@ -741,22 +667,13 @@ ev_window_open (EvWindow *ev_window, con
if (mime_type == NULL)
document = NULL;
- else if (!strcmp (mime_type, "application/pdf"))
- document = g_object_new (PDF_TYPE_DOCUMENT, NULL);
- else if (!strcmp (mime_type, "application/postscript") ||
- !strcmp (mime_type, "application/x-gzpostscript") ||
- !strcmp (mime_type, "image/x-eps"))
- document = g_object_new (PS_TYPE_DOCUMENT, NULL);
-#ifdef ENABLE_DJVU
- else if (!strcmp (mime_type, "image/vnd.djvu"))
- document = g_object_new (DJVU_TYPE_DOCUMENT, NULL);
-#endif
- else if (mime_type_supported_by_gdk_pixbuf (mime_type))
- document = g_object_new (PIXBUF_TYPE_DOCUMENT, NULL);
-#ifdef ENABLE_DVI
- else if (!strcmp (mime_type, "application/x-dvi"))
- document = g_object_new (DVI_TYPE_DOCUMENT, NULL);
-#endif
+ else {
+ const EvinceDocumentType *document_type = evince_document_type_lookup (mime_type);
+
+ if (document_type) {
+ document = evince_document_type_manufacture_instance (document_type);
+ }
+ }
if (document) {
start_loading_document (ev_window, document, uri);
@@ -789,7 +706,7 @@ ev_window_open_uri_list (EvWindow *ev_wi
uri = gnome_vfs_uri_to_string (list->data, GNOME_VFS_URI_HIDE_NONE);
mime_type = gnome_vfs_get_mime_type (uri);
- if (is_file_supported (mime_type)) {
+ if (evince_document_type_lookup (mime_type)!=NULL) {
if (ev_window_is_empty (EV_WINDOW (ev_window))) {
ev_window_open (ev_window, uri);
@@ -833,6 +750,7 @@ ev_window_cmd_recent_file_activate (EggR
g_free (uri);
}
+#if 0
static void
ev_window_add_recent (EvWindow *window, const char *filename)
{
@@ -845,6 +763,7 @@ ev_window_add_recent (EvWindow *window,
egg_recent_item_add_group (item, "Evince");
egg_recent_model_add_full (window->priv->recent_model, item);
}
+#endif
static void
ev_window_setup_recent (EvWindow *ev_window)
Index: thumbnailer/Makefile.am
===================================================================
RCS file: /cvs/gnome/evince/thumbnailer/Makefile.am,v
retrieving revision 1.2
diff -u -p -r1.2 Makefile.am
--- thumbnailer/Makefile.am 3 Apr 2005 00:01:48 -0000 1.2
+++ thumbnailer/Makefile.am 8 Apr 2005 00:32:10 -0000
@@ -7,6 +7,7 @@ INCLUDES= \
-I$(top_srcdir)/lib \
-I$(top_srcdir)/pdf \
-I$(top_srcdir)/backend \
+ -I$(top_srcdir)/shell \
-DGNOMELOCALEDIR=\"$(datadir)/locale\" \
-DGNOMEICONDIR=\""$(datadir)/pixmaps"\" \
$(THUMBNAILER_CFLAGS) \
@@ -19,11 +20,11 @@ evince_thumbnailer_SOURCES= \
evince-thumbnailer.c
$(NULL)
-evince_thumbnailer_LDADD= \
- $(THUMBNAILER_LIBS) \
+evince_thumbnailer_LDADD= \
+ $(THUMBNAILER_LIBS) \
$(top_builddir)/lib/libev.la \
$(top_builddir)/pdf/libpdfdocument.la \
- $(top_builddir)/backend/libevbackend.la \
+ $(top_builddir)/shell/libevbackendfactory.la \
$(NULL)
pixmapdir = $(pkgdatadir)
Index: thumbnailer/evince-thumbnailer.c
===================================================================
RCS file: /cvs/gnome/evince/thumbnailer/evince-thumbnailer.c,v
retrieving revision 1.6
diff -u -p -r1.6 evince-thumbnailer.c
--- thumbnailer/evince-thumbnailer.c 6 Apr 2005 09:36:25 -0000 1.6
+++ thumbnailer/evince-thumbnailer.c 8 Apr 2005 00:32:10 -0000
@@ -16,14 +16,13 @@
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#include <ev-poppler.h>
-
#include <libgnomevfs/gnome-vfs-mime-utils.h>
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#include <libgnomevfs/gnome-vfs-init.h>
#include <ev-document.h>
+#include <ev-document-types.h>
#include <ev-document-thumbnails.h>
#include <string.h>
@@ -37,16 +36,18 @@ evince_thumbnail_pngenc_get (const char
char *mime_type;
GError *error;
GdkPixbuf *pixbuf;
+ const EvinceDocumentType* document_type;
mime_type = gnome_vfs_get_mime_type (uri);
if (mime_type == NULL)
return FALSE;
- if (!strcmp (mime_type, "application/pdf"))
- document = g_object_new (PDF_TYPE_DOCUMENT, NULL);
- else
+ document_type = evince_document_type_lookup (mime_type);
+ if (document_type==NULL)
return FALSE;
+ document = evince_document_type_manufacture_instance (document_type);
+
if (!ev_document_load (document, uri, &error)) {
if (error->domain == EV_DOCUMENT_ERROR &&
error->code == EV_DOCUMENT_ERROR_ENCRYPTED) {
@@ -56,30 +57,41 @@ evince_thumbnail_pngenc_get (const char
return FALSE;
}
+ if (!EV_IS_DOCUMENT_THUMBNAILS (document)) {
+ return FALSE;
+ }
+
pixbuf = ev_document_thumbnails_get_thumbnail
(EV_DOCUMENT_THUMBNAILS (document), 1, size, FALSE);
if (pixbuf != NULL) {
- GdkPixbuf *pdflogo;
-
- pdflogo = gdk_pixbuf_new_from_file (DATADIR"/pdf-icon.png", NULL);
- if (pdflogo != NULL) {
- int delta_height, delta_width;
-
- delta_width = gdk_pixbuf_get_width (pixbuf) -
- gdk_pixbuf_get_width (pdflogo);
- delta_height = gdk_pixbuf_get_height (pixbuf) -
- gdk_pixbuf_get_height (pdflogo);
-
- gdk_pixbuf_composite (pdflogo, pixbuf,
- delta_width, delta_height,
- gdk_pixbuf_get_width (pdflogo),
- gdk_pixbuf_get_height (pdflogo),
- delta_width, delta_height,
- 1, 1,
- GDK_INTERP_NEAREST, 100);
+ const char *overlaid_icon_name;
- gdk_pixbuf_unref (pdflogo);
+ overlaid_icon_name = evince_document_type_get_overlaid_thumbnail_icon (document_type);
+ if (overlaid_icon_name) {
+ GdkPixbuf *overlaid_pixbuf;
+
+ gchar *overlaid_icon_path = g_strdup_printf ("%s/%s", DATADIR, overlaid_icon_name);
+ overlaid_pixbuf = gdk_pixbuf_new_from_file (overlaid_icon_path, NULL);
+ g_free (overlaid_icon_path);
+ if (overlaid_pixbuf != NULL) {
+ int delta_height, delta_width;
+
+ delta_width = gdk_pixbuf_get_width (pixbuf) -
+ gdk_pixbuf_get_width (overlaid_pixbuf);
+ delta_height = gdk_pixbuf_get_height (pixbuf) -
+ gdk_pixbuf_get_height (overlaid_pixbuf);
+
+ gdk_pixbuf_composite (overlaid_pixbuf, pixbuf,
+ delta_width, delta_height,
+ gdk_pixbuf_get_width (overlaid_pixbuf),
+ gdk_pixbuf_get_height (overlaid_pixbuf),
+ delta_width, delta_height,
+ 1, 1,
+ GDK_INTERP_NEAREST, 100);
+
+ gdk_pixbuf_unref (overlaid_pixbuf);
+ }
}
if (gdk_pixbuf_save (pixbuf, thumbnail, "png", NULL, NULL)) {
gdk_pixbuf_unref (pixbuf);
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
/*
* Copyright (C) 2005, Red Hat, Inc.
*
* 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.
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "ev-document-types.h"
/* The various document type backends: */
#include "ev-poppler.h"
#include "pixbuf-document.h"
#include "ps-document.h"
#ifdef ENABLE_DVI
#include "dvi-document.h"
#endif
#ifdef ENABLE_DJVU
#include "djvu-document.h"
#endif
#include <string.h>
struct _EvinceDocumentType
{
const char *mime_type;
GType (*document_type_factory_callback)();
const char *overlaid_thumbnail_icon;
};
const EvinceDocumentType document_types[] = {
/* PDF: */
{"application/pdf", pdf_document_get_type, "pdf-icon.png"},
/* Postscript: */
{"application/postscript", ps_document_get_type, NULL},
{"application/x-gzpostscript", ps_document_get_type, NULL},
{"image/x-eps", ps_document_get_type, NULL},
#ifdef ENABLE_DJVU
/* djvu: */
{"image/vnd.djvu", djvu_document_get_type, NULL),
#endif
#ifdef ENABLE_DVI
/* dvi: */
{"application/x-dvi", dvi_document_get_type, NULL},
#endif
};
const EvinceDocumentType evince_gdk_pixbuf_type = {NULL, pixbuf_document_get_type, NULL};
/* Would be nice to have this in gdk-pixbuf */
static gboolean
mime_type_supported_by_gdk_pixbuf (const gchar *mime_type)
{
GSList *formats, *list;
gboolean retval = FALSE;
formats = gdk_pixbuf_get_formats ();
list = formats;
while (list) {
GdkPixbufFormat *format = list->data;
int i;
gchar **mime_types;
if (gdk_pixbuf_format_is_disabled (format))
continue;
mime_types = gdk_pixbuf_format_get_mime_types (format);
for (i = 0; mime_types[i] != NULL; i++) {
if (strcmp (mime_types[i], mime_type) == 0) {
retval = TRUE;
break;
}
}
if (retval)
break;
list = list->next;
}
g_slist_free (formats);
return retval;
}
const EvinceDocumentType*
evince_document_type_lookup (const char *mime_type)
{
int i;
g_return_val_if_fail (mime_type, NULL);
for (i=0;i<G_N_ELEMENTS (document_types);i++) {
if (0==strcmp(mime_type, document_types[i].mime_type)) {
return &document_types[i];
}
}
if (mime_type_supported_by_gdk_pixbuf (mime_type)) {
return &evince_gdk_pixbuf_type;
}
return NULL;
}
EvDocument*
evince_document_type_manufacture_instance (const EvinceDocumentType *document_type)
{
EvDocument *new_document;
g_return_val_if_fail (document_type, NULL);
g_assert (document_type->document_type_factory_callback);
new_document = g_object_new (document_type->document_type_factory_callback(), NULL);
g_assert (EV_IS_DOCUMENT (new_document));
return new_document;
}
const char*
evince_document_type_get_overlaid_thumbnail_icon (const EvinceDocumentType *document_type)
{
g_return_val_if_fail (document_type, NULL);
return document_type->overlaid_thumbnail_icon;
}
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
/*
* Copyright (C) 2005, Red Hat, Inc.
*
* 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.
*
*/
#ifndef EV_DOCUMENT_TYPES_H
#define EV_DOCUMENT_TYPES_H
#include "ev-document.h"
G_BEGIN_DECLS
typedef struct _EvinceDocumentType EvinceDocumentType;
const EvinceDocumentType* evince_document_type_lookup (const char *mime_type);
EvDocument* evince_document_type_manufacture_instance (const EvinceDocumentType *document_type);
const char* evince_document_type_get_overlaid_thumbnail_icon (const EvinceDocumentType *document_type);
G_END_DECLS
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]