/src/freetype/src/gxvalid/gxvmort5.c

https://bitbucket.org/cabalistic/ogredeps/ · C · 233 lines · 147 code · 44 blank · 42 comment · 12 complexity · 8ffc154bcb3e1dcb14051bd46d03a4bb MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* gxvmort5.c */
  4. /* */
  5. /* TrueTypeGX/AAT mort table validation */
  6. /* body for type5 (Contextual Glyph Insertion) subtable. */
  7. /* */
  8. /* Copyright 2005 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 "gxvmort.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_gxvmort
  34. /*
  35. * mort subtable type5 (Contextual Glyph Insertion)
  36. * has the format of StateTable with insertion-glyph-list,
  37. * but without name. The offset is given by glyphOffset in
  38. * entryTable. There is no table location declaration
  39. * like xxxTable.
  40. */
  41. typedef struct GXV_mort_subtable_type5_StateOptRec_
  42. {
  43. FT_UShort classTable;
  44. FT_UShort stateArray;
  45. FT_UShort entryTable;
  46. #define GXV_MORT_SUBTABLE_TYPE5_HEADER_SIZE GXV_STATETABLE_HEADER_SIZE
  47. FT_UShort* classTable_length_p;
  48. FT_UShort* stateArray_length_p;
  49. FT_UShort* entryTable_length_p;
  50. } GXV_mort_subtable_type5_StateOptRec,
  51. *GXV_mort_subtable_type5_StateOptRecData;
  52. FT_LOCAL_DEF( void )
  53. gxv_mort_subtable_type5_subtable_setup( FT_UShort table_size,
  54. FT_UShort classTable,
  55. FT_UShort stateArray,
  56. FT_UShort entryTable,
  57. FT_UShort* classTable_length_p,
  58. FT_UShort* stateArray_length_p,
  59. FT_UShort* entryTable_length_p,
  60. GXV_Validator valid )
  61. {
  62. GXV_mort_subtable_type5_StateOptRecData optdata =
  63. (GXV_mort_subtable_type5_StateOptRecData)valid->statetable.optdata;
  64. gxv_StateTable_subtable_setup( table_size,
  65. classTable,
  66. stateArray,
  67. entryTable,
  68. classTable_length_p,
  69. stateArray_length_p,
  70. entryTable_length_p,
  71. valid );
  72. optdata->classTable = classTable;
  73. optdata->stateArray = stateArray;
  74. optdata->entryTable = entryTable;
  75. optdata->classTable_length_p = classTable_length_p;
  76. optdata->stateArray_length_p = stateArray_length_p;
  77. optdata->entryTable_length_p = entryTable_length_p;
  78. }
  79. static void
  80. gxv_mort_subtable_type5_InsertList_validate( FT_UShort offset,
  81. FT_UShort count,
  82. FT_Bytes table,
  83. FT_Bytes limit,
  84. GXV_Validator valid )
  85. {
  86. /*
  87. * We don't know the range of insertion-glyph-list.
  88. * Set range by whole of state table.
  89. */
  90. FT_Bytes p = table + offset;
  91. GXV_mort_subtable_type5_StateOptRecData optdata =
  92. (GXV_mort_subtable_type5_StateOptRecData)valid->statetable.optdata;
  93. if ( optdata->classTable < offset &&
  94. offset < optdata->classTable + *(optdata->classTable_length_p) )
  95. GXV_TRACE(( " offset runs into ClassTable" ));
  96. if ( optdata->stateArray < offset &&
  97. offset < optdata->stateArray + *(optdata->stateArray_length_p) )
  98. GXV_TRACE(( " offset runs into StateArray" ));
  99. if ( optdata->entryTable < offset &&
  100. offset < optdata->entryTable + *(optdata->entryTable_length_p) )
  101. GXV_TRACE(( " offset runs into EntryTable" ));
  102. #ifndef GXV_LOAD_TRACE_VARS
  103. GXV_LIMIT_CHECK( count * 2 );
  104. #else
  105. while ( p < table + offset + ( count * 2 ) )
  106. {
  107. FT_UShort insert_glyphID;
  108. GXV_LIMIT_CHECK( 2 );
  109. insert_glyphID = FT_NEXT_USHORT( p );
  110. GXV_TRACE(( " 0x%04x", insert_glyphID ));
  111. }
  112. GXV_TRACE(( "\n" ));
  113. #endif
  114. }
  115. static void
  116. gxv_mort_subtable_type5_entry_validate(
  117. FT_Byte state,
  118. FT_UShort flags,
  119. GXV_StateTable_GlyphOffsetCPtr glyphOffset,
  120. FT_Bytes table,
  121. FT_Bytes limit,
  122. GXV_Validator valid )
  123. {
  124. #ifdef GXV_LOAD_UNUSED_VARS
  125. FT_Bool setMark;
  126. FT_Bool dontAdvance;
  127. FT_Bool currentIsKashidaLike;
  128. FT_Bool markedIsKashidaLike;
  129. FT_Bool currentInsertBefore;
  130. FT_Bool markedInsertBefore;
  131. #endif
  132. FT_Byte currentInsertCount;
  133. FT_Byte markedInsertCount;
  134. FT_UShort currentInsertList;
  135. FT_UShort markedInsertList;
  136. FT_UNUSED( state );
  137. #ifdef GXV_LOAD_UNUSED_VARS
  138. setMark = FT_BOOL( ( flags >> 15 ) & 1 );
  139. dontAdvance = FT_BOOL( ( flags >> 14 ) & 1 );
  140. currentIsKashidaLike = FT_BOOL( ( flags >> 13 ) & 1 );
  141. markedIsKashidaLike = FT_BOOL( ( flags >> 12 ) & 1 );
  142. currentInsertBefore = FT_BOOL( ( flags >> 11 ) & 1 );
  143. markedInsertBefore = FT_BOOL( ( flags >> 10 ) & 1 );
  144. #endif
  145. currentInsertCount = (FT_Byte)( ( flags >> 5 ) & 0x1F );
  146. markedInsertCount = (FT_Byte)( flags & 0x001F );
  147. currentInsertList = (FT_UShort)( glyphOffset->ul >> 16 );
  148. markedInsertList = (FT_UShort)( glyphOffset->ul );
  149. if ( 0 != currentInsertList && 0 != currentInsertCount )
  150. {
  151. gxv_mort_subtable_type5_InsertList_validate( currentInsertList,
  152. currentInsertCount,
  153. table,
  154. limit,
  155. valid );
  156. }
  157. if ( 0 != markedInsertList && 0 != markedInsertCount )
  158. {
  159. gxv_mort_subtable_type5_InsertList_validate( markedInsertList,
  160. markedInsertCount,
  161. table,
  162. limit,
  163. valid );
  164. }
  165. }
  166. FT_LOCAL_DEF( void )
  167. gxv_mort_subtable_type5_validate( FT_Bytes table,
  168. FT_Bytes limit,
  169. GXV_Validator valid )
  170. {
  171. FT_Bytes p = table;
  172. GXV_mort_subtable_type5_StateOptRec et_rec;
  173. GXV_mort_subtable_type5_StateOptRecData et = &et_rec;
  174. GXV_NAME_ENTER( "mort chain subtable type5 (Glyph Insertion)" );
  175. GXV_LIMIT_CHECK( GXV_MORT_SUBTABLE_TYPE5_HEADER_SIZE );
  176. valid->statetable.optdata =
  177. et;
  178. valid->statetable.optdata_load_func =
  179. NULL;
  180. valid->statetable.subtable_setup_func =
  181. gxv_mort_subtable_type5_subtable_setup;
  182. valid->statetable.entry_glyphoffset_fmt =
  183. GXV_GLYPHOFFSET_ULONG;
  184. valid->statetable.entry_validate_func =
  185. gxv_mort_subtable_type5_entry_validate;
  186. gxv_StateTable_validate( p, limit, valid );
  187. GXV_EXIT;
  188. }
  189. /* END */