ftcglyph.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /***************************************************************************/
  2. /* */
  3. /* ftcglyph.h */
  4. /* */
  5. /* FreeType abstract glyph cache (specification). */
  6. /* */
  7. /* Copyright 2000-2001 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. /* Important: The functions defined in this file are only used to */
  20. /* implement an abstract glyph cache class. You need to */
  21. /* provide additional logic to implement a complete cache. */
  22. /* For example, see `ftcimage.h' and `ftcimage.c' which */
  23. /* implement a FT_Glyph cache based on this code. */
  24. /* */
  25. /*************************************************************************/
  26. /*************************************************************************/
  27. /*************************************************************************/
  28. /*************************************************************************/
  29. /*************************************************************************/
  30. /*************************************************************************/
  31. /********* *********/
  32. /********* WARNING, THIS IS BETA CODE. *********/
  33. /********* *********/
  34. /*************************************************************************/
  35. /*************************************************************************/
  36. /*************************************************************************/
  37. /*************************************************************************/
  38. /*************************************************************************/
  39. #ifndef __FTCGLYPH_H__
  40. #define __FTCGLYPH_H__
  41. #include <ft2build.h>
  42. #include FT_CACHE_H
  43. #include FT_CACHE_MANAGER_H
  44. FT_BEGIN_HEADER
  45. /* each glyph set is characterized by a "glyph set type" which must be */
  46. /* defined by sub-classes */
  47. typedef struct FTC_GlyphFamilyRec_* FTC_GlyphFamily;
  48. /* handle to a glyph cache node */
  49. typedef struct FTC_GlyphNodeRec_* FTC_GlyphNode;
  50. /* size should be 24 + chunk size on 32-bit machines; */
  51. /* note that the node's hash is ((gfam->hash << 16) | glyph_index) -- */
  52. /* this _must_ be set properly by the glyph node initializer */
  53. /* */
  54. typedef struct FTC_GlyphNodeRec_
  55. {
  56. FTC_NodeRec node;
  57. FT_UShort item_count;
  58. FT_UShort item_start;
  59. } FTC_GlyphNodeRec;
  60. #define FTC_GLYPH_NODE( x ) ( (FTC_GlyphNode)(x) )
  61. #define FTC_GLYPH_NODE_P( x ) ( (FTC_GlyphNode*)(x) )
  62. typedef struct FTC_GlyphQueryRec_
  63. {
  64. FTC_QueryRec query;
  65. FT_UInt gindex;
  66. } FTC_GlyphQueryRec, *FTC_GlyphQuery;
  67. #define FTC_GLYPH_QUERY( x ) ( (FTC_GlyphQuery)(x) )
  68. /* a glyph set is used to categorize glyphs of a given type */
  69. typedef struct FTC_GlyphFamilyRec_
  70. {
  71. FTC_FamilyRec family;
  72. FT_UInt32 hash;
  73. FT_UInt item_total; /* total number of glyphs in family */
  74. FT_UInt item_count; /* number of glyph items per node */
  75. } FTC_GlyphFamilyRec;
  76. #define FTC_GLYPH_FAMILY( x ) ( (FTC_GlyphFamily)(x) )
  77. #define FTC_GLYPH_FAMILY_P( x ) ( (FTC_GlyphFamily*)(x) )
  78. #define FTC_GLYPH_FAMILY_MEMORY( x ) FTC_FAMILY(x)->cache->memory
  79. /* each glyph node contains a 'chunk' of glyph items; */
  80. /* translate a glyph index into a chunk index */
  81. #define FTC_GLYPH_FAMILY_CHUNK( gfam, gindex ) \
  82. ( ( gindex ) / FTC_GLYPH_FAMILY( gfam )->item_count )
  83. /* find a glyph index's chunk, and return its start index */
  84. #define FTC_GLYPH_FAMILY_START( gfam, gindex ) \
  85. ( FTC_GLYPH_FAMILY_CHUNK( gfam, gindex ) * \
  86. FTC_GLYPH_FAMILY( gfam )->item_count )
  87. /* compute a glyph request's hash value */
  88. #define FTC_GLYPH_FAMILY_HASH( gfam, gindex ) \
  89. ( (FT_UFast)( \
  90. ( FTC_GLYPH_FAMILY( gfam )->hash << 16 ) | \
  91. ( FTC_GLYPH_FAMILY_CHUNK( gfam, gindex ) & 0xFFFF ) ) )
  92. /* must be called in an FTC_Family_CompareFunc to update the query */
  93. /* whenever a glyph set is matched in the lookup, or when it */
  94. /* is created */
  95. #define FTC_GLYPH_FAMILY_FOUND( gfam, gquery ) \
  96. do \
  97. { \
  98. FTC_QUERY( gquery )->family = FTC_FAMILY( gfam ); \
  99. FTC_QUERY( gquery )->hash = \
  100. FTC_GLYPH_FAMILY_HASH( gfam, \
  101. FTC_GLYPH_QUERY( gquery )->gindex ); \
  102. } while ( 0 )
  103. /* retrieve glyph index of glyph node */
  104. #define FTC_GLYPH_NODE_GINDEX( x ) \
  105. ( (FT_UInt)( FTC_GLYPH_NODE( x )->node.hash & 0xFFFF ) )
  106. /*************************************************************************/
  107. /* */
  108. /* These functions are exported so that they can be called from */
  109. /* user-provided cache classes; otherwise, they are really part of the */
  110. /* cache sub-system internals. */
  111. /* */
  112. /* must be called by derived FTC_Node_InitFunc routines */
  113. FT_EXPORT( void )
  114. ftc_glyph_node_init( FTC_GlyphNode node,
  115. FT_UInt gindex, /* glyph index for node */
  116. FTC_GlyphFamily gfam );
  117. /* returns TRUE iff the query's glyph index correspond to the node; */
  118. /* this assumes that the "family" and "hash" fields of the query are */
  119. /* already correctly set */
  120. FT_EXPORT( FT_Bool )
  121. ftc_glyph_node_compare( FTC_GlyphNode gnode,
  122. FTC_GlyphQuery gquery );
  123. /* must be called by derived FTC_Node_DoneFunc routines */
  124. FT_EXPORT( void )
  125. ftc_glyph_node_done( FTC_GlyphNode node,
  126. FTC_Cache cache );
  127. /* must be called by derived FTC_Family_InitFunc; */
  128. /* calls "ftc_family_init" */
  129. FT_EXPORT( FT_Error )
  130. ftc_glyph_family_init( FTC_GlyphFamily gfam,
  131. FT_UInt32 hash,
  132. FT_UInt item_count,
  133. FT_UInt item_total,
  134. FTC_GlyphQuery gquery,
  135. FTC_Cache cache );
  136. FT_EXPORT( void )
  137. ftc_glyph_family_done( FTC_GlyphFamily gfam );
  138. /* */
  139. FT_END_HEADER
  140. #endif /* __FTCGLYPH_H__ */
  141. /* END */