Home | History | Annotate | Download | only in cff
      1 /***************************************************************************/
      2 /*                                                                         */
      3 /*  cffparse.h                                                             */
      4 /*                                                                         */
      5 /*    CFF token stream parser (specification)                              */
      6 /*                                                                         */
      7 /*  Copyright 1996-2017 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 CFFPARSE_H_
     20 #define CFFPARSE_H_
     21 
     22 
     23 #include <ft2build.h>
     24 #include "cfftypes.h"
     25 #include FT_INTERNAL_OBJECTS_H
     26 
     27 
     28 FT_BEGIN_HEADER
     29 
     30 
     31   /* CFF uses constant parser stack size; */
     32   /* CFF2 can increase from default 193   */
     33 #define CFF_MAX_STACK_DEPTH  96
     34 #define CFF2_MAX_STACK      513
     35 #define CFF2_DEFAULT_STACK  193
     36 
     37 #define CFF_CODE_TOPDICT    0x1000
     38 #define CFF_CODE_PRIVATE    0x2000
     39 #define CFF2_CODE_TOPDICT   0x3000
     40 #define CFF2_CODE_FONTDICT  0x4000
     41 #define CFF2_CODE_PRIVATE   0x5000
     42 
     43 
     44   typedef struct  CFF_ParserRec_
     45   {
     46     FT_Library  library;
     47     FT_Byte*    start;
     48     FT_Byte*    limit;
     49     FT_Byte*    cursor;
     50 
     51     FT_Byte**   stack;
     52     FT_Byte**   top;
     53     FT_UInt     stackSize;  /* allocated size */
     54 
     55     FT_UInt     object_code;
     56     void*       object;
     57 
     58     FT_UShort   num_designs; /* a copy of `CFF_FontRecDict->num_designs' */
     59     FT_UShort   num_axes;    /* a copy of `CFF_FontRecDict->num_axes'    */
     60 
     61   } CFF_ParserRec, *CFF_Parser;
     62 
     63 
     64   FT_LOCAL( FT_Long )
     65   cff_parse_num( CFF_Parser  parser,
     66                  FT_Byte**   d );
     67 
     68   FT_LOCAL( FT_Error )
     69   cff_parser_init( CFF_Parser  parser,
     70                    FT_UInt     code,
     71                    void*       object,
     72                    FT_Library  library,
     73                    FT_UInt     stackSize,
     74                    FT_UShort   num_designs,
     75                    FT_UShort   num_axes );
     76 
     77   FT_LOCAL( void )
     78   cff_parser_done( CFF_Parser  parser );
     79 
     80   FT_LOCAL( FT_Error )
     81   cff_parser_run( CFF_Parser  parser,
     82                   FT_Byte*    start,
     83                   FT_Byte*    limit );
     84 
     85 
     86   enum
     87   {
     88     cff_kind_none = 0,
     89     cff_kind_num,
     90     cff_kind_fixed,
     91     cff_kind_fixed_thousand,
     92     cff_kind_string,
     93     cff_kind_bool,
     94     cff_kind_delta,
     95     cff_kind_callback,
     96     cff_kind_blend,
     97 
     98     cff_kind_max  /* do not remove */
     99   };
    100 
    101 
    102   /* now generate handlers for the most simple fields */
    103   typedef FT_Error  (*CFF_Field_Reader)( CFF_Parser  parser );
    104 
    105   typedef struct  CFF_Field_Handler_
    106   {
    107     int               kind;
    108     int               code;
    109     FT_UInt           offset;
    110     FT_Byte           size;
    111     CFF_Field_Reader  reader;
    112     FT_UInt           array_max;
    113     FT_UInt           count_offset;
    114 
    115 #ifdef FT_DEBUG_LEVEL_TRACE
    116     const char*       id;
    117 #endif
    118 
    119   } CFF_Field_Handler;
    120 
    121 
    122 FT_END_HEADER
    123 
    124 
    125 #endif /* CFFPARSE_H_ */
    126 
    127 
    128 /* END */
    129