/src/freetype/src/otvalid/otvjstf.c

https://bitbucket.org/cabalistic/ogredeps/ · C · 258 lines · 158 code · 64 blank · 36 comment · 18 complexity · ab964cdc3c9211a50cddc563c7f3a2a0 MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* otvjstf.c */
  4. /* */
  5. /* OpenType JSTF table validation (body). */
  6. /* */
  7. /* Copyright 2004, 2007 by */
  8. /* David Turner, Robert Wilhelm, and Werner Lemberg. */
  9. /* */
  10. /* This file is part of the FreeType project, and may only be used, */
  11. /* modified, and distributed under the terms of the FreeType project */
  12. /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
  13. /* this file you indicate that you have read the license and */
  14. /* understand and accept it fully. */
  15. /* */
  16. /***************************************************************************/
  17. #include "otvalid.h"
  18. #include "otvcommn.h"
  19. #include "otvgpos.h"
  20. /*************************************************************************/
  21. /* */
  22. /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
  23. /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
  24. /* messages during execution. */
  25. /* */
  26. #undef FT_COMPONENT
  27. #define FT_COMPONENT trace_otvjstf
  28. #define JstfPriorityFunc otv_JstfPriority_validate
  29. #define JstfLookupFunc otv_GPOS_subtable_validate
  30. /* uses valid->extra1 (GSUB lookup count) */
  31. /* uses valid->extra2 (GPOS lookup count) */
  32. /* sets valid->extra1 (counter) */
  33. static void
  34. otv_JstfPriority_validate( FT_Bytes table,
  35. OTV_Validator valid )
  36. {
  37. FT_Bytes p = table;
  38. FT_UInt table_size;
  39. FT_UInt gsub_lookup_count, gpos_lookup_count;
  40. OTV_OPTIONAL_TABLE( ShrinkageEnableGSUB );
  41. OTV_OPTIONAL_TABLE( ShrinkageDisableGSUB );
  42. OTV_OPTIONAL_TABLE( ShrinkageEnableGPOS );
  43. OTV_OPTIONAL_TABLE( ShrinkageDisableGPOS );
  44. OTV_OPTIONAL_TABLE( ExtensionEnableGSUB );
  45. OTV_OPTIONAL_TABLE( ExtensionDisableGSUB );
  46. OTV_OPTIONAL_TABLE( ExtensionEnableGPOS );
  47. OTV_OPTIONAL_TABLE( ExtensionDisableGPOS );
  48. OTV_OPTIONAL_TABLE( ShrinkageJstfMax );
  49. OTV_OPTIONAL_TABLE( ExtensionJstfMax );
  50. OTV_ENTER;
  51. OTV_TRACE(( "JstfPriority table\n" ));
  52. OTV_LIMIT_CHECK( 20 );
  53. gsub_lookup_count = valid->extra1;
  54. gpos_lookup_count = valid->extra2;
  55. table_size = 20;
  56. valid->extra1 = gsub_lookup_count;
  57. OTV_OPTIONAL_OFFSET( ShrinkageEnableGSUB );
  58. OTV_SIZE_CHECK( ShrinkageEnableGSUB );
  59. if ( ShrinkageEnableGSUB )
  60. otv_x_ux( table + ShrinkageEnableGSUB, valid );
  61. OTV_OPTIONAL_OFFSET( ShrinkageDisableGSUB );
  62. OTV_SIZE_CHECK( ShrinkageDisableGSUB );
  63. if ( ShrinkageDisableGSUB )
  64. otv_x_ux( table + ShrinkageDisableGSUB, valid );
  65. valid->extra1 = gpos_lookup_count;
  66. OTV_OPTIONAL_OFFSET( ShrinkageEnableGPOS );
  67. OTV_SIZE_CHECK( ShrinkageEnableGPOS );
  68. if ( ShrinkageEnableGPOS )
  69. otv_x_ux( table + ShrinkageEnableGPOS, valid );
  70. OTV_OPTIONAL_OFFSET( ShrinkageDisableGPOS );
  71. OTV_SIZE_CHECK( ShrinkageDisableGPOS );
  72. if ( ShrinkageDisableGPOS )
  73. otv_x_ux( table + ShrinkageDisableGPOS, valid );
  74. OTV_OPTIONAL_OFFSET( ShrinkageJstfMax );
  75. OTV_SIZE_CHECK( ShrinkageJstfMax );
  76. if ( ShrinkageJstfMax )
  77. {
  78. /* XXX: check lookup types? */
  79. OTV_NEST2( JstfMax, JstfLookup );
  80. OTV_RUN( table + ShrinkageJstfMax, valid );
  81. }
  82. valid->extra1 = gsub_lookup_count;
  83. OTV_OPTIONAL_OFFSET( ExtensionEnableGSUB );
  84. OTV_SIZE_CHECK( ExtensionEnableGSUB );
  85. if ( ExtensionEnableGSUB )
  86. otv_x_ux( table + ExtensionEnableGSUB, valid );
  87. OTV_OPTIONAL_OFFSET( ExtensionDisableGSUB );
  88. OTV_SIZE_CHECK( ExtensionDisableGSUB );
  89. if ( ExtensionDisableGSUB )
  90. otv_x_ux( table + ExtensionDisableGSUB, valid );
  91. valid->extra1 = gpos_lookup_count;
  92. OTV_OPTIONAL_OFFSET( ExtensionEnableGPOS );
  93. OTV_SIZE_CHECK( ExtensionEnableGPOS );
  94. if ( ExtensionEnableGPOS )
  95. otv_x_ux( table + ExtensionEnableGPOS, valid );
  96. OTV_OPTIONAL_OFFSET( ExtensionDisableGPOS );
  97. OTV_SIZE_CHECK( ExtensionDisableGPOS );
  98. if ( ExtensionDisableGPOS )
  99. otv_x_ux( table + ExtensionDisableGPOS, valid );
  100. OTV_OPTIONAL_OFFSET( ExtensionJstfMax );
  101. OTV_SIZE_CHECK( ExtensionJstfMax );
  102. if ( ExtensionJstfMax )
  103. {
  104. /* XXX: check lookup types? */
  105. OTV_NEST2( JstfMax, JstfLookup );
  106. OTV_RUN( table + ExtensionJstfMax, valid );
  107. }
  108. valid->extra1 = gsub_lookup_count;
  109. valid->extra2 = gpos_lookup_count;
  110. OTV_EXIT;
  111. }
  112. /* sets valid->extra (glyph count) */
  113. /* sets valid->func1 (otv_JstfPriority_validate) */
  114. static void
  115. otv_JstfScript_validate( FT_Bytes table,
  116. OTV_Validator valid )
  117. {
  118. FT_Bytes p = table;
  119. FT_UInt table_size;
  120. FT_UInt JstfLangSysCount;
  121. OTV_OPTIONAL_TABLE( ExtGlyph );
  122. OTV_OPTIONAL_TABLE( DefJstfLangSys );
  123. OTV_NAME_ENTER( "JstfScript" );
  124. OTV_LIMIT_CHECK( 6 );
  125. OTV_OPTIONAL_OFFSET( ExtGlyph );
  126. OTV_OPTIONAL_OFFSET( DefJstfLangSys );
  127. JstfLangSysCount = FT_NEXT_USHORT( p );
  128. OTV_TRACE(( " (JstfLangSysCount = %d)\n", JstfLangSysCount ));
  129. table_size = JstfLangSysCount * 6 + 6;
  130. OTV_SIZE_CHECK( ExtGlyph );
  131. if ( ExtGlyph )
  132. {
  133. valid->extra1 = valid->glyph_count;
  134. OTV_NEST1( ExtenderGlyph );
  135. OTV_RUN( table + ExtGlyph, valid );
  136. }
  137. OTV_SIZE_CHECK( DefJstfLangSys );
  138. if ( DefJstfLangSys )
  139. {
  140. OTV_NEST2( JstfLangSys, JstfPriority );
  141. OTV_RUN( table + DefJstfLangSys, valid );
  142. }
  143. OTV_LIMIT_CHECK( 6 * JstfLangSysCount );
  144. /* JstfLangSysRecord */
  145. OTV_NEST2( JstfLangSys, JstfPriority );
  146. for ( ; JstfLangSysCount > 0; JstfLangSysCount-- )
  147. {
  148. p += 4; /* skip JstfLangSysTag */
  149. OTV_RUN( table + FT_NEXT_USHORT( p ), valid );
  150. }
  151. OTV_EXIT;
  152. }
  153. /* sets valid->extra1 (GSUB lookup count) */
  154. /* sets valid->extra2 (GPOS lookup count) */
  155. /* sets valid->glyph_count */
  156. FT_LOCAL_DEF( void )
  157. otv_JSTF_validate( FT_Bytes table,
  158. FT_Bytes gsub,
  159. FT_Bytes gpos,
  160. FT_UInt glyph_count,
  161. FT_Validator ftvalid )
  162. {
  163. OTV_ValidatorRec validrec;
  164. OTV_Validator valid = &validrec;
  165. FT_Bytes p = table;
  166. FT_UInt JstfScriptCount;
  167. valid->root = ftvalid;
  168. FT_TRACE3(( "validating JSTF table\n" ));
  169. OTV_INIT;
  170. OTV_LIMIT_CHECK( 6 );
  171. if ( FT_NEXT_ULONG( p ) != 0x10000UL ) /* Version */
  172. FT_INVALID_FORMAT;
  173. JstfScriptCount = FT_NEXT_USHORT( p );
  174. FT_TRACE3(( " (JstfScriptCount = %d)\n", JstfScriptCount ));
  175. OTV_LIMIT_CHECK( JstfScriptCount * 6 );
  176. if ( gsub )
  177. valid->extra1 = otv_GSUBGPOS_get_Lookup_count( gsub );
  178. else
  179. valid->extra1 = 0;
  180. if ( gpos )
  181. valid->extra2 = otv_GSUBGPOS_get_Lookup_count( gpos );
  182. else
  183. valid->extra2 = 0;
  184. valid->glyph_count = glyph_count;
  185. /* JstfScriptRecord */
  186. for ( ; JstfScriptCount > 0; JstfScriptCount-- )
  187. {
  188. p += 4; /* skip JstfScriptTag */
  189. /* JstfScript */
  190. otv_JstfScript_validate( table + FT_NEXT_USHORT( p ), valid );
  191. }
  192. FT_TRACE4(( "\n" ));
  193. }
  194. /* END */