formatting

small fixes
This commit is contained in:
Werner Lemberg 2000-10-12 05:05:40 +00:00
parent 3c95d31ed4
commit eddd9909e2
10 changed files with 763 additions and 663 deletions

View File

@ -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,46 +13,52 @@
/* 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 <freetype/cache/ftcmanag.h>
#include <freetype/ftglyph.h>
#include <stddef.h>
#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
@ -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,7 +94,7 @@
( (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.. */
/* 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 ) ) )
@ -92,7 +103,10 @@
#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 );
@ -109,10 +123,10 @@
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_
{
FT_UInt queue_byte_size;
@ -161,9 +175,11 @@
} 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,
@ -185,8 +201,8 @@
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_EXPORT_DEF( FT_Error ) FTC_Glyph_Queue_New( FTC_Glyph_Cache cache,
FT_Pointer type,
FTC_Glyph_Queue* aqueue );
@ -196,10 +212,6 @@
FTC_GlyphNode* anode );
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 );
#ifdef __cplusplus
}
#endif

View File

@ -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.. */
/* - 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 */
/* - 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 a FT_Glyph image containing */
/* a vector outline, or some glyph metrics, or anything else.. */
/* 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. */
/* 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 */
/* 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) */
/* 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 **********/
/********* **********/
/**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/********* *********/
/********* WARNING, THIS IS ALPHA CODE, THIS API *********/
/********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE *********/
/********* FREETYPE DEVELOPMENT TEAM *********/
/********* *********/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
/*************************************************************************/
#ifndef FTCMANAG_H
@ -68,10 +72,11 @@
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 !! */
#define FTC_MAX_BYTES_DEFAULT 300000 /* 300kByte by default! */
/* maximum number of caches registered in a single manager */
#define FTC_MAX_CACHES 16
@ -94,31 +99,31 @@
} FTC_ManagerRec;
/*********************************************************************/
/*********************************************************************/
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** 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 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.. */
/* 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. */
/* */
typedef FT_ListNodeRec FTC_CacheNodeRec;
typedef FTC_CacheNodeRec* FTC_CacheNode;
/* the fields "cachenode.data" is typecasted to this type */
/* the fields `cachenode.data' is typecast to this type */
typedef struct FTC_CacheNode_Data_
{
FT_UShort cache_index;
@ -126,25 +131,25 @@
} FTC_CacheNode_Data;
/* returns a pointer to the FTC_CacheNode_Data contained in a */
/* CacheNode's "data" field.. */
/* 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 )
#define FTC_LIST_TO_CACHENODE( n ) ( (FTC_CacheNode)(n) )
/* returns the size in bytes of a given cache node */
/* return the size in bytes of a given cache node */
typedef FT_ULong (*FTC_CacheNode_SizeFunc)( FTC_CacheNode node,
FT_Pointer user );
/* finalise a given cache node */
/* 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" there because cache objects are entirely */
/* responsible for the creation of new cache nodes */
/* 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_
{
@ -154,13 +159,13 @@
} FTC_CacheNode_Class;
/*********************************************************************/
/*********************************************************************/
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** CACHE DEFINITIONS *****/
/***** *****/
/*********************************************************************/
/*********************************************************************/
/*************************************************************************/
/*************************************************************************/
typedef FT_Error (*FTC_Cache_InitFunc)( FTC_Cache cache );
@ -175,8 +180,6 @@
FTC_Cache_DoneFunc done_cache;
};
typedef struct FTC_CacheRec_
{
FTC_Manager manager;
@ -190,9 +193,9 @@
} 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.. */
/* memory used by the cache. */
FT_EXPORT_DEF( void ) FTC_Manager_Compress( FTC_Manager manager );

View File

