PageRenderTime 36ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/src/freetype/include/freetype/ftcache.h

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