ttinterp.c 245 KB
Newer Older
David Turner's avatar
David Turner committed
1
2
3
4
/***************************************************************************/
/*                                                                         */
/*  ttinterp.c                                                             */
/*                                                                         */
Werner Lemberg's avatar
   
Werner Lemberg committed
5
/*    TrueType bytecode interpreter (body).                                */
David Turner's avatar
David Turner committed
6
/*                                                                         */
Werner Lemberg's avatar
Werner Lemberg committed
7
/*  Copyright 1996-2001, 2002, 2003 by                                     */
David Turner's avatar
David Turner committed
8
9
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
Werner Lemberg's avatar
   
Werner Lemberg committed
10
11
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
David Turner's avatar
David Turner committed
12
13
14
15
16
17
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/***************************************************************************/

Werner Lemberg's avatar
   
Werner Lemberg committed
18

19
20
21
#include <ft2build.h>
#include FT_INTERNAL_DEBUG_H
#include FT_INTERNAL_CALC_H
22
#include FT_TRIGONOMETRY_H
23
#include FT_SYSTEM_H
24

25
#include "ttinterp.h"
26
27

#include "tterrors.h"
David Turner's avatar
David Turner committed
28

Werner Lemberg's avatar
   
Werner Lemberg committed
29

30
31
32
#ifdef TT_CONFIG_OPTION_BYTECODE_INTERPRETER


Werner Lemberg's avatar
   
Werner Lemberg committed
33
34
35
#define TT_MULFIX  FT_MulFix
#define TT_MULDIV  FT_MulDiv
#define TT_INT64   FT_Int64
David Turner's avatar
David Turner committed
36

Werner Lemberg's avatar
   
Werner Lemberg committed
37
38
39
40
41
42
  /*************************************************************************/
  /*                                                                       */
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
  /* messages during execution.                                            */
  /*                                                                       */
David Turner's avatar
David Turner committed
43
#undef  FT_COMPONENT
Werner Lemberg's avatar
   
Werner Lemberg committed
44
#define FT_COMPONENT  trace_ttinterp
David Turner's avatar
David Turner committed
45
46
47

  /*************************************************************************/
  /*                                                                       */
Werner Lemberg's avatar
   
Werner Lemberg committed
48
49
50
  /* In order to detect infinite loops in the code, we set up a counter    */
  /* within the run loop.  A single stroke of interpretation is now        */
  /* limitet to a maximal number of opcodes defined below.                 */
David Turner's avatar
David Turner committed
51
  /*                                                                       */
Werner Lemberg's avatar
   
Werner Lemberg committed
52
#define MAX_RUNNABLE_OPCODES  1000000L
David Turner's avatar
David Turner committed
53
54
55
56
57
58


  /*************************************************************************/
  /*                                                                       */
  /* There are two kinds of implementations:                               */
  /*                                                                       */
Werner Lemberg's avatar
   
Werner Lemberg committed
59
  /* a. static implementation                                              */
David Turner's avatar
David Turner committed
60
61
62
63
64
65
66
  /*                                                                       */
  /*    The current execution context is a static variable, which fields   */
  /*    are accessed directly by the interpreter during execution.  The    */
  /*    context is named `cur'.                                            */
  /*                                                                       */
  /*    This version is non-reentrant, of course.                          */
  /*                                                                       */
Werner Lemberg's avatar
   
Werner Lemberg committed
67
  /* b. indirect implementation                                            */
David Turner's avatar
David Turner committed
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
  /*                                                                       */
  /*    The current execution context is passed to _each_ function as its  */
  /*    first argument, and each field is thus accessed indirectly.        */
  /*                                                                       */
  /*    This version is fully re-entrant.                                  */
  /*                                                                       */
  /* The idea is that an indirect implementation may be slower to execute  */
  /* on low-end processors that are used in some systems (like 386s or     */
  /* even 486s).                                                           */
  /*                                                                       */
  /* As a consequence, the indirect implementation is now the default, as  */
  /* its performance costs can be considered negligible in our context.    */
  /* Note, however, that we kept the same source with macros because:      */
  /*                                                                       */
  /* - The code is kept very close in design to the Pascal code used for   */
  /*   development.                                                        */
  /*                                                                       */
  /* - It's much more readable that way!                                   */
  /*                                                                       */
  /* - It's still open to experimentation and tuning.                      */
  /*                                                                       */
  /*************************************************************************/


Werner Lemberg's avatar
   
Werner Lemberg committed
92
#ifndef TT_CONFIG_OPTION_STATIC_INTERPRETER     /* indirect implementation */
David Turner's avatar
David Turner committed
93

Werner Lemberg's avatar
   
Werner Lemberg committed
94
#define CUR  (*exc)                             /* see ttobjs.h */
David Turner's avatar
David Turner committed
95

Werner Lemberg's avatar
   
Werner Lemberg committed
96
#else                                           /* static implementation */
David Turner's avatar
David Turner committed
97

Werner Lemberg's avatar
   
Werner Lemberg committed
98
#define CUR  cur
David Turner's avatar
David Turner committed
99
100
101
102
103
104
105
106
107
108
109
110
111

  static
  TT_ExecContextRec  cur;   /* static exec. context variable */

  /* apparently, we have a _lot_ of direct indexing when accessing  */
  /* the static `cur', which makes the code bigger (due to all the  */
  /* four bytes addresses).                                         */

#endif /* TT_CONFIG_OPTION_STATIC_INTERPRETER */


  /*************************************************************************/
  /*                                                                       */
Werner Lemberg's avatar
   
Werner Lemberg committed
112
  /* The instruction argument stack.                                       */
David Turner's avatar
David Turner committed
113
  /*                                                                       */
114
#define INS_ARG  EXEC_OP_ FT_Long*  args    /* see ttobjs.h for EXEC_OP_ */
David Turner's avatar
David Turner committed
115
116
117
118
119
120
121


  /*************************************************************************/
  /*                                                                       */
  /* This macro is used whenever `exec' is unused in a function, to avoid  */
  /* stupid warnings from pedantic compilers.                              */
  /*                                                                       */
David Turner's avatar
David Turner committed
122
#define FT_UNUSED_EXEC  FT_UNUSED( CUR )
David Turner's avatar
David Turner committed
123
124
125
126
127
128
129


  /*************************************************************************/
  /*                                                                       */
  /* This macro is used whenever `args' is unused in a function, to avoid  */
  /* stupid warnings from pedantic compilers.                              */
  /*                                                                       */
David Turner's avatar
David Turner committed
130
#define FT_UNUSED_ARG  FT_UNUSED_EXEC; FT_UNUSED( args )
David Turner's avatar
David Turner committed
131
132
133
134
135


  /*************************************************************************/
  /*                                                                       */
  /* The following macros hide the use of EXEC_ARG and EXEC_ARG_ to        */
Werner Lemberg's avatar
   
Werner Lemberg committed
136
  /* increase readabilty of the code.                                      */
David Turner's avatar
David Turner committed
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
  /*                                                                       */
  /*************************************************************************/


#define SKIP_Code() \
          SkipCode( EXEC_ARG )

#define GET_ShortIns() \
          GetShortIns( EXEC_ARG )

#define NORMalize( x, y, v ) \
          Normalize( EXEC_ARG_ x, y, v )

#define SET_SuperRound( scale, flags ) \
          SetSuperRound( EXEC_ARG_ scale, flags )

#define ROUND_None( d, c ) \
          Round_None( EXEC_ARG_ d, c )

#define INS_Goto_CodeRange( range, ip ) \
          Ins_Goto_CodeRange( EXEC_ARG_ range, ip )

#define CUR_Func_project( x, y ) \
          CUR.func_project( EXEC_ARG_ x, y )

#define CUR_Func_move( z, p, d ) \
          CUR.func_move( EXEC_ARG_ z, p, d )

#define CUR_Func_dualproj( x, y ) \
          CUR.func_dualproj( EXEC_ARG_ x, y )

#define CUR_Func_round( d, c ) \
          CUR.func_round( EXEC_ARG_ d, c )

#define CUR_Func_read_cvt( index ) \
          CUR.func_read_cvt( EXEC_ARG_ index )

#define CUR_Func_write_cvt( index, val ) \
          CUR.func_write_cvt( EXEC_ARG_ index, val )

#define CUR_Func_move_cvt( index, val ) \
          CUR.func_move_cvt( EXEC_ARG_ index, val )

#define CURRENT_Ratio() \
          Current_Ratio( EXEC_ARG )

#define CURRENT_Ppem() \
          Current_Ppem( EXEC_ARG )

#define CUR_Ppem() \
          Cur_PPEM( EXEC_ARG )

#define INS_SxVTL( a, b, c, d ) \
          Ins_SxVTL( EXEC_ARG_ a, b, c, d )

#define COMPUTE_Funcs() \
          Compute_Funcs( EXEC_ARG )

#define COMPUTE_Round( a ) \
          Compute_Round( EXEC_ARG_ a )

