]> www.fi.muni.cz Git - evince.git/blobdiff - backend/ps/ps.c
Make fullscreen toolbar always visible. Do not use egg toolbars for
[evince.git] / backend / ps / ps.c
index b4b54e05a2f1eba31d382b0c14e8197ea5426c4c..cccf241b0f660e2cb12a709465d33e251588657a 100644 (file)
@@ -264,7 +264,7 @@ psscan(FILE * file, int respect_eof, const gchar * fname)
 
   rewind(file);
 
-  fd =  ps_io_init(file);
+  fd = ps_io_init(file);
   if (!readline(fd, &line, &position, &line_len)) {
     fprintf(stderr, "Warning: empty file.\n");
     ps_io_exit(fd);
@@ -280,6 +280,7 @@ psscan(FILE * file, int respect_eof, const gchar * fname)
           && (line[0] != '%')) ;
     if(line[0] != '%') {
       g_print("psscan error: input files seems to be a PJL file.\n");
+      ps_io_exit(fd);
       return (NULL);
     }
   }
@@ -326,6 +327,7 @@ psscan(FILE * file, int respect_eof, const gchar * fname)
     doc = g_new0(struct document, 1);
     doc->default_page_orientation = GTK_GS_ORIENTATION_NONE;
     doc->orientation = GTK_GS_ORIENTATION_NONE;
+    ps_io_exit(fd);
     return (doc);
   }
 
@@ -1137,6 +1139,7 @@ newpage:
     }
   }
 #endif
+  ps_io_exit(fd);
   return doc;
 }
 
@@ -1870,3 +1873,90 @@ static char *readline (fd, lineP, positionP, line_lenP)
 
    return(FD_BUF+FD_LINE_BEGIN);
 }
+
+#define DEFAULT_PAGE_SIZE 1
+
+void
+psgetpagebox (const struct document *doc, int page, int *urx, int *ury, int *llx, int *lly)
+{
+   gint new_llx = 0;
+   gint new_lly = 0;
+   gint new_urx = 0;
+   gint new_ury = 0;
+   GtkGSPaperSize *papersizes = gtk_gs_defaults_get_paper_sizes ();
+   int new_pagesize = -1;
+
+   if (new_pagesize == -1) {
+      new_pagesize = DEFAULT_PAGE_SIZE;
+      if (doc) {
+         /* If we have a document:
+         * We use -- the page size (if specified)      
+         * or the doc. size (if specified)     
+         * or the page bbox (if specified)     
+         * or the bounding box 
+         */
+         if ((page >= 0) && (doc->numpages > page) &&
+            (doc->pages) && (doc->pages[page].size)) {
+           new_pagesize = doc->pages[page].size - doc->size;
+        } else if (doc->default_page_size != NULL) {
+           new_pagesize = doc->default_page_size - doc->size;
+        } else if ((page >= 0) &&
+                   (doc->numpages > page) &&
+                   (doc->pages) &&
+                   (doc->pages[page].boundingbox[URX] >
+                    doc->pages[page].boundingbox[LLX]) &&
+                   (doc->pages[page].boundingbox[URY] >
+                    doc->pages[page].boundingbox[LLY])) {
+           new_pagesize = -1;
+        } else if ((doc->boundingbox[URX] > doc->boundingbox[LLX]) &&
+                   (doc->boundingbox[URY] > doc->boundingbox[LLY])) {
+           new_pagesize = -1;
+        }
+      }
+   }
+
+   /* Compute bounding box */
+   if (doc && (doc->epsf || new_pagesize == -1)) {    /* epsf or bbox */
+      if ((page >= 0) &&
+         (doc->pages) &&
+         (doc->pages[page].boundingbox[URX] >
+          doc->pages[page].boundingbox[LLX]) &&
+         (doc->pages[page].boundingbox[URY] >
+          doc->pages[page].boundingbox[LLY])) {
+         /* use page bbox */
+        new_llx = doc->pages[page].boundingbox[LLX];
+        new_lly = doc->pages[page].boundingbox[LLY];
+        new_urx = doc->pages[page].boundingbox[URX];
+        new_ury = doc->pages[page].boundingbox[URY];
+      } else if ((doc->boundingbox[URX] > doc->boundingbox[LLX]) &&
+                (doc->boundingbox[URY] > doc->boundingbox[LLY])) {
+        /* use doc bbox */
+        new_llx = doc->boundingbox[LLX];
+        new_lly = doc->boundingbox[LLY];
+        new_urx = doc->boundingbox[URX];
+        new_ury = doc->boundingbox[URY];
+      }
+   } else {
+      if (new_pagesize < 0)
+         new_pagesize = DEFAULT_PAGE_SIZE;
+      new_llx = new_lly = 0;
+      if (doc && doc->size &&
+         (new_pagesize < doc->numsizes)) {
+             new_urx = doc->size[new_pagesize].width;
+        new_ury = doc->size[new_pagesize].height;
+      } else {
+       new_urx = papersizes[new_pagesize].width;
+       new_ury = papersizes[new_pagesize].height;
+      }
+   }
+
+   if (new_urx <= new_llx)
+      new_urx = papersizes[12].width;
+   if (new_ury <= new_lly)
+      new_ury = papersizes[12].height;
+
+   *urx = new_urx;
+   *ury = new_ury;
+   *llx = new_llx;
+   *lly = new_lly;
+}