1 /***************************************************************************/
5 /* CID-keyed Type1 parser (body). */
7 /* Copyright 1996-2001 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
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. */
16 /***************************************************************************/
20 #include FT_INTERNAL_DEBUG_H
21 #include FT_INTERNAL_CALC_H
22 #include FT_INTERNAL_OBJECTS_H
23 #include FT_INTERNAL_STREAM_H
29 #include <string.h> /* for strncmp() */
32 /*************************************************************************/
34 /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
35 /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
36 /* messages during execution. */
39 #define FT_COMPONENT trace_cidparse
42 /*************************************************************************/
43 /*************************************************************************/
44 /*************************************************************************/
46 /***** INPUT STREAM PARSER *****/
48 /*************************************************************************/
49 /*************************************************************************/
50 /*************************************************************************/
54 CID_New_Parser( CID_Parser* parser,
57 PSAux_Interface* psaux )
60 FT_ULong base_offset, offset, ps_len;
61 FT_Byte buffer[256 + 10];
65 MEM_Set( parser, 0, sizeof ( *parser ) );
66 psaux->t1_parser_funcs->init( &parser->root, 0, 0, memory );
68 parser->stream = stream;
70 base_offset = FILE_Pos();
72 /* first of all, check the font format in the header */
73 if ( ACCESS_Frame( 31 ) )
76 if ( strncmp( (char *)stream->cursor,
77 "%!PS-Adobe-3.0 Resource-CIDFont", 31 ) )
79 FT_TRACE2(( "[not a valid CID-keyed font]\n" ));
80 error = CID_Err_Unknown_File_Format;
87 /* now, read the rest of the file, until we find a `StartData' */
91 FT_Byte *p, *limit = buffer + 256;
92 FT_ULong top_position;
95 /* fill input buffer */
98 MEM_Move( buffer, limit, buff_len );
100 p = buffer + buff_len;
102 if ( FILE_Read( p, 256 + 10 - buff_len ) )
105 top_position = FILE_Pos() - buff_len;
108 /* look for `StartData' */
109 for ( p = buffer; p < limit; p++ )
111 if ( p[0] == 'S' && strncmp( (char*)p, "StartData", 9 ) == 0 )
113 /* save offset of binary data after `StartData' */
114 offset = (FT_ULong)( top_position - ( limit - p ) + 10 );
121 /* we have found the start of the binary data. We will now */
122 /* rewind and extract the frame of corresponding to the Postscript */
125 ps_len = offset - base_offset;
126 if ( FILE_Seek( base_offset ) ||
127 EXTRACT_Frame( ps_len, parser->postscript ) )
130 parser->data_offset = offset;
131 parser->postscript_len = ps_len;
132 parser->root.base = parser->postscript;
133 parser->root.cursor = parser->postscript;
134 parser->root.limit = parser->root.cursor + ps_len;
135 parser->num_dict = -1;
143 CID_Done_Parser( CID_Parser* parser )
145 /* always free the private dictionary */
146 if ( parser->postscript )
148 FT_Stream stream = parser->stream;
151 RELEASE_Frame( parser->postscript );
153 parser->root.funcs.done( &parser->root );