Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ev-document.h
Go to the documentation of this file.
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 <gio/gio.h>
33 #include <gdk/gdk.h>
34 #include <cairo.h>
35 
36 #include "ev-document-info.h"
37 #include "ev-page.h"
38 #include "ev-render-context.h"
39 
40 G_BEGIN_DECLS
41 
42 #define EV_TYPE_DOCUMENT (ev_document_get_type ())
43 #define EV_DOCUMENT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), EV_TYPE_DOCUMENT, EvDocument))
44 #define EV_DOCUMENT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), EV_TYPE_DOCUMENT, EvDocumentClass))
45 #define EV_IS_DOCUMENT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), EV_TYPE_DOCUMENT))
46 #define EV_IS_DOCUMENT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), EV_TYPE_DOCUMENT))
47 #define EV_DOCUMENT_GET_CLASS(inst) (G_TYPE_INSTANCE_GET_CLASS ((inst), EV_TYPE_DOCUMENT, EvDocumentClass))
48 
49 typedef struct _EvDocument EvDocument;
52 
53 #define EV_DOCUMENT_ERROR ev_document_error_quark ()
54 #define EV_DOC_MUTEX_LOCK (ev_document_doc_mutex_lock ())
55 #define EV_DOC_MUTEX_UNLOCK (ev_document_doc_mutex_unlock ())
56 
57 typedef enum /*< flags >*/ {
61 
62 typedef enum
63 {
67 
68 typedef struct _EvPoint EvPoint;
69 typedef struct _EvRectangle EvRectangle;
70 typedef struct _EvMapping EvMapping;
71 typedef struct _EvSourceLink EvSourceLink;
73 
74 struct _EvPoint {
75  double x;
76  double y;
77 };
78 
80 {
81  const gchar *name;
82  const gchar *version;
83 };
84 
86 {
87  GObject base;
88 
90 };
91 
93 {
94  GObjectClass base_class;
95 
96  /* Virtual Methods */
97  gboolean (* load) (EvDocument *document,
98  const char *uri,
99  GError **error);
100  gboolean (* save) (EvDocument *document,
101  const char *uri,
102  GError **error);
103  gint (* get_n_pages) (EvDocument *document);
104  EvPage * (* get_page) (EvDocument *document,
105  gint index);
106  void (* get_page_size) (EvDocument *document,
107  EvPage *page,
108  double *width,
109  double *height);
110  gchar * (* get_page_label) (EvDocument *document,
111  EvPage *page);
112  cairo_surface_t * (* render) (EvDocument *document,
113  EvRenderContext *rc);
114  GdkPixbuf * (* get_thumbnail) (EvDocument *document,
115  EvRenderContext *rc);
116  EvDocumentInfo * (* get_info) (EvDocument *document);
117  gboolean (* get_backend_info) (EvDocument *document,
118  EvDocumentBackendInfo *info);
119  gboolean (* support_synctex) (EvDocument *document);
120 
121  /* GIO streams */
122  gboolean (* load_stream) (EvDocument *document,
123  GInputStream *stream,
124  EvDocumentLoadFlags flags,
125  GCancellable *cancellable,
126  GError **error);
127  gboolean (* load_gfile) (EvDocument *document,
128  GFile *file,
129  EvDocumentLoadFlags flags,
130  GCancellable *cancellable,
131  GError **error);
132  cairo_surface_t * (* get_thumbnail_surface) (EvDocument *document,
133  EvRenderContext *rc);
134 };
135 
136 GType ev_document_get_type (void) G_GNUC_CONST;
137 GQuark ev_document_error_quark (void);
138 
139 /* Document mutex */
140 GMutex *ev_document_get_doc_mutex (void);
141 void ev_document_doc_mutex_lock (void);
142 void ev_document_doc_mutex_unlock (void);
143 gboolean ev_document_doc_mutex_trylock (void);
144 
145 /* FontConfig mutex */
146 GMutex *ev_document_get_fc_mutex (void);
147 void ev_document_fc_mutex_lock (void);
148 void ev_document_fc_mutex_unlock (void);
149 gboolean ev_document_fc_mutex_trylock (void);
150 
152 gboolean ev_document_get_backend_info (EvDocument *document,
153  EvDocumentBackendInfo *info);
154 gboolean ev_document_load (EvDocument *document,
155  const char *uri,
156  GError **error);
157 gboolean ev_document_load_full (EvDocument *document,
158  const char *uri,
159  EvDocumentLoadFlags flags,
160  GError **error);
161 gboolean ev_document_load_stream (EvDocument *document,
162  GInputStream *stream,
163  EvDocumentLoadFlags flags,
164  GCancellable *cancellable,
165  GError **error);
166 gboolean ev_document_load_gfile (EvDocument *document,
167  GFile *file,
168  EvDocumentLoadFlags flags,
169  GCancellable *cancellable,
170  GError **error);
171 gboolean ev_document_save (EvDocument *document,
172  const char *uri,
173  GError **error);
174 gint ev_document_get_n_pages (EvDocument *document);
176  gint index);
177 void ev_document_get_page_size (EvDocument *document,
178  gint page_index,
179  double *width,
180  double *height);
181 gchar *ev_document_get_page_label (EvDocument *document,
182  gint page_index);
183 cairo_surface_t *ev_document_render (EvDocument *document,
184  EvRenderContext *rc);
185 GdkPixbuf *ev_document_get_thumbnail (EvDocument *document,
186  EvRenderContext *rc);
187 cairo_surface_t *ev_document_get_thumbnail_surface (EvDocument *document,
188  EvRenderContext *rc);
189 guint64 ev_document_get_size (EvDocument *document);
190 const gchar *ev_document_get_uri (EvDocument *document);
191 const gchar *ev_document_get_title (EvDocument *document);
192 gboolean ev_document_is_page_size_uniform (EvDocument *document);
194  gdouble *width,
195  gdouble *height);
197  gdouble *width,
198  gdouble *height);
199 gboolean ev_document_check_dimensions (EvDocument *document);
201 gboolean ev_document_has_text_page_labels (EvDocument *document);
202 gboolean ev_document_find_page_by_label (EvDocument *document,
203  const gchar *page_label,
204  gint *page_index);
205 gboolean ev_document_has_synctex (EvDocument *document);
206 
208  (EvDocument *document,
209  gint page_index,
210  gfloat x,
211  gfloat y);
212 
214  (EvDocument *document,
215  EvSourceLink *source_link);
216 
217 gint ev_rect_cmp (EvRectangle *a,
218  EvRectangle *b);
219 
220 #define EV_TYPE_RECTANGLE (ev_rectangle_get_type ())
222 {
223  gdouble x1;
224  gdouble y1;
225  gdouble x2;
226  gdouble y2;
227 };
228 
229 GType ev_rectangle_get_type (void) G_GNUC_CONST;
232 void ev_rectangle_free (EvRectangle *ev_rect);
233 
234 struct _EvMapping {
236  gpointer data;
237 };
238 
239 #define EV_TYPE_SOURCE_LINK (ev_source_link_get_type ())
241 {
242  gchar *filename;
243  gint line;
244  gint col;
245 };
246 
247 GType ev_source_link_get_type (void) G_GNUC_CONST;
248 EvSourceLink *ev_source_link_new (const gchar *filename,
249  gint line,
250  gint col);
252 void ev_source_link_free (EvSourceLink *link);
253 
254 /* convenience macro to ease interface addition in the CODE
255  * section of EV_BACKEND_REGISTER_WITH_CODE (this macro relies on
256  * the g_define_type_id present within EV_BACKEND_REGISTER_WITH_CODE()).
257  * usage example:
258  * EV_BACKEND_REGISTER_WITH_CODE (PdfDocument, pdf_document,
259  * EV_BACKEND_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS,
260  * pdf_document_document_thumbnails_iface_init));
261  */
262 #define EV_BACKEND_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) { \
263  const GInterfaceInfo g_implement_interface_info = { \
264  (GInterfaceInitFunc) iface_init, NULL, NULL \
265  }; \
266  g_type_module_add_interface (module, \
267  g_define_type_id, \
268  TYPE_IFACE, \
269  &g_implement_interface_info); \
270 }
271 
272 /*
273  * Utility macro used to register backends
274  *
275  * use: EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE)
276  */
277 #define EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, CODE) \
278  \
279 static GType g_define_type_id = 0; \
280  \
281 GType \
282 backend_name##_get_type (void) \
283 { \
284  return g_define_type_id; \
285 } \
286  \
287 static void backend_name##_init (BackendName *self); \
288 static void backend_name##_class_init (BackendName##Class *klass); \
289 static gpointer backend_name##_parent_class = NULL; \
290 static void backend_name##_class_intern_init (gpointer klass) \
291 { \
292  backend_name##_parent_class = g_type_class_peek_parent (klass); \
293  backend_name##_class_init ((BackendName##Class *) klass); \
294 } \
295  \
296 G_MODULE_EXPORT GType \
297 register_evince_backend (GTypeModule *module) \
298 { \
299  const GTypeInfo our_info = { \
300  sizeof (BackendName##Class), \
301  NULL, /* base_init */ \
302  NULL, /* base_finalize */ \
303  (GClassInitFunc) backend_name##_class_intern_init, \
304  NULL, \
305  NULL, /* class_data */ \
306  sizeof (BackendName), \
307  0, /* n_preallocs */ \
308  (GInstanceInitFunc) backend_name##_init \
309  }; \
310  \
311  /* Initialise the i18n stuff */ \
312  bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); \
313  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); \
314  \
315  g_define_type_id = g_type_module_register_type (module, \
316  EV_TYPE_DOCUMENT, \
317  #BackendName, \
318  &our_info, \
319  (GTypeFlags)0); \
320  \
321  CODE \
322  \
323  return g_define_type_id; \
324 }
325 
326 /*
327  * Utility macro used to register backend
328  *
329  * use: EV_BACKEND_REGISTER(BackendName, backend_name)
330  */
331 #define EV_BACKEND_REGISTER(BackendName, backend_name) \
332  EV_BACKEND_REGISTER_WITH_CODE(BackendName, backend_name, ;)
333 
334 G_END_DECLS
335 
336 #endif /* EV_DOCUMENT_H */