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-12-08 17:17:16 +01:00
|
|
|
|
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_CACHE_H
|
|
|
|
#include FT_CACHE_MANAGER_H
|
|
|
|
#include FT_INTERNAL_OBJECTS_H
|
|
|
|
#include FT_INTERNAL_DEBUG_H
|
|
|
|
#include FT_LIST_H
|
2000-08-23 13:22:30 +02:00
|
|
|
|
Complete redesign of error codes. Please check ftmoderr.h for more
details.
* include/freetype/internal/cfferrs.h,
include/freetype/internal/tterrors.h,
include/freetype/internal/t1errors.h: Removed. Replaced with files
local to the module. All extra error codes have been moved to
`fterrors.h'.
* src/sfnt/ttpost.h: Move error codes to `fterrors.h'.
* src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h,
src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h,
src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h,
src/smooth/ftsmerrs.h, src/truetype/tterrors.h,
src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the
error names for the module it belongs to.
* include/freetype/ftmoderr.h: New file, defining the module error
offsets. Its structure is similar to `fterrors.h'.
* include/freetype/fterrors.h (FT_NOERRORDEF): New macro.
(FT_ERRORDEF): Redefined to use module error offsets.
All internal error codes are now public; unused error codes have
been removed, some are new.
* include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New
macro.
* include/freetype/config/ftoption.h
(FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro.
All other source files have been updated to use the new error codes;
some already existing (internal) error codes local to a module have
been renamed to give them the same name as in the base module.
All make files have been updated to include the local error files.
* src/cid/cidtokens.h: Replaced with...
* src/cid/cidtoken.h: This file for 8+3 consistency.
* src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
|
|
|
#include "ftcerror.h"
|
|
|
|
|
2000-10-12 07:05:40 +02:00
|
|
|
|
|
|
|
#undef FT_COMPONENT
|
|
|
|
#define FT_COMPONENT trace_cache
|
2000-08-23 13:22:30 +02:00
|
|
|
|
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 *****/
|
|
|
|
/***** *****/
|
|
|
|
/*************************************************************************/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
|
2001-06-27 11:26:46 +02:00
|
|
|
FT_CALLBACK_DEF(FT_Error)
|
|
|
|
ftc_manager_init_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_Error error;
|
2000-09-19 03:11:11 +02:00
|
|
|
FT_Face face;
|
2000-10-12 07:05:40 +02:00
|
|
|
|
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-09-19 03:11:11 +02:00
|
|
|
face = (FT_Face)node->root.data;
|
2000-10-31 23:13:54 +01:00
|
|
|
if ( face->size )
|
2000-10-29 01:34:45 +02:00
|
|
|
FT_Done_Size( face->size );
|
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-10-12 07:05:40 +02:00
|
|
|
/* helper function for ftc_manager_done_face() */
|
2001-06-27 11:26:46 +02:00
|
|
|
FT_CALLBACK_DEF(FT_Bool)
|
|
|
|
ftc_manager_size_selector( FT_Lru lru,
|
|
|
|
FT_LruNode node,
|
|
|
|
FT_Pointer data )
|
2000-08-23 19:32:42 +02:00
|
|
|
{
|
|
|
|
FT_UNUSED( lru );
|
|
|
|
|
2001-06-20 01:03:41 +02:00
|
|
|
return FT_BOOL( ((FT_Size)node->root.data)->face == (FT_Face)data );
|
2000-08-23 19:32:42 +02:00
|
|
|
}
|
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
|
2001-06-27 11:26:46 +02:00
|
|
|
FT_CALLBACK_DEF(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-10-12 07:05:40 +02:00
|
|
|
|
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 );
|
|
|
|
|
2000-10-12 07:05:40 +02:00
|
|
|
/* all right, we can discard the face now */
|
2000-08-23 13:22:30 +02:00
|
|
|
FT_Done_Face( face );
|
|
|
|
node->root.data = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
typedef struct FTC_FontRequest_
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
|
|
|
FT_Face face;
|
|
|
|
FT_UShort width;
|
|
|
|
FT_UShort height;
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
} FTC_FontRequest;
|
2000-08-23 13:22:30 +02:00
|
|
|
|
|
|
|
|
2001-06-27 11:26:46 +02:00
|
|
|
FT_CALLBACK_DEF(FT_Error)
|
|
|
|
ftc_manager_init_size( FT_Lru lru,
|
|
|
|
FT_LruNode node )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
2000-09-19 03:11:11 +02:00
|
|
|
FTC_FontRequest* font_req = (FTC_FontRequest*)node->key;
|
2000-08-23 13:22:30 +02:00
|
|
|
FT_Size size;
|
|
|
|
FT_Error error;
|
2000-09-19 03:11:11 +02:00
|
|
|
FT_Face face = font_req->face;
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
FT_UNUSED( lru );
|
|
|
|
|
2000-10-12 07:05:40 +02:00
|
|
|
|
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-09-19 03:11:11 +02:00
|
|
|
font_req->width,
|
|
|
|
font_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;
|
|
|
|
}
|
2000-10-12 07:05:40 +02:00
|
|
|
return error;
|
2000-08-23 13:22:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 11:26:46 +02:00
|
|
|
FT_CALLBACK_DEF(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-12-05 23:23:12 +01:00
|
|
|
node->root.data = 0;
|
2000-10-12 07:05:40 +02:00
|
|
|
}
|
2000-08-23 13:22:30 +02:00
|
|
|
|
|
|
|
|
2001-06-27 11:26:46 +02:00
|
|
|
FT_CALLBACK_DEF(FT_Error)
|
|
|
|
ftc_manager_flush_size( FT_Lru lru,
|
|
|
|
FT_LruNode node,
|
|
|
|
FT_LruKey key )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
2000-09-19 03:11:11 +02:00
|
|
|
FTC_FontRequest* req = (FTC_FontRequest*)key;
|
2000-08-23 13:22:30 +02:00
|
|
|
FT_Size size = (FT_Size)node->root.data;
|
|
|
|
FT_Error error;
|
2000-10-12 07:05:40 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-27 11:26:46 +02:00
|
|
|
FT_CALLBACK_DEF(FT_Bool)
|
|
|
|
ftc_manager_compare_size( FT_LruNode node,
|
|
|
|
FT_LruKey key )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
2000-09-19 03:11:11 +02:00
|
|
|
FTC_FontRequest* req = (FTC_FontRequest*)key;
|
2000-08-23 13:22:30 +02:00
|
|
|
FT_Size size = (FT_Size)node->root.data;
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
FT_UNUSED( node );
|
2000-08-23 13:22:30 +02:00
|
|
|
|
|
|
|
|
2001-06-19 10:28:24 +02:00
|
|
|
return FT_BOOL( size->face == req->face &&
|
|
|
|
size->metrics.x_ppem == req->width &&
|
|
|
|
size->metrics.y_ppem == req->height );
|
2000-08-23 19:32:42 +02:00
|
|
|
}
|
2000-08-23 13:22:30 +02:00
|
|
|
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_CALLBACK_TABLE_DEF
|
|
|
|
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-10-12 07:05:40 +02:00
|
|
|
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_CALLBACK_TABLE_DEF
|
|
|
|
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-11-04 02:55:49 +01:00
|
|
|
FT_EXPORT_DEF( FT_Error ) FTC_Manager_New( FT_Library library,
|
|
|
|
FT_UInt max_faces,
|
|
|
|
FT_UInt max_sizes,
|
|
|
|
FT_ULong max_bytes,
|
|
|
|
FTC_Face_Requester requester,
|
|
|
|
FT_Pointer req_data,
|
2000-11-07 07:30:29 +01: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-10-12 07:05:40 +02:00
|
|
|
|
|
|
|
|
2000-08-24 18:29:15 +02:00
|
|
|
if ( !library )
|
Complete redesign of error codes. Please check ftmoderr.h for more
details.
* include/freetype/internal/cfferrs.h,
include/freetype/internal/tterrors.h,
include/freetype/internal/t1errors.h: Removed. Replaced with files
local to the module. All extra error codes have been moved to
`fterrors.h'.
* src/sfnt/ttpost.h: Move error codes to `fterrors.h'.
* src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h,
src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h,
src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h,
src/smooth/ftsmerrs.h, src/truetype/tterrors.h,
src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the
error names for the module it belongs to.
* include/freetype/ftmoderr.h: New file, defining the module error
offsets. Its structure is similar to `fterrors.h'.
* include/freetype/fterrors.h (FT_NOERRORDEF): New macro.
(FT_ERRORDEF): Redefined to use module error offsets.
All internal error codes are now public; unused error codes have
been removed, some are new.
* include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New
macro.
* include/freetype/config/ftoption.h
(FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro.
All other source files have been updated to use the new error codes;
some already existing (internal) error codes local to a module have
been renamed to give them the same name as in the base module.
All make files have been updated to include the local error files.
* src/cid/cidtokens.h: Replaced with...
* src/cid/cidtoken.h: This file for 8+3 consistency.
* src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
|
|
|
return FTC_Err_Invalid_Library_Handle;
|
2000-08-24 18:29:15 +02:00
|
|
|
|
|
|
|
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-10-12 07:05:40 +02:00
|
|
|
|
2000-08-24 18:29:15 +02:00
|
|
|
if ( max_faces == 0 )
|
2000-09-19 03:11:11 +02:00
|
|
|
max_faces = FTC_MAX_FACES_DEFAULT;
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-08-24 18:29:15 +02:00
|
|
|
if ( max_sizes == 0 )
|
2000-09-19 03:11:11 +02:00
|
|
|
max_sizes = FTC_MAX_SIZES_DEFAULT;
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
if ( max_bytes == 0 )
|
|
|
|
max_bytes = FTC_MAX_BYTES_DEFAULT;
|
2000-10-12 07:05:40 +02:00
|
|
|
|
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;
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
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 */
|
2000-10-12 07:05:40 +02:00
|
|
|
(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;
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
manager->library = library;
|
2000-09-19 03:11:11 +02:00
|
|
|
manager->max_bytes = max_bytes;
|
2000-08-23 13:22:30 +02:00
|
|
|
manager->request_face = requester;
|
|
|
|
manager->request_data = req_data;
|
|
|
|
*amanager = manager;
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
Exit:
|
2000-08-23 19:32:42 +02:00
|
|
|
if ( error && manager )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
|
|
|
FT_Lru_Done( manager->faces_lru );
|
2000-12-06 00:07:16 +01:00
|
|
|
FT_Lru_Done( manager->sizes_lru );
|
2000-08-23 13:22:30 +02:00
|
|
|
FREE( manager );
|
|
|
|
}
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
return error;
|
|
|
|
}
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
|
2000-11-29 18:48:57 +01: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-09-19 03:11:11 +02:00
|
|
|
FT_UInt index;
|
2000-10-12 07:05:40 +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-09-19 03:11:11 +02:00
|
|
|
/* now discard all caches */
|
|
|
|
for (index = 0; index < FTC_MAX_CACHES; index++ )
|
|
|
|
{
|
|
|
|
FTC_Cache cache = manager->caches[index];
|
2000-10-12 07:05:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
if ( cache )
|
2000-09-19 03:11:11 +02:00
|
|
|
{
|
|
|
|
cache->clazz->done_cache( cache );
|
2000-10-12 07:05:40 +02:00
|
|
|
FREE( cache );
|
2000-09-19 03:11:11 +02:00
|
|
|
manager->caches[index] = 0;
|
|
|
|
}
|
|
|
|
}
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
/* discard faces and sizes */
|
2000-08-23 13:22:30 +02:00
|
|
|
FT_Lru_Done( manager->faces_lru );
|
2000-12-05 23:23:12 +01:00
|
|
|
manager->faces_lru = 0;
|
|
|
|
|
|
|
|
FT_Lru_Done( manager->sizes_lru );
|
2000-12-06 00:07:16 +01:00
|
|
|
manager->sizes_lru = 0;
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-08-23 13:22:30 +02:00
|
|
|
FREE( manager );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-29 18:48:57 +01:00
|
|
|
FT_EXPORT_DEF( void ) FTC_Manager_Reset( FTC_Manager manager )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
2000-09-19 03:11:11 +02:00
|
|
|
if (manager )
|
|
|
|
{
|
|
|
|
FT_Lru_Reset( manager->sizes_lru );
|
|
|
|
FT_Lru_Reset( manager->faces_lru );
|
|
|
|
}
|
2000-10-31 23:13:54 +01:00
|
|
|
/* XXX: FIXME: flush the caches? */
|
2000-08-23 13:22:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-29 18:48:57 +01: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 )
|
Complete redesign of error codes. Please check ftmoderr.h for more
details.
* include/freetype/internal/cfferrs.h,
include/freetype/internal/tterrors.h,
include/freetype/internal/t1errors.h: Removed. Replaced with files
local to the module. All extra error codes have been moved to
`fterrors.h'.
* src/sfnt/ttpost.h: Move error codes to `fterrors.h'.
* src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h,
src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h,
src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h,
src/smooth/ftsmerrs.h, src/truetype/tterrors.h,
src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the
error names for the module it belongs to.
* include/freetype/ftmoderr.h: New file, defining the module error
offsets. Its structure is similar to `fterrors.h'.
* include/freetype/fterrors.h (FT_NOERRORDEF): New macro.
(FT_ERRORDEF): Redefined to use module error offsets.
All internal error codes are now public; unused error codes have
been removed, some are new.
* include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New
macro.
* include/freetype/config/ftoption.h
(FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro.
All other source files have been updated to use the new error codes;
some already existing (internal) error codes local to a module have
been renamed to give them the same name as in the base module.
All make files have been updated to include the local error files.
* src/cid/cidtokens.h: Replaced with...
* src/cid/cidtoken.h: This file for 8+3 consistency.
* src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
|
|
|
return FTC_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-10-12 07:05:40 +02:00
|
|
|
(FT_LruKey)face_id,
|
2000-08-23 19:32:42 +02:00
|
|
|
(FT_Pointer*)aface );
|
2000-08-23 13:22:30 +02:00
|
|
|
}
|
2000-09-19 03:11:11 +02:00
|
|
|
|
|
|
|
|
2000-11-29 18:48:57 +01:00
|
|
|
FT_EXPORT_DEF( FT_Error ) FTC_Manager_Lookup_Size( FTC_Manager manager,
|
|
|
|
FTC_Font font,
|
|
|
|
FT_Face *aface,
|
|
|
|
FT_Size *asize )
|
2000-08-23 13:22:30 +02:00
|
|
|
{
|
2000-09-19 03:11:11 +02:00
|
|
|
FTC_FontRequest req;
|
2000-08-23 13:22:30 +02:00
|
|
|
FT_Error error;
|
2000-10-12 07:05:40 +02:00
|
|
|
|
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-10-12 07:05:40 +02:00
|
|
|
|
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-10-12 07:05:40 +02:00
|
|
|
error = FTC_Manager_Lookup_Face( manager, font->face_id, aface );
|
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-10-12 07:05:40 +02:00
|
|
|
|
2000-08-24 18:29:15 +02:00
|
|
|
|
2000-10-12 02:28:00 +02:00
|
|
|
req.face = *aface;
|
2000-09-19 03:11:11 +02:00
|
|
|
req.width = font->pix_width;
|
|
|
|
req.height = font->pix_height;
|
2000-10-12 07:05:40 +02:00
|
|
|
|
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-10-12 07:05:40 +02:00
|
|
|
(*aface)->size = size;
|
|
|
|
|
2000-08-24 18:29:15 +02:00
|
|
|
if ( asize )
|
2000-08-23 23:11:13 +02:00
|
|
|
*asize = size;
|
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-10-12 07:05:40 +02:00
|
|
|
/* `Compress' the manager's data, i.e., get rid of old cache nodes */
|
2000-09-19 03:11:11 +02:00
|
|
|
/* that are not referenced anymore in order to limit the total */
|
2000-10-12 07:05:40 +02:00
|
|
|
/* memory used by the cache. */
|
2000-11-04 02:55:49 +01:00
|
|
|
FT_EXPORT_DEF( void ) FTC_Manager_Compress( FTC_Manager manager )
|
2000-09-19 03:11:11 +02:00
|
|
|
{
|
|
|
|
FT_ListNode node;
|
2000-10-12 07:05:40 +02:00
|
|
|
|
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
node = manager->global_lru.tail;
|
2000-10-12 07:05:40 +02:00
|
|
|
while ( manager->num_bytes > manager->max_bytes && node )
|
2000-09-19 03:11:11 +02:00
|
|
|
{
|
2000-10-12 07:05:40 +02:00
|
|
|
FTC_CacheNode cache_node = FTC_LIST_TO_CACHENODE( node );
|
|
|
|
FTC_CacheNode_Data* data = FTC_CACHENODE_TO_DATA_P( cache_node );
|
2000-09-19 03:11:11 +02:00
|
|
|
FTC_Cache cache;
|
|
|
|
FT_ListNode prev = node->prev;
|
2000-10-12 07:05:40 +02:00
|
|
|
|
|
|
|
|
|
|
|
if ( data->ref_count <= 0 )
|
2000-09-19 03:11:11 +02:00
|
|
|
{
|
2000-10-12 07:05:40 +02:00
|
|
|
/* ok, we are going to remove this node */
|
2000-09-19 03:11:11 +02:00
|
|
|
FT_List_Remove( &manager->global_lru, node );
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
/* finalize cache node */
|
|
|
|
cache = manager->caches[data->cache_index];
|
2000-10-12 07:05:40 +02:00
|
|
|
if ( cache )
|
2000-09-19 03:11:11 +02:00
|
|
|
{
|
|
|
|
FTC_CacheNode_Class* clazz = cache->node_clazz;
|
2000-10-12 07:05:40 +02:00
|
|
|
|
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
manager->num_bytes -= clazz->size_node( cache_node,
|
2000-10-29 01:34:45 +02:00
|
|
|
cache->cache_data );
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-10-29 01:34:45 +02:00
|
|
|
clazz->destroy_node( cache_node, cache->cache_data );
|
2000-09-19 03:11:11 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-12 07:05:40 +02:00
|
|
|
/* this should never happen! */
|
|
|
|
FT_ERROR(( "FTC_Manager_Compress: Cache Manager is corrupted!\n" ));
|
2000-09-19 03:11:11 +02:00
|
|
|
}
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-10-29 01:34:45 +02:00
|
|
|
/* check, just in case of general corruption :-) */
|
2000-10-31 23:13:54 +01:00
|
|
|
if ( manager->num_nodes <= 0 )
|
|
|
|
FT_ERROR(( "FTC_Manager_Compress: Invalid cache node count!\n" ));
|
2000-10-29 01:34:45 +02:00
|
|
|
else
|
|
|
|
manager->num_nodes--;
|
2000-09-19 03:11:11 +02:00
|
|
|
}
|
|
|
|
node = prev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-29 18:48:57 +01:00
|
|
|
FT_EXPORT_DEF( FT_Error ) FTC_Manager_Register_Cache(
|
|
|
|
FTC_Manager manager,
|
|
|
|
FTC_Cache_Class* clazz,
|
|
|
|
FTC_Cache *acache )
|
2000-09-19 03:11:11 +02:00
|
|
|
{
|
Complete redesign of error codes. Please check ftmoderr.h for more
details.
* include/freetype/internal/cfferrs.h,
include/freetype/internal/tterrors.h,
include/freetype/internal/t1errors.h: Removed. Replaced with files
local to the module. All extra error codes have been moved to
`fterrors.h'.
* src/sfnt/ttpost.h: Move error codes to `fterrors.h'.
* src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h,
src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h,
src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h,
src/smooth/ftsmerrs.h, src/truetype/tterrors.h,
src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the
error names for the module it belongs to.
* include/freetype/ftmoderr.h: New file, defining the module error
offsets. Its structure is similar to `fterrors.h'.
* include/freetype/fterrors.h (FT_NOERRORDEF): New macro.
(FT_ERRORDEF): Redefined to use module error offsets.
All internal error codes are now public; unused error codes have
been removed, some are new.
* include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New
macro.
* include/freetype/config/ftoption.h
(FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro.
All other source files have been updated to use the new error codes;
some already existing (internal) error codes local to a module have
been renamed to give them the same name as in the base module.
All make files have been updated to include the local error files.
* src/cid/cidtokens.h: Replaced with...
* src/cid/cidtoken.h: This file for 8+3 consistency.
* src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
|
|
|
FT_Error error = FTC_Err_Invalid_Argument;
|
2000-10-12 07:05:40 +02:00
|
|
|
|
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
if ( manager && clazz && acache )
|
|
|
|
{
|
|
|
|
FT_Memory memory = manager->library->memory;
|
|
|
|
FTC_Cache cache;
|
|
|
|
FT_UInt index = 0;
|
|
|
|
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
/* by default, return 0 */
|
|
|
|
*acache = 0;
|
|
|
|
|
|
|
|
/* check for an empty cache slot in the manager's table */
|
|
|
|
for ( index = 0; index < FTC_MAX_CACHES; index++ )
|
|
|
|
{
|
|
|
|
if ( manager->caches[index] == 0 )
|
|
|
|
break;
|
|
|
|
}
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
/* return an error if there are too many registered caches */
|
2000-10-12 07:05:40 +02:00
|
|
|
if ( index >= FTC_MAX_CACHES )
|
2000-09-19 03:11:11 +02:00
|
|
|
{
|
Complete redesign of error codes. Please check ftmoderr.h for more
details.
* include/freetype/internal/cfferrs.h,
include/freetype/internal/tterrors.h,
include/freetype/internal/t1errors.h: Removed. Replaced with files
local to the module. All extra error codes have been moved to
`fterrors.h'.
* src/sfnt/ttpost.h: Move error codes to `fterrors.h'.
* src/autohint/aherrors.h, src/cache/ftcerror.h, src/cff/cfferrs.h,
src/cid/ciderrs.h, src/pcf/pcferror.h, src/psaux/psauxerr.h,
src/psnames/psnamerr.h, src/raster/rasterrs.h, src/sfnt/sferrors.h,
src/smooth/ftsmerrs.h, src/truetype/tterrors.h,
src/type1/t1errors.h, src/winfonts/fnterrs.h: New files defining the
error names for the module it belongs to.
* include/freetype/ftmoderr.h: New file, defining the module error
offsets. Its structure is similar to `fterrors.h'.
* include/freetype/fterrors.h (FT_NOERRORDEF): New macro.
(FT_ERRORDEF): Redefined to use module error offsets.
All internal error codes are now public; unused error codes have
been removed, some are new.
* include/freetype/config/ftheader.h (FT_MODULE_ERRORS_H): New
macro.
* include/freetype/config/ftoption.h
(FT_CONFIG_OPTION_USE_MODULE_ERRORS): New macro.
All other source files have been updated to use the new error codes;
some already existing (internal) error codes local to a module have
been renamed to give them the same name as in the base module.
All make files have been updated to include the local error files.
* src/cid/cidtokens.h: Replaced with...
* src/cid/cidtoken.h: This file for 8+3 consistency.
* src/raster/ftraster.c: Use macros for header file names.
2001-06-06 19:30:41 +02:00
|
|
|
error = FTC_Err_Too_Many_Caches;
|
2000-09-19 03:11:11 +02:00
|
|
|
FT_ERROR(( "FTC_Manager_Register_Cache:" ));
|
2000-10-12 07:05:40 +02:00
|
|
|
FT_ERROR(( " too many registered caches\n" ));
|
2000-09-19 03:11:11 +02:00
|
|
|
goto Exit;
|
|
|
|
}
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
if ( !ALLOC( cache, clazz->cache_byte_size ) )
|
|
|
|
{
|
|
|
|
cache->manager = manager;
|
|
|
|
cache->memory = memory;
|
|
|
|
cache->clazz = clazz;
|
2000-10-31 21:42:18 +01:00
|
|
|
|
2000-10-31 23:13:54 +01:00
|
|
|
/* THIS IS VERY IMPORTANT! IT WILL WRETCH THE MANAGER */
|
|
|
|
/* IF IT IS NOT SET CORRECTLY */
|
2000-10-31 11:58:23 +01:00
|
|
|
cache->cache_index = index;
|
2000-09-19 03:11:11 +02:00
|
|
|
|
2000-10-12 07:05:40 +02:00
|
|
|
if ( clazz->init_cache )
|
2000-09-19 03:11:11 +02:00
|
|
|
error = clazz->init_cache( cache );
|
2000-10-12 07:05:40 +02:00
|
|
|
|
|
|
|
if ( error )
|
|
|
|
FREE( cache );
|
2000-09-19 03:11:11 +02:00
|
|
|
else
|
2000-10-12 07:05:40 +02:00
|
|
|
manager->caches[index] = *acache = cache;
|
2000-09-19 03:11:11 +02:00
|
|
|
}
|
|
|
|
}
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-09-19 03:11:11 +02:00
|
|
|
Exit:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2000-10-12 07:05:40 +02:00
|
|
|
|
2000-08-23 19:32:42 +02:00
|
|
|
/* END */
|