#define COMPUTE_Point_Displacement( a, b, c, d ) \
          Compute_Point_Displacement( EXEC_ARG_ a, b, c, d )

#define MOVE_Zp2_Point( a, b, c, t ) \
          Move_Zp2_Point( EXEC_ARG_ a, b, c, t )


  /*************************************************************************/
  /*                                                                       */
  /* Instruction dispatch function, as used by the interpreter.            */
  /*                                                                       */
  typedef void  (*TInstruction_Function)( INS_ARG );


  /*************************************************************************/
  /*                                                                       */
  /* A simple bounds-checking macro.                                       */
  /*                                                                       */
216
#define BOUNDS( x, n )  ( (FT_UInt)(x) >= (FT_UInt)(n) )
David Turner's avatar
David Turner committed
217

Werner Lemberg's avatar
   
Werner Lemberg committed
218
219
#undef  SUCCESS
#define SUCCESS  0
David Turner's avatar
David Turner committed
220

Werner Lemberg's avatar
   
Werner Lemberg committed
221
222
#undef  FAILURE
#define FAILURE  1
David Turner's avatar
David Turner committed
223

224
#ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
Werner Lemberg's avatar
Werner Lemberg committed
225
226
227
228
229
#define GUESS_VECTOR( V )                                         \
  if ( CUR.face->unpatented_hinting )                             \
  {                                                               \
    CUR.GS.V.x = (FT_F2Dot14)( CUR.GS.both_x_axis ? 0x4000 : 0 ); \
    CUR.GS.V.y = (FT_F2Dot14)( CUR.GS.both_x_axis ? 0 : 0x4000 ); \
230
231
232
233
  }
#else
#define GUESS_VECTOR( V )
#endif
David Turner's avatar
David Turner committed
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252

  /*************************************************************************/
  /*                                                                       */
  /*                        CODERANGE FUNCTIONS                            */
  /*                                                                       */
  /*************************************************************************/


  /*************************************************************************/
  /*                                                                       */
  /* <Function>                                                            */
  /*    TT_Goto_CodeRange                                                  */
  /*                                                                       */
  /* <Description>                                                         */
  /*    Switches to a new code range (updates the code related elements in */
  /*    `exec', and `IP').                                                 */
  /*                                                                       */
  /* <Input>                                                               */
  /*    range :: The new execution code range.                             */
Werner Lemberg's avatar
   
Werner Lemberg committed
253
254
  /*                                                                       */
  /*    IP    :: The new IP in the new code range.                         */
David Turner's avatar
David Turner committed
255
256
257
258
259
  /*                                                                       */
  /* <InOut>                                                               */
  /*    exec  :: The target execution context.                             */
  /*                                                                       */
  /* <Return>                                                              */
Werner Lemberg's avatar
   
Werner Lemberg committed
260
  /*    FreeType error code.  0 means success.                             */
David Turner's avatar
David Turner committed
261
  /*                                                                       */
262
  FT_LOCAL_DEF( FT_Error )
Werner Lemberg's avatar
   
Werner Lemberg committed
263
264
265
  TT_Goto_CodeRange( TT_ExecContext  exec,
                     FT_Int          range,
                     FT_Long         IP )
David Turner's avatar
David Turner committed
266
267
268
269
  {
    TT_CodeRange*  coderange;


Werner Lemberg's avatar
   
Werner Lemberg committed
270
    FT_ASSERT( range >= 1 && range <= 3 );
David Turner's avatar
David Turner committed
271
272
273

    coderange = &exec->codeRangeTable[range - 1];

Werner Lemberg's avatar
   
Werner Lemberg committed
274
    FT_ASSERT( coderange->base != NULL );
David Turner's avatar
David Turner committed
275
276
277

    /* NOTE: Because the last instruction of a program may be a CALL */
    /*       which will return to the first byte *after* the code    */
Werner Lemberg's avatar
   
Werner Lemberg committed
278
    /*       range, we test for IP <= Size instead of IP < Size.     */
David Turner's avatar
David Turner committed
279
    /*                                                               */
Werner Lemberg's avatar
   
Werner Lemberg committed
280
    FT_ASSERT( (FT_ULong)IP <= coderange->size );
David Turner's avatar
David Turner committed
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300

    exec->code     = coderange->base;
    exec->codeSize = coderange->size;
    exec->IP       = IP;
    exec->curRange = range;

    return TT_Err_Ok;
  }


  /*************************************************************************/
  /*                                                                       */
  /* <Function>                                                            */
  /*    TT_Set_CodeRange                                                   */
  /*                                                                       */
  /* <Description>                                                         */
  /*    Sets a code range.                                                 */
  /*                                                                       */
  /* <Input>                                                               */
  /*    range  :: The code range index.                                    */
Werner Lemberg's avatar
   
Werner Lemberg committed
301
  /*                                                                       */
David Turner's avatar
David Turner committed
302
  /*    base   :: The new code base.                                       */
Werner Lemberg's avatar
   
Werner Lemberg committed
303
  /*                                                                       */
David Turner's avatar
David Turner committed
304
305
306
307
308
309
  /*    length :: The range size in bytes.                                 */
  /*                                                                       */
  /* <InOut>                                                               */
  /*    exec   :: The target execution context.                            */
  /*                                                                       */
  /* <Return>                                                              */
Werner Lemberg's avatar
   
Werner Lemberg committed
310
  /*    FreeType error code.  0 means success.                             */
David Turner's avatar
David Turner committed
311
  /*                                                                       */
312
  FT_LOCAL_DEF( FT_Error )
Werner Lemberg's avatar
   
Werner Lemberg committed
313
314
315
316
  TT_Set_CodeRange( TT_ExecContext  exec,
                    FT_Int          range,
                    void*           base,
                    FT_Long         length )
David Turner's avatar
David Turner committed
317
  {
Werner Lemberg's avatar
   
Werner Lemberg committed
318
    FT_ASSERT( range >= 1 && range <= 3 );
David Turner's avatar
David Turner committed
319

320
    exec->codeRangeTable[range - 1].base = (FT_Byte*)base;
David Turner's avatar
David Turner committed
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
    exec->codeRangeTable[range - 1].size = length;

    return TT_Err_Ok;
  }


  /*************************************************************************/
  /*                                                                       */
  /* <Function>                                                            */
  /*    TT_Clear_CodeRange                                                 */
  /*                                                                       */
  /* <Description>                                                         */
  /*    Clears a code range.                                               */
  /*                                                                       */
  /* <Input>                                                               */
  /*    range :: The code range index.                                     */
  /*                                                                       */
  /* <InOut>                                                               */
  /*    exec  :: The target execution context.                             */
  /*                                                                       */
  /* <Return>                                                              */
Werner Lemberg's avatar
   
Werner Lemberg committed
342
  /*    FreeType error code.  0 means success.                             */
David Turner's avatar
David Turner committed
343
344
345
346
  /*                                                                       */
  /* <Note>                                                                */
  /*    Does not set the Error variable.                                   */
  /*                                                                       */
347
  FT_LOCAL_DEF( FT_Error )
Werner Lemberg's avatar
   
Werner Lemberg committed
348
349
  TT_Clear_CodeRange( TT_ExecContext  exec,
                      FT_Int          range )
David Turner's avatar
David Turner committed
350
  {
Werner Lemberg's avatar
   
Werner Lemberg committed
351
    FT_ASSERT( range >= 1 && range <= 3 );
David Turner's avatar
David Turner committed
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376

    exec->codeRangeTable[range - 1].base = NULL;
    exec->codeRangeTable[range - 1].size = 0;

    return TT_Err_Ok;
  }


  /*************************************************************************/
  /*                                                                       */
  /*                   EXECUTION CONTEXT ROUTINES                          */
  /*                                                                       */
  /*************************************************************************/


  /*************************************************************************/
  /*                                                                       */
  /* <Function>                                                            */
  /*    TT_Destroy_Context                                                 */
  /*                                                                       */
  /* <Description>                                                         */
  /*    Destroys a given context.                                          */
  /*                                                                       */
  /* <Input>                                                               */
  /*    exec   :: A handle to the target execution context.                */
Werner Lemberg's avatar
   
Werner Lemberg committed
377
378
  /*                                                                       */
  /*    memory :: A handle to the parent memory object.                    */
David Turner's avatar
David Turner committed
379
380
  /*                                                                       */
  /* <Return>                                                              */
Werner Lemberg's avatar
   
Werner Lemberg committed
381
  /*    FreeType error code.  0 means success.                             */
David Turner's avatar
David Turner committed
382
383
384
385
  /*                                                                       */
  /* <Note>                                                                */
  /*    Only the glyph loader and debugger should call this function.      */
  /*                                                                       */
386
  FT_LOCAL_DEF( FT_Error )
Werner Lemberg's avatar
   
Werner Lemberg committed
387
388
  TT_Destroy_Context( TT_ExecContext  exec,
                      FT_Memory       memory )
