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;
37 typedef struct _PixbufDocumentClass PixbufDocumentClass;
39 static void pixbuf_document_document_iface_init (EvDocumentIface *iface);
40 static void pixbuf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface);
42 G_DEFINE_TYPE_WITH_CODE (PixbufDocument, pixbuf_document, G_TYPE_OBJECT,
43 { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,
44 pixbuf_document_document_iface_init);
45 G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
46 pixbuf_document_document_thumbnails_iface_init)
50 pixbuf_document_load (EvDocument *document,
54 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
59 /* FIXME: We could actually load uris */
60 filename = g_filename_from_uri (uri, NULL, error);
64 pixbuf = gdk_pixbuf_new_from_file (filename, error);
69 pixbuf_document->pixbuf = pixbuf;
70 g_free (pixbuf_document->uri);
71 pixbuf_document->uri = g_strdup (uri);
77 pixbuf_document_save (EvDocument *document,
81 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
83 return ev_xfer_uri_simple (pixbuf_document->uri, uri, error);
87 pixbuf_document_get_n_pages (EvDocument *document)
93 pixbuf_document_get_page_size (EvDocument *document,
98 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
100 *width = gdk_pixbuf_get_width (pixbuf_document->pixbuf);
101 *height = gdk_pixbuf_get_height (pixbuf_document->pixbuf);
105 pixbuf_document_render_pixbuf (EvDocument *document,
108 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
109 GdkPixbuf *scaled_pixbuf, *rotated_pixbuf;
111 scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf,
112 gdk_pixbuf_get_width (pixbuf_document->pixbuf) * rc->scale,
113 gdk_pixbuf_get_height (pixbuf_document->pixbuf) * rc->scale,
114 GDK_INTERP_BILINEAR);
116 rotated_pixbuf = gdk_pixbuf_rotate_simple (scaled_pixbuf, 360 - rc->rotation);
117 g_object_unref (scaled_pixbuf);
119 return rotated_pixbuf;
123 pixbuf_document_finalize (GObject *object)
125 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (object);
127 g_object_unref (pixbuf_document->pixbuf);
128 g_free (pixbuf_document->uri);
130 G_OBJECT_CLASS (pixbuf_document_parent_class)->finalize (object);
134 pixbuf_document_class_init (PixbufDocumentClass *klass)
136 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
138 gobject_class->finalize = pixbuf_document_finalize;
142 pixbuf_document_can_get_text (EvDocument *document)
147 static EvDocumentInfo *
148 pixbuf_document_get_info (EvDocument *document)
150 EvDocumentInfo *info;
152 info = g_new0 (EvDocumentInfo, 1);
153 info->fields_mask = 0;
159 pixbuf_document_document_iface_init (EvDocumentIface *iface)
161 iface->load = pixbuf_document_load;
162 iface->save = pixbuf_document_save;
163 iface->can_get_text = pixbuf_document_can_get_text;
164 iface->get_n_pages = pixbuf_document_get_n_pages;
165 iface->get_page_size = pixbuf_document_get_page_size;
166 iface->render_pixbuf = pixbuf_document_render_pixbuf;
167 iface->get_info = pixbuf_document_get_info;
171 pixbuf_document_thumbnails_get_thumbnail (EvDocumentThumbnails *document,
175 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
176 GdkPixbuf *pixbuf, *rotated_pixbuf;
179 width = (gint) (gdk_pixbuf_get_width (pixbuf_document->pixbuf) * rc->scale);
180 height = (gint) (gdk_pixbuf_get_height (pixbuf_document->pixbuf) * rc->scale);
182 pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf,
184 GDK_INTERP_BILINEAR);
186 rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rc->rotation);
187 g_object_unref (pixbuf);
189 return rotated_pixbuf;
193 pixbuf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
198 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
199 gint p_width = gdk_pixbuf_get_width (pixbuf_document->pixbuf);
200 gint p_height = gdk_pixbuf_get_height (pixbuf_document->pixbuf);
202 if (rc->rotation == 90 || rc->rotation == 270) {
203 *width = (gint) (p_height * rc->scale);
204 *height = (gint) (p_width * rc->scale);
206 *width = (gint) (p_width * rc->scale);
207 *height = (gint) (p_height * rc->scale);
212 pixbuf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
214 iface->get_thumbnail = pixbuf_document_thumbnails_get_thumbnail;
215 iface->get_dimensions = pixbuf_document_thumbnails_get_dimensions;
220 pixbuf_document_init (PixbufDocument *pixbuf_document)