~ubuntu-branches/ubuntu/trusty/evince/trusty-proposed

« back to all changes in this revision

Viewing changes to ps/ps-document.c

Tags: upstream-0.7.0
ImportĀ upstreamĀ versionĀ 0.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
#include "ps-document.h"
47
47
#include "ev-debug.h"
48
48
#include "gsdefaults.h"
49
 
#include "ev-ps-exporter.h"
 
49
#include "ev-file-exporter.h"
50
50
#include "ev-async-renderer.h"
51
51
 
52
52
#define MAX_BUFSIZE 1024
70
70
static gboolean broken_pipe = FALSE;
71
71
 
72
72
/* Forward declarations */
73
 
static void     ps_document_init                        (PSDocument           *gs);
74
 
static void     ps_document_class_init                  (PSDocumentClass      *klass);
75
 
static void     send_ps                                 (PSDocument           *gs,
76
 
                                                         long                  begin,
77
 
                                                         unsigned int          len,
78
 
                                                         gboolean              close);
79
 
static void     output                                  (gpointer              data,
80
 
                                                         gint                  source,
81
 
                                                         GdkInputCondition     condition);
82
 
static void     input                                   (gpointer              data,
83
 
                                                         gint                  source,
84
 
                                                         GdkInputCondition     condition);
85
 
static void     stop_interpreter                        (PSDocument           *gs);
86
 
static gint     start_interpreter                       (PSDocument           *gs);
87
 
static void     ps_document_document_iface_init         (EvDocumentIface      *iface);
88
 
static void     ps_document_ps_exporter_iface_init      (EvPSExporterIface    *iface);
89
 
static void     ps_async_renderer_iface_init            (EvAsyncRendererIface *iface);
 
73
static void     ps_document_init                        (PSDocument             *gs);
 
74
static void     ps_document_class_init                  (PSDocumentClass        *klass);
 
75
static void     send_ps                                 (PSDocument             *gs,
 
76
                                                         long                    begin,
 
77
                                                         unsigned int            len,
 
78
                                                         gboolean                close);
 
79
static void     output                                  (gpointer                data,
 
80
                                                         gint                    source,
 
81
                                                         GdkInputCondition       condition);
 
82
static void     input                                   (gpointer                data,
 
83
                                                         gint                    source,
 
84
                                                         GdkInputCondition       condition);
 
85
static void     stop_interpreter                        (PSDocument             *gs);
 
86
static gint     start_interpreter                       (PSDocument             *gs);
 
87
static void     ps_document_document_iface_init         (EvDocumentIface        *iface);
 
88
static void     ps_document_file_exporter_iface_init    (EvFileExporterIface    *iface);
 
89
static void     ps_async_renderer_iface_init            (EvAsyncRendererIface   *iface);
90
90
 
91
91
G_DEFINE_TYPE_WITH_CODE (PSDocument, ps_document, G_TYPE_OBJECT,
92
92
                         {
93
93
                                 G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,
94
94
                                                        ps_document_document_iface_init);
95
 
                                 G_IMPLEMENT_INTERFACE (EV_TYPE_PS_EXPORTER,
96
 
                                                        ps_document_ps_exporter_iface_init);
 
95
                                 G_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER,
 
96
                                                        ps_document_file_exporter_iface_init);
97
97
                                 G_IMPLEMENT_INTERFACE (EV_TYPE_ASYNC_RENDERER,
98
98
                                                        ps_async_renderer_iface_init);
99
99
                         });
294
294
        }
295
295
}
296
296
 
297
 
static float
298
 
get_xdpi (PSDocument *gs)
299
 
{
300
 
        return 25.4 * gdk_screen_width() / gdk_screen_width_mm();
301
 
}
302
 
 
303
 
static float
304
 
get_ydpi (PSDocument *gs)
305
 
