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 #include "ev-backend-marshalers.h"
27 static void ev_document_class_init (gpointer g_class);
30 GMutex *ev_doc_mutex = NULL;
34 ev_document_get_type (void)
36 static GType type = 0;
38 if (G_UNLIKELY (type == 0))
40 const GTypeInfo our_info =
42 sizeof (EvDocumentIface),
45 (GClassInitFunc)ev_document_class_init
48 type = g_type_register_static (G_TYPE_INTERFACE,
50 &our_info, (GTypeFlags)0);
57 ev_document_error_quark (void)
61 q = g_quark_from_static_string ("ev-document-error-quark");
67 ev_document_class_init (gpointer g_class)
72 ev_document_get_doc_mutex (void)
74 if (ev_doc_mutex == NULL) {
75 ev_doc_mutex = g_mutex_new ();
81 ev_document_doc_mutex_lock (void)
83 g_mutex_lock (ev_document_get_doc_mutex ());
87 ev_document_doc_mutex_unlock (void)
89 g_mutex_unlock (ev_document_get_doc_mutex ());
95 ev_document_load (EvDocument *document,
99 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
101 LOG ("ev_document_load");
102 retval = iface->load (document, uri, error);
108 ev_document_save (EvDocument *document,
112 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
115 LOG ("ev_document_save");
116 retval = iface->save (document, uri, error);
122 ev_document_get_n_pages (EvDocument *document)
124 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
127 LOG ("ev_document_get_n_pages");
128 retval = iface->get_n_pages (document);
134 ev_document_get_page_size (EvDocument *document,
139 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
141 LOG ("ev_document_get_page_size");
142 iface->get_page_size (document, page, width, height);
146 ev_document_get_page_label(EvDocument *document,
149 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
151 LOG ("ev_document_get_page_label");
152 if (iface->get_page_label == NULL)
155 return iface->get_page_label (document, page);
159 ev_document_can_get_text (EvDocument *document)
161 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
163 return iface->can_get_text (document);
167 ev_document_get_info (EvDocument *document)
169 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
171 return iface->get_info (document);
175 ev_document_get_text (EvDocument *document,
179 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
182 LOG ("ev_document_get_text");
183 retval = iface->get_text (document, page, rect);
189 ev_document_has_attachments (EvDocument *document)
191 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
193 if (iface->has_attachments == NULL)
196 return iface->has_attachments (document);
200 ev_document_get_attachments (EvDocument *document)
202 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
205 LOG ("ev_document_get_attachments");
206 if (iface->get_attachments == NULL)
208 retval = iface->get_attachments (document);
214 ev_document_render_pixbuf (EvDocument *document,
217 EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
220 LOG ("ev_document_render_pixbuf");
221 g_assert (iface->render_pixbuf);
223 retval = iface->render_pixbuf (document, rc);
229 ev_document_info_free (EvDocumentInfo *info)
234 g_free (info->title);
235 g_free (info->format);
236 g_free (info->author);
237 g_free (info->subject);
238 g_free (info->keywords);
239 g_free (info->security);
245 /* Compares two rects. returns 0 if they're equal */
246 #define EPSILON 0.0000001
249 ev_rect_cmp (EvRectangle *a,
254 if (a == NULL || b == NULL)
257 return ! ((ABS (a->x1 - b->x1) < EPSILON) &&
258 (ABS (a->y1 - b->y1) < EPSILON) &&
259 (ABS (a->x2 - b->x2) < EPSILON) &&
260 (ABS (a->y2 - b->y2) < EPSILON));