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"
28 struct _PixbufDocumentClass
30 GObjectClass parent_class;
33 struct _PixbufDocument
35 GObject parent_instance;
41 gint x_offset, y_offset;
44 typedef struct _PixbufDocumentClass PixbufDocumentClass;
46 static void pixbuf_document_document_iface_init (EvDocumentIface *iface);
47 static void pixbuf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface);
49 G_DEFINE_TYPE_WITH_CODE (PixbufDocument, pixbuf_document, G_TYPE_OBJECT,
50 { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,
51 pixbuf_document_document_iface_init);
52 G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
53 pixbuf_document_document_thumbnails_iface_init)
56 static GObjectClass *parent_class;
59 pixbuf_document_load (EvDocument *document,
63 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
68 /* FIXME: We could actually load uris */
69 filename = g_filename_from_uri (uri, NULL, error);
73 pixbuf = gdk_pixbuf_new_from_file (filename, error);
78 pixbuf_document->pixbuf = pixbuf;
84 pixbuf_document_save (EvDocument *document,
88 g_warning ("pixbuf_document_save not implemented"); /* FIXME */
93 pixbuf_document_get_n_pages (EvDocument *document)
99 pixbuf_document_set_page (EvDocument *document,
106 pixbuf_document_get_page (EvDocument *document)
112 pixbuf_document_set_target (EvDocument *document,
115 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
117 pixbuf_document->target = target;
121 pixbuf_document_set_scale (EvDocument *document,
124 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
126 pixbuf_document->scale = scale;
130 pixbuf_document_set_page_offset (EvDocument *document,
134 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
136 pixbuf_document->x_offset = x;
137 pixbuf_document->y_offset = y;
141 pixbuf_document_get_page_size (EvDocument *document,
145 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
148 *width = gdk_pixbuf_get_width (pixbuf_document->pixbuf);
150 *height = gdk_pixbuf_get_height (pixbuf_document->pixbuf);
154 pixbuf_document_render (EvDocument *document,
160 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
162 if (pixbuf_document->scale == 1.0) {
163 gdk_draw_pixbuf (pixbuf_document->target, NULL, pixbuf_document->pixbuf,
166 clip_width, clip_height, GDK_RGB_DITHER_NORMAL,
170 GdkPixbuf *tmp_pixbuf;
172 tmp_pixbuf = gdk_pixbuf_new (gdk_pixbuf_get_colorspace (pixbuf_document->pixbuf),
173 gdk_pixbuf_get_has_alpha (pixbuf_document->pixbuf),
174 gdk_pixbuf_get_bits_per_sample (pixbuf_document->pixbuf),
175 clip_width, clip_height);
177 gdk_pixbuf_scale (pixbuf_document->pixbuf, tmp_pixbuf, 0, 0, clip_width, clip_height,
178 clip_x * pixbuf_document->scale,
179 clip_y * pixbuf_document->scale,
180 pixbuf_document->scale, pixbuf_document->scale,
181 GDK_INTERP_BILINEAR);
183 gdk_draw_pixbuf (pixbuf_document->target, NULL, tmp_pixbuf,
185 clip_x + pixbuf_document->x_offset,
186 clip_y + pixbuf_document->y_offset,
187 clip_width, clip_height, GDK_RGB_DITHER_NORMAL,
190 g_object_unref (tmp_pixbuf);
195 pixbuf_document_finalize (GObject *object)
197 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (object);
199 g_object_unref (pixbuf_document->pixbuf);
201 G_OBJECT_CLASS (parent_class)->finalize (object);
205 pixbuf_document_set_property (GObject *object,
219 pixbuf_document_get_property (GObject *object,
227 g_value_set_string (value, NULL);
233 pixbuf_document_class_init (PixbufDocumentClass *klass)
235 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
237 parent_class = g_type_class_peek_parent (klass);
239 gobject_class->finalize = pixbuf_document_finalize;
240 gobject_class->get_property = pixbuf_document_get_property;
241 gobject_class->set_property = pixbuf_document_set_property;
243 g_object_class_override_property (gobject_class, PROP_TITLE, "title");
247 pixbuf_document_get_text (EvDocument *document, GdkRectangle *rect)
249 /* FIXME this method should not be in EvDocument */
250 g_warning ("pixbuf_document_get_text not implemented");
256 pixbuf_document_get_link (EvDocument *document,
264 pixbuf_document_document_iface_init (EvDocumentIface *iface)
266 iface->load = pixbuf_document_load;
267 iface->save = pixbuf_document_save;
268 iface->get_text = pixbuf_document_get_text;
269 iface->get_link = pixbuf_document_get_link;
270 iface->get_n_pages = pixbuf_document_get_n_pages;
271 iface->set_page = pixbuf_document_set_page;
272 iface->get_page = pixbuf_document_get_page;
273 iface->set_scale = pixbuf_document_set_scale;
274 iface->set_target = pixbuf_document_set_target;
275 iface->set_page_offset = pixbuf_document_set_page_offset;
276 iface->get_page_size = pixbuf_document_get_page_size;
277 iface->render = pixbuf_document_render;
281 pixbuf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
285 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
287 gdouble scale_factor;
290 scale_factor = (gdouble)width / gdk_pixbuf_get_width (pixbuf_document->pixbuf);
292 height = gdk_pixbuf_get_height (pixbuf_document->pixbuf) * scale_factor;
294 pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf, width, height,
295 GDK_INTERP_BILINEAR);
301 pixbuf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
303 gint suggested_width,
307 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
310 page_ratio = ((double)gdk_pixbuf_get_height (pixbuf_document->pixbuf)) /
311 gdk_pixbuf_get_width (pixbuf_document->pixbuf);
312 *width = suggested_width;
313 *height = (gint) (suggested_width * page_ratio);
317 pixbuf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
319 iface->get_thumbnail = pixbuf_document_thumbnails_get_thumbnail;
320 iface->get_dimensions = pixbuf_document_thumbnails_get_dimensions;
325 pixbuf_document_init (PixbufDocument *pixbuf_document)
327 pixbuf_document->scale = 1.0;
329 pixbuf_document->x_offset = 10;
330 pixbuf_document->y_offset = 10;