X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=backend%2Fpixbuf%2Fpixbuf-document.c;h=b508810803632e5bfcbf886567e22c6ef9282915;hb=0526caefb3e35fe432e40fb9503d370907c9ef28;hp=e3d064da4f95cbc2e9dfdcdcc5e43bb20a5547ef;hpb=13a06349251874bd35d2f03c3fc93217cee749a2;p=evince.git diff --git a/backend/pixbuf/pixbuf-document.c b/backend/pixbuf/pixbuf-document.c index e3d064da..b5088108 100644 --- a/backend/pixbuf/pixbuf-document.c +++ b/backend/pixbuf/pixbuf-document.c @@ -17,17 +17,22 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include +#include + #include "pixbuf-document.h" #include "ev-document-thumbnails.h" +#include "ev-document-misc.h" +#include "ev-file-helpers.h" struct _PixbufDocumentClass { - GObjectClass parent_class; + EvDocumentClass parent_class; }; struct _PixbufDocument { - GObject parent_instance; + EvDocument parent_instance; GdkPixbuf *pixbuf; @@ -36,15 +41,13 @@ struct _PixbufDocument typedef struct _PixbufDocumentClass PixbufDocumentClass; -static void pixbuf_document_document_iface_init (EvDocumentIface *iface); static void pixbuf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface); -G_DEFINE_TYPE_WITH_CODE (PixbufDocument, pixbuf_document, G_TYPE_OBJECT, - { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT, - pixbuf_document_document_iface_init); - G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, - pixbuf_document_document_thumbnails_iface_init) - }); +EV_BACKEND_REGISTER_WITH_CODE (PixbufDocument, pixbuf_document, + { + EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, + pixbuf_document_document_thumbnails_iface_init) + }); static gboolean pixbuf_document_load (EvDocument *document, @@ -91,7 +94,7 @@ pixbuf_document_get_n_pages (EvDocument *document) static void pixbuf_document_get_page_size (EvDocument *document, - int page, + EvPage *page, double *width, double *height) { @@ -101,22 +104,27 @@ pixbuf_document_get_page_size (EvDocument *document, *height = gdk_pixbuf_get_height (pixbuf_document->pixbuf); } -static GdkPixbuf* -pixbuf_document_render_pixbuf (EvDocument *document, - EvRenderContext *rc) +static cairo_surface_t * +pixbuf_document_render (EvDocument *document, + EvRenderContext *rc) { PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document); GdkPixbuf *scaled_pixbuf, *rotated_pixbuf; + cairo_surface_t *surface; - scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf, - gdk_pixbuf_get_width (pixbuf_document->pixbuf) * rc->scale, - gdk_pixbuf_get_height (pixbuf_document->pixbuf) * rc->scale, - GDK_INTERP_BILINEAR); - + scaled_pixbuf = gdk_pixbuf_scale_simple ( + pixbuf_document->pixbuf, + (gdk_pixbuf_get_width (pixbuf_document->pixbuf) * rc->scale) + 0.5, + (gdk_pixbuf_get_height (pixbuf_document->pixbuf) * rc->scale) + 0.5, + GDK_INTERP_BILINEAR); + rotated_pixbuf = gdk_pixbuf_rotate_simple (scaled_pixbuf, 360 - rc->rotation); g_object_unref (scaled_pixbuf); - return rotated_pixbuf; + surface = ev_document_misc_surface_from_pixbuf (rotated_pixbuf); + g_object_unref (rotated_pixbuf); + + return surface; } static void @@ -133,60 +141,35 @@ pixbuf_document_finalize (GObject *object) static void pixbuf_document_class_init (PixbufDocumentClass *klass) { - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + EvDocumentClass *ev_document_class = EV_DOCUMENT_CLASS (klass); gobject_class->finalize = pixbuf_document_finalize; -} - -static gboolean -pixbuf_document_can_get_text (EvDocument *document) -{ - return FALSE; -} -static EvDocumentInfo * -pixbuf_document_get_info (EvDocument *document) -{ - EvDocumentInfo *info; - - info = g_new0 (EvDocumentInfo, 1); - info->fields_mask = 0; - - return info; -} - -static void -pixbuf_document_document_iface_init (EvDocumentIface *iface) -{ - iface->load = pixbuf_document_load; - iface->save = pixbuf_document_save; - iface->can_get_text = pixbuf_document_can_get_text; - iface->get_n_pages = pixbuf_document_get_n_pages; - iface->get_page_size = pixbuf_document_get_page_size; - iface->render_pixbuf = pixbuf_document_render_pixbuf; - iface->get_info = pixbuf_document_get_info; + ev_document_class->load = pixbuf_document_load; + ev_document_class->save = pixbuf_document_save; + ev_document_class->get_n_pages = pixbuf_document_get_n_pages; + ev_document_class->get_page_size = pixbuf_document_get_page_size; + ev_document_class->render = pixbuf_document_render; } static GdkPixbuf * -pixbuf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, - gint page, - gint rotation, - gint size, - gboolean border) +pixbuf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, + EvRenderContext *rc, + gboolean border) { PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document); GdkPixbuf *pixbuf, *rotated_pixbuf; - gdouble scale_factor; - gint height; + gint width, height; - scale_factor = (gdouble)size / gdk_pixbuf_get_width (pixbuf_document->pixbuf); - - height = gdk_pixbuf_get_height (pixbuf_document->pixbuf) * scale_factor; + width = (gint) (gdk_pixbuf_get_width (pixbuf_document->pixbuf) * rc->scale); + height = (gint) (gdk_pixbuf_get_height (pixbuf_document->pixbuf) * rc->scale); - pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf, size, height, + pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf, + width, height, GDK_INTERP_BILINEAR); - rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rotation); + rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rc->rotation); g_object_unref (pixbuf); return rotated_pixbuf; @@ -194,18 +177,21 @@ pixbuf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document, static void pixbuf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document, - gint page, - gint suggested_width, - gint *width, - gint *height) + EvRenderContext *rc, + gint *width, + gint *height) { PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document); - gdouble page_ratio; - - page_ratio = ((double)gdk_pixbuf_get_height (pixbuf_document->pixbuf)) / - gdk_pixbuf_get_width (pixbuf_document->pixbuf); - *width = suggested_width; - *height = (gint) (suggested_width * page_ratio); + gint p_width = gdk_pixbuf_get_width (pixbuf_document->pixbuf); + gint p_height = gdk_pixbuf_get_height (pixbuf_document->pixbuf); + + if (rc->rotation == 90 || rc->rotation == 270) { + *width = (gint) (p_height * rc->scale); + *height = (gint) (p_width * rc->scale); + } else { + *width = (gint) (p_width * rc->scale); + *height = (gint) (p_height * rc->scale); + } } static void