From: Marco Pesenti Gritti Date: Fri, 15 Apr 2005 09:01:54 +0000 (+0000) Subject: Based on a patch by J�rg Billeter X-Git-Tag: EVINCE_0_2_1~54 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=9d164a6d7df8ee8039ac22419a2969117747202b;p=evince.git Based on a patch by J�rg Billeter 2005-04-15 Marco Pesenti Gritti * 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 Implement print and save a copy for the ps backend. --- diff --git a/ChangeLog b/ChangeLog index 87c05e83..9a11a7fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2005-04-15 Marco Pesenti Gritti + + * 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 + + Implement print and save a copy for the ps backend. + 2005-04-14 Marco Pesenti Gritti * backend/ev-document.h: diff --git a/ps/ps-document.c b/ps/ps-document.c index d06855f3..9a7bf70b 100644 --- a/ps/ps-document.c +++ b/ps/ps-document.c @@ -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 @@ -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; +} diff --git a/ps/ps-document.h b/ps/ps-document.h index 2ea93dd3..23392299 100644 --- a/ps/ps-document.h +++ b/ps/ps-document.h @@ -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 */ };