tizen 2.3.1 release
[framework/graphics/freetype.git] / src / truetype / ttinterp.h
1 /***************************************************************************/
2 /*                                                                         */
3 /*  ttinterp.h                                                             */
4 /*                                                                         */
5 /*    TrueType bytecode interpreter (specification).                       */
6 /*                                                                         */
7 /*  Copyright 1996-2007, 2010, 2012-2014 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   /* getting current ppem.  Take care of non-square pixels if necessary */
85   typedef FT_Long
86   (*TT_Cur_Ppem_Func)( EXEC_OP );
87
88   /* reading a cvt value.  Take care of non-square pixels if necessary */
89   typedef FT_F26Dot6
90   (*TT_Get_CVT_Func)( EXEC_OP_ FT_ULong  idx );
91
92   /* setting or moving a cvt value.  Take care of non-square pixels  */
93   /* if necessary                                                    */
94   typedef void
95   (*TT_Set_CVT_Func)( EXEC_OP_ FT_ULong    idx,
96                                FT_F26Dot6  value );
97
98
99   /*************************************************************************/
100   /*                                                                       */
101   /* This structure defines a call record, used to manage function calls.  */
102   /*                                                                       */
103   typedef struct  TT_CallRec_
104   {
105     FT_Int   Caller_Range;
106     FT_Long  Caller_IP;
107     FT_Long  Cur_Count;
108
109     TT_DefRecord  *Def; /* either FDEF or IDEF */
110
111   } TT_CallRec, *TT_CallStack;
112
113
114 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
115
116   /*************************************************************************/
117   /*                                                                       */
118   /* These structures define rules used to tweak subpixel hinting for      */
119   /* various fonts.  "", 0, "", NULL value indicates to match any value.   */
120   /*                                                                       */
121
122 #define SPH_MAX_NAME_SIZE      32
123 #define SPH_MAX_CLASS_MEMBERS  100
124
125   typedef struct  SPH_TweakRule_
126   {
127     const char      family[SPH_MAX_NAME_SIZE];
128     const FT_UInt   ppem;
129     const char      style[SPH_MAX_NAME_SIZE];
130     const FT_ULong  glyph;
131
132   } SPH_TweakRule;
133
134
135   typedef struct  SPH_ScaleRule_
136   {
137     const char      family[SPH_MAX_NAME_SIZE];
138     const FT_UInt   ppem;
139     const char      style[SPH_MAX_NAME_SIZE];
140     const FT_ULong  glyph;
141     const FT_ULong  scale;
142
143   } SPH_ScaleRule;
144
145
146   typedef struct  SPH_Font_Class_
147   {
148     const char  name[SPH_MAX_NAME_SIZE];
149     const char  member[SPH_MAX_CLASS_MEMBERS][SPH_MAX_NAME_SIZE];
150
151   } SPH_Font_Class;
152
153 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
154
155
156   /*************************************************************************/
157   /*                                                                       */
158   /* The main structure for the interpreter which collects all necessary   */
159   /* variables and states.                                                 */
160   /*                                                                       */
161   typedef struct  TT_ExecContextRec_
162   {
163     TT_Face            face;
164     TT_Size            size;
165     FT_Memory          memory;
166
167     /* instructions state */
168
169     FT_Error           error;      /* last execution error */
170
171     FT_Long            top;        /* top of exec. stack   */
172
173     FT_UInt            stackSize;  /* size of exec. stack  */
174     FT_Long*           stack;      /* current exec. stack  */
175
176     FT_Long            args;
177     FT_UInt            new_top;    /* new top after exec.  */
178
179     TT_GlyphZoneRec    zp0,        /* zone records */
180                        zp1,
181                        zp2,
182                        pts,
183                        twilight;
184
185     FT_Size_Metrics    metrics;
186     TT_Size_Metrics    tt_metrics; /* size metrics */
187
188     TT_GraphicsState   GS;         /* current graphics state */
189
190     FT_Int             curRange;  /* current code range number   */
191     FT_Byte*           code;      /* current code range          */
192     FT_Long            IP;        /* current instruction pointer */
193     FT_Long            codeSize;  /* size of current range       */
194
195     FT_Byte            opcode;    /* current opcode              */
196     FT_Int             length;    /* length of current opcode    */
197
198     FT_Bool            step_ins;  /* true if the interpreter must */
199                                   /* increment IP after ins. exec */
200     FT_ULong           cvtSize;
201     FT_Long*           cvt;
202
203     FT_UInt            glyphSize; /* glyph instructions buffer size */
204     FT_Byte*           glyphIns;  /* glyph instructions buffer */
205
206     FT_UInt            numFDefs;  /* number of function defs         */
207     FT_UInt            maxFDefs;  /* maximum number of function defs */
208     TT_DefArray        FDefs;     /* table of FDefs entries          */
209
210     FT_UInt            numIDefs;  /* number of instruction defs */
211     FT_UInt            maxIDefs;  /* maximum number of ins defs */
212     TT_DefArray        IDefs;     /* table of IDefs entries     */
213
214     FT_UInt            maxFunc;   /* maximum function index     */
215     FT_UInt            maxIns;    /* maximum instruction index  */
216
217     FT_Int             callTop,    /* top of call stack during execution */
218                        callSize;   /* size of call stack */
219     TT_CallStack       callStack;  /* call stack */
220
221     FT_UShort          maxPoints;    /* capacity of this context's `pts' */
222     FT_Short           maxContours;  /* record, expressed in points and  */
223                                      /* contours.                        */
224
225     TT_CodeRangeTable  codeRangeTable;  /* table of valid code ranges */
226                                         /* useful for the debugger   */
227
228     FT_UShort          storeSize;  /* size of current storage */
229     FT_Long*           storage;    /* storage area            */
230
231     FT_F26Dot6         period;     /* values used for the */
232     FT_F26Dot6         phase;      /* `SuperRounding'     */
233     FT_F26Dot6         threshold;
234
235     FT_Bool            instruction_trap; /* If `True', the interpreter will */
236                                          /* exit after each instruction     */
237
238     TT_GraphicsState   default_GS;       /* graphics state resulting from   */
239                                          /* the prep program                */
240     FT_Bool            is_composite;     /* true if the glyph is composite  */
241     FT_Bool            pedantic_hinting; /* true if pedantic interpretation */
242
243     /* latest interpreter additions */
244
245     FT_Long            F_dot_P;    /* dot product of freedom and projection */
246                                    /* vectors                               */
247     TT_Round_Func      func_round; /* current rounding function             */
248
249     TT_Project_Func    func_project,   /* current projection function */
250                        func_dualproj,  /* current dual proj. function */
251                        func_freeProj;  /* current freedom proj. func  */
252
253     TT_Move_Func       func_move;      /* current point move function */
254     TT_Move_Func       func_move_orig; /* move original position function */
255
256     TT_Cur_Ppem_Func   func_cur_ppem;  /* get current proj. ppem value  */
257
258     TT_Get_CVT_Func    func_read_cvt;  /* read a cvt entry              */
259     TT_Set_CVT_Func    func_write_cvt; /* write a cvt entry (in pixels) */
260     TT_Set_CVT_Func    func_move_cvt;  /* incr a cvt entry (in pixels)  */
261
262     FT_Bool            grayscale;      /* are we hinting for grayscale? */
263
264 #ifdef TT_CONFIG_OPTION_SUBPIXEL_HINTING
265     TT_Round_Func      func_round_sphn;   /* subpixel rounding function */
266
267     FT_Bool            subpixel;          /* Using subpixel hinting?       */
268     FT_Bool            ignore_x_mode;     /* Standard rendering mode for   */
269                                           /* subpixel hinting.  On if gray */
270                                           /* or subpixel hinting is on.    */
271
272     /* The following 4 aren't fully implemented but here for MS rasterizer */
273     /* compatibility.                                                      */
274     FT_Bool            compatible_widths;     /* compatible widths?        */
275     FT_Bool            symmetrical_smoothing; /* symmetrical_smoothing?    */
276     FT_Bool            bgr;                   /* bgr instead of rgb?       */
277     FT_Bool            subpixel_positioned;   /* subpixel positioned       */
278                                               /* (DirectWrite ClearType)?  */
279
280     FT_Int             rasterizer_version;    /* MS rasterizer version     */
281
282     FT_Bool            iup_called;            /* IUP called for glyph?     */
283
284     FT_ULong           sph_tweak_flags;       /* flags to control          */
285                                               /* hint tweaks               */
286
287     FT_ULong           sph_in_func_flags;     /* flags to indicate if in   */
288                                               /* special functions         */
289
290 #endif /* TT_CONFIG_OPTION_SUBPIXEL_HINTING */
291
292   } TT_ExecContextRec;
293
294
295   extern const TT_GraphicsState  tt_default_graphics_state;
296
297
298 #ifdef TT_USE_BYTECODE_INTERPRETER
299   FT_LOCAL( void )
300   TT_Goto_CodeRange( TT_ExecContext  exec,
301                      FT_Int          range,
302                      FT_Long         IP );
303
304   FT_LOCAL( void )
305   TT_Set_CodeRange( TT_ExecContext  exec,
306                     FT_Int          range,
307                     void*           base,
308                     FT_Long         length );
309
310   FT_LOCAL( void )
311   TT_Clear_CodeRange( TT_ExecContext  exec,
312                       FT_Int          range );
313
314
315   FT_LOCAL( FT_Error )
316   Update_Max( FT_Memory  memory,
317               FT_ULong*  size,
318               FT_Long    multiplier,
319               void*      _pbuff,
320               FT_ULong   new_max );
321 #endif /* TT_USE_BYTECODE_INTERPRETER */
322
323
324   /*************************************************************************/
325   /*                                                                       */
326   /* <Function>                                                            */
327   /*    TT_New_Context                                                     */
328   /*                                                                       */
329   /* <Description>                                                         */
330   /*    Queries the face context for a given font.  Note that there is     */
331   /*    now a _single_ execution context in the TrueType driver which is   */
332   /*    shared among faces.                                                */
333   /*                                                                       */
334   /* <Input>                                                               */
335   /*    face :: A handle to the source face object.                        */
336   /*                                                                       */
337   /* <Return>                                                              */
338   /*    A handle to the execution context.  Initialized for `face'.        */
339   /*                                                                       */
340   /* <Note>                                                                */
341   /*    Only the glyph loader and debugger should call this function.      */
342   /*                                                                       */
343   FT_EXPORT( TT_ExecContext )
344   TT_New_Context( TT_Driver  driver );
345
346
347 #ifdef TT_USE_BYTECODE_INTERPRETER
348   FT_LOCAL( void )
349   TT_Done_Context( TT_ExecContext  exec );
350
351   FT_LOCAL( FT_Error )
352   TT_Load_Context( TT_ExecContext  exec,
353                    TT_Face         face,
354                    TT_Size         size );
355
356   FT_LOCAL( void )
357   TT_Save_Context( TT_ExecContext  exec,
358                    TT_Size         ins );
359
360   FT_LOCAL( FT_Error )
361   TT_Run_Context( TT_ExecContext  exec,
362                   FT_Bool         debug );
363 #endif /* TT_USE_BYTECODE_INTERPRETER */
364
365
366   /*************************************************************************/
367   /*                                                                       */
368   /* <Function>                                                            */
369   /*    TT_RunIns                                                          */
370   /*                                                                       */
371   /* <Description>                                                         */
372   /*    Executes one or more instruction in the execution context.  This   */
373   /*    is the main function of the TrueType opcode interpreter.           */
374   /*                                                                       */
375   /* <Input>                                                               */
376   /*    exec :: A handle to the target execution context.                  */
377   /*                                                                       */
378   /* <Return>                                                              */
379   /*    FreeType error code.  0 means success.                             */
380   /*                                                                       */
381   /* <Note>                                                                */
382   /*    Only the object manager and debugger should call this function.    */
383   /*                                                                       */
384   /*    This function is publicly exported because it is directly          */
385   /*    invoked by the TrueType debugger.                                  */
386   /*                                                                       */
387   FT_EXPORT( FT_Error )
388   TT_RunIns( TT_ExecContext  exec );
389
390
391 FT_END_HEADER
392
393 #endif /* __TTINTERP_H__ */
394
395
396 /* END */