PageRenderTime 42ms CodeModel.GetById 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/compiler/android-ndk/jni/freetype/include/freetype/ftcache.h

http://ftk.googlecode.com/
C++ Header | 1125 lines | 154 code | 107 blank | 864 comment | 10 complexity | a201565bfed787d64f1860722e271953 MD5 | raw file
Possible License(s): LGPL-3.0
  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. Any negative value
  564. * means to use the cache @FT_Face's default charmap.
  565. *
  566. * char_code ::
  567. * The character code (in the corresponding charmap).
  568. *
  569. * @return:
  570. * Glyph index. 0~means `no glyph'.
  571. *
  572. */
  573. FT_EXPORT( FT_UInt )
  574. FTC_CMapCache_Lookup( FTC_CMapCache cache,
  575. FTC_FaceID face_id,
  576. FT_Int cmap_index,
  577. FT_UInt32 char_code );
  578. /*************************************************************************/
  579. /* */
  580. /* <Section> */
  581. /* cache_subsystem */
  582. /* */
  583. /*************************************************************************/
  584. /*************************************************************************/
  585. /*************************************************************************/
  586. /*************************************************************************/
  587. /***** *****/
  588. /***** IMAGE CACHE OBJECT *****/
  589. /***** *****/
  590. /*************************************************************************/
  591. /*************************************************************************/
  592. /*************************************************************************/
  593. /*************************************************************************
  594. *
  595. * @struct:
  596. * FTC_ImageTypeRec
  597. *
  598. * @description:
  599. * A structure used to model the type of images in a glyph cache.
  600. *
  601. * @fields:
  602. * face_id ::
  603. * The face ID.
  604. *
  605. * width ::
  606. * The width in pixels.
  607. *
  608. * height ::
  609. * The height in pixels.
  610. *
  611. * flags ::
  612. * The load flags, as in @FT_Load_Glyph.
  613. *
  614. */
  615. typedef struct FTC_ImageTypeRec_
  616. {
  617. FTC_FaceID face_id;
  618. FT_Int width;
  619. FT_Int height;
  620. FT_Int32 flags;
  621. } FTC_ImageTypeRec;
  622. /*************************************************************************
  623. *
  624. * @type:
  625. * FTC_ImageType
  626. *
  627. * @description:
  628. * A handle to an @FTC_ImageTypeRec structure.
  629. *
  630. */
  631. typedef struct FTC_ImageTypeRec_* FTC_ImageType;
  632. /* */
  633. #define FTC_IMAGE_TYPE_COMPARE( d1, d2 ) \
  634. ( (d1)->face_id == (d2)->face_id && \
  635. (d1)->width == (d2)->width && \
  636. (d1)->flags == (d2)->flags )
  637. #define FTC_IMAGE_TYPE_HASH( d ) \
  638. (FT_UFast)( FTC_FACE_ID_HASH( (d)->face_id ) ^ \
  639. ( (d)->width << 8 ) ^ (d)->height ^ \
  640. ( (d)->flags << 4 ) )
  641. /*************************************************************************/
  642. /* */
  643. /* <Type> */
  644. /* FTC_ImageCache */
  645. /* */
  646. /* <Description> */
  647. /* A handle to an glyph image cache object. They are designed to */
  648. /* hold many distinct glyph images while not exceeding a certain */
  649. /* memory threshold. */
  650. /* */
  651. typedef struct FTC_ImageCacheRec_* FTC_ImageCache;
  652. /*************************************************************************/
  653. /* */
  654. /* <Function> */
  655. /* FTC_ImageCache_New */
  656. /* */
  657. /* <Description> */
  658. /* Create a new glyph image cache. */
  659. /* */
  660. /* <Input> */
  661. /* manager :: The parent manager for the image cache. */
  662. /* */
  663. /* <Output> */
  664. /* acache :: A handle to the new glyph image cache object. */
  665. /* */
  666. /* <Return> */
  667. /* FreeType error code. 0~means success. */
  668. /* */
  669. FT_EXPORT( FT_Error )
  670. FTC_ImageCache_New( FTC_Manager manager,
  671. FTC_ImageCache *acache );
  672. /*************************************************************************/
  673. /* */
  674. /* <Function> */
  675. /* FTC_ImageCache_Lookup */
  676. /* */
  677. /* <Description> */
  678. /* Retrieve a given glyph image from a glyph image cache. */
  679. /* */
  680. /* <Input> */
  681. /* cache :: A handle to the source glyph image cache. */
  682. /* */
  683. /* type :: A pointer to a glyph image type descriptor. */
  684. /* */
  685. /* gindex :: The glyph index to retrieve. */
  686. /* */
  687. /* <Output> */
  688. /* aglyph :: The corresponding @FT_Glyph object. 0~in case of */
  689. /* failure. */
  690. /* */
  691. /* anode :: Used to return the address of of the corresponding cache */
  692. /* node after incrementing its reference count (see note */
  693. /* below). */
  694. /* */
  695. /* <Return> */
  696. /* FreeType error code. 0~means success. */
  697. /* */
  698. /* <Note> */
  699. /* The returned glyph is owned and managed by the glyph image cache. */
  700. /* Never try to transform or discard it manually! You can however */
  701. /* create a copy with @FT_Glyph_Copy and modify the new one. */
  702. /* */
  703. /* If `anode' is _not_ NULL, it receives the address of the cache */
  704. /* node containing the glyph image, after increasing its reference */
  705. /* count. This ensures that the node (as well as the @FT_Glyph) will */
  706. /* always be kept in the cache until you call @FTC_Node_Unref to */
  707. /* `release' it. */
  708. /* */
  709. /* If `anode' is NULL, the cache node is left unchanged, which means */
  710. /* that the @FT_Glyph could be flushed out of the cache on the next */
  711. /* call to one of the caching sub-system APIs. Don't assume that it */
  712. /* is persistent! */
  713. /* */
  714. FT_EXPORT( FT_Error )
  715. FTC_ImageCache_Lookup( FTC_ImageCache cache,
  716. FTC_ImageType type,
  717. FT_UInt gindex,
  718. FT_Glyph *aglyph,
  719. FTC_Node *anode );
  720. /*************************************************************************/
  721. /* */
  722. /* <Function> */
  723. /* FTC_ImageCache_LookupScaler */
  724. /* */
  725. /* <Description> */
  726. /* A variant of @FTC_ImageCache_Lookup that uses an @FTC_ScalerRec */
  727. /* to specify the face ID and its size. */
  728. /* */
  729. /* <Input> */
  730. /* cache :: A handle to the source glyph image cache. */
  731. /* */
  732. /* scaler :: A pointer to a scaler descriptor. */
  733. /* */
  734. /* load_flags :: The corresponding load flags. */
  735. /* */
  736. /* gindex :: The glyph index to retrieve. */
  737. /* */
  738. /* <Output> */
  739. /* aglyph :: The corresponding @FT_Glyph object. 0~in case of */
  740. /* failure. */
  741. /* */
  742. /* anode :: Used to return the address of of the corresponding */
  743. /* cache node after incrementing its reference count */
  744. /* (see note below). */
  745. /* */
  746. /* <Return> */
  747. /* FreeType error code. 0~means success. */
  748. /* */
  749. /* <Note> */
  750. /* The returned glyph is owned and managed by the glyph image cache. */
  751. /* Never try to transform or discard it manually! You can however */
  752. /* create a copy with @FT_Glyph_Copy and modify the new one. */
  753. /* */
  754. /* If `anode' is _not_ NULL, it receives the address of the cache */
  755. /* node containing the glyph image, after increasing its reference */
  756. /* count. This ensures that the node (as well as the @FT_Glyph) will */
  757. /* always be kept in the cache until you call @FTC_Node_Unref to */
  758. /* `release' it. */
  759. /* */
  760. /* If `anode' is NULL, the cache node is left unchanged, which means */
  761. /* that the @FT_Glyph could be flushed out of the cache on the next */
  762. /* call to one of the caching sub-system APIs. Don't assume that it */
  763. /* is persistent! */
  764. /* */
  765. /* Calls to @FT_Set_Char_Size and friends have no effect on cached */
  766. /* glyphs; you should always use the FreeType cache API instead. */
  767. /* */
  768. FT_EXPORT( FT_Error )
  769. FTC_ImageCache_LookupScaler( FTC_ImageCache cache,
  770. FTC_Scaler scaler,
  771. FT_ULong load_flags,
  772. FT_UInt gindex,
  773. FT_Glyph *aglyph,
  774. FTC_Node *anode );
  775. /*************************************************************************/
  776. /* */
  777. /* <Type> */
  778. /* FTC_SBit */
  779. /* */
  780. /* <Description> */
  781. /* A handle to a small bitmap descriptor. See the @FTC_SBitRec */
  782. /* structure for details. */
  783. /* */
  784. typedef struct FTC_SBitRec_* FTC_SBit;
  785. /*************************************************************************/
  786. /* */
  787. /* <Struct> */
  788. /* FTC_SBitRec */
  789. /* */
  790. /* <Description> */
  791. /* A very compact structure used to describe a small glyph bitmap. */
  792. /* */
  793. /* <Fields> */
  794. /* width :: The bitmap width in pixels. */
  795. /* */
  796. /* height :: The bitmap height in pixels. */
  797. /* */
  798. /* left :: The horizontal distance from the pen position to the */
  799. /* left bitmap border (a.k.a. `left side bearing', or */
  800. /* `lsb'). */
  801. /* */
  802. /* top :: The vertical distance from the pen position (on the */
  803. /* baseline) to the upper bitmap border (a.k.a. `top */
  804. /* side bearing'). The distance is positive for upwards */
  805. /* y~coordinates. */
  806. /* */
  807. /* format :: The format of the glyph bitmap (monochrome or gray). */
  808. /* */
  809. /* max_grays :: Maximum gray level value (in the range 1 to~255). */
  810. /* */
  811. /* pitch :: The number of bytes per bitmap line. May be positive */
  812. /* or negative. */
  813. /* */
  814. /* xadvance :: The horizontal advance width in pixels. */
  815. /* */
  816. /* yadvance :: The vertical advance height in pixels. */
  817. /* */
  818. /* buffer :: A pointer to the bitmap pixels. */
  819. /* */
  820. typedef struct FTC_SBitRec_
  821. {
  822. FT_Byte width;
  823. FT_Byte height;
  824. FT_Char left;
  825. FT_Char top;
  826. FT_Byte format;
  827. FT_Byte max_grays;
  828. FT_Short pitch;
  829. FT_Char xadvance;
  830. FT_Char yadvance;
  831. FT_Byte* buffer;
  832. } FTC_SBitRec;
  833. /*************************************************************************/
  834. /* */
  835. /* <Type> */
  836. /* FTC_SBitCache */
  837. /* */
  838. /* <Description> */
  839. /* A handle to a small bitmap cache. These are special cache objects */
  840. /* used to store small glyph bitmaps (and anti-aliased pixmaps) in a */
  841. /* much more efficient way than the traditional glyph image cache */
  842. /* implemented by @FTC_ImageCache. */
  843. /* */
  844. typedef struct FTC_SBitCacheRec_* FTC_SBitCache;
  845. /*************************************************************************/
  846. /* */
  847. /* <Function> */
  848. /* FTC_SBitCache_New */
  849. /* */
  850. /* <Description> */
  851. /* Create a new cache to store small glyph bitmaps. */
  852. /* */
  853. /* <Input> */
  854. /* manager :: A handle to the source cache manager. */
  855. /* */
  856. /* <Output> */
  857. /* acache :: A handle to the new sbit cache. NULL in case of error. */
  858. /* */
  859. /* <Return> */
  860. /* FreeType error code. 0~means success. */
  861. /* */
  862. FT_EXPORT( FT_Error )
  863. FTC_SBitCache_New( FTC_Manager manager,
  864. FTC_SBitCache *acache );
  865. /*************************************************************************/
  866. /* */
  867. /* <Function> */
  868. /* FTC_SBitCache_Lookup */
  869. /* */
  870. /* <Description> */
  871. /* Look up a given small glyph bitmap in a given sbit cache and */
  872. /* `lock' it to prevent its flushing from the cache until needed. */
  873. /* */
  874. /* <Input> */
  875. /* cache :: A handle to the source sbit cache. */
  876. /* */
  877. /* type :: A pointer to the glyph image type descriptor. */
  878. /* */
  879. /* gindex :: The glyph index. */
  880. /* */
  881. /* <Output> */
  882. /* sbit :: A handle to a small bitmap descriptor. */
  883. /* */
  884. /* anode :: Used to return the address of of the corresponding cache */
  885. /* node after incrementing its reference count (see note */
  886. /* below). */
  887. /* */
  888. /* <Return> */
  889. /* FreeType error code. 0~means success. */
  890. /* */
  891. /* <Note> */
  892. /* The small bitmap descriptor and its bit buffer are owned by the */
  893. /* cache and should never be freed by the application. They might */
  894. /* as well disappear from memory on the next cache lookup, so don't */
  895. /* treat them as persistent data. */
  896. /* */
  897. /* The descriptor's `buffer' field is set to~0 to indicate a missing */
  898. /* glyph bitmap. */
  899. /* */
  900. /* If `anode' is _not_ NULL, it receives the address of the cache */
  901. /* node containing the bitmap, after increasing its reference count. */
  902. /* This ensures that the node (as well as the image) will always be */
  903. /* kept in the cache until you call @FTC_Node_Unref to `release' it. */
  904. /* */
  905. /* If `anode' is NULL, the cache node is left unchanged, which means */
  906. /* that the bitmap could be flushed out of the cache on the next */
  907. /* call to one of the caching sub-system APIs. Don't assume that it */
  908. /* is persistent! */
  909. /* */
  910. FT_EXPORT( FT_Error )
  911. FTC_SBitCache_Lookup( FTC_SBitCache cache,
  912. FTC_ImageType type,
  913. FT_UInt gindex,
  914. FTC_SBit *sbit,
  915. FTC_Node *anode );
  916. /*************************************************************************/
  917. /* */
  918. /* <Function> */
  919. /* FTC_SBitCache_LookupScaler */
  920. /* */
  921. /* <Description> */
  922. /* A variant of @FTC_SBitCache_Lookup that uses an @FTC_ScalerRec */
  923. /* to specify the face ID and its size. */
  924. /* */
  925. /* <Input> */
  926. /* cache :: A handle to the source sbit cache. */
  927. /* */
  928. /* scaler :: A pointer to the scaler descriptor. */
  929. /* */
  930. /* load_flags :: The corresponding load flags. */
  931. /* */
  932. /* gindex :: The glyph index. */
  933. /* */
  934. /* <Output> */
  935. /* sbit :: A handle to a small bitmap descriptor. */
  936. /* */
  937. /* anode :: Used to return the address of of the corresponding */
  938. /* cache node after incrementing its reference count */
  939. /* (see note below). */
  940. /* */
  941. /* <Return> */
  942. /* FreeType error code. 0~means success. */
  943. /* */
  944. /* <Note> */
  945. /* The small bitmap descriptor and its bit buffer are owned by the */
  946. /* cache and should never be freed by the application. They might */
  947. /* as well disappear from memory on the next cache lookup, so don't */
  948. /* treat them as persistent data. */
  949. /* */
  950. /* The descriptor's `buffer' field is set to~0 to indicate a missing */
  951. /* glyph bitmap. */
  952. /* */
  953. /* If `anode' is _not_ NULL, it receives the address of the cache */
  954. /* node containing the bitmap, after increasing its reference count. */
  955. /* This ensures that the node (as well as the image) will always be */
  956. /* kept in the cache until you call @FTC_Node_Unref to `release' it. */
  957. /* */
  958. /* If `anode' is NULL, the cache node is left unchanged, which means */
  959. /* that the bitmap could be flushed out of the cache on the next */
  960. /* call to one of the caching sub-system APIs. Don't assume that it */
  961. /* is persistent! */
  962. /* */
  963. FT_EXPORT( FT_Error )
  964. FTC_SBitCache_LookupScaler( FTC_SBitCache cache,
  965. FTC_Scaler scaler,
  966. FT_ULong load_flags,
  967. FT_UInt gindex,
  968. FTC_SBit *sbit,
  969. FTC_Node *anode );
  970. /* */
  971. #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
  972. /*@***********************************************************************/
  973. /* */
  974. /* <Struct> */
  975. /* FTC_FontRec */
  976. /* */
  977. /* <Description> */
  978. /* A simple structure used to describe a given `font' to the cache */
  979. /* manager. Note that a `font' is the combination of a given face */
  980. /* with a given character size. */
  981. /* */
  982. /* <Fields> */
  983. /* face_id :: The ID of the face to use. */
  984. /* */
  985. /* pix_width :: The character width in integer pixels. */
  986. /* */
  987. /* pix_height :: The character height in integer pixels. */
  988. /* */
  989. typedef struct FTC_FontRec_
  990. {
  991. FTC_FaceID face_id;
  992. FT_UShort pix_width;
  993. FT_UShort pix_height;
  994. } FTC_FontRec;
  995. /* */
  996. #define FTC_FONT_COMPARE( f1, f2 ) \
  997. ( (f1)->face_id == (f2)->face_id && \
  998. (f1)->pix_width == (f2)->pix_width && \
  999. (f1)->pix_height == (f2)->pix_height )
  1000. #define FTC_FONT_HASH( f ) \
  1001. (FT_UInt32)( FTC_FACE_ID_HASH((f)->face_id) ^ \
  1002. ((f)->pix_width << 8) ^ \
  1003. ((f)->pix_height) )
  1004. typedef FTC_FontRec* FTC_Font;
  1005. FT_EXPORT( FT_Error )
  1006. FTC_Manager_Lookup_Face( FTC_Manager manager,
  1007. FTC_FaceID face_id,
  1008. FT_Face *aface );
  1009. FT_EXPORT( FT_Error )
  1010. FTC_Manager_Lookup_Size( FTC_Manager manager,
  1011. FTC_Font font,
  1012. FT_Face *aface,
  1013. FT_Size *asize );
  1014. #endif /* FT_CONFIG_OPTION_OLD_INTERNALS */
  1015. /* */
  1016. FT_END_HEADER
  1017. #endif /* __FTCACHE_H__ */
  1018. /* END */