blob: c480dfa506e0808fe72f6a7d18b4171d6a8894ce [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 Lemberg6da023d2010-05-20 15:38:00 +02007/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2010 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
David Turner19ed8af2000-12-08 02:42:29 +000022#include <ft2build.h>
David Turner8d3a4012001-03-20 11:14:24 +000023#include "ttobjs.h"
David Turnera90663f2000-07-08 00:41:13 +000024
Werner Lembergcc069be2000-12-08 16:17:16 +000025
David Turner19ed8af2000-12-08 02:42:29 +000026FT_BEGIN_HEADER
David Turnerd2b1f351999-12-16 23:11:37 +000027
Werner Lembergcc069be2000-12-08 16:17:16 +000028
Werner Lemberg85cc0a32004-11-23 22:10:21 +000029#ifndef TT_CONFIG_OPTION_STATIC_INTERPRETER /* indirect implementation */
David Turnerd2b1f351999-12-16 23:11:37 +000030
Werner Lembergcc069be2000-12-08 16:17:16 +000031#define EXEC_OP_ TT_ExecContext exc,
32#define EXEC_OP TT_ExecContext exc
33#define EXEC_ARG_ exc,
34#define EXEC_ARG exc
David Turnerd2b1f351999-12-16 23:11:37 +000035
Werner Lemberg78575dc2000-06-12 19:36:41 +000036#else /* static implementation */
David Turnerd2b1f351999-12-16 23:11:37 +000037
Werner Lembergcc069be2000-12-08 16:17:16 +000038#define EXEC_OP_ /* void */
39#define EXEC_OP /* void */
40#define EXEC_ARG_ /* void */
41#define EXEC_ARG /* void */
David Turnerd2b1f351999-12-16 23:11:37 +000042
Werner Lemberg78575dc2000-06-12 19:36:41 +000043#endif /* TT_CONFIG_OPTION_STATIC_INTERPRETER */
David Turnerd2b1f351999-12-16 23:11:37 +000044
45
46 /*************************************************************************/
47 /* */
48 /* Rounding mode constants. */
49 /* */
50#define TT_Round_Off 5
51#define TT_Round_To_Half_Grid 0
52#define TT_Round_To_Grid 1
53#define TT_Round_To_Double_Grid 2
54#define TT_Round_Up_To_Grid 4
55#define TT_Round_Down_To_Grid 3
56#define TT_Round_Super 6
57#define TT_Round_Super_45 7
58
59
60 /*************************************************************************/
61 /* */
62 /* Function types used by the interpreter, depending on various modes */
63 /* (e.g. the rounding mode, whether to render a vertical or horizontal */
64 /* line etc). */
65 /* */
66 /*************************************************************************/
67
68 /* Rounding function */
Werner Lemberg4a2305c2001-06-28 07:17:51 +000069 typedef FT_F26Dot6
70 (*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 */
Werner Lemberg4a2305c2001-06-28 07:17:51 +000074 typedef void
Werner Lemberg91db04c2002-04-01 14:25:28 +000075 (*TT_Move_Func)( EXEC_OP_ TT_GlyphZone zone,
76 FT_UShort point,
77 FT_F26Dot6 distance );
David Turnerd2b1f351999-12-16 23:11:37 +000078
79 /* Distance projection along one of the projection vectors */
Werner Lemberg4a2305c2001-06-28 07:17:51 +000080 typedef FT_F26Dot6
David Turner72a0dd22007-02-12 15:24:51 +000081 (*TT_Project_Func)( EXEC_OP_ FT_Pos dx,
82 FT_Pos dy );
David Turnerd2b1f351999-12-16 23:11:37 +000083
84 /* reading a cvt value. Take care of non-square pixels if necessary */
Werner Lemberg4a2305c2001-06-28 07:17:51 +000085 typedef FT_F26Dot6
Werner Lemberg91db04c2002-04-01 14:25:28 +000086 (*TT_Get_CVT_Func)( EXEC_OP_ FT_ULong idx );
David Turnerd2b1f351999-12-16 23:11:37 +000087
88 /* setting or moving a cvt value. Take care of non-square pixels */
89 /* if necessary */
Werner Lemberg4a2305c2001-06-28 07:17:51 +000090 typedef void
Werner Lemberg91db04c2002-04-01 14:25:28 +000091 (*TT_Set_CVT_Func)( EXEC_OP_ FT_ULong idx,
Werner Lemberg4a2305c2001-06-28 07:17:51 +000092 FT_F26Dot6 value );
David Turnerd2b1f351999-12-16 23:11:37 +000093
94
95 /*************************************************************************/
96 /* */
97 /* This structure defines a call record, used to manage function calls. */
98 /* */
99 typedef struct TT_CallRec_
100 {
David Turnerf9b8dec2000-06-16 19:34:52 +0000101 FT_Int Caller_Range;
102 FT_Long Caller_IP;
103 FT_Long Cur_Count;
104 FT_Long Cur_Restart;
David Turnerd2b1f351999-12-16 23:11:37 +0000105
106 } TT_CallRec, *TT_CallStack;
107
108
109 /*************************************************************************/
110 /* */
111 /* The main structure for the interpreter which collects all necessary */
112 /* variables and states. */
113 /* */
114 typedef struct TT_ExecContextRec_
115 {
Werner Lemberg91db04c2002-04-01 14:25:28 +0000116 TT_Face face;
117 TT_Size size;
118 FT_Memory memory;
David Turnerd2b1f351999-12-16 23:11:37 +0000119
120 /* instructions state */
121
Werner Lemberg91db04c2002-04-01 14:25:28 +0000122 FT_Error error; /* last execution error */
David Turnerd2b1f351999-12-16 23:11:37 +0000123
Werner Lemberg91db04c2002-04-01 14:25:28 +0000124 FT_Long top; /* top of exec. stack */
David Turnerd2b1f351999-12-16 23:11:37 +0000125
Werner Lemberg91db04c2002-04-01 14:25:28 +0000126 FT_UInt stackSize; /* size of exec. stack */
127 FT_Long* stack; /* current exec. stack */
David Turnerd2b1f351999-12-16 23:11:37 +0000128
Werner Lemberg91db04c2002-04-01 14:25:28 +0000129 FT_Long args;
130 FT_UInt new_top; /* new top after exec. */
David Turnerd2b1f351999-12-16 23:11:37 +0000131
David Turnerb5713c52002-03-14 11:26:29 +0000132 TT_GlyphZoneRec zp0, /* zone records */
Werner Lemberg91db04c2002-04-01 14:25:28 +0000133 zp1,
134 zp2,
135 pts,
136 twilight;
David Turnerd2b1f351999-12-16 23:11:37 +0000137
Werner Lemberg91db04c2002-04-01 14:25:28 +0000138 FT_Size_Metrics metrics;
139 TT_Size_Metrics tt_metrics; /* size metrics */
David Turnerd2b1f351999-12-16 23:11:37 +0000140
Werner Lemberg91db04c2002-04-01 14:25:28 +0000141 TT_GraphicsState GS; /* current graphics state */
David Turnerd2b1f351999-12-16 23:11:37 +0000142
Werner Lemberg91db04c2002-04-01 14:25:28 +0000143 FT_Int curRange; /* current code range number */
144 FT_Byte* code; /* current code range */
145 FT_Long IP; /* current instruction pointer */
146 FT_Long codeSize; /* size of current range */
David Turnerd2b1f351999-12-16 23:11:37 +0000147
Werner Lemberg91db04c2002-04-01 14:25:28 +0000148 FT_Byte opcode; /* current opcode */
149 FT_Int length; /* length of current opcode */
David Turnerd2b1f351999-12-16 23:11:37 +0000150
Werner Lemberg91db04c2002-04-01 14:25:28 +0000151 FT_Bool step_ins; /* true if the interpreter must */
152 /* increment IP after ins. exec */
Werner Lemberg346f1862010-08-06 00:47:57 +0200153 FT_ULong cvtSize;
Werner Lemberg91db04c2002-04-01 14:25:28 +0000154 FT_Long* cvt;
David Turnerd2b1f351999-12-16 23:11:37 +0000155
Werner Lemberg91db04c2002-04-01 14:25:28 +0000156 FT_UInt glyphSize; /* glyph instructions buffer size */
157 FT_Byte* glyphIns; /* glyph instructions buffer */
David Turnerd2b1f351999-12-16 23:11:37 +0000158
Werner Lemberg91db04c2002-04-01 14:25:28 +0000159 FT_UInt numFDefs; /* number of function defs */
160 FT_UInt maxFDefs; /* maximum number of function defs */
161 TT_DefArray FDefs; /* table of FDefs entries */
David Turnerd2b1f351999-12-16 23:11:37 +0000162
Werner Lemberg91db04c2002-04-01 14:25:28 +0000163 FT_UInt numIDefs; /* number of instruction defs */
164 FT_UInt maxIDefs; /* maximum number of ins defs */
165 TT_DefArray IDefs; /* table of IDefs entries */
David Turnerd2b1f351999-12-16 23:11:37 +0000166
Werner Lemberg91db04c2002-04-01 14:25:28 +0000167 FT_UInt maxFunc; /* maximum function index */
168 FT_UInt maxIns; /* maximum instruction index */
David Turnerd2b1f351999-12-16 23:11:37 +0000169
Werner Lemberg91db04c2002-04-01 14:25:28 +0000170 FT_Int callTop, /* top of call stack during execution */
171 callSize; /* size of call stack */
172 TT_CallStack callStack; /* call stack */
David Turnerd2b1f351999-12-16 23:11:37 +0000173
Werner Lemberg91db04c2002-04-01 14:25:28 +0000174 FT_UShort maxPoints; /* capacity of this context's `pts' */
175 FT_Short maxContours; /* record, expressed in points and */
176 /* contours. */
David Turnerd2b1f351999-12-16 23:11:37 +0000177
178 TT_CodeRangeTable codeRangeTable; /* table of valid code ranges */
179 /* useful for the debugger */
180
Werner Lemberg91db04c2002-04-01 14:25:28 +0000181 FT_UShort storeSize; /* size of current storage */
182 FT_Long* storage; /* storage area */
David Turnerd2b1f351999-12-16 23:11:37 +0000183
Werner Lemberg91db04c2002-04-01 14:25:28 +0000184 FT_F26Dot6 period; /* values used for the */
185 FT_F26Dot6 phase; /* `SuperRounding' */
186 FT_F26Dot6 threshold;
David Turnerd2b1f351999-12-16 23:11:37 +0000187
David Turnerd2b1f351999-12-16 23:11:37 +0000188#if 0
Werner Lemberg5811c7c2000-07-02 13:53:16 +0000189 /* this seems to be unused */
Werner Lemberg91db04c2002-04-01 14:25:28 +0000190 FT_Int cur_ppem; /* ppem along the current proj vector */
David Turnerd2b1f351999-12-16 23:11:37 +0000191#endif
Werner Lemberg5811c7c2000-07-02 13:53:16 +0000192
Werner Lemberg91db04c2002-04-01 14:25:28 +0000193 FT_Bool instruction_trap; /* If `True', the interpreter will */
194 /* exit after each instruction */
David Turnerd2b1f351999-12-16 23:11:37 +0000195
Werner Lemberg91db04c2002-04-01 14:25:28 +0000196 TT_GraphicsState default_GS; /* graphics state resulting from */
197 /* the prep program */
198 FT_Bool is_composite; /* true if the glyph is composite */
199 FT_Bool pedantic_hinting; /* true if pedantic interpretation */
David Turnerd2b1f351999-12-16 23:11:37 +0000200
201 /* latest interpreter additions */
202
David Turnerf9b8dec2000-06-16 19:34:52 +0000203 FT_Long F_dot_P; /* dot product of freedom and projection */
David Turnerd2b1f351999-12-16 23:11:37 +0000204 /* vectors */
205 TT_Round_Func func_round; /* current rounding function */
206
207 TT_Project_Func func_project, /* current projection function */
208 func_dualproj, /* current dual proj. function */
209 func_freeProj; /* current freedom proj. func */
210
211 TT_Move_Func func_move; /* current point move function */
Werner Lembergbe67c4e2003-11-24 22:54:58 +0000212 TT_Move_Func func_move_orig; /* move original position function */
David Turnerd2b1f351999-12-16 23:11:37 +0000213
214 TT_Get_CVT_Func func_read_cvt; /* read a cvt entry */
215 TT_Set_CVT_Func func_write_cvt; /* write a cvt entry (in pixels) */
216 TT_Set_CVT_Func func_move_cvt; /* incr a cvt entry (in pixels) */
217
Werner Lembergdea712b2004-08-07 15:08:33 +0000218 FT_Bool grayscale; /* are we hinting for grayscale? */
219
David Turnerd2b1f351999-12-16 23:11:37 +0000220 } TT_ExecContextRec;
221
222
Werner Lembergbd5ae402000-07-05 04:32:02 +0000223 extern const TT_GraphicsState tt_default_graphics_state;
David Turnerd2b1f351999-12-16 23:11:37 +0000224
225
David Turnerbc82f1b2002-03-01 02:26:22 +0000226 FT_LOCAL( FT_Error )
Werner Lemberg4a2305c2001-06-28 07:17:51 +0000227 TT_Goto_CodeRange( TT_ExecContext exec,
228 FT_Int range,
229 FT_Long IP );
David Turnerd2b1f351999-12-16 23:11:37 +0000230
David Turnerbc82f1b2002-03-01 02:26:22 +0000231 FT_LOCAL( FT_Error )
Werner Lemberg4a2305c2001-06-28 07:17:51 +0000232 TT_Set_CodeRange( TT_ExecContext exec,
233 FT_Int range,
234 void* base,
235 FT_Long length );
David Turnerd2b1f351999-12-16 23:11:37 +0000236
David Turnerbc82f1b2002-03-01 02:26:22 +0000237 FT_LOCAL( FT_Error )
Werner Lemberg4a2305c2001-06-28 07:17:51 +0000238 TT_Clear_CodeRange( TT_ExecContext exec,
239 FT_Int range );
David Turnerd2b1f351999-12-16 23:11:37 +0000240
Werner Lemberg90a03302000-11-07 17:21:11 +0000241
Werner Lemberg6da023d2010-05-20 15:38:00 +0200242 FT_LOCAL( FT_Error )
243 Update_Max( FT_Memory memory,
244 FT_ULong* size,
245 FT_Long multiplier,
246 void* _pbuff,
247 FT_ULong new_max );
248
249
Werner Lemberg90a03302000-11-07 17:21:11 +0000250 /*************************************************************************/
251 /* */
252 /* <Function> */
253 /* TT_New_Context */
254 /* */
255 /* <Description> */
256 /* Queries the face context for a given font. Note that there is */
257 /* now a _single_ execution context in the TrueType driver which is */
258 /* shared among faces. */
259 /* */
260 /* <Input> */
261 /* face :: A handle to the source face object. */
262 /* */
263 /* <Return> */
264 /* A handle to the execution context. Initialized for `face'. */
265 /* */
266 /* <Note> */
267 /* Only the glyph loader and debugger should call this function. */
268 /* */
Werner Lemberg4a2305c2001-06-28 07:17:51 +0000269 FT_EXPORT( TT_ExecContext )
Wu, Chia-I (吳佳一)0142e6a2005-08-16 01:54:59 +0000270 TT_New_Context( TT_Driver driver );
Werner Lemberg90a03302000-11-07 17:21:11 +0000271
David Turnerbc82f1b2002-03-01 02:26:22 +0000272 FT_LOCAL( FT_Error )
Werner Lemberg4a2305c2001-06-28 07:17:51 +0000273 TT_Done_Context( TT_ExecContext exec );
David Turnerd2b1f351999-12-16 23:11:37 +0000274
David Turnerbc82f1b2002-03-01 02:26:22 +0000275 FT_LOCAL( FT_Error )
Werner Lemberg4a2305c2001-06-28 07:17:51 +0000276 TT_Load_Context( TT_ExecContext exec,
277 TT_Face face,
278 TT_Size size );
David Turnerd2b1f351999-12-16 23:11:37 +0000279
David Turnerbc82f1b2002-03-01 02:26:22 +0000280 FT_LOCAL( FT_Error )
Werner Lemberg4a2305c2001-06-28 07:17:51 +0000281 TT_Save_Context( TT_ExecContext exec,
282 TT_Size ins );
David Turnerd2b1f351999-12-16 23:11:37 +0000283
David Turnerbc82f1b2002-03-01 02:26:22 +0000284 FT_LOCAL( FT_Error )
Werner Lemberg4a2305c2001-06-28 07:17:51 +0000285 TT_Run_Context( TT_ExecContext exec,
286 FT_Bool debug );
David Turnerd2b1f351999-12-16 23:11:37 +0000287
Werner Lemberg90a03302000-11-07 17:21:11 +0000288
289 /*************************************************************************/
290 /* */
291 /* <Function> */
292 /* TT_RunIns */
293 /* */
294 /* <Description> */
295 /* Executes one or more instruction in the execution context. This */
296 /* is the main function of the TrueType opcode interpreter. */
297 /* */
298 /* <Input> */
299 /* exec :: A handle to the target execution context. */
300 /* */
301 /* <Return> */
302 /* FreeType error code. 0 means success. */
303 /* */
304 /* <Note> */
305 /* Only the object manager and debugger should call this function. */
306 /* */
307 /* This function is publicly exported because it is directly */
308 /* invoked by the TrueType debugger. */
309 /* */
Werner Lemberg4a2305c2001-06-28 07:17:51 +0000310 FT_EXPORT( FT_Error )
311 TT_RunIns( TT_ExecContext exec );
David Turnerd2b1f351999-12-16 23:11:37 +0000312
313
David Turner19ed8af2000-12-08 02:42:29 +0000314FT_END_HEADER
David Turnerd2b1f351999-12-16 23:11:37 +0000315
Werner Lemberg90d99642000-12-09 00:45:38 +0000316#endif /* __TTINTERP_H__ */
David Turnerd2b1f351999-12-16 23:11:37 +0000317
318
319/* END */