70
70
static gboolean broken_pipe = FALSE;
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,
79
static void output (gpointer data,
81
GdkInputCondition condition);
82
static void input (gpointer data,
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,
79
static void output (gpointer data,
81
GdkInputCondition condition);
82
static void input (gpointer data,
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);
91
91
G_DEFINE_TYPE_WITH_CODE (PSDocument, ps_document, G_TYPE_OBJECT,
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);
298
get_xdpi (PSDocument *gs)
300
return 25.4 * gdk_screen_width() / gdk_screen_width_mm();
304
get_ydpi (PSDocument *gs)
306
return 25.4 * gdk_screen_height() / gdk_screen_height_mm();
310
298
setup_pixmap (PSDocument *gs, int page, double scale, int rotation)
447
435
setup_page (PSDocument *gs, int page, double scale, int rotation)
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;
454
441
LOG ("Setup the page");
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);
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,
464
450
LOG ("GS property %s", buf);
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;
629
616
LOG ("Start the interpreter");
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);
687
675
gs->interpreter_pid = fork ();
708
gv_env_vars = g_strsplit (gv_env, ";", -1);
710
for (i = 0; gv_env_vars[i]; i++) {
711
putenv (gv_env_vars[i]);
722
714
/* change to directory where the input file is. This helps
723
715
* with postscript-files which include other files using
1001
996
gs->busy = TRUE;
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);
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;
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);
1012
1013
gdk_error_trap_pop ();
1212
1213
PSDocument *gs = PS_DOCUMENT (document);
1213
1214
int urx, ury, llx, lly;
1215
get_page_box (PS_DOCUMENT (document), page, &urx, &ury, &llx, &lly);
1216
get_page_box (gs, page, &urx, &ury, &llx, &lly);
1218
*width = (urx - llx) / 72.0 * get_xdpi (gs) + 0.5;
1219
*width = (urx - llx) + 0.5;
1222
*height = (ury - lly) / 72.0 * get_ydpi (gs) + 0.5;
1223
*height = (ury - lly) + 0.5;
1258
1259
EvDocumentInfo *info;
1259
1260
PSDocument *ps = PS_DOCUMENT (document);
1261
int urx, ury, llx, lly;
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;
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);
1276
get_page_box (PS_DOCUMENT (document), 0, &urx, &ury, &llx, &lly);
1278
info->paper_width = (urx - llx) / 72.0f * 25.4f;
1279
info->paper_height = (ury - lly) / 72.0f * 25.4f;
1289
1298
iface->render_pixbuf = ps_async_renderer_render_pixbuf;
1302
ps_document_file_exporter_format_supported (EvFileExporter *exporter,
1303
EvFileExporterFormat format)
1305
return (format == EV_FILE_FORMAT_PS);
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,
1297
1318
PSDocument *document = PS_DOCUMENT (exporter);
1336
ps_document_ps_exporter_iface_init (EvPSExporterIface *iface)
1357
ps_document_file_exporter_iface_init (EvFileExporterIface *iface)
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;