1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
3 * Copyright (C) 2004 Marco Pesenti Gritti
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)
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.
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.
23 #include "ev-document.h"
25 GMutex *ev_doc_mutex = NULL;
26 GMutex *ev_fc_mutex = NULL;
28 EV_DEFINE_INTERFACE (EvDocument, ev_document, G_TYPE_OBJECT)
31 ev_document_error_quark (void)
35 q = g_quark_from_static_string ("ev-document-error-quark");
41 ev_document_class_init (EvDocumentIface *klass)
46 ev_document_get_doc_mutex (void)
48 if (ev_doc_mutex == NULL) {
49 ev_doc_mutex = g_mutex_new ();
55 ev_document_doc_mutex_lock (void)
57 g_mutex_lock (ev_document_get_doc_mutex ());
61 ev_document_doc_mutex_unlock (void)
63 g_mutex_unlock (ev_document_get_doc_mutex ());
67 ev_document_doc_mutex_trylock (void)
69 return g_mutex_trylock (ev_document_get_doc_mutex ());
73 ev_document_get_fc_mutex (void)
75 if (ev_fc_mutex == NULL) {
76 ev_fc_mutex = g_mutex_new ();
82 ev_document_fc_mutex_lock (void)
84 g_mutex_lock (ev_document_get_fc_mutex ());
88 ev_document_fc_mutex_unlock (void)
90 g_mutex_unlock (ev_document_get_fc_mutex ());
94 ev_document_fc_mutex_trylock (void)
96 return g_mutex_trylock (ev_document_get_fc_mutex ());
101 * @document: a #EvDocument
102 * @uri: the document's URI
103 * @error: a #GError location to store an error, or %NULL
105 * Loads @document from @uri.
106 * On failure, @error is filled in.
108 * Returns: %TRUE on success, or %FALSE on failure.
111 ev_document_load (EvDocument *document,
115 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
118 retval = iface->load (document, uri, error);
124 ev_document_save (EvDocument *document,
128 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
131 retval = iface->save (document, uri, error);
137 ev_document_get_n_pages (EvDocument *document)
139 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
142 retval = iface->get_n_pages (document);
148 ev_document_get_page (EvDocument *document,
151 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
155 retval = iface->get_page (document, index);
157 retval = ev_page_new (index);
163 ev_document_get_page_size (EvDocument *document,
168 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
170 iface->get_page_size (document, page, width, height);
174 ev_document_get_page_label (EvDocument *document,
177 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
179 if (iface->get_page_label == NULL)
182 return iface->get_page_label (document, page);
186 ev_document_get_info (EvDocument *document)
188 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
190 return iface->get_info (document);
194 ev_document_has_attachments (EvDocument *document)
196 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
198 if (iface->has_attachments == NULL)
201 return iface->has_attachments (document);
205 ev_document_get_attachments (EvDocument *document)
207 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
210 if (iface->get_attachments == NULL)
212 retval = iface->get_attachments (document);
218 ev_document_render (EvDocument *document,
221 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
222 cairo_surface_t *retval;
224 g_assert (iface->render);
226 retval = iface->render (document, rc);
232 EV_DEFINE_BOXED_TYPE (EvDocumentInfo, ev_document_info, ev_document_info_copy, ev_document_info_free)
235 ev_document_info_copy (EvDocumentInfo *info)
237 EvDocumentInfo *copy;
239 g_return_val_if_fail (info != NULL, NULL);
241 copy = g_new0 (EvDocumentInfo, 1);
242 copy->title = g_strdup (info->title);
243 copy->format = g_strdup (info->format);
244 copy->author = g_strdup (info->author);
245 copy->subject = g_strdup (info->subject);
246 copy->keywords = g_strdup (info->keywords);
247 copy->security = g_strdup (info->security);
248 copy->creator = g_strdup (info->creator);
249 copy->producer = g_strdup (info->producer);
250 copy->linearized = g_strdup (info->linearized);
252 copy->creation_date = info->creation_date;
253 copy->modified_date = info->modified_date;
254 copy->layout = info->layout;
255 copy->mode = info->mode;
256 copy->ui_hints = info->ui_hints;
257 copy->permissions = info->permissions;
258 copy->n_pages = info->n_pages;
259 copy->fields_mask = info->fields_mask;
265 ev_document_info_free (EvDocumentInfo *info)
270 g_free (info->title);
271 g_free (info->format);
272 g_free (info->author);
273 g_free (info->subject);
274 g_free (info->keywords);
275 g_free (info->creator);
276 g_free (info->producer);
277 g_free (info->linearized);
278 g_free (info->security);
284 /* Compares two rects. returns 0 if they're equal */
285 #define EPSILON 0.0000001
288 ev_rect_cmp (EvRectangle *a,
293 if (a == NULL || b == NULL)
296 return ! ((ABS (a->x1 - b->x1) < EPSILON) &&
297 (ABS (a->y1 - b->y1) < EPSILON) &&
298 (ABS (a->x2 - b->x2) < EPSILON) &&
299 (ABS (a->y2 - b->y2) < EPSILON));