From 02280535bea08395871722f733aaaed70c992260 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 10 Dec 2018 14:59:49 +0100 Subject: Update bundled Freetype to 2.9.1 This is required to support the new emoji font on Android 9. [ChangeLog][Freetype] Upgraded bundled Freetype version to 2.9.1. This also adds support for the latest emoji font in use on Android 9. Fixes: QTBUG-70657 Change-Id: I99be72f0d23c20aca122b8fdadd4ded87b2edce1 Reviewed-by: Konstantin Ritt --- src/3rdparty/freetype/src/bdf/Jamfile | 2 +- src/3rdparty/freetype/src/bdf/README | 2 +- src/3rdparty/freetype/src/bdf/bdf.c | 3 +- src/3rdparty/freetype/src/bdf/bdf.h | 27 +- src/3rdparty/freetype/src/bdf/bdfdrivr.c | 188 ++++++++-- src/3rdparty/freetype/src/bdf/bdfdrivr.h | 6 +- src/3rdparty/freetype/src/bdf/bdferror.h | 8 +- src/3rdparty/freetype/src/bdf/bdflib.c | 625 ++++++++++--------------------- 8 files changed, 365 insertions(+), 496 deletions(-) (limited to 'src/3rdparty/freetype/src/bdf') diff --git a/src/3rdparty/freetype/src/bdf/Jamfile b/src/3rdparty/freetype/src/bdf/Jamfile index 86b85fa3e4..d9e441c188 100644 --- a/src/3rdparty/freetype/src/bdf/Jamfile +++ b/src/3rdparty/freetype/src/bdf/Jamfile @@ -1,6 +1,6 @@ # FreeType 2 src/bdf Jamfile # -# Copyright 2002-2015 by +# Copyright 2002-2018 by # David Turner, Robert Wilhelm, and Werner Lemberg. # # This file is part of the FreeType project, and may only be used, modified, diff --git a/src/3rdparty/freetype/src/bdf/README b/src/3rdparty/freetype/src/bdf/README index b761aba2b2..996ac2d2aa 100644 --- a/src/3rdparty/freetype/src/bdf/README +++ b/src/3rdparty/freetype/src/bdf/README @@ -13,7 +13,7 @@ This code implements a BDF driver for the FreeType library, following the Adobe Specification V 2.2. The specification of the BDF font format is available from Adobe's web site: - http://partners.adobe.com/public/developer/en/font/5005.BDF_Spec.pdf + https://www.adobe.com/content/dam/acom/en/devnet/font/pdfs/5005.BDF_Spec.pdf Many good bitmap fonts in bdf format come with XFree86 (www.XFree86.org). They do not define vertical metrics, because the X Consortium BDF diff --git a/src/3rdparty/freetype/src/bdf/bdf.c b/src/3rdparty/freetype/src/bdf/bdf.c index f95fb76225..e54df6649b 100644 --- a/src/3rdparty/freetype/src/bdf/bdf.c +++ b/src/3rdparty/freetype/src/bdf/bdf.c @@ -24,9 +24,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#define FT_MAKE_OPTION_SINGLE_OBJECT +#define FT_MAKE_OPTION_SINGLE_OBJECT #include + #include "bdflib.c" #include "bdfdrivr.c" diff --git a/src/3rdparty/freetype/src/bdf/bdf.h b/src/3rdparty/freetype/src/bdf/bdf.h index f24d925d8f..9012727c7e 100644 --- a/src/3rdparty/freetype/src/bdf/bdf.h +++ b/src/3rdparty/freetype/src/bdf/bdf.h @@ -22,8 +22,8 @@ */ -#ifndef __BDF_H__ -#define __BDF_H__ +#ifndef BDF_H_ +#define BDF_H_ /* @@ -33,6 +33,7 @@ #include #include FT_INTERNAL_OBJECTS_H #include FT_INTERNAL_STREAM_H +#include FT_INTERNAL_HASH_H FT_BEGIN_HEADER @@ -157,24 +158,6 @@ FT_BEGIN_HEADER } bdf_glyph_t; - typedef struct _hashnode_ - { - const char* key; - size_t data; - - } _hashnode, *hashnode; - - - typedef struct hashtable_ - { - unsigned int limit; - unsigned int size; - unsigned int used; - hashnode* table; - - } hashtable; - - typedef struct bdf_glyphlist_t_ { unsigned short pad; /* Pad to 4-byte boundary. */ @@ -238,7 +221,7 @@ FT_BEGIN_HEADER bdf_property_t* user_props; unsigned long nuser_props; - hashtable proptbl; + FT_HashRec proptbl; } bdf_font_t; @@ -291,7 +274,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* __BDF_H__ */ +#endif /* BDF_H_ */ /* END */ diff --git a/src/3rdparty/freetype/src/bdf/bdfdrivr.c b/src/3rdparty/freetype/src/bdf/bdfdrivr.c index 404af517e5..ca937f89ce 100644 --- a/src/3rdparty/freetype/src/bdf/bdfdrivr.c +++ b/src/3rdparty/freetype/src/bdf/bdfdrivr.c @@ -276,7 +276,7 @@ THE SOFTWARE. len = lengths[nn]; - if ( src == NULL ) + if ( !src ) continue; /* separate elements with a space */ @@ -373,7 +373,7 @@ THE SOFTWARE. /* we have a bdf font: let's construct the face object */ face->bdffont = font; - /* BDF could not have multiple face in single font file. + /* BDF cannot have multiple faces in a single font file. * XXX: non-zero face_index is already invalid argument, but * Type1, Type42 driver has a convention to return * an invalid argument error when the font could be @@ -423,7 +423,7 @@ THE SOFTWARE. else bdfface->family_name = NULL; - if ( ( error = bdf_interpret_style( face ) ) != 0 ) + if ( FT_SET_ERROR( bdf_interpret_style( face ) ) ) goto Exit; /* the number of glyphs (with one slot for the undefined glyph */ @@ -437,46 +437,156 @@ THE SOFTWARE. { FT_Bitmap_Size* bsize = bdfface->available_sizes; FT_Short resolution_x = 0, resolution_y = 0; + long value; - FT_MEM_ZERO( bsize, sizeof ( FT_Bitmap_Size ) ); + FT_ZERO( bsize ); + + /* sanity checks */ + if ( font->font_ascent > 0x7FFF || font->font_ascent < -0x7FFF ) + { + font->font_ascent = font->font_ascent < 0 ? -0x7FFF : 0x7FFF; + FT_TRACE0(( "BDF_Face_Init: clamping font ascent to value %d\n", + font->font_ascent )); + } + if ( font->font_descent > 0x7FFF || font->font_descent < -0x7FFF ) + { + font->font_descent = font->font_descent < 0 ? -0x7FFF : 0x7FFF; + FT_TRACE0(( "BDF_Face_Init: clamping font descent to value %d\n", + font->font_descent )); + } bsize->height = (FT_Short)( font->font_ascent + font->font_descent ); prop = bdf_get_font_property( font, "AVERAGE_WIDTH" ); if ( prop ) - bsize->width = (FT_Short)( ( prop->value.l + 5 ) / 10 ); + { +#ifdef FT_DEBUG_LEVEL_TRACE + if ( prop->value.l < 0 ) + FT_TRACE0(( "BDF_Face_Init: negative average width\n" )); +#endif + if ( prop->value.l > 0x7FFFL * 10 - 5 || + prop->value.l < -( 0x7FFFL * 10 - 5 ) ) + { + bsize->width = 0x7FFF; + FT_TRACE0(( "BDF_Face_Init: clamping average width to value %d\n", + bsize->width )); + } + else + bsize->width = FT_ABS( (FT_Short)( ( prop->value.l + 5 ) / 10 ) ); + } else - bsize->width = (FT_Short)( bsize->height * 2/3 ); + { + /* this is a heuristical value */ + bsize->width = (FT_Short)FT_MulDiv( bsize->height, 2, 3 ); + } prop = bdf_get_font_property( font, "POINT_SIZE" ); if ( prop ) + { +#ifdef FT_DEBUG_LEVEL_TRACE + if ( prop->value.l < 0 ) + FT_TRACE0(( "BDF_Face_Init: negative point size\n" )); +#endif /* convert from 722.7 decipoints to 72 points per inch */ - bsize->size = - (FT_Pos)( ( prop->value.l * 64 * 7200 + 36135L ) / 72270L ); + if ( prop->value.l > 0x504C2L || /* 0x7FFF * 72270/7200 */ + prop->value.l < -0x504C2L ) + { + bsize->size = 0x7FFF; + FT_TRACE0(( "BDF_Face_Init: clamping point size to value %d\n", + bsize->size )); + } + else + bsize->size = FT_MulDiv( FT_ABS( prop->value.l ), + 64 * 7200, + 72270L ); + } + else if ( font->point_size ) + { + if ( font->point_size > 0x7FFF ) + { + bsize->size = 0x7FFF; + FT_TRACE0(( "BDF_Face_Init: clamping point size to value %d\n", + bsize->size )); + } + else + bsize->size = (FT_Pos)font->point_size << 6; + } else - bsize->size = bsize->width << 6; + { + /* this is a heuristical value */ + bsize->size = bsize->width * 64; + } prop = bdf_get_font_property( font, "PIXEL_SIZE" ); if ( prop ) - bsize->y_ppem = (FT_Short)prop->value.l << 6; + { +#ifdef FT_DEBUG_LEVEL_TRACE + if ( prop->value.l < 0 ) + FT_TRACE0(( "BDF_Face_Init: negative pixel size\n" )); +#endif + if ( prop->value.l > 0x7FFF || prop->value.l < -0x7FFF ) + { + bsize->y_ppem = 0x7FFF << 6; + FT_TRACE0(( "BDF_Face_Init: clamping pixel size to value %d\n", + bsize->y_ppem )); + } + else + bsize->y_ppem = FT_ABS( (FT_Short)prop->value.l ) << 6; + } prop = bdf_get_font_property( font, "RESOLUTION_X" ); if ( prop ) - resolution_x = (FT_Short)prop->value.l; + value = prop->value.l; + else + value = (long)font->resolution_x; + if ( value ) + { +#ifdef FT_DEBUG_LEVEL_TRACE + if ( value < 0 ) + FT_TRACE0(( "BDF_Face_Init: negative X resolution\n" )); +#endif + if ( value > 0x7FFF || value < -0x7FFF ) + { + resolution_x = 0x7FFF; + FT_TRACE0(( "BDF_Face_Init: clamping X resolution to value %d\n", + resolution_x )); + } + else + resolution_x = FT_ABS( (FT_Short)value ); + } prop = bdf_get_font_property( font, "RESOLUTION_Y" ); if ( prop ) - resolution_y = (FT_Short)prop->value.l; + value = prop->value.l; + else + value = (long)font->resolution_y; + if ( value ) + { +#ifdef FT_DEBUG_LEVEL_TRACE + if ( value < 0 ) + FT_TRACE0(( "BDF_Face_Init: negative Y resolution\n" )); +#endif + if ( value > 0x7FFF || value < -0x7FFF ) + { + resolution_y = 0x7FFF; + FT_TRACE0(( "BDF_Face_Init: clamping Y resolution to value %d\n", + resolution_y )); + } + else + resolution_y = FT_ABS( (FT_Short)value ); + } if ( bsize->y_ppem == 0 ) { bsize->y_ppem = bsize->size; if ( resolution_y ) - bsize->y_ppem = bsize->y_ppem * resolution_y / 72; + bsize->y_ppem = FT_MulDiv( bsize->y_ppem, resolution_y, 72 ); } if ( resolution_x && resolution_y ) - bsize->x_ppem = bsize->y_ppem * resolution_x / resolution_y; + bsize->x_ppem = FT_MulDiv( bsize->y_ppem, + resolution_x, + resolution_y ); else bsize->x_ppem = bsize->y_ppem; } @@ -545,7 +655,11 @@ THE SOFTWARE. if ( !ft_strcmp( s, "10646" ) || ( !ft_strcmp( s, "8859" ) && !ft_strcmp( face->charset_encoding, "1" ) ) ) - unicode_charmap = 1; + unicode_charmap = 1; + /* another name for ASCII */ + else if ( !ft_strcmp( s, "646.1991" ) && + !ft_strcmp( face->charset_encoding, "IRV" ) ) + unicode_charmap = 1; } { @@ -566,12 +680,6 @@ THE SOFTWARE. } error = FT_CMap_New( &bdf_cmap_class, NULL, &charmap, NULL ); - -#if 0 - /* Select default charmap */ - if ( bdfface->num_charmaps ) - bdfface->charmap = bdfface->charmaps[0]; -#endif } goto Exit; @@ -705,7 +813,7 @@ THE SOFTWARE. bitmap->rows = glyph.bbx.height; bitmap->width = glyph.bbx.width; - if ( glyph.bpr > INT_MAX ) + if ( glyph.bpr > FT_INT_MAX ) FT_TRACE1(( "BDF_Glyph_Load: too large pitch %d is truncated\n", glyph.bpr )); bitmap->pitch = (int)glyph.bpr; /* same as FT_Bitmap.pitch */ @@ -824,8 +932,8 @@ THE SOFTWARE. static const FT_Service_BDFRec bdf_service_bdf = { - (FT_BDF_GetCharsetIdFunc)bdf_get_charset_id, - (FT_BDF_GetPropertyFunc) bdf_get_bdf_property + (FT_BDF_GetCharsetIdFunc)bdf_get_charset_id, /* get_charset_id */ + (FT_BDF_GetPropertyFunc) bdf_get_bdf_property /* get_property */ }; @@ -866,32 +974,32 @@ THE SOFTWARE. 0x10000L, 0x20000L, - 0, + NULL, /* module-specific interface */ - 0, /* FT_Module_Constructor */ - 0, /* FT_Module_Destructor */ - bdf_driver_requester + NULL, /* FT_Module_Constructor module_init */ + NULL, /* FT_Module_Destructor module_done */ + bdf_driver_requester /* FT_Module_Requester get_interface */ }, sizeof ( BDF_FaceRec ), sizeof ( FT_SizeRec ), sizeof ( FT_GlyphSlotRec ), - BDF_Face_Init, - BDF_Face_Done, - 0, /* FT_Size_InitFunc */ - 0, /* FT_Size_DoneFunc */ - 0, /* FT_Slot_InitFunc */ - 0, /* FT_Slot_DoneFunc */ + BDF_Face_Init, /* FT_Face_InitFunc init_face */ + BDF_Face_Done, /* FT_Face_DoneFunc done_face */ + NULL, /* FT_Size_InitFunc init_size */ + NULL, /* FT_Size_DoneFunc done_size */ + NULL, /* FT_Slot_InitFunc init_slot */ + NULL, /* FT_Slot_DoneFunc done_slot */ - BDF_Glyph_Load, + BDF_Glyph_Load, /* FT_Slot_LoadFunc load_glyph */ - 0, /* FT_Face_GetKerningFunc */ - 0, /* FT_Face_AttachFunc */ - 0, /* FT_Face_GetAdvancesFunc */ + NULL, /* FT_Face_GetKerningFunc get_kerning */ + NULL, /* FT_Face_AttachFunc attach_file */ + NULL, /* FT_Face_GetAdvancesFunc get_advances */ - BDF_Size_Request, - BDF_Size_Select + BDF_Size_Request, /* FT_Size_RequestFunc request_size */ + BDF_Size_Select /* FT_Size_SelectFunc select_size */ }; diff --git a/src/3rdparty/freetype/src/bdf/bdfdrivr.h b/src/3rdparty/freetype/src/bdf/bdfdrivr.h index 3c61d644f4..94550818c1 100644 --- a/src/3rdparty/freetype/src/bdf/bdfdrivr.h +++ b/src/3rdparty/freetype/src/bdf/bdfdrivr.h @@ -25,8 +25,8 @@ THE SOFTWARE. */ -#ifndef __BDFDRIVR_H__ -#define __BDFDRIVR_H__ +#ifndef BDFDRIVR_H_ +#define BDFDRIVR_H_ #include #include FT_INTERNAL_DRIVER_H @@ -74,7 +74,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* __BDFDRIVR_H__ */ +#endif /* BDFDRIVR_H_ */ /* END */ diff --git a/src/3rdparty/freetype/src/bdf/bdferror.h b/src/3rdparty/freetype/src/bdf/bdferror.h index ea545aca06..b462c7d3b5 100644 --- a/src/3rdparty/freetype/src/bdf/bdferror.h +++ b/src/3rdparty/freetype/src/bdf/bdferror.h @@ -26,12 +26,12 @@ /* */ /*************************************************************************/ -#ifndef __BDFERROR_H__ -#define __BDFERROR_H__ +#ifndef BDFERROR_H_ +#define BDFERROR_H_ #include FT_MODULE_ERRORS_H -#undef __FTERRORS_H__ +#undef FTERRORS_H_ #undef FT_ERR_PREFIX #define FT_ERR_PREFIX BDF_Err_ @@ -39,7 +39,7 @@ #include FT_ERRORS_H -#endif /* __BDFERROR_H__ */ +#endif /* BDFERROR_H_ */ /* END */ diff --git a/src/3rdparty/freetype/src/bdf/bdflib.c b/src/3rdparty/freetype/src/bdf/bdflib.c index 414deb58ad..2f5c99d544 100644 --- a/src/3rdparty/freetype/src/bdf/bdflib.c +++ b/src/3rdparty/freetype/src/bdf/bdflib.c @@ -201,6 +201,7 @@ #define ACMSG14 "Glyph %ld extra columns removed.\n" #define ACMSG15 "Incorrect glyph count: %ld indicated but %ld found.\n" #define ACMSG16 "Glyph %ld missing columns padded with zero bits.\n" +#define ACMSG17 "Adjusting number of glyphs to %ld.\n" /* Error messages. */ #define ERRMSG1 "[line %ld] Missing `%s' line.\n" @@ -218,164 +219,6 @@ #define DBGMSG2 " (0x%lX)\n" - /*************************************************************************/ - /* */ - /* Hash table utilities for the properties. */ - /* */ - /*************************************************************************/ - - /* XXX: Replace this with FreeType's hash functions */ - - -#define INITIAL_HT_SIZE 241 - - typedef void - (*hash_free_func)( hashnode node ); - - static hashnode* - hash_bucket( const char* key, - hashtable* ht ) - { - const char* kp = key; - unsigned long res = 0; - hashnode* bp = ht->table, *ndp; - - - /* Mocklisp hash function. */ - while ( *kp ) - res = ( res << 5 ) - res + (unsigned long)*kp++; - - ndp = bp + ( res % ht->size ); - while ( *ndp ) - { - kp = (*ndp)->key; - if ( kp[0] == key[0] && ft_strcmp( kp, key ) == 0 ) - break; - ndp--; - if ( ndp < bp ) - ndp = bp + ( ht->size - 1 ); - } - - return ndp; - } - - - static FT_Error - hash_rehash( hashtable* ht, - FT_Memory memory ) - { - hashnode* obp = ht->table, *bp, *nbp; - unsigned int i, sz = ht->size; - FT_Error error = FT_Err_Ok; - - - ht->size <<= 1; - ht->limit = ht->size / 3; - - if ( FT_NEW_ARRAY( ht->table, ht->size ) ) - goto Exit; - - for ( i = 0, bp = obp; i < sz; i++, bp++ ) - { - if ( *bp ) - { - nbp = hash_bucket( (*bp)->key, ht ); - *nbp = *bp; - } - } - FT_FREE( obp ); - - Exit: - return error; - } - - - static FT_Error - hash_init( hashtable* ht, - FT_Memory memory ) - { - unsigned int sz = INITIAL_HT_SIZE; - FT_Error error = FT_Err_Ok; - - - ht->size = sz; - ht->limit = sz / 3; - ht->used = 0; - - if ( FT_NEW_ARRAY( ht->table, sz ) ) - goto Exit; - - Exit: - return error; - } - - - static void - hash_free( hashtable* ht, - FT_Memory memory ) - { - if ( ht != 0 ) - { - unsigned int i, sz = ht->size; - hashnode* bp = ht->table; - - - for ( i = 0; i < sz; i++, bp++ ) - FT_FREE( *bp ); - - FT_FREE( ht->table ); - } - } - - - static FT_Error - hash_insert( char* key, - size_t data, - hashtable* ht, - FT_Memory memory ) - { - hashnode nn; - hashnode* bp = hash_bucket( key, ht ); - FT_Error error = FT_Err_Ok; - - - nn = *bp; - if ( !nn ) - { - if ( FT_NEW( nn ) ) - goto Exit; - *bp = nn; - - nn->key = key; - nn->data = data; - - if ( ht->used >= ht->limit ) - { - error = hash_rehash( ht, memory ); - if ( error ) - goto Exit; - } - ht->used++; - } - else - nn->data = data; - - Exit: - return error; - } - - - static hashnode - hash_lookup( const char* key, - hashtable* ht ) - { - hashnode *np = hash_bucket( key, ht ); - - - return *np; - } - - /*************************************************************************/ /* */ /* Utility types and functions. */ @@ -432,6 +275,7 @@ _bdf_list_t list; FT_Memory memory; + unsigned long size; /* the stream size */ } _bdf_parse_t; @@ -832,14 +676,6 @@ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - static const unsigned char odigits[32] = - { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - }; - static const unsigned char ddigits[32] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03, @@ -857,81 +693,41 @@ }; - /* Routine to convert an ASCII string into an unsigned long integer. */ + /* Routine to convert a decimal ASCII string to an unsigned long integer. */ static unsigned long - _bdf_atoul( char* s, - char** end, - unsigned int base ) + _bdf_atoul( char* s ) { - unsigned long v; - const unsigned char* dmap; + unsigned long v; if ( s == 0 || *s == 0 ) return 0; - /* Make sure the radix is something recognizable. Default to 10. */ - switch ( base ) + for ( v = 0; sbitset( ddigits, *s ); s++ ) { - case 8: - dmap = odigits; - break; - case 16: - dmap = hdigits; - break; - default: - base = 10; - dmap = ddigits; - break; - } - - /* Check for the special hex prefix. */ - if ( *s == '0' && - ( *( s + 1 ) == 'x' || *( s + 1 ) == 'X' ) ) - { - base = 16; - dmap = hdigits; - s += 2; + if ( v < ( FT_ULONG_MAX - 9 ) / 10 ) + v = v * 10 + a2i[(int)*s]; + else + { + v = FT_ULONG_MAX; + break; + } } - for ( v = 0; sbitset( dmap, *s ); s++ ) - v = v * base + a2i[(int)*s]; - - if ( end != 0 ) - *end = s; - return v; } - /* Routine to convert an ASCII string into a signed long integer. */ + /* Routine to convert a decimal ASCII string to a signed long integer. */ static long - _bdf_atol( char* s, - char** end, - int base ) + _bdf_atol( char* s ) { - long v, neg; - const unsigned char* dmap; + long v, neg; if ( s == 0 || *s == 0 ) return 0; - /* Make sure the radix is something recognizable. Default to 10. */ - switch ( base ) - { - case 8: - dmap = odigits; - break; - case 16: - dmap = hdigits; - break; - default: - base = 10; - dmap = ddigits; - break; - } - /* Check for a minus sign. */ neg = 0; if ( *s == '-' ) @@ -940,100 +736,56 @@ neg = 1; } - /* Check for the special hex prefix. */ - if ( *s == '0' && - ( *( s + 1 ) == 'x' || *( s + 1 ) == 'X' ) ) + for ( v = 0; sbitset( ddigits, *s ); s++ ) { - base = 16; - dmap = hdigits; - s += 2; + if ( v < ( FT_LONG_MAX - 9 ) / 10 ) + v = v * 10 + a2i[(int)*s]; + else + { + v = FT_LONG_MAX; + break; + } } - for ( v = 0; sbitset( dmap, *s ); s++ ) - v = v * base + a2i[(int)*s]; - - if ( end != 0 ) - *end = s; - return ( !neg ) ? v : -v; } - /* Routine to convert an ASCII string into an unsigned short integer. */ + /* Routine to convert a decimal ASCII string to an unsigned short integer. */ static unsigned short - _bdf_atous( char* s, - char** end, - unsigned int base ) + _bdf_atous( char* s ) { - unsigned short v; - const unsigned char* dmap; + unsigned short v; if ( s == 0 || *s == 0 ) return 0; - /* Make sure the radix is something recognizable. Default to 10. */ - switch ( base ) - { - case 8: - dmap = odigits; - break; - case 16: - dmap = hdigits; - break; - default: - base = 10; - dmap = ddigits; - break; - } - - /* Check for the special hex prefix. */ - if ( *s == '0' && - ( *( s + 1 ) == 'x' || *( s + 1 ) == 'X' ) ) + for ( v = 0; sbitset( ddigits, *s ); s++ ) { - base = 16; - dmap = hdigits; - s += 2; + if ( v < ( FT_USHORT_MAX - 9 ) / 10 ) + v = (unsigned short)( v * 10 + a2i[(int)*s] ); + else + { + v = FT_USHORT_MAX; + break; + } } - for ( v = 0; sbitset( dmap, *s ); s++ ) - v = (unsigned short)( v * base + a2i[(int)*s] ); - - if ( end != 0 ) - *end = s; - return v; } - /* Routine to convert an ASCII string into a signed short integer. */ + /* Routine to convert a decimal ASCII string to a signed short integer. */ static short - _bdf_atos( char* s, - char** end, - int base ) + _bdf_atos( char* s ) { - short v, neg; - const unsigned char* dmap; + short v, neg; if ( s == 0 || *s == 0 ) return 0; - /* Make sure the radix is something recognizable. Default to 10. */ - switch ( base ) - { - case 8: - dmap = odigits; - break; - case 16: - dmap = hdigits; - break; - default: - base = 10; - dmap = ddigits; - break; - } - /* Check for a minus. */ neg = 0; if ( *s == '-' ) @@ -1042,21 +794,17 @@ neg = 1; } - /* Check for the special hex prefix. */ - if ( *s == '0' && - ( *( s + 1 ) == 'x' || *( s + 1 ) == 'X' ) ) + for ( v = 0; sbitset( ddigits, *s ); s++ ) { - base = 16; - dmap = hdigits; - s += 2; + if ( v < ( SHRT_MAX - 9 ) / 10 ) + v = (short)( v * 10 + a2i[(int)*s] ); + else + { + v = SHRT_MAX; + break; + } } - for ( v = 0; sbitset( dmap, *s ); s++ ) - v = (short)( v * base + a2i[(int)*s] ); - - if ( end != 0 ) - *end = s; - return (short)( ( !neg ) ? v : -v ); } @@ -1096,7 +844,7 @@ /* First check whether the property has */ /* already been added or not. If it has, then */ /* simply ignore it. */ - if ( hash_lookup( name, &(font->proptbl) ) ) + if ( ft_hash_str_lookup( name, &(font->proptbl) ) ) goto Exit; if ( FT_RENEW_ARRAY( font->user_props, @@ -1121,7 +869,7 @@ n = _num_bdf_properties + font->nuser_props; - error = hash_insert( p->name, n, &(font->proptbl), memory ); + error = ft_hash_str_insert( p->name, n, &(font->proptbl), memory ); if ( error ) goto Exit; @@ -1132,25 +880,23 @@ } - FT_LOCAL_DEF( bdf_property_t * ) + FT_LOCAL_DEF( bdf_property_t* ) bdf_get_property( char* name, bdf_font_t* font ) { - hashnode hn; - size_t propid; + size_t* propid; if ( name == 0 || *name == 0 ) return 0; - if ( ( hn = hash_lookup( name, &(font->proptbl) ) ) == 0 ) + if ( ( propid = ft_hash_str_lookup( name, &(font->proptbl) ) ) == NULL ) return 0; - propid = hn->data; - if ( propid >= _num_bdf_properties ) - return font->user_props + ( propid - _num_bdf_properties ); + if ( *propid >= _num_bdf_properties ) + return font->user_props + ( *propid - _num_bdf_properties ); - return (bdf_property_t*)_bdf_properties + propid; + return (bdf_property_t*)_bdf_properties + *propid; } @@ -1163,30 +909,30 @@ /* Parse flags. */ -#define _BDF_START 0x0001U -#define _BDF_FONT_NAME 0x0002U -#define _BDF_SIZE 0x0004U -#define _BDF_FONT_BBX 0x0008U -#define _BDF_PROPS 0x0010U -#define _BDF_GLYPHS 0x0020U -#define _BDF_GLYPH 0x0040U -#define _BDF_ENCODING 0x0080U -#define _BDF_SWIDTH 0x0100U -#define _BDF_DWIDTH 0x0200U -#define _BDF_BBX 0x0400U -#define _BDF_BITMAP 0x0800U +#define BDF_START_ 0x0001U +#define BDF_FONT_NAME_ 0x0002U +#define BDF_SIZE_ 0x0004U +#define BDF_FONT_BBX_ 0x0008U +#define BDF_PROPS_ 0x0010U +#define BDF_GLYPHS_ 0x0020U +#define BDF_GLYPH_ 0x0040U +#define BDF_ENCODING_ 0x0080U +#define BDF_SWIDTH_ 0x0100U +#define BDF_DWIDTH_ 0x0200U +#define BDF_BBX_ 0x0400U +#define BDF_BITMAP_ 0x0800U -#define _BDF_SWIDTH_ADJ 0x1000U +#define BDF_SWIDTH_ADJ_ 0x1000U -#define _BDF_GLYPH_BITS ( _BDF_GLYPH | \ - _BDF_ENCODING | \ - _BDF_SWIDTH | \ - _BDF_DWIDTH | \ - _BDF_BBX | \ - _BDF_BITMAP ) +#define BDF_GLYPH_BITS_ ( BDF_GLYPH_ | \ + BDF_ENCODING_ | \ + BDF_SWIDTH_ | \ + BDF_DWIDTH_ | \ + BDF_BBX_ | \ + BDF_BITMAP_ ) -#define _BDF_GLYPH_WIDTH_CHECK 0x40000000UL -#define _BDF_GLYPH_HEIGHT_CHECK 0x80000000UL +#define BDF_GLYPH_WIDTH_CHECK_ 0x40000000UL +#define BDF_GLYPH_HEIGHT_CHECK_ 0x80000000UL static FT_Error @@ -1358,8 +1104,7 @@ char* value, unsigned long lineno ) { - size_t propid; - hashnode hn; + size_t* propid; bdf_property_t *prop, *fp; FT_Memory memory = font->memory; FT_Error error = FT_Err_Ok; @@ -1368,11 +1113,12 @@ /* First, check whether the property already exists in the font. */ - if ( ( hn = hash_lookup( name, (hashtable *)font->internal ) ) != 0 ) + if ( ( propid = ft_hash_str_lookup( name, + (FT_Hash)font->internal ) ) != NULL ) { /* The property already exists in the font, so simply replace */ /* the value of the property with the current value. */ - fp = font->props + hn->data; + fp = font->props + *propid; switch ( fp->format ) { @@ -1388,11 +1134,11 @@ break; case BDF_INTEGER: - fp->value.l = _bdf_atol( value, 0, 10 ); + fp->value.l = _bdf_atol( value ); break; case BDF_CARDINAL: - fp->value.ul = _bdf_atoul( value, 0, 10 ); + fp->value.ul = _bdf_atoul( value ); break; default: @@ -1404,16 +1150,16 @@ /* See whether this property type exists yet or not. */ /* If not, create it. */ - hn = hash_lookup( name, &(font->proptbl) ); - if ( hn == 0 ) + propid = ft_hash_str_lookup( name, &(font->proptbl) ); + if ( !propid ) { error = bdf_create_property( name, BDF_ATOM, font ); if ( error ) goto Exit; - hn = hash_lookup( name, &(font->proptbl) ); + propid = ft_hash_str_lookup( name, &(font->proptbl) ); } - /* Allocate another property if this is overflow. */ + /* Allocate another property if this is overflowing. */ if ( font->props_used == font->props_size ) { if ( font->props_size == 0 ) @@ -1430,15 +1176,14 @@ } fp = font->props + font->props_size; - FT_MEM_ZERO( fp, sizeof ( bdf_property_t ) ); + FT_ZERO( fp ); font->props_size++; } - propid = hn->data; - if ( propid >= _num_bdf_properties ) - prop = font->user_props + ( propid - _num_bdf_properties ); + if ( *propid >= _num_bdf_properties ) + prop = font->user_props + ( *propid - _num_bdf_properties ); else - prop = (bdf_property_t*)_bdf_properties + propid; + prop = (bdf_property_t*)_bdf_properties + *propid; fp = font->props + font->props_used; @@ -1458,11 +1203,11 @@ break; case BDF_INTEGER: - fp->value.l = _bdf_atol( value, 0, 10 ); + fp->value.l = _bdf_atol( value ); break; case BDF_CARDINAL: - fp->value.ul = _bdf_atoul( value, 0, 10 ); + fp->value.ul = _bdf_atoul( value ); break; } @@ -1471,10 +1216,10 @@ if ( _bdf_strncmp( name, "COMMENT", 7 ) != 0 ) { /* Add the property to the font property table. */ - error = hash_insert( fp->name, - font->props_used, - (hashtable *)font->internal, - memory ); + error = ft_hash_str_insert( fp->name, + font->props_used, + (FT_Hash)font->internal, + memory ); if ( error ) goto Exit; } @@ -1565,7 +1310,7 @@ } /* The very first thing expected is the number of glyphs. */ - if ( !( p->flags & _BDF_GLYPHS ) ) + if ( !( p->flags & BDF_GLYPHS_ ) ) { if ( _bdf_strncmp( line, "CHARS", 5 ) != 0 ) { @@ -1577,7 +1322,14 @@ error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); if ( error ) goto Exit; - p->cnt = font->glyphs_size = _bdf_atoul( p->list.field[1], 0, 10 ); + p->cnt = font->glyphs_size = _bdf_atoul( p->list.field[1] ); + + /* We need at least 20 bytes per glyph. */ + if ( p->cnt > p->size / 20 ) + { + p->cnt = font->glyphs_size = p->size / 20; + FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG17, p->cnt )); + } /* Make sure the number of glyphs is non-zero. */ if ( p->cnt == 0 ) @@ -1595,7 +1347,7 @@ if ( FT_NEW_ARRAY( font->glyphs, font->glyphs_size ) ) goto Exit; - p->flags |= _BDF_GLYPHS; + p->flags |= BDF_GLYPHS_; goto Exit; } @@ -1603,7 +1355,7 @@ /* Check for the ENDFONT field. */ if ( _bdf_strncmp( line, "ENDFONT", 7 ) == 0 ) { - if ( p->flags & _BDF_GLYPH_BITS ) + if ( p->flags & BDF_GLYPH_BITS_ ) { /* Missing ENDCHAR field. */ FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "ENDCHAR" )); @@ -1617,7 +1369,7 @@ sizeof ( bdf_glyph_t ), by_encoding ); - p->flags &= ~_BDF_START; + p->flags &= ~BDF_START_; goto Exit; } @@ -1626,14 +1378,14 @@ if ( _bdf_strncmp( line, "ENDCHAR", 7 ) == 0 ) { p->glyph_enc = 0; - p->flags &= ~_BDF_GLYPH_BITS; + p->flags &= ~BDF_GLYPH_BITS_; goto Exit; } /* Check whether a glyph is being scanned but should be */ /* ignored because it is an unencoded glyph. */ - if ( ( p->flags & _BDF_GLYPH ) && + if ( ( p->flags & BDF_GLYPH_ ) && p->glyph_enc == -1 && p->opts->keep_unencoded == 0 ) goto Exit; @@ -1641,6 +1393,14 @@ /* Check for the STARTCHAR field. */ if ( _bdf_strncmp( line, "STARTCHAR", 9 ) == 0 ) { + if ( p->flags & BDF_GLYPH_BITS_ ) + { + /* Missing ENDCHAR field. */ + FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "ENDCHAR" )); + error = FT_THROW( Missing_Startchar_Field ); + goto Exit; + } + /* Set the character name in the parse info first until the */ /* encoding can be checked for an unencoded character. */ FT_FREE( p->glyph_name ); @@ -1665,7 +1425,7 @@ FT_MEM_COPY( p->glyph_name, s, slen + 1 ); - p->flags |= _BDF_GLYPH; + p->flags |= BDF_GLYPH_; FT_TRACE4(( DBGMSG1, lineno, s )); @@ -1675,7 +1435,7 @@ /* Check for the ENCODING field. */ if ( _bdf_strncmp( line, "ENCODING", 8 ) == 0 ) { - if ( !( p->flags & _BDF_GLYPH ) ) + if ( !( p->flags & BDF_GLYPH_ ) ) { /* Missing STARTCHAR field. */ FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "STARTCHAR" )); @@ -1687,7 +1447,7 @@ if ( error ) goto Exit; - p->glyph_enc = _bdf_atol( p->list.field[1], 0, 10 ); + p->glyph_enc = _bdf_atol( p->list.field[1] ); /* Normalize negative encoding values. The specification only */ /* allows -1, but we can be more generous here. */ @@ -1696,7 +1456,7 @@ /* Check for alternative encoding format. */ if ( p->glyph_enc == -1 && p->list.used > 2 ) - p->glyph_enc = _bdf_atol( p->list.field[2], 0, 10 ); + p->glyph_enc = _bdf_atol( p->list.field[2] ); if ( p->glyph_enc < -1 ) p->glyph_enc = -1; @@ -1773,20 +1533,25 @@ glyph = font->unencoded + font->unencoded_used; glyph->name = p->glyph_name; glyph->encoding = (long)font->unencoded_used++; + + /* Reset the initial glyph info. */ + p->glyph_name = NULL; } else + { /* Free up the glyph name if the unencoded shouldn't be */ /* kept. */ FT_FREE( p->glyph_name ); + } p->glyph_name = NULL; } /* Clear the flags that might be added when width and height are */ /* checked for consistency. */ - p->flags &= ~( _BDF_GLYPH_WIDTH_CHECK | _BDF_GLYPH_HEIGHT_CHECK ); + p->flags &= ~( BDF_GLYPH_WIDTH_CHECK_ | BDF_GLYPH_HEIGHT_CHECK_ ); - p->flags |= _BDF_ENCODING; + p->flags |= BDF_ENCODING_; goto Exit; } @@ -1798,16 +1563,16 @@ glyph = font->glyphs + ( font->glyphs_used - 1 ); /* Check whether a bitmap is being constructed. */ - if ( p->flags & _BDF_BITMAP ) + if ( p->flags & BDF_BITMAP_ ) { /* If there are more rows than are specified in the glyph metrics, */ /* ignore the remaining lines. */ if ( p->row >= (unsigned long)glyph->bbx.height ) { - if ( !( p->flags & _BDF_GLYPH_HEIGHT_CHECK ) ) + if ( !( p->flags & BDF_GLYPH_HEIGHT_CHECK_ ) ) { FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG13, glyph->encoding )); - p->flags |= _BDF_GLYPH_HEIGHT_CHECK; + p->flags |= BDF_GLYPH_HEIGHT_CHECK_; font->modified = 1; } @@ -1832,10 +1597,10 @@ /* If any line has not enough columns, */ /* indicate they have been padded with zero bits. */ if ( i < nibbles && - !( p->flags & _BDF_GLYPH_WIDTH_CHECK ) ) + !( p->flags & BDF_GLYPH_WIDTH_CHECK_ ) ) { FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG16, glyph->encoding )); - p->flags |= _BDF_GLYPH_WIDTH_CHECK; + p->flags |= BDF_GLYPH_WIDTH_CHECK_; font->modified = 1; } @@ -1847,10 +1612,10 @@ /* If any line has extra columns, indicate they have been removed. */ if ( i == nibbles && sbitset( hdigits, line[nibbles] ) && - !( p->flags & _BDF_GLYPH_WIDTH_CHECK ) ) + !( p->flags & BDF_GLYPH_WIDTH_CHECK_ ) ) { FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG14, glyph->encoding )); - p->flags |= _BDF_GLYPH_WIDTH_CHECK; + p->flags |= BDF_GLYPH_WIDTH_CHECK_; font->modified = 1; } @@ -1861,15 +1626,15 @@ /* Expect the SWIDTH (scalable width) field next. */ if ( _bdf_strncmp( line, "SWIDTH", 6 ) == 0 ) { - if ( !( p->flags & _BDF_ENCODING ) ) + if ( !( p->flags & BDF_ENCODING_ ) ) goto Missing_Encoding; error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); if ( error ) goto Exit; - glyph->swidth = (unsigned short)_bdf_atoul( p->list.field[1], 0, 10 ); - p->flags |= _BDF_SWIDTH; + glyph->swidth = (unsigned short)_bdf_atoul( p->list.field[1] ); + p->flags |= BDF_SWIDTH_; goto Exit; } @@ -1877,16 +1642,16 @@ /* Expect the DWIDTH (scalable width) field next. */ if ( _bdf_strncmp( line, "DWIDTH", 6 ) == 0 ) { - if ( !( p->flags & _BDF_ENCODING ) ) + if ( !( p->flags & BDF_ENCODING_ ) ) goto Missing_Encoding; error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); if ( error ) goto Exit; - glyph->dwidth = (unsigned short)_bdf_atoul( p->list.field[1], 0, 10 ); + glyph->dwidth = (unsigned short)_bdf_atoul( p->list.field[1] ); - if ( !( p->flags & _BDF_SWIDTH ) ) + if ( !( p->flags & BDF_SWIDTH_ ) ) { /* Missing SWIDTH field. Emit an auto correction message and set */ /* the scalable width from the device width. */ @@ -1898,24 +1663,24 @@ font->resolution_x ) ); } - p->flags |= _BDF_DWIDTH; + p->flags |= BDF_DWIDTH_; goto Exit; } /* Expect the BBX field next. */ if ( _bdf_strncmp( line, "BBX", 3 ) == 0 ) { - if ( !( p->flags & _BDF_ENCODING ) ) + if ( !( p->flags & BDF_ENCODING_ ) ) goto Missing_Encoding; error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); if ( error ) goto Exit; - glyph->bbx.width = _bdf_atous( p->list.field[1], 0, 10 ); - glyph->bbx.height = _bdf_atous( p->list.field[2], 0, 10 ); - glyph->bbx.x_offset = _bdf_atos( p->list.field[3], 0, 10 ); - glyph->bbx.y_offset = _bdf_atos( p->list.field[4], 0, 10 ); + glyph->bbx.width = _bdf_atous( p->list.field[1] ); + glyph->bbx.height = _bdf_atous( p->list.field[2] ); + glyph->bbx.x_offset = _bdf_atos( p->list.field[3] ); + glyph->bbx.y_offset = _bdf_atos( p->list.field[4] ); /* Generate the ascent and descent of the character. */ glyph->bbx.ascent = (short)( glyph->bbx.height + glyph->bbx.y_offset ); @@ -1932,7 +1697,7 @@ p->minlb = (short)FT_MIN( glyph->bbx.x_offset, p->minlb ); p->maxlb = (short)FT_MAX( glyph->bbx.x_offset, p->maxlb ); - if ( !( p->flags & _BDF_DWIDTH ) ) + if ( !( p->flags & BDF_DWIDTH_ ) ) { /* Missing DWIDTH field. Emit an auto correction message and set */ /* the device width to the glyph width. */ @@ -1961,12 +1726,12 @@ else _bdf_set_glyph_modified( font->nmod, glyph->encoding ); - p->flags |= _BDF_SWIDTH_ADJ; + p->flags |= BDF_SWIDTH_ADJ_; font->modified = 1; } } - p->flags |= _BDF_BBX; + p->flags |= BDF_BBX_; goto Exit; } @@ -1976,7 +1741,7 @@ unsigned long bitmap_size; - if ( !( p->flags & _BDF_BBX ) ) + if ( !( p->flags & BDF_BBX_ ) ) { /* Missing BBX field. */ FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "BBX" )); @@ -2001,7 +1766,7 @@ goto Exit; p->row = 0; - p->flags |= _BDF_BITMAP; + p->flags |= BDF_BITMAP_; goto Exit; } @@ -2016,7 +1781,7 @@ error = FT_THROW( Missing_Encoding_Field ); Exit: - if ( error && ( p->flags & _BDF_GLYPH ) ) + if ( error && ( p->flags & BDF_GLYPH_ ) ) FT_FREE( p->glyph_name ); return error; @@ -2080,7 +1845,7 @@ p->font->modified = 1; } - p->flags &= ~_BDF_PROPS; + p->flags &= ~BDF_PROPS_; *next = _bdf_parse_glyphs; goto Exit; @@ -2178,7 +1943,7 @@ goto Exit; } - if ( !( p->flags & _BDF_START ) ) + if ( !( p->flags & BDF_START_ ) ) { memory = p->memory; @@ -2190,7 +1955,7 @@ goto Exit; } - p->flags = _BDF_START; + p->flags = BDF_START_; font = p->font = 0; if ( FT_NEW( font ) ) @@ -2205,22 +1970,22 @@ bdf_property_t* prop; - error = hash_init( &(font->proptbl), memory ); + error = ft_hash_str_init( &(font->proptbl), memory ); if ( error ) goto Exit; for ( i = 0, prop = (bdf_property_t*)_bdf_properties; i < _num_bdf_properties; i++, prop++ ) { - error = hash_insert( prop->name, i, - &(font->proptbl), memory ); + error = ft_hash_str_insert( prop->name, i, + &(font->proptbl), memory ); if ( error ) goto Exit; } } - if ( FT_ALLOC( p->font->internal, sizeof ( hashtable ) ) ) + if ( FT_ALLOC( p->font->internal, sizeof ( FT_HashRec ) ) ) goto Exit; - error = hash_init( (hashtable *)p->font->internal,memory ); + error = ft_hash_str_init( (FT_Hash)p->font->internal, memory ); if ( error ) goto Exit; p->font->spacing = p->opts->font_spacing; @@ -2232,7 +1997,7 @@ /* Check for the start of the properties. */ if ( _bdf_strncmp( line, "STARTPROPERTIES", 15 ) == 0 ) { - if ( !( p->flags & _BDF_FONT_BBX ) ) + if ( !( p->flags & BDF_FONT_BBX_ ) ) { /* Missing the FONTBOUNDINGBOX field. */ FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONTBOUNDINGBOX" )); @@ -2243,8 +2008,18 @@ error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); if ( error ) goto Exit; + /* at this point, `p->font' can't be NULL */ - p->cnt = p->font->props_size = _bdf_atoul( p->list.field[1], 0, 10 ); + p->cnt = p->font->props_size = _bdf_atoul( p->list.field[1] ); + /* We need at least 4 bytes per property. */ + if ( p->cnt > p->size / 4 ) + { + p->font->props_size = 0; + + FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG5, lineno, "STARTPROPERTIES" )); + error = FT_THROW( Invalid_Argument ); + goto Exit; + } if ( FT_NEW_ARRAY( p->font->props, p->cnt ) ) { @@ -2252,7 +2027,7 @@ goto Exit; } - p->flags |= _BDF_PROPS; + p->flags |= BDF_PROPS_; *next = _bdf_parse_properties; goto Exit; @@ -2261,7 +2036,7 @@ /* Check for the FONTBOUNDINGBOX field. */ if ( _bdf_strncmp( line, "FONTBOUNDINGBOX", 15 ) == 0 ) { - if ( !( p->flags & _BDF_SIZE ) ) + if ( !( p->flags & BDF_SIZE_ ) ) { /* Missing the SIZE field. */ FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "SIZE" )); @@ -2273,18 +2048,18 @@ if ( error ) goto Exit; - p->font->bbx.width = _bdf_atous( p->list.field[1], 0, 10 ); - p->font->bbx.height = _bdf_atous( p->list.field[2], 0, 10 ); + p->font->bbx.width = _bdf_atous( p->list.field[1] ); + p->font->bbx.height = _bdf_atous( p->list.field[2] ); - p->font->bbx.x_offset = _bdf_atos( p->list.field[3], 0, 10 ); - p->font->bbx.y_offset = _bdf_atos( p->list.field[4], 0, 10 ); + p->font->bbx.x_offset = _bdf_atos( p->list.field[3] ); + p->font->bbx.y_offset = _bdf_atos( p->list.field[4] ); p->font->bbx.ascent = (short)( p->font->bbx.height + p->font->bbx.y_offset ); p->font->bbx.descent = (short)( -p->font->bbx.y_offset ); - p->flags |= _BDF_FONT_BBX; + p->flags |= BDF_FONT_BBX_; goto Exit; } @@ -2319,7 +2094,7 @@ if ( error ) goto Exit; - p->flags |= _BDF_FONT_NAME; + p->flags |= BDF_FONT_NAME_; goto Exit; } @@ -2327,7 +2102,7 @@ /* Check for the SIZE field. */ if ( _bdf_strncmp( line, "SIZE", 4 ) == 0 ) { - if ( !( p->flags & _BDF_FONT_NAME ) ) + if ( !( p->flags & BDF_FONT_NAME_ ) ) { /* Missing the FONT field. */ FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONT" )); @@ -2339,9 +2114,9 @@ if ( error ) goto Exit; - p->font->point_size = _bdf_atoul( p->list.field[1], 0, 10 ); - p->font->resolution_x = _bdf_atoul( p->list.field[2], 0, 10 ); - p->font->resolution_y = _bdf_atoul( p->list.field[3], 0, 10 ); + p->font->point_size = _bdf_atoul( p->list.field[1] ); + p->font->resolution_x = _bdf_atoul( p->list.field[2] ); + p->font->resolution_y = _bdf_atoul( p->list.field[3] ); /* Check for the bits per pixel field. */ if ( p->list.used == 5 ) @@ -2349,7 +2124,7 @@ unsigned short bpp; - bpp = (unsigned short)_bdf_atos( p->list.field[4], 0, 10 ); + bpp = (unsigned short)_bdf_atos( p->list.field[4] ); /* Only values 1, 2, 4, 8 are allowed for greymap fonts. */ if ( bpp > 4 ) @@ -2367,7 +2142,7 @@ else p->font->bpp = 1; - p->flags |= _BDF_SIZE; + p->flags |= BDF_SIZE_; goto Exit; } @@ -2378,7 +2153,7 @@ char nbuf[128]; - if ( !( p->flags & _BDF_FONT_BBX ) ) + if ( !( p->flags & BDF_FONT_BBX_ ) ) { /* Missing the FONTBOUNDINGBOX field. */ FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONTBOUNDINGBOX" )); @@ -2447,6 +2222,7 @@ memory = NULL; p->opts = (bdf_options_t*)( ( opts != 0 ) ? opts : &_bdf_opts ); p->minlb = 32767; + p->size = stream->size; p->memory = extmemory; /* only during font creation */ _bdf_list_init( &p->list, extmemory ); @@ -2518,27 +2294,27 @@ p->font->bbx.height = (unsigned short)( p->maxas + p->maxds ); } - if ( p->flags & _BDF_SWIDTH_ADJ ) + if ( p->flags & BDF_SWIDTH_ADJ_ ) FT_TRACE2(( "bdf_load_font: " ACMSG8 )); } } - if ( p->flags & _BDF_START ) + if ( p->flags & BDF_START_ ) { /* The ENDFONT field was never reached or did not exist. */ - if ( !( p->flags & _BDF_GLYPHS ) ) + if ( !( p->flags & BDF_GLYPHS_ ) ) { /* Error happened while parsing header. */ FT_ERROR(( "bdf_load_font: " ERRMSG2, lineno )); error = FT_THROW( Corrupted_Font_Header ); - goto Exit; + goto Fail; } else { /* Error happened when parsing glyphs. */ FT_ERROR(( "bdf_load_font: " ERRMSG3, lineno )); error = FT_THROW( Corrupted_Font_Glyphs ); - goto Exit; + goto Fail; } } @@ -2557,7 +2333,7 @@ p->font->comments[p->font->comments_len] = 0; } } - else if ( error == FT_Err_Ok ) + else if ( !error ) error = FT_THROW( Invalid_File_Format ); *font = p->font; @@ -2569,6 +2345,7 @@ memory = extmemory; + FT_FREE( p->glyph_name ); FT_FREE( p ); } @@ -2604,7 +2381,7 @@ /* Free up the internal hash table of property names. */ if ( font->internal ) { - hash_free( (hashtable *)font->internal, memory ); + ft_hash_str_free( (FT_Hash)font->internal, memory ); FT_FREE( font->internal ); } @@ -2649,7 +2426,7 @@ FT_FREE( font->overflow.glyphs ); /* bdf_cleanup */ - hash_free( &(font->proptbl), memory ); + ft_hash_str_free( &(font->proptbl), memory ); /* Free up the user defined properties. */ for ( prop = font->user_props, i = 0; @@ -2670,15 +2447,15 @@ bdf_get_font_property( bdf_font_t* font, const char* name ) { - hashnode hn; + size_t* propid; if ( font == 0 || font->props_size == 0 || name == 0 || *name == 0 ) return 0; - hn = hash_lookup( name, (hashtable *)font->internal ); + propid = ft_hash_str_lookup( name, (FT_Hash)font->internal ); - return hn ? ( font->props + hn->data ) : 0; + return propid ? ( font->props + *propid ) : 0; } -- cgit v1.2.3