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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 #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;
68 typedef struct _EvMapping EvMapping;
70 typedef struct _EvDocumentBackendInfo EvDocumentBackendInfo;
71 struct _EvDocumentBackendInfo
78 const gchar *filename;
87 EvDocumentPrivate *priv;
90 struct _EvDocumentClass
92 GObjectClass base_class;
95 gboolean (* load) (EvDocument *document,
98 gboolean (* save) (EvDocument *document,
101 gint (* get_n_pages) (EvDocument *document);
102 EvPage * (* get_page) (EvDocument *document,
104 void (* get_page_size) (EvDocument *document,
108 gchar * (* get_page_label) (EvDocument *document,
110 cairo_surface_t * (* render) (EvDocument *document,
111 EvRenderContext *rc);
112 GdkPixbuf * (* get_thumbnail) (EvDocument *document,
113 EvRenderContext *rc);
114 EvDocumentInfo * (* get_info) (EvDocument *document);
115 gboolean (* get_backend_info)(EvDocument *document,
116 EvDocumentBackendInfo *info);
117 gboolean (* support_synctex) (EvDocument *document);
120 GType ev_document_get_type (void) G_GNUC_CONST;
121 GQuark ev_document_error_quark (void);
124 GMutex *ev_document_get_doc_mutex (void);
125 void ev_document_doc_mutex_lock (void);
126 void ev_document_doc_mutex_unlock (void);
127 gboolean ev_document_doc_mutex_trylock (void);
129 /* FontConfig mutex */
130 GMutex *ev_document_get_fc_mutex (void);
131 void ev_document_fc_mutex_lock (void);
132 void ev_document_fc_mutex_unlock (void);
133 gboolean ev_document_fc_mutex_trylock (void);
135 EvDocumentInfo *ev_document_get_info (EvDocument *document);
136 gboolean ev_document_get_backend_info (EvDocument *document,
137 EvDocumentBackendInfo *info);
138 gboolean ev_document_load (EvDocument *document,
141 gboolean ev_document_save (EvDocument *document,
144 gint ev_document_get_n_pages (EvDocument *document);
145 EvPage *ev_document_get_page (EvDocument *document,
147 void ev_document_get_page_size (EvDocument *document,
151 gchar *ev_document_get_page_label (EvDocument *document,
153 cairo_surface_t *ev_document_render (EvDocument *document,
154 EvRenderContext *rc);
155 GdkPixbuf *ev_document_get_thumbnail (EvDocument *document,
156 EvRenderContext *rc);
157 const gchar *ev_document_get_uri (EvDocument *document);
158 const gchar *ev_document_get_title (EvDocument *document);
159 gboolean ev_document_is_page_size_uniform (EvDocument *document);
160 void ev_document_get_max_page_size (EvDocument *document,
163 void ev_document_get_min_page_size (EvDocument *document,
166 gboolean ev_document_check_dimensions (EvDocument *document);
167 gint ev_document_get_max_label_len (EvDocument *document);
168 gboolean ev_document_has_text_page_labels (EvDocument *document);
169 gboolean ev_document_find_page_by_label (EvDocument *document,
170 const gchar *page_label,
172 gboolean ev_document_has_synctex (EvDocument *document);
174 EvSourceLink *ev_document_synctex_backward_search
175 (EvDocument *document,
180 EvMapping *ev_document_synctex_forward_search
181 (EvDocument *document,
182 EvSourceLink *source_link);
184 gint ev_rect_cmp (EvRectangle *a,
187 #define EV_TYPE_RECTANGLE (ev_rectangle_get_type ())
196 GType ev_rectangle_get_type (void) G_GNUC_CONST;
197 EvRectangle *ev_rectangle_new (void);
198 EvRectangle *ev_rectangle_copy (EvRectangle *ev_rect);
199 void ev_rectangle_free (EvRectangle *ev_rect);
206 /* convenience macro to ease interface addition in the CODE
207 * section of EV_BACKEND_REGISTER_WITH_CODE (this macro relies on
208 * the g_define_type_id present within EV_BACKEND_REGISTER_WITH_CODE()).
210 * EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
211 * EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
212 * pdf_document_document_thumbnails_iface_init));
214 #define EV_BACKEND_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) { \
215 const GInterfaceInfo g_implement_interface_info = { \
216 (GInterfaceInitFunc) iface_init, NULL, NULL \
218 g_type_module_add_interface (module, \
221 &g_implement_interface_info); \
225 * Utility macro used to register backends
227 * use: EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE)
229 #define EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE) \
231 static GType g_define_type_id = 0; \
234 backend_name##_get_type (void) \
236 return g_define_type_id; \
239 static void backend_name##_init (BackendName *self); \
240 static void backend_name##_class_init (BackendName##Class *klass); \
241 static gpointer backend_name##_parent_class = NULL; \
242 static void backend_name##_class_intern_init (gpointer klass) \
244 backend_name##_parent_class = g_type_class_peek_parent (klass); \
245 backend_name##_class_init ((BackendName##Class *) klass); \
248 G_MODULE_EXPORT GType \
249 register_evince_backend (GTypeModule *module) \
251 const GTypeInfo our_info = { \
252 sizeof (BackendName##Class), \
253 NULL, /* base_init */ \
254 NULL, /* base_finalize */ \
255 (GClassInitFunc) backend_name##_class_intern_init, \
257 NULL, /* class_data */ \
258 sizeof (BackendName), \
259 0, /* n_preallocs */ \
260 (GInstanceInitFunc) backend_name##_init \
263 /* Initialise the i18n stuff */ \
264 bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); \
265 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); \
267 g_define_type_id = g_type_module_register_type (module, \
275 return g_define_type_id; \
279 * Utility macro used to register backend
281 * use: EV_BACKEND_REGISTER(BackendName, backend_name)
283 #define EV_BACKEND_REGISTER(BackendName, backend_name) \
284 EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, ;)
287 * A convenience macro for boxed type implementations, which defines a
288 * type_name_get_type() function registering the boxed type.
290 #define EV_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func) \
292 type_name##_get_type (void) \
294 static volatile gsize g_define_type_id__volatile = 0; \
295 if (g_once_init_enter (&g_define_type_id__volatile)) { \
296 GType g_define_type_id = \
297 g_boxed_type_register_static (g_intern_static_string (#TypeName), \
298 (GBoxedCopyFunc) copy_func, \
299 (GBoxedFreeFunc) free_func); \
300 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); \
302 return g_define_type_id__volatile; \
307 #endif /* EV_DOCUMENT_H */