2 Copyright (C) 2005 Fernando Herrera <fherrera@onirica.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include <ev-document.h>
22 #include <ev-document-thumbnails.h>
23 #include <ev-async-renderer.h>
24 #include <ev-document-factory.h>
25 #include <ev-backends-manager.h>
32 #define THUMBNAIL_SIZE 128
42 evince_thumbnailer_get_document (const gchar *uri)
44 EvDocument *document = NULL;
47 document = ev_document_factory_get_document (uri, &error);
49 if (error->domain == EV_DOCUMENT_ERROR &&
50 error->code == EV_DOCUMENT_ERROR_ENCRYPTED) {
51 /* FIXME: Create a thumb for cryp docs */
63 evince_thumbnail_pngenc_get (EvDocument *document, const char *thumbnail, int size)
69 ev_document_get_page_size (document, 0, &width, &height);
71 rc = ev_render_context_new (0, 0, size / width);
72 pixbuf = ev_document_thumbnails_get_thumbnail (EV_DOCUMENT_THUMBNAILS (document),
77 const char *overlaid_icon_name = NULL;
79 if (overlaid_icon_name) {
80 GdkPixbuf *overlaid_pixbuf;
82 gchar *overlaid_icon_path = g_strdup_printf ("%s/%s", DATADIR, overlaid_icon_name);
83 overlaid_pixbuf = gdk_pixbuf_new_from_file (overlaid_icon_path, NULL);
84 g_free (overlaid_icon_path);
85 if (overlaid_pixbuf != NULL) {
86 int delta_height, delta_width;
88 delta_width = gdk_pixbuf_get_width (pixbuf) -
89 gdk_pixbuf_get_width (overlaid_pixbuf);
90 delta_height = gdk_pixbuf_get_height (pixbuf) -
91 gdk_pixbuf_get_height (overlaid_pixbuf);
93 gdk_pixbuf_composite (overlaid_pixbuf, pixbuf,
94 delta_width, delta_height,
95 gdk_pixbuf_get_width (overlaid_pixbuf),
96 gdk_pixbuf_get_height (overlaid_pixbuf),
97 delta_width, delta_height,
99 GDK_INTERP_NEAREST, 100);
101 g_object_unref (overlaid_pixbuf);
105 if (gdk_pixbuf_save (pixbuf, thumbnail, "png", NULL, NULL)) {
106 g_object_unref (pixbuf);
110 g_object_unref (pixbuf);
117 evince_thumbnail_pngenc_get_async (struct AsyncData *data)
119 ev_document_doc_mutex_lock ();
120 data->success = evince_thumbnail_pngenc_get (data->document,
123 ev_document_doc_mutex_unlock ();
125 g_idle_add ((GSourceFunc)gtk_main_quit, NULL);
131 main (int argc, char *argv[])
133 EvDocument *document;
140 if (argc <= 2 || argc > 5 || strcmp (argv[1], "-h") == 0 ||
141 strcmp (argv[1], "--help") == 0) {
142 g_print ("Usage: %s [-s <size>] <input> <output>\n", argv[0]);
146 if (!strcmp (argv[1], "-s")) {
149 size = atoi (argv[2]);
153 size = THUMBNAIL_SIZE;
157 g_print ("Size cannot be smaller than 40 pixels\n");
163 if (!g_thread_supported ())
164 g_thread_init (NULL);
166 ev_backends_manager_init ();
168 file = g_file_new_for_commandline_arg (input);
169 uri = g_file_get_uri (file);
170 document = evince_thumbnailer_get_document (uri);
172 g_object_unref (file);
176 ev_backends_manager_shutdown ();
180 if (!EV_IS_DOCUMENT_THUMBNAILS (document)) {
181 g_object_unref (document);
182 ev_backends_manager_shutdown ();
186 if (EV_IS_ASYNC_RENDERER (document)) {
187 struct AsyncData data;
189 gtk_init (&argc, &argv);
191 data.document = document;
192 data.output = output;
195 g_thread_create ((GThreadFunc) evince_thumbnail_pngenc_get_async,
200 g_object_unref (document);
201 ev_backends_manager_shutdown ();
203 return data.success ? 0 : -2;
206 if (!evince_thumbnail_pngenc_get (document, output, size)) {
207 g_object_unref (document);
208 ev_backends_manager_shutdown ();
212 g_object_unref (document);
213 ev_backends_manager_shutdown ();