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 */ /* ftcglyph.h */
/* */ /* */
/* FreeType glyph image (FT_Glyph) cache.. */ /* FreeType glyph image (FT_Glyph) cache (specification). */
/* */ /* */
/* Copyright 2000 by */ /* Copyright 2000 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */
@ -13,53 +13,59 @@
/* this file you indicate that you have read the license and */ /* this file you indicate that you have read the license and */
/* understand and accept it fully. */ /* 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.. */
/* */
/***************************************************************************/ /***************************************************************************/
/**************************************************************************/
/**************************************************************************/ /*************************************************************************/
/**************************************************************************/ /* */
/**************************************************************************/ /* 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 */
/********* WARNING, THIS IS ALPHA CODE, THIS API **********/ /* implement a FT_Glyph cache based on this code. */
/********* 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 FTCGLYPH_H #ifndef FTCGLYPH_H
#define FTCGLYPH_H #define FTCGLYPH_H
#include <freetype/cache/ftcmanag.h> #include <freetype/cache/ftcmanag.h>
#include <freetype/ftglyph.h> #include <freetype/ftglyph.h>
#include <stddef.h> #include <stddef.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #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_MAX_GLYPH_QUEUES 16
#define FTC_QUEUE_HASH_SIZE_DEFAULT 64 #define FTC_QUEUE_HASH_SIZE_DEFAULT 64
typedef struct FTC_Glyph_QueueRec_* FTC_Glyph_Queue; typedef struct FTC_Glyph_QueueRec_* FTC_Glyph_Queue;
typedef struct FTC_GlyphNodeRec_* FTC_GlyphNode; typedef struct FTC_GlyphNodeRec_* FTC_GlyphNode;
typedef struct FTC_Glyph_CacheRec_* FTC_Glyph_Cache; typedef struct FTC_Glyph_CacheRec_* FTC_Glyph_Cache;
typedef struct FTC_GlyphNodeRec_ typedef struct FTC_GlyphNodeRec_
{ {
@ -74,8 +80,13 @@
} FTC_GlyphNodeRec; } FTC_GlyphNodeRec;
#define FTC_GLYPHNODE_GET_GLYPH(n) ((FT_Glyph)((n)->link.data)) #define FTC_GLYPHNODE_GET_GLYPH( n ) \
#define FTC_GLYPHNODE_SET_GLYPH(n,g) do { (n)->link.data = (g); } while (0) ( (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 */ /* this macro is used to extract a handle to the bucket's lru list */
/* corresponding to a given image node */ /* corresponding to a given image node */
@ -83,37 +94,40 @@
( (FT_ListNode)&(n)->link ) ( (FT_ListNode)&(n)->link )
/* this macro is used to extract a handle to a given image node from */ /* 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 ) \ #define FTC_LISTNODE_TO_GLYPHNODE( p ) \
( (FTC_GlyphNode)( (char*)(p) - \ ( (FTC_GlyphNode)( (char*)(p) - \
offsetof( FTC_GlyphNodeRec,link ) ) ) offsetof( FTC_GlyphNodeRec,link ) ) )
#define FTC_GLYPHNODE_TO_LRUNODE(n) ((FT_ListNode)(n)) #define FTC_GLYPHNODE_TO_LRUNODE( n ) ( (FT_ListNode)(n) )
#define FTC_LRUNODE_TO_GLYPHNODE(n) ((FTC_GlyphNode)(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, typedef FT_Error (*FTC_Glyph_Queue_InitFunc)( FTC_Glyph_Queue queue,
FT_Pointer type ); 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, typedef FT_Bool (*FTC_Glyph_Queue_CompareFunc)( FTC_Glyph_Queue queue,
FT_Pointer type ); FT_Pointer type );
typedef FT_Error (*FTC_Glyph_Queue_NewNodeFunc)( FTC_Glyph_Queue queue, typedef FT_Error (*FTC_Glyph_Queue_NewNodeFunc)( FTC_Glyph_Queue queue,
FT_UInt gindex, FT_UInt gindex,
FTC_GlyphNode *anode ); FTC_GlyphNode* anode );
typedef void (*FTC_Glyph_Queue_DestroyNodeFunc)( FTC_GlyphNode node, typedef void (*FTC_Glyph_Queue_DestroyNodeFunc)( FTC_GlyphNode node,
FTC_Glyph_Queue queue ); FTC_Glyph_Queue queue );
typedef FT_ULong (*FTC_Glyph_Queue_SizeNodeFunc)( FTC_GlyphNode node, typedef FT_ULong (*FTC_Glyph_Queue_SizeNodeFunc)( FTC_GlyphNode node,
FTC_Glyph_Queue queue ); FTC_Glyph_Queue queue );
typedef struct FTC_Glyph_Queue_Class_
typedef struct FTC_Glyph_Queue_Class_
{ {
FT_UInt queue_byte_size; FT_UInt queue_byte_size;
@ -142,8 +156,8 @@
} FTC_Glyph_QueueRec; } FTC_Glyph_QueueRec;
/* the abstract glyph cache class */ /* the abstract glyph cache class */
typedef struct FTC_Glyph_Cache_Class_ typedef struct FTC_Glyph_Cache_Class_
{ {
FTC_Cache_Class root; FTC_Cache_Class root;
FTC_Glyph_Queue_Class* queue_class; FTC_Glyph_Queue_Class* queue_class;
@ -151,54 +165,52 @@
} FTC_Glyph_Cache_Class; } FTC_Glyph_Cache_Class;
/* the abstract glyph cache object */ /* the abstract glyph cache object */
typedef struct FTC_Glyph_CacheRec_ typedef struct FTC_Glyph_CacheRec_
{ {
FTC_CacheRec root; FTC_CacheRec root;
FT_Lru queues_lru; /* static queues lru list */ FT_Lru queues_lru; /* static queues lru list */
FTC_Glyph_Queue last_queue; /* small cache */ FTC_Glyph_Queue last_queue; /* small cache */
} FTC_Glyph_CacheRec; } 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, FT_EXPORT_FUNC( void ) FTC_GlyphNode_Init( FTC_GlyphNode node,
FTC_Glyph_Queue queue, FTC_Glyph_Queue queue,
FT_UInt gindex ); FT_UInt gindex );
#define FTC_GlyphNode_Ref(n) \ #define FTC_GlyphNode_Ref( n ) \
FTC_CACHENODE_TO_DATA_P(&(n)->root)->ref_count++ FTC_CACHENODE_TO_DATA_P( &(n)->root )->ref_count++
#define FTC_GlyphNode_Unref(n) \ #define FTC_GlyphNode_Unref( n ) \
FTC_CACHENODE_TO_DATA_P(&(n)->root)->ref_count-- FTC_CACHENODE_TO_DATA_P( &(n)->root )->ref_count--
FT_EXPORT_DEF(void) FTC_Destroy_Glyph_Node( FTC_GlyphNode node, FT_EXPORT_DEF( void ) FTC_Destroy_Glyph_Node( FTC_GlyphNode node,
FTC_Glyph_Cache cache ); 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( 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(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 #ifdef __cplusplus
} }

View File

@ -13,48 +13,52 @@
/* this file you indicate that you have read the license and */ /* this file you indicate that you have read the license and */
/* understand and accept it fully. */ /* 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) */
/* */
/***************************************************************************/ /***************************************************************************/
/**************************************************************************/
/**************************************************************************/ /*************************************************************************/
/**************************************************************************/ /* */
/**************************************************************************/ /* 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 */
/********* WARNING, THIS IS ALPHA CODE, THIS API **********/ /* callback. However, the manager maintains a small cache of FT_Face */
/********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE **********/ /* & FT_Size objects in order to speed things considerably. */
/********* FREETYPE DEVELOPMENT TEAM **********/ /* */
/********* **********/ /* - 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 #ifndef FTCMANAG_H
@ -68,13 +72,14 @@
extern "C" { extern "C" {
#endif #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 */ /* default values */
#define FTC_MAX_CACHES 16 #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_ typedef struct FTC_ManagerRec_
@ -86,114 +91,112 @@
FT_ULong max_bytes; FT_ULong max_bytes;
FT_ULong num_bytes; FT_ULong num_bytes;
FT_ListRec global_lru; FT_ListRec global_lru;
FTC_Cache caches[ FTC_MAX_CACHES ]; FTC_Cache caches[FTC_MAX_CACHES];
FT_Pointer request_data; FT_Pointer request_data;
FTC_Face_Requester request_face; FTC_Face_Requester request_face;
} FTC_ManagerRec; } 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 FT_ListNodeRec FTC_CacheNodeRec;
typedef FTC_CacheNodeRec* FTC_CacheNode; 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_ typedef struct FTC_CacheNode_Data_
{ {
FT_UShort cache_index; FT_UShort cache_index;
FT_Short ref_count; FT_Short ref_count;
} FTC_CacheNode_Data; } 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 */ #define FTC_LIST_TO_CACHENODE( n ) ( (FTC_CacheNode)(n) )
typedef FT_ULong (*FTC_CacheNode_SizeFunc)( FTC_CacheNode node,
FT_Pointer user );
/* finalise a given cache node */ /* return the size in bytes of a given cache node */
typedef void (*FTC_CacheNode_DestroyFunc)( FTC_CacheNode node, typedef FT_ULong (*FTC_CacheNode_SizeFunc)( FTC_CacheNode node,
FT_Pointer user ); FT_Pointer user );
/* this structure is used to provide functions to the cache manager */ /* finalize a given cache node */
/* It will use them to size and destroy cache nodes.. Note that there */ typedef void (*FTC_CacheNode_DestroyFunc)( FTC_CacheNode node,
/* is no "init_node" there because cache objects are entirely */ FT_Pointer user );
/* 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_ typedef struct FTC_CacheNode_Class_
{ {
FTC_CacheNode_SizeFunc size_node; FTC_CacheNode_SizeFunc size_node;
FTC_CacheNode_DestroyFunc destroy_node; FTC_CacheNode_DestroyFunc destroy_node;
} FTC_CacheNode_Class; } 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; FT_UInt cache_byte_size;
FTC_Cache_InitFunc init_cache; FTC_Cache_InitFunc init_cache;
FTC_Cache_DoneFunc done_cache; FTC_Cache_DoneFunc done_cache;
}; };
typedef struct FTC_CacheRec_ typedef struct FTC_CacheRec_
{ {
FTC_Manager manager; FTC_Manager manager;
FT_Memory memory; FT_Memory memory;
FTC_Cache_Class* clazz; FTC_Cache_Class* clazz;
FTC_CacheNode_Class* node_clazz; FTC_CacheNode_Class* node_clazz;
FT_UInt cache_index; /* in manager's table */ FT_UInt cache_index; /* in manager's table */
FT_Pointer cache_user; /* passed to cache node methods*/ FT_Pointer cache_user; /* passed to cache node methods */
} FTC_CacheRec; } 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 */ /* 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 ); FT_EXPORT_DEF( void ) FTC_Manager_Compress( FTC_Manager manager );
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -13,45 +13,48 @@
/* this file you indicate that you have read the license and */ /* this file you indicate that you have read the license and */
/* understand and accept it fully. */ /* 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 */
/* */
/***************************************************************************/ /***************************************************************************/
/**************************************************************************/
/**************************************************************************/ /*************************************************************************/
/**************************************************************************/ /* */
/**************************************************************************/ /* 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. */
/********* WARNING, THIS IS ALPHA CODE, THIS API **********/ /* */
/********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE **********/ /* When doing a lookup (either through `Lookup()' or `Lookup_Node()'), */
/********* FREETYPE DEVELOPMENT TEAM **********/ /* 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 #ifndef FTLRU_H
@ -64,11 +67,12 @@
extern "C" { extern "C" {
#endif #endif
/* generic key type */
/* generic key type */
typedef FT_Pointer FT_LruKey; 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_ typedef struct FT_LruNodeRec_
{ {
FT_ListNodeRec root; FT_ListNodeRec root;
@ -76,43 +80,44 @@
} FT_LruNodeRec, *FT_LruNode; } FT_LruNodeRec, *FT_LruNode;
/* forward declaration */ /* forward declaration */
typedef struct FT_LruRec_* FT_Lru; typedef struct FT_LruRec_* FT_Lru;
/* LRU clazz */ /* LRU clazz */
typedef struct FT_Lru_Class_ 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_Error (*init_element)( FT_Lru lru,
FT_LruNode node ); 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, void (*done_element)( FT_Lru lru,
FT_LruNode node ); FT_LruNode node );
/* when defined, this method is called when the list if full */ /* If defined, this method is called when the list if full */
/* during the lookup process.. it is used to change the content */ /* during the lookup process -- it is used to change the contents */
/* of a list element node, instead of calling "done_element" */ /* of a list element node, instead of calling `done_element()', */
/* then "init_element". Put it to 0 for default behaviour */ /* then `init_element'. Set it to 0 for default behaviour. */
FT_Error (*flush_element)( FT_Lru lru, FT_Error (*flush_element)( FT_Lru lru,
FT_LruNode node, FT_LruNode node,
FT_LruKey new_key ); FT_LruKey new_key );
/* when defined, this method is used to compare a list element node */ /* If defined, this method is used to compare a list element node */
/* with a given key during a lookup. When set to 0, the "key" */ /* with a given key during a lookup. If set to 0, the `key' */
/* fields will be directly compared instead.. */ /* fields will be directly compared instead. */
FT_Bool (*compare_element)( FT_LruNode node, FT_Bool (*compare_element)( FT_LruNode node,
FT_LruKey key ); FT_LruKey key );
} FT_Lru_Class; } 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 */ /* A selector is used to indicate whether a given list element node */
/* must returns true (i.e. non 0) to indicate that the node is part */ /* is part of a selection for FT_Lru_Remove_Selection(). The function */
/* of it.. */ /* 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, typedef FT_Bool (*FT_Lru_Selector)( FT_Lru lru,
FT_LruNode node, FT_LruNode node,
FT_Pointer data ); FT_Pointer data );
@ -120,16 +125,16 @@
typedef struct FT_LruRec_ typedef struct FT_LruRec_
{ {
FT_Lru_Class* clazz; FT_Lru_Class* clazz;
FT_UInt max_elements; FT_UInt max_elements;
FT_UInt num_elements; FT_UInt num_elements;
FT_ListRec elements; FT_ListRec elements;
FT_Memory memory; FT_Memory memory;
FT_Pointer user_data; FT_Pointer user_data;
/* the following fields are only meaningful for static lru containers */ /* the following fields are only meaningful for static lru containers */
FT_ListRec free_nodes; FT_ListRec free_nodes;
FT_LruNode nodes; FT_LruNode nodes;
} FT_LruRec; } FT_LruRec;
@ -141,9 +146,9 @@
FT_Bool pre_alloc, FT_Bool pre_alloc,
FT_Lru* alru ); 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_EXPORT_DEF( FT_Error ) FT_Lru_Lookup_Node( FT_Lru lru,
FT_LruKey key, FT_LruKey key,
@ -153,12 +158,12 @@
FT_LruKey key, FT_LruKey key,
FT_Pointer* aobject ); FT_Pointer* aobject );
FT_EXPORT_DEF( void ) FT_Lru_Remove_Node( FT_Lru lru, FT_EXPORT_DEF( void ) FT_Lru_Remove_Node( FT_Lru lru,
FT_LruNode node ); FT_LruNode node );
FT_EXPORT_DEF( void ) FT_Lru_Remove_Selection( FT_Lru lru, FT_EXPORT_DEF( void ) FT_Lru_Remove_Selection( FT_Lru lru,
FT_Lru_Selector selector, FT_Lru_Selector selector,
FT_Pointer data ); FT_Pointer data );
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -16,26 +16,27 @@
/***************************************************************************/ /***************************************************************************/
/**************************************************************************/ /*************************************************************************/
/**************************************************************************/ /*************************************************************************/
/**************************************************************************/ /*************************************************************************/
/**************************************************************************/ /*************************************************************************/
/**************************************************************************/ /*************************************************************************/
/********* **********/ /********* *********/
/********* **********/ /********* WARNING, THIS IS ALPHA CODE, THIS API *********/
/********* WARNING, THIS IS ALPHA CODE, THIS API **********/ /********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE *********/
/********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE **********/ /********* FREETYPE DEVELOPMENT TEAM *********/
/********* FREETYPE DEVELOPMENT TEAM **********/ /********* *********/
/********* **********/ /*************************************************************************/
/**************************************************************************/ /*************************************************************************/
/**************************************************************************/ /*************************************************************************/
/**************************************************************************/ /*************************************************************************/
/**************************************************************************/ /*************************************************************************/
/**************************************************************************/
#ifndef FTCACHE_H #ifndef FTCACHE_H
#define FTCACHE_H #define FTCACHE_H
#include <freetype/ftglyph.h> #include <freetype/ftglyph.h>
@ -91,7 +92,7 @@
/* */ /* */
typedef FT_Error (*FTC_Face_Requester)( FTC_FaceID face_id, typedef FT_Error (*FTC_Face_Requester)( FTC_FaceID face_id,
FT_Library library, FT_Library library,
FT_Pointer request_data, FT_Pointer request_data,
FT_Face* aface ); FT_Face* aface );
@ -102,8 +103,8 @@
/* */ /* */
/* <Description> */ /* <Description> */
/* A simple structure used to describe a given `font' to the cache */ /* A simple structure used to describe a given `font' to the cache */
/* manager. Note that a "font" is the combination of a given face */ /* manager. Note that a `font' is the combination of a given face */
/* with a given character size.. */ /* with a given character size. */
/* */ /* */
/* <Fields> */ /* <Fields> */
/* face_id :: The ID of the face to use. */ /* face_id :: The ID of the face to use. */
@ -117,7 +118,7 @@
FTC_FaceID face_id; FTC_FaceID face_id;
FT_UShort pix_width; FT_UShort pix_width;
FT_UShort pix_height; FT_UShort pix_height;
} FTC_FontRec; } FTC_FontRec;
@ -130,7 +131,7 @@
/* A simple handle to a FTC_FontRec structure. */ /* A simple handle to a FTC_FontRec structure. */
/* */ /* */
typedef FTC_FontRec* FTC_Font; typedef FTC_FontRec* FTC_Font;
/*************************************************************************/ /*************************************************************************/
/*************************************************************************/ /*************************************************************************/
@ -196,7 +197,7 @@
FT_Pointer req_data, FT_Pointer req_data,
FTC_Manager* amanager ); FTC_Manager* amanager );
/*************************************************************************/ /*************************************************************************/
/* */ /* */
/* <Function> */ /* <Function> */
@ -261,7 +262,7 @@
FT_EXPORT_DEF( FT_Error ) FTC_Manager_Lookup_Face( FTC_Manager manager, FT_EXPORT_DEF( FT_Error ) FTC_Manager_Lookup_Face( FTC_Manager manager,
FTC_FaceID face_id, FTC_FaceID face_id,
FT_Face* aface ); FT_Face* aface );
/*************************************************************************/ /*************************************************************************/
/* */ /* */
@ -308,19 +309,18 @@
FT_Size* asize ); FT_Size* asize );
/* a cache class is used to describe a unique cache type to the */ /* a cache class is used to describe a unique cache type to the manager */
/* manager.. */
typedef struct FTC_Cache_Class_ FTC_Cache_Class; typedef struct FTC_Cache_Class_ FTC_Cache_Class;
typedef struct FTC_CacheRec_* FTC_Cache; typedef struct FTC_CacheRec_* FTC_Cache;
/* this must be used internally for the moment */ /* this must be used internally for the moment */
FT_EXPORT_DEF( FT_Error ) FTC_Manager_Register_Cache( FT_EXPORT_DEF( FT_Error ) FTC_Manager_Register_Cache(
FTC_Manager manager, FTC_Manager manager,
FTC_Cache_Class* clazz, FTC_Cache_Class* clazz,
FTC_Cache *acache ); FTC_Cache* acache );
/*************************************************************************/ /*************************************************************************/
/*************************************************************************/ /*************************************************************************/
/*************************************************************************/ /*************************************************************************/
@ -332,6 +332,8 @@
/*************************************************************************/ /*************************************************************************/
#define FTC_IMAGE_FORMAT( x ) ( (x) & 7 )
/*************************************************************************/ /*************************************************************************/
/* */ /* */
/* <Enum> */ /* <Enum> */
@ -353,30 +355,25 @@
/* <Note> */ /* <Note> */
/* Other types may be defined in the future. */ /* Other types may be defined in the future. */
/* */ /* */
#define FTC_IMAGE_FORMAT(x) ((x) & 7)
typedef enum FTC_Image_Type_ typedef enum FTC_Image_Type_
{ {
ftc_image_format_bitmap = 0, ftc_image_format_bitmap = 0,
ftc_image_format_outline = 1, ftc_image_format_outline = 1,
ftc_image_flag_monochrome = 16, ftc_image_flag_monochrome = 16,
ftc_image_flag_unhinted = 32, ftc_image_flag_unhinted = 32,
ftc_image_flag_autohinted = 64, ftc_image_flag_autohinted = 64,
ftc_image_flag_unscaled = 128, ftc_image_flag_unscaled = 128,
ftc_image_flag_no_sbits = 256, ftc_image_flag_no_sbits = 256,
ftc_image_mono = ftc_image_format_bitmap | ftc_image_mono = ftc_image_format_bitmap |
ftc_image_flag_monochrome, /* monochrome bitmap */ ftc_image_flag_monochrome, /* monochrome bitmap */
ftc_image_grays = ftc_image_format_bitmap, /* anti-aliased bitmap */
ftc_image_grays = ftc_image_format_bitmap, /* anti-aliased bitmap */ ftc_image_outline = ftc_image_format_outline /* scaled outline */
ftc_image_outline = ftc_image_format_outline /* scaled outline */
} FTC_Image_Type; } FTC_Image_Type;
/*************************************************************************/ /*************************************************************************/
/* */ /* */
/* <Struct> */ /* <Struct> */
@ -395,7 +392,7 @@
{ {
FTC_FontRec font; FTC_FontRec font;
FT_UInt image_type; FT_UInt image_type;
} FTC_Image_Desc; } FTC_Image_Desc;
@ -409,7 +406,7 @@
/* hold many distinct glyph images, while not exceeding a certain */ /* hold many distinct glyph images, while not exceeding a certain */
/* memory threshold. */ /* 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, FT_EXPORT_DEF( FT_Error ) FTC_Image_Cache_New( FTC_Manager manager,
FTC_Image_Cache* acache ); FTC_Image_Cache* acache );
/*************************************************************************/ /*************************************************************************/
/* */ /* */
@ -462,7 +459,7 @@
/* */ /* */
/* Because the glyph image cache limits the total amount of memory */ /* Because the glyph image cache limits the total amount of memory */
/* taken by the glyphs it holds, the returned glyph might disappear */ /* 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( FT_EXPORT_DEF( FT_Error ) FTC_Image_Cache_Lookup(
FTC_Image_Cache cache, FTC_Image_Cache cache,

View File

@ -16,22 +16,23 @@
/* */ /* */
/***************************************************************************/ /***************************************************************************/
/**************************************************************************/
/**************************************************************************/ /*************************************************************************/
/**************************************************************************/ /*************************************************************************/
/**************************************************************************/ /*************************************************************************/
/**************************************************************************/ /*************************************************************************/
/********* **********/ /*************************************************************************/
/********* **********/ /********* *********/
/********* WARNING, THIS IS ALPHA CODE, THIS API **********/ /********* WARNING, THIS IS ALPHA CODE, THIS API *********/
/********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE **********/ /********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE *********/
/********* FREETYPE DEVELOPMENT TEAM **********/ /********* FREETYPE DEVELOPMENT TEAM *********/
/********* **********/ /********* *********/
/**************************************************************************/ /*************************************************************************/
/**************************************************************************/ /*************************************************************************/
/**************************************************************************/ /*************************************************************************/
/**************************************************************************/ /*************************************************************************/
/**************************************************************************/ /*************************************************************************/
#ifndef FTSYNTH_H #ifndef FTSYNTH_H
#define FTSYNTH_H #define FTSYNTH_H
@ -44,9 +45,9 @@
#endif #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 */ /* 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_EXPORT_DEF( FT_Error ) FT_Embolden_Outline( FT_Face original,
FT_Outline* outline, FT_Outline* outline,
FT_Pos* advance ); FT_Pos* advance );

