*** fontfcn.c	2000/01/02 18:55:56	1.1
--- fontfcn.c	2000/01/02 19:00:17
***************
*** 33,38 ****
--- 33,39 ----
  #include <string.h>
  #include "t1imager.h"
  #include "util.h"
+ #include "t1stdio.h"
  #include "fontfcn.h"
  #include "fontmisc.h"
   
***************
*** 117,132 ****
    resetFont(env);
    /* This will load the font into the FontP */
    rcode = scan_font(FontP);
!   if (rcode == SCAN_OUT_OF_MEMORY) {
      /* free the memory and start again */
      xfree(vm_base);
      if (!(initFont(vm_size * 2))) {
        /* we are really out of memory */
        return(SCAN_OUT_OF_MEMORY);
        }
      resetFont(env);
      rcode = scan_font(FontP);
-     /* only double the memory once, then report error */
    }
    return(rcode);
  }
--- 118,151 ----
    resetFont(env);
    /* This will load the font into the FontP */
    rcode = scan_font(FontP);
!   if (rcode != SCAN_OUT_OF_MEMORY) 
!     return rcode;
! 
!   if (T1FileSize > VM_SIZE) {
!     /* use the file size as estimation */
! 
      /* free the memory and start again */
      xfree(vm_base);
+     if (!(initFont(T1FileSize))) {
+ 	/* we are really out of memory */
+ 	return(SCAN_OUT_OF_MEMORY);
+     }
+     resetFont(env);
+     rcode = scan_font(FontP);
+     if (rcode != SCAN_OUT_OF_MEMORY) 
+       return rcode;
+   }
+ 
+   /* if still not enough, increase up to maximum */
+   while (rcode == SCAN_OUT_OF_MEMORY
+   && vm_size <= VM_SIZE_MAX/2 ) {
+     xfree(vm_base);
      if (!(initFont(vm_size * 2))) {
        /* we are really out of memory */
        return(SCAN_OUT_OF_MEMORY);
        }
      resetFont(env);
      rcode = scan_font(FontP);
    }
    return(rcode);
  }
*** paths.c	2000/01/02 18:55:56	1.1
--- paths.c	2000/01/02 18:56:27
***************
*** 584,590 ****
                 CONCAT(before, r);
                 r = before;
         }
!        else
                 r->context = after->context;
         if (after != NULL)
                 CONCAT(r, after);
--- 584,590 ----
                 CONCAT(before, r);
                 r = before;
         }
!        else if (after != NULL)
                 r->context = after->context;
         if (after != NULL)
                 CONCAT(r, after);
*** scanfont.c	2000/01/02 18:55:56	1.1
--- scanfont.c	2000/01/02 18:56:26
***************
*** 1383,1388 ****
--- 1383,1390 ----
      /* point to name and search for leading blanks */
      nameP= FontP->FontFileName.data.nameP;
      namelen  = FontP->FontFileName.len;
+     if (namelen > (128-1) ) /* prevent getting out of filename[] */
+ 	namelen = (128-1);
      while (nameP[0] == ' ') {
          nameP++;
          namelen--;
*** t1io.c	2000/01/02 18:55:56	1.1
--- t1io.c	2000/01/02 18:56:32
***************
*** 54,59 ****
--- 54,62 ----
  /* Our single FILE structure and buffer for this package */
  STATIC F_FILE TheFile;
  STATIC unsigned char TheBuffer[F_BUFSIZ];
+ 
+ /* the size of the file we read */
+ int T1FileSize;
   
  /* Our routines */
  F_FILE *T1Open(), *T1Eexec();
***************
*** 87,92 ****
--- 90,96 ----
    of->flags = 0;
    of->error = 0;
    haveextrach = 0;
+   T1FileSize = 0;
    return &TheFile;
  } /* end Open */
   
***************
*** 165,171 ****
--- 169,181 ----
  int T1Close(f)       /* Close the file */
    F_FILE *f;         /* Stream descriptor */
  {
+   int rc;
+ 
    if (f->b_base == NULL) return 0;  /* already closed */
+ 
+   while ( (rc = read(f->fd, f->b_base, F_BUFSIZ)) >0)
+ 	T1FileSize += rc; /* count the rest of the file */
+ 
    f->b_base = NULL;  /* no valid stream */
    return close(f->fd);
  } /* end Close */
***************
*** 289,294 ****
--- 299,305 ----
      }
    }
    f->b_ptr = f->b_base;
+   T1FileSize += rc; /* remember how many bytes we have */
    if (Decrypt) rc = T1Decrypt(f->b_base, rc);
    return rc;
  } /* end Fill */
*** type1.c	2000/01/02 18:55:56	1.1
--- type1.c	2000/01/02 18:56:27
***************
*** 365,378 ****
    /* ADJUST STEM WIDTHS */
    /**********************/
   
!   widthdiff = 0.0;
   
    /* Find standard stem with smallest width difference from this stem */
    if (stems[stemno].vertical) { /* vertical stem */
      if (blues->StdVW != 0)      /* there is an entry for StdVW */
        widthdiff = blues->StdVW - stemwidth;
      for (i = 0; i < blues->numStemSnapV; ++i) { /* now look at StemSnapV */
!       if (blues->StemSnapV[i] - stemwidth < widthdiff)
          /* this standard width is the best match so far for this stem */
          widthdiff = blues->StemSnapV[i] - stemwidth;
      }
--- 365,380 ----
    /* ADJUST STEM WIDTHS */
    /**********************/
   
!   /* a big value to not compete with StemSnap */
!   /* if there is no StemSnap it will be caught later */
!   widthdiff = onepixel*2; 
   
    /* Find standard stem with smallest width difference from this stem */
    if (stems[stemno].vertical) { /* vertical stem */
      if (blues->StdVW != 0)      /* there is an entry for StdVW */
        widthdiff = blues->StdVW - stemwidth;
      for (i = 0; i < blues->numStemSnapV; ++i) { /* now look at StemSnapV */
!       if ( FABS(blues->StemSnapV[i] - stemwidth) < FABS(widthdiff) )
          /* this standard width is the best match so far for this stem */
          widthdiff = blues->StemSnapV[i] - stemwidth;
      }
***************
*** 380,386 ****
      if (blues->StdHW != 0)      /* there is an entry for StdHW */
        widthdiff = blues->StdHW - stemwidth;
      for (i = 0; i < blues->numStemSnapH; ++i) { /* now look at StemSnapH */
!       if (blues->StemSnapH[i] - stemwidth < widthdiff)
          /* this standard width is the best match so far for this stem */
          widthdiff = blues->StemSnapH[i] - stemwidth;
      }
--- 382,388 ----
      if (blues->StdHW != 0)      /* there is an entry for StdHW */
        widthdiff = blues->StdHW - stemwidth;
      for (i = 0; i < blues->numStemSnapH; ++i) { /* now look at StemSnapH */
!       if ( FABS(blues->StemSnapH[i] - stemwidth) < FABS(widthdiff) )
          /* this standard width is the best match so far for this stem */
          widthdiff = blues->StemSnapH[i] - stemwidth;
      }