{
306
 
        return 25.4 * gdk_screen_height() / gdk_screen_height_mm();
307
 
}
308
 
 
309
297
static void
310
298
setup_pixmap (PSDocument *gs, int page, double scale, int rotation)
311
299
{
447
435
setup_page (PSDocument *gs, int page, double scale, int rotation)
448
436
{
449
437
        gchar *buf;
450
 
        char scaled_xdpi[G_ASCII_DTOSTR_BUF_SIZE];      
451
 
        char scaled_ydpi[G_ASCII_DTOSTR_BUF_SIZE];
 
438
        char scaled_dpi[G_ASCII_DTOSTR_BUF_SIZE];       
452
439
        int urx, ury, llx, lly;
453
440
 
454
441
        LOG ("Setup the page");
455
442
 
456
443
        get_page_box (gs, page, &urx, &ury, &llx, &lly);
457
 
        g_ascii_dtostr (scaled_xdpi, G_ASCII_DTOSTR_BUF_SIZE, get_xdpi (gs) * scale);
458
 
        g_ascii_dtostr (scaled_ydpi, G_ASCII_DTOSTR_BUF_SIZE, get_ydpi (gs) * scale);
 
444
        g_ascii_dtostr (scaled_dpi, G_ASCII_DTOSTR_BUF_SIZE, 72.0 * scale);
459
445
 
460
446
        buf = g_strdup_printf ("%ld %d %d %d %d %d %s %s %d %d %d %d",
461
447
                               0L, rotation, llx, lly, urx, ury,
462
 
                               scaled_xdpi, scaled_ydpi,
 
448
                               scaled_dpi, scaled_dpi,
463
449
                               0, 0, 0, 0);
464
450
        LOG ("GS property %s", buf);
465
451
 
624
610
 
625
611
        char *argv[NUM_ARGS], *dir, *gv_env, *gs_path;
626
612
        char **gs_args, **alpha_args = NULL;
 
613
        char **gv_env_vars = NULL;
627
614
        int argc = 0, i;
628
615
 
629
616
        LOG ("Start the interpreter");
679
666
                return -1;
680
667
        }
681
668
 
682
 
        gv_env = g_strdup_printf ("GHOSTVIEW=%ld %ld",
 
669
        gv_env = g_strdup_printf ("GHOSTVIEW=%ld %ld;DISPLAY=%s",
683
670
                                  gdk_x11_drawable_get_xid (gs->pstarget),
684
 
                                  gdk_x11_drawable_get_xid (gs->bpixmap));
 
671
                                  gdk_x11_drawable_get_xid (gs->bpixmap),
 
672
                                  gdk_display_get_name (gdk_drawable_get_display (gs->pstarget)));
685
673
        LOG ("Launching ghostview with env %s", gv_env);
686
674
 
687
675
        gs->interpreter_pid = fork ();
717
705
                                }
718
706
                        }
719
707
 
720
 
                        putenv(gv_env);
 
708
                        gv_env_vars = g_strsplit (gv_env, ";", -1);
 
709
                        g_free (gv_env);
 
710
                        for (i = 0; gv_env_vars[i]; i++) {
 
711
                                putenv (gv_env_vars[i]);
 
712
                        }
721
713
 
722
714
                        /* change to directory where the input file is. This helps
723
715
                         * with postscript-files which include other files using
731
723
                        /* Notify error */
732
724
                        g_critical ("Unable to execute [%s]\n", argv[0]);
733
725
                        g_strfreev (gs_args);
734
 
                        g_free (gv_env);
735
726
                        g_strfreev (alpha_args);
 
727
                        g_strfreev (gv_env_vars);
736
728
                        _exit (1);
737
729
                        break;
738
730
                default:                     /* parent */
990
982
static gboolean
991
983
ps_document_next_page (PSDocument *gs)
992
984
{
993
 
        XEvent event;
 
985
        XEvent      event;
 
986
        GdkScreen  *screen;
 
987
        GdkDisplay *display;
 
988
        Display    *dpy;
994
989
 
995
990
        LOG ("Make ghostscript render next page");
996
991
 
1000
995
 
1001
996
        gs->busy = TRUE;
1002
997
 
 
998
        screen = gtk_window_get_screen (GTK_WINDOW (gs->target_window));
 
999
        display = gdk_screen_get_display (screen);
 
1000
        dpy = gdk_x11_display_get_xdisplay (display);
 
1001
 
1003
1002
        event.xclient.type = ClientMessage;
1004
 
        event.xclient.display = gdk_display;
 
1003
        event.xclient.display = dpy;
1005
1004
        event.xclient.window = gs->message_window;
1006
 
        event.xclient.message_type = gdk_x11_atom_to_xatom(gs_class->next_atom);
 
1005
        event.xclient.message_type =
 
1006
                gdk_x11_atom_to_xatom_for_display (display,
 
1007
                                                   gs_class->next_atom);
1007
1008
        event.xclient.format = 32;
1008
1009
 
1009
1010
        gdk_error_trap_push ();
1010
 
        XSendEvent (gdk_display, gs->message_window, FALSE, 0, &event);
 
1011
        XSendEvent (dpy, gs->message_window, FALSE, 0, &event);
1011
1012
        gdk_flush ();
1012
1013
        gdk_error_trap_pop ();
1013
1014
 
1212
1213
        PSDocument *gs = PS_DOCUMENT (document);
1213
1214
        int urx, ury, llx, lly;
1214
1215
 
1215
 
        get_page_box (PS_DOCUMENT (document), page, &urx, &ury, &llx, &lly);
 
1216
        get_page_box (gs, page, &urx, &ury, &llx, &lly);
1216
1217
 
1217
1218
        if (width) {
1218
 
                *width = (urx - llx) / 72.0 * get_xdpi (gs) + 0.5;
 
1219
                *width = (urx - llx) + 0.5;
1219
1220
        }
1220
1221
 
1221
1222
        if (height) {
1222
 
                *height = (ury - lly) / 72.0 * get_ydpi (gs) + 0.5;
 
1223
                *height = (ury - lly) + 0.5;
1223
1224
        }
1224
1225
}
1225
1226
 
