Hash :
99aa14c2
        
        Author :
  
        
        Date :
2005-09-05T19:31:27
        
      
Fixes for `make multi' and using C++ compiler. * gxvalid/gxvcommn.c (gxv_set_length_by_ushort_offset, gxv_set_length_by_ulong_offset, gxv_array_getlimits_byte, gxv_array_getlimits_ushort): Declare with FT_LOCAL_DEF. (gxv_compare_ranges): Make it static. (gxv_LookupTable_fmt0_validate, gxv_LookupTable_fmt2_validate, gxv_LookupTable_fmt4_validate, gxv_LookupTable_fmt6_validate, gxv_LookupTable_fmt8_validate, gxv_LookupTable_validate): Improve trace messages. (gxv_StateArray_validate, gxv_XStateArray_validate): s/class/clazz/. (GXV_STATETABLE_HEADER_SIZE, GXV_STATEHEADER_SIZE, GXV_XSTATETABLE_HEADER_SIZE, GXV_XSTATEHEADER_SIZE): Move to gxvcommn.h. * gxvalid/gxvcommn.h: Add prototypes for gxv_StateTable_subtable_setup, gxv_XStateTable_subtable_setup, gxv_XStateTable_validate, gxv_array_getlimits_byte, gxv_array_getlimits_ushort, gxv_set_length_by_ushort_offset, gxv_set_length_by_ulong_offset, gxv_odtect_add_range, gxv_odtect_validate. (GXV_STATETABLE_HEADER_SIZE, GXV_STATEHEADER_SIZE, GXV_XSTATETABLE_HEADER_SIZE, GXV_XSTATEHEADER_SIZE): Moved from gxvcommn.c. * src/gxvalid/gxvbsln.c (gxv_bsln_LookupValue_validate, gxv_bsln_parts_fmt1_validate): Improve trace messages. * gxvalid/gxvfeat.c: Split off predefined registry stuff to... * gxvalid/gxvfeat.h: New file. * gxvalid/gxvjust.c (gxv_just_wdc_entry_validate): Improve trace message. * gxvalid/gxvkern.c (GXV_kern_Dialect): Add KERN_DIALECT_UNKNOWN. (gxv_kern_subtable_fmt1_valueTable_load, gxv_kern_subtable_fmt1_subtable_setup, gxv_kern_subtable_fmt1_entry_validate): Fix C++ compiler errors. (gxv_kern_coverage_validate): Use KERN_DIALECT_UNKWOWN. Improve trace message. (gxv_kern_validate_generic): Fix C++ compiler error. Improve trace message. (gxv_kern_validate_classic): Fix C++ compiler error. * gxvalid/gxvmort0.c (gxv_mort_subtable_type0_validate): Declare with FT_LOCAL_DEF. * gxvalid/gxvmort1.c (gxv_mort_subtable_type1_substitutionTable_load, gxv_mort_subtable_type1_subtable_setup): Fix C++ compiler errors. (gxv_mort_subtable_type1_substTable_validate): Improve trace message. (gxv_mort_subtable_type1_validate): Declare with FT_LOCAL_DEF. * gxvalid/gxvmort2.c (gxv_mort_subtable_type2_opttable_load, gxv_mort_subtable_type2_subtable_setup, gxv_mort_subtable_type2_ligActionOffset_validate, gxv_mort_subtable_type2_ligatureTable_validate): Fix C++ compiler errors. (gxv_mort_subtable_type2_validate): Declare with FT_LOCAL_DEF. * gxvalid/gxvmort4.c (gxv_mort_subtable_type4_validate): Declare with FT_LOCAL_DEF. * gxvalid/gxvmort5.c (gxv_mort_subtable_type5_subtable_setup, gxv_mort_subtable_type5_InsertList_validate): Fix C++ compiler errors. (gxv_mort_subtable_type5_validate): Declare with FT_LOCAL_DEF. * gxvalid/gxvmort.c: Include gxvfeat.h. (gxv_mort_featurearray_validate, gxv_mort_coverage_validate): Declare with FT_LOCAL_DEF. (gxv_mort_subtables_validate, gxv_mort_validate): Improve trace messages. * gxvalid/gxvmort.h (gxv_mort_feature_validate): Remove. * gxvalid/gxvmorx0.c (gxv_morx_subtable_type0_validate): Declare with FT_LOCAL_DEF. * gxvalid/gxvmorx1.c (gxv_morx_subtable_type1_substitutionTable_load, gxv_morx_subtable_type1_subtable_setup, gxv_morx_subtable_type1_entry_validate, gxv_morx_subtable_type1_substitutionTable_validate): Fix C++ compiler errors. (gxv_morx_subtable_type1_validate): Declare with FT_LOCAL_DEF. * gxvalid/gxvmorx2.c (gxv_morx_subtable_type2_opttable_load, gxv_morx_subtable_type2_subtable_setup, gxv_morx_subtable_type2_ligActionIndex_validate, gxv_morx_subtable_type2_ligatureTable_validate): Fix C++ compiler errors. (gxv_morx_subtable_type2_validate): Declare with FT_LOCAL_DEF. Fix typo. * gxvalid/gxvmorx4.c (gxv_morx_subtable_type4_validate): Declare with FT_LOCAL_DEF. * gxvalid/gxvmorx5.c (gxv_morx_subtable_type5_insertionGlyph_load, gxv_morx_subtable_type5_subtable_setup): Fix C++ compiler error. (gxv_morx_subtable_type5_validate): Declare with FT_LOCAL_DEF. * gxvalid/gxvmorx.c (gxv_morx_subtables_validate, gxv_morx_validate): Improve trace message. * gxvalid/gxvopbd.c (gxv_opbd_LookupFmt4_transit): Fix compiler warnings. (gxv_opbd_validate): Improve trace message. * gxvalid/gxvprop.c: Decorate constants with `U' and `L' where appropriate. (gxv_prop_zero_advance_validate, gxv_prop_validate): Improve trace message. * gxvalid/gxvtrak.c (gxv_trak_trackTable_validate): Remove unused parameter. Update all callers. (gxv_trak_validate): Improve trace message. * rules.mk (GXV_DRV_H): Add gxvfeat.h.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
/***************************************************************************/
/*                                                                         */
/*  gxvtrak.c                                                              */
/*                                                                         */
/*    TrueTypeGX/AAT trak table validation (body).                         */
/*                                                                         */
/*  Copyright 2004, 2005 by suzuki toshiya, Masatake YAMATO, Red Hat K.K., */
/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
/*                                                                         */
/*  This file is part of the FreeType project, and may only be used,       */
/*  modified, and distributed under the terms of the FreeType project      */
/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
/*  this file you indicate that you have read the license and              */
/*  understand and accept it fully.                                        */
/*                                                                         */
/***************************************************************************/
/***************************************************************************/
/*                                                                         */
/* gxvalid is derived from both gxlayout module and otvalid module.        */
/* Development of gxlayout is supported by the Information-technology      */
/* Promotion Agency(IPA), Japan.                                           */
/*                                                                         */
/***************************************************************************/
#include "gxvalid.h"
#include "gxvcommn.h"
  /*************************************************************************/
  /*                                                                       */
  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
  /* messages during execution.                                            */
  /*                                                                       */
