]> www.fi.muni.cz Git - evince.git/blob - libdocument/ev-document.c
Add application/x-ext-pdf mime type for pdf backend. See bug #339172.
[evince.git] / libdocument / 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 GMutex *ev_doc_mutex = NULL;
26 GMutex *ev_fc_mutex = NULL;
27
28 EV_DEFINE_INTERFACE (EvDocument, ev_document, G_TYPE_OBJECT)
29
30 GQuark
31 ev_document_error_quark (void)
32 {
33   static GQuark q = 0;
34   if (q == 0)
35     q = g_quark_from_static_string ("ev-document-error-quark");
36
37   return q;
38 }
39
40 static void
41 ev_document_class_init (EvDocumentIface *klass)
42 {
43 }
44
45 GMutex *
46 ev_document_get_doc_mutex (void)
47 {
48         if (ev_doc_mutex == NULL) {
49                 ev_doc_mutex = g_mutex_new ();
50         }
51         return ev_doc_mutex;
52 }
53
54 void
55 ev_document_doc_mutex_lock (void)
56 {
57         g_mutex_lock (ev_document_get_doc_mutex ());
58 }
59
60 void
61 ev_document_doc_mutex_unlock (void)
62 {
63         g_mutex_unlock (ev_document_get_doc_mutex ());
64 }
65
66 gboolean
67 ev_document_doc_mutex_trylock (void)
68 {
69         return g_mutex_trylock (ev_document_get_doc_mutex ());
70 }
71
72 GMutex *
73 ev_document_get_fc_mutex (void)
74 {
75         if (ev_fc_mutex == NULL) {
76                 ev_fc_mutex = g_mutex_new ();
77         }
78         return ev_fc_mutex;
79 }
80
81 void
82 ev_document_fc_mutex_lock (void)
83 {
84         g_mutex_lock (ev_document_get_fc_mutex ());
85 }
86
87 void
88 ev_document_fc_mutex_unlock (void)
89 {
90         g_mutex_unlock (ev_document_get_fc_mutex ());
91 }
92
93 gboolean
94 ev_document_fc_mutex_trylock (void)
95 {
96         return g_mutex_trylock (ev_document_get_fc_mutex ());
97 }
98
99 gboolean
100 ev_document_load (EvDocument  *document,
101                   const char  *uri,
102                   GError     **error)
103 {
104         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
105         gboolean retval;
106
107         retval = iface->load (document, uri, error);
108
109         return retval;
110 }
111
112 gboolean
113 ev_document_save (EvDocument  *document,
114                   const char  *uri,
115                   GError     **error)
116 {
117         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
118         gboolean retval;
119
120         retval = iface->save (document, uri, error);
121
122         return retval;
123 }
124
125 int
126 ev_document_get_n_pages (EvDocument  *document)
127 {
128         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
129         gint retval;
130
131         retval = iface->get_n_pages (document);
132
133         return retval;
134 }
135
136 EvPage *
137 ev_document_get_page (EvDocument *document,
138                       gint        index)
139 {
140         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
141         EvPage *retval;
142
143         if (iface->get_page)
144                 retval = iface->get_page (document, index);
145         else
146                 retval = ev_page_new (index);
147
148         return retval;
149 }
150
151 void
152 ev_document_get_page_size (EvDocument *document,
153                            EvPage     *page,
154                            double     *width,
155                            double     *height)
156 {
157         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
158
159         iface->get_page_size (document, page, width, height);
160 }
161
162 char *
163 ev_document_get_page_label (EvDocument *document,
164                             EvPage     *page)
165 {
166         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
167
168         if (iface->get_page_label == NULL)
169                 return NULL;
170
171         return iface->get_page_label (document, page);
172 }
173
174 EvDocumentInfo *
175 ev_document_get_info (EvDocument *document)
176 {
177         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
178
179         return iface->get_info (document);
180 }
181
182 gboolean
183 ev_document_has_attachments (EvDocument *document)
184 {
185         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
186
187         if (iface->has_attachments == NULL)
188                 return FALSE;
189         
190         return iface->has_attachments (document);
191 }
192
193 GList *
194 ev_document_get_attachments (EvDocument *document)
195 {
196         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
197         GList *retval;
198
199         if (iface->get_attachments == NULL)
200                 return NULL;
201         retval = iface->get_attachments (document);
202
203         return retval;
204 }
205
206 cairo_surface_t *
207 ev_document_render (EvDocument      *document,
208                     EvRenderContext *rc)
209 {
210         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
211         cairo_surface_t *retval;
212
213         g_assert (iface->render);
214
215         retval = iface->render (document, rc);
216
217         return retval;
218 }
219
220 /* EvDocumentInfo */
221 EV_DEFINE_BOXED_TYPE (EvDocumentInfo, ev_document_info, ev_document_info_copy, ev_document_info_free)
222
223 EvDocumentInfo *
224 ev_document_info_copy (EvDocumentInfo *info)
225 {
226         EvDocumentInfo *copy;
227         
228         g_return_val_if_fail (info != NULL, NULL);
229
230         copy = g_new0 (EvDocumentInfo, 1);
231         copy->title = info->title ? g_strdup (info->title) : NULL;
232         copy->format = info->format ? g_strdup (info->format) : NULL;
233         copy->author = info->author ? g_strdup (info->author) : NULL;
234         copy->subject = info->subject ? g_strdup (info->subject) : NULL;
235         copy->keywords = info->keywords ? g_strdup (info->keywords) : NULL;
236         copy->security = info->security ? g_strdup (info->security) : NULL;
237         copy->creator = info->creator ? g_strdup (info->creator) : NULL;
238         copy->producer = info->producer ? g_strdup (info->producer) : NULL;
239         copy->linearized = info->linearized ? g_strdup (info->linearized) : NULL;
240         
241         copy->creation_date = info->creation_date;
242         copy->modified_date = info->modified_date;
243         copy->layout = info->layout;
244         copy->mode = info->mode;
245         copy->ui_hints = info->ui_hints;
246         copy->permissions = info->permissions;
247         copy->n_pages = info->n_pages;
248         copy->fields_mask = info->fields_mask;
249
250         return copy;
251 }
252
253 void
254 ev_document_info_free (EvDocumentInfo *info)
255 {
256         if (info == NULL)
257                 return;
258
259         g_free (info->title);
260         g_free (info->format);
261         g_free (info->author);
262         g_free (info->subject);
263         g_free (info->keywords);
264         g_free (info->creator);
265         g_free (info->producer);
266         g_free (info->linearized);
267         g_free (info->security);
268         
269         g_free (info);
270 }
271
272
273 /* Compares two rects.  returns 0 if they're equal */
274 #define EPSILON 0.0000001
275
276 gint
277 ev_rect_cmp (EvRectangle *a,
278              EvRectangle *b)
279 {
280         if (a == b)
281                 return 0;
282         if (a == NULL || b == NULL)
283                 return 1;
284
285         return ! ((ABS (a->x1 - b->x1) < EPSILON) &&
286                   (ABS (a->y1 - b->y1) < EPSILON) &&
287                   (ABS (a->x2 - b->x2) < EPSILON) &&
288                   (ABS (a->y2 - b->y2) < EPSILON));
289 }
290
291
292