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