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