]> www.fi.muni.cz Git - evince.git/blobdiff - ps/ps-document.c
Updated Czech translation.
[evince.git] / ps / ps-document.c
index d06855f30ac02ee9039f98a4ed793380f7ef81bc..a794e9956340dd0172a8e5689a454a4ea095b806 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>
@@ -67,11 +68,6 @@ GCond* pixbuf_cond = NULL;
 GMutex* pixbuf_mutex = NULL;
 GdkPixbuf *current_pixbuf = NULL;
 
-enum {
-       PROP_0,
-       PROP_TITLE
-};
-
 /* structure to describe section of file to send to ghostscript */
 struct record_list {
   FILE *fp;
@@ -101,6 +97,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,45 +139,13 @@ 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 ();
 }
 
-static void
-ps_document_set_property (GObject *object,
-                         guint prop_id,
-                         const GValue *value,
-                         GParamSpec *pspec)
-{
-       switch (prop_id)
-
-       {
-               case PROP_TITLE:
-                       /* read only */
-                       break;
-       }
-}
-
-static void
-ps_document_get_property (GObject *object,
-                         guint prop_id,
-                         GValue *value,
-                         GParamSpec *pspec)
-{
-       PSDocument *ps = PS_DOCUMENT (object);
-
-       switch (prop_id)
-       {
-               case PROP_TITLE:
-                       if (ps->doc) {
-                               g_value_set_string (value, ps->doc->title);
-                       } else {
-                               g_value_set_string (value, NULL);
-                       }
-                       break;
-       }
-}
-
 static void
 ps_document_class_init(PSDocumentClass *klass)
 {
@@ -191,15 +156,11 @@ ps_document_class_init(PSDocumentClass *klass)
        gs_class = klass;
 
        object_class->finalize = ps_document_finalize;
-       object_class->get_property = ps_document_get_property;
-       object_class->set_property = ps_document_set_property;
 
        klass->gs_atom = gdk_atom_intern ("GHOSTVIEW", FALSE);
        klass->next_atom = gdk_atom_intern ("NEXT", FALSE);
        klass->page_atom = gdk_atom_intern ("PAGE", FALSE);
        klass->string_atom = gdk_atom_intern ("STRING", FALSE);
-
-       g_object_class_override_property (object_class, PROP_TITLE, "title");
 }
 
 static void
@@ -503,6 +464,12 @@ get_page_orientation (PSDocument *gs, int page)
        if (gs->structured_doc) {
                orientation = gs->doc->pages[page].orientation;
        }
+       if (orientation == GTK_GS_ORIENTATION_NONE) {
+               orientation = gs->doc->default_page_orientation;
+       }
+       if (orientation == GTK_GS_ORIENTATION_NONE) {
+               orientation = gs->doc->orientation;
+       }
        if (orientation == GTK_GS_ORIENTATION_NONE) {
                orientation = GTK_GS_ORIENTATION_PORTRAIT;
        }
@@ -1029,12 +996,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;
 
@@ -1101,8 +1078,6 @@ document_load(PSDocument * gs, const gchar * fname)
     /* we grab the vital statistics!!! */
     gs->doc = psscan(gs->gs_psfile, TRUE, filename);
 
-    g_object_notify (G_OBJECT (gs), "title");
-
     if(gs->doc == NULL) {
       /* File does not seem to be a Postscript one */
       gchar buf[1024];
@@ -1224,13 +1199,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
@@ -1342,6 +1363,19 @@ ps_document_render_pixbuf (EvDocument *document, int page, double scale)
        return pixbuf;
 }
 
+static EvDocumentInfo *
+ps_document_get_info (EvDocument *document)
+{
+       EvDocumentInfo *info;
+       PSDocument *ps = PS_DOCUMENT (document);
+
+       info = g_new0 (EvDocumentInfo, 1);
+       info->fields_mask = EV_DOCUMENT_INFO_TITLE;
+       info->title = ps->doc->title;
+
+       return info;
+}
+
 static void
 ps_document_document_iface_init (EvDocumentIface *iface)
 {
@@ -1351,4 +1385,46 @@ ps_document_document_iface_init (EvDocumentIface *iface)
        iface->get_n_pages = ps_document_get_n_pages;
        iface->get_page_size = ps_document_get_page_size;
        iface->render_pixbuf = ps_document_render_pixbuf;
+       iface->get_info = ps_document_get_info;
+}
+
+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;
 }