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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include <glib/gi18n-lib.h>
23 #include "pixbuf-document.h"
24 #include "ev-document-misc.h"
25 #include "ev-file-helpers.h"
27 struct _PixbufDocumentClass
29 EvDocumentClass parent_class;
32 struct _PixbufDocument
34 EvDocument parent_instance;
41 typedef struct _PixbufDocumentClass PixbufDocumentClass;
43 EV_BACKEND_REGISTER (PixbufDocument, pixbuf_document)
46 pixbuf_document_load (EvDocument *document,
50 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
55 /* FIXME: We could actually load uris */
56 filename = g_filename_from_uri (uri, NULL, error);
60 pixbuf = gdk_pixbuf_new_from_file (filename, error);
65 pixbuf_document->pixbuf = pixbuf;
66 g_free (pixbuf_document->uri);
67 pixbuf_document->uri = g_strdup (uri);
73 pixbuf_document_save (EvDocument *document,
77 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
79 return ev_xfer_uri_simple (pixbuf_document->uri, uri, error);
83 pixbuf_document_get_n_pages (EvDocument *document)
89 pixbuf_document_get_page_size (EvDocument *document,
94 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
96 *width = gdk_pixbuf_get_width (pixbuf_document->pixbuf);
97 *height = gdk_pixbuf_get_height (pixbuf_document->pixbuf);
100 static cairo_surface_t *
101 pixbuf_document_render (EvDocument *document,
104 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
105 GdkPixbuf *scaled_pixbuf, *rotated_pixbuf;
106 cairo_surface_t *surface;
108 scaled_pixbuf = gdk_pixbuf_scale_simple (
109 pixbuf_document->pixbuf,
110 (gdk_pixbuf_get_width (pixbuf_document->pixbuf) * rc->scale) + 0.5,
111 (gdk_pixbuf_get_height (pixbuf_document->pixbuf) * rc->scale) + 0.5,
112 GDK_INTERP_BILINEAR);
114 rotated_pixbuf = gdk_pixbuf_rotate_simple (scaled_pixbuf, 360 - rc->rotation);
115 g_object_unref (scaled_pixbuf);
117 surface = ev_document_misc_surface_from_pixbuf (rotated_pixbuf);
118 g_object_unref (rotated_pixbuf);
124 pixbuf_document_get_thumbnail (EvDocument *document,
127 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
128 GdkPixbuf *pixbuf, *rotated_pixbuf;
131 width = (gint) (gdk_pixbuf_get_width (pixbuf_document->pixbuf) * rc->scale);
132 height = (gint) (gdk_pixbuf_get_height (pixbuf_document->pixbuf) * rc->scale);
134 pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf,
136 GDK_INTERP_BILINEAR);
138 rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, 360 - rc->rotation);
139 g_object_unref (pixbuf);
141 return rotated_pixbuf;
145 pixbuf_document_finalize (GObject *object)
147 PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (object);
149 g_object_unref (pixbuf_document->pixbuf);
150 g_free (pixbuf_document->uri);
152 G_OBJECT_CLASS (pixbuf_document_parent_class)->finalize (object);
156 pixbuf_document_class_init (PixbufDocumentClass *klass)
158 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
159 EvDocumentClass *ev_document_class = EV_DOCUMENT_CLASS (klass);
161 gobject_class->finalize = pixbuf_document_finalize;
163 ev_document_class->load = pixbuf_document_load;
164 ev_document_class->save = pixbuf_document_save;
165 ev_document_class->get_n_pages = pixbuf_document_get_n_pages;
166 ev_document_class->get_page_size = pixbuf_document_get_page_size;
167 ev_document_class->render = pixbuf_document_render;
168 ev_document_class->get_thumbnail = pixbuf_document_get_thumbnail;
172 pixbuf_document_init (PixbufDocument *pixbuf_document)