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