gxvmorx2.c

Go to the documentation of this file.
00001 /***************************************************************************/
00002 /*                                                                         */
00003 /*  gxvmorx2.c                                                             */
00004 /*                                                                         */
00005 /*    TrueTypeGX/AAT morx table validation                                 */
00006 /*    body for type2 (Ligature Substitution) subtable.                     */
00007 /*                                                                         */
00008 /*  Copyright 2005 by suzuki toshiya, Masatake YAMATO, Red Hat K.K.,       */
00009 /*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
00010 /*                                                                         */
00011 /*  This file is part of the FreeType project, and may only be used,       */
00012 /*  modified, and distributed under the terms of the FreeType project      */
00013 /*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
00014 /*  this file you indicate that you have read the license and              */
00015 /*  understand and accept it fully.                                        */
00016 /*                                                                         */
00017 /***************************************************************************/
00018 
00019 /***************************************************************************/
00020 /*                                                                         */
00021 /* gxvalid is derived from both gxlayout module and otvalid module.        */
00022 /* Development of gxlayout is supported by the Information-technology      */
00023 /* Promotion Agency(IPA), Japan.                                           */
00024 /*                                                                         */
00025 /***************************************************************************/
00026 
00027 
00028 #include "gxvmorx.h"
00029 
00030 
00031   /*************************************************************************/
00032   /*                                                                       */
00033   /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
00034   /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
00035   /* messages during execution.                                            */
00036   /*                                                                       */
00037 #undef  FT_COMPONENT
00038 #define FT_COMPONENT  trace_gxvmorx
00039 
00040 
00041   typedef struct  GXV_morx_subtable_type2_StateOptRec_
00042   {
00043     FT_ULong  ligActionTable;
00044     FT_ULong  componentTable;
00045     FT_ULong  ligatureTable;
00046     FT_ULong  ligActionTable_length;
00047     FT_ULong  componentTable_length;
00048     FT_ULong  ligatureTable_length;
00049 
00050   }  GXV_morx_subtable_type2_StateOptRec,
00051     *GXV_morx_subtable_type2_StateOptRecData;
00052 
00053 
00054 #define GXV_MORX_SUBTABLE_TYPE2_HEADER_SIZE \
00055           ( GXV_XSTATETABLE_HEADER_SIZE + 4 + 4 + 4 )
00056 
00057 
00058   static void
00059   gxv_morx_subtable_type2_opttable_load( FT_Bytes       table,
00060                                          FT_Bytes       limit,
00061                                          GXV_Validator  valid )
00062   {
00063     FT_Bytes  p = table;
00064 
00065     GXV_morx_subtable_type2_StateOptRecData  optdata =
00066       (GXV_morx_subtable_type2_StateOptRecData)valid->xstatetable.optdata;
00067 
00068 
00069     GXV_LIMIT_CHECK( 4 + 4 + 4 );
00070     optdata->ligActionTable = FT_NEXT_ULONG( p );
00071     optdata->componentTable = FT_NEXT_ULONG( p );
00072     optdata->ligatureTable  = FT_NEXT_ULONG( p );
00073 
00074     GXV_TRACE(( "offset to ligActionTable=0x%08x\n",
00075                 optdata->ligActionTable ));
00076     GXV_TRACE(( "offset to componentTable=0x%08x\n",
00077                 optdata->componentTable ));
00078     GXV_TRACE(( "offset to ligatureTable=0x%08x\n",
00079                 optdata->ligatureTable ));
00080   }
00081 
00082 
00083   static void
00084   gxv_morx_subtable_type2_subtable_setup( FT_ULong       table_size,
00085                                           FT_ULong       classTable,
00086                                           FT_ULong       stateArray,
00087                                           FT_ULong       entryTable,
00088                                           FT_ULong*      classTable_length_p,
00089                                           FT_ULong*      stateArray_length_p,
00090                                           FT_ULong*      entryTable_length_p,
00091                                           GXV_Validator  valid )
00092   {
00093     FT_ULong   o[6];
00094     FT_ULong*  l[6];
00095     FT_ULong   buff[7];
00096 
00097     GXV_morx_subtable_type2_StateOptRecData  optdata =
00098       (GXV_morx_subtable_type2_StateOptRecData)valid->xstatetable.optdata;
00099 
00100 
00101     GXV_NAME_ENTER( "subtable boundaries setup" );
00102 
00103     o[0] = classTable;
00104     o[1] = stateArray;
00105     o[2] = entryTable;
00106     o[3] = optdata->ligActionTable;
00107     o[4] = optdata->componentTable;
00108     o[5] = optdata->ligatureTable;
00109     l[0] = classTable_length_p;
00110     l[1] = stateArray_length_p;
00111     l[2] = entryTable_length_p;
00112     l[3] = &(optdata->ligActionTable_length);
00113     l[4] = &(optdata->componentTable_length);
00114     l[5] = &(optdata->ligatureTable_length);
00115 
00116     gxv_set_length_by_ulong_offset( o, l, buff, 6, table_size, valid );
00117 
00118     GXV_TRACE(( "classTable: offset=0x%08x length=0x%08x\n",
00119                 classTable, *classTable_length_p ));
00120     GXV_TRACE(( "stateArray: offset=0x%08x length=0x%08x\n",
00121                 stateArray, *stateArray_length_p ));
00122     GXV_TRACE(( "entryTable: offset=0x%08x length=0x%08x\n",
00123                 entryTable, *entryTable_length_p ));
00124     GXV_TRACE(( "ligActionTable: offset=0x%08x length=0x%08x\n",
00125                 optdata->ligActionTable,
00126                 optdata->ligActionTable_length ));
00127     GXV_TRACE(( "componentTable: offset=0x%08x length=0x%08x\n",
00128                 optdata->componentTable,
00129                 optdata->componentTable_length ));
00130     GXV_TRACE(( "ligatureTable:  offset=0x%08x length=0x%08x\n",
00131                 optdata->ligatureTable,
00132                 optdata->ligatureTable_length ));
00133 
00134     GXV_EXIT;
00135   }
00136 
00137 
00138 #define GXV_MORX_LIGACTION_ENTRY_SIZE  4
00139 
00140 
00141   static void
00142   gxv_morx_subtable_type2_ligActionIndex_validate(
00143     FT_Bytes       table,
00144     FT_UShort      ligActionIndex,
00145     GXV_Validator  valid )
00146   {
00147     /* access ligActionTable */
00148     GXV_morx_subtable_type2_StateOptRecData optdata =
00149       (GXV_morx_subtable_type2_StateOptRecData)valid->xstatetable.optdata;
00150 
00151     FT_Bytes lat_base  = table + optdata->ligActionTable;
00152     FT_Bytes p         = lat_base +
00153                          ligActionIndex * GXV_MORX_LIGACTION_ENTRY_SIZE;
00154     FT_Bytes lat_limit = lat_base + optdata->ligActionTable;
00155 
00156 
00157     if ( p < lat_base )
00158     {
00159       GXV_TRACE(( "p < lat_base (%d byte rewind)\n", lat_base - p ));
00160       FT_INVALID_OFFSET;
00161     }
00162     else if ( lat_limit < p )
00163     {
00164       GXV_TRACE(( "lat_limit < p (%d byte overrun)\n", p - lat_limit ));
00165       FT_INVALID_OFFSET;
00166     }
00167 
00168     {
00169       /* validate entry in ligActionTable */
00170       FT_ULong   lig_action;
00171       FT_UShort  last;
00172       FT_UShort  store;
00173       FT_ULong   offset;
00174 
00175 
00176       lig_action = FT_NEXT_ULONG( p );
00177       last       = (FT_UShort)( ( lig_action >> 31 ) & 1 );
00178       store      = (FT_UShort)( ( lig_action >> 30 ) & 1 );
00179 
00180       offset = lig_action & 0x3FFFFFFFUL;
00181     }
00182   }
00183 
00184 
00185   static void
00186   gxv_morx_subtable_type2_entry_validate(
00187     FT_UShort                       state,
00188     FT_UShort                       flags,
00189     GXV_StateTable_GlyphOffsetCPtr  glyphOffset_p,
00190     FT_Bytes                        table,
00191     FT_Bytes                        limit,
00192     GXV_Validator                   valid )
00193   {
00194     FT_UShort  setComponent;
00195     FT_UShort  dontAdvance;
00196     FT_UShort  performAction;
00197     FT_UShort  reserved;
00198     FT_UShort  ligActionIndex;
00199 
00200     FT_UNUSED( state );
00201     FT_UNUSED( limit );
00202 
00203 
00204     setComponent   = (FT_UShort)( ( flags >> 15 ) & 1 );
00205     dontAdvance    = (FT_UShort)( ( flags >> 14 ) & 1 );
00206     performAction  = (FT_UShort)( ( flags >> 13 ) & 1 );
00207 
00208     reserved       = (FT_UShort)( flags & 0x1FFF );
00209     ligActionIndex = glyphOffset_p->u;
00210 
00211     if ( reserved > 0 )
00212       GXV_TRACE(( "  reserved 14bit is non-zero\n" ));
00213 
00214     if ( 0 < ligActionIndex )
00215       gxv_morx_subtable_type2_ligActionIndex_validate(
00216         table, ligActionIndex, valid );
00217   }
00218 
00219 
00220   static void
00221   gxv_morx_subtable_type2_ligatureTable_validate( FT_Bytes       table,
00222                                                   GXV_Validator  valid )
00223   {
00224     GXV_morx_subtable_type2_StateOptRecData  optdata =
00225       (GXV_morx_subtable_type2_StateOptRecData)valid->xstatetable.optdata;
00226 
00227     FT_Bytes p     = table + optdata->ligatureTable;
00228     FT_Bytes limit = table + optdata->ligatureTable
00229                            + optdata->ligatureTable_length;
00230 
00231 
00232     GXV_NAME_ENTER( "morx chain subtable type2 - substitutionTable" );
00233 
00234     if ( 0 != optdata->ligatureTable )
00235     {
00236       /* Apple does not give specification of ligatureTable format */
00237       while ( p < limit )
00238       {
00239         FT_UShort  lig_gid;
00240 
00241 
00242         GXV_LIMIT_CHECK( 2 );
00243         lig_gid = FT_NEXT_USHORT( p );
00244       }
00245     }
00246 
00247     GXV_EXIT;
00248   }
00249 
00250 
00251   FT_LOCAL_DEF( void )
00252   gxv_morx_subtable_type2_validate( FT_Bytes       table,
00253                                     FT_Bytes       limit,
00254                                     GXV_Validator  valid )
00255   {
00256     FT_Bytes  p = table;
00257 
00258     GXV_morx_subtable_type2_StateOptRec  lig_rec;
00259 
00260 
00261     GXV_NAME_ENTER( "morx chain subtable type2 (Ligature Substitution)" );
00262 
00263     GXV_LIMIT_CHECK( GXV_MORX_SUBTABLE_TYPE2_HEADER_SIZE );
00264 
00265     valid->xstatetable.optdata =
00266       &lig_rec;
00267     valid->xstatetable.optdata_load_func =
00268       gxv_morx_subtable_type2_opttable_load;
00269     valid->xstatetable.subtable_setup_func =
00270       gxv_morx_subtable_type2_subtable_setup;
00271     valid->xstatetable.entry_glyphoffset_fmt =
00272       GXV_GLYPHOFFSET_USHORT;
00273     valid->xstatetable.entry_validate_func =
00274       gxv_morx_subtable_type2_entry_validate;
00275 
00276     gxv_XStateTable_validate( p, limit, valid );
00277 
00278     p += valid->subtable_length;
00279     gxv_morx_subtable_type2_ligatureTable_validate( table, valid );
00280 
00281     GXV_EXIT;
00282   }
00283 
00284 
00285 /* END */

Generated on Tue Jul 5 14:13:47 2011 for ROOT_528-00b_version by  doxygen 1.5.1