]> www.fi.muni.cz Git - evince.git/blob - backend/ev-document.c
Updated Canadian English translation.
[evince.git] / backend / ev-document.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
2 /*
3  *  Copyright (C) 2004 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  */
20
21 #include "config.h"
22
23 #include "ev-document.h"
24
25 #include "ev-backend-marshalers.h"
26 #include "ev-job-queue.h"
27
28 static void ev_document_class_init (gpointer g_class);
29
30
31 GMutex *ev_doc_mutex = NULL;
32
33 #define LOG(x) 
34 GType
35 ev_document_get_type (void)
36 {
37         static GType type = 0;
38
39         if (G_UNLIKELY (type == 0))
40         {
41                 static const GTypeInfo our_info =
42                 {
43                         sizeof (EvDocumentIface),
44                         NULL,
45                         NULL,
46                         (GClassInitFunc)ev_document_class_init
47                 };
48
49                 type = g_type_register_static (G_TYPE_INTERFACE,
50                                                "EvDocument",
51                                                &our_info, (GTypeFlags)0);
52         }
53
54         return type;
55 }
56
57 GQuark
58 ev_document_error_quark (void)
59 {
60   static GQuark q = 0;
61   if (q == 0)
62     q = g_quark_from_static_string ("ev-document-error-quark");
63
64   return q;
65 }
66
67 static void
68 ev_document_class_init (gpointer g_class)
69 {
70 }
71
72 #define PAGE_CACHE_STRING "ev-page-cache"
73
74 EvPageCache *
75 ev_document_get_page_cache (EvDocument *document)
76 {
77         EvPageCache *page_cache;
78
79         g_return_val_if_fail (EV_IS_DOCUMENT (document), NULL);
80
81         page_cache = g_object_get_data (G_OBJECT (document), PAGE_CACHE_STRING);
82         if (page_cache == NULL) {
83                 page_cache = _ev_page_cache_new (document);
84                 g_object_set_data_full (G_OBJECT (document), PAGE_CACHE_STRING, page_cache, g_object_unref);
85         }
86
87         return page_cache;
88 }
89
90 GMutex *
91 ev_document_get_doc_mutex (void)
92 {
93         if (ev_doc_mutex == NULL) {
94                 ev_doc_mutex = g_mutex_new ();
95         }
96         return ev_doc_mutex;
97 }
98
99
100 gboolean
101 ev_document_load (EvDocument  *document,
102                   const char  *uri,
103                   GError     **error)
104 {
105         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
106         gboolean retval;
107         LOG ("ev_document_load");
108         retval = iface->load (document, uri, error);
109
110         /* Call this to make the initial cached copy */
111         if (retval)
112                 ev_document_get_page_cache (document);
113
114         return retval;
115 }
116
117 gboolean
118 ev_document_save (EvDocument  *document,
119                   const char  *uri,
120                   GError     **error)
121 {
122         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
123         gboolean retval;
124
125         LOG ("ev_document_save");
126         retval = iface->save (document, uri, error);
127
128         return retval;
129 }
130
131 int
132 ev_document_get_n_pages (EvDocument  *document)
133 {
134         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
135         gint retval;
136
137         LOG ("ev_document_get_n_pages");
138         retval = iface->get_n_pages (document);
139
140         return retval;
141 }
142
143 void
144 ev_document_get_page_size   (EvDocument   *document,
145                              int           page,
146                              double       *width,
147                              double       *height)
148 {
149         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
150
151         LOG ("ev_document_get_page_size");
152         iface->get_page_size (document, page, width, height);
153 }
154
155 char *
156 ev_document_get_page_label(EvDocument    *document,
157                            int             page)
158 {
159         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
160
161         LOG ("ev_document_get_page_label");
162         if (iface->get_page_label == NULL)
163                 return NULL;
164
165         return iface->get_page_label (document, page);
166 }
167
168 gboolean
169 ev_document_can_get_text (EvDocument  *document)
170 {
171         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
172
173         return iface->can_get_text (document);
174 }
175
176 EvDocumentInfo *
177 ev_document_get_info (EvDocument *document)
178 {
179         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
180
181         return iface->get_info (document);
182 }
183
184 char *
185 ev_document_get_text (EvDocument  *document,
186                       int          page,
187                       EvRectangle *rect)
188 {
189         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
190         char *retval;
191
192         LOG ("ev_document_get_text");
193         retval = iface->get_text (document, page, rect);
194
195         return retval;
196 }
197
198 GList *
199 ev_document_get_links (EvDocument *document,
200                        int         page)
201 {
202         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
203         GList *retval;
204
205         LOG ("ev_document_get_link");
206         if (iface->get_links == NULL)
207                 return NULL;
208         retval = iface->get_links (document, page);
209
210         return retval;
211 }
212
213
214
215 GdkPixbuf *
216 ev_document_render_pixbuf (EvDocument *document,
217                            int         page,
218                            double      scale)
219 {
220         EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
221         GdkPixbuf *retval;
222
223         LOG ("ev_document_render_pixbuf");
224         g_assert (iface->render_pixbuf);
225
226         retval = iface->render_pixbuf (document, page, scale);
227
228         return retval;
229 }