ttinterp.h
上传用户:yisoukefu
上传日期:2020-08-09
资源大小:39506k
文件大小:13k
源码类别:

其他游戏

开发平台:

Visual C++

  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. #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_INTERPRETER /* 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_Pos   dx,
  64.                                FT_Pos   dy );
  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_Move_Func       func_move_orig; /* move original position function */
  161.     TT_Get_CVT_Func    func_read_cvt;  /* read a cvt entry              */
  162.     TT_Set_CVT_Func    func_write_cvt; /* write a cvt entry (in pixels) */
  163.     TT_Set_CVT_Func    func_move_cvt;  /* incr a cvt entry (in pixels)  */
  164.     FT_Bool            grayscale;      /* are we hinting for grayscale? */
  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_Driver  driver );
  200.   FT_LOCAL( FT_Error )
  201.   TT_Done_Context( TT_ExecContext  exec );
  202.   FT_LOCAL( FT_Error )
  203.   TT_Load_Context( TT_ExecContext  exec,
  204.                    TT_Face         face,
  205.                    TT_Size         size );
  206.   FT_LOCAL( FT_Error )
  207.   TT_Save_Context( TT_ExecContext  exec,
  208.                    TT_Size         ins );
  209.   FT_LOCAL( FT_Error )
  210.   TT_Run_Context( TT_ExecContext  exec,
  211.                   FT_Bool         debug );
  212.   /*************************************************************************/
  213.   /*                                                                       */
  214.   /* <Function>                                                            */
  215.   /*    TT_RunIns                                                          */
  216.   /*                                                                       */
  217.   /* <Description>                                                         */
  218.   /*    Executes one or more instruction in the execution context.  This   */
  219.   /*    is the main function of the TrueType opcode interpreter.           */
  220.   /*                                                                       */
  221.   /* <Input>                                                               */
  222.   /*    exec :: A handle to the target execution context.                  */
  223.   /*                                                                       */
  224.   /* <Return>                                                              */
  225.   /*    FreeType error code.  0 means success.                             */
  226.   /*                                                                       */
  227.   /* <Note>                                                                */
  228.   /*    Only the object manager and debugger should call this function.    */
  229.   /*                                                                       */
  230.   /*    This function is publicly exported because it is directly          */
  231.   /*    invoked by the TrueType debugger.                                  */
  232.   /*                                                                       */
  233.   FT_EXPORT( FT_Error )
  234.   TT_RunIns( TT_ExecContext  exec );
  235. FT_END_HEADER
  236. #endif /* __TTINTERP_H__ */
  237. /* END */