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;
35 gint x_offset, y_offset;
38 typedef struct _PixbufDocumentClass PixbufDocumentClass;
40 static void pixbuf_document_document_iface_init (EvDocumentIface *iface);
41 static void pixbuf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface);
43 G_DEFINE_TYPE_WITH_CODE (PixbufDocument, pixbuf_document, G_TYPE_OBJECT,
44 { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,
45 pixbuf_document_document_iface_init);
46 G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
47 pixbuf_document_document_thumbnails_iface_init)
51 pixbuf_document_load (EvDocument *document,
55 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
60 /* FIXME: We could actually load uris */
61 filename = g_filename_from_uri (uri, NULL, error);
65 pixbuf = gdk_pixbuf_new_from_file (filename, error);
70 pixbuf_document->pixbuf = pixbuf;
76 pixbuf_document_save (EvDocument *document,
80 g_warning ("pixbuf_document_save not implemented"); /* FIXME */
85 pixbuf_document_get_n_pages (EvDocument *document)
91 pixbuf_document_get_page_size (EvDocument *document,
96 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
99 *width = gdk_pixbuf_get_width (pixbuf_document->pixbuf);
101 *height = gdk_pixbuf_get_height (pixbuf_document->pixbuf);
103 printf ("get_page_size, page=%d, *width=%f, *height=%f\n",
104 page, *width, *height);
108 pixbuf_document_render_pixbuf (EvDocument *document, int page, double scale)
110 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
111 return gdk_pixbuf_scale_simple (pixbuf_document->pixbuf,
112 gdk_pixbuf_get_width (pixbuf_document->pixbuf) * scale,
113 gdk_pixbuf_get_height (pixbuf_document->pixbuf) * scale,
114 GDK_INTERP_BILINEAR);
118 pixbuf_document_finalize (GObject *object)
120 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (object);
122 g_object_unref (pixbuf_document->pixbuf);
124 G_OBJECT_CLASS (pixbuf_document_parent_class)->finalize (object);
128 pixbuf_document_class_init (PixbufDocumentClass *klass)
130 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
132 gobject_class->finalize = pixbuf_document_finalize;
136 pixbuf_document_can_get_text (EvDocument *document)
141 static EvDocumentInfo *
142 pixbuf_document_get_info (EvDocument *document)
144 EvDocumentInfo *info;
146 info = g_new0 (EvDocumentInfo, 1);
147 info->fields_mask = 0;
153 pixbuf_document_document_iface_init (EvDocumentIface *iface)
155 iface->load = pixbuf_document_load;
156 iface->save = pixbuf_document_save;
157 iface->can_get_text = pixbuf_document_can_get_text;
158 iface->get_n_pages = pixbuf_document_get_n_pages;
159 iface->get_page_size = pixbuf_document_get_page_size;
160 iface->render_pixbuf = pixbuf_document_render_pixbuf;
161 iface->get_info = pixbuf_document_get_info;
165 pixbuf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
170 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
172 gdouble scale_factor;
175 scale_factor = (gdouble)size / gdk_pixbuf_get_width (pixbuf_document->pixbuf);
177 height = gdk_pixbuf_get_height (pixbuf_document->pixbuf) * scale_factor;
179 pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf, size, height,
180 GDK_INTERP_BILINEAR);
186 pixbuf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
188 gint suggested_width,
192 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
195 page_ratio = ((double)gdk_pixbuf_get_height (pixbuf_document->pixbuf)) /
196 gdk_pixbuf_get_width (pixbuf_document->pixbuf);
197 *width = suggested_width;
198 *height = (gint) (suggested_width * page_ratio);
202 pixbuf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
204 iface->get_thumbnail = pixbuf_document_thumbnails_get_thumbnail;
205 iface->get_dimensions = pixbuf_document_thumbnails_get_dimensions;
210 pixbuf_document_init (PixbufDocument *pixbuf_document)
212 pixbuf_document->x_offset = 0;
213 pixbuf_document->y_offset = 0;