View File

@ -975,13 +975,13 @@
/* when the flag NO_RECURSE is set, we disable hinting and scaling */ /* when the flag NO_RECURSE is set, we disable hinting and scaling */
if ( load_flags & FT_LOAD_NO_RECURSE ) if ( load_flags & FT_LOAD_NO_RECURSE )
{ {
/* disable scaling, hinting and transform */ /* disable scaling, hinting, and transformation */
load_flags |= FT_LOAD_NO_SCALE | load_flags |= FT_LOAD_NO_SCALE |
FT_LOAD_NO_HINTING | FT_LOAD_NO_HINTING |
FT_LOAD_IGNORE_TRANSFORM; FT_LOAD_IGNORE_TRANSFORM;
/* disable bitmap rendering */ /* disable bitmap rendering */
load_flags &= ~FT_LOAD_RENDER; load_flags &= ~FT_LOAD_RENDER;
} }
/* do we need to load the glyph through the auto-hinter? */ /* do we need to load the glyph through the auto-hinter? */
@ -1032,7 +1032,7 @@
{ {
FT_UInt EM = face->units_per_EM; FT_UInt EM = face->units_per_EM;
FT_Size_Metrics* metrics = &face->size->metrics; FT_Size_Metrics* metrics = &face->size->metrics;
slot->linearHoriAdvance = FT_MulDiv( slot->linearHoriAdvance, slot->linearHoriAdvance = FT_MulDiv( slot->linearHoriAdvance,
(FT_Long)metrics->x_ppem << 16, EM ); (FT_Long)metrics->x_ppem << 16, EM );
@ -1161,7 +1161,7 @@
/* discard auto-hinting data */ /* discard auto-hinting data */
if ( face->autohint.finalizer ) if ( face->autohint.finalizer )
face->autohint.finalizer( face->autohint.data ); face->autohint.finalizer( face->autohint.data );
/* Discard glyph slots for this face */ /* Discard glyph slots for this face */
/* Beware! FT_Done_GlyphSlot() changes the field `face->slot' */ /* Beware! FT_Done_GlyphSlot() changes the field `face->slot' */
while ( face->glyph ) while ( face->glyph )
@ -2344,12 +2344,12 @@
FT_UInt buffer_max ) FT_UInt buffer_max )
{ {
FT_Error error = FT_Err_Invalid_Argument; FT_Error error = FT_Err_Invalid_Argument;
/* clean up buffer */ /* clean up buffer */
if ( buffer && buffer_max > 0 ) if ( buffer && buffer_max > 0 )
((FT_Byte*)buffer)[0] = 0; ((FT_Byte*)buffer)[0] = 0;
if ( face && if ( face &&
glyph_index < (FT_UInt)face->num_glyphs && glyph_index < (FT_UInt)face->num_glyphs &&
FT_HAS_GLYPH_NAMES( face ) ) FT_HAS_GLYPH_NAMES( face ) )
@ -2362,7 +2362,7 @@
if ( clazz->get_interface ) if ( clazz->get_interface )
{ {
FT_Glyph_Name_Requester requester; FT_Glyph_Name_Requester requester;
requester = (FT_Glyph_Name_Requester)clazz->get_interface( requester = (FT_Glyph_Name_Requester)clazz->get_interface(
FT_MODULE( driver ), "glyph_name" ); FT_MODULE( driver ), "glyph_name" );
@ -2372,7 +2372,7 @@
} }
return error; return error;
} }
/*************************************************************************/ /*************************************************************************/

