ftcache.h 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  1. /***************************************************************************/
  2. /* */
  3. /* ftcache.h */
  4. /* */
  5. /* FreeType Cache subsystem (specification). */
  6. /* */
  7. /* Copyright 1996-2008, 2010, 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 __FTCACHE_H__
  18. #define __FTCACHE_H__
  19. #include <ft2build.h>
  20. #include FT_GLYPH_H
  21. FT_BEGIN_HEADER
  22. /*************************************************************************
  23. *
  24. * <Section>
  25. * cache_subsystem
  26. *
  27. * <Title>
  28. * Cache Sub-System
  29. *
  30. * <Abstract>
  31. * How to cache face, size, and glyph data with FreeType~2.
  32. *
  33. * <Description>
  34. * This section describes the FreeType~2 cache sub-system, which is used
  35. * to limit the number of concurrently opened @FT_Face and @FT_Size
  36. * objects, as well as caching information like character maps and glyph
  37. * images while limiting their maximum memory usage.
  38. *
  39. * Note that all types and functions begin with the `FTC_' prefix.
  40. *
  41. * The cache is highly portable and thus doesn't know anything about the
  42. * fonts installed on your system, or how to access them. This implies
  43. * the following scheme:
  44. *
  45. * First, available or installed font faces are uniquely identified by
  46. * @FTC_FaceID values, provided to the cache by the client. Note that
  47. * the cache only stores and compares these values, and doesn't try to
  48. * interpret them in any way.
  49. *
  50. * Second, the cache calls, only when needed, a client-provided function
  51. * to convert an @FTC_FaceID into a new @FT_Face object. The latter is
  52. * then completely managed by the cache, including its termination
  53. * through @FT_Done_Face. To monitor termination of face objects, the
  54. * finalizer callback in the `generic' field of the @FT_Face object can
  55. * be used, which might also be used to store the @FTC_FaceID of the
  56. * face.
  57. *
  58. * Clients are free to map face IDs to anything else. The most simple
  59. * usage is to associate them to a (pathname,face_index) pair that is
  60. * used to call @FT_New_Face. However, more complex schemes are also
  61. * possible.
  62. *
  63. * Note that for the cache to work correctly, the face ID values must be
  64. * *persistent*, which means that the contents they point to should not
  65. * change at runtime, or that their value should not become invalid.
  66. *
  67. * If this is unavoidable (e.g., when a font is uninstalled at runtime),
  68. * you should call @FTC_Manager_RemoveFaceID as soon as possible, to let
  69. * the cache get rid of any references to the old @FTC_FaceID it may
  70. * keep internally. Failure to do so will lead to incorrect behaviour
  71. * or even crashes.
  72. *
  73. * To use the cache, start with calling @FTC_Manager_New to create a new
  74. * @FTC_Manager object, which models a single cache instance. You can
  75. * then look up @FT_Face and @FT_Size objects with
  76. * @FTC_Manager_LookupFace and @FTC_Manager_LookupSize, respectively.
  77. *
  78. * If you want to use the charmap caching, call @FTC_CMapCache_New, then
  79. * later use @FTC_CMapCache_Lookup to perform the equivalent of
  80. * @FT_Get_Char_Index, only much faster.
  81. *
  82. * If you want to use the @FT_Glyph caching, call @FTC_ImageCache, then
  83. * later use @FTC_ImageCache_Lookup to retrieve the corresponding
  84. * @FT_Glyph objects from the cache.
  85. *
  86. * If you need lots of small bitmaps, it is much more memory efficient
  87. * to call @FTC_SBitCache_New followed by @FTC_SBitCache_Lookup. This
  88. * returns @FTC_SBitRec structures, which are used to store small
  89. * bitmaps directly. (A small bitmap is one whose metrics and
  90. * dimensions all fit into 8-bit integers).
  91. *
  92. * We hope to also provide a kerning cache in the near future.
  93. *
  94. *
  95. * <Order>
  96. * FTC_Manager
  97. * FTC_FaceID
  98. * FTC_Face_Requester
  99. *
  100. * FTC_Manager_New
  101. * FTC_Manager_Reset
  102. * FTC_Manager_Done
  103. * FTC_Manager_LookupFace
  104. * FTC_Manager_LookupSize
  105. * FTC_Manager_RemoveFaceID
  106. *
  107. * FTC_Node
  108. * FTC_Node_Unref
  109. *
  110. * FTC_ImageCache
  111. * FTC_ImageCache_New
  112. * FTC_ImageCache_Lookup
  113. *
  114. * FTC_SBit
  115. * FTC_SBitCache
  116. * FTC_SBitCache_New
  117. * FTC_SBitCache_Lookup
  118. *
  119. * FTC_CMapCache
  120. * FTC_CMapCache_New
  121. * FTC_CMapCache_Lookup
  122. *
  123. *************************************************************************/
  124. /*************************************************************************/
  125. /*************************************************************************/
  126. /*************************************************************************/
  127. /***** *****/
  128. /***** BASIC TYPE DEFINITIONS *****/
  129. /***** *****/
  130. /*************************************************************************/
  131. /*************************************************************************/
  132. /*************************************************************************/
  133. /*************************************************************************
  134. *
  135. * @type: FTC_FaceID
  136. *
  137. * @description:
  138. * An opaque pointer type that is used to identity face objects. The
  139. * contents of such objects is application-dependent.
  140. *
  141. * These pointers are typically used to point to a user-defined
  142. * structure containing a font file path, and face index.
  143. *
  144. * @note:
  145. * Never use NULL as a valid @FTC_FaceID.
  146. *
  147. * Face IDs are passed by the client to the cache manager that calls,
  148. * when needed, the @FTC_Face_Requester to translate them into new
  149. * @FT_Face objects.
  150. *
  151. * If the content of a given face ID changes at runtime, or if the value
  152. * becomes invalid (e.g., when uninstalling a font), you should
  153. * immediately call @FTC_Manager_RemoveFaceID before any other cache
  154. * function.
  155. *
  156. * Failure to do so will result in incorrect behaviour or even
  157. * memory leaks and crashes.
  158. */
  159. typedef FT_Pointer FTC_FaceID;
  160. /************************************************************************
  161. *
  162. * @functype:
  163. * FTC_Face_Requester
  164. *
  165. * @description:
  166. * A callback function provided by client applications. It is used by
  167. * the cache manager to translate a given @FTC_FaceID into a new valid
  168. * @FT_Face object, on demand.
  169. *
  170. * <Input>
  171. * face_id ::
  172. * The face ID to resolve.
  173. *
  174. * library ::
  175. * A handle to a FreeType library object.
  176. *
  177. * req_data ::
  178. * Application-provided request data (see note below).
  179. *
  180. * <Output>
  181. * aface ::
  182. * A new @FT_Face handle.
  183. *
  184. * <Return>
  185. * FreeType error code. 0~means success.
  186. *
  187. * <Note>
  188. * The third parameter `req_data' is the same as the one passed by the
  189. * client when @FTC_Manager_New is called.
  190. *
  191. * The face requester should not perform funny things on the returned
  192. * face object, like creating a new @FT_Size for it, or setting a
  193. * transformation through @FT_Set_Transform!
  194. */
  195. typedef FT_Error
  196. (*FTC_Face_Requester)( FTC_FaceID face_id,
  197. FT_Library library,
  198. FT_Pointer request_data,
  199. FT_Face* aface );
  200. /* */
  201. /*************************************************************************/
  202. /*************************************************************************/
  203. /*************************************************************************/
  204. /***** *****/
  205. /***** CACHE MANAGER OBJECT *****/
  206. /***** *****/
  207. /*************************************************************************/
  208. /*************************************************************************/
  209. /*************************************************************************/
  210. /*************************************************************************/
  211. /* */
  212. /* <Type> */
  213. /* FTC_Manager */
  214. /* */
  215. /* <Description> */
  216. /* This object corresponds to one instance of the cache-subsystem. */
  217. /* It is used to cache one or more @FT_Face objects, along with */
  218. /* corresponding @FT_Size objects. */
  219. /* */
  220. /* The manager intentionally limits the total number of opened */
  221. /* @FT_Face and @FT_Size objects to control memory usage. See the */
  222. /* `max_faces' and `max_sizes' parameters of @FTC_Manager_New. */
  223. /* */
  224. /* The manager is also used to cache `nodes' of various types while */
  225. /* limiting their total memory usage. */
  226. /* */
  227. /* All limitations are enforced by keeping lists of managed objects */
  228. /* in most-recently-used order, and flushing old nodes to make room */
  229. /* for new ones. */
  230. /* */
  231. typedef struct FTC_ManagerRec_* FTC_Manager;
  232. /*************************************************************************/
  233. /* */
  234. /* <Type> */
  235. /* FTC_Node */
  236. /* */
  237. /* <Description> */
  238. /* An opaque handle to a cache node object. Each cache node is */
  239. /* reference-counted. A node with a count of~0 might be flushed */
  240. /* out of a full cache whenever a lookup request is performed. */
  241. /* */
  242. /* If you look up nodes, you have the ability to `acquire' them, */
  243. /* i.e., to increment their reference count. This will prevent the */
  244. /* node from being flushed out of the cache until you explicitly */
  245. /* `release' it (see @FTC_Node_Unref). */
  246. /* */
  247. /* See also @FTC_SBitCache_Lookup and @FTC_ImageCache_Lookup. */
  248. /* */
  249. typedef struct FTC_NodeRec_* FTC_Node;
  250. /*************************************************************************/
  251. /* */
  252. /* <Function> */
  253. /* FTC_Manager_New */
  254. /* */
  255. /* <Description> */
  256. /* Create a new cache manager. */
  257. /* */
  258. /* <Input> */
  259. /* library :: The parent FreeType library handle to use. */
  260. /* */
  261. /* max_faces :: Maximum number of opened @FT_Face objects managed by */
  262. /* this cache instance. Use~0 for defaults. */
  263. /* */
  264. /* max_sizes :: Maximum number of opened @FT_Size objects managed by */
  265. /* this cache instance. Use~0 for defaults. */
  266. /* */
  267. /* max_bytes :: Maximum number of bytes to use for cached data nodes. */
  268. /* Use~0 for defaults. Note that this value does not */
  269. /* account for managed @FT_Face and @FT_Size objects. */
  270. /* */
  271. /* requester :: An application-provided callback used to translate */
  272. /* face IDs into real @FT_Face objects. */
  273. /* */
  274. /* req_data :: A generic pointer that is passed to the requester */
  275. /* each time it is called (see @FTC_Face_Requester). */
  276. /* */
  277. /* <Output> */
  278. /* amanager :: A handle to a new manager object. 0~in case of */
  279. /* failure. */
  280. /* */
  281. /* <Return> */
  282. /* FreeType error code. 0~means success. */
  283. /* */
  284. FT_EXPORT( FT_Error )
  285. FTC_Manager_New( FT_Library library,
  286. FT_UInt max_faces,
  287. FT_UInt max_sizes,
  288. FT_ULong max_bytes,
  289. FTC_Face_Requester requester,
  290. FT_Pointer req_data,
  291. FTC_Manager *amanager );
  292. /*************************************************************************/
  293. /* */
  294. /* <Function> */
  295. /* FTC_Manager_Reset */
  296. /* */
  297. /* <Description> */
  298. /* Empty a given cache manager. This simply gets rid of all the */
  299. /* currently cached @FT_Face and @FT_Size objects within the manager. */
  300. /* */
  301. /* <InOut> */
  302. /* manager :: A handle to the manager. */
  303. /* */
  304. FT_EXPORT( void )
  305. FTC_Manager_Reset( FTC_Manager manager );
  306. /*************************************************************************/
  307. /* */
  308. /* <Function> */
  309. /* FTC_Manager_Done */
  310. /* */
  311. /* <Description> */
  312. /* Destroy a given manager after emptying it. */
  313. /* */
  314. /* <Input> */
  315. /* manager :: A handle to the target cache manager object. */
  316. /* */
  317. FT_EXPORT( void )
  318. FTC_Manager_Done( FTC_Manager manager );
  319. /*************************************************************************/
  320. /* */
  321. /* <Function> */
  322. /* FTC_Manager_LookupFace */
  323. /* */
  324. /* <Description> */
  325. /* Retrieve the @FT_Face object that corresponds to a given face ID */
  326. /* through a cache manager. */
  327. /* */
  328. /* <Input> */
  329. /* manager :: A handle to the cache manager. */
  330. /* */
  331. /* face_id :: The ID of the face object. */
  332. /* */
  333. /* <Output> */
  334. /* aface :: A handle to the face object. */
  335. /* */
  336. /* <Return> */
  337. /* FreeType error code. 0~means success. */
  338. /* */
  339. /* <Note> */
  340. /* The returned @FT_Face object is always owned by the manager. You */
  341. /* should never try to discard it yourself. */
  342. /* */
  343. /* The @FT_Face object doesn't necessarily have a current size object */
  344. /* (i.e., face->size can be~0). If you need a specific `font size', */
  345. /* use @FTC_Manager_LookupSize instead. */
  346. /* */
  347. /* Never change the face's transformation matrix (i.e., never call */
  348. /* the @FT_Set_Transform function) on a returned face! If you need */
  349. /* to transform glyphs, do it yourself after glyph loading. */
  350. /* */
  351. /* When you perform a lookup, out-of-memory errors are detected */
  352. /* _within_ the lookup and force incremental flushes of the cache */
  353. /* until enough memory is released for the lookup to succeed. */
  354. /* */
  355. /* If a lookup fails with `FT_Err_Out_Of_Memory' the cache has */
  356. /* already been completely flushed, and still no memory was available */
  357. /* for the operation. */
  358. /* */
  359. FT_EXPORT( FT_Error )
  360. FTC_Manager_LookupFace( FTC_Manager manager,
  361. FTC_FaceID face_id,
  362. FT_Face *aface );
  363. /*************************************************************************/
  364. /* */
  365. /* <Struct> */
  366. /* FTC_ScalerRec */
  367. /* */
  368. /* <Description> */
  369. /* A structure used to describe a given character size in either */
  370. /* pixels or points to the cache manager. See */
  371. /* @FTC_Manager_LookupSize. */
  372. /* */
  373. /* <Fields> */
  374. /* face_id :: The source face ID. */
  375. /* */
  376. /* width :: The character width. */
  377. /* */
  378. /* height :: The character height. */
  379. /* */
  380. /* pixel :: A Boolean. If 1, the `width' and `height' fields are */
  381. /* interpreted as integer pixel character sizes. */
  382. /* Otherwise, they are expressed as 1/64th of points. */
  383. /* */
  384. /* x_res :: Only used when `pixel' is value~0 to indicate the */
  385. /* horizontal resolution in dpi. */
  386. /* */
  387. /* y_res :: Only used when `pixel' is value~0 to indicate the */
  388. /* vertical resolution in dpi. */
  389. /* */
  390. /* <Note> */
  391. /* This type is mainly used to retrieve @FT_Size objects through the */
  392. /* cache manager. */
  393. /* */
  394. typedef struct FTC_ScalerRec_
  395. {
  396. FTC_FaceID face_id;
  397. FT_UInt width;
  398. FT_UInt height;
  399. FT_Int pixel;
  400. FT_UInt x_res;
  401. FT_UInt y_res;
  402. } FTC_ScalerRec;
  403. /*************************************************************************/
  404. /* */
  405. /* <Struct> */
  406. /* FTC_Scaler */
  407. /* */
  408. /* <Description> */
  409. /* A handle to an @FTC_ScalerRec structure. */
  410. /* */
  411. typedef struct FTC_ScalerRec_* FTC_Scaler;
  412. /*************************************************************************/
  413. /* */
  414. /* <Function> */
  415. /* FTC_Manager_LookupSize */
  416. /* */
  417. /* <Description> */
  418. /* Retrieve the @FT_Size object that corresponds to a given */
  419. /* @FTC_ScalerRec pointer through a cache manager. */
  420. /* */
  421. /* <Input> */
  422. /* manager :: A handle to the cache manager. */
  423. /* */
  424. /* scaler :: A scaler handle. */
  425. /* */
  426. /* <Output> */
  427. /* asize :: A handle to the size object. */
  428. /* */
  429. /* <Return> */
  430. /* FreeType error code. 0~means success. */
  431. /* */
  432. /* <Note> */
  433. /* The returned @FT_Size object is always owned by the manager. You */
  434. /* should never try to discard it by yourself. */
  435. /* */
  436. /* You can access the parent @FT_Face object simply as `size->face' */
  437. /* if you need it. Note that this object is also owned by the */
  438. /* manager. */
  439. /* */
  440. /* <Note> */
  441. /* When you perform a lookup, out-of-memory errors are detected */
  442. /* _within_ the lookup and force incremental flushes of the cache */
  443. /* until enough memory is released for the lookup to succeed. */
  444. /* */
  445. /* If a lookup fails with `FT_Err_Out_Of_Memory' the cache has */
  446. /* already been completely flushed, and still no memory is available */
  447. /* for the operation. */
  448. /* */
  449. FT_EXPORT( FT_Error )
  450. FTC_Manager_LookupSize( FTC_Manager manager,
  451. FTC_Scaler scaler,
  452. FT_Size *asize );
  453. /*************************************************************************/
  454. /* */
  455. /* <Function> */
  456. /* FTC_Node_Unref */
  457. /* */
  458. /* <Description> */
  459. /* Decrement a cache node's internal reference count. When the count */
  460. /* reaches 0, it is not destroyed but becomes eligible for subsequent */
  461. /* cache flushes. */
  462. /* */
  463. /* <Input> */
  464. /* node :: The cache node handle. */
  465. /* */
  466. /* manager :: The cache manager handle. */
  467. /* */
  468. FT_EXPORT( void )
  469. FTC_Node_Unref( FTC_Node node,
  470. FTC_Manager manager );
  471. /*************************************************************************
  472. *
  473. * @function:
  474. * FTC_Manager_RemoveFaceID
  475. *
  476. * @description:
  477. * A special function used to indicate to the cache manager that
  478. * a given @FTC_FaceID is no longer valid, either because its
  479. * content changed, or because it was deallocated or uninstalled.
  480. *
  481. * @input:
  482. * manager ::
  483. * The cache manager handle.
  484. *
  485. * face_id ::
  486. * The @FTC_FaceID to be removed.
  487. *
  488. * @note:
  489. * This function flushes all nodes from the cache corresponding to this
  490. * `face_id', with the exception of nodes with a non-null reference
  491. * count.
  492. *
  493. * Such nodes are however modified internally so as to never appear
  494. * in later lookups with the same `face_id' value, and to be immediately
  495. * destroyed when released by all their users.
  496. *
  497. */
  498. FT_EXPORT( void )
  499. FTC_Manager_RemoveFaceID( FTC_Manager manager,
  500. FTC_FaceID face_id );
  501. /*************************************************************************/
  502. /* */
  503. /* <Section> */
  504. /* cache_subsystem */
  505. /* */
  506. /*************************************************************************/
  507. /*************************************************************************
  508. *
  509. * @type:
  510. * FTC_CMapCache
  511. *
  512. * @description:
  513. * An opaque handle used to model a charmap cache. This cache is to
  514. * hold character codes -> glyph indices mappings.
  515. *
  516. */
  517. typedef struct FTC_CMapCacheRec_* FTC_CMapCache;
  518. /*************************************************************************
  519. *
  520. * @function:
  521. * FTC_CMapCache_New
  522. *
  523. * @description:
  524. * Create a new charmap cache.
  525. *
  526. * @input:
  527. * manager ::
  528. * A handle to the cache manager.
  529. *
  530. * @output:
  531. * acache ::
  532. * A new cache handle. NULL in case of error.
  533. *
  534. * @return:
  535. * FreeType error code. 0~means success.
  536. *
  537. * @note:
  538. * Like all other caches, this one will be destroyed with the cache
  539. * manager.
  540. *
  541. */
  542. FT_EXPORT( FT_Error )
  543. FTC_CMapCache_New( FTC_Manager manager,
  544. FTC_CMapCache *acache );
  545. /************************************************************************
  546. *
  547. * @function:
  548. * FTC_CMapCache_Lookup
  549. *
  550. * @description:
  551. * Translate a character code into a glyph index, using the charmap
  552. * cache.
  553. *
  554. * @input:
  555. * cache ::
  556. * A charmap cache handle.
  557. *
  558. * face_id ::
  559. * The source face ID.
  560. *
  561. * cmap_index ::
  562. * The index of the charmap in the source face. Any negative value
  563. * means to use the cache @FT_Face's default charmap.
  564. *
  565. * char_code ::
  566. * The character code (in the corresponding charmap).
  567. *
  568. * @return:
  569. * Glyph index. 0~means `no glyph'.
  570. *
  571. */
  572. FT_EXPORT( FT_UInt )
  573. FTC_CMapCache_Lookup( FTC_CMapCache cache,
  574. FTC_FaceID face_id,
  575. FT_Int cmap_index,
  576. FT_UInt32 char_code );
  577. /*************************************************************************/
  578. /* */
  579. /* <Section> */
  580. /* cache_subsystem */
  581. /* */
  582. /*************************************************************************/
  583. /*************************************************************************/
  584. /*************************************************************************/
  585. /*************************************************************************/
  586. /***** *****/
  587. /***** IMAGE CACHE OBJECT *****/
  588. /***** *****/
  589. /*************************************************************************/
  590. /*************************************************************************/
  591. /*************************************************************************/
  592. /*************************************************************************
  593. *
  594. * @struct:
  595. * FTC_ImageTypeRec
  596. *
  597. * @description:
  598. * A structure used to model the type of images in a glyph cache.
  599. *
  600. * @fields:
  601. * face_id ::
  602. * The face ID.
  603. *
  604. * width ::
  605. * The width in pixels.
  606. *
  607. * height ::
  608. * The height in pixels.
  609. *
  610. * flags ::
  611. * The load flags, as in @FT_Load_Glyph.
  612. *
  613. */
  614. typedef struct FTC_ImageTypeRec_
  615. {
  616. FTC_FaceID face_id;
  617. FT_Int width;
  618. FT_Int height;
  619. FT_Int32 flags;
  620. } FTC_ImageTypeRec;
  621. /*************************************************************************
  622. *
  623. * @type:
  624. * FTC_ImageType
  625. *
  626. * @description:
  627. * A handle to an @FTC_ImageTypeRec structure.
  628. *
  629. */
  630. typedef struct FTC_ImageTypeRec_* FTC_ImageType;
  631. /* */
  632. #define FTC_IMAGE_TYPE_COMPARE( d1, d2 ) \
  633. ( (d1)->face_id == (d2)->face_id && \
  634. (d1)->width == (d2)->width && \
  635. (d1)->flags == (d2)->flags )
  636. /*************************************************************************/
  637. /* */
  638. /* <Type> */
  639. /* FTC_ImageCache */
  640. /* */
  641. /* <Description> */
  642. /* A handle to a glyph image cache object. They are designed to */
  643. /* hold many distinct glyph images while not exceeding a certain */
  644. /* memory threshold. */
  645. /* */
  646. typedef struct FTC_ImageCacheRec_* FTC_ImageCache;
  647. /*************************************************************************/
  648. /* */
  649. /* <Function> */
  650. /* FTC_ImageCache_New */
  651. /* */
  652. /* <Description> */
  653. /* Create a new glyph image cache. */
  654. /* */
  655. /* <Input> */
  656. /* manager :: The parent manager for the image cache. */
  657. /* */
  658. /* <Output> */
  659. /* acache :: A handle to the new glyph image cache object. */
  660. /* */
  661. /* <Return> */
  662. /* FreeType error code. 0~means success. */
  663. /* */
  664. FT_EXPORT( FT_Error )
  665. FTC_ImageCache_New( FTC_Manager manager,
  666. FTC_ImageCache *acache );
  667. /*************************************************************************/
  668. /* */
  669. /* <Function> */
  670. /* FTC_ImageCache_Lookup */
  671. /* */
  672. /* <Description> */
  673. /* Retrieve a given glyph image from a glyph image cache. */
  674. /* */
  675. /* <Input> */
  676. /* cache :: A handle to the source glyph image cache. */
  677. /* */
  678. /* type :: A pointer to a glyph image type descriptor. */
  679. /* */
  680. /* gindex :: The glyph index to retrieve. */
  681. /* */
  682. /* <Output> */
  683. /* aglyph :: The corresponding @FT_Glyph object. 0~in case of */
  684. /* failure. */
  685. /* */
  686. /* anode :: Used to return the address of of the corresponding cache */
  687. /* node after incrementing its reference count (see note */
  688. /* below). */
  689. /* */
  690. /* <Return> */
  691. /* FreeType error code. 0~means success. */
  692. /* */
  693. /* <Note> */
  694. /* The returned glyph is owned and managed by the glyph image cache. */
  695. /* Never try to transform or discard it manually! You can however */
  696. /* create a copy with @FT_Glyph_Copy and modify the new one. */
  697. /* */
  698. /* If `anode' is _not_ NULL, it receives the address of the cache */
  699. /* node containing the glyph image, after increasing its reference */
  700. /* count. This ensures that the node (as well as the @FT_Glyph) will */
  701. /* always be kept in the cache until you call @FTC_Node_Unref to */
  702. /* `release' it. */
  703. /* */
  704. /* If `anode' is NULL, the cache node is left unchanged, which means */
  705. /* that the @FT_Glyph could be flushed out of the cache on the next */
  706. /* call to one of the caching sub-system APIs. Don't assume that it */
  707. /* is persistent! */
  708. /* */
  709. FT_EXPORT( FT_Error )
  710. FTC_ImageCache_Lookup( FTC_ImageCache cache,
  711. FTC_ImageType type,
  712. FT_UInt gindex,
  713. FT_Glyph *aglyph,
  714. FTC_Node *anode );
  715. /*************************************************************************/
  716. /* */
  717. /* <Function> */
  718. /* FTC_ImageCache_LookupScaler */
  719. /* */
  720. /* <Description> */
  721. /* A variant of @FTC_ImageCache_Lookup that uses an @FTC_ScalerRec */
  722. /* to specify the face ID and its size. */
  723. /* */
  724. /* <Input> */
  725. /* cache :: A handle to the source glyph image cache. */
  726. /* */
  727. /* scaler :: A pointer to a scaler descriptor. */
  728. /* */
  729. /* load_flags :: The corresponding load flags. */
  730. /* */
  731. /* gindex :: The glyph index to retrieve. */
  732. /* */
  733. /* <Output> */
  734. /* aglyph :: The corresponding @FT_Glyph object. 0~in case of */
  735. /* failure. */
  736. /* */
  737. /* anode :: Used to return the address of of the corresponding */
  738. /* cache node after incrementing its reference count */
  739. /* (see note below). */
  740. /* */
  741. /* <Return> */
  742. /* FreeType error code. 0~means success. */
  743. /* */
  744. /* <Note> */
  745. /* The returned glyph is owned and managed by the glyph image cache. */
  746. /* Never try to transform or discard it manually! You can however */
  747. /* create a copy with @FT_Glyph_Copy and modify the new one. */
  748. /* */
  749. /* If `anode' is _not_ NULL, it receives the address of the cache */
  750. /* node containing the glyph image, after increasing its reference */
  751. /* count. This ensures that the node (as well as the @FT_Glyph) will */
  752. /* always be kept in the cache until you call @FTC_Node_Unref to */
  753. /* `release' it. */
  754. /* */
  755. /* If `anode' is NULL, the cache node is left unchanged, which means */
  756. /* that the @FT_Glyph could be flushed out of the cache on the next */
  757. /* call to one of the caching sub-system APIs. Don't assume that it */
  758. /* is persistent! */
  759. /* */
  760. /* Calls to @FT_Set_Char_Size and friends have no effect on cached */
  761. /* glyphs; you should always use the FreeType cache API instead. */
  762. /* */
  763. FT_EXPORT( FT_Error )
  764. FTC_ImageCache_LookupScaler( FTC_ImageCache cache,
  765. FTC_Scaler scaler,
  766. FT_ULong load_flags,
  767. FT_UInt gindex,
  768. FT_Glyph *aglyph,
  769. FTC_Node *anode );
  770. /*************************************************************************/
  771. /* */
  772. /* <Type> */
  773. /* FTC_SBit */
  774. /* */
  775. /* <Description> */
  776. /* A handle to a small bitmap descriptor. See the @FTC_SBitRec */
  777. /* structure for details. */
  778. /* */
  779. typedef struct FTC_SBitRec_* FTC_SBit;
  780. /*************************************************************************/
  781. /* */
  782. /* <Struct> */
  783. /* FTC_SBitRec */
  784. /* */
  785. /* <Description> */
  786. /* A very compact structure used to describe a small glyph bitmap. */
  787. /* */
  788. /* <Fields> */
  789. /* width :: The bitmap width in pixels. */
  790. /* */
  791. /* height :: The bitmap height in pixels. */
  792. /* */
  793. /* left :: The horizontal distance from the pen position to the */
  794. /* left bitmap border (a.k.a. `left side bearing', or */
  795. /* `lsb'). */
  796. /* */
  797. /* top :: The vertical distance from the pen position (on the */
  798. /* baseline) to the upper bitmap border (a.k.a. `top */
  799. /* side bearing'). The distance is positive for upwards */
  800. /* y~coordinates. */
  801. /* */
  802. /* format :: The format of the glyph bitmap (monochrome or gray). */
  803. /* */
  804. /* max_grays :: Maximum gray level value (in the range 1 to~255). */
  805. /* */
  806. /* pitch :: The number of bytes per bitmap line. May be positive */
  807. /* or negative. */
  808. /* */
  809. /* xadvance :: The horizontal advance width in pixels. */
  810. /* */
  811. /* yadvance :: The vertical advance height in pixels. */
  812. /* */
  813. /* buffer :: A pointer to the bitmap pixels. */
  814. /* */
  815. typedef struct FTC_SBitRec_
  816. {
  817. FT_Byte width;
  818. FT_Byte height;
  819. FT_Char left;
  820. FT_Char top;
  821. FT_Byte format;
  822. FT_Byte max_grays;
  823. FT_Short pitch;
  824. FT_Char xadvance;
  825. FT_Char yadvance;
  826. FT_Byte* buffer;
  827. } FTC_SBitRec;
  828. /*************************************************************************/
  829. /* */
  830. /* <Type> */
  831. /* FTC_SBitCache */
  832. /* */
  833. /* <Description> */
  834. /* A handle to a small bitmap cache. These are special cache objects */
  835. /* used to store small glyph bitmaps (and anti-aliased pixmaps) in a */
  836. /* much more efficient way than the traditional glyph image cache */
  837. /* implemented by @FTC_ImageCache. */
  838. /* */
  839. typedef struct FTC_SBitCacheRec_* FTC_SBitCache;
  840. /*************************************************************************/
  841. /* */
  842. /* <Function> */
  843. /* FTC_SBitCache_New */
  844. /* */
  845. /* <Description> */
  846. /* Create a new cache to store small glyph bitmaps. */
  847. /* */
  848. /* <Input> */
  849. /* manager :: A handle to the source cache manager. */
  850. /* */
  851. /* <Output> */
  852. /* acache :: A handle to the new sbit cache. NULL in case of error. */
  853. /* */
  854. /* <Return> */
  855. /* FreeType error code. 0~means success. */
  856. /* */
  857. FT_EXPORT( FT_Error )
  858. FTC_SBitCache_New( FTC_Manager manager,
  859. FTC_SBitCache *acache );
  860. /*************************************************************************/
  861. /* */
  862. /* <Function> */
  863. /* FTC_SBitCache_Lookup */
  864. /* */
  865. /* <Description> */
  866. /* Look up a given small glyph bitmap in a given sbit cache and */
  867. /* `lock' it to prevent its flushing from the cache until needed. */
  868. /* */
  869. /* <Input> */
  870. /* cache :: A handle to the source sbit cache. */
  871. /* */
  872. /* type :: A pointer to the glyph image type descriptor. */
  873. /* */
  874. /* gindex :: The glyph index. */
  875. /* */
  876. /* <Output> */
  877. /* sbit :: A handle to a small bitmap descriptor. */
  878. /* */
  879. /* anode :: Used to return the address of of the corresponding cache */
  880. /* node after incrementing its reference count (see note */
  881. /* below). */
  882. /* */
  883. /* <Return> */
  884. /* FreeType error code. 0~means success. */
  885. /* */
  886. /* <Note> */
  887. /* The small bitmap descriptor and its bit buffer are owned by the */
  888. /* cache and should never be freed by the application. They might */
  889. /* as well disappear from memory on the next cache lookup, so don't */
  890. /* treat them as persistent data. */
  891. /* */
  892. /* The descriptor's `buffer' field is set to~0 to indicate a missing */
  893. /* glyph bitmap. */
  894. /* */
  895. /* If `anode' is _not_ NULL, it receives the address of the cache */
  896. /* node containing the bitmap, after increasing its reference count. */
  897. /* This ensures that the node (as well as the image) will always be */
  898. /* kept in the cache until you call @FTC_Node_Unref to `release' it. */
  899. /* */
  900. /* If `anode' is NULL, the cache node is left unchanged, which means */
  901. /* that the bitmap could be flushed out of the cache on the next */
  902. /* call to one of the caching sub-system APIs. Don't assume that it */
  903. /* is persistent! */
  904. /* */
  905. FT_EXPORT( FT_Error )
  906. FTC_SBitCache_Lookup( FTC_SBitCache cache,
  907. FTC_ImageType type,
  908. FT_UInt gindex,
  909. FTC_SBit *sbit,
  910. FTC_Node *anode );
  911. /*************************************************************************/
  912. /* */
  913. /* <Function> */
  914. /* FTC_SBitCache_LookupScaler */
  915. /* */
  916. /* <Description> */
  917. /* A variant of @FTC_SBitCache_Lookup that uses an @FTC_ScalerRec */
  918. /* to specify the face ID and its size. */
  919. /* */
  920. /* <Input> */
  921. /* cache :: A handle to the source sbit cache. */
  922. /* */
  923. /* scaler :: A pointer to the scaler descriptor. */
  924. /* */
  925. /* load_flags :: The corresponding load flags. */
  926. /* */
  927. /* gindex :: The glyph index. */
  928. /* */
  929. /* <Output> */
  930. /* sbit :: A handle to a small bitmap descriptor. */
  931. /* */
  932. /* anode :: Used to return the address of of the corresponding */
  933. /* cache node after incrementing its reference count */
  934. /* (see note below). */
  935. /* */
  936. /* <Return> */
  937. /* FreeType error code. 0~means success. */
  938. /* */
  939. /* <Note> */
  940. /* The small bitmap descriptor and its bit buffer are owned by the */
  941. /* cache and should never be freed by the application. They might */
  942. /* as well disappear from memory on the next cache lookup, so don't */
  943. /* treat them as persistent data. */
  944. /* */
  945. /* The descriptor's `buffer' field is set to~0 to indicate a missing */
  946. /* glyph bitmap. */
  947. /* */
  948. /* If `anode' is _not_ NULL, it receives the address of the cache */
  949. /* node containing the bitmap, after increasing its reference count. */
  950. /* This ensures that the node (as well as the image) will always be */
  951. /* kept in the cache until you call @FTC_Node_Unref to `release' it. */
  952. /* */
  953. /* If `anode' is NULL, the cache node is left unchanged, which means */
  954. /* that the bitmap could be flushed out of the cache on the next */
  955. /* call to one of the caching sub-system APIs. Don't assume that it */
  956. /* is persistent! */
  957. /* */
  958. FT_EXPORT( FT_Error )
  959. FTC_SBitCache_LookupScaler( FTC_SBitCache cache,
  960. FTC_Scaler scaler,
  961. FT_ULong load_flags,
  962. FT_UInt gindex,
  963. FTC_SBit *sbit,
  964. FTC_Node *anode );
  965. /* */
  966. FT_END_HEADER
  967. #endif /* __FTCACHE_H__ */
  968. /* END */