-/* publicly accessible functions */
-
-GType
-ps_document_get_type(void)
-{
- static GType gs_type = 0;
- if(!gs_type) {
- GTypeInfo gs_info = {
- sizeof(PSDocumentClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) ps_document_class_init,
- (GClassFinalizeFunc) NULL,
- NULL, /* class_data */
- sizeof(PSDocument),
- 0, /* n_preallocs */
- (GInstanceInitFunc) ps_document_init
- };
-
- static const GInterfaceInfo document_info =
- {
- (GInterfaceInitFunc) ps_document_document_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);
- }
- return gs_type;
-
-
-}
-
-/*
- * Show error message -> send signal "interpreter_message"
- */
-static void
-ps_document_emit_error_msg(PSDocument * gs, const gchar * msg)
-{
- gdk_pointer_ungrab(GDK_CURRENT_TIME);
- if(strstr(msg, "Error:")) {
- gs->gs_status = _("File is not a valid PostScript document.");
- ps_document_cleanup(gs);
- }
-}
-
-static gboolean
-document_load(PSDocument * gs, const gchar * fname)
-{
- 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);
-
- if(fname == NULL) {
- gs->gs_status = "";
- return FALSE;
- }
-
- /* prepare this document */
-
- /* default values: no dsc information available */
- gs->structured_doc = FALSE;
- gs->send_filename_to_gs = TRUE;
- gs->current_page = -2;
- gs->loaded = FALSE;
- if(*fname == '/') {
- /* an absolute path */
- gs->gs_filename = g_strdup(fname);
- }
- else {
- /* path relative to our cwd: make it absolute */
- gchar *cwd = g_get_current_dir();
- gs->gs_filename = g_strconcat(cwd, "/", fname, NULL);
- g_free(cwd);
- }
-
- if((gs->reading_from_pipe = (strcmp(fname, "-") == 0))) {
- gs->send_filename_to_gs = FALSE;
- }
- else {
- /*
- * We need to make sure that the file is loadable/exists!
- * otherwise we want to exit without loading new stuff...
- */
- gchar *filename = NULL;
-
- if(!file_readable(fname)) {
- gchar buf[1024];
- g_snprintf(buf, 1024, _("Cannot open file %s.\n"), fname);
- ps_document_emit_error_msg(gs, buf);
- gs->gs_status = _("File is not readable.");
- }
- else {
- filename = check_filecompressed(gs);
- if(filename)
- filename = check_pdf(gs);
- }
-
- if(!filename || (gs->gs_psfile = fopen(filename, "r")) == NULL) {
- ps_document_cleanup(gs);
- return FALSE;
- }
-
- /* we grab the vital statistics!!! */
- gs->doc = psscan(gs->gs_psfile, gs->respect_eof, filename);
-
- g_object_notify (G_OBJECT (gs), "title");
-
- if(gs->doc == NULL) {
- /* File does not seem to be a Postscript one */
- gchar buf[1024];
- g_snprintf(buf, 1024, _("Error while scanning file %s\n"), fname);
- ps_document_emit_error_msg(gs, buf);
- ps_document_cleanup(gs);
- gs->gs_status = _("The file is not a PostScript document.");
- return FALSE;
- }
-
- if((!gs->doc->epsf && gs->doc->numpages > 0) ||
- (gs->doc->epsf && gs->doc->numpages > 1)) {
- gs->structured_doc = TRUE;
- gs->send_filename_to_gs = FALSE;
- }
-
- /* We have to set up the orientation of the document */
-
-
- /* orientation can only be portrait, and landscape or none.
- This is the document default. A document can have
- pages in landscape and some in portrait */
- if(gs->override_orientation) {
- /* If the orientation should be override...
- then gs->orientation has already the correct
- value (it was set when the widget was created */
- /* So do nothing */
-
- }
- else {
- /* Otherwise, set the proper orientation for the doc */
- gs->real_orientation = gs->doc->orientation;
- }
- }
- ps_document_set_page_size(gs, -1, gs->current_page);
- gs->loaded = TRUE;
-
- gs->gs_status = _("Document loaded.");
-
- return gs->loaded;
-}
-
-