1 /***************************************************************************/ 
   5 /*    TrueType bytecode interpreter (specification).                       */ 
   7 /*  Copyright 1996-2000 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 /***************************************************************************/ 
  23 #ifdef FT_FLAT_COMPILE 
  29 #include <truetype/ttobjs.h> 
  39 #ifndef TT_CONFIG_OPTION_STATIC_INTEPRETER  /* indirect implementation */ 
  41 #define EXEC_OP_   TT_ExecContext  exc, 
  42 #define EXEC_OP    TT_ExecContext  exc 
  43 #define EXEC_ARG_  exc, 
  46 #else                                       /* static implementation */ 
  48 #define EXEC_OP_   /* void */ 
  49 #define EXEC_OP    /* void */ 
  50 #define EXEC_ARG_  /* void */ 
  51 #define EXEC_ARG   /* void */ 
  53 #endif /* TT_CONFIG_OPTION_STATIC_INTERPRETER */ 
  56   /*************************************************************************/ 
  58   /* Rounding mode constants.                                              */ 
  60 #define TT_Round_Off             5 
  61 #define TT_Round_To_Half_Grid    0 
  62 #define TT_Round_To_Grid         1 
  63 #define TT_Round_To_Double_Grid  2 
  64 #define TT_Round_Up_To_Grid      4 
  65 #define TT_Round_Down_To_Grid    3 
  66 #define TT_Round_Super           6 
  67 #define TT_Round_Super_45        7 
  70   /*************************************************************************/ 
  72   /* Function types used by the interpreter, depending on various modes    */ 
  73   /* (e.g. the rounding mode, whether to render a vertical or horizontal   */ 
  76   /*************************************************************************/ 
  78   /* Rounding function */ 
  79   typedef FT_F26Dot6  (*TT_Round_Func
)( EXEC_OP_ FT_F26Dot6  distance
, 
  80                                                  FT_F26Dot6  compensation 
); 
  82   /* Point displacement along the freedom vector routine */ 
  83   typedef void  (*TT_Move_Func
)( EXEC_OP_ TT_GlyphZone
*  zone
, 
  85                                           FT_F26Dot6     distance 
); 
  87   /* Distance projection along one of the projection vectors */ 
  88   typedef FT_F26Dot6  (*TT_Project_Func
)( EXEC_OP_ FT_Vector
*  v1
, 
  91   /* reading a cvt value.  Take care of non-square pixels if necessary */ 
  92   typedef FT_F26Dot6  (*TT_Get_CVT_Func
)( EXEC_OP_ FT_ULong  index 
); 
  94   /* setting or moving a cvt value.  Take care of non-square pixels  */ 
  96   typedef void  (*TT_Set_CVT_Func
)( EXEC_OP_ FT_ULong    index
, 
 100   /*************************************************************************/ 
 102   /* This structure defines a call record, used to manage function calls.  */ 
 104   typedef struct  TT_CallRec_
 
 111   } TT_CallRec
, *TT_CallStack
; 
 114   /*************************************************************************/ 
 116   /* The main structure for the interpreter which collects all necessary   */ 
 117   /* variables and states.                                                 */ 
 119   typedef struct  TT_ExecContextRec_
 
 125     /* instructions state */ 
 127     FT_Error        error
;      /* last execution error */ 
 129     FT_Long         top
;        /* top of exec. stack   */ 
 131     FT_UInt         stackSize
;  /* size of exec. stack  */ 
 132     FT_Long
*        stack
;      /* current exec. stack  */ 
 135     FT_UInt         new_top
;    /* new top after exec.  */ 
 137     TT_GlyphZone    zp0
,        /* zone records */ 
 143     FT_Size_Metrics  metrics
; 
 144     TT_Size_Metrics  tt_metrics
; /* size metrics */ 
 146     TT_GraphicsState  GS
;         /* current graphics state */ 
 148     FT_Int          curRange
;  /* current code range number   */ 
 149     FT_Byte
*        code
;      /* current code range          */ 
 150     FT_Long         IP
;        /* current instruction pointer */ 
 151     FT_Long         codeSize
;  /* size of current range       */ 
 153     FT_Byte         opcode
;    /* current opcode              */ 
 154     FT_Int          length
;    /* length of current opcode    */ 
 156     FT_Bool         step_ins
;  /* true if the interpreter must */ 
 157                                /* increment IP after ins. exec */ 
 161     FT_UInt         glyphSize
; /* glyph instructions buffer size */ 
 162     FT_Byte
*        glyphIns
;  /* glyph instructions buffer */ 
 164     FT_UInt         numFDefs
;  /* number of function defs         */ 
 165     FT_UInt         maxFDefs
;  /* maximum number of function defs */ 
 166     TT_DefArray     FDefs
;     /* table of FDefs entries          */ 
 168     FT_UInt         numIDefs
;  /* number of instruction defs */ 
 169     FT_UInt         maxIDefs
;  /* maximum number of ins defs */ 
 170     TT_DefArray     IDefs
;     /* table of IDefs entries     */ 
 172     FT_UInt         maxFunc
;   /* maximum function index     */ 
 173     FT_UInt         maxIns
;    /* maximum instruction index  */ 
 175     FT_Int          callTop
,    /* top of call stack during execution */ 
 176                     callSize
;   /* size of call stack */ 
 177     TT_CallStack    callStack
;  /* call stack */ 
 179     FT_UShort       maxPoints
;    /* capacity of this context's `pts' */ 
 180     FT_Short        maxContours
;  /* record, expressed in points and  */ 
 183     TT_CodeRangeTable  codeRangeTable
;  /* table of valid code ranges */ 
 184                                         /* useful for the debugger   */ 
 186     FT_UShort       storeSize
;  /* size of current storage */ 
 187     FT_Long
*        storage
;    /* storage area            */ 
 189     FT_F26Dot6      period
;     /* values used for the */ 
 190     FT_F26Dot6      phase
;      /* `SuperRounding'     */ 
 191     FT_F26Dot6      threshold
; 
 194     /* this seems to be unused */ 
 195     FT_Int          cur_ppem
;       /* ppem along the current proj vector */ 
 198     FT_Bool         instruction_trap
;  /* If `True', the interpreter will */ 
 199                                        /* exit after each instruction     */ 
 201     TT_GraphicsState  default_GS
;      /* graphics state resulting from    */ 
 202                                        /* the prep program                 */ 
 203     FT_Bool          is_composite
;     /* true if the glyph is composite   */ 
 204     FT_Bool          pedantic_hinting
; /* true for pedantic interpretation */ 
 206     /* latest interpreter additions */ 
 208     FT_Long            F_dot_P
;    /* dot product of freedom and projection */ 
 210     TT_Round_Func      func_round
; /* current rounding function             */ 
 212     TT_Project_Func    func_project
,   /* current projection function */ 
 213                        func_dualproj
,  /* current dual proj. function */ 
 214                        func_freeProj
;  /* current freedom proj. func  */ 
 216     TT_Move_Func       func_move
;      /* current point move function */ 
 218     TT_Get_CVT_Func    func_read_cvt
;  /* read a cvt entry              */ 
 219     TT_Set_CVT_Func    func_write_cvt
; /* write a cvt entry (in pixels) */ 
 220     TT_Set_CVT_Func    func_move_cvt
;  /* incr a cvt entry (in pixels)  */ 
 223     TT_SubGlyph_Stack  loadStack
;      /* loading subglyph stack */ 
 228   extern const TT_GraphicsState  tt_default_graphics_state
; 
 232   FT_Error  
TT_Goto_CodeRange( TT_ExecContext  exec
, 
 237   FT_Error  
TT_Set_CodeRange( TT_ExecContext  exec
, 
 243   FT_Error  
TT_Clear_CodeRange( TT_ExecContext  exec
, 
 246   FT_EXPORT_DEF( TT_ExecContext 
)  TT_New_Context( TT_Face  face 
); 
 249   FT_Error  
TT_Done_Context( TT_ExecContext  exec 
); 
 252   FT_Error  
TT_Destroy_Context( TT_ExecContext  exec
, 
 256   FT_Error  
TT_Load_Context( TT_ExecContext  exec
, 
 261   FT_Error  
TT_Save_Context( TT_ExecContext  exec
, 
 265   FT_Error  
TT_Run_Context( TT_ExecContext  exec
, 
 268   FT_EXPORT_DEF( FT_Error 
)  TT_RunIns( TT_ExecContext  exec 
); 
 275 #endif /* TTINTERP_H */