From 711cf8474935cbe85d02428445e9fbee13fa44f6 Mon Sep 17 00:00:00 2001 From: David Turner Date: Fri, 11 May 2007 14:36:24 +0000 Subject: [PATCH] implement FTC_ImageCache_LookupScaler and FTC_SBitCache_LookupScaler, which allow us to specify the font size with a FTC_Scaler structure, hence enabling fractional point sizes, etc... --- ChangeLog | 8 +++ include/freetype/ftcache.h | 108 ++++++++++++++++++++++++++++++++++++ src/cache/ftcbasic.c | 110 +++++++++++++++++++++++++++++++++++++ 3 files changed, 226 insertions(+) diff --git a/ChangeLog b/ChangeLog index 492614df8..c48a0b7a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-05-11 David Turner + + * src/cache/ftbasic.c, include/freetype/ftcache.h: introduce + two new functions FTC_ImageCache_LookupScaler and + FTC_SBitCache_LookupScaler that allows us to lookup glyphs using a + FTC_Scaler object to specify the size. This allows fractional pixel + sizes + 2007-05-09 Graham Asher * src/truetype/ttinterp.c (Ins_IP), src/autofit/aflatin.c diff --git a/include/freetype/ftcache.h b/include/freetype/ftcache.h index 38b956c0a..8b74cf505 100644 --- a/include/freetype/ftcache.h +++ b/include/freetype/ftcache.h @@ -776,6 +776,59 @@ FT_BEGIN_HEADER FTC_Node *anode ); + /*************************************************************************/ + /* */ + /* */ + /* FTC_ImageCache_LookupScaler */ + /* */ + /* */ + /* A variant of @FTC_ImageCache_Lookup that uses a @FTC_ScalerRec */ + /* to specify the face id and its size */ + /* */ + /* */ + /* cache :: A handle to the source glyph image cache. */ + /* */ + /* scaler :: A pointer to a scaler descriptor. */ + /* */ + /* load_flags :: corresponding load flags */ + /* */ + /* gindex :: The glyph index to retrieve. */ + /* */ + /* */ + /* aglyph :: The corresponding @FT_Glyph object. 0 in case of */ + /* failure. */ + /* */ + /* anode :: Used to return the address of of the corresponding cache */ + /* node after incrementing its reference count (see note */ + /* below). */ + /* */ + /* */ + /* FreeType error code. 0 means success. */ + /* */ + /* */ + /* The returned glyph is owned and managed by the glyph image cache. */ + /* Never try to transform or discard it manually! You can however */ + /* create a copy with @FT_Glyph_Copy and modify the new one. */ + /* */ + /* If `anode' is _not_ NULL, it receives the address of the cache */ + /* node containing the glyph image, after increasing its reference */ + /* count. This ensures that the node (as well as the @FT_Glyph) will */ + /* always be kept in the cache until you call @FTC_Node_Unref to */ + /* `release' it. */ + /* */ + /* If `anode' is NULL, the cache node is left unchanged, which means */ + /* that the @FT_Glyph could be flushed out of the cache on the next */ + /* call to one of the caching sub-system APIs. Don't assume that it */ + /* is persistent! */ + /* */ + FT_EXPORT( FT_Error ) + FTC_ImageCache_LookupScaler( FTC_ImageCache cache, + FTC_Scaler scaler, + FT_ULong load_flags, + FT_UInt gindex, + FT_Glyph *aglyph, + FTC_Node *anode ); + /*************************************************************************/ /* */ /* */ @@ -929,6 +982,61 @@ FT_BEGIN_HEADER FTC_SBit *sbit, FTC_Node *anode ); + /*************************************************************************/ + /* */ + /* */ + /* FTC_SBitCache_LookupScaler */ + /* */ + /* */ + /* A variant of @FTC_SBitCache_Lookup that uses a @FTC_ScalerRec */ + /* to specify the face id and its size. */ + /* */ + /* */ + /* cache :: A handle to the source sbit cache. */ + /* */ + /* scaler :: A pointer to the scaler descriptor. */ + /* */ + /* load_flags :: corresponding load flags */ + /* */ + /* gindex :: The glyph index. */ + /* */ + /* */ + /* sbit :: A handle to a small bitmap descriptor. */ + /* */ + /* anode :: Used to return the address of of the corresponding cache */ + /* node after incrementing its reference count (see note */ + /* below). */ + /* */ + /* */ + /* FreeType error code. 0 means success. */ + /* */ + /* */ + /* The small bitmap descriptor and its bit buffer are owned by the */ + /* cache and should never be freed by the application. They might */ + /* as well disappear from memory on the next cache lookup, so don't */ + /* treat them as persistent data. */ + /* */ + /* The descriptor's `buffer' field is set to 0 to indicate a missing */ + /* glyph bitmap. */ + /* */ + /* If `anode' is _not_ NULL, it receives the address of the cache */ + /* node containing the bitmap, after increasing its reference count. */ + /* This ensures that the node (as well as the image) will always be */ + /* kept in the cache until you call @FTC_Node_Unref to `release' it. */ + /* */ + /* If `anode' is NULL, the cache node is left unchanged, which means */ + /* that the bitmap could be flushed out of the cache on the next */ + /* call to one of the caching sub-system APIs. Don't assume that it */ + /* is persistent! */ + /* */ + FT_EXPORT( FT_Error ) + FTC_SBitCache_LookupScaler( FTC_SBitCache cache, + FTC_Scaler scaler, + FT_ULong load_flags, + FT_UInt gindex, + FTC_SBit *sbit, + FTC_Node *anode ); + /* */ diff --git a/src/cache/ftcbasic.c b/src/cache/ftcbasic.c index e9e8135ae..91465bfee 100644 --- a/src/cache/ftcbasic.c +++ b/src/cache/ftcbasic.c @@ -383,6 +383,63 @@ } + + /* documentation is in ftcache.h */ + + FT_EXPORT_DEF( FT_Error ) + FTC_ImageCache_LookupScaler( FTC_ImageCache cache, + FTC_Scaler scaler, + FT_ULong load_flags, + FT_UInt gindex, + FT_Glyph *aglyph, + FTC_Node *anode ) + { + FTC_BasicQueryRec query; + FTC_INode node = 0; /* make compiler happy */ + FT_Error error; + FT_UInt32 hash; + + + /* some argument checks are delayed to FTC_Cache_Lookup */ + if ( !aglyph || !scaler ) + { + error = FTC_Err_Invalid_Argument; + goto Exit; + } + + *aglyph = NULL; + if ( anode ) + *anode = NULL; + + query.attrs.scaler = scaler[0]; + query.attrs.load_flags = load_flags; + + hash = FTC_BASIC_ATTR_HASH( &query.attrs ) + gindex; + + FTC_GCACHE_LOOKUP_CMP( cache, + ftc_basic_family_compare, + FTC_GNode_Compare, + hash, gindex, + &query, + node, + error ); + if ( !error ) + { + *aglyph = FTC_INODE( node )->glyph; + + if ( anode ) + { + *anode = FTC_NODE( node ); + FTC_NODE( node )->ref_count++; + } + } + + Exit: + return error; + } + + + #ifdef FT_CONFIG_OPTION_OLD_INTERNALS /* yet another backwards-legacy structure */ @@ -652,6 +709,59 @@ } + FT_EXPORT_DEF( FT_Error ) + FTC_SBitCache_LookupScaler( FTC_SBitCache cache, + FTC_Scaler scaler, + FT_ULong load_flags, + FT_UInt gindex, + FTC_SBit *ansbit, + FTC_Node *anode ) + { + FT_Error error; + FTC_BasicQueryRec query; + FTC_SNode node = 0; /* make compiler happy */ + FT_UInt32 hash; + + + if ( anode ) + *anode = NULL; + + /* other argument checks delayed to FTC_Cache_Lookup */ + if ( !ansbit || !scaler ) + return FTC_Err_Invalid_Argument; + + *ansbit = NULL; + + query.attrs.scaler = scaler[0]; + query.attrs.load_flags = load_flags; + + /* beware, the hash must be the same for all glyph ranges! */ + hash = FTC_BASIC_ATTR_HASH( &query.attrs ) + + gindex / FTC_SBIT_ITEMS_PER_NODE; + + FTC_GCACHE_LOOKUP_CMP( cache, + ftc_basic_family_compare, + FTC_SNode_Compare, + hash, gindex, + &query, + node, + error ); + if ( error ) + goto Exit; + + *ansbit = node->sbits + ( gindex - FTC_GNODE( node )->gindex ); + + if ( anode ) + { + *anode = FTC_NODE( node ); + FTC_NODE( node )->ref_count++; + } + + Exit: + return error; + } + + #ifdef FT_CONFIG_OPTION_OLD_INTERNALS FT_EXPORT( FT_Error )