]> www.fi.muni.cz Git - evince.git/blobdiff - ps/ps-document.c
Updated Ukrainian translation.
[evince.git] / ps / ps-document.c
index 8aa9bd1c79ffff7a678713623d3d50bbfc9462b3..5a4a457183e8205a0664e7bdd5be3d23d23d60e7 100644 (file)
 #include <stdio.h>
 #include <math.h>
 
-#ifdef HAVE_LOCALE_H
-#include <locale.h>
-#endif
-
 #include "ps-document.h"
 #include "ev-debug.h"
 #include "gsdefaults.h"
@@ -182,6 +178,12 @@ ps_document_dispose (GObject *object)
                gs->input_buffer = NULL;
        }
 
+       if (gs->target_window) {
+               gtk_widget_destroy (gs->target_window);
+               gs->target_window = NULL;
+               gs->pstarget = NULL;
+       }
+
        stop_interpreter (gs);
 
        G_OBJECT_CLASS (parent_class)->dispose (object);
@@ -457,36 +459,28 @@ get_page_orientation (PSDocument *gs, int page)
 static void
 setup_page (PSDocument *gs, int page, double scale)
 {
-       char buf[1024];
+       gchar *buf;
        int urx, ury, llx, lly, orientation;
-#ifdef HAVE_LOCALE_H
-       char *savelocale;
-#endif
+       char scaled_xdpi[G_ASCII_DTOSTR_BUF_SIZE];      
+       char scaled_ydpi[G_ASCII_DTOSTR_BUF_SIZE];
 
        LOG ("Setup the page");
 
-#ifdef HAVE_LOCALE_H
-       /* gs needs floating point parameters with '.' as decimal point
-        * while some (european) locales use ',' instead, so we set the 
-        * locale for this snprintf to "C".
-        */
-       savelocale = setlocale (LC_NUMERIC, "C");
-#endif
        get_page_box (gs, page, &urx, &ury, &llx, &lly);
        orientation = get_page_orientation (gs, page);
+       g_ascii_dtostr (scaled_xdpi, G_ASCII_DTOSTR_BUF_SIZE, get_xdpi (gs) * scale);
+       g_ascii_dtostr (scaled_ydpi, G_ASCII_DTOSTR_BUF_SIZE, get_ydpi (gs) * scale);
 
-       g_snprintf (buf, 1024, "%ld %d %d %d %d %d %f %f %d %d %d %d",
-                   0L, orientation * 90, llx, lly, urx, ury,
-                   get_xdpi (gs) * scale,
-                   get_ydpi (gs) * scale,
-                   0, 0, 0, 0);
+       buf = g_strdup_printf ("%ld %d %d %d %d %d %s %s %d %d %d %d",
+                              0L, orientation * 90, llx, lly, urx, ury,
+                              scaled_xdpi, scaled_ydpi,
+                              0, 0, 0, 0);
        LOG ("GS property %s", buf);
 
-#ifdef HAVE_LOCALE_H
-       setlocale(LC_NUMERIC, savelocale);
-#endif
        gdk_property_change (gs->pstarget, gs_class->gs_atom, gs_class->string_atom,
                             8, GDK_PROP_MODE_REPLACE, (guchar *)buf, strlen(buf));
+       g_free (buf);
+       
        gdk_flush ();
 }
 