David Turner's avatar
David Turner committed
389
390
  {
    /* free composite load stack */
391
    FT_FREE( exec->loadStack );
David Turner's avatar
David Turner committed
392
393
394
395
396
397
398
    exec->loadSize = 0;

    /* points zone */
    exec->maxPoints   = 0;
    exec->maxContours = 0;

    /* free stack */
399
    FT_FREE( exec->stack );
David Turner's avatar
David Turner committed
400
401
402
    exec->stackSize = 0;

    /* free call stack */
403
    FT_FREE( exec->callStack );
David Turner's avatar
David Turner committed
404
405
406
407
    exec->callSize = 0;
    exec->callTop  = 0;

    /* free glyph code range */
408
    FT_FREE( exec->glyphIns );
David Turner's avatar
David Turner committed
409
410
411
412
413
    exec->glyphSize = 0;

    exec->size = NULL;
    exec->face = NULL;

414
    FT_FREE( exec );
David Turner's avatar
David Turner committed
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
    return TT_Err_Ok;
  }


  /*************************************************************************/
  /*                                                                       */
  /* <Function>                                                            */
  /*    Init_Context                                                       */
  /*                                                                       */
  /* <Description>                                                         */
  /*    Initializes a context object.                                      */
  /*                                                                       */
  /* <Input>                                                               */
  /*    memory :: A handle to the parent memory object.                    */
  /*                                                                       */
  /*    face   :: A handle to the source TrueType face object.             */
  /*                                                                       */
  /* <InOut>                                                               */
  /*    exec   :: A handle to the target execution context.                */
  /*                                                                       */
  /* <Return>                                                              */
Werner Lemberg's avatar
   
Werner Lemberg committed
436
  /*    FreeType error code.  0 means success.                             */
David Turner's avatar
David Turner committed
437
  /*                                                                       */
Werner Lemberg's avatar
   
Werner Lemberg committed
438
439
440
441
  static FT_Error
  Init_Context( TT_ExecContext  exec,
                TT_Face         face,
                FT_Memory       memory )
David Turner's avatar
David Turner committed
442
  {
443
    FT_Error  error;
David Turner's avatar
David Turner committed
444
445


Werner Lemberg's avatar
   
Werner Lemberg committed
446
    FT_TRACE1(( "Init_Context: new object at 0x%08p, parent = 0x%08p\n",
447
                exec, face ));
David Turner's avatar
David Turner committed
448
449
450
451

    exec->memory   = memory;
    exec->callSize = 32;

452
    if ( FT_NEW_ARRAY( exec->callStack, exec->callSize ) )
David Turner's avatar
David Turner committed
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
      goto Fail_Memory;

    /* all values in the context are set to 0 already, but this is */
    /* here as a remainder                                         */
    exec->maxPoints   = 0;
    exec->maxContours = 0;

    exec->stackSize = 0;
    exec->loadSize  = 0;
    exec->glyphSize = 0;

    exec->stack     = NULL;
    exec->loadStack = NULL;
    exec->glyphIns  = NULL;

    exec->face = face;
    exec->size = NULL;

    return TT_Err_Ok;

  Fail_Memory:
Werner Lemberg's avatar
   
Werner Lemberg committed
474
475
    FT_ERROR(( "Init_Context: not enough memory for 0x%08lx\n",
               (FT_Long)exec ));
David Turner's avatar
David Turner committed
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
    TT_Destroy_Context( exec, memory );

    return error;
 }


  /*************************************************************************/
  /*                                                                       */
  /* <Function>                                                            */
  /*    Update_Max                                                         */
  /*                                                                       */
  /* <Description>                                                         */
  /*    Checks the size of a buffer and reallocates it if necessary.       */
  /*                                                                       */
  /* <Input>                                                               */
Werner Lemberg's avatar
   
Werner Lemberg committed
491
492
  /*    memory     :: A handle to the parent memory object.                */
  /*                                                                       */
David Turner's avatar
David Turner committed
493
494
495
496
497
498
499
500
501
502
503
  /*    multiplier :: The size in bytes of each element in the buffer.     */
  /*                                                                       */
  /*    new_max    :: The new capacity (size) of the buffer.               */
  /*                                                                       */
  /* <InOut>                                                               */
  /*    size       :: The address of the buffer's current size expressed   */
  /*                  in elements.                                         */
  /*                                                                       */
  /*    buff       :: The address of the buffer base pointer.              */
  /*                                                                       */
  /* <Return>                                                              */
Werner Lemberg's avatar
   
Werner Lemberg committed
504
  /*    FreeType error code.  0 means success.                             */
David Turner's avatar
David Turner committed
505
  /*                                                                       */
Werner Lemberg's avatar
   
Werner Lemberg committed
506
507
508
509
510
511
  static FT_Error
  Update_Max( FT_Memory  memory,
              FT_ULong*  size,
              FT_Long    multiplier,
              void**     buff,
              FT_ULong   new_max )
David Turner's avatar
David Turner committed
512
  {
513
    FT_Error  error;
David Turner's avatar
David Turner committed
514
515
516
517


    if ( *size < new_max )
    {
518
519
      FT_FREE( *buff );
      if ( FT_ALLOC( *buff, new_max * multiplier ) )
David Turner's avatar
David Turner committed
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
        return error;
      *size = new_max;
    }

    return TT_Err_Ok;
  }


  /*************************************************************************/
  /*                                                                       */
  /* <Function>                                                            */
  /*    TT_Load_Context                                                    */
  /*                                                                       */
  /* <Description>                                                         */
  /*    Prepare an execution context for glyph hinting.                    */
  /*                                                                       */
  /* <Input>                                                               */
  /*    face :: A handle to the source face object.                        */
Werner Lemberg's avatar
   
Werner Lemberg committed
538
  /*                                                                       */
David Turner's avatar
David Turner committed
539
540
541
542
543
544
  /*    size :: A handle to the source size object.                        */
  /*                                                                       */
  /* <InOut>                                                               */
  /*    exec :: A handle to the target execution context.                  */
  /*                                                                       */
  /* <Return>                                                              */
Werner Lemberg's avatar
   
Werner Lemberg committed
545
  /*    FreeType error code.  0 means success.                             */
David Turner's avatar
David Turner committed
546
547
548
549
  /*                                                                       */
  /* <Note>                                                                */
  /*    Only the glyph loader and debugger should call this function.      */
  /*                                                                       */
550
  FT_LOCAL_DEF( FT_Error )
Werner Lemberg's avatar
   
Werner Lemberg committed
551
552
553
  TT_Load_Context( TT_ExecContext  exec,
                   TT_Face         face,
                   TT_Size         size )
David Turner's avatar
David Turner committed
554
  {
555
556
    FT_Int          i;
    FT_ULong        tmp;
David Turner's avatar
David Turner committed
557
    TT_MaxProfile*  maxp;
558
    FT_Error        error;
David Turner's avatar
David Turner committed
559

Werner Lemberg's avatar
   
Werner Lemberg committed
560

David Turner's avatar
David Turner committed
561
562
563
564
565
566
567
568
569
570
571
572
573
    exec->face = face;
    maxp       = &face->max_profile;
    exec->size = size;

    if ( size )
    {
      exec->numFDefs   = size->num_function_defs;
      exec->maxFDefs   = size->max_function_defs;
      exec->numIDefs   = size->num_instruction_defs;
      exec->maxIDefs   = size->max_instruction_defs;
      exec->FDefs      = size->function_defs;
      exec->IDefs      = size->instruction_defs;
      exec->tt_metrics = size->ttmetrics;
574
      exec->metrics    = size->metrics;
David Turner's avatar
David Turner committed
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606

      exec->maxFunc    = size->max_func;
      exec->maxIns     = size->max_ins;

      for ( i = 0; i < TT_MAX_CODE_RANGES; i++ )
        exec->codeRangeTable[i] = size->codeRangeTable[i];

      /* set graphics state */
      exec->GS = size->GS;

      exec->cvtSize = size->cvt_size;
      exec->cvt     = size->cvt;

      exec->storeSize = size->storage_size;
      exec->storage   = size->storage;

      exec->twilight  = size->twilight;
    }

    error = Update_Max( exec->memory,
                        &exec->loadSize,
                        sizeof ( TT_SubGlyphRec ),
                        (void**)&exec->loadStack,
                        exec->face->max_components + 1 );
    if ( error )
      return error;

    /* XXX: We reserve a little more elements on the stack to deal safely */
    /*      with broken fonts like arialbs, courbs, timesbs, etc.         */
    tmp = exec->stackSize;
    error = Update_Max( exec->memory,
                        &tmp,
607
                        sizeof ( FT_F26Dot6 ),
David Turner's avatar
David Turner committed
608
609
                        (void**)&exec->stack,
                        maxp->maxStackElements + 32 );
610
    exec->stackSize = (FT_UInt)tmp;
David Turner's avatar
David Turner committed
611
612
613
614
615
616
    if ( error )
      return error;

    tmp = exec->glyphSize;
    error = Update_Max( exec->memory,
                        &tmp,
617
                        sizeof ( FT_Byte ),
David Turner's avatar
David Turner committed
618
619
                        (void**)&exec->glyphIns,
                        maxp->maxSizeOfInstructions );
620
    exec->glyphSize = (FT_UShort)tmp;
David Turner's avatar
David Turner committed
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
    if ( error )
      return error;

    exec->pts.n_points   = 0;
    exec->pts.n_contours = 0;

    exec->instruction_trap = FALSE;

    return TT_Err_Ok;
  }


  /*************************************************************************/
  /*                                                                       */
  /* <Function>                                                            */
  /*    TT_Save_Context                                                    */
  /*                                                                       */
  /* <Description>                                                         */
  /*    Saves the code ranges in a `size' object.                          */
  /*                                                                       */
  /* <Input>                                                               */
  /*    exec :: A handle to the source execution context.                  */
  /*                                                                       */
