tizen 2.3.1 release
[framework/graphics/freetype.git] / src / cff / cf2intrp.c
1 /***************************************************************************/
2 /*                                                                         */
3 /*  cf2intrp.c                                                             */
4 /*                                                                         */
5 /*    Adobe's CFF Interpreter (body).                                      */
6 /*                                                                         */
7 /*  Copyright 2007-2014 Adobe Systems Incorporated.                        */
8 /*                                                                         */
9 /*  This software, and all works of authorship, whether in source or       */
10 /*  object code form as indicated by the copyright notice(s) included      */
11 /*  herein (collectively, the "Work") is made available, and may only be   */
12 /*  used, modified, and distributed under the FreeType Project License,    */
13 /*  LICENSE.TXT.  Additionally, subject to the terms and conditions of the */
14 /*  FreeType Project License, each contributor to the Work hereby grants   */
15 /*  to any individual or legal entity exercising permissions granted by    */
16 /*  the FreeType Project License and this section (hereafter, "You" or     */
17 /*  "Your") a perpetual, worldwide, non-exclusive, no-charge,              */
18 /*  royalty-free, irrevocable (except as stated in this section) patent    */
19 /*  license to make, have made, use, offer to sell, sell, import, and      */
20 /*  otherwise transfer the Work, where such license applies only to those  */
21 /*  patent claims licensable by such contributor that are necessarily      */
22 /*  infringed by their contribution(s) alone or by combination of their    */
23 /*  contribution(s) with the Work to which such contribution(s) was        */
24 /*  submitted.  If You institute patent litigation against any entity      */
25 /*  (including a cross-claim or counterclaim in a lawsuit) alleging that   */
26 /*  the Work or a contribution incorporated within the Work constitutes    */
27 /*  direct or contributory patent infringement, then any patent licenses   */
28 /*  granted to You under this License for that Work shall terminate as of  */
29 /*  the date such litigation is filed.                                     */
30 /*                                                                         */
31 /*  By using, modifying, or distributing the Work you indicate that you    */
32 /*  have read and understood the terms and conditions of the               */
33 /*  FreeType Project License as well as those provided in this section,    */
34 /*  and you accept them fully.                                             */
35 /*                                                                         */
36 /***************************************************************************/
37
38
39 #include "cf2ft.h"
40 #include FT_INTERNAL_DEBUG_H
41
42 #include "cf2glue.h"
43 #include "cf2font.h"
44 #include "cf2stack.h"
45 #include "cf2hints.h"
46
47 #include "cf2error.h"
48
49
50   /*************************************************************************/
51   /*                                                                       */
52   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
53   /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
54   /* messages during execution.                                            */
55   /*                                                                       */
56 #undef  FT_COMPONENT
57 #define FT_COMPONENT  trace_cf2interp
58
59
60   /* some operators are not implemented yet */
61 #define CF2_FIXME  FT_TRACE4(( "cf2_interpT2CharString:"            \
62                                " operator not implemented yet\n" ))
63
64
65
66   FT_LOCAL_DEF( void )
67   cf2_hintmask_init( CF2_HintMask  hintmask,
68                      FT_Error*     error )
69   {
70     FT_ZERO( hintmask );
71
72     hintmask->error = error;
73   }
74
75
76   FT_LOCAL_DEF( FT_Bool )
77   cf2_hintmask_isValid( const CF2_HintMask  hintmask )
78   {
79     return hintmask->isValid;
80   }
81
82
83   FT_LOCAL_DEF( FT_Bool )
84   cf2_hintmask_isNew( const CF2_HintMask  hintmask )
85   {
86     return hintmask->isNew;
87   }
88
89
90   FT_LOCAL_DEF( void )
91   cf2_hintmask_setNew( CF2_HintMask  hintmask,
92                        FT_Bool       val )
93   {
94     hintmask->isNew = val;
95   }
96
97
98   /* clients call `getMaskPtr' in order to iterate */
99   /* through hint mask                             */
100
101   FT_LOCAL_DEF( FT_Byte* )
102   cf2_hintmask_getMaskPtr( CF2_HintMask  hintmask )
103   {
104     return hintmask->mask;
105   }
106
107
108   static size_t
109   cf2_hintmask_setCounts( CF2_HintMask  hintmask,
110                           size_t        bitCount )
111   {
112     if ( bitCount > CF2_MAX_HINTS )
113     {
114       /* total of h and v stems must be <= 96 */
115       CF2_SET_ERROR( hintmask->error, Invalid_Glyph_Format );
116       return 0;
117     }
118
119     hintmask->bitCount  = bitCount;
120     hintmask->byteCount = ( hintmask->bitCount + 7 ) / 8;
121
122     hintmask->isValid = TRUE;
123     hintmask->isNew   = TRUE;
124
125     return bitCount;
126   }
127
128
129   /* consume the hintmask bytes from the charstring, advancing the src */
130   /* pointer                                                           */
131   static void
132   cf2_hintmask_read( CF2_HintMask  hintmask,
133                      CF2_Buffer    charstring,
134                      size_t        bitCount )
135   {
136     size_t  i;
137
138 #ifndef CF2_NDEBUG
139     /* these are the bits in the final mask byte that should be zero  */
140     /* Note: this variable is only used in an assert expression below */
141     /* and then only if CF2_NDEBUG is not defined                     */
142     CF2_UInt  mask = ( 1 << ( -(CF2_Int)bitCount & 7 ) ) - 1;
143 #endif
144
145
146     /* initialize counts and isValid */
147     if ( cf2_hintmask_setCounts( hintmask, bitCount ) == 0 )
148       return;
149
150     FT_ASSERT( hintmask->byteCount > 0 );
151
152     FT_TRACE4(( " (maskbytes:" ));
153
154     /* set mask and advance interpreter's charstring pointer */
155     for ( i = 0; i < hintmask->byteCount; i++ )
156     {
157       hintmask->mask[i] = (FT_Byte)cf2_buf_readByte( charstring );
158       FT_TRACE4(( " 0x%02X", hintmask->mask[i] ));
159     }
160
161     FT_TRACE4(( ")\n" ));
162
163     /* assert any unused bits in last byte are zero unless there's a prior */
164     /* error                                                               */
165     /* bitCount -> mask, 0 -> 0, 1 -> 7f, 2 -> 3f, ... 6 -> 3, 7 -> 1      */
166 #ifndef CF2_NDEBUG
167     FT_ASSERT( ( hintmask->mask[hintmask->byteCount - 1] & mask ) == 0 ||
168                *hintmask->error                                        );
169 #endif
170   }
171
172
173   FT_LOCAL_DEF( void )
174   cf2_hintmask_setAll( CF2_HintMask  hintmask,
175                        size_t        bitCount )
176   {
177     size_t    i;
178     CF2_UInt  mask = ( 1 << ( -(CF2_Int)bitCount & 7 ) ) - 1;
179
180
181     /* initialize counts and isValid */
182     if ( cf2_hintmask_setCounts( hintmask, bitCount ) == 0 )
183       return;
184
185     FT_ASSERT( hintmask->byteCount > 0 );
186     FT_ASSERT( hintmask->byteCount <
187                  sizeof ( hintmask->mask ) / sizeof ( hintmask->mask[0] ) );
188
189     /* set mask to all ones */
190     for ( i = 0; i < hintmask->byteCount; i++ )
191       hintmask->mask[i] = 0xFF;
192
193     /* clear unused bits                                              */
194     /* bitCount -> mask, 0 -> 0, 1 -> 7f, 2 -> 3f, ... 6 -> 3, 7 -> 1 */
195     hintmask->mask[hintmask->byteCount - 1] &= ~mask;
196   }
197
198
199   /* Type2 charstring opcodes */
200   enum
201   {
202     cf2_cmdRESERVED_0,   /* 0 */
203     cf2_cmdHSTEM,        /* 1 */
204     cf2_cmdRESERVED_2,   /* 2 */
205     cf2_cmdVSTEM,        /* 3 */
206     cf2_cmdVMOVETO,      /* 4 */
207     cf2_cmdRLINETO,      /* 5 */
208     cf2_cmdHLINETO,      /* 6 */
209     cf2_cmdVLINETO,      /* 7 */
210     cf2_cmdRRCURVETO,    /* 8 */
211     cf2_cmdRESERVED_9,   /* 9 */
212     cf2_cmdCALLSUBR,     /* 10 */
213     cf2_cmdRETURN,       /* 11 */
214     cf2_cmdESC,          /* 12 */
215     cf2_cmdRESERVED_13,  /* 13 */
216     cf2_cmdENDCHAR,      /* 14 */
217     cf2_cmdRESERVED_15,  /* 15 */
218     cf2_cmdRESERVED_16,  /* 16 */
219     cf2_cmdRESERVED_17,  /* 17 */
220     cf2_cmdHSTEMHM,      /* 18 */
221     cf2_cmdHINTMASK,     /* 19 */
222     cf2_cmdCNTRMASK,     /* 20 */
223     cf2_cmdRMOVETO,      /* 21 */
224     cf2_cmdHMOVETO,      /* 22 */
225     cf2_cmdVSTEMHM,      /* 23 */
226     cf2_cmdRCURVELINE,   /* 24 */
227     cf2_cmdRLINECURVE,   /* 25 */
228     cf2_cmdVVCURVETO,    /* 26 */
229     cf2_cmdHHCURVETO,    /* 27 */
230     cf2_cmdEXTENDEDNMBR, /* 28 */
231     cf2_cmdCALLGSUBR,    /* 29 */
232     cf2_cmdVHCURVETO,    /* 30 */
233     cf2_cmdHVCURVETO     /* 31 */
234   };
235
236   enum
237   {
238     cf2_escDOTSECTION,   /* 0 */
239     cf2_escRESERVED_1,   /* 1 */
240     cf2_escRESERVED_2,   /* 2 */
241     cf2_escAND,          /* 3 */
242     cf2_escOR,           /* 4 */
243     cf2_escNOT,          /* 5 */
244     cf2_escRESERVED_6,   /* 6 */
245     cf2_escRESERVED_7,   /* 7 */
246     cf2_escRESERVED_8,   /* 8 */
247     cf2_escABS,          /* 9 */
248     cf2_escADD,          /* 10     like otherADD */
249     cf2_escSUB,          /* 11     like otherSUB */
250     cf2_escDIV,          /* 12 */
251     cf2_escRESERVED_13,  /* 13 */
252     cf2_escNEG,          /* 14 */
253     cf2_escEQ,           /* 15 */
254     cf2_escRESERVED_16,  /* 16 */
255     cf2_escRESERVED_17,  /* 17 */
256     cf2_escDROP,         /* 18 */
257     cf2_escRESERVED_19,  /* 19 */
258     cf2_escPUT,          /* 20     like otherPUT    */
259     cf2_escGET,          /* 21     like otherGET    */
260     cf2_escIFELSE,       /* 22     like otherIFELSE */
261     cf2_escRANDOM,       /* 23     like otherRANDOM */
262     cf2_escMUL,          /* 24     like otherMUL    */
263     cf2_escRESERVED_25,  /* 25 */
264     cf2_escSQRT,         /* 26 */
265     cf2_escDUP,          /* 27     like otherDUP    */
266     cf2_escEXCH,         /* 28     like otherEXCH   */
267     cf2_escINDEX,        /* 29 */
268     cf2_escROLL,         /* 30 */
269     cf2_escRESERVED_31,  /* 31 */
270     cf2_escRESERVED_32,  /* 32 */
271     cf2_escRESERVED_33,  /* 33 */
272     cf2_escHFLEX,        /* 34 */
273     cf2_escFLEX,         /* 35 */
274     cf2_escHFLEX1,       /* 36 */
275     cf2_escFLEX1         /* 37 */
276   };
277
278
279   /* `stemHintArray' does not change once we start drawing the outline. */
280   static void
281   cf2_doStems( const CF2_Font  font,
282                CF2_Stack       opStack,
283                CF2_ArrStack    stemHintArray,
284                CF2_Fixed*      width,
285                FT_Bool*        haveWidth,
286                CF2_Fixed       hintOffset )
287   {
288     CF2_UInt  i;
289     CF2_UInt  count       = cf2_stack_count( opStack );
290     FT_Bool   hasWidthArg = (FT_Bool)( count & 1 );
291
292     /* variable accumulates delta values from operand stack */
293     CF2_Fixed  position = hintOffset;
294
295     if ( hasWidthArg && ! *haveWidth )
296       *width = cf2_stack_getReal( opStack, 0 ) +
297                  cf2_getNominalWidthX( font->decoder );
298
299     if ( font->decoder->width_only )
300       goto exit;
301
302     for ( i = hasWidthArg ? 1 : 0; i < count; i += 2 )
303     {
304       /* construct a CF2_StemHint and push it onto the list */
305       CF2_StemHintRec  stemhint;
306
307
308       stemhint.min  =
309         position   += cf2_stack_getReal( opStack, i );
310       stemhint.max  =
311         position   += cf2_stack_getReal( opStack, i + 1 );
312
313       stemhint.used  = FALSE;
314       stemhint.maxDS =
315       stemhint.minDS = 0;
316
317       cf2_arrstack_push( stemHintArray, &stemhint ); /* defer error check */
318     }
319
320     cf2_stack_clear( opStack );
321
322   exit:
323     /* cf2_doStems must define a width (may be default) */
324     *haveWidth = TRUE;
325   }
326
327
328   static void
329   cf2_doFlex( CF2_Stack       opStack,
330               CF2_Fixed*      curX,
331               CF2_Fixed*      curY,
332               CF2_GlyphPath   glyphPath,
333               const FT_Bool*  readFromStack,
334               FT_Bool         doConditionalLastRead )
335   {
336     CF2_Fixed  vals[14];
337     CF2_UInt   index;
338     FT_Bool    isHFlex;
339     CF2_Int    top, i, j;
340
341
342     vals[0] = *curX;
343     vals[1] = *curY;
344     index   = 0;
345     isHFlex = readFromStack[9] == FALSE;
346     top     = isHFlex ? 9 : 10;
347
348     for ( i = 0; i < top; i++ )
349     {
350       vals[i + 2] = vals[i];
351       if ( readFromStack[i] )
352         vals[i + 2] += cf2_stack_getReal( opStack, index++ );
353     }
354
355     if ( isHFlex )
356       vals[9 + 2] = *curY;
357
358     if ( doConditionalLastRead )
359     {
360       FT_Bool    lastIsX = (FT_Bool)( cf2_fixedAbs( vals[10] - *curX ) >
361                                         cf2_fixedAbs( vals[11] - *curY ) );
362       CF2_Fixed  lastVal = cf2_stack_getReal( opStack, index );
363
364
365       if ( lastIsX )
366       {
367         vals[12] = vals[10] + lastVal;
368         vals[13] = *curY;
369       }
370       else
371       {
372         vals[12] = *curX;
373         vals[13] = vals[11] + lastVal;
374       }
375     }
376     else
377     {
378       if ( readFromStack[10] )
379         vals[12] = vals[10] + cf2_stack_getReal( opStack, index++ );
380       else
381         vals[12] = *curX;
382
383       if ( readFromStack[11] )
384         vals[13] = vals[11] + cf2_stack_getReal( opStack, index );
385       else
386         vals[13] = *curY;
387     }
388
389     for ( j = 0; j < 2; j++ )
390       cf2_glyphpath_curveTo( glyphPath, vals[j * 6 + 2],
391                                         vals[j * 6 + 3],
392                                         vals[j * 6 + 4],
393                                         vals[j * 6 + 5],
394                                         vals[j * 6 + 6],
395                                         vals[j * 6 + 7] );
396
397     cf2_stack_clear( opStack );
398
399     *curX = vals[12];
400     *curY = vals[13];
401   }
402
403
404   /*
405    * `error' is a shared error code used by many objects in this
406    * routine.  Before the code continues from an error, it must check and
407    * record the error in `*error'.  The idea is that this shared
408    * error code will record the first error encountered.  If testing
409    * for an error anyway, the cost of `goto exit' is small, so we do it,
410    * even if continuing would be safe.  In this case, `lastError' is
411    * set, so the testing and storing can be done in one place, at `exit'.
412    *
413    * Continuing after an error is intended for objects which do their own
414    * testing of `*error', e.g., array stack functions.  This allows us to
415    * avoid an extra test after the call.
416    *
417    * Unimplemented opcodes are ignored.
418    *
419    */
420   FT_LOCAL_DEF( void )
421   cf2_interpT2CharString( CF2_Font              font,
422                           CF2_Buffer            buf,
423                           CF2_OutlineCallbacks  callbacks,
424                           const FT_Vector*      translation,
425                           FT_Bool               doingSeac,
426                           CF2_Fixed             curX,
427                           CF2_Fixed             curY,
428                           CF2_Fixed*            width )
429   {
430     /* lastError is used for errors that are immediately tested */
431     FT_Error  lastError = FT_Err_Ok;
432
433     /* pointer to parsed font object */
434     CFF_Decoder*  decoder = font->decoder;
435
436     FT_Error*  error  = &font->error;
437     FT_Memory  memory = font->memory;
438
439     CF2_Fixed  scaleY        = font->innerTransform.d;
440     CF2_Fixed  nominalWidthX = cf2_getNominalWidthX( decoder );
441
442     /* save this for hinting seac accents */
443     CF2_Fixed  hintOriginY = curY;
444
445     CF2_Stack  opStack = NULL;
446     FT_Byte    op1;                       /* first opcode byte */
447
448     /* instruction limit; 20,000,000 matches Avalon */
449     FT_UInt32  instructionLimit = 20000000UL;
450
451     CF2_ArrStackRec  subrStack;
452
453     FT_Bool     haveWidth;
454     CF2_Buffer  charstring = NULL;
455
456     CF2_Int  charstringIndex = -1;       /* initialize to empty */
457
458     /* TODO: placeholders for hint structures */
459
460     /* objects used for hinting */
461     CF2_ArrStackRec  hStemHintArray;
462     CF2_ArrStackRec  vStemHintArray;
463
464     CF2_HintMaskRec   hintMask;
465     CF2_GlyphPathRec  glyphPath;
466
467
468     /* initialize the remaining objects */
469     cf2_arrstack_init( &subrStack,
470                        memory,
471                        error,
472                        sizeof ( CF2_BufferRec ) );
473     cf2_arrstack_init( &hStemHintArray,
474                        memory,
475                        error,
476                        sizeof ( CF2_StemHintRec ) );
477     cf2_arrstack_init( &vStemHintArray,
478                        memory,
479                        error,
480                        sizeof ( CF2_StemHintRec ) );
481
482     /* initialize CF2_StemHint arrays */
483     cf2_hintmask_init( &hintMask, error );
484
485     /* initialize path map to manage drawing operations */
486
487     /* Note: last 4 params are used to handle `MoveToPermissive', which */
488     /*       may need to call `hintMap.Build'                           */
489     /* TODO: MoveToPermissive is gone; are these still needed?          */
490     cf2_glyphpath_init( &glyphPath,
491                         font,
492                         callbacks,
493                         scaleY,
494                         /* hShift, */
495                         &hStemHintArray,
496                         &vStemHintArray,
497                         &hintMask,
498                         hintOriginY,
499                         &font->blues,
500                         translation );
501
502     /*
503      * Initialize state for width parsing.  From the CFF Spec:
504      *
505      *   The first stack-clearing operator, which must be one of hstem,
506      *   hstemhm, vstem, vstemhm, cntrmask, hintmask, hmoveto, vmoveto,
507      *   rmoveto, or endchar, takes an additional argument - the width (as
508      *   described earlier), which may be expressed as zero or one numeric
509      *   argument.
510      *
511      * What we implement here uses the first validly specified width, but
512      * does not detect errors for specifying more than one width.
513      *
514      * If one of the above operators occurs without explicitly specifying
515      * a width, we assume the default width.
516      *
517      */
518     haveWidth = FALSE;
519     *width    = cf2_getDefaultWidthX( decoder );
520
521     /*
522      * Note: at this point, all pointers to resources must be NULL
523      * and all local objects must be initialized.
524      * There must be no branches to exit: above this point.
525      *
526      */
527
528     /* allocate an operand stack */
529     opStack = cf2_stack_init( memory, error );
530     if ( !opStack )
531     {
532       lastError = FT_THROW( Out_Of_Memory );
533       goto exit;
534     }
535
536     /* initialize subroutine stack by placing top level charstring as */
537     /* first element (max depth plus one for the charstring)          */
538     /* Note: Caller owns and must finalize the first charstring.      */
539     /*       Our copy of it does not change that requirement.         */
540     cf2_arrstack_setCount( &subrStack, CF2_MAX_SUBR + 1 );
541
542     charstring  = (CF2_Buffer)cf2_arrstack_getBuffer( &subrStack );
543     *charstring = *buf;    /* structure copy */
544
545     charstringIndex = 0;       /* entry is valid now */
546
547     /* catch errors so far */
548     if ( *error )
549       goto exit;
550
551     /* main interpreter loop */
552     while ( 1 )
553     {
554       if ( cf2_buf_isEnd( charstring ) )
555       {
556         /* If we've reached the end of the charstring, simulate a */
557         /* cf2_cmdRETURN or cf2_cmdENDCHAR.                       */
558         if ( charstringIndex )
559           op1 = cf2_cmdRETURN;  /* end of buffer for subroutine */
560         else
561           op1 = cf2_cmdENDCHAR; /* end of buffer for top level charstring */
562       }
563       else
564         op1 = (FT_Byte)cf2_buf_readByte( charstring );
565
566       /* check for errors once per loop */
567       if ( *error )
568         goto exit;
569
570       instructionLimit--;
571       if ( instructionLimit == 0 )
572       {
573         lastError = FT_THROW( Invalid_Glyph_Format );
574         goto exit;
575       }
576
577       switch( op1 )
578       {
579       case cf2_cmdRESERVED_0:
580       case cf2_cmdRESERVED_2:
581       case cf2_cmdRESERVED_9:
582       case cf2_cmdRESERVED_13:
583       case cf2_cmdRESERVED_15:
584       case cf2_cmdRESERVED_16:
585       case cf2_cmdRESERVED_17:
586         /* we may get here if we have a prior error */
587         FT_TRACE4(( " unknown op (%d)\n", op1 ));
588         break;
589
590       case cf2_cmdHSTEMHM:
591       case cf2_cmdHSTEM:
592         FT_TRACE4(( op1 == cf2_cmdHSTEMHM ? " hstemhm\n" : " hstem\n" ));
593
594         /* never add hints after the mask is computed */
595         if ( cf2_hintmask_isValid( &hintMask ) )
596         {
597           FT_TRACE4(( "cf2_interpT2CharString:"
598                       " invalid horizontal hint mask\n" ));
599           break;
600         }
601
602         cf2_doStems( font,
603                      opStack,
604                      &hStemHintArray,
605                      width,
606                      &haveWidth,
607                      0 );
608
609         if ( font->decoder->width_only )
610             goto exit;
611
612         break;
613
614       case cf2_cmdVSTEMHM:
615       case cf2_cmdVSTEM:
616         FT_TRACE4(( op1 == cf2_cmdVSTEMHM ? " vstemhm\n" : " vstem\n" ));
617
618         /* never add hints after the mask is computed */
619         if ( cf2_hintmask_isValid( &hintMask ) )
620         {
621           FT_TRACE4(( "cf2_interpT2CharString:"
622                       " invalid vertical hint mask\n" ));
623           break;
624         }
625
626         cf2_doStems( font,
627                      opStack,
628                      &vStemHintArray,
629                      width,
630                      &haveWidth,
631                      0 );
632
633         if ( font->decoder->width_only )
634             goto exit;
635
636         break;
637
638       case cf2_cmdVMOVETO:
639         FT_TRACE4(( " vmoveto\n" ));
640
641         if ( cf2_stack_count( opStack ) > 1 && !haveWidth )
642           *width = cf2_stack_getReal( opStack, 0 ) + nominalWidthX;
643
644         /* width is defined or default after this */
645         haveWidth = TRUE;
646
647         if ( font->decoder->width_only )
648             goto exit;
649
650         curY += cf2_stack_popFixed( opStack );
651
652         cf2_glyphpath_moveTo( &glyphPath, curX, curY );
653
654         break;
655
656       case cf2_cmdRLINETO:
657         {
658           CF2_UInt  index;
659           CF2_UInt  count = cf2_stack_count( opStack );
660
661
662           FT_TRACE4(( " rlineto\n" ));
663
664           for ( index = 0; index < count; index += 2 )
665           {
666             curX += cf2_stack_getReal( opStack, index + 0 );
667             curY += cf2_stack_getReal( opStack, index + 1 );
668
669             cf2_glyphpath_lineTo( &glyphPath, curX, curY );
670           }
671
672           cf2_stack_clear( opStack );
673         }
674         continue; /* no need to clear stack again */
675
676       case cf2_cmdHLINETO:
677       case cf2_cmdVLINETO:
678         {
679           CF2_UInt  index;
680           CF2_UInt  count = cf2_stack_count( opStack );
681
682           FT_Bool  isX = op1 == cf2_cmdHLINETO;
683
684
685           FT_TRACE4(( isX ? " hlineto\n" : " vlineto\n" ));
686
687           for ( index = 0; index < count; index++ )
688           {
689             CF2_Fixed  v = cf2_stack_getReal( opStack, index );
690
691
692             if ( isX )
693               curX += v;
694             else
695               curY += v;
696
697             isX = !isX;
698
699             cf2_glyphpath_lineTo( &glyphPath, curX, curY );
700           }
701
702           cf2_stack_clear( opStack );
703         }
704         continue;
705
706       case cf2_cmdRCURVELINE:
707       case cf2_cmdRRCURVETO:
708         {
709           CF2_UInt  count = cf2_stack_count( opStack );
710           CF2_UInt  index = 0;
711
712
713           FT_TRACE4(( op1 == cf2_cmdRCURVELINE ? " rcurveline\n"
714                                                : " rrcurveto\n" ));
715
716           while ( index + 6 <= count )
717           {
718             CF2_Fixed  x1 = cf2_stack_getReal( opStack, index + 0 ) + curX;
719             CF2_Fixed  y1 = cf2_stack_getReal( opStack, index + 1 ) + curY;
720             CF2_Fixed  x2 = cf2_stack_getReal( opStack, index + 2 ) + x1;
721             CF2_Fixed  y2 = cf2_stack_getReal( opStack, index + 3 ) + y1;
722             CF2_Fixed  x3 = cf2_stack_getReal( opStack, index + 4 ) + x2;
723             CF2_Fixed  y3 = cf2_stack_getReal( opStack, index + 5 ) + y2;
724
725
726             cf2_glyphpath_curveTo( &glyphPath, x1, y1, x2, y2, x3, y3 );
727
728             curX   = x3;
729             curY   = y3;
730             index += 6;
731           }
732
733           if ( op1 == cf2_cmdRCURVELINE )
734           {
735             curX += cf2_stack_getReal( opStack, index + 0 );
736             curY += cf2_stack_getReal( opStack, index + 1 );
737
738             cf2_glyphpath_lineTo( &glyphPath, curX, curY );
739           }
740
741           cf2_stack_clear( opStack );
742         }
743         continue; /* no need to clear stack again */
744
745       case cf2_cmdCALLGSUBR:
746       case cf2_cmdCALLSUBR:
747         {
748           CF2_UInt  subrIndex;
749
750
751           FT_TRACE4(( op1 == cf2_cmdCALLGSUBR ? " callgsubr"
752                                               : " callsubr" ));
753
754           if ( charstringIndex > CF2_MAX_SUBR )
755           {
756             /* max subr plus one for charstring */
757             lastError = FT_THROW( Invalid_Glyph_Format );
758             goto exit;                      /* overflow of stack */
759           }
760
761           /* push our current CFF charstring region on subrStack */
762           charstring = (CF2_Buffer)
763                          cf2_arrstack_getPointer( &subrStack,
764                                                   charstringIndex + 1 );
765
766           /* set up the new CFF region and pointer */
767           subrIndex = cf2_stack_popInt( opStack );
768
769           switch ( op1 )
770           {
771           case cf2_cmdCALLGSUBR:
772             FT_TRACE4(( "(%d)\n", subrIndex + decoder->globals_bias ));
773
774             if ( cf2_initGlobalRegionBuffer( decoder,
775                                              subrIndex,
776                                              charstring ) )
777             {
778               lastError = FT_THROW( Invalid_Glyph_Format );
779               goto exit;  /* subroutine lookup or stream error */
780             }
781             break;
782
783           default:
784             /* cf2_cmdCALLSUBR */
785             FT_TRACE4(( "(%d)\n", subrIndex + decoder->locals_bias ));
786
787             if ( cf2_initLocalRegionBuffer( decoder,
788                                             subrIndex,
789                                             charstring ) )
790             {
791               lastError = FT_THROW( Invalid_Glyph_Format );
792               goto exit;  /* subroutine lookup or stream error */
793             }
794           }
795
796           charstringIndex += 1;       /* entry is valid now */
797         }
798         continue; /* do not clear the stack */
799
800       case cf2_cmdRETURN:
801         FT_TRACE4(( " return\n" ));
802
803         if ( charstringIndex < 1 )
804         {
805           /* Note: cannot return from top charstring */
806           lastError = FT_THROW( Invalid_Glyph_Format );
807           goto exit;                      /* underflow of stack */
808         }
809
810         /* restore position in previous charstring */
811         charstring = (CF2_Buffer)
812                        cf2_arrstack_getPointer( &subrStack,
813                                                 --charstringIndex );
814         continue;     /* do not clear the stack */
815
816       case cf2_cmdESC:
817         {
818           FT_Byte  op2 = (FT_Byte)cf2_buf_readByte( charstring );
819
820
821           switch ( op2 )
822           {
823           case cf2_escDOTSECTION:
824             /* something about `flip type of locking' -- ignore it */
825             FT_TRACE4(( " dotsection\n" ));
826
827             break;
828
829           /* TODO: should these operators be supported? */
830           case cf2_escAND: /* in spec */
831             FT_TRACE4(( " and\n" ));
832
833             CF2_FIXME;
834             break;
835
836           case cf2_escOR: /* in spec */
837             FT_TRACE4(( " or\n" ));
838
839             CF2_FIXME;
840             break;
841
842           case cf2_escNOT: /* in spec */
843             FT_TRACE4(( " not\n" ));
844
845             CF2_FIXME;
846             break;
847
848           case cf2_escABS: /* in spec */
849             FT_TRACE4(( " abs\n" ));
850
851             CF2_FIXME;
852             break;
853
854           case cf2_escADD: /* in spec */
855             FT_TRACE4(( " add\n" ));
856
857             CF2_FIXME;
858             break;
859
860           case cf2_escSUB: /* in spec */
861             FT_TRACE4(( " sub\n" ));
862
863             CF2_FIXME;
864             break;
865
866           case cf2_escDIV: /* in spec */
867             FT_TRACE4(( " div\n" ));
868
869             CF2_FIXME;
870             break;
871
872           case cf2_escNEG: /* in spec */
873             FT_TRACE4(( " neg\n" ));
874
875             CF2_FIXME;
876             break;
877
878           case cf2_escEQ: /* in spec */
879             FT_TRACE4(( " eq\n" ));
880
881             CF2_FIXME;
882             break;
883
884           case cf2_escDROP: /* in spec */
885             FT_TRACE4(( " drop\n" ));
886
887             CF2_FIXME;
888             break;
889
890           case cf2_escPUT: /* in spec */
891             FT_TRACE4(( " put\n" ));
892
893             CF2_FIXME;
894             break;
895
896           case cf2_escGET: /* in spec */
897             FT_TRACE4(( " get\n" ));
898
899             CF2_FIXME;
900             break;
901
902           case cf2_escIFELSE: /* in spec */
903             FT_TRACE4(( " ifelse\n" ));
904
905             CF2_FIXME;
906             break;
907
908           case cf2_escRANDOM: /* in spec */
909             FT_TRACE4(( " random\n" ));
910
911             CF2_FIXME;
912             break;
913
914           case cf2_escMUL: /* in spec */
915             FT_TRACE4(( " mul\n" ));
916
917             CF2_FIXME;
918             break;
919
920           case cf2_escSQRT: /* in spec */
921             FT_TRACE4(( " sqrt\n" ));
922
923             CF2_FIXME;
924             break;
925
926           case cf2_escDUP: /* in spec */
927             FT_TRACE4(( " dup\n" ));
928
929             CF2_FIXME;
930             break;
931
932           case cf2_escEXCH: /* in spec */
933             FT_TRACE4(( " exch\n" ));
934
935             CF2_FIXME;
936             break;
937
938           case cf2_escINDEX: /* in spec */
939             FT_TRACE4(( " index\n" ));
940
941             CF2_FIXME;
942             break;
943
944           case cf2_escROLL: /* in spec */
945             FT_TRACE4(( " roll\n" ));
946
947             CF2_FIXME;
948             break;
949
950           case cf2_escHFLEX:
951             {
952               static const FT_Bool  readFromStack[12] =
953               {
954                 TRUE /* dx1 */, FALSE /* dy1 */,
955                 TRUE /* dx2 */, TRUE  /* dy2 */,
956                 TRUE /* dx3 */, FALSE /* dy3 */,
957                 TRUE /* dx4 */, FALSE /* dy4 */,
958                 TRUE /* dx5 */, FALSE /* dy5 */,
959                 TRUE /* dx6 */, FALSE /* dy6 */
960               };
961
962
963               FT_TRACE4(( " hflex\n" ));
964
965               cf2_doFlex( opStack,
966                           &curX,
967                           &curY,
968                           &glyphPath,
969                           readFromStack,
970                           FALSE /* doConditionalLastRead */ );
971             }
972             continue;
973
974           case cf2_escFLEX:
975             {
976               static const FT_Bool  readFromStack[12] =
977               {
978                 TRUE /* dx1 */, TRUE /* dy1 */,
979                 TRUE /* dx2 */, TRUE /* dy2 */,
980                 TRUE /* dx3 */, TRUE /* dy3 */,
981                 TRUE /* dx4 */, TRUE /* dy4 */,
982                 TRUE /* dx5 */, TRUE /* dy5 */,
983                 TRUE /* dx6 */, TRUE /* dy6 */
984               };
985
986
987               FT_TRACE4(( " flex\n" ));
988
989               cf2_doFlex( opStack,
990                           &curX,
991                           &curY,
992                           &glyphPath,
993                           readFromStack,
994                           FALSE /* doConditionalLastRead */ );
995             }
996             break;      /* TODO: why is this not a continue? */
997
998           case cf2_escHFLEX1:
999             {
1000               static const FT_Bool  readFromStack[12] =
1001               {
1002                 TRUE /* dx1 */, TRUE  /* dy1 */,
1003                 TRUE /* dx2 */, TRUE  /* dy2 */,
1004                 TRUE /* dx3 */, FALSE /* dy3 */,
1005                 TRUE /* dx4 */, FALSE /* dy4 */,
1006                 TRUE /* dx5 */, TRUE  /* dy5 */,
1007                 TRUE /* dx6 */, FALSE /* dy6 */
1008               };
1009
1010
1011               FT_TRACE4(( " hflex1\n" ));
1012
1013               cf2_doFlex( opStack,
1014                           &curX,
1015                           &curY,
1016                           &glyphPath,
1017                           readFromStack,
1018                           FALSE /* doConditionalLastRead */ );
1019             }
1020             continue;
1021
1022           case cf2_escFLEX1:
1023             {
1024               static const FT_Bool  readFromStack[12] =
1025               {
1026                 TRUE  /* dx1 */, TRUE  /* dy1 */,
1027                 TRUE  /* dx2 */, TRUE  /* dy2 */,
1028                 TRUE  /* dx3 */, TRUE  /* dy3 */,
1029                 TRUE  /* dx4 */, TRUE  /* dy4 */,
1030                 TRUE  /* dx5 */, TRUE  /* dy5 */,
1031                 FALSE /* dx6 */, FALSE /* dy6 */
1032               };
1033
1034
1035               FT_TRACE4(( " flex1\n" ));
1036
1037               cf2_doFlex( opStack,
1038                           &curX,
1039                           &curY,
1040                           &glyphPath,
1041                           readFromStack,
1042                           TRUE /* doConditionalLastRead */ );
1043             }
1044             continue;
1045
1046           case cf2_escRESERVED_1:
1047           case cf2_escRESERVED_2:
1048           case cf2_escRESERVED_6:
1049           case cf2_escRESERVED_7:
1050           case cf2_escRESERVED_8:
1051           case cf2_escRESERVED_13:
1052           case cf2_escRESERVED_16:
1053           case cf2_escRESERVED_17:
1054           case cf2_escRESERVED_19:
1055           case cf2_escRESERVED_25:
1056           case cf2_escRESERVED_31:
1057           case cf2_escRESERVED_32:
1058           case cf2_escRESERVED_33:
1059           default:
1060             FT_TRACE4(( " unknown op (12, %d)\n", op2 ));
1061
1062           }; /* end of switch statement checking `op2' */
1063
1064         } /* case cf2_cmdESC */
1065         break;
1066
1067       case cf2_cmdENDCHAR:
1068         FT_TRACE4(( " endchar\n" ));
1069
1070         if ( cf2_stack_count( opStack ) == 1 ||
1071              cf2_stack_count( opStack ) == 5 )
1072         {
1073           if ( !haveWidth )
1074             *width = cf2_stack_getReal( opStack, 0 ) + nominalWidthX;
1075         }
1076
1077         /* width is defined or default after this */
1078         haveWidth = TRUE;
1079
1080         if ( font->decoder->width_only )
1081             goto exit;
1082
1083         /* close path if still open */
1084         cf2_glyphpath_closeOpenPath( &glyphPath );
1085
1086         if ( cf2_stack_count( opStack ) > 1 )
1087         {
1088           /* must be either 4 or 5 --                       */
1089           /* this is a (deprecated) implied `seac' operator */
1090
1091           CF2_UInt       achar;
1092           CF2_UInt       bchar;
1093           CF2_BufferRec  component;
1094           CF2_Fixed      dummyWidth;   /* ignore component width */
1095           FT_Error       error2;
1096
1097
1098           if ( doingSeac )
1099           {
1100             lastError = FT_THROW( Invalid_Glyph_Format );
1101             goto exit;      /* nested seac */
1102           }
1103
1104           achar = cf2_stack_popInt( opStack );
1105           bchar = cf2_stack_popInt( opStack );
1106
1107           curY = cf2_stack_popFixed( opStack );
1108           curX = cf2_stack_popFixed( opStack );
1109
1110           error2 = cf2_getSeacComponent( decoder, achar, &component );
1111           if ( error2 )
1112           {
1113              lastError = error2;      /* pass FreeType error through */
1114              goto exit;
1115           }
1116           cf2_interpT2CharString( font,
1117                                   &component,
1118                                   callbacks,
1119                                   translation,
1120                                   TRUE,
1121                                   curX,
1122                                   curY,
1123                                   &dummyWidth );
1124           cf2_freeSeacComponent( decoder, &component );
1125
1126           error2 = cf2_getSeacComponent( decoder, bchar, &component );
1127           if ( error2 )
1128           {
1129             lastError = error2;      /* pass FreeType error through */
1130             goto exit;
1131           }
1132           cf2_interpT2CharString( font,
1133                                   &component,
1134                                   callbacks,
1135                                   translation,
1136                                   TRUE,
1137                                   0,
1138                                   0,
1139                                   &dummyWidth );
1140           cf2_freeSeacComponent( decoder, &component );
1141         }
1142         goto exit;
1143
1144       case cf2_cmdCNTRMASK:
1145       case cf2_cmdHINTMASK:
1146         /* the final \n in the tracing message gets added in      */
1147         /* `cf2_hintmask_read' (which also traces the mask bytes) */
1148         FT_TRACE4(( op1 == cf2_cmdCNTRMASK ? " cntrmask" : " hintmask" ));
1149
1150         /* never add hints after the mask is computed */
1151         if ( cf2_stack_count( opStack ) > 1    &&
1152              cf2_hintmask_isValid( &hintMask ) )
1153         {
1154           FT_TRACE4(( "cf2_interpT2CharString: invalid hint mask\n" ));
1155           break;
1156         }
1157
1158         /* if there are arguments on the stack, there this is an */
1159         /* implied cf2_cmdVSTEMHM                                */
1160         cf2_doStems( font,
1161                      opStack,
1162                      &vStemHintArray,
1163                      width,
1164                      &haveWidth,
1165                      0 );
1166
1167         if ( font->decoder->width_only )
1168             goto exit;
1169
1170         if ( op1 == cf2_cmdHINTMASK )
1171         {
1172           /* consume the hint mask bytes which follow the operator */
1173           cf2_hintmask_read( &hintMask,
1174                              charstring,
1175                              cf2_arrstack_size( &hStemHintArray ) +
1176                                cf2_arrstack_size( &vStemHintArray ) );
1177         }
1178         else
1179         {
1180           /*
1181            * Consume the counter mask bytes which follow the operator:
1182            * Build a temporary hint map, just to place and lock those
1183            * stems participating in the counter mask.  These are most
1184            * likely the dominant hstems, and are grouped together in a
1185            * few counter groups, not necessarily in correspondence
1186            * with the hint groups.  This reduces the chances of
1187            * conflicts between hstems that are initially placed in
1188            * separate hint groups and then brought together.  The
1189            * positions are copied back to `hStemHintArray', so we can
1190            * discard `counterMask' and `counterHintMap'.
1191            *
1192            */
1193           CF2_HintMapRec   counterHintMap;
1194           CF2_HintMaskRec  counterMask;
1195
1196
1197           cf2_hintmap_init( &counterHintMap,
1198                             font,
1199                             &glyphPath.initialHintMap,
1200                             &glyphPath.hintMoves,
1201                             scaleY );
1202           cf2_hintmask_init( &counterMask, error );
1203
1204           cf2_hintmask_read( &counterMask,
1205                              charstring,
1206                              cf2_arrstack_size( &hStemHintArray ) +
1207                                cf2_arrstack_size( &vStemHintArray ) );
1208           cf2_hintmap_build( &counterHintMap,
1209                              &hStemHintArray,
1210                              &vStemHintArray,
1211                              &counterMask,
1212                              0,
1213                              FALSE );
1214         }
1215         break;
1216
1217       case cf2_cmdRMOVETO:
1218         FT_TRACE4(( " rmoveto\n" ));
1219
1220         if ( cf2_stack_count( opStack ) > 2 && !haveWidth )
1221           *width = cf2_stack_getReal( opStack, 0 ) + nominalWidthX;
1222
1223         /* width is defined or default after this */
1224         haveWidth = TRUE;
1225
1226         if ( font->decoder->width_only )
1227             goto exit;
1228
1229         curY += cf2_stack_popFixed( opStack );
1230         curX += cf2_stack_popFixed( opStack );
1231
1232         cf2_glyphpath_moveTo( &glyphPath, curX, curY );
1233
1234         break;
1235
1236       case cf2_cmdHMOVETO:
1237         FT_TRACE4(( " hmoveto\n" ));
1238
1239         if ( cf2_stack_count( opStack ) > 1 && !haveWidth )
1240           *width = cf2_stack_getReal( opStack, 0 ) + nominalWidthX;
1241
1242         /* width is defined or default after this */
1243         haveWidth = TRUE;
1244
1245         if ( font->decoder->width_only )
1246             goto exit;
1247
1248         curX += cf2_stack_popFixed( opStack );
1249
1250         cf2_glyphpath_moveTo( &glyphPath, curX, curY );
1251
1252         break;
1253
1254       case cf2_cmdRLINECURVE:
1255         {
1256           CF2_UInt  count = cf2_stack_count( opStack );
1257           CF2_UInt  index = 0;
1258
1259
1260           FT_TRACE4(( " rlinecurve\n" ));
1261
1262           while ( index + 6 < count )
1263           {
1264             curX += cf2_stack_getReal( opStack, index + 0 );
1265             curY += cf2_stack_getReal( opStack, index + 1 );
1266
1267             cf2_glyphpath_lineTo( &glyphPath, curX, curY );
1268             index += 2;
1269           }
1270
1271           while ( index < count )
1272           {
1273             CF2_Fixed  x1 = cf2_stack_getReal( opStack, index + 0 ) + curX;
1274             CF2_Fixed  y1 = cf2_stack_getReal( opStack, index + 1 ) + curY;
1275             CF2_Fixed  x2 = cf2_stack_getReal( opStack, index + 2 ) + x1;
1276             CF2_Fixed  y2 = cf2_stack_getReal( opStack, index + 3 ) + y1;
1277             CF2_Fixed  x3 = cf2_stack_getReal( opStack, index + 4 ) + x2;
1278             CF2_Fixed  y3 = cf2_stack_getReal( opStack, index + 5 ) + y2;
1279
1280
1281             cf2_glyphpath_curveTo( &glyphPath, x1, y1, x2, y2, x3, y3 );
1282
1283             curX   = x3;
1284             curY   = y3;
1285             index += 6;
1286           }
1287
1288           cf2_stack_clear( opStack );
1289         }
1290         continue; /* no need to clear stack again */
1291
1292       case cf2_cmdVVCURVETO:
1293         {
1294           CF2_UInt  count = cf2_stack_count( opStack );
1295           CF2_UInt  index = 0;
1296
1297
1298           FT_TRACE4(( " vvcurveto\n" ));
1299
1300           while ( index < count )
1301           {
1302             CF2_Fixed  x1, y1, x2, y2, x3, y3;
1303
1304
1305             if ( ( count - index ) & 1 )
1306             {
1307               x1 = cf2_stack_getReal( opStack, index ) + curX;
1308
1309               ++index;
1310             }
1311             else
1312               x1 = curX;
1313
1314             y1 = cf2_stack_getReal( opStack, index + 0 ) + curY;
1315             x2 = cf2_stack_getReal( opStack, index + 1 ) + x1;
1316             y2 = cf2_stack_getReal( opStack, index + 2 ) + y1;
1317             x3 = x2;
1318             y3 = cf2_stack_getReal( opStack, index + 3 ) + y2;
1319
1320             cf2_glyphpath_curveTo( &glyphPath, x1, y1, x2, y2, x3, y3 );
1321
1322             curX   = x3;
1323             curY   = y3;
1324             index += 4;
1325           }
1326
1327           cf2_stack_clear( opStack );
1328         }
1329         continue; /* no need to clear stack again */
1330
1331       case cf2_cmdHHCURVETO:
1332         {
1333           CF2_UInt  count = cf2_stack_count( opStack );
1334           CF2_UInt  index = 0;
1335
1336
1337           FT_TRACE4(( " hhcurveto\n" ));
1338
1339           while ( index < count )
1340           {
1341             CF2_Fixed  x1, y1, x2, y2, x3, y3;
1342
1343
1344             if ( ( count - index ) & 1 )
1345             {
1346               y1 = cf2_stack_getReal( opStack, index ) + curY;
1347
1348               ++index;
1349             }
1350             else
1351               y1 = curY;
1352
1353             x1 = cf2_stack_getReal( opStack, index + 0 ) + curX;
1354             x2 = cf2_stack_getReal( opStack, index + 1 ) + x1;
1355             y2 = cf2_stack_getReal( opStack, index + 2 ) + y1;
1356             x3 = cf2_stack_getReal( opStack, index + 3 ) + x2;
1357             y3 = y2;
1358
1359             cf2_glyphpath_curveTo( &glyphPath, x1, y1, x2, y2, x3, y3 );
1360
1361             curX   = x3;
1362             curY   = y3;
1363             index += 4;
1364           }
1365
1366           cf2_stack_clear( opStack );
1367         }
1368         continue; /* no need to clear stack again */
1369
1370       case cf2_cmdVHCURVETO:
1371       case cf2_cmdHVCURVETO:
1372         {
1373           CF2_UInt  count = cf2_stack_count( opStack );
1374           CF2_UInt  index = 0;
1375
1376           FT_Bool  alternate = op1 == cf2_cmdHVCURVETO;
1377
1378
1379           FT_TRACE4(( alternate ? " hvcurveto\n" : " vhcurveto\n" ));
1380
1381           while ( index < count )
1382           {
1383             CF2_Fixed x1, x2, x3, y1, y2, y3;
1384
1385
1386             if ( alternate )
1387             {
1388               x1 = cf2_stack_getReal( opStack, index + 0 ) + curX;
1389               y1 = curY;
1390               x2 = cf2_stack_getReal( opStack, index + 1 ) + x1;
1391               y2 = cf2_stack_getReal( opStack, index + 2 ) + y1;
1392               y3 = cf2_stack_getReal( opStack, index + 3 ) + y2;
1393
1394               if ( count - index == 5 )
1395               {
1396                 x3 = cf2_stack_getReal( opStack, index + 4 ) + x2;
1397
1398                 ++index;
1399               }
1400               else
1401                 x3 = x2;
1402
1403               alternate = FALSE;
1404             }
1405             else
1406             {
1407               x1 = curX;
1408               y1 = cf2_stack_getReal( opStack, index + 0 ) + curY;
1409               x2 = cf2_stack_getReal( opStack, index + 1 ) + x1;
1410               y2 = cf2_stack_getReal( opStack, index + 2 ) + y1;
1411               x3 = cf2_stack_getReal( opStack, index + 3 ) + x2;
1412
1413               if ( count - index == 5 )
1414               {
1415                 y3 = cf2_stack_getReal( opStack, index + 4 ) + y2;
1416
1417                 ++index;
1418               }
1419               else
1420                 y3 = y2;
1421
1422               alternate = TRUE;
1423             }
1424
1425             cf2_glyphpath_curveTo( &glyphPath, x1, y1, x2, y2, x3, y3 );
1426
1427             curX   = x3;
1428             curY   = y3;
1429             index += 4;
1430           }
1431
1432           cf2_stack_clear( opStack );
1433         }
1434         continue;     /* no need to clear stack again */
1435
1436       case cf2_cmdEXTENDEDNMBR:
1437         {
1438           CF2_Int  v;
1439
1440
1441           v = (FT_Short)( ( cf2_buf_readByte( charstring ) << 8 ) |
1442                             cf2_buf_readByte( charstring )        );
1443
1444           FT_TRACE4(( " %d", v ));
1445
1446           cf2_stack_pushInt( opStack, v );
1447         }
1448         continue;
1449
1450       default:
1451         /* numbers */
1452         {
1453           if ( /* op1 >= 32 && */ op1 <= 246 )
1454           {
1455             CF2_Int  v;
1456
1457
1458             v = op1 - 139;
1459
1460             FT_TRACE4(( " %d", v ));
1461
1462             /* -107 .. 107 */
1463             cf2_stack_pushInt( opStack, v );
1464           }
1465
1466           else if ( /* op1 >= 247 && */ op1 <= 250 )
1467           {
1468             CF2_Int  v;
1469
1470
1471             v  = op1;
1472             v -= 247;
1473             v *= 256;
1474             v += cf2_buf_readByte( charstring );
1475             v += 108;
1476
1477             FT_TRACE4(( " %d", v ));
1478
1479             /* 108 .. 1131 */
1480             cf2_stack_pushInt( opStack, v );
1481           }
1482
1483           else if ( /* op1 >= 251 && */ op1 <= 254 )
1484           {
1485             CF2_Int  v;
1486
1487
1488             v  = op1;
1489             v -= 251;
1490             v *= 256;
1491             v += cf2_buf_readByte( charstring );
1492             v  = -v - 108;
1493
1494             FT_TRACE4(( " %d", v ));
1495
1496             /* -1131 .. -108 */
1497             cf2_stack_pushInt( opStack, v );
1498           }
1499
1500           else /* op1 == 255 */
1501           {
1502             CF2_Fixed  v;
1503
1504
1505             v = (CF2_Fixed)
1506                   ( ( (FT_UInt32)cf2_buf_readByte( charstring ) << 24 ) |
1507                     ( (FT_UInt32)cf2_buf_readByte( charstring ) << 16 ) |
1508                     ( (FT_UInt32)cf2_buf_readByte( charstring ) <<  8 ) |
1509                       (FT_UInt32)cf2_buf_readByte( charstring )         );
1510
1511             FT_TRACE4(( " %.2f", v / 65536.0 ));
1512
1513             cf2_stack_pushFixed( opStack, v );
1514           }
1515         }
1516         continue;   /* don't clear stack */
1517
1518       } /* end of switch statement checking `op1' */
1519
1520       cf2_stack_clear( opStack );
1521
1522     } /* end of main interpreter loop */
1523
1524     /* we get here if the charstring ends without cf2_cmdENDCHAR */
1525     FT_TRACE4(( "cf2_interpT2CharString:"
1526                 "  charstring ends without ENDCHAR\n" ));
1527
1528   exit:
1529     /* check whether last error seen is also the first one */
1530     cf2_setError( error, lastError );
1531
1532     /* free resources from objects we've used */
1533     cf2_glyphpath_finalize( &glyphPath );
1534     cf2_arrstack_finalize( &vStemHintArray );
1535     cf2_arrstack_finalize( &hStemHintArray );
1536     cf2_arrstack_finalize( &subrStack );
1537     cf2_stack_free( opStack );
1538
1539     FT_TRACE4(( "\n" ));
1540
1541     return;
1542   }
1543
1544
1545 /* END */