From 1b167536f9277df8953cc30a531c1c17eab10382 Mon Sep 17 00:00:00 2001 From: "Nickolay V. Shmyrev" Date: Fri, 1 Jul 2005 07:44:23 +0000 Subject: [PATCH] Require libgnomeprint >= 2.5.1. Thanks to Colin Slater * configure.ac: Require libgnomeprint >= 2.5.1. Thanks to Colin Slater * djvu/djvu-document.c: (djvu_document_get_orientation), (djvu_document_set_orientation), (djvu_document_get_page_size), (rotate_pixbuf), (djvu_document_render_pixbuf), (djvu_document_document_iface_init): * dvi/dvi-document.c: (dvi_document_get_orientation), (dvi_document_set_orientation), (dvi_document_get_page_size), (rotate_pixbuf), (dvi_document_render_pixbuf), (dvi_document_document_iface_init): Dvi and djvu backends are ported to new API --- ChangeLog | 18 +++++++++++ configure.ac | 2 +- djvu/djvu-document.c | 65 ++++++++++++++++++++++++++++++++------ dvi/dvi-document.c | 74 ++++++++++++++++++++++++++++++++++++-------- 4 files changed, 136 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 09c3de7e..0afe222c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2005-07-01 Nickolay V. Shmyrev + + * configure.ac: + + Require libgnomeprint >= 2.5.1. Thanks to Colin Slater + + + * djvu/djvu-document.c: (djvu_document_get_orientation), + (djvu_document_set_orientation), (djvu_document_get_page_size), + (rotate_pixbuf), (djvu_document_render_pixbuf), + (djvu_document_document_iface_init): + * dvi/dvi-document.c: (dvi_document_get_orientation), + (dvi_document_set_orientation), (dvi_document_get_page_size), + (rotate_pixbuf), (dvi_document_render_pixbuf), + (dvi_document_document_iface_init): + + Dvi and djvu backends are ported to new API + Fri Jul 1 00:10:15 2005 Jonathan Blandford * backend/ev-selection.c: (ev_selection_get_selection_region), diff --git a/configure.ac b/configure.ac index 227b0206..d49fe82c 100644 --- a/configure.ac +++ b/configure.ac @@ -39,7 +39,7 @@ PKG_CHECK_MODULES(LIBEVPRIVATE, gtk+-2.0 >= 2.4.0) PKG_CHECK_MODULES(TOOLBAR_EDITOR, gtk+-2.0 >= 2.4.0 libgnomeui-2.0 >= 2.4.0) PKG_CHECK_MODULES(RECENT_FILES, gtk+-2.0 >= 2.4.0 libgnomeui-2.0 >= 2.4.0) PKG_CHECK_MODULES(ZOOM_CONTROL, gtk+-2.0 >= 2.4.0) -PKG_CHECK_MODULES(SHELL, gtk+-2.0 >= 2.6.0 libgnomeui-2.0 gnome-vfs-2.0 libgnomeprint-2.2 libgnomeprintui-2.2 libglade-2.0 gconf-2.0 poppler-glib >= $POPPLER_REQUIRED) +PKG_CHECK_MODULES(SHELL, gtk+-2.0 >= 2.6.0 libgnomeui-2.0 gnome-vfs-2.0 libgnomeprint-2.2 >= 2.5.1 libgnomeprintui-2.2 libglade-2.0 gconf-2.0 poppler-glib >= $POPPLER_REQUIRED) PKG_CHECK_MODULES(THUMBNAILER, gtk+-2.0 >= 2.6.0 gnome-vfs-2.0 poppler-glib >= $POPPLER_REQUIRED) PKG_CHECK_MODULES(DVI, gtk+-2.0 >= 2.6.0) PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.6.0) diff --git a/djvu/djvu-document.c b/djvu/djvu-document.c index d82a643f..25cdb075 100644 --- a/djvu/djvu-document.c +++ b/djvu/djvu-document.c @@ -44,6 +44,8 @@ struct _DjvuDocument ddjvu_context_t *d_context; ddjvu_document_t *d_document; ddjvu_format_t *d_format; + + EvOrientation orientation; }; typedef struct _DjvuDocumentClass DjvuDocumentClass; @@ -109,6 +111,23 @@ djvu_document_get_n_pages (EvDocument *document) return ddjvu_document_get_pagenum (djvu_document->d_document); } +static EvOrientation +djvu_document_get_orientation (EvDocument *document) +{ + DjvuDocument *djvu_document = DJVU_DOCUMENT (document); + + return djvu_document->orientation; +} + +static void +djvu_document_set_orientation (EvDocument *document, + EvOrientation orientation) +{ + DjvuDocument *djvu_document = DJVU_DOCUMENT (document); + + djvu_document->orientation = orientation; +} + static void djvu_document_get_page_size (EvDocument *document, int page, @@ -125,18 +144,41 @@ djvu_document_get_page_size (EvDocument *document, ddjvu_message_pop (djvu_document->d_context); } - if (width) - *width = info.width * SCALE_FACTOR; - if (height) - *height = info.height * SCALE_FACTOR; + if (djvu_document->orientation == EV_ORIENTATION_PORTRAIT || + djvu_document->orientation == EV_ORIENTATION_UPSIDEDOWN) { + *width = info.width * SCALE_FACTOR; + *height = info.height * SCALE_FACTOR; + } else { + *width = info.height * SCALE_FACTOR; + *height = info.width * SCALE_FACTOR; + } +} + +static GdkPixbuf * +rotate_pixbuf (EvDocument *document, GdkPixbuf *pixbuf) +{ + DjvuDocument *djvu_document = DJVU_DOCUMENT (document); + + switch (djvu_document->orientation) + { + case EV_ORIENTATION_LANDSCAPE: + return gdk_pixbuf_rotate_simple (pixbuf, 90); + case EV_ORIENTATION_UPSIDEDOWN: + return gdk_pixbuf_rotate_simple (pixbuf, 180); + case EV_ORIENTATION_SEASCAPE: + return gdk_pixbuf_rotate_simple (pixbuf, 270); + default: + return g_object_ref (pixbuf); + } } static GdkPixbuf * djvu_document_render_pixbuf (EvDocument *document, - int page, gdouble scale) + EvRenderContext *rc) { DjvuDocument *djvu_document = DJVU_DOCUMENT (document); GdkPixbuf *pixbuf; + GdkPixbuf *rotated_pixbuf; ddjvu_rect_t rrect; ddjvu_rect_t prect; @@ -144,15 +186,15 @@ djvu_document_render_pixbuf (EvDocument *document, double page_width, page_height; - d_page = ddjvu_page_create_by_pageno (djvu_document->d_document, page); + d_page = ddjvu_page_create_by_pageno (djvu_document->d_document, rc->page); while (!ddjvu_page_decoding_done (d_page)) { ddjvu_message_wait (djvu_document->d_context); ddjvu_message_pop (djvu_document->d_context); } - page_width = ddjvu_page_get_width (d_page) * scale * SCALE_FACTOR; - page_height = ddjvu_page_get_height (d_page) * scale * SCALE_FACTOR; + page_width = ddjvu_page_get_width (d_page) * rc->scale * SCALE_FACTOR; + page_height = ddjvu_page_get_height (d_page) * rc->scale * SCALE_FACTOR; pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, page_width, page_height); @@ -168,7 +210,10 @@ djvu_document_render_pixbuf (EvDocument *document, (gchar *)gdk_pixbuf_get_pixels (pixbuf)); - return pixbuf; + rotated_pixbuf = rotate_pixbuf (document, pixbuf); + g_object_unref (pixbuf); + + return rotated_pixbuf; } static void @@ -219,6 +264,8 @@ djvu_document_document_iface_init (EvDocumentIface *iface) iface->get_page_size = djvu_document_get_page_size; iface->render_pixbuf = djvu_document_render_pixbuf; iface->get_info = djvu_document_get_info; + iface->set_orientation = djvu_document_set_orientation; + iface->get_orientation = djvu_document_get_orientation; } static void diff --git a/dvi/dvi-document.c b/dvi/dvi-document.c index d0307e3a..0aff86a3 100644 --- a/dvi/dvi-document.c +++ b/dvi/dvi-document.c @@ -54,6 +54,8 @@ struct _DviDocument double base_width; double base_height; + + EvOrientation orientation; }; typedef struct _DviDocumentClass DviDocumentClass; @@ -134,6 +136,24 @@ dvi_document_get_n_pages (EvDocument *document) return dvi_document->context->npages; } +static EvOrientation +dvi_document_get_orientation (EvDocument *document) +{ + DviDocument *dvi_document = DVI_DOCUMENT (document); + + return dvi_document->orientation; +} + +static void +dvi_document_set_orientation (EvDocument *document, + EvOrientation orientation) +{ + DviDocument *dvi_document = DVI_DOCUMENT (document); + + dvi_document->orientation = orientation; +} + + static void dvi_document_get_page_size (EvDocument *document, int page, @@ -141,20 +161,43 @@ dvi_document_get_page_size (EvDocument *document, double *height) { DviDocument * dvi_document = DVI_DOCUMENT (document); - - if (width != NULL) - *width = dvi_document->base_width; - if (height != NULL) - *height = dvi_document->base_height; - + if (dvi_document->orientation == EV_ORIENTATION_PORTRAIT || + dvi_document->orientation == EV_ORIENTATION_UPSIDEDOWN) { + *width = dvi_document->base_width; + *height = dvi_document->base_height;; + } else { + *width = dvi_document->base_height; + *height = dvi_document->base_width; + } + return; } static GdkPixbuf * -dvi_document_render_pixbuf (EvDocument *document, int page, double scale) +rotate_pixbuf (EvDocument *document, GdkPixbuf *pixbuf) +{ + DviDocument *dvi_document = DVI_DOCUMENT (document); + + switch (dvi_document->orientation) + { + case EV_ORIENTATION_LANDSCAPE: + return gdk_pixbuf_rotate_simple (pixbuf, 90); + case EV_ORIENTATION_UPSIDEDOWN: + return gdk_pixbuf_rotate_simple (pixbuf, 180); + case EV_ORIENTATION_SEASCAPE: + return gdk_pixbuf_rotate_simple (pixbuf, 270); + default: + return g_object_ref (pixbuf); + } +} + +static GdkPixbuf * +dvi_document_render_pixbuf (EvDocument *document, + EvRenderContext *rc) { GdkPixbuf *pixbuf; + GdkPixbuf *rotated_pixbuf; DviDocument *dvi_document = DVI_DOCUMENT(document); @@ -168,14 +211,14 @@ dvi_document_render_pixbuf (EvDocument *document, int page, double scale) */ g_mutex_lock (dvi_context_mutex); - mdvi_setpage(dvi_document->context, page); + mdvi_setpage(dvi_document->context, rc->page); mdvi_set_shrink (dvi_document->context, - (int)((dvi_document->params->hshrink - 1) / scale) + 1, - (int)((dvi_document->params->vshrink - 1) / scale) + 1); + (int)((dvi_document->params->hshrink - 1) / rc->scale) + 1, + (int)((dvi_document->params->vshrink - 1) / rc->scale) + 1); - required_width = dvi_document->base_width * scale; - required_height = dvi_document->base_height * scale; + required_width = dvi_document->base_width * rc->scale; + required_height = dvi_document->base_height * rc->scale; proposed_width = dvi_document->context->dvi_page_w * dvi_document->context->params.conv; proposed_height = dvi_document->context->dvi_page_h * dvi_document->context->params.vconv; @@ -192,7 +235,10 @@ dvi_document_render_pixbuf (EvDocument *document, int page, double scale) g_mutex_unlock (dvi_context_mutex); - return pixbuf; + rotated_pixbuf = rotate_pixbuf (document, pixbuf); + g_object_unref (pixbuf); + + return rotated_pixbuf; } static void @@ -247,6 +293,8 @@ dvi_document_document_iface_init (EvDocumentIface *iface) iface->get_page_size = dvi_document_get_page_size; iface->render_pixbuf = dvi_document_render_pixbuf; iface->get_info = dvi_document_get_info; + iface->get_orientation = dvi_document_get_orientation; + iface->set_orientation = dvi_document_set_orientation; } static void -- 2.43.5