Werner Lemberg's avatar
   
Werner Lemberg committed
644
645
  /* <InOut>                                                               */
  /*    size :: A handle to the target size object.                        */
David Turner's avatar
David Turner committed
646
647
  /*                                                                       */
  /* <Return>                                                              */
Werner Lemberg's avatar
   
Werner Lemberg committed
648
  /*    FreeType error code.  0 means success.                             */
David Turner's avatar
David Turner committed
649
650
651
652
  /*                                                                       */
  /* <Note>                                                                */
  /*    Only the glyph loader and debugger should call this function.      */
  /*                                                                       */
653
  FT_LOCAL_DEF( FT_Error )
Werner Lemberg's avatar
   
Werner Lemberg committed
654
655
  TT_Save_Context( TT_ExecContext  exec,
                   TT_Size         size )
David Turner's avatar
David Turner committed
656
  {
657
    FT_Int  i;
David Turner's avatar
David Turner committed
658

Werner Lemberg's avatar
   
Werner Lemberg committed
659

David Turner's avatar
David Turner committed
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
    /* XXXX: Will probably disappear soon with all the code range */
    /*       management, which is now rather obsolete.            */
    /*                                                            */
    size->num_function_defs    = exec->numFDefs;
    size->num_instruction_defs = exec->numIDefs;

    size->max_func = exec->maxFunc;
    size->max_ins  = exec->maxIns;

    for ( i = 0; i < TT_MAX_CODE_RANGES; i++ )
      size->codeRangeTable[i] = exec->codeRangeTable[i];

    return TT_Err_Ok;
  }


  /*************************************************************************/
  /*                                                                       */
  /* <Function>                                                            */
  /*    TT_Run_Context                                                     */
  /*                                                                       */
  /* <Description>                                                         */
  /*    Executes one or more instructions in the execution context.        */
  /*                                                                       */
  /* <Input>                                                               */
  /*    debug :: A Boolean flag.  If set, the function sets some internal  */
  /*             variables and returns immediately, otherwise TT_RunIns()  */
  /*             is called.                                                */
  /*                                                                       */
Werner Lemberg's avatar
   
Werner Lemberg committed
689
690
  /*             This is commented out currently.                          */
  /*                                                                       */
David Turner's avatar
David Turner committed
691
692
693
694
  /* <Input>                                                               */
  /*    exec  :: A handle to the target execution context.                 */
  /*                                                                       */
  /* <Return>                                                              */
David Turner's avatar
David Turner committed
695
  /*    TrueTyoe error code.  0 means success.                             */
David Turner's avatar
David Turner committed
696
697
698
699
  /*                                                                       */
  /* <Note>                                                                */
  /*    Only the glyph loader and debugger should call this function.      */
  /*                                                                       */
700
  FT_LOCAL_DEF( FT_Error )
Werner Lemberg's avatar
   
Werner Lemberg committed
701
702
  TT_Run_Context( TT_ExecContext  exec,
                  FT_Bool         debug )
David Turner's avatar
David Turner committed
703
  {
704
    FT_Error  error;
David Turner's avatar
David Turner committed
705

Werner Lemberg's avatar
   
Werner Lemberg committed
706
707

    if ( ( error = TT_Goto_CodeRange( exec, tt_coderange_glyph, 0  ) )
David Turner's avatar
David Turner committed
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
           != TT_Err_Ok )
      return error;

    exec->zp0 = exec->pts;
    exec->zp1 = exec->pts;
    exec->zp2 = exec->pts;

    exec->GS.gep0 = 1;
    exec->GS.gep1 = 1;
    exec->GS.gep2 = 1;

    exec->GS.projVector.x = 0x4000;
    exec->GS.projVector.y = 0x0000;

    exec->GS.freeVector = exec->GS.projVector;
    exec->GS.dualVector = exec->GS.projVector;

725
#ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
726
727
728
    exec->GS.both_x_axis = TRUE;
#endif

David Turner's avatar
David Turner committed
729
730
731
732
733
734
735
736
737
    exec->GS.round_state = 1;
    exec->GS.loop        = 1;

    /* some glyphs leave something on the stack. so we clean it */
    /* before a new execution.                                  */
    exec->top     = 0;
    exec->callTop = 0;

#if 1
David Turner's avatar
David Turner committed
738
    FT_UNUSED( debug );
Werner Lemberg's avatar
   
Werner Lemberg committed
739

David Turner's avatar
David Turner committed
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
    return exec->face->interpreter( exec );
#else
    if ( !debug )
      return TT_RunIns( exec );
    else
      return TT_Err_Ok;
#endif
  }


  const TT_GraphicsState  tt_default_graphics_state =
  {
    0, 0, 0,
    { 0x4000, 0 },
    { 0x4000, 0 },
    { 0x4000, 0 },
756

757
#ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
Werner Lemberg's avatar
Werner Lemberg committed
758
    TRUE,
759
760
#endif

David Turner's avatar
David Turner committed
761
762
763
764
765
766
    1, 64, 1,
    TRUE, 68, 0, 0, 9, 3,
    0, FALSE, 2, 1, 1, 1
  };


Werner Lemberg's avatar
   
Werner Lemberg committed
767
768
  /* documentation is in ttinterp.h */

Werner Lemberg's avatar
   
Werner Lemberg committed
769
770
  FT_EXPORT_DEF( TT_ExecContext )
  TT_New_Context( TT_Face  face )
David Turner's avatar
David Turner committed
771
  {
Werner Lemberg's avatar
   
Werner Lemberg committed
772
    TT_Driver       driver;
David Turner's avatar
David Turner committed
773
    TT_ExecContext  exec;
Werner Lemberg's avatar
   
Werner Lemberg committed
774
775
776
777
778
    FT_Memory       memory;


    if ( !face )
      return 0;
David Turner's avatar
David Turner committed
779

Werner Lemberg's avatar
   
Werner Lemberg committed
780
    driver = (TT_Driver)face->root.driver;
David Turner's avatar
David Turner committed
781

David Turner's avatar
David Turner committed
782
    memory = driver->root.root.memory;
Werner Lemberg's avatar
   
Werner Lemberg committed
783
    exec   = driver->context;
David Turner's avatar
David Turner committed
784
785
786

    if ( !driver->context )
    {
Werner Lemberg's avatar
   
Werner Lemberg committed
787
      FT_Error  error;
David Turner's avatar
David Turner committed
788
789
790


      /* allocate object */
791
      if ( FT_NEW( exec ) )
David Turner's avatar
David Turner committed
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
        goto Exit;

      /* initialize it */
      error = Init_Context( exec, face, memory );
      if ( error )
        goto Fail;

      /* store it into the driver */
      driver->context = exec;
    }

  Exit:
    return driver->context;

  Fail:
807
    FT_FREE( exec );
David Turner's avatar
David Turner committed
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824

    return 0;
  }


  /*************************************************************************/
  /*                                                                       */
  /* <Function>                                                            */
  /*    TT_Done_Context                                                    */
  /*                                                                       */
  /* <Description>                                                         */
  /*    Discards an execution context.                                     */
  /*                                                                       */
  /* <Input>                                                               */
  /*    exec :: A handle to the target execution context.                  */
  /*                                                                       */
  /* <Return>                                                              */
Werner Lemberg's avatar
   
Werner Lemberg committed
825
  /*    FreeType error code.  0 means success.                             */
David Turner's avatar
David Turner committed
826
827
828
829
  /*                                                                       */
  /* <Note>                                                                */
  /*    Only the glyph loader and debugger should call this function.      */
  /*                                                                       */
830
  FT_LOCAL_DEF( FT_Error )
Werner Lemberg's avatar
   
Werner Lemberg committed
831
  TT_Done_Context( TT_ExecContext  exec )
David Turner's avatar
David Turner committed
832
833
  {
    /* Nothing at all for now */
David Turner's avatar
David Turner committed
834
    FT_UNUSED( exec );
David Turner's avatar
David Turner committed
835
836
837
838
839

    return TT_Err_Ok;
  }


840

