#include <math.h>
#include "ps-document.h"
+#include "ev-debug.h"
#include "gsdefaults.h"
#ifdef HAVE_LOCALE_H
gs->right_margin = 0;
gs->bottom_margin = 0;
+ gs->page_x_offset = 0;
+ gs->page_y_offset = 0;
+
/* Set user defined defaults */
gs->override_orientation = gtk_gs_defaults_get_override_orientation();
gs->fallback_orientation = gtk_gs_defaults_get_orientation();
}
static void
-ps_document_class_init(PSDocumentClass * klass)
+ps_document_class_init(PSDocumentClass *klass)
{
GObjectClass *object_class;
object_class = (GObjectClass *) klass;
- parent_class = gtk_type_class(gtk_widget_get_type());
+ parent_class = g_type_class_peek_parent (klass);
gs_class = klass;
object_class->finalize = ps_document_finalize;
}
static void
-ps_document_finalize(GObject * object)
+ps_document_finalize (GObject * object)
{
- PSDocument *gs;
+ PSDocument *gs;
- g_return_if_fail(object != NULL);
- g_return_if_fail(GTK_IS_GS(object));
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (GTK_IS_GS (object));
- gs = PS_DOCUMENT(object);
+ LOG ("Finalize");
- ps_document_cleanup(gs);
+ gs = PS_DOCUMENT (object);
- if(gs->input_buffer) {
- g_free(gs->input_buffer);
- gs->input_buffer = NULL;
- }
+ ps_document_cleanup (gs);
+ stop_interpreter (gs);
+
+ if(gs->input_buffer) {
+ g_free(gs->input_buffer);
+ gs->input_buffer = NULL;
+ }
- (*G_OBJECT_CLASS(parent_class)->finalize) (object);
+ (*G_OBJECT_CLASS(parent_class)->finalize) (object);
}
static void
GdkColor white = { 0, 0xFFFF, 0xFFFF, 0xFFFF }; /* pixel, r, g, b */
GdkColormap *colormap;
+ LOG ("Setup the page");
+
#ifdef HAVE_LOCALE_H
char *savelocale;
#endif
gs->bpixmap = NULL;
}
+ LOG ("Create our internal pixmap");
gs->bpixmap = gdk_pixmap_new(gs->pstarget, gs->width, gs->height, -1);
gdk_draw_rectangle(gs->bpixmap, fill, TRUE,
gs->left_margin,
gs->bottom_margin, gs->right_margin, gs->top_margin);
+ LOG ("GS property %s", buf);
+
#ifdef HAVE_LOCALE_H
setlocale(LC_NUMERIC, savelocale);
#endif
int std_out[2]; /* pipe from interp stdout */
int std_err[2]; /* pipe from interp stderr */
+ LOG ("Start the interpreter");
+
#define NUM_ARGS 100
#define NUM_GS_ARGS (NUM_ARGS - 20)
#define NUM_ALPHA_ARGS 10
return -1;
}
+ gv_env = g_strdup_printf("GHOSTVIEW=%ld %ld",
+ gdk_x11_drawable_get_xid(gs->pstarget),
+ gdk_x11_drawable_get_xid(gs->bpixmap));
+
+ LOG ("Launching ghostview with env %s", gv_env);
+
gs->busy = TRUE;
gs->interpreter_pid = fork();
switch (gs->interpreter_pid) {
}
}
- gv_env = g_strdup_printf("GHOSTVIEW=%ld %ld",
- gdk_x11_drawable_get_xid(gs->pstarget),
- gdk_x11_drawable_get_xid(gs->bpixmap));
putenv(gv_env);
/* change to directory where the input file is. This helps
{
if(gs->interpreter_pid > 0) {
int status = 0;
+ LOG ("Stop the interpreter");
kill(gs->interpreter_pid, SIGTERM);
while((wait(&status) == -1) && (errno == EINTR)) ;
gs->interpreter_pid = -1;
g_return_val_if_fail(gs != NULL, FALSE);
g_return_val_if_fail(GTK_IS_GS(gs), FALSE);
+ LOG ("Load the document");
+
/* clean up previous document */
ps_document_cleanup(gs);
{
XEvent event;
+ LOG ("Make ghostscript render next page");
+
g_return_val_if_fail(gs != NULL, FALSE);
g_return_val_if_fail(GTK_IS_GS(gs), FALSE);
return TRUE;
}
-static gint
-ps_document_get_current_page(PSDocument * gs)
-{
- g_return_val_if_fail(gs != NULL, -1);
- g_return_val_if_fail(GTK_IS_GS(gs), -1);
-
- return gs->current_page;
-}
-
-static gint
-ps_document_get_page_count(PSDocument * gs)
-{
- if(!gs->gs_filename)
- return 0;
-
- if(gs->doc) {
- if(gs->structured_doc)
- return gs->doc->numpages;
- else
- return G_MAXINT;
- }
- else
- return 0;
-}
-
static gboolean
ps_document_goto_page(PSDocument * gs, gint page)
{
g_return_val_if_fail(gs != NULL, FALSE);
g_return_val_if_fail(GTK_IS_GS(gs), FALSE);
+ LOG ("Go to page %d", page);
+
if(!gs->gs_filename) {
return FALSE;
}
page = 0;
if(gs->structured_doc && gs->doc) {
+
+ LOG ("It's a structured document, let's send one page to gs");
+
if(page >= gs->doc->numpages)
page = gs->doc->numpages - 1;
the last page of the file was displayed. In that
case, ggv restarts GS again and the first page is displayed.
*/
+
+ LOG ("It's an unstructured document, gs will just read the file");
+
if(page == gs->current_page && !gs->changed)
return TRUE;
gint new_ury = 0;
GtkGSPaperSize *papersizes = gtk_gs_defaults_get_paper_sizes();
+ LOG ("Set the page size");
+
g_return_val_if_fail(gs != NULL, FALSE);
g_return_val_if_fail(GTK_IS_GS(gs), FALSE);
return FALSE;
result = document_load (PS_DOCUMENT (document), filename);
+ if (!result) {
+ g_set_error (error, G_FILE_ERROR,
+ G_FILE_ERROR_FAILED,
+ "Failed to load document '%s'\n",
+ uri);
+ }
g_free (filename);
return result;
}
+static gboolean
+ps_document_save (EvDocument *document,
+ const char *uri,
+ GError **error)
+{
+ g_warning ("ps_document_save not implemented"); /* FIXME */
+ return TRUE;
+}
+
static int
ps_document_get_n_pages (EvDocument *document)
{
- return ps_document_get_page_count (PS_DOCUMENT (document));
+ PSDocument *ps = PS_DOCUMENT (document);
+
+ g_return_val_if_fail (ps != NULL, -1);
+
+ if (!ps->gs_filename || !ps->doc) {
+ return -1;
+ }
+
+ return ps->structured_doc ? ps->doc->numpages : 1;
}
static void
static int
ps_document_get_page (EvDocument *document)
{
- return ps_document_get_current_page (PS_DOCUMENT (document));
+ PSDocument *ps = PS_DOCUMENT (document);
+
+ g_return_val_if_fail (ps != NULL, -1);
+
+ return ps->current_page;
}
static gboolean
if(event->type != GDK_CLIENT_EVENT)
return FALSE;
+ gs->message_window = event->client.data.l[0];
+
if (event->client.message_type == gs_class->page_atom) {
+ LOG ("GS rendered the document");
gs->busy = FALSE;
ev_document_changed (EV_DOCUMENT (gs));
}
int x,
int y)
{
+ PSDocument *gs = PS_DOCUMENT (document);
+
+ gs->page_x_offset = x;
+ gs->page_y_offset = y;
}
static void
ps_document_get_page_size (EvDocument *document,
- int *width,
- int *height)
+ int page,
+ int *width,
+ int *height)
{
+ /* Post script documents never vary in size */
+
PSDocument *gs = PS_DOCUMENT (document);
if (width) {
int clip_height)
{
PSDocument *gs = PS_DOCUMENT (document);
+ GdkRectangle page;
+ GdkRectangle draw;
GdkGC *gc;
if (gs->pstarget == NULL ||
return;
}
+ page.x = gs->page_x_offset;
+ page.y = gs->page_y_offset;
+ page.width = gs->width;
+ page.height = gs->height;
+
+ draw.x = clip_x;
+ draw.y = clip_y;
+ draw.width = clip_width;
+ draw.height = clip_height;
+
gc = gdk_gc_new (gs->pstarget);
gdk_draw_drawable (gs->pstarget, gc,
gs->bpixmap,
- clip_x, clip_y,
- clip_x, clip_y,
- clip_width, clip_height);
+ draw.x - page.x, draw.y - page.y,
+ draw.x, draw.y,
+ draw.width, draw.height);
+
+ LOG ("Copy the internal pixmap: %d %d %d %d %d %d",
+ draw.x - page.x, draw.y - page.y,
+ draw.x, draw.y, draw.width, draw.height);
g_object_unref (gc);
}
+static char *
+ps_document_get_text (EvDocument *document, GdkRectangle *rect)
+{
+ g_warning ("ps_document_get_text not implemented"); /* FIXME ? */
+ return NULL;
+}
+
static EvLink *
ps_document_get_link (EvDocument *document,
int x,
ps_document_document_iface_init (EvDocumentIface *iface)
{
iface->load = ps_document_load;
+ iface->save = ps_document_save;
+ iface->get_text = ps_document_get_text;
iface->get_link = ps_document_get_link;
iface->get_n_pages = ps_document_get_n_pages;
iface->set_page = ps_document_set_page;