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