1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
3 * Copyright (C) 2000-2003 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.
22 #if !defined (__EV_EVINCE_DOCUMENT_H_INSIDE__) && !defined (EVINCE_COMPILATION)
23 #error "Only <evince-document.h> can be included directly."
29 #include <glib-object.h>
34 #include "ev-document-info.h"
36 #include "ev-render-context.h"
40 #define EV_TYPE_DOCUMENT (ev_document_get_type ())
41 #define EV_DOCUMENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EV_TYPE_DOCUMENT, EvDocument))
42 #define EV_DOCUMENT_IFACE(k) (G_TYPE_CHECK_CLASS_CAST((k), EV_TYPE_DOCUMENT, EvDocumentIface))
43 #define EV_IS_DOCUMENT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EV_TYPE_DOCUMENT))
44 #define EV_IS_DOCUMENT_IFACE(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EV_TYPE_DOCUMENT))
45 #define EV_DOCUMENT_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), EV_TYPE_DOCUMENT, EvDocumentIface))
47 typedef struct _EvDocument EvDocument;
48 typedef struct _EvDocumentIface EvDocumentIface;
49 typedef struct _EvPageCache EvPageCache;
50 typedef struct _EvPageCacheClass EvPageCacheClass;
52 #define EV_DOCUMENT_ERROR ev_document_error_quark ()
53 #define EV_DOC_MUTEX_LOCK (ev_document_doc_mutex_lock ())
54 #define EV_DOC_MUTEX_UNLOCK (ev_document_doc_mutex_unlock ())
58 EV_DOCUMENT_ERROR_INVALID,
59 EV_DOCUMENT_ERROR_ENCRYPTED
74 struct _EvDocumentIface
76 GTypeInterface base_iface;
79 gboolean (* load) (EvDocument *document,
82 gboolean (* save) (EvDocument *document,
85 int (* get_n_pages) (EvDocument *document);
86 EvPage * (* get_page) (EvDocument *document,
88 void (* get_page_size) (EvDocument *document,
92 char * (* get_page_label) (EvDocument *document,
94 gboolean (* has_attachments) (EvDocument *document);
95 GList * (* get_attachments) (EvDocument *document);
96 cairo_surface_t * (* render) (EvDocument *document,
98 EvDocumentInfo * (* get_info) (EvDocument *document);
101 GType ev_document_get_type (void) G_GNUC_CONST;
102 GQuark ev_document_error_quark (void);
105 GMutex *ev_document_get_doc_mutex (void);
106 void ev_document_doc_mutex_lock (void);
107 void ev_document_doc_mutex_unlock (void);
108 gboolean ev_document_doc_mutex_trylock(void);
110 /* FontConfig mutex */
111 GMutex *ev_document_get_fc_mutex (void);
112 void ev_document_fc_mutex_lock (void);
113 void ev_document_fc_mutex_unlock (void);
114 gboolean ev_document_fc_mutex_trylock (void);
116 EvDocumentInfo *ev_document_get_info (EvDocument *document);
117 gboolean ev_document_load (EvDocument *document,
120 gboolean ev_document_save (EvDocument *document,
123 int ev_document_get_n_pages (EvDocument *document);
124 EvPage *ev_document_get_page (EvDocument *document,
126 void ev_document_get_page_size (EvDocument *document,
130 char *ev_document_get_page_label (EvDocument *document,
132 gboolean ev_document_has_attachments (EvDocument *document);
133 GList *ev_document_get_attachments (EvDocument *document);
134 cairo_surface_t *ev_document_render (EvDocument *document,
135 EvRenderContext *rc);
137 gint ev_rect_cmp (EvRectangle *a,
140 /* convenience macro to ease interface addition in the CODE
141 * section of EV_BACKEND_REGISTER_WITH_CODE (this macro relies on
142 * the g_define_type_id present within EV_BACKEND_REGISTER_WITH_CODE()).
144 * EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
145 * EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
146 * pdf_document_document_thumbnails_iface_init));
148 #define EV_BACKEND_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) { \
149 const GInterfaceInfo g_implement_interface_info = { \
150 (GInterfaceInitFunc) iface_init, NULL, NULL \
152 g_type_module_add_interface (module, \
155 &g_implement_interface_info); \
159 * Utility macro used to register backends
161 * use: EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE)
163 #define EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE) \
165 static GType g_define_type_id = 0; \
168 backend_name##_get_type (void) \
170 return g_define_type_id; \
173 static void backend_name##_init (BackendName *self); \
174 static void backend_name##_class_init (BackendName##Class *klass); \
175 static gpointer backend_name##_parent_class = NULL; \
176 static void backend_name##_class_intern_init (gpointer klass) \
178 backend_name##_parent_class = g_type_class_peek_parent (klass); \
179 backend_name##_class_init ((BackendName##Class *) klass); \
182 G_MODULE_EXPORT GType \
183 register_evince_backend (GTypeModule *module) \
185 const GTypeInfo our_info = { \
186 sizeof (BackendName##Class), \
187 NULL, /* base_init */ \
188 NULL, /* base_finalize */ \
189 (GClassInitFunc) backend_name##_class_intern_init, \
191 NULL, /* class_data */ \
192 sizeof (BackendName), \
193 0, /* n_preallocs */ \
194 (GInstanceInitFunc) backend_name##_init \
197 /* Initialise the i18n stuff */ \
198 bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); \
199 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); \
201 g_define_type_id = g_type_module_register_type (module, \
207 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT, \
208 backend_name##_document_iface_init); \
212 return g_define_type_id; \
216 * Utility macro used to register backend
218 * use: EV_BACKEND_REGISTER(BackendName, backend_name)
220 #define EV_BACKEND_REGISTER(BackendName, backend_name) \
221 EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, ;)
224 * A convenience macro for boxed type implementations, which defines a
225 * type_name_get_type() function registering the boxed type.
227 #define EV_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func) \
229 type_name##_get_type (void) \
231 static volatile gsize g_define_type_id__volatile = 0; \
232 if (g_once_init_enter (&g_define_type_id__volatile)) { \
233 GType g_define_type_id = \
234 g_boxed_type_register_static (g_intern_static_string (#TypeName), \
235 (GBoxedCopyFunc) copy_func, \
236 (GBoxedFreeFunc) free_func); \
237 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
239 return g_define_type_id__volatile; \
242 /* A convenience macro for GTypeInterface definitions, which declares
243 * a default vtable initialization function and defines a *_get_type()
246 * The macro expects the interface initialization function to have the
247 * name <literal>t_n ## _default_init</literal>, and the interface
248 * structure to have the name <literal>TN ## Interface</literal>.
250 #define EV_DEFINE_INTERFACE(TypeName, type_name, TYPE_PREREQ) \
251 static void type_name##_class_init (TypeName##Iface *klass); \
254 type_name##_get_type (void) \
256 static volatile gsize g_define_type_id__volatile = 0; \
257 if (g_once_init_enter (&g_define_type_id__volatile)) { \
258 GType g_define_type_id = \
259 g_type_register_static_simple (G_TYPE_INTERFACE, \
260 g_intern_static_string (#TypeName), \
261 sizeof (TypeName##Iface), \
262 (GClassInitFunc)type_name##_class_init, \
264 (GInstanceInitFunc)NULL, \
267 g_type_interface_add_prerequisite (g_define_type_id, TYPE_PREREQ); \
268 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
270 return g_define_type_id__volatile; \
275 #endif /* EV_DOCUMENT_H */