Merge branch 'master' of ssh+git://git.claws-mail.org/home/git/claws
[claws.git] / src / plugins / pdf_viewer / poppler_viewer.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright(C) 1999-2007 the Claws Mail Team
4  * This file Copyright (C) 2007 Salvatore De Paolis 
5  * <iwkse@claws-mail.org> 
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  *(at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #  include "config.h"
24 #include "claws-features.h"
25 #endif
26
27 #include <glib.h>
28 #include <glib/gi18n.h>
29
30 #include "poppler_viewer.h"
31 #include "printing.h"
32 #include "prefs_common.h"
33 #include "gtk/gtkutils.h"
34 #include "mimeview.h"
35 #ifndef POPPLER_WITH_GDK
36 #include "stdbool.h"
37 #endif
38
39 static FileType pdf_viewer_mimepart_get_type(MimeInfo *partinfo);
40 static MimeViewerFactory pdf_viewer_factory;
41
42 static void pdf_viewer_show_mimepart(MimeViewer *_viewer, const gchar *infile,
43                                 MimeInfo *partinfo);
44
45 static MimeViewer *pdf_viewer_create(void);
46 static void pdf_viewer_clear(MimeViewer *_viewer);
47 static void pdf_viewer_destroy(MimeViewer *_viewer);
48 static void pdf_viewer_update(MimeViewer *_viewer, gboolean reload_file, int page_num);
49
50 static GtkWidget *pdf_viewer_get_widget(MimeViewer *_viewer);
51
52 static void pdf_viewer_hide_index_pane(PdfViewer *viewer);
53 static void pdf_viewer_set_index_button_sensitive(PdfViewer *viewer);
54 static void pdf_viewer_scroll_to(PdfViewer *viewer, gfloat x, gfloat y);
55
56 static void search_matches_free(PdfViewer *viewer);
57 static gboolean pdf_viewer_text_search(MimeViewer *_viewer, gboolean backward,
58                                      const gchar *str, gboolean case_sens);
59 static void pdf_viewer_render_selection(PdfViewer *viewer, PopplerRectangle *rect, PageResult *page_results);
60 static void pdf_viewer_render_page(PopplerPage *page, GtkWidget *view, double width, double height, double zoom, gint rotate);
61
62 static char * pdf_viewer_get_document_format_data(GTime utime);
63 static void pdf_viewer_get_document_index(PdfViewer *viewer, PopplerIndexIter *index_iter, GtkTreeIter *parentiter);
64 static void pdf_viewer_index_row_activated(GtkTreeView          *tree_view,
65                                         GtkTreePath             *path,
66                                         GtkTreeViewColumn       *column,
67                                         gpointer                 data);
68
69 static GtkTable * pdf_viewer_fill_info_table(PdfViewer *viewer);
70
71 /* Callbacks */
72 static void pdf_viewer_move_events_cb(GtkWidget *widget, GdkEventMotion *event, PdfViewer *viewer); 
73 static void pdf_viewer_button_press_events_cb(GtkWidget *widget, GdkEventButton *event, PdfViewer *viewer); 
74 static void pdf_viewer_mouse_scroll_destroy_cb(GtkWidget *widget, GdkEventButton *event, PdfViewer *viewer); 
75 static void pdf_viewer_button_first_page_cb(GtkButton *button, PdfViewer *viewer);
76 static void pdf_viewer_button_last_page_cb(GtkButton *button, PdfViewer *viewer);
77 static void pdf_viewer_button_zoom_in_cb(GtkButton *button, PdfViewer *viewer);
78 static void pdf_viewer_button_zoom_out_cb(GtkButton *button, PdfViewer *viewer);
79 static void pdf_viewer_button_zoom_fit_cb(GtkButton *button, PdfViewer *viewer);
80 static void pdf_viewer_button_zoom_width_cb(GtkButton *button, PdfViewer *viewer);
81 static void pdf_viewer_button_rotate_right_cb(GtkButton *button, PdfViewer *viewer);
82 static void pdf_viewer_button_rotate_left_cb(GtkButton *button, PdfViewer *viewer);
83 static void pdf_viewer_spin_change_page_cb(GtkSpinButton *button, PdfViewer *viewer);
84 static void pdf_viewer_spin_zoom_scroll_cb(GtkSpinButton *button, PdfViewer *viewer);
85 /* Show/Hide the index pane */
86 static void pdf_viewer_show_document_index_cb(GtkButton *button, PdfViewer *viewer);
87 static void pdf_viewer_button_document_info_cb(GtkButton *button, PdfViewer *viewer);
88
89 static void pdf_viewer_show_controls(PdfViewer *viewer, gboolean show);
90 static gboolean pdf_viewer_scroll_page(MimeViewer *_viewer, gboolean up);
91 static void pdf_viewer_scroll_one_line(MimeViewer *_viewer, gboolean up);
92
93 /** Claws-Mail Plugin functions*/
94 gint plugin_init(gchar **error);
95 const gchar *plugin_name(void);
96 const gchar *plugin_desc(void);
97 const gchar *plugin_type(void);
98 const gchar *plugin_licence(void);
99 const gchar *plugin_version(void);
100 struct PluginFeature *plugin_provides(void);
101
102 #ifndef POPPLER_WITH_GDK
103 static void
104 copy_cairo_surface_to_pixbuf (cairo_surface_t *surface,
105                               GdkPixbuf       *pixbuf)
106 {
107         int cairo_width, cairo_height, cairo_rowstride;
108         unsigned char *pixbuf_data, *dst, *cairo_data;
109         int pixbuf_rowstride, pixbuf_n_channels;
110         unsigned int *src;
111         int x, y;
112
113         cairo_width = cairo_image_surface_get_width (surface);
114         cairo_height = cairo_image_surface_get_height (surface);
115         cairo_rowstride = cairo_image_surface_get_stride (surface);
116         cairo_data = cairo_image_surface_get_data (surface);
117
118         pixbuf_data = gdk_pixbuf_get_pixels (pixbuf);
119         pixbuf_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
120         pixbuf_n_channels = gdk_pixbuf_get_n_channels (pixbuf);
121
122         if (cairo_width > gdk_pixbuf_get_width (pixbuf))
123                 cairo_width = gdk_pixbuf_get_width (pixbuf);
124         if (cairo_height > gdk_pixbuf_get_height (pixbuf))
125                 cairo_height = gdk_pixbuf_get_height (pixbuf);
126         for (y = 0; y < cairo_height; y++) {
127                 src = (unsigned int *) (cairo_data + y * cairo_rowstride);
128                 dst = pixbuf_data + y * pixbuf_rowstride;
129                 for (x = 0; x < cairo_width; x++) {
130                         dst[0] = (*src >> 16) & 0xff;
131                         dst[1] = (*src >> 8) & 0xff; 
132                         dst[2] = (*src >> 0) & 0xff;
133                         if (pixbuf_n_channels == 4)
134                                 dst[3] = (*src >> 24) & 0xff;
135                         dst += pixbuf_n_channels;
136                         src++;
137                 }
138         }
139 }
140 static void
141 _poppler_page_render_to_pixbuf (PopplerPage *page,
142                                 int src_x, int src_y,
143                                 int src_width, int src_height,
144                                 double scale,
145                                 int rotation,
146                                 gboolean printing,
147                                 GdkPixbuf *pixbuf)
148 {
149         cairo_t *cr;
150         cairo_surface_t *surface;
151
152         surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
153                                         src_width, src_height);
154         cr = cairo_create (surface);
155         cairo_save (cr);
156         switch (rotation) {
157         case 90:
158                 cairo_translate (cr, src_x + src_width, -src_y);
159                 break;
160         case 180:
161                 cairo_translate (cr, src_x + src_width, src_y + src_height);
162                 break;
163         case 270:
164                 cairo_translate (cr, -src_x, src_y + src_height);
165                 break;
166         default:
167                 cairo_translate (cr, -src_x, -src_y);
168         }
169
170         if (scale != 1.0)
171                 cairo_scale (cr, scale, scale);
172
173         if (rotation != 0)
174                 cairo_rotate (cr, rotation * G_PI / 180.0);
175
176         if (printing)
177                 poppler_page_render_for_printing (page, cr);
178         else
179                 poppler_page_render (page, cr);
180         cairo_restore (cr);
181
182         cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER);
183         cairo_set_source_rgb (cr, 1., 1., 1.);
184         cairo_paint (cr);
185
186         cairo_destroy (cr);
187
188         copy_cairo_surface_to_pixbuf (surface, pixbuf);
189         cairo_surface_destroy (surface);
190 }
191
192 /**
193  * poppler_page_render_to_pixbuf:
194  * @page: the page to render from
195  * @src_x: x coordinate of upper left corner  
196  * @src_y: y coordinate of upper left corner  
197  * @src_width: width of rectangle to render  
198  * @src_height: height of rectangle to render
199  * @scale: scale specified as pixels per point
200  * @rotation: rotate the document by the specified degree
201  * @pixbuf: pixbuf to render into
202  *
203  * First scale the document to match the specified pixels per point,
204  * then render the rectangle given by the upper left corner at
205  * (src_x, src_y) and src_width and src_height.
206  * This function is for rendering a page that will be displayed.
207  * If you want to render a page that will be printed use
208  * poppler_page_render_to_pixbuf_for_printing() instead
209  *
210  * Deprecated: 0.16
211  **/
212 static void
213 poppler_page_render_to_pixbuf (PopplerPage *page,
214                                int src_x, int src_y,
215                                int src_width, int src_height,
216                                double scale,
217                                int rotation,
218                                GdkPixbuf *pixbuf)
219 {
220         g_return_if_fail (POPPLER_IS_PAGE (page));
221         g_return_if_fail (scale > 0.0);
222         g_return_if_fail (pixbuf != NULL);
223
224         _poppler_page_render_to_pixbuf (page, src_x, src_y,
225                                   src_width, src_height,
226                                   scale, rotation,
227                                   FALSE,
228                                   pixbuf);
229 }
230 #endif
231 static GtkWidget *pdf_viewer_get_widget(MimeViewer *_viewer)
232 {
233         PdfViewer *viewer = (PdfViewer *) _viewer;
234         debug_print("pdf_viewer_get_widget: %p\n", viewer->vbox);
235
236         return GTK_WIDGET(viewer->vbox);
237 }
238 /** Hide the index panel */
239 static void pdf_viewer_hide_index_pane(PdfViewer *viewer)
240 {
241         if (viewer->pdf_index) {   
242                 poppler_index_iter_free(viewer->pdf_index);
243                 viewer->pdf_index = NULL;
244                 gtk_widget_hide(GTK_WIDGET(viewer->frame_index));
245         }
246 }
247
248 static void search_matches_free(PdfViewer *viewer)
249 {
250         GList *cur; 
251         for(cur = viewer->text_found; cur; cur = cur->next) {
252                 PageResult *res = (PageResult *)cur->data;
253                 g_list_free(res->results);
254                 g_free(res);
255         }
256         g_list_free(viewer->text_found);
257         viewer->text_found = NULL;
258         g_free(viewer->last_search);
259         viewer->last_search = NULL;
260         if (viewer->last_rect && viewer->last_page_result) {
261                 viewer->last_rect = NULL;
262                 viewer->last_page_result = NULL;
263                 pdf_viewer_update((MimeViewer *)viewer, 
264                         FALSE, 
265                         gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page)));
266         }
267 }
268
269 static void pdf_viewer_scroll_to(PdfViewer *viewer, gfloat x, gfloat y)
270 {
271         GtkAdjustment *vadj;
272         GtkAdjustment *hadj;
273         vadj = gtk_scrolled_window_get_vadjustment(
274                 GTK_SCROLLED_WINDOW(viewer->scrollwin));
275
276         if (y < vadj->value) {
277                 vadj->value = y;
278         }
279         else {
280                 while(y > vadj->value + vadj->page_size) {
281                         vadj->value += vadj->page_size;
282                 }
283         }
284
285         hadj = gtk_scrolled_window_get_hadjustment(
286                 GTK_SCROLLED_WINDOW(viewer->scrollwin));
287
288         if (x < hadj->value) {
289                 hadj->value = x;
290         }
291         else {
292                 while(x > hadj->value + hadj->page_size) {
293                         hadj->value += hadj->page_size;
294                 }
295         }
296
297         g_signal_emit_by_name(G_OBJECT(hadj), "value-changed", 0);      
298         g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);      
299 }
300 static void pdf_viewer_render_page(PopplerPage *page, GtkWidget *view, double width, 
301                                    double height, double zoom, gint rotate)
302 {
303         GdkPixbuf *pb;
304
305         debug_print("width: %f\n", width);
306         pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, 
307                                 FALSE, 8, 
308                                 (int)(width * zoom), 
309                                 (int)(height * zoom));  
310
311                         poppler_page_render_to_pixbuf(page, 0, 0, 
312                                 (int)(width * zoom), 
313                                 (int)(height * zoom), 
314                                 zoom, rotate, pb);
315
316                         gtk_image_set_from_pixbuf(GTK_IMAGE(view), pb);
317                         g_object_unref(G_OBJECT(pb));
318 }
319 static void pdf_viewer_render_selection(PdfViewer *viewer, PopplerRectangle *rect, PageResult *page_results)
320 {
321         gint selw, selh;
322         double width_points, height_points;
323         gint width, height;
324         GdkPixbuf *sel_pb, *page_pb;
325         gfloat x1, x2, y1, y2;  
326
327
328         gint cur_page_num = 
329                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page));
330
331         viewer->last_match = viewer->res_cnt;
332
333         viewer->last_rect = NULL;
334         viewer->last_page_result = NULL;
335         if (cur_page_num != page_results->page_num) {
336                 /* we changed page. update the view */
337                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->cur_page), 
338         (gdouble) page_results->page_num);
339         }
340
341         viewer->last_rect = rect;
342         viewer->last_page_result = page_results;
343
344         GTK_EVENTS_FLUSH();
345
346         poppler_page_get_size(POPPLER_PAGE(viewer->pdf_page), &width_points, &height_points);
347         width = (int)((width_points * viewer->zoom) + 0.5);
348         height = (int)((height_points * viewer->zoom) + 0.5);
349
350         if (viewer->rotate == 90) {
351                 x1 = MIN(rect->y1,rect->y2) * viewer->zoom;
352                 x2 = MAX(rect->y1,rect->y2) * viewer->zoom;
353                 y1 = MAX(rect->x1,rect->x2) * viewer->zoom;
354                 y2 = MIN(rect->x1,rect->x2) * viewer->zoom;
355                 selw = (x2 - x1);
356                 selh = (y1 - y2);
357
358         } else if (viewer->rotate == 180) {
359                 x1 = width - rect->x2 * viewer->zoom;
360                 x2 = width - rect->x1 * viewer->zoom;
361                 y1 = height - rect->y2 * viewer->zoom;
362                 y2 = height - rect->y1 * viewer->zoom;
363                 selw = (x2 - x1);
364                 selh = (y2 - y1);
365                 y1 = height - y1;
366                 y2 = height - y2;
367
368         } else if (viewer->rotate == 270) {
369                 x1 = height - MAX(rect->y1,rect->y2) * viewer->zoom;
370                 x2 = height - MIN(rect->y1,rect->y2) * viewer->zoom;
371                 y1 = width - MIN(rect->x1,rect->x2) * viewer->zoom;
372                 y2 = width - MAX(rect->x1,rect->x2) * viewer->zoom;
373                 selw = (x2 - x1);
374                 selh = (y1 - y2);
375         } else {
376                 x1 = rect->x1 * viewer->zoom;
377                 x2 = rect->x2 * viewer->zoom;
378                 y1 = rect->y1 * viewer->zoom;
379                 y2 = rect->y2 * viewer->zoom;
380                 selw = (x2 - x1);
381                 selh = (y2 - y1);
382                 y1 = height - y1;
383                 y2 = height - y2;
384         }
385
386         sel_pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 
387                                                         selw, selh);
388
389         gdk_pixbuf_fill(sel_pb, SELECTION_COLOR);
390
391         page_pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, 
392                                         FALSE, 8, 
393                                 (int)(viewer->width * viewer->zoom), 
394                                 (int)(viewer->height * viewer->zoom));  
395
396         poppler_page_render_to_pixbuf(viewer->pdf_page, 
397                                         0, 
398                                         0, 
399                                 (int)(viewer->width * viewer->zoom), 
400                                 (int)(viewer->height * viewer->zoom), 
401                                         viewer->zoom, 
402                                         viewer->rotate, 
403                                         page_pb);
404
405         gdk_pixbuf_composite(sel_pb, page_pb, 
406                                         x1, y2, selw, selh, 0, 0, 
407                                         viewer->zoom, viewer->zoom, 
408                                         GDK_INTERP_BILINEAR, ALPHA_CHANNEL);
409
410         gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->pdf_view), page_pb);
411
412         pdf_viewer_scroll_to(viewer, MIN(x1,x2), MIN(y1,y2));
413
414         g_object_unref(G_OBJECT(sel_pb));
415         g_object_unref(G_OBJECT(page_pb));
416
417 }
418
419 static gboolean pdf_viewer_text_search(MimeViewer *_viewer, gboolean backward,
420                                      const gchar *str, gboolean case_sens)
421 {
422         PdfViewer *viewer = (PdfViewer *)_viewer;
423         GList *all_pages_results, *cur_page_results;
424         viewer->res_cnt = 0;
425
426         debug_print("pdf_viewer_text_search: %s\n", str);
427         main_window_cursor_wait(mainwindow_get_mainwindow());
428
429         if (viewer->last_search && strcmp(str, viewer->last_search)) {
430                 search_matches_free(viewer);
431                 viewer->last_match = -1;
432                 viewer->num_matches = 0;
433         } else if (!viewer->last_search) {
434                 viewer->last_match = -1;
435                 viewer->num_matches = 0;
436         }
437         /* It's a new search, build list of matches 
438          * across all pages */
439         if (viewer->last_match == -1) {
440                 gint i; 
441
442                 for(i = 1; i <= viewer->num_pages; i++) {
443
444                         PopplerPage *pdf_page = poppler_document_get_page(viewer->pdf_doc, i - 1);
445                         viewer->page_results = poppler_page_find_text(pdf_page, str);
446
447                         if (viewer->page_results != NULL) {
448                                 debug_print("page_results %p\n", viewer->page_results);
449                                 /* store results for this page */
450                                 gint num_res = 0;
451                                 PageResult *res = g_new0(PageResult, 1);
452                                 res->results = viewer->page_results;
453                                 res->page_num = i;
454                                 /* found text, prepend this page(faster than append) */
455                                 viewer->text_found = g_list_prepend(viewer->text_found, res);
456                                 num_res = g_list_length(viewer->page_results);
457                                 debug_print("%d results on page %d\n", num_res, i);
458                                 viewer->num_matches += num_res;
459                         }
460                         g_object_unref(G_OBJECT(pdf_page));
461                 }
462
463                 if (viewer->text_found == NULL) {
464                         main_window_cursor_normal(mainwindow_get_mainwindow());
465                         return FALSE;
466                 }
467                 /* put back the list in the correct order */
468                 viewer->text_found = g_list_reverse(viewer->text_found);
469         } 
470
471         if (!viewer->text_found) {
472                 main_window_cursor_normal(mainwindow_get_mainwindow());
473                 return FALSE;
474         } else {
475                 viewer->last_search = g_strdup(str);
476         }
477
478         if (backward) {
479                 /* if backward, we have to initialize stuff to search 
480                  * from the end */
481                 viewer->res_cnt = viewer->num_matches-1;
482                 if (viewer->last_match == -1) {
483                         viewer->last_match = viewer->num_matches+1;
484                 }
485                 all_pages_results = g_list_last(viewer->text_found);
486         } 
487         else {
488                 all_pages_results = viewer->text_found;
489         }
490
491         for(; all_pages_results; all_pages_results = (backward?all_pages_results->prev:all_pages_results->next)) {
492
493                 PageResult * page_results = (PageResult *)all_pages_results->data;
494
495                 if (backward) {
496                         cur_page_results = g_list_last(page_results->results);
497                 }
498                 else {
499                         cur_page_results = page_results->results;
500                 }
501
502                 for(; cur_page_results; cur_page_results = (backward?cur_page_results->prev:cur_page_results->next)) {
503
504                         gboolean valid = FALSE;
505                         /* first valid result is the last+1 if searching
506                          * forward, last-1 if searching backward */
507                         if (backward) {
508                                 valid = (viewer->res_cnt < viewer->last_match);
509                         }
510                         else {
511                                 valid = (viewer->res_cnt > viewer->last_match);
512                         }
513                         if (valid) {
514                                 pdf_viewer_render_selection(viewer, 
515                                         (PopplerRectangle *)cur_page_results->data,
516                                                 page_results);
517                                 main_window_cursor_normal(mainwindow_get_mainwindow());
518                                 return TRUE;
519                         }
520
521                         if (backward) {
522                                 viewer->res_cnt--;
523                         }
524                         else {
525                                 viewer->res_cnt++;
526                         }
527                 }
528         }
529         main_window_cursor_normal(mainwindow_get_mainwindow());
530         search_matches_free(viewer);
531         return FALSE;
532 }
533
534 static void pdf_viewer_get_document_index(PdfViewer *viewer, PopplerIndexIter *index_iter, GtkTreeIter *parentiter)
535 {
536         PopplerAction *action;
537         PopplerIndexIter *child;
538         GtkTreeIter childiter;
539
540         debug_print("get document index\n");
541         do      {
542                 gint page_num = 0;
543
544                 action = poppler_index_iter_get_action(index_iter);
545
546                 if (action->type != POPPLER_ACTION_GOTO_DEST) {
547                         poppler_action_free(action);
548                         continue;
549                 }
550
551                 if (action->goto_dest.dest->type == POPPLER_DEST_XYZ || action->goto_dest.dest->type == POPPLER_DEST_FITH) {
552                         page_num = action->goto_dest.dest->page_num;
553                 }
554 #ifdef HAVE_POPPLER_DEST_NAMED
555                 else if (action->goto_dest.dest->type == POPPLER_DEST_NAMED) {
556                         PopplerDest *dest = poppler_document_find_dest(
557                                         viewer->pdf_doc, action->goto_dest.dest->named_dest);
558                         if (dest->type != POPPLER_DEST_XYZ) {
559                                 g_warning("couldn't figure out link\n");
560                                 poppler_dest_free(dest);
561                                 continue;
562                         }
563                         page_num = dest->page_num;
564                         poppler_dest_free(dest);
565                 } 
566 #endif
567                 else {
568 #ifdef HAVE_POPPLER_DEST_NAMED
569                         g_warning("unhandled link type %d\nplease contact developers\n", action->goto_dest.dest->type);
570 #else
571                         g_warning("unhandled link type %d\nplease upgrade libpoppler-glib to 0.5.4\n", action->goto_dest.dest->type);
572 #endif
573                         continue;
574                 }
575                 gtk_tree_store_append(GTK_TREE_STORE(viewer->index_model), &childiter, parentiter);
576                 gtk_tree_store_set(GTK_TREE_STORE(viewer->index_model), &childiter,
577                                                 INDEX_NAME, action->named.title,
578                                                 INDEX_PAGE, page_num,
579                                                 INDEX_TOP, action->goto_dest.dest->top,
580                                                 -1);
581                 poppler_action_free(action);
582                 child = poppler_index_iter_get_child(index_iter);
583                 if (child) {
584                         pdf_viewer_get_document_index(viewer, child, &childiter);
585                         poppler_index_iter_free(child);
586                 }
587         }
588         while(poppler_index_iter_next(index_iter));
589 }
590
591 static void pdf_viewer_index_row_activated(GtkTreeView          *tree_view,
592                                         GtkTreePath             *path,
593                                         GtkTreeViewColumn       *column,
594                                         gpointer                 data)
595 {
596         GtkTreeIter iter;
597         GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
598         PdfViewer *viewer = (PdfViewer *)data;
599         gint page_num = 0;
600
601         debug_print("index_row_activated\n");
602         if (!gtk_tree_model_get_iter(model, &iter, path)) return;
603
604         gtk_tree_model_get(model, &iter, 
605                            INDEX_PAGE, &page_num,
606                            -1);
607
608         if (page_num > 0) {
609                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->cur_page),(gdouble)page_num);
610                 debug_print("Page num: %d\n", page_num);
611         }
612         GTK_EVENTS_FLUSH();
613 }
614
615 /** Disable the index button if the document doesn't have an index */
616 static void pdf_viewer_set_index_button_sensitive(PdfViewer *viewer)
617 {
618         viewer->pdf_index  = poppler_index_iter_new(viewer->pdf_doc);
619         if (viewer->pdf_index) {        
620                 if (!gtk_widget_is_sensitive(viewer->doc_index)) {
621                         gtk_widget_set_sensitive(viewer->doc_index, TRUE);
622                 }
623         }
624         else {
625                 gtk_widget_set_sensitive(viewer->doc_index, FALSE);
626         }
627
628     poppler_index_iter_free(viewer->pdf_index);
629     viewer->pdf_index = NULL;
630 }
631
632 static char * pdf_viewer_get_document_format_data(GTime utime) 
633 {
634         time_t time = (time_t) utime;
635         struct tm t;
636         char s[256];
637         const char *fmt_hack = "%c";
638         size_t len;
639
640         if (time == 0 || !localtime_r(&time, &t)) return NULL;
641
642         len = strftime(s, sizeof(s), fmt_hack, &t);
643
644         if (len == 0 || s[0] == '\0') return NULL;
645
646         return g_locale_to_utf8(s, -1, NULL, NULL, NULL);
647 }
648
649 #define ADD_TO_TABLE(LABEL, VALUE) \
650         label = gtk_label_new(LABEL); \
651         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); \
652         gtk_misc_set_padding(GTK_MISC(label), 4, 0); \
653         gtk_table_attach(viewer->table_doc_info, label, 0, 1, row, row+1, GTK_EXPAND | GTK_FILL, 0, 0, 0); \
654         \
655         label = gtk_label_new(VALUE); \
656         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
657         gtk_misc_set_padding(GTK_MISC(label), 4, 0); \
658         gtk_table_attach(viewer->table_doc_info, label, 1, 2, row, row+1, GTK_EXPAND | GTK_FILL, 0, 0, 0); \
659         row++;
660
661
662 static GtkTable * pdf_viewer_fill_info_table(PdfViewer *viewer)
663 {
664         GtkWidget *label;
665         const gchar *title, *format, *author, *subject, *keywords, *creator, *producer;
666         gboolean linearized;
667         gchar *tmp;
668         gint row = 0;
669
670         GTime creation_date, mod_date;
671
672         PopplerPageLayout layout;
673         PopplerPageMode mode;
674         PopplerPermissions permissions;
675         PopplerViewerPreferences view_prefs;
676
677         title = format = author = subject = keywords = creator = producer = tmp = 0;
678
679         g_object_get(viewer->pdf_doc,
680                                 "title", &title,
681                                 "format", &format,
682                                 "author", &author,
683                                 "subject", &subject,
684                                 "keywords", &keywords,
685                                 "creation-date", &creation_date,
686                                 "permissions", &permissions,
687                                 "mod-date", &mod_date,
688                                 "creator", &creator,
689                                 "producer", &producer,  
690                                 "linearized", &linearized,
691                                 "page-mode", &mode,
692                                 "page-layout", &layout,
693                                 "viewer-preferences", &view_prefs,
694                                 NULL);
695
696         viewer->table_doc_info = GTK_TABLE(gtk_table_new(13, 2, FALSE));
697
698         ADD_TO_TABLE(_("Filename:"), viewer->target_filename)
699         ADD_TO_TABLE(_("Size:"), to_human_readable(viewer->to_load->length))
700         ADD_TO_TABLE(NULL, NULL)
701         ADD_TO_TABLE(_("Title:"), title)
702         ADD_TO_TABLE(_("Subject:"), subject)
703         ADD_TO_TABLE(_("Author:"), author)
704         ADD_TO_TABLE(_("Keywords:"), keywords)
705         ADD_TO_TABLE(_("Creator:"), creator)
706         ADD_TO_TABLE(_("Producer:"), producer)
707
708         tmp = pdf_viewer_get_document_format_data(creation_date);
709         ADD_TO_TABLE(_("Created:"), tmp)
710         g_free(tmp);
711
712         tmp = pdf_viewer_get_document_format_data(mod_date);
713         ADD_TO_TABLE(_("Modified:"), tmp)
714         g_free(tmp);
715
716         ADD_TO_TABLE(_("Format:"), format)
717         if (linearized) {
718                 ADD_TO_TABLE(_("Optimized:"), _("Yes"))
719         }
720         else {
721                 ADD_TO_TABLE(_("Optimized:"), _("No"))
722         }
723         //ADD_TO_TABLE(_("Page Mode:"), pdf_viewer_get_document_info_mode(mode)) 
724         //ADD_TO_TABLE(_("Page Layout:"), pdf_viewer_get_document_info_layout(layout))
725
726         return(GtkTable *) viewer->table_doc_info;
727 }
728 #undef ADD_TO_TABLE
729
730 static FileType pdf_viewer_mimepart_get_type(MimeInfo *partinfo)
731 {
732         gchar *content_type = NULL;
733         FileType type = TYPE_UNKNOWN;
734         debug_print("mimepart_get_type\n");
735         if ((partinfo->type == MIMETYPE_APPLICATION) &&
736         (!g_ascii_strcasecmp(partinfo->subtype, "octet-stream"))) {
737
738                 const gchar *filename;
739
740                 filename = procmime_mimeinfo_get_parameter(partinfo, "filename");
741
742                         if (filename == NULL)
743                                 filename = procmime_mimeinfo_get_parameter(partinfo, "name");
744                         if (filename != NULL)
745                                 content_type = procmime_get_mime_type(filename);
746         } 
747         else {
748                 content_type = procmime_get_content_type_str(partinfo->type, partinfo->subtype);
749         }
750
751         if (content_type == NULL) type = TYPE_UNKNOWN;
752         else if (!strcmp(content_type, "application/pdf")) type = TYPE_PDF;
753         else if (!strcmp(content_type, "application/postscript")) type = TYPE_PS;
754         else type = TYPE_UNKNOWN;
755
756         g_free(content_type);
757         return type;
758 }
759
760 /* Callbacks */
761 static void pdf_viewer_button_first_page_cb(GtkButton *button, PdfViewer *viewer) 
762 {
763
764         gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_HOME, 1);
765 }
766
767 static void pdf_viewer_button_prev_page_cb(GtkButton *button, PdfViewer *viewer) 
768 {
769
770         gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_BACKWARD, 1);
771 }
772
773 static void pdf_viewer_button_next_page_cb(GtkButton *button, PdfViewer *viewer) 
774 {
775
776         gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_FORWARD, 1);
777 }
778
779 static void pdf_viewer_button_last_page_cb(GtkButton *button, PdfViewer *viewer) 
780 {
781
782         gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_END, 1);
783 }
784
785 static void pdf_viewer_spin_change_page_cb(GtkSpinButton *button, PdfViewer *viewer)
786 {
787         pdf_viewer_update((MimeViewer *)viewer, 
788                         FALSE, 
789                         gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page)));
790 }
791
792 static void pdf_viewer_button_zoom_in_cb(GtkButton *button, PdfViewer *viewer) 
793 {
794
795         gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->zoom_scroll), GTK_SPIN_STEP_FORWARD, ZOOM_FACTOR);
796 }
797
798 static void pdf_viewer_spin_zoom_scroll_cb(GtkSpinButton *button, PdfViewer *viewer)
799 {
800         viewer->zoom = gtk_spin_button_get_value(GTK_SPIN_BUTTON(viewer->zoom_scroll));
801         pdf_viewer_update((MimeViewer *)viewer,
802                         FALSE,
803                         gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page)));
804 }
805
806 static void pdf_viewer_button_zoom_out_cb(GtkButton *button, PdfViewer *viewer) 
807 {
808
809         gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->zoom_scroll), GTK_SPIN_STEP_BACKWARD, ZOOM_FACTOR);
810
811 }
812
813 static void pdf_viewer_button_press_events_cb(GtkWidget *widget, GdkEventButton *event, PdfViewer *viewer) 
814 {
815         gchar *uri;
816         #ifdef HAVE_POPPLER_DEST_NAMED
817         PopplerDest *dest;
818         #endif
819         static GdkCursor *hand_cur = NULL;
820
821         if (!hand_cur) hand_cur = gdk_cursor_new(GDK_FLEUR);
822
823         /* Execute Poppler Links */
824         if (event->button == 1 && viewer->in_link) {
825                 switch (viewer->link_action->type) {
826                 case POPPLER_ACTION_UNKNOWN:
827                         debug_print("action unknown\n");
828                         break;
829                 case POPPLER_ACTION_GOTO_DEST:
830                         if (viewer->link_action->goto_dest.dest->type == POPPLER_DEST_XYZ || 
831                                         viewer->link_action->goto_dest.dest->type == POPPLER_DEST_FITH) {
832                                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->cur_page), 
833                                                                           (gdouble)viewer->link_action->goto_dest.dest->page_num);
834                         }
835                 #ifdef HAVE_POPPLER_DEST_NAMED
836                         else if (viewer->link_action->goto_dest.dest->type == POPPLER_DEST_NAMED) {
837                                 dest = poppler_document_find_dest(
838                                         viewer->pdf_doc, viewer->link_action->goto_dest.dest->named_dest);
839                         if (dest->type != POPPLER_DEST_XYZ) {
840                                 g_warning("couldn't figure out link\n");
841                                 poppler_dest_free(dest);
842                                 break;
843                         }
844                         gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->cur_page), 
845                                                                           (gdouble)dest->page_num);
846                         poppler_dest_free(dest);
847                 } 
848                 #endif
849                         break;
850                 case POPPLER_ACTION_GOTO_REMOTE:
851                         #ifdef HAVE_POPPLER_DEST_NAMED
852                         dest = poppler_document_find_dest(
853                                         viewer->pdf_doc, viewer->link_action->goto_remote.dest->named_dest);
854                         if (dest->type != POPPLER_DEST_XYZ) {
855                                 g_warning ("couldn't figure out link\n");
856                                 poppler_dest_free(dest);
857                                 break;
858                         }
859                         gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->cur_page),
860                                                                           (gdouble)dest->page_num);
861                         poppler_dest_free(dest);
862                         #endif
863                         break;
864                 case POPPLER_ACTION_LAUNCH:
865                         debug_print("action launch not yet implemented\n");
866                         break;
867                 case POPPLER_ACTION_URI:
868                         uri = g_strdup(viewer->link_action->uri.uri);
869                         if (!g_ascii_strncasecmp(uri, "mailto:", 7)) 
870                                 compose_new(NULL, uri + 7, NULL);
871                         else 
872                                 open_uri(uri, prefs_common_get_uri_cmd());
873                         g_free(uri);
874                         break;
875                 case POPPLER_ACTION_NAMED:
876                         debug_print("action named not yet implemented\n");
877                         break;
878                 case POPPLER_ACTION_NONE:
879                         debug_print("action none does nothing, surprise!\n");
880                         break;
881 #if POPPLER_CHECK_VERSION(0,14,0)
882                 case POPPLER_ACTION_MOVIE:
883                         debug_print("yoyoyo ;-) a movie?\n");
884                         break;
885                 case POPPLER_ACTION_RENDITION:
886                         debug_print("yoyoyo ;-) multimedia?\n");
887                         break;
888                 case POPPLER_ACTION_OCG_STATE:
889                         debug_print("yoyoyo ;-) layer state?\n");
890                         break;
891 #if POPPLER_CHECK_VERSION(0,18,0)
892                 case POPPLER_ACTION_JAVASCRIPT:
893                         debug_print("yoyoyo ;-) javascript?\n");
894                         break;
895 #endif /* 0.18 */
896 #endif /* 0.14 */
897                 }
898                 if (((MimeViewer *)viewer)->mimeview && 
899                         ((MimeViewer *)viewer)->mimeview->messageview && 
900                         ((MimeViewer *)viewer)->mimeview->messageview->window && 
901                         ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
902                         gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, NULL);
903                 else
904                         gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, NULL);
905         }
906
907         /* Init document to be scrolled with left mouse click */
908         if (event->button == 1 && !viewer->in_link) {
909                 viewer->pdf_view_scroll = TRUE;
910                 if (((MimeViewer *)viewer)->mimeview && 
911                         ((MimeViewer *)viewer)->mimeview->messageview && 
912                         ((MimeViewer *)viewer)->mimeview->messageview->window && 
913                         ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
914                         gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, hand_cur);
915                 else
916                         gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, hand_cur);
917
918                 viewer->last_x = event->x;
919                 viewer->last_y = event->y;
920                 viewer->last_dir_x = 0;
921                 viewer->last_dir_y = 0;
922         }
923 }
924 /* Set the normal cursor*/
925 static void pdf_viewer_mouse_scroll_destroy_cb(GtkWidget *widget, GdkEventButton *event, PdfViewer *viewer) 
926 {
927
928         if (event->button == 1) {
929                 viewer->pdf_view_scroll = FALSE;
930                 if (((MimeViewer *)viewer)->mimeview && 
931                         ((MimeViewer *)viewer)->mimeview->messageview && 
932                         ((MimeViewer *)viewer)->mimeview->messageview->window && 
933                         ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
934                         gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, NULL);
935                 else
936                         gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, NULL);
937         }
938 }
939
940 static void pdf_viewer_move_events_cb(GtkWidget *widget, GdkEventMotion *event, PdfViewer *viewer) 
941 {
942         /* Grab the document and scroll it with mouse */ 
943         if (viewer->pdf_view_scroll) {
944
945                 viewer->pdf_view_vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
946                 viewer->pdf_view_hadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
947
948                         if (event->x < viewer->last_x
949                                         && viewer->pdf_view_hadj->value < (viewer->pdf_view_hadj->upper - viewer->pdf_view_hadj->page_size)) {
950                                 if (viewer->last_dir_x == -1) {
951                                         viewer->pdf_view_hadj->value += viewer->last_x - event->x; 
952                                         g_signal_emit_by_name(G_OBJECT(viewer->pdf_view_hadj),
953                                                                 "value_changed", 0);
954                                 }
955                                 viewer->last_dir_x = -1;
956                         }
957                         else if (event->x > viewer->last_x
958                                         && viewer->pdf_view_hadj->value > 0.0)  {
959                                 if (viewer->last_dir_x == +1) {
960                                         viewer->pdf_view_hadj->value += viewer->last_x - event->x; 
961                                         g_signal_emit_by_name(G_OBJECT(viewer->pdf_view_hadj),
962                                                                 "value_changed", 0);
963                                 }
964                                 viewer->last_dir_x = +1;
965                         }
966
967                         if (event->y < viewer->last_y
968                                         && viewer->pdf_view_vadj->value < (viewer->pdf_view_vadj->upper - viewer->pdf_view_vadj->page_size)) {
969                                 if (viewer->last_dir_y == -1) {
970                                         viewer->pdf_view_vadj->value += viewer->last_y - event->y; 
971                                         g_signal_emit_by_name(G_OBJECT(viewer->pdf_view_vadj),
972                                                                 "value_changed", 0);
973                                 }
974                                 viewer->last_dir_y = -1;
975                         }
976                         else if (event->y > viewer->last_y
977                                         && viewer->pdf_view_vadj->value > 0.0)  {
978                                 if (viewer->last_dir_y == +1) {
979                                         viewer->pdf_view_vadj->value += viewer->last_y - event->y; 
980                                         g_signal_emit_by_name(G_OBJECT(viewer->pdf_view_vadj),
981                                                                 "value_changed", 0);
982                                 }
983                                 viewer->last_dir_y = +1;
984                         }
985                         viewer->last_x = event->x;
986                         viewer->last_y = event->y;
987                         GTK_EVENTS_FLUSH();
988                 } 
989         else {  
990         /* Link Mapping */
991         static GList *l;
992         static GdkCursor *link_cur = NULL;
993         static GtkRequisition size;
994         static gdouble x,y, x1, y1, x2, y2;
995         gboolean ccur;
996
997         viewer->pdf_view_vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
998         viewer->pdf_view_hadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
999
1000         if (!link_cur) link_cur = gdk_cursor_new(GDK_HAND2);
1001
1002         ccur = FALSE;
1003         viewer->in_link = FALSE;        
1004         for (l = viewer->link_map; l; l = g_list_next (l)) {
1005                 PopplerLinkMapping *lmapping;
1006                 lmapping = (PopplerLinkMapping *)l->data;
1007
1008                 x1 = lmapping->area.x1;
1009                 y1 = lmapping->area.y1;
1010                 x2 = lmapping->area.x2;
1011                 y2 = lmapping->area.y2;
1012                 gtk_widget_size_request(viewer->pdf_view, &size);
1013
1014                 switch (viewer->rotate) {
1015                 case 0:
1016                 case 360:
1017                                 if (size.width != viewer->pdf_view_hadj->upper)
1018                                         x = (event->x - (viewer->pdf_view_hadj->upper - size.width) / 2) / viewer->zoom;
1019                                 else
1020                                         x = event->x / viewer->zoom;
1021
1022                                 y = (viewer->pdf_view_vadj->upper - event->y) / viewer->zoom;
1023                         break;
1024                 case 90:
1025                                 if (size.width != viewer->pdf_view_hadj->upper)
1026                                         y = (event->x - (viewer->pdf_view_hadj->upper - size.width) / 2) / viewer->zoom;
1027                                 else
1028                                         y = event->x / viewer->zoom;
1029
1030                                 x = (event->y) / viewer->zoom;
1031                         break;
1032                 case 180:
1033                                 if (size.width != viewer->pdf_view_hadj->upper)
1034                                         x = ((viewer->pdf_view_hadj->upper -  event->x) - ((viewer->pdf_view_hadj->upper - size.width) / 2)) / viewer->zoom;
1035                                 else
1036                                         x =  ((viewer->pdf_view_hadj->upper -  event->x) - (viewer->pdf_view_hadj->upper - size.width)) / viewer->zoom;
1037
1038                                 y = (event->y) / viewer->zoom;
1039                         break;
1040                 case 270:
1041                                 if (size.width != viewer->pdf_view_hadj->upper)
1042                                         y = ((viewer->pdf_view_hadj->upper -  event->x) - ((viewer->pdf_view_hadj->upper - size.width) / 2)) / viewer->zoom;
1043                                 else
1044                                         y =  ((viewer->pdf_view_hadj->upper -  event->x) - (viewer->pdf_view_hadj->upper - size.width)) / viewer->zoom;
1045
1046                                 x = (viewer->pdf_view_vadj->upper - event->y) / viewer->zoom;
1047                         break;
1048                 }
1049
1050                 if ( (x > x1 && x < x2) && (y > y1 && y < y2) ) {
1051                                 viewer->in_link = TRUE;
1052                         if (((MimeViewer *)viewer)->mimeview && 
1053                                 ((MimeViewer *)viewer)->mimeview->messageview && 
1054                                 ((MimeViewer *)viewer)->mimeview->messageview->window && 
1055                                 ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
1056                                         gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, link_cur);
1057                                 else
1058                                         gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, link_cur);
1059
1060                                 viewer->link_action = lmapping->action; 
1061                                 ccur = TRUE;
1062                 }
1063                 if (!ccur) {
1064                         if (((MimeViewer *)viewer)->mimeview && 
1065                                 ((MimeViewer *)viewer)->mimeview->messageview && 
1066                                 ((MimeViewer *)viewer)->mimeview->messageview->window && 
1067                                 ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
1068                                 gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, NULL);
1069                         else
1070                                 gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, NULL);
1071                 }
1072         }
1073         g_free(l);
1074         }
1075 }
1076 static gboolean pdf_viewer_scroll_cb(GtkWidget *widget, GdkEventScroll *event,
1077                                     PdfViewer *viewer)
1078 {
1079         GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
1080         static gboolean in_scroll_cb = FALSE;
1081         gboolean handled = FALSE;
1082         gint cur_p = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page));               
1083
1084         if (in_scroll_cb)
1085                 return FALSE;
1086
1087         in_scroll_cb = TRUE;
1088
1089         if (event->direction == GDK_SCROLL_UP &&
1090             adj->value == adj->lower && 
1091             cur_p > 1) {
1092                 gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_BACKWARD, 1);
1093                 adj->value = adj->upper - adj->page_size;
1094                 handled = TRUE;
1095         } else if (event->direction == GDK_SCROLL_DOWN &&
1096             adj->value + adj->page_size == adj->upper &&
1097             cur_p < viewer->num_pages) {
1098                 gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_FORWARD, 1);
1099                 adj->value = 0.0;
1100                 handled = TRUE;
1101         }
1102         in_scroll_cb = FALSE;
1103         return handled;
1104 }
1105
1106 static void pdf_viewer_button_zoom_fit_cb(GtkButton *button, PdfViewer *viewer)
1107 {
1108         GtkAllocation *allocation;
1109         double xratio, yratio;
1110         allocation = &(viewer->scrollwin->allocation);
1111         debug_print("width: %d\n", allocation->width);
1112         debug_print("height: %d\n", allocation->height);
1113         xratio = allocation->width / viewer->width;
1114         yratio = allocation->height / viewer->height;
1115
1116         if (xratio >= yratio) {
1117                 viewer->zoom = yratio;
1118                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->zoom_scroll),viewer->zoom);
1119         }
1120         else {
1121                 viewer->zoom = xratio;
1122                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->zoom_scroll),viewer->zoom);
1123         }
1124 }
1125
1126 static void pdf_viewer_button_zoom_width_cb(GtkButton *button, PdfViewer *viewer)
1127 {
1128         GtkAllocation *allocation;
1129         double xratio;
1130         allocation = &(viewer->scrollwin->allocation);
1131         debug_print("width: %d\n", allocation->width);
1132         xratio = allocation->width / viewer->width;
1133         gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->zoom_scroll), xratio);
1134 }
1135
1136 static void pdf_viewer_button_rotate_right_cb(GtkButton *button, PdfViewer *viewer)
1137 {
1138         if (viewer->rotate == 360) {
1139                 viewer->rotate = 0;
1140         }
1141
1142         viewer->rotate += (gint) ROTATION;
1143         pdf_viewer_update((MimeViewer *)viewer, FALSE,
1144                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page)));
1145 }
1146
1147 static void pdf_viewer_button_rotate_left_cb(GtkButton *button, PdfViewer *viewer)
1148 {
1149         if (viewer->rotate == 0) {
1150                 viewer->rotate = 360;
1151         }
1152
1153         viewer->rotate = abs(viewer->rotate -(gint) ROTATION);
1154         pdf_viewer_update((MimeViewer *)viewer, FALSE,
1155                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page)));
1156 }
1157
1158 /* Show/Hide the index pane */
1159 static void pdf_viewer_show_document_index_cb(GtkButton *button, PdfViewer *viewer)
1160 {
1161         if (!viewer->pdf_index) {
1162                 viewer->pdf_index = poppler_index_iter_new(viewer->pdf_doc);
1163         }
1164
1165         gtk_tree_store_clear(GTK_TREE_STORE(viewer->index_model));
1166
1167         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(viewer->doc_index))) {
1168                 pdf_viewer_get_document_index(viewer,(PopplerIndexIter *) viewer->pdf_index, NULL);
1169                 gtk_widget_show(GTK_WIDGET(viewer->frame_index));
1170         }
1171         else {
1172                 pdf_viewer_hide_index_pane(viewer);
1173         }
1174
1175 }
1176
1177 static void pdf_viewer_button_document_info_cb(GtkButton *button, PdfViewer *viewer)
1178 {
1179         alertpanel_full(_("PDF properties"), NULL, GTK_STOCK_CLOSE, NULL, NULL,
1180                         FALSE, (GtkWidget *) pdf_viewer_fill_info_table(viewer), 
1181                         ALERT_NOTICE, G_ALERTDEFAULT);
1182 }
1183
1184 /*
1185 static const char * poppler_get_document_info_mode(PopplerPageMode mode)
1186 {
1187         GEnumValue *enum_value;
1188
1189         enum_value = g_enum_get_value((GEnumClass *) g_type_class_peek(POPPLER_TYPE_PAGE_MODE), mode);
1190         return(gchar *) enum_value->value_name;
1191 }
1192 static const char * poppler_get_document_info_layout(PopplerPageLayout layout)
1193 {
1194
1195         GEnumValue *enum_value;
1196
1197         enum_value = g_enum_get_value((GEnumClass *) g_type_class_peek(POPPLER_TYPE_PAGE_LAYOUT), layout);
1198         return(gchar *) enum_value->value_name;
1199 }
1200 */
1201 static void pdf_viewer_show_controls(PdfViewer *viewer, gboolean show)
1202 {
1203         if (show) {
1204                 gtk_widget_show(viewer->first_page);
1205                 gtk_widget_show(viewer->cur_page);
1206                 gtk_widget_show(viewer->prev_page);
1207                 gtk_widget_show(viewer->next_page);
1208                 gtk_widget_show(viewer->last_page);
1209                 gtk_widget_show(viewer->zoom_in);
1210                 gtk_widget_show(viewer->zoom_out);
1211                 gtk_widget_show(viewer->zoom_fit);
1212                 gtk_widget_show(viewer->zoom_width);
1213                 gtk_widget_show(viewer->zoom_scroll);
1214                 gtk_widget_show(viewer->widgets_table);
1215                 gtk_widget_show(viewer->rotate_right);
1216                 gtk_widget_show(viewer->rotate_left);
1217                 gtk_widget_show(viewer->doc_info);
1218                 gtk_widget_show(viewer->doc_index);
1219         } else {
1220                 gtk_widget_hide(viewer->first_page);
1221                 gtk_widget_hide(viewer->cur_page);
1222                 gtk_widget_hide(viewer->prev_page);
1223                 gtk_widget_hide(viewer->next_page);
1224                 gtk_widget_hide(viewer->last_page);
1225                 gtk_widget_hide(viewer->zoom_in);
1226                 gtk_widget_hide(viewer->zoom_out);
1227                 gtk_widget_hide(viewer->zoom_fit);
1228                 gtk_widget_hide(viewer->zoom_width);
1229                 gtk_widget_hide(viewer->widgets_table);
1230                 gtk_widget_hide(viewer->rotate_right);
1231                 gtk_widget_hide(viewer->rotate_left);
1232                 gtk_widget_hide(viewer->doc_info);
1233                 gtk_widget_hide(viewer->doc_index);
1234                 gtk_widget_hide(viewer->zoom_scroll);
1235         }
1236 }
1237 /** Render the current page, page_num on the viewer */
1238 static void pdf_viewer_update(MimeViewer *_viewer, gboolean reload_file, int page_num) 
1239 {
1240
1241         PdfViewer *viewer = (PdfViewer *) _viewer;
1242         GError *error;
1243         gchar *tmpfile = NULL;
1244         gchar *tmp;
1245
1246         debug_print("pdf_viewer_update\n");
1247
1248         error = NULL;
1249         if (reload_file) {
1250                 if (viewer->pdf_doc) {
1251                         g_object_unref(G_OBJECT(viewer->pdf_doc));
1252                         viewer->pdf_doc = NULL;
1253                 }
1254
1255                 if (pdf_viewer_mimepart_get_type(viewer->to_load) == TYPE_PS) {
1256                         stock_pixbuf_gdk(viewer->hbox, 
1257                                         STOCK_PIXMAP_MIME_PS, 
1258                                         &viewer->icon_pixbuf);
1259                         gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type),
1260                                                                         viewer->icon_pixbuf);
1261                 } 
1262                 else if (pdf_viewer_mimepart_get_type(viewer->to_load) == TYPE_PDF) {
1263                         stock_pixbuf_gdk(viewer->hbox, 
1264                         STOCK_PIXMAP_MIME_PDF, 
1265                         &viewer->icon_pixbuf);
1266                         gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type), 
1267                                                                         viewer->icon_pixbuf);
1268                 } 
1269                 else {
1270                         stock_pixbuf_gdk(viewer->hbox, 
1271                         STOCK_PIXMAP_MIME_APPLICATION, 
1272                         &viewer->icon_pixbuf);
1273                         gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type), 
1274                                                                         viewer->icon_pixbuf);
1275                 }
1276
1277                 gtk_label_set_text(GTK_LABEL(viewer->doc_label), _("Loading..."));      
1278                 pdf_viewer_show_controls(viewer, FALSE);
1279                 main_window_cursor_wait(mainwindow_get_mainwindow());
1280
1281                 GTK_EVENTS_FLUSH();
1282
1283                 if (pdf_viewer_mimepart_get_type(viewer->to_load) == TYPE_PS) {
1284                         gchar *cmdline = NULL, *tmp = NULL, *gspath = NULL;
1285                         gint result = 0;
1286
1287                         if ((gspath = g_find_program_in_path("gs")) != NULL) {
1288                                 g_free(gspath);
1289                                 /* convert postscript to pdf */
1290                                 tmpfile = get_tmp_file();
1291                                 cmdline = g_strdup_printf(
1292                                         "gs -dSAFER -dCompatibilityLevel=1.2 -q -dNOPAUSE -dBATCH "
1293                                           "-sDEVICE=pdfwrite -sOutputFile=%s -c .setpdfwrite -f \"%s\"",
1294                                         tmpfile, viewer->filename);
1295                                 result = execute_command_line(cmdline, FALSE);
1296                                 if (result == 0) {
1297                                         tmp = g_filename_to_uri(tmpfile, NULL, NULL);
1298                                         viewer->pdf_doc = poppler_document_new_from_file( tmp, NULL, &error);
1299                                         g_free(tmp);
1300                                 } 
1301                                 else {
1302                                         g_warning("gs conversion failed: %s returned %d\n", cmdline, result);
1303                                         tmp = g_strdup_printf("gs: err %d", result);
1304                                         alertpanel_warning("%s", tmp);
1305                                         g_free(tmp);
1306                                 }
1307
1308                                 g_free(cmdline);
1309                                 claws_unlink(tmpfile);
1310                                 g_free(tmpfile);
1311                         }
1312                         else {
1313                                 g_warning("gs conversion disabled: gs binary was not found\n");
1314                                 alertpanel_warning("PostScript view disabled: required gs program not found");
1315                                 result = 1;
1316
1317                         }
1318                         if (result != 0) {
1319                                 main_window_cursor_normal(mainwindow_get_mainwindow());
1320                                 return;
1321                         }
1322                 }   
1323                 else {
1324                         viewer->pdf_doc = poppler_document_new_from_file( viewer->fsname, NULL, &error);
1325                 }
1326
1327                 viewer->num_pages = poppler_document_get_n_pages(viewer->pdf_doc);
1328
1329                 g_signal_handlers_block_by_func(G_OBJECT(viewer->cur_page), pdf_viewer_spin_change_page_cb,(gpointer *)viewer);
1330                 gtk_spin_button_set_range(GTK_SPIN_BUTTON(viewer->cur_page), 
1331                                                                         1, 
1332                                                                 (gdouble)viewer->num_pages );
1333
1334                 g_signal_handlers_unblock_by_func(G_OBJECT(viewer->cur_page), pdf_viewer_spin_change_page_cb,(gpointer *)viewer);
1335                 gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_HOME, 1);
1336                 tmp = g_strdup_printf(_("%s Document"),pdf_viewer_mimepart_get_type(viewer->to_load) == TYPE_PDF ? "PDF":"Postscript");
1337                 CLAWS_SET_TIP(
1338                                 GTK_WIDGET(viewer->icon_type_ebox),
1339                                 tmp);
1340                 g_free(tmp);
1341
1342                 tmp = g_strdup_printf(_("of %d"), viewer->num_pages);
1343                 gtk_label_set_text(GTK_LABEL(viewer->doc_label), tmp);
1344                 g_free(tmp);
1345
1346                 pdf_viewer_show_controls(viewer, TRUE);
1347                 main_window_cursor_normal(mainwindow_get_mainwindow());
1348         } 
1349         if (viewer->pdf_doc == NULL) {
1350                 stock_pixbuf_gdk(viewer->hbox, 
1351                                 STOCK_PIXMAP_MIME_APPLICATION, 
1352                                 &viewer->icon_pixbuf);
1353
1354                 gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type), viewer->icon_pixbuf);
1355                 if (error) {
1356                         strretchomp(error->message);
1357                         alertpanel_error("%s", error->message);
1358                 } else {
1359                         alertpanel_error(_("PDF rendering failed for an unknown reason."));
1360                 }
1361                 pdf_viewer_show_controls(viewer, FALSE);
1362                 g_error_free(error);
1363                 return;
1364         }
1365
1366         if (page_num == 1) { 
1367                 gtk_widget_set_sensitive(viewer->first_page, FALSE);
1368                 gtk_widget_set_sensitive(viewer->prev_page, FALSE);
1369         }
1370         else {
1371                 gtk_widget_set_sensitive(viewer->first_page, TRUE);
1372                 gtk_widget_set_sensitive(viewer->prev_page, TRUE);
1373         }
1374
1375         if (page_num == viewer->num_pages) { 
1376                 gtk_widget_set_sensitive(viewer->last_page, FALSE);
1377                 gtk_widget_set_sensitive(viewer->next_page, FALSE);
1378         }
1379         else {
1380                 gtk_widget_set_sensitive(viewer->last_page, TRUE);
1381                 gtk_widget_set_sensitive(viewer->next_page, TRUE);
1382         }
1383
1384         /* check for the index if exists */
1385         pdf_viewer_set_index_button_sensitive((PdfViewer *) viewer);
1386
1387         if (page_num > 0 && page_num <= viewer->num_pages) {
1388
1389                 GTK_EVENTS_FLUSH();
1390
1391                 if (viewer->pdf_page) {
1392                         g_object_unref(G_OBJECT(viewer->pdf_page));
1393                 }
1394
1395                 viewer->pdf_page = poppler_document_get_page(viewer->pdf_doc, page_num - 1);
1396
1397                 if (viewer->pdf_page == NULL) {
1398                         g_warning("Page not found\n");
1399                         return;
1400                 }   
1401
1402                 if (viewer->rotate == 90 || viewer->rotate == 270) {
1403                         poppler_page_get_size(viewer->pdf_page, &viewer->height, &viewer->width);
1404                 } 
1405                 else {
1406                         poppler_page_get_size(viewer->pdf_page, &viewer->width, &viewer->height);
1407                 }
1408
1409                 if (viewer->last_rect && viewer->last_page_result &&
1410                     viewer->last_page_result->page_num == page_num) {
1411                         pdf_viewer_render_selection(viewer, viewer->last_rect, viewer->last_page_result);
1412                 }
1413                 else {
1414                         pdf_viewer_render_page(viewer->pdf_page, viewer->pdf_view, viewer->width, 
1415                                                                         viewer->height, viewer->zoom, viewer->rotate);
1416
1417                 }
1418
1419         /* Get Links Mapping */
1420         if (viewer->link_map) {
1421                 poppler_page_free_link_mapping(viewer->link_map);
1422         }
1423         viewer->link_map = poppler_page_get_link_mapping(viewer->pdf_page);
1424
1425         }
1426 }
1427
1428
1429 static void pdf_viewer_show_mimepart(MimeViewer *_viewer, const gchar *infile,
1430                                 MimeInfo *partinfo)
1431 {
1432         PdfViewer *viewer = (PdfViewer *) _viewer;
1433         gchar buf[4096];
1434         const gchar *charset = NULL;
1435         MessageView *messageview = ((MimeViewer *)viewer)->mimeview 
1436                                         ?((MimeViewer *)viewer)->mimeview->messageview 
1437                                         : NULL;
1438
1439         viewer->rotate = 0;
1440         viewer->to_load = partinfo;
1441
1442         if (messageview)
1443                 messageview->updating = TRUE;
1444
1445         memset(buf, 0, sizeof(buf));
1446         debug_print("pdf_viewer_show_mimepart\n");
1447
1448         if (viewer->filename != NULL) {
1449                 claws_unlink(viewer->filename);
1450                 g_free(viewer->filename);
1451                 viewer->filename = NULL;
1452         }
1453
1454         viewer->mimeinfo = NULL;
1455
1456         if (partinfo) {
1457                 viewer->target_filename = procmime_get_part_file_name(partinfo);
1458                 viewer->filename = procmime_get_tmp_file_name(partinfo);
1459                 viewer->fsname = g_filename_to_uri(viewer->filename, NULL, NULL);
1460         }
1461
1462         if (partinfo && !(procmime_get_part(viewer->filename, partinfo) < 0)) {
1463
1464                 if (messageview && messageview->forced_charset)
1465                         charset = _viewer->mimeview->messageview->forced_charset;
1466                 else
1467                         charset = procmime_mimeinfo_get_parameter(partinfo, "charset");
1468
1469                 if (charset == NULL) {
1470                         charset = conv_get_locale_charset_str();
1471                 }
1472
1473                 debug_print("using charset %s\n", charset);
1474
1475                 viewer->mimeinfo = partinfo;
1476         }
1477
1478         pdf_viewer_update((MimeViewer *)viewer, TRUE, 1);
1479
1480         messageview->updating = FALSE;
1481 }
1482
1483 static void pdf_viewer_clear(MimeViewer *_viewer)
1484 {
1485         PdfViewer *viewer = (PdfViewer *) _viewer;
1486         GtkAdjustment *vadj;
1487
1488         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(viewer->doc_index), FALSE);
1489         gtk_widget_hide(viewer->frame_index);
1490
1491         debug_print("pdf_viewer_clear\n");
1492         viewer->to_load = NULL;
1493
1494         if (viewer->pdf_doc) {
1495                 g_object_unref(G_OBJECT(viewer->pdf_doc));
1496                 viewer->pdf_doc = NULL;
1497         }
1498
1499         vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
1500         vadj->value = 0.0;
1501         g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);
1502         vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin_index));
1503         vadj->value = 0.0;
1504         g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);
1505         gtk_tree_store_clear(GTK_TREE_STORE(viewer->index_model));
1506         gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->pdf_view), NULL);
1507 }
1508
1509 static void pdf_viewer_destroy(MimeViewer *_viewer)
1510 {
1511         PdfViewer *viewer = (PdfViewer *) _viewer;
1512
1513         debug_print("pdf_viewer_destroy\n");
1514
1515         if (viewer->pdf_index) poppler_index_iter_free(viewer->pdf_index);
1516
1517         poppler_page_free_link_mapping (viewer->link_map);
1518         g_object_unref(GTK_WIDGET(viewer->vbox));
1519         g_object_unref(GTK_WIDGET(viewer->pdf_view));
1520         g_object_unref(GTK_WIDGET(viewer->doc_index_pane));
1521         g_object_unref(GTK_WIDGET(viewer->scrollwin));
1522         g_object_unref(GTK_WIDGET(viewer->scrollwin_index));
1523         claws_unlink(viewer->filename);
1524         g_free(viewer->filename);
1525         g_free(viewer);
1526 }
1527
1528 static gboolean pdf_viewer_scroll_page(MimeViewer *_viewer, gboolean up)
1529 {
1530         PdfViewer *viewer = (PdfViewer *)_viewer;
1531         GtkAdjustment *vadj = gtk_scrolled_window_get_vadjustment(
1532                                 GTK_SCROLLED_WINDOW(viewer->scrollwin));
1533
1534         gint cur_p = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page));
1535
1536         if (viewer->pdf_view == NULL) return FALSE;
1537
1538         if (!gtkutils_scroll_page(GTK_WIDGET(viewer->pdf_view), vadj, up)) {
1539                 if (!up && cur_p != viewer->num_pages) {
1540                         gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_FORWARD, 1);
1541                         vadj = gtk_scrolled_window_get_vadjustment(
1542                                         GTK_SCROLLED_WINDOW(viewer->scrollwin));
1543                         vadj->value = 0.0;
1544                         g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);
1545                         return TRUE;
1546                 } 
1547                 else if (up && cur_p != 1) {
1548                         gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_BACKWARD, 1);
1549                         vadj = gtk_scrolled_window_get_vadjustment(
1550                                         GTK_SCROLLED_WINDOW(viewer->scrollwin));
1551                         vadj->value = vadj->upper - vadj->page_size;
1552                         g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);
1553                         return TRUE;
1554                 } 
1555                 return FALSE;
1556         } 
1557         else return TRUE;
1558 }
1559
1560 static void pdf_viewer_scroll_one_line(MimeViewer *_viewer, gboolean up)
1561 {
1562         PdfViewer *viewer = (PdfViewer *)_viewer;
1563         GtkAdjustment *vadj = gtk_scrolled_window_get_vadjustment(
1564                                 GTK_SCROLLED_WINDOW(viewer->scrollwin));
1565         gint cur_p;
1566         cur_p = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page));
1567
1568         if (viewer->pdf_view == NULL) return; 
1569                 debug_print("up: %d\n", up);    
1570                 if (vadj->value <(vadj->upper - vadj->page_size))  {
1571                         gtkutils_scroll_one_line(GTK_WIDGET(viewer->pdf_view), vadj, up);
1572                 }
1573                 else {
1574                         if (cur_p != viewer->num_pages) {
1575                                 pdf_viewer_scroll_page((MimeViewer *)viewer, up);
1576                         }
1577                 }
1578
1579 }
1580
1581 #define BUTTON_H_PADDING 3
1582 #define ADD_BUTTON_TO_TABLE(widget, stock_image) \
1583         widget = gtk_button_new(); \
1584         img = gtk_image_new_from_stock(stock_image, GTK_ICON_SIZE_MENU); \
1585         gtk_button_set_image(GTK_BUTTON(widget), img); \
1586         gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(widget), \
1587                                 col, col+1, 0, 1, 0, 0, BUTTON_H_PADDING, 0); \
1588         col++;
1589
1590 #define ADD_SEP_TO_TABLE \
1591         sep = gtk_label_new(""); \
1592         gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(sep), \
1593                                         col, col+1, 0, 1, 0, 0, 0, 0); \
1594         gtk_table_set_col_spacing(GTK_TABLE(viewer->widgets_table), col, 3*BUTTON_H_PADDING); \
1595         col++;
1596
1597 #if GTK_CHECK_VERSION(2,10,0) && POPPLER_HAS_CAIRO && !USE_LIBGNOMEPRINT
1598 static PangoContext *pdf_viewer_get_pango_context(gpointer data)
1599 {
1600         return NULL;
1601 }
1602
1603 static gpointer pdf_viewer_get_data_to_print(gpointer data, gint sel_start, gint sel_end)
1604 {
1605         return NULL; /* we don't need it */
1606 }
1607
1608 static void pdf_viewer_cb_begin_print(GtkPrintOperation *op, GtkPrintContext *context,
1609                            gpointer user_data)
1610 {
1611   PrintData *print_data;
1612   PopplerDocument *pdf_doc;
1613   gint n_pages = 0;
1614   print_data = (PrintData*) user_data;
1615   pdf_doc = (PopplerDocument *)printing_get_renderer_data(print_data);
1616
1617   debug_print("Preparing print job...\n");
1618
1619   n_pages = poppler_document_get_n_pages(pdf_doc);
1620   printing_set_n_pages(print_data, n_pages);
1621   gtk_print_operation_set_n_pages(op, n_pages);
1622
1623   debug_print("Starting print job...\n");
1624 }
1625
1626 static void pdf_viewer_cb_draw_page(GtkPrintOperation *op, GtkPrintContext *context,
1627                          int page_nr, gpointer user_data)
1628 {
1629   cairo_t *cr;
1630   PrintData *print_data;
1631   PopplerDocument *pdf_doc;
1632   PopplerPage *pdf_page;
1633   
1634   print_data = (PrintData*) user_data;
1635   pdf_doc = (PopplerDocument *)printing_get_renderer_data(print_data);
1636   pdf_page = poppler_document_get_page(pdf_doc, page_nr);
1637
1638   cr = gtk_print_context_get_cairo_context(context);
1639   cairo_scale(cr, printing_get_zoom(print_data), printing_get_zoom(print_data));
1640   cairo_set_source_rgb(cr, 0., 0., 0.);
1641
1642   poppler_page_render_for_printing(pdf_page, cr);
1643
1644   g_object_unref(G_OBJECT(pdf_page));
1645
1646   debug_print("Sent page %d to printer\n", page_nr+1);
1647 }
1648
1649 static void pdf_viewer_print(MimeViewer *mviewer)
1650 {
1651         PdfViewer *viewer = (PdfViewer *)mviewer;
1652         PrintRenderer *pdf_renderer = g_new0(PrintRenderer, 1);
1653         MainWindow *mainwin = mainwindow_get_mainwindow();
1654
1655         pdf_renderer->get_pango_context = pdf_viewer_get_pango_context;
1656         pdf_renderer->get_data_to_print = pdf_viewer_get_data_to_print;
1657         pdf_renderer->cb_begin_print    = pdf_viewer_cb_begin_print;
1658         pdf_renderer->cb_draw_page      = pdf_viewer_cb_draw_page;
1659
1660         printing_print_full(mainwin ? GTK_WINDOW(mainwin->window):NULL,
1661                         pdf_renderer, viewer->pdf_doc, -1, -1, NULL);
1662
1663         g_free(pdf_renderer);
1664 }
1665 #endif
1666
1667 static MimeViewer *pdf_viewer_create(void)
1668 {
1669         PdfViewer *viewer;
1670         GtkTreeViewColumn *column;
1671         GtkCellRenderer *renderer;
1672         GtkTreeStore *tree_store;
1673         GtkWidget *sep;
1674         GtkWidget *img;
1675         gint col = 0;
1676
1677         viewer = g_new0(PdfViewer, 1);
1678         debug_print("pdf_viewer_create\n");
1679     
1680         viewer->last_x = 0;
1681         viewer->last_y = 0;
1682         viewer->mimeviewer.factory = &pdf_viewer_factory;
1683         viewer->mimeviewer.get_widget = pdf_viewer_get_widget;
1684         viewer->mimeviewer.show_mimepart = pdf_viewer_show_mimepart;
1685         viewer->mimeviewer.clear_viewer = pdf_viewer_clear;
1686         viewer->mimeviewer.destroy_viewer = pdf_viewer_destroy;
1687         viewer->mimeviewer.text_search = pdf_viewer_text_search;
1688         viewer->mimeviewer.scroll_page = pdf_viewer_scroll_page;
1689         viewer->mimeviewer.scroll_one_line = pdf_viewer_scroll_one_line;
1690 #if GTK_CHECK_VERSION(2,10,0) && POPPLER_HAS_CAIRO && !USE_LIBGNOMEPRINT
1691         viewer->mimeviewer.print = pdf_viewer_print;
1692 #endif
1693         viewer->scrollwin = gtk_scrolled_window_new(NULL, NULL);
1694         viewer->scrollwin_index = gtk_scrolled_window_new(NULL, NULL);
1695         viewer->pdf_view_ebox = gtk_event_box_new();
1696         gtk_event_box_set_visible_window(GTK_EVENT_BOX(viewer->pdf_view_ebox), FALSE);
1697
1698         viewer->mimeinfo  = NULL;
1699
1700         viewer->pdf_view = gtk_image_new();
1701         gtk_widget_set_events(viewer->pdf_view_ebox,
1702                                                 GDK_BUTTON_RELEASE_MASK
1703                                                 | GDK_POINTER_MOTION_MASK
1704                                                 | GDK_BUTTON_PRESS_MASK
1705                                                 | GDK_BUTTON_MOTION_MASK
1706                                             );
1707         gtk_container_add (GTK_CONTAINER(viewer->pdf_view_ebox), viewer->pdf_view);
1708         viewer->icon_type = gtk_image_new();
1709         viewer->icon_type_ebox = gtk_event_box_new();
1710
1711         gtk_container_add(GTK_CONTAINER(viewer->icon_type_ebox), viewer->icon_type);
1712
1713         viewer->doc_label = gtk_label_new("");
1714
1715         viewer->widgets_table = gtk_table_new(1, 1, FALSE);
1716
1717         viewer->doc_index_pane = gtk_hpaned_new();
1718
1719         viewer->frame_index = gtk_frame_new(NULL);
1720         gtk_frame_set_shadow_type(GTK_FRAME(viewer->frame_index), GTK_SHADOW_IN);
1721         gtk_widget_set_size_request(viewer->frame_index, 18, -1);
1722         gtk_frame_set_label(GTK_FRAME(viewer->frame_index), _("Document Index"));
1723
1724 #if !(GTK_CHECK_VERSION(2,12,0))
1725         viewer->button_bar_tips = tips;
1726 #endif
1727
1728         ADD_SEP_TO_TABLE
1729         ADD_BUTTON_TO_TABLE(viewer->first_page, GTK_STOCK_GOTO_FIRST)
1730         ADD_BUTTON_TO_TABLE(viewer->prev_page, GTK_STOCK_GO_BACK)
1731         viewer->cur_page = gtk_spin_button_new_with_range(0.0, 0.0, 1.0);
1732         viewer->zoom_scroll = gtk_spin_button_new_with_range(0.20, 8.0, 0.20);
1733         gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->zoom_scroll), 1.0);
1734         viewer->zoom = 1.0;
1735         gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(viewer->cur_page), TRUE);
1736         gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(viewer->zoom_scroll), TRUE);
1737         gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(viewer->cur_page),
1738                                         col, col+1, 
1739                                         0, 1, 0, 0, 
1740                                         BUTTON_H_PADDING, 
1741                                         0);
1742         col++;
1743         gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(viewer->doc_label),
1744                                         col, col+1, 
1745                                         0, 1, 0, 0, 
1746                                         BUTTON_H_PADDING, 
1747                                         0);
1748         col++;
1749
1750         ADD_BUTTON_TO_TABLE(viewer->next_page, GTK_STOCK_GO_FORWARD)
1751         ADD_BUTTON_TO_TABLE(viewer->last_page, GTK_STOCK_GOTO_LAST)
1752         ADD_SEP_TO_TABLE
1753         ADD_BUTTON_TO_TABLE(viewer->zoom_fit, GTK_STOCK_ZOOM_FIT)
1754         ADD_BUTTON_TO_TABLE(viewer->zoom_in, GTK_STOCK_ZOOM_IN)
1755         gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(viewer->zoom_scroll),
1756                                         col, col+1, 
1757                                         0, 1, 0, 0, 
1758                                         BUTTON_H_PADDING, 
1759                                         0);
1760         col++;
1761         ADD_BUTTON_TO_TABLE(viewer->zoom_out, GTK_STOCK_ZOOM_OUT)
1762         ADD_BUTTON_TO_TABLE(viewer->zoom_width, GTK_STOCK_FULLSCREEN)
1763         ADD_SEP_TO_TABLE
1764         ADD_BUTTON_TO_TABLE(viewer->rotate_left, GTK_STOCK_UNDO)
1765         ADD_BUTTON_TO_TABLE(viewer->rotate_right, GTK_STOCK_REDO)
1766         ADD_SEP_TO_TABLE
1767         ADD_BUTTON_TO_TABLE(viewer->doc_info, GTK_STOCK_INFO)
1768
1769         viewer->doc_index = GTK_WIDGET(gtk_toggle_tool_button_new_from_stock(GTK_STOCK_INDEX));
1770         gtk_widget_set_size_request(GTK_WIDGET(viewer->doc_index), 26, 26);
1771         gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(viewer->doc_index),
1772                                         col, col+1, 
1773                                         0, 1, 0, 0, 
1774                                         BUTTON_H_PADDING, 
1775                                         0);
1776         col++;
1777
1778         gtk_scrolled_window_set_policy(
1779                         GTK_SCROLLED_WINDOW(viewer->scrollwin), 
1780                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1781
1782         gtk_scrolled_window_set_shadow_type(
1783                         GTK_SCROLLED_WINDOW(viewer->scrollwin),
1784                         GTK_SHADOW_IN);
1785
1786         gtk_scrolled_window_add_with_viewport(
1787                         GTK_SCROLLED_WINDOW(viewer->scrollwin),
1788                         viewer->pdf_view_ebox);
1789
1790         viewer->vbox = gtk_vbox_new(FALSE, 4);
1791         viewer->hbox = gtk_hbox_new(FALSE, 4);
1792
1793     /* treeview */
1794         tree_store = gtk_tree_store_new(N_INDEX_COLUMNS,
1795                                         G_TYPE_STRING,
1796                                         G_TYPE_INT,
1797                                         G_TYPE_DOUBLE);
1798
1799         viewer->index_list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(tree_store));
1800         renderer = gtk_cell_renderer_text_new();
1801         column = gtk_tree_view_column_new_with_attributes(_("Name"),  renderer, "text", 0,  NULL);
1802         gtk_tree_view_append_column(GTK_TREE_VIEW(viewer->index_list), column);         
1803         gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(viewer->index_list), FALSE);
1804
1805         viewer->index_model = GTK_TREE_MODEL(tree_store);
1806
1807         gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(viewer->index_list)), 
1808                                                                 GTK_SELECTION_SINGLE);
1809
1810         g_signal_connect(G_OBJECT(viewer->index_list), "row_activated",
1811                          G_CALLBACK(pdf_viewer_index_row_activated),
1812                                          viewer);
1813
1814         gtk_scrolled_window_set_policy(
1815                         GTK_SCROLLED_WINDOW(viewer->scrollwin_index), 
1816                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1817
1818         gtk_scrolled_window_set_shadow_type(
1819                         GTK_SCROLLED_WINDOW(viewer->scrollwin_index),
1820                         GTK_SHADOW_IN);
1821
1822         gtk_scrolled_window_add_with_viewport(
1823                         GTK_SCROLLED_WINDOW(viewer->scrollwin_index),
1824                         viewer->index_list);
1825
1826         /* end treeview */
1827
1828         stock_pixbuf_gdk(viewer->hbox, 
1829                         STOCK_PIXMAP_MIME_TEXT_PLAIN, 
1830                         &viewer->icon_pixbuf);
1831
1832         gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type), 
1833                                 viewer->icon_pixbuf);
1834
1835         /* pack widgets*/
1836         gtk_box_pack_start(GTK_BOX(viewer->hbox), viewer->icon_type_ebox, FALSE, FALSE, 0);
1837         gtk_box_pack_start(GTK_BOX(viewer->hbox), viewer->widgets_table, FALSE, FALSE, 0);
1838
1839         gtk_container_add(GTK_CONTAINER(viewer->frame_index), viewer->scrollwin_index);
1840
1841         gtk_paned_pack1(GTK_PANED(viewer->doc_index_pane), viewer->frame_index, FALSE, FALSE);
1842         gtk_paned_pack2(GTK_PANED(viewer->doc_index_pane), viewer->scrollwin, FALSE, FALSE);
1843
1844         gtk_box_pack_start(GTK_BOX(viewer->vbox), viewer->hbox, FALSE, FALSE, 0);
1845         gtk_box_pack_start(GTK_BOX(viewer->vbox), viewer->doc_index_pane, TRUE, TRUE, 0);
1846         /* show widgets */
1847         gtk_widget_show(GTK_WIDGET(viewer->doc_index_pane));
1848         g_object_ref(GTK_WIDGET(viewer->doc_index_pane));
1849         gtk_widget_show(GTK_WIDGET(viewer->scrollwin));
1850         g_object_ref(GTK_WIDGET(viewer->scrollwin));
1851         gtk_widget_show(GTK_WIDGET(viewer->icon_type_ebox));
1852         g_object_ref(GTK_WIDGET(viewer->icon_type_ebox));
1853         gtk_widget_show(GTK_WIDGET(viewer->pdf_view_ebox));
1854         g_object_ref(GTK_WIDGET(viewer->pdf_view_ebox));
1855         gtk_widget_show(GTK_WIDGET(viewer->scrollwin_index));
1856         g_object_ref(GTK_WIDGET(viewer->scrollwin_index));
1857         gtk_widget_show(GTK_WIDGET(viewer->hbox));
1858         g_object_ref(GTK_WIDGET(viewer->hbox)); 
1859         gtk_widget_show(GTK_WIDGET(viewer->vbox));
1860         g_object_ref(GTK_WIDGET(viewer->vbox));
1861
1862         gtk_widget_show(GTK_WIDGET(viewer->widgets_table));
1863         g_object_ref(GTK_WIDGET(viewer->widgets_table));
1864
1865         gtk_widget_show(GTK_WIDGET(viewer->cur_page));
1866         g_object_ref(GTK_WIDGET(viewer->cur_page));
1867
1868         gtk_widget_show(GTK_WIDGET(viewer->first_page));
1869         g_object_ref(GTK_WIDGET(viewer->first_page));
1870
1871         gtk_widget_show(GTK_WIDGET(viewer->last_page));
1872         g_object_ref(GTK_WIDGET(viewer->last_page));
1873
1874         gtk_widget_show(GTK_WIDGET(viewer->prev_page));
1875         g_object_ref(GTK_WIDGET(viewer->prev_page));
1876
1877         gtk_widget_show(GTK_WIDGET(viewer->next_page));
1878         g_object_ref(GTK_WIDGET(viewer->next_page));
1879
1880         gtk_widget_show(GTK_WIDGET(viewer->zoom_in));
1881         g_object_ref(GTK_WIDGET(viewer->zoom_in));
1882         gtk_widget_show(GTK_WIDGET(viewer->zoom_out));
1883         g_object_ref(GTK_WIDGET(viewer->zoom_out));
1884         gtk_widget_show(GTK_WIDGET(viewer->zoom_fit));
1885         g_object_ref(GTK_WIDGET(viewer->zoom_fit));
1886         gtk_widget_show(GTK_WIDGET(viewer->zoom_width));
1887         g_object_ref(GTK_WIDGET(viewer->zoom_width));
1888
1889         gtk_widget_show(GTK_WIDGET(viewer->rotate_right));
1890         g_object_ref(GTK_WIDGET(viewer->rotate_right));
1891         gtk_widget_show(GTK_WIDGET(viewer->rotate_left));
1892         g_object_ref(GTK_WIDGET(viewer->rotate_left));
1893         gtk_widget_show(GTK_WIDGET(viewer->doc_info));
1894         g_object_ref(GTK_WIDGET(viewer->doc_info));
1895         gtk_widget_show(GTK_WIDGET(viewer->doc_index));
1896         g_object_ref(GTK_WIDGET(viewer->doc_index));
1897
1898         gtk_widget_show(GTK_WIDGET(viewer->doc_label));
1899         g_object_ref(GTK_WIDGET(viewer->doc_label));
1900         gtk_widget_show(GTK_WIDGET(viewer->icon_type));
1901         g_object_ref(GTK_WIDGET(viewer->icon_type));    
1902         gtk_widget_show(GTK_WIDGET(viewer->pdf_view));
1903         g_object_ref(GTK_WIDGET(viewer->pdf_view));
1904         gtk_widget_show(GTK_WIDGET(viewer->zoom_scroll));
1905         g_object_ref(GTK_WIDGET(viewer->zoom_scroll));
1906
1907         gtk_widget_show(GTK_WIDGET(viewer->index_list));
1908         g_object_ref(GTK_WIDGET(viewer->index_list));
1909
1910         /* Set Tooltips*/
1911         CLAWS_SET_TIP(viewer->first_page,
1912                                 _("First Page"));
1913
1914         CLAWS_SET_TIP(viewer->prev_page,
1915                                 _("Previous Page"));
1916
1917         CLAWS_SET_TIP(viewer->next_page,
1918                                 _("Next Page"));
1919
1920         CLAWS_SET_TIP(viewer->last_page,
1921                                 _("Last Page"));
1922
1923         CLAWS_SET_TIP(viewer->zoom_in,
1924                                 _("Zoom In"));
1925         CLAWS_SET_TIP(viewer->zoom_out,
1926                                 _("Zoom Out"));
1927
1928         CLAWS_SET_TIP(viewer->zoom_fit,
1929                                 _("Fit Page"));
1930
1931         CLAWS_SET_TIP(viewer->zoom_width,
1932                                 _("Fit Page Width"));
1933
1934         CLAWS_SET_TIP(viewer->rotate_left,
1935                                 _("Rotate Left"));
1936
1937         CLAWS_SET_TIP(viewer->rotate_right,
1938                                 _("Rotate Right"));
1939
1940         CLAWS_SET_TIP(viewer->doc_info,
1941                                 _("Document Info"));
1942
1943         CLAWS_SET_TIP(viewer->doc_index,
1944                                 _("Document Index"));
1945         CLAWS_SET_TIP(viewer->cur_page,
1946                                 _("Page Number"));
1947         CLAWS_SET_TIP(viewer->zoom_scroll,
1948                                 _("Zoom Factor"));
1949         /* Connect Signals */
1950         g_signal_connect(G_OBJECT(viewer->cur_page), 
1951                                     "value-changed", 
1952                                     G_CALLBACK(pdf_viewer_spin_change_page_cb), 
1953                                    (gpointer) viewer);
1954
1955         g_signal_connect(G_OBJECT(viewer->first_page), 
1956                                     "clicked", 
1957                                     G_CALLBACK(pdf_viewer_button_first_page_cb), 
1958                                    (gpointer) viewer);
1959         g_signal_connect(G_OBJECT(viewer->prev_page), 
1960                                     "clicked", 
1961                                     G_CALLBACK(pdf_viewer_button_prev_page_cb), 
1962                                    (gpointer) viewer);
1963         g_signal_connect(G_OBJECT(viewer->next_page), 
1964                                     "clicked", 
1965                                     G_CALLBACK(pdf_viewer_button_next_page_cb), 
1966                                    (gpointer) viewer);
1967         g_signal_connect(G_OBJECT(viewer->last_page), 
1968                                     "clicked", 
1969                                     G_CALLBACK(pdf_viewer_button_last_page_cb), 
1970                                    (gpointer) viewer);
1971         g_signal_connect(G_OBJECT(viewer->zoom_in), 
1972                                     "clicked", 
1973                                     G_CALLBACK(pdf_viewer_button_zoom_in_cb), 
1974                                    (gpointer) viewer);
1975         g_signal_connect(G_OBJECT(viewer->zoom_out), 
1976                                     "clicked", 
1977                                     G_CALLBACK(pdf_viewer_button_zoom_out_cb), 
1978                                    (gpointer) viewer);
1979         g_signal_connect(G_OBJECT(viewer->zoom_scroll), 
1980                                     "value-changed", 
1981                                     G_CALLBACK(pdf_viewer_spin_zoom_scroll_cb), 
1982                                    (gpointer) viewer);
1983
1984         g_signal_connect(G_OBJECT(viewer->zoom_fit), 
1985                                    "clicked", 
1986                                     G_CALLBACK(pdf_viewer_button_zoom_fit_cb), 
1987                                    (gpointer) viewer);
1988
1989         g_signal_connect(G_OBJECT(viewer->zoom_width), 
1990                                     "clicked", 
1991                                     G_CALLBACK(pdf_viewer_button_zoom_width_cb), 
1992                                    (gpointer) viewer);
1993
1994         g_signal_connect(G_OBJECT(viewer->rotate_right), 
1995                                     "clicked", 
1996                                     G_CALLBACK(pdf_viewer_button_rotate_right_cb), 
1997                                    (gpointer) viewer);
1998
1999         g_signal_connect(G_OBJECT(viewer->rotate_left), 
2000                                     "clicked", 
2001                                     G_CALLBACK(pdf_viewer_button_rotate_left_cb), 
2002                                    (gpointer) viewer);
2003
2004         g_signal_connect(G_OBJECT(viewer->doc_info), 
2005                                     "clicked", 
2006                                     G_CALLBACK(pdf_viewer_button_document_info_cb), 
2007                                    (gpointer) viewer);  
2008
2009         g_signal_connect(G_OBJECT(viewer->doc_index), 
2010                                     "clicked", 
2011                                     G_CALLBACK(pdf_viewer_show_document_index_cb), 
2012                                    (gpointer) viewer);
2013         g_signal_connect(G_OBJECT(viewer->scrollwin), 
2014                                     "scroll-event", 
2015                                     G_CALLBACK(pdf_viewer_scroll_cb), 
2016                                    (gpointer) viewer);
2017         g_signal_connect(G_OBJECT(viewer->pdf_view_ebox), 
2018                                     "button_press_event", 
2019                                     G_CALLBACK(pdf_viewer_button_press_events_cb), 
2020                                    (gpointer) viewer);
2021         g_signal_connect(G_OBJECT(viewer->pdf_view_ebox), 
2022                                     "button_release_event", 
2023                                     G_CALLBACK(pdf_viewer_mouse_scroll_destroy_cb), 
2024                                    (gpointer) viewer);
2025         g_signal_connect(G_OBJECT(viewer->pdf_view_ebox), 
2026                                     "motion_notify_event", 
2027                                     G_CALLBACK(pdf_viewer_move_events_cb), 
2028                                    (gpointer) viewer);
2029
2030         viewer->target_filename = NULL;
2031         viewer->filename = NULL;
2032         viewer->fsname = NULL;
2033
2034         return(MimeViewer *) viewer;
2035 }
2036
2037 #undef ADD_BUTTON_TO_TABLE
2038 #undef ADD_SEP_TO_TABLE
2039 #undef BUTTON_H_PADDING
2040 #undef SEP_H_PADDING
2041
2042 static MimeViewerFactory pdf_viewer_factory =
2043 {
2044         content_types,
2045         0,
2046         pdf_viewer_create,
2047 };
2048
2049 gint plugin_init(gchar **error)
2050 {
2051         gchar *gspath = NULL;
2052
2053         msg = g_strdup_printf(_("This plugin enables the viewing of PDF and PostScript "
2054                                 "attachments using the Poppler %s Lib and the gs tool.\n\n"
2055                                 "Any feedback is welcome: iwkse@claws-mail.org"
2056                                 ), poppler_get_version());
2057
2058         if (!check_plugin_version(MAKE_NUMERIC_VERSION(3,8,1,46),
2059                     VERSION_NUMERIC, _("PDF Viewer"), error)) return -1;
2060
2061         if ((gspath = g_find_program_in_path("gs")) == NULL) {
2062                 gchar *pmsg = msg;
2063                 msg = g_strdup_printf(_("Warning: could not find ghostscript binary (gs) required "
2064                                         "for %s plugin to process PostScript attachments, only PDF "
2065                                         "attachments will be displayed. To enable PostScript "
2066                                         "support please install gs program.\n\n%s"
2067                                         ), _("PDF Viewer"), pmsg);
2068                 g_free(pmsg);
2069         }
2070         else {
2071                 g_free(gspath);
2072         }
2073
2074         mimeview_register_viewer_factory(&pdf_viewer_factory);
2075         return 0;
2076 }
2077
2078 gboolean plugin_done(void)
2079 {
2080         g_free(msg);    
2081         mimeview_unregister_viewer_factory(&pdf_viewer_factory);
2082         return TRUE;
2083 }
2084
2085 const gchar *plugin_name(void)
2086 {
2087         return _("PDF Viewer");
2088 }
2089
2090 const gchar *plugin_desc(void)
2091 {
2092         return msg;
2093 }
2094
2095 const gchar *plugin_type(void)
2096 {
2097         return "GTK2";
2098 }
2099
2100 const gchar *plugin_licence(void)
2101 {
2102         return "GPL3+";
2103 }
2104
2105 const gchar *plugin_version(void)
2106 {
2107         return VERSION;
2108 }
2109
2110 struct PluginFeature *plugin_provides(void)
2111 {
2112         static struct PluginFeature features[] = 
2113                 { {PLUGIN_MIMEVIEWER, "application/pdf"},
2114                   {PLUGIN_MIMEVIEWER, "application/postscript"},
2115                   {PLUGIN_NOTHING, NULL} };
2116         return features;
2117 }
2118