]> www.fi.muni.cz Git - evince.git/blob - libdocument/ev-document.h
Renamed from evince-backend.pc.in. Renamed library to libevdocument.la.
[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 {
68         double x1;
69         double y1;
70         double x2;
71         double y2;
72 } EvRectangle;
73
74 struct _EvDocumentIface
75 {
76         GTypeInterface base_iface;
77
78         /* Methods  */
79         gboolean          (* load)            (EvDocument      *document,
80                                                const char      *uri,
81                                                GError         **error);
82         gboolean          (* save)            (EvDocument      *document,
83                                                const char      *uri,
84                                                GError         **error);
85         int               (* get_n_pages)     (EvDocument      *document);
86         EvPage          * (* get_page)        (EvDocument      *document,
87                                                gint             index);
88         void              (* get_page_size)   (EvDocument      *document,
89                                                EvPage          *page,
90                                                double          *width,
91                                                double          *height);
92         char            * (* get_page_label)  (EvDocument      *document,
93                                                EvPage          *page);
94         gboolean          (* has_attachments) (EvDocument      *document);
95         GList           * (* get_attachments) (EvDocument      *document);
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 int              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                                                EvPage          *page,
128                                                double          *width,
129                                                double          *height);
130 char            *ev_document_get_page_label   (EvDocument      *document,
131                                                EvPage          *page);
132 gboolean         ev_document_has_attachments  (EvDocument      *document);
133 GList           *ev_document_get_attachments  (EvDocument      *document);
134 cairo_surface_t *ev_document_render           (EvDocument      *document,
135                                                EvRenderContext *rc);
136
137 gint            ev_rect_cmp                   (EvRectangle     *a,
138                                                EvRectangle     *b);
139
140 /* convenience macro to ease interface addition in the CODE
141  * section of EV_BACKEND_REGISTER_WITH_CODE (this macro relies on
142  * the g_define_type_id present within EV_BACKEND_REGISTER_WITH_CODE()).
143  * usage example:
144  * EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
145  *                          EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
146  *                                                 pdf_document_document_thumbnails_iface_init));
147  */
148 #define EV_BACKEND_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) {                \
149         const GInterfaceInfo g_implement_interface_info = {                     \
150                 (GInterfaceInitFunc) iface_init, NULL, NULL                     \
151         };                                                                      \
152         g_type_module_add_interface (module,                                    \
153                                      g_define_type_id,                          \
154                                      TYPE_IFACE,                                \
155                                      &g_implement_interface_info);              \
156 }
157
158 /*
159  * Utility macro used to register backends
160  *
161  * use: EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE)
162  */
163 #define EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE)          \
164                                                                                 \
165 static GType g_define_type_id = 0;                                              \
166                                                                                 \
167 GType                                                                           \
168 backend_name##_get_type (void)                                                  \
169 {                                                                               \
170         return g_define_type_id;                                                \
171 }                                                                               \
172                                                                                 \
173 static void     backend_name##_init              (BackendName        *self);    \
174 static void     backend_name##_class_init        (BackendName##Class *klass);   \
175 static gpointer backend_name##_parent_class = NULL;                             \
176 static void     backend_name##_class_intern_init (gpointer klass)               \
177 {                                                                               \
178         backend_name##_parent_class = g_type_class_peek_parent (klass);         \
179         backend_name##_class_init ((BackendName##Class *) klass);               \
180 }                                                                               \
181                                                                                 \
182 G_MODULE_EXPORT GType                                                           \
183 register_evince_backend (GTypeModule *module)                                   \
184 {                                                                               \
185         static const GTypeInfo our_info = {                                     \
186                 sizeof (BackendName##Class),                                    \
187                 NULL, /* base_init */                                           \
188                 NULL, /* base_finalize */                                       \
189                 (GClassInitFunc) backend_name##_class_intern_init,              \
190                 NULL,                                                           \
191                 NULL, /* class_data */                                          \
192                 sizeof (BackendName),                                           \
193                 0, /* n_preallocs */                                            \
194                 (GInstanceInitFunc) backend_name##_init                         \
195         };                                                                      \
196                                                                                 \
197         /* Initialise the i18n stuff */                                         \
198         bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);                       \
199         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");                     \
200                                                                                 \
201         g_define_type_id = g_type_module_register_type (module,                 \
202                                             G_TYPE_OBJECT,                      \
203                                             #BackendName,                       \
204                                             &our_info,                          \
205                                            (GTypeFlags)0);                      \
206                                                                                 \
207         EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,                       \
208                                backend_name##_document_iface_init);             \
209                                                                                 \
210         CODE                                                                    \
211                                                                                 \
212         return g_define_type_id;                                                \
213 }
214
215 /*
216  * Utility macro used to register backend
217  *
218  * use: EV_BACKEND_REGISTER(BackendName, backend_name)
219  */
220 #define EV_BACKEND_REGISTER(BackendName, backend_name)                  \
221         EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, ;)
222
223 /*
224  * A convenience macro for boxed type implementations, which defines a
225  * type_name_get_type() function registering the boxed type.
226  */
227 #define EV_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func)               \
228 GType                                                                                 \
229 type_name##_get_type (void)                                                           \
230 {                                                                                     \
231         static volatile gsize g_define_type_id__volatile = 0;                         \
232         if (g_once_init_enter (&g_define_type_id__volatile)) {                        \
233                 GType g_define_type_id =                                              \
234                     g_boxed_type_register_static (g_intern_static_string (#TypeName), \
235                                                   (GBoxedCopyFunc) copy_func,         \
236                                                   (GBoxedFreeFunc) free_func);        \
237                 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);    \
238         }                                                                             \
239         return g_define_type_id__volatile;                                            \
240 }
241
242 /* A convenience macro for GTypeInterface definitions, which declares
243  * a default vtable initialization function and defines a *_get_type()
244  * function.
245  *
246  * The macro expects the interface initialization function to have the
247  * name <literal>t_n ## _default_init</literal>, and the interface
248  * structure to have the name <literal>TN ## Interface</literal>.
249  */
250 #define EV_DEFINE_INTERFACE(TypeName, type_name, TYPE_PREREQ)                                \
251 static void     type_name##_class_init        (TypeName##Iface *klass);                      \
252                                                                                              \
253 GType                                                                                        \
254 type_name##_get_type (void)                                                                  \
255 {                                                                                            \
256         static volatile gsize g_define_type_id__volatile = 0;                                \
257         if (g_once_init_enter (&g_define_type_id__volatile)) {                               \
258                 GType g_define_type_id =                                                     \
259                     g_type_register_static_simple (G_TYPE_INTERFACE,                         \
260                                                    g_intern_static_string (#TypeName),       \
261                                                    sizeof (TypeName##Iface),                 \
262                                                    (GClassInitFunc)type_name##_class_init,   \
263                                                    0,                                        \
264                                                    (GInstanceInitFunc)NULL,                  \
265                                                    (GTypeFlags) 0);                          \
266                 if (TYPE_PREREQ)                                                             \
267                         g_type_interface_add_prerequisite (g_define_type_id, TYPE_PREREQ);   \
268                 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);           \
269         }                                                                                    \
270         return g_define_type_id__volatile;                                                   \
271 }
272                 
273 G_END_DECLS
274
275 #endif /* EV_DOCUMENT_H */