]> www.fi.muni.cz Git - evince.git/blob - backend/ev-document.c
Add support for PDF attachments. Fixes bug #325143
[evince.git] / backend / ev-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 Marco Pesenti Gritti
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
21 #include "config.h"
22
23 #include "ev-document.h"
24
25 #include "ev-backend-marshalers.h"
26
27 static void ev_document_class_init (gpointer g_class);
28
29
30 GMutex *ev_doc_mutex = NULL;
31
32 #define LOG(x) 
33 GType
34 ev_document_get_type (void)
35 {
36         static GType type = 0;
37
38         if (G_UNLIKELY (type == 0))
39         {
40                 static const GTypeInfo our_info =
41                 {
42                         sizeof (EvDocumentIface),
43                         NULL,
44                         NULL,
45                         (GClassInitFunc)ev_document_class_init
46                 };
47
48                 type = g_type_register_static (G_TYPE_INTERFACE,
49                                                "EvDocument",
50                                                &our_info, (GTypeFlags)0);
51         }
52
53         return type;
54 }
55
56 GQuark
57 ev_document_error_quark (void)
58 {
59   static GQuark q = 0;
60   if (q == 0)
61     q = g_quark_from_static_string ("ev-document-error-quark");
62
63   return q;
64 }
65
66 static void
67 ev_document_class_init (gpointer g_class)
68 {
69 }
70
71 GMutex *
72 ev_document_get_doc_mutex (void)
73 {
74         if (ev_doc_mutex == NULL) {
75                 ev_doc_mutex = g_mutex_new ();
76         }
77         return ev_doc_mutex;
78 }
79
80 void
81 ev_document_doc_mutex_lock (void)
82 {
83         g_mutex_lock (ev_document_get_doc_mutex ());
84 }
85
86 void
87 ev_document_doc_mutex_unlock (void)
88 {
89         g_mutex_unlock (ev_document_get_doc_mutex ());
90 }
91
92
93
94 gboolean
95 ev_document_load (EvDocument  *document,
96                   const char  *uri,
97                   GError     **error)
98 {
99         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
100         gboolean retval;
101         LOG ("ev_document_load");
102         retval = iface->load (document, uri, error);
103
104         return retval;
105 }
106
107 gboolean
108 ev_document_save (EvDocument  *document,
109                   const char  *uri,
110                   GError     **error)
111 {
112         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
113         gboolean retval;
114
115         LOG ("ev_document_save");
116         retval = iface->save (document, uri, error);
117
118         return retval;
119 }
120
121 int
122 ev_document_get_n_pages (EvDocument  *document)
123 {
124         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
125         gint retval;
126
127         LOG ("ev_document_get_n_pages");
128         retval = iface->get_n_pages (document);
129
130         return retval;
131 }
132
133 void
134 ev_document_get_page_size   (EvDocument   *document,
135                              int           page,
136                              double       *width,
137                              double       *height)
138 {
139         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
140
141         LOG ("ev_document_get_page_size");
142         iface->get_page_size (document, page, width, height);
143 }
144
145 char *
146 ev_document_get_page_label(EvDocument    *document,
147                            int             page)
148 {
149         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
150
151         LOG ("ev_document_get_page_label");
152         if (iface->get_page_label == NULL)
153                 return NULL;
154
155         return iface->get_page_label (document, page);
156 }
157
158 gboolean
159 ev_document_can_get_text (EvDocument  *document)
160 {
161         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
162
163         return iface->can_get_text (document);
164 }
165
166 EvDocumentInfo *
167 ev_document_get_info (EvDocument *document)
168 {
169         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
170
171         return iface->get_info (document);
172 }
173
174 char *
175 ev_document_get_text (EvDocument  *document,
176                       int          page,
177                       EvRectangle *rect)
178 {
179         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
180         char *retval;
181
182         LOG ("ev_document_get_text");
183         retval = iface->get_text (document, page, rect);
184
185         return retval;
186 }
187
188 GList *
189 ev_document_get_links (EvDocument *document,
190                        int         page)
191 {
192         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
193         GList *retval;
194
195         LOG ("ev_document_get_link");
196         if (iface->get_links == NULL)
197                 return NULL;
198         retval = iface->get_links (document, page);
199
200         return retval;
201 }
202
203 gboolean
204 ev_document_has_attachments (EvDocument *document)
205 {
206         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
207
208         if (iface->has_attachments == NULL)
209                 return FALSE;
210         
211         return iface->has_attachments (document);
212 }
213
214 GList *
215 ev_document_get_attachments (EvDocument *document)
216 {
217         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
218         GList *retval;
219
220         LOG ("ev_document_get_attachments");
221         if (iface->get_attachments == NULL)
222                 return NULL;
223         retval = iface->get_attachments (document);
224
225         return retval;
226 }
227
228 GdkPixbuf *
229 ev_document_render_pixbuf (EvDocument      *document,
230                            EvRenderContext *rc)
231 {
232         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
233         GdkPixbuf *retval;
234
235         LOG ("ev_document_render_pixbuf");
236         g_assert (iface->render_pixbuf);
237
238         retval = iface->render_pixbuf (document, rc);
239
240         return retval;
241 }
242
243 void
244 ev_document_info_free (EvDocumentInfo *info)
245 {
246         if (info == NULL)
247                 return;
248
249         g_free (info->title);
250         g_free (info->format);
251         g_free (info->author);
252         g_free (info->subject);
253         g_free (info->keywords);
254         g_free (info->security);
255
256         g_free (info);
257 }
258
259
260 /* Compares two rects.  returns 0 if they're equal */
261 #define EPSILON 0.0000001
262
263 gint
264 ev_rect_cmp (EvRectangle *a,
265              EvRectangle *b)
266 {
267         if (a == b)
268                 return 0;
269         if (a == NULL || b == NULL)
270                 return 1;
271
272         return ! ((ABS (a->x1 - b->x1) < EPSILON) &&
273                   (ABS (a->y1 - b->y1) < EPSILON) &&
274                   (ABS (a->x2 - b->x2) < EPSILON) &&
275                   (ABS (a->y2 - b->y2) < EPSILON));
276 }