2001-12-20 18:49:10 +01:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* ftccache.c */
|
|
|
|
/* */
|
|
|
|
/* The FreeType internal cache interface (body). */
|
|
|
|
/* */
|
2003-04-23 08:32:41 +02:00
|
|
|
/* Copyright 2000-2001, 2002, 2003 by */
|
2001-12-20 18:49:10 +01:00
|
|
|
/* 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. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
|
2001-12-06 17:45:26 +01:00
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_CACHE_MANAGER_H
|
|
|
|
#include FT_INTERNAL_OBJECTS_H
|
|
|
|
#include FT_INTERNAL_DEBUG_H
|
|
|
|
|
|
|
|
#include "ftcerror.h"
|
|
|
|
|
2002-06-07 22:07:44 +02:00
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
#define FTC_HASH_MAX_LOAD 2
|
|
|
|
#define FTC_HASH_MIN_LOAD 1
|
|
|
|
#define FTC_HASH_SUB_LOAD ( FTC_HASH_MAX_LOAD - FTC_HASH_MIN_LOAD )
|
2002-06-07 22:07:44 +02:00
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
/* this one _must_ be a power of 2! */
|
|
|
|
#define FTC_HASH_INITIAL_SIZE 8
|
2002-06-07 22:07:44 +02:00
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
|
2001-12-06 17:45:26 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** CACHE NODE DEFINITIONS *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
FT_EXPORT_DEF( void )
|
2001-12-06 17:45:26 +01:00
|
|
|
ftc_node_done( FTC_Node node,
|
|
|
|
FTC_Cache cache )
|
|
|
|
{
|
|
|
|
FTC_Family family;
|
|
|
|
FTC_FamilyEntry entry;
|
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
|
2001-12-06 17:45:26 +01:00
|
|
|
entry = cache->manager->families.entries + node->fam_index;
|
|
|
|
family = entry->family;
|
|
|
|
|
|
|
|
/* remove from parent set table - eventually destroy the set */
|
2002-01-25 17:05:39 +01:00
|
|
|
if ( --family->num_nodes == 0 )
|
2001-12-06 17:45:26 +01:00
|
|
|
FT_LruList_Remove( cache->families, (FT_LruNode) family );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
/* add a new node to the head of the manager's circular MRU list */
|
2001-12-06 17:45:26 +01:00
|
|
|
static void
|
|
|
|
ftc_node_mru_link( FTC_Node node,
|
|
|
|
FTC_Manager manager )
|
|
|
|
{
|
|
|
|
FTC_Node first = manager->nodes_list;
|
|
|
|
|
|
|
|
|
|
|
|
if ( first )
|
|
|
|
{
|
2002-06-07 22:07:44 +02:00
|
|
|
FTC_Node last = first->mru_prev;
|
2002-06-08 03:05:56 +02:00
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
|
2002-06-08 03:05:56 +02:00
|
|
|
FT_ASSERT( last->mru_next == first );
|
|
|
|
|
2002-06-07 22:07:44 +02:00
|
|
|
node->mru_prev = last;
|
2001-12-06 17:45:26 +01:00
|
|
|
node->mru_next = first;
|
|
|
|
|
2002-06-07 22:07:44 +02:00
|
|
|
last->mru_next = node;
|
|
|
|
first->mru_prev = node;
|
2001-12-06 17:45:26 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-06-08 00:09:20 +02:00
|
|
|
FT_ASSERT( manager->num_nodes == 0 );
|
|
|
|
|
2001-12-06 17:45:26 +01:00
|
|
|
node->mru_next = node;
|
|
|
|
node->mru_prev = node;
|
|
|
|
}
|
|
|
|
|
|
|
|
manager->nodes_list = node;
|
|
|
|
manager->num_nodes++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* remove a node from the manager's MRU list */
|
|
|
|
static void
|
|
|
|
ftc_node_mru_unlink( FTC_Node node,
|
|
|
|
FTC_Manager manager )
|
|
|
|
{
|
2002-06-08 00:09:20 +02:00
|
|
|
FTC_Node first = manager->nodes_list;
|
2001-12-06 17:45:26 +01:00
|
|
|
FTC_Node prev = node->mru_prev;
|
|
|
|
FTC_Node next = node->mru_next;
|
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
|
2002-06-08 00:09:20 +02:00
|
|
|
FT_ASSERT( first != NULL && manager->num_nodes > 0 );
|
|
|
|
FT_ASSERT( next->mru_prev == node );
|
|
|
|
FT_ASSERT( prev->mru_next == node );
|
2001-12-06 17:45:26 +01:00
|
|
|
|
|
|
|
next->mru_prev = prev;
|
2002-06-08 00:09:20 +02:00
|
|
|
prev->mru_next = next;
|
2001-12-06 17:45:26 +01:00
|
|
|
|
2002-06-08 00:09:20 +02:00
|
|
|
if ( node == first )
|
2001-12-06 17:45:26 +01:00
|
|
|
{
|
2002-06-08 08:47:18 +02:00
|
|
|
/* this is the last node in the list; update its head pointer */
|
2002-06-08 00:09:20 +02:00
|
|
|
if ( node == next )
|
2001-12-06 17:45:26 +01:00
|
|
|
manager->nodes_list = NULL;
|
|
|
|
else
|
2002-06-08 00:09:20 +02:00
|
|
|
manager->nodes_list = next;
|
2001-12-06 17:45:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
node->mru_next = NULL;
|
|
|
|
node->mru_prev = NULL;
|
|
|
|
manager->num_nodes--;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* move a node to the head of the manager's MRU list */
|
|
|
|
static void
|
|
|
|
ftc_node_mru_up( FTC_Node node,
|
|
|
|
FTC_Manager manager )
|
|
|
|
{
|
|
|
|
FTC_Node first = manager->nodes_list;
|
|
|
|
|
|
|
|
|
|
|
|
if ( node != first )
|
|
|
|
{
|
2002-06-07 22:07:44 +02:00
|
|
|
FTC_Node prev = node->mru_prev;
|
|
|
|
FTC_Node next = node->mru_next;
|
2002-06-08 03:05:56 +02:00
|
|
|
FTC_Node last;
|
2002-06-07 22:07:44 +02:00
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
|
2002-06-07 22:07:44 +02:00
|
|
|
prev->mru_next = next;
|
|
|
|
next->mru_prev = prev;
|
|
|
|
|
2002-06-08 03:05:56 +02:00
|
|
|
last = first->mru_prev;
|
2002-06-07 22:07:44 +02:00
|
|
|
node->mru_next = first;
|
|
|
|
node->mru_prev = last;
|
|
|
|
first->mru_prev = node;
|
|
|
|
last->mru_next = node;
|
|
|
|
|
|
|
|
manager->nodes_list = node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* remove a node from its cache's hash table */
|
|
|
|
static FT_Error
|
|
|
|
ftc_node_hash_unlink( FTC_Node node,
|
|
|
|
FTC_Cache cache )
|
|
|
|
{
|
|
|
|
FT_Error error = 0;
|
|
|
|
FTC_Node *pnode;
|
2002-08-06 23:47:40 +02:00
|
|
|
FT_UInt idx, num_buckets;
|
2002-06-07 22:07:44 +02:00
|
|
|
|
2002-07-17 22:56:48 +02:00
|
|
|
|
2002-08-06 23:47:40 +02:00
|
|
|
idx = (FT_UInt)( node->hash & cache->mask );
|
|
|
|
if ( idx < cache->p )
|
|
|
|
idx = (FT_UInt)( node->hash & ( 2 * cache->mask + 1 ) );
|
2002-06-07 22:07:44 +02:00
|
|
|
|
2002-08-06 23:47:40 +02:00
|
|
|
pnode = cache->buckets + idx;
|
2002-06-07 22:07:44 +02:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if ( *pnode == NULL )
|
|
|
|
{
|
2002-06-08 08:47:18 +02:00
|
|
|
FT_ERROR(( "ftc_node_hash_unlink: unknown node!\n" ));
|
* src/winfonts/winfnt.c (FNT_Load_Glyph): Use first_char in
computation of glyph_index.
(FNT_Size_Set_Pixels): To find a strike, first check pixel_height
only, then try to find a better hit by comparing pixel_width also.
Without this fix it isn't possible to access all strikes.
Also compute metrics.max_advance to be in sync with other bitmap
drivers.
* src/base/ftobjs.c (FT_Set_Char_Size): Remove redundant code.
(FT_Set_Pixel_Size): Assign value to `metrics' after validation of
arguments.
Synchronize computation of height and width for bitmap strikes. The
`width' field in the FT_Bitmap_Size structure is now only useful to
enumerate different strikes. The `max_advance' field of the
FT_Size_Metrics structure should be used to get the (maximum) width
of a strike.
* src/bdf/bdfdrivr.c (BDF_Face_Init): Don't use AVERAGE_WIDTH for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/pcf/pcfread.c (pcf_load_font): Don't use RESOLUTION_X for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/truetype/ttdriver.c (Set_Pixel_Sizes): Pass only single
argument to function.
* src/psnames/psmodule.c (ps_unicode_value): Handle `.' after
`uniXXXX' and `uXXXX[X[X]]'.
* src/bdf/bdfdrivr.c: s/FT_Err_/BDF_Err/.
* src/cache/ftccache.c, src/cache/ftcsbits.c, src/cache/ftlru.c:
s/FT_Err_/FTC_Err_/.
* src/cff/cffcmap.c: s/FT_Err_/CFF_Err_/.
* src/pcf/pcfdrivr.c: s/FT_Err_/PCF_Err_/.
* src/psaux/t1cmap.c: Include psauxerr.h.
s/FT_Err_/PSaux_Err_/.
* src/pshinter/pshnterr.h: New file.
* src/pshinter/rules.mk: Updated.
* src/pshinter/pshalgo.c, src/pshinter/pshrec.c: Include pshnterr.h.
s/FT_Err_/PSH_Err_/.
* src/pfr/pfrdrivr.c, src/pfr/pfrobjs.c, src/pfr/pfrsbit.c:
s/FT_Err_/PFR_Err_/.
* src/sfnt/sfdriver.c, src/sfnt/sfobjs.c, src/sfnt/ttcmap0.c,
src/sfnt/ttload.c: s/FT_Err_/SFNT_Err_/.
* src/truetype/ttgload.c: s/FT_Err_/TT_Err_/.
* src/gzip/ftgzip.c: Load FT_MODULE_ERRORS_H and define
FT_ERR_PREFIX and FT_ERR_BASE.
s/FT_Err_/Gzip_Err_/.
2003-06-22 17:33:53 +02:00
|
|
|
return FTC_Err_Ok;
|
2002-06-07 22:07:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( *pnode == node )
|
|
|
|
{
|
|
|
|
*pnode = node->link;
|
|
|
|
node->link = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
pnode = &(*pnode)->link;
|
|
|
|
}
|
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
num_buckets = ( cache->p + cache->mask + 1 );
|
2002-06-07 22:07:44 +02:00
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
if ( ++cache->slack > (FT_Long)num_buckets * FTC_HASH_SUB_LOAD )
|
2002-06-07 22:07:44 +02:00
|
|
|
{
|
|
|
|
FT_UInt p = cache->p;
|
|
|
|
FT_UInt mask = cache->mask;
|
|
|
|
FT_UInt old_index = p + mask;
|
|
|
|
FTC_Node* pold;
|
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
|
2003-04-23 08:32:41 +02:00
|
|
|
if ( old_index + 1 <= FTC_HASH_INITIAL_SIZE )
|
2003-01-07 23:54:02 +01:00
|
|
|
goto Exit;
|
2002-06-07 22:07:44 +02:00
|
|
|
|
|
|
|
if ( p == 0 )
|
|
|
|
{
|
|
|
|
FT_Memory memory = cache->memory;
|
|
|
|
|
|
|
|
|
|
|
|
cache->mask >>= 1;
|
|
|
|
p = cache->mask;
|
|
|
|
|
2002-06-08 15:48:41 +02:00
|
|
|
if ( FT_RENEW_ARRAY( cache->buckets, ( mask + 1 ) * 2, (mask+1) ) )
|
2002-06-07 22:07:44 +02:00
|
|
|
{
|
2002-06-08 08:47:18 +02:00
|
|
|
FT_ERROR(( "ftc_node_hash_unlink: couldn't shunk buckets!\n" ));
|
2002-06-07 22:07:44 +02:00
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
p--;
|
|
|
|
|
|
|
|
pnode = cache->buckets + p;
|
|
|
|
while ( *pnode )
|
|
|
|
pnode = &(*pnode)->link;
|
|
|
|
|
|
|
|
pold = cache->buckets + old_index;
|
|
|
|
*pnode = *pold;
|
|
|
|
*pold = NULL;
|
|
|
|
|
|
|
|
cache->slack -= FTC_HASH_MAX_LOAD;
|
|
|
|
cache->p = p;
|
2001-12-06 17:45:26 +01:00
|
|
|
}
|
2002-06-07 22:07:44 +02:00
|
|
|
|
|
|
|
Exit:
|
|
|
|
return error;
|
2001-12-06 17:45:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-07 22:07:44 +02:00
|
|
|
|
|
|
|
/* add a node to the "top" of its cache's hash table */
|
|
|
|
static FT_Error
|
|
|
|
ftc_node_hash_link( FTC_Node node,
|
|
|
|
FTC_Cache cache )
|
|
|
|
{
|
|
|
|
FTC_Node *pnode;
|
2002-08-06 23:47:40 +02:00
|
|
|
FT_UInt idx;
|
2002-06-07 22:07:44 +02:00
|
|
|
FT_Error error = 0;
|
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
|
2002-08-06 23:47:40 +02:00
|
|
|
idx = (FT_UInt)( node->hash & cache->mask );
|
|
|
|
if ( idx < cache->p )
|
|
|
|
idx = (FT_UInt)( node->hash & (2 * cache->mask + 1 ) );
|
2002-06-07 22:07:44 +02:00
|
|
|
|
2002-08-06 23:47:40 +02:00
|
|
|
pnode = cache->buckets + idx;
|
2002-06-07 22:07:44 +02:00
|
|
|
|
|
|
|
node->link = *pnode;
|
|
|
|
*pnode = node;
|
|
|
|
|
|
|
|
if ( --cache->slack < 0 )
|
|
|
|
{
|
|
|
|
FT_UInt p = cache->p;
|
|
|
|
FT_UInt mask = cache->mask;
|
|
|
|
FTC_Node new_list;
|
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
|
2002-06-07 22:07:44 +02:00
|
|
|
/* split a single bucket */
|
|
|
|
new_list = NULL;
|
|
|
|
pnode = cache->buckets + p;
|
2002-06-08 08:47:18 +02:00
|
|
|
|
2002-06-07 22:07:44 +02:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
node = *pnode;
|
|
|
|
if ( node == NULL )
|
|
|
|
break;
|
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
if ( node->hash & ( mask + 1 ) )
|
2002-06-07 22:07:44 +02:00
|
|
|
{
|
|
|
|
*pnode = node->link;
|
|
|
|
node->link = new_list;
|
|
|
|
new_list = node;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pnode = &node->link;
|
|
|
|
}
|
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
cache->buckets[p + mask + 1] = new_list;
|
2002-06-07 22:07:44 +02:00
|
|
|
|
|
|
|
cache->slack += FTC_HASH_MAX_LOAD;
|
|
|
|
|
|
|
|
if ( p >= mask )
|
|
|
|
{
|
|
|
|
FT_Memory memory = cache->memory;
|
|
|
|
|
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
if ( FT_RENEW_ARRAY( cache->buckets,
|
|
|
|
( mask + 1 ) * 2, ( mask + 1 ) * 4 ) )
|
2002-06-07 22:07:44 +02:00
|
|
|
{
|
2002-06-08 08:47:18 +02:00
|
|
|
FT_ERROR(( "ftc_node_hash_link: couldn't expand buckets!\n" ));
|
2002-06-07 22:07:44 +02:00
|
|
|
goto Exit;
|
|
|
|
}
|
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
cache->mask = 2 * mask + 1;
|
2002-06-07 22:07:44 +02:00
|
|
|
cache->p = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cache->p = p + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-12-06 17:45:26 +01:00
|
|
|
|
2001-12-16 09:17:33 +01:00
|
|
|
/* remove a node from the cache manager */
|
|
|
|
FT_EXPORT_DEF( void )
|
2001-12-06 17:45:26 +01:00
|
|
|
ftc_node_destroy( FTC_Node node,
|
|
|
|
FTC_Manager manager )
|
|
|
|
{
|
|
|
|
FT_Memory memory = manager->library->memory;
|
|
|
|
FTC_Cache cache;
|
|
|
|
FTC_FamilyEntry entry;
|
|
|
|
FTC_Cache_Class clazz;
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef FT_DEBUG_ERROR
|
|
|
|
/* find node's cache */
|
|
|
|
if ( node->fam_index >= manager->families.count )
|
|
|
|
{
|
2001-12-20 18:49:10 +01:00
|
|
|
FT_ERROR(( "ftc_node_destroy: invalid node handle\n" ));
|
2001-12-06 17:45:26 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
entry = manager->families.entries + node->fam_index;
|
|
|
|
cache = entry->cache;
|
|
|
|
|
|
|
|
#ifdef FT_DEBUG_ERROR
|
|
|
|
if ( cache == NULL )
|
|
|
|
{
|
2001-12-20 18:49:10 +01:00
|
|
|
FT_ERROR(( "ftc_node_destroy: invalid node handle\n" ));
|
2001-12-06 17:45:26 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
clazz = cache->clazz;
|
|
|
|
|
|
|
|
manager->cur_weight -= clazz->node_weight( node, cache );
|
|
|
|
|
|
|
|
/* remove node from mru list */
|
|
|
|
ftc_node_mru_unlink( node, manager );
|
|
|
|
|
|
|
|
/* remove node from cache's hash table */
|
|
|
|
ftc_node_hash_unlink( node, cache );
|
|
|
|
|
|
|
|
/* now finalize it */
|
|
|
|
if ( clazz->node_done )
|
|
|
|
clazz->node_done( node, cache );
|
|
|
|
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_FREE( node );
|
2001-12-06 17:45:26 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
#if 0
|
2001-12-06 17:45:26 +01:00
|
|
|
/* check, just in case of general corruption :-) */
|
2002-01-25 17:05:39 +01:00
|
|
|
if ( manager->num_nodes == 0 )
|
2001-12-20 18:49:10 +01:00
|
|
|
FT_ERROR(( "ftc_node_destroy: invalid cache node count! = %d\n",
|
2001-12-06 17:45:26 +01:00
|
|
|
manager->num_nodes ));
|
2003-03-20 21:58:57 +01:00
|
|
|
#endif
|
2001-12-06 17:45:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** CACHE FAMILY DEFINITIONS *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
FT_EXPORT_DEF( FT_Error )
|
2001-12-06 17:45:26 +01:00
|
|
|
ftc_family_init( FTC_Family family,
|
|
|
|
FTC_Query query,
|
|
|
|
FTC_Cache cache )
|
|
|
|
{
|
|
|
|
FT_Error error;
|
|
|
|
FTC_Manager manager = cache->manager;
|
|
|
|
FT_Memory memory = manager->library->memory;
|
|
|
|
FTC_FamilyEntry entry;
|
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
|
2001-12-06 17:45:26 +01:00
|
|
|
family->cache = cache;
|
|
|
|
family->num_nodes = 0;
|
|
|
|
|
|
|
|
/* now add to manager's family table */
|
|
|
|
error = ftc_family_table_alloc( &manager->families, memory, &entry );
|
2001-12-20 18:49:10 +01:00
|
|
|
if ( !error )
|
2001-12-06 17:45:26 +01:00
|
|
|
{
|
|
|
|
entry->cache = cache;
|
|
|
|
entry->family = family;
|
|
|
|
family->fam_index = entry->index;
|
|
|
|
|
|
|
|
query->family = family; /* save family in query */
|
|
|
|
}
|
2001-12-20 18:49:10 +01:00
|
|
|
|
2001-12-06 17:45:26 +01:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
FT_EXPORT_DEF( void )
|
2001-12-06 17:45:26 +01:00
|
|
|
ftc_family_done( FTC_Family family )
|
|
|
|
{
|
2003-03-20 21:58:57 +01:00
|
|
|
if ( family && family->cache )
|
|
|
|
{
|
|
|
|
FTC_Manager manager = family->cache->manager;
|
2001-12-06 17:45:26 +01:00
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
|
2003-03-20 21:58:57 +01:00
|
|
|
/* remove from manager's family table */
|
|
|
|
ftc_family_table_free( &manager->families, family->fam_index );
|
|
|
|
}
|
2001-12-06 17:45:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** ABSTRACT CACHE CLASS *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
|
2001-12-06 17:45:26 +01:00
|
|
|
FT_EXPORT_DEF( FT_Error )
|
|
|
|
ftc_cache_init( FTC_Cache cache )
|
|
|
|
{
|
|
|
|
FT_Memory memory = cache->memory;
|
|
|
|
FTC_Cache_Class clazz = cache->clazz;
|
|
|
|
FT_Error error;
|
|
|
|
|
|
|
|
|
2002-06-07 22:07:44 +02:00
|
|
|
cache->p = 0;
|
2002-06-08 08:47:18 +02:00
|
|
|
cache->mask = FTC_HASH_INITIAL_SIZE - 1;
|
|
|
|
cache->slack = FTC_HASH_INITIAL_SIZE * FTC_HASH_MAX_LOAD;
|
2002-06-07 22:07:44 +02:00
|
|
|
|
2002-06-08 08:47:18 +02:00
|
|
|
if ( FT_NEW_ARRAY( cache->buckets, FTC_HASH_INITIAL_SIZE * 2 ) )
|
2002-06-07 22:07:44 +02:00
|
|
|
goto Exit;
|
|
|
|
|
2001-12-06 17:45:26 +01:00
|
|
|
/* now, initialize the lru list of families for this cache */
|
|
|
|
if ( clazz->family_size > 0 )
|
|
|
|
{
|
|
|
|
FT_LruList_ClassRec* lru_class = &cache->family_class;
|
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
|
2001-12-06 17:45:26 +01:00
|
|
|
lru_class->list_size = sizeof( FT_LruListRec );
|
|
|
|
lru_class->list_init = NULL;
|
|
|
|
lru_class->list_done = NULL;
|
|
|
|
|
|
|
|
lru_class->node_size = clazz->family_size;
|
2001-12-20 18:49:10 +01:00
|
|
|
lru_class->node_init = (FT_LruNode_InitFunc) clazz->family_init;
|
|
|
|
lru_class->node_done = (FT_LruNode_DoneFunc) clazz->family_done;
|
|
|
|
lru_class->node_flush = (FT_LruNode_FlushFunc) NULL;
|
|
|
|
lru_class->node_compare = (FT_LruNode_CompareFunc)clazz->family_compare;
|
2001-12-06 17:45:26 +01:00
|
|
|
|
|
|
|
error = FT_LruList_New( (FT_LruList_Class) lru_class,
|
2001-12-20 18:49:10 +01:00
|
|
|
0, /* max items == 0 => unbounded list */
|
2001-12-06 17:45:26 +01:00
|
|
|
cache,
|
|
|
|
memory,
|
|
|
|
&cache->families );
|
2001-12-20 18:49:10 +01:00
|
|
|
if ( error )
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_FREE( cache->buckets );
|
2001-12-06 17:45:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
FT_EXPORT_DEF( void )
|
2001-12-06 17:45:26 +01:00
|
|
|
ftc_cache_clear( FTC_Cache cache )
|
|
|
|
{
|
|
|
|
if ( cache )
|
|
|
|
{
|
|
|
|
FT_Memory memory = cache->memory;
|
|
|
|
FTC_Cache_Class clazz = cache->clazz;
|
|
|
|
FTC_Manager manager = cache->manager;
|
|
|
|
FT_UFast i;
|
2002-06-07 22:07:44 +02:00
|
|
|
FT_UInt count;
|
2001-12-06 17:45:26 +01:00
|
|
|
|
2002-06-07 22:07:44 +02:00
|
|
|
count = cache->p + cache->mask + 1;
|
2001-12-06 17:45:26 +01:00
|
|
|
|
2002-06-07 22:07:44 +02:00
|
|
|
for ( i = 0; i < count; i++ )
|
2001-12-06 17:45:26 +01:00
|
|
|
{
|
|
|
|
FTC_Node *pnode = cache->buckets + i, next, node = *pnode;
|
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
|
2001-12-06 17:45:26 +01:00
|
|
|
while ( node )
|
|
|
|
{
|
|
|
|
next = node->link;
|
|
|
|
node->link = NULL;
|
|
|
|
|
|
|
|
/* remove node from mru list */
|
|
|
|
ftc_node_mru_unlink( node, manager );
|
|
|
|
|
|
|
|
/* now finalize it */
|
|
|
|
manager->cur_weight -= clazz->node_weight( node, cache );
|
|
|
|
|
|
|
|
if ( clazz->node_done )
|
|
|
|
clazz->node_done( node, cache );
|
|
|
|
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_FREE( node );
|
2001-12-06 17:45:26 +01:00
|
|
|
node = next;
|
|
|
|
}
|
|
|
|
cache->buckets[i] = NULL;
|
|
|
|
}
|
|
|
|
|
2002-06-07 22:07:44 +02:00
|
|
|
cache->p = 0;
|
2002-07-17 22:56:48 +02:00
|
|
|
|
2001-12-06 17:45:26 +01:00
|
|
|
/* destroy the families */
|
|
|
|
if ( cache->families )
|
|
|
|
FT_LruList_Reset( cache->families );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
|
2001-12-06 17:45:26 +01:00
|
|
|
FT_EXPORT_DEF( void )
|
|
|
|
ftc_cache_done( FTC_Cache cache )
|
|
|
|
{
|
|
|
|
if ( cache )
|
|
|
|
{
|
|
|
|
FT_Memory memory = cache->memory;
|
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
|
2001-12-06 17:45:26 +01:00
|
|
|
ftc_cache_clear( cache );
|
|
|
|
|
2002-03-22 14:52:37 +01:00
|
|
|
FT_FREE( cache->buckets );
|
2002-06-07 22:07:44 +02:00
|
|
|
cache->mask = 0;
|
|
|
|
cache->slack = 0;
|
2001-12-06 17:45:26 +01:00
|
|
|
|
|
|
|
if ( cache->families )
|
|
|
|
{
|
|
|
|
FT_LruList_Destroy( cache->families );
|
|
|
|
cache->families = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Look up a node in "top" of its cache's hash table. */
|
|
|
|
/* If not found, create a new node. */
|
|
|
|
/* */
|
2001-12-20 18:49:10 +01:00
|
|
|
FT_EXPORT_DEF( FT_Error )
|
2001-12-06 17:45:26 +01:00
|
|
|
ftc_cache_lookup( FTC_Cache cache,
|
|
|
|
FTC_Query query,
|
|
|
|
FTC_Node *anode )
|
|
|
|
{
|
* src/winfonts/winfnt.c (FNT_Load_Glyph): Use first_char in
computation of glyph_index.
(FNT_Size_Set_Pixels): To find a strike, first check pixel_height
only, then try to find a better hit by comparing pixel_width also.
Without this fix it isn't possible to access all strikes.
Also compute metrics.max_advance to be in sync with other bitmap
drivers.
* src/base/ftobjs.c (FT_Set_Char_Size): Remove redundant code.
(FT_Set_Pixel_Size): Assign value to `metrics' after validation of
arguments.
Synchronize computation of height and width for bitmap strikes. The
`width' field in the FT_Bitmap_Size structure is now only useful to
enumerate different strikes. The `max_advance' field of the
FT_Size_Metrics structure should be used to get the (maximum) width
of a strike.
* src/bdf/bdfdrivr.c (BDF_Face_Init): Don't use AVERAGE_WIDTH for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/pcf/pcfread.c (pcf_load_font): Don't use RESOLUTION_X for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/truetype/ttdriver.c (Set_Pixel_Sizes): Pass only single
argument to function.
* src/psnames/psmodule.c (ps_unicode_value): Handle `.' after
`uniXXXX' and `uXXXX[X[X]]'.
* src/bdf/bdfdrivr.c: s/FT_Err_/BDF_Err/.
* src/cache/ftccache.c, src/cache/ftcsbits.c, src/cache/ftlru.c:
s/FT_Err_/FTC_Err_/.
* src/cff/cffcmap.c: s/FT_Err_/CFF_Err_/.
* src/pcf/pcfdrivr.c: s/FT_Err_/PCF_Err_/.
* src/psaux/t1cmap.c: Include psauxerr.h.
s/FT_Err_/PSaux_Err_/.
* src/pshinter/pshnterr.h: New file.
* src/pshinter/rules.mk: Updated.
* src/pshinter/pshalgo.c, src/pshinter/pshrec.c: Include pshnterr.h.
s/FT_Err_/PSH_Err_/.
* src/pfr/pfrdrivr.c, src/pfr/pfrobjs.c, src/pfr/pfrsbit.c:
s/FT_Err_/PFR_Err_/.
* src/sfnt/sfdriver.c, src/sfnt/sfobjs.c, src/sfnt/ttcmap0.c,
src/sfnt/ttload.c: s/FT_Err_/SFNT_Err_/.
* src/truetype/ttgload.c: s/FT_Err_/TT_Err_/.
* src/gzip/ftgzip.c: Load FT_MODULE_ERRORS_H and define
FT_ERR_PREFIX and FT_ERR_BASE.
s/FT_Err_/Gzip_Err_/.
2003-06-22 17:33:53 +02:00
|
|
|
FT_Error error = FTC_Err_Ok;
|
2003-03-13 22:07:51 +01:00
|
|
|
FTC_Manager manager;
|
|
|
|
FT_LruNode lru;
|
|
|
|
FT_UInt free_count = 0;
|
2001-12-06 17:45:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
if ( !cache || !query || !anode )
|
|
|
|
return FTC_Err_Invalid_Argument;
|
|
|
|
|
|
|
|
*anode = NULL;
|
|
|
|
|
|
|
|
query->hash = 0;
|
|
|
|
query->family = NULL;
|
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
manager = cache->manager;
|
|
|
|
|
2003-04-23 08:32:41 +02:00
|
|
|
/* here's a small note explaining what's happening in the code below.
|
2003-03-13 22:07:51 +01:00
|
|
|
*
|
2003-04-23 08:32:41 +02:00
|
|
|
* We need to deal intelligently with out-of-memory (OOM) conditions
|
2003-03-13 22:07:51 +01:00
|
|
|
* when trying to create a new family or cache node during the lookup.
|
|
|
|
*
|
2003-04-23 08:32:41 +02:00
|
|
|
* When an OOM is detected, we try to free one or more "old" nodes
|
|
|
|
* from the cache, then try again. It may be necessary to do that
|
|
|
|
* several times, so a loop is needed.
|
2003-03-13 22:07:51 +01:00
|
|
|
*
|
2003-04-23 08:32:41 +02:00
|
|
|
* The local variable "free_count" holds the number of "old" nodes to
|
|
|
|
* discard on each attempt. It starts at 1 and doubles on each
|
|
|
|
* iteration. The loop stops when:
|
2003-03-13 22:07:51 +01:00
|
|
|
*
|
|
|
|
* - a non-OOM error is detected
|
|
|
|
* - a succesful lookup is performed
|
|
|
|
* - there are no more unused nodes in the cache
|
|
|
|
*
|
2003-04-23 08:32:41 +02:00
|
|
|
* For the record, remember that all used nodes appear _before_
|
2003-03-13 22:07:51 +01:00
|
|
|
* unused ones in the manager's MRU node list.
|
|
|
|
*/
|
2002-06-07 22:07:44 +02:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
for (;;)
|
|
|
|
{
|
2002-06-07 22:07:44 +02:00
|
|
|
{
|
2003-03-13 22:07:51 +01:00
|
|
|
/* first of all, find the relevant family */
|
|
|
|
FT_LruList list = cache->families;
|
|
|
|
FT_LruNode fam, *pfam;
|
|
|
|
FT_LruNode_CompareFunc compare = list->clazz->node_compare;
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
pfam = &list->nodes;
|
|
|
|
for (;;)
|
2002-06-07 22:07:44 +02:00
|
|
|
{
|
2003-03-13 22:07:51 +01:00
|
|
|
fam = *pfam;
|
|
|
|
if ( fam == NULL )
|
|
|
|
{
|
|
|
|
error = FT_LruList_Lookup( list, query, &lru );
|
|
|
|
if ( error )
|
|
|
|
goto Fail;
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
goto Skip;
|
|
|
|
}
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
if ( compare( fam, query, list->data ) )
|
|
|
|
break;
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
pfam = &fam->next;
|
2002-06-07 22:07:44 +02:00
|
|
|
}
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
FT_ASSERT( fam != NULL );
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
/* move to top of list when needed */
|
|
|
|
if ( fam != list->nodes )
|
|
|
|
{
|
|
|
|
*pfam = fam->next;
|
|
|
|
fam->next = list->nodes;
|
|
|
|
list->nodes = fam;
|
|
|
|
}
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
lru = fam;
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
Skip:
|
|
|
|
;
|
2001-12-20 18:49:10 +01:00
|
|
|
}
|
2001-12-06 17:45:26 +01:00
|
|
|
|
|
|
|
{
|
2003-03-13 22:07:51 +01:00
|
|
|
FTC_Family family = (FTC_Family) lru;
|
|
|
|
FT_UFast hash = query->hash;
|
|
|
|
FTC_Node* bucket;
|
|
|
|
FT_UInt idx;
|
2003-03-20 21:58:57 +01:00
|
|
|
|
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
idx = hash & cache->mask;
|
|
|
|
if ( idx < cache->p )
|
|
|
|
idx = hash & ( cache->mask * 2 + 1 );
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
bucket = cache->buckets + idx;
|
2003-03-20 21:58:57 +01:00
|
|
|
|
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
if ( query->family != family ||
|
|
|
|
family->fam_index >= manager->families.size )
|
2001-12-06 17:45:26 +01:00
|
|
|
{
|
2003-03-13 22:07:51 +01:00
|
|
|
FT_ERROR((
|
|
|
|
"ftc_cache_lookup: invalid query (bad 'family' field)\n" ));
|
|
|
|
error = FTC_Err_Invalid_Argument;
|
|
|
|
goto Exit;
|
|
|
|
}
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
if ( *bucket )
|
|
|
|
{
|
|
|
|
FTC_Node* pnode = bucket;
|
|
|
|
FTC_Node_CompareFunc compare = cache->clazz->node_compare;
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2001-12-06 17:45:26 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
for ( ;; )
|
2001-12-06 17:45:26 +01:00
|
|
|
{
|
2003-03-13 22:07:51 +01:00
|
|
|
FTC_Node node;
|
2003-03-20 21:58:57 +01:00
|
|
|
|
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
node = *pnode;
|
|
|
|
if ( node == NULL )
|
|
|
|
break;
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
if ( node->hash == hash &&
|
|
|
|
(FT_UInt)node->fam_index == family->fam_index &&
|
|
|
|
compare( node, query, cache ) )
|
2001-12-06 17:45:26 +01:00
|
|
|
{
|
2003-03-13 22:07:51 +01:00
|
|
|
/* move to head of bucket list */
|
|
|
|
if ( pnode != bucket )
|
|
|
|
{
|
|
|
|
*pnode = node->link;
|
|
|
|
node->link = *bucket;
|
|
|
|
*bucket = node;
|
|
|
|
}
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
/* move to head of MRU list */
|
|
|
|
if ( node != manager->nodes_list )
|
|
|
|
ftc_node_mru_up( node, manager );
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
*anode = node;
|
|
|
|
goto Exit;
|
2001-12-06 17:45:26 +01:00
|
|
|
}
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
pnode = &node->link;
|
2001-12-06 17:45:26 +01:00
|
|
|
}
|
|
|
|
}
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
/* didn't find a node, create a new one */
|
|
|
|
{
|
|
|
|
FTC_Cache_Class clazz = cache->clazz;
|
|
|
|
FT_Memory memory = cache->memory;
|
|
|
|
FTC_Node node;
|
2003-03-20 21:58:57 +01:00
|
|
|
|
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
if ( FT_ALLOC( node, clazz->node_size ) )
|
|
|
|
goto Fail;
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
node->fam_index = (FT_UShort) family->fam_index;
|
|
|
|
node->hash = query->hash;
|
|
|
|
node->ref_count = 0;
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
error = clazz->node_init( node, query, cache );
|
|
|
|
if ( error )
|
|
|
|
{
|
|
|
|
FT_FREE( node );
|
|
|
|
goto Fail;
|
|
|
|
}
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
error = ftc_node_hash_link( node, cache );
|
|
|
|
if ( error )
|
|
|
|
{
|
|
|
|
clazz->node_done( node, cache );
|
|
|
|
FT_FREE( node );
|
|
|
|
goto Fail;
|
|
|
|
}
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
ftc_node_mru_link( node, cache->manager );
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
cache->manager->cur_weight += clazz->node_weight( node, cache );
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
/* now try to compress the node pool when necessary */
|
|
|
|
if ( manager->cur_weight >= manager->max_weight )
|
|
|
|
{
|
|
|
|
node->ref_count++;
|
|
|
|
FTC_Manager_Compress( manager );
|
|
|
|
node->ref_count--;
|
|
|
|
}
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
*anode = node;
|
|
|
|
}
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
/* all is well, exit now
|
|
|
|
*/
|
|
|
|
goto Exit;
|
2001-12-06 17:45:26 +01:00
|
|
|
}
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
Fail:
|
* src/winfonts/winfnt.c (FNT_Load_Glyph): Use first_char in
computation of glyph_index.
(FNT_Size_Set_Pixels): To find a strike, first check pixel_height
only, then try to find a better hit by comparing pixel_width also.
Without this fix it isn't possible to access all strikes.
Also compute metrics.max_advance to be in sync with other bitmap
drivers.
* src/base/ftobjs.c (FT_Set_Char_Size): Remove redundant code.
(FT_Set_Pixel_Size): Assign value to `metrics' after validation of
arguments.
Synchronize computation of height and width for bitmap strikes. The
`width' field in the FT_Bitmap_Size structure is now only useful to
enumerate different strikes. The `max_advance' field of the
FT_Size_Metrics structure should be used to get the (maximum) width
of a strike.
* src/bdf/bdfdrivr.c (BDF_Face_Init): Don't use AVERAGE_WIDTH for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/pcf/pcfread.c (pcf_load_font): Don't use RESOLUTION_X for
computing `available_sizes->width' but make it always equal to
`available_sizes->height'.
* src/truetype/ttdriver.c (Set_Pixel_Sizes): Pass only single
argument to function.
* src/psnames/psmodule.c (ps_unicode_value): Handle `.' after
`uniXXXX' and `uXXXX[X[X]]'.
* src/bdf/bdfdrivr.c: s/FT_Err_/BDF_Err/.
* src/cache/ftccache.c, src/cache/ftcsbits.c, src/cache/ftlru.c:
s/FT_Err_/FTC_Err_/.
* src/cff/cffcmap.c: s/FT_Err_/CFF_Err_/.
* src/pcf/pcfdrivr.c: s/FT_Err_/PCF_Err_/.
* src/psaux/t1cmap.c: Include psauxerr.h.
s/FT_Err_/PSaux_Err_/.
* src/pshinter/pshnterr.h: New file.
* src/pshinter/rules.mk: Updated.
* src/pshinter/pshalgo.c, src/pshinter/pshrec.c: Include pshnterr.h.
s/FT_Err_/PSH_Err_/.
* src/pfr/pfrdrivr.c, src/pfr/pfrobjs.c, src/pfr/pfrsbit.c:
s/FT_Err_/PFR_Err_/.
* src/sfnt/sfdriver.c, src/sfnt/sfobjs.c, src/sfnt/ttcmap0.c,
src/sfnt/ttload.c: s/FT_Err_/SFNT_Err_/.
* src/truetype/ttgload.c: s/FT_Err_/TT_Err_/.
* src/gzip/ftgzip.c: Load FT_MODULE_ERRORS_H and define
FT_ERR_PREFIX and FT_ERR_BASE.
s/FT_Err_/Gzip_Err_/.
2003-06-22 17:33:53 +02:00
|
|
|
if ( error != FTC_Err_Out_Of_Memory )
|
2003-03-13 22:07:51 +01:00
|
|
|
goto Exit;
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-04-23 08:32:41 +02:00
|
|
|
/* There is not enough memory; try to release some unused nodes
|
2003-03-13 22:07:51 +01:00
|
|
|
* from the cache to make room for a new one.
|
|
|
|
*/
|
2001-12-06 17:45:26 +01:00
|
|
|
{
|
2003-04-23 08:32:41 +02:00
|
|
|
FT_UInt new_count;
|
2001-12-06 17:45:26 +01:00
|
|
|
|
2003-04-23 08:32:41 +02:00
|
|
|
|
|
|
|
new_count = 1 + free_count * 2;
|
2001-12-06 17:45:26 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
/* check overflow and bounds */
|
|
|
|
if ( new_count < free_count || free_count > manager->num_nodes )
|
2001-12-06 17:45:26 +01:00
|
|
|
goto Exit;
|
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
free_count = new_count;
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
/* try to remove "new_count" nodes from the list */
|
2001-12-06 17:45:26 +01:00
|
|
|
{
|
2003-04-23 08:32:41 +02:00
|
|
|
FTC_Node first = manager->nodes_list;
|
|
|
|
FTC_Node node;
|
|
|
|
|
2001-12-06 17:45:26 +01:00
|
|
|
|
2003-04-23 08:32:41 +02:00
|
|
|
if ( first == NULL ) /* empty list! */
|
2003-03-13 22:07:51 +01:00
|
|
|
goto Exit;
|
2002-06-07 22:07:44 +02:00
|
|
|
|
2003-04-23 08:32:41 +02:00
|
|
|
/* go to last node - it's a circular list */
|
2003-03-13 22:07:51 +01:00
|
|
|
node = first->mru_prev;
|
|
|
|
for ( ; node && new_count > 0; new_count-- )
|
|
|
|
{
|
|
|
|
FTC_Node prev = node->mru_prev;
|
2001-12-06 17:45:26 +01:00
|
|
|
|
2003-04-23 08:32:41 +02:00
|
|
|
|
|
|
|
/* Used nodes always appear before unused one in the MRU
|
|
|
|
* list. If we find one here, we'd better stop right now
|
|
|
|
* our iteration.
|
|
|
|
*/
|
2003-03-13 22:07:51 +01:00
|
|
|
if ( node->ref_count > 0 )
|
|
|
|
{
|
|
|
|
/* if there are no unused nodes in the list, we'd better exit */
|
|
|
|
if ( new_count == free_count )
|
|
|
|
goto Exit;
|
2003-03-20 21:58:57 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
break;
|
|
|
|
}
|
2001-12-06 17:45:26 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
ftc_node_destroy( node, manager );
|
|
|
|
|
|
|
|
if ( node == first )
|
|
|
|
break;
|
2001-12-06 17:45:26 +01:00
|
|
|
|
2003-03-13 22:07:51 +01:00
|
|
|
node = prev;
|
|
|
|
}
|
|
|
|
}
|
2001-12-06 17:45:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-20 18:49:10 +01:00
|
|
|
/* END */
|