]> www.fi.muni.cz Git - evince.git/commitdiff
Based on a patch by J�rg Billeter <j@bitron.ch>
authorMarco Pesenti Gritti <mpg@redhat.com>
Fri, 15 Apr 2005 09:01:54 +0000 (09:01 +0000)
committerMarco Pesenti Gritti <marco@src.gnome.org>
Fri, 15 Apr 2005 09:01:54 +0000 (09:01 +0000)
2005-04-15  Marco Pesenti Gritti <mpg@redhat.com>

        * ps/ps-document.c: (ps_document_init), (ps_document_get_type),
        (save_page_list), (ps_document_save),
        (ps_document_document_iface_init), (ps_document_ps_export_begin),
        (ps_document_ps_export_do_page), (ps_document_ps_export_end),
        (ps_document_ps_exporter_iface_init):
        * ps/ps-document.h:

        Based on a patch by J�rg Billeter <j@bitron.ch>

        Implement print and save a copy for the ps backend.

ChangeLog
ps/ps-document.c
ps/ps-document.h

index 87c05e835994b3010c8fa7b4182bc12df88e6782..9a11a7fc797e84c48e4948bb15ff2cce46615bdf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2005-04-15  Marco Pesenti Gritti <mpg@redhat.com>
+
+       * ps/ps-document.c: (ps_document_init), (ps_document_get_type),
+       (save_page_list), (ps_document_save),
+       (ps_document_document_iface_init), (ps_document_ps_export_begin),
+       (ps_document_ps_export_do_page), (ps_document_ps_export_end),
+       (ps_document_ps_exporter_iface_init):
+       * ps/ps-document.h:
+
+       Based on a patch by J�rg Billeter <j@bitron.ch>
+       
+       Implement print and save a copy for the ps backend.
+
 2005-04-14   Marco Pesenti Gritti <mpg@redhat.com>
 
        * backend/ev-document.h:
index d06855f30ac02ee9039f98a4ed793380f7ef81bc..9a7bf70b0c61d5004aeeafcab83a428c086000b8 100644 (file)
@@ -46,6 +46,7 @@
 #include "ps-document.h"
 #include "ev-debug.h"
 #include "gsdefaults.h"
+#include "ev-ps-exporter.h"
 
 #ifdef HAVE_LOCALE_H
 #   include <locale.h>
@@ -101,6 +102,7 @@ static void input(gpointer data, gint source, GdkInputCondition condition);
 static void stop_interpreter(PSDocument * gs);
 static gint start_interpreter(PSDocument * gs);
 static void ps_document_document_iface_init (EvDocumentIface *iface);
+static void ps_document_ps_exporter_iface_init (EvPSExporterIface *iface);
 static gboolean ps_document_widget_event (GtkWidget *widget, GdkEvent *event, gpointer data);
 
 static GObjectClass *parent_class = NULL;
@@ -142,6 +144,9 @@ ps_document_init (PSDocument *gs)
 
        gs->gs_status = _("No document loaded.");
 
+       gs->ps_export_pagelist = NULL;
+       gs->ps_export_filename = NULL;
+
        pixbuf_cond = g_cond_new ();
        pixbuf_mutex = g_mutex_new ();
 }
@@ -1029,12 +1034,22 @@ ps_document_get_type(void)
         NULL
     };
 
+    static const GInterfaceInfo ps_exporter_info =
+    {
+        (GInterfaceInitFunc) ps_document_ps_exporter_iface_init,
+        NULL,
+        NULL
+    };
+
     gs_type = g_type_register_static(G_TYPE_OBJECT,
                                      "PSDocument", &gs_info, 0);
 
     g_type_add_interface_static (gs_type,
                                  EV_TYPE_DOCUMENT,
                                  &document_info);
+    g_type_add_interface_static (gs_type,
+                                 EV_TYPE_PS_EXPORTER,
+                                 &ps_exporter_info);
   }
   return gs_type;
 
@@ -1224,13 +1239,59 @@ ps_document_load (EvDocument  *document,
        return result;
 }
 
+static gboolean
+save_page_list (PSDocument *document, int *page_list, const char *filename)
+{
+       gboolean result = TRUE;
+       GtkGSDocSink *sink = gtk_gs_doc_sink_new ();
+       FILE *f;
+       gchar *buf;
+
+       pscopydoc (sink, document->gs_filename, document->doc, page_list);
+       
+       buf = gtk_gs_doc_sink_get_buffer (sink);
+       
+       f = fopen (filename, "w");
+       if (f) {
+               fputs (buf, f);
+               fclose (f);
+       } else {
+               result = FALSE;
+       }
+
+       g_free (buf);
+       gtk_gs_doc_sink_free (sink);
+       g_free (sink);
+
+       return result;
+}
+
 static gboolean
 ps_document_save (EvDocument  *document,
                  const char  *uri,
                  GError     **error)
 {
-       g_warning ("ps_document_save not implemented"); /* FIXME */
-       return TRUE;
+       PSDocument *ps = PS_DOCUMENT (document);
+       int *page_list;
+       gboolean result;
+       int i;
+       char *filename;
+
+       filename = g_filename_from_uri (uri, NULL, error);
+       if (!filename)
+               return FALSE;
+
+       page_list = g_new0 (int, ps->doc->numpages);
+       for (i = 0; i < ps->doc->numpages; i++) {
+               page_list[i] = 1;
+       }
+
+       result = save_page_list (ps, page_list, filename);
+
+       g_free (page_list);
+       g_free (filename);
+
+       return result;
 }
 
 static int
@@ -1352,3 +1413,44 @@ ps_document_document_iface_init (EvDocumentIface *iface)
        iface->get_page_size = ps_document_get_page_size;
        iface->render_pixbuf = ps_document_render_pixbuf;
 }
+
+static void
+ps_document_ps_export_begin (EvPSExporter *exporter, const char *filename)
+{
+       PSDocument *document = PS_DOCUMENT (exporter);
+
+       g_free (document->ps_export_pagelist);
+       
+       document->ps_export_pagelist = g_new0 (int, document->doc->numpages);
+       document->ps_export_filename = g_strdup (filename);
+}
+
+static void
+ps_document_ps_export_do_page (EvPSExporter *exporter, int page)
+{
+       PSDocument *document = PS_DOCUMENT (exporter);
+       
+       document->ps_export_pagelist[page] = 1;
+}
+
+static void
+ps_document_ps_export_end (EvPSExporter *exporter)
+{
+       PSDocument *document = PS_DOCUMENT (exporter);
+
+       save_page_list (document, document->ps_export_pagelist,
+                       document->ps_export_filename);
+
+       g_free (document->ps_export_pagelist);
+       g_free (document->ps_export_filename);  
+       document->ps_export_pagelist = NULL;
+       document->ps_export_filename = NULL;
+}
+
+static void
+ps_document_ps_exporter_iface_init (EvPSExporterIface *iface)
+{
+       iface->begin = ps_document_ps_export_begin;
+       iface->do_page = ps_document_ps_export_do_page;
+       iface->end = ps_document_ps_export_end;
+}
index 2ea93dd38ace50645d3fead0b44dce3ec284f43f..23392299cf2f05c8a5903dba4cf416811f195e67 100644 (file)
@@ -71,6 +71,9 @@ struct _PSDocument {
   gboolean send_filename_to_gs; /* True if gs should read from file directly */
   gboolean reading_from_pipe;   /* True if ggv is reading input from pipe */
   struct document *doc;
+  
+  int *ps_export_pagelist;
+  char *ps_export_filename;
 
   const gchar *gs_status;       /* PSDocument status */
 };