Edit

kc3-lang/freetype/src/gxvalid/gxvtrak.c

Branch :

  • Show log

    Commit

  • Author : Werner Lemberg
    Date : 2005-09-05 19:31:27
    Hash : 99aa14c2
    Message : 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.

  • src/gxvalid/gxvtrak.c
  • /***************************************************************************/
    /*                                                                         */
    /*  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 */