Index: trunk/Jgraph/draw.c
===================================================================
--- trunk/Jgraph/draw.c	(revision 418)
+++ trunk/Jgraph/draw.c	(revision 419)
@@ -9,4 +9,6 @@
 #include <stdio.h>
 #include <math.h>
+#include <stdlib.h> //by pzn@debian.org
+#include <string.h> //by pzn@debian.org
 
 static char real_eof = EOF;
@@ -315,5 +317,5 @@
               }
               for (i = 0; i < 4; i++) {
-                if (fscanf(f, "%d", &(bb[i])) != 1) {
+                if (fscanf(f, "%d", &(bb[i])) == NULL) {
                   fprintf(stderr, "Error: Eps file '%s': eof in %s\n",
                           c->eps, "bounding box");
@@ -642,6 +644,8 @@
   Graphs gs_p;
   Graph g;
+  int page_counter=0;
 
   for (gs_p = first(gs); gs_p != nil(gs); gs_p = next(gs_p)) {
+    page_counter++;
     draw_header(gs_p, pp, landscape);
     for (g = first(gs_p->g); g != nil(gs_p->g); g = next(g)) {
@@ -649,4 +653,9 @@
     }
     draw_footer(gs_p, pp);
+  }
+  if (pp) {
+      printf("\n%%%%Trailer\n");
+      printf("%%%%Pages: %i\n",page_counter);
+      printf("%%%%EOF\n");
   }
 }
@@ -660,15 +669,94 @@
   char c;
 
-  if (gs->page == 1) printf("%%!PS-Adobe-2.0 EPSF-1.2\n");
-  printf("%%%%Page: %d %d\n", gs->page, gs->page);
-  if (landscape) {
-    printf("%%%%BoundingBox: %d %d %d %d\n", gs->bb[1], gs->bb[0], 
-            gs->bb[3], gs->bb[2]);
+  if (gs->page == 1) {
+      if (pp) {
+	  printf("%%!PS-Adobe-3.0\n");
+	  printf("%%%%Pages: (atend)\n");
+	  printf("%%%%Creator: jgraph\n");
+	  printf("%%%%EndComments\n\n");
+	  printf("%%%%BeginProlog\n");
+	  printf("%%%%EndProlog\n");
+	  printf("%%%%BeginSetup\n");
+	  printf("%%%%EndSetup\n");
+      } else {
+	  printf("%%!PS-Adobe-2.0 EPSF-1.2\n");
+	  printf("%%%%Creator: jgraph\n");
+      }
+  }
+
+  if (pp) {
+      printf("\n%%%%Page: %d %d\n", gs->page, gs->page);
+      printf("%%%%BeginPageSetup\n");
+      printf("%%%%EndPageSetup\n\n");
+  }
+
+  if ( (gs->page>1) && !pp ) {
+      /* tring EPS with more than one page */
+      fprintf(stderr, "Error: 'newpage' token is not allowed"
+	      " without '-P' command line option.\n");
+      exit(1);
+  }
+
+  /* if (landscape) {
+      printf("%%%%BoundingBox: %d %d %d %d\n", gs->bb[1], gs->bb[0],
+	     gs->bb[3], gs->bb[2]);
   } else {
-    printf("%%%%BoundingBox: %d %d %d %d\n", gs->bb[0], gs->bb[1], 
-            gs->bb[2], gs->bb[3]);
-  }
-
-  printf("%%%%EndComments\n");
+      printf("%%%%BoundingBox: %d %d %d %d\n", gs->bb[0], gs->bb[1],
+	     gs->bb[2], gs->bb[3]);
+  }
+  printf("%%%%EndComments\n"); */
+
+  //BEGIN added by pzn@debian.org
+  { // expands the bounding box to fit characters with tilde, acute,...
+    // if user has set JGRAPH_BORDER enviroment variable
+    int expandborder=0;
+    char *s;                          \
+    s=(char *)getenv("JGRAPH_BORDER");
+    if (s!=NULL) {
+	expandborder=atoi(s);
+    }
+   if (!pp) {
+    if (landscape) {
+      printf("%%%%BoundingBox: %d %d %d %d\n", gs->bb[1]-expandborder,
+	     gs->bb[0]-expandborder, gs->bb[3]+expandborder,
+	     gs->bb[2]+expandborder);
+    } else {
+      printf("%%%%BoundingBox: %d %d %d %d\n", gs->bb[0]-expandborder,
+             gs->bb[1]-expandborder, gs->bb[2]+expandborder,
+             gs->bb[3]+expandborder);
+    }
+    printf("%%%%EndComments\n\n");
+   }
+  }
+
+  if (gs->page==1)
+  //reencode fonts to ISOLatin1 or other
+  {   //NOTE: this is a preliminary version. It will only work with
+      //      the default fonts, that are Times-Roman and Times-Bold
+      // "export JGRAPH_ENCODING=ISOLatin1Encoding" will work in sh
+      char *s;                          \
+      s=(char *)getenv("JGRAPH_ENCODING");
+      if ((s!=NULL) && (strlen(s)>0)) {
+	  comment("Setting font encoding by pzn@debian.org");
+	  printf("/Times-Bold findfont\n");
+	  printf("dup length dict begin\n");
+	  printf(" {1 index /FID ne {def} {pop pop} ifelse} forall\n");
+	  printf(" /Encoding %s def\n",s);
+	  printf(" currentdict\n");
+	  printf("end\n");
+	  printf("/Times-Bold exch definefont pop\n");
+	  printf("/Times-Roman findfont\n");
+	  printf("dup length dict begin\n");
+	  printf(" {1 index /FID ne {def} {pop pop} ifelse} forall\n");
+	  printf(" /Encoding %s def\n",s);
+	  printf(" currentdict\n");
+	  printf("end\n");
+	  printf("/Times-Roman exch definefont pop\n");
+	  comment("End of font encoding");
+	  printf("\n");
+      }
+  }
+  //END added by pzn
+
   if (landscape) {
     printf("-90 rotate\n");
@@ -771,4 +859,9 @@
   grestore();
   if (pp) printf("showpage\n"); else printf("\n");
-}
-
+
+  if (pp) {
+      printf("%%%%PageTrailer\n");
+  }
+
+}
+
