[3019] | 1 | *** fontfcn.c 2000/01/02 18:55:56 1.1 |
---|
| 2 | --- fontfcn.c 2000/01/02 19:00:17 |
---|
| 3 | *************** |
---|
| 4 | *** 33,38 **** |
---|
| 5 | --- 33,39 ---- |
---|
| 6 | #include <string.h> |
---|
| 7 | #include "t1imager.h" |
---|
| 8 | #include "util.h" |
---|
| 9 | + #include "t1stdio.h" |
---|
| 10 | #include "fontfcn.h" |
---|
| 11 | #include "fontmisc.h" |
---|
| 12 | |
---|
| 13 | *************** |
---|
| 14 | *** 117,132 **** |
---|
| 15 | resetFont(env); |
---|
| 16 | /* This will load the font into the FontP */ |
---|
| 17 | rcode = scan_font(FontP); |
---|
| 18 | ! if (rcode == SCAN_OUT_OF_MEMORY) { |
---|
| 19 | /* free the memory and start again */ |
---|
| 20 | xfree(vm_base); |
---|
| 21 | if (!(initFont(vm_size * 2))) { |
---|
| 22 | /* we are really out of memory */ |
---|
| 23 | return(SCAN_OUT_OF_MEMORY); |
---|
| 24 | } |
---|
| 25 | resetFont(env); |
---|
| 26 | rcode = scan_font(FontP); |
---|
| 27 | - /* only double the memory once, then report error */ |
---|
| 28 | } |
---|
| 29 | return(rcode); |
---|
| 30 | } |
---|
| 31 | --- 118,151 ---- |
---|
| 32 | resetFont(env); |
---|
| 33 | /* This will load the font into the FontP */ |
---|
| 34 | rcode = scan_font(FontP); |
---|
| 35 | ! if (rcode != SCAN_OUT_OF_MEMORY) |
---|
| 36 | ! return rcode; |
---|
| 37 | ! |
---|
| 38 | ! if (T1FileSize > VM_SIZE) { |
---|
| 39 | ! /* use the file size as estimation */ |
---|
| 40 | ! |
---|
| 41 | /* free the memory and start again */ |
---|
| 42 | xfree(vm_base); |
---|
| 43 | + if (!(initFont(T1FileSize))) { |
---|
| 44 | + /* we are really out of memory */ |
---|
| 45 | + return(SCAN_OUT_OF_MEMORY); |
---|
| 46 | + } |
---|
| 47 | + resetFont(env); |
---|
| 48 | + rcode = scan_font(FontP); |
---|
| 49 | + if (rcode != SCAN_OUT_OF_MEMORY) |
---|
| 50 | + return rcode; |
---|
| 51 | + } |
---|
| 52 | + |
---|
| 53 | + /* if still not enough, increase up to maximum */ |
---|
| 54 | + while (rcode == SCAN_OUT_OF_MEMORY |
---|
| 55 | + && vm_size <= VM_SIZE_MAX/2 ) { |
---|
| 56 | + xfree(vm_base); |
---|
| 57 | if (!(initFont(vm_size * 2))) { |
---|
| 58 | /* we are really out of memory */ |
---|
| 59 | return(SCAN_OUT_OF_MEMORY); |
---|
| 60 | } |
---|
| 61 | resetFont(env); |
---|
| 62 | rcode = scan_font(FontP); |
---|
| 63 | } |
---|
| 64 | return(rcode); |
---|
| 65 | } |
---|
| 66 | *** paths.c 2000/01/02 18:55:56 1.1 |
---|
| 67 | --- paths.c 2000/01/02 18:56:27 |
---|
| 68 | *************** |
---|
| 69 | *** 584,590 **** |
---|
| 70 | CONCAT(before, r); |
---|
| 71 | r = before; |
---|
| 72 | } |
---|
| 73 | ! else |
---|
| 74 | r->context = after->context; |
---|
| 75 | if (after != NULL) |
---|
| 76 | CONCAT(r, after); |
---|
| 77 | --- 584,590 ---- |
---|
| 78 | CONCAT(before, r); |
---|
| 79 | r = before; |
---|
| 80 | } |
---|
| 81 | ! else if (after != NULL) |
---|
| 82 | r->context = after->context; |
---|
| 83 | if (after != NULL) |
---|
| 84 | CONCAT(r, after); |
---|
| 85 | *** scanfont.c 2000/01/02 18:55:56 1.1 |
---|
| 86 | --- scanfont.c 2000/01/02 18:56:26 |
---|
| 87 | *************** |
---|
| 88 | *** 1383,1388 **** |
---|
| 89 | --- 1383,1390 ---- |
---|
| 90 | /* point to name and search for leading blanks */ |
---|
| 91 | nameP= FontP->FontFileName.data.nameP; |
---|
| 92 | namelen = FontP->FontFileName.len; |
---|
| 93 | + if (namelen > (128-1) ) /* prevent getting out of filename[] */ |
---|
| 94 | + namelen = (128-1); |
---|
| 95 | while (nameP[0] == ' ') { |
---|
| 96 | nameP++; |
---|
| 97 | namelen--; |
---|
| 98 | *** t1io.c 2000/01/02 18:55:56 1.1 |
---|
| 99 | --- t1io.c 2000/01/02 18:56:32 |
---|
| 100 | *************** |
---|
| 101 | *** 54,59 **** |
---|
| 102 | --- 54,62 ---- |
---|
| 103 | /* Our single FILE structure and buffer for this package */ |
---|
| 104 | STATIC F_FILE TheFile; |
---|
| 105 | STATIC unsigned char TheBuffer[F_BUFSIZ]; |
---|
| 106 | + |
---|
| 107 | + /* the size of the file we read */ |
---|
| 108 | + int T1FileSize; |
---|
| 109 | |
---|
| 110 | /* Our routines */ |
---|
| 111 | F_FILE *T1Open(), *T1Eexec(); |
---|
| 112 | *************** |
---|
| 113 | *** 87,92 **** |
---|
| 114 | --- 90,96 ---- |
---|
| 115 | of->flags = 0; |
---|
| 116 | of->error = 0; |
---|
| 117 | haveextrach = 0; |
---|
| 118 | + T1FileSize = 0; |
---|
| 119 | return &TheFile; |
---|
| 120 | } /* end Open */ |
---|
| 121 | |
---|
| 122 | *************** |
---|
| 123 | *** 165,171 **** |
---|
| 124 | --- 169,181 ---- |
---|
| 125 | int T1Close(f) /* Close the file */ |
---|
| 126 | F_FILE *f; /* Stream descriptor */ |
---|
| 127 | { |
---|
| 128 | + int rc; |
---|
| 129 | + |
---|
| 130 | if (f->b_base == NULL) return 0; /* already closed */ |
---|
| 131 | + |
---|
| 132 | + while ( (rc = read(f->fd, f->b_base, F_BUFSIZ)) >0) |
---|
| 133 | + T1FileSize += rc; /* count the rest of the file */ |
---|
| 134 | + |
---|
| 135 | f->b_base = NULL; /* no valid stream */ |
---|
| 136 | return close(f->fd); |
---|
| 137 | } /* end Close */ |
---|
| 138 | *************** |
---|
| 139 | *** 289,294 **** |
---|
| 140 | --- 299,305 ---- |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | f->b_ptr = f->b_base; |
---|
| 144 | + T1FileSize += rc; /* remember how many bytes we have */ |
---|
| 145 | if (Decrypt) rc = T1Decrypt(f->b_base, rc); |
---|
| 146 | return rc; |
---|
| 147 | } /* end Fill */ |
---|
| 148 | *** type1.c 2000/01/02 18:55:56 1.1 |
---|
| 149 | --- type1.c 2000/01/02 18:56:27 |
---|
| 150 | *************** |
---|
| 151 | *** 365,378 **** |
---|
| 152 | /* ADJUST STEM WIDTHS */ |
---|
| 153 | /**********************/ |
---|
| 154 | |
---|
| 155 | ! widthdiff = 0.0; |
---|
| 156 | |
---|
| 157 | /* Find standard stem with smallest width difference from this stem */ |
---|
| 158 | if (stems[stemno].vertical) { /* vertical stem */ |
---|
| 159 | if (blues->StdVW != 0) /* there is an entry for StdVW */ |
---|
| 160 | widthdiff = blues->StdVW - stemwidth; |
---|
| 161 | for (i = 0; i < blues->numStemSnapV; ++i) { /* now look at StemSnapV */ |
---|
| 162 | ! if (blues->StemSnapV[i] - stemwidth < widthdiff) |
---|
| 163 | /* this standard width is the best match so far for this stem */ |
---|
| 164 | widthdiff = blues->StemSnapV[i] - stemwidth; |
---|
| 165 | } |
---|
| 166 | --- 365,380 ---- |
---|
| 167 | /* ADJUST STEM WIDTHS */ |
---|
| 168 | /**********************/ |
---|
| 169 | |
---|
| 170 | ! /* a big value to not compete with StemSnap */ |
---|
| 171 | ! /* if there is no StemSnap it will be caught later */ |
---|
| 172 | ! widthdiff = onepixel*2; |
---|
| 173 | |
---|
| 174 | /* Find standard stem with smallest width difference from this stem */ |
---|
| 175 | if (stems[stemno].vertical) { /* vertical stem */ |
---|
| 176 | if (blues->StdVW != 0) /* there is an entry for StdVW */ |
---|
| 177 | widthdiff = blues->StdVW - stemwidth; |
---|
| 178 | for (i = 0; i < blues->numStemSnapV; ++i) { /* now look at StemSnapV */ |
---|
| 179 | ! if ( FABS(blues->StemSnapV[i] - stemwidth) < FABS(widthdiff) ) |
---|
| 180 | /* this standard width is the best match so far for this stem */ |
---|
| 181 | widthdiff = blues->StemSnapV[i] - stemwidth; |
---|
| 182 | } |
---|
| 183 | *************** |
---|
| 184 | *** 380,386 **** |
---|
| 185 | if (blues->StdHW != 0) /* there is an entry for StdHW */ |
---|
| 186 | widthdiff = blues->StdHW - stemwidth; |
---|
| 187 | for (i = 0; i < blues->numStemSnapH; ++i) { /* now look at StemSnapH */ |
---|
| 188 | ! if (blues->StemSnapH[i] - stemwidth < widthdiff) |
---|
| 189 | /* this standard width is the best match so far for this stem */ |
---|
| 190 | widthdiff = blues->StemSnapH[i] - stemwidth; |
---|
| 191 | } |
---|
| 192 | --- 382,388 ---- |
---|
| 193 | if (blues->StdHW != 0) /* there is an entry for StdHW */ |
---|
| 194 | widthdiff = blues->StdHW - stemwidth; |
---|
| 195 | for (i = 0; i < blues->numStemSnapH; ++i) { /* now look at StemSnapH */ |
---|
| 196 | ! if ( FABS(blues->StemSnapH[i] - stemwidth) < FABS(widthdiff) ) |
---|
| 197 | /* this standard width is the best match so far for this stem */ |
---|
| 198 | widthdiff = blues->StemSnapH[i] - stemwidth; |
---|
| 199 | } |
---|