David Turner's avatar
David Turner committed
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
  /*************************************************************************/
  /*                                                                       */
  /* Before an opcode is executed, the interpreter verifies that there are */
  /* enough arguments on the stack, with the help of the Pop_Push_Count    */
  /* table.                                                                */
  /*                                                                       */
  /* For each opcode, the first column gives the number of arguments that  */
  /* are popped from the stack; the second one gives the number of those   */
  /* that are pushed in result.                                            */
  /*                                                                       */
  /* Note that for opcodes with a varying number of parameters, either 0   */
  /* or 1 arg is verified before execution, depending on the nature of the */
  /* instruction:                                                          */
  /*                                                                       */
  /* - if the number of arguments is given by the bytecode stream or the   */
  /*   loop variable, 0 is chosen.                                         */
  /*                                                                       */
  /* - if the first argument is a count n that is followed by arguments    */
  /*   a1 .. an, then 1 is chosen.                                         */
  /*                                                                       */
  /*************************************************************************/


#undef  PACK
Werner Lemberg's avatar
   
Werner Lemberg committed
865
#define PACK( x, y )  ( ( x << 4 ) | y )
David Turner's avatar
David Turner committed
866
867
868


  static
869
  const FT_Byte  Pop_Push_Count[256] =
David Turner's avatar
David Turner committed
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
  {
    /* opcodes are gathered in groups of 16 */
    /* please keep the spaces as they are   */

    /*  SVTCA  y  */  PACK( 0, 0 ),
    /*  SVTCA  x  */  PACK( 0, 0 ),
    /*  SPvTCA y  */  PACK( 0, 0 ),
    /*  SPvTCA x  */  PACK( 0, 0 ),
    /*  SFvTCA y  */  PACK( 0, 0 ),
    /*  SFvTCA x  */  PACK( 0, 0 ),
    /*  SPvTL //  */  PACK( 2, 0 ),
    /*  SPvTL +   */  PACK( 2, 0 ),
    /*  SFvTL //  */  PACK( 2, 0 ),
    /*  SFvTL +   */  PACK( 2, 0 ),
    /*  SPvFS     */  PACK( 2, 0 ),
    /*  SFvFS     */  PACK( 2, 0 ),
    /*  GPV       */  PACK( 0, 2 ),
    /*  GFV       */  PACK( 0, 2 ),
    /*  SFvTPv    */  PACK( 0, 0 ),
    /*  ISECT     */  PACK( 5, 0 ),

    /*  SRP0      */  PACK( 1, 0 ),
    /*  SRP1      */  PACK( 1, 0 ),
    /*  SRP2      */  PACK( 1, 0 ),
    /*  SZP0      */  PACK( 1, 0 ),
    /*  SZP1      */  PACK( 1, 0 ),
    /*  SZP2      */  PACK( 1, 0 ),
    /*  SZPS      */  PACK( 1, 0 ),
    /*  SLOOP     */  PACK( 1, 0 ),
    /*  RTG       */  PACK( 0, 0 ),
    /*  RTHG      */  PACK( 0, 0 ),
    /*  SMD       */  PACK( 1, 0 ),
    /*  ELSE      */  PACK( 0, 0 ),
    /*  JMPR      */  PACK( 1, 0 ),
    /*  SCvTCi    */  PACK( 1, 0 ),
    /*  SSwCi     */  PACK( 1, 0 ),
    /*  SSW       */  PACK( 1, 0 ),

    /*  DUP       */  PACK( 1, 2 ),
    /*  POP       */  PACK( 1, 0 ),
    /*  CLEAR     */  PACK( 0, 0 ),
    /*  SWAP      */  PACK( 2, 2 ),
    /*  DEPTH     */  PACK( 0, 1 ),
    /*  CINDEX    */  PACK( 1, 1 ),
    /*  MINDEX    */  PACK( 1, 0 ),
    /*  AlignPTS  */  PACK( 2, 0 ),
    /*  INS_$28   */  PACK( 0, 0 ),
    /*  UTP       */  PACK( 1, 0 ),
    /*  LOOPCALL  */  PACK( 2, 0 ),
    /*  CALL      */  PACK( 1, 0 ),
    /*  FDEF      */  PACK( 1, 0 ),
    /*  ENDF      */  PACK( 0, 0 ),
    /*  MDAP[0]   */  PACK( 1, 0 ),
    /*  MDAP[1]   */  PACK( 1, 0 ),

    /*  IUP[0]    */  PACK( 0, 0 ),
    /*  IUP[1]    */  PACK( 0, 0 ),
    /*  SHP[0]    */  PACK( 0, 0 ),
    /*  SHP[1]    */  PACK( 0, 0 ),
    /*  SHC[0]    */  PACK( 1, 0 ),
    /*  SHC[1]    */  PACK( 1, 0 ),
    /*  SHZ[0]    */  PACK( 1, 0 ),
    /*  SHZ[1]    */  PACK( 1, 0 ),
    /*  SHPIX     */  PACK( 1, 0 ),
    /*  IP        */  PACK( 0, 0 ),
    /*  MSIRP[0]  */  PACK( 2, 0 ),
    /*  MSIRP[1]  */  PACK( 2, 0 ),
    /*  AlignRP   */  PACK( 0, 0 ),
    /*  RTDG      */  PACK( 0, 0 ),
    /*  MIAP[0]   */  PACK( 2, 0 ),
    /*  MIAP[1]   */  PACK( 2, 0 ),

    /*  NPushB    */  PACK( 0, 0 ),
    /*  NPushW    */  PACK( 0, 0 ),
    /*  WS        */  PACK( 2, 0 ),
    /*  RS        */  PACK( 1, 1 ),
    /*  WCvtP     */  PACK( 2, 0 ),
    /*  RCvt      */  PACK( 1, 1 ),
    /*  GC[0]     */  PACK( 1, 1 ),
    /*  GC[1]     */  PACK( 1, 1 ),
    /*  SCFS      */  PACK( 2, 0 ),
    /*  MD[0]     */  PACK( 2, 1 ),
    /*  MD[1]     */  PACK( 2, 1 ),
    /*  MPPEM     */  PACK( 0, 1 ),
    /*  MPS       */  PACK( 0, 1 ),
    /*  FlipON    */  PACK( 0, 0 ),
    /*  FlipOFF   */  PACK( 0, 0 ),
    /*  DEBUG     */  PACK( 1, 0 ),

    /*  LT        */  PACK( 2, 1 ),
    /*  LTEQ      */  PACK( 2, 1 ),
    /*  GT        */  PACK( 2, 1 ),
    /*  GTEQ      */  PACK( 2, 1 ),
    /*  EQ        */  PACK( 2, 1 ),
    /*  NEQ       */  PACK( 2, 1 ),
    /*  ODD       */  PACK( 1, 1 ),
    /*  EVEN      */  PACK( 1, 1 ),
    /*  IF        */  PACK( 1, 0 ),
    /*  EIF       */  PACK( 0, 0 ),
    /*  AND       */  PACK( 2, 1 ),
    /*  OR        */  PACK( 2, 1 ),
    /*  NOT       */  PACK( 1, 1 ),
    /*  DeltaP1   */  PACK( 1, 0 ),
    /*  SDB       */  PACK( 1, 0 ),
    /*  SDS       */  PACK( 1, 0 ),

    /*  ADD       */  PACK( 2, 1 ),
    /*  SUB       */  PACK( 2, 1 ),
    /*  DIV       */  PACK( 2, 1 ),
    /*  MUL       */  PACK( 2, 1 ),
    /*  ABS       */  PACK( 1, 1 ),
    /*  NEG       */  PACK( 1, 1 ),
    /*  FLOOR     */  PACK( 1, 1 ),
    /*  CEILING   */  PACK( 1, 1 ),
    /*  ROUND[0]  */  PACK( 1, 1 ),
    /*  ROUND[1]  */  PACK( 1, 1 ),
    /*  ROUND[2]  */  PACK( 1, 1 ),
    /*  ROUND[3]  */  PACK( 1, 1 ),
    /*  NROUND[0] */  PACK( 1, 1 ),
    /*  NROUND[1] */  PACK( 1, 1 ),
    /*  NROUND[2] */  PACK( 1, 1 ),
    /*  NROUND[3] */  PACK( 1, 1 ),

    /*  WCvtF     */  PACK( 2, 0 ),
    /*  DeltaP2   */  PACK( 1, 0 ),
    /*  DeltaP3   */  PACK( 1, 0 ),
    /*  DeltaCn[0] */ PACK( 1, 0 ),
    /*  DeltaCn[1] */ PACK( 1, 0 ),
    /*  DeltaCn[2] */ PACK( 1, 0 ),
    /*  SROUND    */  PACK( 1, 0 ),
    /*  S45Round  */  PACK( 1, 0 ),
    /*  JROT      */  PACK( 2, 0 ),
    /*  JROF      */  PACK( 2, 0 ),
    /*  ROFF      */  PACK( 0, 0 ),
    /*  INS_$7B   */  PACK( 0, 0 ),
    /*  RUTG      */  PACK( 0, 0 ),
    /*  RDTG      */  PACK( 0, 0 ),
    /*  SANGW     */  PACK( 1, 0 ),
    /*  AA        */  PACK( 1, 0 ),

    /*  FlipPT    */  PACK( 0, 0 ),
    /*  FlipRgON  */  PACK( 2, 0 ),
    /*  FlipRgOFF */  PACK( 2, 0 ),
    /*  INS_$83   */  PACK( 0, 0 ),
    /*  INS_$84   */  PACK( 0, 0 ),
    /*  ScanCTRL  */  PACK( 1, 0 ),
    /*  SDVPTL[0] */  PACK( 2, 0 ),
    /*  SDVPTL[1] */  PACK( 2, 0 ),
    /*  GetINFO   */  PACK( 1, 1 ),
    /*  IDEF      */  PACK( 1, 0 ),
    /*  ROLL      */  PACK( 3, 3 ),
    /*  MAX       */  PACK( 2, 1 ),
    /*  MIN       */  PACK( 2, 1 ),
    /*  ScanTYPE  */  PACK( 1, 0 ),
    /*  InstCTRL  */  PACK( 2, 0 ),
    /*  INS_$8F   */  PACK( 0, 0 ),

    /*  INS_$90  */   PACK( 0, 0 ),
    /*  INS_$91  */   PACK( 0, 0 ),
    /*  INS_$92  */   PACK( 0, 0 ),
    /*  INS_$93  */   PACK( 0, 0 ),
    /*  INS_$94  */   PACK( 0, 0 ),
    /*  INS_$95  */   PACK( 0, 0 ),
    /*  INS_$96  */   PACK( 0, 0 ),
    /*  INS_$97  */   PACK( 0, 0 ),
    /*  INS_$98  */   PACK( 0, 0 ),
    /*  INS_$99  */   PACK( 0, 0 ),
    /*  INS_$9A  */   PACK( 0, 0 ),
    /*  INS_$9B  */   PACK( 0, 0 ),
    /*  INS_$9C  */   PACK( 0, 0 ),
    /*  INS_$9D  */   PACK( 0, 0 ),
    /*  INS_$9E  */   PACK( 0, 0 ),
    /*  INS_$9F  */   PACK( 0, 0 ),

    /*  INS_$A0  */   PACK( 0, 0 ),
    /*  INS_$A1  */   PACK( 0, 0 ),
    /*  INS_$A2  */   PACK( 0, 0 ),
    /*  INS_$A3  */   PACK( 0, 0 ),
    /*  INS_$A4  */   PACK( 0, 0 ),
    /*  INS_$A5  */   PACK( 0, 0 ),
    /*  INS_$A6  */   PACK( 0, 0 ),
    /*  INS_$A7  */   PACK( 0, 0 ),
    /*  INS_$A8  */   PACK( 0, 0 ),
    /*  INS_$A9  */   PACK( 0, 0 ),
    /*  INS_$AA  */   PACK( 0, 0 ),
    /*  INS_$AB  */   PACK( 0, 0 ),
    /*  INS_$AC  */   PACK( 0, 0 ),
    /*  INS_$AD  */   PACK( 0, 0 ),
    /*  INS_$AE  */   PACK( 0, 0 ),
    /*  INS_$AF  */   PACK( 0, 0 ),

    /*  PushB[0]  */  PACK( 0, 1 ),
    /*  PushB[1]  */  PACK( 0, 2 ),
    /*  PushB[2]  */  PACK( 0, 3 ),
    /*  PushB[3]  */  PACK( 0, 4 ),
    /*  PushB[4]  */  PACK( 0, 5 ),
    /*  PushB[5]  */  PACK( 0, 6 ),
    /*  PushB[6]  */  PACK( 0, 7 ),
    /*  PushB[7]  */  PACK( 0, 8 ),
    /*  PushW[0]  */  PACK( 0, 1 ),
    /*  PushW[1]  */  PACK( 0, 2 ),
    /*  PushW[2]  */  PACK( 0, 3 ),
    /*  PushW[3]  */  PACK( 0, 4 ),
    /*  PushW[4]  */  PACK( 0, 5 ),
    /*  PushW[5]  */  PACK( 0, 6 ),
    /*  PushW[6]  */  PACK( 0, 7 ),
    /*  PushW[7]  */  PACK( 0, 8 ),

    /*  MDRP[00]  */  PACK( 1, 0 ),
    /*  MDRP[01]  */  PACK( 1, 0 ),
    /*  MDRP[02]  */  PACK( 1, 0 ),
    /*  MDRP[03]  */  PACK( 1, 0 ),
    /*  MDRP[04]  */  PACK( 1, 0 ),
    /*  MDRP[05]  */  PACK( 1, 0 ),
    /*  MDRP[06]  */  PACK( 1, 0 ),
    /*  MDRP[07]  */  PACK( 1, 0 ),
    /*  MDRP[08]  */  PACK( 1, 0 ),
    /*  MDRP[09]  */  PACK( 1, 0 ),
    /*  MDRP[10]  */  PACK( 1, 0 ),
    /*  MDRP[11]  */  PACK( 1, 0 ),
    /*  MDRP[12]  */  PACK( 1, 0 ),
    /*  MDRP[13]  */  PACK( 1, 0 ),
    /*  MDRP[14]  */  PACK( 1, 0 ),
    /*  MDRP[15]  */  PACK( 1, 0 ),

    /*  MDRP[16]  */  PACK( 1, 0 ),
    /*  MDRP[17]  */  PACK( 1, 0 ),
    /*  MDRP[18]  */  PACK( 1, 0 ),
    /*  MDRP[19]  */  PACK( 1, 0 ),
    /*  MDRP[20]  */  PACK( 1, 0 ),
    /*  MDRP[21]  */  PACK( 1, 0 ),
    /*  MDRP[22]  */  PACK( 1, 0 ),
    /*  MDRP[23]  */  PACK( 1, 0 ),
    /*  MDRP[24]  */  PACK( 1, 0 ),
    /*  MDRP[25]  */  PACK( 1, 0 ),
    /*  MDRP[26]  */  PACK( 1, 0 ),
    /*  MDRP[27]  */  PACK( 1, 0 ),
    /*  MDRP[28]  */  PACK( 1, 0 ),
    /*  MDRP[29]  */  PACK( 1, 0 ),
    /*  MDRP[30]  */  PACK( 1, 0 ),
    /*  MDRP[31]  */  PACK( 1, 0 ),

    /*  MIRP[00]  */  PACK( 2, 0 ),
    /*  MIRP[01]  */  PACK( 2, 0 ),
    /*  MIRP[02]  */  PACK( 2, 0 ),
    /*  MIRP[03]  */  PACK( 2, 0 ),
    /*  MIRP[04]  */  PACK( 2, 0 ),
    /*  MIRP[05]  */  PACK( 2, 0 ),
    /*  MIRP[06]  */  PACK( 2, 0 ),
    /*  MIRP[07]  */  PACK( 2, 0 ),
    /*  MIRP[08]  */  PACK( 2, 0 ),
    /*  MIRP[09]  */  PACK( 2, 0 ),
    /*  MIRP[10]  */  PACK( 2, 0 ),
    /*  MIRP[11]  */  PACK( 2, 0 ),
    /*  MIRP[12]  */  PACK( 2, 0 ),
    /*  MIRP[13]  */  PACK( 2, 0 ),
    /*  MIRP[14]  */  PACK( 2, 0 ),
    /*  MIRP[15]  */  PACK( 2, 0 ),

    /*  MIRP[16]  */  PACK( 2, 0 ),
    /*  MIRP[17]  */  PACK( 2, 0 ),
    /*  MIRP[18]  */  PACK( 2, 0 ),
    /*  MIRP[19]  */  PACK( 2, 0 ),
    /*  MIRP[20]  */  PACK( 2, 0 ),
    /*  MIRP[21]  */  PACK( 2, 0 ),
    /*  MIRP[22]  */  PACK( 2, 0 ),
    /*  MIRP[23]  */  PACK( 2, 0 ),
    /*  MIRP[24]  */  PACK( 2, 0 ),
    /*  MIRP[25]  */  PACK( 2, 0 ),
    /*  MIRP[26]  */  PACK( 2, 0 ),
    /*  MIRP[27]  */  PACK( 2, 0 ),
    /*  MIRP[28]  */  PACK( 2, 0 ),
    /*  MIRP[29]  */  PACK( 2, 0 ),
    /*  MIRP[30]  */  PACK( 2, 0 ),
    /*  MIRP[31]  */  PACK( 2, 0 )
  };


  static
