*** scanfont.c	1999/12/27 00:34:02	1.1
--- scanfont.c	1999/12/27 00:35:34
***************
*** 2234,2239 ****
--- 2234,2241 ----
      /* 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--;
*** paths.c	1999/12/27 00:37:01	1.1
--- paths.c	1999/12/27 00:37:43
***************
*** 583,589 ****
                 CONCAT(before, r);
                 r = before;
         }
!        else
                 r->context = after->context;
         if (after != NULL)
                 CONCAT(r, after);
--- 583,589 ----
                 CONCAT(before, r);
                 r = before;
         }
!        else if (after != NULL)
                 r->context = after->context;
         if (after != NULL)
                 CONCAT(r, after);
*** type1.c	1999/12/27 00:38:16	1.1
--- type1.c	1999/12/27 01:08:02
***************
*** 399,412 ****
    /* 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;
      }
--- 399,414 ----
    /* 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;
      }
***************
*** 414,420 ****
      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;
      }
--- 416,422 ----
      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;
      }
*** t1io.c	2000/01/01 00:41:44	1.1
--- t1io.c	2000/01/01 01:23:38
***************
*** 78,83 ****
--- 78,86 ----
  /* 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();
***************
*** 118,123 ****
--- 121,127 ----
    of->flags = 0;
    of->error = 0;
    haveextrach = 0;
+   T1FileSize = 0;
    return &TheFile;
  } /* end Open */
   
***************
*** 196,202 ****
--- 200,212 ----
  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 */
***************
*** 381,386 ****
--- 391,397 ----
      }
    }
    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 */
*** t1stdio.h	2000/01/01 00:43:38	1.1
--- t1stdio.h	2000/01/01 01:24:19
***************
*** 73,78 ****
--- 73,79 ----
  
  extern FILE *T1Open(), *T1eexec();
  extern int T1Close(), T1Ungetc(), T1Read();
+ extern int T1FileSize;
   
  #undef fclose
  #undef fopen
*** fontfcn.c	2000/01/01 00:07:54	1.1
--- fontfcn.c	2000/01/01 01:36:02
***************
*** 57,62 ****
--- 57,63 ----
  #endif
  #include "t1imager.h"
  #include "util.h"
+ #include "t1stdio.h"
  #ifdef BUILDCID
  #include "range.h"
  #include "fontmisc.h"
***************
*** 300,333 ****
    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 */
  #ifdef BUILDCID
      /* xfree(vm_base); */
  #else
      xfree(vm_base);
  #endif
      if (!(initFont(vm_size * 2))) {
        /* we are really out of memory */
        return(SCAN_OUT_OF_MEMORY);
        }
      resetFont(env);
      rcode = scan_font(FontP);
- #ifdef BUILDCID
-     /* only double the memory twice, then report error */
-     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);
-     }
- #else
-     /* only double the memory once, then report error */
- #endif
    }
    return(rcode);
  }
--- 301,342 ----
    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 */
  #ifdef BUILDCID
      /* xfree(vm_base); */
  #else
      xfree(vm_base);
  #endif
+     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 ) {
+ #ifdef BUILDCID
+     /* xfree(vm_base); */
+ #else
+     xfree(vm_base);
+ #endif
      if (!(initFont(vm_size * 2))) {
        /* we are really out of memory */
        return(SCAN_OUT_OF_MEMORY);
        }
      resetFont(env);
      rcode = scan_font(FontP);
    }
    return(rcode);
  }
*** util.h	2000/01/01 00:40:11	1.1
--- util.h	2000/01/01 01:29:18
***************
*** 83,88 ****
--- 83,92 ----
  #else
  #define VM_SIZE               (50*1024)
  #endif
+ 
+ /* this is the maximal permitted memory size */
+ #define VM_SIZE_MAX           (1024*1024)
+ 
  /***================================================================***/
   
  #ifndef MIN
