ftobjs.h 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569
  1. /***************************************************************************/
  2. /* */
  3. /* ftobjs.h */
  4. /* */
  5. /* The FreeType private base classes (specification). */
  6. /* */
  7. /* Copyright 1996-2006, 2008, 2010, 2012-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. /*************************************************************************/
  18. /* */
  19. /* This file contains the definition of all internal FreeType classes. */
  20. /* */
  21. /*************************************************************************/
  22. #ifndef __FTOBJS_H__
  23. #define __FTOBJS_H__
  24. #include <ft2build.h>
  25. #include FT_RENDER_H
  26. #include FT_SIZES_H
  27. #include FT_LCD_FILTER_H
  28. #include FT_INTERNAL_MEMORY_H
  29. #include FT_INTERNAL_GLYPH_LOADER_H
  30. #include FT_INTERNAL_DRIVER_H
  31. #include FT_INTERNAL_AUTOHINT_H
  32. #include FT_INTERNAL_SERVICE_H
  33. #include FT_INTERNAL_PIC_H
  34. #ifdef FT_CONFIG_OPTION_INCREMENTAL
  35. #include FT_INCREMENTAL_H
  36. #endif
  37. FT_BEGIN_HEADER
  38. /*************************************************************************/
  39. /* */
  40. /* Some generic definitions. */
  41. /* */
  42. #ifndef TRUE
  43. #define TRUE 1
  44. #endif
  45. #ifndef FALSE
  46. #define FALSE 0
  47. #endif
  48. #ifndef NULL
  49. #define NULL (void*)0
  50. #endif
  51. /*************************************************************************/
  52. /* */
  53. /* The min and max functions missing in C. As usual, be careful not to */
  54. /* write things like FT_MIN( a++, b++ ) to avoid side effects. */
  55. /* */
  56. #define FT_MIN( a, b ) ( (a) < (b) ? (a) : (b) )
  57. #define FT_MAX( a, b ) ( (a) > (b) ? (a) : (b) )
  58. #define FT_ABS( a ) ( (a) < 0 ? -(a) : (a) )
  59. #define FT_PAD_FLOOR( x, n ) ( (x) & ~((n)-1) )
  60. #define FT_PAD_ROUND( x, n ) FT_PAD_FLOOR( (x) + ((n)/2), n )
  61. #define FT_PAD_CEIL( x, n ) FT_PAD_FLOOR( (x) + ((n)-1), n )
  62. #define FT_PIX_FLOOR( x ) ( (x) & ~63 )
  63. #define FT_PIX_ROUND( x ) FT_PIX_FLOOR( (x) + 32 )
  64. #define FT_PIX_CEIL( x ) FT_PIX_FLOOR( (x) + 63 )
  65. /*
  66. * Return the highest power of 2 that is <= value; this correspond to
  67. * the highest bit in a given 32-bit value.
  68. */
  69. FT_BASE( FT_UInt32 )
  70. ft_highpow2( FT_UInt32 value );
  71. /*
  72. * character classification functions -- since these are used to parse
  73. * font files, we must not use those in <ctypes.h> which are
  74. * locale-dependent
  75. */
  76. #define ft_isdigit( x ) ( ( (unsigned)(x) - '0' ) < 10U )
  77. #define ft_isxdigit( x ) ( ( (unsigned)(x) - '0' ) < 10U || \
  78. ( (unsigned)(x) - 'a' ) < 6U || \
  79. ( (unsigned)(x) - 'A' ) < 6U )
  80. /* the next two macros assume ASCII representation */
  81. #define ft_isupper( x ) ( ( (unsigned)(x) - 'A' ) < 26U )
  82. #define ft_islower( x ) ( ( (unsigned)(x) - 'a' ) < 26U )
  83. #define ft_isalpha( x ) ( ft_isupper( x ) || ft_islower( x ) )
  84. #define ft_isalnum( x ) ( ft_isdigit( x ) || ft_isalpha( x ) )
  85. /*************************************************************************/
  86. /*************************************************************************/
  87. /*************************************************************************/
  88. /**** ****/
  89. /**** ****/
  90. /**** C H A R M A P S ****/
  91. /**** ****/
  92. /**** ****/
  93. /*************************************************************************/
  94. /*************************************************************************/
  95. /*************************************************************************/
  96. /* handle to internal charmap object */
  97. typedef struct FT_CMapRec_* FT_CMap;
  98. /* handle to charmap class structure */
  99. typedef const struct FT_CMap_ClassRec_* FT_CMap_Class;
  100. /* internal charmap object structure */
  101. typedef struct FT_CMapRec_
  102. {
  103. FT_CharMapRec charmap;
  104. FT_CMap_Class clazz;
  105. } FT_CMapRec;
  106. /* typecase any pointer to a charmap handle */
  107. #define FT_CMAP( x ) ((FT_CMap)( x ))
  108. /* obvious macros */
  109. #define FT_CMAP_PLATFORM_ID( x ) FT_CMAP( x )->charmap.platform_id
  110. #define FT_CMAP_ENCODING_ID( x ) FT_CMAP( x )->charmap.encoding_id
  111. #define FT_CMAP_ENCODING( x ) FT_CMAP( x )->charmap.encoding
  112. #define FT_CMAP_FACE( x ) FT_CMAP( x )->charmap.face
  113. /* class method definitions */
  114. typedef FT_Error
  115. (*FT_CMap_InitFunc)( FT_CMap cmap,
  116. FT_Pointer init_data );
  117. typedef void
  118. (*FT_CMap_DoneFunc)( FT_CMap cmap );
  119. typedef FT_UInt
  120. (*FT_CMap_CharIndexFunc)( FT_CMap cmap,
  121. FT_UInt32 char_code );
  122. typedef FT_UInt
  123. (*FT_CMap_CharNextFunc)( FT_CMap cmap,
  124. FT_UInt32 *achar_code );
  125. typedef FT_UInt
  126. (*FT_CMap_CharVarIndexFunc)( FT_CMap cmap,
  127. FT_CMap unicode_cmap,
  128. FT_UInt32 char_code,
  129. FT_UInt32 variant_selector );
  130. typedef FT_Bool
  131. (*FT_CMap_CharVarIsDefaultFunc)( FT_CMap cmap,
  132. FT_UInt32 char_code,
  133. FT_UInt32 variant_selector );
  134. typedef FT_UInt32 *
  135. (*FT_CMap_VariantListFunc)( FT_CMap cmap,
  136. FT_Memory mem );
  137. typedef FT_UInt32 *
  138. (*FT_CMap_CharVariantListFunc)( FT_CMap cmap,
  139. FT_Memory mem,
  140. FT_UInt32 char_code );
  141. typedef FT_UInt32 *
  142. (*FT_CMap_VariantCharListFunc)( FT_CMap cmap,
  143. FT_Memory mem,
  144. FT_UInt32 variant_selector );
  145. typedef struct FT_CMap_ClassRec_
  146. {
  147. FT_ULong size;
  148. FT_CMap_InitFunc init;
  149. FT_CMap_DoneFunc done;
  150. FT_CMap_CharIndexFunc char_index;
  151. FT_CMap_CharNextFunc char_next;
  152. /* Subsequent entries are special ones for format 14 -- the variant */
  153. /* selector subtable which behaves like no other */
  154. FT_CMap_CharVarIndexFunc char_var_index;
  155. FT_CMap_CharVarIsDefaultFunc char_var_default;
  156. FT_CMap_VariantListFunc variant_list;
  157. FT_CMap_CharVariantListFunc charvariant_list;
  158. FT_CMap_VariantCharListFunc variantchar_list;
  159. } FT_CMap_ClassRec;
  160. #ifndef FT_CONFIG_OPTION_PIC
  161. #define FT_DECLARE_CMAP_CLASS( class_ ) \
  162. FT_CALLBACK_TABLE const FT_CMap_ClassRec class_;
  163. #define FT_DEFINE_CMAP_CLASS( \
  164. class_, \
  165. size_, \
  166. init_, \
  167. done_, \
  168. char_index_, \
  169. char_next_, \
  170. char_var_index_, \
  171. char_var_default_, \
  172. variant_list_, \
  173. charvariant_list_, \
  174. variantchar_list_ ) \
  175. FT_CALLBACK_TABLE_DEF \
  176. const FT_CMap_ClassRec class_ = \
  177. { \
  178. size_, \
  179. init_, \
  180. done_, \
  181. char_index_, \
  182. char_next_, \
  183. char_var_index_, \
  184. char_var_default_, \
  185. variant_list_, \
  186. charvariant_list_, \
  187. variantchar_list_ \
  188. };
  189. #else /* FT_CONFIG_OPTION_PIC */
  190. #define FT_DECLARE_CMAP_CLASS( class_ ) \
  191. void \
  192. FT_Init_Class_ ## class_( FT_Library library, \
  193. FT_CMap_ClassRec* clazz );
  194. #define FT_DEFINE_CMAP_CLASS( \
  195. class_, \
  196. size_, \
  197. init_, \
  198. done_, \
  199. char_index_, \
  200. char_next_, \
  201. char_var_index_, \
  202. char_var_default_, \
  203. variant_list_, \
  204. charvariant_list_, \
  205. variantchar_list_ ) \
  206. void \
  207. FT_Init_Class_ ## class_( FT_Library library, \
  208. FT_CMap_ClassRec* clazz ) \
  209. { \
  210. FT_UNUSED( library ); \
  211. \
  212. clazz->size = size_; \
  213. clazz->init = init_; \
  214. clazz->done = done_; \
  215. clazz->char_index = char_index_; \
  216. clazz->char_next = char_next_; \
  217. clazz->char_var_index = char_var_index_; \
  218. clazz->char_var_default = char_var_default_; \
  219. clazz->variant_list = variant_list_; \
  220. clazz->charvariant_list = charvariant_list_; \
  221. clazz->variantchar_list = variantchar_list_; \
  222. }
  223. #endif /* FT_CONFIG_OPTION_PIC */
  224. /* create a new charmap and add it to charmap->face */
  225. FT_BASE( FT_Error )
  226. FT_CMap_New( FT_CMap_Class clazz,
  227. FT_Pointer init_data,
  228. FT_CharMap charmap,
  229. FT_CMap *acmap );
  230. /* destroy a charmap and remove it from face's list */
  231. FT_BASE( void )
  232. FT_CMap_Done( FT_CMap cmap );
  233. /*************************************************************************/
  234. /* */
  235. /* <Struct> */
  236. /* FT_Face_InternalRec */
  237. /* */
  238. /* <Description> */
  239. /* This structure contains the internal fields of each FT_Face */
  240. /* object. These fields may change between different releases of */
  241. /* FreeType. */
  242. /* */
  243. /* <Fields> */
  244. /* max_points :: */
  245. /* The maximum number of points used to store the vectorial outline */
  246. /* of any glyph in this face. If this value cannot be known in */
  247. /* advance, or if the face isn't scalable, this should be set to 0. */
  248. /* Only relevant for scalable formats. */
  249. /* */
  250. /* max_contours :: */
  251. /* The maximum number of contours used to store the vectorial */
  252. /* outline of any glyph in this face. If this value cannot be */
  253. /* known in advance, or if the face isn't scalable, this should be */
  254. /* set to 0. Only relevant for scalable formats. */
  255. /* */
  256. /* transform_matrix :: */
  257. /* A 2x2 matrix of 16.16 coefficients used to transform glyph */
  258. /* outlines after they are loaded from the font. Only used by the */
  259. /* convenience functions. */
  260. /* */
  261. /* transform_delta :: */
  262. /* A translation vector used to transform glyph outlines after they */
  263. /* are loaded from the font. Only used by the convenience */
  264. /* functions. */
  265. /* */
  266. /* transform_flags :: */
  267. /* Some flags used to classify the transform. Only used by the */
  268. /* convenience functions. */
  269. /* */
  270. /* services :: */
  271. /* A cache for frequently used services. It should be only */
  272. /* accessed with the macro `FT_FACE_LOOKUP_SERVICE'. */
  273. /* */
  274. /* incremental_interface :: */
  275. /* If non-null, the interface through which glyph data and metrics */
  276. /* are loaded incrementally for faces that do not provide all of */
  277. /* this data when first opened. This field exists only if */
  278. /* @FT_CONFIG_OPTION_INCREMENTAL is defined. */
  279. /* */
  280. /* ignore_unpatented_hinter :: */
  281. /* This boolean flag instructs the glyph loader to ignore the */
  282. /* native font hinter, if one is found. This is exclusively used */
  283. /* in the case when the unpatented hinter is compiled within the */
  284. /* library. */
  285. /* */
  286. /* refcount :: */
  287. /* A counter initialized to~1 at the time an @FT_Face structure is */
  288. /* created. @FT_Reference_Face increments this counter, and */
  289. /* @FT_Done_Face only destroys a face if the counter is~1, */
  290. /* otherwise it simply decrements it. */
  291. /* */
  292. typedef struct FT_Face_InternalRec_
  293. {
  294. FT_Matrix transform_matrix;
  295. FT_Vector transform_delta;
  296. FT_Int transform_flags;
  297. FT_ServiceCacheRec services;
  298. #ifdef FT_CONFIG_OPTION_INCREMENTAL
  299. FT_Incremental_InterfaceRec* incremental_interface;
  300. #endif
  301. FT_Bool ignore_unpatented_hinter;
  302. FT_Int refcount;
  303. } FT_Face_InternalRec;
  304. /*************************************************************************/
  305. /* */
  306. /* <Struct> */
  307. /* FT_Slot_InternalRec */
  308. /* */
  309. /* <Description> */
  310. /* This structure contains the internal fields of each FT_GlyphSlot */
  311. /* object. These fields may change between different releases of */
  312. /* FreeType. */
  313. /* */
  314. /* <Fields> */
  315. /* loader :: The glyph loader object used to load outlines */
  316. /* into the glyph slot. */
  317. /* */
  318. /* flags :: Possible values are zero or */
  319. /* FT_GLYPH_OWN_BITMAP. The latter indicates */
  320. /* that the FT_GlyphSlot structure owns the */
  321. /* bitmap buffer. */
  322. /* */
  323. /* glyph_transformed :: Boolean. Set to TRUE when the loaded glyph */
  324. /* must be transformed through a specific */
  325. /* font transformation. This is _not_ the same */
  326. /* as the face transform set through */
  327. /* FT_Set_Transform(). */
  328. /* */
  329. /* glyph_matrix :: The 2x2 matrix corresponding to the glyph */
  330. /* transformation, if necessary. */
  331. /* */
  332. /* glyph_delta :: The 2d translation vector corresponding to */
  333. /* the glyph transformation, if necessary. */
  334. /* */
  335. /* glyph_hints :: Format-specific glyph hints management. */
  336. /* */
  337. #define FT_GLYPH_OWN_BITMAP 0x1
  338. typedef struct FT_Slot_InternalRec_
  339. {
  340. FT_GlyphLoader loader;
  341. FT_UInt flags;
  342. FT_Bool glyph_transformed;
  343. FT_Matrix glyph_matrix;
  344. FT_Vector glyph_delta;
  345. void* glyph_hints;
  346. } FT_GlyphSlot_InternalRec;
  347. #if 0
  348. /*************************************************************************/
  349. /* */
  350. /* <Struct> */
  351. /* FT_Size_InternalRec */
  352. /* */
  353. /* <Description> */
  354. /* This structure contains the internal fields of each FT_Size */
  355. /* object. Currently, it's empty. */
  356. /* */
  357. /*************************************************************************/
  358. typedef struct FT_Size_InternalRec_
  359. {
  360. /* empty */
  361. } FT_Size_InternalRec;
  362. #endif
  363. /*************************************************************************/
  364. /*************************************************************************/
  365. /*************************************************************************/
  366. /**** ****/
  367. /**** ****/
  368. /**** M O D U L E S ****/
  369. /**** ****/
  370. /**** ****/
  371. /*************************************************************************/
  372. /*************************************************************************/
  373. /*************************************************************************/
  374. /*************************************************************************/
  375. /* */
  376. /* <Struct> */
  377. /* FT_ModuleRec */
  378. /* */
  379. /* <Description> */
  380. /* A module object instance. */
  381. /* */
  382. /* <Fields> */
  383. /* clazz :: A pointer to the module's class. */
  384. /* */
  385. /* library :: A handle to the parent library object. */
  386. /* */
  387. /* memory :: A handle to the memory manager. */
  388. /* */
  389. typedef struct FT_ModuleRec_
  390. {
  391. FT_Module_Class* clazz;
  392. FT_Library library;
  393. FT_Memory memory;
  394. } FT_ModuleRec;
  395. /* typecast an object to an FT_Module */
  396. #define FT_MODULE( x ) ((FT_Module)( x ))
  397. #define FT_MODULE_CLASS( x ) FT_MODULE( x )->clazz
  398. #define FT_MODULE_LIBRARY( x ) FT_MODULE( x )->library
  399. #define FT_MODULE_MEMORY( x ) FT_MODULE( x )->memory
  400. #define FT_MODULE_IS_DRIVER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
  401. FT_MODULE_FONT_DRIVER )
  402. #define FT_MODULE_IS_RENDERER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
  403. FT_MODULE_RENDERER )
  404. #define FT_MODULE_IS_HINTER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
  405. FT_MODULE_HINTER )
  406. #define FT_MODULE_IS_STYLER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
  407. FT_MODULE_STYLER )
  408. #define FT_DRIVER_IS_SCALABLE( x ) ( FT_MODULE_CLASS( x )->module_flags & \
  409. FT_MODULE_DRIVER_SCALABLE )
  410. #define FT_DRIVER_USES_OUTLINES( x ) !( FT_MODULE_CLASS( x )->module_flags & \
  411. FT_MODULE_DRIVER_NO_OUTLINES )
  412. #define FT_DRIVER_HAS_HINTER( x ) ( FT_MODULE_CLASS( x )->module_flags & \
  413. FT_MODULE_DRIVER_HAS_HINTER )
  414. /*************************************************************************/
  415. /* */
  416. /* <Function> */
  417. /* FT_Get_Module_Interface */
  418. /* */
  419. /* <Description> */
  420. /* Finds a module and returns its specific interface as a typeless */
  421. /* pointer. */
  422. /* */
  423. /* <Input> */
  424. /* library :: A handle to the library object. */
  425. /* */
  426. /* module_name :: The module's name (as an ASCII string). */
  427. /* */
  428. /* <Return> */
  429. /* A module-specific interface if available, 0 otherwise. */
  430. /* */
  431. /* <Note> */
  432. /* You should better be familiar with FreeType internals to know */
  433. /* which module to look for, and what its interface is :-) */
  434. /* */
  435. FT_BASE( const void* )
  436. FT_Get_Module_Interface( FT_Library library,
  437. const char* mod_name );
  438. FT_BASE( FT_Pointer )
  439. ft_module_get_service( FT_Module module,
  440. const char* service_id );
  441. /* */
  442. /*************************************************************************/
  443. /*************************************************************************/
  444. /*************************************************************************/
  445. /**** ****/
  446. /**** ****/
  447. /**** F A C E, S I Z E & G L Y P H S L O T O B J E C T S ****/
  448. /**** ****/
  449. /**** ****/
  450. /*************************************************************************/
  451. /*************************************************************************/
  452. /*************************************************************************/
  453. /* a few macros used to perform easy typecasts with minimal brain damage */
  454. #define FT_FACE( x ) ((FT_Face)(x))
  455. #define FT_SIZE( x ) ((FT_Size)(x))
  456. #define FT_SLOT( x ) ((FT_GlyphSlot)(x))
  457. #define FT_FACE_DRIVER( x ) FT_FACE( x )->driver
  458. #define FT_FACE_LIBRARY( x ) FT_FACE_DRIVER( x )->root.library
  459. #define FT_FACE_MEMORY( x ) FT_FACE( x )->memory
  460. #define FT_FACE_STREAM( x ) FT_FACE( x )->stream
  461. #define FT_SIZE_FACE( x ) FT_SIZE( x )->face
  462. #define FT_SLOT_FACE( x ) FT_SLOT( x )->face
  463. #define FT_FACE_SLOT( x ) FT_FACE( x )->glyph
  464. #define FT_FACE_SIZE( x ) FT_FACE( x )->size
  465. /*************************************************************************/
  466. /* */
  467. /* <Function> */
  468. /* FT_New_GlyphSlot */
  469. /* */
  470. /* <Description> */
  471. /* It is sometimes useful to have more than one glyph slot for a */
  472. /* given face object. This function is used to create additional */
  473. /* slots. All of them are automatically discarded when the face is */
  474. /* destroyed. */
  475. /* */
  476. /* <Input> */
  477. /* face :: A handle to a parent face object. */
  478. /* */
  479. /* <Output> */
  480. /* aslot :: A handle to a new glyph slot object. */
  481. /* */
  482. /* <Return> */
  483. /* FreeType error code. 0 means success. */
  484. /* */
  485. FT_BASE( FT_Error )
  486. FT_New_GlyphSlot( FT_Face face,
  487. FT_GlyphSlot *aslot );
  488. /*************************************************************************/
  489. /* */
  490. /* <Function> */
  491. /* FT_Done_GlyphSlot */
  492. /* */
  493. /* <Description> */
  494. /* Destroys a given glyph slot. Remember however that all slots are */
  495. /* automatically destroyed with its parent. Using this function is */
  496. /* not always mandatory. */
  497. /* */
  498. /* <Input> */
  499. /* slot :: A handle to a target glyph slot. */
  500. /* */
  501. FT_BASE( void )
  502. FT_Done_GlyphSlot( FT_GlyphSlot slot );
  503. /* */
  504. #define FT_REQUEST_WIDTH( req ) \
  505. ( (req)->horiResolution \
  506. ? (FT_Pos)( (req)->width * (req)->horiResolution + 36 ) / 72 \
  507. : (req)->width )
  508. #define FT_REQUEST_HEIGHT( req ) \
  509. ( (req)->vertResolution \
  510. ? (FT_Pos)( (req)->height * (req)->vertResolution + 36 ) / 72 \
  511. : (req)->height )
  512. /* Set the metrics according to a bitmap strike. */
  513. FT_BASE( void )
  514. FT_Select_Metrics( FT_Face face,
  515. FT_ULong strike_index );
  516. /* Set the metrics according to a size request. */
  517. FT_BASE( void )
  518. FT_Request_Metrics( FT_Face face,
  519. FT_Size_Request req );
  520. /* Match a size request against `available_sizes'. */
  521. FT_BASE( FT_Error )
  522. FT_Match_Size( FT_Face face,
  523. FT_Size_Request req,
  524. FT_Bool ignore_width,
  525. FT_ULong* size_index );
  526. /* Use the horizontal metrics to synthesize the vertical metrics. */
  527. /* If `advance' is zero, it is also synthesized. */
  528. FT_BASE( void )
  529. ft_synthesize_vertical_metrics( FT_Glyph_Metrics* metrics,
  530. FT_Pos advance );
  531. /* Free the bitmap of a given glyphslot when needed (i.e., only when it */
  532. /* was allocated with ft_glyphslot_alloc_bitmap). */
  533. FT_BASE( void )
  534. ft_glyphslot_free_bitmap( FT_GlyphSlot slot );
  535. /* Allocate a new bitmap buffer in a glyph slot. */
  536. FT_BASE( FT_Error )
  537. ft_glyphslot_alloc_bitmap( FT_GlyphSlot slot,
  538. FT_ULong size );
  539. /* Set the bitmap buffer in a glyph slot to a given pointer. The buffer */
  540. /* will not be freed by a later call to ft_glyphslot_free_bitmap. */
  541. FT_BASE( void )
  542. ft_glyphslot_set_bitmap( FT_GlyphSlot slot,
  543. FT_Byte* buffer );
  544. /*************************************************************************/
  545. /*************************************************************************/
  546. /*************************************************************************/
  547. /**** ****/
  548. /**** ****/
  549. /**** R E N D E R E R S ****/
  550. /**** ****/
  551. /**** ****/
  552. /*************************************************************************/
  553. /*************************************************************************/
  554. /*************************************************************************/
  555. #define FT_RENDERER( x ) ((FT_Renderer)( x ))
  556. #define FT_GLYPH( x ) ((FT_Glyph)( x ))
  557. #define FT_BITMAP_GLYPH( x ) ((FT_BitmapGlyph)( x ))
  558. #define FT_OUTLINE_GLYPH( x ) ((FT_OutlineGlyph)( x ))
  559. typedef struct FT_RendererRec_
  560. {
  561. FT_ModuleRec root;
  562. FT_Renderer_Class* clazz;
  563. FT_Glyph_Format glyph_format;
  564. FT_Glyph_Class glyph_class;
  565. FT_Raster raster;
  566. FT_Raster_Render_Func raster_render;
  567. FT_Renderer_RenderFunc render;
  568. } FT_RendererRec;
  569. /*************************************************************************/
  570. /*************************************************************************/
  571. /*************************************************************************/
  572. /**** ****/
  573. /**** ****/
  574. /**** F O N T D R I V E R S ****/
  575. /**** ****/
  576. /**** ****/
  577. /*************************************************************************/
  578. /*************************************************************************/
  579. /*************************************************************************/
  580. /* typecast a module into a driver easily */
  581. #define FT_DRIVER( x ) ((FT_Driver)(x))
  582. /* typecast a module as a driver, and get its driver class */
  583. #define FT_DRIVER_CLASS( x ) FT_DRIVER( x )->clazz
  584. /*************************************************************************/
  585. /* */
  586. /* <Struct> */
  587. /* FT_DriverRec */
  588. /* */
  589. /* <Description> */
  590. /* The root font driver class. A font driver is responsible for */
  591. /* managing and loading font files of a given format. */
  592. /* */
  593. /* <Fields> */
  594. /* root :: Contains the fields of the root module class. */
  595. /* */
  596. /* clazz :: A pointer to the font driver's class. Note that */
  597. /* this is NOT root.clazz. `class' wasn't used */
  598. /* as it is a reserved word in C++. */
  599. /* */
  600. /* faces_list :: The list of faces currently opened by this */
  601. /* driver. */
  602. /* */
  603. /* glyph_loader :: The glyph loader for all faces managed by this */
  604. /* driver. This object isn't defined for unscalable */
  605. /* formats. */
  606. /* */
  607. typedef struct FT_DriverRec_
  608. {
  609. FT_ModuleRec root;
  610. FT_Driver_Class clazz;
  611. FT_ListRec faces_list;
  612. FT_GlyphLoader glyph_loader;
  613. } FT_DriverRec;
  614. /*************************************************************************/
  615. /*************************************************************************/
  616. /*************************************************************************/
  617. /**** ****/
  618. /**** ****/
  619. /**** L I B R A R I E S ****/
  620. /**** ****/
  621. /**** ****/
  622. /*************************************************************************/
  623. /*************************************************************************/
  624. /*************************************************************************/
  625. /* This hook is used by the TrueType debugger. It must be set to an */
  626. /* alternate truetype bytecode interpreter function. */
  627. #define FT_DEBUG_HOOK_TRUETYPE 0
  628. /* Set this debug hook to a non-null pointer to force unpatented hinting */
  629. /* for all faces when both TT_USE_BYTECODE_INTERPRETER and */
  630. /* TT_CONFIG_OPTION_UNPATENTED_HINTING are defined. This is only used */
  631. /* during debugging. */
  632. #define FT_DEBUG_HOOK_UNPATENTED_HINTING 1
  633. typedef void (*FT_Bitmap_LcdFilterFunc)( FT_Bitmap* bitmap,
  634. FT_Render_Mode render_mode,
  635. FT_Library library );
  636. /*************************************************************************/
  637. /* */
  638. /* <Struct> */
  639. /* FT_LibraryRec */
  640. /* */
  641. /* <Description> */
  642. /* The FreeType library class. This is the root of all FreeType */
  643. /* data. Use FT_New_Library() to create a library object, and */
  644. /* FT_Done_Library() to discard it and all child objects. */
  645. /* */
  646. /* <Fields> */
  647. /* memory :: The library's memory object. Manages memory */
  648. /* allocation. */
  649. /* */
  650. /* version_major :: The major version number of the library. */
  651. /* */
  652. /* version_minor :: The minor version number of the library. */
  653. /* */
  654. /* version_patch :: The current patch level of the library. */
  655. /* */
  656. /* num_modules :: The number of modules currently registered */
  657. /* within this library. This is set to 0 for new */
  658. /* libraries. New modules are added through the */
  659. /* FT_Add_Module() API function. */
  660. /* */
  661. /* modules :: A table used to store handles to the currently */
  662. /* registered modules. Note that each font driver */
  663. /* contains a list of its opened faces. */
  664. /* */
  665. /* renderers :: The list of renderers currently registered */
  666. /* within the library. */
  667. /* */
  668. /* cur_renderer :: The current outline renderer. This is a */
  669. /* shortcut used to avoid parsing the list on */
  670. /* each call to FT_Outline_Render(). It is a */
  671. /* handle to the current renderer for the */
  672. /* FT_GLYPH_FORMAT_OUTLINE format. */
  673. /* */
  674. /* auto_hinter :: XXX */
  675. /* */
  676. /* raster_pool :: The raster object's render pool. This can */
  677. /* ideally be changed dynamically at run-time. */
  678. /* */
  679. /* raster_pool_size :: The size of the render pool in bytes. */
  680. /* */
  681. /* debug_hooks :: XXX */
  682. /* */
  683. /* lcd_filter :: If subpixel rendering is activated, the */
  684. /* selected LCD filter mode. */
  685. /* */
  686. /* lcd_extra :: If subpixel rendering is activated, the number */
  687. /* of extra pixels needed for the LCD filter. */
  688. /* */
  689. /* lcd_weights :: If subpixel rendering is activated, the LCD */
  690. /* filter weights, if any. */
  691. /* */
  692. /* lcd_filter_func :: If subpixel rendering is activated, the LCD */
  693. /* filtering callback function. */
  694. /* */
  695. /* pic_container :: Contains global structs and tables, instead */
  696. /* of defining them globallly. */
  697. /* */
  698. /* refcount :: A counter initialized to~1 at the time an */
  699. /* @FT_Library structure is created. */
  700. /* @FT_Reference_Library increments this counter, */
  701. /* and @FT_Done_Library only destroys a library */
  702. /* if the counter is~1, otherwise it simply */
  703. /* decrements it. */
  704. /* */
  705. typedef struct FT_LibraryRec_
  706. {
  707. FT_Memory memory; /* library's memory manager */
  708. FT_Int version_major;
  709. FT_Int version_minor;
  710. FT_Int version_patch;
  711. FT_UInt num_modules;
  712. FT_Module modules[FT_MAX_MODULES]; /* module objects */
  713. FT_ListRec renderers; /* list of renderers */
  714. FT_Renderer cur_renderer; /* current outline renderer */
  715. FT_Module auto_hinter;
  716. FT_Byte* raster_pool; /* scan-line conversion */
  717. /* render pool */
  718. FT_ULong raster_pool_size; /* size of render pool in bytes */
  719. FT_DebugHook_Func debug_hooks[4];
  720. #ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
  721. FT_LcdFilter lcd_filter;
  722. FT_Int lcd_extra; /* number of extra pixels */
  723. FT_Byte lcd_weights[7]; /* filter weights, if any */
  724. FT_Bitmap_LcdFilterFunc lcd_filter_func; /* filtering callback */
  725. #endif
  726. #ifdef FT_CONFIG_OPTION_PIC
  727. FT_PIC_Container pic_container;
  728. #endif
  729. FT_Int refcount;
  730. } FT_LibraryRec;
  731. FT_BASE( FT_Renderer )
  732. FT_Lookup_Renderer( FT_Library library,
  733. FT_Glyph_Format format,
  734. FT_ListNode* node );
  735. FT_BASE( FT_Error )
  736. FT_Render_Glyph_Internal( FT_Library library,
  737. FT_GlyphSlot slot,
  738. FT_Render_Mode render_mode );
  739. typedef const char*
  740. (*FT_Face_GetPostscriptNameFunc)( FT_Face face );
  741. typedef FT_Error
  742. (*FT_Face_GetGlyphNameFunc)( FT_Face face,
  743. FT_UInt glyph_index,
  744. FT_Pointer buffer,
  745. FT_UInt buffer_max );
  746. typedef FT_UInt
  747. (*FT_Face_GetGlyphNameIndexFunc)( FT_Face face,
  748. FT_String* glyph_name );
  749. #ifndef FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM
  750. /*************************************************************************/
  751. /* */
  752. /* <Function> */
  753. /* FT_New_Memory */
  754. /* */
  755. /* <Description> */
  756. /* Creates a new memory object. */
  757. /* */
  758. /* <Return> */
  759. /* A pointer to the new memory object. 0 in case of error. */
  760. /* */
  761. FT_BASE( FT_Memory )
  762. FT_New_Memory( void );
  763. /*************************************************************************/
  764. /* */
  765. /* <Function> */
  766. /* FT_Done_Memory */
  767. /* */
  768. /* <Description> */
  769. /* Discards memory manager. */
  770. /* */
  771. /* <Input> */
  772. /* memory :: A handle to the memory manager. */
  773. /* */
  774. FT_BASE( void )
  775. FT_Done_Memory( FT_Memory memory );
  776. #endif /* !FT_CONFIG_OPTION_NO_DEFAULT_SYSTEM */
  777. /* Define default raster's interface. The default raster is located in */
  778. /* `src/base/ftraster.c'. */
  779. /* */
  780. /* Client applications can register new rasters through the */
  781. /* FT_Set_Raster() API. */
  782. #ifndef FT_NO_DEFAULT_RASTER
  783. FT_EXPORT_VAR( FT_Raster_Funcs ) ft_default_raster;
  784. #endif
  785. /*************************************************************************/
  786. /*************************************************************************/
  787. /*************************************************************************/
  788. /**** ****/
  789. /**** ****/
  790. /**** P I C S U P P O R T ****/
  791. /**** ****/
  792. /**** ****/
  793. /*************************************************************************/
  794. /*************************************************************************/
  795. /*************************************************************************/
  796. /* PIC support macros for ftimage.h */
  797. /*************************************************************************/
  798. /* */
  799. /* <Macro> */
  800. /* FT_DEFINE_OUTLINE_FUNCS */
  801. /* */
  802. /* <Description> */
  803. /* Used to initialize an instance of FT_Outline_Funcs struct. */
  804. /* When FT_CONFIG_OPTION_PIC is defined an init funtion will need to */
  805. /* be called with a pre-allocated structure to be filled. */
  806. /* When FT_CONFIG_OPTION_PIC is not defined the struct will be */
  807. /* allocated in the global scope (or the scope where the macro */
  808. /* is used). */
  809. /* */
  810. #ifndef FT_CONFIG_OPTION_PIC
  811. #define FT_DEFINE_OUTLINE_FUNCS( \
  812. class_, \
  813. move_to_, \
  814. line_to_, \
  815. conic_to_, \
  816. cubic_to_, \
  817. shift_, \
  818. delta_ ) \
  819. static const FT_Outline_Funcs class_ = \
  820. { \
  821. move_to_, \
  822. line_to_, \
  823. conic_to_, \
  824. cubic_to_, \
  825. shift_, \
  826. delta_ \
  827. };
  828. #else /* FT_CONFIG_OPTION_PIC */
  829. #define FT_DEFINE_OUTLINE_FUNCS( \
  830. class_, \
  831. move_to_, \
  832. line_to_, \
  833. conic_to_, \
  834. cubic_to_, \
  835. shift_, \
  836. delta_ ) \
  837. static FT_Error \
  838. Init_Class_ ## class_( FT_Outline_Funcs* clazz ) \
  839. { \
  840. clazz->move_to = move_to_; \
  841. clazz->line_to = line_to_; \
  842. clazz->conic_to = conic_to_; \
  843. clazz->cubic_to = cubic_to_; \
  844. clazz->shift = shift_; \
  845. clazz->delta = delta_; \
  846. \
  847. return FT_Err_Ok; \
  848. }
  849. #endif /* FT_CONFIG_OPTION_PIC */
  850. /*************************************************************************/
  851. /* */
  852. /* <Macro> */
  853. /* FT_DEFINE_RASTER_FUNCS */
  854. /* */
  855. /* <Description> */
  856. /* Used to initialize an instance of FT_Raster_Funcs struct. */
  857. /* When FT_CONFIG_OPTION_PIC is defined an init funtion will need to */
  858. /* be called with a pre-allocated structure to be filled. */
  859. /* When FT_CONFIG_OPTION_PIC is not defined the struct will be */
  860. /* allocated in the global scope (or the scope where the macro */
  861. /* is used). */
  862. /* */
  863. #ifndef FT_CONFIG_OPTION_PIC
  864. #define FT_DEFINE_RASTER_FUNCS( \
  865. class_, \
  866. glyph_format_, \
  867. raster_new_, \
  868. raster_reset_, \
  869. raster_set_mode_, \
  870. raster_render_, \
  871. raster_done_ ) \
  872. const FT_Raster_Funcs class_ = \
  873. { \
  874. glyph_format_, \
  875. raster_new_, \
  876. raster_reset_, \
  877. raster_set_mode_, \
  878. raster_render_, \
  879. raster_done_ \
  880. };
  881. #else /* FT_CONFIG_OPTION_PIC */
  882. #define FT_DEFINE_RASTER_FUNCS( \
  883. class_, \
  884. glyph_format_, \
  885. raster_new_, \
  886. raster_reset_, \
  887. raster_set_mode_, \
  888. raster_render_, \
  889. raster_done_ ) \
  890. void \
  891. FT_Init_Class_ ## class_( FT_Raster_Funcs* clazz ) \
  892. { \
  893. clazz->glyph_format = glyph_format_; \
  894. clazz->raster_new = raster_new_; \
  895. clazz->raster_reset = raster_reset_; \
  896. clazz->raster_set_mode = raster_set_mode_; \
  897. clazz->raster_render = raster_render_; \
  898. clazz->raster_done = raster_done_; \
  899. }
  900. #endif /* FT_CONFIG_OPTION_PIC */
  901. /* PIC support macros for ftrender.h */
  902. /*************************************************************************/
  903. /* */
  904. /* <Macro> */
  905. /* FT_DEFINE_GLYPH */
  906. /* */
  907. /* <Description> */
  908. /* Used to initialize an instance of FT_Glyph_Class struct. */
  909. /* When FT_CONFIG_OPTION_PIC is defined an init funtion will need to */
  910. /* be called with a pre-allocated stcture to be filled. */
  911. /* When FT_CONFIG_OPTION_PIC is not defined the struct will be */
  912. /* allocated in the global scope (or the scope where the macro */
  913. /* is used). */
  914. /* */
  915. #ifndef FT_CONFIG_OPTION_PIC
  916. #define FT_DEFINE_GLYPH( \
  917. class_, \
  918. size_, \
  919. format_, \
  920. init_, \
  921. done_, \
  922. copy_, \
  923. transform_, \
  924. bbox_, \
  925. prepare_ ) \
  926. FT_CALLBACK_TABLE_DEF \
  927. const FT_Glyph_Class class_ = \
  928. { \
  929. size_, \
  930. format_, \
  931. init_, \
  932. done_, \
  933. copy_, \
  934. transform_, \
  935. bbox_, \
  936. prepare_ \
  937. };
  938. #else /* FT_CONFIG_OPTION_PIC */
  939. #define FT_DEFINE_GLYPH( \
  940. class_, \
  941. size_, \
  942. format_, \
  943. init_, \
  944. done_, \
  945. copy_, \
  946. transform_, \
  947. bbox_, \
  948. prepare_ ) \
  949. void \
  950. FT_Init_Class_ ## class_( FT_Glyph_Class* clazz ) \
  951. { \
  952. clazz->glyph_size = size_; \
  953. clazz->glyph_format = format_; \
  954. clazz->glyph_init = init_; \
  955. clazz->glyph_done = done_; \
  956. clazz->glyph_copy = copy_; \
  957. clazz->glyph_transform = transform_; \
  958. clazz->glyph_bbox = bbox_; \
  959. clazz->glyph_prepare = prepare_; \
  960. }
  961. #endif /* FT_CONFIG_OPTION_PIC */
  962. /*************************************************************************/
  963. /* */
  964. /* <Macro> */
  965. /* FT_DECLARE_RENDERER */
  966. /* */
  967. /* <Description> */
  968. /* Used to create a forward declaration of a */
  969. /* FT_Renderer_Class struct instance. */
  970. /* */
  971. /* <Macro> */
  972. /* FT_DEFINE_RENDERER */
  973. /* */
  974. /* <Description> */
  975. /* Used to initialize an instance of FT_Renderer_Class struct. */
  976. /* */
  977. /* When FT_CONFIG_OPTION_PIC is defined a `create' funtion will need */
  978. /* to be called with a pointer where the allocated structure is */
  979. /* returned. And when it is no longer needed a `destroy' function */
  980. /* needs to be called to release that allocation. */
  981. /* `fcinit.c' (ft_create_default_module_classes) already contains */
  982. /* a mechanism to call these functions for the default modules */
  983. /* described in `ftmodule.h'. */
  984. /* */
  985. /* Notice that the created `create' and `destroy' functions call */
  986. /* `pic_init' and `pic_free' to allow you to manually allocate and */
  987. /* initialize any additional global data, like a module specific */
  988. /* interface, and put them in the global pic container defined in */
  989. /* `ftpic.h'. If you don't need them just implement the functions as */
  990. /* empty to resolve the link error. Also the `pic_init' and */
  991. /* `pic_free' functions should be declared in `pic.h', to be referred */
  992. /* by the renderer definition calling `FT_DEFINE_RENDERER' in the */
  993. /* following. */
  994. /* */
  995. /* When FT_CONFIG_OPTION_PIC is not defined the struct will be */
  996. /* allocated in the global scope (or the scope where the macro */
  997. /* is used). */
  998. /* */
  999. #ifndef FT_CONFIG_OPTION_PIC
  1000. #define FT_DECLARE_RENDERER( class_ ) \
  1001. FT_EXPORT_VAR( const FT_Renderer_Class ) class_;
  1002. #define FT_DEFINE_RENDERER( \
  1003. class_, \
  1004. flags_, \
  1005. size_, \
  1006. name_, \
  1007. version_, \
  1008. requires_, \
  1009. interface_, \
  1010. init_, \
  1011. done_, \
  1012. get_interface_, \
  1013. glyph_format_, \
  1014. render_glyph_, \
  1015. transform_glyph_, \
  1016. get_glyph_cbox_, \
  1017. set_mode_, \
  1018. raster_class_ ) \
  1019. FT_CALLBACK_TABLE_DEF \
  1020. const FT_Renderer_Class class_ = \
  1021. { \
  1022. FT_DEFINE_ROOT_MODULE( flags_, \
  1023. size_, \
  1024. name_, \
  1025. version_, \
  1026. requires_, \
  1027. interface_, \
  1028. init_, \
  1029. done_, \
  1030. get_interface_ ) \
  1031. glyph_format_, \
  1032. \
  1033. render_glyph_, \
  1034. transform_glyph_, \
  1035. get_glyph_cbox_, \
  1036. set_mode_, \
  1037. \
  1038. raster_class_ \
  1039. };
  1040. #else /* FT_CONFIG_OPTION_PIC */
  1041. #define FT_DECLARE_RENDERER( class_ ) FT_DECLARE_MODULE( class_ )
  1042. #define FT_DEFINE_RENDERER( \
  1043. class_, \
  1044. flags_, \
  1045. size_, \
  1046. name_, \
  1047. version_, \
  1048. requires_, \
  1049. interface_, \
  1050. init_, \
  1051. done_, \
  1052. get_interface_, \
  1053. glyph_format_, \
  1054. render_glyph_, \
  1055. transform_glyph_, \
  1056. get_glyph_cbox_, \
  1057. set_mode_, \
  1058. raster_class_ ) \
  1059. void \
  1060. FT_Destroy_Class_ ## class_( FT_Library library, \
  1061. FT_Module_Class* clazz ) \
  1062. { \
  1063. FT_Renderer_Class* rclazz = (FT_Renderer_Class*)clazz; \
  1064. FT_Memory memory = library->memory; \
  1065. \
  1066. \
  1067. class_ ## _pic_free( library ); \
  1068. if ( rclazz ) \
  1069. FT_FREE( rclazz ); \
  1070. } \
  1071. \
  1072. \
  1073. FT_Error \
  1074. FT_Create_Class_ ## class_( FT_Library library, \
  1075. FT_Module_Class** output_class ) \
  1076. { \
  1077. FT_Renderer_Class* clazz = NULL; \
  1078. FT_Error error; \
  1079. FT_Memory memory = library->memory; \
  1080. \
  1081. \
  1082. if ( FT_ALLOC( clazz, sizeof ( *clazz ) ) ) \
  1083. return error; \
  1084. \
  1085. error = class_ ## _pic_init( library ); \
  1086. if ( error ) \
  1087. { \
  1088. FT_FREE( clazz ); \
  1089. return error; \
  1090. } \
  1091. \
  1092. FT_DEFINE_ROOT_MODULE( flags_, \
  1093. size_, \
  1094. name_, \
  1095. version_, \
  1096. requires_, \
  1097. interface_, \
  1098. init_, \
  1099. done_, \
  1100. get_interface_ ) \
  1101. \
  1102. clazz->glyph_format = glyph_format_; \
  1103. \
  1104. clazz->render_glyph = render_glyph_; \
  1105. clazz->transform_glyph = transform_glyph_; \
  1106. clazz->get_glyph_cbox = get_glyph_cbox_; \
  1107. clazz->set_mode = set_mode_; \
  1108. \
  1109. clazz->raster_class = raster_class_; \
  1110. \
  1111. *output_class = (FT_Module_Class*)clazz; \
  1112. \
  1113. return FT_Err_Ok; \
  1114. }
  1115. #endif /* FT_CONFIG_OPTION_PIC */
  1116. /* PIC support macros for ftmodapi.h **/
  1117. #ifdef FT_CONFIG_OPTION_PIC
  1118. /*************************************************************************/
  1119. /* */
  1120. /* <FuncType> */
  1121. /* FT_Module_Creator */
  1122. /* */
  1123. /* <Description> */
  1124. /* A function used to create (allocate) a new module class object. */
  1125. /* The object's members are initialized, but the module itself is */
  1126. /* not. */
  1127. /* */
  1128. /* <Input> */
  1129. /* memory :: A handle to the memory manager. */
  1130. /* output_class :: Initialized with the newly allocated class. */
  1131. /* */
  1132. typedef FT_Error
  1133. (*FT_Module_Creator)( FT_Memory memory,
  1134. FT_Module_Class** output_class );
  1135. /*************************************************************************/
  1136. /* */
  1137. /* <FuncType> */
  1138. /* FT_Module_Destroyer */
  1139. /* */
  1140. /* <Description> */
  1141. /* A function used to destroy (deallocate) a module class object. */
  1142. /* */
  1143. /* <Input> */
  1144. /* memory :: A handle to the memory manager. */
  1145. /* clazz :: Module class to destroy. */
  1146. /* */
  1147. typedef void
  1148. (*FT_Module_Destroyer)( FT_Memory memory,
  1149. FT_Module_Class* clazz );
  1150. #endif
  1151. /*************************************************************************/
  1152. /* */
  1153. /* <Macro> */
  1154. /* FT_DECLARE_MODULE */
  1155. /* */
  1156. /* <Description> */
  1157. /* Used to create a forward declaration of a */
  1158. /* FT_Module_Class struct instance. */
  1159. /* */
  1160. /* <Macro> */
  1161. /* FT_DEFINE_MODULE */
  1162. /* */
  1163. /* <Description> */
  1164. /* Used to initialize an instance of an FT_Module_Class struct. */
  1165. /* */
  1166. /* When FT_CONFIG_OPTION_PIC is defined a `create' funtion needs to */
  1167. /* be called with a pointer where the allocated structure is */
  1168. /* returned. And when it is no longer needed a `destroy' function */
  1169. /* needs to be called to release that allocation. */
  1170. /* `fcinit.c' (ft_create_default_module_classes) already contains */
  1171. /* a mechanism to call these functions for the default modules */
  1172. /* described in `ftmodule.h'. */
  1173. /* */
  1174. /* Notice that the created `create' and `destroy' functions call */
  1175. /* `pic_init' and `pic_free' to allow you to manually allocate and */
  1176. /* initialize any additional global data, like a module specific */
  1177. /* interface, and put them in the global pic container defined in */
  1178. /* `ftpic.h'. If you don't need them just implement the functions as */
  1179. /* empty to resolve the link error. Also the `pic_init' and */
  1180. /* `pic_free' functions should be declared in `pic.h', to be referred */
  1181. /* by the module definition calling `FT_DEFINE_MODULE' in the */
  1182. /* following. */
  1183. /* */
  1184. /* When FT_CONFIG_OPTION_PIC is not defined the struct will be */
  1185. /* allocated in the global scope (or the scope where the macro */
  1186. /* is used). */
  1187. /* */
  1188. /* <Macro> */
  1189. /* FT_DEFINE_ROOT_MODULE */
  1190. /* */
  1191. /* <Description> */
  1192. /* Used to initialize an instance of an FT_Module_Class struct inside */
  1193. /* another struct that contains it or in a function that initializes */
  1194. /* that containing struct. */
  1195. /* */
  1196. #ifndef FT_CONFIG_OPTION_PIC
  1197. #define FT_DECLARE_MODULE( class_ ) \
  1198. FT_CALLBACK_TABLE \
  1199. const FT_Module_Class class_;
  1200. #define FT_DEFINE_ROOT_MODULE( \
  1201. flags_, \
  1202. size_, \
  1203. name_, \
  1204. version_, \
  1205. requires_, \
  1206. interface_, \
  1207. init_, \
  1208. done_, \
  1209. get_interface_ ) \
  1210. { \
  1211. flags_, \
  1212. size_, \
  1213. \
  1214. name_, \
  1215. version_, \
  1216. requires_, \
  1217. \
  1218. interface_, \
  1219. \
  1220. init_, \
  1221. done_, \
  1222. get_interface_, \
  1223. },
  1224. #define FT_DEFINE_MODULE( \
  1225. class_, \
  1226. flags_, \
  1227. size_, \
  1228. name_, \
  1229. version_, \
  1230. requires_, \
  1231. interface_, \
  1232. init_, \
  1233. done_, \
  1234. get_interface_ ) \
  1235. FT_CALLBACK_TABLE_DEF \
  1236. const FT_Module_Class class_ = \
  1237. { \
  1238. flags_, \
  1239. size_, \
  1240. \
  1241. name_, \
  1242. version_, \
  1243. requires_, \
  1244. \
  1245. interface_, \
  1246. \
  1247. init_, \
  1248. done_, \
  1249. get_interface_, \
  1250. };
  1251. #else /* FT_CONFIG_OPTION_PIC */
  1252. #define FT_DECLARE_MODULE( class_ ) \
  1253. FT_Error \
  1254. FT_Create_Class_ ## class_( FT_Library library, \
  1255. FT_Module_Class** output_class ); \
  1256. void \
  1257. FT_Destroy_Class_ ## class_( FT_Library library, \
  1258. FT_Module_Class* clazz );
  1259. #define FT_DEFINE_ROOT_MODULE( \
  1260. flags_, \
  1261. size_, \
  1262. name_, \
  1263. version_, \
  1264. requires_, \
  1265. interface_, \
  1266. init_, \
  1267. done_, \
  1268. get_interface_ ) \
  1269. clazz->root.module_flags = flags_; \
  1270. clazz->root.module_size = size_; \
  1271. clazz->root.module_name = name_; \
  1272. clazz->root.module_version = version_; \
  1273. clazz->root.module_requires = requires_; \
  1274. \
  1275. clazz->root.module_interface = interface_; \
  1276. \
  1277. clazz->root.module_init = init_; \
  1278. clazz->root.module_done = done_; \
  1279. clazz->root.get_interface = get_interface_;
  1280. #define FT_DEFINE_MODULE( \
  1281. class_, \
  1282. flags_, \
  1283. size_, \
  1284. name_, \
  1285. version_, \
  1286. requires_, \
  1287. interface_, \
  1288. init_, \
  1289. done_, \
  1290. get_interface_ ) \
  1291. void \
  1292. FT_Destroy_Class_ ## class_( FT_Library library, \
  1293. FT_Module_Class* clazz ) \
  1294. { \
  1295. FT_Memory memory = library->memory; \
  1296. \
  1297. \
  1298. class_ ## _pic_free( library ); \
  1299. if ( clazz ) \
  1300. FT_FREE( clazz ); \
  1301. } \
  1302. \
  1303. \
  1304. FT_Error \
  1305. FT_Create_Class_ ## class_( FT_Library library, \
  1306. FT_Module_Class** output_class ) \
  1307. { \
  1308. FT_Memory memory = library->memory; \
  1309. FT_Module_Class* clazz = NULL; \
  1310. FT_Error error; \
  1311. \
  1312. \
  1313. if ( FT_ALLOC( clazz, sizeof ( *clazz ) ) ) \
  1314. return error; \
  1315. error = class_ ## _pic_init( library ); \
  1316. if ( error ) \
  1317. { \
  1318. FT_FREE( clazz ); \
  1319. return error; \
  1320. } \
  1321. \
  1322. clazz->module_flags = flags_; \
  1323. clazz->module_size = size_; \
  1324. clazz->module_name = name_; \
  1325. clazz->module_version = version_; \
  1326. clazz->module_requires = requires_; \
  1327. \
  1328. clazz->module_interface = interface_; \
  1329. \
  1330. clazz->module_init = init_; \
  1331. clazz->module_done = done_; \
  1332. clazz->get_interface = get_interface_; \
  1333. \
  1334. *output_class = clazz; \
  1335. \
  1336. return FT_Err_Ok; \
  1337. }
  1338. #endif /* FT_CONFIG_OPTION_PIC */
  1339. FT_END_HEADER
  1340. #endif /* __FTOBJS_H__ */
  1341. /* END */