1
/***************************************************************************/
5
/* CID-keyed Type1 parser (body). */
7
/* Copyright 1996-2001, 2002, 2003, 2004 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
30
/*************************************************************************/
32
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
33
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
34
/* messages during execution. */
37
#define FT_COMPONENT trace_cidparse
40
/*************************************************************************/
41
/*************************************************************************/
42
/*************************************************************************/
44
/***** INPUT STREAM PARSER *****/
46
/*************************************************************************/
47
/*************************************************************************/
48
/*************************************************************************/
51
FT_LOCAL_DEF( FT_Error )
52
cid_parser_new( CID_Parser* parser,
58
FT_ULong base_offset, offset, ps_len;
59
FT_Byte buffer[256 + 10];
65
FT_MEM_ZERO( parser, sizeof ( *parser ) );
66
psaux->ps_parser_funcs->init( &parser->root, 0, 0, memory );
68
parser->stream = stream;
70
base_offset = FT_STREAM_POS();
72
/* first of all, check the font format in the header */
73
if ( FT_FRAME_ENTER( 31 ) )
76
if ( ft_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;
88
/* now, read the rest of the file until we find a `StartData' */
93
FT_ULong top_position;
96
/* fill input buffer */
100
FT_MEM_MOVE( buffer, limit, buff_len );
102
p = buffer + buff_len;
104
if ( FT_STREAM_READ( p, 256 + 10 - buff_len ) )
107
top_position = FT_STREAM_POS() - buff_len;
110
/* look for `StartData' */
111
for ( p = buffer; p < limit; p++ )
113
if ( p[0] == 'S' && ft_strncmp( (char*)p, "StartData", 9 ) == 0 )
115
/* save offset of binary data after `StartData' */
116
offset = (FT_ULong)( top_position - ( limit - p ) + 10 );
123
/* we have found the start of the binary data. We will now */
124
/* rewind and extract the frame corresponding to the PostScript */
127
ps_len = offset - base_offset;
128
if ( FT_STREAM_SEEK( base_offset ) ||
129
FT_FRAME_EXTRACT( ps_len, parser->postscript ) )
132
parser->data_offset = offset;
133
parser->postscript_len = ps_len;
134
parser->root.base = parser->postscript;
135
parser->root.cursor = parser->postscript;
136
parser->root.limit = parser->root.cursor + ps_len;
137
parser->num_dict = -1;
139
/* Finally, we check whether `StartData' was real -- it could be */
140
/* in a comment or string. We also get its arguments to find out */
141
/* whether the data is represented in binary or hex format. */
143
arg1 = parser->root.cursor;
144
cid_parser_skip_PS_token( parser );
145
cid_parser_skip_spaces ( parser );
146
arg2 = parser->root.cursor;
147
cid_parser_skip_PS_token( parser );
148
cid_parser_skip_spaces ( parser );
150
limit = parser->root.limit;
151
cur = parser->root.cursor;
153
while ( cur < limit )
155
if ( *cur == 'S' && ft_strncmp( (char*)cur, "StartData", 9 ) == 0 )
157
if ( ft_strncmp( (char*)arg1, "(Hex)", 5 ) == 0 )
158
parser->binary_length = ft_atol( (const char *)arg2 );
160
limit = parser->root.limit;
161
cur = parser->root.cursor;
165
cid_parser_skip_PS_token( parser );
166
cid_parser_skip_spaces ( parser );
169
cur = parser->root.cursor;
172
/* we haven't found the correct `StartData'; go back and continue */
174
FT_FRAME_RELEASE( parser->postscript );
175
if ( !FT_STREAM_SEEK( offset ) )
184
cid_parser_done( CID_Parser* parser )
186
/* always free the private dictionary */
187
if ( parser->postscript )
189
FT_Stream stream = parser->stream;
192
FT_FRAME_RELEASE( parser->postscript );
194
parser->root.funcs.done( &parser->root );