gxvmorx5.c 8.3 KB
Newer Older
M
Ming, Bai 已提交
1 2 3 4 5 6 7
/***************************************************************************/
/*                                                                         */
/*  gxvmorx5.c                                                             */
/*                                                                         */
/*    TrueTypeGX/AAT morx table validation                                 */
/*    body for type5 (Contextual Glyph Insertion) subtable.                */
/*                                                                         */
8 9
/*  Copyright 2005-2015 by                                                 */
/*  suzuki toshiya, Masatake YAMATO, Red Hat K.K.,                         */
M
Ming, Bai 已提交
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
/*  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 "gxvmorx.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_gxvmorx


  /*
   * `morx' subtable type5 (Contextual Glyph Insertion)
   * has format of a StateTable with insertion-glyph-list
   * without name.  However, the 32bit offset from the head
   * of subtable to the i-g-l is given after `entryTable',
   * without variable name specification (the existence of
   * this offset to the table is different from mort type5).
   */


  typedef struct  GXV_morx_subtable_type5_StateOptRec_
  {
    FT_ULong  insertionGlyphList;
    FT_ULong  insertionGlyphList_length;

  }  GXV_morx_subtable_type5_StateOptRec,
    *GXV_morx_subtable_type5_StateOptRecData;


#define GXV_MORX_SUBTABLE_TYPE5_HEADER_SIZE \
          ( GXV_STATETABLE_HEADER_SIZE + 4 )


  static void
  gxv_morx_subtable_type5_insertionGlyphList_load( FT_Bytes       table,
                                                   FT_Bytes       limit,
G
Grissiom 已提交
68
                                                   GXV_Validator  gxvalid )
M
Ming, Bai 已提交
69 70 71 72
  {
    FT_Bytes  p = table;

    GXV_morx_subtable_type5_StateOptRecData  optdata =
G
Grissiom 已提交
73
      (GXV_morx_subtable_type5_StateOptRecData)gxvalid->xstatetable.optdata;
M
Ming, Bai 已提交
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88


    GXV_LIMIT_CHECK( 4 );
    optdata->insertionGlyphList = FT_NEXT_ULONG( p );
  }


  static void
  gxv_morx_subtable_type5_subtable_setup( FT_ULong       table_size,
                                          FT_ULong       classTable,
                                          FT_ULong       stateArray,
                                          FT_ULong       entryTable,
                                          FT_ULong*      classTable_length_p,
                                          FT_ULong*      stateArray_length_p,
                                          FT_ULong*      entryTable_length_p,
G
Grissiom 已提交
89
                                          GXV_Validator  gxvalid )
M
Ming, Bai 已提交
90 91 92 93 94 95
  {
    FT_ULong   o[4];
    FT_ULong*  l[4];
    FT_ULong   buff[5];

    GXV_morx_subtable_type5_StateOptRecData  optdata =
G
Grissiom 已提交
96
      (GXV_morx_subtable_type5_StateOptRecData)gxvalid->xstatetable.optdata;
M
Ming, Bai 已提交
97 98 99 100 101 102 103 104 105 106 107


    o[0] = classTable;
    o[1] = stateArray;
    o[2] = entryTable;
    o[3] = optdata->insertionGlyphList;
    l[0] = classTable_length_p;
    l[1] = stateArray_length_p;
    l[2] = entryTable_length_p;
    l[3] = &(optdata->insertionGlyphList_length);

G
Grissiom 已提交
108
    gxv_set_length_by_ulong_offset( o, l, buff, 4, table_size, gxvalid );
M
Ming, Bai 已提交
109 110 111 112 113 114 115 116
  }


  static void
  gxv_morx_subtable_type5_InsertList_validate( FT_UShort      table_index,
                                               FT_UShort      count,
                                               FT_Bytes       table,
                                               FT_Bytes       limit,
G
Grissiom 已提交
117
                                               GXV_Validator  gxvalid )
M
Ming, Bai 已提交
118
  {
G
Grissiom 已提交
119
    FT_Bytes  p = table + table_index * 2;
M
Ming, Bai 已提交
120 121


G
Grissiom 已提交
122 123 124
#ifndef GXV_LOAD_TRACE_VARS
    GXV_LIMIT_CHECK( count * 2 );
#else
M
Ming, Bai 已提交
125 126 127 128 129 130 131 132 133 134 135
    while ( p < table + count * 2 + table_index * 2 )
    {
      FT_UShort  insert_glyphID;


      GXV_LIMIT_CHECK( 2 );
      insert_glyphID = FT_NEXT_USHORT( p );
      GXV_TRACE(( " 0x%04x", insert_glyphID ));
    }

    GXV_TRACE(( "\n" ));
G
Grissiom 已提交
136
#endif
M
Ming, Bai 已提交
137 138 139 140 141 142 143 144 145 146
  }


  static void
  gxv_morx_subtable_type5_entry_validate(
    FT_UShort                       state,
    FT_UShort                       flags,
    GXV_StateTable_GlyphOffsetCPtr  glyphOffset_p,
    FT_Bytes                        table,
    FT_Bytes                        limit,
G
Grissiom 已提交
147
    GXV_Validator                   gxvalid )
