/src/freetype/src/gxvalid/gxvmorx5.c

https://bitbucket.org/cabalistic/ogredeps/ · C · 225 lines · 136 code · 50 blank · 39 comment · 7 complexity · 064e005310b763b5a02d9e3910b5cdc0 MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* gxvmorx5.c */
  4. /* */
  5. /* TrueTypeGX/AAT morx table validation */
  6. /* body for type5 (Contextual Glyph Insertion) 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. /*
  35. * `morx' subtable type5 (Contextual Glyph Insertion)
  36. * has format of a StateTable with insertion-glyph-list
  37. * without name. However, the 32bit offset from the head
  38. * of subtable to the i-g-l is given after `entryTable',
  39. * without variable name specification (the existence of
  40. * this offset to the table is different from mort type5).
  41. */
  42. typedef struct GXV_morx_subtable_type5_StateOptRec_
  43. {
  44. FT_ULong insertionGlyphList;
  45. FT_ULong insertionGlyphList_length;
  46. } GXV_morx_subtable_type5_StateOptRec,
  47. *GXV_morx_subtable_type5_StateOptRecData;
  48. #define GXV_MORX_SUBTABLE_TYPE5_HEADER_SIZE \
  49. ( GXV_STATETABLE_HEADER_SIZE + 4 )
  50. static void
  51. gxv_morx_subtable_type5_insertionGlyphList_load( FT_Bytes table,
  52. FT_Bytes limit,
  53. GXV_Validator valid )
  54. {
  55. FT_Bytes p = table;
  56. GXV_morx_subtable_type5_StateOptRecData optdata =
  57. (GXV_morx_subtable_type5_StateOptRecData)valid->xstatetable.optdata;
  58. GXV_LIMIT_CHECK( 4 );
  59. optdata->insertionGlyphList = FT_NEXT_ULONG( p );
  60. }
  61. static void
  62. gxv_morx_subtable_type5_subtable_setup( FT_ULong table_size,
  63. FT_ULong classTable,
  64. FT_ULong stateArray,
  65. FT_ULong entryTable,
  66. FT_ULong* classTable_length_p,
  67. FT_ULong* stateArray_length_p,
  68. FT_ULong* entryTable_length_p,
  69. GXV_Validator valid )
  70. {
  71. FT_ULong o[4];
  72. FT_ULong* l[4];
  73. FT_ULong buff[5];
  74. GXV_morx_subtable_type5_StateOptRecData optdata =
  75. (GXV_morx_subtable_type5_StateOptRecData)valid->xstatetable.optdata;
  76. o[0] = classTable;
  77. o[1] = stateArray;
  78. o[2] = entryTable;
  79. o[3] = optdata->insertionGlyphList;
  80. l[0] = classTable_length_p;
  81. l[1] = stateArray_length_p;
  82. l[2] = entryTable_length_p;
  83. l[3] = &(optdata->insertionGlyphList_length);
  84. gxv_set_length_by_ulong_offset( o, l, buff, 4, table_size, valid );
  85. }
  86. static void
  87. gxv_morx_subtable_type5_InsertList_validate( FT_UShort table_index,
  88. FT_UShort count,
  89. FT_Bytes table,
  90. FT_Bytes limit,
  91. GXV_Validator valid )
  92. {
  93. FT_Bytes p = table + table_index * 2;
  94. #ifndef GXV_LOAD_TRACE_VARS
  95. GXV_LIMIT_CHECK( count * 2 );
  96. #else
  97. while ( p < table + count * 2 + table_index * 2 )
  98. {
  99. FT_UShort insert_glyphID;
  100. GXV_LIMIT_CHECK( 2 );
  101. insert_glyphID = FT_NEXT_USHORT( p );
  102. GXV_TRACE(( " 0x%04x", insert_glyphID ));
  103. }
  104. GXV_TRACE(( "\n" ));
  105. #endif
  106. }
  107. static void
  108. gxv_morx_subtable_type5_entry_validate(
  109. FT_UShort state,
  110. FT_UShort flags,
  111. GXV_StateTable_GlyphOffsetCPtr glyphOffset_p,
  112. FT_Bytes table,
  113. FT_Bytes limit,
  114. GXV_Validator valid )
  115. {
  116. #ifdef GXV_LOAD_UNUSED_VARS
  117. FT_Bool setMark;
  118. FT_Bool dontAdvance;
  119. FT_Bool currentIsKashidaLike;
  120. FT_Bool markedIsKashidaLike;
  121. FT_Bool currentInsertBefore;
  122. FT_Bool markedInsertBefore;
  123. #endif
  124. FT_Byte currentInsertCount;
  125. FT_Byte markedInsertCount;
  126. FT_Byte currentInsertList;
  127. FT_UShort markedInsertList;
  128. FT_UNUSED( state );
  129. #ifdef GXV_LOAD_UNUSED_VARS
  130. setMark = FT_BOOL( ( flags >> 15 ) & 1 );
  131. dontAdvance = FT_BOOL( ( flags >> 14 ) & 1 );
  132. currentIsKashidaLike = FT_BOOL( ( flags >> 13 ) & 1 );
  133. markedIsKashidaLike = FT_BOOL( ( flags >> 12 ) & 1 );
  134. currentInsertBefore = FT_BOOL( ( flags >> 11 ) & 1 );
  135. markedInsertBefore = FT_BOOL( ( flags >> 10 ) & 1 );
  136. #endif
  137. currentInsertCount = (FT_Byte)( ( flags >> 5 ) & 0x1F );
  138. markedInsertCount = (FT_Byte)( flags & 0x001F );
  139. currentInsertList = (FT_Byte) ( glyphOffset_p->ul >> 16 );
  140. markedInsertList = (FT_UShort)( glyphOffset_p->ul );
  141. if ( currentInsertList && 0 != currentInsertCount )
  142. gxv_morx_subtable_type5_InsertList_validate( currentInsertList,
  143. currentInsertCount,
  144. table, limit,
  145. valid );
  146. if ( markedInsertList && 0 != markedInsertCount )
  147. gxv_morx_subtable_type5_InsertList_validate( markedInsertList,
  148. markedInsertCount,
  149. table, limit,
  150. valid );
  151. }
  152. FT_LOCAL_DEF( void )
  153. gxv_morx_subtable_type5_validate( FT_Bytes table,
  154. FT_Bytes limit,
  155. GXV_Validator valid )
  156. {
  157. FT_Bytes p = table;
  158. GXV_morx_subtable_type5_StateOptRec et_rec;
  159. GXV_morx_subtable_type5_StateOptRecData et = &et_rec;
  160. GXV_NAME_ENTER( "morx chain subtable type5 (Glyph Insertion)" );
  161. GXV_LIMIT_CHECK( GXV_MORX_SUBTABLE_TYPE5_HEADER_SIZE );
  162. valid->xstatetable.optdata =
  163. et;
  164. valid->xstatetable.optdata_load_func =
  165. gxv_morx_subtable_type5_insertionGlyphList_load;
  166. valid->xstatetable.subtable_setup_func =
  167. gxv_morx_subtable_type5_subtable_setup;
  168. valid->xstatetable.entry_glyphoffset_fmt =
  169. GXV_GLYPHOFFSET_ULONG;
  170. valid->xstatetable.entry_validate_func =
  171. gxv_morx_subtable_type5_entry_validate;
  172. gxv_XStateTable_validate( p, limit, valid );
  173. GXV_EXIT;
  174. }
  175. /* END */