+/* EvFileExporterIface */
+static void
+dvi_document_file_exporter_begin (EvFileExporter *exporter,
+ EvFileExporterContext *fc)
+{
+ DviDocument *dvi_document = DVI_DOCUMENT(exporter);
+
+ if (dvi_document->exporter_filename)
+ g_free (dvi_document->exporter_filename);
+ dvi_document->exporter_filename = g_strdup (fc->filename);
+
+ if (dvi_document->exporter_opts) {
+ g_string_free (dvi_document->exporter_opts, TRUE);
+ }
+ dvi_document->exporter_opts = g_string_new ("-s ");
+}
+
+static void
+dvi_document_file_exporter_do_page (EvFileExporter *exporter,
+ EvRenderContext *rc)
+{
+ DviDocument *dvi_document = DVI_DOCUMENT(exporter);
+
+ g_string_append_printf (dvi_document->exporter_opts, "%d,", (rc->page->index) + 1);
+}
+
+static void
+dvi_document_file_exporter_end (EvFileExporter *exporter)
+{
+ gchar *command_line;
+ gint exit_stat;
+ GError *err = NULL;
+ gboolean success;
+
+ DviDocument *dvi_document = DVI_DOCUMENT(exporter);
+
+ command_line = g_strdup_printf ("dvipdfm %s -o %s \"%s\"", /* dvipdfm -s 1,2,.., -o exporter_filename dvi_filename */
+ dvi_document->exporter_opts->str,
+ dvi_document->exporter_filename,
+ dvi_document->context->filename);
+
+ success = g_spawn_command_line_sync (command_line,
+ NULL,
+ NULL,
+ &exit_stat,
+ &err);
+
+ g_free (command_line);
+
+ if (success == FALSE) {
+ g_warning ("Error: %s", err->message);
+ } else if (!WIFEXITED(exit_stat) || WEXITSTATUS(exit_stat) != EXIT_SUCCESS){
+ g_warning ("Error: dvipdfm does not end normally or exit with a failure status.");
+ }
+
+ if (err)
+ g_error_free (err);
+}
+
+static EvFileExporterCapabilities
+dvi_document_file_exporter_get_capabilities (EvFileExporter *exporter)
+{
+ return EV_FILE_EXPORTER_CAN_PAGE_SET |
+ EV_FILE_EXPORTER_CAN_COPIES |
+ EV_FILE_EXPORTER_CAN_COLLATE |
+ EV_FILE_EXPORTER_CAN_REVERSE |
+ EV_FILE_EXPORTER_CAN_GENERATE_PDF;
+}
+
+static void
+dvi_document_file_exporter_iface_init (EvFileExporterIface *iface)
+{
+ iface->begin = dvi_document_file_exporter_begin;
+ iface->do_page = dvi_document_file_exporter_do_page;
+ iface->end = dvi_document_file_exporter_end;
+ iface->get_capabilities = dvi_document_file_exporter_get_capabilities;
+}
+