@@ -910,10 +904,16 @@ check_filecompressed (PSDocument * gs)
                /* sucessfully uncompressed file */
                gs->gs_filename_unc = filename_unc;
        } else {
+               gchar *filename_dsp;
+               gchar *msg;
+
                /* report error */
-               g_snprintf (buf, 1024, _("Error while decompressing file %s:\n"),
-                            gs->gs_filename);
-               interpreter_failed (gs, buf);
+               filename_dsp = g_filename_display_name (gs->gs_filename);
+               msg = g_strdup_printf (_("Error while decompressing file %s:\n"), filename_dsp);
+               g_free (filename_dsp);
+               
+               interpreter_failed (gs, msg);
+               g_free (msg);
                unlink (filename_unc);
                g_free (filename_unc);
                filename_unc = NULL;
@@ -965,10 +965,15 @@ document_load (PSDocument *gs, const gchar *fname)
                gchar *filename = NULL;
 
                if (!file_readable(fname)) {
-                       gchar buf[1024];
-
-                       g_snprintf (buf, 1024, _("Cannot open file %s.\n"), fname);
-                       interpreter_failed (gs, buf);
+                       gchar *filename_dsp;
+                       gchar *msg;
+
+                       filename_dsp = g_filename_display_name (fname);
+                       msg = g_strdup_printf (_("Cannot open file %s.\n"), filename_dsp);
+                       g_free (filename_dsp);
+                       
+                       interpreter_failed (gs, msg);
+                       g_free (msg);
                        gs->gs_status = _("File is not readable.");
                } else {
                        filename = check_filecompressed(gs);
@@ -1080,10 +1085,16 @@ ps_document_load (EvDocument  *document,
 
        result = document_load (PS_DOCUMENT (document), filename);
        if (!result) {
+               gchar *filename_dsp;
+
+               filename_dsp = g_filename_display_name (filename);
+
                g_set_error (error, G_FILE_ERROR,
                             G_FILE_ERROR_FAILED,
-                            "Failed to load document '%s'\n",
-                            uri);
+                            _("Failed to load document '%s'"),
+                            filename_dsp);
+
+               g_free (filename_dsp);
        }
 
        g_free (filename);
@@ -1099,7 +1110,8 @@ save_page_list (PSDocument *document, int *page_list, const char *filename)
        FILE *f;
        gchar *buf;
 
-       pscopydoc (sink, document->gs_filename, document->doc, page_list);
+       pscopydoc (sink, PS_DOCUMENT_GET_PS_FILE(document), 
+                  document->doc, page_list);
        
        buf = gtk_gs_doc_sink_get_buffer (sink);
        
@@ -1211,15 +1223,13 @@ ps_async_renderer_render_pixbuf (EvAsyncRenderer *renderer, int page, double sca
        PSDocument *gs = PS_DOCUMENT (renderer);
 
        if (gs->pstarget == NULL) {
-               GtkWidget *widget;
-
-               widget = gtk_window_new (GTK_WINDOW_POPUP);
-               gtk_widget_realize (widget);
-               gs->pstarget = widget->window;
+               gs->target_window = gtk_window_new (GTK_WINDOW_POPUP);
+               gtk_widget_realize (gs->target_window);
+               gs->pstarget = gs->target_window->window;
 
                g_assert (gs->pstarget != NULL);
 
-               g_signal_connect (widget, "event",
+               g_signal_connect (gs->target_window, "event",
                                  G_CALLBACK (ps_document_widget_event),
                                  gs);
        }
@@ -1250,58 +1260,6 @@ ps_document_get_info (EvDocument *document)
        return info;
 }
 
-static EvOrientation
-ps_document_get_orientation (EvDocument *document)
-{
-       EvOrientation orientation;
-       PSDocument *ps = PS_DOCUMENT (document);
-
-       g_return_val_if_fail (ps != NULL, EV_ORIENTATION_PORTRAIT);
-
-       switch (ps->orientation) {
-               case GTK_GS_ORIENTATION_PORTRAIT:
-                       orientation = EV_ORIENTATION_PORTRAIT;
-                       break;
-               case GTK_GS_ORIENTATION_LANDSCAPE:
-                       orientation = EV_ORIENTATION_LANDSCAPE;
-                       break;
-               case GTK_GS_ORIENTATION_UPSIDEDOWN:
-                       orientation = EV_ORIENTATION_UPSIDEDOWN;
-                       break;
-               case GTK_GS_ORIENTATION_SEASCAPE:
-                       orientation = EV_ORIENTATION_SEASCAPE;
-                       break;
-               default:
-                       orientation = EV_ORIENTATION_PORTRAIT;
-                       break;
-       }
-
-       return orientation;
-}
-
-static void
-ps_document_set_orientation (EvDocument *document, EvOrientation orientation)
-{
-       PSDocument *ps = PS_DOCUMENT (document);
-
-       g_return_if_fail (ps != NULL);
-
-       switch (orientation) {
-               case EV_ORIENTATION_PORTRAIT:
-                       ps->orientation = GTK_GS_ORIENTATION_PORTRAIT;
-                       break;
-               case EV_ORIENTATION_LANDSCAPE:
-                       ps->orientation = GTK_GS_ORIENTATION_LANDSCAPE;
-                       break;
-               case EV_ORIENTATION_UPSIDEDOWN:
-                       ps->orientation = GTK_GS_ORIENTATION_UPSIDEDOWN;
-                       break;
-               case EV_ORIENTATION_SEASCAPE:
-                       ps->orientation = GTK_GS_ORIENTATION_SEASCAPE;
-                       break;
-       }
-}
-
 static void
 ps_document_document_iface_init (EvDocumentIface *iface)
 {
@@ -1311,8 +1269,6 @@ 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->get_info = ps_document_get_info;
-       iface->set_orientation = ps_document_set_orientation;
-       iface->get_orientation = ps_document_get_orientation;
 }
 
 static void
@@ -1323,7 +1279,8 @@ ps_async_renderer_iface_init (EvAsyncRendererIface *iface)
 
 static void
 ps_document_ps_export_begin (EvPSExporter *exporter, const char *filename,
-                            int first_page, int last_page)
+                            int first_page, int last_page,
+                             double width, double height, gboolean duplex)
 {
        PSDocument *document = PS_DOCUMENT (exporter);
 
@@ -1334,11 +1291,11 @@ ps_document_ps_export_begin (EvPSExporter *exporter, const char *filename,
 }
 
 static void
-ps_document_ps_export_do_page (EvPSExporter *exporter, int page)
+ps_document_ps_export_do_page (EvPSExporter *exporter, EvRenderContext *rc)
 {
        PSDocument *document = PS_DOCUMENT (exporter);
        
-       document->ps_export_pagelist[page] = 1;
+       document->ps_export_pagelist[rc->page] = 1;
 }
 
 static void