1149
  const FT_Char  opcode_length[256] =
David Turner's avatar
David Turner committed
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
  {
    1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,
    1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,
    1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,
    1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,

   -1,-1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,
    1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,
    1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,
    1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,

    1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,
    1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,
    1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,
    2, 3, 4, 5,  6, 7, 8, 9,  3, 5, 7, 9, 11,13,15,17,

    1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,
    1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,
    1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,
    1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1
  };

  static
1173
  const FT_Vector  Null_Vector = {0,0};
David Turner's avatar
David Turner committed
1174
1175


Werner Lemberg's avatar
   
Werner Lemberg committed
1176
#undef PACK
David Turner's avatar
David Turner committed
1177
1178
1179


#undef  NULL_Vector
1180
#define NULL_Vector  (FT_Vector*)&Null_Vector
David Turner's avatar
David Turner committed
1181
1182


Werner Lemberg's avatar
   
Werner Lemberg committed
1183
  /* compute (a*b)/2^14 with maximal accuracy and rounding */
David Turner's avatar
David Turner committed
1184
  static FT_Int32
Werner Lemberg's avatar
   
Werner Lemberg committed
1185
1186
  TT_MulFix14( FT_Int32  a,
               FT_Int    b )
David Turner's avatar
David Turner committed
1187
1188
1189
  {
    FT_Int32   m, s, hi;
    FT_UInt32  l, lo;
1190

Werner Lemberg's avatar
   
Werner Lemberg committed
1191

David Turner's avatar
David Turner committed
1192
    /* compute ax*bx as 64-bit value */
Werner Lemberg's avatar
   
Werner Lemberg committed
1193
1194
    l  = (FT_UInt32)( ( a & 0xFFFFU ) * b );
    m  = ( a >> 16 ) * b;
1195

Werner Lemberg's avatar
   
Werner Lemberg committed
1196
1197
    lo = l + (FT_UInt32)( m << 16 );
    hi = ( m >> 16 ) + ( (FT_Int32)l >> 31 ) + ( lo < l );
1198

David Turner's avatar
David Turner committed
1199
    /* divide the result by 2^14 with rounding */
Werner Lemberg's avatar
   
Werner Lemberg committed
1200
    s   = hi >> 31;
David Turner's avatar
David Turner committed
1201
    l   = lo + (FT_UInt32)s;
Werner Lemberg's avatar
   
Werner Lemberg committed
1202
    hi += s + ( l < lo );
David Turner's avatar
David Turner committed
1203
1204
1205
1206
    lo  = l;

    l   = lo + 0x2000U;
    hi += (l < lo);
1207

Werner Lemberg's avatar
   
Werner Lemberg committed
1208
    return ( hi << 18 ) | ( l >> 14 );
David Turner's avatar
David Turner committed
1209
1210
1211
  }