1257
1258
{
1258
1259
        EvDocumentInfo *info;
1259
1260
        PSDocument *ps = PS_DOCUMENT (document);
 
1261
        int urx, ury, llx, lly;
1260
1262
 
1261
1263
        info = g_new0 (EvDocumentInfo, 1);
1262
1264
        info->fields_mask = EV_DOCUMENT_INFO_TITLE |
1263
1265
                            EV_DOCUMENT_INFO_FORMAT |
1264
1266
                            EV_DOCUMENT_INFO_CREATOR |
1265
 
                            EV_DOCUMENT_INFO_N_PAGES;
 
1267
                            EV_DOCUMENT_INFO_N_PAGES |
 
1268
                            EV_DOCUMENT_INFO_PAPER_SIZE;
 
1269
 
1266
1270
        info->title = g_strdup (ps->doc->title);
1267
1271
        info->format = ps->doc->epsf ? g_strdup (_("Encapsulated PostScript"))
1268
1272
                                     : g_strdup (_("PostScript"));
1269
1273
        info->creator = g_strdup (ps->doc->creator);
1270
1274
        info->n_pages = ev_document_get_n_pages (document);
 
1275
        
 
1276
        get_page_box (PS_DOCUMENT (document), 0, &urx, &ury, &llx, &lly);
 
1277
 
 
1278
        info->paper_width  = (urx - llx) / 72.0f * 25.4f;
 
1279
        info->paper_height = (ury - lly) / 72.0f * 25.4f;
1271
1280
 
1272
1281
        return info;
1273
1282
}
1289
1298
        iface->render_pixbuf = ps_async_renderer_render_pixbuf;
1290
1299
}
1291
1300
 
 
1301
static gboolean
 
1302
ps_document_file_exporter_format_supported (EvFileExporter      *exporter,
 
1303
                                            EvFileExporterFormat format)
 
1304
{
 
1305
        return (format == EV_FILE_FORMAT_PS);
 
1306
}
 
1307
 
1292
1308
static void
1293
 
ps_document_ps_export_begin (EvPSExporter *exporter, const char *filename,
1294
 
                             int first_page, int last_page,
1295
 
                             double width, double height, gboolean duplex)
 
1309
ps_document_file_exporter_begin (EvFileExporter      *exporter,
 
1310
                                 EvFileExporterFormat format,
 
1311
                                 const char          *filename,
 
1312
                                 int                  first_page,
 
1313
                                 int                  last_page,
 
1314
                                 double               width,
 
1315
                                 double               height,
 
1316
                                 gboolean             duplex)
1296
1317
{
1297
1318
        PSDocument *document = PS_DOCUMENT (exporter);
1298
1319
 
1306
1327
}
1307
1328
 
1308
1329
static void
1309
 
ps_document_ps_export_do_page (EvPSExporter *exporter, EvRenderContext *rc)
 
1330
ps_document_file_exporter_do_page (EvFileExporter *exporter, EvRenderContext *rc)
1310
1331
{
1311
1332
        PSDocument *document = PS_DOCUMENT (exporter);
1312
1333
        
1316
1337
}
1317
1338
 
1318
1339
static void
1319
 
ps_document_ps_export_end (EvPSExporter *exporter)
 
1340
ps_document_file_exporter_end (EvFileExporter *exporter)
1320
1341
{
1321
1342
        PSDocument *document = PS_DOCUMENT (exporter);
1322
1343
 
1333
1354
}
1334
1355
 
1335
1356
static void
1336
 
ps_document_ps_exporter_iface_init (EvPSExporterIface *iface)
 
1357
ps_document_file_exporter_iface_init (EvFileExporterIface *iface)
1337
1358
{
1338
 
        iface->begin = ps_document_ps_export_begin;
1339
 
        iface->do_page = ps_document_ps_export_do_page;
1340
 
        iface->end = ps_document_ps_export_end;
 
1359
        iface->format_supported = ps_document_file_exporter_format_supported;
 
1360
        iface->begin = ps_document_file_exporter_begin;
 
1361
        iface->do_page = ps_document_file_exporter_do_page;
 
1362
        iface->end = ps_document_file_exporter_end;
1341
1363
}