1 /***************************************************************************/ 
   5 /*    CID-keyed Type1 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> 
  32   /*************************************************************************/ 
  38   /*    A CID_Table is a simple object used to store an array of objects   */ 
  39   /*    in a single memory block.                                          */ 
  42   /*    block     :: The address in memory of the growheap's block.  This  */ 
  43   /*                 can change between two object adds, due to the use    */ 
  46   /*    cursor    :: The current top of the growheap within its block.     */ 
  48   /*    capacity  :: The current size of the heap block.  Increments by    */ 
  49   /*                 blocks of 1 kByte.                                    */ 
  51   /*    init      :: A boolean.  Set when the table has been initialized   */ 
  52   /*                 (the table user should set this field).               */ 
  54   /*    max_elems :: The maximal number of elements in the table.          */ 
  56   /*    num_elems :: The current number of elements (in use) in the table. */ 
  58   /*    elements  :: A table of element addresses within the block.        */ 
  60   /*    lengths   :: A table of element sizes within the block.            */ 
  62   /*    memory    :: The memory object used for memory operations          */ 
  63   /*                 (allocation resp. reallocation).                      */ 
  65   typedef struct  CID_Table_
 
  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   */ 
  74     FT_Byte
**  elements
;       /* addresses of table elements */ 
  75     FT_Int
*    lengths
;        /* lengths of table elements   */ 
  83   FT_Error  
