ftincrem.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. /****************************************************************************
  2. *
  3. * ftincrem.h
  4. *
  5. * FreeType incremental loading (specification).
  6. *
  7. * Copyright (C) 2002-2023 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. #ifndef FTINCREM_H_
  18. #define FTINCREM_H_
  19. #include <freetype/freetype.h>
  20. #include <freetype/ftparams.h>
  21. #ifdef FREETYPE_H
  22. #error "freetype.h of FreeType 1 has been loaded!"
  23. #error "Please fix the directory search order for header files"
  24. #error "so that freetype.h of FreeType 2 is found first."
  25. #endif
  26. FT_BEGIN_HEADER
  27. /**************************************************************************
  28. *
  29. * @section:
  30. * incremental
  31. *
  32. * @title:
  33. * Incremental Loading
  34. *
  35. * @abstract:
  36. * Custom Glyph Loading.
  37. *
  38. * @description:
  39. * This section contains various functions used to perform so-called
  40. * 'incremental' glyph loading. This is a mode where all glyphs loaded
  41. * from a given @FT_Face are provided by the client application.
  42. *
  43. * Apart from that, all other tables are loaded normally from the font
  44. * file. This mode is useful when FreeType is used within another
  45. * engine, e.g., a PostScript Imaging Processor.
  46. *
  47. * To enable this mode, you must use @FT_Open_Face, passing an
  48. * @FT_Parameter with the @FT_PARAM_TAG_INCREMENTAL tag and an
  49. * @FT_Incremental_Interface value. See the comments for
  50. * @FT_Incremental_InterfaceRec for an example.
  51. *
  52. */
  53. /**************************************************************************
  54. *
  55. * @type:
  56. * FT_Incremental
  57. *
  58. * @description:
  59. * An opaque type describing a user-provided object used to implement
  60. * 'incremental' glyph loading within FreeType. This is used to support
  61. * embedded fonts in certain environments (e.g., PostScript
  62. * interpreters), where the glyph data isn't in the font file, or must be
  63. * overridden by different values.
  64. *
  65. * @note:
  66. * It is up to client applications to create and implement
  67. * @FT_Incremental objects, as long as they provide implementations for
  68. * the methods @FT_Incremental_GetGlyphDataFunc,
  69. * @FT_Incremental_FreeGlyphDataFunc and
  70. * @FT_Incremental_GetGlyphMetricsFunc.
  71. *
  72. * See the description of @FT_Incremental_InterfaceRec to understand how
  73. * to use incremental objects with FreeType.
  74. *
  75. */
  76. typedef struct FT_IncrementalRec_* FT_Incremental;
  77. /**************************************************************************
  78. *
  79. * @struct:
  80. * FT_Incremental_MetricsRec
  81. *
  82. * @description:
  83. * A small structure used to contain the basic glyph metrics returned by
  84. * the @FT_Incremental_GetGlyphMetricsFunc method.
  85. *
  86. * @fields:
  87. * bearing_x ::
  88. * Left bearing, in font units.
  89. *
  90. * bearing_y ::
  91. * Top bearing, in font units.
  92. *
  93. * advance ::
  94. * Horizontal component of glyph advance, in font units.
  95. *
  96. * advance_v ::
  97. * Vertical component of glyph advance, in font units.
  98. *
  99. * @note:
  100. * These correspond to horizontal or vertical metrics depending on the
  101. * value of the `vertical` argument to the function
  102. * @FT_Incremental_GetGlyphMetricsFunc.
  103. *
  104. */
  105. typedef struct FT_Incremental_MetricsRec_
  106. {
  107. FT_Long bearing_x;
  108. FT_Long bearing_y;
  109. FT_Long advance;
  110. FT_Long advance_v; /* since 2.3.12 */
  111. } FT_Incremental_MetricsRec;
  112. /**************************************************************************
  113. *
  114. * @struct:
  115. * FT_Incremental_Metrics
  116. *
  117. * @description:
  118. * A handle to an @FT_Incremental_MetricsRec structure.
  119. *
  120. */
  121. typedef struct FT_Incremental_MetricsRec_* FT_Incremental_Metrics;
  122. /**************************************************************************
  123. *
  124. * @type:
  125. * FT_Incremental_GetGlyphDataFunc
  126. *
  127. * @description:
  128. * A function called by FreeType to access a given glyph's data bytes
  129. * during @FT_Load_Glyph or @FT_Load_Char if incremental loading is
  130. * enabled.
  131. *
  132. * Note that the format of the glyph's data bytes depends on the font
  133. * file format. For TrueType, it must correspond to the raw bytes within
  134. * the 'glyf' table. For PostScript formats, it must correspond to the
  135. * **unencrypted** charstring bytes, without any `lenIV` header. It is
  136. * undefined for any other format.
  137. *
  138. * @input:
  139. * incremental ::
  140. * Handle to an opaque @FT_Incremental handle provided by the client
  141. * application.
  142. *
  143. * glyph_index ::
  144. * Index of relevant glyph.
  145. *
  146. * @output:
  147. * adata ::
  148. * A structure describing the returned glyph data bytes (which will be
  149. * accessed as a read-only byte block).
  150. *
  151. * @return:
  152. * FreeType error code. 0~means success.
  153. *
  154. * @note:
  155. * If this function returns successfully the method
  156. * @FT_Incremental_FreeGlyphDataFunc will be called later to release the
  157. * data bytes.
  158. *
  159. * Nested calls to @FT_Incremental_GetGlyphDataFunc can happen for
  160. * compound glyphs.
  161. *
  162. */
  163. typedef FT_Error
  164. (*FT_Incremental_GetGlyphDataFunc)( FT_Incremental incremental,
  165. FT_UInt glyph_index,
  166. FT_Data* adata );
  167. /**************************************************************************
  168. *
  169. * @type:
  170. * FT_Incremental_FreeGlyphDataFunc
  171. *
  172. * @description:
  173. * A function used to release the glyph data bytes returned by a
  174. * successful call to @FT_Incremental_GetGlyphDataFunc.
  175. *
  176. * @input:
  177. * incremental ::
  178. * A handle to an opaque @FT_Incremental handle provided by the client
  179. * application.
  180. *
  181. * data ::
  182. * A structure describing the glyph data bytes (which will be accessed
  183. * as a read-only byte block).
  184. *
  185. */
  186. typedef void
  187. (*FT_Incremental_FreeGlyphDataFunc)( FT_Incremental incremental,
  188. FT_Data* data );
  189. /**************************************************************************
  190. *
  191. * @type:
  192. * FT_Incremental_GetGlyphMetricsFunc
  193. *
  194. * @description:
  195. * A function used to retrieve the basic metrics of a given glyph index
  196. * before accessing its data. This allows for handling font types such
  197. * as PCL~XL Format~1, Class~2 downloaded TrueType fonts, where the glyph
  198. * metrics (`hmtx` and `vmtx` tables) are permitted to be omitted from
  199. * the font, and the relevant metrics included in the header of the glyph
  200. * outline data. Importantly, this is not intended to allow custom glyph
  201. * metrics (for example, Postscript Metrics dictionaries), because that
  202. * conflicts with the requirements of outline hinting. Such custom
  203. * metrics must be handled separately, by the calling application.
  204. *
  205. * @input:
  206. * incremental ::
  207. * A handle to an opaque @FT_Incremental handle provided by the client
  208. * application.
  209. *
  210. * glyph_index ::
  211. * Index of relevant glyph.
  212. *
  213. * vertical ::
  214. * If true, return vertical metrics.
  215. *
  216. * ametrics ::
  217. * This parameter is used for both input and output. The original
  218. * glyph metrics, if any, in font units. If metrics are not available
  219. * all the values must be set to zero.
  220. *
  221. * @output:
  222. * ametrics ::
  223. * The glyph metrics in font units.
  224. *
  225. */
  226. typedef FT_Error
  227. (*FT_Incremental_GetGlyphMetricsFunc)
  228. ( FT_Incremental incremental,
  229. FT_UInt glyph_index,
  230. FT_Bool vertical,
  231. FT_Incremental_MetricsRec *ametrics );
  232. /**************************************************************************
  233. *
  234. * @struct:
  235. * FT_Incremental_FuncsRec
  236. *
  237. * @description:
  238. * A table of functions for accessing fonts that load data incrementally.
  239. * Used in @FT_Incremental_InterfaceRec.
  240. *
  241. * @fields:
  242. * get_glyph_data ::
  243. * The function to get glyph data. Must not be null.
  244. *
  245. * free_glyph_data ::
  246. * The function to release glyph data. Must not be null.
  247. *
  248. * get_glyph_metrics ::
  249. * The function to get glyph metrics. May be null if the font does not
  250. * require it.
  251. *
  252. */
  253. typedef struct FT_Incremental_FuncsRec_
  254. {
  255. FT_Incremental_GetGlyphDataFunc get_glyph_data;
  256. FT_Incremental_FreeGlyphDataFunc free_glyph_data;
  257. FT_Incremental_GetGlyphMetricsFunc get_glyph_metrics;
  258. } FT_Incremental_FuncsRec;
  259. /**************************************************************************
  260. *
  261. * @struct:
  262. * FT_Incremental_InterfaceRec
  263. *
  264. * @description:
  265. * A structure to be used with @FT_Open_Face to indicate that the user
  266. * wants to support incremental glyph loading. You should use it with
  267. * @FT_PARAM_TAG_INCREMENTAL as in the following example:
  268. *
  269. * ```
  270. * FT_Incremental_InterfaceRec inc_int;
  271. * FT_Parameter parameter;
  272. * FT_Open_Args open_args;
  273. *
  274. *
  275. * // set up incremental descriptor
  276. * inc_int.funcs = my_funcs;
  277. * inc_int.object = my_object;
  278. *
  279. * // set up optional parameter
  280. * parameter.tag = FT_PARAM_TAG_INCREMENTAL;
  281. * parameter.data = &inc_int;
  282. *
  283. * // set up FT_Open_Args structure
  284. * open_args.flags = FT_OPEN_PATHNAME | FT_OPEN_PARAMS;
  285. * open_args.pathname = my_font_pathname;
  286. * open_args.num_params = 1;
  287. * open_args.params = &parameter; // we use one optional argument
  288. *
  289. * // open the font
  290. * error = FT_Open_Face( library, &open_args, index, &face );
  291. * ...
  292. * ```
  293. *
  294. */
  295. typedef struct FT_Incremental_InterfaceRec_
  296. {
  297. const FT_Incremental_FuncsRec* funcs;
  298. FT_Incremental object;
  299. } FT_Incremental_InterfaceRec;
  300. /**************************************************************************
  301. *
  302. * @type:
  303. * FT_Incremental_Interface
  304. *
  305. * @description:
  306. * A pointer to an @FT_Incremental_InterfaceRec structure.
  307. *
  308. */
  309. typedef FT_Incremental_InterfaceRec* FT_Incremental_Interface;
  310. /* */
  311. FT_END_HEADER
  312. #endif /* FTINCREM_H_ */
  313. /* END */