[PATCH] PostScript printing support



Hi

I've attached a small patch to add support for printing PostScript
documents to evince. It uses pscopydoc to accomplish that, I don't know
whether that's the right way but it seems to work ;)

BTW: Probably other people on this list miss the functionality to print
multiple pages per sheet with evince (and gpdf). I've written a small
patch[1] for libgnomeprint to fix that problem.

Regards,

Jürg

[1]
http://mail.gnome.org/archives/gnome-print-list/2005-February/msg00005.html

-- 
Jürg Billeter <j bitron ch>
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evince/ChangeLog,v
retrieving revision 1.224
diff -p -u -r1.224 ChangeLog
--- ChangeLog	25 Feb 2005 18:53:34 -0000	1.224
+++ ChangeLog	27 Feb 2005 16:44:00 -0000
@@ -1,3 +1,11 @@
+2005-02-27  Juerg Billeter  <j bitron ch>
+
+	* ps/ps-document.c: (ps_document_init), (ps_document_ps_export_begin),
+	(ps_document_ps_export_do_page), (ps_document_ps_export_end):
+	* ps/ps-document.h:
+
+	Implement EvPSExporter interface in PSDocument.
+
 2005-02-25  Sebastien Bacher  <seb128 debian org>
 
 	* configure.ac: add the french translation.
Index: ps/ps-document.c
===================================================================
RCS file: /cvs/gnome/evince/ps/ps-document.c,v
retrieving revision 1.18
diff -p -u -r1.18 ps-document.c
--- ps/ps-document.c	24 Feb 2005 12:47:27 -0000	1.18
+++ ps/ps-document.c	27 Feb 2005 16:44:01 -0000
@@ -152,6 +152,7 @@ The DONE message indicates that ghostscr
 #include "ps-document.h"
 #include "ev-debug.h"
 #include "gsdefaults.h"
+#include "ev-ps-exporter.h"
 
 #ifdef HAVE_LOCALE_H
 #   include <locale.h>
@@ -216,6 +217,7 @@ static gint start_interpreter(PSDocument
 gboolean computeSize(void);
 static gboolean ps_document_set_page_size(PSDocument * gs, gint new_pagesize, gint pageid);
 static void ps_document_document_iface_init (EvDocumentIface *iface);
+static void ps_document_ps_exporter_iface_init (EvPSExporterIface *iface);
 
 static GObjectClass *parent_class = NULL;
 
@@ -275,6 +277,9 @@ ps_document_init(PSDocument * gs)
 
   gs->page_x_offset = 0;
   gs->page_y_offset = 0;
+  
+  gs->ps_export_pagelist = NULL;
+  gs->ps_export_filename = NULL;
 
   /* Set user defined defaults */
   gs->override_orientation = gtk_gs_defaults_get_override_orientation();
@@ -1269,12 +1274,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;
 
@@ -1906,3 +1921,55 @@ ps_document_document_iface_init (EvDocum
 	iface->get_page_size = ps_document_get_page_size;
 	iface->render = ps_document_render;
 }
+
+static void
+ps_document_ps_export_begin (EvPSExporter *exporter, const char *filename)
+{
+	PSDocument *document = PS_DOCUMENT (exporter);
+
+	if (document->ps_export_pagelist)
+		g_free (document->ps_export_pagelist);
+	
+	document->ps_export_pagelist = g_malloc0 (sizeof (int) * document->doc->numpages);
+	document->ps_export_filename = filename;
+}
+
+static void
+ps_document_ps_export_do_page (EvPSExporter *exporter, int page)
+{
+	PSDocument *document = PS_DOCUMENT (exporter);
+	
+	document->ps_export_pagelist[page - 1] = 1;
+}
+
+static void
+ps_document_ps_export_end (EvPSExporter *exporter)
+{
+	PSDocument *document = PS_DOCUMENT (exporter);
+	GtkGSDocSink *sink = gtk_gs_doc_sink_new ();
+	FILE *f;
+	gchar *buf;
+
+	pscopydoc (sink, document->gs_filename, document->doc, document->ps_export_pagelist);
+	
+	buf = gtk_gs_doc_sink_get_buffer (sink);
+	
+	f = fopen (document->ps_export_filename, "w");
+	fputs (buf, f);
+	fclose (f);
+
+	g_free (buf);
+	gtk_gs_doc_sink_free (sink);
+	g_free (sink);
+	g_free (document->ps_export_pagelist);
+	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: ps/ps-document.h
===================================================================
RCS file: /cvs/gnome/evince/ps/ps-document.h,v
retrieving revision 1.4
diff -p -u -r1.4 ps-document.h
--- ps/ps-document.h	24 Feb 2005 12:47:27 -0000	1.4
+++ ps/ps-document.h	27 Feb 2005 16:44:01 -0000
@@ -93,6 +93,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;
+  const char *ps_export_filename;
 
   /* User selected options... */
   gboolean antialiased;         /* Using antialiased display */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]