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
67 typedef struct _EvRectangle EvRectangle;
69 struct _EvDocumentIface
71 GTypeInterface base_iface;
74 gboolean (* load) (EvDocument *document,
77 gboolean (* save) (EvDocument *document,
80 int (* get_n_pages) (EvDocument *document);
81 EvPage * (* get_page) (EvDocument *document,
83 void (* get_page_size) (EvDocument *document,
87 char * (* get_page_label) (EvDocument *document,
89 gboolean (* has_attachments) (EvDocument *document);
90 GList * (* get_attachments) (EvDocument *document);
91 cairo_surface_t * (* render) (EvDocument *document,
93 EvDocumentInfo * (* get_info) (EvDocument *document);
96 GType ev_document_get_type (void) G_GNUC_CONST;
97 GQuark ev_document_error_quark (void);
100 GMutex *ev_document_get_doc_mutex (void);
101 void ev_document_doc_mutex_lock (void);
102 void ev_document_doc_mutex_unlock (void);
103 gboolean ev_document_doc_mutex_trylock(void);
105 /* FontConfig mutex */
106 GMutex *ev_document_get_fc_mutex (void);
107 void ev_document_fc_mutex_lock (void);
108 void ev_document_fc_mutex_unlock (void);
109 gboolean ev_document_fc_mutex_trylock (void);
111 EvDocumentInfo *ev_document_get_info (EvDocument *document);
112 gboolean ev_document_load (EvDocument *document,
115 gboolean ev_document_save (EvDocument *document,
118 int ev_document_get_n_pages (EvDocument *document);
119 EvPage *ev_document_get_page (EvDocument *document,
121 void ev_document_get_page_size (EvDocument *document,
125 char *ev_document_get_page_label (EvDocument *document,
127 gboolean ev_document_has_attachments (EvDocument *document);
128 GList *ev_document_get_attachments (EvDocument *document);
129 cairo_surface_t *ev_document_render (EvDocument *document,
130 EvRenderContext *rc);
132 gint ev_rect_cmp (EvRectangle *a,
135 #define EV_TYPE_RECTANGLE (ev_rectangle_get_type ())
144 GType ev_rectangle_get_type (void) G_GNUC_CONST;
145 EvRectangle *ev_rectangle_new (void);
146 EvRectangle *ev_rectangle_copy (EvRectangle *ev_rect);
147 void ev_rectangle_free (EvRectangle *ev_rect);
149 /* convenience macro to ease interface addition in the CODE
150 * section of EV_BACKEND_REGISTER_WITH_CODE (this macro relies on
151 * the g_define_type_id present within EV_BACKEND_REGISTER_WITH_CODE()).
153 * EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
154 * EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
155 * pdf_document_document_thumbnails_iface_init));
157 #define EV_BACKEND_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) { \
158 const GInterfaceInfo g_implement_interface_info = { \
159 (GInterfaceInitFunc) iface_init, NULL, NULL \
161 g_type_module_add_interface (module, \
164 &g_implement_interface_info); \
168 * Utility macro used to register backends
170 * use: EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE)
172 #define EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE) \
174 static GType g_define_type_id = 0; \
177 backend_name##_get_type (void) \
179 return g_define_type_id; \
182 static void backend_name##_init (BackendName *self); \
183 static void backend_name##_class_init (BackendName##Class *klass); \
184 static gpointer backend_name##_parent_class = NULL; \
185 static void backend_name##_class_intern_init (gpointer klass) \
187 backend_name##_parent_class = g_type_class_peek_parent (klass); \
188 backend_name##_class_init ((BackendName##Class *) klass); \
191 G_MODULE_EXPORT GType \
192 register_evince_backend (GTypeModule *module) \
194 const GTypeInfo our_info = { \
195 sizeof (BackendName##Class), \
196 NULL, /* base_init */ \
197 NULL, /* base_finalize */ \
198 (GClassInitFunc) backend_name##_class_intern_init, \
200 NULL, /* class_data */ \
201 sizeof (BackendName), \
202 0, /* n_preallocs */ \
203 (GInstanceInitFunc) backend_name##_init \
206 /* Initialise the i18n stuff */ \
207 bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); \
208 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); \
210 g_define_type_id = g_type_module_register_type (module, \
216 EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT, \
217 backend_name##_document_iface_init); \
221 return g_define_type_id; \
225 * Utility macro used to register backend
227 * use: EV_BACKEND_REGISTER(BackendName, backend_name)
229 #define EV_BACKEND_REGISTER(BackendName, backend_name) \
230 EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, ;)
233 * A convenience macro for boxed type implementations, which defines a
234 * type_name_get_type() function registering the boxed type.
236 #define EV_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func) \
238 type_name##_get_type (void) \
240 static volatile gsize g_define_type_id__volatile = 0; \
241 if (g_once_init_enter (&g_define_type_id__volatile)) { \
242 GType g_define_type_id = \
243 g_boxed_type_register_static (g_intern_static_string (#TypeName), \
244 (GBoxedCopyFunc) copy_func, \
245 (GBoxedFreeFunc) free_func); \
246 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
248 return g_define_type_id__volatile; \
251 /* A convenience macro for GTypeInterface definitions, which declares
252 * a default vtable initialization function and defines a *_get_type()
255 * The macro expects the interface initialization function to have the
256 * name <literal>t_n ## _default_init</literal>, and the interface
257 * structure to have the name <literal>TN ## Interface</literal>.
259 #define EV_DEFINE_INTERFACE(TypeName, type_name, TYPE_PREREQ) \
260 static void type_name##_class_init (TypeName##Iface *klass); \
263 type_name##_get_type (void) \
265 static volatile gsize g_define_type_id__volatile = 0; \
266 if (g_once_init_enter (&g_define_type_id__volatile)) { \
267 GType g_define_type_id = \
268 g_type_register_static_simple (G_TYPE_INTERFACE, \
269 g_intern_static_string (#TypeName), \
270 sizeof (TypeName##Iface), \
271 (GClassInitFunc)type_name##_class_init, \
273 (GInstanceInitFunc)NULL, \
276 g_type_interface_add_prerequisite (g_define_type_id, TYPE_PREREQ); \
277 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
279 return g_define_type_id__volatile; \
283 * A convenience macro for boxed type implementations, which defines a
284 * type_name_get_type() function registering the boxed type.
286 #define EV_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func) \
288 type_name##_get_type (void) \
290 static volatile gsize g_define_type_id__volatile = 0; \
291 if (g_once_init_enter (&g_define_type_id__volatile)) { \
292 GType g_define_type_id = \
293 g_boxed_type_register_static (g_intern_static_string (#TypeName), \
294 (GBoxedCopyFunc) copy_func, \
295 (GBoxedFreeFunc) free_func); \
296 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
298 return g_define_type_id__volatile; \
303 #endif /* EV_DOCUMENT_H */