#undef  FT_COMPONENT
#define FT_COMPONENT  trace_gxvtrak
  /*************************************************************************/
  /*************************************************************************/
  /*****                                                               *****/
  /*****                      Data and Types                           *****/
  /*****                                                               *****/
  /*************************************************************************/
  /*************************************************************************/
    /*
     * referred track table format specification:
     * http://developer.apple.com/fonts/TTRefMan/RM06/Chap6trak.html
     * last update was 1996.
     * ----------------------------------------------
     * [MINIMUM HEADER]: GXV_TRAK_SIZE_MIN
     * version          (fixed:  32bit) = 0x00010000
     * format           (uint16: 16bit) = 0 is only defined (1996)
     * horizOffset      (uint16: 16bit)
     * vertOffset       (uint16: 16bit)
     * reserved         (uint16: 16bit) = 0
     * ----------------------------------------------
     * [VARIABLE BODY]:
     * horizData
     *   header         ( 2 + 2 + 4
     *   trackTable       + nTracks * ( 4 + 2 + 2 )
     *   sizeTable        + nSizes * 4 )
     * ----------------------------------------------
     * vertData
     *   header         ( 2 + 2 + 4
     *   trackTable       + nTracks * ( 4 + 2 + 2 )
     *   sizeTable        + nSizes * 4 )
     * ----------------------------------------------
     */
  typedef struct  GXV_trak_DataRec_
  {
    FT_UShort  trackValueOffset_min;
    FT_UShort  trackValueOffset_max;
  } GXV_trak_DataRec, *GXV_trak_Data;
