1 | *** scanfont.c 1999/12/27 00:34:02 1.1 |
---|
2 | --- scanfont.c 1999/12/27 00:35:34 |
---|
3 | *************** |
---|
4 | *** 2234,2239 **** |
---|
5 | --- 2234,2241 ---- |
---|
6 | /* point to name and search for leading blanks */ |
---|
7 | nameP= FontP->FontFileName.data.nameP; |
---|
8 | namelen = FontP->FontFileName.len; |
---|
9 | + if (namelen > (128-1) ) /* prevent getting out of filename[] */ |
---|
10 | + namelen = (128-1); |
---|
11 | while (nameP[0] == ' ') { |
---|
12 | nameP++; |
---|
13 | namelen--; |
---|
14 | *** paths.c 1999/12/27 00:37:01 1.1 |
---|
15 | --- paths.c 1999/12/27 00:37:43 |
---|
16 | *************** |
---|
17 | *** 583,589 **** |
---|
18 | CONCAT(before, r); |
---|
19 | r = before; |
---|
20 | } |
---|
21 | ! else |
---|
22 | r->context = after->context; |
---|
23 | if (after != NULL) |
---|
24 | CONCAT(r, after); |
---|
25 | --- 583,589 ---- |
---|
26 | CONCAT(before, r); |
---|
27 | r = before; |
---|
28 | } |
---|
29 | ! else if (after != NULL) |
---|
30 | r->context = after->context; |
---|
31 | if (after != NULL) |
---|
32 | CONCAT(r, after); |
---|
33 | *** type1.c 1999/12/27 00:38:16 1.1 |
---|
34 | --- type1.c 1999/12/27 01:08:02 |
---|
35 | *************** |
---|
36 | *** 399,412 **** |
---|
37 | /* ADJUST STEM WIDTHS */ |
---|
38 | /**********************/ |
---|
39 | |
---|
40 | ! widthdiff = 0.0; |
---|
41 | |
---|
42 | /* Find standard stem with smallest width difference from this stem */ |
---|
43 | if (stems[stemno].vertical) { /* vertical stem */ |
---|
44 | if (blues->StdVW != 0) /* there is an entry for StdVW */ |
---|
45 | widthdiff = blues->StdVW - stemwidth; |
---|
46 | for (i = 0; i < blues->numStemSnapV; ++i) { /* now look at StemSnapV */ |
---|
47 | ! if (blues->StemSnapV[i] - stemwidth < widthdiff) |
---|
48 | /* this standard width is the best match so far for this stem */ |
---|
49 | widthdiff = blues->StemSnapV[i] - stemwidth; |
---|
50 | } |
---|
51 | --- 399,414 ---- |
---|
52 | /* ADJUST STEM WIDTHS */ |
---|
53 | /**********************/ |
---|
54 | |
---|
55 | ! /* a big value to not compete with StemSnap */ |
---|
56 | ! /* if there is no StemSnap it will be caught later */ |
---|
57 | ! widthdiff = onepixel*2; |
---|
58 | |
---|
59 | /* Find standard stem with smallest width difference from this stem */ |
---|
60 | if (stems[stemno].vertical) { /* vertical stem */ |
---|
61 | if (blues->StdVW != 0) /* there is an entry for StdVW */ |
---|
62 | widthdiff = blues->StdVW - stemwidth; |
---|
63 | for (i = 0; i < blues->numStemSnapV; ++i) { /* now look at StemSnapV */ |
---|
64 | ! if ( FABS(blues->StemSnapV[i] - stemwidth) < FABS(widthdiff) ) |
---|
65 | /* this standard width is the best match so far for this stem */ |
---|
66 | widthdiff = blues->StemSnapV[i] - stemwidth; |
---|
67 | } |
---|
68 | *************** |
---|
69 | *** 414,420 **** |
---|
70 | if (blues->StdHW != 0) /* there is an entry for StdHW */ |
---|
71 | widthdiff = blues->StdHW - stemwidth; |
---|
72 | for (i = 0; i < blues->numStemSnapH; ++i) { /* now look at StemSnapH */ |
---|
73 | ! if (blues->StemSnapH[i] - stemwidth < widthdiff) |
---|
74 | /* this standard width is the best match so far for this stem */ |
---|
75 | widthdiff = blues->StemSnapH[i] - stemwidth; |
---|
76 | } |
---|
77 | --- 416,422 ---- |
---|
78 | if (blues->StdHW != 0) /* there is an entry for StdHW */ |
---|
79 | widthdiff = blues->StdHW - stemwidth; |
---|
80 | for (i = 0; i < blues->numStemSnapH; ++i) { /* now look at StemSnapH */ |
---|
81 | ! if ( FABS(blues->StemSnapH[i] - stemwidth) < FABS(widthdiff) ) |
---|
82 | /* this standard width is the best match so far for this stem */ |
---|
83 | widthdiff = blues->StemSnapH[i] - stemwidth; |
---|
84 | } |
---|
85 | *** t1io.c 2000/01/01 00:41:44 1.1 |
---|
86 | --- t1io.c 2000/01/01 01:23:38 |
---|
87 | *************** |
---|
88 | *** 78,83 **** |
---|
89 | --- 78,86 ---- |
---|
90 | /* Our single FILE structure and buffer for this package */ |
---|
91 | STATIC F_FILE TheFile; |
---|
92 | STATIC unsigned char TheBuffer[F_BUFSIZ]; |
---|
93 | + |
---|
94 | + /* the size of the file we read */ |
---|
95 | + int T1FileSize; |
---|
96 | |
---|
97 | /* Our routines */ |
---|
98 | F_FILE *T1Open(), *T1Eexec(); |
---|
99 | *************** |
---|
100 | *** 118,123 **** |
---|
101 | --- 121,127 ---- |
---|
102 | of->flags = 0; |
---|
103 | of->error = 0; |
---|
104 | haveextrach = 0; |
---|
105 | + T1FileSize = 0; |
---|
106 | return &TheFile; |
---|
107 | } /* end Open */ |
---|
108 | |
---|
109 | *************** |
---|
110 | *** 196,202 **** |
---|
111 | --- 200,212 ---- |
---|
112 | int T1Close(f) /* Close the file */ |
---|
113 | F_FILE *f; /* Stream descriptor */ |
---|
114 | { |
---|
115 | + int rc; |
---|
116 | + |
---|
117 | if (f->b_base == NULL) return 0; /* already closed */ |
---|
118 | + |
---|
119 | + while ( (rc = read(f->fd, f->b_base, F_BUFSIZ)) >0) |
---|
120 | + T1FileSize += rc; /* count the rest of the file */ |
---|
121 | + |
---|
122 | f->b_base = NULL; /* no valid stream */ |
---|
123 | return close(f->fd); |
---|
124 | } /* end Close */ |
---|
125 | *************** |
---|
126 | *** 381,386 **** |
---|
127 | --- 391,397 ---- |
---|
128 | } |
---|
129 | } |
---|
130 | f->b_ptr = f->b_base; |
---|
131 | + T1FileSize += rc; /* remember how many bytes we have */ |
---|
132 | if (Decrypt) rc = T1Decrypt(f->b_base, rc); |
---|
133 | return rc; |
---|
134 | } /* end Fill */ |
---|
135 | *** t1stdio.h 2000/01/01 00:43:38 1.1 |
---|
136 | --- t1stdio.h 2000/01/01 01:24:19 |
---|
137 | *************** |
---|
138 | *** 73,78 **** |
---|
139 | --- 73,79 ---- |
---|
140 | |
---|
141 | extern FILE *T1Open(), *T1eexec(); |
---|
142 | extern int T1Close(), T1Ungetc(), T1Read(); |
---|
143 | + extern int T1FileSize; |
---|
144 | |
---|
145 | #undef fclose |
---|
146 | #undef fopen |
---|
147 | *** fontfcn.c 2000/01/01 00:07:54 1.1 |
---|
148 | --- fontfcn.c 2000/01/01 01:36:02 |
---|
149 | *************** |
---|
150 | *** 57,62 **** |
---|
151 | --- 57,63 ---- |
---|
152 | #endif |
---|
153 | #include "t1imager.h" |
---|
154 | #include "util.h" |
---|
155 | + #include "t1stdio.h" |
---|
156 | #ifdef BUILDCID |
---|
157 | #include "range.h" |
---|
158 | #include "fontmisc.h" |
---|
159 | *************** |
---|
160 | *** 300,333 **** |
---|
161 | resetFont(env); |
---|
162 | /* This will load the font into the FontP */ |
---|
163 | rcode = scan_font(FontP); |
---|
164 | ! if (rcode == SCAN_OUT_OF_MEMORY) { |
---|
165 | /* free the memory and start again */ |
---|
166 | #ifdef BUILDCID |
---|
167 | /* xfree(vm_base); */ |
---|
168 | #else |
---|
169 | xfree(vm_base); |
---|
170 | #endif |
---|
171 | if (!(initFont(vm_size * 2))) { |
---|
172 | /* we are really out of memory */ |
---|
173 | return(SCAN_OUT_OF_MEMORY); |
---|
174 | } |
---|
175 | resetFont(env); |
---|
176 | rcode = scan_font(FontP); |
---|
177 | - #ifdef BUILDCID |
---|
178 | - /* only double the memory twice, then report error */ |
---|
179 | - if (rcode == SCAN_OUT_OF_MEMORY) { |
---|
180 | - /* free the memory and start again */ |
---|
181 | - /* xfree(vm_base) */ |
---|
182 | - if (!(initFont(vm_size * 2))) { |
---|
183 | - /* we are really out of memory */ |
---|
184 | - return(SCAN_OUT_OF_MEMORY); |
---|
185 | - } |
---|
186 | - resetFont(env); |
---|
187 | - rcode = scan_font(FontP); |
---|
188 | - } |
---|
189 | - #else |
---|
190 | - /* only double the memory once, then report error */ |
---|
191 | - #endif |
---|
192 | } |
---|
193 | return(rcode); |
---|
194 | } |
---|
195 | --- 301,342 ---- |
---|
196 | resetFont(env); |
---|
197 | /* This will load the font into the FontP */ |
---|
198 | rcode = scan_font(FontP); |
---|
199 | ! if (rcode != SCAN_OUT_OF_MEMORY) |
---|
200 | ! return rcode; |
---|
201 | ! |
---|
202 | ! if (T1FileSize > VM_SIZE) { |
---|
203 | ! /* use the file size as estimation */ |
---|
204 | ! |
---|
205 | /* free the memory and start again */ |
---|
206 | #ifdef BUILDCID |
---|
207 | /* xfree(vm_base); */ |
---|
208 | #else |
---|
209 | xfree(vm_base); |
---|
210 | #endif |
---|
211 | + if (!(initFont(T1FileSize))) { |
---|
212 | + /* we are really out of memory */ |
---|
213 | + return(SCAN_OUT_OF_MEMORY); |
---|
214 | + } |
---|
215 | + resetFont(env); |
---|
216 | + rcode = scan_font(FontP); |
---|
217 | + if (rcode != SCAN_OUT_OF_MEMORY) |
---|
218 | + return rcode; |
---|
219 | + } |
---|
220 | + |
---|
221 | + /* if still not enough, increase up to maximum */ |
---|
222 | + while (rcode == SCAN_OUT_OF_MEMORY |
---|
223 | + && vm_size <= VM_SIZE_MAX/2 ) { |
---|
224 | + #ifdef BUILDCID |
---|
225 | + /* xfree(vm_base); */ |
---|
226 | + #else |
---|
227 | + xfree(vm_base); |
---|
228 | + #endif |
---|
229 | if (!(initFont(vm_size * 2))) { |
---|
230 | /* we are really out of memory */ |
---|
231 | return(SCAN_OUT_OF_MEMORY); |
---|
232 | } |
---|
233 | resetFont(env); |
---|
234 | rcode = scan_font(FontP); |
---|
235 | } |
---|
236 | return(rcode); |
---|
237 | } |
---|
238 | *** util.h 2000/01/01 00:40:11 1.1 |
---|
239 | --- util.h 2000/01/01 01:29:18 |
---|
240 | *************** |
---|
241 | *** 83,88 **** |
---|
242 | --- 83,92 ---- |
---|
243 | #else |
---|
244 | #define VM_SIZE (50*1024) |
---|
245 | #endif |
---|
246 | + |
---|
247 | + /* this is the maximal permitted memory size */ |
---|
248 | + #define VM_SIZE_MAX (1024*1024) |
---|
249 | + |
---|
250 | /***================================================================***/ |
---|
251 | |
---|
252 | #ifndef MIN |
---|