1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
3 * Copyright (C) 2009 Carlos Garcia Campos
4 * Copyright (C) 2000-2003 Marco Pesenti Gritti
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #if !defined (__EV_EVINCE_DOCUMENT_H_INSIDE__) && !defined (EVINCE_COMPILATION)
24 #error "Only <evince-document.h> can be included directly."
30 #include <glib-object.h>
35 #include "ev-document-info.h"
37 #include "ev-render-context.h"
41 #define EV_TYPE_DOCUMENT (ev_document_get_type ())
42 #define EV_DOCUMENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EV_TYPE_DOCUMENT, EvDocument))
43 #define EV_DOCUMENT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EV_TYPE_DOCUMENT, EvDocumentClass))
44 #define EV_IS_DOCUMENT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EV_TYPE_DOCUMENT))
45 #define EV_IS_DOCUMENT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EV_TYPE_DOCUMENT))
46 #define EV_DOCUMENT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), EV_TYPE_DOCUMENT, EvDocumentClass))
48 typedef struct _EvDocument EvDocument;
49 typedef struct _EvDocumentClass EvDocumentClass;
50 typedef struct _EvPageCache EvPageCache;
51 typedef struct _EvPageCacheClass EvPageCacheClass;
53 #define EV_DOCUMENT_ERROR ev_document_error_quark ()
54 #define EV_DOC_MUTEX_LOCK (ev_document_doc_mutex_lock ())
55 #define EV_DOC_MUTEX_UNLOCK (ev_document_doc_mutex_unlock ())
59 EV_DOCUMENT_ERROR_INVALID,
60 EV_DOCUMENT_ERROR_ENCRYPTED
68 typedef struct _EvRectangle EvRectangle;
75 struct _EvDocumentClass
77 GObjectClass base_class;
80 gboolean (* load) (EvDocument *document,
83 gboolean (* save) (EvDocument *document,
86 gint (* get_n_pages) (EvDocument *document);
87 EvPage * (* get_page) (EvDocument *document,
89 void (* get_page_size) (EvDocument *document,
93 gchar * (* get_page_label) (EvDocument *document,
95 cairo_surface_t * (* render) (EvDocument *document,
97 EvDocumentInfo * (* get_info) (EvDocument *document);
100 GType ev_document_get_type (void) G_GNUC_CONST;
101 GQuark ev_document_error_quark (void);
104 GMutex *ev_document_get_doc_mutex (void);
105 void ev_document_doc_mutex_lock (void);
106 void ev_document_doc_mutex_unlock (void);
107 gboolean ev_document_doc_mutex_trylock(void);
109 /* FontConfig mutex */
110 GMutex *ev_document_get_fc_mutex (void);
111 void ev_document_fc_mutex_lock (void);
112 void ev_document_fc_mutex_unlock (void);
113 gboolean ev_document_fc_mutex_trylock (void);
115 EvDocumentInfo *ev_document_get_info (EvDocument *document);
116 gboolean ev_document_load (EvDocument *document,
119 gboolean ev_document_save (EvDocument *document,
122 gint ev_document_get_n_pages (EvDocument *document);
123 EvPage *ev_document_get_page (EvDocument *document,
125 void ev_document_get_page_size (EvDocument *document,
129 gchar *ev_document_get_page_label (EvDocument *document,
131 cairo_surface_t *ev_document_render (EvDocument *document,
132 EvRenderContext *rc);
134 gint ev_rect_cmp (EvRectangle *a,
137 #define EV_TYPE_RECTANGLE (ev_rectangle_get_type ())
146 GType ev_rectangle_get_type (void) G_GNUC_CONST;
147 EvRectangle *ev_rectangle_new (void);
148 EvRectangle *ev_rectangle_copy (EvRectangle *ev_rect);
149 void ev_rectangle_free (EvRectangle *ev_rect);
151 /* convenience macro to ease interface addition in the CODE
152 * section of EV_BACKEND_REGISTER_WITH_CODE (this macro relies on
153 * the g_define_type_id present within EV_BACKEND_REGISTER_WITH_CODE()).
155 * EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
156 * EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
157 * pdf_document_document_thumbnails_iface_init));
159 #define EV_BACKEND_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) { \
160 const GInterfaceInfo g_implement_interface_info = { \
161 (GInterfaceInitFunc) iface_init, NULL, NULL \
163 g_type_module_add_interface (module, \
166 &g_implement_interface_info); \
170 * Utility macro used to register backends
172 * use: EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE)
174 #define EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE) \
176 static GType g_define_type_id = 0; \
179 backend_name##_get_type (void) \
181 return g_define_type_id; \
184 static void backend_name##_init (BackendName *self); \
185 static void backend_name##_class_init (BackendName##Class *klass); \
186 static gpointer backend_name##_parent_class = NULL; \
187 static void backend_name##_class_intern_init (gpointer klass) \
189 backend_name##_parent_class = g_type_class_peek_parent (klass); \
190 backend_name##_class_init ((BackendName##Class *) klass); \
193 G_MODULE_EXPORT GType \
194 register_evince_backend (GTypeModule *module) \
196 const GTypeInfo our_info = { \
197 sizeof (BackendName##Class), \
198 NULL, /* base_init */ \
199 NULL, /* base_finalize */ \
200 (GClassInitFunc) backend_name##_class_intern_init, \
202 NULL, /* class_data */ \
203 sizeof (BackendName), \
204 0, /* n_preallocs */ \
205 (GInstanceInitFunc) backend_name##_init \
208 /* Initialise the i18n stuff */ \
209 bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); \
210 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); \
212 g_define_type_id = g_type_module_register_type (module, \
220 return g_define_type_id; \
224 * Utility macro used to register backend
226 * use: EV_BACKEND_REGISTER(BackendName, backend_name)
228 #define EV_BACKEND_REGISTER(BackendName, backend_name) \
229 EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, ;)
232 * A convenience macro for boxed type implementations, which defines a
233 * type_name_get_type() function registering the boxed type.
235 #define EV_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func) \
237 type_name##_get_type (void) \
239 static volatile gsize g_define_type_id__volatile = 0; \
240 if (g_once_init_enter (&g_define_type_id__volatile)) { \
241 GType g_define_type_id = \
242 g_boxed_type_register_static (g_intern_static_string (#TypeName), \
243 (GBoxedCopyFunc) copy_func, \
244 (GBoxedFreeFunc) free_func); \
245 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
247 return g_define_type_id__volatile; \
250 /* A convenience macro for GTypeInterface definitions, which declares
251 * a default vtable initialization function and defines a *_get_type()
254 * The macro expects the interface initialization function to have the
255 * name <literal>t_n ## _default_init</literal>, and the interface
256 * structure to have the name <literal>TN ## Interface</literal>.
258 #define EV_DEFINE_INTERFACE(TypeName, type_name, TYPE_PREREQ) \
259 static void type_name##_class_init (TypeName##Iface *klass); \
262 type_name##_get_type (void) \
264 static volatile gsize g_define_type_id__volatile = 0; \
265 if (g_once_init_enter (&g_define_type_id__volatile)) { \
266 GType g_define_type_id = \
267 g_type_register_static_simple (G_TYPE_INTERFACE, \
268 g_intern_static_string (#TypeName), \
269 sizeof (TypeName##Iface), \
270 (GClassInitFunc)type_name##_class_init, \
272 (GInstanceInitFunc)NULL, \
275 g_type_interface_add_prerequisite (g_define_type_id, TYPE_PREREQ); \
276 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
278 return g_define_type_id__volatile; \
282 * A convenience macro for boxed type implementations, which defines a
283 * type_name_get_type() function registering the boxed type.
285 #define EV_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func) \
287 type_name##_get_type (void) \
289 static volatile gsize g_define_type_id__volatile = 0; \
290 if (g_once_init_enter (&g_define_type_id__volatile)) { \
291 GType g_define_type_id = \
292 g_boxed_type_register_static (g_intern_static_string (#TypeName), \
293 (GBoxedCopyFunc) copy_func, \
294 (GBoxedFreeFunc) free_func); \
295 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
297 return g_define_type_id__volatile; \
302 #endif /* EV_DOCUMENT_H */