From 9b11b9e3e42c68070aba0f02a50da0d12aca4038 Mon Sep 17 00:00:00 2001 From: David Turner Date: Fri, 15 Sep 2000 22:50:59 +0000 Subject: [PATCH] adding updated cache header files --- include/freetype/cache/ftcglyph.h | 211 ++++++++++++++++++++++++++++ include/freetype/config/ftoption.h | 4 +- include/freetype/ftcache.h | 64 ++++----- include/freetype/fterrors.h | 5 + include/freetype/internal/ftdebug.h | 3 + 5 files changed, 253 insertions(+), 34 deletions(-) create mode 100644 include/freetype/cache/ftcglyph.h diff --git a/include/freetype/cache/ftcglyph.h b/include/freetype/cache/ftcglyph.h new file mode 100644 index 000000000..621ee93aa --- /dev/null +++ b/include/freetype/cache/ftcglyph.h @@ -0,0 +1,211 @@ +/***************************************************************************/ +/* */ +/* ftcglyph.h */ +/* */ +/* FreeType glyph image (FT_Glyph) cache.. */ +/* */ +/* 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. */ +/* */ +/* */ +/* 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.. */ +/* */ +/***************************************************************************/ + + /**************************************************************************/ + /**************************************************************************/ + /**************************************************************************/ + /**************************************************************************/ + /**************************************************************************/ + /********* **********/ + /********* **********/ + /********* WARNING, THIS IS ALPHA CODE, THIS API **********/ + /********* IS DUE TO CHANGE UNTIL STRICTLY NOTIFIED BY THE **********/ + /********* FREETYPE DEVELOPMENT TEAM **********/ + /********* **********/ + /**************************************************************************/ + /**************************************************************************/ + /**************************************************************************/ + /**************************************************************************/ + /**************************************************************************/ + + +#ifndef FTCGLYPH_H +#define FTCGLYPH_H + +#include +#include +#include + +#ifdef __cplusplus + extern "C" { +#endif + +/* maximum number of queues per image cache, must be < 256 */ +#define FTC_MAX_GLYPH_QUEUES 16 + +#define FTC_QUEUE_HASH_SIZE_DEFAULT 64 + + typedef struct FTC_Glyph_QueueRec_* FTC_Glyph_Queue; + typedef struct FTC_GlyphNodeRec_* FTC_GlyphNode; + typedef struct FTC_Glyph_CacheRec_* FTC_Glyph_Cache; + + typedef struct FTC_GlyphNodeRec_ + { + FTC_CacheNodeRec root; + + /* link.data contains a handle to a FT_Glyph object */ + FT_ListNodeRec link; + + FT_UShort glyph_index; + FT_UShort queue_index; + + } FTC_GlyphNodeRec; + + +#define FTC_GLYPHNODE_GET_GLYPH(n) ((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 */ + /* corresponding to a given image node */ +#define FTC_GLYPHNODE_TO_LISTNODE( n ) \ + ( (FT_ListNode)&(n)->link ) + + /* 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.. */ +#define FTC_LISTNODE_TO_GLYPHNODE( p ) \ + ( (FTC_GlyphNode)( (char*)(p) - \ + offsetof( FTC_GlyphNodeRec,link ) ) ) + +#define FTC_GLYPHNODE_TO_LRUNODE(n) ((FT_ListNode)(n)) +#define FTC_LRUNODE_TO_GLYPHNODE(n) ((FTC_GlyphNode)(n)) + + + /* glyph queue methods *****************************************************/ + + typedef FT_Error (*FTC_Glyph_Queue_InitFunc) ( FTC_Glyph_Queue queue, + FT_Pointer type ); + + typedef void (*FTC_Glyph_Queue_DoneFunc) ( FTC_Glyph_Queue queue ); + + typedef FT_Bool (*FTC_Glyph_Queue_CompareFunc)( FTC_Glyph_Queue queue, + FT_Pointer type ); + + typedef FT_Error (*FTC_Glyph_Queue_NewNodeFunc)( FTC_Glyph_Queue queue, + FT_UInt gindex, + FTC_GlyphNode *anode ); + + typedef void (*FTC_Glyph_Queue_DestroyNodeFunc)( FTC_GlyphNode node, + FTC_Glyph_Queue queue ); + + + typedef FT_ULong (*FTC_Glyph_Queue_SizeNodeFunc)( FTC_GlyphNode node, + FTC_Glyph_Queue queue ); + + typedef struct FTC_Glyph_Queue_Class_ + { + FT_UInt queue_byte_size; + + FTC_Glyph_Queue_InitFunc init; + FTC_Glyph_Queue_DoneFunc done; + FTC_Glyph_Queue_CompareFunc compare; + + FTC_Glyph_Queue_NewNodeFunc new_node; + FTC_Glyph_Queue_SizeNodeFunc size_node; + FTC_Glyph_Queue_DestroyNodeFunc destroy_node; + + } FTC_Glyph_Queue_Class; + + + typedef struct FTC_Glyph_QueueRec_ + { + FTC_Glyph_Cache cache; + FTC_Manager manager; + FT_Memory memory; + FTC_Glyph_Queue_Class* clazz; + FTC_Image_Desc descriptor; + FT_UInt hash_size; + FT_List buckets; + FT_UInt queue_index; /* index in parent cache */ + + } FTC_Glyph_QueueRec; + + + /* the abstract glyph cache class */ + typedef struct FTC_Glyph_Cache_Class_ + { + FTC_Cache_Class root; + FTC_Glyph_Queue_Class* queue_class; + + } FTC_Glyph_Cache_Class; + + + /* the abstract glyph cache object */ + typedef struct FTC_Glyph_CacheRec_ + { + FTC_CacheRec root; + FT_Lru queues_lru; /* static queues lru list */ + FTC_Glyph_Queue last_queue; /* small cache */ + + } FTC_Glyph_CacheRec; + + + /* these function are exported so that they can be called from */ + /* user-provided cache classes.. otherwise, they're really */ + /* pars of the cache sub-system internals.. */ + /* */ + + FT_EXPORT_FUNC(void) FTC_GlyphNode_Init( FTC_GlyphNode node, + FTC_Glyph_Queue queue, + FT_UInt gindex ); + +#define FTC_GlyphNode_Ref(n) \ + FTC_CACHENODE_TO_DATA_P(&(n)->root)->ref_count++ + +#define FTC_GlyphNode_Unref(n) \ + FTC_CACHENODE_TO_DATA_P(&(n)->root)->ref_count-- + + + FT_EXPORT_DEF(void) FTC_Destroy_Glyph_Node( FTC_GlyphNode node, + 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(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(void) FTC_Glyph_Cache_Done( FTC_Glyph_Cache cache ); + +#ifdef __cplusplus + } +#endif + + +#endif /* FTCIMAGE_H */ + + +/* END */ diff --git a/include/freetype/config/ftoption.h b/include/freetype/config/ftoption.h index 11553a34a..7474a55ea 100644 --- a/include/freetype/config/ftoption.h +++ b/include/freetype/config/ftoption.h @@ -220,7 +220,7 @@ /* */ /* This must be greater than 4kByte. */ /* */ -#define FT_RENDER_POOL_SIZE 16384 +#define FT_RENDER_POOL_SIZE 32768 /*************************************************************************/ @@ -310,7 +310,7 @@ /* By undefining this, you will only compile the code necessary to load */ /* TrueType glyphs without hinting. */ /* */ -#undef TT_CONFIG_OPTION_BYTECODE_INTERPRETER +#define TT_CONFIG_OPTION_BYTECODE_INTERPRETER /*************************************************************************/ diff --git a/include/freetype/ftcache.h b/include/freetype/ftcache.h index ae1dc19fd..4baa058e8 100644 --- a/include/freetype/ftcache.h +++ b/include/freetype/ftcache.h @@ -98,11 +98,12 @@ /*************************************************************************/ /* */ /* */ - /* FTC_SizeRec */ + /* FTC_FontRec */ /* */ /* */ - /* A simple structure used to describe a given `font size' to the */ - /* cache manager. */ + /* A simple structure used to describe a given `font' to the cache */ + /* manager. Note that a "font" is the combination of a given face */ + /* with a given character size.. */ /* */ /* */ /* face_id :: The ID of the face to use. */ @@ -111,24 +112,24 @@ /* */ /* pix_height :: The character height in integer pixels. */ /* */ - typedef struct FTC_SizeRec_ + typedef struct FTC_FontRec_ { FTC_FaceID face_id; FT_UShort pix_width; FT_UShort pix_height; - } FTC_SizeRec; + } FTC_FontRec; /*************************************************************************/ /* */ /* */ - /* FTC_SizeID */ + /* FTC_Font */ /* */ /* */ - /* A simple handle to a FTC_SizeRec structure. */ + /* A simple handle to a FTC_FontRec structure. */ /* */ - typedef FTC_SizeRec* FTC_SizeID; + typedef FTC_FontRec* FTC_Font; /*************************************************************************/ @@ -171,6 +172,9 @@ /* max_sizes :: Maximum number of sizes to keep alive in manager. */ /* Use 0 for defaults. */ /* */ + /* max_bytes :: Maximum number of bytes to use for cached data. */ + /* Use 0 for defaults. */ + /* */ /* requester :: An application-provided callback used to translate */ /* face IDs into real FT_Face objects. */ /* */ @@ -187,6 +191,7 @@ 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, FTC_Manager* amanager ); @@ -298,10 +303,23 @@ /* that you can call FT_Load_Glyph() with the face if you need to. */ /* */ FT_EXPORT_DEF( FT_Error ) FTC_Manager_Lookup_Size( FTC_Manager manager, - FTC_SizeID size_id, + FTC_Font font, FT_Face* aface, FT_Size* asize ); + + /* a cache class is used to describe a unique cache type to the */ + /* manager.. */ + typedef struct FTC_Cache_Class_ FTC_Cache_Class; + typedef struct FTC_CacheRec_* FTC_Cache; + + + /* this must be used internally for the moment */ + FT_EXPORT_DEF( FT_Error ) FTC_Manager_Register_Cache( + FTC_Manager manager, + FTC_Cache_Class* clazz, + FTC_Cache *acache ); + /*************************************************************************/ /*************************************************************************/ @@ -349,12 +367,12 @@ ftc_image_flag_unscaled = 128, ftc_image_flag_no_sbits = 256, - ftc_image_mono = ftc_image_format_bitmap | - ftc_image_flag_monochrome, /* monochrome bitmap */ + ftc_image_mono = ftc_image_format_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; @@ -375,7 +393,7 @@ /* */ typedef struct FTC_Image_Desc_ { - FTC_SizeRec size; + FTC_FontRec font; FT_UInt image_type; } FTC_Image_Desc; @@ -405,9 +423,6 @@ /* */ /* manager :: The parent manager for the image cache. */ /* */ - /* max_bytes :: The maximum amount of memory that will be used to */ - /* store glyph images. */ - /* */ /* */ /* acache :: A handle to the new glyph image cache object. */ /* */ @@ -415,24 +430,9 @@ /* FreeType error code. 0 means success. */ /* */ FT_EXPORT_DEF( FT_Error ) FTC_Image_Cache_New( FTC_Manager manager, - FT_ULong max_bytes, FTC_Image_Cache* acache ); - /*************************************************************************/ - /* */ - /* */ - /* FTC_Image_Cache_Done */ - /* */ - /* */ - /* Destroys a given glyph image cache (and all glyphs within it). */ - /* */ - /* */ - /* manager :: The parent manager for the image cache. */ - /* */ - FT_EXPORT_DEF( void ) FTC_Image_Cache_Done( FTC_Image_Cache cache ); - - /*************************************************************************/ /* */ /* */ diff --git a/include/freetype/fterrors.h b/include/freetype/fterrors.h index 4dda5163c..94d3e97c1 100644 --- a/include/freetype/fterrors.h +++ b/include/freetype/fterrors.h @@ -163,6 +163,11 @@ FT_ERRORDEF( FT_Err_Raster_Negative_Height, 0x0063, \ "negative height while rastering" ) + /* cache errors */ + + FT_ERRORDEF( FT_Err_Too_Many_Caches, 0x0070, \ + "too many registered caches" ) + /* range 0x400 - 0x4FF is reserved for TrueType specific stuff */ /* range 0x500 - 0x5FF is reserved for CFF specific stuff */ diff --git a/include/freetype/internal/ftdebug.h b/include/freetype/internal/ftdebug.h index c70b7e881..c3648922f 100644 --- a/include/freetype/internal/ftdebug.h +++ b/include/freetype/internal/ftdebug.h @@ -63,6 +63,9 @@ trace_raster, /* rasterizer (ftraster.c) */ trace_stream, /* stream manager (ftstream.c) */ + /* Cache sub-system */ + trace_cache, + /* SFNT driver components */ trace_sfobjs, /* SFNT object handler (sfobjs.c) */ trace_ttcmap, /* charmap handler (ttcmap.c) */