M
Ming, Bai 已提交
148
  {
G
Grissiom 已提交
149
#ifdef GXV_LOAD_UNUSED_VARS
M
Ming, Bai 已提交
150 151 152 153 154 155
    FT_Bool    setMark;
    FT_Bool    dontAdvance;
    FT_Bool    currentIsKashidaLike;
    FT_Bool    markedIsKashidaLike;
    FT_Bool    currentInsertBefore;
    FT_Bool    markedInsertBefore;
G
Grissiom 已提交
156
#endif
M
Ming, Bai 已提交
157 158 159 160 161 162 163 164
    FT_Byte    currentInsertCount;
    FT_Byte    markedInsertCount;
    FT_Byte    currentInsertList;
    FT_UShort  markedInsertList;

    FT_UNUSED( state );


G
Grissiom 已提交
165
#ifdef GXV_LOAD_UNUSED_VARS
M
Ming, Bai 已提交
166 167 168 169 170 171
    setMark              = FT_BOOL( ( flags >> 15 ) & 1 );
    dontAdvance          = FT_BOOL( ( flags >> 14 ) & 1 );
    currentIsKashidaLike = FT_BOOL( ( flags >> 13 ) & 1 );
    markedIsKashidaLike  = FT_BOOL( ( flags >> 12 ) & 1 );
    currentInsertBefore  = FT_BOOL( ( flags >> 11 ) & 1 );
    markedInsertBefore   = FT_BOOL( ( flags >> 10 ) & 1 );
G
Grissiom 已提交
172
#endif
M
Ming, Bai 已提交
173 174 175 176 177 178 179 180 181 182 183

    currentInsertCount = (FT_Byte)( ( flags >> 5 ) & 0x1F   );
    markedInsertCount  = (FT_Byte)(   flags        & 0x001F );

    currentInsertList = (FT_Byte)  ( glyphOffset_p->ul >> 16 );
    markedInsertList  = (FT_UShort)( glyphOffset_p->ul       );

    if ( currentInsertList && 0 != currentInsertCount )
      gxv_morx_subtable_type5_InsertList_validate( currentInsertList,
                                                   currentInsertCount,
                                                   table, limit,
G
Grissiom 已提交
184
                                                   gxvalid );
M
Ming, Bai 已提交
185 186 187 188 189

    if ( markedInsertList && 0 != markedInsertCount )
      gxv_morx_subtable_type5_InsertList_validate( markedInsertList,
                                                   markedInsertCount,
                                                   table, limit,
G
Grissiom 已提交
190
                                                   gxvalid );
M
Ming, Bai 已提交
191 192 193 194 195 196
  }


  FT_LOCAL_DEF( void )
  gxv_morx_subtable_type5_validate( FT_Bytes       table,
                                    FT_Bytes       limit,
G
Grissiom 已提交
197
                                    GXV_Validator  gxvalid )
M
Ming, Bai 已提交
198 199 200 201 202 203 204 205 206 207 208
  {
    FT_Bytes  p = table;

    GXV_morx_subtable_type5_StateOptRec      et_rec;
    GXV_morx_subtable_type5_StateOptRecData  et = &et_rec;


    GXV_NAME_ENTER( "morx chain subtable type5 (Glyph Insertion)" );

    GXV_LIMIT_CHECK( GXV_MORX_SUBTABLE_TYPE5_HEADER_SIZE );

G
Grissiom 已提交
209
    gxvalid->xstatetable.optdata =
M
Ming, Bai 已提交
210
      et;
G
Grissiom 已提交
211
    gxvalid->xstatetable.optdata_load_func =
M
Ming, Bai 已提交
212
      gxv_morx_subtable_type5_insertionGlyphList_load;
G
Grissiom 已提交
213
    gxvalid->xstatetable.subtable_setup_func =
M
Ming, Bai 已提交
214
      gxv_morx_subtable_type5_subtable_setup;
G
Grissiom 已提交
215
    gxvalid->xstatetable.entry_glyphoffset_fmt =
M
Ming, Bai 已提交
216
      GXV_GLYPHOFFSET_ULONG;
G
Grissiom 已提交
217
    gxvalid->xstatetable.entry_validate_func =
M
Ming, Bai 已提交
218 219
      gxv_morx_subtable_type5_entry_validate;

G
Grissiom 已提交
220
    gxv_XStateTable_validate( p, limit, gxvalid );
M
Ming, Bai 已提交
221 222 223 224 225 226

    GXV_EXIT;
  }


/* END */