misc/libfreetype/src/gxvalid/gxvmorx.c
author nemo
Sun, 11 Sep 2011 10:46:53 -0400
changeset 5856 ed97138dc414
parent 5172 88f2e05288ba
permissions -rw-r--r--
Should prevent a crasher when drowning while firing
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
/*  gxvmorx.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 morx table 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 2005, 2008 by                                                */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
/*  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 "gxvmorx.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_gxvmorx
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
  gxv_morx_subtables_validate( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
                               FT_Bytes       limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
                               FT_UShort      nSubtables,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
                               GXV_Validator  valid )
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
    FT_Bytes  p = table;
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
    GXV_Validate_Func fmt_funcs_table[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
      gxv_morx_subtable_type0_validate, /* 0 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
      gxv_morx_subtable_type1_validate, /* 1 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
      gxv_morx_subtable_type2_validate, /* 2 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
      NULL,                             /* 3 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
      gxv_morx_subtable_type4_validate, /* 4 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
      gxv_morx_subtable_type5_validate, /* 5 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
    };
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
    GXV_Validate_Func  func;
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_UShort  i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
    GXV_NAME_ENTER( "subtables in a chain" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
    for ( i = 0; i < nSubtables; i++ )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
      FT_ULong  length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
      FT_ULong  coverage;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
      FT_ULong  subFeatureFlags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
      FT_ULong  type;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
      FT_ULong  rest;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
      GXV_LIMIT_CHECK( 4 + 4 + 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
      length          = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
      coverage        = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
      subFeatureFlags = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
      GXV_TRACE(( "validating chain subtable %d/%d (%d bytes)\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
                  i + 1, nSubtables, length ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
      type = coverage & 0x0007;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
      rest = length - ( 4 + 4 + 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
      GXV_LIMIT_CHECK( rest );
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
      /* morx coverage consists of mort_coverage & 16bit padding */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
      gxv_mort_coverage_validate( (FT_UShort)( ( coverage >> 16 ) | coverage ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
                                  valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
      if ( type > 5 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
        FT_INVALID_FORMAT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
      func = fmt_funcs_table[type];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
      if ( func == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
        GXV_TRACE(( "morx type %d is reserved\n", type ));
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
      func( p, p + rest, valid );
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
      p += rest;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
    }
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
    valid->subtable_length = p - table;
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
    GXV_EXIT;
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
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
  gxv_morx_chain_validate( FT_Bytes       table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
                           FT_Bytes       limit,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
                           GXV_Validator  valid )
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
    FT_Bytes  p = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
    FT_ULong  defaultFlags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
    FT_ULong  chainLength;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
    FT_ULong  nFeatureFlags;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
    FT_ULong  nSubtables;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
    GXV_NAME_ENTER( "morx chain header" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
    GXV_LIMIT_CHECK( 4 + 4 + 4 + 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
    defaultFlags  = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
    chainLength   = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
    nFeatureFlags = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
    nSubtables    = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
    /* feature-array of morx is same with that of mort */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
    gxv_mort_featurearray_validate( p, limit, nFeatureFlags, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
    p += valid->subtable_length;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
    if ( nSubtables >= 0x10000L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
      FT_INVALID_DATA;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
    gxv_morx_subtables_validate( p, table + chainLength,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
                                 (FT_UShort)nSubtables, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
    valid->subtable_length = chainLength;
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
    GXV_EXIT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
  FT_LOCAL_DEF( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
  gxv_morx_validate( FT_Bytes      table,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
                     FT_Face       face,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
                     FT_Validator  ftvalid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
    GXV_ValidatorRec  validrec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
    GXV_Validator     valid = &validrec;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
    FT_Bytes          p     = table;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
    FT_Bytes          limit = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
    FT_ULong          version;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
    FT_ULong          nChains;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
    FT_ULong          i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
    valid->root = ftvalid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
    valid->face = face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
    FT_TRACE3(( "validating `morx' table\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
    GXV_INIT;
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
    GXV_LIMIT_CHECK( 4 + 4 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
    version = FT_NEXT_ULONG( p );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
    nChains = FT_NEXT_ULONG( p );
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
    if ( version != 0x00020000UL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
      FT_INVALID_FORMAT;
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
    for ( i = 0; i < nChains; i++ )
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
      GXV_TRACE(( "validating chain %d/%d\n", i + 1, nChains ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
      GXV_32BIT_ALIGNMENT_VALIDATE( p - table );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
      gxv_morx_chain_validate( p, limit, valid );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
      p += valid->subtable_length;
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_TRACE4(( "\n" ));
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
/* END */