From ab8552321c70e947fedfd31709c43c4cb27d496f Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Tue, 31 Oct 2000 22:13:54 +0000 Subject: [PATCH] Fixing include header for a `make multi' build. Finishing formatting of cache stuff. Fixed getDriverClass stuff -- added it to winfnt.c also. Note that this still has to be documented. --- include/freetype/cache/ftcsbits.h | 1 + src/cache/ftcchunk.c | 126 +++++++-------- src/cache/ftcglyph.c | 72 ++++----- src/cache/ftcimage.c | 47 +++--- src/cache/ftcmanag.c | 14 +- src/cache/ftcsbits.c | 251 +++++++++++++++++------------- src/cache/ftlru.c | 5 +- src/cff/t2driver.c | 2 +- src/cid/cidriver.c | 2 +- src/truetype/ttdriver.c | 4 +- src/type1/t1driver.c | 23 ++- src/winfonts/winfnt.c | 31 ++++ 12 files changed, 331 insertions(+), 247 deletions(-) diff --git a/include/freetype/cache/ftcsbits.h b/include/freetype/cache/ftcsbits.h index bc10fed1a..9266c8601 100644 --- a/include/freetype/cache/ftcsbits.h +++ b/include/freetype/cache/ftcsbits.h @@ -21,6 +21,7 @@ #include +#include #ifdef __cplusplus diff --git a/src/cache/ftcchunk.c b/src/cache/ftcchunk.c index 334718260..7252dcc9d 100644 --- a/src/cache/ftcchunk.c +++ b/src/cache/ftcchunk.c @@ -22,6 +22,7 @@ #include #include + /*************************************************************************/ /*************************************************************************/ /***** *****/ @@ -31,55 +32,55 @@ /*************************************************************************/ - /* create a new chunk node, setting its cache index and ref count */ - FT_EXPORT_FUNC( FT_Error ) - FTC_ChunkNode_Init( FTC_ChunkNode node, - FTC_ChunkSet cset, - FT_UInt index, - FT_Bool alloc ) + FT_EXPORT_FUNC( FT_Error ) FTC_ChunkNode_Init( FTC_ChunkNode node, + FTC_ChunkSet cset, + FT_UInt index, + FT_Bool alloc ) { FTC_Chunk_Cache cache = cset->cache; FTC_CacheNode_Data* data = FTC_CACHENODE_TO_DATA_P( &node->root ); FT_Error error = 0; - data->cache_index = (FT_UShort) cache->root.cache_index; - data->ref_count = (FT_Short) 0; + data->cache_index = (FT_UShort)cache->root.cache_index; + data->ref_count = (FT_Short) 0; node->cset = cset; - node->cset_index = (FT_UShort) index; - node->num_elements = (index+1 < cset->num_chunks) - ? cset->element_count - : cset->element_max - cset->element_count*index; - if (alloc) + node->cset_index = (FT_UShort)index; + node->num_elements = ( index + 1 < cset->num_chunks ) + ? cset->element_count + : cset->element_max - cset->element_count*index; + if ( alloc ) { /* allocate elements array */ FT_Memory memory; memory = cache->root.memory; - error = MEM_Alloc( node->elements, cset->element_size * - cset->element_count ); + error = MEM_Alloc( node->elements, + cset->element_size * cset->element_count ); } + return error; } - FT_EXPORT_FUNC( void ) FTC_ChunkNode_Destroy( FTC_ChunkNode node ) + FT_EXPORT_FUNC( void ) FTC_ChunkNode_Destroy( FTC_ChunkNode node ) { - FTC_ChunkSet cset = node->cset; + FTC_ChunkSet cset = node->cset; + /* remove from parent set table */ - cset->chunks[ node->cset_index ] = 0; + cset->chunks[node->cset_index] = 0; /* destroy the node */ cset->clazz->destroy_node( node ); } - FT_EXPORT_FUNC( FT_ULong ) FTC_ChunkNode_Size( FTC_ChunkNode node ) + FT_EXPORT_FUNC( FT_ULong ) FTC_ChunkNode_Size( FTC_ChunkNode node ) { - FTC_ChunkSet cset = node->cset; + FTC_ChunkSet cset = node->cset; return cset->clazz->size_node( node ); @@ -88,8 +89,8 @@ FT_CPLUSPLUS( const FTC_CacheNode_Class ) ftc_chunk_cache_node_class = { - (FTC_CacheNode_SizeFunc) FTC_ChunkNode_Size, - (FTC_CacheNode_DestroyFunc) FTC_ChunkNode_Destroy + (FTC_CacheNode_SizeFunc) FTC_ChunkNode_Size, + (FTC_CacheNode_DestroyFunc)FTC_ChunkNode_Destroy }; @@ -102,10 +103,9 @@ /*************************************************************************/ - FT_EXPORT_FUNC( FT_Error ) - FTC_ChunkSet_New( FTC_Chunk_Cache cache, - FT_Pointer type, - FTC_ChunkSet *aset ) + FT_EXPORT_FUNC( FT_Error ) FTC_ChunkSet_New( FTC_Chunk_Cache cache, + FT_Pointer type, + FTC_ChunkSet* aset ) { FT_Error error; FT_Memory memory = cache->root.memory; @@ -124,19 +124,19 @@ if ( ALLOC( cset, clazz->cset_byte_size ) ) goto Exit; - cset->cache = cache; - cset->manager = manager; - cset->memory = memory; - cset->clazz = clazz; + cset->cache = cache; + cset->manager = manager; + cset->memory = memory; + cset->clazz = clazz; /* now compute element_max, element_count and element_size */ - error = clazz->sizes( cset, type); - if (error) + error = clazz->sizes( cset, type ); + if ( error ) goto Exit; /* compute maximum number of nodes */ - cset->num_chunks = (cset->element_max + - cset->element_count - 1) / cset->element_count; + cset->num_chunks = ( cset->element_max + cset->element_count - 1 ) / + cset->element_count; /* allocate chunk pointers table */ if ( ALLOC_ARRAY( cset->chunks, cset->num_chunks, FTC_ChunkNode ) ) @@ -165,26 +165,27 @@ FT_EXPORT_FUNC( void ) FTC_ChunkSet_Destroy( FTC_ChunkSet cset ) { - FTC_Chunk_Cache cache = cset->cache; - FTC_Manager manager = cache->root.manager; - FT_List glyphs_lru = &manager->global_lru; - FTC_ChunkNode* bucket = cset->chunks; - FTC_ChunkNode* bucket_limit = bucket + cset->num_chunks; - FT_Memory memory = cache->root.memory; + FTC_Chunk_Cache cache = cset->cache; + FTC_Manager manager = cache->root.manager; + FT_List glyphs_lru = &manager->global_lru; + FTC_ChunkNode* bucket = cset->chunks; + FTC_ChunkNode* bucket_limit = bucket + cset->num_chunks; + FT_Memory memory = cache->root.memory; - FTC_ChunkSet_Class* clazz = cset->clazz; + FTC_ChunkSet_Class* clazz = cset->clazz; /* for each bucket, free the list of glyph nodes */ for ( ; bucket < bucket_limit; bucket++ ) { - FTC_ChunkNode node = bucket[0]; - FT_ListNode lrunode; + FTC_ChunkNode node = bucket[0]; + FT_ListNode lrunode; + lrunode = FTC_CHUNKNODE_TO_LRUNODE( node ); manager->num_bytes -= clazz->size_node( node ); - manager->num_nodes --; + manager->num_nodes--; FT_List_Remove( glyphs_lru, lrunode ); @@ -201,32 +202,33 @@ } - FT_EXPORT_FUNC( FT_Error ) - FTC_ChunkSet_Lookup_Node( FTC_ChunkSet cset, - FT_UInt glyph_index, - FTC_ChunkNode *anode, - FT_UInt *aindex ) + FT_EXPORT_FUNC( FT_Error ) FTC_ChunkSet_Lookup_Node( + FTC_ChunkSet cset, + FT_UInt glyph_index, + FTC_ChunkNode* anode, + FT_UInt* aindex ) { - FTC_Chunk_Cache cache = cset->cache; - FTC_Manager manager = cache->root.manager; - FT_Error error = 0; + FTC_Chunk_Cache cache = cset->cache; + FTC_Manager manager = cache->root.manager; + FT_Error error = 0; - FTC_ChunkSet_Class* clazz = cset->clazz; + FTC_ChunkSet_Class* clazz = cset->clazz; *anode = 0; - if (glyph_index >= cset->element_max) + if ( glyph_index >= cset->element_max ) error = FT_Err_Invalid_Argument; else { FT_UInt chunk_size = cset->element_count; - FT_UInt chunk_index = glyph_index/chunk_size; + FT_UInt chunk_index = glyph_index / chunk_size; FTC_ChunkNode* pnode = cset->chunks + chunk_index; FTC_ChunkNode node = *pnode; - if (!node) + + if ( !node ) { - /* we didn't found the glyph image, we will now create a new one */ + /* we didn't found the glyph image; we will now create a new one */ error = clazz->new_node( cset, chunk_index, &node ); if ( error ) goto Exit; @@ -235,12 +237,13 @@ *pnode = node; /* insert the node at the start the global LRU glyph list */ - FT_List_Insert( &manager->global_lru, FTC_CHUNKNODE_TO_LRUNODE( node ) ); + FT_List_Insert( &manager->global_lru, + FTC_CHUNKNODE_TO_LRUNODE( node ) ); manager->num_bytes += clazz->size_node( node ); - manager->num_nodes ++; + manager->num_nodes++; - if (manager->num_bytes > manager->max_bytes) + if ( manager->num_bytes > manager->max_bytes ) { FTC_ChunkNode_Ref ( node ); FTC_Manager_Compress( manager ); @@ -249,7 +252,7 @@ } *anode = node; - *aindex = glyph_index - chunk_index*chunk_size; + *aindex = glyph_index - chunk_index * chunk_size; } Exit: @@ -369,3 +372,4 @@ } +/* END */ diff --git a/src/cache/ftcglyph.c b/src/cache/ftcglyph.c index 961f8406b..2cffa53be 100644 --- a/src/cache/ftcglyph.c +++ b/src/cache/ftcglyph.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include /*************************************************************************/ @@ -62,23 +62,25 @@ FTC_GlyphSet gset = (FTC_GlyphSet)gset_lru->root.data; FT_UInt hash = node->glyph_index % gset->hash_size; + /* remove the node from its gset's bucket list */ { FTC_GlyphNode* pnode = gset->buckets + hash; FTC_GlyphNode cur; + for (;;) { cur = *pnode; - if (!cur) + if ( !cur ) { - /* that's very strange, this should not happen !! */ + /* this should never happen */ FT_ERROR(( "FTC_GlyphNode_Destroy:" - " trying to delete an unlisted node !!!!" )); + " trying to delete an unlisted node!" )); return; } - if (cur == node) + if ( cur == node ) { *pnode = cur->gset_next; break; @@ -112,8 +114,8 @@ FT_CPLUSPLUS( const FTC_CacheNode_Class ) ftc_glyph_cache_node_class = { - (FTC_CacheNode_SizeFunc) FTC_GlyphNode_Size, - (FTC_CacheNode_DestroyFunc) FTC_GlyphNode_Destroy + (FTC_CacheNode_SizeFunc) FTC_GlyphNode_Size, + (FTC_CacheNode_DestroyFunc)FTC_GlyphNode_Destroy }; @@ -128,12 +130,12 @@ FT_EXPORT_FUNC( FT_Error ) FTC_GlyphSet_New( FTC_Glyph_Cache cache, FT_Pointer type, - FTC_GlyphSet *aset ) + FTC_GlyphSet* aset ) { - FT_Error error; - FT_Memory memory = cache->root.memory; - FTC_Manager manager = cache->root.manager; - FTC_GlyphSet gset = 0; + FT_Error error; + FT_Memory memory = cache->root.memory; + FTC_Manager manager = cache->root.manager; + FTC_GlyphSet gset = 0; FTC_Glyph_Cache_Class* gcache_class; FTC_GlyphSet_Class* clazz; @@ -180,14 +182,14 @@ FT_EXPORT_FUNC( void ) FTC_GlyphSet_Destroy( FTC_GlyphSet gset ) { - FTC_Glyph_Cache cache = gset->cache; - FTC_Manager manager = cache->root.manager; - FT_List glyphs_lru = &manager->global_lru; - FTC_GlyphNode* bucket = gset->buckets; - FTC_GlyphNode* bucket_limit = bucket + gset->hash_size; - FT_Memory memory = cache->root.memory; + FTC_Glyph_Cache cache = gset->cache; + FTC_Manager manager = cache->root.manager; + FT_List glyphs_lru = &manager->global_lru; + FTC_GlyphNode* bucket = gset->buckets; + FTC_GlyphNode* bucket_limit = bucket + gset->hash_size; + FT_Memory memory = cache->root.memory; - FTC_GlyphSet_Class* clazz = gset->clazz; + FTC_GlyphSet_Class* clazz = gset->clazz; /* for each bucket, free the list of glyph nodes */ @@ -204,7 +206,7 @@ lrunode = FTC_GLYPHNODE_TO_LRUNODE( node ); manager->num_bytes -= clazz->size_node( node, gset ); - manager->num_nodes --; + manager->num_nodes--; FT_List_Remove( glyphs_lru, lrunode ); @@ -222,20 +224,20 @@ } - FT_EXPORT_FUNC( FT_Error ) - FTC_GlyphSet_Lookup_Node( FTC_GlyphSet gset, - FT_UInt glyph_index, - FTC_GlyphNode *anode ) + FT_EXPORT_FUNC( FT_Error ) FTC_GlyphSet_Lookup_Node( + FTC_GlyphSet gset, + FT_UInt glyph_index, + FTC_GlyphNode* anode ) { - FTC_Glyph_Cache cache = gset->cache; - FTC_Manager manager = cache->root.manager; - FT_UInt hash_index = glyph_index % gset->hash_size; - FTC_GlyphNode* bucket = gset->buckets + hash_index; - FTC_GlyphNode* pnode = bucket; - FTC_GlyphNode node; - FT_Error error; + FTC_Glyph_Cache cache = gset->cache; + FTC_Manager manager = cache->root.manager; + FT_UInt hash_index = glyph_index % gset->hash_size; + FTC_GlyphNode* bucket = gset->buckets + hash_index; + FTC_GlyphNode* pnode = bucket; + FTC_GlyphNode node; + FT_Error error; - FTC_GlyphSet_Class* clazz = gset->clazz; + FTC_GlyphSet_Class* clazz = gset->clazz; *anode = 0; @@ -243,7 +245,7 @@ for ( ;; ) { node = *pnode; - if (!node) + if ( !node ) break; if ( node->glyph_index == glyph_index ) @@ -274,9 +276,9 @@ FT_List_Insert( &manager->global_lru, FTC_GLYPHNODE_TO_LRUNODE( node ) ); manager->num_bytes += clazz->size_node( node, gset ); - manager->num_nodes ++; + manager->num_nodes++; - if (manager->num_bytes > manager->max_bytes) + if ( manager->num_bytes > manager->max_bytes ) { FTC_GlyphNode_Ref ( node ); FTC_Manager_Compress( manager ); diff --git a/src/cache/ftcimage.c b/src/cache/ftcimage.c index dcc3c7b9e..6f1534727 100644 --- a/src/cache/ftcimage.c +++ b/src/cache/ftcimage.c @@ -19,14 +19,14 @@ #include #include -#include +#include /* memcmp() */ - /* the FT_Glyph image "glyph node" type */ + /* the FT_Glyph image `glyph node' type */ typedef struct FTC_GlyphImageRec_ { - FTC_GlyphNodeRec root; - FT_Glyph ft_glyph; + FTC_GlyphNodeRec root; + FT_Glyph ft_glyph; } FTC_GlyphImageRec, *FTC_GlyphImage; @@ -70,24 +70,24 @@ LOCAL_FUNC_X - FT_Error ftc_glyph_image_node_new( FTC_GlyphSet gset, - FT_UInt glyph_index, - FTC_GlyphImage *anode ) + FT_Error ftc_glyph_image_node_new( FTC_GlyphSet gset, + FT_UInt glyph_index, + FTC_GlyphImage* anode ) { - FT_Memory memory = gset->memory; - FTC_ImageSet imageset = (FTC_ImageSet)gset; - FT_Error error; - FTC_GlyphImage node = 0; - FT_Face face; - FT_Size size; + FT_Memory memory = gset->memory; + FTC_ImageSet imageset = (FTC_ImageSet)gset; + FT_Error error; + FTC_GlyphImage node = 0; + FT_Face face; + FT_Size size; /* allocate node */ if ( ALLOC( node, sizeof ( *node ) ) ) goto Exit; - /* init its inner fields */ - FTC_GlyphNode_Init( FTC_GLYPHNODE(node), gset, glyph_index ); + /* initialize its inner fields */ + FTC_GlyphNode_Init( FTC_GLYPHNODE( node ), gset, glyph_index ); /* we will now load the glyph image */ error = FTC_Manager_Lookup_Size( gset->manager, @@ -154,7 +154,7 @@ /* this function is important because it is both part of */ - /* a FTC_GlyphSet_Class and a FTC_CacheNode_Class */ + /* an FTC_GlyphSet_Class and an FTC_CacheNode_Class */ /* */ LOCAL_FUNC_X FT_ULong ftc_glyph_image_node_size( FTC_GlyphImage node ) @@ -262,17 +262,16 @@ FTC_Image_Cache* acache ) { return FTC_Manager_Register_Cache( - manager, - (FTC_Cache_Class*)&ftc_glyph_image_cache_class, - (FTC_Cache*)acache ); + manager, + (FTC_Cache_Class*)&ftc_glyph_image_cache_class, + (FTC_Cache*)acache ); } - FT_EXPORT_DEF( FT_Error ) - FTC_Image_Cache_Lookup( FTC_Image_Cache cache, - FTC_Image_Desc* desc, - FT_UInt gindex, - FT_Glyph* aglyph ) + FT_EXPORT_DEF( FT_Error ) FTC_Image_Cache_Lookup( FTC_Image_Cache cache, + FTC_Image_Desc* desc, + FT_UInt gindex, + FT_Glyph* aglyph ) { FT_Error error; FTC_GlyphSet gset; diff --git a/src/cache/ftcmanag.c b/src/cache/ftcmanag.c index ab70dd556..cbfdb1b9a 100644 --- a/src/cache/ftcmanag.c +++ b/src/cache/ftcmanag.c @@ -54,7 +54,7 @@ { /* destroy initial size object; it will be re-created later */ face = (FT_Face)node->root.data; - if (face->size) + if ( face->size ) FT_Done_Size( face->size ); } @@ -311,7 +311,7 @@ FT_Lru_Reset( manager->sizes_lru ); FT_Lru_Reset( manager->faces_lru ); } - /* FIXME: flush the caches ?? */ + /* XXX: FIXME: flush the caches? */ } @@ -413,10 +413,8 @@ } /* check, just in case of general corruption :-) */ - if (manager->num_nodes <= 0) - { - FT_ERROR(( "FTC_Manager_Compress: invalid cache node count !!\n" )); - } + if ( manager->num_nodes <= 0 ) + FT_ERROR(( "FTC_Manager_Compress: Invalid cache node count!\n" )); else manager->num_nodes--; } @@ -465,8 +463,8 @@ cache->memory = memory; cache->clazz = clazz; - /* THIS IS VERY IMPORTANT, THIS WILL WRECH THE MANAGER */ - /* IF IT IS NOT SET CORRECTLY.. */ + /* THIS IS VERY IMPORTANT! IT WILL WRETCH THE MANAGER */ + /* IF IT IS NOT SET CORRECTLY */ cache->cache_index = index; if ( clazz->init_cache ) diff --git a/src/cache/ftcsbits.c b/src/cache/ftcsbits.c index 7d414ec30..5ce2f5d63 100644 --- a/src/cache/ftcsbits.c +++ b/src/cache/ftcsbits.c @@ -1,20 +1,43 @@ +/***************************************************************************/ +/* */ +/* ftcsbits.c */ +/* */ +/* FreeType sbits manager (body). */ +/* */ +/* 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. */ +/* */ +/***************************************************************************/ + + #include +#include +#include #include +#include /* memcmp() */ + + #define FTC_SBITSET_ELEMENT_COUNT 16 - typedef struct FTC_SBitSetRec_ + typedef struct FTC_SBitSetRec_ { - FTC_ChunkSetRec root; - FTC_Image_Desc desc; + FTC_ChunkSetRec root; + FTC_Image_Desc desc; } FTC_SBitSetRec, *FTC_SBitSet; - typedef struct FTC_SBit_CacheRec_ + typedef struct FTC_SBit_CacheRec_ { - FTC_Chunk_CacheRec root; + FTC_Chunk_CacheRec root; } FTC_SBit_CacheRec; @@ -32,10 +55,11 @@ LOCAL_FUNC_X void ftc_sbit_chunk_node_destroy( FTC_ChunkNode node ) { - FTC_ChunkSet cset = node->cset; - FT_Memory memory = cset->memory; - FT_UInt count = node->num_elements; - FTC_SBit sbit = (FTC_SBit)node->elements; + FTC_ChunkSet cset = node->cset; + FT_Memory memory = cset->memory; + FT_UInt count = node->num_elements; + FTC_SBit sbit = (FTC_SBit)node->elements; + for ( ; count > 0; sbit++, count-- ) FREE( sbit->buffer ); @@ -45,9 +69,7 @@ } - - - static + LOCAL_FUNC_X FT_Error ftc_bitmap_copy( FT_Memory memory, FT_Bitmap* source, FTC_SBit target ) @@ -56,6 +78,7 @@ FT_Int pitch = source->pitch; FT_ULong size; + if ( pitch < 0 ) pitch = -pitch; @@ -69,25 +92,25 @@ LOCAL_FUNC_X - FT_Error ftc_sbit_chunk_node_new( FTC_ChunkSet cset, - FT_UInt index, - FTC_ChunkNode *anode ) + FT_Error ftc_sbit_chunk_node_new( FTC_ChunkSet cset, + FT_UInt index, + FTC_ChunkNode* anode ) { - FT_Error error; - FT_Memory memory = cset->memory; - FTC_SBitSet sbitset = (FTC_SBitSet)cset; - FTC_ChunkNode node = 0; - FT_Face face; - FT_Size size; + FT_Error error; + FT_Memory memory = cset->memory; + FTC_SBitSet sbitset = (FTC_SBitSet)cset; + FTC_ChunkNode node = 0; + FT_Face face; + FT_Size size; /* allocate node */ if ( ALLOC( node, sizeof ( *node ) ) ) goto Exit; - /* init its inner fields */ + /* initialize its inner fields */ error = FTC_ChunkNode_Init( node, cset, index, 1 ); - if (error) + if ( error ) goto Exit; /* we will now load all glyph images for this chunk */ @@ -96,86 +119,86 @@ &face, &size ); if ( !error ) { - FT_UInt glyph_index = index * cset->element_count; - FT_UInt load_flags = FT_LOAD_DEFAULT; - FT_UInt image_type = sbitset->desc.image_type; - FT_UInt count = node->num_elements; - FTC_SBit sbit = (FTC_SBit)node->elements; + FT_UInt glyph_index = index * cset->element_count; + FT_UInt load_flags = FT_LOAD_DEFAULT; + FT_UInt image_type = sbitset->desc.image_type; + FT_UInt count = node->num_elements; + FTC_SBit sbit = (FTC_SBit)node->elements; + /* determine load flags, depending on the font description's */ - /* image type.. */ + /* image type */ + + if ( FTC_IMAGE_FORMAT( image_type ) == ftc_image_format_bitmap ) { - if ( FTC_IMAGE_FORMAT( image_type ) == ftc_image_format_bitmap ) - { - if ( image_type & ftc_image_flag_monochrome ) - load_flags |= FT_LOAD_MONOCHROME; + if ( image_type & ftc_image_flag_monochrome ) + load_flags |= FT_LOAD_MONOCHROME; - /* disable embedded bitmaps loading if necessary */ - if ( image_type & ftc_image_flag_no_sbits ) - load_flags |= FT_LOAD_NO_BITMAP; - } - else - { - FT_ERROR(( "FTC_SBit_Cache: cannot load scalable glyphs in a" - " sbit cache, please check your arguments !!\n" )); - error = FT_Err_Invalid_Argument; - goto Exit; - } - - /* always render glyphs to bitmaps */ - load_flags |= FT_LOAD_RENDER; - - if ( image_type & ftc_image_flag_unhinted ) - load_flags |= FT_LOAD_NO_HINTING; - - if ( image_type & ftc_image_flag_autohinted ) - load_flags |= FT_LOAD_FORCE_AUTOHINT; + /* disable embedded bitmaps loading if necessary */ + if ( image_type & ftc_image_flag_no_sbits ) + load_flags |= FT_LOAD_NO_BITMAP; + } + else + { + FT_ERROR(( "FTC_SBit_Cache: cannot load scalable glyphs in an" + " sbit cache, please check your arguments!\n" )); + error = FT_Err_Invalid_Argument; + goto Exit; } + /* always render glyphs to bitmaps */ + load_flags |= FT_LOAD_RENDER; + + if ( image_type & ftc_image_flag_unhinted ) + load_flags |= FT_LOAD_NO_HINTING; + + if ( image_type & ftc_image_flag_autohinted ) + load_flags |= FT_LOAD_FORCE_AUTOHINT; /* load a chunk of small bitmaps in a row */ for ( ; count > 0; count--, glyph_index++, sbit++ ) { - /* by default, indicates a "missing" glyph */ + /* by default, indicates a `missing' glyph */ sbit->buffer = 0; error = FT_Load_Glyph( face, glyph_index, load_flags ); - if (!error) + if ( !error ) { FT_Int temp; FT_GlyphSlot slot = face->glyph; FT_Bitmap* bitmap = &slot->bitmap; FT_Int xadvance, yadvance; - /* check that our values fit in 8-bit containers !! */ - /* if this is not the case, our bitmap is too large */ - /* and we will leave it as "missing" with sbit.buffer = 0 */ -#define CHECK_CHAR(d) ( temp = (FT_Char)d, temp == d ) -#define CHECK_BYTE(d) ( temp = (FT_Byte)d, temp == d ) + /* check that our values fit into 8-bit containers! */ + /* If this is not the case, our bitmap is too large */ + /* and we will leave it as `missing' with sbit.buffer = 0 */ - /* FIXME: add support for vertical layouts maybe.. */ +#define CHECK_CHAR( d ) ( temp = (FT_Char)d, temp == d ) +#define CHECK_BYTE( d ) ( temp = (FT_Byte)d, temp == d ) - /* horizontal advance in pixels */ - xadvance = (slot->metrics.horiAdvance+32) >> 6; - yadvance = (slot->metrics.vertAdvance+32) >> 6; + /* XXX: FIXME: add support for vertical layouts maybe */ - if ( CHECK_BYTE ( bitmap->rows ) && - CHECK_BYTE ( bitmap->width ) && - CHECK_CHAR ( bitmap->pitch ) && - CHECK_CHAR ( slot->bitmap_left ) && - CHECK_CHAR ( slot->bitmap_top ) && - CHECK_CHAR ( xadvance ) && - CHECK_CHAR ( yadvance ) ) + /* horizontal advance in pixels */ + xadvance = ( slot->metrics.horiAdvance + 32 ) >> 6; + yadvance = ( slot->metrics.vertAdvance + 32 ) >> 6; + + if ( CHECK_BYTE( bitmap->rows ) && + CHECK_BYTE( bitmap->width ) && + CHECK_CHAR( bitmap->pitch ) && + CHECK_CHAR( slot->bitmap_left ) && + CHECK_CHAR( slot->bitmap_top ) && + CHECK_CHAR( xadvance ) && + CHECK_CHAR( yadvance ) ) { - sbit->width = (FT_Byte) bitmap->width; - sbit->height = (FT_Byte) bitmap->rows; - sbit->pitch = (FT_Char) bitmap->pitch; - sbit->left = (FT_Char) slot->bitmap_left; - sbit->top = (FT_Char) slot->bitmap_top; - sbit->xadvance = (FT_Char) xadvance; - sbit->yadvance = (FT_Char) yadvance; - sbit->format = (FT_Byte) bitmap->pixel_mode; + sbit->width = (FT_Byte)bitmap->width; + sbit->height = (FT_Byte)bitmap->rows; + sbit->pitch = (FT_Char)bitmap->pitch; + sbit->left = (FT_Char)slot->bitmap_left; + sbit->top = (FT_Char)slot->bitmap_top; + sbit->xadvance = (FT_Char)xadvance; + sbit->yadvance = (FT_Char)yadvance; + sbit->format = (FT_Byte)bitmap->pixel_mode; /* grab the bitmap when possible */ if ( slot->flags & ft_glyph_own_bitmap ) @@ -185,15 +208,15 @@ } else { - /* copy the bitmap into a new buffer - ignore error */ + /* copy the bitmap into a new buffer -- ignore error */ ftc_bitmap_copy( memory, bitmap, sbit ); } } } } - /* ignore the errors that might have occured there */ - /* we recognize unloaded glyphs with "sbit.buffer == 0" */ + /* ignore the errors that might have occurred -- */ + /* we recognize unloaded glyphs with `sbit.buffer == 0' */ error = 0; } @@ -205,12 +228,13 @@ } *anode = node; + return error; } /* this function is important because it is both part of */ - /* a FTC_ChunkSet_Class and a FTC_CacheNode_Class */ + /* an FTC_ChunkSet_Class and an FTC_CacheNode_Class */ /* */ LOCAL_FUNC_X FT_ULong ftc_sbit_chunk_node_size( FTC_ChunkNode node ) @@ -221,15 +245,18 @@ FT_Int pitch; FTC_SBit sbit = (FTC_SBit)node->elements; - size = sizeof (*node); /* the node itself */ - size += cset->element_count * sizeof(FTC_SBitRec); /* the sbit recors */ + + /* the node itself */ + size = sizeof ( *node ); + /* the sbit records */ + size += cset->element_count * sizeof ( FTC_SBitRec ); for ( ; count > 0; count--, sbit++ ) { - if (sbit->buffer) + if ( sbit->buffer ) { pitch = sbit->pitch; - if (pitch < 0) + if ( pitch < 0 ) pitch = -pitch; /* add the size of a given glyph image */ @@ -257,25 +284,26 @@ FT_Error error; FT_Face face; + cset->element_count = FTC_SBITSET_ELEMENT_COUNT; - cset->element_size = sizeof(FTC_SBitRec); + cset->element_size = sizeof ( FTC_SBitRec ); /* lookup the FT_Face to obtain the number of glyphs */ error = FTC_Manager_Lookup_Face( cset->manager, desc->font.face_id, &face ); - if (!error) + if ( !error ) cset->element_max = face->num_glyphs; return error; } - LOCAL_FUNC_X FT_Error ftc_sbit_chunk_set_init( FTC_SBitSet sset, FTC_Image_Desc* type ) { sset->desc = *type; + return 0; } @@ -292,14 +320,14 @@ { sizeof( FTC_SBitSetRec ), - (FTC_ChunkSet_InitFunc) ftc_sbit_chunk_set_init, - (FTC_ChunkSet_DoneFunc) 0, - (FTC_ChunkSet_CompareFunc) ftc_sbit_chunk_set_compare, - (FTC_ChunkSet_SizesFunc) ftc_sbit_chunk_set_sizes, + (FTC_ChunkSet_InitFunc) ftc_sbit_chunk_set_init, + (FTC_ChunkSet_DoneFunc) 0, + (FTC_ChunkSet_CompareFunc) ftc_sbit_chunk_set_compare, + (FTC_ChunkSet_SizesFunc) ftc_sbit_chunk_set_sizes, - (FTC_ChunkSet_NewNodeFunc) ftc_sbit_chunk_node_new, - (FTC_ChunkSet_SizeNodeFunc) ftc_sbit_chunk_node_size, - (FTC_ChunkSet_DestroyNodeFunc) ftc_sbit_chunk_node_destroy + (FTC_ChunkSet_NewNodeFunc) ftc_sbit_chunk_node_new, + (FTC_ChunkSet_SizeNodeFunc) ftc_sbit_chunk_node_size, + (FTC_ChunkSet_DestroyNodeFunc)ftc_sbit_chunk_node_destroy }; @@ -316,16 +344,15 @@ { { sizeof( FTC_SBit_CacheRec ), - (FTC_Cache_InitFunc) FTC_Chunk_Cache_Init, - (FTC_Cache_DoneFunc) FTC_Chunk_Cache_Done + (FTC_Cache_InitFunc)FTC_Chunk_Cache_Init, + (FTC_Cache_DoneFunc)FTC_Chunk_Cache_Done }, - (FTC_ChunkSet_Class*) &ftc_sbit_chunk_set_class + (FTC_ChunkSet_Class*)&ftc_sbit_chunk_set_class }; - FT_EXPORT_FUNC( FT_Error ) - FTC_SBit_Cache_New( FTC_Manager manager, - FTC_SBit_Cache* acache ) + FT_EXPORT_FUNC( FT_Error ) FTC_SBit_Cache_New( FTC_Manager manager, + FTC_SBit_Cache* acache ) { return FTC_Manager_Register_Cache( manager, @@ -334,11 +361,10 @@ } - FT_EXPORT_DEF( FT_Error ) - FTC_SBit_Cache_Lookup( FTC_SBit_Cache cache, - FTC_Image_Desc* desc, - FT_UInt gindex, - FTC_SBit *asbit ) + FT_EXPORT_DEF( FT_Error ) FTC_SBit_Cache_Lookup( FTC_SBit_Cache cache, + FTC_Image_Desc* desc, + FT_UInt gindex, + FTC_SBit* asbit ) { FT_Error error; FTC_ChunkSet cset; @@ -355,9 +381,10 @@ if ( !cache || !asbit ) return FT_Err_Invalid_Argument; - *asbit = 0; - cset = cache->root.last_cset; - sset = (FTC_SBitSet)cset; + *asbit = 0; + cset = cache->root.last_cset; + sset = (FTC_SBitSet)cset; + if ( !cset || memcmp( &sset->desc, desc, sizeof ( *desc ) ) ) { error = FT_Lru_Lookup( cache->root.csets_lru, @@ -388,3 +415,5 @@ return error; } + +/* END */ diff --git a/src/cache/ftlru.c b/src/cache/ftlru.c index 53331eb64..4a5808930 100644 --- a/src/cache/ftlru.c +++ b/src/cache/ftlru.c @@ -80,7 +80,6 @@ } - FT_EXPORT_DEF( void ) FT_Lru_Reset( FT_Lru lru ) { FT_ListNode node; @@ -220,8 +219,8 @@ /* create a new lru list node, then the element for it */ if ( lru->nodes ) { - node = lru->free_nodes.head; - lru_node = (FT_LruNode)node; + node = lru->free_nodes.head; + lru_node = (FT_LruNode)node; lru_node->key = key; error = clazz->init_element( lru, lru_node ); diff --git a/src/cff/t2driver.c b/src/cff/t2driver.c index 9e3ca4811..011f3c893 100644 --- a/src/cff/t2driver.c +++ b/src/cff/t2driver.c @@ -365,7 +365,7 @@ /* format-specific interface can then be retrieved through the method */ /* interface->get_format_interface. */ /* */ - EXPORT_FUNC( FT_Driver_Class* ) getDriverClass( void ) + FT_EXPORT_FUNC( const FT_Driver_Class* ) getDriverClass( void ) { return &cff_driver_class; } diff --git a/src/cid/cidriver.c b/src/cid/cidriver.c index 224b0c69d..484430c98 100644 --- a/src/cid/cidriver.c +++ b/src/cid/cidriver.c @@ -247,7 +247,7 @@ /* format-specific interface can then be retrieved through the method */ /* interface->get_format_interface. */ /* */ - EXPORT_FUNC( FT_Driver_Class* ) getDriverClass( void ) + FT_EXPORT_FUNC( const FT_Driver_Class* ) getDriverClass( void ) { return &t1cid_driver_class; } diff --git a/src/truetype/ttdriver.c b/src/truetype/ttdriver.c index 02b60697f..6cd61d95e 100644 --- a/src/truetype/ttdriver.c +++ b/src/truetype/ttdriver.c @@ -483,7 +483,7 @@ /*************************************************************************/ /* */ /* */ - /* getDriverInterface */ + /* getDriverClass */ /* */ /* */ /* This function is used when compiling the TrueType driver as a */ @@ -499,7 +499,7 @@ /* format-specific interface can then be retrieved through the method */ /* interface->get_format_interface. */ /* */ - EXPORT_FUNC( const FT_Driver_Class* ) getDriverClass( void ) + FT_EXPORT_FUNC( const FT_Driver_Class* ) getDriverClass( void ) { return &tt_driver_class; } diff --git a/src/type1/t1driver.c b/src/type1/t1driver.c index 3fb1d8d20..12d0a8e81 100644 --- a/src/type1/t1driver.c +++ b/src/type1/t1driver.c @@ -329,11 +329,32 @@ #ifdef FT_CONFIG_OPTION_DYNAMIC_DRIVERS - EXPORT_FUNC( const FT_Driver_Class* ) getDriverClass( void ) + + /*************************************************************************/ + /* */ + /* */ + /* getDriverClass */ + /* */ + /* */ + /* This function is used when compiling the TrueType driver as a */ + /* shared library (`.DLL' or `.so'). It will be used by the */ + /* high-level library of FreeType to retrieve the address of the */ + /* driver's generic interface. */ + /* */ + /* It shouldn't be implemented in a static build, as each driver must */ + /* have the same function as an exported entry point. */ + /* */ + /* */ + /* The address of the TrueType's driver generic interface. The */ + /* format-specific interface can then be retrieved through the method */ + /* interface->get_format_interface. */ + /* */ + FT_EXPORT_FUNC( const FT_Driver_Class* ) getDriverClass( void ) { return &t1_driver_class; } + #endif /* FT_CONFIG_OPTION_DYNAMIC_DRIVERS */ diff --git a/src/winfonts/winfnt.c b/src/winfonts/winfnt.c index 2964b2f21..63cdc1b8d 100644 --- a/src/winfonts/winfnt.c +++ b/src/winfonts/winfnt.c @@ -629,4 +629,35 @@ }; +#ifdef FT_CONFIG_OPTION_DYNAMIC_DRIVERS + + + /*************************************************************************/ + /* */ + /* */ + /* getDriverClass */ + /* */ + /* */ + /* This function is used when compiling the TrueType driver as a */ + /* shared library (`.DLL' or `.so'). It will be used by the */ + /* high-level library of FreeType to retrieve the address of the */ + /* driver's generic interface. */ + /* */ + /* It shouldn't be implemented in a static build, as each driver must */ + /* have the same function as an exported entry point. */ + /* */ + /* */ + /* The address of the TrueType's driver generic interface. The */ + /* format-specific interface can then be retrieved through the method */ + /* interface->get_format_interface. */ + /* */ + FT_EXPORT_FUNC( const FT_Driver_Class* ) getDriverClass( void ) + { + return &winfnt_driver_class; + } + + +#endif /* FT_CONFIG_OPTION_DYNAMIC_DRIVERS */ + + /* END */