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 ());
100 ev_document_load (EvDocument *document,
104 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
107 retval = iface->load (document, uri, error);
113 ev_document_save (EvDocument *document,
117 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
120 retval = iface->save (document, uri, error);
126 ev_document_get_n_pages (EvDocument *document)
128 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
131 retval = iface->get_n_pages (document);
137 ev_document_get_page (EvDocument *document,
140 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
144 retval = iface->get_page (document, index);
146 retval = ev_page_new (index);
152 ev_document_get_page_size (EvDocument *document,
157 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
159 iface->get_page_size (document, page, width, height);
163 ev_document_get_page_label (EvDocument *document,
166 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
168 if (iface->get_page_label == NULL)
171 return iface->get_page_label (document, page);
175 ev_document_get_info (EvDocument *document)
177 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
179 return iface->get_info (document);
183 ev_document_has_attachments (EvDocument *document)
185 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
187 if (iface->has_attachments == NULL)
190 return iface->has_attachments (document);
194 ev_document_get_attachments (EvDocument *document)
196 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
199 if (iface->get_attachments == NULL)
201 retval = iface->get_attachments (document);
207 ev_document_render (EvDocument *document,
210 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
211 cairo_surface_t *retval;
213 g_assert (iface->render);
215 retval = iface->render (document, rc);
221 EV_DEFINE_BOXED_TYPE (EvDocumentInfo, ev_document_info, ev_document_info_copy, ev_document_info_free)
224 ev_document_info_copy (EvDocumentInfo *info)
226 EvDocumentInfo *copy;
228 g_return_val_if_fail (info != NULL, NULL);
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;
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;
254 ev_document_info_free (EvDocumentInfo *info)
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);
273 /* Compares two rects. returns 0 if they're equal */
274 #define EPSILON 0.0000001
277 ev_rect_cmp (EvRectangle *a,
282 if (a == NULL || b == NULL)
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));