| 1 | /***************************************************************************/ |
|---|
| 2 | /* */ |
|---|
| 3 | /* ttinterp.h */ |
|---|
| 4 | /* */ |
|---|
| 5 | /* TrueType bytecode interpreter (specification). */ |
|---|
| 6 | /* */ |
|---|
| 7 | /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007 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 __TTINTERP_H__ |
|---|
| 20 | #define __TTINTERP_H__ |
|---|
| 21 | |
|---|
| 22 | #include <ft2build.h> |
|---|
| 23 | #include "ttobjs.h" |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | FT_BEGIN_HEADER |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | #ifndef TT_CONFIG_OPTION_STATIC_INTERPRETER /* indirect implementation */ |
|---|
| 30 | |
|---|
| 31 | #define EXEC_OP_ TT_ExecContext exc, |
|---|
| 32 | #define EXEC_OP TT_ExecContext exc |
|---|
| 33 | #define EXEC_ARG_ exc, |
|---|
| 34 | #define EXEC_ARG exc |
|---|
| 35 | |
|---|
| 36 | #else /* static implementation */ |
|---|
| 37 | |
|---|
| 38 | #define EXEC_OP_ /* void */ |
|---|
| 39 | #define EXEC_OP /* void */ |
|---|
| 40 | #define EXEC_ARG_ /* void */ |
|---|
| 41 | #define EXEC_ARG /* void */ |
|---|
| 42 | |
|---|
| 43 | #endif /* TT_CONFIG_OPTION_STATIC_INTERPRETER */ |
|---|
| 44 | |
|---|
| 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 */ |
|---|
| 69 | typedef FT_F26Dot6 |
|---|
| 70 | (*TT_Round_Func)( EXEC_OP_ FT_F26Dot6 distance, |
|---|
| 71 | FT_F26Dot6 compensation ); |
|---|
| 72 | |
|---|
| 73 | /* Point displacement along the freedom vector routine */ |
|---|
| 74 | typedef void |
|---|
| 75 | (*TT_Move_Func)( EXEC_OP_ TT_GlyphZone zone, |
|---|
| 76 | FT_UShort point, |
|---|
| 77 | FT_F26Dot6 distance ); |
|---|
| 78 | |
|---|
| 79 | /* Distance projection along one of the projection vectors */ |
|---|
| 80 | typedef FT_F26Dot6 |
|---|
| 81 | (*TT_Project_Func)( EXEC_OP_ FT_Pos dx, |
|---|
| 82 | FT_Pos dy ); |
|---|
| 83 | |
|---|
| 84 | /* reading a cvt value. Take care of non-square pixels if necessary */ |
|---|
| 85 | typedef FT_F26Dot6 |
|---|
| 86 | (*TT_Get_CVT_Func)( EXEC_OP_ FT_ULong idx ); |
|---|
| 87 | |
|---|
| 88 | /* setting or moving a cvt value. Take care of non-square pixels */ |
|---|
| 89 | /* if necessary */ |
|---|
| 90 | typedef void |
|---|
| 91 | (*TT_Set_CVT_Func)( EXEC_OP_ FT_ULong idx, |
|---|
| 92 | FT_F26Dot6 value ); |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | /*************************************************************************/ |
|---|
| 96 | /* */ |
|---|
| 97 | /* This structure defines a call record, used to manage function calls. */ |
|---|
| 98 | /* */ |
|---|
| 99 | typedef struct TT_CallRec_ |
|---|
| 100 | { |
|---|
| 101 | FT_Int Caller_Range; |
|---|
| 102 | FT_Long Caller_IP; |
|---|
| 103 | FT_Long Cur_Count; |
|---|
| 104 | FT_Long Cur_Restart; |
|---|
| 105 | |
|---|
| 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 | { |
|---|
| 116 | TT_Face face; |
|---|
| 117 | TT_Size size; |
|---|
| 118 | FT_Memory memory; |
|---|
| 119 | |
|---|
| 120 | /* instructions state */ |
|---|
| 121 | |
|---|
| 122 | FT_Error error; /* last execution error */ |
|---|
| 123 | |
|---|
| 124 | FT_Long top; /* top of exec. stack */ |
|---|
| 125 | |
|---|
| 126 | FT_UInt stackSize; /* size of exec. stack */ |
|---|
| 127 | FT_Long* stack; /* current exec. stack */ |
|---|
| 128 | |
|---|
| 129 | FT_Long args; |
|---|
| 130 | FT_UInt new_top; /* new top after exec. */ |
|---|
| 131 | |
|---|
| 132 | TT_GlyphZoneRec zp0, /* zone records */ |
|---|
| 133 | zp1, |
|---|
| 134 | zp2, |
|---|
| 135 | pts, |
|---|
| 136 | twilight; |
|---|
| 137 | |
|---|
| 138 | FT_Size_Metrics metrics; |
|---|
| 139 | TT_Size_Metrics tt_metrics; /* size metrics */ |
|---|
| 140 | |
|---|
| 141 | TT_GraphicsState GS; /* current graphics state */ |
|---|
| 142 | |
|---|
| 143 | 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 */ |
|---|
| 147 | |
|---|
| 148 | FT_Byte opcode; /* current opcode */ |
|---|
| 149 | FT_Int length; /* length of current opcode */ |
|---|
| 150 | |
|---|
| 151 | FT_Bool step_ins; /* true if the interpreter must */ |
|---|
| 152 | /* increment IP after ins. exec */ |
|---|
| 153 | FT_Long cvtSize; |
|---|
| 154 | FT_Long* cvt; |
|---|
| 155 | |
|---|
| 156 | FT_UInt glyphSize; /* glyph instructions buffer size */ |
|---|
| 157 | FT_Byte* glyphIns; /* glyph instructions buffer */ |
|---|
| 158 | |
|---|
| 159 | FT_UInt numFDefs; /* number of function defs */ |
|---|
| 160 | FT_UInt maxFDefs; /* maximum number of function defs */ |
|---|
| 161 | TT_DefArray FDefs; /* table of FDefs entries */ |
|---|
| 162 | |
|---|
| 163 | FT_UInt numIDefs; /* number of instruction defs */ |
|---|
| 164 | FT_UInt maxIDefs; /* maximum number of ins defs */ |
|---|
| 165 | TT_DefArray IDefs; /* table of IDefs entries */ |
|---|
| 166 | |
|---|
| 167 | FT_UInt maxFunc; /* maximum function index */ |
|---|
| 168 | FT_UInt maxIns; /* maximum instruction index */ |
|---|
| 169 | |
|---|
| 170 | FT_Int callTop, /* top of call stack during execution */ |
|---|
| 171 | callSize; /* size of call stack */ |
|---|
| 172 | TT_CallStack callStack; /* call stack */ |
|---|
| 173 | |
|---|
| 174 | FT_UShort maxPoints; /* capacity of this context's `pts' */ |
|---|
| 175 | FT_Short maxContours; /* record, expressed in points and */ |
|---|
| 176 | /* contours. */ |
|---|
| 177 | |
|---|
| 178 | TT_CodeRangeTable codeRangeTable; /* table of valid code ranges */ |
|---|
| 179 | /* useful for the debugger */ |
|---|
| 180 | |
|---|
| 181 | FT_UShort storeSize; /* size of current storage */ |
|---|
| 182 | FT_Long* storage; /* storage area */ |
|---|
| 183 | |
|---|
| 184 | FT_F26Dot6 period; /* values used for the */ |
|---|
| 185 | FT_F26Dot6 phase; /* `SuperRounding' */ |
|---|
| 186 | FT_F26Dot6 threshold; |
|---|
| 187 | |
|---|
| 188 | #if 0 |
|---|
| 189 | /* this seems to be unused */ |
|---|
| 190 | FT_Int cur_ppem; /* ppem along the current proj vector */ |
|---|
| 191 | #endif |
|---|
| 192 | |
|---|
| 193 | FT_Bool instruction_trap; /* If `True', the interpreter will */ |
|---|
| 194 | /* exit after each instruction */ |
|---|
| 195 | |
|---|
| 196 | 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 */ |
|---|
| 200 | |
|---|
| 201 | /* latest interpreter additions */ |
|---|
| 202 | |
|---|
| 203 | FT_Long F_dot_P; /* dot product of freedom and projection */ |
|---|
| 204 | /* 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 */ |
|---|
| 212 | TT_Move_Func func_move_orig; /* move original position function */ |
|---|
| 213 | |
|---|
| 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 | |
|---|
| 218 | FT_Bool grayscale; /* are we hinting for grayscale? */ |
|---|
| 219 | |
|---|
| 220 | } TT_ExecContextRec; |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | extern const TT_GraphicsState tt_default_graphics_state; |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | FT_LOCAL( FT_Error ) |
|---|
| 227 | TT_Goto_CodeRange( TT_ExecContext exec, |
|---|
| 228 | FT_Int range, |
|---|
| 229 | FT_Long IP ); |
|---|
| 230 | |
|---|
| 231 | FT_LOCAL( FT_Error ) |
|---|
| 232 | TT_Set_CodeRange( TT_ExecContext exec, |
|---|
| 233 | FT_Int range, |
|---|
| 234 | void* base, |
|---|
| 235 | FT_Long length ); |
|---|
| 236 | |
|---|
| 237 | FT_LOCAL( FT_Error ) |
|---|
| 238 | TT_Clear_CodeRange( TT_ExecContext exec, |
|---|
| 239 | FT_Int range ); |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | /*************************************************************************/ |
|---|
| 243 | /* */ |
|---|
| 244 | /* <Function> */ |
|---|
| 245 | /* TT_New_Context */ |
|---|
| 246 | /* */ |
|---|
| 247 | /* <Description> */ |
|---|
| 248 | /* Queries the face context for a given font. Note that there is */ |
|---|
| 249 | /* now a _single_ execution context in the TrueType driver which is */ |
|---|
| 250 | /* shared among faces. */ |
|---|
| 251 | /* */ |
|---|
| 252 | /* <Input> */ |
|---|
| 253 | /* face :: A handle to the source face object. */ |
|---|
| 254 | /* */ |
|---|
| 255 | /* <Return> */ |
|---|
| 256 | /* A handle to the execution context. Initialized for `face'. */ |
|---|
| 257 | /* */ |
|---|
| 258 | /* <Note> */ |
|---|
| 259 | /* Only the glyph loader and debugger should call this function. */ |
|---|
| 260 | /* */ |
|---|
| 261 | FT_EXPORT( TT_ExecContext ) |
|---|
| 262 | TT_New_Context( TT_Driver driver ); |
|---|
| 263 | |
|---|
| 264 | FT_LOCAL( FT_Error ) |
|---|
| 265 | TT_Done_Context( TT_ExecContext exec ); |
|---|
| 266 | |
|---|
| 267 | FT_LOCAL( FT_Error ) |
|---|
| 268 | TT_Load_Context( TT_ExecContext exec, |
|---|
| 269 | TT_Face face, |
|---|
| 270 | TT_Size size ); |
|---|
| 271 | |
|---|
| 272 | FT_LOCAL( FT_Error ) |
|---|
| 273 | TT_Save_Context( TT_ExecContext exec, |
|---|
| 274 | TT_Size ins ); |
|---|
| 275 | |
|---|
| 276 | FT_LOCAL( FT_Error ) |
|---|
| 277 | TT_Run_Context( TT_ExecContext exec, |
|---|
| 278 | FT_Bool debug ); |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 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 | /* */ |
|---|
| 302 | FT_EXPORT( FT_Error ) |
|---|
| 303 | TT_RunIns( TT_ExecContext exec ); |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | FT_END_HEADER |
|---|
| 307 | |
|---|
| 308 | #endif /* __TTINTERP_H__ */ |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | /* END */ |
|---|