]> www.fi.muni.cz Git - evince.git/blob - libdocument/ev-document.c
Merge branch 'ev-debug' into work
[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
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 GMutex *
93 ev_document_get_fc_mutex (void)
94 {
95         if (ev_fc_mutex == NULL) {
96                 ev_fc_mutex = g_mutex_new ();
97         }
98         return ev_fc_mutex;
99 }
100
101 void
102 ev_document_fc_mutex_lock (void)
103 {
104         g_mutex_lock (ev_document_get_fc_mutex ());
105 }
106
107 void
108 ev_document_fc_mutex_unlock (void)
109 {
110         g_mutex_unlock (ev_document_get_fc_mutex ());
111 }
112
113 gboolean
114 ev_document_load (EvDocument  *document,
115                   const char  *uri,
116                   GError     **error)
117 {
118         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
119         gboolean retval;
120
121         retval = iface->load (document, uri, error);
122
123         return retval;
124 }
125
126 gboolean
127 ev_document_save (EvDocument  *document,
128                   const char  *uri,
129                   GError     **error)
130 {
131         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
132         gboolean retval;
133
134         retval = iface->save (document, uri, error);
135
136         return retval;
137 }
138
139 int
140 ev_document_get_n_pages (EvDocument  *document)
141 {
142         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
143         gint retval;
144
145         retval = iface->get_n_pages (document);
146
147         return retval;
148 }
149
150 EvPage *
151 ev_document_get_page (EvDocument *document,
152                       gint        index)
153 {
154         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
155         EvPage *retval;
156
157         if (iface->get_page)
158                 retval = iface->get_page (document, index);
159         else
160                 retval = ev_page_new (index);
161
162         return retval;
163 }
164
165 void
166 ev_document_get_page_size (EvDocument *document,
167                            EvPage     *page,
168                            double     *width,
169                            double     *height)
170 {
171         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
172
173         iface->get_page_size (document, page, width, height);
174 }
175
176 char *
177 ev_document_get_page_label (EvDocument *document,
178                             EvPage     *page)
179 {
180         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
181
182         if (iface->get_page_label == NULL)
183                 return NULL;
184
185         return iface->get_page_label (document, page);
186 }
187
188 EvDocumentInfo *
189 ev_document_get_info (EvDocument *document)
190 {
191         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
192
193         return iface->get_info (document);
194 }
195
196 gboolean
197 ev_document_has_attachments (EvDocument *document)
198 {
199         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
200
201         if (iface->has_attachments == NULL)
202                 return FALSE;
203         
204         return iface->has_attachments (document);
205 }
206
207 GList *
208 ev_document_get_attachments (EvDocument *document)
209 {
210         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
211         GList *retval;
212
213         if (iface->get_attachments == NULL)
214                 return NULL;
215         retval = iface->get_attachments (document);
216
217         return retval;
218 }
219
220 cairo_surface_t *
221 ev_document_render (EvDocument      *document,
222                     EvRenderContext *rc)
223 {
224         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
225         cairo_surface_t *retval;
226
227         g_assert (iface->render);
228
229         retval = iface->render (document, rc);
230
231         return retval;
232 }
233
234 void
235 ev_document_info_free (EvDocumentInfo *info)
236 {
237         if (info == NULL)
238                 return;
239
240         g_free (info->title);
241         g_free (info->format);
242         g_free (info->author);
243         g_free (info->subject);
244         g_free (info->keywords);
245         g_free (info->creator);
246         g_free (info->producer);
247         g_free (info->linearized);
248         g_free (info->security);
249         
250         g_free (info);
251 }
252
253
254 /* Compares two rects.  returns 0 if they're equal */
255 #define EPSILON 0.0000001
256
257 gint
258 ev_rect_cmp (EvRectangle *a,
259              EvRectangle *b)
260 {
261         if (a == b)
262                 return 0;
263         if (a == NULL || b == NULL)
264                 return 1;
265
266         return ! ((ABS (a->x1 - b->x1) < EPSILON) &&
267                   (ABS (a->y1 - b->y1) < EPSILON) &&
268                   (ABS (a->x2 - b->x2) < EPSILON) &&
269                   (ABS (a->y2 - b->y2) < EPSILON));
270 }
271
272
273