1 /****************************************************************************
2  *
3  * cffparse.h
4  *
5  *   CFF token stream parser (specification)
6  *
7  * Copyright (C) 1996-2019 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 FT_INTERNAL_CFF_TYPES_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 
35   /*
36    * There are plans to remove the `maxstack' operator in a forthcoming
37    * revision of the CFF2 specification, increasing the (then static) stack
38    * size to 513.  By making the default stack size equal to the maximum
39    * stack size, the operator is essentially disabled, which has the
40    * desired effect in FreeType.
41    */
42 #define CFF2_MAX_STACK      513
43 #define CFF2_DEFAULT_STACK  513
44 
45 #define CFF_CODE_TOPDICT    0x1000
46 #define CFF_CODE_PRIVATE    0x2000
47 #define CFF2_CODE_TOPDICT   0x3000
48 #define CFF2_CODE_FONTDICT  0x4000
49 #define CFF2_CODE_PRIVATE   0x5000
50 
51 
52   typedef struct  CFF_ParserRec_
53   {
54     FT_Library  library;
55     FT_Byte*    start;
56     FT_Byte*    limit;
57     FT_Byte*    cursor;
58 
59     FT_Byte**   stack;
60     FT_Byte**   top;
61     FT_UInt     stackSize;  /* allocated size */
62 
63 #ifdef CFF_CONFIG_OPTION_OLD_ENGINE
64     FT_ListRec  t2_strings;
65 #endif /* CFF_CONFIG_OPTION_OLD_ENGINE */
66 
67     FT_UInt     object_code;
68     void*       object;
69 
70     FT_UShort   num_designs; /* a copy of `CFF_FontRecDict->num_designs' */
71     FT_UShort   num_axes;    /* a copy of `CFF_FontRecDict->num_axes'    */
72 
73   } CFF_ParserRec, *CFF_Parser;
74 
75 
76   FT_LOCAL( FT_Long )
77   cff_parse_num( CFF_Parser  parser,
78                  FT_Byte**   d );
79 
80   FT_LOCAL( FT_Error )
81   cff_parser_init( CFF_Parser  parser,
82                    FT_UInt     code,
83                    void*       object,
84                    FT_Library  library,
85                    FT_UInt     stackSize,
86                    FT_UShort   num_designs,
87                    FT_UShort   num_axes );
88 
89   FT_LOCAL( void )
90   cff_parser_done( CFF_Parser  parser );
91 
92   FT_LOCAL( FT_Error )
93   cff_parser_run( CFF_Parser  parser,
94                   FT_Byte*    start,
95                   FT_Byte*    limit );
96 
97 
98   enum
99   {
100     cff_kind_none = 0,
101     cff_kind_num,
102     cff_kind_fixed,
103     cff_kind_fixed_thousand,
104     cff_kind_string,
105     cff_kind_bool,
106     cff_kind_delta,
107     cff_kind_callback,
108     cff_kind_blend,
109 
110     cff_kind_max  /* do not remove */
111   };
112 
113 
114   /* now generate handlers for the most simple fields */
115   typedef FT_Error  (*CFF_Field_Reader)( CFF_Parser  parser );
116 
117   typedef struct  CFF_Field_Handler_
118   {
119     int               kind;
120     int               code;
121     FT_UInt           offset;
122     FT_Byte           size;
123     CFF_Field_Reader  reader;
124     FT_UInt           array_max;
125     FT_UInt           count_offset;
126 
127 #ifdef FT_DEBUG_LEVEL_TRACE
128     const char*       id;
129 #endif
130 
131   } CFF_Field_Handler;
132 
133 
134 FT_END_HEADER
135 
136 
137 #ifdef CFF_CONFIG_OPTION_OLD_ENGINE
138   typedef struct  CFF_T2_String_
139   {
140     FT_Byte*  start;
141     FT_Byte*  limit;
142 
143   } CFF_T2_StringRec, *CFF_T2_String;
144 #endif /* CFF_CONFIG_OPTION_OLD_ENGINE */
145 
146 #endif /* CFFPARSE_H_ */
147 
148 
149 /* END */
150