#define GXV_TRAK_DATA( FIELD )  GXV_TABLE_DATA( trak, FIELD )
  /*************************************************************************/
  /*************************************************************************/
  /*****                                                               *****/
  /*****                      UTILITY FUNCTIONS                        *****/
  /*****                                                               *****/
  /*************************************************************************/
  /*************************************************************************/
  static void
  gxv_trak_trackTable_validate( FT_Bytes       table,
                                FT_Bytes       limit,
                                FT_UShort      nTracks,
                                GXV_Validator  valid )
  {
    FT_Bytes   p = table;
    FT_Fixed   track;
    FT_UShort  nameIndex;
    FT_UShort  offset;
    FT_UShort  i;
    GXV_NAME_ENTER( "trackTable" );
    GXV_TRAK_DATA( trackValueOffset_min ) = 0xFFFFU;
    GXV_TRAK_DATA( trackValueOffset_max ) = 0x0000;
    for ( i = 0; i < nTracks; i ++ )
    {
      GXV_LIMIT_CHECK( 4 + 2 + 2 );
      track     = FT_NEXT_LONG( p );
      nameIndex = FT_NEXT_USHORT( p );
      offset    = FT_NEXT_USHORT( p );
      if ( offset < GXV_TRAK_DATA( trackValueOffset_min ) )
        GXV_TRAK_DATA( trackValueOffset_min ) = offset;
      if ( offset > GXV_TRAK_DATA( trackValueOffset_max ) )
        GXV_TRAK_DATA( trackValueOffset_max ) = offset;
      gxv_sfntName_validate( nameIndex, 256, 32767, valid );
    }
    valid->subtable_length = p - table;
    GXV_EXIT;
  }
  static void
  gxv_trak_trackData_validate( FT_Bytes       table,
                               FT_Bytes       limit,
                               GXV_Validator  valid )
  {
    FT_Bytes   p = table;
    FT_UShort  nTracks;
    FT_UShort  nSizes;
    FT_ULong   sizeTableOffset;
    GXV_ODTECT( 4, odtect );
    GXV_ODTECT_INIT( odtect );
    GXV_NAME_ENTER( "trackData" );
    /* read the header of trackData */
    GXV_LIMIT_CHECK( 2 + 2 + 4 );
    nTracks         = FT_NEXT_USHORT( p );
    nSizes          = FT_NEXT_USHORT( p );
    sizeTableOffset = FT_NEXT_ULONG( p );
    gxv_odtect_add_range( table, p - table, "trackData header", odtect );
    /* validate trackTable */
    gxv_trak_trackTable_validate( p, limit, nTracks, valid );
    gxv_odtect_add_range( p, valid->subtable_length,
                          "trackTable", odtect );
    /* sizeTable is array of FT_Fixed, don't check contents */
    p = valid->root->base + sizeTableOffset;
    GXV_LIMIT_CHECK( nSizes * 4 );
    gxv_odtect_add_range( p, nSizes * 4, "sizeTable", odtect );
    /* validate trackValueOffet */
    p = valid->root->base + GXV_TRAK_DATA( trackValueOffset_min );
    if ( limit - p < nTracks * nSizes * 2 )
      GXV_TRACE(( "too short trackValue array\n" ));
    p = valid->root->base + GXV_TRAK_DATA( trackValueOffset_max );
    GXV_LIMIT_CHECK( nSizes * 2 );
    gxv_odtect_add_range( valid->root->base
                            + GXV_TRAK_DATA( trackValueOffset_min ),
                          GXV_TRAK_DATA( trackValueOffset_max )
                            - GXV_TRAK_DATA( trackValueOffset_min )
                            + nSizes * 2,
                          "trackValue array", odtect );
    gxv_odtect_validate( odtect, valid );
    GXV_EXIT;
  }
  /*************************************************************************/
  /*************************************************************************/
  /*****                                                               *****/
  /*****                          trak TABLE                           *****/
  /*****                                                               *****/
  /*************************************************************************/
  /*************************************************************************/
  FT_LOCAL_DEF( void )
  gxv_trak_validate( FT_Bytes      table,
                     FT_Face       face,
                     FT_Validator  ftvalid )
  {
    FT_Bytes          p = table;
    FT_Bytes          limit = 0;
    FT_UInt           table_size;
    GXV_ValidatorRec  validrec;
    GXV_Validator     valid = &validrec;
    GXV_trak_DataRec  trakrec;
    GXV_trak_Data     trak = &trakrec;
    FT_ULong   version;
    FT_UShort  format;
    FT_UShort  horizOffset;
    FT_UShort  vertOffset;
    FT_UShort  reserved;
    GXV_ODTECT( 3, odtect );
    GXV_ODTECT_INIT( odtect );
    valid->root       = ftvalid;
    valid->table_data = trak;
    valid->face       = face;
    limit      = valid->root->limit;
    table_size = limit - table;
    FT_TRACE3(( "validating `trak' table\n" ));
    GXV_INIT;
    GXV_LIMIT_CHECK( 4 + 2 + 2 + 2 + 2 );
    version     = FT_NEXT_ULONG( p );
    format      = FT_NEXT_USHORT( p );
    horizOffset = FT_NEXT_USHORT( p );
    vertOffset  = FT_NEXT_USHORT( p );
    reserved    = FT_NEXT_USHORT( p );
    GXV_TRACE(( " (version = 0x%08x)\n", version ));
    GXV_TRACE(( " (format = 0x%04x)\n", format ));
    GXV_TRACE(( " (horizOffset = 0x%04x)\n", horizOffset ));
    GXV_TRACE(( " (vertOffset = 0x%04x)\n", vertOffset ));
    GXV_TRACE(( " (reserved = 0x%04x)\n", reserved ));
    /* Version 1.0 (always:1996) */
    if ( version != 0x00010000UL )
      FT_INVALID_FORMAT;
    /* format 0 (always:1996) */
    if ( format != 0x0000 )
      FT_INVALID_FORMAT;
    GXV_32BIT_ALIGNMENT_VALIDATE( horizOffset );
    GXV_32BIT_ALIGNMENT_VALIDATE( vertOffset );
    /* Reserved Fixed Value (always) */
    if ( reserved != 0x0000 )
      FT_INVALID_DATA;
    /* validate trackData */
    if ( 0 < horizOffset )
    {
      gxv_trak_trackData_validate( table + horizOffset, limit, valid );
      gxv_odtect_add_range( table + horizOffset, valid->subtable_length,
                            "horizJustData", odtect );
    }
    if ( 0 < vertOffset )
    {
      gxv_trak_trackData_validate( table + vertOffset, limit, valid );
      gxv_odtect_add_range( table + vertOffset, valid->subtable_length,
                            "vertJustData", odtect );
    }
    gxv_odtect_validate( odtect, valid );
    FT_TRACE4(( "\n" ));
  }
/* END */