ftdriver.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. /***************************************************************************/
  2. /* */
  3. /* ftdriver.h */
  4. /* */
  5. /* FreeType font driver interface (specification). */
  6. /* */
  7. /* Copyright 1996-2003, 2006, 2008, 2011-2013 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 __FTDRIVER_H__
  18. #define __FTDRIVER_H__
  19. #include <ft2build.h>
  20. #include FT_MODULE_H
  21. FT_BEGIN_HEADER
  22. typedef FT_Error
  23. (*FT_Face_InitFunc)( FT_Stream stream,
  24. FT_Face face,
  25. FT_Int typeface_index,
  26. FT_Int num_params,
  27. FT_Parameter* parameters );
  28. typedef void
  29. (*FT_Face_DoneFunc)( FT_Face face );
  30. typedef FT_Error
  31. (*FT_Size_InitFunc)( FT_Size size );
  32. typedef void
  33. (*FT_Size_DoneFunc)( FT_Size size );
  34. typedef FT_Error
  35. (*FT_Slot_InitFunc)( FT_GlyphSlot slot );
  36. typedef void
  37. (*FT_Slot_DoneFunc)( FT_GlyphSlot slot );
  38. typedef FT_Error
  39. (*FT_Size_RequestFunc)( FT_Size size,
  40. FT_Size_Request req );
  41. typedef FT_Error
  42. (*FT_Size_SelectFunc)( FT_Size size,
  43. FT_ULong size_index );
  44. typedef FT_Error
  45. (*FT_Slot_LoadFunc)( FT_GlyphSlot slot,
  46. FT_Size size,
  47. FT_UInt glyph_index,
  48. FT_Int32 load_flags );
  49. typedef FT_UInt
  50. (*FT_CharMap_CharIndexFunc)( FT_CharMap charmap,
  51. FT_Long charcode );
  52. typedef FT_Long
  53. (*FT_CharMap_CharNextFunc)( FT_CharMap charmap,
  54. FT_Long charcode );
  55. typedef FT_Error
  56. (*FT_Face_GetKerningFunc)( FT_Face face,
  57. FT_UInt left_glyph,
  58. FT_UInt right_glyph,
  59. FT_Vector* kerning );
  60. typedef FT_Error
  61. (*FT_Face_AttachFunc)( FT_Face face,
  62. FT_Stream stream );
  63. typedef FT_Error
  64. (*FT_Face_GetAdvancesFunc)( FT_Face face,
  65. FT_UInt first,
  66. FT_UInt count,
  67. FT_Int32 flags,
  68. FT_Fixed* advances );
  69. /*************************************************************************/
  70. /* */
  71. /* <Struct> */
  72. /* FT_Driver_ClassRec */
  73. /* */
  74. /* <Description> */
  75. /* The font driver class. This structure mostly contains pointers to */
  76. /* driver methods. */
  77. /* */
  78. /* <Fields> */
  79. /* root :: The parent module. */
  80. /* */
  81. /* face_object_size :: The size of a face object in bytes. */
  82. /* */
  83. /* size_object_size :: The size of a size object in bytes. */
  84. /* */
  85. /* slot_object_size :: The size of a glyph object in bytes. */
  86. /* */
  87. /* init_face :: The format-specific face constructor. */
  88. /* */
  89. /* done_face :: The format-specific face destructor. */
  90. /* */
  91. /* init_size :: The format-specific size constructor. */
  92. /* */
  93. /* done_size :: The format-specific size destructor. */
  94. /* */
  95. /* init_slot :: The format-specific slot constructor. */
  96. /* */
  97. /* done_slot :: The format-specific slot destructor. */
  98. /* */
  99. /* */
  100. /* load_glyph :: A function handle to load a glyph to a slot. */
  101. /* This field is mandatory! */
  102. /* */
  103. /* get_kerning :: A function handle to return the unscaled */
  104. /* kerning for a given pair of glyphs. Can be */
  105. /* set to 0 if the format doesn't support */
  106. /* kerning. */
  107. /* */
  108. /* attach_file :: This function handle is used to read */
  109. /* additional data for a face from another */
  110. /* file/stream. For example, this can be used to */
  111. /* add data from AFM or PFM files on a Type 1 */
  112. /* face, or a CIDMap on a CID-keyed face. */
  113. /* */
  114. /* get_advances :: A function handle used to return advance */
  115. /* widths of `count' glyphs (in font units), */
  116. /* starting at `first'. The `vertical' flag must */
  117. /* be set to get vertical advance heights. The */
  118. /* `advances' buffer is caller-allocated. */
  119. /* The idea of this function is to be able to */
  120. /* perform device-independent text layout without */
  121. /* loading a single glyph image. */
  122. /* */
  123. /* request_size :: A handle to a function used to request the new */
  124. /* character size. Can be set to 0 if the */
  125. /* scaling done in the base layer suffices. */
  126. /* */
  127. /* select_size :: A handle to a function used to select a new */
  128. /* fixed size. It is used only if */
  129. /* @FT_FACE_FLAG_FIXED_SIZES is set. Can be set */
  130. /* to 0 if the scaling done in the base layer */
  131. /* suffices. */
  132. /* <Note> */
  133. /* Most function pointers, with the exception of `load_glyph', can be */
  134. /* set to 0 to indicate a default behaviour. */
  135. /* */
  136. typedef struct FT_Driver_ClassRec_
  137. {
  138. FT_Module_Class root;
  139. FT_Long face_object_size;
  140. FT_Long size_object_size;
  141. FT_Long slot_object_size;
  142. FT_Face_InitFunc init_face;
  143. FT_Face_DoneFunc done_face;
  144. FT_Size_InitFunc init_size;
  145. FT_Size_DoneFunc done_size;
  146. FT_Slot_InitFunc init_slot;
  147. FT_Slot_DoneFunc done_slot;
  148. FT_Slot_LoadFunc load_glyph;
  149. FT_Face_GetKerningFunc get_kerning;
  150. FT_Face_AttachFunc attach_file;
  151. FT_Face_GetAdvancesFunc get_advances;
  152. /* since version 2.2 */
  153. FT_Size_RequestFunc request_size;
  154. FT_Size_SelectFunc select_size;
  155. } FT_Driver_ClassRec, *FT_Driver_Class;
  156. /*************************************************************************/
  157. /* */
  158. /* <Macro> */
  159. /* FT_DECLARE_DRIVER */
  160. /* */
  161. /* <Description> */
  162. /* Used to create a forward declaration of an FT_Driver_ClassRec */
  163. /* struct instance. */
  164. /* */
  165. /* <Macro> */
  166. /* FT_DEFINE_DRIVER */
  167. /* */
  168. /* <Description> */
  169. /* Used to initialize an instance of FT_Driver_ClassRec struct. */
  170. /* */
  171. /* When FT_CONFIG_OPTION_PIC is defined a `create' function has to be */
  172. /* called with a pointer where the allocated structure is returned. */
  173. /* And when it is no longer needed a `destroy' function needs to be */
  174. /* called to release that allocation. */
  175. /* */
  176. /* `fcinit.c' (ft_create_default_module_classes) already contains a */
  177. /* mechanism to call these functions for the default modules */
  178. /* described in `ftmodule.h'. */
  179. /* */
  180. /* Notice that the created `create' and `destroy' functions call */
  181. /* `pic_init' and `pic_free' to allow you to manually allocate and */
  182. /* initialize any additional global data, like a module specific */
  183. /* interface, and put them in the global pic container defined in */
  184. /* `ftpic.h'. If you don't need them just implement the functions as */
  185. /* empty to resolve the link error. Also the `pic_init' and */
  186. /* `pic_free' functions should be declared in `pic.h', to be referred */
  187. /* by driver definition calling `FT_DEFINE_DRIVER' in following. */
  188. /* */
  189. /* When FT_CONFIG_OPTION_PIC is not defined the struct will be */
  190. /* allocated in the global scope (or the scope where the macro is */
  191. /* used). */
  192. /* */
  193. #ifndef FT_CONFIG_OPTION_PIC
  194. #define FT_DECLARE_DRIVER( class_ ) \
  195. FT_CALLBACK_TABLE \
  196. const FT_Driver_ClassRec class_;
  197. #define FT_DEFINE_DRIVER( \
  198. class_, \
  199. flags_, \
  200. size_, \
  201. name_, \
  202. version_, \
  203. requires_, \
  204. interface_, \
  205. init_, \
  206. done_, \
  207. get_interface_, \
  208. face_object_size_, \
  209. size_object_size_, \
  210. slot_object_size_, \
  211. init_face_, \
  212. done_face_, \
  213. init_size_, \
  214. done_size_, \
  215. init_slot_, \
  216. done_slot_, \
  217. load_glyph_, \
  218. get_kerning_, \
  219. attach_file_, \
  220. get_advances_, \
  221. request_size_, \
  222. select_size_ ) \
  223. FT_CALLBACK_TABLE_DEF \
  224. const FT_Driver_ClassRec class_ = \
  225. { \
  226. FT_DEFINE_ROOT_MODULE( flags_, \
  227. size_, \
  228. name_, \
  229. version_, \
  230. requires_, \
  231. interface_, \
  232. init_, \
  233. done_, \
  234. get_interface_ ) \
  235. \
  236. face_object_size_, \
  237. size_object_size_, \
  238. slot_object_size_, \
  239. \
  240. init_face_, \
  241. done_face_, \
  242. \
  243. init_size_, \
  244. done_size_, \
  245. \
  246. init_slot_, \
  247. done_slot_, \
  248. \
  249. load_glyph_, \
  250. \
  251. get_kerning_, \
  252. attach_file_, \
  253. get_advances_, \
  254. \
  255. request_size_, \
  256. select_size_ \
  257. };
  258. #else /* FT_CONFIG_OPTION_PIC */
  259. #define FT_DECLARE_DRIVER( class_ ) FT_DECLARE_MODULE( class_ )
  260. #define FT_DEFINE_DRIVER( \
  261. class_, \
  262. flags_, \
  263. size_, \
  264. name_, \
  265. version_, \
  266. requires_, \
  267. interface_, \
  268. init_, \
  269. done_, \
  270. get_interface_, \
  271. face_object_size_, \
  272. size_object_size_, \
  273. slot_object_size_, \
  274. init_face_, \
  275. done_face_, \
  276. init_size_, \
  277. done_size_, \
  278. init_slot_, \
  279. done_slot_, \
  280. load_glyph_, \
  281. get_kerning_, \
  282. attach_file_, \
  283. get_advances_, \
  284. request_size_, \
  285. select_size_ ) \
  286. void \
  287. FT_Destroy_Class_ ## class_( FT_Library library, \
  288. FT_Module_Class* clazz ) \
  289. { \
  290. FT_Memory memory = library->memory; \
  291. FT_Driver_Class dclazz = (FT_Driver_Class)clazz; \
  292. \
  293. \
  294. class_ ## _pic_free( library ); \
  295. if ( dclazz ) \
  296. FT_FREE( dclazz ); \
  297. } \
  298. \
  299. \
  300. FT_Error \
  301. FT_Create_Class_ ## class_( FT_Library library, \
  302. FT_Module_Class** output_class ) \
  303. { \
  304. FT_Driver_Class clazz = NULL; \
  305. FT_Error error; \
  306. FT_Memory memory = library->memory; \
  307. \
  308. \
  309. if ( FT_ALLOC( clazz, sizeof ( *clazz ) ) ) \
  310. return error; \
  311. \
  312. error = class_ ## _pic_init( library ); \
  313. if ( error ) \
  314. { \
  315. FT_FREE( clazz ); \
  316. return error; \
  317. } \
  318. \
  319. FT_DEFINE_ROOT_MODULE( flags_, \
  320. size_, \
  321. name_, \
  322. version_, \
  323. requires_, \
  324. interface_, \
  325. init_, \
  326. done_, \
  327. get_interface_ ) \
  328. \
  329. clazz->face_object_size = face_object_size_; \
  330. clazz->size_object_size = size_object_size_; \
  331. clazz->slot_object_size = slot_object_size_; \
  332. \
  333. clazz->init_face = init_face_; \
  334. clazz->done_face = done_face_; \
  335. \
  336. clazz->init_size = init_size_; \
  337. clazz->done_size = done_size_; \
  338. \
  339. clazz->init_slot = init_slot_; \
  340. clazz->done_slot = done_slot_; \
  341. \
  342. clazz->load_glyph = load_glyph_; \
  343. \
  344. clazz->get_kerning = get_kerning_; \
  345. clazz->attach_file = attach_file_; \
  346. clazz->get_advances = get_advances_; \
  347. \
  348. clazz->request_size = request_size_; \
  349. clazz->select_size = select_size_; \
  350. \
  351. *output_class = (FT_Module_Class*)clazz; \
  352. \
  353. return FT_Err_Ok; \
  354. }
  355. #endif /* FT_CONFIG_OPTION_PIC */
  356. FT_END_HEADER
  357. #endif /* __FTDRIVER_H__ */
  358. /* END */