/src/freetype/src/gxvalid/gxvmorx.c

https://bitbucket.org/cabalistic/ogredeps/ · C · 199 lines · 118 code · 46 blank · 35 comment · 8 complexity · d917a49fd571a820a07ff145957a7d9f MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* gxvmorx.c */
  4. /* */
  5. /* TrueTypeGX/AAT morx table validation (body). */
  6. /* */
  7. /* Copyright 2005, 2008 by */
  8. /* 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. static void
  35. gxv_morx_subtables_validate( FT_Bytes table,
  36. FT_Bytes limit,
  37. FT_UShort nSubtables,
  38. GXV_Validator valid )
  39. {
  40. FT_Bytes p = table;
  41. GXV_Validate_Func fmt_funcs_table[] =
  42. {
  43. gxv_morx_subtable_type0_validate, /* 0 */
  44. gxv_morx_subtable_type1_validate, /* 1 */
  45. gxv_morx_subtable_type2_validate, /* 2 */
  46. NULL, /* 3 */
  47. gxv_morx_subtable_type4_validate, /* 4 */
  48. gxv_morx_subtable_type5_validate, /* 5 */
  49. };
  50. GXV_Validate_Func func;
  51. FT_UShort i;
  52. GXV_NAME_ENTER( "subtables in a chain" );
  53. for ( i = 0; i < nSubtables; i++ )
  54. {
  55. FT_ULong length;
  56. FT_ULong coverage;
  57. #ifdef GXV_LOAD_UNUSED_VARS
  58. FT_ULong subFeatureFlags;
  59. #endif
  60. FT_ULong type;
  61. FT_ULong rest;
  62. GXV_LIMIT_CHECK( 4 + 4 + 4 );
  63. length = FT_NEXT_ULONG( p );
  64. coverage = FT_NEXT_ULONG( p );
  65. #ifdef GXV_LOAD_UNUSED_VARS
  66. subFeatureFlags = FT_NEXT_ULONG( p );
  67. #else
  68. p += 4;
  69. #endif
  70. GXV_TRACE(( "validating chain subtable %d/%d (%d bytes)\n",
  71. i + 1, nSubtables, length ));
  72. type = coverage & 0x0007;
  73. rest = length - ( 4 + 4 + 4 );
  74. GXV_LIMIT_CHECK( rest );
  75. /* morx coverage consists of mort_coverage & 16bit padding */
  76. gxv_mort_coverage_validate( (FT_UShort)( ( coverage >> 16 ) | coverage ),
  77. valid );
  78. if ( type > 5 )
  79. FT_INVALID_FORMAT;
  80. func = fmt_funcs_table[type];
  81. if ( func == NULL )
  82. GXV_TRACE(( "morx type %d is reserved\n", type ));
  83. func( p, p + rest, valid );
  84. /* TODO: subFeatureFlags should be unique in a table? */
  85. p += rest;
  86. }
  87. valid->subtable_length = p - table;
  88. GXV_EXIT;
  89. }
  90. static void
  91. gxv_morx_chain_validate( FT_Bytes table,
  92. FT_Bytes limit,
  93. GXV_Validator valid )
  94. {
  95. FT_Bytes p = table;
  96. #ifdef GXV_LOAD_UNUSED_VARS
  97. FT_ULong defaultFlags;
  98. #endif
  99. FT_ULong chainLength;
  100. FT_ULong nFeatureFlags;
  101. FT_ULong nSubtables;
  102. GXV_NAME_ENTER( "morx chain header" );
  103. GXV_LIMIT_CHECK( 4 + 4 + 4 + 4 );
  104. #ifdef GXV_LOAD_UNUSED_VARS
  105. defaultFlags = FT_NEXT_ULONG( p );
  106. #else
  107. p += 4;
  108. #endif
  109. chainLength = FT_NEXT_ULONG( p );
  110. nFeatureFlags = FT_NEXT_ULONG( p );
  111. nSubtables = FT_NEXT_ULONG( p );
  112. /* feature-array of morx is same with that of mort */
  113. gxv_mort_featurearray_validate( p, limit, nFeatureFlags, valid );
  114. p += valid->subtable_length;
  115. if ( nSubtables >= 0x10000L )
  116. FT_INVALID_DATA;
  117. gxv_morx_subtables_validate( p, table + chainLength,
  118. (FT_UShort)nSubtables, valid );
  119. valid->subtable_length = chainLength;
  120. /* TODO: defaultFlags should be compared with the flags in tables */
  121. GXV_EXIT;
  122. }
  123. FT_LOCAL_DEF( void )
  124. gxv_morx_validate( FT_Bytes table,
  125. FT_Face face,
  126. FT_Validator ftvalid )
  127. {
  128. GXV_ValidatorRec validrec;
  129. GXV_Validator valid = &validrec;
  130. FT_Bytes p = table;
  131. FT_Bytes limit = 0;
  132. FT_ULong version;
  133. FT_ULong nChains;
  134. FT_ULong i;
  135. valid->root = ftvalid;
  136. valid->face = face;
  137. FT_TRACE3(( "validating `morx' table\n" ));
  138. GXV_INIT;
  139. GXV_LIMIT_CHECK( 4 + 4 );
  140. version = FT_NEXT_ULONG( p );
  141. nChains = FT_NEXT_ULONG( p );
  142. if ( version != 0x00020000UL )
  143. FT_INVALID_FORMAT;
  144. for ( i = 0; i < nChains; i++ )
  145. {
  146. GXV_TRACE(( "validating chain %d/%d\n", i + 1, nChains ));
  147. GXV_32BIT_ALIGNMENT_VALIDATE( p - table );
  148. gxv_morx_chain_validate( p, limit, valid );
  149. p += valid->subtable_length;
  150. }
  151. FT_TRACE4(( "\n" ));
  152. }
  153. /* END */