1 /***************************************************************************/
5 /* TrueType bytecode interpreter (specification). */
7 /* Copyright 1996-2007, 2010, 2012-2013 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 /* reading a cvt value. Take care of non-square pixels if necessary */
86 (*TT_Get_CVT_Func
)( EXEC_OP_ FT_ULong idx
);
88 /* setting or moving a cvt value. Take care of non-square pixels */
91 (*TT_Set_CVT_Func
)( EXEC_OP_ FT_ULong idx
,
95 /*************************************************************************/
97 /* This structure defines a call record, used to manage function calls. */
99 typedef struct TT_CallRec_
105 TT_DefRecord
*Def
; /* either FDEF or IDEF */
107 } TT_CallRec
, *TT_CallStack
;
110 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
112 /*************************************************************************/
114 /* These structures define rules used to tweak subpixel hinting for */
115 /* various fonts. "", 0, "", NULL value indicates to match any value. */
118 #define SPH_MAX_NAME_SIZE 32
119 #define SPH_MAX_CLASS_MEMBERS 100
121 typedef struct SPH_TweakRule_
123 const char family
[SPH_MAX_NAME_SIZE
];
125 const char style
[SPH_MAX_NAME_SIZE
];
126 const FT_ULong glyph
;
131 typedef struct SPH_ScaleRule_
133 const char family
[SPH_MAX_NAME_SIZE
];
135 const char style
[SPH_MAX_NAME_SIZE
];
136 const FT_ULong glyph
;
137 const FT_ULong scale
;
142 typedef struct SPH_Font_Class_
144 const char name
[SPH_MAX_NAME_SIZE
];
145 const char member
[SPH_MAX_CLASS_MEMBERS
][SPH_MAX_NAME_SIZE
];
149 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
152 /*************************************************************************/
154 /* The main structure for the interpreter which collects all necessary */
155 /* variables and states. */
157 typedef struct TT_ExecContextRec_
163 /* instructions state */
165 FT_Error error
; /* last execution error */
167 FT_Long top
; /* top of exec. stack */
169 FT_UInt stackSize
; /* size of exec. stack */
170 FT_Long
* stack
; /* current exec. stack */
173 FT_UInt new_top
; /* new top after exec. */
175 TT_GlyphZoneRec zp0
, /* zone records */
181 FT_Size_Metrics metrics
;
182 TT_Size_Metrics tt_metrics
; /* size metrics */
184 TT_GraphicsState GS
; /* current graphics state */
186 FT_Int curRange
; /* current code range number */
187 FT_Byte
* code
; /* current code range */
188 FT_Long IP
; /* current instruction pointer */
189 FT_Long codeSize
; /* size of current range */
191 FT_Byte opcode
; /* current opcode */
192 FT_Int length
; /* length of current opcode */
194 FT_Bool step_ins
; /* true if the interpreter must */
195 /* increment IP after ins. exec */
199 FT_UInt glyphSize
; /* glyph instructions buffer size */
200 FT_Byte
* glyphIns
; /* glyph instructions buffer */
202 FT_UInt numFDefs
; /* number of function defs */
203 FT_UInt maxFDefs
; /* maximum number of function defs */
204 TT_DefArray FDefs
; /* table of FDefs entries */
206 FT_UInt numIDefs
; /* number of instruction defs */
207 FT_UInt maxIDefs
; /* maximum number of ins defs */
208 TT_DefArray IDefs
; /* table of IDefs entries */
210 FT_UInt maxFunc
; /* maximum function index */
211 FT_UInt maxIns
; /* maximum instruction index */
213 FT_Int callTop
, /* top of call stack during execution */
214 callSize
; /* size of call stack */
215 TT_CallStack callStack
; /* call stack */
217 FT_UShort maxPoints
; /* capacity of this context's `pts' */
218 FT_Short maxContours
; /* record, expressed in points and */
221 TT_CodeRangeTable codeRangeTable
; /* table of valid code ranges */
222 /* useful for the debugger */
224 FT_UShort storeSize
; /* size of current storage */
225 FT_Long
* storage
; /* storage area */
227 FT_F26Dot6 period
; /* values used for the */
228 FT_F26Dot6 phase
; /* `SuperRounding' */
229 FT_F26Dot6 threshold
;
232 /* this seems to be unused */
233 FT_Int cur_ppem
; /* ppem along the current proj vector */
236 FT_Bool instruction_trap
; /* If `True', the interpreter will */
237 /* exit after each instruction */
239 TT_GraphicsState default_GS
; /* graphics state resulting from */
240 /* the prep program */
241 FT_Bool is_composite
; /* true if the glyph is composite */
242 FT_Bool pedantic_hinting
; /* true if pedantic interpretation */
244 /* latest interpreter additions */
246 FT_Long F_dot_P
; /* dot product of freedom and projection */
248 TT_Round_Func func_round
; /* current rounding function */
250 TT_Project_Func func_project
, /* current projection function */
251 func_dualproj
, /* current dual proj. function */
252 func_freeProj
; /* current freedom proj. func */
254 TT_Move_Func func_move
; /* current point move function */
255 TT_Move_Func func_move_orig
; /* move original position function */
257 TT_Get_CVT_Func func_read_cvt
; /* read a cvt entry */
258 TT_Set_CVT_Func func_write_cvt
; /* write a cvt entry (in pixels) */
259 TT_Set_CVT_Func func_move_cvt
; /* incr a cvt entry (in pixels) */
261 FT_Bool grayscale
; /* are we hinting for grayscale? */
263 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
264 TT_Round_Func func_round_sphn
; /* subpixel rounding function */
266 FT_Bool subpixel
; /* Using subpixel hinting? */
267 FT_Bool ignore_x_mode
; /* Standard rendering mode for */
268 /* subpixel hinting. On if gray */
269 /* or subpixel hinting is on. */
271 /* The following 4 aren't fully implemented but here for MS rasterizer */
273 FT_Bool compatible_widths
; /* compatible widths? */
274 FT_Bool symmetrical_smoothing
; /* symmetrical_smoothing? */
275 FT_Bool bgr
; /* bgr instead of rgb? */
276 FT_Bool subpixel_positioned
; /* subpixel positioned */
277 /* (DirectWrite ClearType)? */
279 FT_Int rasterizer_version
; /* MS rasterizer version */
281 FT_Bool iup_called
; /* IUP called for glyph? */
283 FT_ULong sph_tweak_flags
; /* flags to control */
286 FT_ULong sph_in_func_flags
; /* flags to indicate if in */
287 /* special functions */
289 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
294 extern const TT_GraphicsState tt_default_graphics_state
;
297 #ifdef TT_USE_BYTECODE_INTERPRETER
299 TT_Goto_CodeRange( TT_ExecContext exec
,
304 TT_Set_CodeRange( TT_ExecContext exec
,
310 TT_Clear_CodeRange( TT_ExecContext exec
,
315 Update_Max( FT_Memory memory
,
320 #endif /* TT_USE_BYTECODE_INTERPRETER */
323 /*************************************************************************/
329 /* Queries the face context for a given font. Note that there is */
330 /* now a _single_ execution context in the TrueType driver which is */
331 /* shared among faces. */
334 /* face :: A handle to the source face object. */
337 /* A handle to the execution context. Initialized for `face'. */
340 /* Only the glyph loader and debugger should call this function. */
342 FT_EXPORT( TT_ExecContext
)
343 TT_New_Context( TT_Driver driver
);
346 #ifdef TT_USE_BYTECODE_INTERPRETER
348 TT_Done_Context( TT_ExecContext exec
);
351 TT_Load_Context( TT_ExecContext exec
,
356 TT_Save_Context( TT_ExecContext exec
,
360 TT_Run_Context( TT_ExecContext exec
,
362 #endif /* TT_USE_BYTECODE_INTERPRETER */
365 /*************************************************************************/
371 /* Executes one or more instruction in the execution context. This */
372 /* is the main function of the TrueType opcode interpreter. */
375 /* exec :: A handle to the target execution context. */
378 /* FreeType error code. 0 means success. */
381 /* Only the object manager and debugger should call this function. */
383 /* This function is publicly exported because it is directly */
384 /* invoked by the TrueType debugger. */
386 FT_EXPORT( FT_Error
)
387 TT_RunIns( TT_ExecContext exec
);
392 #endif /* __TTINTERP_H__ */