From eddd9909e275b997629996d85ccf6abd10fbb493 Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Thu, 12 Oct 2000 05:05:40 +0000 Subject: [PATCH] formatting small fixes --- include/freetype/cache/ftcglyph.h | 168 +++++++++-------- include/freetype/cache/ftcmanag.h | 249 ++++++++++++------------- include/freetype/cache/ftlru.h | 153 ++++++++-------- include/freetype/ftcache.h | 89 +++++---- include/freetype/ftsynth.h | 37 ++-- src/base/ftobjs.c | 22 +-- src/cache/ftcglyph.c | 291 ++++++++++++++++-------------- src/cache/ftcimage.c | 222 +++++++++++++---------- src/cache/ftcimage.h | 40 +++- src/cache/ftcmanag.c | 155 ++++++++-------- 10 files changed, 763 insertions(+), 663 deletions(-) diff --git a/include/freetype/cache/ftcglyph.h b/include/freetype/cache/ftcglyph.h index 0bda99dd9..0a1882310 100644 --- a/include/freetype/cache/ftcglyph.h +++ b/include/freetype/cache/ftcglyph.h @@ -2,7 +2,7 @@ /* */ /* ftcglyph.h */ /* */ -/* FreeType glyph image (FT_Glyph) cache.. */ +/* FreeType glyph image (FT_Glyph) cache (specification). */ /* */ /* Copyright 2000 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ @@ -13,53 +13,59 @@ /* 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 ALPHA CODE, THIS API **********/ - /********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE **********/ - /********* FREETYPE DEVELOPMENT TEAM **********/ - /********* **********/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ + + /*************************************************************************/ + /* */ + /* 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 ALPHA CODE, THIS API *********/ + /********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE *********/ + /********* FREETYPE DEVELOPMENT TEAM *********/ + /********* *********/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ #ifndef FTCGLYPH_H #define FTCGLYPH_H + #include #include #include + #ifdef __cplusplus extern "C" { #endif -/* maximum number of queues per image cache, must be < 256 */ + + /* maximum number of queues per image cache; must be < 256 */ #define FTC_MAX_GLYPH_QUEUES 16 #define FTC_QUEUE_HASH_SIZE_DEFAULT 64 - typedef struct FTC_Glyph_QueueRec_* FTC_Glyph_Queue; - typedef struct FTC_GlyphNodeRec_* FTC_GlyphNode; - typedef struct FTC_Glyph_CacheRec_* FTC_Glyph_Cache; + typedef struct FTC_Glyph_QueueRec_* FTC_Glyph_Queue; + typedef struct FTC_GlyphNodeRec_* FTC_GlyphNode; + typedef struct FTC_Glyph_CacheRec_* FTC_Glyph_Cache; typedef struct FTC_GlyphNodeRec_ { @@ -74,8 +80,13 @@ } FTC_GlyphNodeRec; -#define FTC_GLYPHNODE_GET_GLYPH(n) ((FT_Glyph)((n)->link.data)) -#define FTC_GLYPHNODE_SET_GLYPH(n,g) do { (n)->link.data = (g); } while (0) +#define FTC_GLYPHNODE_GET_GLYPH( n ) \ + ( (FT_Glyph)((n)->link.data) ) +#define FTC_GLYPHNODE_SET_GLYPH( n, g ) \ + do \ + { \ + (n)->link.data = (g); \ + } while ( 0 ) /* this macro is used to extract a handle to the bucket's lru list */ /* corresponding to a given image node */ @@ -83,37 +94,40 @@ ( (FT_ListNode)&(n)->link ) /* this macro is used to extract a handle to a given image node from */ - /* the corresponding LRU glyph list node. That's a bit hackish.. */ -#define FTC_LISTNODE_TO_GLYPHNODE( p ) \ - ( (FTC_GlyphNode)( (char*)(p) - \ + /* the corresponding LRU glyph list node. That's a bit hackish... */ +#define FTC_LISTNODE_TO_GLYPHNODE( p ) \ + ( (FTC_GlyphNode)( (char*)(p) - \ offsetof( FTC_GlyphNodeRec,link ) ) ) -#define FTC_GLYPHNODE_TO_LRUNODE(n) ((FT_ListNode)(n)) -#define FTC_LRUNODE_TO_GLYPHNODE(n) ((FTC_GlyphNode)(n)) +#define FTC_GLYPHNODE_TO_LRUNODE( n ) ( (FT_ListNode)(n) ) +#define FTC_LRUNODE_TO_GLYPHNODE( n ) ( (FTC_GlyphNode)(n) ) - /* glyph queue methods *****************************************************/ + /*************************************************************************/ + /* */ + /* Glyph queue methods. */ + /* */ - typedef FT_Error (*FTC_Glyph_Queue_InitFunc) ( FTC_Glyph_Queue queue, - FT_Pointer type ); + typedef FT_Error (*FTC_Glyph_Queue_InitFunc)( FTC_Glyph_Queue queue, + FT_Pointer type ); - typedef void (*FTC_Glyph_Queue_DoneFunc) ( FTC_Glyph_Queue queue ); + typedef void (*FTC_Glyph_Queue_DoneFunc)( FTC_Glyph_Queue queue ); - typedef FT_Bool (*FTC_Glyph_Queue_CompareFunc)( FTC_Glyph_Queue queue, - FT_Pointer type ); + typedef FT_Bool (*FTC_Glyph_Queue_CompareFunc)( FTC_Glyph_Queue queue, + FT_Pointer type ); typedef FT_Error (*FTC_Glyph_Queue_NewNodeFunc)( FTC_Glyph_Queue queue, FT_UInt gindex, - FTC_GlyphNode *anode ); + FTC_GlyphNode* anode ); typedef void (*FTC_Glyph_Queue_DestroyNodeFunc)( FTC_GlyphNode node, FTC_Glyph_Queue queue ); - typedef FT_ULong (*FTC_Glyph_Queue_SizeNodeFunc)( FTC_GlyphNode node, FTC_Glyph_Queue queue ); - typedef struct FTC_Glyph_Queue_Class_ + + typedef struct FTC_Glyph_Queue_Class_ { FT_UInt queue_byte_size; @@ -142,8 +156,8 @@ } FTC_Glyph_QueueRec; - /* the abstract glyph cache class */ - typedef struct FTC_Glyph_Cache_Class_ + /* the abstract glyph cache class */ + typedef struct FTC_Glyph_Cache_Class_ { FTC_Cache_Class root; FTC_Glyph_Queue_Class* queue_class; @@ -151,54 +165,52 @@ } FTC_Glyph_Cache_Class; - /* the abstract glyph cache object */ + /* the abstract glyph cache object */ typedef struct FTC_Glyph_CacheRec_ { - FTC_CacheRec root; - FT_Lru queues_lru; /* static queues lru list */ - FTC_Glyph_Queue last_queue; /* small cache */ + FTC_CacheRec root; + FT_Lru queues_lru; /* static queues lru list */ + FTC_Glyph_Queue last_queue; /* small cache */ } FTC_Glyph_CacheRec; - /* these function are exported so that they can be called from */ - /* user-provided cache classes.. otherwise, they're really */ - /* part of the cache sub-system internals.. */ - /* */ + /*************************************************************************/ + /* */ + /* These functions are exported so that they can be called from */ + /* user-provided cache classes; otherwise, they are really parts of the */ + /* cache sub-system internals. */ + /* */ - FT_EXPORT_FUNC(void) FTC_GlyphNode_Init( FTC_GlyphNode node, - FTC_Glyph_Queue queue, - FT_UInt gindex ); + FT_EXPORT_FUNC( void ) FTC_GlyphNode_Init( FTC_GlyphNode node, + FTC_Glyph_Queue queue, + FT_UInt gindex ); -#define FTC_GlyphNode_Ref(n) \ - FTC_CACHENODE_TO_DATA_P(&(n)->root)->ref_count++ +#define FTC_GlyphNode_Ref( n ) \ + FTC_CACHENODE_TO_DATA_P( &(n)->root )->ref_count++ -#define FTC_GlyphNode_Unref(n) \ - FTC_CACHENODE_TO_DATA_P(&(n)->root)->ref_count-- +#define FTC_GlyphNode_Unref( n ) \ + FTC_CACHENODE_TO_DATA_P( &(n)->root )->ref_count-- - FT_EXPORT_DEF(void) FTC_Destroy_Glyph_Node( FTC_GlyphNode node, - FTC_Glyph_Cache cache ); + FT_EXPORT_DEF( void ) FTC_Destroy_Glyph_Node( FTC_GlyphNode node, + FTC_Glyph_Cache cache ); - FT_EXPORT_DEF(FT_Error) FTC_Glyph_Cache_Init( FTC_Glyph_Cache cache ); + FT_EXPORT_DEF( FT_Error ) FTC_Glyph_Cache_Init( FTC_Glyph_Cache cache ); - FT_EXPORT_DEF(void) FTC_Glyph_Cache_Done( FTC_Glyph_Cache cache ); - - FT_EXPORT_DEF(FT_Error) FTC_Glyph_Queue_New( - FTC_Glyph_Cache cache, - FT_Pointer type, - FTC_Glyph_Queue *aqueue ); - - FT_EXPORT_DEF(FT_Error) FTC_Glyph_Queue_Lookup_Node( - FTC_Glyph_Queue queue, - FT_UInt glyph_index, - FTC_GlyphNode* anode ); + FT_EXPORT_DEF( void ) FTC_Glyph_Cache_Done( FTC_Glyph_Cache cache ); - FT_EXPORT_DEF(FT_Error) FTC_Glyph_Cache_Init( FTC_Glyph_Cache cache ); + FT_EXPORT_DEF( FT_Error ) FTC_Glyph_Queue_New( FTC_Glyph_Cache cache, + FT_Pointer type, + FTC_Glyph_Queue* aqueue ); + + FT_EXPORT_DEF( FT_Error ) FTC_Glyph_Queue_Lookup_Node( + FTC_Glyph_Queue queue, + FT_UInt glyph_index, + FTC_GlyphNode* anode ); - FT_EXPORT_DEF(void) FTC_Glyph_Cache_Done( FTC_Glyph_Cache cache ); #ifdef __cplusplus } diff --git a/include/freetype/cache/ftcmanag.h b/include/freetype/cache/ftcmanag.h index 10678d516..0956a4d06 100644 --- a/include/freetype/cache/ftcmanag.h +++ b/include/freetype/cache/ftcmanag.h @@ -13,48 +13,52 @@ /* 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 & FT_Size objects in order to speed things */ -/* considerably.. */ -/* */ -/* - manage one or more cache object. 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 a 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 ALPHA CODE, THIS API **********/ - /********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE **********/ - /********* FREETYPE DEVELOPMENT TEAM **********/ - /********* **********/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ + + /*************************************************************************/ + /* */ + /* 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 */ + /* & FT_Size objects in order to speed 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 ALPHA CODE, THIS API *********/ + /********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE *********/ + /********* FREETYPE DEVELOPMENT TEAM *********/ + /********* *********/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ #ifndef FTCMANAG_H @@ -68,13 +72,14 @@ extern "C" { #endif -/* default values */ -#define FTC_MAX_FACES_DEFAULT 4 -#define FTC_MAX_SIZES_DEFAULT 8 -#define FTC_MAX_BYTES_DEFAULT 300000 /* 300 Kb by default !! */ -/* maximum number of caches registered in a single manager */ -#define FTC_MAX_CACHES 16 + /* default values */ +#define FTC_MAX_FACES_DEFAULT 4 +#define FTC_MAX_SIZES_DEFAULT 8 +#define FTC_MAX_BYTES_DEFAULT 300000 /* 300kByte by default! */ + + /* maximum number of caches registered in a single manager */ +#define FTC_MAX_CACHES 16 typedef struct FTC_ManagerRec_ @@ -86,114 +91,112 @@ FT_ULong max_bytes; FT_ULong num_bytes; FT_ListRec global_lru; - FTC_Cache caches[ FTC_MAX_CACHES ]; - + FTC_Cache caches[FTC_MAX_CACHES]; + FT_Pointer request_data; FTC_Face_Requester request_face; - + } FTC_ManagerRec; - /*********************************************************************/ - /*********************************************************************/ - /***** *****/ - /***** CACHE NODE DEFINITIONS *****/ - /***** *****/ - /*********************************************************************/ - /*********************************************************************/ - - + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** 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 hold by */ + /* the cache. It can be an individual glyph image, a set of bitmaps */ + /* glyphs for a given size, some metrics, etc. */ + /* */ - /* 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 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.. */ - /* */ - typedef FT_ListNodeRec FTC_CacheNodeRec; typedef FTC_CacheNodeRec* FTC_CacheNode; - /* the fields "cachenode.data" is typecasted to this type */ - typedef struct FTC_CacheNode_Data_ + /* the fields `cachenode.data' is typecast to this type */ + typedef struct FTC_CacheNode_Data_ { - FT_UShort cache_index; - FT_Short ref_count; - + FT_UShort cache_index; + FT_Short ref_count; + } FTC_CacheNode_Data; - -/* returns a pointer to the FTC_CacheNode_Data contained in a */ -/* CacheNode's "data" field.. */ -#define FTC_CACHENODE_TO_DATA_P(n) \ - ((FTC_CacheNode_Data*)&(n)->data) -#define FTC_LIST_TO_CACHENODE(n) ((FTC_CacheNode)(n)) + /* return a pointer to the FTC_CacheNode_Data contained in a */ + /* CacheNode's `data' field */ +#define FTC_CACHENODE_TO_DATA_P( n ) \ + ( (FTC_CacheNode_Data*)&(n)->data ) - /* returns the size in bytes of a given cache node */ - typedef FT_ULong (*FTC_CacheNode_SizeFunc)( FTC_CacheNode node, - FT_Pointer user ); +#define FTC_LIST_TO_CACHENODE( n ) ( (FTC_CacheNode)(n) ) - /* finalise a given cache node */ - typedef void (*FTC_CacheNode_DestroyFunc)( FTC_CacheNode node, - FT_Pointer user ); + /* return the size in bytes of a given cache node */ + typedef FT_ULong (*FTC_CacheNode_SizeFunc)( FTC_CacheNode node, + FT_Pointer user ); - /* this structure is used to provide functions to the cache manager */ - /* It will use them to size and destroy cache nodes.. Note that there */ - /* is no "init_node" there because cache objects are entirely */ - /* responsible for the creation of new cache nodes */ + /* finalize a given cache node */ + typedef void (*FTC_CacheNode_DestroyFunc)( FTC_CacheNode node, + FT_Pointer user ); + + /* This structure is used to provide functions to the cache manager. */ + /* It will use them to size and destroy cache nodes. Note that there */ + /* is no `init_node' because cache objects are entirely responsible */ + /* for the creation of new cache nodes. */ /* */ - typedef struct FTC_CacheNode_Class_ + typedef struct FTC_CacheNode_Class_ { - FTC_CacheNode_SizeFunc size_node; - FTC_CacheNode_DestroyFunc destroy_node; - + FTC_CacheNode_SizeFunc size_node; + FTC_CacheNode_DestroyFunc destroy_node; + } FTC_CacheNode_Class; - - /*********************************************************************/ - /*********************************************************************/ - /***** *****/ - /***** CACHE DEFINITIONS *****/ - /***** *****/ - /*********************************************************************/ - /*********************************************************************/ - - typedef FT_Error (*FTC_Cache_InitFunc)( FTC_Cache cache ); - - typedef void (*FTC_Cache_DoneFunc)( FTC_Cache cache ); - + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** CACHE DEFINITIONS *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ - struct FTC_Cache_Class_ + + typedef FT_Error (*FTC_Cache_InitFunc)( FTC_Cache cache ); + + typedef void (*FTC_Cache_DoneFunc)( FTC_Cache cache ); + + + struct FTC_Cache_Class_ { - FT_UInt cache_byte_size; - FTC_Cache_InitFunc init_cache; - FTC_Cache_DoneFunc done_cache; + FT_UInt cache_byte_size; + FTC_Cache_InitFunc init_cache; + FTC_Cache_DoneFunc done_cache; }; - - typedef struct FTC_CacheRec_ { - FTC_Manager manager; - FT_Memory memory; - FTC_Cache_Class* clazz; - FTC_CacheNode_Class* node_clazz; - - FT_UInt cache_index; /* in manager's table */ - FT_Pointer cache_user; /* passed to cache node methods*/ - + FTC_Manager manager; + FT_Memory memory; + FTC_Cache_Class* clazz; + FTC_CacheNode_Class* node_clazz; + + FT_UInt cache_index; /* in manager's table */ + FT_Pointer cache_user; /* passed to cache node methods */ + } FTC_CacheRec; - /* "compress" the manager's data, i.e. get rids of old cache nodes */ + /* `Compress' the manager's data, i.e., get rid of old cache nodes */ /* that are not referenced anymore in order to limit the total */ - /* memory used by the cache.. */ - FT_EXPORT_DEF(void) FTC_Manager_Compress( FTC_Manager manager ); + /* memory used by the cache. */ + FT_EXPORT_DEF( void ) FTC_Manager_Compress( FTC_Manager manager ); #ifdef __cplusplus diff --git a/include/freetype/cache/ftlru.h b/include/freetype/cache/ftlru.h index 8e7df5349..856caefc4 100644 --- a/include/freetype/cache/ftlru.h +++ b/include/freetype/cache/ftlru.h @@ -13,45 +13,48 @@ /* this file you indicate that you have read the license and */ /* understand and accept it fully. */ /* */ -/* */ -/* A LRU is a list that cannot hold more than a certain number of */ -/* elements ("max_elements"). All elements on the list are sorted */ -/* in lest-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. */ -/* That's handy when "max_elements" is sufficiently small, as it */ -/* saves allocations/releases during the lookup process */ -/* */ /***************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /********* **********/ - /********* **********/ - /********* WARNING, THIS IS ALPHA CODE, THIS API **********/ - /********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE **********/ - /********* FREETYPE DEVELOPMENT TEAM **********/ - /********* **********/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ + + /*************************************************************************/ + /* */ + /* An LRU is a list that cannot hold more than a certain number of */ + /* elements (`max_elements'). All elements on the list are sorted in */ + /* lest-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 ALPHA CODE, THIS API *********/ + /********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE *********/ + /********* FREETYPE DEVELOPMENT TEAM *********/ + /********* *********/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ #ifndef FTLRU_H @@ -64,11 +67,12 @@ extern "C" { #endif - /* generic key type */ + + /* generic key type */ typedef FT_Pointer FT_LruKey; - /* a lru node - node.root.data points to the element */ + /* an lru node -- node.root.data points to the element */ typedef struct FT_LruNodeRec_ { FT_ListNodeRec root; @@ -76,43 +80,44 @@ } FT_LruNodeRec, *FT_LruNode; - /* forward declaration */ + /* forward declaration */ typedef struct FT_LruRec_* FT_Lru; - /* LRU clazz */ + /* LRU clazz */ typedef struct FT_Lru_Class_ { - FT_UInt lru_size; /* object size in bytes */ + FT_UInt lru_size; /* object size in bytes */ - /* this method is used to initialise a new list element node */ + /* this method is used to initialize a new list element node */ FT_Error (*init_element)( FT_Lru lru, FT_LruNode node ); - /* this method is used to finalise a given list element node */ - void (*done_element)( FT_Lru lru, - FT_LruNode node ); + /* this method is used to finalize a given list element node */ + void (*done_element)( FT_Lru lru, + FT_LruNode node ); - /* when defined, this method is called when the list if full */ - /* during the lookup process.. it is used to change the content */ - /* of a list element node, instead of calling "done_element" */ - /* then "init_element". Put it to 0 for default behaviour */ + /* 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. */ FT_Error (*flush_element)( FT_Lru lru, FT_LruNode node, FT_LruKey new_key ); - /* when defined, this method is used to compare a list element node */ - /* with a given key during a lookup. When set to 0, the "key" */ - /* fields will be directly compared instead.. */ - FT_Bool (*compare_element)( FT_LruNode node, - FT_LruKey key ); + /* 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. */ + FT_Bool (*compare_element)( FT_LruNode node, + FT_LruKey key ); } FT_Lru_Class; - /* a selector is used to indicate wether a given list element node */ - /* is part of a selection for FT_Lru_Remove_Selection. The function */ - /* must returns true (i.e. non 0) to indicate that the node is part */ - /* of it.. */ + + /* A selector is used to indicate whether a given list element node */ + /* is part of a selection for FT_Lru_Remove_Selection(). The function */ + /* must return true (i.e., non-null) to indicate that the node is part */ + /* of it. */ typedef FT_Bool (*FT_Lru_Selector)( FT_Lru lru, FT_LruNode node, FT_Pointer data ); @@ -120,16 +125,16 @@ typedef struct FT_LruRec_ { - FT_Lru_Class* clazz; - FT_UInt max_elements; - FT_UInt num_elements; - FT_ListRec elements; - FT_Memory memory; - FT_Pointer user_data; + FT_Lru_Class* clazz; + FT_UInt max_elements; + FT_UInt num_elements; + FT_ListRec elements; + FT_Memory memory; + FT_Pointer user_data; /* the following fields are only meaningful for static lru containers */ - FT_ListRec free_nodes; - FT_LruNode nodes; + FT_ListRec free_nodes; + FT_LruNode nodes; } FT_LruRec; @@ -141,9 +146,9 @@ FT_Bool pre_alloc, FT_Lru* alru ); - FT_EXPORT_DEF( void ) FT_Lru_Reset( FT_Lru lru ); + FT_EXPORT_DEF( void ) FT_Lru_Reset( FT_Lru lru ); - FT_EXPORT_DEF( void ) FT_Lru_Done( FT_Lru lru ); + FT_EXPORT_DEF( void ) FT_Lru_Done( FT_Lru lru ); FT_EXPORT_DEF( FT_Error ) FT_Lru_Lookup_Node( FT_Lru lru, FT_LruKey key, @@ -153,12 +158,12 @@ FT_LruKey key, FT_Pointer* aobject ); - FT_EXPORT_DEF( void ) FT_Lru_Remove_Node( FT_Lru lru, - FT_LruNode node ); + FT_EXPORT_DEF( void ) FT_Lru_Remove_Node( FT_Lru lru, + FT_LruNode node ); - FT_EXPORT_DEF( void ) FT_Lru_Remove_Selection( FT_Lru lru, - FT_Lru_Selector selector, - FT_Pointer data ); + FT_EXPORT_DEF( void ) FT_Lru_Remove_Selection( FT_Lru lru, + FT_Lru_Selector selector, + FT_Pointer data ); #ifdef __cplusplus diff --git a/include/freetype/ftcache.h b/include/freetype/ftcache.h index 4baa058e8..97df18781 100644 --- a/include/freetype/ftcache.h +++ b/include/freetype/ftcache.h @@ -16,26 +16,27 @@ /***************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /********* **********/ - /********* **********/ - /********* WARNING, THIS IS ALPHA CODE, THIS API **********/ - /********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE **********/ - /********* FREETYPE DEVELOPMENT TEAM **********/ - /********* **********/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /********* *********/ + /********* WARNING, THIS IS ALPHA CODE, THIS API *********/ + /********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE *********/ + /********* FREETYPE DEVELOPMENT TEAM *********/ + /********* *********/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + #ifndef FTCACHE_H #define FTCACHE_H + #include @@ -91,7 +92,7 @@ /* */ typedef FT_Error (*FTC_Face_Requester)( FTC_FaceID face_id, FT_Library library, - FT_Pointer request_data, + FT_Pointer request_data, FT_Face* aface ); @@ -102,8 +103,8 @@ /* */ /* */ /* A simple structure used to describe a given `font' to the cache */ - /* manager. Note that a "font" is the combination of a given face */ - /* with a given character size.. */ + /* manager. Note that a `font' is the combination of a given face */ + /* with a given character size. */ /* */ /* */ /* face_id :: The ID of the face to use. */ @@ -117,7 +118,7 @@ FTC_FaceID face_id; FT_UShort pix_width; FT_UShort pix_height; - + } FTC_FontRec; @@ -130,7 +131,7 @@ /* A simple handle to a FTC_FontRec structure. */ /* */ typedef FTC_FontRec* FTC_Font; - + /*************************************************************************/ /*************************************************************************/ @@ -196,7 +197,7 @@ FT_Pointer req_data, FTC_Manager* amanager ); - + /*************************************************************************/ /* */ /* */ @@ -261,7 +262,7 @@ FT_EXPORT_DEF( FT_Error ) FTC_Manager_Lookup_Face( FTC_Manager manager, FTC_FaceID face_id, FT_Face* aface ); - + /*************************************************************************/ /* */ @@ -308,19 +309,18 @@ FT_Size* asize ); - /* a cache class is used to describe a unique cache type to the */ - /* manager.. */ + /* a cache class is used to describe a unique cache type to the manager */ typedef struct FTC_Cache_Class_ FTC_Cache_Class; typedef struct FTC_CacheRec_* FTC_Cache; /* this must be used internally for the moment */ FT_EXPORT_DEF( FT_Error ) FTC_Manager_Register_Cache( - FTC_Manager manager, - FTC_Cache_Class* clazz, - FTC_Cache *acache ); + FTC_Manager manager, + FTC_Cache_Class* clazz, + FTC_Cache* acache ); + - /*************************************************************************/ /*************************************************************************/ /*************************************************************************/ @@ -332,6 +332,8 @@ /*************************************************************************/ +#define FTC_IMAGE_FORMAT( x ) ( (x) & 7 ) + /*************************************************************************/ /* */ /* */ @@ -353,30 +355,25 @@ /* */ /* Other types may be defined in the future. */ /* */ - -#define FTC_IMAGE_FORMAT(x) ((x) & 7) - typedef enum FTC_Image_Type_ { ftc_image_format_bitmap = 0, ftc_image_format_outline = 1, - + ftc_image_flag_monochrome = 16, ftc_image_flag_unhinted = 32, ftc_image_flag_autohinted = 64, ftc_image_flag_unscaled = 128, ftc_image_flag_no_sbits = 256, - - ftc_image_mono = ftc_image_format_bitmap | - ftc_image_flag_monochrome, /* monochrome bitmap */ - - ftc_image_grays = ftc_image_format_bitmap, /* anti-aliased bitmap */ - - ftc_image_outline = ftc_image_format_outline /* scaled outline */ - + + ftc_image_mono = ftc_image_format_bitmap | + ftc_image_flag_monochrome, /* monochrome bitmap */ + ftc_image_grays = ftc_image_format_bitmap, /* anti-aliased bitmap */ + ftc_image_outline = ftc_image_format_outline /* scaled outline */ + } FTC_Image_Type; - + /*************************************************************************/ /* */ /* */ @@ -395,7 +392,7 @@ { FTC_FontRec font; FT_UInt image_type; - + } FTC_Image_Desc; @@ -409,7 +406,7 @@ /* hold many distinct glyph images, while not exceeding a certain */ /* memory threshold. */ /* */ - typedef struct FTC_Image_CacheRec_* FTC_Image_Cache; + typedef struct FTC_Image_CacheRec_* FTC_Image_Cache; /*************************************************************************/ @@ -431,7 +428,7 @@ /* */ FT_EXPORT_DEF( FT_Error ) FTC_Image_Cache_New( FTC_Manager manager, FTC_Image_Cache* acache ); - + /*************************************************************************/ /* */ @@ -462,7 +459,7 @@ /* */ /* 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's a cache after all ;-) */ + /* on a later invocation of this function! It's a cache after all... */ /* */ FT_EXPORT_DEF( FT_Error ) FTC_Image_Cache_Lookup( FTC_Image_Cache cache, diff --git a/include/freetype/ftsynth.h b/include/freetype/ftsynth.h index cfe02062f..9e7f95d42 100644 --- a/include/freetype/ftsynth.h +++ b/include/freetype/ftsynth.h @@ -16,22 +16,23 @@ /* */ /***************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /********* **********/ - /********* **********/ - /********* WARNING, THIS IS ALPHA CODE, THIS API **********/ - /********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE **********/ - /********* FREETYPE DEVELOPMENT TEAM **********/ - /********* **********/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ - /**************************************************************************/ + + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /********* *********/ + /********* WARNING, THIS IS ALPHA CODE, THIS API *********/ + /********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE *********/ + /********* FREETYPE DEVELOPMENT TEAM *********/ + /********* *********/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + #ifndef FTSYNTH_H #define FTSYNTH_H @@ -44,9 +45,9 @@ #endif - /* This code is completely experimental - use with care! */ + /* This code is completely experimental -- use with care! */ /* It will probably be completely rewritten in the future */ - /* or even integrated within the library... */ + /* or even integrated into the library. */ FT_EXPORT_DEF( FT_Error ) FT_Embolden_Outline( FT_Face original, FT_Outline* outline, FT_Pos* advance ); diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index d08ed0e05..bfa440e61 100644 --- a/src/base/ftobjs.c +++ b/src/base/ftobjs.c @@ -975,13 +975,13 @@ /* when the flag NO_RECURSE is set, we disable hinting and scaling */ if ( load_flags & FT_LOAD_NO_RECURSE ) { - /* disable scaling, hinting and transform */ - load_flags |= FT_LOAD_NO_SCALE | - FT_LOAD_NO_HINTING | + /* disable scaling, hinting, and transformation */ + load_flags |= FT_LOAD_NO_SCALE | + FT_LOAD_NO_HINTING | FT_LOAD_IGNORE_TRANSFORM; - + /* disable bitmap rendering */ - load_flags &= ~FT_LOAD_RENDER; + load_flags &= ~FT_LOAD_RENDER; } /* do we need to load the glyph through the auto-hinter? */ @@ -1032,7 +1032,7 @@ { FT_UInt EM = face->units_per_EM; FT_Size_Metrics* metrics = &face->size->metrics; - + slot->linearHoriAdvance = FT_MulDiv( slot->linearHoriAdvance, (FT_Long)metrics->x_ppem << 16, EM ); @@ -1161,7 +1161,7 @@ /* discard auto-hinting data */ if ( face->autohint.finalizer ) face->autohint.finalizer( face->autohint.data ); - + /* Discard glyph slots for this face */ /* Beware! FT_Done_GlyphSlot() changes the field `face->slot' */ while ( face->glyph ) @@ -2344,12 +2344,12 @@ FT_UInt buffer_max ) { FT_Error error = FT_Err_Invalid_Argument; - + /* clean up buffer */ if ( buffer && buffer_max > 0 ) ((FT_Byte*)buffer)[0] = 0; - + if ( face && glyph_index < (FT_UInt)face->num_glyphs && FT_HAS_GLYPH_NAMES( face ) ) @@ -2362,7 +2362,7 @@ if ( clazz->get_interface ) { FT_Glyph_Name_Requester requester; - + requester = (FT_Glyph_Name_Requester)clazz->get_interface( FT_MODULE( driver ), "glyph_name" ); @@ -2372,7 +2372,7 @@ } return error; - } + } /*************************************************************************/ diff --git a/src/cache/ftcglyph.c b/src/cache/ftcglyph.c index c7d746393..970cc3d22 100644 --- a/src/cache/ftcglyph.c +++ b/src/cache/ftcglyph.c @@ -2,7 +2,7 @@ /* */ /* ftcglyph.c */ /* */ -/* FreeType Glyph Image (FT_Glyph) cache.. */ +/* FreeType Glyph Image (FT_Glyph) cache (body). */ /* */ /* Copyright 2000 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ @@ -13,124 +13,134 @@ /* this file you indicate that you have read the license and */ /* understand and accept it fully. */ /* */ -/* */ -/* Note: the implementation of glyph queues is rather generic in this */ -/* code. This will allow other glyph node/cache types to be */ -/* easily included in the future.. For now, we only cache */ -/* glyph images.. */ -/* */ /***************************************************************************/ + /*************************************************************************/ + /* */ + /* Note: The implementation of glyph queues is rather generic in this */ + /* code. This will allow other glyph node/cache types to be */ + /* easily included in the future. For now, we only cache glyph */ + /* images. */ + /* */ + /*************************************************************************/ + + #include #include #include #include #include - /*************************************************************************/ - /*************************************************************************/ - /***** *****/ - /***** GLYPH NODES *****/ - /***** *****/ - /*************************************************************************/ - /*************************************************************************/ - -/* in the future, we might provide a better scheme for managing */ -/* glyph node element. For the moment, we simply use FT_Alloc/FT_Free */ - /* creates a new glyph node, setting its cache index and ref count */ - FT_EXPORT_FUNC(void) FTC_GlyphNode_Init( FTC_GlyphNode node, - FTC_Glyph_Queue queue, - FT_UInt gindex ) + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** GLYPH NODES *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ + + + /* In the future, we might provide a better scheme for managing glyph */ + /* node elements. For the moment, we simply use FT_Alloc()/FT_Free(). */ + + + /* create a new glyph node, setting its cache index and ref count */ + FT_EXPORT_FUNC( void ) FTC_GlyphNode_Init( FTC_GlyphNode node, + FTC_Glyph_Queue queue, + FT_UInt gindex ) { FTC_Glyph_Cache cache = queue->cache; FTC_CacheNode_Data* data = FTC_CACHENODE_TO_DATA_P( &node->root ); - - data->cache_index = (FT_UShort) cache->root.cache_index; - data->ref_count = (FT_Short) 0; - node->queue_index = (FT_UShort) queue->queue_index; - node->glyph_index = (FT_UShort) gindex; + + + data->cache_index = (FT_UShort)cache->root.cache_index; + data->ref_count = (FT_Short) 0; + node->queue_index = (FT_UShort)queue->queue_index; + node->glyph_index = (FT_UShort)gindex; } + /* Important: This function is called from the cache manager to */ + /* destroy a given cache node during `cache compression'. The */ + /* second argument is always `cache.user_data'. Thus be */ + /* certain that the function FTC_Image_Cache_New() does indeed */ + /* set its `user_data' field correctly, otherwise bad things */ + /* will happen! */ - - /* Important: this function is called from the cache manager to */ - /* destroy a given cache node during "cache compression". The */ - /* second argument is always "cache.user_data". You thus be */ - /* certain that the function FTC_Image_Cache_New does indeed */ - /* set its "user_data" field correctly, otherwise bad things */ - /* will happen !! */ - - FT_EXPORT_FUNC(void) FTC_GlyphNode_Destroy( FTC_GlyphNode node, - FTC_Glyph_Cache cache ) + FT_EXPORT_FUNC( void ) FTC_GlyphNode_Destroy( FTC_GlyphNode node, + FTC_Glyph_Cache cache ) { - FT_LruNode queue_lru = cache->queues_lru->nodes+node->queue_index; + FT_LruNode queue_lru = cache->queues_lru->nodes + node->queue_index; FTC_Glyph_Queue queue = (FTC_Glyph_Queue)queue_lru->root.data; FT_UInt hash = node->glyph_index % queue->hash_size; FT_List bucket = queue->buckets + hash; - + + /* remove node from its queue's bucket list */ - FT_List_Remove( bucket, FTC_GLYPHNODE_TO_LISTNODE(node) ); - + FT_List_Remove( bucket, FTC_GLYPHNODE_TO_LISTNODE( node ) ); + /* destroy the node */ queue->clazz->destroy_node( node, queue ); } - - /* Important: this function is called from the cache manager to */ - /* size a given cache node during "cache compression". The */ - /* second argument is always "cache.user_data". You thus be */ - /* certain that the function FTC_Image_Cache_New does indeed */ - /* set its "user_data" field correctly, otherwise bad things */ - /* will happen !! */ - - FT_EXPORT_FUNC(FT_ULong) FTC_GlyphNode_Size( FTC_GlyphNode node, - FTC_Glyph_Cache cache ) + + /* Important: This function is called from the cache manager to */ + /* size a given cache node during `cache compression'. The */ + /* second argument is always `cache.user_data'. Thus be */ + /* certain that the function FTC_Image_Cache_New() does indeed */ + /* set its `user_data' field correctly, otherwise bad things */ + /* will happen! */ + + FT_EXPORT_FUNC( FT_ULong ) FTC_GlyphNode_Size( FTC_GlyphNode node, + FTC_Glyph_Cache cache ) { - FT_LruNode queue_lru = cache->queues_lru->nodes+node->queue_index; + FT_LruNode queue_lru = cache->queues_lru->nodes + node->queue_index; FTC_Glyph_Queue queue = (FTC_Glyph_Queue)queue_lru->root.data; - + + return queue->clazz->size_node( node, queue ); } - FT_CPLUSPLUS(const FTC_CacheNode_Class) ftc_glyph_cache_node_class = + FT_CPLUSPLUS( const FTC_CacheNode_Class ) ftc_glyph_cache_node_class = { - (FTC_CacheNode_SizeFunc) FTC_GlyphNode_Size, - (FTC_CacheNode_DestroyFunc) FTC_GlyphNode_Destroy + (FTC_CacheNode_SizeFunc) FTC_GlyphNode_Size, + (FTC_CacheNode_DestroyFunc)FTC_GlyphNode_Destroy }; - /*************************************************************************/ - /*************************************************************************/ - /***** *****/ - /***** GLYPH QUEUES *****/ - /***** *****/ - /*************************************************************************/ - /*************************************************************************/ - FT_EXPORT_FUNC(FT_Error) FTC_Glyph_Queue_New( - FTC_Glyph_Cache cache, - FT_Pointer type, - FTC_Glyph_Queue* aqueue ) + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** GLYPH QUEUES *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ + + + FT_EXPORT_FUNC( FT_Error ) FTC_Glyph_Queue_New( FTC_Glyph_Cache cache, + FT_Pointer type, + FTC_Glyph_Queue* aqueue ) { FT_Error error; FT_Memory memory = cache->root.memory; FTC_Manager manager = cache->root.manager; FTC_Glyph_Queue queue = 0; - - FTC_Glyph_Cache_Class* gcache_class; - FTC_Glyph_Queue_Class* clazz; - + + FTC_Glyph_Cache_Class* gcache_class; + FTC_Glyph_Queue_Class* clazz; + + gcache_class = (FTC_Glyph_Cache_Class*)cache->root.clazz; clazz = gcache_class->queue_class; - + *aqueue = 0; - + if ( ALLOC( queue, clazz->queue_byte_size ) ) goto Exit; - + queue->cache = cache; queue->manager = manager; queue->memory = memory; @@ -139,14 +149,13 @@ /* allocate buckets table */ if ( ALLOC_ARRAY( queue->buckets, queue->hash_size, FT_ListRec ) ) - if (error) goto Exit; - /* initialize queue by type - if needed */ - if (clazz->init) + /* initialize queue by type if needed */ + if ( clazz->init ) { error = clazz->init( queue, type ); - if (error) + if ( error ) goto Exit; } @@ -160,77 +169,79 @@ } return error; - } + } - - FT_EXPORT_FUNC(void) FTC_Glyph_Queue_Done( FTC_Glyph_Queue queue ) + FT_EXPORT_FUNC( void ) FTC_Glyph_Queue_Done( FTC_Glyph_Queue queue ) { - FTC_Glyph_Cache cache = queue->cache; - FTC_Manager manager = cache->root.manager; - FT_List glyphs_lru = &manager->global_lru; - FT_List bucket = queue->buckets; - FT_List bucket_limit = bucket + queue->hash_size; - FT_Memory memory = cache->root.memory; - + FTC_Glyph_Cache cache = queue->cache; + FTC_Manager manager = cache->root.manager; + FT_List glyphs_lru = &manager->global_lru; + FT_List bucket = queue->buckets; + FT_List bucket_limit = bucket + queue->hash_size; + FT_Memory memory = cache->root.memory; + FTC_Glyph_Queue_Class* clazz = queue->clazz; - /* for each bucket, free the list of Glyph nodes */ + + /* for each bucket, free the list of glyph nodes */ for ( ; bucket < bucket_limit; bucket++ ) { FT_ListNode node = bucket->head; FT_ListNode next = 0; FT_ListNode lrunode; FTC_GlyphNode inode; - + for ( ; node; node = next ) { next = node->next; - inode = FTC_LISTNODE_TO_GLYPHNODE(node); + inode = FTC_LISTNODE_TO_GLYPHNODE( node ); lrunode = FTC_GLYPHNODE_TO_LRUNODE( inode ); - + manager->num_bytes -= clazz->size_node( inode, queue ); - + FT_List_Remove( glyphs_lru, lrunode ); clazz->destroy_node( inode, queue ); } - + bucket->head = bucket->tail = 0; } - if (clazz->done) - clazz->done(queue); + if ( clazz->done ) + clazz->done( queue ); FREE( queue->buckets ); FREE( queue ); } - FT_EXPORT_FUNC(FT_Error) FTC_Glyph_Queue_Lookup_Node( - FTC_Glyph_Queue queue, - FT_UInt glyph_index, - FTC_GlyphNode* anode ) + FT_EXPORT_FUNC( FT_Error ) FTC_Glyph_Queue_Lookup_Node( + FTC_Glyph_Queue queue, + FT_UInt glyph_index, + FTC_GlyphNode* anode ) { - FTC_Glyph_Cache cache = queue->cache; - FTC_Manager manager = cache->root.manager; - FT_UInt hash_index = glyph_index % queue->hash_size; - FT_List bucket = queue->buckets + hash_index; - FT_ListNode node; - FT_Error error; - FTC_GlyphNode inode; - + FTC_Glyph_Cache cache = queue->cache; + FTC_Manager manager = cache->root.manager; + FT_UInt hash_index = glyph_index % queue->hash_size; + FT_List bucket = queue->buckets + hash_index; + FT_ListNode node; + FT_Error error; + FTC_GlyphNode inode; + FTC_Glyph_Queue_Class* clazz = queue->clazz; + *anode = 0; for ( node = bucket->head; node; node = node->next ) { FT_UInt gindex; - - inode = FTC_LISTNODE_TO_GLYPHNODE(node); + + + inode = FTC_LISTNODE_TO_GLYPHNODE( node ); gindex = inode->glyph_index; - + if ( gindex == glyph_index ) { /* we found it! -- move glyph to start of the lists */ @@ -247,23 +258,23 @@ goto Exit; /* insert the node at the start of our bucket list */ - FT_List_Insert( bucket, FTC_GLYPHNODE_TO_LISTNODE(inode) ); - + FT_List_Insert( bucket, FTC_GLYPHNODE_TO_LISTNODE( inode ) ); + /* insert the node at the start the global LRU glyph list */ - FT_List_Insert( &manager->global_lru, FTC_GLYPHNODE_TO_LRUNODE(inode) ); - + FT_List_Insert( &manager->global_lru, FTC_GLYPHNODE_TO_LRUNODE( inode ) ); + manager->num_bytes += clazz->size_node( inode, queue ); if (manager->num_bytes > manager->max_bytes) FTC_Manager_Compress( manager ); - + *anode = inode; Exit: return error; } - + /*************************************************************************/ /*************************************************************************/ /***** *****/ @@ -271,14 +282,14 @@ /***** *****/ /*************************************************************************/ /*************************************************************************/ - + #define FTC_QUEUE_LRU_GET_CACHE( lru ) \ ( (FTC_Glyph_Cache)(lru)->user_data ) - + #define FTC_QUEUE_LRU_GET_MANAGER( lru ) \ FTC_QUEUE_LRU_GET_CACHE( lru )->manager - + #define FTC_LRUNODE_QUEUE( node ) \ ( (FTC_Glyph_Queue)(node)->root.data ) @@ -291,6 +302,7 @@ FT_Error error; FTC_Glyph_Queue queue; + error = FTC_Glyph_Queue_New( cache, (FT_Pointer)node->key, &queue ); @@ -300,18 +312,17 @@ queue->queue_index = node - lru->nodes; node->root.data = queue; } - + return error; } - LOCAL_FUNC_X void ftc_glyph_queue_lru_done( FT_Lru lru, FT_LruNode node ) { FTC_Glyph_Queue queue = FTC_LRUNODE_QUEUE( node ); - + FT_UNUSED( lru ); @@ -319,16 +330,16 @@ } - LOCAL_FUNC_X FT_Bool ftc_glyph_queue_lru_compare( FT_LruNode node, FT_LruKey key ) { FTC_Glyph_Queue queue = FTC_LRUNODE_QUEUE( node ); - return queue->clazz->compare( queue, (FT_Pointer)key ); - } + return queue->clazz->compare( queue, (FT_Pointer)key ); + } + FT_CPLUSPLUS( const FT_Lru_Class ) ftc_glyph_queue_lru_class = { @@ -340,7 +351,6 @@ }; - /*************************************************************************/ /*************************************************************************/ /***** *****/ @@ -348,21 +358,23 @@ /***** *****/ /*************************************************************************/ /*************************************************************************/ - - FT_EXPORT_FUNC(FT_Error) FTC_Glyph_Cache_Init( FTC_Glyph_Cache cache ) + + FT_EXPORT_FUNC( FT_Error ) FTC_Glyph_Cache_Init( FTC_Glyph_Cache cache ) { - FT_Memory memory = cache->root.memory; - FT_Error error; + FT_Memory memory = cache->root.memory; + FT_Error error; + /* set up root node_class to be used by manager */ - cache->root.node_clazz = (FTC_CacheNode_Class*)&ftc_glyph_cache_node_class; - - /* The following is extremely important for ftc_destroy_glyph_image */ - /* to work properly, as the second parameter that is sent to it */ - /* through the cache manager is "user_data" and must be set to */ - /* "cache" here.. */ - /* */ + cache->root.node_clazz = + (FTC_CacheNode_Class*)&ftc_glyph_cache_node_class; + + /* The following is extremely important for ftc_destroy_glyph_image() */ + /* to work properly, as the second parameter that is sent to it */ + /* through the cache manager is `user_data' and must be set to */ + /* `cache' here. */ + /* */ cache->root.cache_user = cache; error = FT_Lru_New( &ftc_glyph_queue_lru_class, @@ -375,12 +387,11 @@ } - FT_EXPORT_FUNC(void) FTC_Glyph_Cache_Done( FTC_Glyph_Cache cache ) + FT_EXPORT_FUNC( void ) FTC_Glyph_Cache_Done( FTC_Glyph_Cache cache ) { - /* discard Glyph queues */ + /* discard glyph queues */ FT_Lru_Done( cache->queues_lru ); } - /* END */ diff --git a/src/cache/ftcimage.c b/src/cache/ftcimage.c index a9e4f9df4..19d33b868 100644 --- a/src/cache/ftcimage.c +++ b/src/cache/ftcimage.c @@ -1,17 +1,39 @@ +/***************************************************************************/ +/* */ +/* ftcimage.c */ +/* */ +/* FreeType Image cache (body). */ +/* */ +/* Copyright 2000 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. */ +/* */ +/***************************************************************************/ + + #ifdef FT_FLAT_COMPILE # include "ftcimage.h" #else # include #endif - /*************************************************************************/ - /*************************************************************************/ - /***** *****/ - /***** GLYPH IMAGE NODES *****/ - /***** *****/ - /*************************************************************************/ - /*************************************************************************/ - +#include + + + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** GLYPH IMAGE NODES *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ + + /* this is a simple glyph image destructor, which is called exclusively */ /* from the CacheQueue object */ LOCAL_FUNC_X @@ -19,7 +41,8 @@ FTC_Glyph_Queue queue ) { FT_Memory memory = queue->memory; - + + FT_Done_Glyph( FTC_GLYPHNODE_GET_GLYPH( node ) ); FREE( node ); } @@ -28,8 +51,8 @@ LOCAL_FUNC_X FT_Error ftc_glyph_image_node_new( FTC_Glyph_Queue queue, FT_UInt glyph_index, - FTC_GlyphNode *anode ) - { + FTC_GlyphNode* anode ) + { FT_Memory memory = queue->memory; FTC_Image_Queue imageq = (FTC_Image_Queue)queue; FT_Error error; @@ -37,8 +60,9 @@ FT_Face face; FT_Size size; + /* allocate node */ - if ( ALLOC( node, sizeof(*node) ) ) + if ( ALLOC( node, sizeof ( *node ) ) ) goto Exit; /* init its inner fields */ @@ -53,13 +77,14 @@ FT_UInt glyph_index = node->glyph_index; FT_UInt load_flags = FT_LOAD_DEFAULT; FT_UInt image_type = imageq->description.image_type; - + + if ( FTC_IMAGE_FORMAT( image_type ) == ftc_image_format_bitmap ) - { - load_flags |= FT_LOAD_RENDER; + { + load_flags |= FT_LOAD_RENDER; if ( image_type & ftc_image_flag_monochrome ) load_flags |= FT_LOAD_MONOCHROME; - + /* disable embedded bitmaps loading if necessary */ if ( image_type & ftc_image_flag_no_sbits ) load_flags |= FT_LOAD_NO_BITMAP; @@ -68,14 +93,14 @@ { /* disable embedded bitmaps loading */ load_flags |= FT_LOAD_NO_BITMAP; - + if ( image_type & ftc_image_flag_unscaled ) load_flags |= FT_LOAD_NO_SCALE; } - + if ( image_type & ftc_image_flag_unhinted ) load_flags |= FT_LOAD_NO_HINTING; - + if ( image_type & ftc_image_flag_autohinted ) load_flags |= FT_LOAD_FORCE_AUTOHINT; @@ -84,11 +109,11 @@ { if ( face->glyph->format == ft_glyph_format_bitmap || face->glyph->format == ft_glyph_format_outline ) - { + { /* ok, copy it */ FT_Glyph glyph; - - + + error = FT_Get_Glyph( face->glyph, &glyph ); if ( !error ) FTC_GLYPHNODE_SET_GLYPH( node, glyph ); @@ -97,64 +122,68 @@ error = FT_Err_Invalid_Argument; } } + Exit: - if (error && node) - FREE(node); + if ( error && node ) + FREE( node ); *anode = node; return error; } - /* this function is important, because it is both part of */ - /* a FTC_Glyph_Queue_Class and a FTC_CacheNode_Class */ - /* */ + /* this function is important because it is both part of */ + /* a FTC_Glyph_Queue_Class and a FTC_CacheNode_Class */ + /* */ LOCAL_FUNC_X - FT_ULong ftc_glyph_image_node_size( FTC_GlyphNode node ) + FT_ULong ftc_glyph_image_node_size( FTC_GlyphNode node ) { - FT_ULong size = 0; - FT_Glyph glyph = FTC_GLYPHNODE_GET_GLYPH(node); - - switch (glyph->format) + FT_ULong size = 0; + FT_Glyph glyph = FTC_GLYPHNODE_GET_GLYPH( node ); + + + switch ( glyph->format ) { - case ft_glyph_format_bitmap: - { - FT_BitmapGlyph bitg; - - bitg = (FT_BitmapGlyph)glyph; - size = bitg->bitmap.rows * labs(bitg->bitmap.pitch) + - sizeof(*bitg); - } - break; - - case ft_glyph_format_outline: - { - FT_OutlineGlyph outg; - - outg = (FT_OutlineGlyph)glyph; - size = outg->outline.n_points * - ( sizeof( FT_Vector ) + sizeof( FT_Byte ) ) + - outg->outline.n_contours * - sizeof( FT_Short ) + - sizeof(*outg); - } - break; - - default: - ; + case ft_glyph_format_bitmap: + { + FT_BitmapGlyph bitg; + + + bitg = (FT_BitmapGlyph)glyph; + size = bitg->bitmap.rows * labs( bitg->bitmap.pitch ) + + sizeof ( *bitg ); + } + break; + + case ft_glyph_format_outline: + { + FT_OutlineGlyph outg; + + + outg = (FT_OutlineGlyph)glyph; + size = outg->outline.n_points * + ( sizeof( FT_Vector ) + sizeof ( FT_Byte ) ) + + outg->outline.n_contours * sizeof ( FT_Short ) + + sizeof ( *outg ); + } + break; + + default: + ; } - size += sizeof(*node); + + size += sizeof ( *node ); return size; } - /*************************************************************************/ - /*************************************************************************/ - /***** *****/ - /***** GLYPH IMAGE QUEUES *****/ - /***** *****/ - /*************************************************************************/ - /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** GLYPH IMAGE QUEUES *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ LOCAL_FUNC_X @@ -167,45 +196,44 @@ LOCAL_FUNC_X - FT_Bool ftc_image_queue_compare( FTC_Image_Queue queue, - FTC_Image_Desc* type ) + FT_Bool ftc_image_queue_compare( FTC_Image_Queue queue, + FTC_Image_Desc* type ) { - return !memcmp( &queue->description, type, sizeof(*type) ); + return !memcmp( &queue->description, type, sizeof ( *type ) ); } - - FT_CPLUSPLUS(const FTC_Glyph_Queue_Class) ftc_glyph_image_queue_class = + + FT_CPLUSPLUS( const FTC_Glyph_Queue_Class ) ftc_glyph_image_queue_class = { sizeof( FTC_Image_QueueRec ), - - (FTC_Glyph_Queue_InitFunc) ftc_image_queue_init, - (FTC_Glyph_Queue_DoneFunc) 0, - (FTC_Glyph_Queue_CompareFunc) ftc_image_queue_compare, - - (FTC_Glyph_Queue_NewNodeFunc) ftc_glyph_image_node_new, - (FTC_Glyph_Queue_SizeNodeFunc) ftc_glyph_image_node_size, - (FTC_Glyph_Queue_DestroyNodeFunc) ftc_glyph_image_node_destroy + + (FTC_Glyph_Queue_InitFunc) ftc_image_queue_init, + (FTC_Glyph_Queue_DoneFunc) 0, + (FTC_Glyph_Queue_CompareFunc) ftc_image_queue_compare, + + (FTC_Glyph_Queue_NewNodeFunc) ftc_glyph_image_node_new, + (FTC_Glyph_Queue_SizeNodeFunc) ftc_glyph_image_node_size, + (FTC_Glyph_Queue_DestroyNodeFunc)ftc_glyph_image_node_destroy }; - /*************************************************************************/ - /*************************************************************************/ - /***** *****/ - /***** GLYPH IMAGE CACHE *****/ - /***** *****/ - /*************************************************************************/ - /*************************************************************************/ + /*************************************************************************/ + /*************************************************************************/ + /***** *****/ + /***** GLYPH IMAGE CACHE *****/ + /***** *****/ + /*************************************************************************/ + /*************************************************************************/ - - FT_CPLUSPLUS(const FTC_Glyph_Cache_Class) ftc_glyph_image_cache_class = + FT_CPLUSPLUS( const FTC_Glyph_Cache_Class ) ftc_glyph_image_cache_class = { { sizeof( FTC_Glyph_CacheRec ), - (FTC_Cache_InitFunc) FTC_Glyph_Cache_Init, - (FTC_Cache_DoneFunc) FTC_Glyph_Cache_Done + (FTC_Cache_InitFunc)FTC_Glyph_Cache_Init, + (FTC_Cache_DoneFunc)FTC_Glyph_Cache_Done }, - (FTC_Glyph_Queue_Class*) &ftc_glyph_image_queue_class + (FTC_Glyph_Queue_Class*)&ftc_glyph_image_queue_class }; @@ -217,7 +245,7 @@ (FTC_Cache_Class*)&ftc_glyph_image_cache_class, (FTC_Cache*)acache ); } - + FT_EXPORT_DEF( FT_Error ) FTC_Image_Cache_Lookup( FTC_Image_Cache cache, @@ -232,15 +260,16 @@ FTC_Image_Queue img_queue; + /* check for valid `desc' delayed to FT_Lru_Lookup() */ if ( !cache || !aglyph ) return FT_Err_Invalid_Argument; - *aglyph = 0; + *aglyph = 0; queue = cache->root.last_queue; img_queue = (FTC_Image_Queue)queue; - if ( !queue || memcmp( &img_queue->description, desc, sizeof(*desc) ) ) + if ( !queue || memcmp( &img_queue->description, desc, sizeof ( *desc ) ) ) { error = FT_Lru_Lookup( cache->root.queues_lru, (FT_LruKey)desc, @@ -256,11 +285,11 @@ /* now compress the manager's cache pool if needed */ manager = cache->root.root.manager; - if (manager->num_bytes > manager->max_bytes) + if ( manager->num_bytes > manager->max_bytes ) { - FTC_GlyphNode_Ref(inode); + FTC_GlyphNode_Ref( inode ); FTC_Manager_Compress( manager ); - FTC_GlyphNode_Unref(inode); + FTC_GlyphNode_Unref( inode ); } *aglyph = FTC_GLYPHNODE_GET_GLYPH( inode ); @@ -270,3 +299,4 @@ } +/* END */ diff --git a/src/cache/ftcimage.h b/src/cache/ftcimage.h index cf29d2a81..80de1150e 100644 --- a/src/cache/ftcimage.h +++ b/src/cache/ftcimage.h @@ -1,21 +1,55 @@ +/***************************************************************************/ +/* */ +/* ftcimage.c */ +/* */ +/* FreeType Image cache (body). */ +/* */ +/* Copyright 2000 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 FTCIMAGE_H #define FTCIMAGE_H + #include - /* the glyph image queue type */ - typedef struct FTC_Image_QueueRec_ + +#ifdef __cplusplus + extern "C" { +#endif + + + /* the glyph image queue type */ + typedef struct FTC_Image_QueueRec_ { FTC_Glyph_QueueRec root; FTC_Image_Desc description; } FTC_Image_QueueRec, *FTC_Image_Queue; - typedef struct FTC_Image_CacheRec_ + + typedef struct FTC_Image_CacheRec_ { FTC_Glyph_CacheRec root; } FTC_Image_CacheRec; + +#ifdef __cplusplus + } +#endif + + #endif /* FTCIMAGE_H */ + +/* END */ diff --git a/src/cache/ftcmanag.c b/src/cache/ftcmanag.c index 64157e130..fe4664a0f 100644 --- a/src/cache/ftcmanag.c +++ b/src/cache/ftcmanag.c @@ -21,8 +21,9 @@ #include #include -#undef FT_COMPONENT -#define FT_COMPONENT trace_cache + +#undef FT_COMPONENT +#define FT_COMPONENT trace_cache #define FTC_LRU_GET_MANAGER( lru ) (FTC_Manager)lru->user_data @@ -36,14 +37,14 @@ /*************************************************************************/ - LOCAL_FUNC_X + LOCAL_FUNC_X FT_Error ftc_manager_init_face( FT_Lru lru, FT_LruNode node ) { FTC_Manager manager = FTC_LRU_GET_MANAGER( lru ); FT_Error error; FT_Face face; - + error = manager->request_face( (FTC_FaceID)node->key, manager->library, @@ -60,7 +61,7 @@ } - /* helper function for ftc_manager_done_face */ + /* helper function for ftc_manager_done_face() */ LOCAL_FUNC_X FT_Bool ftc_manager_size_selector( FT_Lru lru, FT_LruNode node, @@ -78,7 +79,7 @@ { FTC_Manager manager = FTC_LRU_GET_MANAGER( lru ); FT_Face face = (FT_Face)node->root.data; - + /* we must begin by removing all sizes for the target face */ /* from the manager's list */ @@ -86,7 +87,7 @@ ftc_manager_size_selector, face ); - /* all right, we can discard the face now */ + /* all right, we can discard the face now */ FT_Done_Face( face ); node->root.data = 0; } @@ -97,7 +98,7 @@ FT_Face face; FT_UShort width; FT_UShort height; - + } FTC_FontRequest; @@ -109,10 +110,10 @@ FT_Size size; FT_Error error; FT_Face face = font_req->face; - + FT_UNUSED( lru ); - + node->root.data = 0; error = FT_New_Size( face, &size ); if ( !error ) @@ -126,7 +127,7 @@ else node->root.data = size; } - return error; + return error; } @@ -137,7 +138,7 @@ FT_UNUSED( lru ); FT_Done_Size( (FT_Size)node->root.data ); - } + } LOCAL_FUNC_X @@ -148,7 +149,7 @@ FTC_FontRequest* req = (FTC_FontRequest*)key; FT_Size size = (FT_Size)node->root.data; FT_Error error; - + if ( size->face == req->face ) { @@ -173,7 +174,7 @@ { FTC_FontRequest* req = (FTC_FontRequest*)key; FT_Size size = (FT_Size)node->root.data; - + FT_UNUSED( node ); @@ -182,7 +183,7 @@ size->metrics.y_ppem == req->height ); } - + FT_CPLUSPLUS( const FT_Lru_Class ) ftc_face_lru_class = { sizeof ( FT_LruRec ), @@ -192,7 +193,7 @@ 0 }; - + FT_CPLUSPLUS( const FT_Lru_Class ) ftc_size_lru_class = { sizeof ( FT_LruRec ), @@ -214,8 +215,8 @@ FT_Error error; FT_Memory memory; FTC_Manager manager = 0; - - + + if ( !library ) return FT_Err_Invalid_Library_Handle; @@ -223,16 +224,16 @@ if ( ALLOC( manager, sizeof ( *manager ) ) ) goto Exit; - + if ( max_faces == 0 ) max_faces = FTC_MAX_FACES_DEFAULT; - + if ( max_sizes == 0 ) max_sizes = FTC_MAX_SIZES_DEFAULT; - + if ( max_bytes == 0 ) max_bytes = FTC_MAX_BYTES_DEFAULT; - + error = FT_Lru_New( &ftc_face_lru_class, max_faces, manager, @@ -241,22 +242,22 @@ (FT_Lru*)&manager->faces_lru ); if ( error ) goto Exit; - + error = FT_Lru_New( &ftc_size_lru_class, max_sizes, manager, memory, 1, /* pre_alloc = TRUE */ - (FT_Lru*)&manager->sizes_lru ); + (FT_Lru*)&manager->sizes_lru ); if ( error ) goto Exit; - + manager->library = library; manager->max_bytes = max_bytes; manager->request_face = requester; manager->request_data = req_data; *amanager = manager; - + Exit: if ( error && manager ) { @@ -264,16 +265,16 @@ FT_Lru_Done( manager->faces_lru ); FREE( manager ); } - + return error; } - + FT_EXPORT_DEF( void ) FTC_Manager_Done( FTC_Manager manager ) { FT_Memory memory; FT_UInt index; - + if ( !manager || !manager->library ) return; @@ -284,20 +285,20 @@ for (index = 0; index < FTC_MAX_CACHES; index++ ) { FTC_Cache cache = manager->caches[index]; - - - if (cache) + + + if ( cache ) { cache->clazz->done_cache( cache ); - FREE(cache); + FREE( cache ); manager->caches[index] = 0; } } - + /* discard faces and sizes */ FT_Lru_Done( manager->sizes_lru ); FT_Lru_Done( manager->faces_lru ); - + FREE( manager ); } @@ -320,7 +321,7 @@ return FT_Err_Invalid_Cache_Handle; return FT_Lru_Lookup( manager->faces_lru, - (FT_LruKey)face_id, + (FT_LruKey)face_id, (FT_Pointer*)aface ); } @@ -332,34 +333,34 @@ { FTC_FontRequest req; FT_Error error; - + /* check for valid `manager' delayed to FTC_Manager_Lookup_Face() */ if ( aface ) *aface = 0; - + if ( asize ) *asize = 0; - error = FTC_Manager_Lookup_Face( manager, font->face_id, aface ); + error = FTC_Manager_Lookup_Face( manager, font->face_id, aface ); if ( !error ) { FT_Size size; - + req.face = *aface; req.width = font->pix_width; req.height = font->pix_height; - + error = FT_Lru_Lookup( manager->sizes_lru, (FT_LruKey)&req, (FT_Pointer*)&size ); if ( !error ) { /* select the size as the current one for this face */ - face->size = size; - + (*aface)->size = size; + if ( asize ) *asize = size; } @@ -369,41 +370,44 @@ } - /* "compress" the manager's data, i.e. get rids of old cache nodes */ + /* `Compress' the manager's data, i.e., get rid of old cache nodes */ /* that are not referenced anymore in order to limit the total */ - /* memory used by the cache.. */ - FT_EXPORT_FUNC(void) FTC_Manager_Compress( FTC_Manager manager ) + /* memory used by the cache. */ + FT_EXPORT_FUNC( void ) FTC_Manager_Compress( FTC_Manager manager ) { FT_ListNode node; - + + node = manager->global_lru.tail; - while (manager->num_bytes > manager->max_bytes && node) + while ( manager->num_bytes > manager->max_bytes && node ) { - FTC_CacheNode cache_node = FTC_LIST_TO_CACHENODE(node); - FTC_CacheNode_Data* data = FTC_CACHENODE_TO_DATA_P(cache_node); + FTC_CacheNode cache_node = FTC_LIST_TO_CACHENODE( node ); + FTC_CacheNode_Data* data = FTC_CACHENODE_TO_DATA_P( cache_node ); FTC_Cache cache; FT_ListNode prev = node->prev; - - if (data->ref_count <= 0) + + + if ( data->ref_count <= 0 ) { - /* ok, we're going to remove this node */ + /* ok, we are going to remove this node */ FT_List_Remove( &manager->global_lru, node ); - + /* finalize cache node */ cache = manager->caches[data->cache_index]; - if (cache) + if ( cache ) { FTC_CacheNode_Class* clazz = cache->node_clazz; - + + manager->num_bytes -= clazz->size_node( cache_node, cache->cache_user ); - + clazz->destroy_node( cache_node, cache->cache_user ); } else { - /* this should never happen !! */ - FT_ERROR(( "FTC_Manager_Compress: Cache Manager is corrupted !!\n" )); + /* this should never happen! */ + FT_ERROR(( "FTC_Manager_Compress: Cache Manager is corrupted!\n" )); } } node = prev; @@ -412,19 +416,20 @@ FT_EXPORT_DEF( FT_Error ) FTC_Manager_Register_Cache( - FTC_Manager manager, - FTC_Cache_Class* clazz, - FTC_Cache *acache ) + FTC_Manager manager, + FTC_Cache_Class* clazz, + FTC_Cache* acache ) { - FT_Error error = FT_Err_Invalid_Argument; - - + FT_Error error = FT_Err_Invalid_Argument; + + if ( manager && clazz && acache ) { FT_Memory memory = manager->library->memory; FTC_Cache cache; FT_UInt index = 0; + /* by default, return 0 */ *acache = 0; @@ -434,33 +439,35 @@ if ( manager->caches[index] == 0 ) break; } - + /* return an error if there are too many registered caches */ - if (index >= FTC_MAX_CACHES) + if ( index >= FTC_MAX_CACHES ) { error = FT_Err_Too_Many_Caches; FT_ERROR(( "FTC_Manager_Register_Cache:" )); - FT_ERROR(( " too many registered caches..\n" )); + FT_ERROR(( " too many registered caches\n" )); goto Exit; } - + if ( !ALLOC( cache, clazz->cache_byte_size ) ) { cache->manager = manager; cache->memory = memory; cache->clazz = clazz; - if (clazz->init_cache) + if ( clazz->init_cache ) error = clazz->init_cache( cache ); - - if (error) - FREE(cache); + + if ( error ) + FREE( cache ); else - manager->caches[index] = *acache = cache; + manager->caches[index] = *acache = cache; } } + Exit: return error; } + /* END */