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