1 /***************************************************************************/
5 /* FreeType abstract glyph cache (specification). */
7 /* Copyright 2000-2001 by */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
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. */
16 /***************************************************************************/
19 /*************************************************************************/
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. */
27 /* NOTE: For now, each glyph set is implemented as a static hash table. */
28 /* It would be interesting to experiment with dynamic hashes to */
29 /* see whether this improves performance or not (I don't know why */
30 /* but something tells me it won't). */
32 /* In all cases, this change should not affect any derived glyph */
35 /*************************************************************************/
38 /*************************************************************************/
39 /*************************************************************************/
40 /*************************************************************************/
41 /*************************************************************************/
42 /*************************************************************************/
44 /********* WARNING, THIS IS BETA CODE. *********/
46 /*************************************************************************/
47 /*************************************************************************/
48 /*************************************************************************/
49 /*************************************************************************/
50 /*************************************************************************/
53 #ifndef __FTCGLYPH_H__
54 #define __FTCGLYPH_H__
59 #include FT_CACHE_MANAGER_H
67 /* maximum number of glyph sets per glyph cache; must be < 256 */
68 #define FTC_MAX_GLYPH_SETS 16
69 #define FTC_GSET_HASH_SIZE_DEFAULT 64
72 typedef struct FTC_GlyphSetRec_* FTC_GlyphSet;
73 typedef struct FTC_GlyphNodeRec_* FTC_GlyphNode;
74 typedef struct FTC_Glyph_CacheRec_* FTC_Glyph_Cache;
76 typedef struct FTC_GlyphNodeRec_
78 FTC_CacheNodeRec root;
79 FTC_GlyphNode gset_next; /* next in glyph set's bucket list */
80 FT_UShort glyph_index;
86 #define FTC_GLYPHNODE( x ) ( (FTC_GlyphNode)( x ) )
87 #define FTC_GLYPHNODE_TO_LRUNODE( n ) ( (FT_ListNode)( n ) )
88 #define FTC_LRUNODE_TO_GLYPHNODE( n ) ( (FTC_GlyphNode)( n ) )
91 /*************************************************************************/
93 /* Glyph set methods. */
97 (*FTC_GlyphSet_InitFunc)( FTC_GlyphSet gset,
101 (*FTC_GlyphSet_DoneFunc)( FTC_GlyphSet gset );
104 (*FTC_GlyphSet_CompareFunc)( FTC_GlyphSet gset,
109 (*FTC_GlyphSet_NewNodeFunc)( FTC_GlyphSet gset,
111 FTC_GlyphNode* anode );
114 (*FTC_GlyphSet_DestroyNodeFunc)( FTC_GlyphNode node,
118 (*FTC_GlyphSet_SizeNodeFunc)( FTC_GlyphNode node,
122 typedef struct FTC_GlyphSet_Class_
124 FT_UInt gset_byte_size;
126 FTC_GlyphSet_InitFunc init;
127 FTC_GlyphSet_DoneFunc done;
128 FTC_GlyphSet_CompareFunc compare;
130 FTC_GlyphSet_NewNodeFunc new_node;
131 FTC_GlyphSet_SizeNodeFunc size_node;
132 FTC_GlyphSet_DestroyNodeFunc destroy_node;
134 } FTC_GlyphSet_Class;
137 typedef struct FTC_GlyphSetRec_
139 FTC_Glyph_Cache cache;
142 FTC_GlyphSet_Class* clazz;
144 FTC_GlyphNode* buckets;
145 FT_UInt gset_index; /* index in parent cache */
150 /* the abstract glyph cache class */
151 typedef struct FTC_Glyph_Cache_Class_
153 FTC_Cache_Class root;
154 FTC_GlyphSet_Class* gset_class;
156 } FTC_Glyph_Cache_Class;
159 /* the abstract glyph cache object */
160 typedef struct FTC_Glyph_CacheRec_
163 FT_Lru gsets_lru; /* static sets lru list */
164 FTC_GlyphSet last_gset; /* small cache :-) */
165 FTC_GlyphSet_CompareFunc compare; /* useful shortcut */
167 } FTC_Glyph_CacheRec;
170 /*************************************************************************/
172 /* These functions are exported so that they can be called from */
173 /* user-provided cache classes; otherwise, they are really part of the */
174 /* cache sub-system internals. */
178 FTC_GlyphNode_Init( FTC_GlyphNode node,
182 #define FTC_GlyphNode_Ref( n ) \
183 FTC_CACHENODE_TO_DATA_P( &(n)->root )->ref_count++
185 #define FTC_GlyphNode_Unref( n ) \
186 FTC_CACHENODE_TO_DATA_P( &(n)->root )->ref_count--
190 FTC_GlyphNode_Destroy( FTC_GlyphNode node,
191 FTC_Glyph_Cache cache );
193 FT_EXPORT( FT_Error )
194 FTC_Glyph_Cache_Init( FTC_Glyph_Cache cache );
197 FTC_Glyph_Cache_Done( FTC_Glyph_Cache cache );
200 FT_EXPORT( FT_Error )
201 FTC_GlyphSet_New( FTC_Glyph_Cache cache,
203 FTC_GlyphSet *aset );
205 FT_EXPORT( FT_Error )
206 FTC_GlyphSet_Lookup_Node( FTC_GlyphSet gset,
208 FTC_GlyphNode *anode );
210 FT_EXPORT( FT_Error )
211 FTC_Glyph_Cache_Lookup( FTC_Glyph_Cache cache,
214 FTC_GlyphNode *anode );
219 #endif /* __FTCGLYPH_H__ */