]> www.fi.muni.cz Git - evince.git/blob - pixbuf/pixbuf-document.c
Hungarian translation updated.
[evince.git] / pixbuf / pixbuf-document.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /*
3  * Copyright (C) 2004, Anders Carlsson <andersca@gnome.org>
4  *
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)
8  * any later version.
9  *
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.
14  *
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.
18  */
19
20 #include "pixbuf-document.h"
21 #include "ev-document-thumbnails.h"
22
23 struct _PixbufDocumentClass
24 {
25         GObjectClass parent_class;
26 };
27
28 struct _PixbufDocument
29 {
30         GObject parent_instance;
31
32         GdkPixbuf *pixbuf;
33 };
34
35 typedef struct _PixbufDocumentClass PixbufDocumentClass;
36
37 static void pixbuf_document_document_iface_init (EvDocumentIface *iface);
38 static void pixbuf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface);
39
40 G_DEFINE_TYPE_WITH_CODE (PixbufDocument, pixbuf_document, G_TYPE_OBJECT,
41                          { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,
42                                                   pixbuf_document_document_iface_init);
43                          G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
44                                                 pixbuf_document_document_thumbnails_iface_init)                            
45                                    });
46
47 static gboolean
48 pixbuf_document_load (EvDocument  *document,
49                       const char  *uri,
50                       GError     **error)
51 {
52         PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
53         
54         gchar *filename;
55         GdkPixbuf *pixbuf;
56
57         /* FIXME: We could actually load uris  */
58         filename = g_filename_from_uri (uri, NULL, error);
59         if (!filename)
60                 return FALSE;
61         
62         pixbuf = gdk_pixbuf_new_from_file (filename, error);
63
64         if (!pixbuf)
65                 return FALSE;
66
67         pixbuf_document->pixbuf = pixbuf;
68         
69         return TRUE;
70 }
71
72 static gboolean
73 pixbuf_document_save (EvDocument  *document,
74                       const char  *uri,
75                       GError     **error)
76 {
77         g_warning ("pixbuf_document_save not implemented"); /* FIXME */
78         return TRUE;
79 }
80
81 static int
82 pixbuf_document_get_n_pages (EvDocument  *document)
83 {
84         return 1;
85 }
86
87 static void
88 pixbuf_document_get_page_size (EvDocument   *document,
89                                int           page,
90                                double       *width,
91                                double       *height)
92 {
93         PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
94
95         *width = gdk_pixbuf_get_width (pixbuf_document->pixbuf);
96         *height = gdk_pixbuf_get_height (pixbuf_document->pixbuf);
97 }
98
99 static GdkPixbuf*
100 pixbuf_document_render_pixbuf (EvDocument      *document,
101                                EvRenderContext *rc)
102 {
103         PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
104         GdkPixbuf *scaled_pixbuf, *rotated_pixbuf;
105
106         scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf,
107                                                  gdk_pixbuf_get_width (pixbuf_document->pixbuf) * rc->scale,
108                                                  gdk_pixbuf_get_height (pixbuf_document->pixbuf) * rc->scale,
109                                                  GDK_INTERP_BILINEAR);
110
111         rotated_pixbuf = gdk_pixbuf_rotate_simple (scaled_pixbuf, rc->rotation);
112         g_object_unref (scaled_pixbuf);
113
114         return rotated_pixbuf;
115 }
116
117 static void
118 pixbuf_document_finalize (GObject *object)
119 {
120         PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (object);
121
122         g_object_unref (pixbuf_document->pixbuf);
123         
124         G_OBJECT_CLASS (pixbuf_document_parent_class)->finalize (object);
125 }
126
127 static void
128 pixbuf_document_class_init (PixbufDocumentClass *klass)
129 {
130         GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
131
132         gobject_class->finalize = pixbuf_document_finalize;
133 }
134
135 static gboolean
136 pixbuf_document_can_get_text (EvDocument *document)
137 {
138         return FALSE;
139 }
140
141 static EvDocumentInfo *
142 pixbuf_document_get_info (EvDocument *document)
143 {
144         EvDocumentInfo *info;
145
146         info = g_new0 (EvDocumentInfo, 1);
147         info->fields_mask = 0;
148
149         return info;
150 }
151
152 static void
153 pixbuf_document_document_iface_init (EvDocumentIface *iface)
154 {
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;
162 }
163
164 static GdkPixbuf *
165 pixbuf_document_thumbnails_get_thumbnail (EvDocumentThumbnails   *document,
166                                           gint                    page,
167                                           gint                    rotation,
168                                           gint                    size,
169                                           gboolean                border)
170 {
171         PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
172         GdkPixbuf *pixbuf, *rotated_pixbuf;
173         gdouble scale_factor;
174         gint height;
175         
176         scale_factor = (gdouble)size / gdk_pixbuf_get_width (pixbuf_document->pixbuf);
177
178         height = gdk_pixbuf_get_height (pixbuf_document->pixbuf) * scale_factor;
179         
180         pixbuf = gdk_pixbuf_scale_simple (pixbuf_document->pixbuf, size, height,
181                                           GDK_INTERP_BILINEAR);
182
183         rotated_pixbuf = gdk_pixbuf_rotate_simple (pixbuf, rotation);
184         g_object_unref (pixbuf);
185
186         return rotated_pixbuf;
187 }
188
189 static void
190 pixbuf_document_thumbnails_get_dimensions (EvDocumentThumbnails *document,
191                                            gint                  page,
192                                            gint                  suggested_width,
193                                            gint                  *width,
194                                            gint                  *height)
195 {
196         PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
197         gdouble page_ratio;
198
199         page_ratio = ((double)gdk_pixbuf_get_height (pixbuf_document->pixbuf)) /
200                      gdk_pixbuf_get_width (pixbuf_document->pixbuf);
201         *width = suggested_width;
202         *height = (gint) (suggested_width * page_ratio);
203 }
204
205 static void
206 pixbuf_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
207 {
208         iface->get_thumbnail = pixbuf_document_thumbnails_get_thumbnail;
209         iface->get_dimensions = pixbuf_document_thumbnails_get_dimensions;
210 }
211
212
213 static void
214 pixbuf_document_init (PixbufDocument *pixbuf_document)
215 {
216 }