]> www.fi.muni.cz Git - evince.git/blob - libdocument/ev-document.h
Remove unneeded GLIB_CHECK_VERSION macros
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 typedef struct _EvDocumentBackendInfo EvDocumentBackendInfo;
70 struct _EvDocumentBackendInfo
71 {
72         const gchar *name;
73         const gchar *version;
74 };
75
76 struct _EvDocument
77 {
78         GObject base;
79
80         EvDocumentPrivate *priv;
81 };
82
83 struct _EvDocumentClass
84 {
85         GObjectClass base_class;
86
87         /* Virtual Methods  */
88         gboolean          (* load)            (EvDocument      *document,
89                                                const char      *uri,
90                                                GError         **error);
91         gboolean          (* save)            (EvDocument      *document,
92                                                const char      *uri,
93                                                GError         **error);
94         gint              (* get_n_pages)     (EvDocument      *document);
95         EvPage          * (* get_page)        (EvDocument      *document,
96                                                gint             index);
97         void              (* get_page_size)   (EvDocument      *document,
98                                                EvPage          *page,
99                                                double          *width,
100                                                double          *height);
101         gchar           * (* get_page_label)  (EvDocument      *document,
102                                                EvPage          *page);
103         cairo_surface_t * (* render)          (EvDocument      *document,
104                                                EvRenderContext *rc);
105         EvDocumentInfo  * (* get_info)        (EvDocument      *document);
106         gboolean          (* get_backend_info)(EvDocument      *document,
107                                                EvDocumentBackendInfo *info);
108 };
109
110 GType            ev_document_get_type             (void) G_GNUC_CONST;
111 GQuark           ev_document_error_quark          (void);
112
113 /* Document mutex */
114 GMutex          *ev_document_get_doc_mutex        (void);
115 void             ev_document_doc_mutex_lock       (void);
116 void             ev_document_doc_mutex_unlock     (void);
117 gboolean         ev_document_doc_mutex_trylock    (void);
118
119 /* FontConfig mutex */
120 GMutex          *ev_document_get_fc_mutex         (void);
121 void             ev_document_fc_mutex_lock        (void);
122 void             ev_document_fc_mutex_unlock      (void);
123 gboolean         ev_document_fc_mutex_trylock     (void);
124
125 EvDocumentInfo  *ev_document_get_info             (EvDocument      *document);
126 gboolean         ev_document_get_backend_info     (EvDocument      *document,
127                                                    EvDocumentBackendInfo *info);
128 gboolean         ev_document_load                 (EvDocument      *document,
129                                                    const char      *uri,
130                                                    GError         **error);
131 gboolean         ev_document_save                 (EvDocument      *document,
132                                                    const char      *uri,
133                                                    GError         **error);
134 gint             ev_document_get_n_pages          (EvDocument      *document);
135 EvPage          *ev_document_get_page             (EvDocument      *document,
136                                                    gint             index);
137 void             ev_document_get_page_size        (EvDocument      *document,
138                                                    gint             page_index,
139                                                    double          *width,
140                                                    double          *height);
141 gchar           *ev_document_get_page_label       (EvDocument      *document,
142                                                    gint             page_index);
143 cairo_surface_t *ev_document_render               (EvDocument      *document,
144                                                    EvRenderContext *rc);
145 const gchar     *ev_document_get_uri              (EvDocument      *document);
146 const gchar     *ev_document_get_title            (EvDocument      *document);
147 gboolean         ev_document_is_page_size_uniform (EvDocument      *document);
148 void             ev_document_get_max_page_size    (EvDocument      *document,
149                                                    gdouble         *width,
150                                                    gdouble         *height);
151 gboolean         ev_document_check_dimensions     (EvDocument      *document);
152 gint             ev_document_get_max_label_len    (EvDocument      *document);
153 gboolean         ev_document_has_text_page_labels (EvDocument      *document);
154 gboolean         ev_document_find_page_by_label   (EvDocument      *document,
155                                                    const gchar     *page_label,
156                                                    gint            *page_index);
157
158 gint             ev_rect_cmp                      (EvRectangle     *a,
159                                                    EvRectangle     *b);
160
161 #define EV_TYPE_RECTANGLE (ev_rectangle_get_type ())
162 struct _EvRectangle
163 {
164         gdouble x1;
165         gdouble y1;
166         gdouble x2;
167         gdouble y2;
168 };
169
170 GType        ev_rectangle_get_type (void) G_GNUC_CONST;
171 EvRectangle *ev_rectangle_new      (void);
172 EvRectangle *ev_rectangle_copy     (EvRectangle *ev_rect);
173 void         ev_rectangle_free     (EvRectangle *ev_rect);
174
175 /* convenience macro to ease interface addition in the CODE
176  * section of EV_BACKEND_REGISTER_WITH_CODE (this macro relies on
177  * the g_define_type_id present within EV_BACKEND_REGISTER_WITH_CODE()).
178  * usage example:
179  * EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
180  *                          EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
181  *                                                 pdf_document_document_thumbnails_iface_init));
182  */
183 #define EV_BACKEND_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) {                \
184         const GInterfaceInfo g_implement_interface_info = {                     \
185                 (GInterfaceInitFunc) iface_init, NULL, NULL                     \
186         };                                                                      \
187         g_type_module_add_interface (module,                                    \
188                                      g_define_type_id,                          \
189                                      TYPE_IFACE,                                \
190                                      &g_implement_interface_info);              \
191 }
192
193 /*
194  * Utility macro used to register backends
195  *
196  * use: EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE)
197  */
198 #define EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE)          \
199                                                                                 \
200 static GType g_define_type_id = 0;                                              \
201                                                                                 \
202 GType                                                                           \
203 backend_name##_get_type (void)                                                  \
204 {                                                                               \
205         return g_define_type_id;                                                \
206 }                                                                               \
207                                                                                 \
208 static void     backend_name##_init              (BackendName        *self);    \
209 static void     backend_name##_class_init        (BackendName##Class *klass);   \
210 static gpointer backend_name##_parent_class = NULL;                             \
211 static void     backend_name##_class_intern_init (gpointer klass)               \
212 {                                                                               \
213         backend_name##_parent_class = g_type_class_peek_parent (klass);         \
214         backend_name##_class_init ((BackendName##Class *) klass);               \
215 }                                                                               \
216                                                                                 \
217 G_MODULE_EXPORT GType                                                           \
218 register_evince_backend (GTypeModule *module)                                   \
219 {                                                                               \
220         const GTypeInfo our_info = {                                            \
221                 sizeof (BackendName##Class),                                    \
222                 NULL, /* base_init */                                           \
223                 NULL, /* base_finalize */                                       \
224                 (GClassInitFunc) backend_name##_class_intern_init,              \
225                 NULL,                                                           \
226                 NULL, /* class_data */                                          \
227                 sizeof (BackendName),                                           \
228                 0, /* n_preallocs */                                            \
229                 (GInstanceInitFunc) backend_name##_init                         \
230         };                                                                      \
231                                                                                 \
232         /* Initialise the i18n stuff */                                         \
233         bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);                       \
234         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");                     \
235                                                                                 \
236         g_define_type_id = g_type_module_register_type (module,                 \
237                                                         EV_TYPE_DOCUMENT,       \
238                                                         #BackendName,           \
239                                                         &our_info,              \
240                                                         (GTypeFlags)0);         \
241                                                                                 \
242         CODE                                                                    \
243                                                                                 \
244         return g_define_type_id;                                                \
245 }
246
247 /*
248  * Utility macro used to register backend
249  *
250  * use: EV_BACKEND_REGISTER(BackendName, backend_name)
251  */
252 #define EV_BACKEND_REGISTER(BackendName, backend_name)                  \
253         EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, ;)
254
255 /*
256  * A convenience macro for boxed type implementations, which defines a
257  * type_name_get_type() function registering the boxed type.
258  */
259 #define EV_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func)               \
260 GType                                                                                 \
261 type_name##_get_type (void)                                                           \
262 {                                                                                     \
263         static volatile gsize g_define_type_id__volatile = 0;                         \
264         if (g_once_init_enter (&g_define_type_id__volatile)) {                        \
265                 GType g_define_type_id =                                              \
266                     g_boxed_type_register_static (g_intern_static_string (#TypeName), \
267                                                   (GBoxedCopyFunc) copy_func,         \
268                                                   (GBoxedFreeFunc) free_func);        \
269                 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);    \
270         }                                                                             \
271         return g_define_type_id__volatile;                                            \
272 }
273
274 /* A convenience macro for GTypeInterface definitions, which declares
275  * a default vtable initialization function and defines a *_get_type()
276  * function.
277  *
278  * The macro expects the interface initialization function to have the
279  * name <literal>t_n ## _default_init</literal>, and the interface
280  * structure to have the name <literal>TN ## Interface</literal>.
281  */
282 #define EV_DEFINE_INTERFACE(TypeName, type_name, TYPE_PREREQ)                                \
283 static void     type_name##_class_init        (TypeName##Iface *klass);                      \
284                                                                                              \
285 GType                                                                                        \
286 type_name##_get_type (void)                                                                  \
287 {                                                                                            \
288         static volatile gsize g_define_type_id__volatile = 0;                                \
289         if (g_once_init_enter (&g_define_type_id__volatile)) {                               \
290                 GType g_define_type_id =                                                     \
291                     g_type_register_static_simple (G_TYPE_INTERFACE,                         \
292                                                    g_intern_static_string (#TypeName),       \
293                                                    sizeof (TypeName##Iface),                 \
294                                                    (GClassInitFunc)type_name##_class_init,   \
295                                                    0,                                        \
296                                                    (GInstanceInitFunc)NULL,                  \
297                                                    (GTypeFlags) 0);                          \
298                 if (TYPE_PREREQ)                                                             \
299                         g_type_interface_add_prerequisite (g_define_type_id, TYPE_PREREQ);   \
300                 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);           \
301         }                                                                                    \
302         return g_define_type_id__volatile;                                                   \
303 }
304
305 /*
306  * A convenience macro for boxed type implementations, which defines a
307  * type_name_get_type() function registering the boxed type.
308  */
309 #define EV_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func)               \
310 GType                                                                                 \
311 type_name##_get_type (void)                                                           \
312 {                                                                                     \
313         static volatile gsize g_define_type_id__volatile = 0;                         \
314         if (g_once_init_enter (&g_define_type_id__volatile)) {                        \
315                 GType g_define_type_id =                                              \
316                     g_boxed_type_register_static (g_intern_static_string (#TypeName), \
317                                                   (GBoxedCopyFunc) copy_func,         \
318                                                   (GBoxedFreeFunc) free_func);        \
319                 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);    \
320         }                                                                             \
321         return g_define_type_id__volatile;                                            \
322 }
323                 
324 G_END_DECLS
325
326 #endif /* EV_DOCUMENT_H */