1 | /***************************************************************************/ |
---|
2 | /* */ |
---|
3 | /* t1load.c */ |
---|
4 | /* */ |
---|
5 | /* Type 1 font loader (body). */ |
---|
6 | /* */ |
---|
7 | /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 by */ |
---|
8 | /* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
---|
9 | /* */ |
---|
10 | /* This file is part of the FreeType project, and may only be used, */ |
---|
11 | /* modified, and distributed under the terms of the FreeType project */ |
---|
12 | /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
---|
13 | /* this file you indicate that you have read the license and */ |
---|
14 | /* understand and accept it fully. */ |
---|
15 | /* */ |
---|
16 | /***************************************************************************/ |
---|
17 | |
---|
18 | |
---|
19 | /*************************************************************************/ |
---|
20 | /* */ |
---|
21 | /* This is the new and improved Type 1 data loader for FreeType 2. The */ |
---|
22 | /* old loader has several problems: it is slow, complex, difficult to */ |
---|
23 | /* maintain, and contains incredible hacks to make it accept some */ |
---|
24 | /* ill-formed Type 1 fonts without hiccup-ing. Moreover, about 5% of */ |
---|
25 | /* the Type 1 fonts on my machine still aren't loaded correctly by it. */ |
---|
26 | /* */ |
---|
27 | /* This version is much simpler, much faster and also easier to read and */ |
---|
28 | /* maintain by a great order of magnitude. The idea behind it is to */ |
---|
29 | /* _not_ try to read the Type 1 token stream with a state machine (i.e. */ |
---|
30 | /* a Postscript-like interpreter) but rather to perform simple pattern */ |
---|
31 | /* matching. */ |
---|
32 | /* */ |
---|
33 | /* Indeed, nearly all data definitions follow a simple pattern like */ |
---|
34 | /* */ |
---|
35 | /* ... /Field <data> ... */ |
---|
36 | /* */ |
---|
37 | /* where <data> can be a number, a boolean, a string, or an array of */ |
---|
38 | /* numbers. There are a few exceptions, namely the encoding, font name, */ |
---|
39 | /* charstrings, and subrs; they are handled with a special pattern */ |
---|
40 | /* matching routine. */ |
---|
41 | /* */ |
---|
42 | /* All other common cases are handled very simply. The matching rules */ |
---|
43 | /* are defined in the file `t1tokens.h' through the use of several */ |
---|
44 | /* macros calls PARSE_XXX. This file is included twice here; the first */ |
---|
45 | /* time to generate parsing callback functions, the second time to */ |
---|
46 | /* generate a table of keywords (with pointers to the associated */ |
---|
47 | /* callback functions). */ |
---|
48 | /* */ |
---|
49 | /* The function `parse_dict' simply scans *linearly* a given dictionary */ |
---|
50 | /* (either the top-level or private one) and calls the appropriate */ |
---|
51 | /* callback when it encounters an immediate keyword. */ |
---|
52 | /* */ |
---|
53 | /* This is by far the fastest way one can find to parse and read all */ |
---|
54 | /* data. */ |
---|
55 | /* */ |
---|
56 | /* This led to tremendous code size reduction. Note that later, the */ |
---|
57 | /* glyph loader will also be _greatly_ simplified, and the automatic */ |
---|
58 | /* hinter will replace the clumsy `t1hinter'. */ |
---|
59 | /* */ |
---|
60 | /*************************************************************************/ |
---|
61 | |
---|
62 | |
---|
63 | #include <ft2build.h> |
---|
64 | #include FT_INTERNAL_DEBUG_H |
---|
65 | #include FT_CONFIG_CONFIG_H |
---|
66 | #include FT_MULTIPLE_MASTERS_H |
---|
67 | #include FT_INTERNAL_TYPE1_TYPES_H |
---|
68 | |
---|
69 | #include "t1load.h" |
---|
70 | #include "t1errors.h" |
---|
71 | |
---|
72 | |
---|
73 | /*************************************************************************/ |
---|
74 | /* */ |
---|
75 | /* The macro FT_COMPONENT is used in trace mode. It is an implicit */ |
---|
76 | /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ |
---|
77 | /* messages during execution. */ |
---|
78 | /* */ |
---|
79 | #undef FT_COMPONENT |
---|
80 | #define FT_COMPONENT trace_t1load |
---|
81 | |
---|
82 | |
---|
83 | #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT |
---|
84 | |
---|
85 | |
---|
86 | /*************************************************************************/ |
---|
87 | /*************************************************************************/ |
---|
88 | /***** *****/ |
---|
89 | /***** MULTIPLE MASTERS SUPPORT *****/ |
---|
90 | /***** *****/ |
---|
91 | /*************************************************************************/ |
---|
92 | /*************************************************************************/ |
---|
93 | |
---|
94 | static FT_Error |
---|
95 | t1_allocate_blend( T1_Face face, |
---|
96 | FT_UInt num_designs, |
---|
97 | FT_UInt num_axis ) |
---|
98 | { |
---|
99 | PS_Blend blend; |
---|
100 | FT_Memory memory = face->root.memory; |
---|
101 | FT_Error error = T1_Err_Ok; |
---|
102 | |
---|
103 | |
---|
104 | blend = face->blend; |
---|
105 | if ( !blend ) |
---|
106 | { |
---|
107 | if ( FT_NEW( blend ) ) |
---|
108 | goto Exit; |
---|
109 | |
---|
110 | blend->num_default_design_vector = 0; |
---|
111 | |
---|
112 | face->blend = blend; |
---|
113 | } |
---|
114 | |
---|
115 | /* allocate design data if needed */ |
---|
116 | if ( num_designs > 0 ) |
---|
117 | { |
---|
118 | if ( blend->num_designs == 0 ) |
---|
119 | { |
---|
120 | FT_UInt nn; |
---|
121 | |
---|
122 | |
---|
123 | /* allocate the blend `private' and `font_info' dictionaries */ |
---|
124 | if ( FT_NEW_ARRAY( blend->font_infos[1], num_designs ) || |
---|
125 | FT_NEW_ARRAY( blend->privates[1], num_designs ) || |
---|
126 | FT_NEW_ARRAY( blend->bboxes[1], num_designs ) || |
---|
127 | FT_NEW_ARRAY( blend->weight_vector, num_designs * 2 ) ) |
---|
128 | goto Exit; |
---|
129 | |
---|
130 | blend->default_weight_vector = blend->weight_vector + num_designs; |
---|
131 | |
---|
132 | blend->font_infos[0] = &face->type1.font_info; |
---|
133 | blend->privates [0] = &face->type1.private_dict; |
---|
134 | blend->bboxes [0] = &face->type1.font_bbox; |
---|
135 | |
---|
136 | for ( nn = 2; nn <= num_designs; nn++ ) |
---|
137 | { |
---|
138 | blend->privates[nn] = blend->privates [nn - 1] + 1; |
---|
139 | blend->font_infos[nn] = blend->font_infos[nn - 1] + 1; |
---|
140 | blend->bboxes[nn] = blend->bboxes [nn - 1] + 1; |
---|
141 | } |
---|
142 | |
---|
143 | blend->num_designs = num_designs; |
---|
144 | } |
---|
145 | else if ( blend->num_designs != num_designs ) |
---|
146 | goto Fail; |
---|
147 | } |
---|
148 | |
---|
149 | /* allocate axis data if needed */ |
---|
150 | if ( num_axis > 0 ) |
---|
151 | { |
---|
152 | if ( blend->num_axis != 0 && blend->num_axis != num_axis ) |
---|
153 | goto Fail; |
---|
154 | |
---|
155 | blend->num_axis = num_axis; |
---|
156 | } |
---|
157 | |
---|
158 | /* allocate the blend design pos table if needed */ |
---|
159 | num_designs = blend->num_designs; |
---|
160 | num_axis = blend->num_axis; |
---|
161 | if ( num_designs && num_axis && blend->design_pos[0] == 0 ) |
---|
162 | { |
---|
163 | FT_UInt n; |
---|
164 | |
---|
165 | |
---|
166 | if ( FT_NEW_ARRAY( blend->design_pos[0], num_designs * num_axis ) ) |
---|
167 | goto Exit; |
---|
168 | |
---|
169 | for ( n = 1; n < num_designs; n++ ) |
---|
170 | blend->design_pos[n] = blend->design_pos[0] + num_axis * n; |
---|
171 | } |
---|
172 | |
---|
173 | Exit: |
---|
174 | return error; |
---|
175 | |
---|
176 | Fail: |
---|
177 | error = T1_Err_Invalid_File_Format; |
---|
178 | goto Exit; |
---|
179 | } |
---|
180 | |
---|
181 | |
---|
182 | FT_LOCAL_DEF( FT_Error ) |
---|
183 | T1_Get_Multi_Master( T1_Face face, |
---|
184 | FT_Multi_Master* master ) |
---|
185 | { |
---|
186 | PS_Blend blend = face->blend; |
---|
187 | FT_UInt n; |
---|
188 | FT_Error error; |
---|
189 | |
---|
190 | |
---|
191 | error = T1_Err_Invalid_Argument; |
---|
192 | |
---|
193 | if ( blend ) |
---|
194 | { |
---|
195 | master->num_axis = blend->num_axis; |
---|
196 | master->num_designs = blend->num_designs; |
---|
197 | |
---|
198 | for ( n = 0; n < blend->num_axis; n++ ) |
---|
199 | { |
---|
200 | FT_MM_Axis* axis = master->axis + n; |
---|
201 | PS_DesignMap map = blend->design_map + n; |
---|
202 | |
---|
203 | |
---|
204 | axis->name = blend->axis_names[n]; |
---|
205 | axis->minimum = map->design_points[0]; |
---|
206 | axis->maximum = map->design_points[map->num_points - 1]; |
---|
207 | } |
---|
208 | |
---|
209 | error = T1_Err_Ok; |
---|
210 | } |
---|
211 | |
---|
212 | return error; |
---|
213 | } |
---|
214 | |
---|
215 | |
---|
216 | #define FT_INT_TO_FIXED( a ) ( (a) << 16 ) |
---|
217 | #define FT_FIXED_TO_INT( a ) ( FT_RoundFix( a ) >> 16 ) |
---|
218 | |
---|
219 | |
---|
220 | /*************************************************************************/ |
---|
221 | /* */ |
---|
222 | /* Given a normalized (blend) coordinate, figure out the design */ |
---|
223 | /* coordinate appropriate for that value. */ |
---|
224 | /* */ |
---|
225 | FT_LOCAL_DEF( FT_Fixed ) |
---|
226 | mm_axis_unmap( PS_DesignMap axismap, |
---|
227 | FT_Fixed ncv ) |
---|
228 | { |
---|
229 | int j; |
---|
230 | |
---|
231 | |
---|
232 | if ( ncv <= axismap->blend_points[0] ) |
---|
233 | return FT_INT_TO_FIXED( axismap->design_points[0] ); |
---|
234 | |
---|
235 | for ( j = 1; j < axismap->num_points; ++j ) |
---|
236 | { |
---|
237 | if ( ncv <= axismap->blend_points[j] ) |
---|
238 | { |
---|
239 | FT_Fixed t = FT_MulDiv( ncv - axismap->blend_points[j - 1], |
---|
240 | 0x10000L, |
---|
241 | axismap->blend_points[j] - |
---|
242 | axismap->blend_points[j - 1] ); |
---|
243 | |
---|
244 | return FT_INT_TO_FIXED( axismap->design_points[j - 1] ) + |
---|
245 | FT_MulDiv( t, |
---|
246 | axismap->design_points[j] - |
---|
247 | axismap->design_points[j - 1], |
---|
248 | 1L ); |
---|
249 | } |
---|
250 | } |
---|
251 | |
---|
252 | return FT_INT_TO_FIXED( axismap->design_points[axismap->num_points - 1] ); |
---|
253 | } |
---|
254 | |
---|
255 | |
---|
256 | /*************************************************************************/ |
---|
257 | /* */ |
---|
258 | /* Given a vector of weights, one for each design, figure out the */ |
---|
259 | /* normalized axis coordinates which gave rise to those weights. */ |
---|
260 | /* */ |
---|
261 | FT_LOCAL_DEF( void ) |
---|
262 | mm_weights_unmap( FT_Fixed* weights, |
---|
263 | FT_Fixed* axiscoords, |
---|
264 | FT_UInt axis_count ) |
---|
265 | { |
---|
266 | FT_ASSERT( axis_count <= T1_MAX_MM_AXIS ); |
---|
267 | |
---|
268 | if ( axis_count == 1 ) |
---|
269 | axiscoords[0] = weights[1]; |
---|
270 | |
---|
271 | else if ( axis_count == 2 ) |
---|
272 | { |
---|
273 | axiscoords[0] = weights[3] + weights[1]; |
---|
274 | axiscoords[1] = weights[3] + weights[2]; |
---|
275 | } |
---|
276 | |
---|
277 | else if ( axis_count == 3 ) |
---|
278 | { |
---|
279 | axiscoords[0] = weights[7] + weights[5] + weights[3] + weights[1]; |
---|
280 | axiscoords[1] = weights[7] + weights[6] + weights[3] + weights[2]; |
---|
281 | axiscoords[2] = weights[7] + weights[6] + weights[5] + weights[4]; |
---|
282 | } |
---|
283 | |
---|
284 | else |
---|
285 | { |
---|
286 | axiscoords[0] = weights[15] + weights[13] + weights[11] + weights[9] + |
---|
287 | weights[7] + weights[5] + weights[3] + weights[1]; |
---|
288 | axiscoords[1] = weights[15] + weights[14] + weights[11] + weights[10] + |
---|
289 | weights[7] + weights[6] + weights[3] + weights[2]; |
---|
290 | axiscoords[2] = weights[15] + weights[14] + weights[13] + weights[12] + |
---|
291 | weights[7] + weights[6] + weights[5] + weights[4]; |
---|
292 | axiscoords[3] = weights[15] + weights[14] + weights[13] + weights[12] + |
---|
293 | weights[11] + weights[10] + weights[9] + weights[8]; |
---|
294 | } |
---|
295 | } |
---|
296 | |
---|
297 | |
---|
298 | /*************************************************************************/ |
---|
299 | /* */ |
---|
300 | /* Just a wrapper around T1_Get_Multi_Master to support the different */ |
---|
301 | /* arguments needed by the GX var distortable fonts. */ |
---|
302 | /* */ |
---|
303 | FT_LOCAL_DEF( FT_Error ) |
---|
304 | T1_Get_MM_Var( T1_Face face, |
---|
305 | FT_MM_Var* *master ) |
---|
306 | { |
---|
307 | FT_Memory memory = face->root.memory; |
---|
308 | FT_MM_Var *mmvar; |
---|
309 | FT_Multi_Master mmaster; |
---|
310 | FT_Error error; |
---|
311 | FT_UInt i; |
---|
312 | FT_Fixed axiscoords[T1_MAX_MM_AXIS]; |
---|
313 | PS_Blend blend = face->blend; |
---|
314 | |
---|
315 | |
---|
316 | error = T1_Get_Multi_Master( face, &mmaster ); |
---|
317 | if ( error ) |
---|
318 | goto Exit; |
---|
319 | if ( FT_ALLOC( mmvar, |
---|
320 | sizeof ( FT_MM_Var ) + |
---|
321 | mmaster.num_axis * sizeof ( FT_Var_Axis ) ) ) |
---|
322 | goto Exit; |
---|
323 | |
---|
324 | mmvar->num_axis = mmaster.num_axis; |
---|
325 | mmvar->num_designs = mmaster.num_designs; |
---|
326 | mmvar->num_namedstyles = (FT_UInt)-1; /* Does not apply */ |
---|
327 | mmvar->axis = (FT_Var_Axis*)&mmvar[1]; |
---|
328 | /* Point to axes after MM_Var struct */ |
---|
329 | mmvar->namedstyle = NULL; |
---|
330 | |
---|
331 | for ( i = 0 ; i < mmaster.num_axis; ++i ) |
---|
332 | { |
---|
333 | mmvar->axis[i].name = mmaster.axis[i].name; |
---|
334 | mmvar->axis[i].minimum = FT_INT_TO_FIXED( mmaster.axis[i].minimum); |
---|
335 | mmvar->axis[i].maximum = FT_INT_TO_FIXED( mmaster.axis[i].maximum); |
---|
336 | mmvar->axis[i].def = ( mmvar->axis[i].minimum + |
---|
337 | mmvar->axis[i].maximum ) / 2; |
---|
338 | /* Does not apply. But this value is in range */ |
---|
339 | mmvar->axis[i].strid = (FT_UInt)-1; /* Does not apply */ |
---|
340 | mmvar->axis[i].tag = (FT_ULong)-1; /* Does not apply */ |
---|
341 | |
---|
342 | if ( ft_strcmp( mmvar->axis[i].name, "Weight" ) == 0 ) |
---|
343 | mmvar->axis[i].tag = FT_MAKE_TAG( 'w', 'g', 'h', 't' ); |
---|
344 | else if ( ft_strcmp( mmvar->axis[i].name, "Width" ) == 0 ) |
---|
345 | mmvar->axis[i].tag = FT_MAKE_TAG( 'w', 'd', 't', 'h' ); |
---|
346 | else if ( ft_strcmp( mmvar->axis[i].name, "OpticalSize" ) == 0 ) |
---|
347 | mmvar->axis[i].tag = FT_MAKE_TAG( 'o', 'p', 's', 'z' ); |
---|
348 | } |
---|
349 | |
---|
350 | if ( blend->num_designs == ( 1U << blend->num_axis ) ) |
---|
351 | { |
---|
352 | mm_weights_unmap( blend->default_weight_vector, |
---|
353 | axiscoords, |
---|
354 | blend->num_axis ); |
---|
355 | |
---|
356 | for ( i = 0; i < mmaster.num_axis; ++i ) |
---|
357 | mmvar->axis[i].def = mm_axis_unmap( &blend->design_map[i], |
---|
358 | axiscoords[i] ); |
---|
359 | } |
---|
360 | |
---|
361 | *master = mmvar; |
---|
362 | |
---|
363 | Exit: |
---|
364 | return error; |
---|
365 | } |
---|
366 | |
---|
367 | |
---|
368 | FT_LOCAL_DEF( FT_Error ) |
---|
369 | T1_Set_MM_Blend( T1_Face face, |
---|
370 | FT_UInt num_coords, |
---|
371 | FT_Fixed* coords ) |
---|
372 | { |
---|
373 | PS_Blend blend = face->blend; |
---|
374 | FT_Error error; |
---|
375 | FT_UInt n, m; |
---|
376 | |
---|
377 | |
---|
378 | error = T1_Err_Invalid_Argument; |
---|
379 | |
---|
380 | if ( blend && blend->num_axis == num_coords ) |
---|
381 | { |
---|
382 | /* recompute the weight vector from the blend coordinates */ |
---|
383 | error = T1_Err_Ok; |
---|
384 | |
---|
385 | for ( n = 0; n < blend->num_designs; n++ ) |
---|
386 | { |
---|
387 | FT_Fixed result = 0x10000L; /* 1.0 fixed */ |
---|
388 | |
---|
389 | |
---|
390 | for ( m = 0; m < blend->num_axis; m++ ) |
---|
391 | { |
---|
392 | FT_Fixed factor; |
---|
393 | |
---|
394 | |
---|
395 | /* get current blend axis position */ |
---|
396 | factor = coords[m]; |
---|
397 | if ( factor < 0 ) factor = 0; |
---|
398 | if ( factor > 0x10000L ) factor = 0x10000L; |
---|
399 | |
---|
400 | if ( ( n & ( 1 << m ) ) == 0 ) |
---|
401 | factor = 0x10000L - factor; |
---|
402 | |
---|
403 | result = FT_MulFix( result, factor ); |
---|
404 | } |
---|
405 | blend->weight_vector[n] = result; |
---|
406 | } |
---|
407 | |
---|
408 | error = T1_Err_Ok; |
---|
409 | } |
---|
410 | |
---|
411 | return error; |
---|
412 | } |
---|
413 | |
---|
414 | |
---|
415 | FT_LOCAL_DEF( FT_Error ) |
---|
416 | T1_Set_MM_Design( T1_Face face, |
---|
417 | FT_UInt num_coords, |
---|
418 | FT_Long* coords ) |
---|
419 | { |
---|
420 | PS_Blend blend = face->blend; |
---|
421 | FT_Error error; |
---|
422 | FT_UInt n, p; |
---|
423 | |
---|
424 | |
---|
425 | error = T1_Err_Invalid_Argument; |
---|
426 | if ( blend && blend->num_axis == num_coords ) |
---|
427 | { |
---|
428 | /* compute the blend coordinates through the blend design map */ |
---|
429 | FT_Fixed final_blends[T1_MAX_MM_DESIGNS]; |
---|
430 | |
---|
431 | |
---|
432 | for ( n = 0; n < blend->num_axis; n++ ) |
---|
433 | { |
---|
434 | FT_Long design = coords[n]; |
---|
435 | FT_Fixed the_blend; |
---|
436 | PS_DesignMap map = blend->design_map + n; |
---|
437 | FT_Long* designs = map->design_points; |
---|
438 | FT_Fixed* blends = map->blend_points; |
---|
439 | FT_Int before = -1, after = -1; |
---|
440 | |
---|
441 | |
---|
442 | for ( p = 0; p < (FT_UInt)map->num_points; p++ ) |
---|
443 | { |
---|
444 | FT_Long p_design = designs[p]; |
---|
445 | |
---|
446 | |
---|
447 | /* exact match? */ |
---|
448 | if ( design == p_design ) |
---|
449 | { |
---|
450 | the_blend = blends[p]; |
---|
451 | goto Found; |
---|
452 | } |
---|
453 | |
---|
454 | if ( design < p_design ) |
---|
455 | { |
---|
456 | after = p; |
---|
457 | break; |
---|
458 | } |
---|
459 | |
---|
460 | before = p; |
---|
461 | } |
---|
462 | |
---|
463 | /* now interpolate if necessary */ |
---|
464 | if ( before < 0 ) |
---|
465 | the_blend = blends[0]; |
---|
466 | |
---|
467 | else if ( after < 0 ) |
---|
468 | the_blend = blends[map->num_points - 1]; |
---|
469 | |
---|
470 | else |
---|
471 | the_blend = FT_MulDiv( design - designs[before], |
---|
472 | blends [after] - blends [before], |
---|
473 | designs[after] - designs[before] ); |
---|
474 | |
---|
475 | Found: |
---|
476 | final_blends[n] = the_blend; |
---|
477 | } |
---|
478 | |
---|
479 | error = T1_Set_MM_Blend( face, num_coords, final_blends ); |
---|
480 | } |
---|
481 | |
---|
482 | return error; |
---|
483 | } |
---|
484 | |
---|
485 | |
---|
486 | /*************************************************************************/ |
---|
487 | /* */ |
---|
488 | /* Just a wrapper around T1_Set_MM_Design to support the different */ |
---|
489 | /* arguments needed by the GX var distortable fonts. */ |
---|
490 | /* */ |
---|
491 | FT_LOCAL_DEF( FT_Error ) |
---|
492 | T1_Set_Var_Design( T1_Face face, |
---|
493 | FT_UInt num_coords, |
---|
494 | FT_Fixed* coords ) |
---|
495 | { |
---|
496 | FT_Long lcoords[4]; /* maximum axis count is 4 */ |
---|
497 | FT_UInt i; |
---|
498 | FT_Error error; |
---|
499 | |
---|
500 | |
---|
501 | error = T1_Err_Invalid_Argument; |
---|
502 | if ( num_coords <= 4 && num_coords > 0 ) |
---|
503 | { |
---|
504 | for ( i = 0; i < num_coords; ++i ) |
---|
505 | lcoords[i] = FT_FIXED_TO_INT( coords[i] ); |
---|
506 | error = T1_Set_MM_Design( face, num_coords, lcoords ); |
---|
507 | } |
---|
508 | |
---|
509 | return error; |
---|
510 | } |
---|
511 | |
---|
512 | |
---|
513 | FT_LOCAL_DEF( void ) |
---|
514 | T1_Done_Blend( T1_Face face ) |
---|
515 | { |
---|
516 | FT_Memory memory = face->root.memory; |
---|
517 | PS_Blend blend = face->blend; |
---|
518 | |
---|
519 | |
---|
520 | if ( blend ) |
---|
521 | { |
---|
522 | FT_UInt num_designs = blend->num_designs; |
---|
523 | FT_UInt num_axis = blend->num_axis; |
---|
524 | FT_UInt n; |
---|
525 | |
---|
526 | |
---|
527 | /* release design pos table */ |
---|
528 | FT_FREE( blend->design_pos[0] ); |
---|
529 | for ( n = 1; n < num_designs; n++ ) |
---|
530 | blend->design_pos[n] = 0; |
---|
531 | |
---|
532 | /* release blend `private' and `font info' dictionaries */ |
---|
533 | FT_FREE( blend->privates[1] ); |
---|
534 | FT_FREE( blend->font_infos[1] ); |
---|
535 | FT_FREE( blend->bboxes[1] ); |
---|
536 | |
---|
537 | for ( n = 0; n < num_designs; n++ ) |
---|
538 | { |
---|
539 | blend->privates [n] = 0; |
---|
540 | blend->font_infos[n] = 0; |
---|
541 | blend->bboxes [n] = 0; |
---|
542 | } |
---|
543 | |
---|
544 | /* release weight vectors */ |
---|
545 | FT_FREE( blend->weight_vector ); |
---|
546 | blend->default_weight_vector = 0; |
---|
547 | |
---|
548 | /* release axis names */ |
---|
549 | for ( n = 0; n < num_axis; n++ ) |
---|
550 | FT_FREE( blend->axis_names[n] ); |
---|
551 | |
---|
552 | /* release design map */ |
---|
553 | for ( n = 0; n < num_axis; n++ ) |
---|
554 | { |
---|
555 | PS_DesignMap dmap = blend->design_map + n; |
---|
556 | |
---|
557 | |
---|
558 | FT_FREE( dmap->design_points ); |
---|
559 | dmap->num_points = 0; |
---|
560 | } |
---|
561 | |
---|
562 | FT_FREE( face->blend ); |
---|
563 | } |
---|
564 | } |
---|
565 | |
---|
566 | |
---|
567 | static void |
---|
568 | parse_blend_axis_types( T1_Face face, |
---|
569 | T1_Loader loader ) |
---|
570 | { |
---|
571 | T1_TokenRec axis_tokens[T1_MAX_MM_AXIS]; |
---|
572 | FT_Int n, num_axis; |
---|
573 | FT_Error error = T1_Err_Ok; |
---|
574 | PS_Blend blend; |
---|
575 | FT_Memory memory; |
---|
576 | |
---|
577 | |
---|
578 | /* take an array of objects */ |
---|
579 | T1_ToTokenArray( &loader->parser, axis_tokens, |
---|
580 | T1_MAX_MM_AXIS, &num_axis ); |
---|
581 | if ( num_axis < 0 ) |
---|
582 | { |
---|
583 | error = T1_Err_Ignore; |
---|
584 | goto Exit; |
---|
585 | } |
---|
586 | if ( num_axis == 0 || num_axis > T1_MAX_MM_AXIS ) |
---|
587 | { |
---|
588 | FT_ERROR(( "parse_blend_axis_types: incorrect number of axes: %d\n", |
---|
589 | num_axis )); |
---|
590 | error = T1_Err_Invalid_File_Format; |
---|
591 | goto Exit; |
---|
592 | } |
---|
593 | |
---|
594 | /* allocate blend if necessary */ |
---|
595 | error = t1_allocate_blend( face, 0, (FT_UInt)num_axis ); |
---|
596 | if ( error ) |
---|
597 | goto Exit; |
---|
598 | |
---|
599 | blend = face->blend; |
---|
600 | memory = face->root.memory; |
---|
601 | |
---|
602 | /* each token is an immediate containing the name of the axis */ |
---|
603 | for ( n = 0; n < num_axis; n++ ) |
---|
604 | { |
---|
605 | T1_Token token = axis_tokens + n; |
---|
606 | FT_Byte* name; |
---|
607 | FT_PtrDist len; |
---|
608 | |
---|
609 | |
---|
610 | /* skip first slash, if any */ |
---|
611 | if ( token->start[0] == '/' ) |
---|
612 | token->start++; |
---|
613 | |
---|
614 | len = token->limit - token->start; |
---|
615 | if ( len == 0 ) |
---|
616 | { |
---|
617 | error = T1_Err_Invalid_File_Format; |
---|
618 | goto Exit; |
---|
619 | } |
---|
620 | |
---|
621 | if ( FT_ALLOC( blend->axis_names[n], len + 1 ) ) |
---|
622 | goto Exit; |
---|
623 | |
---|
624 | name = (FT_Byte*)blend->axis_names[n]; |
---|
625 | FT_MEM_COPY( name, token->start, len ); |
---|
626 | name[len] = 0; |
---|
627 | } |
---|
628 | |
---|
629 | Exit: |
---|
630 | loader->parser.root.error = error; |
---|
631 | } |
---|
632 | |
---|
633 | |
---|
634 | static void |
---|
635 | parse_blend_design_positions( T1_Face face, |
---|
636 | T1_Loader loader ) |
---|
637 | { |
---|
638 | T1_TokenRec design_tokens[T1_MAX_MM_DESIGNS]; |
---|
639 | FT_Int num_designs; |
---|
640 | FT_Int num_axis; |
---|
641 | T1_Parser parser = &loader->parser; |
---|
642 | |
---|
643 | FT_Error error = T1_Err_Ok; |
---|
644 | PS_Blend blend; |
---|
645 | |
---|
646 | |
---|
647 | /* get the array of design tokens -- compute number of designs */ |
---|
648 | T1_ToTokenArray( parser, design_tokens, |
---|
649 | T1_MAX_MM_DESIGNS, &num_designs ); |
---|
650 | if ( num_designs < 0 ) |
---|
651 | { |
---|
652 | error = T1_Err_Ignore; |
---|
653 | goto Exit; |
---|
654 | } |
---|
655 | if ( num_designs == 0 || num_designs > T1_MAX_MM_DESIGNS ) |
---|
656 | { |
---|
657 | FT_ERROR(( "parse_blend_design_positions:" )); |
---|
658 | FT_ERROR(( " incorrect number of designs: %d\n", |
---|
659 | num_designs )); |
---|
660 | error = T1_Err_Invalid_File_Format; |
---|
661 | goto Exit; |
---|
662 | } |
---|
663 | |
---|
664 | { |
---|
665 | FT_Byte* old_cursor = parser->root.cursor; |
---|
666 | FT_Byte* old_limit = parser->root.limit; |
---|
667 | FT_Int n; |
---|
668 | |
---|
669 | |
---|
670 | blend = face->blend; |
---|
671 | num_axis = 0; /* make compiler happy */ |
---|
672 | |
---|
673 | for ( n = 0; n < num_designs; n++ ) |
---|
674 | { |
---|
675 | T1_TokenRec axis_tokens[T1_MAX_MM_AXIS]; |
---|
676 | T1_Token token; |
---|
677 | FT_Int axis, n_axis; |
---|
678 | |
---|
679 | |
---|
680 | /* read axis/coordinates tokens */ |
---|
681 | token = design_tokens + n; |
---|
682 | parser->root.cursor = token->start; |
---|
683 | parser->root.limit = token->limit; |
---|
684 | T1_ToTokenArray( parser, axis_tokens, T1_MAX_MM_AXIS, &n_axis ); |
---|
685 | |
---|
686 | if ( n == 0 ) |
---|
687 | { |
---|
688 | if ( n_axis <= 0 || n_axis > T1_MAX_MM_AXIS ) |
---|
689 | { |
---|
690 | FT_ERROR(( "parse_blend_design_positions:" )); |
---|
691 | FT_ERROR(( " invalid number of axes: %d\n", |
---|
692 | n_axis )); |
---|
693 | error = T1_Err_Invalid_File_Format; |
---|
694 | goto Exit; |
---|
695 | } |
---|
696 | |
---|
697 | num_axis = n_axis; |
---|
698 | error = t1_allocate_blend( face, num_designs, num_axis ); |
---|
699 | if ( error ) |
---|
700 | goto Exit; |
---|
701 | blend = face->blend; |
---|
702 | } |
---|
703 | else if ( n_axis != num_axis ) |
---|
704 | { |
---|
705 | FT_ERROR(( "parse_blend_design_positions: incorrect table\n" )); |
---|
706 | error = T1_Err_Invalid_File_Format; |
---|
707 | goto Exit; |
---|
708 | } |
---|
709 | |
---|
710 | /* now read each axis token into the design position */ |
---|
711 | for ( axis = 0; axis < n_axis; axis++ ) |
---|
712 | { |
---|
713 | T1_Token token2 = axis_tokens + axis; |
---|
714 | |
---|
715 | |
---|
716 | parser->root.cursor = token2->start; |
---|
717 | parser->root.limit = token2->limit; |
---|
718 | blend->design_pos[n][axis] = T1_ToFixed( parser, 0 ); |
---|
719 | } |
---|
720 | } |
---|
721 | |
---|
722 | loader->parser.root.cursor = old_cursor; |
---|
723 | loader->parser.root.limit = old_limit; |
---|
724 | } |
---|
725 | |
---|
726 | Exit: |
---|
727 | loader->parser.root.error = error; |
---|
728 | } |
---|
729 | |
---|
730 | |
---|
731 | static void |
---|
732 | parse_blend_design_map( T1_Face face, |
---|
733 | T1_Loader loader ) |
---|
734 | { |
---|
735 | FT_Error error = T1_Err_Ok; |
---|
736 | T1_Parser parser = &loader->parser; |
---|
737 | PS_Blend blend; |
---|
738 | T1_TokenRec axis_tokens[T1_MAX_MM_AXIS]; |
---|
739 | FT_Int n, num_axis; |
---|
740 | FT_Byte* old_cursor; |
---|
741 | FT_Byte* old_limit; |
---|
742 | FT_Memory memory = face->root.memory; |
---|
743 | |
---|
744 | |
---|
745 | T1_ToTokenArray( parser, axis_tokens, |
---|
746 | T1_MAX_MM_AXIS, &num_axis ); |
---|
747 | if ( num_axis < 0 ) |
---|
748 | { |
---|
749 | error = T1_Err_Ignore; |
---|
750 | goto Exit; |
---|
751 | } |
---|
752 | if ( num_axis == 0 || num_axis > T1_MAX_MM_AXIS ) |
---|
753 | { |
---|
754 | FT_ERROR(( "parse_blend_design_map: incorrect number of axes: %d\n", |
---|
755 | num_axis )); |
---|
756 | error = T1_Err_Invalid_File_Format; |
---|
757 | goto Exit; |
---|
758 | } |
---|
759 | |
---|
760 | old_cursor = parser->root.cursor; |
---|
761 | old_limit = parser->root.limit; |
---|
762 | |
---|
763 | error = t1_allocate_blend( face, 0, num_axis ); |
---|
764 | if ( error ) |
---|
765 | goto Exit; |
---|
766 | blend = face->blend; |
---|
767 | |
---|
768 | /* now read each axis design map */ |
---|
769 | for ( n = 0; n < num_axis; n++ ) |
---|
770 | { |
---|
771 | PS_DesignMap map = blend->design_map + n; |
---|
772 | T1_Token axis_token; |
---|
773 | T1_TokenRec point_tokens[T1_MAX_MM_MAP_POINTS]; |
---|
774 | FT_Int p, num_points; |
---|
775 | |
---|
776 | |
---|
777 | axis_token = axis_tokens + n; |
---|
778 | |
---|
779 | parser->root.cursor = axis_token->start; |
---|
780 | parser->root.limit = axis_token->limit; |
---|
781 | T1_ToTokenArray( parser, point_tokens, |
---|
782 | T1_MAX_MM_MAP_POINTS, &num_points ); |
---|
783 | |
---|
784 | if ( num_points <= 0 || num_points > T1_MAX_MM_MAP_POINTS ) |
---|
785 | { |
---|
786 | FT_ERROR(( "parse_blend_design_map: incorrect table\n" )); |
---|
787 | error = T1_Err_Invalid_File_Format; |
---|
788 | goto Exit; |
---|
789 | } |
---|
790 | |
---|
791 | /* allocate design map data */ |
---|
792 | if ( FT_NEW_ARRAY( map->design_points, num_points * 2 ) ) |
---|
793 | goto Exit; |
---|
794 | map->blend_points = map->design_points + num_points; |
---|
795 | map->num_points = (FT_Byte)num_points; |
---|
796 | |
---|
797 | for ( p = 0; p < num_points; p++ ) |
---|
798 | { |
---|
799 | T1_Token point_token; |
---|
800 | |
---|
801 | |
---|
802 | point_token = point_tokens + p; |
---|
803 | |
---|
804 | /* don't include delimiting brackets */ |
---|
805 | parser->root.cursor = point_token->start + 1; |
---|
806 | parser->root.limit = point_token->limit - 1; |
---|
807 | |
---|
808 | map->design_points[p] = T1_ToInt( parser ); |
---|
809 | map->blend_points [p] = T1_ToFixed( parser, 0 ); |
---|
810 | } |
---|
811 | } |
---|
812 | |
---|
813 | parser->root.cursor = old_cursor; |
---|
814 | parser->root.limit = old_limit; |
---|
815 | |
---|
816 | Exit: |
---|
817 | parser->root.error = error; |
---|
818 | } |
---|
819 | |
---|
820 | |
---|
821 | static void |
---|
822 | parse_weight_vector( T1_Face face, |
---|
823 | T1_Loader loader ) |
---|
824 | { |
---|
825 | T1_TokenRec design_tokens[T1_MAX_MM_DESIGNS]; |
---|
826 | FT_Int num_designs; |
---|
827 | FT_Error error = T1_Err_Ok; |
---|
828 | T1_Parser parser = &loader->parser; |
---|
829 | PS_Blend blend = face->blend; |
---|
830 | T1_Token token; |
---|
831 | FT_Int n; |
---|
832 | FT_Byte* old_cursor; |
---|
833 | FT_Byte* old_limit; |
---|
834 | |
---|
835 | |
---|
836 | T1_ToTokenArray( parser, design_tokens, |
---|
837 | T1_MAX_MM_DESIGNS, &num_designs ); |
---|
838 | if ( num_designs < 0 ) |
---|
839 | { |
---|
840 | error = T1_Err_Ignore; |
---|
841 | goto Exit; |
---|
842 | } |
---|
843 | if ( num_designs == 0 || num_designs > T1_MAX_MM_DESIGNS ) |
---|
844 | { |
---|
845 | FT_ERROR(( "parse_weight_vector:" )); |
---|
846 | FT_ERROR(( " incorrect number of designs: %d\n", |
---|
847 | num_designs )); |
---|
848 | error = T1_Err_Invalid_File_Format; |
---|
849 | goto Exit; |
---|
850 | } |
---|
851 | |
---|
852 | if ( !blend || !blend->num_designs ) |
---|
853 | { |
---|
854 | error = t1_allocate_blend( face, num_designs, 0 ); |
---|
855 | if ( error ) |
---|
856 | goto Exit; |
---|
857 | blend = face->blend; |
---|
858 | } |
---|
859 | else if ( blend->num_designs != (FT_UInt)num_designs ) |
---|
860 | { |
---|
861 | FT_ERROR(( "parse_weight_vector:" |
---|
862 | " /BlendDesignPosition and /WeightVector have\n" )); |
---|
863 | FT_ERROR(( " " |
---|
864 | " different number of elements!\n" )); |
---|
865 | error = T1_Err_Invalid_File_Format; |
---|
866 | goto Exit; |
---|
867 | } |
---|
868 | |
---|
869 | old_cursor = parser->root.cursor; |
---|
870 | old_limit = parser->root.limit; |
---|
871 | |
---|
872 | for ( n = 0; n < num_designs; n++ ) |
---|
873 | { |
---|
874 | token = design_tokens + n; |
---|
875 | parser->root.cursor = token->start; |
---|
876 | parser->root.limit = token->limit; |
---|
877 | |
---|
878 | blend->default_weight_vector[n] = |
---|
879 | blend->weight_vector[n] = T1_ToFixed( parser, 0 ); |
---|
880 | } |
---|
881 | |
---|
882 | parser->root.cursor = old_cursor; |
---|
883 | parser->root.limit = old_limit; |
---|
884 | |
---|
885 | Exit: |
---|
886 | parser->root.error = error; |
---|
887 | } |
---|
888 | |
---|
889 | |
---|
890 | /* e.g., /BuildCharArray [0 0 0 0 0 0 0 0] def */ |
---|
891 | /* we're only interested in the number of array elements */ |
---|
892 | static void |
---|
893 | parse_buildchar( T1_Face face, |
---|
894 | T1_Loader loader ) |
---|
895 | { |
---|
896 | face->len_buildchar = T1_ToFixedArray( &loader->parser, 0, NULL, 0 ); |
---|
897 | |
---|
898 | return; |
---|
899 | } |
---|
900 | |
---|
901 | |
---|
902 | #endif /* T1_CONFIG_OPTION_NO_MM_SUPPORT */ |
---|
903 | |
---|
904 | |
---|
905 | |
---|
906 | |
---|
907 | /*************************************************************************/ |
---|
908 | /*************************************************************************/ |
---|
909 | /***** *****/ |
---|
910 | /***** TYPE 1 SYMBOL PARSING *****/ |
---|
911 | /***** *****/ |
---|
912 | /*************************************************************************/ |
---|
913 | /*************************************************************************/ |
---|
914 | |
---|
915 | static FT_Error |
---|
916 | t1_load_keyword( T1_Face face, |
---|
917 | T1_Loader loader, |
---|
918 | const T1_Field field ) |
---|
919 | { |
---|
920 | FT_Error error; |
---|
921 | void* dummy_object; |
---|
922 | void** objects; |
---|
923 | FT_UInt max_objects; |
---|
924 | PS_Blend blend = face->blend; |
---|
925 | |
---|
926 | |
---|
927 | /* if the keyword has a dedicated callback, call it */ |
---|
928 | if ( field->type == T1_FIELD_TYPE_CALLBACK ) |
---|
929 | { |
---|
930 | field->reader( (FT_Face)face, loader ); |
---|
931 | error = loader->parser.root.error; |
---|
932 | goto Exit; |
---|
933 | } |
---|
934 | |
---|
935 | /* now, the keyword is either a simple field, or a table of fields; */ |
---|
936 | /* we are now going to take care of it */ |
---|
937 | switch ( field->location ) |
---|
938 | { |
---|
939 | case T1_FIELD_LOCATION_FONT_INFO: |
---|
940 | dummy_object = &face->type1.font_info; |
---|
941 | objects = &dummy_object; |
---|
942 | max_objects = 0; |
---|
943 | |
---|
944 | if ( blend ) |
---|
945 | { |
---|
946 | objects = (void**)blend->font_infos; |
---|
947 | max_objects = blend->num_designs; |
---|
948 | } |
---|
949 | break; |
---|
950 | |
---|
951 | case T1_FIELD_LOCATION_PRIVATE: |
---|
952 | dummy_object = &face->type1.private_dict; |
---|
953 | objects = &dummy_object; |
---|
954 | max_objects = 0; |
---|
955 | |
---|
956 | if ( blend ) |
---|
957 | { |
---|
958 | objects = (void**)blend->privates; |
---|
959 | max_objects = blend->num_designs; |
---|
960 | } |
---|
961 | break; |
---|
962 | |
---|
963 | case T1_FIELD_LOCATION_BBOX: |
---|
964 | dummy_object = &face->type1.font_bbox; |
---|
965 | objects = &dummy_object; |
---|
966 | max_objects = 0; |
---|
967 | |
---|
968 | if ( blend ) |
---|
969 | { |
---|
970 | objects = (void**)blend->bboxes; |
---|
971 | max_objects = blend->num_designs; |
---|
972 | } |
---|
973 | break; |
---|
974 | |
---|
975 | case T1_FIELD_LOCATION_LOADER: |
---|
976 | dummy_object = loader; |
---|
977 | objects = &dummy_object; |
---|
978 | max_objects = 0; |
---|
979 | break; |
---|
980 | |
---|
981 | case T1_FIELD_LOCATION_FACE: |
---|
982 | dummy_object = face; |
---|
983 | objects = &dummy_object; |
---|
984 | max_objects = 0; |
---|
985 | break; |
---|
986 | |
---|
987 | #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT |
---|
988 | case T1_FIELD_LOCATION_BLEND: |
---|
989 | dummy_object = face->blend; |
---|
990 | objects = &dummy_object; |
---|
991 | max_objects = 0; |
---|
992 | break; |
---|
993 | #endif |
---|
994 | |
---|
995 | default: |
---|
996 | dummy_object = &face->type1; |
---|
997 | objects = &dummy_object; |
---|
998 | max_objects = 0; |
---|
999 | } |
---|
1000 | |
---|
1001 | if ( field->type == T1_FIELD_TYPE_INTEGER_ARRAY || |
---|
1002 | field->type == T1_FIELD_TYPE_FIXED_ARRAY ) |
---|
1003 | error = T1_Load_Field_Table( &loader->parser, field, |
---|
1004 | objects, max_objects, 0 ); |
---|
1005 | else |
---|
1006 | error = T1_Load_Field( &loader->parser, field, |
---|
1007 | objects, max_objects, 0 ); |
---|
1008 | |
---|
1009 | Exit: |
---|
1010 | return error; |
---|
1011 | } |
---|
1012 | |
---|
1013 | |
---|
1014 | static void |
---|
1015 | parse_private( T1_Face face, |
---|
1016 | T1_Loader loader ) |
---|
1017 | { |
---|
1018 | FT_UNUSED( face ); |
---|
1019 | |
---|
1020 | loader->keywords_encountered |= T1_PRIVATE; |
---|
1021 | } |
---|
1022 | |
---|
1023 | |
---|
1024 | static int |
---|
1025 | read_binary_data( T1_Parser parser, |
---|
1026 | FT_Long* size, |
---|
1027 | FT_Byte** base ) |
---|
1028 | { |
---|
1029 | FT_Byte* cur; |
---|
1030 | FT_Byte* limit = parser->root.limit; |
---|
1031 | |
---|
1032 | |
---|
1033 | /* the binary data has one of the following formats */ |
---|
1034 | /* */ |
---|
1035 | /* `size' [white*] RD white ....... ND */ |
---|
1036 | /* `size' [white*] -| white ....... |- */ |
---|
1037 | /* */ |
---|
1038 | |
---|
1039 | T1_Skip_Spaces( parser ); |
---|
1040 | |
---|
1041 | cur = parser->root.cursor; |
---|
1042 | |
---|
1043 | if ( cur < limit && ft_isdigit( *cur ) ) |
---|
1044 | { |
---|
1045 | *size = T1_ToInt( parser ); |
---|
1046 | |
---|
1047 | T1_Skip_PS_Token( parser ); /* `RD' or `-|' or something else */ |
---|
1048 | |
---|
1049 | /* there is only one whitespace char after the */ |
---|
1050 | /* `RD' or `-|' token */ |
---|
1051 | *base = parser->root.cursor + 1; |
---|
1052 | |
---|
1053 | parser->root.cursor += *size + 1; |
---|
1054 | return !parser->root.error; |
---|
1055 | } |
---|
1056 | |
---|
1057 | FT_ERROR(( "read_binary_data: invalid size field\n" )); |
---|
1058 | parser->root.error = T1_Err_Invalid_File_Format; |
---|
1059 | return 0; |
---|
1060 | } |
---|
1061 | |
---|
1062 | |
---|
1063 | /* We now define the routines to handle the `/Encoding', `/Subrs', */ |
---|
1064 | /* and `/CharStrings' dictionaries. */ |
---|
1065 | |
---|
1066 | static void |
---|
1067 | parse_font_matrix( T1_Face face, |
---|
1068 | T1_Loader loader ) |
---|
1069 | { |
---|
1070 | T1_Parser parser = &loader->parser; |
---|
1071 | FT_Matrix* matrix = &face->type1.font_matrix; |
---|
1072 | FT_Vector* offset = &face->type1.font_offset; |
---|
1073 | FT_Face root = (FT_Face)&face->root; |
---|
1074 | FT_Fixed temp[6]; |
---|
1075 | FT_Fixed temp_scale; |
---|
1076 | FT_Int result; |
---|
1077 | |
---|
1078 | |
---|
1079 | result = T1_ToFixedArray( parser, 6, temp, 3 ); |
---|
1080 | |
---|
1081 | if ( result < 0 ) |
---|
1082 | { |
---|
1083 | parser->root.error = T1_Err_Invalid_File_Format; |
---|
1084 | return; |
---|
1085 | } |
---|
1086 | |
---|
1087 | temp_scale = FT_ABS( temp[3] ); |
---|
1088 | |
---|
1089 | if ( temp_scale == 0 ) |
---|
1090 | { |
---|
1091 | FT_ERROR(( "parse_font_matrix: invalid font matrix\n" )); |
---|
1092 | parser->root.error = T1_Err_Invalid_File_Format; |
---|
1093 | return; |
---|
1094 | } |
---|
1095 | |
---|
1096 | /* Set Units per EM based on FontMatrix values. We set the value to */ |
---|
1097 | /* 1000 / temp_scale, because temp_scale was already multiplied by */ |
---|
1098 | /* 1000 (in t1_tofixed, from psobjs.c). */ |
---|
1099 | |
---|
1100 | root->units_per_EM = (FT_UShort)( FT_DivFix( 1000 * 0x10000L, |
---|
1101 | temp_scale ) >> 16 ); |
---|
1102 | |
---|
1103 | /* we need to scale the values by 1.0/temp_scale */ |
---|
1104 | if ( temp_scale != 0x10000L ) |
---|
1105 | { |
---|
1106 | temp[0] = FT_DivFix( temp[0], temp_scale ); |
---|
1107 | temp[1] = FT_DivFix( temp[1], temp_scale ); |
---|
1108 | temp[2] = FT_DivFix( temp[2], temp_scale ); |
---|
1109 | temp[4] = FT_DivFix( temp[4], temp_scale ); |
---|
1110 | temp[5] = FT_DivFix( temp[5], temp_scale ); |
---|
1111 | temp[3] = 0x10000L; |
---|
1112 | } |
---|
1113 | |
---|
1114 | matrix->xx = temp[0]; |
---|
1115 | matrix->yx = temp[1]; |
---|
1116 | matrix->xy = temp[2]; |
---|
1117 | matrix->yy = temp[3]; |
---|
1118 | |
---|
1119 | /* note that the offsets must be expressed in integer font units */ |
---|
1120 | offset->x = temp[4] >> 16; |
---|
1121 | offset->y = temp[5] >> 16; |
---|
1122 | } |
---|
1123 | |
---|
1124 | |
---|
1125 | static void |
---|
1126 | parse_encoding( T1_Face face, |
---|
1127 | T1_Loader loader ) |
---|
1128 | { |
---|
1129 | T1_Parser parser = &loader->parser; |
---|
1130 | FT_Byte* cur; |
---|
1131 | FT_Byte* limit = parser->root.limit; |
---|
1132 | |
---|
1133 | PSAux_Service psaux = (PSAux_Service)face->psaux; |
---|
1134 | |
---|
1135 | |
---|
1136 | T1_Skip_Spaces( parser ); |
---|
1137 | cur = parser->root.cursor; |
---|
1138 | if ( cur >= limit ) |
---|
1139 | { |
---|
1140 | FT_ERROR(( "parse_encoding: out of bounds!\n" )); |
---|
1141 | parser->root.error = T1_Err_Invalid_File_Format; |
---|
1142 | return; |
---|
1143 | } |
---|
1144 | |
---|
1145 | /* if we have a number or `[', the encoding is an array, */ |
---|
1146 | /* and we must load it now */ |
---|
1147 | if ( ft_isdigit( *cur ) || *cur == '[' ) |
---|
1148 | { |
---|
1149 | T1_Encoding encode = &face->type1.encoding; |
---|
1150 | FT_Int count, n; |
---|
1151 | PS_Table char_table = &loader->encoding_table; |
---|
1152 | FT_Memory memory = parser->root.memory; |
---|
1153 | FT_Error error; |
---|
1154 | FT_Bool only_immediates = 0; |
---|
1155 | |
---|
1156 | |
---|
1157 | /* read the number of entries in the encoding; should be 256 */ |
---|
1158 | if ( *cur == '[' ) |
---|
1159 | { |
---|
1160 | count = 256; |
---|
1161 | only_immediates = 1; |
---|
1162 | parser->root.cursor++; |
---|
1163 | } |
---|
1164 | else |
---|
1165 | count = (FT_Int)T1_ToInt( parser ); |
---|
1166 | |
---|
1167 | T1_Skip_Spaces( parser ); |
---|
1168 | if ( parser->root.cursor >= limit ) |
---|
1169 | return; |
---|
1170 | |
---|
1171 | /* we use a T1_Table to store our charnames */ |
---|
1172 | loader->num_chars = encode->num_chars = count; |
---|
1173 | if ( FT_NEW_ARRAY( encode->char_index, count ) || |
---|
1174 | FT_NEW_ARRAY( encode->char_name, count ) || |
---|
1175 | FT_SET_ERROR( psaux->ps_table_funcs->init( |
---|
1176 | char_table, count, memory ) ) ) |
---|
1177 | { |
---|
1178 | parser->root.error = error; |
---|
1179 | return; |
---|
1180 | } |
---|
1181 | |
---|
1182 | /* We need to `zero' out encoding_table.elements */ |
---|
1183 | for ( n = 0; n < count; n++ ) |
---|
1184 | { |
---|
1185 | char* notdef = (char *)".notdef"; |
---|
1186 | |
---|
1187 | |
---|
1188 | T1_Add_Table( char_table, n, notdef, 8 ); |
---|
1189 | } |
---|
1190 | |
---|
1191 | /* Now we need to read records of the form */ |
---|
1192 | /* */ |
---|
1193 | /* ... charcode /charname ... */ |
---|
1194 | /* */ |
---|
1195 | /* for each entry in our table. */ |
---|
1196 | /* */ |
---|
1197 | /* We simply look for a number followed by an immediate */ |
---|
1198 | /* name. Note that this ignores correctly the sequence */ |
---|
1199 | /* that is often seen in type1 fonts: */ |
---|
1200 | /* */ |
---|
1201 | /* 0 1 255 { 1 index exch /.notdef put } for dup */ |
---|
1202 | /* */ |
---|
1203 | /* used to clean the encoding array before anything else. */ |
---|
1204 | /* */ |
---|
1205 | /* Alternatively, if the array is directly given as */ |
---|
1206 | /* */ |
---|
1207 | /* /Encoding [ ... ] */ |
---|
1208 | /* */ |
---|
1209 | /* we only read immediates. */ |
---|
1210 | |
---|
1211 | n = 0; |
---|
1212 | T1_Skip_Spaces( parser ); |
---|
1213 | |
---|
1214 | while ( parser->root.cursor < limit ) |
---|
1215 | { |
---|
1216 | cur = parser->root.cursor; |
---|
1217 | |
---|
1218 | /* we stop when we encounter a `def' or `]' */ |
---|
1219 | if ( *cur == 'd' && cur + 3 < limit ) |
---|
1220 | { |
---|
1221 | if ( cur[1] == 'e' && |
---|
1222 | cur[2] == 'f' && |
---|
1223 | IS_PS_DELIM( cur[3] ) ) |
---|
1224 | { |
---|
1225 | FT_TRACE6(( "encoding end\n" )); |
---|
1226 | cur += 3; |
---|
1227 | break; |
---|
1228 | } |
---|
1229 | } |
---|
1230 | if ( *cur == ']' ) |
---|
1231 | { |
---|
1232 | FT_TRACE6(( "encoding end\n" )); |
---|
1233 | cur++; |
---|
1234 | break; |
---|
1235 | } |
---|
1236 | |
---|
1237 | /* check whether we've found an entry */ |
---|
1238 | if ( ft_isdigit( *cur ) || only_immediates ) |
---|
1239 | { |
---|
1240 | FT_Int charcode; |
---|
1241 | |
---|
1242 | |
---|
1243 | if ( only_immediates ) |
---|
1244 | charcode = n; |
---|
1245 | else |
---|
1246 | { |
---|
1247 | charcode = (FT_Int)T1_ToInt( parser ); |
---|
1248 | T1_Skip_Spaces( parser ); |
---|
1249 | } |
---|
1250 | |
---|
1251 | cur = parser->root.cursor; |
---|
1252 | |
---|
1253 | if ( *cur == '/' && cur + 2 < limit && n < count ) |
---|
1254 | { |
---|
1255 | FT_PtrDist len; |
---|
1256 | |
---|
1257 | |
---|
1258 | cur++; |
---|
1259 | |
---|
1260 | parser->root.cursor = cur; |
---|
1261 | T1_Skip_PS_Token( parser ); |
---|
1262 | if ( parser->root.error ) |
---|
1263 | return; |
---|
1264 | |
---|
1265 | len = parser->root.cursor - cur; |
---|
1266 | |
---|
1267 | parser->root.error = T1_Add_Table( char_table, charcode, |
---|
1268 | cur, len + 1 ); |
---|
1269 | if ( parser->root.error ) |
---|
1270 | return; |
---|
1271 | char_table->elements[charcode][len] = '\0'; |
---|
1272 | |
---|
1273 | n++; |
---|
1274 | } |
---|
1275 | else if ( only_immediates ) |
---|
1276 | { |
---|
1277 | /* Since the current position is not updated for */ |
---|
1278 | /* immediates-only mode we would get an infinite loop if */ |
---|
1279 | /* we don't do anything here. */ |
---|
1280 | /* */ |
---|
1281 | /* This encoding array is not valid according to the type1 */ |
---|
1282 | /* specification (it might be an encoding for a CID type1 */ |
---|
1283 | /* font, however), so we conclude that this font is NOT a */ |
---|
1284 | /* type1 font. */ |
---|
1285 | parser->root.error = FT_Err_Unknown_File_Format; |
---|
1286 | return; |
---|
1287 | } |
---|
1288 | } |
---|
1289 | else |
---|
1290 | { |
---|
1291 | T1_Skip_PS_Token( parser ); |
---|
1292 | if ( parser->root.error ) |
---|
1293 | return; |
---|
1294 | } |
---|
1295 | |
---|
1296 | T1_Skip_Spaces( parser ); |
---|
1297 | } |
---|
1298 | |
---|
1299 | face->type1.encoding_type = T1_ENCODING_TYPE_ARRAY; |
---|
1300 | parser->root.cursor = cur; |
---|
1301 | } |
---|
1302 | |
---|
1303 | /* Otherwise, we should have either `StandardEncoding', */ |
---|
1304 | /* `ExpertEncoding', or `ISOLatin1Encoding' */ |
---|
1305 | else |
---|
1306 | { |
---|
1307 | if ( cur + 17 < limit && |
---|
1308 | ft_strncmp( (const char*)cur, "StandardEncoding", 16 ) == 0 ) |
---|
1309 | face->type1.encoding_type = T1_ENCODING_TYPE_STANDARD; |
---|
1310 | |
---|
1311 | else if ( cur + 15 < limit && |
---|
1312 | ft_strncmp( (const char*)cur, "ExpertEncoding", 14 ) == 0 ) |
---|
1313 | face->type1.encoding_type = T1_ENCODING_TYPE_EXPERT; |
---|
1314 | |
---|
1315 | else if ( cur + 18 < limit && |
---|
1316 | ft_strncmp( (const char*)cur, "ISOLatin1Encoding", 17 ) == 0 ) |
---|
1317 | face->type1.encoding_type = T1_ENCODING_TYPE_ISOLATIN1; |
---|
1318 | |
---|
1319 | else |
---|
1320 | parser->root.error = T1_Err_Ignore; |
---|
1321 | } |
---|
1322 | } |
---|
1323 | |
---|
1324 | |
---|
1325 | static void |
---|
1326 | parse_subrs( T1_Face face, |
---|
1327 | T1_Loader loader ) |
---|
1328 | { |
---|
1329 | T1_Parser parser = &loader->parser; |
---|
1330 | PS_Table table = &loader->subrs; |
---|
1331 | FT_Memory memory = parser->root.memory; |
---|
1332 | FT_Error error; |
---|
1333 | FT_Int num_subrs; |
---|
1334 | |
---|
1335 | PSAux_Service psaux = (PSAux_Service)face->psaux; |
---|
1336 | |
---|
1337 | |
---|
1338 | T1_Skip_Spaces( parser ); |
---|
1339 | |
---|
1340 | /* test for empty array */ |
---|
1341 | if ( parser->root.cursor < parser->root.limit && |
---|
1342 | *parser->root.cursor == '[' ) |
---|
1343 | { |
---|
1344 | T1_Skip_PS_Token( parser ); |
---|
1345 | T1_Skip_Spaces ( parser ); |
---|
1346 | if ( parser->root.cursor >= parser->root.limit || |
---|
1347 | *parser->root.cursor != ']' ) |
---|
1348 | parser->root.error = T1_Err_Invalid_File_Format; |
---|
1349 | return; |
---|
1350 | } |
---|
1351 | |
---|
1352 | num_subrs = (FT_Int)T1_ToInt( parser ); |
---|
1353 | |
---|
1354 | /* position the parser right before the `dup' of the first subr */ |
---|
1355 | T1_Skip_PS_Token( parser ); /* `array' */ |
---|
1356 | if ( parser->root.error ) |
---|
1357 | return; |
---|
1358 | T1_Skip_Spaces( parser ); |
---|
1359 | |
---|
1360 | /* initialize subrs array -- with synthetic fonts it is possible */ |
---|
1361 | /* we get here twice */ |
---|
1362 | if ( !loader->num_subrs ) |
---|
1363 | { |
---|
1364 | error = psaux->ps_table_funcs->init( table, num_subrs, memory ); |
---|
1365 | if ( error ) |
---|
1366 | goto Fail; |
---|
1367 | } |
---|
1368 | |
---|
1369 | /* the format is simple: */ |
---|
1370 | /* */ |
---|
1371 | /* `index' + binary data */ |
---|
1372 | /* */ |
---|
1373 | for (;;) |
---|
1374 | { |
---|
1375 | FT_Long idx, size; |
---|
1376 | FT_Byte* base; |
---|
1377 | |
---|
1378 | |
---|
1379 | /* If the next token isn't `dup' we are done. */ |
---|
1380 | if ( ft_strncmp( (char*)parser->root.cursor, "dup", 3 ) != 0 ) |
---|
1381 | break; |
---|
1382 | |
---|
1383 | T1_Skip_PS_Token( parser ); /* `dup' */ |
---|
1384 | |
---|
1385 | idx = T1_ToInt( parser ); |
---|
1386 | |
---|
1387 | if ( !read_binary_data( parser, &size, &base ) ) |
---|
1388 | return; |
---|
1389 | |
---|
1390 | /* The binary string is followed by one token, e.g. `NP' */ |
---|
1391 | /* (bound to `noaccess put') or by two separate tokens: */ |
---|
1392 | /* `noaccess' & `put'. We position the parser right */ |
---|
1393 | /* before the next `dup', if any. */ |
---|
1394 | T1_Skip_PS_Token( parser ); /* `NP' or `|' or `noaccess' */ |
---|
1395 | if ( parser->root.error ) |
---|
1396 | return; |
---|
1397 | T1_Skip_Spaces ( parser ); |
---|
1398 | |
---|
1399 | if ( ft_strncmp( (char*)parser->root.cursor, "put", 3 ) == 0 ) |
---|
1400 | { |
---|
1401 | T1_Skip_PS_Token( parser ); /* skip `put' */ |
---|
1402 | T1_Skip_Spaces ( parser ); |
---|
1403 | } |
---|
1404 | |
---|
1405 | /* with synthetic fonts it is possible we get here twice */ |
---|
1406 | if ( loader->num_subrs ) |
---|
1407 | continue; |
---|
1408 | |
---|
1409 | /* some fonts use a value of -1 for lenIV to indicate that */ |
---|
1410 | /* the charstrings are unencoded */ |
---|
1411 | /* */ |
---|
1412 | /* thanks to Tom Kacvinsky for pointing this out */ |
---|
1413 | /* */ |
---|
1414 | if ( face->type1.private_dict.lenIV >= 0 ) |
---|
1415 | { |
---|
1416 | FT_Byte* temp; |
---|
1417 | |
---|
1418 | |
---|
1419 | /* some fonts define empty subr records -- this is not totally */ |
---|
1420 | /* compliant to the specification (which says they should at */ |
---|
1421 | /* least contain a `return'), but we support them anyway */ |
---|
1422 | if ( size < face->type1.private_dict.lenIV ) |
---|
1423 | { |
---|
1424 | error = T1_Err_Invalid_File_Format; |
---|
1425 | goto Fail; |
---|
1426 | } |
---|
1427 | |
---|
1428 | /* t1_decrypt() shouldn't write to base -- make temporary copy */ |
---|
1429 | if ( FT_ALLOC( temp, size ) ) |
---|
1430 | goto Fail; |
---|
1431 | FT_MEM_COPY( temp, base, size ); |
---|
1432 | psaux->t1_decrypt( temp, size, 4330 ); |
---|
1433 | size -= face->type1.private_dict.lenIV; |
---|
1434 | error = T1_Add_Table( table, (FT_Int)idx, |
---|
1435 | temp + face->type1.private_dict.lenIV, size ); |
---|
1436 | FT_FREE( temp ); |
---|
1437 | } |
---|
1438 | else |
---|
1439 | error = T1_Add_Table( table, (FT_Int)idx, base, size ); |
---|
1440 | if ( error ) |
---|
1441 | goto Fail; |
---|
1442 | } |
---|
1443 | |
---|
1444 | if ( !loader->num_subrs ) |
---|
1445 | loader->num_subrs = num_subrs; |
---|
1446 | |
---|
1447 | return; |
---|
1448 | |
---|
1449 | Fail: |
---|
1450 | parser->root.error = error; |
---|
1451 | } |
---|
1452 | |
---|
1453 | |
---|
1454 | #define TABLE_EXTEND 5 |
---|
1455 | |
---|
1456 | |
---|
1457 | static void |
---|
1458 | parse_charstrings( T1_Face face, |
---|
1459 | T1_Loader loader ) |
---|
1460 | { |
---|
1461 | T1_Parser parser = &loader->parser; |
---|
1462 | PS_Table code_table = &loader->charstrings; |
---|
1463 | PS_Table name_table = &loader->glyph_names; |
---|
1464 | PS_Table swap_table = &loader->swap_table; |
---|
1465 | FT_Memory memory = parser->root.memory; |
---|
1466 | FT_Error error; |
---|
1467 | |
---|
1468 | PSAux_Service psaux = (PSAux_Service)face->psaux; |
---|
1469 | |
---|
1470 | FT_Byte* cur; |
---|
1471 | FT_Byte* limit = parser->root.limit; |
---|
1472 | FT_Int n, num_glyphs; |
---|
1473 | FT_UInt notdef_index = 0; |
---|
1474 | FT_Byte notdef_found = 0; |
---|
1475 | |
---|
1476 | |
---|
1477 | num_glyphs = (FT_Int)T1_ToInt( parser ); |
---|
1478 | /* some fonts like Optima-Oblique not only define the /CharStrings */ |
---|
1479 | /* array but access it also */ |
---|
1480 | if ( num_glyphs == 0 || parser->root.error ) |
---|
1481 | return; |
---|
1482 | |
---|
1483 | /* initialize tables, leaving space for addition of .notdef, */ |
---|
1484 | /* if necessary, and a few other glyphs to handle buggy */ |
---|
1485 | /* fonts which have more glyphs than specified. */ |
---|
1486 | |
---|
1487 | /* for some non-standard fonts like `Optima' which provides */ |
---|
1488 | /* different outlines depending on the resolution it is */ |
---|
1489 | /* possible to get here twice */ |
---|
1490 | if ( !loader->num_glyphs ) |
---|
1491 | { |
---|
1492 | error = psaux->ps_table_funcs->init( |
---|
1493 | code_table, num_glyphs + 1 + TABLE_EXTEND, memory ); |
---|
1494 | if ( error ) |
---|
1495 | goto Fail; |
---|
1496 | |
---|
1497 | error = psaux->ps_table_funcs->init( |
---|
1498 | name_table, num_glyphs + 1 + TABLE_EXTEND, memory ); |
---|
1499 | if ( error ) |
---|
1500 | goto Fail; |
---|
1501 | |
---|
1502 | /* Initialize table for swapping index notdef_index and */ |
---|
1503 | /* index 0 names and codes (if necessary). */ |
---|
1504 | |
---|
1505 | error = psaux->ps_table_funcs->init( swap_table, 4, memory ); |
---|
1506 | if ( error ) |
---|
1507 | goto Fail; |
---|
1508 | } |
---|
1509 | |
---|
1510 | n = 0; |
---|
1511 | |
---|
1512 | for (;;) |
---|
1513 | { |
---|
1514 | FT_Long size; |
---|
1515 | FT_Byte* base; |
---|
1516 | |
---|
1517 | |
---|
1518 | /* the format is simple: */ |
---|
1519 | /* `/glyphname' + binary data */ |
---|
1520 | |
---|
1521 | T1_Skip_Spaces( parser ); |
---|
1522 | |
---|
1523 | cur = parser->root.cursor; |
---|
1524 | if ( cur >= limit ) |
---|
1525 | break; |
---|
1526 | |
---|
1527 | /* we stop when we find a `def' or `end' keyword */ |
---|
1528 | if ( cur + 3 < limit && IS_PS_DELIM( cur[3] ) ) |
---|
1529 | { |
---|
1530 | if ( cur[0] == 'd' && |
---|
1531 | cur[1] == 'e' && |
---|
1532 | cur[2] == 'f' ) |
---|
1533 | { |
---|
1534 | /* There are fonts which have this: */ |
---|
1535 | /* */ |
---|
1536 | /* /CharStrings 118 dict def */ |
---|
1537 | /* Private begin */ |
---|
1538 | /* CharStrings begin */ |
---|
1539 | /* ... */ |
---|
1540 | /* */ |
---|
1541 | /* To catch this we ignore `def' if */ |
---|
1542 | /* no charstring has actually been */ |
---|
1543 | /* seen. */ |
---|
1544 | if ( n ) |
---|
1545 | break; |
---|
1546 | } |
---|
1547 | |
---|
1548 | if ( cur[0] == 'e' && |
---|
1549 | cur[1] == 'n' && |
---|
1550 | cur[2] == 'd' ) |
---|
1551 | break; |
---|
1552 | } |
---|
1553 | |
---|
1554 | T1_Skip_PS_Token( parser ); |
---|
1555 | if ( parser->root.error ) |
---|
1556 | return; |
---|
1557 | |
---|
1558 | if ( *cur == '/' ) |
---|
1559 | { |
---|
1560 | FT_PtrDist len; |
---|
1561 | |
---|
1562 | |
---|
1563 | if ( cur + 1 >= limit ) |
---|
1564 | { |
---|
1565 | error = T1_Err_Invalid_File_Format; |
---|
1566 | goto Fail; |
---|
1567 | } |
---|
1568 | |
---|
1569 | cur++; /* skip `/' */ |
---|
1570 | len = parser->root.cursor - cur; |
---|
1571 | |
---|
1572 | if ( !read_binary_data( parser, &size, &base ) ) |
---|
1573 | return; |
---|
1574 | |
---|
1575 | /* for some non-standard fonts like `Optima' which provides */ |
---|
1576 | /* different outlines depending on the resolution it is */ |
---|
1577 | /* possible to get here twice */ |
---|
1578 | if ( loader->num_glyphs ) |
---|
1579 | continue; |
---|
1580 | |
---|
1581 | error = T1_Add_Table( name_table, n, cur, len + 1 ); |
---|
1582 | if ( error ) |
---|
1583 | goto Fail; |
---|
1584 | |
---|
1585 | /* add a trailing zero to the name table */ |
---|
1586 | name_table->elements[n][len] = '\0'; |
---|
1587 | |
---|
1588 | /* record index of /.notdef */ |
---|
1589 | if ( *cur == '.' && |
---|
1590 | ft_strcmp( ".notdef", |
---|
1591 | (const char*)(name_table->elements[n]) ) == 0 ) |
---|
1592 | { |
---|
1593 | notdef_index = n; |
---|
1594 | notdef_found = 1; |
---|
1595 | } |
---|
1596 | |
---|
1597 | if ( face->type1.private_dict.lenIV >= 0 && |
---|
1598 | n < num_glyphs + TABLE_EXTEND ) |
---|
1599 | { |
---|
1600 | FT_Byte* temp; |
---|
1601 | |
---|
1602 | |
---|
1603 | if ( size <= face->type1.private_dict.lenIV ) |
---|
1604 | { |
---|
1605 | error = T1_Err_Invalid_File_Format; |
---|
1606 | goto Fail; |
---|
1607 | } |
---|
1608 | |
---|
1609 | /* t1_decrypt() shouldn't write to base -- make temporary copy */ |
---|
1610 | if ( FT_ALLOC( temp, size ) ) |
---|
1611 | goto Fail; |
---|
1612 | FT_MEM_COPY( temp, base, size ); |
---|
1613 | psaux->t1_decrypt( temp, size, 4330 ); |
---|
1614 | size -= face->type1.private_dict.lenIV; |
---|
1615 | error = T1_Add_Table( code_table, n, |
---|
1616 | temp + face->type1.private_dict.lenIV, size ); |
---|
1617 | FT_FREE( temp ); |
---|
1618 | } |
---|
1619 | else |
---|
1620 | error = T1_Add_Table( code_table, n, base, size ); |
---|
1621 | if ( error ) |
---|
1622 | goto Fail; |
---|
1623 | |
---|
1624 | n++; |
---|
1625 | } |
---|
1626 | } |
---|
1627 | |
---|
1628 | loader->num_glyphs = n; |
---|
1629 | |
---|
1630 | /* if /.notdef is found but does not occupy index 0, do our magic. */ |
---|
1631 | if ( notdef_found && |
---|
1632 | ft_strcmp( ".notdef", (const char*)name_table->elements[0] ) ) |
---|
1633 | { |
---|
1634 | /* Swap glyph in index 0 with /.notdef glyph. First, add index 0 */ |
---|
1635 | /* name and code entries to swap_table. Then place notdef_index */ |
---|
1636 | /* name and code entries into swap_table. Then swap name and code */ |
---|
1637 | /* entries at indices notdef_index and 0 using values stored in */ |
---|
1638 | /* swap_table. */ |
---|
1639 | |
---|
1640 | /* Index 0 name */ |
---|
1641 | error = T1_Add_Table( swap_table, 0, |
---|
1642 | name_table->elements[0], |
---|
1643 | name_table->lengths [0] ); |
---|
1644 | if ( error ) |
---|
1645 | goto Fail; |
---|
1646 | |
---|
1647 | /* Index 0 code */ |
---|
1648 | error = T1_Add_Table( swap_table, 1, |
---|
1649 | code_table->elements[0], |
---|
1650 | code_table->lengths [0] ); |
---|
1651 | if ( error ) |
---|
1652 | goto Fail; |
---|
1653 | |
---|
1654 | /* Index notdef_index name */ |
---|
1655 | error = T1_Add_Table( swap_table, 2, |
---|
1656 | name_table->elements[notdef_index], |
---|
1657 | name_table->lengths [notdef_index] ); |
---|
1658 | if ( error ) |
---|
1659 | goto Fail; |
---|
1660 | |
---|
1661 | /* Index notdef_index code */ |
---|
1662 | error = T1_Add_Table( swap_table, 3, |
---|
1663 | code_table->elements[notdef_index], |
---|
1664 | code_table->lengths [notdef_index] ); |
---|
1665 | if ( error ) |
---|
1666 | goto Fail; |
---|
1667 | |
---|
1668 | error = T1_Add_Table( name_table, notdef_index, |
---|
1669 | swap_table->elements[0], |
---|
1670 | swap_table->lengths [0] ); |
---|
1671 | if ( error ) |
---|
1672 | goto Fail; |
---|
1673 | |
---|
1674 | error = T1_Add_Table( code_table, notdef_index, |
---|
1675 | swap_table->elements[1], |
---|
1676 | swap_table->lengths [1] ); |
---|
1677 | if ( error ) |
---|
1678 | goto Fail; |
---|
1679 | |
---|
1680 | error = T1_Add_Table( name_table, 0, |
---|
1681 | swap_table->elements[2], |
---|
1682 | swap_table->lengths [2] ); |
---|
1683 | if ( error ) |
---|
1684 | goto Fail; |
---|
1685 | |
---|
1686 | error = T1_Add_Table( code_table, 0, |
---|
1687 | swap_table->elements[3], |
---|
1688 | swap_table->lengths [3] ); |
---|
1689 | if ( error ) |
---|
1690 | goto Fail; |
---|
1691 | |
---|
1692 | } |
---|
1693 | else if ( !notdef_found ) |
---|
1694 | { |
---|
1695 | /* notdef_index is already 0, or /.notdef is undefined in */ |
---|
1696 | /* charstrings dictionary. Worry about /.notdef undefined. */ |
---|
1697 | /* We take index 0 and add it to the end of the table(s) */ |
---|
1698 | /* and add our own /.notdef glyph to index 0. */ |
---|
1699 | |
---|
1700 | /* 0 333 hsbw endchar */ |
---|
1701 | FT_Byte notdef_glyph[] = { 0x8B, 0xF7, 0xE1, 0x0D, 0x0E }; |
---|
1702 | char* notdef_name = (char *)".notdef"; |
---|
1703 | |
---|
1704 | |
---|
1705 | error = T1_Add_Table( swap_table, 0, |
---|
1706 | name_table->elements[0], |
---|
1707 | name_table->lengths [0] ); |
---|
1708 | if ( error ) |
---|
1709 | goto Fail; |
---|
1710 | |
---|
1711 | error = T1_Add_Table( swap_table, 1, |
---|
1712 | code_table->elements[0], |
---|
1713 | code_table->lengths [0] ); |
---|
1714 | if ( error ) |
---|
1715 | goto Fail; |
---|
1716 | |
---|
1717 | error = T1_Add_Table( name_table, 0, notdef_name, 8 ); |
---|
1718 | if ( error ) |
---|
1719 | goto Fail; |
---|
1720 | |
---|
1721 | error = T1_Add_Table( code_table, 0, notdef_glyph, 5 ); |
---|
1722 | |
---|
1723 | if ( error ) |
---|
1724 | goto Fail; |
---|
1725 | |
---|
1726 | error = T1_Add_Table( name_table, n, |
---|
1727 | swap_table->elements[0], |
---|
1728 | swap_table->lengths [0] ); |
---|
1729 | if ( error ) |
---|
1730 | goto Fail; |
---|
1731 | |
---|
1732 | error = T1_Add_Table( code_table, n, |
---|
1733 | swap_table->elements[1], |
---|
1734 | swap_table->lengths [1] ); |
---|
1735 | if ( error ) |
---|
1736 | goto Fail; |
---|
1737 | |
---|
1738 | /* we added a glyph. */ |
---|
1739 | loader->num_glyphs += 1; |
---|
1740 | } |
---|
1741 | |
---|
1742 | return; |
---|
1743 | |
---|
1744 | Fail: |
---|
1745 | parser->root.error = error; |
---|
1746 | } |
---|
1747 | |
---|
1748 | |
---|
1749 | /*************************************************************************/ |
---|
1750 | /* */ |
---|
1751 | /* Define the token field static variables. This is a set of */ |
---|
1752 | /* T1_FieldRec variables. */ |
---|
1753 | /* */ |
---|
1754 | /*************************************************************************/ |
---|
1755 | |
---|
1756 | |
---|
1757 | static |
---|
1758 | const T1_FieldRec t1_keywords[] = |
---|
1759 | { |
---|
1760 | |
---|
1761 | #include "t1tokens.h" |
---|
1762 | |
---|
1763 | /* now add the special functions... */ |
---|
1764 | T1_FIELD_CALLBACK( "FontMatrix", parse_font_matrix, |
---|
1765 | T1_FIELD_DICT_FONTDICT ) |
---|
1766 | T1_FIELD_CALLBACK( "Encoding", parse_encoding, |
---|
1767 | T1_FIELD_DICT_FONTDICT ) |
---|
1768 | T1_FIELD_CALLBACK( "Subrs", parse_subrs, |
---|
1769 | T1_FIELD_DICT_PRIVATE ) |
---|
1770 | T1_FIELD_CALLBACK( "CharStrings", parse_charstrings, |
---|
1771 | T1_FIELD_DICT_PRIVATE ) |
---|
1772 | T1_FIELD_CALLBACK( "Private", parse_private, |
---|
1773 | T1_FIELD_DICT_FONTDICT ) |
---|
1774 | |
---|
1775 | #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT |
---|
1776 | T1_FIELD_CALLBACK( "BlendDesignPositions", parse_blend_design_positions, |
---|
1777 | T1_FIELD_DICT_FONTDICT ) |
---|
1778 | T1_FIELD_CALLBACK( "BlendDesignMap", parse_blend_design_map, |
---|
1779 | T1_FIELD_DICT_FONTDICT ) |
---|
1780 | T1_FIELD_CALLBACK( "BlendAxisTypes", parse_blend_axis_types, |
---|
1781 | T1_FIELD_DICT_FONTDICT ) |
---|
1782 | T1_FIELD_CALLBACK( "WeightVector", parse_weight_vector, |
---|
1783 | T1_FIELD_DICT_FONTDICT ) |
---|
1784 | T1_FIELD_CALLBACK( "BuildCharArray", parse_buildchar, |
---|
1785 | T1_FIELD_DICT_PRIVATE ) |
---|
1786 | #endif |
---|
1787 | |
---|
1788 | { 0, T1_FIELD_LOCATION_CID_INFO, T1_FIELD_TYPE_NONE, 0, 0, 0, 0, 0, 0 } |
---|
1789 | }; |
---|
1790 | |
---|
1791 | |
---|
1792 | #define T1_FIELD_COUNT \ |
---|
1793 | ( sizeof ( t1_keywords ) / sizeof ( t1_keywords[0] ) ) |
---|
1794 | |
---|
1795 | |
---|
1796 | static FT_Error |
---|
1797 | parse_dict( T1_Face face, |
---|
1798 | T1_Loader loader, |
---|
1799 | FT_Byte* base, |
---|
1800 | FT_Long size ) |
---|
1801 | { |
---|
1802 | T1_Parser parser = &loader->parser; |
---|
1803 | FT_Byte *limit, *start_binary = NULL; |
---|
1804 | FT_Bool have_integer = 0; |
---|
1805 | |
---|
1806 | |
---|
1807 | parser->root.cursor = base; |
---|
1808 | parser->root.limit = base + size; |
---|
1809 | parser->root.error = T1_Err_Ok; |
---|
1810 | |
---|
1811 | limit = parser->root.limit; |
---|
1812 | |
---|
1813 | T1_Skip_Spaces( parser ); |
---|
1814 | |
---|
1815 | while ( parser->root.cursor < limit ) |
---|
1816 | { |
---|
1817 | FT_Byte* cur; |
---|
1818 | |
---|
1819 | |
---|
1820 | cur = parser->root.cursor; |
---|
1821 | |
---|
1822 | /* look for `eexec' */ |
---|
1823 | if ( IS_PS_TOKEN( cur, limit, "eexec" ) ) |
---|
1824 | break; |
---|
1825 | |
---|
1826 | /* look for `closefile' which ends the eexec section */ |
---|
1827 | else if ( IS_PS_TOKEN( cur, limit, "closefile" ) ) |
---|
1828 | break; |
---|
1829 | |
---|
1830 | /* in a synthetic font the base font starts after a */ |
---|
1831 | /* `FontDictionary' token that is placed after a Private dict */ |
---|
1832 | else if ( IS_PS_TOKEN( cur, limit, "FontDirectory" ) ) |
---|
1833 | { |
---|
1834 | if ( loader->keywords_encountered & T1_PRIVATE ) |
---|
1835 | loader->keywords_encountered |= |
---|
1836 | T1_FONTDIR_AFTER_PRIVATE; |
---|
1837 | parser->root.cursor += 13; |
---|
1838 | } |
---|
1839 | |
---|
1840 | /* check whether we have an integer */ |
---|
1841 | else if ( ft_isdigit( *cur ) ) |
---|
1842 | { |
---|
1843 | start_binary = cur; |
---|
1844 | T1_Skip_PS_Token( parser ); |
---|
1845 | if ( parser->root.error ) |
---|
1846 | goto Exit; |
---|
1847 | have_integer = 1; |
---|
1848 | } |
---|
1849 | |
---|
1850 | /* in valid Type 1 fonts we don't see `RD' or `-|' directly */ |
---|
1851 | /* since those tokens are handled by parse_subrs and */ |
---|
1852 | /* parse_charstrings */ |
---|
1853 | else if ( *cur == 'R' && cur + 6 < limit && *(cur + 1) == 'D' && |
---|
1854 | have_integer ) |
---|
1855 | { |
---|
1856 | FT_Long s; |
---|
1857 | FT_Byte* b; |
---|
1858 | |
---|
1859 | |
---|
1860 | parser->root.cursor = start_binary; |
---|
1861 | if ( !read_binary_data( parser, &s, &b ) ) |
---|
1862 | return T1_Err_Invalid_File_Format; |
---|
1863 | have_integer = 0; |
---|
1864 | } |
---|
1865 | |
---|
1866 | else if ( *cur == '-' && cur + 6 < limit && *(cur + 1) == '|' && |
---|
1867 | have_integer ) |
---|
1868 | { |
---|
1869 | FT_Long s; |
---|
1870 | FT_Byte* b; |
---|
1871 | |
---|
1872 | |
---|
1873 | parser->root.cursor = start_binary; |
---|
1874 | if ( !read_binary_data( parser, &s, &b ) ) |
---|
1875 | return T1_Err_Invalid_File_Format; |
---|
1876 | have_integer = 0; |
---|
1877 | } |
---|
1878 | |
---|
1879 | /* look for immediates */ |
---|
1880 | else if ( *cur == '/' && cur + 2 < limit ) |
---|
1881 | { |
---|
1882 | FT_PtrDist len; |
---|
1883 | |
---|
1884 | |
---|
1885 | cur++; |
---|
1886 | |
---|
1887 | parser->root.cursor = cur; |
---|
1888 | T1_Skip_PS_Token( parser ); |
---|
1889 | if ( parser->root.error ) |
---|
1890 | goto Exit; |
---|
1891 | |
---|
1892 | len = parser->root.cursor - cur; |
---|
1893 | |
---|
1894 | if ( len > 0 && len < 22 && parser->root.cursor < limit ) |
---|
1895 | { |
---|
1896 | /* now compare the immediate name to the keyword table */ |
---|
1897 | T1_Field keyword = (T1_Field)t1_keywords; |
---|
1898 | |
---|
1899 | |
---|
1900 | for (;;) |
---|
1901 | { |
---|
1902 | FT_Byte* name; |
---|
1903 | |
---|
1904 | |
---|
1905 | name = (FT_Byte*)keyword->ident; |
---|
1906 | if ( !name ) |
---|
1907 | break; |
---|
1908 | |
---|
1909 | if ( cur[0] == name[0] && |
---|
1910 | len == (FT_PtrDist)ft_strlen( (const char *)name ) && |
---|
1911 | ft_memcmp( cur, name, len ) == 0 ) |
---|
1912 | { |
---|
1913 | /* We found it -- run the parsing callback! */ |
---|
1914 | /* We record every instance of every field */ |
---|
1915 | /* (until we reach the base font of a */ |
---|
1916 | /* synthetic font) to deal adequately with */ |
---|
1917 | /* multiple master fonts; this is also */ |
---|
1918 | /* necessary because later PostScript */ |
---|
1919 | /* definitions override earlier ones. */ |
---|
1920 | |
---|
1921 | /* Once we encounter `FontDirectory' after */ |
---|
1922 | /* `/Private', we know that this is a synthetic */ |
---|
1923 | /* font; except for `/CharStrings' we are not */ |
---|
1924 | /* interested in anything that follows this */ |
---|
1925 | /* `FontDirectory'. */ |
---|
1926 | |
---|
1927 | /* MM fonts have more than one /Private token at */ |
---|
1928 | /* the top level; let's hope that all the junk */ |
---|
1929 | /* that follows the first /Private token is not */ |
---|
1930 | /* interesting to us. */ |
---|
1931 | |
---|
1932 | /* According to Adobe Tech Note #5175 (CID-Keyed */ |
---|
1933 | /* Font Installation for ATM Software) a `begin' */ |
---|
1934 | /* must be followed by exactly one `end', and */ |
---|
1935 | /* `begin' -- `end' pairs must be accurately */ |
---|
1936 | /* paired. We could use this to distinguish */ |
---|
1937 | /* between the global Private and the Private */ |
---|
1938 | /* dict that is a member of the Blend dict. */ |
---|
1939 | |
---|
1940 | const FT_UInt dict = |
---|
1941 | ( loader->keywords_encountered & T1_PRIVATE ) |
---|
1942 | ? T1_FIELD_DICT_PRIVATE |
---|
1943 | : T1_FIELD_DICT_FONTDICT; |
---|
1944 | |
---|
1945 | if ( !( dict & keyword->dict ) ) |
---|
1946 | { |
---|
1947 | FT_TRACE1(( "parse_dict: found %s but ignoring it " |
---|
1948 | "since it is in the wrong dictionary\n", |
---|
1949 | keyword->ident )); |
---|
1950 | break; |
---|
1951 | } |
---|
1952 | |
---|
1953 | if ( !( loader->keywords_encountered & |
---|
1954 | T1_FONTDIR_AFTER_PRIVATE ) || |
---|
1955 | ft_strcmp( (const char*)name, "CharStrings" ) == 0 ) |
---|
1956 | { |
---|
1957 | parser->root.error = t1_load_keyword( face, |
---|
1958 | loader, |
---|
1959 | keyword ); |
---|
1960 | if ( parser->root.error != T1_Err_Ok ) |
---|
1961 | { |
---|
1962 | if ( FT_ERROR_BASE( parser->root.error ) == FT_Err_Ignore ) |
---|
1963 | parser->root.error = T1_Err_Ok; |
---|
1964 | else |
---|
1965 | return parser->root.error; |
---|
1966 | } |
---|
1967 | } |
---|
1968 | break; |
---|
1969 | } |
---|
1970 | |
---|
1971 | keyword++; |
---|
1972 | } |
---|
1973 | } |
---|
1974 | |
---|
1975 | have_integer = 0; |
---|
1976 | } |
---|
1977 | else |
---|
1978 | { |
---|
1979 | T1_Skip_PS_Token( parser ); |
---|
1980 | if ( parser->root.error ) |
---|
1981 | goto Exit; |
---|
1982 | have_integer = 0; |
---|
1983 | } |
---|
1984 | |
---|
1985 | T1_Skip_Spaces( parser ); |
---|
1986 | } |
---|
1987 | |
---|
1988 | Exit: |
---|
1989 | return parser->root.error; |
---|
1990 | } |
---|
1991 | |
---|
1992 | |
---|
1993 | static void |
---|
1994 | t1_init_loader( T1_Loader loader, |
---|
1995 | T1_Face face ) |
---|
1996 | { |
---|
1997 | FT_UNUSED( face ); |
---|
1998 | |
---|
1999 | FT_MEM_ZERO( loader, sizeof ( *loader ) ); |
---|
2000 | loader->num_glyphs = 0; |
---|
2001 | loader->num_chars = 0; |
---|
2002 | |
---|
2003 | /* initialize the tables -- simply set their `init' field to 0 */ |
---|
2004 | loader->encoding_table.init = 0; |
---|
2005 | loader->charstrings.init = 0; |
---|
2006 | loader->glyph_names.init = 0; |
---|
2007 | loader->subrs.init = 0; |
---|
2008 | loader->swap_table.init = 0; |
---|
2009 | loader->fontdata = 0; |
---|
2010 | loader->keywords_encountered = 0; |
---|
2011 | } |
---|
2012 | |
---|
2013 | |
---|
2014 | static void |
---|
2015 | t1_done_loader( T1_Loader loader ) |
---|
2016 | { |
---|
2017 | T1_Parser parser = &loader->parser; |
---|
2018 | |
---|
2019 | |
---|
2020 | /* finalize tables */ |
---|
2021 | T1_Release_Table( &loader->encoding_table ); |
---|
2022 | T1_Release_Table( &loader->charstrings ); |
---|
2023 | T1_Release_Table( &loader->glyph_names ); |
---|
2024 | T1_Release_Table( &loader->swap_table ); |
---|
2025 | T1_Release_Table( &loader->subrs ); |
---|
2026 | |
---|
2027 | /* finalize parser */ |
---|
2028 | T1_Finalize_Parser( parser ); |
---|
2029 | } |
---|
2030 | |
---|
2031 | |
---|
2032 | FT_LOCAL_DEF( FT_Error ) |
---|
2033 | T1_Open_Face( T1_Face face ) |
---|
2034 | { |
---|
2035 | T1_LoaderRec loader; |
---|
2036 | T1_Parser parser; |
---|
2037 | T1_Font type1 = &face->type1; |
---|
2038 | PS_Private priv = &type1->private_dict; |
---|
2039 | FT_Error error; |
---|
2040 | |
---|
2041 | PSAux_Service psaux = (PSAux_Service)face->psaux; |
---|
2042 | |
---|
2043 | |
---|
2044 | t1_init_loader( &loader, face ); |
---|
2045 | |
---|
2046 | /* default values */ |
---|
2047 | face->ndv_idx = -1; |
---|
2048 | face->cdv_idx = -1; |
---|
2049 | face->len_buildchar = 0; |
---|
2050 | |
---|
2051 | priv->blue_shift = 7; |
---|
2052 | priv->blue_fuzz = 1; |
---|
2053 | priv->lenIV = 4; |
---|
2054 | priv->expansion_factor = (FT_Fixed)( 0.06 * 0x10000L ); |
---|
2055 | priv->blue_scale = (FT_Fixed)( 0.039625 * 0x10000L * 1000 ); |
---|
2056 | |
---|
2057 | parser = &loader.parser; |
---|
2058 | error = T1_New_Parser( parser, |
---|
2059 | face->root.stream, |
---|
2060 | face->root.memory, |
---|
2061 | psaux ); |
---|
2062 | if ( error ) |
---|
2063 | goto Exit; |
---|
2064 | |
---|
2065 | error = parse_dict( face, &loader, |
---|
2066 | parser->base_dict, parser->base_len ); |
---|
2067 | if ( error ) |
---|
2068 | goto Exit; |
---|
2069 | |
---|
2070 | error = T1_Get_Private_Dict( parser, psaux ); |
---|
2071 | if ( error ) |
---|
2072 | goto Exit; |
---|
2073 | |
---|
2074 | error = parse_dict( face, &loader, |
---|
2075 | parser->private_dict, parser->private_len ); |
---|
2076 | if ( error ) |
---|
2077 | goto Exit; |
---|
2078 | |
---|
2079 | /* ensure even-ness of `num_blue_values' */ |
---|
2080 | priv->num_blue_values &= ~1; |
---|
2081 | |
---|
2082 | #ifndef T1_CONFIG_OPTION_NO_MM_SUPPORT |
---|
2083 | |
---|
2084 | if ( face->blend && |
---|
2085 | face->blend->num_default_design_vector != 0 && |
---|
2086 | face->blend->num_default_design_vector != face->blend->num_axis ) |
---|
2087 | { |
---|
2088 | /* we don't use it currently so just warn, reset, and ignore */ |
---|
2089 | FT_ERROR(( "T1_Open_Face(): /DesignVector contains %u entries " |
---|
2090 | "while there are %u axes.\n", |
---|
2091 | face->blend->num_default_design_vector, |
---|
2092 | face->blend->num_axis )); |
---|
2093 | |
---|
2094 | face->blend->num_default_design_vector = 0; |
---|
2095 | } |
---|
2096 | |
---|
2097 | /* the following can happen for MM instances; we then treat the */ |
---|
2098 | /* font as a normal PS font */ |
---|
2099 | if ( face->blend && |
---|
2100 | ( !face->blend->num_designs || !face->blend->num_axis ) ) |
---|
2101 | T1_Done_Blend( face ); |
---|
2102 | |
---|
2103 | /* another safety check */ |
---|
2104 | if ( face->blend ) |
---|
2105 | { |
---|
2106 | FT_UInt i; |
---|
2107 | |
---|
2108 | |
---|
2109 | for ( i = 0; i < face->blend->num_axis; i++ ) |
---|
2110 | if ( !face->blend->design_map[i].num_points ) |
---|
2111 | { |
---|
2112 | T1_Done_Blend( face ); |
---|
2113 | break; |
---|
2114 | } |
---|
2115 | } |
---|
2116 | |
---|
2117 | if ( face->blend ) |
---|
2118 | { |
---|
2119 | if ( face->len_buildchar > 0 ) |
---|
2120 | { |
---|
2121 | FT_Memory memory = face->root.memory; |
---|
2122 | |
---|
2123 | |
---|
2124 | if ( FT_NEW_ARRAY( face->buildchar, face->len_buildchar ) ) |
---|
2125 | { |
---|
2126 | FT_ERROR(( "T1_Open_Face: cannot allocate BuildCharArray\n" )); |
---|
2127 | face->len_buildchar = 0; |
---|
2128 | goto Exit; |
---|
2129 | } |
---|
2130 | } |
---|
2131 | } |
---|
2132 | |
---|
2133 | #endif /* T1_CONFIG_OPTION_NO_MM_SUPPORT */ |
---|
2134 | |
---|
2135 | /* now, propagate the subrs, charstrings, and glyphnames tables */ |
---|
2136 | /* to the Type1 data */ |
---|
2137 | type1->num_glyphs = loader.num_glyphs; |
---|
2138 | |
---|
2139 | if ( loader.subrs.init ) |
---|
2140 | { |
---|
2141 | loader.subrs.init = 0; |
---|
2142 | type1->num_subrs = loader.num_subrs; |
---|
2143 | type1->subrs_block = loader.subrs.block; |
---|
2144 | type1->subrs = loader.subrs.elements; |
---|
2145 | type1->subrs_len = loader.subrs.lengths; |
---|
2146 | } |
---|
2147 | |
---|
2148 | #ifdef FT_CONFIG_OPTION_INCREMENTAL |
---|
2149 | if ( !face->root.internal->incremental_interface ) |
---|
2150 | #endif |
---|
2151 | if ( !loader.charstrings.init ) |
---|
2152 | { |
---|
2153 | FT_ERROR(( "T1_Open_Face: no `/CharStrings' array in face!\n" )); |
---|
2154 | error = T1_Err_Invalid_File_Format; |
---|
2155 | } |
---|
2156 | |
---|
2157 | loader.charstrings.init = 0; |
---|
2158 | type1->charstrings_block = loader.charstrings.block; |
---|
2159 | type1->charstrings = loader.charstrings.elements; |
---|
2160 | type1->charstrings_len = loader.charstrings.lengths; |
---|
2161 | |
---|
2162 | /* we copy the glyph names `block' and `elements' fields; */ |
---|
2163 | /* the `lengths' field must be released later */ |
---|
2164 | type1->glyph_names_block = loader.glyph_names.block; |
---|
2165 | type1->glyph_names = (FT_String**)loader.glyph_names.elements; |
---|
2166 | loader.glyph_names.block = 0; |
---|
2167 | loader.glyph_names.elements = 0; |
---|
2168 | |
---|
2169 | /* we must now build type1.encoding when we have a custom array */ |
---|
2170 | if ( type1->encoding_type == T1_ENCODING_TYPE_ARRAY ) |
---|
2171 | { |
---|
2172 | FT_Int charcode, idx, min_char, max_char; |
---|
2173 | FT_Byte* char_name; |
---|
2174 | FT_Byte* glyph_name; |
---|
2175 | |
---|
2176 | |
---|
2177 | /* OK, we do the following: for each element in the encoding */ |
---|
2178 | /* table, look up the index of the glyph having the same name */ |
---|
2179 | /* the index is then stored in type1.encoding.char_index, and */ |
---|
2180 | /* a the name to type1.encoding.char_name */ |
---|
2181 | |
---|
2182 | min_char = +32000; |
---|
2183 | max_char = -32000; |
---|
2184 | |
---|
2185 | charcode = 0; |
---|
2186 | for ( ; charcode < loader.encoding_table.max_elems; charcode++ ) |
---|
2187 | { |
---|
2188 | type1->encoding.char_index[charcode] = 0; |
---|
2189 | type1->encoding.char_name [charcode] = (char *)".notdef"; |
---|
2190 | |
---|
2191 | char_name = loader.encoding_table.elements[charcode]; |
---|
2192 | if ( char_name ) |
---|
2193 | for ( idx = 0; idx < type1->num_glyphs; idx++ ) |
---|
2194 | { |
---|
2195 | glyph_name = (FT_Byte*)type1->glyph_names[idx]; |
---|
2196 | if ( ft_strcmp( (const char*)char_name, |
---|
2197 | (const char*)glyph_name ) == 0 ) |
---|
2198 | { |
---|
2199 | type1->encoding.char_index[charcode] = (FT_UShort)idx; |
---|
2200 | type1->encoding.char_name [charcode] = (char*)glyph_name; |
---|
2201 | |
---|
2202 | /* Change min/max encoded char only if glyph name is */ |
---|
2203 | /* not /.notdef */ |
---|
2204 | if ( ft_strcmp( (const char*)".notdef", |
---|
2205 | (const char*)glyph_name ) != 0 ) |
---|
2206 | { |
---|
2207 | if ( charcode < min_char ) |
---|
2208 | min_char = charcode; |
---|
2209 | if ( charcode > max_char ) |
---|
2210 | max_char = charcode; |
---|
2211 | } |
---|
2212 | break; |
---|
2213 | } |
---|
2214 | } |
---|
2215 | } |
---|
2216 | |
---|
2217 | /* |
---|
2218 | * Yes, this happens: Certain PDF-embedded fonts have only a |
---|
2219 | * `.notdef' glyph defined! |
---|
2220 | */ |
---|
2221 | |
---|
2222 | if ( min_char > max_char ) |
---|
2223 | { |
---|
2224 | min_char = 0; |
---|
2225 | max_char = loader.encoding_table.max_elems; |
---|
2226 | } |
---|
2227 | |
---|
2228 | type1->encoding.code_first = min_char; |
---|
2229 | type1->encoding.code_last = max_char; |
---|
2230 | type1->encoding.num_chars = loader.num_chars; |
---|
2231 | } |
---|
2232 | |
---|
2233 | Exit: |
---|
2234 | t1_done_loader( &loader ); |
---|
2235 | return error; |
---|
2236 | } |
---|
2237 | |
---|
2238 | |
---|
2239 | /* END */ |
---|