/modules/freetype2/src/gxvalid/gxvmorx1.c

http://github.com/zpao/v8monkey · C · 274 lines · 165 code · 67 blank · 42 comment · 6 complexity · aa4d1eecab4748225ed4c3bd046b731f MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* gxvmorx1.c */
  4. /* */
  5. /* TrueTypeGX/AAT morx table validation */
  6. /* body for type1 (Contextual Substitution) subtable. */
  7. /* */
  8. /* Copyright 2005, 2007 by suzuki toshiya, Masatake YAMATO, Red Hat K.K., */
  9. /* David Turner, Robert Wilhelm, and Werner Lemberg. */
  10. /* */
  11. /* This file is part of the FreeType project, and may only be used, */
  12. /* modified, and distributed under the terms of the FreeType project */
  13. /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
  14. /* this file you indicate that you have read the license and */
  15. /* understand and accept it fully. */
  16. /* */
  17. /***************************************************************************/
  18. /***************************************************************************/
  19. /* */
  20. /* gxvalid is derived from both gxlayout module and otvalid module. */
  21. /* Development of gxlayout is supported by the Information-technology */
  22. /* Promotion Agency(IPA), Japan. */
  23. /* */
  24. /***************************************************************************/
  25. #include "gxvmorx.h"
  26. /*************************************************************************/
  27. /* */
  28. /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
  29. /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
  30. /* messages during execution. */
  31. /* */
  32. #undef FT_COMPONENT
  33. #define FT_COMPONENT trace_gxvmorx
  34. typedef struct GXV_morx_subtable_type1_StateOptRec_
  35. {
  36. FT_ULong substitutionTable;
  37. FT_ULong substitutionTable_length;
  38. FT_UShort substitutionTable_num_lookupTables;
  39. } GXV_morx_subtable_type1_StateOptRec,
  40. *GXV_morx_subtable_type1_StateOptRecData;
  41. #define GXV_MORX_SUBTABLE_TYPE1_HEADER_SIZE \
  42. ( GXV_STATETABLE_HEADER_SIZE + 2 )
  43. static void
  44. gxv_morx_subtable_type1_substitutionTable_load( FT_Bytes table,
  45. FT_Bytes limit,
  46. GXV_Validator valid )
  47. {
  48. FT_Bytes p = table;
  49. GXV_morx_subtable_type1_StateOptRecData optdata =
  50. (GXV_morx_subtable_type1_StateOptRecData)valid->xstatetable.optdata;
  51. GXV_LIMIT_CHECK( 2 );
  52. optdata->substitutionTable = FT_NEXT_USHORT( p );
  53. }
  54. static void
  55. gxv_morx_subtable_type1_subtable_setup( FT_ULong table_size,
  56. FT_ULong classTable,
  57. FT_ULong stateArray,
  58. FT_ULong entryTable,
  59. FT_ULong* classTable_length_p,
  60. FT_ULong* stateArray_length_p,
  61. FT_ULong* entryTable_length_p,
  62. GXV_Validator valid )
  63. {
  64. FT_ULong o[4];
  65. FT_ULong *l[4];
  66. FT_ULong buff[5];
  67. GXV_morx_subtable_type1_StateOptRecData optdata =
  68. (GXV_morx_subtable_type1_StateOptRecData)valid->xstatetable.optdata;
  69. o[0] = classTable;
  70. o[1] = stateArray;
  71. o[2] = entryTable;
  72. o[3] = optdata->substitutionTable;
  73. l[0] = classTable_length_p;
  74. l[1] = stateArray_length_p;
  75. l[2] = entryTable_length_p;
  76. l[3] = &(optdata->substitutionTable_length);
  77. gxv_set_length_by_ulong_offset( o, l, buff, 4, table_size, valid );
  78. }
  79. static void
  80. gxv_morx_subtable_type1_entry_validate(
  81. FT_UShort state,
  82. FT_UShort flags,
  83. GXV_StateTable_GlyphOffsetCPtr glyphOffset_p,
  84. FT_Bytes table,
  85. FT_Bytes limit,
  86. GXV_Validator valid )
  87. {
  88. FT_UShort setMark;
  89. FT_UShort dontAdvance;
  90. FT_UShort reserved;
  91. FT_Short markIndex;
  92. FT_Short currentIndex;
  93. GXV_morx_subtable_type1_StateOptRecData optdata =
  94. (GXV_morx_subtable_type1_StateOptRecData)valid->xstatetable.optdata;
  95. FT_UNUSED( state );
  96. FT_UNUSED( table );
  97. FT_UNUSED( limit );
  98. setMark = (FT_UShort)( ( flags >> 15 ) & 1 );
  99. dontAdvance = (FT_UShort)( ( flags >> 14 ) & 1 );
  100. reserved = (FT_UShort)( flags & 0x3FFF );
  101. markIndex = (FT_Short)( glyphOffset_p->ul >> 16 );
  102. currentIndex = (FT_Short)( glyphOffset_p->ul );
  103. GXV_TRACE(( " setMark=%01d dontAdvance=%01d\n",
  104. setMark, dontAdvance ));
  105. if ( 0 < reserved )
  106. {
  107. GXV_TRACE(( " non-zero bits found in reserved range\n" ));
  108. if ( valid->root->level >= FT_VALIDATE_PARANOID )
  109. FT_INVALID_DATA;
  110. }
  111. GXV_TRACE(( "markIndex = %d, currentIndex = %d\n",
  112. markIndex, currentIndex ));
  113. if ( optdata->substitutionTable_num_lookupTables < markIndex + 1 )
  114. optdata->substitutionTable_num_lookupTables =
  115. (FT_Short)( markIndex + 1 );
  116. if ( optdata->substitutionTable_num_lookupTables < currentIndex + 1 )
  117. optdata->substitutionTable_num_lookupTables =
  118. (FT_Short)( currentIndex + 1 );
  119. }
  120. static void
  121. gxv_morx_subtable_type1_LookupValue_validate( FT_UShort glyph,
  122. GXV_LookupValueCPtr value_p,
  123. GXV_Validator valid )
  124. {
  125. FT_UNUSED( glyph ); /* for the non-debugging case */
  126. GXV_TRACE(( "morx subtable type1 subst.: %d -> %d\n", glyph, value_p->u ));
  127. if ( value_p->u > valid->face->num_glyphs )
  128. FT_INVALID_GLYPH_ID;
  129. }
  130. static GXV_LookupValueDesc
  131. gxv_morx_subtable_type1_LookupFmt4_transit(
  132. FT_UShort relative_gindex,
  133. GXV_LookupValueCPtr base_value_p,
  134. FT_Bytes lookuptbl_limit,
  135. GXV_Validator valid )
  136. {
  137. FT_Bytes p;
  138. FT_Bytes limit;
  139. FT_UShort offset;
  140. GXV_LookupValueDesc value;
  141. /* XXX: check range? */
  142. offset = (FT_UShort)( base_value_p->u +
  143. relative_gindex * sizeof ( FT_UShort ) );
  144. p = valid->lookuptbl_head + offset;
  145. limit = lookuptbl_limit;
  146. GXV_LIMIT_CHECK ( 2 );
  147. value.u = FT_NEXT_USHORT( p );
  148. return value;
  149. }
  150. /*
  151. * TODO: length should be limit?
  152. **/
  153. static void
  154. gxv_morx_subtable_type1_substitutionTable_validate( FT_Bytes table,
  155. FT_Bytes limit,
  156. GXV_Validator valid )
  157. {
  158. FT_Bytes p = table;
  159. FT_UShort i;
  160. GXV_morx_subtable_type1_StateOptRecData optdata =
  161. (GXV_morx_subtable_type1_StateOptRecData)valid->xstatetable.optdata;
  162. /* TODO: calculate offset/length for each lookupTables */
  163. valid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED;
  164. valid->lookupval_func = gxv_morx_subtable_type1_LookupValue_validate;
  165. valid->lookupfmt4_trans = gxv_morx_subtable_type1_LookupFmt4_transit;
  166. for ( i = 0; i < optdata->substitutionTable_num_lookupTables; i++ )
  167. {
  168. FT_ULong offset;
  169. GXV_LIMIT_CHECK( 4 );
  170. offset = FT_NEXT_ULONG( p );
  171. gxv_LookupTable_validate( table + offset, limit, valid );
  172. }
  173. /* TODO: overlapping of lookupTables in substitutionTable */
  174. }
  175. /*
  176. * subtable for Contextual glyph substitution is a modified StateTable.
  177. * In addition to classTable, stateArray, entryTable, the field
  178. * `substitutionTable' is added.
  179. */
  180. FT_LOCAL_DEF( void )
  181. gxv_morx_subtable_type1_validate( FT_Bytes table,
  182. FT_Bytes limit,
  183. GXV_Validator valid )
  184. {
  185. FT_Bytes p = table;
  186. GXV_morx_subtable_type1_StateOptRec st_rec;
  187. GXV_NAME_ENTER( "morx chain subtable type1 (Contextual Glyph Subst)" );
  188. GXV_LIMIT_CHECK( GXV_MORX_SUBTABLE_TYPE1_HEADER_SIZE );
  189. st_rec.substitutionTable_num_lookupTables = 0;
  190. valid->xstatetable.optdata =
  191. &st_rec;
  192. valid->xstatetable.optdata_load_func =
  193. gxv_morx_subtable_type1_substitutionTable_load;
  194. valid->xstatetable.subtable_setup_func =
  195. gxv_morx_subtable_type1_subtable_setup;
  196. valid->xstatetable.entry_glyphoffset_fmt =
  197. GXV_GLYPHOFFSET_ULONG;
  198. valid->xstatetable.entry_validate_func =
  199. gxv_morx_subtable_type1_entry_validate;
  200. gxv_XStateTable_validate( p, limit, valid );
  201. gxv_morx_subtable_type1_substitutionTable_validate(
  202. table + st_rec.substitutionTable,
  203. table + st_rec.substitutionTable + st_rec.substitutionTable_length,
  204. valid );
  205. GXV_EXIT;
  206. }
  207. /* END */