2000-08-23 19:32:42 +02:00
|
|
|
/***************************************************************************/
|
|
|
|
/* */
|
2000-08-24 18:29:15 +02:00
|
|
|
/* ftcmanag.c */
|
2000-08-23 19:32:42 +02:00
|
|
|
/* */
|
2000-08-24 18:29:15 +02:00
|
|
|
/* FreeType Cache Manager (body). */
|
2000-08-23 19:32:42 +02:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/* */
|
|
|
|
/***************************************************************************/
|
|
|
|
|
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
#include <cache/ftcmanag.h>
|
|
|
|
#include <freetype/internal/ftobjs.h>
|
|
|
|
|
|
|
|
|
2000-08-23 23:11:13 +02:00
|
|
|
#define FTC_LRU_GET_MANAGER( lru ) (FTC_Manager)lru->user_data
|
2000-08-23 19:32:42 +02:00
|
|
|
|
|
|
|
|
2000-08-29 18:50:01 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
/***** *****/
|
|
|
|
/***** FACE & SIZE LRU CALLBACKS *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
LOCAL_FUNC_X
|
2000-08-23 13:22:30 +02:00
|
|
|
FT_Error ftc_manager_init_face( FT_Lru lru,
|
|
|
|
FT_LruNode node )
|
|
|
|
{
|
2000-08-23 19:32:42 +02:00
|
|
|
FTC_Manager manager = FTC_LRU_GET_MANAGER( lru );
|
2000-08-23 13:22:30 +02:00
|
|
|
FT_Error error;
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
error = manager->request_face( (FTC_FaceID)node->key,
|
2000-08-23 23:11:13 +02:00
|
|
|
manager->library,
|
2000-08-23 13:22:30 +02:00
|
|
|
manager->request_data,
|
|
|
|
(FT_Face*)&node->root.data );
|
2000-08-23 19:32:42 +02:00
|
|
|
if ( !error )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
2000-08-23 19:32:42 +02:00
|
|
|
/* destroy initial size object; it will be re-created later */
|
2000-08-23 13:22:30 +02:00
|
|
|
FT_Face face = (FT_Face)node->root.data;
|
2000-08-23 19:32:42 +02:00
|
|
|
|
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
FT_Done_Size( face->size );
|
|
|
|
}
|
2000-08-23 19:32:42 +02:00
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
/* helper function for ftc_manager_done_face */
|
2000-08-29 18:50:01 +02:00
|
|
|
LOCAL_FUNC_X
|
2000-08-23 19:32:42 +02:00
|
|
|
FT_Bool ftc_manager_size_selector( FT_Lru lru,
|
|
|
|
FT_LruNode node,
|
|
|
|
FT_Pointer data )
|
|
|
|
{
|
|
|
|
FT_UNUSED( lru );
|
|
|
|
|
|
|
|
return ((FT_Size)node->root.data)->face == (FT_Face)data;
|
|
|
|
}
|
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
|
2000-08-29 18:50:01 +02:00
|
|
|
LOCAL_FUNC_X
|
2000-08-23 19:32:42 +02:00
|
|
|
void ftc_manager_done_face( FT_Lru lru,
|
|
|
|
FT_LruNode node )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
2000-08-23 19:32:42 +02:00
|
|
|
FTC_Manager manager = FTC_LRU_GET_MANAGER( lru );
|
2000-08-23 13:22:30 +02:00
|
|
|
FT_Face face = (FT_Face)node->root.data;
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
/* we must begin by removing all sizes for the target face */
|
2000-08-23 19:32:42 +02:00
|
|
|
/* from the manager's list */
|
2000-08-23 13:22:30 +02:00
|
|
|
FT_Lru_Remove_Selection( manager->sizes_lru,
|
|
|
|
ftc_manager_size_selector,
|
|
|
|
face );
|
|
|
|
|
|
|
|
/* all right, we can discard the face now */
|
|
|
|
FT_Done_Face( face );
|
|
|
|
node->root.data = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
typedef struct FTC_SizeRequest_
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
|
|
|
FT_Face face;
|
|
|
|
FT_UShort width;
|
|
|
|
FT_UShort height;
|
|
|
|
|
|
|
|
} FTC_SizeRequest;
|
|
|
|
|
|
|
|
|
2000-08-29 18:50:01 +02:00
|
|
|
LOCAL_FUNC_X
|
2000-08-23 19:32:42 +02:00
|
|
|
FT_Error ftc_manager_init_size( FT_Lru lru,
|
|
|
|
FT_LruNode node )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
|
|
|
FTC_SizeRequest* size_req = (FTC_SizeRequest*)node->key;
|
|
|
|
FT_Size size;
|
|
|
|
FT_Error error;
|
2000-08-24 13:53:35 +02:00
|
|
|
FT_Face face = size_req->face;
|
2000-08-23 13:22:30 +02:00
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
FT_UNUSED( lru );
|
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
|
|
|
|
node->root.data = 0;
|
2000-08-24 13:53:35 +02:00
|
|
|
error = FT_New_Size( face, &size );
|
2000-08-23 19:32:42 +02:00
|
|
|
if ( !error )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
2000-08-24 13:53:35 +02:00
|
|
|
face->size = size;
|
|
|
|
error = FT_Set_Pixel_Sizes( face,
|
2000-08-23 13:22:30 +02:00
|
|
|
size_req->width,
|
|
|
|
size_req->height );
|
2000-08-23 19:32:42 +02:00
|
|
|
if ( error )
|
|
|
|
FT_Done_Size( size );
|
2000-08-23 13:22:30 +02:00
|
|
|
else
|
|
|
|
node->root.data = size;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-29 18:50:01 +02:00
|
|
|
LOCAL_FUNC_X
|
2000-08-23 19:32:42 +02:00
|
|
|
void ftc_manager_done_size( FT_Lru lru,
|
|
|
|
FT_LruNode node )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
2000-08-23 19:32:42 +02:00
|
|
|
FT_UNUSED( lru );
|
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
FT_Done_Size( (FT_Size)node->root.data );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-29 18:50:01 +02:00
|
|
|
LOCAL_FUNC_X
|
2000-08-23 19:32:42 +02:00
|
|
|
FT_Error ftc_manager_flush_size( FT_Lru lru,
|
|
|
|
FT_LruNode node,
|
|
|
|
FT_LruKey key )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
|
|
|
FTC_SizeRequest* req = (FTC_SizeRequest*)key;
|
|
|
|
FT_Size size = (FT_Size)node->root.data;
|
|
|
|
FT_Error error;
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
if ( size->face == req->face )
|
|
|
|
{
|
|
|
|
size->face->size = size; /* set current size */
|
|
|
|
error = FT_Set_Pixel_Sizes( req->face, req->width, req->height );
|
2000-08-23 19:32:42 +02:00
|
|
|
if ( error )
|
2000-08-23 13:22:30 +02:00
|
|
|
FT_Done_Size( size );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-08-23 19:32:42 +02:00
|
|
|
FT_Done_Size( size );
|
2000-08-23 13:22:30 +02:00
|
|
|
node->key = key;
|
|
|
|
error = ftc_manager_init_size( lru, node );
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-29 18:50:01 +02:00
|
|
|
LOCAL_FUNC_X
|
2000-08-23 19:32:42 +02:00
|
|
|
FT_Bool ftc_manager_compare_size( FT_LruNode node,
|
|
|
|
FT_LruKey key )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
|
|
|
FTC_SizeRequest* req = (FTC_SizeRequest*)key;
|
|
|
|
FT_Size size = (FT_Size)node->root.data;
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
FT_UNUSED( node );
|
2000-08-23 13:22:30 +02:00
|
|
|
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
return ( size->face == req->face &&
|
|
|
|
size->metrics.x_ppem == req->width &&
|
|
|
|
size->metrics.y_ppem == req->height );
|
|
|
|
}
|
2000-08-23 13:22:30 +02:00
|
|
|
|
|
|
|
|
2000-08-29 18:50:01 +02:00
|
|
|
FT_CPLUSPLUS( const FT_Lru_Class ) ftc_face_lru_class =
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
2000-08-23 23:11:13 +02:00
|
|
|
sizeof ( FT_LruRec ),
|
2000-08-23 13:22:30 +02:00
|
|
|
ftc_manager_init_face,
|
|
|
|
ftc_manager_done_face,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-08-29 18:50:01 +02:00
|
|
|
FT_CPLUSPLUS( const FT_Lru_Class ) ftc_size_lru_class =
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
2000-08-23 23:11:13 +02:00
|
|
|
sizeof ( FT_LruRec ),
|
2000-08-23 13:22:30 +02:00
|
|
|
ftc_manager_init_size,
|
|
|
|
ftc_manager_done_size,
|
|
|
|
ftc_manager_flush_size,
|
|
|
|
ftc_manager_compare_size
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
FT_EXPORT_FUNC( FT_Error ) FTC_Manager_New( FT_Library library,
|
2000-08-24 13:53:35 +02:00
|
|
|
FT_UInt max_faces,
|
2000-08-24 18:29:15 +02:00
|
|
|
FT_UInt max_sizes,
|
2000-08-23 13:22:30 +02:00
|
|
|
FTC_Face_Requester requester,
|
|
|
|
FT_Pointer req_data,
|
2000-08-23 19:32:42 +02:00
|
|
|
FTC_Manager* amanager )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
|
|
|
FT_Error error;
|
2000-08-24 18:29:15 +02:00
|
|
|
FT_Memory memory;
|
2000-08-23 13:22:30 +02:00
|
|
|
FTC_Manager manager = 0;
|
|
|
|
|
|
|
|
|
2000-08-24 18:29:15 +02:00
|
|
|
if ( !library )
|
|
|
|
return FT_Err_Invalid_Library_Handle;
|
|
|
|
|
|
|
|
memory = library->memory;
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
if ( ALLOC( manager, sizeof ( *manager ) ) )
|
2000-08-23 13:22:30 +02:00
|
|
|
goto Exit;
|
2000-08-24 13:53:35 +02:00
|
|
|
|
2000-08-24 18:29:15 +02:00
|
|
|
if ( max_faces == 0 )
|
2000-08-24 13:53:35 +02:00
|
|
|
max_faces = FTC_MAX_FACES;
|
|
|
|
|
2000-08-24 18:29:15 +02:00
|
|
|
if ( max_sizes == 0 )
|
2000-08-24 13:53:35 +02:00
|
|
|
max_sizes = FTC_MAX_SIZES;
|
2000-08-23 13:22:30 +02:00
|
|
|
|
|
|
|
error = FT_Lru_New( &ftc_face_lru_class,
|
2000-08-24 13:53:35 +02:00
|
|
|
max_faces,
|
2000-08-23 23:11:13 +02:00
|
|
|
manager,
|
2000-08-23 13:22:30 +02:00
|
|
|
memory,
|
|
|
|
1, /* pre_alloc = TRUE */
|
|
|
|
(FT_Lru*)&manager->faces_lru );
|
2000-08-23 19:32:42 +02:00
|
|
|
if ( error )
|
2000-08-23 13:22:30 +02:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
error = FT_Lru_New( &ftc_size_lru_class,
|
2000-08-24 13:53:35 +02:00
|
|
|
max_sizes,
|
2000-08-23 23:11:13 +02:00
|
|
|
manager,
|
2000-08-23 13:22:30 +02:00
|
|
|
memory,
|
|
|
|
1, /* pre_alloc = TRUE */
|
|
|
|
(FT_Lru*)&manager->sizes_lru );
|
2000-08-23 19:32:42 +02:00
|
|
|
if ( error )
|
2000-08-23 13:22:30 +02:00
|
|
|
goto Exit;
|
|
|
|
|
|
|
|
manager->library = library;
|
|
|
|
manager->request_face = requester;
|
|
|
|
manager->request_data = req_data;
|
|
|
|
*amanager = manager;
|
|
|
|
|
|
|
|
Exit:
|
2000-08-23 19:32:42 +02:00
|
|
|
if ( error && manager )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
|
|
|
FT_Lru_Done( manager->sizes_lru );
|
|
|
|
FT_Lru_Done( manager->faces_lru );
|
|
|
|
FREE( manager );
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
|
|
|
|
FT_EXPORT_DEF( void ) FTC_Manager_Done( FTC_Manager manager )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
2000-08-24 18:29:15 +02:00
|
|
|
FT_Memory memory;
|
2000-08-23 13:22:30 +02:00
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
|
2000-08-24 18:29:15 +02:00
|
|
|
if ( !manager || !manager->library )
|
|
|
|
return;
|
|
|
|
|
|
|
|
memory = manager->library->memory;
|
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
FT_Lru_Done( manager->sizes_lru );
|
|
|
|
FT_Lru_Done( manager->faces_lru );
|
|
|
|
FREE( manager );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
FT_EXPORT_DEF( void ) FTC_Manager_Reset( FTC_Manager manager )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
2000-08-24 18:29:15 +02:00
|
|
|
if ( !manager )
|
|
|
|
return;
|
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
FT_Lru_Reset( manager->sizes_lru );
|
|
|
|
FT_Lru_Reset( manager->faces_lru );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
FT_EXPORT_DEF( FT_Error ) FTC_Manager_Lookup_Face( FTC_Manager manager,
|
|
|
|
FTC_FaceID face_id,
|
|
|
|
FT_Face* aface )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
2000-08-24 18:29:15 +02:00
|
|
|
if ( !manager )
|
2000-08-27 00:16:44 +02:00
|
|
|
return FT_Err_Invalid_Cache_Handle;
|
2000-08-24 18:29:15 +02:00
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
return FT_Lru_Lookup( manager->faces_lru,
|
2000-08-23 19:32:42 +02:00
|
|
|
(FT_LruKey)face_id,
|
|
|
|
(FT_Pointer*)aface );
|
2000-08-23 13:22:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
FT_EXPORT_DEF( FT_Error ) FTC_Manager_Lookup_Size( FTC_Manager manager,
|
|
|
|
FTC_SizeID size_id,
|
|
|
|
FT_Face* aface,
|
|
|
|
FT_Size* asize )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
|
|
|
FTC_SizeRequest req;
|
|
|
|
FT_Error error;
|
|
|
|
FT_Face face;
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
|
2000-08-24 18:29:15 +02:00
|
|
|
/* check for valid `manager' delayed to FTC_Manager_Lookup_Face() */
|
|
|
|
|
|
|
|
if ( aface )
|
2000-08-23 23:11:13 +02:00
|
|
|
*aface = 0;
|
|
|
|
|
2000-08-24 18:29:15 +02:00
|
|
|
if ( asize )
|
2000-08-23 23:11:13 +02:00
|
|
|
*asize = 0;
|
2000-08-23 19:32:42 +02:00
|
|
|
|
2000-08-24 18:29:15 +02:00
|
|
|
error = FTC_Manager_Lookup_Face( manager, size_id->face_id, &face );
|
2000-08-23 19:32:42 +02:00
|
|
|
if ( !error )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
2000-08-23 23:11:13 +02:00
|
|
|
FT_Size size;
|
|
|
|
|
2000-08-24 18:29:15 +02:00
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
req.face = face;
|
|
|
|
req.width = size_id->pix_width;
|
|
|
|
req.height = size_id->pix_height;
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
error = FT_Lru_Lookup( manager->sizes_lru,
|
|
|
|
(FT_LruKey)&req,
|
2000-08-23 23:11:13 +02:00
|
|
|
(FT_Pointer*)&size );
|
2000-08-23 19:32:42 +02:00
|
|
|
if ( !error )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
|
|
|
/* select the size as the current one for this face */
|
2000-08-24 14:39:40 +02:00
|
|
|
face->size = size;
|
2000-08-23 23:11:13 +02:00
|
|
|
|
2000-08-24 18:29:15 +02:00
|
|
|
if ( asize )
|
2000-08-23 23:11:13 +02:00
|
|
|
*asize = size;
|
|
|
|
|
2000-08-24 18:29:15 +02:00
|
|
|
if ( aface )
|
2000-08-23 23:11:13 +02:00
|
|
|
*aface = face;
|
2000-08-23 13:22:30 +02:00
|
|
|
}
|
|
|
|
}
|
2000-08-23 19:32:42 +02:00
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
/* END */
|