GNOME Bugzilla – Bug 441319
evince does not print dvi files
Last modified: 2007-06-17 19:20:52 UTC
Please describe the problem: I am trying to implement the dvi file exporter. I also implemented the djvu exporter, which was helped by a function contained the libdjvulibre library that converted djvu files to ps. However, I can't seem to find such library for dvi format. So, would the right way to implement this be by converting dvi to ps directly by dvips command? Steps to reproduce: 1. 2. 3. Actual results: Expected results: Does this happen every time? Other information:
You can invoke dvips with g_spawn
Created attachment 89470 [details] [review] Patch to add dvi printing support. Preliminary dvi printing support. Haven't done the setting height and width support as I haven't had time to look at how evince sends height and width to *exporter_begin functions.
Comment on attachment 89470 [details] [review] Patch to add dvi printing support. Thanks for the patch! Some comments below >+static void >+dvi_document_file_exporter_end (EvFileExporter *exporter) >+{ >+ gchar *command_line; >+ gchar **argv; >+ GError *err = NULL; >+ gboolean success; >+ GPid child_pid = -1; it seems you are not using child_pid in the function >+ >+ DviDocument *dvi_document = DVI_DOCUMENT(exporter); >+ >+ command_line = g_strdup_printf ("%s %s %s -o%s", /* dvips filename.dvi -pp1,2,.. -ops_filename */ >+ "dvips", >+ dvi_document->context->filename, >+ dvi_document->opts->str, >+ dvi_document->ps_filename); >+ >+ g_shell_parse_argv (command_line, NULL, &argv, &error); does it compiles? error is not defined, it should be err instead. >+ >+ if (err) { >+ g_warning ("Error %s", err->message); err should be freed here with g_error_free() >+ return NULL; you are returning NULL in a void function. >+ } >+ >+ success = g_spawn_sync (NULL, >+ argv, >+ NULL, >+ G_SPAWN_SEARCH_PATH | G_SPAWN_STDERR_TO_DEV_NULL, >+ NULL, >+ NULL, >+ NULL, >+ NULL, >+ NULL, >+ NULL); success variable is not used for anything. You should also check the dvips exit status to make sure the command didn't fail. Instead of using g_spawn_sync() with all of those NULL, you can use g_spawn_command_line_sync. I would also check here that the resulting ps file actually exists. >+ g_free(command_line); >+ g_strfreev(argv); >+} >+ >+static void >+dvi_document_file_exporter_iface_init (EvFileExporterIface *iface) >+{ >+ iface->format_supported = dvi_document_file_exporter_format_supported; >+ iface->begin = dvi_document_file_exporter_begin; >+ iface->do_page = dvi_document_file_exporter_do_page; >+ iface->end = dvi_document_file_exporter_end; >+} >+ > #define RGB2ULONG(r,g,b) ((0xFF<<24)|(r<<16)|(g<<8)|(b)) > > static gboolean >@@ -480,4 +577,7 @@ > { > dvi_document->context = NULL; > dvi_document_init_params (dvi_document); >+ >+ dvi_document->ps_filename = NULL; >+ dvi_document->opts = g_string_new (""); it's probably better to create the string on demand, I mean, like you are doing with ps_filename. > }
Created attachment 89542 [details] [review] fixed up the previous patch Sorry for the crappy patch last time. Should not have sent it when sleepy, although it compiled and worked fine on my laptop. This patch should be much better. However, I am not checking if ps file actually exists as I could not find glib function to check if a file exists. Also, other backends do not do that check.
Created attachment 89553 [details] [review] dvi printing using dvipdfm This uses dvipdfm as opposed to dvips. The reason is that dvips will print a page only once no matter how many times a page number has been specified in -pp option. For example, dvips -pp2,2,2, will print only one page (pg 2). So dvi backend will not be able to print multiple copies. dvipdfm eliminates this restriction. One thing I noticed was that enabling PDF using *_exporter_format_supported will also cause PS option to be visible in printing dialog even though PS exporting is not supported. However, I guess this is for another bug report...
Patch is applied, thanks a lot.