update for HEAD-2003021201
[reactos.git] / subsys / win32k / freetype / src / cid / cidparse.h
1 /***************************************************************************/
2 /*                                                                         */
3 /*  cidparse.h                                                             */
4 /*                                                                         */
5 /*    CID-keyed Type1 parser (specification).                              */
6 /*                                                                         */
7 /*  Copyright 1996-2000 by                                                 */
8 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
9 /*                                                                         */
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.                                        */
15 /*                                                                         */
16 /***************************************************************************/
17
18
19 #ifndef CIDPARSE_H
20 #define CIDPARSE_H
21
22 #include <freetype/internal/t1types.h>
23
24
25 #ifdef __cplusplus
26   extern "C" {
27 #endif
28
29
30 #if 0
31
32   /*************************************************************************/
33   /*                                                                       */
34   /* <Struct>                                                              */
35   /*    CID_Table                                                          */
36   /*                                                                       */
37   /* <Description>                                                         */
38   /*    A CID_Table is a simple object used to store an array of objects   */
39   /*    in a single memory block.                                          */
40   /*                                                                       */
41   /* <Fields>                                                              */
42   /*    block     :: The address in memory of the growheap's block.  This  */
43   /*                 can change between two object adds, due to the use    */
44   /*                 of `realloc()'.                                       */
45   /*                                                                       */
46   /*    cursor    :: The current top of the growheap within its block.     */
47   /*                                                                       */
48   /*    capacity  :: The current size of the heap block.  Increments by    */
49   /*                 blocks of 1 kByte.                                    */
50   /*                                                                       */
51   /*    init      :: A boolean.  Set when the table has been initialized   */
52   /*                 (the table user should set this field).               */
53   /*                                                                       */
54   /*    max_elems :: The maximal number of elements in the table.          */
55   /*                                                                       */
56   /*    num_elems :: The current number of elements (in use) in the table. */
57   /*                                                                       */
58   /*    elements  :: A table of element addresses within the block.        */
59   /*                                                                       */
60   /*    lengths   :: A table of element sizes within the block.            */
61   /*                                                                       */
62   /*    memory    :: The memory object used for memory operations          */
63   /*                 (allocation resp. reallocation).                      */
64   /*                                                                       */
65   typedef struct  CID_Table_
66   {
67     FT_Byte*   block;          /* current memory block           */
68     FT_Int     cursor;         /* current cursor in memory block */
69     FT_Int     capacity;       /* current size of memory block   */
70     FT_Long    init;
71
72     FT_Int     max_elems;
73     FT_Int     num_elems;
74     FT_Byte**  elements;       /* addresses of table elements */
75     FT_Int*    lengths;        /* lengths of table elements   */
76
77     FT_Memory  memory;
78
79   } CID_Table;
80
81
82   LOCAL_DEF
83   FT_Error  CID_New_Table( CID_Table*  table,
84                            FT_Int      count,
85                            CID_Memory  memory );
86
87   LOCAL_DEF
88   FT_Error  CID_Add_Table( CID_Table*  table,
89                            FT_Int      index,
90                            void*       object,
91                            FT_Int      length );
92
93   LOCAL_DEF
94   void  CID_Release_Table( CID_Table*  table );
95
96 #endif /* 0 */
97
98
99   /*************************************************************************/
100   /*                                                                       */
101   /* <Struct>                                                              */
102   /*    CID_Parser                                                         */
103   /*                                                                       */
104   /* <Description>                                                         */
105   /*    A CID_Parser is an object used to parse a Type 1 fonts very        */
106   /*    quickly.                                                           */
107   /*                                                                       */
108   /* <Fields>                                                              */
109   /*    stream         :: The current input stream.                        */
110   /*                                                                       */
111   /*    memory         :: The current memory object.                       */
112   /*                                                                       */
113   /*    postscript     :: A pointer to the data to be parsed.              */
114   /*                                                                       */
115   /*    postscript_len :: The length of the data to be parsed.             */
116   /*                                                                       */
117   /*    data_offset    :: The start position of the binary data (i.e., the */
118   /*                      end of the data to be parsed.                    */
119   /*                                                                       */
120   /*    cursor         :: The current parser cursor.                       */
121   /*                                                                       */
122   /*    limit          :: The current parser limit (i.e., the first byte   */
123   /*                      after the current dictionary).                   */
124   /*                                                                       */
125   /*    error          :: The current parsing error.                       */
126   /*                                                                       */
127   /*    cid            :: A structure which holds the information about    */
128   /*                      the current font.                                */
129   /*                                                                       */
130   /*    num_dict       :: The number of font dictionaries.                 */
131   /*                                                                       */
132   typedef struct CID_Parser_
133   {
134     FT_Stream  stream;
135     FT_Memory  memory;
136
137     FT_Byte*   postscript;
138     FT_Int     postscript_len;
139
140     FT_ULong   data_offset;
141
142     FT_Byte*   cursor;
143     FT_Byte*   limit;
144     FT_Error   error;
145
146     CID_Info*  cid;
147     FT_Int     num_dict;
148
149   } CID_Parser;
150
151
152   LOCAL_DEF
153   FT_Error  CID_New_Parser( CID_Parser*  parser,
154                             FT_Stream    stream,
155                             FT_Memory    memory );
156
157   LOCAL_DEF
158   void  CID_Done_Parser( CID_Parser*  parser );
159
160
161   /*************************************************************************/
162   /*                                                                       */
163   /*                            PARSING ROUTINES                           */
164   /*                                                                       */
165   /*************************************************************************/
166
167   LOCAL_DEF
168   FT_Long  CID_ToInt( CID_Parser*  parser );
169
170   LOCAL_DEF
171   FT_Int  CID_ToCoordArray( CID_Parser*  parser,
172                             FT_Int       max_coords,
173                             FT_Short*    coords );
174
175   LOCAL_DEF
176   FT_Int  CID_ToFixedArray( CID_Parser*  parser,
177                             FT_Int       max_values,
178                             FT_Fixed*    values,
179                             FT_Int       power_ten );
180
181   LOCAL_DEF
182   void  CID_Skip_Spaces( CID_Parser*  parser );
183
184
185   /* simple enumeration type used to identify token types */
186   typedef enum  CID_Token_Type_
187   {
188     t1_token_none = 0,
189     t1_token_any,
190     t1_token_string,
191     t1_token_array,
192
193     /* do not remove */
194     t1_token_max
195
196   } CID_Token_Type;
197
198
199   /* a simple structure used to identify tokens */
200   typedef struct  CID_Token_Rec_
201   {
202     FT_Byte*        start;   /* first character of token in input stream */
203     FT_Byte*        limit;   /* first character after the token          */
204     CID_Token_Type  type;    /* type of token                            */
205
206   } CID_Token_Rec;
207
208
209   LOCAL_DEF
210   void  CID_ToToken( CID_Parser*     parser,
211                      CID_Token_Rec*  token );
212
213
214   /* enumeration type used to identify object fields */
215   typedef enum  CID_Field_Type_
216   {
217     t1_field_none = 0,
218     t1_field_bool,
219     t1_field_integer,
220     t1_field_fixed,
221     t1_field_string,
222     t1_field_integer_array,
223     t1_field_fixed_array,
224     t1_field_callback,
225
226     /* do not remove */
227     t1_field_max
228
229   } CID_Field_Type;
230
231   typedef enum  CID_Field_Location_
232   {
233     t1_field_cid_info,
234     t1_field_font_dict,
235     t1_field_font_info,
236     t1_field_private,
237
238     /* do not remove */
239     t1_field_location_max
240
241   } CID_Field_Location;
242
243
244   typedef FT_Error  (*CID_Field_Parser)( CID_Face     face,
245                                          CID_Parser*  parser );
246
247   /* structure type used to model object fields */
248   typedef struct  CID_Field_Rec_
249   {
250     const char*         ident;        /* field identifier                  */
251     CID_Field_Location  location;
252     CID_Field_Type      type;         /* type of field                     */
253     CID_Field_Parser    reader;
254     FT_UInt             offset;       /* offset of field in object         */
255     FT_UInt             size;         /* size of field in bytes            */
256     FT_UInt             array_max;    /* maximal number of elements for    */
257                                       /* array                             */
258     FT_UInt             count_offset; /* offset of element count for       */
259                                       /* arrays                            */
260   } CID_Field_Rec;
261
262
263 #define CID_FIELD_REF( s, f )  ( ((s*)0)->f )
264
265 #define CID_NEW_SIMPLE_FIELD( _ident, _type, _fname )         \
266           {                                                   \
267             _ident, T1CODE, _type,                            \
268             0,                                                \
269             (FT_UInt)(char*)&CID_FIELD_REF( T1TYPE, _fname ), \
270             sizeof ( CID_FIELD_REF( T1TYPE, _fname ) ),       \
271             0, 0                                              \
272           },
273
274 #define CID_NEW_CALLBACK_FIELD( _ident, _reader ) \
275           {                                       \
276             _ident, T1CODE, t1_field_callback,    \
277             _reader,                              \
278             0, 0,                                 \
279             0, 0                                  \
280           },
281
282 #define CID_NEW_TABLE_FIELD( _ident, _type, _fname, _max )           \
283           {                                                          \
284             _ident, T1CODE, _type,                                   \
285             0,                                                       \
286             (FT_UInt)(char*)&CID_FIELD_REF( T1TYPE, _fname ),        \
287             sizeof ( CID_FIELD_REF( T1TYPE, _fname )[0] ),           \
288             _max,                                                    \
289             (FT_UInt)(char*)&CID_FIELD_REF( T1TYPE, num_ ## _fname ) \
290           },
291
292 #define CID_NEW_TABLE_FIELD2( _ident, _type, _fname, _max )   \
293           {                                                   \
294             _ident, T1CODE, _type,                            \
295             0,                                                \
296             (FT_UInt)(char*)&CID_FIELD_REF( T1TYPE, _fname ), \
297             sizeof ( CID_FIELD_REF( T1TYPE, _fname )[0] ),    \
298             _max, 0                                           \
299           },
300
301
302 #define CID_FIELD_BOOL( _ident, _fname )                           \
303           CID_NEW_SIMPLE_FIELD( _ident, t1_field_bool, _fname )
304
305 #define CID_FIELD_NUM( _ident, _fname )                            \
306           CID_NEW_SIMPLE_FIELD( _ident, t1_field_integer, _fname )
307
308 #define CID_FIELD_FIXED( _ident, _fname )                          \
309           CID_NEW_SIMPLE_FIELD( _ident, t1_field_fixed, _fname )
310
311 #define CID_FIELD_STRING( _ident, _fname )                         \
312           CID_NEW_SIMPLE_FIELD( _ident, t1_field_string, _fname )
313
314 #define CID_FIELD_NUM_TABLE( _ident, _fname, _fmax )               \
315           CID_NEW_TABLE_FIELD( _ident, t1_field_integer_array,     \
316                                _fname, _fmax )
317
318 #define CID_FIELD_FIXED_TABLE( _ident, _fname, _fmax )             \
319           CID_NEW_TABLE_FIELD( _ident, t1_field_fixed_array,       \
320                                _fname, _fmax )
321
322 #define CID_FIELD_NUM_TABLE2( _ident, _fname, _fmax )              \
323           CID_NEW_TABLE_FIELD2( _ident, t1_field_integer_array,    \
324                                 _fname, _fmax )
325
326 #define CID_FIELD_FIXED_TABLE2( _ident, _fname, _fmax )            \
327           CID_NEW_TABLE_FIELD2( _ident, t1_field_fixed_array,      \
328                                 _fname, _fmax )
329
330 #define CID_FIELD_CALLBACK( _ident, _name )                        \
331           CID_NEW_CALLBACK_FIELD( _ident, parse_ ## _name )
332
333
334   LOCAL_DEF
335   FT_Error  CID_Load_Field( CID_Parser*           parser,
336                             const CID_Field_Rec*  field,
337                             void*                 object );
338
339   LOCAL_DEF
340   FT_Error  CID_Load_Field_Table( CID_Parser*           parser,
341                                   const CID_Field_Rec*  field,
342                                   void*                 object );
343
344
345 #ifdef __cplusplus
346   }
347 #endif
348
349
350 #endif /* CIDPARSE_H */
351
352
353 /* END */