@ -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 */
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;
@ -85,34 +89,35 @@
{
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 */
/* 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.. */
/* 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 );

View File

@ -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 <freetype/ftglyph.h>
@ -102,8 +103,8 @@
/* */
/* <Description> */
/* 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. */
/* */
/* <Fields> */
/* face_id :: The ID of the face to use. */
@ -308,8 +309,7 @@
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;
@ -332,6 +332,8 @@
/*************************************************************************/
#define FTC_IMAGE_FORMAT( x ) ( (x) & 7 )
/*************************************************************************/
/* */
/* <Enum> */
@ -353,9 +355,6 @@
/* <Note> */
/* 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,
@ -369,9 +368,7 @@
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;
@ -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,

View File

@ -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 );

View File

@ -975,7 +975,7 @@
/* when the flag NO_RECURSE is set, we disable hinting and scaling */
if ( load_flags & FT_LOAD_NO_RECURSE )
{
/* disable scaling, hinting and transform */
/* disable scaling, hinting, and transformation */
load_flags |= FT_LOAD_NO_SCALE |
FT_LOAD_NO_HINTING |
FT_LOAD_IGNORE_TRANSFORM;

93
src/cache/ftcglyph.c vendored
View File

@ -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,21 +13,26 @@
/* 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 <freetype/cache/ftcglyph.h>
#include <freetype/fterrors.h>
#include <freetype/internal/ftobjs.h>
#include <freetype/internal/ftlist.h>
#include <freetype/fterrors.h>
/*************************************************************************/
/*************************************************************************/
/***** *****/
@ -36,10 +41,12 @@
/*************************************************************************/
/*************************************************************************/
/* 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 */
/* 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 )
@ -47,6 +54,7 @@
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;
@ -54,14 +62,12 @@
}
/* 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 !! */
/* 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! */
FT_EXPORT_FUNC( void ) FTC_GlyphNode_Destroy( FTC_GlyphNode node,
FTC_Glyph_Cache cache )
@ -71,6 +77,7 @@
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 ) );
@ -79,12 +86,12 @@
}
/* 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 !! */
/* 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 )
@ -92,6 +99,7 @@
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 );
}
@ -102,6 +110,7 @@
(FTC_CacheNode_DestroyFunc)FTC_GlyphNode_Destroy
};
/*************************************************************************/
/*************************************************************************/
/***** *****/
@ -110,8 +119,8 @@
/*************************************************************************/
/*************************************************************************/
FT_EXPORT_FUNC(FT_Error) FTC_Glyph_Queue_New(
FTC_Glyph_Cache cache,
FT_EXPORT_FUNC( FT_Error ) FTC_Glyph_Queue_New( FTC_Glyph_Cache cache,
FT_Pointer type,
FTC_Glyph_Queue* aqueue )
{
@ -123,6 +132,7 @@
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;
@ -139,10 +149,9 @@
/* allocate buckets table */
if ( ALLOC_ARRAY( queue->buckets, queue->hash_size, FT_ListRec ) )
if (error)
goto Exit;
/* initialize queue by type - if needed */
/* initialize queue by type if needed */
if ( clazz->init )
{
error = clazz->init( queue, type );
@ -163,7 +172,6 @@
}
FT_EXPORT_FUNC( void ) FTC_Glyph_Queue_Done( FTC_Glyph_Queue queue )
{
FTC_Glyph_Cache cache = queue->cache;
@ -175,7 +183,8 @@
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;
@ -223,11 +232,13 @@
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 );
gindex = inode->glyph_index;
@ -291,6 +302,7 @@
FT_Error error;
FTC_Glyph_Queue queue;
error = FTC_Glyph_Queue_New( cache,
(FT_Pointer)node->key,
&queue );
@ -305,7 +317,6 @@
}
LOCAL_FUNC_X
void ftc_glyph_queue_lru_done( FT_Lru lru,
FT_LruNode node )
@ -319,17 +330,17 @@
}
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 );
}
FT_CPLUSPLUS( const FT_Lru_Class ) ftc_glyph_queue_lru_class =
{
sizeof( FT_LruRec ),
@ -340,7 +351,6 @@
};
/*************************************************************************/
/*************************************************************************/
/***** *****/
@ -355,13 +365,15 @@
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 */
/* 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.. */
/* through the cache manager is `user_data' and must be set to */
/* `cache' here. */
/* */
cache->root.cache_user = cache;
@ -377,10 +389,9 @@
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 */

