1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
3 * Copyright (C) 2004, Anders Carlsson <andersca@gnome.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "pixbuf-document.h"
24 #include "ev-document-thumbnails.h"
25 #include "ev-document-misc.h"
27 struct _PixbufDocumentClass
29 GObjectClass parent_class;
32 struct _PixbufDocument
34 GObject parent_instance;
41 typedef struct _PixbufDocumentClass PixbufDocumentClass;
43 static void pixbuf_document_document_iface_init (EvDocumentIface *iface);
44 static void pixbuf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface);
46 EV_BACKEND_REGISTER_WITH_CODE (PixbufDocument, pixbuf_document,
48 G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
49 pixbuf_document_document_thumbnails_iface_init)
53 pixbuf_document_load (EvDocument *document,
57 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
62 /* FIXME: We could actually load uris */
63 filename = g_filename_from_uri (uri, NULL, error);
67 pixbuf = gdk_pixbuf_new_from_file (filename, error);
72 pixbuf_document->pixbuf = pixbuf;
73 g_free (pixbuf_document->uri);
74 pixbuf_document->uri = g_strdup (uri);
80 pixbuf_document_save (EvDocument *document,
84 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
86 return ev_xfer_uri_simple (pixbuf_document->uri, uri, error);
90 pixbuf_document_get_n_pages (EvDocument *document)
96 pixbuf_document_get_page_size (EvDocument *document,
101 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
103 *width = gdk_pixbuf_get_width (pixbuf_document->pixbuf);
104 *height = gdk_pixbuf_get_height (pixbuf_document->pixbuf);
107 static cairo_surface_t *
108 pixbuf_document_render (EvDocument *document,
111 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
112 GdkPixbuf *scaled_pixbuf, *rotated_pixbuf;
113 cairo_surface_t *surface;
115 scaled_pixbuf = gdk_pixbuf_scale_simple (
116 pixbuf_document->pixbuf,
117 (gdk_pixbuf_get_width (pixbuf_document->pixbuf) * rc->scale) + 0.5,
118 (gdk_pixbuf_get_height (pixbuf_document->pixbuf) * rc->scale) + 0.5,
119 GDK_INTERP_BILINEAR);
121 rotated_pixbuf = gdk_pixbuf_rotate_simple (scaled_pixbuf, 360 - rc->rotation);
122 g_object_unref (scaled_pixbuf);
124 surface = ev_document_misc_surface_from_pixbuf (rotated_pixbuf);
125 g_object_unref (rotated_pixbuf);
131 pixbuf_document_finalize (GObject *object)
133 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (object);
135 g_object_unref (pixbuf_document->pixbuf);
136 g_free (pixbuf_document->uri);
138 G_OBJECT_CLASS (pixbuf_document_parent_class)->finalize (object);
142 pixbuf_document_class_init (PixbufDocumentClass *klass)
144 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
146 gobject_class->finalize = pixbuf_document_finalize;
149 static EvDocumentInfo *
150 pixbuf_document_get_info (EvDocument *document)
152 EvDocumentInfo *info;
154 info = g_new0 (EvDocumentInfo, 1);
155 info->fields_mask = 0;
161 pixbuf_document_document_iface_init (EvDocumentIface *iface)
163 iface->load = pixbuf_document_load;
164 iface->save = pixbuf_document_save;
165 iface->get_n_pages = pixbuf_document_get_n_pages;
166 iface->get_page_size = pixbuf_document_get_page_size;
167 iface->render = pixbuf_document_render;
168 iface->get_info = pixbuf_document_get_info;
172 pixbuf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
176 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
177 GdkPixbuf *pixbuf, *rotated_pixbuf;
180 width = (gint) (gdk_pixbuf_get_width (pixbuf_document->pixbuf) * rc->scale);
181 height = (gint) (gdk_pixbuf_get_height (pixbuf_document->pixbuf) * rc->scale);
183 pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf,
185 GDK_INTERP_BILINEAR);
187 rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rc->rotation);
188 g_object_unref (pixbuf);
190 return rotated_pixbuf;
194 pixbuf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
199 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
200 gint p_width = gdk_pixbuf_get_width (pixbuf_document->pixbuf);
201 gint p_height = gdk_pixbuf_get_height (pixbuf_document->pixbuf);
203 if (rc->rotation == 90 || rc->rotation == 270) {
204 *width = (gint) (p_height * rc->scale);
205 *height = (gint) (p_width * rc->scale);
207 *width = (gint) (p_width * rc->scale);
208 *height = (gint) (p_height * rc->scale);
213 pixbuf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
215 iface->get_thumbnail = pixbuf_document_thumbnails_get_thumbnail;
216 iface->get_dimensions = pixbuf_document_thumbnails_get_dimensions;
221 pixbuf_document_init (PixbufDocument *pixbuf_document)