/Code/Angel/Libraries/freetype-2.3.7/include/freetype/ftcache.h

http://angel-engine.googlecode.com/ · C++ Header · 1121 lines · 154 code · 107 blank · 860 comment · 10 complexity · d36bc8142362e4272b94db2b6816681b MD5 · raw file

Large files are truncated click here to view the full file

  1. /***************************************************************************/
  2. /* */
  3. /* ftcache.h */
  4. /* */
  5. /* FreeType Cache subsystem (specification). */
  6. /* */
  7. /* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 by */
  8. /* David Turner, Robert Wilhelm, and Werner Lemberg. */
  9. /* */
  10. /* This file is part of the FreeType project, and may only be used, */
  11. /* modified, and distributed under the terms of the FreeType project */
  12. /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
  13. /* this file you indicate that you have read the license and */
  14. /* understand and accept it fully. */
  15. /* */
  16. /***************************************************************************/
  17. #ifndef __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 a @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.
  54. *
  55. * Clients are free to map face IDs to anything else. The most simple
  56. * usage is to associate them to a (pathname,face_index) pair that is
  57. * used to call @FT_New_Face. However, more complex schemes are also
  58. * possible.
  59. *
  60. * Note that for the cache to work correctly, the face ID values must be
  61. * *persistent*, which means that the contents they point to should not
  62. * change at runtime, or that their value should not become invalid.
  63. *
  64. * If this is unavoidable (e.g., when a font is uninstalled at runtime),
  65. * you should call @FTC_Manager_RemoveFaceID as soon as possible, to let
  66. * the cache get rid of any references to the old @FTC_FaceID it may
  67. * keep internally. Failure to do so will lead to incorrect behaviour
  68. * or even crashes.
  69. *
  70. * To use the cache, start with calling @FTC_Manager_New to create a new
  71. * @FTC_Manager object, which models a single cache instance. You can
  72. * then look up @FT_Face and @FT_Size objects with
  73. * @FTC_Manager_LookupFace and @FTC_Manager_LookupSize, respectively.
  74. *
  75. * If you want to use the charmap caching, call @FTC_CMapCache_New, then
  76. * later use @FTC_CMapCache_Lookup to perform the equivalent of
  77. * @FT_Get_Char_Index, only much faster.
  78. *
  79. * If you want to use the @FT_Glyph caching, call @FTC_ImageCache, then
  80. * later use @FTC_ImageCache_Lookup to retrieve the corresponding
  81. * @FT_Glyph objects from the cache.
  82. *
  83. * If you need lots of small bitmaps, it is much more memory efficient
  84. * to call @FTC_SBitCache_New followed by @FTC_SBitCache_Lookup. This
  85. * returns @FTC_SBitRec structures, which are used to store small
  86. * bitmaps directly. (A small bitmap is one whose metrics and
  87. * dimensions all fit into 8-bit integers).
  88. *
  89. * We hope to also provide a kerning cache in the near future.
  90. *
  91. *
  92. * <Order>
  93. * FTC_Manager
  94. * FTC_FaceID
  95. * FTC_Face_Requester
  96. *
  97. * FTC_Manager_New
  98. * FTC_Manager_Reset
  99. * FTC_Manager_Done
  100. * FTC_Manager_LookupFace
  101. * FTC_Manager_LookupSize
  102. * FTC_Manager_RemoveFaceID
  103. *
  104. * FTC_Node
  105. * FTC_Node_Unref
  106. *
  107. * FTC_ImageCache
  108. * FTC_ImageCache_New
  109. * FTC_ImageCache_Lookup
  110. *
  111. * FTC_SBit
  112. * FTC_SBitCache
  113. * FTC_SBitCache_New
  114. * FTC_SBitCache_Lookup
  115. *
  116. * FTC_CMapCache
  117. * FTC_CMapCache_New
  118. * FTC_CMapCache_Lookup
  119. *
  120. *************************************************************************/
  121. /*************************************************************************/
  122. /*************************************************************************/
  123. /*************************************************************************/
  124. /***** *****/
  125. /***** BASIC TYPE DEFINITIONS *****/
  126. /***** *****/
  127. /*************************************************************************/
  128. /*************************************************************************/
  129. /*************************************************************************/
  130. /*************************************************************************
  131. *
  132. * @type: FTC_FaceID
  133. *
  134. * @description:
  135. * An opaque pointer type that is used to identity face objects. The
  136. * contents of such objects is application-dependent.
  137. *
  138. * These pointers are typically used to point to a user-defined
  139. * structure containing a font file path, and face index.
  140. *
  141. * @note:
  142. * Never use NULL as a valid @FTC_FaceID.
  143. *
  144. * Face IDs are passed by the client to the cache manager, which calls,
  145. * when needed, the @FTC_Face_Requester to translate them into new
  146. * @FT_Face objects.
  147. *
  148. * If the content of a given face ID changes at runtime, or if the value
  149. * becomes invalid (e.g., when uninstalling a font), you should
  150. * immediately call @FTC_Manager_RemoveFaceID before any other cache
  151. * function.
  152. *
  153. * Failure to do so will result in incorrect behaviour or even
  154. * memory leaks and crashes.
  155. */
  156. typedef FT_Pointer FTC_FaceID;
  157. /************************************************************************
  158. *
  159. * @functype:
  160. * FTC_Face_Requester
  161. *
  162. * @description:
  163. * A callback function provided by client applications. It is used by
  164. * the cache manager to translate a given @FTC_FaceID into a new valid
  165. * @FT_Face object, on demand.
  166. *
  167. * <Input>
  168. * face_id ::
  169. * The face ID to resolve.
  170. *
  171. * library ::
  172. * A handle to a FreeType library object.
  173. *
  174. * req_data ::
  175. * Application-provided request data (see note below).
  176. *
  177. * <Output>
  178. * aface ::
  179. * A new @FT_Face handle.
  180. *
  181. * <Return>
  182. * FreeType error code. 0~means success.
  183. *
  184. * <Note>
  185. * The third parameter `req_data' is the same as the one passed by the
  186. * client when @FTC_Manager_New is called.
  187. *
  188. * The face requester should not perform funny things on the returned
  189. * face object, like creating a new @FT_Size for it, or setting a
  190. * transformation through @FT_Set_Transform!
  191. */
  192. typedef FT_Error
  193. (*FTC_Face_Requester)( FTC_FaceID face_id,
  194. FT_Library library,
  195. FT_Pointer request_data,
  196. FT_Face* aface );
  197. /* */
  198. #define FT_POINTER_TO_ULONG( p ) ( (FT_ULong)(FT_Pointer)(p) )
  199. #define FTC_FACE_ID_HASH( i ) \
  200. ((FT_UInt32)(( FT_POINTER_TO_ULONG( i ) >> 3 ) ^ \
  201. ( FT_POINTER_TO_ULONG( i ) << 7 ) ) )
  202. /*************************************************************************/
  203. /*************************************************************************/
  204. /*************************************************************************/
  205. /***** *****/
  206. /***** CACHE MANAGER OBJECT *****/
  207. /***** *****/
  208. /*************************************************************************/
  209. /*************************************************************************/
  210. /*************************************************************************/
  211. /*************************************************************************/
  212. /* */
  213. /* <Type> */
  214. /* FTC_Manager */
  215. /* */
  216. /* <Description> */
  217. /* This object corresponds to one instance of the cache-subsystem. */
  218. /* It is used to cache one or more @FT_Face objects, along with */
  219. /* corresponding @FT_Size objects. */
  220. /* */
  221. /* The manager intentionally limits the total number of opened */
  222. /* @FT_Face and @FT_Size objects to control memory usage. See the */
  223. /* `max_faces' and `max_sizes' parameters of @FTC_Manager_New. */
  224. /* */
  225. /* The manager is also used to cache `nodes' of various types while */
  226. /* limiting their total memory usage. */
  227. /* */
  228. /* All limitations are enforced by keeping lists of managed objects */
  229. /* in most-recently-used order, and flushing old nodes to make room */
  230. /* for new ones. */
  231. /* */
  232. typedef struct FTC_ManagerRec_* FTC_Manager;
  233. /*************************************************************************/
  234. /* */
  235. /* <Type> */
  236. /* FTC_Node */
  237. /* */
  238. /* <Description> */
  239. /* An opaque handle to a cache node object. Each cache node is */
  240. /* reference-counted. A node with a count of~0 might be flushed */
  241. /* out of a full cache whenever a lookup request is performed. */
  242. /* */
  243. /* If you lookup nodes, you have the ability to `acquire' them, i.e., */
  244. /* to increment their reference count. This will prevent the node */
  245. /* from being flushed out of the cache until you explicitly `release' */
  246. /* it (see @FTC_Node_Unref). */
  247. /* */
  248. /* See also @FTC_SBitCache_Lookup and @FTC_ImageCache_Lookup. */
  249. /* */
  250. typedef struct FTC_NodeRec_* FTC_Node;
  251. /*************************************************************************/
  252. /* */
  253. /* <Function> */
  254. /* FTC_Manager_New */
  255. /* */
  256. /* <Description> */
  257. /* Create a new cache manager. */
  258. /* */
  259. /* <Input> */
  260. /* library :: The parent FreeType library handle to use. */
  261. /* */
  262. /* max_faces :: Maximum number of opened @FT_Face objects managed by */
  263. /* this cache instance. Use~0 for defaults. */
  264. /* */
  265. /* max_sizes :: Maximum number of opened @FT_Size objects managed by */
  266. /* this cache instance. Use~0 for defaults. */
  267. /* */
  268. /* max_bytes :: Maximum number of bytes to use for cached data nodes. */
  269. /* Use~0 for defaults. Note that this value does not */
  270. /* account for managed @FT_Face and @FT_Size objects. */
  271. /* */
  272. /* requester :: An application-provided callback used to translate */
  273. /* face IDs into real @FT_Face objects. */
  274. /* */
  275. /* req_data :: A generic pointer that is passed to the requester */
  276. /* each time it is called (see @FTC_Face_Requester). */
  277. /* */
  278. /* <Output> */
  279. /* amanager :: A handle to a new manager object. 0~in case of */
  280. /* failure. */
  281. /* */
  282. /* <Return> */
  283. /* FreeType error code. 0~means success. */
  284. /* */
  285. FT_EXPORT( FT_Error )
  286. FTC_Manager_New( FT_Library library,
  287. FT_UInt max_faces,
  288. FT_UInt max_sizes,
  289. FT_ULong max_bytes,
  290. FTC_Face_Requester requester,
  291. FT_Pointer req_data,
  292. FTC_Manager *amanager );
  293. /*************************************************************************/
  294. /* */
  295. /* <Function> */
  296. /* FTC_Manager_Reset */
  297. /* */
  298. /* <Description> */
  299. /* Empty a given cache manager. This simply gets rid of all the */
  300. /* currently cached @FT_Face and @FT_Size objects within the manager. */
  301. /* */
  302. /* <InOut> */
  303. /* manager :: A handle to the manager. */
  304. /* */
  305. FT_EXPORT( void )
  306. FTC_Manager_Reset( FTC_Manager manager );
  307. /*************************************************************************/
  308. /* */
  309. /* <Function> */
  310. /* FTC_Manager_Done */
  311. /* */
  312. /* <Description> */
  313. /* Destroy a given manager after emptying it. */
  314. /* */
  315. /* <Input> */
  316. /* manager :: A handle to the target cache manager object. */
  317. /* */
  318. FT_EXPORT( void )
  319. FTC_Manager_Done( FTC_Manager manager );
  320. /*************************************************************************/
  321. /* */
  322. /* <Function> */
  323. /* FTC_Manager_LookupFace */
  324. /* */
  325. /* <Description> */
  326. /* Retrieve the @FT_Face object that corresponds to a given face ID */
  327. /* through a cache manager. */
  328. /* */
  329. /* <Input> */
  330. /* manager :: A handle to the cache manager. */
  331. /* */
  332. /* face_id :: The ID of the face object. */
  333. /* */
  334. /* <Output> */
  335. /* aface :: A handle to the face object. */
  336. /* */
  337. /* <Return> */
  338. /* FreeType error code. 0~means success. */
  339. /* */
  340. /* <Note> */
  341. /* The returned @FT_Face object is always owned by the manager. You */
  342. /* should never try to discard it yourself. */
  343. /* */
  344. /* The @FT_Face object doesn't necessarily have a current size object */
  345. /* (i.e., face->size can be 0). If you need a specific `font size', */
  346. /* use @FTC_Manager_LookupSize instead. */
  347. /* */
  348. /* Never change the face's transformation matrix (i.e., never call */
  349. /* the @FT_Set_Transform function) on a returned face! If you need */
  350. /* to transform glyphs, do it yourself after glyph loading. */
  351. /* */
  352. /* When you perform a lookup, out-of-memory errors are detected */
  353. /* _within_ the lookup and force incremental flushes of the cache */
  354. /* until enough memory is released for the lookup to succeed. */
  355. /* */
  356. /* If a lookup fails with `FT_Err_Out_Of_Memory' the cache has */
  357. /* already been completely flushed, and still no memory was available */
  358. /* for the operation. */
  359. /* */
  360. FT_EXPORT( FT_Error )
  361. FTC_Manager_LookupFace( FTC_Manager manager,
  362. FTC_FaceID face_id,
  363. FT_Face *aface );
  364. /*************************************************************************/
  365. /* */
  366. /* <Struct> */
  367. /* FTC_ScalerRec */
  368. /* */
  369. /* <Description> */
  370. /* A structure used to describe a given character size in either */
  371. /* pixels or points to the cache manager. See */
  372. /* @FTC_Manager_LookupSize. */
  373. /* */
  374. /* <Fields> */
  375. /* face_id :: The source face ID. */
  376. /* */
  377. /* width :: The character width. */
  378. /* */
  379. /* height :: The character height. */
  380. /* */
  381. /* pixel :: A Boolean. If 1, the `width' and `height' fields are */
  382. /* interpreted as integer pixel character sizes. */
  383. /* Otherwise, they are expressed as 1/64th of points. */
  384. /* */
  385. /* x_res :: Only used when `pixel' is value~0 to indicate the */
  386. /* horizontal resolution in dpi. */
  387. /* */
  388. /* y_res :: Only used when `pixel' is value~0 to indicate the */
  389. /* vertical resolution in dpi. */
  390. /* */
  391. /* <Note> */
  392. /* This type is mainly used to retrieve @FT_Size objects through the */
  393. /* cache manager. */
  394. /* */
  395. typedef struct FTC_ScalerRec_
  396. {
  397. FTC_FaceID face_id;
  398. FT_UInt width;
  399. FT_UInt height;
  400. FT_Int pixel;
  401. FT_UInt x_res;
  402. FT_UInt y_res;
  403. } FTC_ScalerRec;
  404. /*************************************************************************/
  405. /* */
  406. /* <Struct> */
  407. /* FTC_Scaler */
  408. /* */
  409. /* <Description> */
  410. /* A handle to an @FTC_ScalerRec structure. */
  411. /* */
  412. typedef struct FTC_ScalerRec_* FTC_Scaler;
  413. /*************************************************************************/
  414. /* */
  415. /* <Function> */
  416. /* FTC_Manager_LookupSize */
  417. /* */
  418. /* <Description> */
  419. /* Retrieve the @FT_Size object that corresponds to a given */
  420. /* @FTC_ScalerRec pointer through a cache manager. */
  421. /* */
  422. /* <Input> */
  423. /* manager :: A handle to the cache manager. */
  424. /* */
  425. /* scaler :: A scaler handle. */
  426. /* */
  427. /* <Output> */
  428. /* asize :: A handle to the size object. */
  429. /* */
  430. /* <Return> */
  431. /* FreeType error code. 0~means success. */
  432. /* */
  433. /* <Note> */
  434. /* The returned @FT_Size object is always owned by the manager. You */
  435. /* should never try to discard it by yourself. */
  436. /* */
  437. /* You can access the parent @FT_Face object simply as `size->face' */
  438. /* if you need it. Note that this object is also owned by the */
  439. /* manager. */
  440. /* */
  441. /* <Note> */
  442. /* When you perform a lookup, out-of-memory errors are detected */
  443. /* _within_ the lookup and force incremental flushes of the cache */
  444. /* until enough memory is released for the lookup to succeed. */
  445. /* */
  446. /* If a lookup fails with `FT_Err_Out_Of_Memory' the cache has */
  447. /* already been completely flushed, and still no memory is available */
  448. /* for the operation. */
  449. /* */
  450. FT_EXPORT( FT_Error )
  451. FTC_Manager_LookupSize( FTC_Manager manager,
  452. FTC_Scaler scaler,
  453. FT_Size *asize );
  454. /*************************************************************************/
  455. /* */
  456. /* <Function> */
  457. /* FTC_Node_Unref */
  458. /* */
  459. /* <Description> */
  460. /* Decrement a cache node's internal reference count. When the count */
  461. /* reaches 0, it is not destroyed but becomes eligible for subsequent */
  462. /* cache flushes. */
  463. /* */
  464. /* <Input> */
  465. /* node :: The cache node handle. */
  466. /* */
  467. /* manager :: The cache manager handle. */
  468. /* */
  469. FT_EXPORT( void )
  470. FTC_Node_Unref( FTC_Node node,
  471. FTC_Manager manager );
  472. /*************************************************************************
  473. *
  474. * @function:
  475. * FTC_Manager_RemoveFaceID
  476. *
  477. * @description:
  478. * A special function used to indicate to the cache manager that
  479. * a given @FTC_FaceID is no longer valid, either because its
  480. * content changed, or because it was deallocated or uninstalled.
  481. *
  482. * @input:
  483. * manager ::
  484. * The cache manager handle.
  485. *
  486. * face_id ::
  487. * The @FTC_FaceID to be removed.
  488. *
  489. * @note:
  490. * This function flushes all nodes from the cache corresponding to this
  491. * `face_id', with the exception of nodes with a non-null reference
  492. * count.
  493. *
  494. * Such nodes are however modified internally so as to never appear
  495. * in later lookups with the same `face_id' value, and to be immediately
  496. * destroyed when released by all their users.
  497. *
  498. */
  499. FT_EXPORT( void )
  500. FTC_Manager_RemoveFaceID( FTC_Manager manager,
  501. FTC_FaceID face_id );
  502. /*************************************************************************/
  503. /* */
  504. /* <Section> */
  505. /* cache_subsystem */
  506. /* */
  507. /*************************************************************************/
  508. /*************************************************************************
  509. *
  510. * @type:
  511. * FTC_CMapCache
  512. *
  513. * @description:
  514. * An opaque handle used to model a charmap cache. This cache is to
  515. * hold character codes -> glyph indices mappings.
  516. *
  517. */
  518. typedef struct FTC_CMapCacheRec_* FTC_CMapCache;
  519. /*************************************************************************
  520. *
  521. * @function:
  522. * FTC_CMapCache_New
  523. *
  524. * @description:
  525. * Create a new charmap cache.
  526. *
  527. * @input:
  528. * manager ::
  529. * A handle to the cache manager.
  530. *
  531. * @output:
  532. * acache ::
  533. * A new cache handle. NULL in case of error.
  534. *
  535. * @return:
  536. * FreeType error code. 0~means success.
  537. *
  538. * @note:
  539. * Like all other caches, this one will be destroyed with the cache
  540. * manager.
  541. *
  542. */
  543. FT_EXPORT( FT_Error )
  544. FTC_CMapCache_New( FTC_Manager manager,
  545. FTC_CMapCache *acache );
  546. /************************************************************************
  547. *
  548. * @function:
  549. * FTC_CMapCache_Lookup
  550. *
  551. * @description:
  552. * Translate a character code into a glyph index, using the charmap
  553. * cache.
  554. *
  555. * @input:
  556. * cache ::
  557. * A charmap cache handle.
  558. *
  559. * face_id ::
  560. * The source face ID.
  561. *
  562. * cmap_index ::
  563. * The index of the charmap in the source face.
  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. #define FTC_IMAGE_TYPE_HASH( d ) \
  637. (FT_UFast)( FTC_FACE_ID_HASH( (d)->face_id ) ^ \
  638. ( (d)->width << 8 ) ^ (d)->height ^ \
  639. ( (d)->flags << 4 ) )
  640. /*************************************************************************/
  641. /* */
  642. /* <Type> */
  643. /* FTC_ImageCache */
  644. /* */
  645. /* <Description> */
  646. /* A handle to an glyph image cache object. They are designed to */
  647. /* hold many distinct glyph images while not exceeding a certain */
  648. /* memory threshold. */
  649. /* */
  650. typedef struct FTC_ImageCacheRec_* FTC_ImageCache;
  651. /*************************************************************************/
  652. /* */
  653. /* <Function> */
  654. /* FTC_ImageCache_New */
  655. /* */
  656. /* <Description> */
  657. /* Create a new glyph image cache. */
  658. /* */
  659. /* <Input> */
  660. /* manager :: The parent manager for the image cache. */
  661. /* */
  662. /* <Output> */
  663. /* acache :: A handle to the new glyph image cache object. */
  664. /* */
  665. /* <Return> */
  666. /* FreeType error code. 0~means success. */
  667. /* */
  668. FT_EXPORT( FT_Error )
  669. FTC_ImageCache_New( FTC_Manager manager,
  670. FTC_ImageCache *acache );
  671. /*************************************************************************/
  672. /* */
  673. /* <Function> */
  674. /* FTC_ImageCache_Lookup */
  675. /* */
  676. /* <Description> */
  677. /* Retrieve a given glyph image from a glyph image cache. */
  678. /* */
  679. /* <Input> */
  680. /* cache :: A handle to the source glyph image cache. */
  681. /* */
  682. /* type :: A pointer to a glyph image type descriptor. */
  683. /* */
  684. /* gindex :: The glyph index to retrieve. */
  685. /* */
  686. /* <Output> */
  687. /* aglyph :: The corresponding @FT_Glyph object. 0~in case of */
  688. /* failure. */
  689. /* */
  690. /* anode :: Used to return the address of of the corresponding cache */
  691. /* node after incrementing its reference count (see note */
  692. /* below). */
  693. /* */
  694. /* <Return> */
  695. /* FreeType error code. 0~means success. */
  696. /* */
  697. /* <Note> */
  698. /* The returned glyph is owned and managed by the glyph image cache. */
  699. /* Never try to transform or discard it manually! You can however */
  700. /* create a copy with @FT_Glyph_Copy and modify the new one. */
  701. /* */
  702. /* If `anode' is _not_ NULL, it receives the address of the cache */
  703. /* node containing the glyph image, after increasing its reference */
  704. /* count. This ensures that the node (as well as the @FT_Glyph) will */
  705. /* always be kept in the cache until you call @FTC_Node_Unref to */
  706. /* `release' it. */
  707. /* */
  708. /* If `anode' is NULL, the cache node is left unchanged, which means */
  709. /* that the @FT_Glyph could be flushed out of the cache on the next */
  710. /* call to one of the caching sub-system APIs. Don't assume that it */
  711. /* is persistent! */
  712. /* */
  713. FT_EXPORT( FT_Error )
  714. FTC_ImageCache_Lookup( FTC_ImageCache cache,
  715. FTC_ImageType type,
  716. FT_UInt gindex,
  717. FT_Glyph *aglyph,
  718. FTC_Node *anode );
  719. /*************************************************************************/
  720. /* */
  721. /* <Function> */
  722. /* FTC_ImageCache_LookupScaler */
  723. /* */
  724. /* <Description> */
  725. /* A variant of @FTC_ImageCache_Lookup that uses an @FTC_ScalerRec */
  726. /* to specify the face ID and its size. */
  727. /* */
  728. /* <Input> */
  729. /* cache :: A handle to the source glyph image cache. */
  730. /* */
  731. /* scaler :: A pointer to a scaler descriptor. */
  732. /* */
  733. /* load_flags :: The corresponding load flags. */
  734. /* */
  735. /* gindex :: The glyph index to retrieve. */
  736. /* */
  737. /* <Output> */
  738. /* aglyph :: The corresponding @FT_Glyph object. 0~in case of */
  739. /* failure. */
  740. /* */
  741. /* anode :: Used to return the address of of the corresponding */
  742. /* cache node after incrementing its reference count */
  743. /* (see note below). */
  744. /* */
  745. /* <Return> */
  746. /* FreeType error code. 0~means success. */
  747. /* */
  748. /* <Note> */
  749. /* The returned glyph is owned and managed by the glyph image cache. */
  750. /* Never try to transform or discard it manually! You can however */
  751. /* create a copy with @FT_Glyph_Copy and modify the new one. */
  752. /* */
  753. /* If `anode' is _not_ NULL, it receives the address of the cache */
  754. /* node containing the glyph image, after increasing its reference */
  755. /* count. This ensures that the node (as well as the @FT_Glyph) will */
  756. /* always be kept in the cache until you call @FTC_Node_Unref to */
  757. /* `release' it. */
  758. /* */
  759. /* If `anode' is NULL, the cache node is left unchanged, which means */
  760. /* that the @FT_Glyph could be flushed out of the cache on the next */
  761. /* call to one of the caching sub-system APIs. Don't assume that it */
  762. /* is persistent! */
  763. /* */
  764. FT_EXPORT( FT_Error )
  765. FTC_ImageCache_LookupScaler( FTC_ImageCache cache,
  766. FTC_Scaler scaler,
  767. FT_ULong load_flags,
  768. FT_UInt gindex,
  769. FT_Glyph *aglyph,
  770. FTC_Node *anode );
  771. /*************************************************************************/
  772. /* */
  773. /* <Type> */
  774. /* FTC_SBit */
  775. /* */
  776. /* <Description> */
  777. /* A handle to a small bitmap descriptor. See the @FTC_SBitRec */
  778. /* structure for details. */
  779. /* */
  780. typedef struct FTC_SBitRec_* FTC_SBit;
  781. /*************************************************************************/
  782. /* */
  783. /* <Struct> */
  784. /* FTC_SBitRec */
  785. /* */
  786. /* <Description> */
  787. /* A very compact structure used to describe a small glyph bitmap. */
  788. /* */
  789. /* <Fields> */
  790. /* width :: The bitmap width in pixels. */
  791. /* */
  792. /* height :: The bitmap height in pixels. */
  793. /* */
  794. /* left :: The horizontal distance from the pen position to the */
  795. /* left bitmap border (a.k.a. `left side bearing', or */
  796. /* `lsb'). */
  797. /* */
  798. /* top :: The vertical distance from the pen position (on the */
  799. /* baseline) to the upper bitmap border (a.k.a. `top */
  800. /* side bearing'). The distance is positive for upwards */
  801. /* y~coordinates. */
  802. /* */
  803. /* format :: The format of the glyph bitmap (monochrome or gray). */
  804. /* */
  805. /* max_grays :: Maximum gray level value (in the range 1 to~255). */
  806. /* */
  807. /* pitch :: The number of bytes per bitmap line. May be positive */
  808. /* or negative. */
  809. /* */
  810. /* xadvance :: The horizontal advance width in pixels. */
  811. /* */
  812. /* yadvance :: The vertical advance height in pixels. */
  813. /* */
  814. /* buffer :: A pointer to the bitmap pixels. */
  815. /* */
  816. typedef struct FTC_SBitRec_
  817. {
  818. FT_Byte width;
  819. FT_Byte height;
  820. FT_Char left;
  821. FT_Char top;
  822. FT_Byte format;
  823. FT_Byte max_grays;
  824. FT_Short pitch;
  825. FT_Char xadvance;
  826. FT_Char yadvance;
  827. FT_Byte* buffer;
  828. } FTC_SBitRec;
  829. /*************************************************************************/
  830. /* */
  831. /* <Type> */
  832. /* FTC_SBitCache */
  833. /* */
  834. /* <Description> */
  835. /* A handle to a small bitmap cache. These are special cache objects */
  836. /* used to store small glyph bitmaps (and anti-aliased pixmaps) in a */
  837. /* much more efficient way than the traditional glyph image cache */
  838. /* implemented by @FTC_ImageCache. */
  839. /* */
  840. typedef struct FTC_SBitCacheRec_* FTC_SBitCache;
  841. /*************************************************************************/
  842. /* */
  843. /* <Function> */
  844. /* FTC_SBitCache_New */
  845. /* */
  846. /* <Description> */
  847. /* Create a new cache to store small glyph bitmaps. */
  848. /* */
  849. /* <Input> */
  850. /* manager :: A handle to the source cache manager. */
  851. /* */
  852. /* <Output> */
  853. /* acache :: A handle to the new sbit cache. NULL in case of error. */
  854. /* */
  855. /* <Return> */
  856. /* FreeType error code. 0~means success. */
  857. /* */
  858. FT_EXPORT( FT_Error )
  859. FTC_SBitCache_New( FTC_Manager manager,
  860. FTC_SBitCache *acache );
  861. /*************************************************************************/
  862. /* */
  863. /* <Function> */
  864. /* FTC_SBitCache_Lookup */
  865. /*…