ReactOS 0.4.16-dev-2380-gf63df20
cidparse.c File Reference
Include dependency graph for cidparse.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FT_COMPONENT   cidparse
 
#define STARTDATA   "StartData"
 
#define STARTDATA_LEN   ( sizeof ( STARTDATA ) - 1 )
 
#define SFNTS   "/sfnts"
 
#define SFNTS_LEN   ( sizeof ( SFNTS ) - 1 )
 

Functions

 cid_parser_new (CID_Parser *parser, FT_Stream stream, FT_Memory memory, PSAux_Service psaux)
 
 cid_parser_done (CID_Parser *parser)
 

Macro Definition Documentation

◆ FT_COMPONENT

#define FT_COMPONENT   cidparse

Definition at line 35 of file cidparse.c.

◆ SFNTS

#define SFNTS   "/sfnts"

Definition at line 51 of file cidparse.c.

◆ SFNTS_LEN

#define SFNTS_LEN   ( sizeof ( SFNTS ) - 1 )

Definition at line 52 of file cidparse.c.

◆ STARTDATA

#define STARTDATA   "StartData"

Definition at line 49 of file cidparse.c.

◆ STARTDATA_LEN

#define STARTDATA_LEN   ( sizeof ( STARTDATA ) - 1 )

Definition at line 50 of file cidparse.c.

Function Documentation

◆ cid_parser_done()

cid_parser_done ( CID_Parser parser)

Definition at line 262 of file cidparse.c.

263 {
264 /* always free the private dictionary */
265 if ( parser->postscript )
266 {
267 FT_Stream stream = parser->stream;
268
269
270 FT_FRAME_RELEASE( parser->postscript );
271 }
272 parser->root.funcs.done( &parser->root );
273 }
#define FT_FRAME_RELEASE(bytes)
Definition: ftstream.h:562
Definition: import.c:81
Definition: parse.h:23

Referenced by cid_done_loader().

◆ cid_parser_new()

cid_parser_new ( CID_Parser parser,
FT_Stream  stream,
FT_Memory  memory,
PSAux_Service  psaux 
)

Definition at line 56 of file cidparse.c.

