ftgxval.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /****************************************************************************
  2. *
  3. * ftgxval.h
  4. *
  5. * FreeType API for validating TrueTypeGX/AAT tables (specification).
  6. *
  7. * Copyright (C) 2004-2023 by
  8. * Masatake YAMATO, Redhat 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. #ifndef FTGXVAL_H_
  26. #define FTGXVAL_H_
  27. #include <freetype/freetype.h>
  28. #ifdef FREETYPE_H
  29. #error "freetype.h of FreeType 1 has been loaded!"
  30. #error "Please fix the directory search order for header files"
  31. #error "so that freetype.h of FreeType 2 is found first."
  32. #endif
  33. FT_BEGIN_HEADER
  34. /**************************************************************************
  35. *
  36. * @section:
  37. * gx_validation
  38. *
  39. * @title:
  40. * TrueTypeGX/AAT Validation
  41. *
  42. * @abstract:
  43. * An API to validate TrueTypeGX/AAT tables.
  44. *
  45. * @description:
  46. * This section contains the declaration of functions to validate some
  47. * TrueTypeGX tables (feat, mort, morx, bsln, just, kern, opbd, trak,
  48. * prop, lcar).
  49. *
  50. * @order:
  51. * FT_TrueTypeGX_Validate
  52. * FT_TrueTypeGX_Free
  53. *
  54. * FT_ClassicKern_Validate
  55. * FT_ClassicKern_Free
  56. *
  57. * FT_VALIDATE_GX_LENGTH
  58. * FT_VALIDATE_GXXXX
  59. * FT_VALIDATE_CKERNXXX
  60. *
  61. */
  62. /**************************************************************************
  63. *
  64. *
  65. * Warning: Use `FT_VALIDATE_XXX` to validate a table.
  66. * Following definitions are for gxvalid developers.
  67. *
  68. *
  69. */
  70. #define FT_VALIDATE_feat_INDEX 0
  71. #define FT_VALIDATE_mort_INDEX 1
  72. #define FT_VALIDATE_morx_INDEX 2
  73. #define FT_VALIDATE_bsln_INDEX 3
  74. #define FT_VALIDATE_just_INDEX 4
  75. #define FT_VALIDATE_kern_INDEX 5
  76. #define FT_VALIDATE_opbd_INDEX 6
  77. #define FT_VALIDATE_trak_INDEX 7
  78. #define FT_VALIDATE_prop_INDEX 8
  79. #define FT_VALIDATE_lcar_INDEX 9
  80. #define FT_VALIDATE_GX_LAST_INDEX FT_VALIDATE_lcar_INDEX
  81. /**************************************************************************
  82. *
  83. * @macro:
  84. * FT_VALIDATE_GX_LENGTH
  85. *
  86. * @description:
  87. * The number of tables checked in this module. Use it as a parameter
  88. * for the `table-length` argument of function @FT_TrueTypeGX_Validate.
  89. */
  90. #define FT_VALIDATE_GX_LENGTH ( FT_VALIDATE_GX_LAST_INDEX + 1 )
  91. /* */
  92. /* Up to 0x1000 is used by otvalid.
  93. Ox2xxx is reserved for feature OT extension. */
  94. #define FT_VALIDATE_GX_START 0x4000
  95. #define FT_VALIDATE_GX_BITFIELD( tag ) \
  96. ( FT_VALIDATE_GX_START << FT_VALIDATE_##tag##_INDEX )
  97. /**************************************************************************
  98. *
  99. * @enum:
  100. * FT_VALIDATE_GXXXX
  101. *
  102. * @description:
  103. * A list of bit-field constants used with @FT_TrueTypeGX_Validate to
  104. * indicate which TrueTypeGX/AAT Type tables should be validated.
  105. *
  106. * @values:
  107. * FT_VALIDATE_feat ::
  108. * Validate 'feat' table.
  109. *
  110. * FT_VALIDATE_mort ::
  111. * Validate 'mort' table.
  112. *
  113. * FT_VALIDATE_morx ::
  114. * Validate 'morx' table.
  115. *
  116. * FT_VALIDATE_bsln ::
  117. * Validate 'bsln' table.
  118. *
  119. * FT_VALIDATE_just ::
  120. * Validate 'just' table.
  121. *
  122. * FT_VALIDATE_kern ::
  123. * Validate 'kern' table.
  124. *
  125. * FT_VALIDATE_opbd ::
  126. * Validate 'opbd' table.
  127. *
  128. * FT_VALIDATE_trak ::
  129. * Validate 'trak' table.
  130. *
  131. * FT_VALIDATE_prop ::
  132. * Validate 'prop' table.
  133. *
  134. * FT_VALIDATE_lcar ::
  135. * Validate 'lcar' table.
  136. *
  137. * FT_VALIDATE_GX ::
  138. * Validate all TrueTypeGX tables (feat, mort, morx, bsln, just, kern,
  139. * opbd, trak, prop and lcar).
  140. *
  141. */
  142. #define FT_VALIDATE_feat FT_VALIDATE_GX_BITFIELD( feat )
  143. #define FT_VALIDATE_mort FT_VALIDATE_GX_BITFIELD( mort )
  144. #define FT_VALIDATE_morx FT_VALIDATE_GX_BITFIELD( morx )
  145. #define FT_VALIDATE_bsln FT_VALIDATE_GX_BITFIELD( bsln )
  146. #define FT_VALIDATE_just FT_VALIDATE_GX_BITFIELD( just )
  147. #define FT_VALIDATE_kern FT_VALIDATE_GX_BITFIELD( kern )
  148. #define FT_VALIDATE_opbd FT_VALIDATE_GX_BITFIELD( opbd )
  149. #define FT_VALIDATE_trak FT_VALIDATE_GX_BITFIELD( trak )
  150. #define FT_VALIDATE_prop FT_VALIDATE_GX_BITFIELD( prop )
  151. #define FT_VALIDATE_lcar FT_VALIDATE_GX_BITFIELD( lcar )
  152. #define FT_VALIDATE_GX ( FT_VALIDATE_feat | \
  153. FT_VALIDATE_mort | \
  154. FT_VALIDATE_morx | \
  155. FT_VALIDATE_bsln | \
  156. FT_VALIDATE_just | \
  157. FT_VALIDATE_kern | \
  158. FT_VALIDATE_opbd | \
  159. FT_VALIDATE_trak | \
  160. FT_VALIDATE_prop | \
  161. FT_VALIDATE_lcar )
  162. /**************************************************************************
  163. *
  164. * @function:
  165. * FT_TrueTypeGX_Validate
  166. *
  167. * @description:
  168. * Validate various TrueTypeGX tables to assure that all offsets and
  169. * indices are valid. The idea is that a higher-level library that
  170. * actually does the text layout can access those tables without error
  171. * checking (which can be quite time consuming).
  172. *
  173. * @input:
  174. * face ::
  175. * A handle to the input face.
  176. *
  177. * validation_flags ::
  178. * A bit field that specifies the tables to be validated. See
  179. * @FT_VALIDATE_GXXXX for possible values.
  180. *
  181. * table_length ::
  182. * The size of the `tables` array. Normally, @FT_VALIDATE_GX_LENGTH
  183. * should be passed.
  184. *
  185. * @output:
  186. * tables ::
  187. * The array where all validated sfnt tables are stored. The array
  188. * itself must be allocated by a client.
  189. *
  190. * @return:
  191. * FreeType error code. 0~means success.
  192. *
  193. * @note:
  194. * This function only works with TrueTypeGX fonts, returning an error
  195. * otherwise.
  196. *
  197. * After use, the application should deallocate the buffers pointed to by
  198. * each `tables` element, by calling @FT_TrueTypeGX_Free. A `NULL` value
  199. * indicates that the table either doesn't exist in the font, the
  200. * application hasn't asked for validation, or the validator doesn't have
  201. * the ability to validate the sfnt table.
  202. */
  203. FT_EXPORT( FT_Error )
  204. FT_TrueTypeGX_Validate( FT_Face face,
  205. FT_UInt validation_flags,
  206. FT_Bytes tables[FT_VALIDATE_GX_LENGTH],
  207. FT_UInt table_length );
  208. /**************************************************************************
  209. *
  210. * @function:
  211. * FT_TrueTypeGX_Free
  212. *
  213. * @description:
  214. * Free the buffer allocated by TrueTypeGX validator.
  215. *
  216. * @input:
  217. * face ::
  218. * A handle to the input face.
  219. *
  220. * table ::
  221. * The pointer to the buffer allocated by @FT_TrueTypeGX_Validate.
  222. *
  223. * @note:
  224. * This function must be used to free the buffer allocated by
  225. * @FT_TrueTypeGX_Validate only.
  226. */
  227. FT_EXPORT( void )
  228. FT_TrueTypeGX_Free( FT_Face face,
  229. FT_Bytes table );
  230. /**************************************************************************
  231. *
  232. * @enum:
  233. * FT_VALIDATE_CKERNXXX
  234. *
  235. * @description:
  236. * A list of bit-field constants used with @FT_ClassicKern_Validate to
  237. * indicate the classic kern dialect or dialects. If the selected type
  238. * doesn't fit, @FT_ClassicKern_Validate regards the table as invalid.
  239. *
  240. * @values:
  241. * FT_VALIDATE_MS ::
  242. * Handle the 'kern' table as a classic Microsoft kern table.
  243. *
  244. * FT_VALIDATE_APPLE ::
  245. * Handle the 'kern' table as a classic Apple kern table.
  246. *
  247. * FT_VALIDATE_CKERN ::
  248. * Handle the 'kern' as either classic Apple or Microsoft kern table.
  249. */
  250. #define FT_VALIDATE_MS ( FT_VALIDATE_GX_START << 0 )
  251. #define FT_VALIDATE_APPLE ( FT_VALIDATE_GX_START << 1 )
  252. #define FT_VALIDATE_CKERN ( FT_VALIDATE_MS | FT_VALIDATE_APPLE )
  253. /**************************************************************************
  254. *
  255. * @function:
  256. * FT_ClassicKern_Validate
  257. *
  258. * @description:
  259. * Validate classic (16-bit format) kern table to assure that the
  260. * offsets and indices are valid. The idea is that a higher-level
  261. * library that actually does the text layout can access those tables
  262. * without error checking (which can be quite time consuming).
  263. *
  264. * The 'kern' table validator in @FT_TrueTypeGX_Validate deals with both
  265. * the new 32-bit format and the classic 16-bit format, while
  266. * FT_ClassicKern_Validate only supports the classic 16-bit format.
  267. *
  268. * @input:
  269. * face ::
  270. * A handle to the input face.
  271. *
  272. * validation_flags ::
  273. * A bit field that specifies the dialect to be validated. See
  274. * @FT_VALIDATE_CKERNXXX for possible values.
  275. *
  276. * @output:
  277. * ckern_table ::
  278. * A pointer to the kern table.
  279. *
  280. * @return:
  281. * FreeType error code. 0~means success.
  282. *
  283. * @note:
  284. * After use, the application should deallocate the buffers pointed to by
  285. * `ckern_table`, by calling @FT_ClassicKern_Free. A `NULL` value
  286. * indicates that the table doesn't exist in the font.
  287. */
  288. FT_EXPORT( FT_Error )
  289. FT_ClassicKern_Validate( FT_Face face,
  290. FT_UInt validation_flags,
  291. FT_Bytes *ckern_table );
  292. /**************************************************************************
  293. *
  294. * @function:
  295. * FT_ClassicKern_Free
  296. *
  297. * @description:
  298. * Free the buffer allocated by classic Kern validator.
  299. *
  300. * @input:
  301. * face ::
  302. * A handle to the input face.
  303. *
  304. * table ::
  305. * The pointer to the buffer that is allocated by
  306. * @FT_ClassicKern_Validate.
  307. *
  308. * @note:
  309. * This function must be used to free the buffer allocated by
  310. * @FT_ClassicKern_Validate only.
  311. */
  312. FT_EXPORT( void )
  313. FT_ClassicKern_Free( FT_Face face,
  314. FT_Bytes table );
  315. /* */
  316. FT_END_HEADER
  317. #endif /* FTGXVAL_H_ */
  318. /* END */