ReactOS 0.4.16-dev-2357-g35d0dfe
t1parse.c File Reference
Include dependency graph for t1parse.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FT_COMPONENT   t1parse
 

Functions

static FT_Error read_pfb_tag (FT_Stream stream, FT_UShort *atag, FT_ULong *asize)
 
static FT_Error check_type1_format (FT_Stream stream, const char *header_string, size_t header_length)
 
 T1_New_Parser (T1_Parser parser, FT_Stream stream, FT_Memory memory, PSAux_Service psaux)
 
 T1_Finalize_Parser (T1_Parser parser)
 
 T1_Get_Private_Dict (T1_Parser parser, PSAux_Service psaux)
 

Macro Definition Documentation

◆ FT_COMPONENT

#define FT_COMPONENT   t1parse

Definition at line 52 of file t1parse.c.

Function Documentation

◆ check_type1_format()

static FT_Error check_type1_format ( FT_Stream  stream,
const char header_string,
size_t  header_length 
)
static

Definition at line 97 of file t1parse.c.

100 {
104
105
106 if ( FT_STREAM_SEEK( 0 ) )
107 goto Exit;
108
110 if ( error )
111 goto Exit;
112
113 /* We assume that the first segment in a PFB is always encoded as */
114 /* text. This might be wrong (and the specification doesn't insist */
115 /* on that), but we have never seen a counterexample. */
116 if ( tag != 0x8001U && FT_STREAM_SEEK( 0 ) )
117 goto Exit;
118
119 if ( !FT_FRAME_ENTER( header_length ) )
120 {
122
123 if ( ft_memcmp( stream->cursor, header_string, header_length ) != 0 )
124 error = FT_THROW( Unknown_File_Format );
125
127 }
128
129 Exit:
130 return error;
131 }
return FT_Err_Ok
Definition: ftbbox.c:526
#define FT_THROW(e)
Definition: ftdebug.h:243
#define ft_memcmp
Definition: ftstdlib.h:81
#define FT_FRAME_ENTER(size)
Definition: ftstream.h:548
#define FT_STREAM_SEEK(position)
Definition: ftstream.h:525
#define FT_FRAME_EXIT()
Definition: ftstream.h:553
unsigned long FT_ULong
Definition: fttypes.h:253
int FT_Error
Definition: fttypes.h:299
unsigned short FT_UShort
Definition: fttypes.h:209
#define error(str)
Definition: mkdosfs.c:1605
static void Exit(void)
Definition: sock.c:1330
Definition: parse.h:23
Definition: ecma_167.h:138
static FT_Error read_pfb_tag(FT_Stream stream, FT_UShort *atag, FT_ULong *asize)
Definition: t1parse.c:69

Referenced by T1_New_Parser().

◆ read_pfb_tag()

static FT_Error read_pfb_tag ( FT_Stream  stream,
FT_UShort atag,
FT_ULong asize 
)
static

Definition at line 69 of file t1parse.c.

72 {
76
77
78 *atag = 0;
79 *asize = 0;
80
81 if ( !FT_READ_USHORT( tag ) )
82 {
83 if ( tag == 0x8001U || tag == 0x8002U )
84 {
85 if ( !FT_READ_ULONG_LE( size ) )
86 *asize = size;
87 }
88
89 *atag = tag;
90 }
91
92 return error;
93 }
#define FT_READ_USHORT(var)
Definition: ftstream.h:339
#define FT_READ_ULONG_LE(var)
Definition: ftstream.h:348
GLsizeiptr size
Definition: glext.h:5919

Referenced by check_type1_format(), T1_Get_Private_Dict(), and T1_New_Parser().

◆ T1_Finalize_Parser()

T1_Finalize_Parser ( T1_Parser  parser)

Definition at line 243 of file t1parse.c.

244 {
245 FT_Memory memory = parser->root.memory;
246
247
248 /* always free the private dictionary */
249 FT_FREE( parser->private_dict );
250
251 /* free the base dictionary only when we have a disk stream */
252 if ( !parser->in_memory )
253 FT_FREE( parser->base_dict );
254
255 parser->root.funcs.done( &parser->root );
256 }
#define FT_FREE(ptr)
Definition: ftmemory.h:337
typedefFT_BEGIN_HEADER struct FT_MemoryRec_ * FT_Memory
Definition: ftsystem.h:64
static char memory[1024 *256]
Definition: process.c:122
Definition: import.c:81

Referenced by t1_done_loader().

◆ T1_Get_Private_Dict()

T1_Get_Private_Dict ( T1_Parser  parser,
PSAux_Service  psaux 
)

Definition at line 260 of file t1parse.c.