60 {
62 FT_ULong base_offset, offset, ps_len;
63 FT_Byte *cur, *limit;
64 FT_Byte *arg1, *arg2;
65
66
67 FT_ZERO( parser );
68 psaux->ps_parser_funcs->init( &parser->root, 0, 0, memory );
69
70 parser->stream = stream;
71
72 base_offset = FT_STREAM_POS();
73
74 /* first of all, check the font format in the header */
75 if ( FT_FRAME_ENTER( 31 ) )
76 goto Exit;
77
78 if ( ft_strncmp( (char *)stream->cursor,
79 "%!PS-Adobe-3.0 Resource-CIDFont", 31 ) )
80 {
81 FT_TRACE2(( " not a CID-keyed font\n" ));
82 error = FT_THROW( Unknown_File_Format );
83 }
84
86 if ( error )
87 goto Exit;
88
89 Again:
90 /* now, read the rest of the file until we find */
91 /* `StartData' or `/sfnts' */
92 {
93 /*
94 * The algorithm is as follows (omitting the case with less than 256
95 * bytes to fill for simplicity).
96 *
97 * 1. Fill the buffer with 256 + STARTDATA_LEN bytes.
98 *
99 * 2. Search for the STARTDATA and SFNTS strings at positions
100 * buffer[0], buffer[1], ...,
101 * buffer[255 + STARTDATA_LEN - SFNTS_LEN].
102 *
103 * 3. Move the last STARTDATA_LEN bytes to buffer[0].
104 *
105 * 4. Fill the buffer with 256 bytes, starting at STARTDATA_LEN.
106 *
107 * 5. Repeat with step 2.
108 *
109 */
110 FT_Byte buffer[256 + STARTDATA_LEN + 1];
111
112 /* values for the first loop */
113 FT_ULong read_len = 256 + STARTDATA_LEN;
114 FT_ULong read_offset = 0;
115 FT_Byte* p = buffer;
116
117
118 for ( offset = FT_STREAM_POS(); ; offset += 256 )
119 {
120 FT_ULong stream_len;
121
122
123 stream_len = stream->size - FT_STREAM_POS();
124
125 read_len = FT_MIN( read_len, stream_len );
126 if ( FT_STREAM_READ( p, read_len ) )
127 goto Exit;
128
129 /* ensure that we do not compare with data beyond the buffer */
130 p[read_len] = '\0';
131
132 limit = p + read_len - SFNTS_LEN;
133
134 for ( p = buffer; p < limit; p++ )
135 {
136 if ( p[0] == 'S' &&
137 ft_strncmp( (char*)p, STARTDATA, STARTDATA_LEN ) == 0 )
138 {
139 /* save offset of binary data after `StartData' */
140 offset += (FT_ULong)( p - buffer ) + STARTDATA_LEN + 1;
141 goto Found;
142 }
143 else if ( p[1] == 's' &&
144 ft_strncmp( (char*)p, SFNTS, SFNTS_LEN ) == 0 )
145 {
146 offset += (FT_ULong)( p - buffer ) + SFNTS_LEN + 1;
147 goto Found;
148 }
149 }
150
151 if ( read_offset + read_len < STARTDATA_LEN )
152 {
153 FT_TRACE2(( "cid_parser_new: no `StartData' keyword found\n" ));
154 error = FT_THROW( Invalid_File_Format );
155 goto Exit;
156 }
157
159 buffer + read_offset + read_len - STARTDATA_LEN,
161
162 /* values for the next loop */
163 read_len = 256;
164 read_offset = STARTDATA_LEN;
165 p = buffer + read_offset;
166 }
167 }
168
169 Found:
170 /* We have found the start of the binary data or the `/sfnts' token. */
171 /* Now rewind and extract the frame corresponding to this PostScript */
172 /* section. */
173
174 ps_len = offset - base_offset;
175 if ( FT_STREAM_SEEK( base_offset ) ||
176 FT_FRAME_EXTRACT( ps_len, parser->postscript ) )
177 goto Exit;
178
179 parser->data_offset = offset;
180 parser->postscript_len = ps_len;
181 parser->root.base = parser->postscript;
182 parser->root.cursor = parser->postscript;
183 parser->root.limit = parser->root.cursor + ps_len;
184 parser->num_dict = -1;
185
186 /* Finally, we check whether `StartData' or `/sfnts' was real -- */
187 /* it could be in a comment or string. We also get the arguments */
188 /* of `StartData' to find out whether the data is represented in */
189 /* binary or hex format. */
190
191 arg1 = parser->root.cursor;
194 arg2 = parser->root.cursor;
197
198 limit = parser->root.limit;
199 cur = parser->root.cursor;
200
201 while ( cur <= limit - SFNTS_LEN )
202 {
203 if ( parser->root.error )
204 {
205 error = parser->root.error;
206 goto Exit;
207 }
208
209 if ( cur[0] == 'S' &&
210 cur <= limit - STARTDATA_LEN &&
211 ft_strncmp( (char*)cur, STARTDATA, STARTDATA_LEN ) == 0 )
212 {
213 if ( ft_strncmp( (char*)arg1, "(Hex)", 5 ) == 0 )
214 {
215 FT_Long tmp = ft_strtol( (const char *)arg2, NULL, 10 );
216
217
218 if ( tmp < 0 )
219 {
220 FT_ERROR(( "cid_parser_new: invalid length of hex data\n" ));
221 error = FT_THROW( Invalid_File_Format );
222 }
223 else
224 parser->binary_length = (FT_ULong)tmp;
225 }
226
227 goto Exit;
228 }
229 else if ( cur[1] == 's' &&
230 ft_strncmp( (char*)cur, SFNTS, SFNTS_LEN ) == 0 )
231 {
232 FT_TRACE2(( "cid_parser_new: cannot handle Type 11 fonts\n" ));
233 error = FT_THROW( Unknown_File_Format );
234 goto Exit;
235 }
236
239 arg1 = arg2;
240 arg2 = cur;
241 cur = parser->root.cursor;
242 }
243
244 /* we haven't found the correct `StartData'; go back and continue */
245 /* searching */
246 FT_FRAME_RELEASE( parser->postscript );
247 if ( !FT_STREAM_SEEK( offset ) )
248 goto Again;
249
250 Exit:
251 return error;
252 }
return Found
Definition: dirsup.c:1270
#define STARTDATA_LEN
Definition: cidparse.c:50
#define STARTDATA
Definition: cidparse.c:49
#define SFNTS
Definition: cidparse.c:51
#define SFNTS_LEN
Definition: cidparse.c:52
#define cid_parser_skip_PS_token(p)
Definition: cidparse.h:104
#define cid_parser_skip_spaces(p)
Definition: cidparse.h:102
#define NULL
Definition: types.h:112
#define FT_ERROR(varformat)
Definition: ftdebug.h:211
#define FT_THROW(e)
Definition: ftdebug.h:243
#define FT_TRACE2(varformat)
Definition: ftdebug.h:189
#define FT_ZERO(p)
Definition: ftmemory.h:246
#define FT_MEM_MOVE(dest, source, count)
Definition: ftmemory.h:240
#define FT_MIN(a, b)
Definition: ftobjs.h:70
#define ft_strncmp
Definition: ftstdlib.h:89
#define ft_strtol
Definition: ftstdlib.h:145
#define FT_FRAME_ENTER(size)
Definition: ftstream.h:548
#define FT_STREAM_SEEK(position)
Definition: ftstream.h:525
#define FT_STREAM_POS()
Definition: ftstream.h:522
#define FT_FRAME_EXIT()
Definition: ftstream.h:553
#define FT_FRAME_EXTRACT(size, bytes)
Definition: ftstream.h:556
#define FT_STREAM_READ(buffer, count)
Definition: ftstream.h:533
unsigned long FT_ULong
Definition: fttypes.h:253
unsigned char FT_Byte
Definition: fttypes.h:154
int FT_Error
Definition: fttypes.h:299
signed long FT_Long
Definition: fttypes.h:242
FxCollectionEntry * cur
GLuint buffer
Definition: glext.h:5915
GLintptr offset
Definition: glext.h:5920
GLuint GLuint GLuint GLuint arg1
Definition: glext.h:9513
GLuint GLuint GLuint GLuint GLuint GLuint GLuint arg2
Definition: glext.h:9514
GLint limit
Definition: glext.h:10326
GLfloat GLfloat p
Definition: glext.h:8902
#define error(str)
Definition: mkdosfs.c:1605
static char memory[1024 *256]
Definition: process.c:122
static void Exit(void)
Definition: sock.c:1330
const PS_Parser_FuncsRec * ps_parser_funcs
Definition: psaux.h:1348
void(* init)(PS_Parser parser, FT_Byte *base, FT_Byte *limit, FT_Memory memory)
Definition: psaux.h:375
unsigned int error
Definition: inffile.c:97
unsigned int size
Definition: parse.h:27

Referenced by cid_face_open().