diff options
Diffstat (limited to 'include/freetype/cache')
| -rw-r--r-- | include/freetype/cache/ftccache.h | 304 | ||||
| -rw-r--r-- | include/freetype/cache/ftccmap.h | 216 | ||||
| -rw-r--r-- | include/freetype/cache/ftcglyph.h | 193 | ||||
| -rw-r--r-- | include/freetype/cache/ftcimage.h | 312 | ||||
| -rw-r--r-- | include/freetype/cache/ftcmanag.h | 244 | ||||
| -rw-r--r-- | include/freetype/cache/ftcsbits.h | 275 | ||||
| -rw-r--r-- | include/freetype/cache/ftlru.h | 202 |
7 files changed, 1746 insertions, 0 deletions
diff --git a/include/freetype/cache/ftccache.h b/include/freetype/cache/ftccache.h new file mode 100644 index 00000000..701b13eb --- /dev/null +++ b/include/freetype/cache/ftccache.h @@ -0,0 +1,304 @@ +/***************************************************************************/ +/* */ +/* ftccache.h */ +/* */ +/* FreeType internal cache interface (specification). */ +/* */ +/* Copyright 2000-2001, 2002 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef __FTCCACHE_H__ +#define __FTCCACHE_H__ + + +/* define to allow cache lookup inlining */ +#define FTC_CACHE_USE_INLINE + + +FT_BEGIN_HEADER + + /* handle to cache object */ + typedef struct FTC_CacheRec_* FTC_Cache; + + /* handle to cache class */ + typedef const struct FTC_Cache_ClassRec_* FTC_Cache_Class; + + /* handle to cache node family */ + typedef struct FTC_FamilyRec_* FTC_Family; + + /* handle to cache root query */ + typedef struct FTC_QueryRec_* FTC_Query; + + + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** CACHE NODE DEFINITIONS *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /* Each cache controls one or more cache nodes. Each node is part of */ + /* the global_lru list of the manager. Its `data' field however is used */ + /* as a reference count for now. */ + /* */ + /* A node can be anything, depending on the type of information held by */ + /* the cache. It can be an individual glyph image, a set of bitmaps */ + /* glyphs for a given size, some metrics, etc. */ + /* */ + /*************************************************************************/ + + /* structure size should be 20 bytes on 32-bits machines */ + typedef struct FTC_NodeRec_ + { + FTC_Node mru_next; /* circular mru list pointer */ + FTC_Node mru_prev; /* circular mru list pointer */ + FTC_Node link; /* used for hashing */ + FT_UInt32 hash; /* used for hashing too */ + FT_UShort fam_index; /* index of family the node belongs to */ + FT_Short ref_count; /* reference count for this node */ + + } FTC_NodeRec; + + +#define FTC_NODE( x ) ( (FTC_Node)(x) ) +#define FTC_NODE_P( x ) ( (FTC_Node*)(x) ) + + + /*************************************************************************/ + /* */ + /* These functions are exported so that they can be called from */ + /* user-provided cache classes; otherwise, they are really part of the */ + /* cache sub-system internals. */ + /* */ + + /* can be used as a FTC_Node_DoneFunc */ + FT_EXPORT( void ) + ftc_node_done( FTC_Node node, + FTC_Cache cache ); + + /* reserved for manager's use */ + FT_EXPORT( void ) + ftc_node_destroy( FTC_Node node, + FTC_Manager manager ); + + + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** CACHE QUERY DEFINITIONS *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ + + /* A structure modelling a cache node query. The following fields must */ + /* all be set by the @FTC_Family_CompareFunc method of a cache's family */ + /* list. */ + /* */ + typedef struct FTC_QueryRec_ + { + FTC_Family family; + FT_UFast hash; + + } FTC_QueryRec; + + +#define FTC_QUERY( x ) ( (FTC_Query)(x) ) +#define FTC_QUERY_P( x ) ( (FTC_Query*)(x) ) + + + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** CACHE FAMILY DEFINITIONS *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ + + typedef struct FTC_FamilyRec_ + { + FT_LruNodeRec lru; + FTC_Cache cache; + FT_UInt num_nodes; + FT_UInt fam_index; + + } FTC_FamilyRec; + + +#define FTC_FAMILY( x ) ( (FTC_Family)(x) ) +#define FTC_FAMILY_P( x ) ( (FTC_Family*)(x) ) + + + /*************************************************************************/ + /* */ + /* These functions are exported so that they can be called from */ + /* user-provided cache classes; otherwise, they are really part of the */ + /* cache sub-system internals. */ + /* */ + + /* must be called by any FTC_Node_InitFunc routine */ + FT_EXPORT( FT_Error ) + ftc_family_init( FTC_Family family, + FTC_Query query, + FTC_Cache cache ); + + + /* can be used as a FTC_Family_DoneFunc; otherwise, must be called */ + /* by any family finalizer function */ + FT_EXPORT( void ) + ftc_family_done( FTC_Family family ); + + + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** CACHE DEFINITIONS *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ + + /* each cache really implements a dynamic hash table to manage its nodes */ + typedef struct FTC_CacheRec_ + { + FTC_Manager manager; + FT_Memory memory; + FTC_Cache_Class clazz; + + FT_UInt cache_index; /* in manager's table */ + FT_Pointer cache_data; /* used by cache node methods */ + + FT_UFast p; + FT_UFast mask; + FT_Long slack; + FTC_Node* buckets; + + FT_LruList_ClassRec family_class; + FT_LruList families; + + } FTC_CacheRec; + + +#define FTC_CACHE( x ) ( (FTC_Cache)(x) ) +#define FTC_CACHE_P( x ) ( (FTC_Cache*)(x) ) + + + /* initialize a given cache */ + typedef FT_Error + (*FTC_Cache_InitFunc)( FTC_Cache cache ); + + /* clear a cache */ + typedef void + (*FTC_Cache_ClearFunc)( FTC_Cache cache ); + + /* finalize a given cache */ + typedef void + (*FTC_Cache_DoneFunc)( FTC_Cache cache ); + + + typedef FT_Error + (*FTC_Family_InitFunc)( FTC_Family family, + FTC_Query query, + FTC_Cache cache ); + + typedef FT_Int + (*FTC_Family_CompareFunc)( FTC_Family family, + FTC_Query query ); + + typedef void + (*FTC_Family_DoneFunc)( FTC_Family family, + FTC_Cache cache ); + + /* initialize a new cache node */ + typedef FT_Error + (*FTC_Node_InitFunc)( FTC_Node node, + FT_Pointer type, + FTC_Cache cache ); + + /* compute the weight of a given cache node */ + typedef FT_ULong + (*FTC_Node_WeightFunc)( FTC_Node node, + FTC_Cache cache ); + + /* compare a node to a given key pair */ + typedef FT_Bool + (*FTC_Node_CompareFunc)( FTC_Node node, + FT_Pointer key, + FTC_Cache cache ); + + /* finalize a given cache node */ + typedef void + (*FTC_Node_DoneFunc)( FTC_Node node, + FTC_Cache cache ); + + + typedef struct FTC_Cache_ClassRec_ + { + FT_UInt cache_size; + FTC_Cache_InitFunc cache_init; + FTC_Cache_ClearFunc cache_clear; + FTC_Cache_DoneFunc cache_done; + + FT_UInt family_size; + FTC_Family_InitFunc family_init; + FTC_Family_CompareFunc family_compare; + FTC_Family_DoneFunc family_done; + + FT_UInt node_size; + FTC_Node_InitFunc node_init; + FTC_Node_WeightFunc node_weight; + FTC_Node_CompareFunc node_compare; + FTC_Node_DoneFunc node_done; + + } FTC_Cache_ClassRec; + + + /* */ + + + /*************************************************************************/ + /* */ + /* These functions are exported so that they can be called from */ + /* user-provided cache classes; otherwise, they are really part of the */ + /* cache sub-system internals. */ + /* */ + + /* can be used directly as FTC_Cache_DoneFunc(), or called by custom */ + /* cache finalizers */ + FT_EXPORT( void ) + ftc_cache_done( FTC_Cache cache ); + + /* can be used directly as FTC_Cache_ClearFunc(), or called by custom */ + /* cache clear routines */ + FT_EXPORT( void ) + ftc_cache_clear( FTC_Cache cache ); + + /* initalize the hash table within the cache */ + FT_EXPORT( FT_Error ) + ftc_cache_init( FTC_Cache cache ); + + /* can be called when the key's hash value has been computed */ + FT_EXPORT( FT_Error ) + ftc_cache_lookup( FTC_Cache cache, + FTC_Query query, + FTC_Node *anode ); + + /* */ + +FT_END_HEADER + + +#endif /* __FTCCACHE_H__ */ + + +/* END */ diff --git a/include/freetype/cache/ftccmap.h b/include/freetype/cache/ftccmap.h new file mode 100644 index 00000000..11f7b03b --- /dev/null +++ b/include/freetype/cache/ftccmap.h @@ -0,0 +1,216 @@ +/***************************************************************************/ +/* */ +/* ftccmap.h */ +/* */ +/* FreeType charmap cache (specification). */ +/* */ +/* Copyright 2000-2001 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef __FTCCMAP_H__ +#define __FTCCMAP_H__ + +#include <ft2build.h> +#include FT_CACHE_H + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* cache_subsystem */ + /* */ + /*************************************************************************/ + + /*************************************************************************/ + /* */ + /* @type: */ + /* FTC_CmapCache */ + /* */ + /* @description: */ + /* An opaque handle used to manager a charmap cache. This cache is */ + /* to hold character codes -> glyph indices mappings. */ + /* */ + typedef struct FTC_CMapCacheRec_* FTC_CMapCache; + + + /*************************************************************************/ + /* */ + /* @type: */ + /* FTC_CMapDesc */ + /* */ + /* @description: */ + /* A handle to an @FTC_CMapDescRec structure used to describe a given */ + /* charmap in a charmap cache. */ + /* */ + /* Each @FTC_CMapDesc describes which charmap (of which @FTC_Face) we */ + /* want to use in @FTC_CMapCache_Lookup. */ + /* */ + typedef struct FTC_CMapDescRec_* FTC_CMapDesc; + + + /*************************************************************************/ + /* */ + /* @enum: */ + /* FTC_CMapType */ + /* */ + /* @description: */ + /* The list of valid @FTC_CMap types. They indicate how we want to */ + /* address a charmap within an @FTC_FaceID. */ + /* */ + /* @values: */ + /* FTC_CMAP_BY_INDEX :: */ + /* Address a charmap by its index in the corresponding @FT_Face. */ + /* */ + /* FTC_CMAP_BY_ENCODING :: */ + /* Use a @FT_Face charmap that corresponds to a given encoding. */ + /* */ + /* FTC_CMAP_BY_ID :: */ + /* Use an @FT_Face charmap that corresponds to a given */ + /* (platform,encoding) ID. See @FTC_CMapIdRec. */ + /* */ + typedef enum FTC_CMapType_ + { + FTC_CMAP_BY_INDEX = 0, + FTC_CMAP_BY_ENCODING = 1, + FTC_CMAP_BY_ID = 2 + + } FTC_CMapType; + + + /*************************************************************************/ + /* */ + /* @struct: */ + /* FTC_CMapIdRec */ + /* */ + /* @description: */ + /* A short structure to identify a charmap by a (platform,encoding) */ + /* pair of values. */ + /* */ + /* @fields: */ + /* platform :: The platform ID. */ + /* */ + /* encoding :: The encoding ID. */ + /* */ + typedef struct FTC_CMapIdRec_ + { + FT_UInt platform; + FT_UInt encoding; + + } FTC_CMapIdRec; + + + /*************************************************************************/ + /* */ + /* @struct: */ + /* FTC_CMapDescRec */ + /* */ + /* @description: */ + /* A structure to describe a given charmap to @FTC_CMapCache. */ + /* */ + /* @fields: */ + /* face_id :: @FTC_FaceID of the face this charmap belongs to. */ + /* */ + /* type :: The type of charmap, see @FTC_CMapType. */ + /* */ + /* u.index :: For @FTC_CMAP_BY_INDEX types, this is the charmap */ + /* index (within a @FT_Face) we want to use. */ + /* */ + /* u.encoding :: For @FTC_CMAP_BY_ENCODING types, this is the charmap */ + /* encoding we want to use. see @FT_Encoding. */ + /* */ + /* u.id :: For @FTC_CMAP_BY_ID types, this is the */ + /* (platform,encoding) pair we want to use. see */ + /* @FTC_CMapIdRec and @FT_CharMapRec. */ + /* */ + typedef struct FTC_CMapDescRec_ + { + FTC_FaceID face_id; + FTC_CMapType type; + + union + { + FT_UInt index; + FT_Encoding encoding; + FTC_CMapIdRec id; + + } u; + + } FTC_CMapDescRec; + + + /*************************************************************************/ + /* */ + /* @function: */ + /* FTC_CMapCache_New */ + /* */ + /* @description: */ + /* Creates a new charmap cache. */ + /* */ + /* @input: */ + /* manager :: A handle to the cache manager. */ + /* */ + /* @output: */ + /* acache :: A new cache handle. NULL in case of error. */ + /* */ + /* @return: */ + /* FreeType error code. 0 means success. */ + /* */ + /* @note: */ + /* Like all other caches, this one will be destroyed with the cache */ + /* manager. */ + /* */ + FT_EXPORT( FT_Error ) + FTC_CMapCache_New( FTC_Manager manager, + FTC_CMapCache *acache ); + + + /*************************************************************************/ + /* */ + /* @function: */ + /* FTC_CMapCache_Lookup */ + /* */ + /* @description: */ + /* Translates a character code into a glyph index, using the charmap */ + /* cache. */ + /* */ + /* @input: */ + /* cache :: A charmap cache handle. */ + /* */ + /* cmap_desc :: A charmap descriptor handle. */ + /* */ + /* char_code :: The character code (in the corresponding charmap). */ + /* */ + /* @return: */ + /* Glyph index. 0 means "no glyph". */ + /* */ + /* @note: */ + /* This function doesn't return @FTC_Node handles, since there is no */ + /* real use for them with typical uses of charmaps. */ + /* */ + FT_EXPORT( FT_UInt ) + FTC_CMapCache_Lookup( FTC_CMapCache cache, + FTC_CMapDesc cmap_desc, + FT_UInt32 char_code ); + + /* */ + + +FT_END_HEADER + + +#endif /* __FTCCMAP_H__ */ + + +/* END */ diff --git a/include/freetype/cache/ftcglyph.h b/include/freetype/cache/ftcglyph.h new file mode 100644 index 00000000..3d14cf02 --- /dev/null +++ b/include/freetype/cache/ftcglyph.h @@ -0,0 +1,193 @@ +/***************************************************************************/ +/* */ +/* ftcglyph.h */ +/* */ +/* FreeType abstract glyph cache (specification). */ +/* */ +/* Copyright 2000-2001 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* Important: The functions defined in this file are only used to */ + /* implement an abstract glyph cache class. You need to */ + /* provide additional logic to implement a complete cache. */ + /* For example, see `ftcimage.h' and `ftcimage.c' which */ + /* implement a FT_Glyph cache based on this code. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /********* *********/ + /********* WARNING, THIS IS BETA CODE. *********/ + /********* *********/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + + +#ifndef __FTCGLYPH_H__ +#define __FTCGLYPH_H__ + + +#include <ft2build.h> +#include FT_CACHE_H +#include FT_CACHE_MANAGER_H + +#include <stddef.h> + + +FT_BEGIN_HEADER + + + /* each glyph set is characterized by a "glyph set type" which must be */ + /* defined by sub-classes */ + typedef struct FTC_GlyphFamilyRec_* FTC_GlyphFamily; + + /* handle to a glyph cache node */ + typedef struct FTC_GlyphNodeRec_* FTC_GlyphNode; + + + /* size should be 24 + chunk size on 32-bit machines; */ + /* note that the node's hash is ((gfam->hash << 16) | glyph_index) -- */ + /* this _must_ be set properly by the glyph node initializer */ + /* */ + typedef struct FTC_GlyphNodeRec_ + { + FTC_NodeRec node; + FT_UShort item_count; + FT_UShort item_start; + + } FTC_GlyphNodeRec; + + +#define FTC_GLYPH_NODE( x ) ( (FTC_GlyphNode)(x) ) +#define FTC_GLYPH_NODE_P( x ) ( (FTC_GlyphNode*)(x) ) + + + typedef struct FTC_GlyphQueryRec_ + { + FTC_QueryRec query; + FT_UInt gindex; + + } FTC_GlyphQueryRec, *FTC_GlyphQuery; + + +#define FTC_GLYPH_QUERY( x ) ( (FTC_GlyphQuery)(x) ) + + + /* a glyph set is used to categorize glyphs of a given type */ + typedef struct FTC_GlyphFamilyRec_ + { + FTC_FamilyRec family; + FT_UInt32 hash; + FT_UInt item_total; /* total number of glyphs in family */ + FT_UInt item_count; /* number of glyph items per node */ + + } FTC_GlyphFamilyRec; + + +#define FTC_GLYPH_FAMILY( x ) ( (FTC_GlyphFamily)(x) ) +#define FTC_GLYPH_FAMILY_P( x ) ( (FTC_GlyphFamily*)(x) ) + +#define FTC_GLYPH_FAMILY_MEMORY( x ) FTC_FAMILY(x)->cache->memory + + + /* each glyph node contains a 'chunk' of glyph items; */ + /* translate a glyph index into a chunk index */ +#define FTC_GLYPH_FAMILY_CHUNK( gfam, gindex ) \ + ( ( gindex ) / FTC_GLYPH_FAMILY( gfam )->item_count ) + + /* find a glyph index's chunk, and return its start index */ +#define FTC_GLYPH_FAMILY_START( gfam, gindex ) \ + ( FTC_GLYPH_FAMILY_CHUNK( gfam, gindex ) * \ + FTC_GLYPH_FAMILY( gfam )->item_count ) + + /* compute a glyph request's hash value */ +#define FTC_GLYPH_FAMILY_HASH( gfam, gindex ) \ + ( (FT_UFast)( \ + ( FTC_GLYPH_FAMILY( gfam )->hash << 16 ) | \ + ( FTC_GLYPH_FAMILY_CHUNK( gfam, gindex ) & 0xFFFF ) ) ) + + /* must be called in an FTC_Family_CompareFunc to update the query */ + /* whenever a glyph set is matched in the lookup, or when it */ + /* is created */ +#define FTC_GLYPH_FAMILY_FOUND( gfam, gquery ) \ + do \ + { \ + FTC_QUERY( gquery )->family = FTC_FAMILY( gfam ); \ + FTC_QUERY( gquery )->hash = \ + FTC_GLYPH_FAMILY_HASH( gfam, \ + FTC_GLYPH_QUERY( gquery )->gindex ); \ + } while ( 0 ) + + /* retrieve glyph index of glyph node */ +#define FTC_GLYPH_NODE_GINDEX( x ) \ + ( (FT_UInt)( FTC_GLYPH_NODE( x )->node.hash & 0xFFFF ) ) + + + /*************************************************************************/ + /* */ + /* These functions are exported so that they can be called from */ + /* user-provided cache classes; otherwise, they are really part of the */ + /* cache sub-system internals. */ + /* */ + + /* must be called by derived FTC_Node_InitFunc routines */ + FT_EXPORT( void ) + ftc_glyph_node_init( FTC_GlyphNode node, + FT_UInt gindex, /* glyph index for node */ + FTC_GlyphFamily gfam ); + + /* returns TRUE iff the query's glyph index correspond to the node; */ + /* this assumes that the "family" and "hash" fields of the query are */ + /* already correctly set */ + FT_EXPORT( FT_Bool ) + ftc_glyph_node_compare( FTC_GlyphNode gnode, + FTC_GlyphQuery gquery ); + + /* must be called by derived FTC_Node_DoneFunc routines */ + FT_EXPORT( void ) + ftc_glyph_node_done( FTC_GlyphNode node, + FTC_Cache cache ); + + + /* must be called by derived FTC_Family_InitFunc; */ + /* calls "ftc_family_init" */ + FT_EXPORT( FT_Error ) + ftc_glyph_family_init( FTC_GlyphFamily gfam, + FT_UInt32 hash, + FT_UInt item_count, + FT_UInt item_total, + FTC_GlyphQuery gquery, + FTC_Cache cache ); + + FT_EXPORT( void ) + ftc_glyph_family_done( FTC_GlyphFamily gfam ); + + + /* */ + +FT_END_HEADER + + +#endif /* __FTCGLYPH_H__ */ + + +/* END */ diff --git a/include/freetype/cache/ftcimage.h b/include/freetype/cache/ftcimage.h new file mode 100644 index 00000000..382d991d --- /dev/null +++ b/include/freetype/cache/ftcimage.h @@ -0,0 +1,312 @@ +/***************************************************************************/ +/* */ +/* ftcimage.h */ +/* */ +/* FreeType Image cache (specification). */ +/* */ +/* Copyright 2000-2001, 2002 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* Each image cache really manages FT_Glyph objects. */ + /* */ + /*************************************************************************/ + + +#ifndef __FTCIMAGE_H__ +#define __FTCIMAGE_H__ + + +#include <ft2build.h> +#include FT_CACHE_H + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* cache_subsystem */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** IMAGE CACHE OBJECT *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + + + /************************************************************************** + * + * @struct: + * FTC_ImageTypeRec + * + * @description: + * A simple structure used to describe the type of glyph image to be + * loaded into the cache. + * + * @fields: + * font :: An @FTC_FontRec used to describe the glyph's face and size. + * + * flags :: The load flags to be applied when loading the glyph; see + * the @FT_LOAD_XXX constants for details. + * + * @note: + * This type completely replaces the @FTC_Image_Desc structure which is + * now obsolete. + */ + typedef struct FTC_ImageTypeRec_ + { + FTC_FontRec font; + FT_Int32 flags; + + } FTC_ImageTypeRec; + + typedef struct FTC_ImageTypeRec_* FTC_ImageType; + + /* */ + +#define FTC_IMAGE_TYPE_COMPARE( d1, d2 ) \ + ( FTC_FONT_COMPARE( &(d1)->font, &(d2)->font ) && \ + (d1)->flags == (d2)->flags ) + +#define FTC_IMAGE_TYPE_HASH( d ) \ + (FT_UFast)( FTC_FONT_HASH( &(d)->font ) ^ \ + ( (d)->flags << 4 ) ) + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FTC_ImageCache */ + /* */ + /* <Description> */ + /* A handle to an glyph image cache object. They are designed to */ + /* hold many distinct glyph images while not exceeding a certain */ + /* memory threshold. */ + /* */ + typedef struct FTC_ImageCacheRec_* FTC_ImageCache; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_ImageCache_New */ + /* */ + /* <Description> */ + /* Creates a new glyph image cache. */ + /* */ + /* <Input> */ + /* manager :: The parent manager for the image cache. */ + /* */ + /* <Output> */ + /* acache :: A handle to the new glyph image cache object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0 means success. */ + /* */ + FT_EXPORT( FT_Error ) + FTC_ImageCache_New( FTC_Manager manager, + FTC_ImageCache *acache ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_ImageCache_Lookup */ + /* */ + /* <Description> */ + /* Retrieves a given glyph image from a glyph image cache. */ + /* */ + /* <Input> */ + /* cache :: A handle to the source glyph image cache. */ + /* */ + /* type :: A pointer to a glyph image type descriptor. */ + /* */ + /* gindex :: The glyph index to retrieve. */ + /* */ + /* <Output> */ + /* aglyph :: The corresponding @FT_Glyph object. 0 in case of */ + /* failure. */ + /* */ + /* anode :: Used to return the address of of the corresponding cache */ + /* node after incrementing its reference count (see note */ + /* below). */ + /* */ + /* <Return> */ + /* FreeType error code. 0 means success. */ + /* */ + /* <Note> */ + /* The returned glyph is owned and managed by the glyph image cache. */ + /* Never try to transform or discard it manually! You can however */ + /* create a copy with @FT_Glyph_Copy and modify the new one. */ + /* */ + /* If "anode" is _not_ NULL, it receives the address of the cache */ + /* node containing the glyph image, after increasing its reference */ + /* count. This ensures that the node (as well as the FT_Glyph) will */ + /* always be kept in the cache until you call @FTC_Node_Unref to */ + /* "release" it. */ + /* */ + /* If "anode" is NULL, the cache node is left unchanged, which means */ + /* that the FT_Glyph could be flushed out of the cache on the next */ + /* call to one of the caching sub-system APIs. Don't assume that it */ + /* is persistent! */ + /* */ + FT_EXPORT( FT_Error ) + FTC_ImageCache_Lookup( FTC_ImageCache cache, + FTC_ImageType type, + FT_UInt gindex, + FT_Glyph *aglyph, + FTC_Node *anode ); + + /* */ + +#define ftc_image_format( x ) ( (x) & 7 ) + + +#define ftc_image_format_bitmap 0x0000 +#define ftc_image_format_outline 0x0001 + +#define ftc_image_format_mask 0x000F + +#define ftc_image_flag_monochrome 0x0010 +#define ftc_image_flag_unhinted 0x0020 +#define ftc_image_flag_autohinted 0x0040 +#define ftc_image_flag_unscaled 0x0080 +#define ftc_image_flag_no_sbits 0x0100 + + /* monochrome bitmap */ +#define ftc_image_mono ftc_image_format_bitmap | \ + ftc_image_flag_monochrome + + /* anti-aliased bitmap */ +#define ftc_image_grays ftc_image_format_bitmap + + /* scaled outline */ +#define ftc_image_outline ftc_image_format_outline + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FTC_Image_Desc */ + /* */ + /* <Description> */ + /* THIS TYPE IS DEPRECATED. Use @FTC_ImageDesc instead. */ + /* */ + /* A simple structure used to describe a given glyph image category. */ + /* */ + /* <Fields> */ + /* size :: An @FTC_SizeRec used to describe the glyph's face */ + /* and size. */ + /* */ + /* image_type :: The glyph image's type. */ + /* */ + typedef struct FTC_Image_Desc_ + { + FTC_FontRec font; + FT_UInt image_type; + + } FTC_Image_Desc; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FTC_Image_Cache */ + /* */ + /* <Description> */ + /* THIS TYPE IS DEPRECATED. Use @FTC_ImageCache instead. */ + /* */ + typedef FTC_ImageCache FTC_Image_Cache; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_Image_Cache_New */ + /* */ + /* <Description> */ + /* THIS FUNCTION IS DEPRECATED. Use @FTC_ImageCache_New instead. */ + /* */ + /* Creates a new glyph image cache. */ + /* */ + /* <Input> */ + /* manager :: The parent manager for the image cache. */ + /* */ + /* <Output> */ + /* acache :: A handle to the new glyph image cache object. */ + /* */ + /* <Return> */ + /* FreeType error code. 0 means success. */ + /* */ + FT_EXPORT( FT_Error ) + FTC_Image_Cache_New( FTC_Manager manager, + FTC_Image_Cache *acache ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_Image_Cache_Lookup */ + /* */ + /* <Description> */ + /* THIS FUNCTION IS DEPRECATED. Use @FTC_ImageCache_Lookup instead. */ + /* */ + /* <Input> */ + /* cache :: A handle to the source glyph image cache. */ + /* */ + /* desc :: A pointer to a glyph image descriptor. */ + /* */ + /* gindex :: The glyph index to retrieve. */ + /* */ + /* <Output> */ + /* aglyph :: The corresponding @FT_Glyph object. 0 in case of */ + /* failure. */ + /* */ + /* <Return> */ + /* FreeType error code. 0 means success. */ + /* */ + /* <Note> */ + /* The returned glyph is owned and managed by the glyph image cache. */ + /* Never try to transform or discard it manually! You can however */ + /* create a copy with @FT_Glyph_Copy and modify the new one. */ + /* */ + /* Because the glyph image cache limits the total amount of memory */ + /* taken by the glyphs it holds, the returned glyph might disappear */ + /* on a later invocation of this function! It is a cache after */ + /* all... */ + /* */ + /* Use this function to "lock" the glyph as long as it is needed. */ + /* */ + FT_EXPORT( FT_Error ) + FTC_Image_Cache_Lookup( FTC_Image_Cache cache, + FTC_Image_Desc* desc, + FT_UInt gindex, + FT_Glyph *aglyph ); + + /* */ + +FT_END_HEADER + + +#endif /* __FTCIMAGE_H__ */ + + +/* END */ diff --git a/include/freetype/cache/ftcmanag.h b/include/freetype/cache/ftcmanag.h new file mode 100644 index 00000000..97c77591 --- /dev/null +++ b/include/freetype/cache/ftcmanag.h @@ -0,0 +1,244 @@ +/***************************************************************************/ +/* */ +/* ftcmanag.h */ +/* */ +/* FreeType Cache Manager (specification). */ +/* */ +/* Copyright 2000-2001 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* A cache manager is in charge of the following: */ + /* */ + /* - Maintain a mapping between generic FTC_FaceIDs and live FT_Face */ + /* objects. The mapping itself is performed through a user-provided */ + /* callback. However, the manager maintains a small cache of FT_Face */ + /* and FT_Size objects in order to speed up things considerably. */ + /* */ + /* - Manage one or more cache objects. Each cache is in charge of */ + /* holding a varying number of `cache nodes'. Each cache node */ + /* represents a minimal amount of individually accessible cached */ + /* data. For example, a cache node can be an FT_Glyph image */ + /* containing a vector outline, or some glyph metrics, or anything */ + /* else. */ + /* */ + /* Each cache node has a certain size in bytes that is added to the */ + /* total amount of `cache memory' within the manager. */ + /* */ + /* All cache nodes are located in a global LRU list, where the oldest */ + /* node is at the tail of the list. */ + /* */ + /* Each node belongs to a single cache, and includes a reference */ + /* count to avoid destroying it (due to caching). */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /********* *********/ + /********* WARNING, THIS IS BETA CODE. *********/ + /********* *********/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + + +#ifndef __FTCMANAG_H__ +#define __FTCMANAG_H__ + + +#include <ft2build.h> +#include FT_CACHE_H +#include FT_CACHE_INTERNAL_LRU_H +#include FT_CACHE_INTERNAL_CACHE_H + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* cache_subsystem */ + /* */ + /*************************************************************************/ + + +#define FTC_MAX_FACES_DEFAULT 2 +#define FTC_MAX_SIZES_DEFAULT 4 +#define FTC_MAX_BYTES_DEFAULT 200000L /* ~200kByte by default */ + + /* maximum number of caches registered in a single manager */ +#define FTC_MAX_CACHES 16 + + + typedef struct FTC_FamilyEntryRec_ + { + FTC_Family family; + FTC_Cache cache; + FT_UInt index; + FT_UInt link; + + } FTC_FamilyEntryRec, *FTC_FamilyEntry; + + +#define FTC_FAMILY_ENTRY_NONE ( (FT_UInt)-1 ) + + + typedef struct FTC_FamilyTableRec_ + { + FT_UInt count; + FT_UInt size; + FTC_FamilyEntry entries; + FT_UInt free; + + } FTC_FamilyTableRec, *FTC_FamilyTable; + + + FT_EXPORT( FT_Error ) + ftc_family_table_alloc( FTC_FamilyTable table, + FT_Memory memory, + FTC_FamilyEntry *aentry ); + + FT_EXPORT( void ) + ftc_family_table_free( FTC_FamilyTable table, + FT_UInt idx ); + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FTC_ManagerRec */ + /* */ + /* <Description> */ + /* The cache manager structure. */ + /* */ + /* <Fields> */ + /* library :: A handle to a FreeType library instance. */ + /* */ + /* faces_list :: The lru list of @FT_Face objects in the cache. */ + /* */ + /* sizes_list :: The lru list of @FT_Size objects in the cache. */ + /* */ + /* max_weight :: The maximum cache pool weight. */ + /* */ + /* cur_weight :: The current cache pool weight. */ + /* */ + /* num_nodes :: The current number of nodes in the manager. */ + /* */ + /* nodes_list :: The global lru list of all cache nodes. */ + /* */ + /* caches :: A table of installed/registered cache objects. */ + /* */ + /* request_data :: User-provided data passed to the requester. */ + /* */ + /* request_face :: User-provided function used to implement a mapping */ + /* between abstract @FTC_FaceID values and real */ + /* @FT_Face objects. */ + /* */ + /* families :: Global table of families. */ + /* */ + typedef struct FTC_ManagerRec_ + { + FT_Library library; + FT_LruList faces_list; + FT_LruList sizes_list; + + FT_ULong max_weight; + FT_ULong cur_weight; + + FT_UInt num_nodes; + FTC_Node nodes_list; + + FTC_Cache caches[FTC_MAX_CACHES]; + + FT_Pointer request_data; + FTC_Face_Requester request_face; + + FTC_FamilyTableRec families; + + } FTC_ManagerRec; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_Manager_Compress */ + /* */ + /* <Description> */ + /* This function is used to check the state of the cache manager if */ + /* its `num_bytes' field is greater than its `max_bytes' field. It */ + /* will flush as many old cache nodes as possible (ignoring cache */ + /* nodes with a non-zero reference count). */ + /* */ + /* <InOut> */ + /* manager :: A handle to the cache manager. */ + /* */ + /* <Note> */ + /* Client applications should not call this function directly. It is */ + /* normally invoked by specific cache implementations. */ + /* */ + /* The reason this function is exported is to allow client-specific */ + /* cache classes. */ + /* */ + FT_EXPORT( void ) + FTC_Manager_Compress( FTC_Manager manager ); + + + /* this must be used internally for the moment */ + FT_EXPORT( FT_Error ) + FTC_Manager_Register_Cache( FTC_Manager manager, + FTC_Cache_Class clazz, + FTC_Cache *acache ); + + + /* can be called to increment a node's reference count */ + FT_EXPORT( void ) + FTC_Node_Ref( FTC_Node node, + FTC_Manager manager ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_Node_Unref */ + /* */ + /* <Description> */ + /* Decrement a cache node's internal reference count. When the count */ + /* reaches 0, it is not destroyed but becomes eligible for subsequent */ + /* cache flushes. */ + /* */ + /* <Input> */ + /* node :: The cache node handle. */ + /* */ + /* manager :: The cache manager handle. */ + /* */ + FT_EXPORT( void ) + FTC_Node_Unref( FTC_Node node, + FTC_Manager manager ); + + /* */ + +FT_END_HEADER + + +#endif /* __FTCMANAG_H__ */ + + +/* END */ diff --git a/include/freetype/cache/ftcsbits.h b/include/freetype/cache/ftcsbits.h new file mode 100644 index 00000000..6f8ef99c --- /dev/null +++ b/include/freetype/cache/ftcsbits.h @@ -0,0 +1,275 @@ +/***************************************************************************/ +/* */ +/* ftcsbits.h */ +/* */ +/* A small-bitmap cache (specification). */ +/* */ +/* Copyright 2000-2001, 2002 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + +#ifndef __FTCSBITS_H__ +#define __FTCSBITS_H__ + + +#include <ft2build.h> +#include FT_CACHE_H +#include FT_CACHE_IMAGE_H + + +FT_BEGIN_HEADER + + + /*************************************************************************/ + /* */ + /* <Section> */ + /* cache_subsystem */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FTC_SBit */ + /* */ + /* <Description> */ + /* A handle to a small bitmap descriptor. See the @FTC_SBitRec */ + /* structure for details. */ + /* */ + typedef struct FTC_SBitRec_* FTC_SBit; + + + /*************************************************************************/ + /* */ + /* <Struct> */ + /* FTC_SBitRec */ + /* */ + /* <Description> */ + /* A very compact structure used to describe a small glyph bitmap. */ + /* */ + /* <Fields> */ + /* width :: The bitmap width in pixels. */ + /* */ + /* height :: The bitmap height in pixels. */ + /* */ + /* left :: The horizontal distance from the pen position to the */ + /* left bitmap border (a.k.a. `left side bearing', or */ + /* `lsb'). */ + /* */ + /* top :: The vertical distance from the pen position (on the */ + /* baseline) to the upper bitmap border (a.k.a. `top */ + /* side bearing'). The distance is positive for upwards */ + /* Y coordinates. */ + /* */ + /* format :: The format of the glyph bitmap (monochrome or gray). */ + /* */ + /* max_grays :: Maximum gray level value (in the range 1 to 255). */ + /* */ + /* pitch :: The number of bytes per bitmap line. May be positive */ + /* or negative. */ + /* */ + /* xadvance :: The horizontal advance width in pixels. */ + /* */ + /* yadvance :: The vertical advance height in pixels. */ + /* */ + /* buffer :: A pointer to the bitmap pixels. */ + /* */ + typedef struct FTC_SBitRec_ + { + FT_Byte width; + FT_Byte height; + FT_Char left; + FT_Char top; + + FT_Byte format; + FT_Byte max_grays; + FT_Short pitch; + FT_Char xadvance; + FT_Char yadvance; + + FT_Byte* buffer; + + } FTC_SBitRec; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FTC_SBitCache */ + /* */ + /* <Description> */ + /* A handle to a small bitmap cache. These are special cache objects */ + /* used to store small glyph bitmaps (and anti-aliased pixmaps) in a */ + /* much more efficient way than the traditional glyph image cache */ + /* implemented by @FTC_ImageCache. */ + /* */ + typedef struct FTC_SBitCacheRec_* FTC_SBitCache; + + + /*************************************************************************/ + /* */ + /* <Type> */ + /* FTC_SBit_Cache */ + /* */ + /* <Description> */ + /* DEPRECATED. Use @FTC_SBitCache instead. */ + /* */ + typedef FTC_SBitCache FTC_SBit_Cache; + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_SBitCache_New */ + /* */ + /* <Description> */ + /* Creates a new cache to store small glyph bitmaps. */ + /* */ + /* <Input> */ + /* manager :: A handle to the source cache manager. */ + /* */ + /* <Output> */ + /* acache :: A handle to the new sbit cache. NULL in case of error. */ + /* */ + /* <Return> */ + /* FreeType error code. 0 means success. */ + /* */ + FT_EXPORT( FT_Error ) + FTC_SBitCache_New( FTC_Manager manager, + FTC_SBitCache *acache ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_SBitCache_Lookup */ + /* */ + /* <Description> */ + /* Looks up a given small glyph bitmap in a given sbit cache and */ + /* "lock" it to prevent its flushing from the cache until needed */ + /* */ + /* <Input> */ + /* cache :: A handle to the source sbit cache. */ + /* */ + /* type :: A pointer to the glyph image type descriptor. */ + /* */ + /* gindex :: The glyph index. */ + /* */ + /* <Output> */ + /* sbit :: A handle to a small bitmap descriptor. */ + /* */ + /* anode :: Used to return the address of of the corresponding cache */ + /* node after incrementing its reference count (see note */ + /* below). */ + /* */ + /* <Return> */ + /* FreeType error code. 0 means success. */ + /* */ + /* <Note> */ + /* The small bitmap descriptor and its bit buffer are owned by the */ + /* cache and should never be freed by the application. They might */ + /* as well disappear from memory on the next cache lookup, so don't */ + /* treat them as persistent data. */ + /* */ + /* The descriptor's `buffer' field is set to 0 to indicate a missing */ + /* glyph bitmap. */ + /* */ + /* If "anode" is _not_ NULL, it receives the address of the cache */ + /* node containing the bitmap, after increasing its reference count. */ + /* This ensures that the node (as well as the image) will always be */ + /* kept in the cache until you call @FTC_Node_Unref to "release" it. */ + /* */ + /* If "anode" is NULL, the cache node is left unchanged, which means */ + /* that the bitmap could be flushed out of the cache on the next */ + /* call to one of the caching sub-system APIs. Don't assume that it */ + /* is persistent! */ + /* */ + FT_EXPORT( FT_Error ) + FTC_SBitCache_Lookup( FTC_SBitCache cache, + FTC_ImageType type, + FT_UInt gindex, + FTC_SBit *sbit, + FTC_Node *anode ); + + + /* */ + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_SBit_Cache_New */ + /* */ + /* <Description> */ + /* DEPRECATED. Use @FTC_SBitCache_New instead. */ + /* */ + /* Creates a new cache to store small glyph bitmaps. */ + /* */ + /* <Input> */ + /* manager :: A handle to the source cache manager. */ + /* */ + /* <Output> */ + /* acache :: A handle to the new sbit cache. NULL in case of error. */ + /* */ + /* <Return> */ + /* FreeType error code. 0 means success. */ + /* */ + FT_EXPORT( FT_Error ) + FTC_SBit_Cache_New( FTC_Manager manager, + FTC_SBit_Cache *acache ); + + + /*************************************************************************/ + /* */ + /* <Function> */ + /* FTC_SBit_Cache_Lookup */ + /* */ + /* <Description> */ + /* DEPRECATED. Use @FTC_SBitCache_Lookup instead. */ + /* */ + /* Looks up a given small glyph bitmap in a given sbit cache. */ + /* */ + /* <Input> */ + /* cache :: A handle to the source sbit cache. */ + /* */ + /* desc :: A pointer to the glyph image descriptor. */ + /* */ + /* gindex :: The glyph index. */ + /* */ + /* <Output> */ + /* sbit :: A handle to a small bitmap descriptor. */ + /* */ + /* <Return> */ + /* FreeType error code. 0 means success. */ + /* */ + /* <Note> */ + /* The small bitmap descriptor and its bit buffer are owned by the */ + /* cache and should never be freed by the application. They might */ + /* as well disappear from memory on the next cache lookup, so don't */ + /* treat them as persistent data. */ + /* */ + /* The descriptor's `buffer' field is set to 0 to indicate a missing */ + /* glyph bitmap. */ + /* */ + FT_EXPORT( FT_Error ) + FTC_SBit_Cache_Lookup( FTC_SBit_Cache cache, + FTC_Image_Desc* desc, + FT_UInt gindex, + FTC_SBit *sbit ); + + +FT_END_HEADER + +#endif /* __FTCSBITS_H__ */ + + +/* END */ diff --git a/include/freetype/cache/ftlru.h b/include/freetype/cache/ftlru.h new file mode 100644 index 00000000..9e4507ef --- /dev/null +++ b/include/freetype/cache/ftlru.h @@ -0,0 +1,202 @@ +/***************************************************************************/ +/* */ +/* ftlru.h */ +/* */ +/* Simple LRU list-cache (specification). */ +/* */ +/* Copyright 2000-2001 by */ +/* David Turner, Robert Wilhelm, and Werner Lemberg. */ +/* */ +/* This file is part of the FreeType project, and may only be used, */ +/* modified, and distributed under the terms of the FreeType project */ +/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ +/* this file you indicate that you have read the license and */ +/* understand and accept it fully. */ +/* */ +/***************************************************************************/ + + + /*************************************************************************/ + /* */ + /* An LRU is a list that cannot hold more than a certain number of */ + /* elements (`max_elements'). All elements in the list are sorted in */ + /* least-recently-used order, i.e., the `oldest' element is at the tail */ + /* of the list. */ + /* */ + /* When doing a lookup (either through `Lookup()' or `Lookup_Node()'), */ + /* the list is searched for an element with the corresponding key. If */ + /* it is found, the element is moved to the head of the list and is */ + /* returned. */ + /* */ + /* If no corresponding element is found, the lookup routine will try to */ + /* obtain a new element with the relevant key. If the list is already */ + /* full, the oldest element from the list is discarded and replaced by a */ + /* new one; a new element is added to the list otherwise. */ + /* */ + /* Note that it is possible to pre-allocate the element list nodes. */ + /* This is handy if `max_elements' is sufficiently small, as it saves */ + /* allocations/releases during the lookup process. */ + /* */ + /*************************************************************************/ + + + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /********* *********/ + /********* WARNING, THIS IS BETA CODE. *********/ + /********* *********/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + + +#ifndef __FTLRU_H__ +#define __FTLRU_H__ + + +#include <ft2build.h> +#include FT_FREETYPE_H + + +FT_BEGIN_HEADER + + + /* generic list key type */ + typedef FT_Pointer FT_LruKey; + + /* a list list handle */ + typedef struct FT_LruListRec_* FT_LruList; + + /* a list class handle */ + typedef const struct FT_LruList_ClassRec_* FT_LruList_Class; + + /* a list node handle */ + typedef struct FT_LruNodeRec_* FT_LruNode; + + /* the list node structure */ + typedef struct FT_LruNodeRec_ + { + FT_LruNode next; + FT_LruKey key; + + } FT_LruNodeRec; + + + /* the list structure */ + typedef struct FT_LruListRec_ + { + FT_Memory memory; + FT_LruList_Class clazz; + FT_LruNode nodes; + FT_UInt max_nodes; + FT_UInt num_nodes; + FT_Pointer data; + + } FT_LruListRec; + + + /* initialize a list list */ + typedef FT_Error + (*FT_LruList_InitFunc)( FT_LruList list ); + + /* finalize a list list */ + typedef void + (*FT_LruList_DoneFunc)( FT_LruList list ); + + /* this method is used to initialize a new list element node */ + typedef FT_Error + (*FT_LruNode_InitFunc)( FT_LruNode node, + FT_LruKey key, + FT_Pointer data ); + + /* this method is used to finalize a given list element node */ + typedef void + (*FT_LruNode_DoneFunc)( FT_LruNode node, + FT_Pointer data ); + + /* If defined, this method is called when the list if full */ + /* during the lookup process -- it is used to change the contents */ + /* of a list element node instead of calling `done_element()', */ + /* then `init_element()'. Set it to 0 for default behaviour. */ + typedef FT_Error + (*FT_LruNode_FlushFunc)( FT_LruNode node, + FT_LruKey new_key, + FT_Pointer data ); + + /* If defined, this method is used to compare a list element node */ + /* with a given key during a lookup. If set to 0, the `key' */ + /* fields will be directly compared instead. */ + typedef FT_Bool + (*FT_LruNode_CompareFunc)( FT_LruNode node, + FT_LruKey key, + FT_Pointer data ); + + /* A selector is used to indicate whether a given list element node */ + /* is part of a selection for FT_LruList_Remove_Selection(). The */ + /* functrion must return true (i.e., non-null) to indicate that the */ + /* node is part of it. */ + typedef FT_Bool + (*FT_LruNode_SelectFunc)( FT_LruNode node, + FT_Pointer data, + FT_Pointer list_data ); + + /* LRU class */ + typedef struct FT_LruList_ClassRec_ + { + FT_UInt list_size; + FT_LruList_InitFunc list_init; /* optional */ + FT_LruList_DoneFunc list_done; /* optional */ + + FT_UInt node_size; + FT_LruNode_InitFunc node_init; /* MANDATORY */ + FT_LruNode_DoneFunc node_done; /* optional */ + FT_LruNode_FlushFunc node_flush; /* optional */ + FT_LruNode_CompareFunc node_compare; /* optional */ + + } FT_LruList_ClassRec; + + + /* The following functions must be exported in the case where */ + /* applications would want to write their own cache classes. */ + + FT_EXPORT( FT_Error ) + FT_LruList_New( FT_LruList_Class clazz, + FT_UInt max_elements, + FT_Pointer user_data, + FT_Memory memory, + FT_LruList *alist ); + + FT_EXPORT( void ) + FT_LruList_Reset( FT_LruList list ); + + FT_EXPORT( void ) + FT_LruList_Destroy ( FT_LruList list ); + + FT_EXPORT( FT_Error ) + FT_LruList_Lookup( FT_LruList list, + FT_LruKey key, + FT_LruNode *anode ); + + FT_EXPORT( void ) + FT_LruList_Remove( FT_LruList list, + FT_LruNode node ); + + FT_EXPORT( void ) + FT_LruList_Remove_Selection( FT_LruList list, + FT_LruNode_SelectFunc select_func, + FT_Pointer select_data ); + + /* */ + +FT_END_HEADER + + +#endif /* __FTLRU_H__ */ + + +/* END */ |
