misc/libfreetype/src/cff/cffparse.c
author Bryan Dunsmore <dunsmoreb@gmail.com>
Sat, 01 Dec 2012 15:52:36 -0600
branchwebgl
changeset 8113 0ad9c42dca7c
parent 5172 88f2e05288ba
permissions -rw-r--r--
Refactor Clang module.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
/*  cffparse.c                                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
/*    CFF token stream parser (body)                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
/*  Copyright 1996-2001, 2002, 2003, 2004, 2007, 2008, 2009, 2010 by       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*  This file is part of the FreeType project, and may only be used,       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  modified, and distributed under the terms of the FreeType project      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
/*  this file you indicate that you have read the license and              */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
/*  understand and accept it fully.                                        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
#include "cffparse.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
#include FT_INTERNAL_STREAM_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
#include FT_INTERNAL_DEBUG_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
#include "cfferrs.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
#include "cffpic.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  /* messages during execution.                                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
#define FT_COMPONENT  trace_cffparse
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  cff_parser_init( CFF_Parser  parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
                   FT_UInt     code,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
                   void*       object,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
                   FT_Library  library)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
    FT_MEM_ZERO( parser, sizeof ( *parser ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
    parser->top         = parser->stack;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
    parser->object_code = code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
    parser->object      = object;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
    parser->library     = library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
  /* read an integer */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
  static FT_Long
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
  cff_parse_integer( FT_Byte*  start,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
                     FT_Byte*  limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
    FT_Byte*  p   = start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
    FT_Int    v   = *p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
    FT_Long   val = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
    if ( v == 28 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
      if ( p + 2 > limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
        goto Bad;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
      val = (FT_Short)( ( (FT_Int)p[0] << 8 ) | p[1] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
      p  += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
    else if ( v == 29 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
      if ( p + 4 > limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
        goto Bad;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
      val = ( (FT_Long)p[0] << 24 ) |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
            ( (FT_Long)p[1] << 16 ) |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
            ( (FT_Long)p[2] <<  8 ) |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
                       p[3];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
      p += 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
    else if ( v < 247 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
      val = v - 139;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
    else if ( v < 251 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
      if ( p + 1 > limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
        goto Bad;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
      val = ( v - 247 ) * 256 + p[0] + 108;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
      p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
      if ( p + 1 > limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
        goto Bad;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
      val = -( v - 251 ) * 256 - p[0] - 108;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
      p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
    return val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
  Bad:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
    val = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
    goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
  static const FT_Long power_tens[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
    1L,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
    10L,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
    100L,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
    1000L,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
    10000L,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
    100000L,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
    1000000L,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
    10000000L,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
    100000000L,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
    1000000000L
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
  /* read a real */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
  static FT_Fixed
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
  cff_parse_real( FT_Byte*  start,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
                  FT_Byte*  limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
                  FT_Long   power_ten,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
                  FT_Long*  scaling )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
    FT_Byte*  p = start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
    FT_UInt   nib;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
    FT_UInt   phase;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
    FT_Long   result, number, exponent;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
    FT_Int    sign = 0, exponent_sign = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
    FT_Long   exponent_add, integer_length, fraction_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
    if ( scaling )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
      *scaling = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
    result = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
    number   = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
    exponent = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
    exponent_add    = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
    integer_length  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    fraction_length = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
    /* First of all, read the integer part. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
    phase = 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
    for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
      /* If we entered this iteration with phase == 4, we need to */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
      /* read a new byte.  This also skips past the initial 0x1E. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
      if ( phase )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
        p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
        /* Make sure we don't read past the end. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
        if ( p >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
      /* Get the nibble. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
      nib   = ( p[0] >> phase ) & 0xF;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
      phase = 4 - phase;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
      if ( nib == 0xE )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
        sign = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
      else if ( nib > 9 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
        /* Increase exponent if we can't add the digit. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
        if ( number >= 0xCCCCCCCL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
          exponent_add++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
        /* Skip leading zeros. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
        else if ( nib || number )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
          integer_length++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
          number = number * 10 + nib;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
    /* Read fraction part, if any. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
    if ( nib == 0xa )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
      for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
        /* If we entered this iteration with phase == 4, we need */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
        /* to read a new byte.                                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
        if ( phase )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
          p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
          /* Make sure we don't read past the end. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
          if ( p >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
        /* Get the nibble. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
        nib   = ( p[0] >> phase ) & 0xF;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
        phase = 4 - phase;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
        if ( nib >= 10 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
        /* Skip leading zeros if possible. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
        if ( !nib && !number )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
          exponent_add--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
        /* Only add digit if we don't overflow. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
        else if ( number < 0xCCCCCCCL && fraction_length < 9 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
          fraction_length++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
          number = number * 10 + nib;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
    /* Read exponent, if any. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
    if ( nib == 12 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
      exponent_sign = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
      nib           = 11;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
    if ( nib == 11 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
      for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
        /* If we entered this iteration with phase == 4, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
        /* we need to read a new byte.                   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
        if ( phase )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
          p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
          /* Make sure we don't read past the end. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
          if ( p >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
            goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
        /* Get the nibble. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
        nib   = ( p[0] >> phase ) & 0xF;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
        phase = 4 - phase;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
        if ( nib >= 10 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
        exponent = exponent * 10 + nib;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
        /* Arbitrarily limit exponent. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
        if ( exponent > 1000 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
      if ( exponent_sign )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
        exponent = -exponent;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
    /* We don't check `power_ten' and `exponent_add'. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
    exponent += power_ten + exponent_add;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
    if ( scaling )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
      /* Only use `fraction_length'. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
      fraction_length += integer_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
      exponent        += integer_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
      if ( fraction_length <= 5 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
        if ( number > 0x7FFFL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
          result   = FT_DivFix( number, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
          *scaling = exponent - fraction_length + 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
          if ( exponent > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
            FT_Long  new_fraction_length, shift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
            /* Make `scaling' as small as possible. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
            new_fraction_length = FT_MIN( exponent, 5 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
            exponent           -= new_fraction_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
            shift               = new_fraction_length - fraction_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
            number *= power_tens[shift];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
            if ( number > 0x7FFFL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
              number   /= 10;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
              exponent += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
            exponent -= fraction_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
          result   = number << 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
          *scaling = exponent;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
        if ( ( number / power_tens[fraction_length - 5] ) > 0x7FFFL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
          result   = FT_DivFix( number, power_tens[fraction_length - 4] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
          *scaling = exponent - 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
          result   = FT_DivFix( number, power_tens[fraction_length - 5] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
          *scaling = exponent - 5;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
      integer_length  += exponent;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
      fraction_length -= exponent;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
      /* Check for overflow and underflow. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
      if ( FT_ABS( integer_length ) > 5 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
      /* Remove non-significant digits. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
      if ( integer_length < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
        number          /= power_tens[-integer_length];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
        fraction_length += integer_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
      /* this can only happen if exponent was non-zero */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
      if ( fraction_length == 10 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
        number          /= 10;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
        fraction_length -= 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
      /* Convert into 16.16 format. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
      if ( fraction_length > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
        if ( ( number / power_tens[fraction_length] ) > 0x7FFFL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
        result = FT_DivFix( number, power_tens[fraction_length] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
        number *= power_tens[-fraction_length];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
        if ( number > 0x7FFFL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
          goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
        result = number << 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
    if ( sign )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
      result = -result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
    return result;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
  /* read a number, either integer or real */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
  static FT_Long
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
  cff_parse_num( FT_Byte**  d )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
    return **d == 30 ? ( cff_parse_real( d[0], d[1], 0, NULL ) >> 16 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
                     :   cff_parse_integer( d[0], d[1] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
  /* read a floating point number, either integer or real */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
  static FT_Fixed
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
  cff_parse_fixed( FT_Byte**  d )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
    return **d == 30 ? cff_parse_real( d[0], d[1], 0, NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
                     : cff_parse_integer( d[0], d[1] ) << 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
  /* read a floating point number, either integer or real, */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
  /* but return `10^scaling' times the number read in      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
  static FT_Fixed
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
  cff_parse_fixed_scaled( FT_Byte**  d,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
                          FT_Long    scaling )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
    return **d == 30 ? cff_parse_real( d[0], d[1], scaling, NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
                     : ( cff_parse_integer( d[0], d[1] ) *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
                           power_tens[scaling] ) << 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
  /* read a floating point number, either integer or real,     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
  /* and return it as precise as possible -- `scaling' returns */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
  /* the scaling factor (as a power of 10)                     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
  static FT_Fixed
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
  cff_parse_fixed_dynamic( FT_Byte**  d,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
                           FT_Long*   scaling )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
    FT_ASSERT( scaling );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
    if ( **d == 30 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
      return cff_parse_real( d[0], d[1], 0, scaling );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
      FT_Long  number;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
      FT_Int   integer_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
      number = cff_parse_integer( d[0], d[1] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
      if ( number > 0x7FFFL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
        for ( integer_length = 5; integer_length < 10; integer_length++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
          if ( number < power_tens[integer_length] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
            break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
        if ( ( number / power_tens[integer_length - 5] ) > 0x7FFFL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
          *scaling = integer_length - 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
          return FT_DivFix( number, power_tens[integer_length - 4] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
          *scaling = integer_length - 5;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
          return FT_DivFix( number, power_tens[integer_length - 5] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
        *scaling = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
        return number << 16;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
  cff_parse_font_matrix( CFF_Parser  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
    CFF_FontRecDict  dict   = (CFF_FontRecDict)parser->object;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
    FT_Matrix*       matrix = &dict->font_matrix;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
    FT_Vector*       offset = &dict->font_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
    FT_ULong*        upm    = &dict->units_per_em;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
    FT_Byte**        data   = parser->stack;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
    FT_Error         error  = CFF_Err_Stack_Underflow;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
    if ( parser->top >= parser->stack + 6 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
      FT_Long  scaling;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
      error = CFF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
      /* We expect a well-formed font matrix, this is, the matrix elements */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
      /* `xx' and `yy' are of approximately the same magnitude.  To avoid  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
      /* loss of precision, we use the magnitude of element `xx' to scale  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
      /* all other elements.  The scaling factor is then contained in the  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
      /* `units_per_em' value.                                             */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
      matrix->xx = cff_parse_fixed_dynamic( data++, &scaling );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
      scaling = -scaling;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
      if ( scaling < 0 || scaling > 9 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
        /* Return default matrix in case of unlikely values. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
        matrix->xx = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
        matrix->yx = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
        matrix->yx = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
        matrix->yy = 0x10000L;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
        offset->x  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
        offset->y  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
        *upm       = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
      matrix->yx = cff_parse_fixed_scaled( data++, scaling );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
      matrix->xy = cff_parse_fixed_scaled( data++, scaling );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
      matrix->yy = cff_parse_fixed_scaled( data++, scaling );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
      offset->x  = cff_parse_fixed_scaled( data++, scaling );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
      offset->y  = cff_parse_fixed_scaled( data,   scaling );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
      *upm = power_tens[scaling];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
  cff_parse_font_bbox( CFF_Parser  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
    CFF_FontRecDict  dict = (CFF_FontRecDict)parser->object;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
    FT_BBox*         bbox = &dict->font_bbox;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
    FT_Byte**        data = parser->stack;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
    FT_Error         error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
    error = CFF_Err_Stack_Underflow;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
    if ( parser->top >= parser->stack + 4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
      bbox->xMin = FT_RoundFix( cff_parse_fixed( data++ ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
      bbox->yMin = FT_RoundFix( cff_parse_fixed( data++ ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
      bbox->xMax = FT_RoundFix( cff_parse_fixed( data++ ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
      bbox->yMax = FT_RoundFix( cff_parse_fixed( data   ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
      error = CFF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
  cff_parse_private_dict( CFF_Parser  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
    CFF_FontRecDict  dict = (CFF_FontRecDict)parser->object;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
    FT_Byte**        data = parser->stack;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
    FT_Error         error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
    error = CFF_Err_Stack_Underflow;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
    if ( parser->top >= parser->stack + 2 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
      dict->private_size   = cff_parse_num( data++ );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
      dict->private_offset = cff_parse_num( data   );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
      error = CFF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
  static FT_Error
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
  cff_parse_cid_ros( CFF_Parser  parser )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
    CFF_FontRecDict  dict = (CFF_FontRecDict)parser->object;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
    FT_Byte**        data = parser->stack;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
    FT_Error         error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
    error = CFF_Err_Stack_Underflow;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
    if ( parser->top >= parser->stack + 3 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
      dict->cid_registry   = (FT_UInt)cff_parse_num ( data++ );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
      dict->cid_ordering   = (FT_UInt)cff_parse_num ( data++ );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
      if ( **data == 30 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
        FT_TRACE1(( "cff_parse_cid_ros: real supplement is rounded\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
      dict->cid_supplement = cff_parse_num( data );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
      if ( dict->cid_supplement < 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
        FT_TRACE1(( "cff_parse_cid_ros: negative supplement %d is found\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
                   dict->cid_supplement ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
      error = CFF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
#define CFF_FIELD_NUM( code, name ) \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
          CFF_FIELD( code, name, cff_kind_num )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
#define CFF_FIELD_FIXED( code, name ) \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
          CFF_FIELD( code, name, cff_kind_fixed )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
#define CFF_FIELD_FIXED_1000( code, name ) \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
          CFF_FIELD( code, name, cff_kind_fixed_thousand )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
#define CFF_FIELD_STRING( code, name ) \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
          CFF_FIELD( code, name, cff_kind_string )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
#define CFF_FIELD_BOOL( code, name ) \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
          CFF_FIELD( code, name, cff_kind_bool )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
#define CFF_FIELD_DELTA( code, name, max ) \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
          CFF_FIELD( code, name, cff_kind_delta )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
#define CFFCODE_TOPDICT  0x1000
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
#define CFFCODE_PRIVATE  0x2000
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
#ifndef FT_CONFIG_OPTION_PIC
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
#define CFF_FIELD_CALLBACK( code, name ) \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
          {                              \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
            cff_kind_callback,           \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
            code | CFFCODE,              \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
            0, 0,                        \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
            cff_parse_ ## name,          \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
            0, 0                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
          },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
#undef  CFF_FIELD
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
#define CFF_FIELD( code, name, kind ) \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
          {                          \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
            kind,                    \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
            code | CFFCODE,          \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
            FT_FIELD_OFFSET( name ), \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
            FT_FIELD_SIZE( name ),   \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
            0, 0, 0                  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
          },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
#undef  CFF_FIELD_DELTA
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
#define CFF_FIELD_DELTA( code, name, max ) \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
        {                                  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
          cff_kind_delta,                  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
          code | CFFCODE,                  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
          FT_FIELD_OFFSET( name ),         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
          FT_FIELD_SIZE_DELTA( name ),     \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
          0,                               \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
          max,                             \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
          FT_FIELD_OFFSET( num_ ## name )  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
        },
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
  static const CFF_Field_Handler  cff_field_handlers[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
#include "cfftoken.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
    { 0, 0, 0, 0, 0, 0, 0 }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
#else /* FT_CONFIG_OPTION_PIC */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
  void FT_Destroy_Class_cff_field_handlers(FT_Library library, CFF_Field_Handler* clazz)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
    FT_Memory memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
    if ( clazz )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
      FT_FREE( clazz );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
  FT_Error FT_Create_Class_cff_field_handlers(FT_Library library, CFF_Field_Handler** output_class)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
    CFF_Field_Handler*  clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
    FT_Error          error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
    FT_Memory memory = library->memory;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
    int i=0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
#undef CFF_FIELD
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
#undef CFF_FIELD_DELTA
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
#undef CFF_FIELD_CALLBACK
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
#define CFF_FIELD_CALLBACK( code, name ) i++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
#define CFF_FIELD( code, name, kind ) i++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
#define CFF_FIELD_DELTA( code, name, max ) i++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
#include "cfftoken.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
    i++;/*{ 0, 0, 0, 0, 0, 0, 0 }*/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
    if ( FT_ALLOC( clazz, sizeof(CFF_Field_Handler)*i ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
      return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
    i=0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
#undef CFF_FIELD
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
#undef CFF_FIELD_DELTA
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
#undef CFF_FIELD_CALLBACK
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
#define CFF_FIELD_CALLBACK( code_, name_ )                                   \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
    clazz[i].kind = cff_kind_callback;                                       \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
    clazz[i].code = code_ | CFFCODE;                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
    clazz[i].offset = 0;                                                     \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
    clazz[i].size = 0;                                                       \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
    clazz[i].reader = cff_parse_ ## name_;                                   \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
    clazz[i].array_max = 0;                                                  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
    clazz[i].count_offset = 0;                                               \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
    i++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
#undef  CFF_FIELD
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
#define CFF_FIELD( code_, name_, kind_ )                                     \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
    clazz[i].kind = kind_;                                                   \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
    clazz[i].code = code_ | CFFCODE;                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
    clazz[i].offset = FT_FIELD_OFFSET( name_ );                              \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
    clazz[i].size = FT_FIELD_SIZE( name_ );                                  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
    clazz[i].reader = 0;                                                     \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
    clazz[i].array_max = 0;                                                  \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
    clazz[i].count_offset = 0;                                               \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
    i++;                                                                     \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
#undef  CFF_FIELD_DELTA
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
#define CFF_FIELD_DELTA( code_, name_, max_ )                                \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
    clazz[i].kind = cff_kind_delta;                                          \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
    clazz[i].code = code_ | CFFCODE;                                         \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
    clazz[i].offset = FT_FIELD_OFFSET( name_ );                              \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
    clazz[i].size = FT_FIELD_SIZE_DELTA( name_ );                            \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
    clazz[i].reader = 0;                                                     \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
    clazz[i].array_max = max_;                                               \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
    clazz[i].count_offset = FT_FIELD_OFFSET( num_ ## name_ );                \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
    i++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   698
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   699
#include "cfftoken.h"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
    clazz[i].kind = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
    clazz[i].code = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
    clazz[i].offset = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
    clazz[i].size = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
    clazz[i].reader = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
    clazz[i].array_max = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   707
    clazz[i].count_offset = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
    *output_class = clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
    return CFF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   712
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   713
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
#endif /* FT_CONFIG_OPTION_PIC */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   715
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   716
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
  FT_LOCAL_DEF( FT_Error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
  cff_parser_run( CFF_Parser  parser,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
                  FT_Byte*    start,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
                  FT_Byte*    limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   721
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   722
    FT_Byte*    p       = start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   723
    FT_Error    error   = CFF_Err_Ok;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
    FT_Library  library = parser->library;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
    FT_UNUSED(library);
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
    parser->top    = parser->stack;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
    parser->start  = start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
    parser->limit  = limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
    parser->cursor = start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   732
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   733
    while ( p < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
      FT_UInt  v = *p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   736
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   737
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   738
      if ( v >= 27 && v != 31 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   739
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   740
        /* it's a number; we will push its position on the stack */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
        if ( parser->top - parser->stack >= CFF_MAX_STACK_DEPTH )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
          goto Stack_Overflow;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
        *parser->top ++ = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
        /* now, skip it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
        if ( v == 30 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
          /* skip real number */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
          p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
          for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
            /* An unterminated floating point number at the */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
            /* end of a dictionary is invalid but harmless. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
            if ( p >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
              goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
            v = p[0] >> 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
            if ( v == 15 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
            v = p[0] & 0xF;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
            if ( v == 15 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
            p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   765
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   766
        else if ( v == 28 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
          p += 2;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
        else if ( v == 29 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
          p += 4;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
        else if ( v > 246 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
          p += 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   773
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   774
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
        /* This is not a number, hence it's an operator.  Compute its code */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
        /* and look for it in our current list.                            */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
        FT_UInt                   code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
        FT_UInt                   num_args = (FT_UInt)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
                                             ( parser->top - parser->stack );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
        const CFF_Field_Handler*  field;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   783
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   784
        *parser->top = p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
        code = v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
        if ( v == 12 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
          /* two byte operator */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
          p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
          if ( p >= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
            goto Syntax_Error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
          code = 0x100 | p[0];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   794
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   795
        code = code | parser->object_code;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
        for ( field = FT_CFF_FIELD_HANDLERS_GET; field->kind; field++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
          if ( field->code == (FT_Int)code )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
            /* we found our field's handler; read it */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
            FT_Long   val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
            FT_Byte*  q = (FT_Byte*)parser->object + field->offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   804
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   805
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
            /* check that we have enough arguments -- except for */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
            /* delta encoded arrays, which can be empty          */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
            if ( field->kind != cff_kind_delta && num_args < 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
              goto Stack_Underflow;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   810
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   811
            switch ( field->kind )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   812
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   813
            case cff_kind_bool:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
            case cff_kind_string:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
            case cff_kind_num:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
              val = cff_parse_num( parser->stack );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
              goto Store_Number;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   818
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   819
            case cff_kind_fixed:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
              val = cff_parse_fixed( parser->stack );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
              goto Store_Number;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   822
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   823
            case cff_kind_fixed_thousand:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
              val = cff_parse_fixed_scaled( parser->stack, 3 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   825
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   826
            Store_Number:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
              switch ( field->size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
              {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
              case (8 / FT_CHAR_BIT):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
                *(FT_Byte*)q = (FT_Byte)val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
                break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
              case (16 / FT_CHAR_BIT):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   834
                *(FT_Short*)q = (FT_Short)val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
                break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
              case (32 / FT_CHAR_BIT):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
                *(FT_Int32*)q = (FT_Int)val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
                break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   840
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   841
              default:  /* for 64-bit systems */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   842
                *(FT_Long*)q = val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   843
              }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   844
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   845
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   846
            case cff_kind_delta:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   847
              {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   848
                FT_Byte*   qcount = (FT_Byte*)parser->object +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
                                      field->count_offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   850
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   851
                FT_Byte**  data = parser->stack;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   852
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   853
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
                if ( num_args > field->array_max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
                  num_args = field->array_max;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   856
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
                /* store count */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
                *qcount = (FT_Byte)num_args;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
                val = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
                while ( num_args > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
                {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
                  val += cff_parse_num( data++ );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
                  switch ( field->size )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   865
                  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   866
                  case (8 / FT_CHAR_BIT):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
                    *(FT_Byte*)q = (FT_Byte)val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
                    break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   870
                  case (16 / FT_CHAR_BIT):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
                    *(FT_Short*)q = (FT_Short)val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
                    break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   873
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   874
                  case (32 / FT_CHAR_BIT):
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   875
                    *(FT_Int32*)q = (FT_Int)val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
                    break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   877
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   878
                  default:  /* for 64-bit systems */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
                    *(FT_Long*)q = val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
                  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   881
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   882
                  q += field->size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
                  num_args--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   884
                }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   885
              }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   886
              break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
            default:  /* callback */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
              error = field->reader( parser );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
              if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
                goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
            goto Found;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
        /* this is an unknown operator, or it is unsupported; */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
        /* we will ignore it for now.                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   899
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
      Found:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
        /* clear stack */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
        parser->top = parser->stack;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
      p++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
    return error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
  Stack_Overflow:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
    error = CFF_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
    goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   913
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   914
  Stack_Underflow:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
    error = CFF_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
    goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   917
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   918
  Syntax_Error:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
    error = CFF_Err_Invalid_Argument;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
    goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   921
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   922
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
/* END */