291
src/cache/ftcglyph.c vendored
View File

@ -2,7 +2,7 @@
/* */ /* */
/* ftcglyph.c */ /* ftcglyph.c */
/* */ /* */
/* FreeType Glyph Image (FT_Glyph) cache.. */ /* FreeType Glyph Image (FT_Glyph) cache (body). */
/* */ /* */
/* Copyright 2000 by */ /* Copyright 2000 by */
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */
@ -13,124 +13,134 @@
/* this file you indicate that you have read the license and */ /* this file you indicate that you have read the license and */
/* understand and accept it fully. */ /* 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/cache/ftcglyph.h>
#include <freetype/fterrors.h> #include <freetype/fterrors.h>
#include <freetype/internal/ftobjs.h> #include <freetype/internal/ftobjs.h>
#include <freetype/internal/ftlist.h> #include <freetype/internal/ftlist.h>
#include <freetype/fterrors.h> #include <freetype/fterrors.h>
/*************************************************************************/
/*************************************************************************/
/***** *****/
/***** 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_Glyph_Cache cache = queue->cache;
FTC_CacheNode_Data* data = FTC_CACHENODE_TO_DATA_P( &node->root ); 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; data->cache_index = (FT_UShort)cache->root.cache_index;
node->queue_index = (FT_UShort) queue->queue_index; data->ref_count = (FT_Short) 0;
node->glyph_index = (FT_UShort) gindex; 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! */
FT_EXPORT_FUNC( void ) FTC_GlyphNode_Destroy( FTC_GlyphNode node,
/* Important: this function is called from the cache manager to */ FTC_Glyph_Cache cache )
/* 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_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; FTC_Glyph_Queue queue = (FTC_Glyph_Queue)queue_lru->root.data;
FT_UInt hash = node->glyph_index % queue->hash_size; FT_UInt hash = node->glyph_index % queue->hash_size;
FT_List bucket = queue->buckets + hash; FT_List bucket = queue->buckets + hash;
/* remove node from its queue's bucket list */ /* 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 */ /* destroy the node */
queue->clazz->destroy_node( node, queue ); queue->clazz->destroy_node( node, queue );
} }
/* Important: this function is called from the cache manager to */ /* Important: This function is called from the cache manager to */
/* size a given cache node during "cache compression". The */ /* size a given cache node during `cache compression'. The */
/* second argument is always "cache.user_data". You thus be */ /* second argument is always `cache.user_data'. Thus be */
/* certain that the function FTC_Image_Cache_New does indeed */ /* certain that the function FTC_Image_Cache_New() does indeed */
/* set its "user_data" field correctly, otherwise bad things */ /* set its `user_data' field correctly, otherwise bad things */
/* will happen !! */ /* will happen! */
FT_EXPORT_FUNC(FT_ULong) FTC_GlyphNode_Size( FTC_GlyphNode node, FT_EXPORT_FUNC( FT_ULong ) FTC_GlyphNode_Size( FTC_GlyphNode node,
FTC_Glyph_Cache cache ) 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; FTC_Glyph_Queue queue = (FTC_Glyph_Queue)queue_lru->root.data;
return queue->clazz->size_node( node, queue ); 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_SizeFunc) FTC_GlyphNode_Size,
(FTC_CacheNode_DestroyFunc) FTC_GlyphNode_Destroy (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_Error error;
FT_Memory memory = cache->root.memory; FT_Memory memory = cache->root.memory;
FTC_Manager manager = cache->root.manager; FTC_Manager manager = cache->root.manager;
FTC_Glyph_Queue queue = 0; FTC_Glyph_Queue queue = 0;
FTC_Glyph_Cache_Class* gcache_class; FTC_Glyph_Cache_Class* gcache_class;
FTC_Glyph_Queue_Class* clazz; FTC_Glyph_Queue_Class* clazz;
gcache_class = (FTC_Glyph_Cache_Class*)cache->root.clazz; gcache_class = (FTC_Glyph_Cache_Class*)cache->root.clazz;
clazz = gcache_class->queue_class; clazz = gcache_class->queue_class;
*aqueue = 0; *aqueue = 0;
if ( ALLOC( queue, clazz->queue_byte_size ) ) if ( ALLOC( queue, clazz->queue_byte_size ) )
goto Exit; goto Exit;
queue->cache = cache; queue->cache = cache;
queue->manager = manager; queue->manager = manager;
queue->memory = memory; queue->memory = memory;
@ -139,14 +149,13 @@
/* allocate buckets table */ /* allocate buckets table */
if ( ALLOC_ARRAY( queue->buckets, queue->hash_size, FT_ListRec ) ) if ( ALLOC_ARRAY( queue->buckets, queue->hash_size, FT_ListRec ) )
if (error)
goto Exit; goto Exit;
/* initialize queue by type - if needed */ /* initialize queue by type if needed */
if (clazz->init) if ( clazz->init )
{ {
error = clazz->init( queue, type ); error = clazz->init( queue, type );
if (error) if ( error )
goto Exit; goto Exit;
} }
@ -160,77 +169,79 @@
} }
return error; 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_Glyph_Cache cache = queue->cache;
FTC_Manager manager = cache->root.manager; FTC_Manager manager = cache->root.manager;
FT_List glyphs_lru = &manager->global_lru; FT_List glyphs_lru = &manager->global_lru;
FT_List bucket = queue->buckets; FT_List bucket = queue->buckets;
FT_List bucket_limit = bucket + queue->hash_size; FT_List bucket_limit = bucket + queue->hash_size;
FT_Memory memory = cache->root.memory; FT_Memory memory = cache->root.memory;
FTC_Glyph_Queue_Class* clazz = queue->clazz; 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++ ) for ( ; bucket < bucket_limit; bucket++ )
{ {
FT_ListNode node = bucket->head; FT_ListNode node = bucket->head;
FT_ListNode next = 0; FT_ListNode next = 0;
FT_ListNode lrunode; FT_ListNode lrunode;
FTC_GlyphNode inode; FTC_GlyphNode inode;
for ( ; node; node = next ) for ( ; node; node = next )
{ {
next = node->next; next = node->next;
inode = FTC_LISTNODE_TO_GLYPHNODE(node); inode = FTC_LISTNODE_TO_GLYPHNODE( node );
lrunode = FTC_GLYPHNODE_TO_LRUNODE( inode ); lrunode = FTC_GLYPHNODE_TO_LRUNODE( inode );
manager->num_bytes -= clazz->size_node( inode, queue ); manager->num_bytes -= clazz->size_node( inode, queue );
FT_List_Remove( glyphs_lru, lrunode ); FT_List_Remove( glyphs_lru, lrunode );
clazz->destroy_node( inode, queue ); clazz->destroy_node( inode, queue );
} }
bucket->head = bucket->tail = 0; bucket->head = bucket->tail = 0;
} }
if (clazz->done) if ( clazz->done )
clazz->done(queue); clazz->done( queue );
FREE( queue->buckets ); FREE( queue->buckets );
FREE( queue ); FREE( queue );
} }
FT_EXPORT_FUNC(FT_Error) FTC_Glyph_Queue_Lookup_Node( FT_EXPORT_FUNC( FT_Error ) FTC_Glyph_Queue_Lookup_Node(
FTC_Glyph_Queue queue, FTC_Glyph_Queue queue,
FT_UInt glyph_index, FT_UInt glyph_index,
FTC_GlyphNode* anode ) FTC_GlyphNode* anode )
{ {
FTC_Glyph_Cache cache = queue->cache; FTC_Glyph_Cache cache = queue->cache;
FTC_Manager manager = cache->root.manager; FTC_Manager manager = cache->root.manager;
FT_UInt hash_index = glyph_index % queue->hash_size; FT_UInt hash_index = glyph_index % queue->hash_size;
FT_List bucket = queue->buckets + hash_index; FT_List bucket = queue->buckets + hash_index;
FT_ListNode node; FT_ListNode node;
FT_Error error; FT_Error error;
FTC_GlyphNode inode; FTC_GlyphNode inode;
FTC_Glyph_Queue_Class* clazz = queue->clazz; FTC_Glyph_Queue_Class* clazz = queue->clazz;
*anode = 0; *anode = 0;
for ( node = bucket->head; node; node = node->next ) for ( node = bucket->head; node; node = node->next )
{ {
FT_UInt gindex; FT_UInt gindex;
inode = FTC_LISTNODE_TO_GLYPHNODE(node);
inode = FTC_LISTNODE_TO_GLYPHNODE( node );
gindex = inode->glyph_index; gindex = inode->glyph_index;
if ( gindex == glyph_index ) if ( gindex == glyph_index )
{ {
/* we found it! -- move glyph to start of the lists */ /* we found it! -- move glyph to start of the lists */
@ -247,23 +258,23 @@
goto Exit; goto Exit;
/* insert the node at the start of our bucket list */ /* 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 */ /* 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 ); manager->num_bytes += clazz->size_node( inode, queue );
if (manager->num_bytes > manager->max_bytes) if (manager->num_bytes > manager->max_bytes)
FTC_Manager_Compress( manager ); FTC_Manager_Compress( manager );
*anode = inode; *anode = inode;
Exit: Exit:
return error; return error;
} }
/*************************************************************************/ /*************************************************************************/
/*************************************************************************/ /*************************************************************************/
/***** *****/ /***** *****/
@ -271,14 +282,14 @@
/***** *****/ /***** *****/
/*************************************************************************/ /*************************************************************************/
/*************************************************************************/ /*************************************************************************/
#define FTC_QUEUE_LRU_GET_CACHE( lru ) \ #define FTC_QUEUE_LRU_GET_CACHE( lru ) \
( (FTC_Glyph_Cache)(lru)->user_data ) ( (FTC_Glyph_Cache)(lru)->user_data )
#define FTC_QUEUE_LRU_GET_MANAGER( lru ) \ #define FTC_QUEUE_LRU_GET_MANAGER( lru ) \
FTC_QUEUE_LRU_GET_CACHE( lru )->manager FTC_QUEUE_LRU_GET_CACHE( lru )->manager
#define FTC_LRUNODE_QUEUE( node ) \ #define FTC_LRUNODE_QUEUE( node ) \
( (FTC_Glyph_Queue)(node)->root.data ) ( (FTC_Glyph_Queue)(node)->root.data )
@ -291,6 +302,7 @@
FT_Error error; FT_Error error;
FTC_Glyph_Queue queue; FTC_Glyph_Queue queue;
error = FTC_Glyph_Queue_New( cache, error = FTC_Glyph_Queue_New( cache,
(FT_Pointer)node->key, (FT_Pointer)node->key,
&queue ); &queue );
@ -300,18 +312,17 @@
queue->queue_index = node - lru->nodes; queue->queue_index = node - lru->nodes;
node->root.data = queue; node->root.data = queue;
} }
return error; return error;
} }
LOCAL_FUNC_X LOCAL_FUNC_X
void ftc_glyph_queue_lru_done( FT_Lru lru, void ftc_glyph_queue_lru_done( FT_Lru lru,
FT_LruNode node ) FT_LruNode node )
{ {
FTC_Glyph_Queue queue = FTC_LRUNODE_QUEUE( node ); FTC_Glyph_Queue queue = FTC_LRUNODE_QUEUE( node );
FT_UNUSED( lru ); FT_UNUSED( lru );
@ -319,16 +330,16 @@
} }
LOCAL_FUNC_X LOCAL_FUNC_X
FT_Bool ftc_glyph_queue_lru_compare( FT_LruNode node, FT_Bool ftc_glyph_queue_lru_compare( FT_LruNode node,
FT_LruKey key ) FT_LruKey key )
{ {
FTC_Glyph_Queue queue = FTC_LRUNODE_QUEUE( node ); 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 = 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_Memory memory = cache->root.memory;
FT_Error error; FT_Error error;
/* set up root node_class to be used by manager */ /* set up root node_class to be used by manager */
cache->root.node_clazz = (FTC_CacheNode_Class*)&ftc_glyph_cache_node_class; 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 */ /* The following is extremely important for ftc_destroy_glyph_image() */
/* through the cache manager is "user_data" and must be set to */ /* to work properly, as the second parameter that is sent to it */
/* "cache" here.. */ /* through the cache manager is `user_data' and must be set to */
/* */ /* `cache' here. */
/* */
cache->root.cache_user = cache; cache->root.cache_user = cache;
error = FT_Lru_New( &ftc_glyph_queue_lru_class, 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 ); FT_Lru_Done( cache->queues_lru );
} }
/* END */ /* END */

222
src/cache/ftcimage.c vendored
View File

@ -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 #ifdef FT_FLAT_COMPILE
# include "ftcimage.h" # include "ftcimage.h"
#else #else
# include <cache/ftcimage.h> # include <cache/ftcimage.h>
#endif #endif
/*************************************************************************/ #include <string.h>
/*************************************************************************/
/***** *****/
/***** GLYPH IMAGE NODES *****/ /*************************************************************************/
/***** *****/ /*************************************************************************/
/*************************************************************************/ /***** *****/
/*************************************************************************/ /***** GLYPH IMAGE NODES *****/
/***** *****/
/*************************************************************************/
/*************************************************************************/
/* this is a simple glyph image destructor, which is called exclusively */ /* this is a simple glyph image destructor, which is called exclusively */
/* from the CacheQueue object */ /* from the CacheQueue object */
LOCAL_FUNC_X LOCAL_FUNC_X
@ -19,7 +41,8 @@
FTC_Glyph_Queue queue ) FTC_Glyph_Queue queue )
{ {
FT_Memory memory = queue->memory; FT_Memory memory = queue->memory;
FT_Done_Glyph( FTC_GLYPHNODE_GET_GLYPH( node ) ); FT_Done_Glyph( FTC_GLYPHNODE_GET_GLYPH( node ) );
FREE( node ); FREE( node );
} }
@ -28,8 +51,8 @@
LOCAL_FUNC_X LOCAL_FUNC_X
FT_Error ftc_glyph_image_node_new( FTC_Glyph_Queue queue, FT_Error ftc_glyph_image_node_new( FTC_Glyph_Queue queue,
FT_UInt glyph_index, FT_UInt glyph_index,
FTC_GlyphNode *anode ) FTC_GlyphNode* anode )
{ {
FT_Memory memory = queue->memory; FT_Memory memory = queue->memory;
FTC_Image_Queue imageq = (FTC_Image_Queue)queue; FTC_Image_Queue imageq = (FTC_Image_Queue)queue;
FT_Error error; FT_Error error;
@ -37,8 +60,9 @@
FT_Face face; FT_Face face;
FT_Size size; FT_Size size;
/* allocate node */ /* allocate node */
if ( ALLOC( node, sizeof(*node) ) ) if ( ALLOC( node, sizeof ( *node ) ) )
goto Exit; goto Exit;
/* init its inner fields */ /* init its inner fields */
@ -53,13 +77,14 @@
FT_UInt glyph_index = node->glyph_index; FT_UInt glyph_index = node->glyph_index;
FT_UInt load_flags = FT_LOAD_DEFAULT; FT_UInt load_flags = FT_LOAD_DEFAULT;
FT_UInt image_type = imageq->description.image_type; FT_UInt image_type = imageq->description.image_type;
if ( FTC_IMAGE_FORMAT( image_type ) == ftc_image_format_bitmap ) 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 ) if ( image_type & ftc_image_flag_monochrome )
load_flags |= FT_LOAD_MONOCHROME; load_flags |= FT_LOAD_MONOCHROME;
/* disable embedded bitmaps loading if necessary */ /* disable embedded bitmaps loading if necessary */
if ( image_type & ftc_image_flag_no_sbits ) if ( image_type & ftc_image_flag_no_sbits )
load_flags |= FT_LOAD_NO_BITMAP; load_flags |= FT_LOAD_NO_BITMAP;
@ -68,14 +93,14 @@
{ {
/* disable embedded bitmaps loading */ /* disable embedded bitmaps loading */
load_flags |= FT_LOAD_NO_BITMAP; load_flags |= FT_LOAD_NO_BITMAP;
if ( image_type & ftc_image_flag_unscaled ) if ( image_type & ftc_image_flag_unscaled )
load_flags |= FT_LOAD_NO_SCALE; load_flags |= FT_LOAD_NO_SCALE;
} }
if ( image_type & ftc_image_flag_unhinted ) if ( image_type & ftc_image_flag_unhinted )
load_flags |= FT_LOAD_NO_HINTING; load_flags |= FT_LOAD_NO_HINTING;
if ( image_type & ftc_image_flag_autohinted ) if ( image_type & ftc_image_flag_autohinted )
load_flags |= FT_LOAD_FORCE_AUTOHINT; load_flags |= FT_LOAD_FORCE_AUTOHINT;
@ -84,11 +109,11 @@
{ {
if ( face->glyph->format == ft_glyph_format_bitmap || if ( face->glyph->format == ft_glyph_format_bitmap ||
face->glyph->format == ft_glyph_format_outline ) face->glyph->format == ft_glyph_format_outline )
{ {
/* ok, copy it */ /* ok, copy it */
FT_Glyph glyph; FT_Glyph glyph;
error = FT_Get_Glyph( face->glyph, &glyph ); error = FT_Get_Glyph( face->glyph, &glyph );
if ( !error ) if ( !error )
FTC_GLYPHNODE_SET_GLYPH( node, glyph ); FTC_GLYPHNODE_SET_GLYPH( node, glyph );
@ -97,64 +122,68 @@
error = FT_Err_Invalid_Argument; error = FT_Err_Invalid_Argument;
} }
} }
Exit: Exit:
if (error && node) if ( error && node )
FREE(node); FREE( node );
*anode = node; *anode = node;
return error; return error;
} }
/* 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 */ /* a FTC_Glyph_Queue_Class and a FTC_CacheNode_Class */
/* */ /* */
LOCAL_FUNC_X 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_ULong size = 0;
FT_Glyph glyph = FTC_GLYPHNODE_GET_GLYPH(node); FT_Glyph glyph = FTC_GLYPHNODE_GET_GLYPH( node );
switch (glyph->format)
switch ( glyph->format )
{ {
case ft_glyph_format_bitmap: case ft_glyph_format_bitmap:
{ {
FT_BitmapGlyph bitg; FT_BitmapGlyph bitg;
bitg = (FT_BitmapGlyph)glyph;
size = bitg->bitmap.rows * labs(bitg->bitmap.pitch) + bitg = (FT_BitmapGlyph)glyph;
sizeof(*bitg); size = bitg->bitmap.rows * labs( bitg->bitmap.pitch ) +
} sizeof ( *bitg );
break; }
break;
case ft_glyph_format_outline:
{ case ft_glyph_format_outline:
FT_OutlineGlyph outg; {
FT_OutlineGlyph outg;
outg = (FT_OutlineGlyph)glyph;
size = outg->outline.n_points *
( sizeof( FT_Vector ) + sizeof( FT_Byte ) ) + outg = (FT_OutlineGlyph)glyph;
outg->outline.n_contours * size = outg->outline.n_points *
sizeof( FT_Short ) + ( sizeof( FT_Vector ) + sizeof ( FT_Byte ) ) +
sizeof(*outg); outg->outline.n_contours * sizeof ( FT_Short ) +
} sizeof ( *outg );
break; }
break;
default:
; default:
;
} }
size += sizeof(*node);
size += sizeof ( *node );
return size; return size;
} }
/*************************************************************************/ /*************************************************************************/
/*************************************************************************/ /*************************************************************************/
/***** *****/ /***** *****/
/***** GLYPH IMAGE QUEUES *****/ /***** GLYPH IMAGE QUEUES *****/
/***** *****/ /***** *****/
/*************************************************************************/ /*************************************************************************/
/*************************************************************************/ /*************************************************************************/
LOCAL_FUNC_X LOCAL_FUNC_X
@ -167,45 +196,44 @@
LOCAL_FUNC_X LOCAL_FUNC_X
FT_Bool ftc_image_queue_compare( FTC_Image_Queue queue, FT_Bool ftc_image_queue_compare( FTC_Image_Queue queue,
FTC_Image_Desc* type ) 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 ), sizeof( FTC_Image_QueueRec ),
(FTC_Glyph_Queue_InitFunc) ftc_image_queue_init, (FTC_Glyph_Queue_InitFunc) ftc_image_queue_init,
(FTC_Glyph_Queue_DoneFunc) 0, (FTC_Glyph_Queue_DoneFunc) 0,
(FTC_Glyph_Queue_CompareFunc) ftc_image_queue_compare, (FTC_Glyph_Queue_CompareFunc) ftc_image_queue_compare,
(FTC_Glyph_Queue_NewNodeFunc) ftc_glyph_image_node_new, (FTC_Glyph_Queue_NewNodeFunc) ftc_glyph_image_node_new,
(FTC_Glyph_Queue_SizeNodeFunc) ftc_glyph_image_node_size, (FTC_Glyph_Queue_SizeNodeFunc) ftc_glyph_image_node_size,
(FTC_Glyph_Queue_DestroyNodeFunc) ftc_glyph_image_node_destroy (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 ), sizeof( FTC_Glyph_CacheRec ),
(FTC_Cache_InitFunc) FTC_Glyph_Cache_Init, (FTC_Cache_InitFunc)FTC_Glyph_Cache_Init,
(FTC_Cache_DoneFunc) FTC_Glyph_Cache_Done (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_Class*)&ftc_glyph_image_cache_class,
(FTC_Cache*)acache ); (FTC_Cache*)acache );
} }
FT_EXPORT_DEF( FT_Error ) FTC_Image_Cache_Lookup( FT_EXPORT_DEF( FT_Error ) FTC_Image_Cache_Lookup(
FTC_Image_Cache cache, FTC_Image_Cache cache,
@ -232,15 +260,16 @@
FTC_Image_Queue img_queue; FTC_Image_Queue img_queue;
/* check for valid `desc' delayed to FT_Lru_Lookup() */ /* check for valid `desc' delayed to FT_Lru_Lookup() */
if ( !cache || !aglyph ) if ( !cache || !aglyph )
return FT_Err_Invalid_Argument; return FT_Err_Invalid_Argument;
*aglyph = 0; *aglyph = 0;
queue = cache->root.last_queue; queue = cache->root.last_queue;
img_queue = (FTC_Image_Queue)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, error = FT_Lru_Lookup( cache->root.queues_lru,
(FT_LruKey)desc, (FT_LruKey)desc,
@ -256,11 +285,11 @@
/* now compress the manager's cache pool if needed */ /* now compress the manager's cache pool if needed */
manager = cache->root.root.manager; 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_Manager_Compress( manager );
FTC_GlyphNode_Unref(inode); FTC_GlyphNode_Unref( inode );
} }
*aglyph = FTC_GLYPHNODE_GET_GLYPH( inode ); *aglyph = FTC_GLYPHNODE_GET_GLYPH( inode );
@ -270,3 +299,4 @@
} }
/* END */