Werner Lemberg's avatar
   
Werner Lemberg committed
1212
  /* compute (ax*bx+ay*by)/2^14 with maximal accuracy and rounding */
David Turner's avatar
David Turner committed
1213
  static FT_Int32
Werner Lemberg's avatar
   
Werner Lemberg committed
1214
1215
1216
1217
  TT_DotFix14( FT_Int32  ax,
               FT_Int32  ay,
               FT_Int    bx,
               FT_Int    by )
David Turner's avatar
David Turner committed
1218
1219
1220
  {
    FT_Int32   m, s, hi1, hi2, hi;
    FT_UInt32  l, lo1, lo2, lo;
1221

Werner Lemberg's avatar
   
Werner Lemberg committed
1222

David Turner's avatar
David Turner committed
1223
    /* compute ax*bx as 64-bit value */
Werner Lemberg's avatar
   
Werner Lemberg committed
1224
1225
    l = (FT_UInt32)( ( ax & 0xFFFFU ) * bx );
    m = ( ax >> 16 ) * bx;
1226

Werner Lemberg's avatar
   
Werner Lemberg committed
1227
1228
    lo1 = l + (FT_UInt32)( m << 16 );
    hi1 = ( m >> 16 ) + ( (FT_Int32)l >> 31 ) + ( lo1 < l );
1229

David Turner's avatar
David Turner committed
1230
    /* compute ay*by as 64-bit value */
Werner Lemberg's avatar
   
Werner Lemberg committed
1231
1232
    l = (FT_UInt32)( ( ay & 0xFFFFU ) * by );
    m = ( ay >> 16 ) * by;
1233

Werner Lemberg's avatar
   
Werner Lemberg committed
1234
1235
    lo2 = l + (FT_UInt32)( m << 16 );
    hi2 = ( m >> 16 ) + ( (FT_Int32)l >> 31 ) + ( lo2 < l );
1236

David Turner's avatar
David Turner committed
1237
1238
    /* add them */
    lo = lo1 + lo2;
Werner Lemberg's avatar
   
Werner Lemberg committed
1239
    hi = hi1 + hi2 + ( lo < lo1 );
1240

David Turner's avatar
David Turner committed
1241
    /* divide the result by 2^14 with rounding */
Werner Lemberg's avatar
   
Werner Lemberg committed
1242
    s   = hi >> 31;
David Turner's avatar
David Turner committed
1243
    l   = lo + (FT_UInt32)s;
Werner Lemberg's avatar
   
Werner Lemberg committed
1244
    hi += s + ( l < lo );
David Turner's avatar
David Turner committed
1245
1246
1247
    lo  = l;

    l   = lo + 0x2000U;
Werner Lemberg's avatar
   
Werner Lemberg committed
1248
    hi += ( l < lo );
1249

Werner Lemberg's avatar
   
Werner Lemberg committed
1250
    return ( hi << 18 ) | ( l >> 14 );
David Turner's avatar
David Turner committed
1251
1252
  }

Werner Lemberg's avatar
   
Werner Lemberg committed
1253
1254
1255

  /* return length of given vector */

David Turner's avatar
David Turner committed
1256
1257
1258
#if 0

  static FT_Int32
Werner Lemberg's avatar
   
Werner Lemberg committed
1259
1260
  TT_VecLen( FT_Int32  x,
             FT_Int32  y )
David Turner's avatar
David Turner committed
1261
  {
Werner Lemberg's avatar
   
Werner Lemberg committed
1262
1263
1264
    FT_Int32   m, hi1, hi2, hi;
    FT_UInt32  l, lo1, lo2, lo;

1265

David Turner's avatar
David Turner committed
1266
    /* compute x*x as 64-bit value */
Werner Lemberg's avatar
   
Werner Lemberg committed
1267
1268
    lo = (FT_UInt32)( x & 0xFFFFU );
    hi = x >> 16;
1269

Werner Lemberg's avatar
   
Werner Lemberg committed
1270
1271
1272
    l  = lo * lo;
    m  = hi * lo;
    hi = hi * hi;
1273

Werner Lemberg's avatar
   
Werner Lemberg committed
1274
1275
    lo1 = l + (FT_UInt32)( m << 17 );
    hi1 = hi + ( m >> 15 ) + ( lo1 < l );
1276

David Turner's avatar
David Turner committed
1277
    /* compute y*y as 64-bit value */
Werner Lemberg's avatar
   
Werner Lemberg committed
1278
1279
    lo = (FT_UInt32)( y & 0xFFFFU );
    hi = y >> 16;
1280

Werner Lemberg's avatar
   
Werner Lemberg committed
1281
1282
1283
    l  = lo * lo;
    m  = hi * lo;
    hi = hi * hi;
1284

Werner Lemberg's avatar
   
Werner Lemberg committed
1285
1286
    lo2 = l + (FT_UInt32)( m << 17 );
    hi2 = hi + ( m >> 15 ) + ( lo2 < l );
1287

David Turner's avatar
David Turner committed
1288
1289
    /* add them to get 'x*x+y*y' as 64-bit value */
    lo = lo1 + lo2;
Werner Lemberg's avatar
   
Werner Lemberg committed
1290
    hi = hi1 + hi2 + ( lo < lo1 );
1291

David Turner's avatar
David Turner committed
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
    /* compute the square root of this value */
    {
      FT_UInt32  root, rem, test_div;
      FT_Int     count;


      root = 0;

      {
        rem   = 0;
        count = 32;
        do
        {
Werner Lemberg's avatar
   
Werner Lemberg committed
1305
1306
          rem      = ( rem << 2 ) | ( (FT_UInt32)hi >> 30 );
          hi       = (  hi << 2 ) | (            lo >> 30 );
David Turner's avatar
David Turner committed
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
          lo     <<= 2;
          root   <<= 1;
          test_div = ( root << 1 ) + 1;

          if ( rem >= test_div )
          {
            rem  -= test_div;
            root += 1;
          }
        } while ( --count );
      }
1318

David Turner's avatar
David Turner committed
1319
1320
1321
      return (FT_Int32)root;
    }
  }
Werner Lemberg's avatar
   
Werner Lemberg committed
1322

David Turner's avatar
David Turner committed
1323
#else
1324

Werner Lemberg's avatar
   
Werner Lemberg committed
1325
1326
1327
  /* this version uses FT_Vector_Length which computes the same value */
  /* much, much faster..                                              */
  /*                                                                  */
David Turner's avatar
David Turner committed
1328
1329
1330
1331
1332
1333
  static FT_F26Dot6
  TT_VecLen( FT_F26Dot6  X,
             FT_F26Dot6  Y )
  {
    FT_Vector  v;

Werner Lemberg's avatar
   
Werner Lemberg committed
1334

David Turner's avatar
David Turner committed
1335
1336
    v.x = X;
    v.y = Y;
Werner Lemberg's avatar
   
Werner Lemberg committed
1337

David Turner's avatar
David Turner committed
1338
1339
    return FT_Vector_Length( &v );
  }
