]> www.fi.muni.cz Git - evince.git/blob - libdocument/ev-document.h
7cb6d8470551f96e4b5f6574d51dde3ef5dc3278
[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 #ifndef EV_DOCUMENT_H
23 #define EV_DOCUMENT_H
24
25 #include <glib-object.h>
26 #include <glib.h>
27 #include <gdk/gdk.h>
28 #include <cairo.h>
29
30 #include "ev-document-info.h"
31 #include "ev-page.h"
32 #include "ev-render-context.h"
33
34 G_BEGIN_DECLS
35
36 #define EV_TYPE_DOCUMENT            (ev_document_get_type ())
37 #define EV_DOCUMENT(o)              (G_TYPE_CHECK_INSTANCE_CAST ((o), EV_TYPE_DOCUMENT, EvDocument))
38 #define EV_DOCUMENT_IFACE(k)        (G_TYPE_CHECK_CLASS_CAST((k), EV_TYPE_DOCUMENT, EvDocumentIface))
39 #define EV_IS_DOCUMENT(o)           (G_TYPE_CHECK_INSTANCE_TYPE ((o), EV_TYPE_DOCUMENT))
40 #define EV_IS_DOCUMENT_IFACE(k)     (G_TYPE_CHECK_CLASS_TYPE ((k), EV_TYPE_DOCUMENT))
41 #define EV_DOCUMENT_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), EV_TYPE_DOCUMENT, EvDocumentIface))
42
43 typedef struct _EvDocument        EvDocument;
44 typedef struct _EvDocumentIface   EvDocumentIface;
45 typedef struct _EvPageCache       EvPageCache;
46 typedef struct _EvPageCacheClass  EvPageCacheClass;
47
48 #define EV_DOCUMENT_ERROR ev_document_error_quark ()
49 #define EV_DOC_MUTEX_LOCK (ev_document_doc_mutex_lock ())
50 #define EV_DOC_MUTEX_UNLOCK (ev_document_doc_mutex_unlock ())
51
52 typedef enum
53 {
54         EV_DOCUMENT_ERROR_INVALID,
55         EV_DOCUMENT_ERROR_ENCRYPTED
56 } EvDocumentError;
57
58 typedef struct {
59         double x;
60         double y;
61 } EvPoint;
62
63 typedef struct {
64         double x1;
65         double y1;
66         double x2;
67         double y2;
68 } EvRectangle;
69
70 struct _EvDocumentIface
71 {
72         GTypeInterface base_iface;
73
74         /* Methods  */
75         gboolean          (* load)            (EvDocument      *document,
76                                                const char      *uri,
77                                                GError         **error);
78         gboolean          (* save)            (EvDocument      *document,
79                                                const char      *uri,
80                                                GError         **error);
81         int               (* get_n_pages)     (EvDocument      *document);
82         EvPage          * (* get_page)        (EvDocument      *document,
83                                                gint             index);
84         void              (* get_page_size)   (EvDocument      *document,
85                                                EvPage          *page,
86                                                double          *width,
87                                                double          *height);
88         char            * (* get_page_label)  (EvDocument      *document,
89                                                EvPage          *page);
90         gboolean          (* has_attachments) (EvDocument      *document);
91         GList           * (* get_attachments) (EvDocument      *document);
92         cairo_surface_t * (* render)          (EvDocument      *document,
93                                                EvRenderContext *rc);
94         EvDocumentInfo *  (* get_info)        (EvDocument      *document);
95 };
96
97 GType            ev_document_get_type         (void) G_GNUC_CONST;
98 GQuark           ev_document_error_quark      (void);
99
100 /* Document mutex */
101 GMutex          *ev_document_get_doc_mutex    (void);
102 void             ev_document_doc_mutex_lock   (void);
103 void             ev_document_doc_mutex_unlock (void);
104 gboolean         ev_document_doc_mutex_trylock(void);
105
106 /* FontConfig mutex */
107 GMutex          *ev_document_get_fc_mutex     (void);
108 void             ev_document_fc_mutex_lock    (void);
109 void             ev_document_fc_mutex_unlock  (void);
110 gboolean         ev_document_fc_mutex_trylock (void);
111
112 EvDocumentInfo  *ev_document_get_info         (EvDocument      *document);
113 gboolean         ev_document_load             (EvDocument      *document,
114                                                const char      *uri,
115                                                GError         **error);
116 gboolean         ev_document_save             (EvDocument      *document,
117                                                const char      *uri,
118                                                GError         **error);
119 int              ev_document_get_n_pages      (EvDocument      *document);
120 EvPage          *ev_document_get_page         (EvDocument      *document,
121                                                gint             index);
122 void             ev_document_get_page_size    (EvDocument      *document,
123                                                EvPage          *page,
124                                                double          *width,
125                                                double          *height);
126 char            *ev_document_get_page_label   (EvDocument      *document,
127                                                EvPage          *page);
128 gboolean         ev_document_has_attachments  (EvDocument      *document);
129 GList           *ev_document_get_attachments  (EvDocument      *document);
130 cairo_surface_t *ev_document_render           (EvDocument      *document,
131                                                EvRenderContext *rc);
132
133 gint            ev_rect_cmp                   (EvRectangle     *a,
134                                                EvRectangle     *b);
135
136 /* convenience macro to ease interface addition in the CODE
137  * section of EV_BACKEND_REGISTER_WITH_CODE (this macro relies on
138  * the g_define_type_id present within EV_BACKEND_REGISTER_WITH_CODE()).
139  * usage example:
140  * EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
141  *                          EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
142  *                                                 pdf_document_document_thumbnails_iface_init));
143  */
144 #define EV_BACKEND_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) {                \
145         const GInterfaceInfo g_implement_interface_info = {                     \
146                 (GInterfaceInitFunc) iface_init, NULL, NULL                     \
147         };                                                                      \
148         g_type_module_add_interface (module,                                    \
149                                      g_define_type_id,                          \
150                                      TYPE_IFACE,                                \
151                                      &g_implement_interface_info);              \
152 }
153
154 /*
155  * Utility macro used to register backends
156  *
157  * use: EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE)
158  */
159 #define EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE)          \
160                                                                                 \
161 static GType g_define_type_id = 0;                                              \
162                                                                                 \
163 GType                                                                           \
164 backend_name##_get_type (void)                                                  \
165 {                                                                               \
166         return g_define_type_id;                                                \
167 }                                                                               \
168                                                                                 \
169 static void     backend_name##_init              (BackendName        *self);    \
170 static void     backend_name##_class_init        (BackendName##Class *klass);   \
171 static gpointer backend_name##_parent_class = NULL;                             \
172 static void     backend_name##_class_intern_init (gpointer klass)               \
173 {                                                                               \
174         backend_name##_parent_class = g_type_class_peek_parent (klass);         \
175         backend_name##_class_init ((BackendName##Class *) klass);               \
176 }                                                                               \
177                                                                                 \
178 G_MODULE_EXPORT GType                                                           \
179 register_evince_backend (GTypeModule *module)                                   \
180 {                                                                               \
181         static const GTypeInfo our_info = {                                     \
182                 sizeof (BackendName##Class),                                    \
183                 NULL, /* base_init */                                           \
184                 NULL, /* base_finalize */                                       \
185                 (GClassInitFunc) backend_name##_class_intern_init,              \
186                 NULL,                                                           \
187                 NULL, /* class_data */                                          \
188                 sizeof (BackendName),                                           \
189                 0, /* n_preallocs */                                            \
190                 (GInstanceInitFunc) backend_name##_init                         \
191         };                                                                      \
192                                                                                 \
193         /* Initialise the i18n stuff */                                         \
194         bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);                       \
195         bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");                     \
196                                                                                 \
197         g_define_type_id = g_type_module_register_type (module,                 \
198                                             G_TYPE_OBJECT,                      \
199                                             #BackendName,                       \
200                                             &our_info,                          \
201                                            (GTypeFlags)0);                      \
202                                                                                 \
203         EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,                       \
204                                backend_name##_document_iface_init);             \
205                                                                                 \
206         CODE                                                                    \
207                                                                                 \
208         return g_define_type_id;                                                \
209 }
210
211 /*
212  * Utility macro used to register backend
213  *
214  * use: EV_BACKEND_REGISTER(BackendName, backend_name)
215  */
216 #define EV_BACKEND_REGISTER(BackendName, backend_name)                  \
217         EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, ;)
218
219 /*
220  * A convenience macro for boxed type implementations, which defines a
221  * type_name_get_type() function registering the boxed type.
222  */
223 #define EV_DEFINE_BOXED_TYPE(TypeName, type_name, copy_func, free_func)               \
224 GType                                                                                 \
225 type_name##_get_type (void)                                                           \
226 {                                                                                     \
227         static volatile gsize g_define_type_id__volatile = 0;                         \
228         if (g_once_init_enter (&g_define_type_id__volatile)) {                        \
229                 GType g_define_type_id =                                              \
230                     g_boxed_type_register_static (g_intern_static_string (#TypeName), \
231                                                   (GBoxedCopyFunc) copy_func,         \
232                                                   (GBoxedFreeFunc) free_func);        \
233                 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);    \
234         }                                                                             \
235         return g_define_type_id__volatile;                                            \
236 }
237
238 /* A convenience macro for GTypeInterface definitions, which declares
239  * a default vtable initialization function and defines a *_get_type()
240  * function.
241  *
242  * The macro expects the interface initialization function to have the
243  * name <literal>t_n ## _default_init</literal>, and the interface
244  * structure to have the name <literal>TN ## Interface</literal>.
245  */
246 #define EV_DEFINE_INTERFACE(TypeName, type_name, TYPE_PREREQ)                                \
247 static void     type_name##_class_init        (TypeName##Iface *klass);                      \
248                                                                                              \
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_type_register_static_simple (G_TYPE_INTERFACE,                         \
256                                                    g_intern_static_string (#TypeName),       \
257                                                    sizeof (TypeName##Iface),                 \
258                                                    (GClassInitFunc)type_name##_class_init,   \
259                                                    0,                                        \
260                                                    (GInstanceInitFunc)NULL,                  \
261                                                    (GTypeFlags) 0);                          \
262                 if (TYPE_PREREQ)                                                             \
263                         g_type_interface_add_prerequisite (g_define_type_id, TYPE_PREREQ);   \
264                 g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);           \
265         }                                                                                    \
266         return g_define_type_id__volatile;                                                   \
267 }
268                 
269 G_END_DECLS
270
271 #endif /* EV_DOCUMENT_H */