/src/freetype/src/gxvalid/gxvmorx1.c

https://bitbucket.org/cabalistic/ogredeps/ · C · 277 lines · 168 code · 67 blank · 42 comment · 5 complexity · ef339d3ca1810f5bd45bd9b6bce2bae0 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. #ifdef GXV_LOAD_TRACE_VARS
  89. FT_UShort setMark;
  90. FT_UShort dontAdvance;
  91. #endif
  92. FT_UShort reserved;
  93. FT_Short markIndex;
  94. FT_Short currentIndex;
  95. GXV_morx_subtable_type1_StateOptRecData optdata =
  96. (GXV_morx_subtable_type1_StateOptRecData)valid->xstatetable.optdata;
  97. FT_UNUSED( state );
  98. FT_UNUSED( table );
  99. FT_UNUSED( limit );
  100. #ifdef GXV_LOAD_TRACE_VARS
  101. setMark = (FT_UShort)( ( flags >> 15 ) & 1 );
  102. dontAdvance = (FT_UShort)( ( flags >> 14 ) & 1 );
  103. #endif
  104. reserved = (FT_UShort)( flags & 0x3FFF );
  105. markIndex = (FT_Short)( glyphOffset_p->ul >> 16 );
  106. currentIndex = (FT_Short)( glyphOffset_p->ul );
  107. GXV_TRACE(( " setMark=%01d dontAdvance=%01d\n",
  108. setMark, dontAdvance ));
  109. if ( 0 < reserved )
  110. {
  111. GXV_TRACE(( " non-zero bits found in reserved range\n" ));
  112. GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA );
  113. }
  114. GXV_TRACE(( "markIndex = %d, currentIndex = %d\n",
  115. markIndex, currentIndex ));
  116. if ( optdata->substitutionTable_num_lookupTables < markIndex + 1 )
  117. optdata->substitutionTable_num_lookupTables =
  118. (FT_Short)( markIndex + 1 );
  119. if ( optdata->substitutionTable_num_lookupTables < currentIndex + 1 )
  120. optdata->substitutionTable_num_lookupTables =
  121. (FT_Short)( currentIndex + 1 );
  122. }
  123. static void
  124. gxv_morx_subtable_type1_LookupValue_validate( FT_UShort glyph,
  125. GXV_LookupValueCPtr value_p,
  126. GXV_Validator valid )
  127. {
  128. FT_UNUSED( glyph ); /* for the non-debugging case */
  129. GXV_TRACE(( "morx subtable type1 subst.: %d -> %d\n", glyph, value_p->u ));
  130. if ( value_p->u > valid->face->num_glyphs )
  131. FT_INVALID_GLYPH_ID;
  132. }
  133. static GXV_LookupValueDesc
  134. gxv_morx_subtable_type1_LookupFmt4_transit(
  135. FT_UShort relative_gindex,
  136. GXV_LookupValueCPtr base_value_p,
  137. FT_Bytes lookuptbl_limit,
  138. GXV_Validator valid )
  139. {
  140. FT_Bytes p;
  141. FT_Bytes limit;
  142. FT_UShort offset;
  143. GXV_LookupValueDesc value;
  144. /* XXX: check range? */
  145. offset = (FT_UShort)( base_value_p->u +
  146. relative_gindex * sizeof ( FT_UShort ) );
  147. p = valid->lookuptbl_head + offset;
  148. limit = lookuptbl_limit;
  149. GXV_LIMIT_CHECK ( 2 );
  150. value.u = FT_NEXT_USHORT( p );
  151. return value;
  152. }
  153. /*
  154. * TODO: length should be limit?
  155. **/
  156. static void
  157. gxv_morx_subtable_type1_substitutionTable_validate( FT_Bytes table,
  158. FT_Bytes limit,
  159. GXV_Validator valid )
  160. {
  161. FT_Bytes p = table;
  162. FT_UShort i;
  163. GXV_morx_subtable_type1_StateOptRecData optdata =
  164. (GXV_morx_subtable_type1_StateOptRecData)valid->xstatetable.optdata;
  165. /* TODO: calculate offset/length for each lookupTables */
  166. valid->lookupval_sign = GXV_LOOKUPVALUE_UNSIGNED;
  167. valid->lookupval_func = gxv_morx_subtable_type1_LookupValue_validate;
  168. valid->lookupfmt4_trans = gxv_morx_subtable_type1_LookupFmt4_transit;
  169. for ( i = 0; i < optdata->substitutionTable_num_lookupTables; i++ )
  170. {
  171. FT_ULong offset;
  172. GXV_LIMIT_CHECK( 4 );
  173. offset = FT_NEXT_ULONG( p );
  174. gxv_LookupTable_validate( table + offset, limit, valid );
  175. }
  176. /* TODO: overlapping of lookupTables in substitutionTable */
  177. }
  178. /*
  179. * subtable for Contextual glyph substitution is a modified StateTable.
  180. * In addition to classTable, stateArray, entryTable, the field
  181. * `substitutionTable' is added.
  182. */
  183. FT_LOCAL_DEF( void )
  184. gxv_morx_subtable_type1_validate( FT_Bytes table,
  185. FT_Bytes limit,
  186. GXV_Validator valid )
  187. {
  188. FT_Bytes p = table;
  189. GXV_morx_subtable_type1_StateOptRec st_rec;
  190. GXV_NAME_ENTER( "morx chain subtable type1 (Contextual Glyph Subst)" );
  191. GXV_LIMIT_CHECK( GXV_MORX_SUBTABLE_TYPE1_HEADER_SIZE );
  192. st_rec.substitutionTable_num_lookupTables = 0;
  193. valid->xstatetable.optdata =
  194. &st_rec;
  195. valid->xstatetable.optdata_load_func =
  196. gxv_morx_subtable_type1_substitutionTable_load;
  197. valid->xstatetable.subtable_setup_func =
  198. gxv_morx_subtable_type1_subtable_setup;
  199. valid->xstatetable.entry_glyphoffset_fmt =
  200. GXV_GLYPHOFFSET_ULONG;
  201. valid->xstatetable.entry_validate_func =
  202. gxv_morx_subtable_type1_entry_validate;
  203. gxv_XStateTable_validate( p, limit, valid );
  204. gxv_morx_subtable_type1_substitutionTable_validate(
  205. table + st_rec.substitutionTable,
  206. table + st_rec.substitutionTable + st_rec.substitutionTable_length,
  207. valid );
  208. GXV_EXIT;
  209. }
  210. /* END */