X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=ps%2Fps-document.c;h=3ce591f9efaf10db08cc214e5f8c3456da273ea2;hb=205c689a78e992d1ad3cf9223f7c95bf424dda94;hp=8aa9bd1c79ffff7a678713623d3d50bbfc9462b3;hpb=74ddcfcb4098d77e261b95d5ff678bd853c61e10;p=evince.git diff --git a/ps/ps-document.c b/ps/ps-document.c index 8aa9bd1c..3ce591f9 100644 --- a/ps/ps-document.c +++ b/ps/ps-document.c @@ -43,10 +43,6 @@ #include #include -#ifdef HAVE_LOCALE_H -#include -#endif - #include "ps-document.h" #include "ev-debug.h" #include "gsdefaults.h" @@ -141,8 +137,6 @@ ps_document_init (PSDocument *gs) gs->ps_export_pagelist = NULL; gs->ps_export_filename = NULL; - - gs->orientation = GTK_GS_ORIENTATION_NONE; } static void @@ -182,6 +176,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); @@ -213,9 +213,11 @@ push_pixbuf (PSDocument *gs) cmap = gdk_window_get_colormap (gs->pstarget); gdk_drawable_get_size (gs->bpixmap, &width, &height); + LOG ("Get from drawable\n"); pixbuf = gdk_pixbuf_get_from_drawable (NULL, gs->bpixmap, cmap, 0, 0, 0, 0, width, height); + LOG ("Get from drawable done\n"); g_signal_emit_by_name (gs, "render_finished", pixbuf); g_object_unref (pixbuf); } @@ -245,6 +247,7 @@ ps_document_widget_event (GtkWidget *widget, GdkEvent *event, gpointer data) gs->busy = FALSE; push_pixbuf (gs); + LOG ("Pixbuf pushed"); } return TRUE; @@ -301,7 +304,7 @@ get_ydpi (PSDocument *gs) } static void -setup_pixmap (PSDocument *gs, int page, double scale) +setup_pixmap (PSDocument *gs, int page, double scale, int rotation) { GdkGC *fill; GdkColor white = { 0, 0xFFFF, 0xFFFF, 0xFFFF }; /* pixel, r, g, b */ @@ -310,8 +313,14 @@ setup_pixmap (PSDocument *gs, int page, double scale) int pixmap_width, pixmap_height; ev_document_get_page_size (EV_DOCUMENT (gs), page, &width, &height); - pixmap_width = width * scale + 0.5; - pixmap_height = height * scale + 0.5; + + if (rotation == 90 || rotation == 270) { + pixmap_height = width * scale + 0.5; + pixmap_width = height * scale + 0.5; + } else { + pixmap_width = width * scale + 0.5; + pixmap_height = height * scale + 0.5; + } if(gs->bpixmap) { int w, h; @@ -428,65 +437,30 @@ get_page_box (PSDocument *gs, int page, int *urx, int *ury, int *llx, int *lly) *lly = new_lly; } -static int -get_page_orientation (PSDocument *gs, int page) -{ - int orientation; - - orientation = GTK_GS_ORIENTATION_NONE; - - 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; - } - if (gs->orientation != GTK_GS_ORIENTATION_NONE) { - orientation = gs->orientation; - } - - return orientation; -} - static void -setup_page (PSDocument *gs, int page, double scale) +setup_page (PSDocument *gs, int page, double scale, int rotation) { - char buf[1024]; - int urx, ury, llx, lly, orientation; -#ifdef HAVE_LOCALE_H - char *savelocale; -#endif + gchar *buf; + char scaled_xdpi[G_ASCII_DTOSTR_BUF_SIZE]; + char scaled_ydpi[G_ASCII_DTOSTR_BUF_SIZE]; + int urx, ury, llx, lly; 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, rotation, 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 +884,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 +945,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 +1065,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); @@ -1091,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) { @@ -1099,7 +1129,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); @@ -1124,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; @@ -1167,35 +1190,16 @@ ps_document_get_page_size (EvDocument *document, double *height) { PSDocument *gs = PS_DOCUMENT (document); - int w, h; - int urx, ury, llx, lly, orientation; + int urx, ury, llx, lly; get_page_box (PS_DOCUMENT (document), page, &urx, &ury, &llx, &lly); - orientation = get_page_orientation (PS_DOCUMENT (document), page); - - switch (orientation) { - case GTK_GS_ORIENTATION_PORTRAIT: - case GTK_GS_ORIENTATION_UPSIDEDOWN: - w = (urx - llx) / 72.0 * get_xdpi (gs) + 0.5; - h = (ury - lly) / 72.0 * get_ydpi (gs) + 0.5; - break; - case GTK_GS_ORIENTATION_LANDSCAPE: - case GTK_GS_ORIENTATION_SEASCAPE: - w = (ury - lly) / 72.0 * get_xdpi (gs) + 0.5; - h = (urx - llx) / 72.0 * get_ydpi (gs) + 0.5; - break; - default: - w = h = 0; - g_assert_not_reached (); - break; - } if (width) { - *width = w; + *width = (urx - llx) / 72.0 * get_xdpi (gs) + 0.5; } if (height) { - *height = h; + *height = (ury - lly) / 72.0 * get_ydpi (gs) + 0.5; } } @@ -1206,26 +1210,24 @@ ps_document_can_get_text (EvDocument *document) } static void -ps_async_renderer_render_pixbuf (EvAsyncRenderer *renderer, int page, double scale) +ps_async_renderer_render_pixbuf (EvAsyncRenderer *renderer, int page, double scale, int rotation) { 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); } - setup_pixmap (gs, page, scale); - setup_page (gs, page, scale); + setup_pixmap (gs, page, scale, rotation); + setup_page (gs, page, scale, rotation); render_page (gs, page); } @@ -1250,58 +1252,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 +1261,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,22 +1271,28 @@ 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); - 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); } 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; + if (document->structured_doc) { + document->ps_export_pagelist[rc->page] = 1; + } } static void @@ -1346,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