]> www.fi.muni.cz Git - evince.git/commitdiff
Fix unstructured documents save and print
authorMarco Pesenti Gritti <mpg@redhat.com>
Thu, 22 Sep 2005 15:23:15 +0000 (15:23 +0000)
committerMarco Pesenti Gritti <marco@src.gnome.org>
Thu, 22 Sep 2005 15:23:15 +0000 (15:23 +0000)
2005-09-22  Marco Pesenti Gritti  <mpg@redhat.com>

        * ps/ps-document.c: (save_document), (ps_document_save),
        (ps_document_ps_export_begin), (ps_document_ps_export_do_page),
        (ps_document_ps_export_end):

        Fix unstructured documents save and print

ChangeLog
ps/ps-document.c

index 216664774098972170d25d2bc8e160cd63a4769c..de712562c412d55cdf4fc082b5285492db732214 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-09-22  Marco Pesenti Gritti  <mpg@redhat.com>
+
+       * ps/ps-document.c: (save_document), (ps_document_save),
+       (ps_document_ps_export_begin), (ps_document_ps_export_do_page),
+       (ps_document_ps_export_end):
+
+       Fix unstructured documents save and print
+
 2005-09-22  Marco Pesenti Gritti  <mpg@redhat.com>
 
        * shell/ev-application.c: (ev_application_open_uri):
index 91acc9ac89e8333281f32fbe9a299b51ac24af14..3ce591f9efaf10db08cc214e5f8c3456da273ea2 100644 (file)
@@ -1082,6 +1082,45 @@ ps_document_load (EvDocument  *document,
        return result;
 }
 
+static gboolean
+save_document (PSDocument *document, const char *filename)
+{
+       gboolean result = TRUE;
+       GtkGSDocSink *sink = gtk_gs_doc_sink_new ();
+       FILE *f, *src_file;
+       gchar *buf;
+
+       src_file = fopen (PS_DOCUMENT_GET_PS_FILE(document), "r");
+       if (src_file) {
+               struct stat stat_rec;
+
+               if (stat (PS_DOCUMENT_GET_PS_FILE(document), &stat_rec) == 0) {
+                       pscopy (src_file, sink, 0, stat_rec.st_size - 1);
+               }
+
+               fclose (src_file);
+       }
+       
+       buf = gtk_gs_doc_sink_get_buffer (sink);
+       if (buf == NULL) {
+               return FALSE;
+       }
+       
+       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
 save_page_list (PSDocument *document, int *page_list, const char *filename)
 {
@@ -1116,23 +1155,15 @@ ps_document_save (EvDocument  *document,
                  GError     **error)
 {
        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);
+       result = save_document (ps, filename);
 
-       g_free (page_list);
        g_free (filename);
 
        return result;
@@ -1245,9 +1276,12 @@ ps_document_ps_export_begin (EvPSExporter *exporter, const char *filename,
 {
        PSDocument *document = PS_DOCUMENT (exporter);
 
-       g_free (document->ps_export_pagelist);
+       if (document->structured_doc) {
+               g_free (document->ps_export_pagelist);
        
-       document->ps_export_pagelist = g_new0 (int, document->doc->numpages);
+               document->ps_export_pagelist = g_new0 (int, document->doc->numpages);
+       }
+
        document->ps_export_filename = g_strdup (filename);
 }
 
@@ -1256,7 +1290,9 @@ ps_document_ps_export_do_page (EvPSExporter *exporter, EvRenderContext *rc)
 {
        PSDocument *document = PS_DOCUMENT (exporter);
        
-       document->ps_export_pagelist[rc->page] = 1;
+       if (document->structured_doc) {
+               document->ps_export_pagelist[rc->page] = 1;
+       }
 }
 
 static void
@@ -1264,13 +1300,16 @@ 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;
+       if (!document->structured_doc) {
+               save_document (document, document->ps_export_filename);
+       } else {
+               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