1 /***************************************************************************/
5 /* Experimental Type 1 parser (specification). */
7 /* Copyright 1996-2000 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 /***************************************************************************/
22 #include <freetype/internal/t1types.h>
29 /* simple enumeration type used to identify token types */
30 typedef enum Z1_Token_Type_
43 /* a simple structure used to identify tokens */
44 typedef struct Z1_Token_Rec_
46 FT_Byte* start; /* first character of token in input stream */
47 FT_Byte* limit; /* first character after the token */
48 Z1_Token_Type type; /* type of token.. */
53 /* enumeration type used to identify object fields */
54 typedef enum Z1_Field_Type_
61 t1_field_integer_array,
70 /* structure type used to model object fields */
71 typedef struct Z1_Field_Rec_
73 Z1_Field_Type type; /* type of field */
74 FT_UInt offset; /* offset of field in object */
75 FT_UInt size; /* size of field in bytes */
76 FT_UInt array_max; /* maximum number of elements for array */
77 FT_UInt count_offset; /* offset of element count for arrays */
78 FT_Int flag_bit; /* bit number for field flag */
83 #define Z1_FIELD_REF( s, f ) ( ((s*)0)->f )
85 #define Z1_FIELD_BOOL( _ftype, _fname ) \
88 (FT_UInt)(char*)&Z1_FIELD_REF( _ftype, _fname ), \
89 sizeof ( Z1_FIELD_REF( _ftype, _fname ) ), \
93 #define Z1_FIELD_NUM( _ftype, _fname ) \
96 (FT_UInt)(char*)&Z1_FIELD_REF( _ftype, _fname ), \
97 sizeof ( Z1_FIELD_REF( _ftype, _fname ) ), \
101 #define Z1_FIELD_FIXED( _ftype, _fname, _power ) \
104 (FT_UInt)(char*)&Z1_FIELD_REF( _ftype, _fname ), \
105 sizeof ( Z1_FIELD_REF( _ftype, _fname ) ), \
109 #define Z1_FIELD_STRING( _ftype, _fname ) \
112 (FT_UInt)(char*)&Z1_FIELD_REF( _ftype, _fname ), \
113 sizeof ( Z1_FIELD_REF( _ftype, _fname ) ), \
117 #define Z1_FIELD_NUM_ARRAY( _ftype, _fname, _fcount, _fmax ) \
120 (FT_UInt)(char*)&Z1_FIELD_REF( _ftype, _fname ), \
121 sizeof ( Z1_FIELD_REF( _ftype, _fname )[0] ), \
123 (FT_UInt)(char*)&Z1_FIELD_REF( _ftype, _fcount ), \
127 #define Z1_FIELD_FIXED_ARRAY( _ftype, _fname, _fcount, _fmax ) \
130 (FT_UInt)(char*)&Z1_FIELD_REF( _ftype, _fname ), \
131 sizeof ( Z1_FIELD_REF( _ftype, _fname )[0] ), \
133 (FT_UInt)(char*)&Z1_FIELD_REF( _ftype, _fcount ), \
137 #define Z1_FIELD_NUM_ARRAY2( _ftype, _fname, _fmax ) \
140 (FT_UInt)(char*)&Z1_FIELD_REF( _ftype, _fname ), \
141 sizeof ( Z1_FIELD_REF( _ftype, _fname )[0] ), \
146 #define Z1_FIELD_FIXED_ARRAY2( _ftype, _fname, _fmax ) \
149 (FT_UInt)(char*)&Z1_FIELD_REF( _ftype, _fname ), \
150 sizeof ( Z1_FIELD_REF( _ftype, _fname )[0] ), \
156 /*************************************************************************/
162 /* A Z1_Table is a simple object used to store an array of objects in */
163 /* a single memory block. */
166 /* block :: The address in memory of the growheap's block. This */
167 /* can change between two object adds, due to the use of */
170 /* cursor :: The current top of the grow heap within its block. */
172 /* capacity :: The current size of the heap block. Increments in */
175 /* init :: A boolean. Set when the table has been initialized */
176 /* (the table user should set this field). */
178 /* max_elems :: The maximum number of elements in the table. */
180 /* num_elems :: The current number of elements in the table. */
182 /* elements :: A table of element addresses within the block. */
184 /* lengths :: A table of element sizes within the block. */
186 /* memory :: The memory object used for memory operations */
187 /* (allocation/reallocation). */
189 typedef struct Z1_Table_
191 FT_Byte* block; /* current memory block */
192 FT_Int cursor; /* current cursor in memory block */
193 FT_Int capacity; /* current size of memory block */
198 FT_Byte** elements; /* addresses of table elements */
199 FT_Int* lengths; /* lengths of table elements */
206 /*************************************************************************/
212 /* A Z1_Parser is an object used to parse a Type 1 fonts very */
216 /* stream :: The current input stream. */
218 /* memory :: The current memory object. */
220 /* base_dict :: A pointer to the top-level dictionary. */
222 /* base_len :: The length in bytes of the top dictionary. */
224 /* private_dict :: A pointer to the private dictionary. */
226 /* private_len :: The length in bytes of the private dictionary. */
228 /* in_pfb :: A boolean. Indicates that we are handling a PFB */
231 /* in_memory :: A boolean. Indicates a memory-based stream. */
233 /* single_block :: A boolean. Indicates that the private dictionary */
234 /* is stored in lieu of the base dictionary. */
236 /* cursor :: The current parser cursor. */
238 /* limit :: The current parser limit (first byte after the */
239 /* current dictionary). */
241 /* error :: The current parsing error. */
243 typedef struct Z1_Parser_
251 FT_Byte* private_dict;
256 FT_Byte single_block;
266 FT_Error Z1_New_Table( Z1_Table* table,
272 FT_Error Z1_Add_Table( Z1_Table* table,
279 void Z1_Done_Table( Z1_Table* table );
283 void Z1_Release_Table( Z1_Table* table );
286 FT_Long Z1_ToInt( Z1_Parser* parser );
289 FT_Long Z1_ToFixed( Z1_Parser* parser,
293 FT_Int Z1_ToCoordArray( Z1_Parser* parser,
298 FT_Int Z1_ToFixedArray( Z1_Parser* parser,
305 FT_String* Z1_ToString( Z1_Parser* parser );
308 FT_Bool Z1_ToBool( Z1_Parser* parser );
313 void Z1_Skip_Spaces( Z1_Parser* parser );
316 void Z1_ToToken( Z1_Parser* parser,
317 Z1_Token_Rec* token );
320 void Z1_ToTokenArray( Z1_Parser* parser,
321 Z1_Token_Rec* tokens,
323 FT_Int* pnum_tokens );
326 FT_Error Z1_Load_Field( Z1_Parser* parser,
327 const Z1_Field_Rec* field,
333 FT_Error Z1_Load_Field_Table( Z1_Parser* parser,
334 const Z1_Field_Rec* field,
341 FT_Error Z1_New_Parser( Z1_Parser* parser,
346 FT_Error Z1_Get_Private_Dict( Z1_Parser* parser );
349 void Z1_Decrypt( FT_Byte* buffer,
354 void Z1_Done_Parser( Z1_Parser* parser );
360 #endif /* Z1PARSE_H */