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