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;
40 gint x_offset, y_offset;
43 typedef struct _PixbufDocumentClass PixbufDocumentClass;
45 static void pixbuf_document_document_iface_init (EvDocumentIface *iface);
46 static void pixbuf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface);
48 G_DEFINE_TYPE_WITH_CODE (PixbufDocument, pixbuf_document, G_TYPE_OBJECT,
49 { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,
50 pixbuf_document_document_iface_init);
51 G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
52 pixbuf_document_document_thumbnails_iface_init)
56 pixbuf_document_load (EvDocument *document,
60 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
65 /* FIXME: We could actually load uris */
66 filename = g_filename_from_uri (uri, NULL, error);
70 pixbuf = gdk_pixbuf_new_from_file (filename, error);
75 pixbuf_document->pixbuf = pixbuf;
81 pixbuf_document_save (EvDocument *document,
85 g_warning ("pixbuf_document_save not implemented"); /* FIXME */
90 pixbuf_document_get_n_pages (EvDocument *document)
96 pixbuf_document_get_page_size (EvDocument *document,
101 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
104 *width = gdk_pixbuf_get_width (pixbuf_document->pixbuf);
106 *height = gdk_pixbuf_get_height (pixbuf_document->pixbuf);
108 printf ("get_page_size, page=%d, *width=%f, *height=%f\n",
109 page, *width, *height);
113 pixbuf_document_render_pixbuf (EvDocument *document, int page, double scale)
115 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
116 return gdk_pixbuf_scale_simple (pixbuf_document->pixbuf,
117 gdk_pixbuf_get_width (pixbuf_document->pixbuf) * scale,
118 gdk_pixbuf_get_height (pixbuf_document->pixbuf) * scale,
119 GDK_INTERP_BILINEAR);
123 pixbuf_document_finalize (GObject *object)
125 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (object);
127 g_object_unref (pixbuf_document->pixbuf);
129 G_OBJECT_CLASS (pixbuf_document_parent_class)->finalize (object);
133 pixbuf_document_set_property (GObject *object,
147 pixbuf_document_get_property (GObject *object,
155 g_value_set_string (value, NULL);
161 pixbuf_document_class_init (PixbufDocumentClass *klass)
163 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
165 gobject_class->finalize = pixbuf_document_finalize;
166 gobject_class->get_property = pixbuf_document_get_property;
167 gobject_class->set_property = pixbuf_document_set_property;
169 g_object_class_override_property (gobject_class, PROP_TITLE, "title");
173 pixbuf_document_get_text (EvDocument *document, int page, EvRectangle *rect)
175 /* FIXME this method should not be in EvDocument */
176 g_warning ("pixbuf_document_get_text not implemented");
181 pixbuf_document_document_iface_init (EvDocumentIface *iface)
183 iface->load = pixbuf_document_load;
184 iface->save = pixbuf_document_save;
185 iface->get_text = pixbuf_document_get_text;
186 iface->get_n_pages = pixbuf_document_get_n_pages;
187 iface->get_page_size = pixbuf_document_get_page_size;
188 iface->render_pixbuf = pixbuf_document_render_pixbuf;
192 pixbuf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
197 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
199 gdouble scale_factor;
202 scale_factor = (gdouble)size / gdk_pixbuf_get_width (pixbuf_document->pixbuf);
204 height = gdk_pixbuf_get_height (pixbuf_document->pixbuf) * scale_factor;
206 pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf, size, height,
207 GDK_INTERP_BILINEAR);
213 pixbuf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
215 gint suggested_width,
219 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
222 page_ratio = ((double)gdk_pixbuf_get_height (pixbuf_document->pixbuf)) /
223 gdk_pixbuf_get_width (pixbuf_document->pixbuf);
224 *width = suggested_width;
225 *height = (gint) (suggested_width * page_ratio);
229 pixbuf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
231 iface->get_thumbnail = pixbuf_document_thumbnails_get_thumbnail;
232 iface->get_dimensions = pixbuf_document_thumbnails_get_dimensions;
237 pixbuf_document_init (PixbufDocument *pixbuf_document)
239 pixbuf_document->x_offset = 0;
240 pixbuf_document->y_offset = 0;