38
src/cache/ftcimage.c vendored
View File

@ -1,9 +1,30 @@
/***************************************************************************/
/* */
/* 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 <cache/ftcimage.h>
#endif
#include <string.h>
/*************************************************************************/
/*************************************************************************/
/***** *****/
@ -12,6 +33,7 @@
/*************************************************************************/
/*************************************************************************/
/* this is a simple glyph image destructor, which is called exclusively */
/* from the CacheQueue object */
LOCAL_FUNC_X
@ -20,6 +42,7 @@
{
FT_Memory memory = queue->memory;
FT_Done_Glyph( FTC_GLYPHNODE_GET_GLYPH( node ) );
FREE( node );
}
@ -37,6 +60,7 @@
FT_Face face;
FT_Size size;
/* allocate node */
if ( ALLOC( node, sizeof ( *node ) ) )
goto Exit;
@ -54,6 +78,7 @@
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;
@ -97,6 +122,7 @@
error = FT_Err_Invalid_Argument;
}
}
Exit:
if ( error && node )
FREE( node );
@ -106,7 +132,7 @@
}
/* this function is important, because it is both part of */
/* this function is important because it is both part of */
/* a FTC_Glyph_Queue_Class and a FTC_CacheNode_Class */
/* */
LOCAL_FUNC_X
@ -115,12 +141,14 @@
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 );
@ -131,11 +159,11 @@
{
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 ) +
outg->outline.n_contours * sizeof ( FT_Short ) +
sizeof ( *outg );
}
break;
@ -143,6 +171,7 @@
default:
;
}
size += sizeof ( *node );
return size;
}
@ -197,7 +226,6 @@
/*************************************************************************/
FT_CPLUSPLUS( const FTC_Glyph_Cache_Class ) ftc_glyph_image_cache_class =
{
{
@ -232,6 +260,7 @@
FTC_Image_Queue img_queue;
/* check for valid `desc' delayed to FT_Lru_Lookup() */
if ( !cache || !aglyph )
@ -270,3 +299,4 @@
}
/* END */

34
src/cache/ftcimage.h vendored
View File

@ -1,8 +1,33 @@
/***************************************************************************/
/* */
/* 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 <freetype/cache/ftcglyph.h>
#ifdef __cplusplus
extern "C" {
#endif
/* the glyph image queue type */
typedef struct FTC_Image_QueueRec_
{
@ -11,11 +36,20 @@
} FTC_Image_QueueRec, *FTC_Image_Queue;
typedef struct FTC_Image_CacheRec_
{
FTC_Glyph_CacheRec root;
} FTC_Image_CacheRec;
#ifdef __cplusplus
}
#endif
#endif /* FTCIMAGE_H */
/* END */

23
src/cache/ftcmanag.c vendored
View File

@ -21,6 +21,7 @@
#include <freetype/internal/ftdebug.h>
#include <freetype/ftlist.h>
#undef FT_COMPONENT
#define FT_COMPONENT trace_cache
@ -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,
@ -358,7 +359,7 @@
if ( !error )
{
/* select the size as the current one for this face */
face->size = size;
(*aface)->size = size;
if ( asize )
*asize = size;
@ -369,13 +370,14 @@
}
/* "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.. */
/* 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 )
{
@ -384,9 +386,10 @@
FTC_Cache cache;
FT_ListNode prev = node->prev;
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 */
@ -395,6 +398,7 @@
{
FTC_CacheNode_Class* clazz = cache->node_clazz;
manager->num_bytes -= clazz->size_node( cache_node,
cache->cache_user );
@ -402,8 +406,8 @@
}
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;
@ -425,6 +429,7 @@
FTC_Cache cache;
FT_UInt index = 0;
/* by default, return 0 */
*acache = 0;
@ -440,7 +445,7 @@
{
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;
}
@ -459,8 +464,10 @@
manager->caches[index] = *acache = cache;
}
}
Exit:
return error;
}
/* END */