PageRenderTime 32ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/extensions/gdx-freetype/jni/freetype-2.4.8/src/cache/ftcglyph.h

http://libgdx.googlecode.com/
C++ Header | 329 lines | 128 code | 67 blank | 134 comment | 3 complexity | 3e61ec2ceda8f179decef6f0a3654f29 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, Apache-2.0, GPL-3.0, LGPL-2.1
  1. /***************************************************************************/
  2. /* */
  3. /* ftcglyph.h */
  4. /* */
  5. /* FreeType abstract glyph cache (specification). */
  6. /* */
  7. /* Copyright 2000-2001, 2003, 2004, 2006, 2007, 2011 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. /*
  18. *
  19. * FTC_GCache is an _abstract_ cache object optimized to store glyph
  20. * data. It works as follows:
  21. *
  22. * - It manages FTC_GNode objects. Each one of them can hold one or more
  23. * glyph `items'. Item types are not specified in the FTC_GCache but
  24. * in classes that extend it.
  25. *
  26. * - Glyph attributes, like face ID, character size, render mode, etc.,
  27. * can be grouped into abstract `glyph families'. This avoids storing
  28. * the attributes within the FTC_GCache, since it is likely that many
  29. * FTC_GNodes will belong to the same family in typical uses.
  30. *
  31. * - Each FTC_GNode is thus an FTC_Node with two additional fields:
  32. *
  33. * * gindex: A glyph index, or the first index in a glyph range.
  34. * * family: A pointer to a glyph `family'.
  35. *
  36. * - Family types are not fully specific in the FTC_Family type, but
  37. * by classes that extend it.
  38. *
  39. * Note that both FTC_ImageCache and FTC_SBitCache extend FTC_GCache.
  40. * They share an FTC_Family sub-class called FTC_BasicFamily which is
  41. * used to store the following data: face ID, pixel/point sizes, load
  42. * flags. For more details see the file `src/cache/ftcbasic.c'.
  43. *
  44. * Client applications can extend FTC_GNode with their own FTC_GNode
  45. * and FTC_Family sub-classes to implement more complex caches (e.g.,
  46. * handling automatic synthesis, like obliquing & emboldening, colored
  47. * glyphs, etc.).
  48. *
  49. * See also the FTC_ICache & FTC_SCache classes in `ftcimage.h' and
  50. * `ftcsbits.h', which both extend FTC_GCache with additional
  51. * optimizations.
  52. *
  53. * A typical FTC_GCache implementation must provide at least the
  54. * following:
  55. *
  56. * - FTC_GNode sub-class, e.g. MyNode, with relevant methods:
  57. * my_node_new (must call FTC_GNode_Init)
  58. * my_node_free (must call FTC_GNode_Done)
  59. * my_node_compare (must call FTC_GNode_Compare)
  60. * my_node_remove_faceid (must call ftc_gnode_unselect in case
  61. * of match)
  62. *
  63. * - FTC_Family sub-class, e.g. MyFamily, with relevant methods:
  64. * my_family_compare
  65. * my_family_init
  66. * my_family_reset (optional)
  67. * my_family_done
  68. *
  69. * - FTC_GQuery sub-class, e.g. MyQuery, to hold cache-specific query
  70. * data.
  71. *
  72. * - Constant structures for a FTC_GNodeClass.
  73. *
  74. * - MyCacheNew() can be implemented easily as a call to the convenience
  75. * function FTC_GCache_New.
  76. *
  77. * - MyCacheLookup with a call to FTC_GCache_Lookup. This function will
  78. * automatically:
  79. *
  80. * - Search for the corresponding family in the cache, or create
  81. * a new one if necessary. Put it in FTC_GQUERY(myquery).family
  82. *
  83. * - Call FTC_Cache_Lookup.
  84. *
  85. * If it returns NULL, you should create a new node, then call
  86. * ftc_cache_add as usual.
  87. */
  88. /*************************************************************************/
  89. /* */
  90. /* Important: The functions defined in this file are only used to */
  91. /* implement an abstract glyph cache class. You need to */
  92. /* provide additional logic to implement a complete cache. */
  93. /* */
  94. /*************************************************************************/
  95. /*************************************************************************/
  96. /*************************************************************************/
  97. /*************************************************************************/
  98. /*************************************************************************/
  99. /*************************************************************************/
  100. /********* *********/
  101. /********* WARNING, THIS IS BETA CODE. *********/
  102. /********* *********/
  103. /*************************************************************************/
  104. /*************************************************************************/
  105. /*************************************************************************/
  106. /*************************************************************************/
  107. /*************************************************************************/
  108. #ifndef __FTCGLYPH_H__
  109. #define __FTCGLYPH_H__
  110. #include <ft2build.h>
  111. #include "ftcmanag.h"
  112. FT_BEGIN_HEADER
  113. /*
  114. * We can group glyphs into `families'. Each family correspond to a
  115. * given face ID, character size, transform, etc.
  116. *
  117. * Families are implemented as MRU list nodes. They are
  118. * reference-counted.
  119. */
  120. typedef struct FTC_FamilyRec_
  121. {
  122. FTC_MruNodeRec mrunode;
  123. FT_UInt num_nodes; /* current number of nodes in this family */
  124. FTC_Cache cache;
  125. FTC_MruListClass clazz;
  126. } FTC_FamilyRec, *FTC_Family;
  127. #define FTC_FAMILY(x) ( (FTC_Family)(x) )
  128. #define FTC_FAMILY_P(x) ( (FTC_Family*)(x) )
  129. typedef struct FTC_GNodeRec_
  130. {
  131. FTC_NodeRec node;
  132. FTC_Family family;
  133. FT_UInt gindex;
  134. } FTC_GNodeRec, *FTC_GNode;
  135. #define FTC_GNODE( x ) ( (FTC_GNode)(x) )
  136. #define FTC_GNODE_P( x ) ( (FTC_GNode*)(x) )
  137. typedef struct FTC_GQueryRec_
  138. {
  139. FT_UInt gindex;
  140. FTC_Family family;
  141. } FTC_GQueryRec, *FTC_GQuery;
  142. #define FTC_GQUERY( x ) ( (FTC_GQuery)(x) )
  143. /*************************************************************************/
  144. /* */
  145. /* These functions are exported so that they can be called from */
  146. /* user-provided cache classes; otherwise, they are really part of the */
  147. /* cache sub-system internals. */
  148. /* */
  149. /* must be called by derived FTC_Node_InitFunc routines */
  150. FT_LOCAL( void )
  151. FTC_GNode_Init( FTC_GNode node,
  152. FT_UInt gindex, /* glyph index for node */
  153. FTC_Family family );
  154. #ifdef FTC_INLINE
  155. /* returns TRUE iff the query's glyph index correspond to the node; */
  156. /* this assumes that the `family' and `hash' fields of the query are */
  157. /* already correctly set */
  158. FT_LOCAL( FT_Bool )
  159. FTC_GNode_Compare( FTC_GNode gnode,
  160. FTC_GQuery gquery,
  161. FTC_Cache cache,
  162. FT_Bool* list_changed );
  163. #endif
  164. /* call this function to clear a node's family -- this is necessary */
  165. /* to implement the `node_remove_faceid' cache method correctly */
  166. FT_LOCAL( void )
  167. FTC_GNode_UnselectFamily( FTC_GNode gnode,
  168. FTC_Cache cache );
  169. /* must be called by derived FTC_Node_DoneFunc routines */
  170. FT_LOCAL( void )
  171. FTC_GNode_Done( FTC_GNode node,
  172. FTC_Cache cache );
  173. FT_LOCAL( void )
  174. FTC_Family_Init( FTC_Family family,
  175. FTC_Cache cache );
  176. typedef struct FTC_GCacheRec_
  177. {
  178. FTC_CacheRec cache;
  179. FTC_MruListRec families;
  180. } FTC_GCacheRec, *FTC_GCache;
  181. #define FTC_GCACHE( x ) ((FTC_GCache)(x))
  182. #if 0
  183. /* can be used as @FTC_Cache_InitFunc */
  184. FT_LOCAL( FT_Error )
  185. FTC_GCache_Init( FTC_GCache cache );
  186. #endif
  187. #if 0
  188. /* can be used as @FTC_Cache_DoneFunc */
  189. FT_LOCAL( void )
  190. FTC_GCache_Done( FTC_GCache cache );
  191. #endif
  192. /* the glyph cache class adds fields for the family implementation */
  193. typedef struct FTC_GCacheClassRec_
  194. {
  195. FTC_CacheClassRec clazz;
  196. FTC_MruListClass family_class;
  197. } FTC_GCacheClassRec;
  198. typedef const FTC_GCacheClassRec* FTC_GCacheClass;
  199. #define FTC_GCACHE_CLASS( x ) ((FTC_GCacheClass)(x))
  200. #define FTC_CACHE__GCACHE_CLASS( x ) \
  201. FTC_GCACHE_CLASS( FTC_CACHE(x)->org_class )
  202. #define FTC_CACHE__FAMILY_CLASS( x ) \
  203. ( (FTC_MruListClass)FTC_CACHE__GCACHE_CLASS( x )->family_class )
  204. /* convenience function; use it instead of FTC_Manager_Register_Cache */
  205. FT_LOCAL( FT_Error )
  206. FTC_GCache_New( FTC_Manager manager,
  207. FTC_GCacheClass clazz,
  208. FTC_GCache *acache );
  209. #ifndef FTC_INLINE
  210. FT_LOCAL( FT_Error )
  211. FTC_GCache_Lookup( FTC_GCache cache,
  212. FT_PtrDist hash,
  213. FT_UInt gindex,
  214. FTC_GQuery query,
  215. FTC_Node *anode );
  216. #endif
  217. /* */
  218. #define FTC_FAMILY_FREE( family, cache ) \
  219. FTC_MruList_Remove( &FTC_GCACHE((cache))->families, \
  220. (FTC_MruNode)(family) )
  221. #ifdef FTC_INLINE
  222. #define FTC_GCACHE_LOOKUP_CMP( cache, famcmp, nodecmp, hash, \
  223. gindex, query, node, error ) \
  224. FT_BEGIN_STMNT \
  225. FTC_GCache _gcache = FTC_GCACHE( cache ); \
  226. FTC_GQuery _gquery = (FTC_GQuery)( query ); \
  227. FTC_MruNode_CompareFunc _fcompare = (FTC_MruNode_CompareFunc)(famcmp); \
  228. FTC_MruNode _mrunode; \
  229. \
  230. \
  231. _gquery->gindex = (gindex); \
  232. \
  233. FTC_MRULIST_LOOKUP_CMP( &_gcache->families, _gquery, _fcompare, \
  234. _mrunode, error ); \
  235. _gquery->family = FTC_FAMILY( _mrunode ); \
  236. if ( !error ) \
  237. { \
  238. FTC_Family _gqfamily = _gquery->family; \
  239. \
  240. \
  241. _gqfamily->num_nodes++; \
  242. \
  243. FTC_CACHE_LOOKUP_CMP( cache, nodecmp, hash, query, node, error ); \
  244. \
  245. if ( --_gqfamily->num_nodes == 0 ) \
  246. FTC_FAMILY_FREE( _gqfamily, _gcache ); \
  247. } \
  248. FT_END_STMNT
  249. /* */
  250. #else /* !FTC_INLINE */
  251. #define FTC_GCACHE_LOOKUP_CMP( cache, famcmp, nodecmp, hash, \
  252. gindex, query, node, error ) \
  253. FT_BEGIN_STMNT \
  254. \
  255. error = FTC_GCache_Lookup( FTC_GCACHE( cache ), hash, gindex, \
  256. FTC_GQUERY( query ), &node ); \
  257. \
  258. FT_END_STMNT
  259. #endif /* !FTC_INLINE */
  260. FT_END_HEADER
  261. #endif /* __FTCGLYPH_H__ */
  262. /* END */