ftdriver.h 22 KB

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