]> www.fi.muni.cz Git - evince.git/blob - libdocument/ev-document.h
89acbe67877f6b5db1a37f31495e8cad16b405f2
[evince.git] / libdocument / ev-document.h
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /*
3  *  Copyright (C) 2009 Carlos Garcia Campos
4  *  Copyright (C) 2000-2003 Marco Pesenti Gritti
5  *
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)
9  *  any later version.
10  *
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.
15  *
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.
19  *
20  *  $Id$
21  */
22
23 #if !defined (__EV_EVINCE_DOCUMENT_H_INSIDE__) && !defined (EVINCE_COMPILATION)
24 #error "Only <evince-document.h> can be included directly."
25 #endif
26
27 #ifndef EV_DOCUMENT_H
28 #define EV_DOCUMENT_H
29
30 #include <glib-object.h>
31 #include <glib.h>
32 #include <gdk/gdk.h>
33 #include <cairo.h>
34
35 #include "ev-document-info.h"
36 #include "ev-page.h"
37 #include "ev-render-context.h"
38
39 G_BEGIN_DECLS
40
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))
47
48 typedef struct _EvDocument        EvDocument;
49 typedef struct _EvDocumentClass   EvDocumentClass;
50 typedef struct _EvDocumentPrivate EvDocumentPrivate;
51
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 ())
55
56 typedef enum
57 {
58         EV_DOCUMENT_ERROR_INVALID,
59         EV_DOCUMENT_ERROR_ENCRYPTED
60 } EvDocumentError;
61
62 typedef struct {
63         double x;
64         double y;
65 } EvPoint;
66
67 typedef struct _EvRectangle EvRectangle;
68
69 struct _EvDocument
70 {
71         GObject base;
72
73         EvDocumentPrivate *priv;
74 };
75
76 struct _EvDocumentClass
77 {
78         GObjectClass base_class;
79
80         /* Virtual Methods  */
81         gboolean          (* load)            (EvDocument      *document,
82                                                const char      *uri,
83                                                GError         **error);
84         gboolean          (* save)            (EvDocument      *document,
85                                                const char      *uri,
86                                                GError         **error);
87         gint              (* get_n_pages)     (EvDocument      *document);
88         EvPage          * (* get_page)        (EvDocument      *document,
89                                                gint             index);
90         void              (* get_page_size)   (EvDocument      *document,
91                                                EvPage          *page,
92                                                double          *width,
93                                                double          *height);
94         gchar           * (* get_page_label)  (EvDocument      *document,
95                                                EvPage          *page);
96         cairo_surface_t * (* render)          (EvDocument      *document,
97                                                EvRenderContext *rc);
98         EvDocumentInfo  * (* get_info)        (EvDocument      *document);
99 };
100
101 GType            ev_document_get_type             (void) G_GNUC_CONST;
102 GQuark           ev_document_error_quark          (void);
103
104 /* Document mutex */
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);
109
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);
115
116 EvDocumentInfo  *ev_document_get_info             (EvDocument      *document);
117 gboolean         ev_document_load                 (EvDocument      *document,
118                                                    const char      *uri,
119                                                    GError         **error);
120 gboolean         ev_document_save                 (EvDocument      *document,
121                                                    const char      *uri,
122                                                    GError         **error);
123 gint             ev_document_get_n_pages          (EvDocument      *document);
124 EvPage          *ev_document_get_page             (EvDocument      *document,
125                                                    gint             index);
126 void             ev_document_get_page_size        (EvDocument      *document,
127                                                    gint             page_index,
128                                                    double          *width,
129                                                    double          *height);
130 gchar           *ev_document_get_page_label       (EvDocument      *document,
131                                                    gint             page_index);
132 cairo_surface_t *ev_document_render               (EvDocument      *document,
133                                                    EvRenderContext *rc);
134 const gchar     *ev_document_get_uri              (EvDocument      *document);
135 const gchar     *ev_document_get_title            (EvDocument      *document);
136 gboolean         ev_document_is_page_size_uniform (EvDocument      *document);
137 void             ev_document_get_max_page_size    (EvDocument      *document,
138                                                    gdouble         *width,
139                                                    gdouble         *height);
140 gboolean         ev_document_check_dimensions     (EvDocument      *document);
141 gint             ev_document_get_max_label_len    (EvDocument      *document);
142 gboolean         ev_document_has_text_page_labels (EvDocument      *document);
143 gboolean         ev_document_find_page_by_label   (EvDocument      *document,
144                                                    const gchar     *page_label,
145                                                    gint            *page_index);
146
147 gint             ev_rect_cmp                      (EvRectangle     *a,
148                                                    EvRectangle     *b);
149
150 #define EV_TYPE_RECTANGLE (ev_rectangle_get_type ())
151 struct _EvRectangle
152 {
153         gdouble x1;
154         gdouble y1;
155         gdouble x2;
156         gdouble y2;
157 };
158
159 GType        ev_rectangle_get_type (void) G_GNUC_CONST;
160 EvRectangle *ev_rectangle_new      (void);
161 EvRectangle *ev_rectangle_copy     (EvRectangle *ev_rect);
162 void         ev_rectangle_free     (EvRectangle *ev_rect);
163
164 /* convenience macro to ease interface addition in the CODE
165  * section of EV_BACKEND_REGISTER_WITH_CODE (this macro relies on
166  * the g_define_type_id present within EV_BACKEND_REGISTER_WITH_CODE()).
167  * usage example:
168  * EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
169  *                          EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
170  *                                                 pdf_document_document_thumbnails_iface_init));
171  */
172 #define EV_BACKEND_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) {                \
173         const GInterfaceInfo g_implement_interface_info = {                     \
174                 (GInterfaceInitFunc) iface_init, NULL, NULL                     \
175         };                                                                      \
176         g_type_module_add_interface (module,                                    \
177                                      g_define_type_id,                          \
178                                      TYPE_IFACE,                                \
179                                      &g_implement_interface_info);              \
180 }
181
182 /*
183  * Utility macro used to register backends
184  *
185  * use: EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE)
186  */
187 #define EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE)          \
188                                                                                 \
189 static GType g_define_type_id = 0;                                              \
190                                                                                 \
191 GType                                                                           \
192 backend_name##_get_type (void)                                                  \
193 {                                                                               \
194         return g_define_type_id;                                                \
195 }                                                                               \
196                                                                                 \
197 static void     backend_name##_init              (BackendName        *self);    \
198 static void     backend_name##_class_init        (BackendName##Class *klass);   \
199 static gpointer backend_name##_parent_class = NULL;                             \
200 static void     backend_name##_class_intern_init (gpointer klass)               \
201 {                                                                               \
202         backend_name##_parent_class = g_type_class_peek_parent (klass);         \
203         backend_name##_class_init ((BackendName##Class *) klass);               \
204 }                                                                               \
205                                                                                 \
206 G_MODULE_EXPORT GType                                                           \
207 register_evince_backend (GTypeModule *module)                                   \
208 {                                                                               \
209         const GTypeInfo our_info = {                                            \
210                 sizeof (BackendName##Class),                                    \
211                 NULL, /* base_init */                                           \
212                 NULL, /* base_finalize */                                       \
213                 (GClassInitFunc) backend_name##_class_intern_init,              \
214                 NULL,                                                           \
215                 NULL, /* class_data */                                          \
216                 sizeof (BackendName),                                           \
217                 0, /* n_preallocs */                                            \
218                 (GInstanceInitFunc) backend_name##_init                         \
219         };                                                                      \
220                                                                                 \
221         /* Initialise the i18n stuff */                                         \
222         bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);                       \
223         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");                     \
224                                                                                 \
225         g_define_type_id = g_type_module_register_type (module,                 \
226                                                         EV_TYPE_DOCUMENT,       \
227                                                         #BackendName,           \
228                                                         &our_info,              \
229                                                         (GTypeFlags)0);         \
230                                                                                 \
231         CODE                                                                    \
232                                                                                 \
233         return g_define_type_id;                                                \
234 }
235
236 /*
237  * Utility macro used to register backend
238  *
239  * use: EV_BACKEND_REGISTER(BackendName, backend_name)
240  */
241 #define EV_BACKEND_REGISTER(BackendName, backend_name)                  \
242         EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, ;)
243
244 /*
245  * A convenience macro for boxed type implementations, which defines a
246  * type_name_get_type() function registering the boxed type.
247  */
248 #define EV_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func)               \
249 GType                                                                                 \
250 type_name##_get_type (void)                                                           \
251 {                                                                                     \
252         static volatile gsize g_define_type_id__volatile = 0;                         \
253         if (g_once_init_enter (&g_define_type_id__volatile)) {                        \
254                 GType g_define_type_id =                                              \
255                     g_boxed_type_register_static (g_intern_static_string (#TypeName), \
256                                                   (GBoxedCopyFunc) copy_func,         \
257                                                   (GBoxedFreeFunc) free_func);        \
258                 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);    \
259         }                                                                             \
260         return g_define_type_id__volatile;                                            \
261 }
262
263 /* A convenience macro for GTypeInterface definitions, which declares
264  * a default vtable initialization function and defines a *_get_type()
265  * function.
266  *
267  * The macro expects the interface initialization function to have the
268  * name <literal>t_n ## _default_init</literal>, and the interface
269  * structure to have the name <literal>TN ## Interface</literal>.
270  */
271 #define EV_DEFINE_INTERFACE(TypeName, type_name, TYPE_PREREQ)                                \
272 static void     type_name##_class_init        (TypeName##Iface *klass);                      \
273                                                                                              \
274 GType                                                                                        \
275 type_name##_get_type (void)                                                                  \
276 {                                                                                            \
277         static volatile gsize g_define_type_id__volatile = 0;                                \
278         if (g_once_init_enter (&g_define_type_id__volatile)) {                               \
279                 GType g_define_type_id =                                                     \
280                     g_type_register_static_simple (G_TYPE_INTERFACE,                         \
281                                                    g_intern_static_string (#TypeName),       \
282                                                    sizeof (TypeName##Iface),                 \
283                                                    (GClassInitFunc)type_name##_class_init,   \
284                                                    0,                                        \
285                                                    (GInstanceInitFunc)NULL,                  \
286                                                    (GTypeFlags) 0);                          \
287                 if (TYPE_PREREQ)                                                             \
288                         g_type_interface_add_prerequisite (g_define_type_id, TYPE_PREREQ);   \
289                 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);           \
290         }                                                                                    \
291         return g_define_type_id__volatile;                                                   \
292 }
293
294 /*
295  * A convenience macro for boxed type implementations, which defines a
296  * type_name_get_type() function registering the boxed type.
297  */
298 #define EV_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func)               \
299 GType                                                                                 \
300 type_name##_get_type (void)                                                           \
301 {                                                                                     \
302         static volatile gsize g_define_type_id__volatile = 0;                         \
303         if (g_once_init_enter (&g_define_type_id__volatile)) {                        \
304                 GType g_define_type_id =                                              \
305                     g_boxed_type_register_static (g_intern_static_string (#TypeName), \
306                                                   (GBoxedCopyFunc) copy_func,         \
307                                                   (GBoxedFreeFunc) free_func);        \
308                 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);    \
309         }                                                                             \
310         return g_define_type_id__volatile;                                            \
311 }
312                 
313 G_END_DECLS
314
315 #endif /* EV_DOCUMENT_H */