262 {
263 FT_Stream stream = parser->stream;
264 FT_Memory memory = parser->root.memory;
267
268
269 if ( parser->in_pfb )
270 {
271 /* in the case of the PFB format, the private dictionary can be */
272 /* made of several segments. We thus first read the number of */
273 /* segments to compute the total size of the private dictionary */
274 /* then re-read them into memory. */
275 FT_ULong start_pos = FT_STREAM_POS();
277
278
279 parser->private_len = 0;
280 for (;;)
281 {
283 if ( error )
284 goto Fail;
285
286 if ( tag != 0x8002U )
287 break;
288
289 parser->private_len += size;
290
291 if ( FT_STREAM_SKIP( size ) )
292 goto Fail;
293 }
294
295 /* Check that we have a private dictionary there */
296 /* and allocate private dictionary buffer */
297 if ( parser->private_len == 0 )
298 {
299 FT_ERROR(( "T1_Get_Private_Dict:"
300 " invalid private dictionary section\n" ));
301 error = FT_THROW( Invalid_File_Format );
302 goto Fail;
303 }
304
305 if ( FT_STREAM_SEEK( start_pos ) ||
306 FT_ALLOC( parser->private_dict, parser->private_len ) )
307 goto Fail;
308
309 parser->private_len = 0;
310 for (;;)
311 {
313 if ( error || tag != 0x8002U )
314 {
316 break;
317 }
318
319 if ( FT_STREAM_READ( parser->private_dict + parser->private_len,
320 size ) )
321 goto Fail;
322
323 parser->private_len += size;
324 }
325 }
326 else
327 {
328 /* We have already `loaded' the whole PFA font file into memory; */
329 /* if this is a memory resource, allocate a new block to hold */
330 /* the private dict. Otherwise, simply overwrite into the base */
331 /* dictionary block in the heap. */
332
333 /* first of all, look at the `eexec' keyword */
334 FT_Byte* cur = parser->base_dict;
335 FT_Byte* limit = cur + parser->base_len;
336 FT_Pointer pos_lf;
337 FT_Bool test_cr;
338
339
340 Again:
341 for (;;)
342 {
343 if ( cur[0] == 'e' &&
344 cur + 9 < limit ) /* 9 = 5 letters for `eexec' + */
345 /* whitespace + 4 chars */
346 {
347 if ( cur[1] == 'e' &&
348 cur[2] == 'x' &&
349 cur[3] == 'e' &&
350 cur[4] == 'c' )
351 break;
352 }
353 cur++;
354 if ( cur >= limit )
355 {
356 FT_ERROR(( "T1_Get_Private_Dict:"
357 " could not find `eexec' keyword\n" ));
358 error = FT_THROW( Invalid_File_Format );
359 goto Exit;
360 }
361 }
362
363 /* check whether `eexec' was real -- it could be in a comment */
364 /* or string (as e.g. in u003043t.gsf from ghostscript) */
365
366 parser->root.cursor = parser->base_dict;
367 /* set limit to `eexec' + whitespace + 4 characters */
368 parser->root.limit = cur + 10;
369
370 cur = parser->root.cursor;
371 limit = parser->root.limit;
372
373 while ( cur < limit )
374 {
375 if ( cur[0] == 'e' &&
376 cur + 5 < limit )
377 {
378 if ( cur[1] == 'e' &&
379 cur[2] == 'x' &&
380 cur[3] == 'e' &&
381 cur[4] == 'c' )
382 goto Found;
383 }
384
386 if ( parser->root.error )
387 break;
389 cur = parser->root.cursor;
390 }
391
392 /* we haven't found the correct `eexec'; go back and continue */
393 /* searching */
394
395 cur = limit;
396 limit = parser->base_dict + parser->base_len;
397
398 if ( cur >= limit )
399 {
400 FT_ERROR(( "T1_Get_Private_Dict:"
401 " premature end in private dictionary\n" ));
402 error = FT_THROW( Invalid_File_Format );
403 goto Exit;
404 }
405
406 goto Again;
407
408 /* now determine where to write the _encrypted_ binary private */
409 /* dictionary. We overwrite the base dictionary for disk-based */
410 /* resources and allocate a new block otherwise */
411
412 Found:
413 parser->root.limit = parser->base_dict + parser->base_len;
414
416 cur = parser->root.cursor;
417 limit = parser->root.limit;
418
419 /* According to the Type 1 spec, the first cipher byte must not be */
420 /* an ASCII whitespace character code (blank, tab, carriage return */
421 /* or line feed). We have seen Type 1 fonts with two line feed */
422 /* characters... So skip now all whitespace character codes. */
423 /* */
424 /* On the other hand, Adobe's Type 1 parser handles fonts just */
425 /* fine that are violating this limitation, so we add a heuristic */
426 /* test to stop at \r only if it is not used for EOL. */
427
428 pos_lf = ft_memchr( cur, '\n', (size_t)( limit - cur ) );
429 test_cr = FT_BOOL( !pos_lf ||
430 pos_lf > ft_memchr( cur,
431 '\r',
432 (size_t)( limit - cur ) ) );
433
434 while ( cur < limit &&
435 ( *cur == ' ' ||
436 *cur == '\t' ||
437 (test_cr && *cur == '\r' ) ||
438 *cur == '\n' ) )
439 cur++;
440 if ( cur >= limit )
441 {
442 FT_ERROR(( "T1_Get_Private_Dict:"
443 " `eexec' not properly terminated\n" ));
444 error = FT_THROW( Invalid_File_Format );
445 goto Exit;
446 }
447
448 size = parser->base_len - (FT_ULong)( cur - parser->base_dict );
449
450 if ( parser->in_memory )
451 {
452 /* note that we allocate one more byte to put a terminating `0' */
453 if ( FT_ALLOC( parser->private_dict, size + 1 ) )
454 goto Fail;
455 parser->private_len = size;
456 }
457 else
458 {
459 parser->single_block = 1;
460 parser->private_dict = parser->base_dict;
461 parser->private_len = size;
462 parser->base_dict = NULL;
463 parser->base_len = 0;
464 }
465
466 /* now determine whether the private dictionary is encoded in binary */
467 /* or hexadecimal ASCII format -- decode it accordingly */
468
469 /* we need to access the next 4 bytes (after the final whitespace */
470 /* following the `eexec' keyword); if they all are hexadecimal */
471 /* digits, then we have a case of ASCII storage */
472
473 if ( cur + 3 < limit &&
474 ft_isxdigit( cur[0] ) && ft_isxdigit( cur[1] ) &&
475 ft_isxdigit( cur[2] ) && ft_isxdigit( cur[3] ) )
476 {
477 /* ASCII hexadecimal encoding */
479
480
481 parser->root.cursor = cur;
482 (void)psaux->ps_parser_funcs->to_bytes( &parser->root,
483 parser->private_dict,
484 parser->private_len,
485 &len,
486 0 );
487 parser->private_len = len;
488
489 /* put a safeguard */
490 parser->private_dict[len] = '\0';
491 }
492 else
493 /* binary encoding -- copy the private dict */
494 FT_MEM_MOVE( parser->private_dict, cur, size );
495 }
496
497 /* we now decrypt the encoded binary private dictionary */
498 psaux->t1_decrypt( parser->private_dict, parser->private_len, 55665U );
499
500 if ( parser->private_len < 4 )
501 {
502 FT_ERROR(( "T1_Get_Private_Dict:"
503 " invalid private dictionary section\n" ));
504 error = FT_THROW( Invalid_File_Format );
505 goto Fail;
506 }
507
508 /* replace the four random bytes at the beginning with whitespace */
509 parser->private_dict[0] = ' ';
510 parser->private_dict[1] = ' ';
511 parser->private_dict[2] = ' ';
512 parser->private_dict[3] = ' ';
513
514 parser->root.base = parser->private_dict;
515 parser->root.cursor = parser->private_dict;
516 parser->root.limit = parser->root.cursor + parser->private_len;
517
518 Fail:
519 Exit:
520 return error;
521 }
return Found
Definition: dirsup.c:1270
#define NULL
Definition: types.h:112
int Fail
Definition: ehthrow.cxx:24
#define FT_ERROR(varformat)
Definition: ftdebug.h:211
#define FT_ALLOC(ptr, size)
Definition: ftmemory.h:311
#define FT_MEM_MOVE(dest, source, count)
Definition: ftmemory.h:240
#define ft_isxdigit(x)
Definition: ftobjs.h:118
#define ft_memchr
Definition: ftstdlib.h:80
#define FT_STREAM_POS()
Definition: ftstream.h:522
#define FT_STREAM_SKIP(distance)
Definition: ftstream.h:529
#define FT_STREAM_READ(buffer, count)
Definition: ftstream.h:533
FT_BEGIN_HEADER typedef unsigned char FT_Bool
Definition: fttypes.h:108
unsigned char FT_Byte
Definition: fttypes.h:154
#define FT_BOOL(x)
Definition: fttypes.h:591
FxCollectionEntry * cur
GLint limit
Definition: glext.h:10326
GLenum GLsizei len
Definition: glext.h:6722
void(* t1_decrypt)(FT_Byte *buffer, FT_Offset length, FT_UShort seed)
Definition: psaux.h:1353
const PS_Parser_FuncsRec * ps_parser_funcs
Definition: psaux.h:1348
FT_Error(* to_bytes)(PS_Parser parser, FT_Byte *bytes, FT_Offset max_bytes, FT_ULong *pnum_bytes, FT_Bool delimiters)
Definition: psaux.h:395
unsigned int error
Definition: inffile.c:97
#define T1_Skip_Spaces(p)
Definition: t1parse.h:96
#define T1_Skip_PS_Token(p)
Definition: t1parse.h:97

