< prev index next >

src/java.desktop/share/native/libfreetype/src/psaux/psstack.c

Print this page


   1 /***************************************************************************/
   2 /*                                                                         */
   3 /*  psstack.c                                                              */
   4 /*                                                                         */
   5 /*    Adobe's code for emulating a CFF stack (body).                       */
   6 /*                                                                         */
   7 /*  Copyright 2007-2013 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 "psft.h"
  40 #include FT_INTERNAL_DEBUG_H
  41 
  42 #include "psglue.h"
  43 #include "psfont.h"
  44 #include "psstack.h"
  45 
  46 #include "pserror.h"
  47 
  48 
  49   /* Allocate and initialize an instance of CF2_Stack.       */
  50   /* Note: This function returns NULL on error (does not set */
  51   /* `error').                                               */
  52   FT_LOCAL_DEF( CF2_Stack )
  53   cf2_stack_init( FT_Memory  memory,
  54                   FT_Error*  e,
  55                   FT_UInt    stackSize )
  56   {


 241   FT_LOCAL_DEF( void )
 242   cf2_stack_roll( CF2_Stack  stack,
 243                   CF2_Int    count,
 244                   CF2_Int    shift )
 245   {
 246     /* we initialize this variable to avoid compiler warnings */
 247     CF2_StackNumber  last = { { 0 }, CF2_NumberInt };
 248 
 249     CF2_Int  start_idx, idx, i;
 250 
 251 
 252     if ( count < 2 )
 253       return; /* nothing to do (values 0 and 1), or undefined value */
 254 
 255     if ( (CF2_UInt)count > cf2_stack_count( stack ) )
 256     {
 257       CF2_SET_ERROR( stack->error, Stack_Overflow );
 258       return;
 259     }
 260 



 261     if ( shift < 0 )
 262       shift = -( ( -shift ) % count );
 263     else
 264       shift %= count;
 265 
 266     if ( shift == 0 )
 267       return; /* nothing to do */
 268 
 269     /* We use the following algorithm to do the rolling, */
 270     /* which needs two temporary variables only.         */
 271     /*                                                   */
 272     /* Example:                                          */
 273     /*                                                   */
 274     /*   count = 8                                       */
 275     /*   shift = 2                                       */
 276     /*                                                   */
 277     /*   stack indices before roll:  7 6 5 4 3 2 1 0     */
 278     /*   stack indices after roll:   1 0 7 6 5 4 3 2     */
 279     /*                                                   */
 280     /* The value of index 0 gets moved to index 2, while */


   1 /****************************************************************************
   2  *
   3  * psstack.c
   4  *
   5  *   Adobe's code for emulating a CFF stack (body).
   6  *
   7  * Copyright 2007-2013 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 "psft.h"
  40 #include FT_INTERNAL_DEBUG_H
  41 
  42 #include "psglue.h"
  43 #include "psfont.h"
  44 #include "psstack.h"
  45 
  46 #include "pserror.h"
  47 
  48 
  49   /* Allocate and initialize an instance of CF2_Stack.       */
  50   /* Note: This function returns NULL on error (does not set */
  51   /* `error').                                               */
  52   FT_LOCAL_DEF( CF2_Stack )
  53   cf2_stack_init( FT_Memory  memory,
  54                   FT_Error*  e,
  55                   FT_UInt    stackSize )
  56   {


 241   FT_LOCAL_DEF( void )
 242   cf2_stack_roll( CF2_Stack  stack,
 243                   CF2_Int    count,
 244                   CF2_Int    shift )
 245   {
 246     /* we initialize this variable to avoid compiler warnings */
 247     CF2_StackNumber  last = { { 0 }, CF2_NumberInt };
 248 
 249     CF2_Int  start_idx, idx, i;
 250 
 251 
 252     if ( count < 2 )
 253       return; /* nothing to do (values 0 and 1), or undefined value */
 254 
 255     if ( (CF2_UInt)count > cf2_stack_count( stack ) )
 256     {
 257       CF2_SET_ERROR( stack->error, Stack_Overflow );
 258       return;
 259     }
 260 
 261     /* before C99 it is implementation-defined whether    */
 262     /* the result of `%' is negative if the first operand */
 263     /* is negative                                        */
 264     if ( shift < 0 )
 265       shift = -( ( -shift ) % count );
 266     else
 267       shift %= count;
 268 
 269     if ( shift == 0 )
 270       return; /* nothing to do */
 271 
 272     /* We use the following algorithm to do the rolling, */
 273     /* which needs two temporary variables only.         */
 274     /*                                                   */
 275     /* Example:                                          */
 276     /*                                                   */
 277     /*   count = 8                                       */
 278     /*   shift = 2                                       */
 279     /*                                                   */
 280     /*   stack indices before roll:  7 6 5 4 3 2 1 0     */
 281     /*   stack indices after roll:   1 0 7 6 5 4 3 2     */
 282     /*                                                   */
 283     /* The value of index 0 gets moved to index 2, while */


< prev index next >