freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Devel] Radix numbers in type1 format


From: Martin Muskens
Subject: [Devel] Radix numbers in type1 format
Date: Thu, 30 Aug 2001 13:37:29 +0200

Hi all,

in the file psobjs.c the routine t1_toint is not (yet) suited for the use of
numbers in the radix format.
Instead of decimal number some fonts define their numbers in a radix format.
We have encountered a few.
For this purpose the next routine can be used to assist t1_toint. The
modification to t1_toint is also inbetween #ifdef AURELON:

Best regards
Martin Muskens

#ifdef AURELON
static FT_Long  T1Radix( FT_Long radixBase, FT_Byte** cur, FT_Byte* limit )
{
        FT_Long result = 0;
        FT_Byte radixEndChar0 = (FT_Byte)( radixBase > 10 ? '9' + 1 : '0' +
radixBase );
        FT_Byte radixEndChar1 = (FT_Byte)( 'A' + radixBase - 10 );
        FT_Byte radixEndChar2 = (FT_Byte)( 'a' + radixBase - 10 );
        while( *cur < limit )
        {
                if( (*cur)[0] >= '0' && (*cur)[0] < radixEndChar0 )
                        result = result * radixBase + (*cur)[0] - '0';
                else if( radixBase > 10 && (*cur)[0] >= 'A' && (*cur)[0] <
radixEndChar1 )
                        result = result * radixBase + ( (*cur)[0] - 'A' + 10
);
                else if( radixBase > 10 && (*cur)[0] >= 'a' && (*cur)[0] <
radixEndChar2 )
                        result = result * radixBase + ( (*cur)[0] - 'a' + 10
);
                else
                        return result;
                ++(*cur);
        }
        return result;
}
#endif


  static FT_Long
  t1_toint( FT_Byte**  cursor,
            FT_Byte*   limit )
  {
    FT_Long   result = 0;
    FT_Byte*  cur    = *cursor;
    FT_Byte   c = '\0', d;


    for ( ; cur < limit; cur++ )
    {
      c = *cur;
      d = (FT_Byte)( c - '0' );
      if ( d < 10 )
        break;

      if ( c == '-' )
      {
        cur++;
        break;
      }
    }

    if ( cur < limit )
    {
      do
      {
        d = (FT_Byte)( cur[0] - '0' );
#ifdef AURELON
                        if( d >= 10 )
                        {
                                if( cur[0] == '#' )
                                {
                                        ++cur;
                                        result = T1Radix( result, &cur,
limit );
                                }
                                break;
                        }

#else
        if ( d >= 10 )
          break;
#endif

        result = result * 10 + d;
        cur++;

      } while ( cur < limit );

      if ( c == '-' )
        result = -result;
    }

    *cursor = cur;
    return result;
  }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]