1 /***************************************************************************/
5 /* TrueType bytecode interpreter (specification). */
7 /* Copyright 1996-2007, 2010, 2012-2014 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
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. */
16 /***************************************************************************/
19 #ifndef __TTINTERP_H__
20 #define __TTINTERP_H__
29 #ifndef TT_CONFIG_OPTION_STATIC_INTERPRETER /* indirect implementation */
31 #define EXEC_OP_ TT_ExecContext exc,
32 #define EXEC_OP TT_ExecContext exc
33 #define EXEC_ARG_ exc,
36 #else /* static implementation */
38 #define EXEC_OP_ /* void */
39 #define EXEC_OP /* void */
40 #define EXEC_ARG_ /* void */
41 #define EXEC_ARG /* void */
43 #endif /* TT_CONFIG_OPTION_STATIC_INTERPRETER */
46 /*************************************************************************/
48 /* Rounding mode constants. */
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
60 /*************************************************************************/
62 /* Function types used by the interpreter, depending on various modes */
63 /* (e.g. the rounding mode, whether to render a vertical or horizontal */
66 /*************************************************************************/
68 /* Rounding function */
70 (*TT_Round_Func)( EXEC_OP_ FT_F26Dot6 distance,
71 FT_F26Dot6 compensation );
73 /* Point displacement along the freedom vector routine */
75 (*TT_Move_Func)( EXEC_OP_ TT_GlyphZone zone,
77 FT_F26Dot6 distance );
79 /* Distance projection along one of the projection vectors */
81 (*TT_Project_Func)( EXEC_OP_ FT_Pos dx,
84 /* getting current ppem. Take care of non-square pixels if necessary */
86 (*TT_Cur_Ppem_Func)( EXEC_OP );
88 /* reading a cvt value. Take care of non-square pixels if necessary */
90 (*TT_Get_CVT_Func)( EXEC_OP_ FT_ULong idx );
92 /* setting or moving a cvt value. Take care of non-square pixels */
95 (*TT_Set_CVT_Func)( EXEC_OP_ FT_ULong idx,
99 /*************************************************************************/
101 /* This structure defines a call record, used to manage function calls. */
103 typedef struct TT_CallRec_
109 TT_DefRecord *Def; /* either FDEF or IDEF */
111 } TT_CallRec, *TT_CallStack;
114 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
116 /*************************************************************************/
118 /* These structures define rules used to tweak subpixel hinting for */
119 /* various fonts. "", 0, "", NULL value indicates to match any value. */
122 #define SPH_MAX_NAME_SIZE 32
123 #define SPH_MAX_CLASS_MEMBERS 100
125 typedef struct SPH_TweakRule_
127 const char family[SPH_MAX_NAME_SIZE];
129 const char style[SPH_MAX_NAME_SIZE];
130 const FT_ULong glyph;
135 typedef struct SPH_ScaleRule_
137 const char family[SPH_MAX_NAME_SIZE];
139 const char style[SPH_MAX_NAME_SIZE];
140 const FT_ULong glyph;
141 const FT_ULong scale;
146 typedef struct SPH_Font_Class_
148 const char name[SPH_MAX_NAME_SIZE];
149 const char member[SPH_MAX_CLASS_MEMBERS][SPH_MAX_NAME_SIZE];
153 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
156 /*************************************************************************/
158 /* The main structure for the interpreter which collects all necessary */
159 /* variables and states. */
161 typedef struct TT_ExecContextRec_
167 /* instructions state */
169 FT_Error error; /* last execution error */
171 FT_Long top; /* top of exec. stack */
173 FT_UInt stackSize; /* size of exec. stack */
174 FT_Long* stack; /* current exec. stack */
177 FT_UInt new_top; /* new top after exec. */
179 TT_GlyphZoneRec zp0, /* zone records */
185 FT_Size_Metrics metrics;
186 TT_Size_Metrics tt_metrics; /* size metrics */
188 TT_GraphicsState GS; /* current graphics state */
190 FT_Int curRange; /* current code range number */
191 FT_Byte* code; /* current code range */
192 FT_Long IP; /* current instruction pointer */
193 FT_Long codeSize; /* size of current range */
195 FT_Byte opcode; /* current opcode */
196 FT_Int length; /* length of current opcode */
198 FT_Bool step_ins; /* true if the interpreter must */
199 /* increment IP after ins. exec */
203 FT_UInt glyphSize; /* glyph instructions buffer size */
204 FT_Byte* glyphIns; /* glyph instructions buffer */
206 FT_UInt numFDefs; /* number of function defs */
207 FT_UInt maxFDefs; /* maximum number of function defs */
208 TT_DefArray FDefs; /* table of FDefs entries */
210 FT_UInt numIDefs; /* number of instruction defs */
211 FT_UInt maxIDefs; /* maximum number of ins defs */
212 TT_DefArray IDefs; /* table of IDefs entries */
214 FT_UInt maxFunc; /* maximum function index */
215 FT_UInt maxIns; /* maximum instruction index */
217 FT_Int callTop, /* top of call stack during execution */
218 callSize; /* size of call stack */
219 TT_CallStack callStack; /* call stack */
221 FT_UShort maxPoints; /* capacity of this context's `pts' */
222 FT_Short maxContours; /* record, expressed in points and */
225 TT_CodeRangeTable codeRangeTable; /* table of valid code ranges */
226 /* useful for the debugger */
228 FT_UShort storeSize; /* size of current storage */
229 FT_Long* storage; /* storage area */
231 FT_F26Dot6 period; /* values used for the */
232 FT_F26Dot6 phase; /* `SuperRounding' */
233 FT_F26Dot6 threshold;
235 FT_Bool instruction_trap; /* If `True', the interpreter will */
236 /* exit after each instruction */
238 TT_GraphicsState default_GS; /* graphics state resulting from */
239 /* the prep program */
240 FT_Bool is_composite; /* true if the glyph is composite */
241 FT_Bool pedantic_hinting; /* true if pedantic interpretation */
243 /* latest interpreter additions */
245 FT_Long F_dot_P; /* dot product of freedom and projection */
247 TT_Round_Func func_round; /* current rounding function */
249 TT_Project_Func func_project, /* current projection function */
250 func_dualproj, /* current dual proj. function */
251 func_freeProj; /* current freedom proj. func */
253 TT_Move_Func func_move; /* current point move function */
254 TT_Move_Func func_move_orig; /* move original position function */
256 TT_Cur_Ppem_Func func_cur_ppem; /* get current proj. ppem value */
258 TT_Get_CVT_Func func_read_cvt; /* read a cvt entry */
259 TT_Set_CVT_Func func_write_cvt; /* write a cvt entry (in pixels) */
260 TT_Set_CVT_Func func_move_cvt; /* incr a cvt entry (in pixels) */
262 FT_Bool grayscale; /* are we hinting for grayscale? */
264 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
265 TT_Round_Func func_round_sphn; /* subpixel rounding function */
267 FT_Bool subpixel; /* Using subpixel hinting? */
268 FT_Bool ignore_x_mode; /* Standard rendering mode for */
269 /* subpixel hinting. On if gray */
270 /* or subpixel hinting is on. */
272 /* The following 4 aren't fully implemented but here for MS rasterizer */
274 FT_Bool compatible_widths; /* compatible widths? */
275 FT_Bool symmetrical_smoothing; /* symmetrical_smoothing? */
276 FT_Bool bgr; /* bgr instead of rgb? */
277 FT_Bool subpixel_positioned; /* subpixel positioned */
278 /* (DirectWrite ClearType)? */
280 FT_Int rasterizer_version; /* MS rasterizer version */
282 FT_Bool iup_called; /* IUP called for glyph? */
284 FT_ULong sph_tweak_flags; /* flags to control */
287 FT_ULong sph_in_func_flags; /* flags to indicate if in */
288 /* special functions */
290 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
295 extern const TT_GraphicsState tt_default_graphics_state;
298 #ifdef TT_USE_BYTECODE_INTERPRETER
300 TT_Goto_CodeRange( TT_ExecContext exec,
305 TT_Set_CodeRange( TT_ExecContext exec,
311 TT_Clear_CodeRange( TT_ExecContext exec,
316 Update_Max( FT_Memory memory,
321 #endif /* TT_USE_BYTECODE_INTERPRETER */
324 /*************************************************************************/
330 /* Queries the face context for a given font. Note that there is */
331 /* now a _single_ execution context in the TrueType driver which is */
332 /* shared among faces. */
335 /* face :: A handle to the source face object. */
338 /* A handle to the execution context. Initialized for `face'. */
341 /* Only the glyph loader and debugger should call this function. */
343 FT_EXPORT( TT_ExecContext )
344 TT_New_Context( TT_Driver driver );
347 #ifdef TT_USE_BYTECODE_INTERPRETER
349 TT_Done_Context( TT_ExecContext exec );
352 TT_Load_Context( TT_ExecContext exec,
357 TT_Save_Context( TT_ExecContext exec,
361 TT_Run_Context( TT_ExecContext exec,
363 #endif /* TT_USE_BYTECODE_INTERPRETER */
366 /*************************************************************************/
372 /* Executes one or more instruction in the execution context. This */
373 /* is the main function of the TrueType opcode interpreter. */
376 /* exec :: A handle to the target execution context. */
379 /* FreeType error code. 0 means success. */
382 /* Only the object manager and debugger should call this function. */
384 /* This function is publicly exported because it is directly */
385 /* invoked by the TrueType debugger. */
387 FT_EXPORT( FT_Error )
388 TT_RunIns( TT_ExecContext exec );
393 #endif /* __TTINTERP_H__ */