misc/libfreetype/src/gxvalid/gxvcommn.c
author nemo
Sat, 18 Aug 2012 09:29:40 -0400
changeset 7555 acadabfb2dd1
parent 5172 88f2e05288ba
permissions -rw-r--r--
byte order
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
/*  gxvcommn.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
/*    TrueTypeGX/AAT common tables validation (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 2004, 2005, 2009, 2010                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  by suzuki toshiya, Masatake YAMATO, Red Hat K.K.,                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
/*  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
    12
/*  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
    13
/*  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
    14
/*  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
    15
/*  understand and accept it fully.                                        */
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
/***************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
/* gxvalid is derived from both gxlayout module and otvalid module.        */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
/* Development of gxlayout is supported by the Information-technology      */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
/* Promotion Agency(IPA), Japan.                                           */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
/*                                                                         */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
/***************************************************************************/
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
#include "gxvcommn.h"
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
  /*                                                                       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
  /* 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
    34
  /* 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
    35
  /* messages during execution.                                            */
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
#undef  FT_COMPONENT
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
#define FT_COMPONENT  trace_gxvcommon
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
  /*****                       16bit offset sorter                     *****/
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
  /*************************************************************************/
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
  gxv_compare_ushort_offset( FT_UShort*  a,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
                             FT_UShort*  b )
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
    if ( *a < *b )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
      return -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
    else if ( *a > *b )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
      return 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
      return 0;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
  gxv_set_length_by_ushort_offset( FT_UShort*     offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
                                   FT_UShort**    length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
                                   FT_UShort*     buff,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
                                   FT_UInt        nmemb,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
                                   FT_UShort      limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
                                   GXV_Validator  valid )
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
    FT_UInt  i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
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
    for ( i = 0; i < nmemb; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
      *(length[i]) = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
    for ( i = 0; i < nmemb; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
      buff[i] = offset[i];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
    buff[nmemb] = limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
    ft_qsort( buff, ( nmemb + 1 ), sizeof ( FT_UShort ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
              ( int(*)(const void*, const void*) )gxv_compare_ushort_offset );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
    if ( buff[nmemb] > limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
      FT_INVALID_OFFSET;
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
    for ( i = 0; i < nmemb; i++ )
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
      FT_UInt  j;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
      for ( j = 0; j < nmemb; j++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
        if ( buff[j] == offset[i] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
      if ( j == nmemb )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
        FT_INVALID_OFFSET;
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
      *(length[i]) = (FT_UShort)( buff[j + 1] - buff[j] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
      if ( 0 != offset[i] && 0 == *(length[i]) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
        FT_INVALID_OFFSET;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
    }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
  /*************************************************************************/
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
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
  /*****                       32bit offset sorter                     *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
  /*****                                                               *****/
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 int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
  gxv_compare_ulong_offset( FT_ULong*  a,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
                            FT_ULong*  b )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
    if ( *a < *b )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
      return -1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
    else if ( *a > *b )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
      return 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
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
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
  gxv_set_length_by_ulong_offset( FT_ULong*      offset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
                                  FT_ULong**     length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
                                  FT_ULong*      buff,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
                                  FT_UInt        nmemb,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
                                  FT_ULong       limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
                                  GXV_Validator  valid)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
    FT_UInt  i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
    for ( i = 0; i < nmemb; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
      *(length[i]) = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
    for ( i = 0; i < nmemb; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
      buff[i] = offset[i];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
    buff[nmemb] = limit;
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
    ft_qsort( buff, ( nmemb + 1 ), sizeof ( FT_ULong ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
              ( int(*)(const void*, const void*) )gxv_compare_ulong_offset );
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
    if ( buff[nmemb] > limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
      FT_INVALID_OFFSET;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
    for ( i = 0; i < nmemb; i++ )
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
      FT_UInt  j;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
      for ( j = 0; j < nmemb; j++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
        if ( buff[j] == offset[i] )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
          break;
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
      if ( j == nmemb )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
        FT_INVALID_OFFSET;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
      *(length[i]) = buff[j + 1] - buff[j];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
      if ( 0 != offset[i] && 0 == *(length[i]) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
        FT_INVALID_OFFSET;
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
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
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
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
  /*****               scan value array and get min & max              *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
  /*****                                                               *****/
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
  gxv_array_getlimits_byte( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
                            FT_Bytes       limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
                            FT_Byte*       min,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
                            FT_Byte*       max,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
                            GXV_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
    FT_Bytes  p = table;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
    *min = 0xFF;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
    *max = 0x00;
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
    while ( p < limit )
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
      FT_Byte  val;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
      GXV_LIMIT_CHECK( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
      val = FT_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
      *min = (FT_Byte)FT_MIN( *min, val );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
      *max = (FT_Byte)FT_MAX( *max, val );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
    }
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
    valid->subtable_length = p - table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
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
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
  gxv_array_getlimits_ushort( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
                              FT_Bytes       limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
                              FT_UShort*     min,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
                              FT_UShort*     max,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
                              GXV_Validator  valid )
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
    FT_Bytes  p = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
    *min = 0xFFFFU;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
    *max = 0x0000;
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
    while ( p < limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
      FT_UShort  val;
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
      GXV_LIMIT_CHECK( 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
      val = FT_NEXT_USHORT( p );
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
      *min = (FT_Byte)FT_MIN( *min, val );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
      *max = (FT_Byte)FT_MAX( *max, val );
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
    valid->subtable_length = p - table;
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
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
  /*****                       BINSEARCHHEADER                         *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
  /*****                                                               *****/
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
  typedef struct  GXV_BinSrchHeader_
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
    FT_UShort  unitSize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
    FT_UShort  nUnits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
    FT_UShort  searchRange;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
    FT_UShort  entrySelector;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
    FT_UShort  rangeShift;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
  } GXV_BinSrchHeader;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
  gxv_BinSrchHeader_check_consistency( GXV_BinSrchHeader*  binSrchHeader,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
                                       GXV_Validator       valid )
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
    FT_UShort  searchRange;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
    FT_UShort  entrySelector;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
    FT_UShort  rangeShift;
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
    if ( binSrchHeader->unitSize == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
      FT_INVALID_DATA;
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 ( binSrchHeader->nUnits == 0 )
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
      if ( binSrchHeader->searchRange   == 0 &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
           binSrchHeader->entrySelector == 0 &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
           binSrchHeader->rangeShift    == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
        return;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
        FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
    }
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
    for ( searchRange = 1, entrySelector = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
          ( searchRange * 2 ) <= binSrchHeader->nUnits &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
            searchRange < 0x8000U;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
          searchRange *= 2, entrySelector++ )
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
    entrySelector--;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
    searchRange = (FT_UShort)( searchRange * binSrchHeader->unitSize );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
    rangeShift  = (FT_UShort)( binSrchHeader->nUnits * binSrchHeader->unitSize
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
                               - searchRange );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
    if ( searchRange   != binSrchHeader->searchRange   ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
         entrySelector != binSrchHeader->entrySelector ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
         rangeShift    != binSrchHeader->rangeShift    )
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
      GXV_TRACE(( "Inconsistency found in BinSrchHeader\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
      GXV_TRACE(( "originally: unitSize=%d, nUnits=%d, "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
                  "searchRange=%d, entrySelector=%d, "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
                  "rangeShift=%d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
                  binSrchHeader->unitSize, binSrchHeader->nUnits,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
                  binSrchHeader->searchRange, binSrchHeader->entrySelector,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
                  binSrchHeader->rangeShift ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
      GXV_TRACE(( "calculated: unitSize=%d, nUnits=%d, "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
                  "searchRange=%d, entrySelector=%d, "
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
                  "rangeShift=%d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
                  binSrchHeader->unitSize, binSrchHeader->nUnits,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
                  searchRange, entrySelector, rangeShift ));
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
      if ( valid->root->level >= FT_VALIDATE_PARANOID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
        FT_INVALID_DATA;
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
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
  /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
   * parser & validator of BinSrchHeader
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
   * which is used in LookupTable format 2, 4, 6.
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
   * Essential parameters (unitSize, nUnits) are returned by
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
   * given pointer, others (searchRange, entrySelector, rangeShift)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
   * can be calculated by essential parameters, so they are just
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
   * validated and discarded.
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
   * However, wrong values in searchRange, entrySelector, rangeShift
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
   * won't cause fatal errors, because these parameters might be
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
   * only used in old m68k font driver in MacOS.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
   *   -- suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
  gxv_BinSrchHeader_validate( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
                              FT_Bytes       limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
                              FT_UShort*     unitSize_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
                              FT_UShort*     nUnits_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
                              GXV_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
    FT_Bytes           p = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
    GXV_BinSrchHeader  binSrchHeader;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
    GXV_NAME_ENTER( "BinSrchHeader validate" );
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
    if ( *unitSize_p == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
      GXV_LIMIT_CHECK( 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
      binSrchHeader.unitSize =  FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
      binSrchHeader.unitSize = *unitSize_p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
    if ( *nUnits_p == 0 )
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
      GXV_LIMIT_CHECK( 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
      binSrchHeader.nUnits = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
      binSrchHeader.nUnits = *nUnits_p;
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
    GXV_LIMIT_CHECK( 2 + 2 + 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
    binSrchHeader.searchRange   = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
    binSrchHeader.entrySelector = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
    binSrchHeader.rangeShift    = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
    GXV_TRACE(( "nUnits %d\n", binSrchHeader.nUnits ));
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
    gxv_BinSrchHeader_check_consistency( &binSrchHeader, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
    if ( *unitSize_p == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
      *unitSize_p = binSrchHeader.unitSize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
    if ( *nUnits_p == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
      *nUnits_p = binSrchHeader.nUnits;
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
    valid->subtable_length = p - table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
    GXV_EXIT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
  /*************************************************************************/
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
  /*****                         LOOKUP TABLE                          *****/
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
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
#define GXV_LOOKUP_VALUE_LOAD( P, SIGNSPEC )                   \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
          ( P += 2, gxv_lookup_value_load( P - 2, SIGNSPEC ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
  static GXV_LookupValueDesc
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
  gxv_lookup_value_load( FT_Bytes  p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
                         int       signspec )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
    GXV_LookupValueDesc  v;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
    if ( signspec == GXV_LOOKUPVALUE_UNSIGNED )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
      v.u = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
      v.s = FT_NEXT_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
    return v;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
#define GXV_UNITSIZE_VALIDATE( FORMAT, UNITSIZE, NUNITS, CORRECTSIZE ) \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
          FT_BEGIN_STMNT                                               \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
            if ( UNITSIZE != CORRECTSIZE )                             \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
            {                                                          \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
              FT_ERROR(( "unitSize=%d differs from"                    \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
                         " expected unitSize=%d"                       \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
                         " in LookupTable %s\n",                       \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
                          UNITSIZE, CORRECTSIZE, FORMAT ));            \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
              if ( UNITSIZE != 0 && NUNITS != 0 )                      \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
              {                                                        \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
                FT_ERROR(( " cannot validate anymore\n" ));            \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
                FT_INVALID_FORMAT;                                     \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
              }                                                        \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
              else                                                     \
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
                FT_ERROR(( " forcibly continues\n" ));                 \
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
          FT_END_STMNT
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
  /* ================= Simple Array Format 0 Lookup Table ================ */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
  gxv_LookupTable_fmt0_validate( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
                                 FT_Bytes       limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
                                 GXV_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
    FT_Bytes   p = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
    FT_UShort  i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
    GXV_LookupValueDesc  value;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
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
    GXV_NAME_ENTER( "LookupTable format 0" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
    GXV_LIMIT_CHECK( 2 * valid->face->num_glyphs );
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
    for ( i = 0; i < valid->face->num_glyphs; i++ )
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
      GXV_LIMIT_CHECK( 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
      if ( p + 2 >= limit )     /* some fonts have too-short fmt0 array */
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
        GXV_TRACE(( "too short, glyphs %d - %d are missing\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
                    i, valid->face->num_glyphs ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
        if ( valid->root->level >= FT_VALIDATE_PARANOID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
          FT_INVALID_GLYPH_ID;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
      }
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
      value = GXV_LOOKUP_VALUE_LOAD( p, valid->lookupval_sign );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
      valid->lookupval_func( i, &value, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
    valid->subtable_length = p - table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
    GXV_EXIT;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
  /* ================= Segment Single Format 2 Loolup Table ============== */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
  /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
   * Apple spec says:
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
   *   To guarantee that a binary search terminates, you must include one or
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
   *   more special `end of search table' values at the end of the data to
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
   *   be searched.  The number of termination values that need to be
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
   *   included is table-specific.  The value that indicates binary search
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
   *   termination is 0xFFFF.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
   *
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
   * The problem is that nUnits does not include this end-marker.  It's
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
   * quite difficult to discriminate whether the following 0xFFFF comes from
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
   * the end-marker or some next data.
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
   *   -- suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
  gxv_LookupTable_fmt2_skip_endmarkers( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
                                        FT_UShort      unitSize,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
                                        GXV_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
    FT_Bytes  p = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
    while ( ( p + 4 ) < valid->root->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
      if ( p[0] != 0xFF || p[1] != 0xFF || /* lastGlyph */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
           p[2] != 0xFF || p[3] != 0xFF )  /* firstGlyph */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
      p += unitSize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
    valid->subtable_length = p - table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
  gxv_LookupTable_fmt2_validate( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
                                 FT_Bytes       limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
                                 GXV_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
    FT_Bytes             p = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
    FT_UShort            gid;
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
    FT_UShort            unitSize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
    FT_UShort            nUnits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
    FT_UShort            unit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
    FT_UShort            lastGlyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
    FT_UShort            firstGlyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
    GXV_LookupValueDesc  value;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
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
    GXV_NAME_ENTER( "LookupTable format 2" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
    unitSize = nUnits = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
    gxv_BinSrchHeader_validate( p, limit, &unitSize, &nUnits, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
    p += valid->subtable_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
    GXV_UNITSIZE_VALIDATE( "format2", unitSize, nUnits, 6 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
    for ( unit = 0, gid = 0; unit < nUnits; unit++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
      GXV_LIMIT_CHECK( 2 + 2 + 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
      lastGlyph  = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
      firstGlyph = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
      value      = GXV_LOOKUP_VALUE_LOAD( p, valid->lookupval_sign );
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
      gxv_glyphid_validate( firstGlyph, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
      gxv_glyphid_validate( lastGlyph, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
      if ( lastGlyph < gid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
        GXV_TRACE(( "reverse ordered segment specification:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
                    " lastGlyph[%d]=%d < lastGlyph[%d]=%d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
                    unit, lastGlyph, unit - 1 , gid ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
        if ( valid->root->level >= FT_VALIDATE_PARANOID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
          FT_INVALID_GLYPH_ID;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
      if ( lastGlyph < firstGlyph )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
        GXV_TRACE(( "reverse ordered range specification at unit %d:",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
                    " lastGlyph %d < firstGlyph %d ",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
                    unit, lastGlyph, firstGlyph ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
        if ( valid->root->level >= FT_VALIDATE_PARANOID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
          FT_INVALID_GLYPH_ID;
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
        if ( valid->root->level == FT_VALIDATE_TIGHT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
          continue;     /* ftxvalidator silently skips such an entry */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
        FT_TRACE4(( "continuing with exchanged values\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
        gid        = firstGlyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
        firstGlyph = lastGlyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
        lastGlyph  = gid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
      }
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
      for ( gid = firstGlyph; gid <= lastGlyph; gid++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
        valid->lookupval_func( gid, &value, valid );
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
    gxv_LookupTable_fmt2_skip_endmarkers( p, unitSize, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
    p += valid->subtable_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
    valid->subtable_length = p - table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
    GXV_EXIT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
  /* ================= Segment Array Format 4 Lookup Table =============== */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
  gxv_LookupTable_fmt4_validate( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
                                 FT_Bytes       limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
                                 GXV_Validator  valid )
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
    FT_Bytes             p = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
    FT_UShort            unit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
    FT_UShort            gid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
    FT_UShort            unitSize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
    FT_UShort            nUnits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
    FT_UShort            lastGlyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
    FT_UShort            firstGlyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
    GXV_LookupValueDesc  base_value;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
    GXV_LookupValueDesc  value;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
    GXV_NAME_ENTER( "LookupTable format 4" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
    unitSize = nUnits = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
    gxv_BinSrchHeader_validate( p, limit, &unitSize, &nUnits, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
    p += valid->subtable_length;
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
    GXV_UNITSIZE_VALIDATE( "format4", unitSize, nUnits, 6 );
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
    for ( unit = 0, gid = 0; unit < nUnits; unit++ )
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
      GXV_LIMIT_CHECK( 2 + 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
      lastGlyph  = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
      firstGlyph = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
      gxv_glyphid_validate( firstGlyph, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
      gxv_glyphid_validate( lastGlyph, valid );
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
      if ( lastGlyph < gid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
        GXV_TRACE(( "reverse ordered segment specification:"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
                    " lastGlyph[%d]=%d < lastGlyph[%d]=%d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
                    unit, lastGlyph, unit - 1 , gid ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
        if ( valid->root->level >= FT_VALIDATE_PARANOID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
          FT_INVALID_GLYPH_ID;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
      }
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
      if ( lastGlyph < firstGlyph )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
        GXV_TRACE(( "reverse ordered range specification at unit %d:",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
                    " lastGlyph %d < firstGlyph %d ",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
                    unit, lastGlyph, firstGlyph ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
        if ( valid->root->level >= FT_VALIDATE_PARANOID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
          FT_INVALID_GLYPH_ID;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
        if ( valid->root->level == FT_VALIDATE_TIGHT )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
          continue; /* ftxvalidator silently skips such an entry */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
        FT_TRACE4(( "continuing with exchanged values\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
        gid        = firstGlyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
        firstGlyph = lastGlyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
        lastGlyph  = gid;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
      GXV_LIMIT_CHECK( 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
      base_value = GXV_LOOKUP_VALUE_LOAD( p, GXV_LOOKUPVALUE_UNSIGNED );
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
      for ( gid = firstGlyph; gid <= lastGlyph; gid++ )
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
        value = valid->lookupfmt4_trans( (FT_UShort)( gid - firstGlyph ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
                                         &base_value,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
                                         limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
                                         valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
        valid->lookupval_func( gid, &value, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
      }
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
    gxv_LookupTable_fmt2_skip_endmarkers( p, unitSize, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
    p += valid->subtable_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
    valid->subtable_length = p - table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
    GXV_EXIT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
  }
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
  /* ================= Segment Table Format 6 Lookup Table =============== */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
  gxv_LookupTable_fmt6_skip_endmarkers( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
                                        FT_UShort      unitSize,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
                                        GXV_Validator  valid )
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
    FT_Bytes  p = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
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
    while ( p < valid->root->limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   660
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   661
      if ( p[0] != 0xFF || p[1] != 0xFF )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   662
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   663
      p += unitSize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   664
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   665
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   666
    valid->subtable_length = p - table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   667
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   668
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   669
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   670
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   671
  gxv_LookupTable_fmt6_validate( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   672
                                 FT_Bytes       limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   673
                                 GXV_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   674
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   675
    FT_Bytes             p = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   676
    FT_UShort            unit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   677
    FT_UShort            prev_glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   678
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   679
    FT_UShort            unitSize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   680
    FT_UShort            nUnits;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   681
    FT_UShort            glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   682
    GXV_LookupValueDesc  value;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   683
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   684
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   685
    GXV_NAME_ENTER( "LookupTable format 6" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   686
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   687
    unitSize = nUnits = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   688
    gxv_BinSrchHeader_validate( p, limit, &unitSize, &nUnits, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   689
    p += valid->subtable_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   690
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   691
    GXV_UNITSIZE_VALIDATE( "format6", unitSize, nUnits, 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   692
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   693
    for ( unit = 0, prev_glyph = 0; unit < nUnits; unit++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   694
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   695
      GXV_LIMIT_CHECK( 2 + 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   696
      glyph = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   697
      value = GXV_LOOKUP_VALUE_LOAD( p, valid->lookupval_sign );
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
      if ( gxv_glyphid_validate( glyph, valid ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   700
        GXV_TRACE(( " endmarker found within defined range"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   701
                    " (entry %d < nUnits=%d)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   702
                    unit, nUnits ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   703
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   704
      if ( prev_glyph > glyph )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   705
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   706
        GXV_TRACE(( "current gid 0x%04x < previous gid 0x%04x\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   707
                    glyph, prev_glyph ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   708
        if ( valid->root->level >= FT_VALIDATE_PARANOID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   709
          FT_INVALID_GLYPH_ID;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   710
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   711
      prev_glyph = glyph;
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
      valid->lookupval_func( glyph, &value, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   714
    }
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
    gxv_LookupTable_fmt6_skip_endmarkers( p, unitSize, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   717
    p += valid->subtable_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   718
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   719
    valid->subtable_length = p - table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   720
    GXV_EXIT;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   723
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   724
  /* ================= Trimmed Array Format 8 Lookup Table =============== */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   725
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   726
  gxv_LookupTable_fmt8_validate( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   727
                                 FT_Bytes       limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   728
                                 GXV_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   729
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   730
    FT_Bytes              p = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   731
    FT_UShort             i;
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
    GXV_LookupValueDesc   value;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   734
    FT_UShort             firstGlyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   735
    FT_UShort             glyphCount;
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
    GXV_NAME_ENTER( "LookupTable format 8" );
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
    /* firstGlyph + glyphCount */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   741
    GXV_LIMIT_CHECK( 2 + 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   742
    firstGlyph = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   743
    glyphCount = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   744
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   745
    gxv_glyphid_validate( firstGlyph, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   746
    gxv_glyphid_validate( (FT_UShort)( firstGlyph + glyphCount ), valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   747
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   748
    /* valueArray */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   749
    for ( i = 0; i < glyphCount; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   750
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   751
      GXV_LIMIT_CHECK( 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   752
      value = GXV_LOOKUP_VALUE_LOAD( p, valid->lookupval_sign );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   753
      valid->lookupval_func( (FT_UShort)( firstGlyph + i ), &value, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   754
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   755
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   756
    valid->subtable_length = p - table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   757
    GXV_EXIT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   758
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   759
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   760
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   761
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   762
  gxv_LookupTable_validate( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   763
                            FT_Bytes       limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   764
                            GXV_Validator  valid )
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
    FT_Bytes   p = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   767
    FT_UShort  format;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   768
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   769
    GXV_Validate_Func  fmt_funcs_table[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   770
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   771
      gxv_LookupTable_fmt0_validate, /* 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   772
      NULL,                          /* 1 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   773
      gxv_LookupTable_fmt2_validate, /* 2 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   774
      NULL,                          /* 3 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   775
      gxv_LookupTable_fmt4_validate, /* 4 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   776
      NULL,                          /* 5 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   777
      gxv_LookupTable_fmt6_validate, /* 6 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   778
      NULL,                          /* 7 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   779
      gxv_LookupTable_fmt8_validate, /* 8 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   780
    };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   781
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   782
    GXV_Validate_Func  func;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   785
    GXV_NAME_ENTER( "LookupTable" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   786
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   787
    /* lookuptbl_head may be used in fmt4 transit function. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   788
    valid->lookuptbl_head = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   789
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   790
    /* format */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   791
    GXV_LIMIT_CHECK( 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   792
    format = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   793
    GXV_TRACE(( " (format %d)\n", format ));
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
    if ( format > 8 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   796
      FT_INVALID_FORMAT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   797
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   798
    func = fmt_funcs_table[format];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   799
    if ( func == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   800
      FT_INVALID_FORMAT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   801
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   802
    func( p, limit, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   803
    p += valid->subtable_length;
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
    valid->subtable_length = p - table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   806
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   807
    GXV_EXIT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   808
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   809
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
  /*************************************************************************/
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
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   814
  /*****                          Glyph ID                             *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   815
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   816
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   817
  /*************************************************************************/
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
  FT_LOCAL_DEF( FT_Int )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   820
  gxv_glyphid_validate( FT_UShort      gid,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   821
                        GXV_Validator  valid )
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
    FT_Face  face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   824
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
    if ( gid == 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   827
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   828
      GXV_EXIT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   829
      return 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   830
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   831
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   832
    face = valid->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   833
    if ( face->num_glyphs < gid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   834
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   835
      GXV_TRACE(( " gxv_glyphid_check() gid overflow: num_glyphs %d < %d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   836
                  face->num_glyphs, gid ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   837
      if ( valid->root->level >= FT_VALIDATE_PARANOID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   838
        FT_INVALID_GLYPH_ID;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   839
    }
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
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   842
  }
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
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
  /*************************************************************************/
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
  /*****                        CONTROL POINT                          *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   849
  /*****                                                               *****/
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
  /*************************************************************************/
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
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   854
  gxv_ctlPoint_validate( FT_UShort      gid,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   855
                         FT_Short       ctl_point,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   856
                         GXV_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   857
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   858
    FT_Face       face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   859
    FT_Error      error;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   860
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   861
    FT_GlyphSlot  glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   862
    FT_Outline    outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   863
    short         n_points;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   864
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
    face = valid->face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   867
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   868
    error = FT_Load_Glyph( face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   869
                           gid,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   870
                           FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   871
    if ( error )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   872
      FT_INVALID_GLYPH_ID;
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
    glyph    = face->glyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   875
    outline  = glyph->outline;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   876
    n_points = outline.n_points;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   879
    if ( !( ctl_point < n_points ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   880
      FT_INVALID_DATA;
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
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   883
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
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   887
  /*****                          SFNT NAME                            *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   888
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   889
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   890
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   891
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   892
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   893
  gxv_sfntName_validate( FT_UShort      name_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   894
                         FT_UShort      min_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   895
                         FT_UShort      max_index,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   896
                         GXV_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   897
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   898
    FT_SfntName  name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   899
    FT_UInt      i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   900
    FT_UInt      nnames;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   901
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   902
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   903
    GXV_NAME_ENTER( "sfntName" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   904
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   905
    if ( name_index < min_index || max_index < name_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   906
      FT_INVALID_FORMAT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   907
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   908
    nnames = FT_Get_Sfnt_Name_Count( valid->face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   909
    for ( i = 0; i < nnames; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   910
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   911
      if ( FT_Get_Sfnt_Name( valid->face, i, &name ) != GXV_Err_Ok )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   912
        continue ;
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
      if ( name.name_id == name_index )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   915
        goto Out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   916
    }
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
    GXV_TRACE(( "  nameIndex = %d (UNTITLED)\n", name_index ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   919
    FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   920
    goto Exit;  /* make compiler happy */
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
  Out:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   923
    FT_TRACE1(( "  nameIndex = %d (", name_index ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   924
    GXV_TRACE_HEXDUMP_SFNTNAME( name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   925
    FT_TRACE1(( ")\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   926
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   927
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   928
    GXV_EXIT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   929
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   930
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   931
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   932
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   933
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   934
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   935
  /*****                          STATE TABLE                          *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   936
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   937
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   938
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   939
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   940
  /* -------------------------- Class Table --------------------------- */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   941
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   942
  /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   943
   * highestClass specifies how many classes are defined in this
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   944
   * Class Subtable.  Apple spec does not mention whether undefined
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   945
   * holes in the class (e.g.: 0-3 are predefined, 4 is unused, 5 is used)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   946
   * are permitted.  At present, holes in a defined class are not checked.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   947
   *   -- suzuki toshiya <mpsuzuki@hiroshima-u.ac.jp>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   948
   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   949
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   950
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   951
  gxv_ClassTable_validate( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   952
                           FT_UShort*     length_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   953
                           FT_UShort      stateSize,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   954
                           FT_Byte*       maxClassID_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   955
                           GXV_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   956
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   957
    FT_Bytes   p     = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   958
    FT_Bytes   limit = table + *length_p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   959
    FT_UShort  firstGlyph;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   960
    FT_UShort  nGlyphs;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   961
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   962
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   963
    GXV_NAME_ENTER( "ClassTable" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   964
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   965
    *maxClassID_p = 3;  /* Classes 0, 2, and 3 are predefined */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   966
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   967
    GXV_LIMIT_CHECK( 2 + 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   968
    firstGlyph = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   969
    nGlyphs    = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   970
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   971
    GXV_TRACE(( " (firstGlyph = %d, nGlyphs = %d)\n", firstGlyph, nGlyphs ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   972
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   973
    if ( !nGlyphs )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   974
      goto Out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   975
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   976
    gxv_glyphid_validate( (FT_UShort)( firstGlyph + nGlyphs ), valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   977
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   978
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   979
      FT_Byte    nGlyphInClass[256];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   980
      FT_Byte    classID;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   981
      FT_UShort  i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   982
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   983
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   984
      ft_memset( nGlyphInClass, 0, 256 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   985
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   986
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   987
      for ( i = 0; i < nGlyphs; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   988
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   989
        GXV_LIMIT_CHECK( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   990
        classID = FT_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   991
        switch ( classID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   992
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   993
          /* following classes should not appear in class array */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   994
        case 0:             /* end of text */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   995
        case 2:             /* out of bounds */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   996
        case 3:             /* end of line */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   997
          FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   998
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   999
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1000
        case 1:             /* out of bounds */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1001
        default:            /* user-defined: 4 - ( stateSize - 1 ) */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1002
          if ( classID >= stateSize )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1003
            FT_INVALID_DATA;   /* assign glyph to undefined state */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1004
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1005
          nGlyphInClass[classID]++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1006
          break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1007
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1008
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1009
      *length_p = (FT_UShort)( p - table );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1010
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1011
      /* scan max ClassID in use */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1012
      for ( i = 0; i < stateSize; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1013
        if ( ( 3 < i ) && ( nGlyphInClass[i] > 0 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1014
          *maxClassID_p = (FT_Byte)i;  /* XXX: Check Range? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1015
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1016
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1017
  Out:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1018
    GXV_TRACE(( "Declared stateSize=0x%02x, Used maxClassID=0x%02x\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1019
                stateSize, *maxClassID_p ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1020
    GXV_EXIT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1021
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1022
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1023
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1024
  /* --------------------------- State Array ----------------------------- */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1025
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1026
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1027
  gxv_StateArray_validate( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1028
                           FT_UShort*     length_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1029
                           FT_Byte        maxClassID,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1030
                           FT_UShort      stateSize,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1031
                           FT_Byte*       maxState_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1032
                           FT_Byte*       maxEntry_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1033
                           GXV_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1034
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1035
    FT_Bytes  p = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1036
    FT_Bytes  limit = table + *length_p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1037
    FT_Byte   clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1038
    FT_Byte   entry;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1039
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1040
    FT_UNUSED( stateSize ); /* for the non-debugging case */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1041
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1042
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1043
    GXV_NAME_ENTER( "StateArray" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1044
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1045
    GXV_TRACE(( "parse %d bytes by stateSize=%d maxClassID=%d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1046
                (int)(*length_p), stateSize, (int)(maxClassID) ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1047
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1048
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1049
     * 2 states are predefined and must be described in StateArray:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1050
     * state 0 (start of text), 1 (start of line)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1051
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1052
    GXV_LIMIT_CHECK( ( 1 + maxClassID ) * 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1053
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1054
    *maxState_p = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1055
    *maxEntry_p = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1056
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1057
    /* read if enough to read another state */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1058
    while ( p + ( 1 + maxClassID ) <= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1059
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1060
      (*maxState_p)++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1061
      for ( clazz = 0; clazz <= maxClassID; clazz++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1062
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1063
        entry = FT_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1064
        *maxEntry_p = (FT_Byte)FT_MAX( *maxEntry_p, entry );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1065
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1066
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1067
    GXV_TRACE(( "parsed: maxState=%d, maxEntry=%d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1068
                *maxState_p, *maxEntry_p ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1069
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1070
    *length_p = (FT_UShort)( p - table );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1071
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1072
    GXV_EXIT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1073
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1074
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1075
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1076
  /* --------------------------- Entry Table ----------------------------- */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1077
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1078
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1079
  gxv_EntryTable_validate( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1080
                           FT_UShort*     length_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1081
                           FT_Byte        maxEntry,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1082
                           FT_UShort      stateArray,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1083
                           FT_UShort      stateArray_length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1084
                           FT_Byte        maxClassID,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1085
                           FT_Bytes       statetable_table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1086
                           FT_Bytes       statetable_limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1087
                           GXV_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1088
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1089
    FT_Bytes  p     = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1090
    FT_Bytes  limit = table + *length_p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1091
    FT_Byte   entry;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1092
    FT_Byte   state;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1093
    FT_Int    entrySize = 2 + 2 + GXV_GLYPHOFFSET_SIZE( statetable );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1094
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1095
    GXV_XStateTable_GlyphOffsetDesc  glyphOffset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1096
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1097
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1098
    GXV_NAME_ENTER( "EntryTable" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1099
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1100
    GXV_TRACE(( "maxEntry=%d entrySize=%d\n", maxEntry, entrySize ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1101
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1102
    if ( ( maxEntry + 1 ) * entrySize > *length_p )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1103
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1104
      if ( valid->root->level >= FT_VALIDATE_PARANOID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1105
        FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1106
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1107
      /* ftxvalidator and FontValidator both warn and continue */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1108
      maxEntry = (FT_Byte)( *length_p / entrySize - 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1109
      GXV_TRACE(( "too large maxEntry, shrinking to %d fit EntryTable length\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1110
                  maxEntry ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1111
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1112
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1113
    for ( entry = 0; entry <= maxEntry; entry++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1114
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1115
      FT_UShort  newState;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1116
      FT_UShort  flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1117
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1118
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1119
      GXV_LIMIT_CHECK( 2 + 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1120
      newState = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1121
      flags    = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1122
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1123
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1124
      if ( newState < stateArray                     ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1125
           stateArray + stateArray_length < newState )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1126
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1127
        GXV_TRACE(( " newState offset 0x%04x is out of stateArray\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1128
                    newState ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1129
        if ( valid->root->level >= FT_VALIDATE_PARANOID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1130
          FT_INVALID_OFFSET;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1131
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1132
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1133
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1134
      if ( 0 != ( ( newState - stateArray ) % ( 1 + maxClassID ) ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1135
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1136
        GXV_TRACE(( " newState offset 0x%04x is not aligned to %d-classes\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1137
                    newState,  1 + maxClassID ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1138
        if ( valid->root->level >= FT_VALIDATE_PARANOID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1139
          FT_INVALID_OFFSET;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1140
        continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1141
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1142
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1143
      state = (FT_Byte)( ( newState - stateArray ) / ( 1 + maxClassID ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1144
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1145
      switch ( GXV_GLYPHOFFSET_FMT( statetable ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1146
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1147
      case GXV_GLYPHOFFSET_NONE:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1148
        glyphOffset.uc = 0;  /* make compiler happy */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1149
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1150
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1151
      case GXV_GLYPHOFFSET_UCHAR:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1152
        glyphOffset.uc = FT_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1153
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1154
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1155
      case GXV_GLYPHOFFSET_CHAR:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1156
        glyphOffset.c = FT_NEXT_CHAR( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1157
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1158
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1159
      case GXV_GLYPHOFFSET_USHORT:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1160
        glyphOffset.u = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1161
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1162
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1163
      case GXV_GLYPHOFFSET_SHORT:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1164
        glyphOffset.s = FT_NEXT_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1165
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1166
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1167
      case GXV_GLYPHOFFSET_ULONG:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1168
        glyphOffset.ul = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1169
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1170
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1171
      case GXV_GLYPHOFFSET_LONG:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1172
        glyphOffset.l = FT_NEXT_LONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1173
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1174
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1175
      default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1176
        if ( valid->root->level >= FT_VALIDATE_PARANOID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1177
          FT_INVALID_FORMAT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1178
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1179
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1180
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1181
      if ( NULL != valid->statetable.entry_validate_func )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1182
        valid->statetable.entry_validate_func( state,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1183
                                               flags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1184
                                               &glyphOffset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1185
                                               statetable_table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1186
                                               statetable_limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1187
                                               valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1188
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1189
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1190
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1191
    *length_p = (FT_UShort)( p - table );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1192
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1193
    GXV_EXIT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1194
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1195
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1196
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1197
  /* =========================== State Table ============================= */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1198
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1199
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1200
  gxv_StateTable_subtable_setup( FT_UShort      table_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1201
                                 FT_UShort      classTable,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1202
                                 FT_UShort      stateArray,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1203
                                 FT_UShort      entryTable,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1204
                                 FT_UShort*     classTable_length_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1205
                                 FT_UShort*     stateArray_length_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1206
                                 FT_UShort*     entryTable_length_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1207
                                 GXV_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1208
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1209
    FT_UShort   o[3];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1210
    FT_UShort*  l[3];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1211
    FT_UShort   buff[4];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1212
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1213
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1214
    o[0] = classTable;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1215
    o[1] = stateArray;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1216
    o[2] = entryTable;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1217
    l[0] = classTable_length_p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1218
    l[1] = stateArray_length_p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1219
    l[2] = entryTable_length_p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1220
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1221
    gxv_set_length_by_ushort_offset( o, l, buff, 3, table_size, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1222
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1223
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1224
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1225
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1226
  gxv_StateTable_validate( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1227
                           FT_Bytes       limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1228
                           GXV_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1229
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1230
    FT_UShort   stateSize;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1231
    FT_UShort   classTable;     /* offset to Class(Sub)Table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1232
    FT_UShort   stateArray;     /* offset to StateArray */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1233
    FT_UShort   entryTable;     /* offset to EntryTable */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1234
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1235
    FT_UShort   classTable_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1236
    FT_UShort   stateArray_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1237
    FT_UShort   entryTable_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1238
    FT_Byte     maxClassID;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1239
    FT_Byte     maxState;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1240
    FT_Byte     maxEntry;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1241
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1242
    GXV_StateTable_Subtable_Setup_Func  setup_func;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1243
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1244
    FT_Bytes    p = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1245
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1246
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1247
    GXV_NAME_ENTER( "StateTable" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1248
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1249
    GXV_TRACE(( "StateTable header\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1250
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1251
    GXV_LIMIT_CHECK( 2 + 2 + 2 + 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1252
    stateSize  = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1253
    classTable = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1254
    stateArray = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1255
    entryTable = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1256
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1257
    GXV_TRACE(( "stateSize=0x%04x\n", stateSize ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1258
    GXV_TRACE(( "offset to classTable=0x%04x\n", classTable ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1259
    GXV_TRACE(( "offset to stateArray=0x%04x\n", stateArray ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1260
    GXV_TRACE(( "offset to entryTable=0x%04x\n", entryTable ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1261
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1262
    if ( stateSize > 0xFF )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1263
      FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1264
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1265
    if ( valid->statetable.optdata_load_func != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1266
      valid->statetable.optdata_load_func( p, limit, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1267
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1268
    if ( valid->statetable.subtable_setup_func != NULL)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1269
      setup_func = valid->statetable.subtable_setup_func;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1270
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1271
      setup_func = gxv_StateTable_subtable_setup;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1272
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1273
    setup_func( (FT_UShort)( limit - table ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1274
                classTable,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1275
                stateArray,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1276
                entryTable,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1277
                &classTable_length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1278
                &stateArray_length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1279
                &entryTable_length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1280
                valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1281
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1282
    GXV_TRACE(( "StateTable Subtables\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1283
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1284
    if ( classTable != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1285
      gxv_ClassTable_validate( table + classTable,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1286
                               &classTable_length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1287
                               stateSize,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1288
                               &maxClassID,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1289
                               valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1290
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1291
      maxClassID = (FT_Byte)( stateSize - 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1292
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1293
    if ( stateArray != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1294
      gxv_StateArray_validate( table + stateArray,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1295
                               &stateArray_length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1296
                               maxClassID,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1297
                               stateSize,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1298
                               &maxState,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1299
                               &maxEntry,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1300
                               valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1301
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1302
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1303
      maxState = 1;     /* 0:start of text, 1:start of line are predefined */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1304
      maxEntry = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1305
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1306
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1307
    if ( maxEntry > 0 && entryTable == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1308
      FT_INVALID_OFFSET;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1309
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1310
    if ( entryTable != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1311
      gxv_EntryTable_validate( table + entryTable,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1312
                               &entryTable_length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1313
                               maxEntry,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1314
                               stateArray,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1315
                               stateArray_length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1316
                               maxClassID,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1317
                               table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1318
                               limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1319
                               valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1320
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1321
    GXV_EXIT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1322
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1323
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1324
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1325
  /* ================= eXtended State Table (for morx) =================== */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1326
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1327
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1328
  gxv_XStateTable_subtable_setup( FT_ULong       table_size,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1329
                                  FT_ULong       classTable,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1330
                                  FT_ULong       stateArray,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1331
                                  FT_ULong       entryTable,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1332
                                  FT_ULong*      classTable_length_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1333
                                  FT_ULong*      stateArray_length_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1334
                                  FT_ULong*      entryTable_length_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1335
                                  GXV_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1336
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1337
    FT_ULong   o[3];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1338
    FT_ULong*  l[3];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1339
    FT_ULong   buff[4];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1340
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1341
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1342
    o[0] = classTable;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1343
    o[1] = stateArray;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1344
    o[2] = entryTable;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1345
    l[0] = classTable_length_p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1346
    l[1] = stateArray_length_p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1347
    l[2] = entryTable_length_p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1348
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1349
    gxv_set_length_by_ulong_offset( o, l, buff, 4, table_size, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1350
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1351
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1352
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1353
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1354
  gxv_XClassTable_lookupval_validate( FT_UShort            glyph,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1355
                                      GXV_LookupValueCPtr  value_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1356
                                      GXV_Validator        valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1357
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1358
    FT_UNUSED( glyph );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1359
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1360
    if ( value_p->u >= valid->xstatetable.nClasses )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1361
      FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1362
    if ( value_p->u > valid->xstatetable.maxClassID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1363
      valid->xstatetable.maxClassID = value_p->u;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1364
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1365
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1366
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1367
  /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1368
    +===============+ --------+
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1369
    | lookup header |         |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1370
    +===============+         |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1371
    | BinSrchHeader |         |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1372
    +===============+         |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1373
    | lastGlyph[0]  |         |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1374
    +---------------+         |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1375
    | firstGlyph[0] |         |    head of lookup table
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1376
    +---------------+         |             +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1377
    | offset[0]     |    ->   |          offset            [byte]
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1378
    +===============+         |             +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1379
    | lastGlyph[1]  |         | (glyphID - firstGlyph) * 2 [byte]
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1380
    +---------------+         |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1381
    | firstGlyph[1] |         |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1382
    +---------------+         |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1383
    | offset[1]     |         |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1384
    +===============+         |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1385
                              |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1386
     ....                     |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1387
                              |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1388
    16bit value array         |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1389
    +===============+         |
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1390
    |     value     | <-------+
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1391
     ....
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1392
  */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1393
  static GXV_LookupValueDesc
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1394
  gxv_XClassTable_lookupfmt4_transit( FT_UShort            relative_gindex,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1395
                                      GXV_LookupValueCPtr  base_value_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1396
                                      FT_Bytes             lookuptbl_limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1397
                                      GXV_Validator        valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1398
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1399
    FT_Bytes             p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1400
    FT_Bytes             limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1401
    FT_UShort            offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1402
    GXV_LookupValueDesc  value;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1403
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1404
    /* XXX: check range? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1405
    offset = (FT_UShort)( base_value_p->u +
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1406
                          relative_gindex * sizeof ( FT_UShort ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1407
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1408
    p     = valid->lookuptbl_head + offset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1409
    limit = lookuptbl_limit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1410
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1411
    GXV_LIMIT_CHECK ( 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1412
    value.u = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1413
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1414
    return value;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1415
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1416
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1417
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1418
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1419
  gxv_XStateArray_validate( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1420
                            FT_ULong*      length_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1421
                            FT_UShort      maxClassID,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1422
                            FT_ULong       stateSize,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1423
                            FT_UShort*     maxState_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1424
                            FT_UShort*     maxEntry_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1425
                            GXV_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1426
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1427
    FT_Bytes   p = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1428
    FT_Bytes   limit = table + *length_p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1429
    FT_UShort  clazz;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1430
    FT_UShort  entry;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1431
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1432
    FT_UNUSED( stateSize ); /* for the non-debugging case */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1433
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1434
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1435
    GXV_NAME_ENTER( "XStateArray" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1436
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1437
    GXV_TRACE(( "parse % 3d bytes by stateSize=% 3d maxClassID=% 3d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1438
                (int)(*length_p), stateSize, (int)(maxClassID) ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1439
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1440
    /*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1441
     * 2 states are predefined and must be described:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1442
     * state 0 (start of text), 1 (start of line)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1443
     */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1444
    GXV_LIMIT_CHECK( ( 1 + maxClassID ) * 2 * 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1445
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1446
    *maxState_p = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1447
    *maxEntry_p = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1448
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1449
    /* read if enough to read another state */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1450
    while ( p + ( ( 1 + maxClassID ) * 2 ) <= limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1451
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1452
      (*maxState_p)++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1453
      for ( clazz = 0; clazz <= maxClassID; clazz++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1454
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1455
        entry = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1456
        *maxEntry_p = (FT_UShort)FT_MAX( *maxEntry_p, entry );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1457
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1458
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1459
    GXV_TRACE(( "parsed: maxState=%d, maxEntry=%d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1460
                *maxState_p, *maxEntry_p ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1461
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1462
    *length_p = p - table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1463
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1464
    GXV_EXIT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1465
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1466
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1467
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1468
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1469
  gxv_XEntryTable_validate( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1470
                            FT_ULong*      length_p,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1471
                            FT_UShort      maxEntry,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1472
                            FT_ULong       stateArray_length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1473
                            FT_UShort      maxClassID,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1474
                            FT_Bytes       xstatetable_table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1475
                            FT_Bytes       xstatetable_limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1476
                            GXV_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1477
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1478
    FT_Bytes   p = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1479
    FT_Bytes   limit = table + *length_p;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1480
    FT_UShort  entry;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1481
    FT_UShort  state;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1482
    FT_Int     entrySize = 2 + 2 + GXV_GLYPHOFFSET_SIZE( xstatetable );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1483
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1484
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1485
    GXV_NAME_ENTER( "XEntryTable" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1486
    GXV_TRACE(( "maxEntry=%d entrySize=%d\n", maxEntry, entrySize ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1487
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1488
    if ( ( p + ( maxEntry + 1 ) * entrySize ) > limit )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1489
      FT_INVALID_TOO_SHORT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1490
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1491
    for (entry = 0; entry <= maxEntry ; entry++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1492
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1493
      FT_UShort                        newState_idx;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1494
      FT_UShort                        flags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1495
      GXV_XStateTable_GlyphOffsetDesc  glyphOffset;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1496
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1497
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1498
      GXV_LIMIT_CHECK( 2 + 2 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1499
      newState_idx = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1500
      flags        = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1501
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1502
      if ( stateArray_length < (FT_ULong)( newState_idx * 2 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1503
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1504
        GXV_TRACE(( "  newState index 0x%04x points out of stateArray\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1505
                    newState_idx ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1506
        if ( valid->root->level >= FT_VALIDATE_PARANOID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1507
          FT_INVALID_OFFSET;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1508
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1509
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1510
      state = (FT_UShort)( newState_idx / ( 1 + maxClassID ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1511
      if ( 0 != ( newState_idx % ( 1 + maxClassID ) ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1512
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1513
        FT_TRACE4(( "-> new state = %d (supposed)\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1514
                    "but newState index 0x%04x is not aligned to %d-classes\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1515
                    state, newState_idx,  1 + maxClassID ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1516
        if ( valid->root->level >= FT_VALIDATE_PARANOID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1517
          FT_INVALID_OFFSET;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1518
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1519
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1520
      switch ( GXV_GLYPHOFFSET_FMT( xstatetable ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1521
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1522
      case GXV_GLYPHOFFSET_NONE:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1523
        glyphOffset.uc = 0; /* make compiler happy */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1524
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1525
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1526
      case GXV_GLYPHOFFSET_UCHAR:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1527
        glyphOffset.uc = FT_NEXT_BYTE( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1528
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1529
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1530
      case GXV_GLYPHOFFSET_CHAR:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1531
        glyphOffset.c = FT_NEXT_CHAR( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1532
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1533
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1534
      case GXV_GLYPHOFFSET_USHORT:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1535
        glyphOffset.u = FT_NEXT_USHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1536
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1537
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1538
      case GXV_GLYPHOFFSET_SHORT:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1539
        glyphOffset.s = FT_NEXT_SHORT( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1540
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1541
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1542
      case GXV_GLYPHOFFSET_ULONG:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1543
        glyphOffset.ul = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1544
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1545
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1546
      case GXV_GLYPHOFFSET_LONG:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1547
        glyphOffset.l = FT_NEXT_LONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1548
        break;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1549
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1550
      default:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1551
        if ( valid->root->level >= FT_VALIDATE_PARANOID )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1552
          FT_INVALID_FORMAT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1553
        goto Exit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1554
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1555
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1556
      if ( NULL != valid->xstatetable.entry_validate_func )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1557
        valid->xstatetable.entry_validate_func( state,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1558
                                                flags,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1559
                                                &glyphOffset,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1560
                                                xstatetable_table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1561
                                                xstatetable_limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1562
                                                valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1563
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1564
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1565
  Exit:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1566
    *length_p = p - table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1567
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1568
    GXV_EXIT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1569
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1570
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1571
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1572
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1573
  gxv_XStateTable_validate( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1574
                            FT_Bytes       limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1575
                            GXV_Validator  valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1576
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1577
    /* StateHeader members */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1578
    FT_ULong   classTable;      /* offset to Class(Sub)Table */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1579
    FT_ULong   stateArray;      /* offset to StateArray */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1580
    FT_ULong   entryTable;      /* offset to EntryTable */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1581
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1582
    FT_ULong   classTable_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1583
    FT_ULong   stateArray_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1584
    FT_ULong   entryTable_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1585
    FT_UShort  maxState;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1586
    FT_UShort  maxEntry;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1587
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1588
    GXV_XStateTable_Subtable_Setup_Func  setup_func;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1589
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1590
    FT_Bytes   p = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1591
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1592
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1593
    GXV_NAME_ENTER( "XStateTable" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1594
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1595
    GXV_TRACE(( "XStateTable header\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1596
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1597
    GXV_LIMIT_CHECK( 4 + 4 + 4 + 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1598
    valid->xstatetable.nClasses = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1599
    classTable = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1600
    stateArray = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1601
    entryTable = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1602
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1603
    GXV_TRACE(( "nClasses =0x%08x\n", valid->xstatetable.nClasses ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1604
    GXV_TRACE(( "offset to classTable=0x%08x\n", classTable ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1605
    GXV_TRACE(( "offset to stateArray=0x%08x\n", stateArray ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1606
    GXV_TRACE(( "offset to entryTable=0x%08x\n", entryTable ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1607
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1608
    if ( valid->xstatetable.nClasses > 0xFFFFU )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1609
      FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1610
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1611
    GXV_TRACE(( "StateTable Subtables\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1612
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1613
    if ( valid->xstatetable.optdata_load_func != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1614
      valid->xstatetable.optdata_load_func( p, limit, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1615
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1616
    if ( valid->xstatetable.subtable_setup_func != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1617
      setup_func = valid->xstatetable.subtable_setup_func;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1618
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1619
      setup_func = gxv_XStateTable_subtable_setup;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1620
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1621
    setup_func( limit - table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1622
                classTable,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1623
                stateArray,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1624
                entryTable,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1625
                &classTable_length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1626
                &stateArray_length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1627
                &entryTable_length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1628
                valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1629
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1630
    if ( classTable != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1631
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1632
      valid->xstatetable.maxClassID = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1633
      valid->lookupval_sign         = GXV_LOOKUPVALUE_UNSIGNED;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1634
      valid->lookupval_func         = gxv_XClassTable_lookupval_validate;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1635
      valid->lookupfmt4_trans       = gxv_XClassTable_lookupfmt4_transit;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1636
      gxv_LookupTable_validate( table + classTable,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1637
                                table + classTable + classTable_length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1638
                                valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1639
      if ( valid->subtable_length < classTable_length )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1640
        classTable_length = valid->subtable_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1641
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1642
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1643
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1644
      /* XXX: check range? */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1645
      valid->xstatetable.maxClassID =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1646
        (FT_UShort)( valid->xstatetable.nClasses - 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1647
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1648
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1649
    if ( stateArray != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1650
      gxv_XStateArray_validate( table + stateArray,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1651
                                &stateArray_length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1652
                                valid->xstatetable.maxClassID,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1653
                                valid->xstatetable.nClasses,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1654
                                &maxState,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1655
                                &maxEntry,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1656
                                valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1657
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1658
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1659
      maxState = 1; /* 0:start of text, 1:start of line are predefined */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1660
      maxEntry = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1661
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1662
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1663
    if ( maxEntry > 0 && entryTable == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1664
      FT_INVALID_OFFSET;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1665
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1666
    if ( entryTable != 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1667
      gxv_XEntryTable_validate( table + entryTable,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1668
                                &entryTable_length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1669
                                maxEntry,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1670
                                stateArray_length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1671
                                valid->xstatetable.maxClassID,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1672
                                table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1673
                                limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1674
                                valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1675
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1676
    GXV_EXIT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1677
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1678
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1679
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1680
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1681
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1682
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1683
  /*****                        Table overlapping                      *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1684
  /*****                                                               *****/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1685
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1686
  /*************************************************************************/
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1687
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1688
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1689
  gxv_compare_ranges( FT_Bytes  table1_start,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1690
                      FT_ULong  table1_length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1691
                      FT_Bytes  table2_start,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1692
                      FT_ULong  table2_length )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1693
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1694
    if ( table1_start == table2_start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1695
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1696
      if ( ( table1_length == 0 || table2_length == 0 ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1697
        goto Out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1698
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1699
    else if ( table1_start < table2_start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1700
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1701
      if ( ( table1_start + table1_length ) <= table2_start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1702
        goto Out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1703
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1704
    else if ( table1_start > table2_start )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1705
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1706
      if ( ( table1_start >= table2_start + table2_length ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1707
        goto Out;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1708
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1709
    return 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1710
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1711
  Out:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1712
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1713
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1714
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1715
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1716
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1717
  gxv_odtect_add_range( FT_Bytes          start,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1718
                        FT_ULong          length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1719
                        const FT_String*  name,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1720
                        GXV_odtect_Range  odtect )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1721
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1722
    odtect->range[ odtect->nRanges ].start  = start;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1723
    odtect->range[ odtect->nRanges ].length = length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1724
    odtect->range[ odtect->nRanges ].name   = (FT_String*)name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1725
    odtect->nRanges++;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1726
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1727
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1728
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1729
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1730
  gxv_odtect_validate( GXV_odtect_Range  odtect,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1731
                       GXV_Validator     valid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1732
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1733
    FT_UInt  i, j;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1734
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1735
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1736
    GXV_NAME_ENTER( "check overlap among multi ranges" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1737
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1738
    for ( i = 0; i < odtect->nRanges; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1739
      for ( j = 0; j < i; j++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1740
        if ( 0 != gxv_compare_ranges( odtect->range[i].start,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1741
                                      odtect->range[i].length,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1742
                                      odtect->range[j].start,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1743
                                      odtect->range[j].length ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1744
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1745
          if ( odtect->range[i].name || odtect->range[j].name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1746
            GXV_TRACE(( "found overlap between range %d and range %d\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1747
                        i, j ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1748
          else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1749
            GXV_TRACE(( "found overlap between `%s' and `%s\'\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1750
                        odtect->range[i].name,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1751
                        odtect->range[j].name ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1752
          FT_INVALID_OFFSET;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1753
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1754
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1755
    GXV_EXIT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1756
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1757
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1758
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
  1759
/* END */