X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=ps%2Fps-document.c;h=75009dc9844f54c4ed8ef6ede8240c26a19d36f9;hb=3979c5c5ca307cad84b417b0d350aa205fdc422f;hp=5a4a457183e8205a0664e7bdd5be3d23d23d60e7;hpb=0e7bb3210dc91cde7a9dffecc3c8447f9789c295;p=evince.git diff --git a/ps/ps-document.c b/ps/ps-document.c index 5a4a4571..75009dc9 100644 --- a/ps/ps-document.c +++ b/ps/ps-document.c @@ -137,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 @@ -215,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); } @@ -247,6 +247,7 @@ ps_document_widget_event (GtkWidget *widget, GdkEvent *event, gpointer data) gs->busy = FALSE; push_pixbuf (gs); + LOG ("Pixbuf pushed"); } return TRUE; @@ -303,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 */ @@ -312,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; @@ -430,49 +437,22 @@ 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) { gchar *buf; - int urx, ury, llx, lly, orientation; 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"); 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); buf = g_strdup_printf ("%ld %d %d %d %d %d %s %s %d %d %d %d", - 0L, orientation * 90, llx, lly, urx, ury, + 0L, rotation, llx, lly, urx, ury, scaled_xdpi, scaled_ydpi, 0, 0, 0, 0); LOG ("GS property %s", buf); @@ -636,7 +616,7 @@ start_interpreter (PSDocument *gs) #define NUM_GS_ARGS (NUM_ARGS - 20) #define NUM_ALPHA_ARGS 10 - char *argv[NUM_ARGS], *dir, *gv_env; + char *argv[NUM_ARGS], *dir, *gv_env, *gs_path; char **gs_args, **alpha_args = NULL; int argc = 0, i; @@ -648,7 +628,9 @@ start_interpreter (PSDocument *gs) stop_interpreter(gs); /* set up the args... */ - gs_args = g_strsplit (gtk_gs_defaults_get_interpreter_cmd (), " ", NUM_GS_ARGS); + gs_path = g_find_program_in_path ("gs"); + gs_args = g_strsplit (gs_path, " ", NUM_GS_ARGS); + g_free (gs_path); for(i = 0; i < NUM_GS_ARGS && gs_args[i]; i++, argc++) { argv[argc] = gs_args[i]; } @@ -1076,28 +1058,79 @@ ps_document_load (EvDocument *document, const char *uri, GError **error) { - gboolean result; char *filename; + char *gs_path; + gboolean result; filename = g_filename_from_uri (uri, NULL, error); if (!filename) return FALSE; - result = document_load (PS_DOCUMENT (document), filename); - if (!result) { - gchar *filename_dsp; + gs_path = g_find_program_in_path ("gs"); + if (!gs_path) { + gchar *filename_dsp; + filename_dsp = g_filename_display_name (filename); + g_set_error(error, + G_FILE_ERROR, + G_FILE_ERROR_NOENT, + _("Failed to load document '%s'. Ghostscript interpreter was not found in path"), + filename); + g_free (filename_dsp); + result = FALSE; + } else { + 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'"), + filename_dsp); + g_free (filename_dsp); + } + g_free (gs_path); + } + g_free (filename); - filename_dsp = g_filename_display_name (filename); + return result; +} - g_set_error (error, G_FILE_ERROR, - G_FILE_ERROR_FAILED, - _("Failed to load document '%s'"), - filename_dsp); +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; - g_free (filename_dsp); + 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 (filename); + g_free (buf); + gtk_gs_doc_sink_free (sink); + g_free (sink); return result; } @@ -1136,23 +1169,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; @@ -1179,35 +1204,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; } } @@ -1218,7 +1224,7 @@ 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); @@ -1234,8 +1240,8 @@ ps_async_renderer_render_pixbuf (EvAsyncRenderer *renderer, int page, double sca 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); } @@ -1284,9 +1290,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); } @@ -1295,7 +1304,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 @@ -1303,13 +1314,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