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 _EvDocumentPrivate EvDocumentPrivate;
52 typedef struct _EvPageCache EvPageCache;
53 typedef struct _EvPageCacheClass EvPageCacheClass;
55 #define EV_DOCUMENT_ERROR ev_document_error_quark ()
56 #define EV_DOC_MUTEX_LOCK (ev_document_doc_mutex_lock ())
57 #define EV_DOC_MUTEX_UNLOCK (ev_document_doc_mutex_unlock ())
61 EV_DOCUMENT_ERROR_INVALID,
62 EV_DOCUMENT_ERROR_ENCRYPTED
70 typedef struct _EvRectangle EvRectangle;
76 EvDocumentPrivate *priv;
79 struct _EvDocumentClass
81 GObjectClass base_class;
84 gboolean (* load) (EvDocument *document,
87 gboolean (* save) (EvDocument *document,
90 gint (* get_n_pages) (EvDocument *document);
91 EvPage * (* get_page) (EvDocument *document,
93 void (* get_page_size) (EvDocument *document,
97 gchar * (* get_page_label) (EvDocument *document,
99 cairo_surface_t * (* render) (EvDocument *document,
100 EvRenderContext *rc);
101 EvDocumentInfo * (* get_info) (EvDocument *document);
104 GType ev_document_get_type (void) G_GNUC_CONST;
105 GQuark ev_document_error_quark (void);
108 GMutex *ev_document_get_doc_mutex (void);
109 void ev_document_doc_mutex_lock (void);
110 void ev_document_doc_mutex_unlock (void);
111 gboolean ev_document_doc_mutex_trylock (void);
113 /* FontConfig mutex */
114 GMutex *ev_document_get_fc_mutex (void);
115 void ev_document_fc_mutex_lock (void);
116 void ev_document_fc_mutex_unlock (void);
117 gboolean ev_document_fc_mutex_trylock (void);
119 EvDocumentInfo *ev_document_get_info (EvDocument *document);
120 gboolean ev_document_load (EvDocument *document,
123 gboolean ev_document_save (EvDocument *document,
126 gint ev_document_get_n_pages (EvDocument *document);
127 EvPage *ev_document_get_page (EvDocument *document,
129 void ev_document_get_page_size (EvDocument *document,
133 gchar *ev_document_get_page_label (EvDocument *document,
135 cairo_surface_t *ev_document_render (EvDocument *document,
136 EvRenderContext *rc);
137 const gchar *ev_document_get_title (EvDocument *document);
138 gboolean ev_document_is_page_size_uniform (EvDocument *document);
139 void ev_document_get_max_page_size (EvDocument *document,
142 gboolean ev_document_check_dimensions (EvDocument *document);
143 gint ev_document_get_max_label_len (EvDocument *document);
144 gboolean ev_document_has_text_page_labels (EvDocument *document);
145 gboolean ev_document_find_page_by_label (EvDocument *document,
146 const gchar *page_label,
149 gint ev_rect_cmp (EvRectangle *a,
152 #define EV_TYPE_RECTANGLE (ev_rectangle_get_type ())
161 GType ev_rectangle_get_type (void) G_GNUC_CONST;
162 EvRectangle *ev_rectangle_new (void);
163 EvRectangle *ev_rectangle_copy (EvRectangle *ev_rect);
164 void ev_rectangle_free (EvRectangle *ev_rect);
166 /* convenience macro to ease interface addition in the CODE
167 * section of EV_BACKEND_REGISTER_WITH_CODE (this macro relies on
168 * the g_define_type_id present within EV_BACKEND_REGISTER_WITH_CODE()).
170 * EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
171 * EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
172 * pdf_document_document_thumbnails_iface_init));
174 #define EV_BACKEND_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) { \
175 const GInterfaceInfo g_implement_interface_info = { \
176 (GInterfaceInitFunc) iface_init, NULL, NULL \
178 g_type_module_add_interface (module, \
181 &g_implement_interface_info); \
185 * Utility macro used to register backends
187 * use: EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE)
189 #define EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE) \
191 static GType g_define_type_id = 0; \
194 backend_name##_get_type (void) \
196 return g_define_type_id; \
199 static void backend_name##_init (BackendName *self); \
200 static void backend_name##_class_init (BackendName##Class *klass); \
201 static gpointer backend_name##_parent_class = NULL; \
202 static void backend_name##_class_intern_init (gpointer klass) \
204 backend_name##_parent_class = g_type_class_peek_parent (klass); \
205 backend_name##_class_init ((BackendName##Class *) klass); \
208 G_MODULE_EXPORT GType \
209 register_evince_backend (GTypeModule *module) \
211 const GTypeInfo our_info = { \
212 sizeof (BackendName##Class), \
213 NULL, /* base_init */ \
214 NULL, /* base_finalize */ \
215 (GClassInitFunc) backend_name##_class_intern_init, \
217 NULL, /* class_data */ \
218 sizeof (BackendName), \
219 0, /* n_preallocs */ \
220 (GInstanceInitFunc) backend_name##_init \
223 /* Initialise the i18n stuff */ \
224 bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); \
225 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); \
227 g_define_type_id = g_type_module_register_type (module, \
235 return g_define_type_id; \
239 * Utility macro used to register backend
241 * use: EV_BACKEND_REGISTER(BackendName, backend_name)
243 #define EV_BACKEND_REGISTER(BackendName, backend_name) \
244 EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, ;)
247 * A convenience macro for boxed type implementations, which defines a
248 * type_name_get_type() function registering the boxed type.
250 #define EV_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func) \
252 type_name##_get_type (void) \
254 static volatile gsize g_define_type_id__volatile = 0; \
255 if (g_once_init_enter (&g_define_type_id__volatile)) { \
256 GType g_define_type_id = \
257 g_boxed_type_register_static (g_intern_static_string (#TypeName), \
258 (GBoxedCopyFunc) copy_func, \
259 (GBoxedFreeFunc) free_func); \
260 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
262 return g_define_type_id__volatile; \
265 /* A convenience macro for GTypeInterface definitions, which declares
266 * a default vtable initialization function and defines a *_get_type()
269 * The macro expects the interface initialization function to have the
270 * name <literal>t_n ## _default_init</literal>, and the interface
271 * structure to have the name <literal>TN ## Interface</literal>.
273 #define EV_DEFINE_INTERFACE(TypeName, type_name, TYPE_PREREQ) \
274 static void type_name##_class_init (TypeName##Iface *klass); \
277 type_name##_get_type (void) \
279 static volatile gsize g_define_type_id__volatile = 0; \
280 if (g_once_init_enter (&g_define_type_id__volatile)) { \
281 GType g_define_type_id = \
282 g_type_register_static_simple (G_TYPE_INTERFACE, \
283 g_intern_static_string (#TypeName), \
284 sizeof (TypeName##Iface), \
285 (GClassInitFunc)type_name##_class_init, \
287 (GInstanceInitFunc)NULL, \
290 g_type_interface_add_prerequisite (g_define_type_id, TYPE_PREREQ); \
291 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
293 return g_define_type_id__volatile; \
297 * A convenience macro for boxed type implementations, which defines a
298 * type_name_get_type() function registering the boxed type.
300 #define EV_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func) \
302 type_name##_get_type (void) \
304 static volatile gsize g_define_type_id__volatile = 0; \
305 if (g_once_init_enter (&g_define_type_id__volatile)) { \
306 GType g_define_type_id = \
307 g_boxed_type_register_static (g_intern_static_string (#TypeName), \
308 (GBoxedCopyFunc) copy_func, \
309 (GBoxedFreeFunc) free_func); \
310 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
312 return g_define_type_id__volatile; \
317 #endif /* EV_DOCUMENT_H */