CID_New_Table( CID_Table
*  table
, 
  88   FT_Error  
CID_Add_Table( CID_Table
*  table
, 
  94   void  CID_Release_Table( CID_Table
*  table 
); 
  99   /*************************************************************************/ 
 105   /*    A CID_Parser is an object used to parse a Type 1 fonts very        */ 
 109   /*    stream         :: The current input stream.                        */ 
 111   /*    memory         :: The current memory object.                       */ 
 113   /*    postscript     :: A pointer to the data to be parsed.              */ 
 115   /*    postscript_len :: The length of the data to be parsed.             */ 
 117   /*    data_offset    :: The start position of the binary data (i.e., the */ 
 118   /*                      end of the data to be parsed.                    */ 
 120   /*    cursor         :: The current parser cursor.                       */ 
 122   /*    limit          :: The current parser limit (i.e., the first byte   */ 
 123   /*                      after the current dictionary).                   */ 
 125   /*    error          :: The current parsing error.                       */ 
 127   /*    cid            :: A structure which holds the information about    */ 
 128   /*                      the current font.                                */ 
 130   /*    num_dict       :: The number of font dictionaries.                 */ 
 132   typedef struct CID_Parser_
 
 138     FT_Int     postscript_len
; 
 140     FT_ULong   data_offset
; 
 153   FT_Error  
CID_New_Parser( CID_Parser
*  parser
, 
 158   void  CID_Done_Parser( CID_Parser
*  parser 
); 
 161   /*************************************************************************/ 
 163   /*                            PARSING ROUTINES                           */ 
 165   /*************************************************************************/ 
 168   FT_Long  
CID_ToInt( CID_Parser
*  parser 
); 
 171   FT_Int  
CID_ToCoordArray( CID_Parser
*  parser
, 
 176   FT_Int  
CID_ToFixedArray( CID_Parser
*  parser
, 
 182   void  CID_Skip_Spaces( CID_Parser
*  parser 
); 
 185   /* simple enumeration type used to identify token types */ 
 186   typedef enum  CID_Token_Type_
 
 199   /* a simple structure used to identify tokens */ 
 200   typedef struct  CID_Token_Rec_
 
 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                            */ 
 210   void  CID_ToToken( CID_Parser
*     parser
, 
 211                      CID_Token_Rec
*  token 
); 
 214   /* enumeration type used to identify object fields */ 
 215   typedef enum  CID_Field_Type_
 
 222     t1_field_integer_array
, 
 223     t1_field_fixed_array
, 
 231   typedef enum  CID_Field_Location_
 
 239     t1_field_location_max
 
 241   } CID_Field_Location
; 
 244   typedef FT_Error  (*CID_Field_Parser
)( CID_Face     face
, 
 245                                          CID_Parser
*  parser 
); 
 247   /* structure type used to model object fields */ 
 248   typedef struct  CID_Field_Rec_
 
 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    */ 
 258     FT_UInt             count_offset
; /* offset of element count for       */ 
 263 #define CID_FIELD_REF( s, f )  ( ((s*)0)->f ) 
 265 #define CID_NEW_SIMPLE_FIELD( _ident, _type, _fname )         \ 
 267             _ident, T1CODE, _type,                            \ 
 269             (FT_UInt)(char*)&CID_FIELD_REF( T1TYPE, _fname ), \ 
 270             sizeof ( CID_FIELD_REF( T1TYPE, _fname ) ),       \ 
 274 #define CID_NEW_CALLBACK_FIELD( _ident, _reader ) \ 
 276             _ident, T1CODE, t1_field_callback,    \ 
 282 #define CID_NEW_TABLE_FIELD( _ident, _type, _fname, _max )           \ 
 284             _ident, T1CODE, _type,                                   \ 
 286             (FT_UInt)(char*)&CID_FIELD_REF( T1TYPE, _fname ),        \ 
 287             sizeof ( CID_FIELD_REF( T1TYPE, _fname )[0] ),           \ 
 289             (FT_UInt)(char*)&CID_FIELD_REF( T1TYPE, num_ ## _fname ) \ 
 292 #define CID_NEW_TABLE_FIELD2( _ident, _type, _fname, _max )   \ 
 294             _ident, T1CODE, _type,                            \ 
 296             (FT_UInt)(char*)&CID_FIELD_REF( T1TYPE, _fname ), \ 
 297             sizeof ( CID_FIELD_REF( T1TYPE, _fname )[0] ),    \ 
 302 #define CID_FIELD_BOOL( _ident, _fname )                           \ 
 303           CID_NEW_SIMPLE_FIELD( _ident, t1_field_bool, _fname ) 
 305 #define CID_FIELD_NUM( _ident, _fname )                            \ 
 306           CID_NEW_SIMPLE_FIELD( _ident, t1_field_integer, _fname ) 
 308 #define CID_FIELD_FIXED( _ident, _fname )                          \ 
 309           CID_NEW_SIMPLE_FIELD( _ident, t1_field_fixed, _fname ) 
 311 #define CID_FIELD_STRING( _ident, _fname )                         \ 
 312           CID_NEW_SIMPLE_FIELD( _ident, t1_field_string, _fname ) 
 314 #define CID_FIELD_NUM_TABLE( _ident, _fname, _fmax )               \ 
 315           CID_NEW_TABLE_FIELD( _ident, t1_field_integer_array,     \ 
 318 #define CID_FIELD_FIXED_TABLE( _ident, _fname, _fmax )             \ 
 319           CID_NEW_TABLE_FIELD( _ident, t1_field_fixed_array,       \ 
 322 #define CID_FIELD_NUM_TABLE2( _ident, _fname, _fmax )              \ 
 323           CID_NEW_TABLE_FIELD2( _ident, t1_field_integer_array,    \ 
 326 #define CID_FIELD_FIXED_TABLE2( _ident, _fname, _fmax )            \ 
 327           CID_NEW_TABLE_FIELD2( _ident, t1_field_fixed_array,      \ 
 330 #define CID_FIELD_CALLBACK( _ident, _name )                        \ 
 331           CID_NEW_CALLBACK_FIELD( _ident, parse_ ## _name ) 
 335   FT_Error  
CID_Load_Field( CID_Parser
*           parser
, 
 336                             const CID_Field_Rec
*  field
, 
 340   FT_Error  
CID_Load_Field_Table( CID_Parser
*           parser
, 
 341                                   const CID_Field_Rec
*  field
, 
 350 #endif /* CIDPARSE_H */