@ -377,16 +377,22 @@
/*************************************************************************/
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_Memory memory = cache - > root . memory ;
FT_Error error ;
FTC_Glyph_Cache_Class * gcache_clazz ;
/* set up root node_class to be used by manager */
cache - > root . node_clazz =
( FTC_CacheNode_Class * ) & ftc_glyph_cache_node_class ;
/* setup the "compare" shortcut */
gcache_clazz = ( FTC_Glyph_Cache_Class * ) cache - > root . clazz ;
cache - > compare = gcache_clazz - > gset_class - > compare ;
/* The following is extremely important for ftc_destroy_glyph_image() */
/* to work properly, as the second parameter that is sent to it */
/* through the cache manager is `cache_data' and must be set to */
@ -404,11 +410,59 @@
}
FT_EXPORT_DEF ( void ) FTC_Glyph_Cache_Done ( FTC_Glyph_Cache cache )
FT_EXPORT_DEF ( void )
FTC_Glyph_Cache_Done ( FTC_Glyph_Cache cache )
{
/* discard glyph sets */
FT_Lru_Done ( cache - > gsets_lru ) ;
}
FT_EXPORT_DEF ( FT_Error )
FTC_Glyph_Cache_Lookup ( FTC_Glyph_Cache cache ,
FT_Pointer type ,
FT_UInt gindex ,
FTC_GlyphNode * anode )
{
FT_Error error ;
FTC_GlyphSet gset ;
FTC_GlyphNode node ;
FTC_Manager manager ;
/* check for valid `desc' delayed to FT_Lru_Lookup() */
if ( ! cache | | ! anode )
return FT_Err_Invalid_Argument ;
* anode = 0 ;
gset = cache - > last_gset ;
if ( ! gset | | ! cache - > compare ( gset , type ) )
{
error = FT_Lru_Lookup ( cache - > gsets_lru ,
( FT_LruKey ) type ,
( FT_Pointer * ) & gset ) ;
cache - > last_gset = gset ;
if ( error )
goto Exit ;
}
error = FTC_GlyphSet_Lookup_Node ( gset , gindex , & node ) ;
if ( error )
goto Exit ;
/* now compress the manager's cache pool if needed */
manager = cache - > root . manager ;
if ( manager - > num_bytes > manager - > max_bytes )
{
FTC_GlyphNode_Ref ( node ) ;
FTC_Manager_Compress ( manager ) ;
FTC_GlyphNode_Unref ( node ) ;
}
* anode = node ;
Exit :
return error ;
}
/* END */