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