]> www.fi.muni.cz Git - evince.git/commitdiff
PDF exporter for dvi documents. Fixes bug #441319.
authorAlaska Subedi <asubedi@gmail.com>
Sun, 17 Jun 2007 19:20:31 +0000 (19:20 +0000)
committerNickolay V. Shmyrev <nshmyrev@src.gnome.org>
Sun, 17 Jun 2007 19:20:31 +0000 (19:20 +0000)
2007-06-17  Alaska Subedi  <asubedi@gmail.com>

* backend/dvi/dvi-document.c:
(dvi_document_finalize),
(dvi_document_file_exporter_format_supported),
(dvi_document_file_exporter_begin),
(dvi_document_file_exporter_do_page),
(dvi_document_file_exporter_end),
(dvi_document_file_exporter_iface_init), (dvi_document_init):

PDF exporter for dvi documents. Fixes bug #441319.

svn path=/trunk/; revision=2510

ChangeLog
backend/dvi/dvi-document.c

index 2288074aca89e97d7d5e49ac3a47f5a0f5fbc771..276a010568c7ee10f09f0538d7ccf5906e84c8f4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,16 +1,28 @@
+2007-06-17  Alaska Subedi  <asubedi@gmail.com>
+
+       * backend/dvi/dvi-document.c:
+       (dvi_document_finalize),
+       (dvi_document_file_exporter_format_supported),
+       (dvi_document_file_exporter_begin),
+       (dvi_document_file_exporter_do_page),
+       (dvi_document_file_exporter_end),
+       (dvi_document_file_exporter_iface_init), (dvi_document_init):
+       
+       PDF exporter for dvi documents. Fixes bug #441319.
+
 2007-06-17  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * shell/ev-window.c: (ev_window_clear_print_job):
 
        Clear gtk print job when job has finished. Fixes bug #447612.
-       
+
 2007-06-17  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * shell/ev-window.c: (ev_window_print_send),
        (ev_window_print_dialog_response_cb), (ev_window_print_range):
 
        Add preview button to print dialog. Fixes bug #445419.
-       
+
 2007-06-17  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * backend/dvi/Makefile.am:
        (ev_document_misc_pixbuf_from_surface):
 
        Port dvi backend to cairo and fix a problem with colors. 
-       
+
 2007-06-14  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * shell/ev-view.c: (draw_one_page):
 
        Draw only visible region.
-       
+
 2007-06-13  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * backend/djvu/djvu-document.c: (djvu_document_render):
 
        Fix rotation in djvu backend.
-       
+
 2007-06-13  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * shell/ev-pixbuf-cache.c: (job_finished_cb),
        (ev_pixbuf_cache_get_text_mapping):
 
        Redraw view every time we have a new surface. Fixes bug #443587.
-       
+
 2007-06-13  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * libdocument/ev-document.c: (ev_document_info_free):
 
        Fix memory leaks.
-       
+
 2007-06-13  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * backend/dvi/dvi-document.c: (dvi_document_render),
 
        Use cairo image surfaces instead of GDK pixbufs for drawing pages
        and selections.
-       
+
 2007-06-12  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * shell/ev-window-title.c: (ev_window_title_update):
 
        Fix memory leak.
-       
+
 2007-06-09  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * shell/ev-view.c: (draw_loading_text):
 
        Show loading text centered. Fixes bug #433061
-       
+
 2007-06-09  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * shell/ev-sidebar-thumbnails.c:
 
        Remove a mutex in the main thread that blocks the UI in heavy
        documents.
-       
+
 2007-06-09  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * shell/ev-pixbuf-cache.c (copy_job_to_job_info):
 
        Set points_set to TRUE so that selections don't disappear after a
        zoom change.
-       
+
 2007-06-07  Michael Monreal  <infernux@web.de>
 
        * data/icons/16x16/actions/Makefile.am:
index 56d8bbb84aa7facd1553671528934244e4626676..c85e4f5a70d712953e5f782f7f4e490106929e3d 100644 (file)
@@ -20,6 +20,7 @@
 #include "dvi-document.h"
 #include "ev-document-thumbnails.h"
 #include "ev-document-misc.h"
+#include "ev-file-exporter.h"
 
 #include "mdvi.h"
 #include "fonts.h"
@@ -53,12 +54,17 @@ struct _DviDocument
        double base_height;
        
        gchar *uri;
+
+       /* PDF exporter */
+       gchar            *exporter_filename;
+       GString          *exporter_opts;
 };
 
 typedef struct _DviDocumentClass DviDocumentClass;
 
 static void dvi_document_document_iface_init            (EvDocumentIface           *iface);
 static void dvi_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface);
+static void dvi_document_file_exporter_iface_init      (EvFileExporterIface       *iface);
 static void dvi_document_get_page_size                         (EvDocument                *document,
                                                         int                        page,
                                                         double                    *width,
@@ -71,7 +77,8 @@ G_DEFINE_TYPE_WITH_CODE
     (DviDocument, dvi_document, G_TYPE_OBJECT, 
     {
       G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT, dvi_document_document_iface_init);    
-      G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, dvi_document_document_thumbnails_iface_init)
+      G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT_THUMBNAILS, dvi_document_document_thumbnails_iface_init);
+      G_IMPLEMENT_INTERFACE (EV_TYPE_FILE_EXPORTER, dvi_document_file_exporter_iface_init);
      });
 
 static gboolean
@@ -217,6 +224,12 @@ dvi_document_finalize (GObject *object)
        if (dvi_document->params)
                g_free (dvi_document->params);
 
+       if (dvi_document->exporter_filename)
+               g_free (dvi_document->exporter_filename);
+       
+       if (dvi_document->exporter_opts)
+               g_string_free (dvi_document->exporter_opts, TRUE);
+
         g_free (dvi_document->uri);
                
        G_OBJECT_CLASS (dvi_document_parent_class)->finalize (object);
@@ -348,6 +361,86 @@ dvi_document_document_thumbnails_iface_init (EvDocumentThumbnailsIface *iface)
        iface->get_dimensions = dvi_document_thumbnails_get_dimensions;
 }
 
+/* EvFileExporterIface */
+static gboolean
+dvi_document_file_exporter_format_supported (EvFileExporter      *exporter,
+                                              EvFileExporterFormat format)
+{
+        return (format == EV_FILE_FORMAT_PDF); /* only exporting to PDF is implemented. */
+}
+
+static void
+dvi_document_file_exporter_begin (EvFileExporter      *exporter,
+                                  EvFileExporterFormat format,
+                                  const char          *filename, /* for storing the temp pdf file */
+                                  int                  first_page,
+                                  int                  last_page,
+                                  double               width,
+                                  double               height,
+                                  gboolean             duplex)
+{
+       DviDocument *dvi_document = DVI_DOCUMENT(exporter);
+       
+       if (dvi_document->exporter_filename)
+               g_free (dvi_document->exporter_filename);       
+       dvi_document->exporter_filename = g_strdup(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)+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 (exit_stat != 0) {
+               g_warning (_("Error: dvipdfm exited with non-zero status."));
+       }
+
+       if (err)
+               g_error_free(err);
+}
+
+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
@@ -524,4 +617,7 @@ dvi_document_init (DviDocument *dvi_document)
 {
        dvi_document->context = NULL;
        dvi_document_init_params (dvi_document);
+
+       dvi_document->exporter_filename = NULL;
+       dvi_document->exporter_opts = NULL;
 }