40
src/cache/ftcimage.h vendored
View File

@ -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 #ifndef FTCIMAGE_H
#define FTCIMAGE_H #define FTCIMAGE_H
#include <freetype/cache/ftcglyph.h> #include <freetype/cache/ftcglyph.h>
/* 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_Glyph_QueueRec root;
FTC_Image_Desc description; FTC_Image_Desc description;
} FTC_Image_QueueRec, *FTC_Image_Queue; } FTC_Image_QueueRec, *FTC_Image_Queue;
typedef struct FTC_Image_CacheRec_
typedef struct FTC_Image_CacheRec_
{ {
FTC_Glyph_CacheRec root; FTC_Glyph_CacheRec root;
} FTC_Image_CacheRec; } FTC_Image_CacheRec;
#ifdef __cplusplus
}
#endif
#endif /* FTCIMAGE_H */ #endif /* FTCIMAGE_H */
/* END */

155
src/cache/ftcmanag.c vendored
View File

@ -21,8 +21,9 @@
#include <freetype/internal/ftdebug.h> #include <freetype/internal/ftdebug.h>
#include <freetype/ftlist.h> #include <freetype/ftlist.h>
#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 #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_Error ftc_manager_init_face( FT_Lru lru,
FT_LruNode node ) FT_LruNode node )
{ {
FTC_Manager manager = FTC_LRU_GET_MANAGER( lru ); FTC_Manager manager = FTC_LRU_GET_MANAGER( lru );
FT_Error error; FT_Error error;
FT_Face face; FT_Face face;
error = manager->request_face( (FTC_FaceID)node->key, error = manager->request_face( (FTC_FaceID)node->key,
manager->library, manager->library,
@ -60,7 +61,7 @@
} }
/* helper function for ftc_manager_done_face */ /* helper function for ftc_manager_done_face() */
LOCAL_FUNC_X LOCAL_FUNC_X
FT_Bool ftc_manager_size_selector( FT_Lru lru, FT_Bool ftc_manager_size_selector( FT_Lru lru,
FT_LruNode node, FT_LruNode node,
@ -78,7 +79,7 @@
{ {
FTC_Manager manager = FTC_LRU_GET_MANAGER( lru ); FTC_Manager manager = FTC_LRU_GET_MANAGER( lru );
FT_Face face = (FT_Face)node->root.data; FT_Face face = (FT_Face)node->root.data;
/* we must begin by removing all sizes for the target face */ /* we must begin by removing all sizes for the target face */
/* from the manager's list */ /* from the manager's list */
@ -86,7 +87,7 @@
ftc_manager_size_selector, ftc_manager_size_selector,
face ); face );
/* all right, we can discard the face now */ /* all right, we can discard the face now */
FT_Done_Face( face ); FT_Done_Face( face );
node->root.data = 0; node->root.data = 0;
} }
@ -97,7 +98,7 @@
FT_Face face; FT_Face face;
FT_UShort width; FT_UShort width;
FT_UShort height; FT_UShort height;
} FTC_FontRequest; } FTC_FontRequest;
@ -109,10 +110,10 @@
FT_Size size; FT_Size size;
FT_Error error; FT_Error error;
FT_Face face = font_req->face; FT_Face face = font_req->face;
FT_UNUSED( lru ); FT_UNUSED( lru );
node->root.data = 0; node->root.data = 0;
error = FT_New_Size( face, &size ); error = FT_New_Size( face, &size );
if ( !error ) if ( !error )
@ -126,7 +127,7 @@
else else
node->root.data = size; node->root.data = size;
} }
return error; return error;
} }
@ -137,7 +138,7 @@
FT_UNUSED( lru ); FT_UNUSED( lru );
FT_Done_Size( (FT_Size)node->root.data ); FT_Done_Size( (FT_Size)node->root.data );
} }
LOCAL_FUNC_X LOCAL_FUNC_X
@ -148,7 +149,7 @@
FTC_FontRequest* req = (FTC_FontRequest*)key; FTC_FontRequest* req = (FTC_FontRequest*)key;
FT_Size size = (FT_Size)node->root.data; FT_Size size = (FT_Size)node->root.data;
FT_Error error; FT_Error error;
if ( size->face == req->face ) if ( size->face == req->face )
{ {
@ -173,7 +174,7 @@
{ {
FTC_FontRequest* req = (FTC_FontRequest*)key; FTC_FontRequest* req = (FTC_FontRequest*)key;
FT_Size size = (FT_Size)node->root.data; FT_Size size = (FT_Size)node->root.data;
FT_UNUSED( node ); FT_UNUSED( node );
@ -182,7 +183,7 @@
size->metrics.y_ppem == req->height ); size->metrics.y_ppem == req->height );
} }
FT_CPLUSPLUS( const FT_Lru_Class ) ftc_face_lru_class = FT_CPLUSPLUS( const FT_Lru_Class ) ftc_face_lru_class =
{ {
sizeof ( FT_LruRec ), sizeof ( FT_LruRec ),
@ -192,7 +193,7 @@
0 0
}; };
FT_CPLUSPLUS( const FT_Lru_Class ) ftc_size_lru_class = FT_CPLUSPLUS( const FT_Lru_Class ) ftc_size_lru_class =
{ {
sizeof ( FT_LruRec ), sizeof ( FT_LruRec ),
@ -214,8 +215,8 @@
FT_Error error; FT_Error error;
FT_Memory memory; FT_Memory memory;
FTC_Manager manager = 0; FTC_Manager manager = 0;
if ( !library ) if ( !library )
return FT_Err_Invalid_Library_Handle; return FT_Err_Invalid_Library_Handle;
@ -223,16 +224,16 @@
if ( ALLOC( manager, sizeof ( *manager ) ) ) if ( ALLOC( manager, sizeof ( *manager ) ) )
goto Exit; goto Exit;
if ( max_faces == 0 ) if ( max_faces == 0 )
max_faces = FTC_MAX_FACES_DEFAULT; max_faces = FTC_MAX_FACES_DEFAULT;
if ( max_sizes == 0 ) if ( max_sizes == 0 )
max_sizes = FTC_MAX_SIZES_DEFAULT; max_sizes = FTC_MAX_SIZES_DEFAULT;
if ( max_bytes == 0 ) if ( max_bytes == 0 )
max_bytes = FTC_MAX_BYTES_DEFAULT; max_bytes = FTC_MAX_BYTES_DEFAULT;
error = FT_Lru_New( &ftc_face_lru_class, error = FT_Lru_New( &ftc_face_lru_class,
max_faces, max_faces,
manager, manager,
@ -241,22 +242,22 @@
(FT_Lru*)&manager->faces_lru ); (FT_Lru*)&manager->faces_lru );
if ( error ) if ( error )
goto Exit; goto Exit;
error = FT_Lru_New( &ftc_size_lru_class, error = FT_Lru_New( &ftc_size_lru_class,
max_sizes, max_sizes,
manager, manager,
memory, memory,
1, /* pre_alloc = TRUE */ 1, /* pre_alloc = TRUE */
(FT_Lru*)&manager->sizes_lru ); (FT_Lru*)&manager->sizes_lru );
if ( error ) if ( error )
goto Exit; goto Exit;
manager->library = library; manager->library = library;
manager->max_bytes = max_bytes; manager->max_bytes = max_bytes;
manager->request_face = requester; manager->request_face = requester;
manager->request_data = req_data; manager->request_data = req_data;
*amanager = manager; *amanager = manager;
Exit: Exit:
if ( error && manager ) if ( error && manager )
{ {
@ -264,16 +265,16 @@
FT_Lru_Done( manager->faces_lru ); FT_Lru_Done( manager->faces_lru );
FREE( manager ); FREE( manager );
} }
return error; return error;
} }
FT_EXPORT_DEF( void ) FTC_Manager_Done( FTC_Manager manager ) FT_EXPORT_DEF( void ) FTC_Manager_Done( FTC_Manager manager )
{ {
FT_Memory memory; FT_Memory memory;
FT_UInt index; FT_UInt index;
if ( !manager || !manager->library ) if ( !manager || !manager->library )
return; return;
@ -284,20 +285,20 @@
for (index = 0; index < FTC_MAX_CACHES; index++ ) for (index = 0; index < FTC_MAX_CACHES; index++ )
{ {
FTC_Cache cache = manager->caches[index]; FTC_Cache cache = manager->caches[index];
if (cache) if ( cache )
{ {
cache->clazz->done_cache( cache ); cache->clazz->done_cache( cache );
FREE(cache); FREE( cache );
manager->caches[index] = 0; manager->caches[index] = 0;
} }
} }
/* discard faces and sizes */ /* discard faces and sizes */
FT_Lru_Done( manager->sizes_lru ); FT_Lru_Done( manager->sizes_lru );
FT_Lru_Done( manager->faces_lru ); FT_Lru_Done( manager->faces_lru );
FREE( manager ); FREE( manager );
} }
@ -320,7 +321,7 @@
return FT_Err_Invalid_Cache_Handle; return FT_Err_Invalid_Cache_Handle;
return FT_Lru_Lookup( manager->faces_lru, return FT_Lru_Lookup( manager->faces_lru,
(FT_LruKey)face_id, (FT_LruKey)face_id,
(FT_Pointer*)aface ); (FT_Pointer*)aface );
} }
@ -332,34 +333,34 @@
{ {
FTC_FontRequest req; FTC_FontRequest req;
FT_Error error; FT_Error error;
/* check for valid `manager' delayed to FTC_Manager_Lookup_Face() */ /* check for valid `manager' delayed to FTC_Manager_Lookup_Face() */
if ( aface ) if ( aface )
*aface = 0; *aface = 0;
if ( asize ) if ( asize )
*asize = 0; *asize = 0;
error = FTC_Manager_Lookup_Face( manager, font->face_id, aface ); error = FTC_Manager_Lookup_Face( manager, font->face_id, aface );
if ( !error ) if ( !error )
{ {
FT_Size size; FT_Size size;
req.face = *aface; req.face = *aface;
req.width = font->pix_width; req.width = font->pix_width;
req.height = font->pix_height; req.height = font->pix_height;
error = FT_Lru_Lookup( manager->sizes_lru, error = FT_Lru_Lookup( manager->sizes_lru,
(FT_LruKey)&req, (FT_LruKey)&req,
(FT_Pointer*)&size ); (FT_Pointer*)&size );
if ( !error ) if ( !error )
{ {
/* select the size as the current one for this face */ /* select the size as the current one for this face */
face->size = size; (*aface)->size = size;
if ( asize ) if ( asize )
*asize = size; *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 */ /* 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_EXPORT_FUNC( void ) FTC_Manager_Compress( FTC_Manager manager )
{ {
FT_ListNode node; FT_ListNode node;
node = manager->global_lru.tail; 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 cache_node = FTC_LIST_TO_CACHENODE( node );
FTC_CacheNode_Data* data = FTC_CACHENODE_TO_DATA_P(cache_node); FTC_CacheNode_Data* data = FTC_CACHENODE_TO_DATA_P( cache_node );
FTC_Cache cache; FTC_Cache cache;
FT_ListNode prev = node->prev; 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 ); FT_List_Remove( &manager->global_lru, node );
/* finalize cache node */ /* finalize cache node */
cache = manager->caches[data->cache_index]; cache = manager->caches[data->cache_index];
if (cache) if ( cache )
{ {
FTC_CacheNode_Class* clazz = cache->node_clazz; FTC_CacheNode_Class* clazz = cache->node_clazz;
manager->num_bytes -= clazz->size_node( cache_node, manager->num_bytes -= clazz->size_node( cache_node,
cache->cache_user ); cache->cache_user );
clazz->destroy_node( cache_node, cache->cache_user ); clazz->destroy_node( cache_node, cache->cache_user );
} }
else else
{ {
/* this should never happen !! */ /* this should never happen! */
FT_ERROR(( "FTC_Manager_Compress: Cache Manager is corrupted !!\n" )); FT_ERROR(( "FTC_Manager_Compress: Cache Manager is corrupted!\n" ));
} }
} }
node = prev; node = prev;
@ -412,19 +416,20 @@
FT_EXPORT_DEF( FT_Error ) FTC_Manager_Register_Cache( FT_EXPORT_DEF( FT_Error ) FTC_Manager_Register_Cache(
FTC_Manager manager, FTC_Manager manager,
FTC_Cache_Class* clazz, FTC_Cache_Class* clazz,
FTC_Cache *acache ) FTC_Cache* acache )
{ {
FT_Error error = FT_Err_Invalid_Argument; FT_Error error = FT_Err_Invalid_Argument;
if ( manager && clazz && acache ) if ( manager && clazz && acache )
{ {
FT_Memory memory = manager->library->memory; FT_Memory memory = manager->library->memory;
FTC_Cache cache; FTC_Cache cache;
FT_UInt index = 0; FT_UInt index = 0;
/* by default, return 0 */ /* by default, return 0 */
*acache = 0; *acache = 0;
@ -434,33 +439,35 @@
if ( manager->caches[index] == 0 ) if ( manager->caches[index] == 0 )
break; break;
} }
/* return an error if there are too many registered caches */ /* 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; error = FT_Err_Too_Many_Caches;
FT_ERROR(( "FTC_Manager_Register_Cache:" )); FT_ERROR(( "FTC_Manager_Register_Cache:" ));
FT_ERROR(( " too many registered caches..\n" )); FT_ERROR(( " too many registered caches\n" ));
goto Exit; goto Exit;
} }
if ( !ALLOC( cache, clazz->cache_byte_size ) ) if ( !ALLOC( cache, clazz->cache_byte_size ) )
{ {
cache->manager = manager; cache->manager = manager;
cache->memory = memory; cache->memory = memory;
cache->clazz = clazz; cache->clazz = clazz;
if (clazz->init_cache) if ( clazz->init_cache )
error = clazz->init_cache( cache ); error = clazz->init_cache( cache );
if (error) if ( error )
FREE(cache); FREE( cache );
else else
manager->caches[index] = *acache = cache; manager->caches[index] = *acache = cache;
} }
} }
Exit: Exit:
return error; return error;
} }
/* END */ /* END */