Referenced by T1_Open_Face().

◆ T1_New_Parser()

T1_New_Parser ( T1_Parser  parser,
FT_Stream  stream,
FT_Memory  memory,
PSAux_Service  psaux 
)

Definition at line 135 of file t1parse.c.

139 {
143
144
145 psaux->ps_parser_funcs->init( &parser->root, NULL, NULL, memory );
146
147 parser->stream = stream;
148 parser->base_len = 0;
149 parser->base_dict = NULL;
150 parser->private_len = 0;
151 parser->private_dict = NULL;
152 parser->in_pfb = 0;
153 parser->in_memory = 0;
154 parser->single_block = 0;
155
156 /* check the header format */
157 error = check_type1_format( stream, "%!PS-AdobeFont", 14 );
158 if ( error )
159 {
160 if ( FT_ERR_NEQ( error, Unknown_File_Format ) )
161 goto Exit;
162
163 error = check_type1_format( stream, "%!FontType", 10 );
164 if ( error )
165 {
166 FT_TRACE2(( " not a Type 1 font\n" ));
167 goto Exit;
168 }
169 }
170
171 /*******************************************************************
172 *
173 * Here a short summary of what is going on:
174 *
175 * When creating a new Type 1 parser, we try to locate and load
176 * the base dictionary if this is possible (i.e., for PFB
177 * files). Otherwise, we load the whole font into memory.
178 *
179 * When `loading' the base dictionary, we only setup pointers
180 * in the case of a memory-based stream. Otherwise, we
181 * allocate and load the base dictionary in it.
182 *
183 * parser->in_pfb is set if we are in a binary (`.pfb') font.
184 * parser->in_memory is set if we have a memory stream.
185 */
186
187 /* try to compute the size of the base dictionary; */
188 /* look for a Postscript binary file tag, i.e., 0x8001 */
189 if ( FT_STREAM_SEEK( 0L ) )
190 goto Exit;
191
193 if ( error )
194 goto Exit;
195
196 if ( tag != 0x8001U )
197 {
198 /* assume that this is a PFA file for now; an error will */
199 /* be produced later when more things are checked */
200 if ( FT_STREAM_SEEK( 0L ) )
201 goto Exit;
202 size = stream->size;
203 }
204 else
205 parser->in_pfb = 1;
206
207 /* now, try to load `size' bytes of the `base' dictionary we */
208 /* found previously */
209
210 /* if it is a memory-based resource, set up pointers */
211 if ( !stream->read )
212 {
213 parser->base_dict = (FT_Byte*)stream->base + stream->pos;
214 parser->base_len = size;
215 parser->in_memory = 1;
216
217 /* check that the `size' field is valid */
218 if ( FT_STREAM_SKIP( size ) )
219 goto Exit;
220 }
221 else
222 {
223 /* read segment in memory -- this is clumsy, but so does the format */
224 if ( FT_ALLOC( parser->base_dict, size ) ||
225 FT_STREAM_READ( parser->base_dict, size ) )
226 goto Exit;
227 parser->base_len = size;
228 }
229
230 parser->root.base = parser->base_dict;
231 parser->root.cursor = parser->base_dict;
232 parser->root.limit = parser->root.cursor + parser->base_len;
233
234 Exit:
235 if ( error && !parser->in_memory )
236 FT_FREE( parser->base_dict );
237
238 return error;
239 }
#define L(x)
Definition: resources.c:13
#define FT_TRACE2(varformat)
Definition: ftdebug.h:189
#define FT_ERR_NEQ(x, e)
Definition: fttypes.h:606
if(dx< 0)
Definition: linetemp.h:194
void(* init)(PS_Parser parser, FT_Byte *base, FT_Byte *limit, FT_Memory memory)
Definition: psaux.h:375
ULARGE_INTEGER pos
Definition: request.c:4380
unsigned int size
Definition: parse.h:27
static FT_Error check_type1_format(FT_Stream stream, const char *header_string, size_t header_length)
Definition: t1parse.c:97

Referenced by T1_Open_Face().