1340

David Turner's avatar
David Turner committed
1341
1342
#endif

Werner Lemberg's avatar
   
Werner Lemberg committed
1343

David Turner's avatar
David Turner committed
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
  /*************************************************************************/
  /*                                                                       */
  /* <Function>                                                            */
  /*    Current_Ratio                                                      */
  /*                                                                       */
  /* <Description>                                                         */
  /*    Returns the current aspect ratio scaling factor depending on the   */
  /*    projection vector's state and device resolutions.                  */
  /*                                                                       */
  /* <Return>                                                              */
  /*    The aspect ratio in 16.16 format, always <= 1.0 .                  */
  /*                                                                       */
Werner Lemberg's avatar
   
Werner Lemberg committed
1356
1357
  static FT_Long
  Current_Ratio( EXEC_OP )
David Turner's avatar
David Turner committed
1358
  {
1359
    if ( !CUR.tt_metrics.ratio )
David Turner's avatar
David Turner committed
1360
    {
1361
#ifdef TT_CONFIG_OPTION_UNPATENTED_HINTING
1362
1363
1364
1365
1366
1367
1368
1369
1370
      if ( CUR.face->unpatented_hinting )
      {
        if ( CUR.GS.both_x_axis )
          CUR.tt_metrics.ratio = CUR.tt_metrics.x_ratio;
        else
          CUR.tt_metrics.ratio = CUR.tt_metrics.y_ratio;
      }
      else
#endif
Werner Lemberg's avatar
Werner Lemberg committed
1371
      {
1372
1373
        if ( CUR.GS.projVector.y == 0 )
          CUR.tt_metrics.ratio = CUR.tt_metrics.x_ratio;
Werner Lemberg's avatar
   
Werner Lemberg committed
1374

1375
1376
        else if ( CUR.GS.projVector.x == 0 )
          CUR.tt_metrics.ratio = CUR.tt_metrics.y_ratio;
David Turner's avatar
David Turner committed
1377

1378
1379
1380
1381
        else
        {
          FT_Long  x, y;

Werner Lemberg's avatar
Werner Lemberg committed
1382
1383
1384
1385
1386

          x = TT_MULDIV( CUR.GS.projVector.x,
                         CUR.tt_metrics.x_ratio, 0x4000 );
          y = TT_MULDIV( CUR.GS.projVector.y,
                         CUR.tt_metrics.y_ratio, 0x4000 );
1387
1388
          CUR.tt_metrics.ratio = TT_VecLen( x, y );
        }
Werner Lemberg's avatar
Werner Lemberg committed
1389
1390
      }
    }
David Turner's avatar
David Turner committed
1391
1392
1393
1394
    return CUR.tt_metrics.ratio;
  }


Werner Lemberg's avatar
   
Werner Lemberg committed
1395
1396
  static FT_Long
  Current_Ppem( EXEC_OP )
David Turner's avatar
David Turner committed
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
  {
    return TT_MULFIX( CUR.tt_metrics.ppem, CURRENT_Ratio() );
  }


  /*************************************************************************/
  /*                                                                       */
  /* Functions related to the control value table (CVT).                   */
  /*                                                                       */
  /*************************************************************************/


Werner Lemberg's avatar
   
Werner Lemberg committed
1409
  FT_CALLBACK_DEF( FT_F26Dot6 )
Werner Lemberg's avatar
   
Werner Lemberg committed
1410
  Read_CVT( EXEC_OP_ FT_ULong  idx )
David Turner's avatar
David Turner committed
1411
  {
Werner Lemberg's avatar
   
Werner Lemberg committed
1412
    return CUR.cvt[idx];
David Turner's avatar
David Turner committed
1413
1414
1415
  }


Werner Lemberg's avatar
   
Werner Lemberg committed
1416
  FT_CALLBACK_DEF( FT_F26Dot6 )
Werner Lemberg's avatar
   
Werner Lemberg committed
1417
  Read_CVT_Stretched( EXEC_OP_ FT_ULong  idx )
David Turner's avatar
David Turner committed
1418
  {
Werner Lemberg's avatar
   
Werner Lemberg committed
1419
    return TT_MULFIX( CUR.cvt[idx], CURRENT_Ratio() );
David Turner's avatar
David Turner committed
1420
1421
1422
  }


Werner Lemberg's avatar
   
Werner Lemberg committed
1423
  FT_CALLBACK_DEF( void )
Werner Lemberg's avatar
   
Werner Lemberg committed
1424
  Write_CVT( EXEC_OP_ FT_ULong    idx,
Werner Lemberg's avatar
   
Werner Lemberg committed
1425
                      FT_F26Dot6  value )
David Turner's avatar
David Turner committed
1426
  {
Werner Lemberg's avatar
   
Werner Lemberg committed
1427
    CUR.cvt[idx] = value;
David Turner's avatar
David Turner committed
1428
1429
  }

Werner Lemberg's avatar
   
Werner Lemberg committed
1430

Werner Lemberg's avatar
   
Werner Lemberg committed
1431
  FT_CALLBACK_DEF( void )
Werner Lemberg's avatar
   
Werner Lemberg committed
1432
  Write_CVT_Stretched( EXEC_OP_ FT_ULong    idx,
Werner Lemberg's avatar
   
Werner Lemberg committed
1433
                                FT_F26Dot6  value )
David Turner's avatar
David Turner committed
1434
  {
Werner Lemberg's avatar
   
Werner Lemberg committed
1435
    CUR.cvt[idx] = FT_DivFix( value, CURRENT_Ratio() );
David Turner's avatar
David Turner committed
1436
1437
1438
  }


Werner Lemberg's avatar
   
Werner Lemberg committed
1439
  FT_CALLBACK_DEF( void )
Werner Lemberg's avatar
   
Werner Lemberg committed
1440
  Move_CVT( EXEC_OP_ FT_ULong    idx,
Werner Lemberg's avatar
   
Werner Lemberg committed
1441
                     FT_F26Dot6  value )
David Turner's avatar
David Turner committed
1442
  {
Werner Lemberg's avatar
   
Werner Lemberg committed
1443
    CUR.cvt[idx] += value;
David Turner's avatar
David Turner committed
1444
1445
1446
  }


Werner Lemberg's avatar
   
Werner Lemberg committed
1447
  FT_CALLBACK_DEF( void )
Werner Lemberg's avatar
   
Werner Lemberg committed
1448
  Move_CVT_Stretched( EXEC_OP_ FT_ULong    idx,
Werner Lemberg's avatar
   
Werner Lemberg committed
1449
                               FT_F26Dot6  value )
David Turner's avatar
David Turner committed
1450
  {
Werner Lemberg's avatar
   
Werner Lemberg committed
1451
    CUR.cvt[idx] += FT_DivFix( value, CURRENT_Ratio() );
David Turner's avatar
David Turner committed
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
  }


  /*************************************************************************/
  /*                                                                       */
  /* <Function>                                                            */
  /*    GetShortIns                                                        */
  /*                                                                       */
  /* <Description>                                                         */
  /*    Returns a short integer taken from the instruction stream at       */
  /*    address IP.                                                        */
  /*                                                                       */
  /* <Return>                                                              */
  /*    Short read at code[IP].                                            */
  /*                                                                       */
  /* <Note>                                                                */
  /*    This one could become a macro.                                     */
  /*                                                                       */
Werner Lemberg's avatar
   
Werner Lemberg committed
1470
1471
  static FT_Short
  GetShortIns( EXEC_OP )
David Turner's avatar
David Turner committed
1472
1473
1474
  {
    /* Reading a byte stream so there is no endianess (DaveP) */
    CUR.IP += 2;
1475
    return (FT_Short)( ( CUR.code[CUR.IP - 2] << 8 ) +
Werner Lemberg's avatar
   
Werner Lemberg committed
1476
                         CUR.code[CUR.IP - 1]      );
David Turner's avatar
David Turner committed
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
  }


  /*************************************************************************/
  /*                                                                       */
  /* <Function>                                                            */
  /*    Ins_Goto_CodeRange                                                 */
  /*                                                                       */
  /* <Description>                                                         */
  /*    Goes to a certain code range in the instruction stream.            */
  /*                                                                       */
  /* <Input>                                                               */
  /*    aRange :: The index of the code range.                             */
  /*                                                                       */
  /*    aIP    :: The new IP address in the code range.                    */
  /*                                                                       */
  /* <Return>                                                              */
  /*    SUCCESS or FAILURE.                                                */
  /*                                                                       */
Werner Lemberg's avatar
   
Werner Lemberg committed
1496
1497
1498
  static FT_Bool
  Ins_Goto_CodeRange( EXEC_OP_ FT_Int    aRange,
                               FT_ULong  aIP )
David Turner's avatar
David Turner committed
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525