blob: b6f861c3a55be28822c78944e3e518cc0735692a [file] [log] [blame]
David Turnerd2b1f351999-12-16 23:11:37 +00001/***************************************************************************/
2/* */
3/* ttinterp.h */
4/* */
Werner Lemberg78575dc2000-06-12 19:36:41 +00005/* TrueType bytecode interpreter (specification). */
David Turnerd2b1f351999-12-16 23:11:37 +00006/* */
Werner Lemberg78575dc2000-06-12 19:36:41 +00007/* Copyright 1996-2000 by */
David Turnerd2b1f351999-12-16 23:11:37 +00008/* David Turner, Robert Wilhelm, and Werner Lemberg. */
9/* */
Werner Lemberg78575dc2000-06-12 19:36:41 +000010/* This file is part of the FreeType project, and may only be used, */
11/* modified, and distributed under the terms of the FreeType project */
David Turnerd2b1f351999-12-16 23:11:37 +000012/* 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
Werner Lemberg90d99642000-12-09 00:45:38 +000019#ifndef __TTINTERP_H__
20#define __TTINTERP_H__
David Turnerd2b1f351999-12-16 23:11:37 +000021
Werner Lembergcc069be2000-12-08 16:17:16 +000022
David Turner19ed8af2000-12-08 02:42:29 +000023#include <ft2build.h>
24#include FT_SOURCE_FILE(truetype,ttobjs.h)
David Turnera90663f2000-07-08 00:41:13 +000025
Werner Lembergcc069be2000-12-08 16:17:16 +000026
David Turner19ed8af2000-12-08 02:42:29 +000027FT_BEGIN_HEADER
David Turnerd2b1f351999-12-16 23:11:37 +000028
Werner Lembergcc069be2000-12-08 16:17:16 +000029
Werner Lemberg78575dc2000-06-12 19:36:41 +000030#ifndef TT_CONFIG_OPTION_STATIC_INTEPRETER /* indirect implementation */
David Turnerd2b1f351999-12-16 23:11:37 +000031
Werner Lembergcc069be2000-12-08 16:17:16 +000032#define EXEC_OP_ TT_ExecContext exc,
33#define EXEC_OP TT_ExecContext exc
34#define EXEC_ARG_ exc,
35#define EXEC_ARG exc
David Turnerd2b1f351999-12-16 23:11:37 +000036
Werner Lemberg78575dc2000-06-12 19:36:41 +000037#else /* static implementation */
David Turnerd2b1f351999-12-16 23:11:37 +000038
Werner Lembergcc069be2000-12-08 16:17:16 +000039#define EXEC_OP_ /* void */
40#define EXEC_OP /* void */
41#define EXEC_ARG_ /* void */
42#define EXEC_ARG /* void */
David Turnerd2b1f351999-12-16 23:11:37 +000043
Werner Lemberg78575dc2000-06-12 19:36:41 +000044#endif /* TT_CONFIG_OPTION_STATIC_INTERPRETER */
David Turnerd2b1f351999-12-16 23:11:37 +000045
46
47 /*************************************************************************/
48 /* */
49 /* Rounding mode constants. */
50 /* */
51#define TT_Round_Off 5
52#define TT_Round_To_Half_Grid 0
53#define TT_Round_To_Grid 1
54#define TT_Round_To_Double_Grid 2
55#define TT_Round_Up_To_Grid 4
56#define TT_Round_Down_To_Grid 3
57#define TT_Round_Super 6
58#define TT_Round_Super_45 7
59
60
61 /*************************************************************************/
62 /* */
63 /* Function types used by the interpreter, depending on various modes */
64 /* (e.g. the rounding mode, whether to render a vertical or horizontal */
65 /* line etc). */
66 /* */
67 /*************************************************************************/
68
69 /* Rounding function */
David Turnerf9b8dec2000-06-16 19:34:52 +000070 typedef FT_F26Dot6 (*TT_Round_Func)( EXEC_OP_ FT_F26Dot6 distance,
71 FT_F26Dot6 compensation );
David Turnerd2b1f351999-12-16 23:11:37 +000072
73 /* Point displacement along the freedom vector routine */
David Turnerf9b8dec2000-06-16 19:34:52 +000074 typedef void (*TT_Move_Func)( EXEC_OP_ TT_GlyphZone* zone,
75 FT_UInt point,
76 FT_F26Dot6 distance );
David Turnerd2b1f351999-12-16 23:11:37 +000077
78 /* Distance projection along one of the projection vectors */
David Turnerf9b8dec2000-06-16 19:34:52 +000079 typedef FT_F26Dot6 (*TT_Project_Func)( EXEC_OP_ FT_Vector* v1,
80 FT_Vector* v2 );
David Turnerd2b1f351999-12-16 23:11:37 +000081
82 /* reading a cvt value. Take care of non-square pixels if necessary */
David Turnerf9b8dec2000-06-16 19:34:52 +000083 typedef FT_F26Dot6 (*TT_Get_CVT_Func)( EXEC_OP_ FT_ULong index );
David Turnerd2b1f351999-12-16 23:11:37 +000084
85 /* setting or moving a cvt value. Take care of non-square pixels */
86 /* if necessary */
David Turnerf9b8dec2000-06-16 19:34:52 +000087 typedef void (*TT_Set_CVT_Func)( EXEC_OP_ FT_ULong index,
88 FT_F26Dot6 value );
David Turnerd2b1f351999-12-16 23:11:37 +000089
90
91 /*************************************************************************/
92 /* */
93 /* This structure defines a call record, used to manage function calls. */
94 /* */
95 typedef struct TT_CallRec_
96 {
David Turnerf9b8dec2000-06-16 19:34:52 +000097 FT_Int Caller_Range;
98 FT_Long Caller_IP;
99 FT_Long Cur_Count;
100 FT_Long Cur_Restart;
David Turnerd2b1f351999-12-16 23:11:37 +0000101
102 } TT_CallRec, *TT_CallStack;
103
104
105 /*************************************************************************/
106 /* */
107 /* The main structure for the interpreter which collects all necessary */
108 /* variables and states. */
109 /* */
110 typedef struct TT_ExecContextRec_
111 {
112 TT_Face face;
113 TT_Size size;
114 FT_Memory memory;
115
116 /* instructions state */
117
David Turnerf9b8dec2000-06-16 19:34:52 +0000118 FT_Error error; /* last execution error */
David Turnerd2b1f351999-12-16 23:11:37 +0000119
David Turnerf9b8dec2000-06-16 19:34:52 +0000120 FT_Long top; /* top of exec. stack */
David Turnerd2b1f351999-12-16 23:11:37 +0000121
David Turnerf9b8dec2000-06-16 19:34:52 +0000122 FT_UInt stackSize; /* size of exec. stack */
123 FT_Long* stack; /* current exec. stack */
David Turnerd2b1f351999-12-16 23:11:37 +0000124
David Turnerf9b8dec2000-06-16 19:34:52 +0000125 FT_Long args;
126 FT_UInt new_top; /* new top after exec. */
David Turnerd2b1f351999-12-16 23:11:37 +0000127
David Turnerf9b8dec2000-06-16 19:34:52 +0000128 TT_GlyphZone zp0, /* zone records */
David Turnerd2b1f351999-12-16 23:11:37 +0000129 zp1,
130 zp2,
131 pts,
132 twilight;
133
134 FT_Size_Metrics metrics;
135 TT_Size_Metrics tt_metrics; /* size metrics */
136
137 TT_GraphicsState GS; /* current graphics state */
138
David Turnerf9b8dec2000-06-16 19:34:52 +0000139 FT_Int curRange; /* current code range number */
140 FT_Byte* code; /* current code range */
141 FT_Long IP; /* current instruction pointer */
142 FT_Long codeSize; /* size of current range */
David Turnerd2b1f351999-12-16 23:11:37 +0000143
David Turnerf9b8dec2000-06-16 19:34:52 +0000144 FT_Byte opcode; /* current opcode */
145 FT_Int length; /* length of current opcode */
David Turnerd2b1f351999-12-16 23:11:37 +0000146
David Turnerf9b8dec2000-06-16 19:34:52 +0000147 FT_Bool step_ins; /* true if the interpreter must */
David Turnerd2b1f351999-12-16 23:11:37 +0000148 /* increment IP after ins. exec */
David Turnerf9b8dec2000-06-16 19:34:52 +0000149 FT_Long cvtSize;
150 FT_Long* cvt;
David Turnerd2b1f351999-12-16 23:11:37 +0000151
David Turnerf9b8dec2000-06-16 19:34:52 +0000152 FT_UInt glyphSize; /* glyph instructions buffer size */
153 FT_Byte* glyphIns; /* glyph instructions buffer */
David Turnerd2b1f351999-12-16 23:11:37 +0000154
David Turnerf9b8dec2000-06-16 19:34:52 +0000155 FT_UInt numFDefs; /* number of function defs */
156 FT_UInt maxFDefs; /* maximum number of function defs */
David Turnerd2b1f351999-12-16 23:11:37 +0000157 TT_DefArray FDefs; /* table of FDefs entries */
158
David Turnerf9b8dec2000-06-16 19:34:52 +0000159 FT_UInt numIDefs; /* number of instruction defs */
160 FT_UInt maxIDefs; /* maximum number of ins defs */
David Turnerd2b1f351999-12-16 23:11:37 +0000161 TT_DefArray IDefs; /* table of IDefs entries */
162
David Turnerf9b8dec2000-06-16 19:34:52 +0000163 FT_UInt maxFunc; /* maximum function index */
164 FT_UInt maxIns; /* maximum instruction index */
David Turnerd2b1f351999-12-16 23:11:37 +0000165
David Turnerf9b8dec2000-06-16 19:34:52 +0000166 FT_Int callTop, /* top of call stack during execution */
David Turnerd2b1f351999-12-16 23:11:37 +0000167 callSize; /* size of call stack */
168 TT_CallStack callStack; /* call stack */
169
David Turnerf9b8dec2000-06-16 19:34:52 +0000170 FT_UShort maxPoints; /* capacity of this context's `pts' */
171 FT_Short maxContours; /* record, expressed in points and */
David Turnerd2b1f351999-12-16 23:11:37 +0000172 /* contours. */
173
174 TT_CodeRangeTable codeRangeTable; /* table of valid code ranges */
175 /* useful for the debugger */
176
David Turnerf9b8dec2000-06-16 19:34:52 +0000177 FT_UShort storeSize; /* size of current storage */
178 FT_Long* storage; /* storage area */
David Turnerd2b1f351999-12-16 23:11:37 +0000179
David Turnerf9b8dec2000-06-16 19:34:52 +0000180 FT_F26Dot6 period; /* values used for the */
181 FT_F26Dot6 phase; /* `SuperRounding' */
182 FT_F26Dot6 threshold;
David Turnerd2b1f351999-12-16 23:11:37 +0000183
David Turnerd2b1f351999-12-16 23:11:37 +0000184#if 0
Werner Lemberg5811c7c2000-07-02 13:53:16 +0000185 /* this seems to be unused */
David Turnerf9b8dec2000-06-16 19:34:52 +0000186 FT_Int cur_ppem; /* ppem along the current proj vector */
David Turnerd2b1f351999-12-16 23:11:37 +0000187#endif
Werner Lemberg5811c7c2000-07-02 13:53:16 +0000188
David Turnerf9b8dec2000-06-16 19:34:52 +0000189 FT_Bool instruction_trap; /* If `True', the interpreter will */
David Turnerd2b1f351999-12-16 23:11:37 +0000190 /* exit after each instruction */
191
192 TT_GraphicsState default_GS; /* graphics state resulting from */
193 /* the prep program */
David Turnerf9b8dec2000-06-16 19:34:52 +0000194 FT_Bool is_composite; /* true if the glyph is composite */
195 FT_Bool pedantic_hinting; /* true for pedantic interpretation */
David Turnerd2b1f351999-12-16 23:11:37 +0000196
197 /* latest interpreter additions */
198
David Turnerf9b8dec2000-06-16 19:34:52 +0000199 FT_Long F_dot_P; /* dot product of freedom and projection */
David Turnerd2b1f351999-12-16 23:11:37 +0000200 /* vectors */
201 TT_Round_Func func_round; /* current rounding function */
202
203 TT_Project_Func func_project, /* current projection function */
204 func_dualproj, /* current dual proj. function */
205 func_freeProj; /* current freedom proj. func */
206
207 TT_Move_Func func_move; /* current point move function */
208
209 TT_Get_CVT_Func func_read_cvt; /* read a cvt entry */
210 TT_Set_CVT_Func func_write_cvt; /* write a cvt entry (in pixels) */
211 TT_Set_CVT_Func func_move_cvt; /* incr a cvt entry (in pixels) */
212
David Turnerf9b8dec2000-06-16 19:34:52 +0000213 FT_ULong loadSize;
David Turnerd2b1f351999-12-16 23:11:37 +0000214 TT_SubGlyph_Stack loadStack; /* loading subglyph stack */
215
216 } TT_ExecContextRec;
217
218
Werner Lembergbd5ae402000-07-05 04:32:02 +0000219 extern const TT_GraphicsState tt_default_graphics_state;
David Turnerd2b1f351999-12-16 23:11:37 +0000220
221
David Turner76a5f622000-11-04 01:55:49 +0000222 FT_LOCAL
David Turnerf9b8dec2000-06-16 19:34:52 +0000223 FT_Error TT_Goto_CodeRange( TT_ExecContext exec,
224 FT_Int range,
225 FT_Long IP );
David Turnerd2b1f351999-12-16 23:11:37 +0000226
David Turner76a5f622000-11-04 01:55:49 +0000227 FT_LOCAL
David Turnerf9b8dec2000-06-16 19:34:52 +0000228 FT_Error TT_Set_CodeRange( TT_ExecContext exec,
229 FT_Int range,
David Turnerd2b1f351999-12-16 23:11:37 +0000230 void* base,
David Turnerf9b8dec2000-06-16 19:34:52 +0000231 FT_Long length );
David Turnerd2b1f351999-12-16 23:11:37 +0000232
David Turner76a5f622000-11-04 01:55:49 +0000233 FT_LOCAL
David Turnerf9b8dec2000-06-16 19:34:52 +0000234 FT_Error TT_Clear_CodeRange( TT_ExecContext exec,
235 FT_Int range );
David Turnerd2b1f351999-12-16 23:11:37 +0000236
Werner Lemberg90a03302000-11-07 17:21:11 +0000237
238 /*************************************************************************/
239 /* */
240 /* <Function> */
241 /* TT_New_Context */
242 /* */
243 /* <Description> */
244 /* Queries the face context for a given font. Note that there is */
245 /* now a _single_ execution context in the TrueType driver which is */
246 /* shared among faces. */
247 /* */
248 /* <Input> */
249 /* face :: A handle to the source face object. */
250 /* */
251 /* <Return> */
252 /* A handle to the execution context. Initialized for `face'. */
253 /* */
254 /* <Note> */
255 /* Only the glyph loader and debugger should call this function. */
256 /* */
David Turner76a5f622000-11-04 01:55:49 +0000257 FT_EXPORT( TT_ExecContext ) TT_New_Context( TT_Face face );
David Turnerd2b1f351999-12-16 23:11:37 +0000258
Werner Lemberg90a03302000-11-07 17:21:11 +0000259
David Turner76a5f622000-11-04 01:55:49 +0000260 FT_LOCAL
David Turnerf9b8dec2000-06-16 19:34:52 +0000261 FT_Error TT_Done_Context( TT_ExecContext exec );
David Turnerd2b1f351999-12-16 23:11:37 +0000262
David Turner76a5f622000-11-04 01:55:49 +0000263 FT_LOCAL
David Turnerf9b8dec2000-06-16 19:34:52 +0000264 FT_Error TT_Destroy_Context( TT_ExecContext exec,
David Turnerd2b1f351999-12-16 23:11:37 +0000265 FT_Memory memory );
266
David Turner76a5f622000-11-04 01:55:49 +0000267 FT_LOCAL
David Turnerf9b8dec2000-06-16 19:34:52 +0000268 FT_Error TT_Load_Context( TT_ExecContext exec,
David Turnerd2b1f351999-12-16 23:11:37 +0000269 TT_Face face,
270 TT_Size size );
271
David Turner76a5f622000-11-04 01:55:49 +0000272 FT_LOCAL
David Turnerf9b8dec2000-06-16 19:34:52 +0000273 FT_Error TT_Save_Context( TT_ExecContext exec,
David Turnerd2b1f351999-12-16 23:11:37 +0000274 TT_Size ins );
275
David Turner76a5f622000-11-04 01:55:49 +0000276 FT_LOCAL
David Turnerf9b8dec2000-06-16 19:34:52 +0000277 FT_Error TT_Run_Context( TT_ExecContext exec,
278 FT_Bool debug );
David Turnerd2b1f351999-12-16 23:11:37 +0000279
Werner Lemberg90a03302000-11-07 17:21:11 +0000280
281 /*************************************************************************/
282 /* */
283 /* <Function> */
284 /* TT_RunIns */
285 /* */
286 /* <Description> */
287 /* Executes one or more instruction in the execution context. This */
288 /* is the main function of the TrueType opcode interpreter. */
289 /* */
290 /* <Input> */
291 /* exec :: A handle to the target execution context. */
292 /* */
293 /* <Return> */
294 /* FreeType error code. 0 means success. */
295 /* */
296 /* <Note> */
297 /* Only the object manager and debugger should call this function. */
298 /* */
299 /* This function is publicly exported because it is directly */
300 /* invoked by the TrueType debugger. */
301 /* */
David Turner76a5f622000-11-04 01:55:49 +0000302 FT_EXPORT( FT_Error ) TT_RunIns( TT_ExecContext exec );
David Turnerd2b1f351999-12-16 23:11:37 +0000303
304
David Turner19ed8af2000-12-08 02:42:29 +0000305FT_END_HEADER
David Turnerd2b1f351999-12-16 23:11:37 +0000306
Werner Lemberg90d99642000-12-09 00:45:38 +0000307#endif /* __TTINTERP_H__ */
David Turnerd2b1f351999-12-16 23:11:37 +0000308
309
310/* END */