ftcache.h 33 KB

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