]> www.fi.muni.cz Git - evince.git/blob - libdocument/ev-document.h
Remove attachments from EvDocument interface and use EvDocumentAttachments instead
[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) 2000-2003 Marco Pesenti Gritti
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  *  $Id$
20  */
21
22 #if !defined (__EV_EVINCE_DOCUMENT_H_INSIDE__) && !defined (EVINCE_COMPILATION)
23 #error "Only <evince-document.h> can be included directly."
24 #endif
25
26 #ifndef EV_DOCUMENT_H
27 #define EV_DOCUMENT_H
28
29 #include <glib-object.h>
30 #include <glib.h>
31 #include <gdk/gdk.h>
32 #include <cairo.h>
33
34 #include "ev-document-info.h"
35 #include "ev-page.h"
36 #include "ev-render-context.h"
37
38 G_BEGIN_DECLS
39
40 #define EV_TYPE_DOCUMENT            (ev_document_get_type ())
41 #define EV_DOCUMENT(o)              (G_TYPE_CHECK_INSTANCE_CAST ((o), EV_TYPE_DOCUMENT, EvDocument))
42 #define EV_DOCUMENT_IFACE(k)        (G_TYPE_CHECK_CLASS_CAST((k), EV_TYPE_DOCUMENT, EvDocumentIface))
43 #define EV_IS_DOCUMENT(o)           (G_TYPE_CHECK_INSTANCE_TYPE ((o), EV_TYPE_DOCUMENT))
44 #define EV_IS_DOCUMENT_IFACE(k)     (G_TYPE_CHECK_CLASS_TYPE ((k), EV_TYPE_DOCUMENT))
45 #define EV_DOCUMENT_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), EV_TYPE_DOCUMENT, EvDocumentIface))
46
47 typedef struct _EvDocument        EvDocument;
48 typedef struct _EvDocumentIface   EvDocumentIface;
49 typedef struct _EvPageCache       EvPageCache;
50 typedef struct _EvPageCacheClass  EvPageCacheClass;
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 _EvDocumentIface
70 {
71         GTypeInterface base_iface;
72
73         /* Methods  */
74         gboolean          (* load)            (EvDocument      *document,
75                                                const char      *uri,
76                                                GError         **error);
77         gboolean          (* save)            (EvDocument      *document,
78                                                const char      *uri,
79                                                GError         **error);
80         int               (* get_n_pages)     (EvDocument      *document);
81         EvPage          * (* get_page)        (EvDocument      *document,
82                                                gint             index);
83         void              (* get_page_size)   (EvDocument      *document,
84                                                EvPage          *page,
85                                                double          *width,
86                                                double          *height);
87         char            * (* get_page_label)  (EvDocument      *document,
88                                                EvPage          *page);
89         cairo_surface_t * (* render)          (EvDocument      *document,
90                                                EvRenderContext *rc);
91         EvDocumentInfo *  (* get_info)        (EvDocument      *document);
92 };
93
94 GType            ev_document_get_type         (void) G_GNUC_CONST;
95 GQuark           ev_document_error_quark      (void);
96
97 /* Document mutex */
98 GMutex          *ev_document_get_doc_mutex    (void);
99 void             ev_document_doc_mutex_lock   (void);
100 void             ev_document_doc_mutex_unlock (void);
101 gboolean         ev_document_doc_mutex_trylock(void);
102
103 /* FontConfig mutex */
104 GMutex          *ev_document_get_fc_mutex     (void);
105 void             ev_document_fc_mutex_lock    (void);
106 void             ev_document_fc_mutex_unlock  (void);
107 gboolean         ev_document_fc_mutex_trylock (void);
108
109 EvDocumentInfo  *ev_document_get_info         (EvDocument      *document);
110 gboolean         ev_document_load             (EvDocument      *document,
111                                                const char      *uri,
112                                                GError         **error);
113 gboolean         ev_document_save             (EvDocument      *document,
114                                                const char      *uri,
115                                                GError         **error);
116 int              ev_document_get_n_pages      (EvDocument      *document);
117 EvPage          *ev_document_get_page         (EvDocument      *document,
118                                                gint             index);
119 void             ev_document_get_page_size    (EvDocument      *document,
120                                                EvPage          *page,
121                                                double          *width,
122                                                double          *height);
123 char            *ev_document_get_page_label   (EvDocument      *document,
124                                                EvPage          *page);
125 cairo_surface_t *ev_document_render           (EvDocument      *document,
126                                                EvRenderContext *rc);
127
128 gint            ev_rect_cmp                   (EvRectangle     *a,
129                                                EvRectangle     *b);
130
131 #define EV_TYPE_RECTANGLE (ev_rectangle_get_type ())
132 struct _EvRectangle
133 {
134         gdouble x1;
135         gdouble y1;
136         gdouble x2;
137         gdouble y2;
138 };
139
140 GType        ev_rectangle_get_type (void) G_GNUC_CONST;
141 EvRectangle *ev_rectangle_new      (void);
142 EvRectangle *ev_rectangle_copy     (EvRectangle *ev_rect);
143 void         ev_rectangle_free     (EvRectangle *ev_rect);
144
145 /* convenience macro to ease interface addition in the CODE
146  * section of EV_BACKEND_REGISTER_WITH_CODE (this macro relies on
147  * the g_define_type_id present within EV_BACKEND_REGISTER_WITH_CODE()).
148  * usage example:
149  * EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
150  *                          EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
151  *                                                 pdf_document_document_thumbnails_iface_init));
152  */
153 #define EV_BACKEND_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) {                \
154         const GInterfaceInfo g_implement_interface_info = {                     \
155                 (GInterfaceInitFunc) iface_init, NULL, NULL                     \
156         };                                                                      \
157         g_type_module_add_interface (module,                                    \
158                                      g_define_type_id,                          \
159                                      TYPE_IFACE,                                \
160                                      &g_implement_interface_info);              \
161 }
162
163 /*
164  * Utility macro used to register backends
165  *
166  * use: EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE)
167  */
168 #define EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE)          \
169                                                                                 \
170 static GType g_define_type_id = 0;                                              \
171                                                                                 \
172 GType                                                                           \
173 backend_name##_get_type (void)                                                  \
174 {                                                                               \
175         return g_define_type_id;                                                \
176 }                                                                               \
177                                                                                 \
178 static void     backend_name##_init              (BackendName        *self);    \
179 static void     backend_name##_class_init        (BackendName##Class *klass);   \
180 static gpointer backend_name##_parent_class = NULL;                             \
181 static void     backend_name##_class_intern_init (gpointer klass)               \
182 {                                                                               \
183         backend_name##_parent_class = g_type_class_peek_parent (klass);         \
184         backend_name##_class_init ((BackendName##Class *) klass);               \
185 }                                                                               \
186                                                                                 \
187 G_MODULE_EXPORT GType                                                           \
188 register_evince_backend (GTypeModule *module)                                   \
189 {                                                                               \
190         const GTypeInfo our_info = {                                    \
191                 sizeof (BackendName##Class),                                    \
192                 NULL, /* base_init */                                           \
193                 NULL, /* base_finalize */                                       \
194                 (GClassInitFunc) backend_name##_class_intern_init,              \
195                 NULL,                                                           \
196                 NULL, /* class_data */                                          \
197                 sizeof (BackendName),                                           \
198                 0, /* n_preallocs */                                            \
199                 (GInstanceInitFunc) backend_name##_init                         \
200         };                                                                      \
201                                                                                 \
202         /* Initialise the i18n stuff */                                         \
203         bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);                       \
204         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");                     \
205                                                                                 \
206         g_define_type_id = g_type_module_register_type (module,                 \
207                                             G_TYPE_OBJECT,                      \
208                                             #BackendName,                       \
209                                             &our_info,                          \
210                                            (GTypeFlags)0);                      \
211                                                                                 \
212         EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,                       \
213                                backend_name##_document_iface_init);             \
214                                                                                 \
215         CODE                                                                    \
216                                                                                 \
217         return g_define_type_id;                                                \
218 }
219
220 /*
221  * Utility macro used to register backend
222  *
223  * use: EV_BACKEND_REGISTER(BackendName, backend_name)
224  */
225 #define EV_BACKEND_REGISTER(BackendName, backend_name)                  \
226         EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, ;)
227
228 /*
229  * A convenience macro for boxed type implementations, which defines a
230  * type_name_get_type() function registering the boxed type.
231  */
232 #define EV_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func)               \
233 GType                                                                                 \
234 type_name##_get_type (void)                                                           \
235 {                                                                                     \
236         static volatile gsize g_define_type_id__volatile = 0;                         \
237         if (g_once_init_enter (&g_define_type_id__volatile)) {                        \
238                 GType g_define_type_id =                                              \
239                     g_boxed_type_register_static (g_intern_static_string (#TypeName), \
240                                                   (GBoxedCopyFunc) copy_func,         \
241                                                   (GBoxedFreeFunc) free_func);        \
242                 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);    \
243         }                                                                             \
244         return g_define_type_id__volatile;                                            \
245 }
246
247 /* A convenience macro for GTypeInterface definitions, which declares
248  * a default vtable initialization function and defines a *_get_type()
249  * function.
250  *
251  * The macro expects the interface initialization function to have the
252  * name <literal>t_n ## _default_init</literal>, and the interface
253  * structure to have the name <literal>TN ## Interface</literal>.
254  */
255 #define EV_DEFINE_INTERFACE(TypeName, type_name, TYPE_PREREQ)                                \
256 static void     type_name##_class_init        (TypeName##Iface *klass);                      \
257                                                                                              \
258 GType                                                                                        \
259 type_name##_get_type (void)                                                                  \
260 {                                                                                            \
261         static volatile gsize g_define_type_id__volatile = 0;                                \
262         if (g_once_init_enter (&g_define_type_id__volatile)) {                               \
263                 GType g_define_type_id =                                                     \
264                     g_type_register_static_simple (G_TYPE_INTERFACE,                         \
265                                                    g_intern_static_string (#TypeName),       \
266                                                    sizeof (TypeName##Iface),                 \
267                                                    (GClassInitFunc)type_name##_class_init,   \
268                                                    0,                                        \
269                                                    (GInstanceInitFunc)NULL,                  \
270                                                    (GTypeFlags) 0);                          \
271                 if (TYPE_PREREQ)                                                             \
272                         g_type_interface_add_prerequisite (g_define_type_id, TYPE_PREREQ);   \
273                 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);           \
274         }                                                                                    \
275         return g_define_type_id__volatile;                                                   \
276 }
277
278 /*
279  * A convenience macro for boxed type implementations, which defines a
280  * type_name_get_type() function registering the boxed type.
281  */
282 #define EV_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func)               \
283 GType                                                                                 \
284 type_name##_get_type (void)                                                           \
285 {                                                                                     \
286         static volatile gsize g_define_type_id__volatile = 0;                         \
287         if (g_once_init_enter (&g_define_type_id__volatile)) {                        \
288                 GType g_define_type_id =                                              \
289                     g_boxed_type_register_static (g_intern_static_string (#TypeName), \
290                                                   (GBoxedCopyFunc) copy_func,         \
291                                                   (GBoxedFreeFunc) free_func);        \
292                 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);    \
293         }                                                                             \
294         return g_define_type_id__volatile;                                            \
295 }
296                 
297 G_END_DECLS
298
299 #endif /* EV_DOCUMENT_H */