#include "ps-document.h"
#include "ev-debug.h"
#include "gsdefaults.h"
+#include "ev-ps-exporter.h"
#ifdef HAVE_LOCALE_H
# include <locale.h>
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;
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;
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)
{
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
pixmap_width = floor (width * scale);
pixmap_height = floor (height * scale);
- g_print ("%f %f %f %d %d\n", width, height, scale, pixmap_width, pixmap_height);
-
if(gs->bpixmap) {
int w, h;
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;
}
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;
/* 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];
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
}
}
-static char *
-ps_document_get_text (EvDocument *document, int page, EvRectangle *rect)
+static gboolean
+ps_document_can_get_text (EvDocument *document)
{
- g_warning ("ps_document_get_text not implemented"); /* FIXME ? */
- return NULL;
+ return FALSE;
}
static gboolean
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)
{
iface->load = ps_document_load;
iface->save = ps_document_save;
- iface->get_text = ps_document_get_text;
+ iface->can_get_text = ps_document_can_get_text;
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;
}