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.
20 #include "pixbuf-document.h"
21 #include "ev-document-thumbnails.h"
23 struct _PixbufDocumentClass
25 GObjectClass parent_class;
28 struct _PixbufDocument
30 GObject parent_instance;
36 gint x_offset, y_offset;
39 typedef struct _PixbufDocumentClass PixbufDocumentClass;
41 static void pixbuf_document_document_iface_init (EvDocumentIface *iface);
42 static void pixbuf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface);
44 G_DEFINE_TYPE_WITH_CODE (PixbufDocument, pixbuf_document, G_TYPE_OBJECT,
45 { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,
46 pixbuf_document_document_iface_init);
47 G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
48 pixbuf_document_document_thumbnails_iface_init)
51 static GObjectClass *parent_class;
54 pixbuf_document_load (EvDocument *document,
58 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
63 /* FIXME: We could actually load uris */
64 filename = g_filename_from_uri (uri, NULL, error);
68 pixbuf = gdk_pixbuf_new_from_file (filename, error);
73 pixbuf_document->pixbuf = pixbuf;
79 pixbuf_document_get_n_pages (EvDocument *document)
85 pixbuf_document_set_page (EvDocument *document,
92 pixbuf_document_get_page (EvDocument *document)
98 pixbuf_document_set_target (EvDocument *document,
101 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
103 pixbuf_document->target = target;
107 pixbuf_document_set_scale (EvDocument *document,
110 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
112 pixbuf_document->scale = scale;
116 pixbuf_document_set_page_offset (EvDocument *document,
120 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
122 pixbuf_document->x_offset = x;
123 pixbuf_document->y_offset = y;
127 pixbuf_document_get_page_size (EvDocument *document,
131 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
133 *width = gdk_pixbuf_get_width (pixbuf_document->pixbuf);
134 *height = gdk_pixbuf_get_height (pixbuf_document->pixbuf);
138 pixbuf_document_render (EvDocument *document,
144 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
146 if (pixbuf_document->scale == 1.0) {
147 gdk_draw_pixbuf (pixbuf_document->target, NULL, pixbuf_document->pixbuf,
150 clip_width, clip_height, GDK_RGB_DITHER_NORMAL,
154 GdkPixbuf *tmp_pixbuf;
156 tmp_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (pixbuf_document->pixbuf),
157 gdk_pixbuf_get_has_alpha (pixbuf_document->pixbuf),
158 gdk_pixbuf_get_bits_per_sample (pixbuf_document->pixbuf),
159 clip_width, clip_height);
161 gdk_pixbuf_scale (pixbuf_document->pixbuf, tmp_pixbuf, 0, 0, clip_width, clip_height,
162 clip_x * pixbuf_document->scale,
163 clip_y * pixbuf_document->scale,
164 pixbuf_document->scale, pixbuf_document->scale,
165 GDK_INTERP_BILINEAR);
167 gdk_draw_pixbuf (pixbuf_document->target, NULL, tmp_pixbuf,
169 clip_x + pixbuf_document->x_offset,
170 clip_y + pixbuf_document->y_offset,
171 clip_width, clip_height, GDK_RGB_DITHER_NORMAL,
174 g_object_unref (tmp_pixbuf);
179 pixbuf_document_finalize (GObject *object)
181 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (object);
183 g_object_unref (pixbuf_document->pixbuf);
185 G_OBJECT_CLASS (parent_class)->finalize (object);
189 pixbuf_document_class_init (PixbufDocumentClass *klass)
191 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
193 parent_class = g_type_class_peek_parent (klass);
195 gobject_class->finalize = pixbuf_document_finalize;
199 pixbuf_document_document_iface_init (EvDocumentIface *iface)
201 iface->load = pixbuf_document_load;
202 iface->get_n_pages = pixbuf_document_get_n_pages;
203 iface->set_page = pixbuf_document_set_page;
204 iface->get_page = pixbuf_document_get_page;
205 iface->set_scale = pixbuf_document_set_scale;
206 iface->set_target = pixbuf_document_set_target;
207 iface->set_page_offset = pixbuf_document_set_page_offset;
208 iface->get_page_size = pixbuf_document_get_page_size;
209 iface->render = pixbuf_document_render;
213 pixbuf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
217 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
219 gdouble scale_factor;
222 scale_factor = (gdouble)width / gdk_pixbuf_get_width (pixbuf_document->pixbuf);
224 height = gdk_pixbuf_get_height (pixbuf_document->pixbuf) * scale_factor;
226 pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf, width, height,
227 GDK_INTERP_BILINEAR);
234 pixbuf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
236 iface->get_thumbnail = pixbuf_document_thumbnails_get_thumbnail;
241 pixbuf_document_init (PixbufDocument *pixbuf_document)
243 pixbuf_document->scale = 1.0;
245 pixbuf_document->x_offset = 10;
246 pixbuf_document->y_offset = 10;