ttinterp.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /***************************************************************************/
  2. /* */
  3. /* ttinterp.h */
  4. /* */
  5. /* TrueType bytecode interpreter (specification). */
  6. /* */
  7. /* Copyright 1996-2001, 2002 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. #ifndef __TTINTERP_H__
  18. #define __TTINTERP_H__
  19. #include <ft2build.h>
  20. #include "ttobjs.h"
  21. FT_BEGIN_HEADER
  22. #ifndef TT_CONFIG_OPTION_STATIC_INTEPRETER /* indirect implementation */
  23. #define EXEC_OP_ TT_ExecContext exc,
  24. #define EXEC_OP TT_ExecContext exc
  25. #define EXEC_ARG_ exc,
  26. #define EXEC_ARG exc
  27. #else /* static implementation */
  28. #define EXEC_OP_ /* void */
  29. #define EXEC_OP /* void */
  30. #define EXEC_ARG_ /* void */
  31. #define EXEC_ARG /* void */
  32. #endif /* TT_CONFIG_OPTION_STATIC_INTERPRETER */
  33. /*************************************************************************/
  34. /* */
  35. /* Rounding mode constants. */
  36. /* */
  37. #define TT_Round_Off 5
  38. #define TT_Round_To_Half_Grid 0
  39. #define TT_Round_To_Grid 1
  40. #define TT_Round_To_Double_Grid 2
  41. #define TT_Round_Up_To_Grid 4
  42. #define TT_Round_Down_To_Grid 3
  43. #define TT_Round_Super 6
  44. #define TT_Round_Super_45 7
  45. /*************************************************************************/
  46. /* */
  47. /* Function types used by the interpreter, depending on various modes */
  48. /* (e.g. the rounding mode, whether to render a vertical or horizontal */
  49. /* line etc). */
  50. /* */
  51. /*************************************************************************/
  52. /* Rounding function */
  53. typedef FT_F26Dot6
  54. (*TT_Round_Func)( EXEC_OP_ FT_F26Dot6 distance,
  55. FT_F26Dot6 compensation );
  56. /* Point displacement along the freedom vector routine */
  57. typedef void
  58. (*TT_Move_Func)( EXEC_OP_ TT_GlyphZone zone,
  59. FT_UShort point,
  60. FT_F26Dot6 distance );
  61. /* Distance projection along one of the projection vectors */
  62. typedef FT_F26Dot6
  63. (*TT_Project_Func)( EXEC_OP_ FT_Vector* v1,
  64. FT_Vector* v2 );
  65. /* reading a cvt value. Take care of non-square pixels if necessary */
  66. typedef FT_F26Dot6
  67. (*TT_Get_CVT_Func)( EXEC_OP_ FT_ULong idx );
  68. /* setting or moving a cvt value. Take care of non-square pixels */
  69. /* if necessary */
  70. typedef void
  71. (*TT_Set_CVT_Func)( EXEC_OP_ FT_ULong idx,
  72. FT_F26Dot6 value );
  73. /*************************************************************************/
  74. /* */
  75. /* This structure defines a call record, used to manage function calls. */
  76. /* */
  77. typedef struct TT_CallRec_
  78. {
  79. FT_Int Caller_Range;
  80. FT_Long Caller_IP;
  81. FT_Long Cur_Count;
  82. FT_Long Cur_Restart;
  83. } TT_CallRec, *TT_CallStack;
  84. /*************************************************************************/
  85. /* */
  86. /* The main structure for the interpreter which collects all necessary */
  87. /* variables and states. */
  88. /* */
  89. typedef struct TT_ExecContextRec_
  90. {
  91. TT_Face face;
  92. TT_Size size;
  93. FT_Memory memory;
  94. /* instructions state */
  95. FT_Error error; /* last execution error */
  96. FT_Long top; /* top of exec. stack */
  97. FT_UInt stackSize; /* size of exec. stack */
  98. FT_Long* stack; /* current exec. stack */
  99. FT_Long args;
  100. FT_UInt new_top; /* new top after exec. */
  101. TT_GlyphZoneRec zp0, /* zone records */
  102. zp1,
  103. zp2,
  104. pts,
  105. twilight;
  106. FT_Size_Metrics metrics;
  107. TT_Size_Metrics tt_metrics; /* size metrics */
  108. TT_GraphicsState GS; /* current graphics state */
  109. FT_Int curRange; /* current code range number */
  110. FT_Byte* code; /* current code range */
  111. FT_Long IP; /* current instruction pointer */
  112. FT_Long codeSize; /* size of current range */
  113. FT_Byte opcode; /* current opcode */
  114. FT_Int length; /* length of current opcode */
  115. FT_Bool step_ins; /* true if the interpreter must */
  116. /* increment IP after ins. exec */
  117. FT_Long cvtSize;
  118. FT_Long* cvt;
  119. FT_UInt glyphSize; /* glyph instructions buffer size */
  120. FT_Byte* glyphIns; /* glyph instructions buffer */
  121. FT_UInt numFDefs; /* number of function defs */
  122. FT_UInt maxFDefs; /* maximum number of function defs */
  123. TT_DefArray FDefs; /* table of FDefs entries */
  124. FT_UInt numIDefs; /* number of instruction defs */
  125. FT_UInt maxIDefs; /* maximum number of ins defs */
  126. TT_DefArray IDefs; /* table of IDefs entries */
  127. FT_UInt maxFunc; /* maximum function index */
  128. FT_UInt maxIns; /* maximum instruction index */
  129. FT_Int callTop, /* top of call stack during execution */
  130. callSize; /* size of call stack */
  131. TT_CallStack callStack; /* call stack */
  132. FT_UShort maxPoints; /* capacity of this context's `pts' */
  133. FT_Short maxContours; /* record, expressed in points and */
  134. /* contours. */
  135. TT_CodeRangeTable codeRangeTable; /* table of valid code ranges */
  136. /* useful for the debugger */
  137. FT_UShort storeSize; /* size of current storage */
  138. FT_Long* storage; /* storage area */
  139. FT_F26Dot6 period; /* values used for the */
  140. FT_F26Dot6 phase; /* `SuperRounding' */
  141. FT_F26Dot6 threshold;
  142. #if 0
  143. /* this seems to be unused */
  144. FT_Int cur_ppem; /* ppem along the current proj vector */
  145. #endif
  146. FT_Bool instruction_trap; /* If `True', the interpreter will */
  147. /* exit after each instruction */
  148. TT_GraphicsState default_GS; /* graphics state resulting from */
  149. /* the prep program */
  150. FT_Bool is_composite; /* true if the glyph is composite */
  151. FT_Bool pedantic_hinting; /* true if pedantic interpretation */
  152. /* latest interpreter additions */
  153. FT_Long F_dot_P; /* dot product of freedom and projection */
  154. /* vectors */
  155. TT_Round_Func func_round; /* current rounding function */
  156. TT_Project_Func func_project, /* current projection function */
  157. func_dualproj, /* current dual proj. function */
  158. func_freeProj; /* current freedom proj. func */
  159. TT_Move_Func func_move; /* current point move function */
  160. TT_Get_CVT_Func func_read_cvt; /* read a cvt entry */
  161. TT_Set_CVT_Func func_write_cvt; /* write a cvt entry (in pixels) */
  162. TT_Set_CVT_Func func_move_cvt; /* incr a cvt entry (in pixels) */
  163. FT_ULong loadSize;
  164. TT_SubGlyph_Stack loadStack; /* loading subglyph stack */
  165. } TT_ExecContextRec;
  166. extern const TT_GraphicsState tt_default_graphics_state;
  167. FT_LOCAL( FT_Error )
  168. TT_Goto_CodeRange( TT_ExecContext exec,
  169. FT_Int range,
  170. FT_Long IP );
  171. FT_LOCAL( FT_Error )
  172. TT_Set_CodeRange( TT_ExecContext exec,
  173. FT_Int range,
  174. void* base,
  175. FT_Long length );
  176. FT_LOCAL( FT_Error )
  177. TT_Clear_CodeRange( TT_ExecContext exec,
  178. FT_Int range );
  179. /*************************************************************************/
  180. /* */
  181. /* <Function> */
  182. /* TT_New_Context */
  183. /* */
  184. /* <Description> */
  185. /* Queries the face context for a given font. Note that there is */
  186. /* now a _single_ execution context in the TrueType driver which is */
  187. /* shared among faces. */
  188. /* */
  189. /* <Input> */
  190. /* face :: A handle to the source face object. */
  191. /* */
  192. /* <Return> */
  193. /* A handle to the execution context. Initialized for `face'. */
  194. /* */
  195. /* <Note> */
  196. /* Only the glyph loader and debugger should call this function. */
  197. /* */
  198. FT_EXPORT( TT_ExecContext )
  199. TT_New_Context( TT_Face face );
  200. FT_LOCAL( FT_Error )
  201. TT_Done_Context( TT_ExecContext exec );
  202. FT_LOCAL( FT_Error )
  203. TT_Destroy_Context( TT_ExecContext exec,
  204. FT_Memory memory );
  205. FT_LOCAL( FT_Error )
  206. TT_Load_Context( TT_ExecContext exec,
  207. TT_Face face,
  208. TT_Size size );
  209. FT_LOCAL( FT_Error )
  210. TT_Save_Context( TT_ExecContext exec,
  211. TT_Size ins );
  212. FT_LOCAL( FT_Error )
  213. TT_Run_Context( TT_ExecContext exec,
  214. FT_Bool debug );
  215. /*************************************************************************/
  216. /* */
  217. /* <Function> */
  218. /* TT_RunIns */
  219. /* */
  220. /* <Description> */
  221. /* Executes one or more instruction in the execution context. This */
  222. /* is the main function of the TrueType opcode interpreter. */
  223. /* */
  224. /* <Input> */
  225. /* exec :: A handle to the target execution context. */
  226. /* */
  227. /* <Return> */
  228. /* FreeType error code. 0 means success. */
  229. /* */
  230. /* <Note> */
  231. /* Only the object manager and debugger should call this function. */
  232. /* */
  233. /* This function is publicly exported because it is directly */
  234. /* invoked by the TrueType debugger. */
  235. /* */
  236. FT_EXPORT( FT_Error )
  237. TT_RunIns( TT_ExecContext exec );
  238. FT_END_HEADER
  239. #endif /* __TTINTERP_H__ */
  240. /* END */