diff options
author | Konstantin Ritt <ritt.ks@gmail.com> | 2015-03-19 17:34:42 +0400 |
---|---|---|
committer | Konstantin Ritt <ritt.ks@gmail.com> | 2015-03-20 13:42:29 +0000 |
commit | 2eaf0cf8fd6e7c290497fedb08134a89e7b49b1d (patch) | |
tree | 0a4f7bf528e87d0b0a71ce7fccf702b87f4cdec1 /src/3rdparty/freetype/src/bdf | |
parent | 77c518a50334d4dcf2476a4f39edc1e3990c7f0b (diff) |
Update bundled FreeType to 2.5.5
Removed everything, imported with help of import_from_tarball.sh script,
and then added a pre-generated builds/unix/ftconfig.h
Task-number: QTBUG-44648
Change-Id: Iea948e41f7761f1580382b3763d04c7a61383382
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/3rdparty/freetype/src/bdf')
-rw-r--r-- | src/3rdparty/freetype/src/bdf/README | 4 | ||||
-rw-r--r-- | src/3rdparty/freetype/src/bdf/bdf.h | 8 | ||||
-rw-r--r-- | src/3rdparty/freetype/src/bdf/bdfdrivr.c | 116 | ||||
-rw-r--r-- | src/3rdparty/freetype/src/bdf/bdfdrivr.h | 2 | ||||
-rw-r--r-- | src/3rdparty/freetype/src/bdf/bdferror.h | 3 | ||||
-rw-r--r-- | src/3rdparty/freetype/src/bdf/bdflib.c | 520 |
6 files changed, 418 insertions, 235 deletions
diff --git a/src/3rdparty/freetype/src/bdf/README b/src/3rdparty/freetype/src/bdf/README index e3f2ae3861..b761aba2b2 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/asn/developer/PDFS/TN/5005.BDF_Spec.pdf + http://partners.adobe.com/public/developer/en/font/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 @@ -119,7 +119,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *** Portions of the driver (that is, bdflib.c and bdf.h): Copyright 2000 Computing Research Labs, New Mexico State University -Copyright 2001-2002 Francesco Zappa Nardelli +Copyright 2001-2002, 2011 Francesco Zappa Nardelli Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), diff --git a/src/3rdparty/freetype/src/bdf/bdf.h b/src/3rdparty/freetype/src/bdf/bdf.h index 561b4158a5..d11be6f147 100644 --- a/src/3rdparty/freetype/src/bdf/bdf.h +++ b/src/3rdparty/freetype/src/bdf/bdf.h @@ -1,6 +1,6 @@ /* * Copyright 2000 Computing Research Labs, New Mexico State University - * Copyright 2001, 2002, 2003, 2004 Francesco Zappa Nardelli + * Copyright 2001-2004, 2011 Francesco Zappa Nardelli * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -226,8 +226,10 @@ FT_BEGIN_HEADER void* internal; /* Internal data for the font. */ - unsigned long nmod[2048]; /* Bitmap indicating modified glyphs. */ - unsigned long umod[2048]; /* Bitmap indicating modified */ + /* The size of the next two arrays must be in sync with the */ + /* size of the `have' array in the `bdf_parse_t' structure. */ + unsigned long nmod[34816]; /* Bitmap indicating modified glyphs. */ + unsigned long umod[34816]; /* Bitmap indicating modified */ /* unencoded glyphs. */ unsigned short modified; /* Boolean indicating font modified. */ unsigned short bpp; /* Bits per pixel. */ diff --git a/src/3rdparty/freetype/src/bdf/bdfdrivr.c b/src/3rdparty/freetype/src/bdf/bdfdrivr.c index 631ec460e7..55a428c1b6 100644 --- a/src/3rdparty/freetype/src/bdf/bdfdrivr.c +++ b/src/3rdparty/freetype/src/bdf/bdfdrivr.c @@ -2,7 +2,7 @@ FreeType font driver for bdf files - Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 by + Copyright (C) 2001-2008, 2011, 2013, 2014 by Francesco Zappa Nardelli Permission is hereby granted, free of charge, to any person obtaining a copy @@ -30,6 +30,7 @@ THE SOFTWARE. #include FT_INTERNAL_STREAM_H #include FT_INTERNAL_OBJECTS_H #include FT_BDF_H +#include FT_TRUETYPE_IDS_H #include FT_SERVICE_BDF_H #include FT_SERVICE_XFREE86_NAME_H @@ -71,7 +72,7 @@ THE SOFTWARE. cmap->num_encodings = face->bdffont->glyphs_used; cmap->encodings = face->en_table; - return BDF_Err_Ok; + return FT_Err_Ok; } @@ -181,7 +182,7 @@ THE SOFTWARE. } - FT_CALLBACK_TABLE_DEF + static const FT_CMap_ClassRec bdf_cmap_class = { sizeof ( BDF_CMapRec ), @@ -197,7 +198,7 @@ THE SOFTWARE. static FT_Error bdf_interpret_style( BDF_Face bdf ) { - FT_Error error = BDF_Err_Ok; + FT_Error error = FT_Err_Ok; FT_Face face = FT_FACE( bdf ); FT_Memory memory = face->memory; bdf_font_t* font = bdf->bdffont; @@ -242,8 +243,6 @@ THE SOFTWARE. !( *(prop->value.atom) == 'N' || *(prop->value.atom) == 'n' ) ) strings[0] = (char *)(prop->value.atom); - len = 0; - for ( len = 0, nn = 0; nn < 4; nn++ ) { lengths[nn] = 0; @@ -331,8 +330,6 @@ THE SOFTWARE. FT_FREE( bdfface->available_sizes ); FT_FREE( face->bdffont ); - - FT_TRACE4(( "BDF_Face_Done: done face\n" )); } @@ -343,7 +340,7 @@ THE SOFTWARE. FT_Int num_params, FT_Parameter* params ) { - FT_Error error = BDF_Err_Ok; + FT_Error error = FT_Err_Ok; BDF_Face face = (BDF_Face)bdfface; FT_Memory memory = FT_FACE_MEMORY( face ); @@ -352,9 +349,10 @@ THE SOFTWARE. FT_UNUSED( num_params ); FT_UNUSED( params ); - FT_UNUSED( face_index ); + FT_TRACE2(( "BDF driver\n" )); + if ( FT_STREAM_SEEK( 0 ) ) goto Exit; @@ -364,9 +362,9 @@ THE SOFTWARE. options.font_spacing = BDF_PROPORTIONAL; error = bdf_load_font( stream, memory, &options, &font ); - if ( error == BDF_Err_Missing_Startfont_Field ) + if ( FT_ERR_EQ( error, Missing_Startfont_Field ) ) { - FT_TRACE2(( "[not a valid BDF file]\n" )); + FT_TRACE2(( " not a BDF file\n" )); goto Fail; } else if ( error ) @@ -374,22 +372,36 @@ 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. + * 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 + * opened by the specified driver. + */ + if ( face_index > 0 ) { + FT_ERROR(( "BDF_Face_Init: invalid face index\n" )); + BDF_Face_Done( bdfface ); + return FT_THROW( Invalid_Argument ); + } + { bdf_property_t* prop = NULL; - FT_TRACE4(( "number of glyphs: %d (%d)\n", + FT_TRACE4(( " number of glyphs: allocated %d (used %d)\n", font->glyphs_size, font->glyphs_used )); - FT_TRACE4(( "number of unencoded glyphs: %d (%d)\n", + FT_TRACE4(( " number of unencoded glyphs: allocated %d (used %d)\n", font->unencoded_size, font->unencoded_used )); bdfface->num_faces = 1; bdfface->face_index = 0; - bdfface->face_flags = FT_FACE_FLAG_FIXED_SIZES | - FT_FACE_FLAG_HORIZONTAL | - FT_FACE_FLAG_FAST_GLYPHS; + + bdfface->face_flags |= FT_FACE_FLAG_FIXED_SIZES | + FT_FACE_FLAG_HORIZONTAL | + FT_FACE_FLAG_FAST_GLYPHS; prop = bdf_get_font_property( font, "SPACING" ); if ( prop && prop->format == BDF_ATOM && @@ -481,7 +493,7 @@ THE SOFTWARE. for ( n = 0; n < font->glyphs_size; n++ ) { (face->en_table[n]).enc = cur[n].encoding; - FT_TRACE4(( "idx %d, val 0x%lX\n", n, cur[n].encoding )); + FT_TRACE4(( " idx %d, val 0x%lX\n", n, cur[n].encoding )); (face->en_table[n]).glyph = (FT_Short)n; if ( cur[n].encoding == font->default_char ) @@ -489,7 +501,8 @@ THE SOFTWARE. if ( n < FT_UINT_MAX ) face->default_glyph = (FT_UInt)n; else - FT_TRACE1(( "idx %d is too large for this system\n", n )); + FT_TRACE1(( "BDF_Face_Init:" + " idx %d is too large for this system\n", n )); } } } @@ -540,14 +553,15 @@ THE SOFTWARE. charmap.face = FT_FACE( face ); charmap.encoding = FT_ENCODING_NONE; - charmap.platform_id = 0; - charmap.encoding_id = 0; + /* initial platform/encoding should indicate unset status? */ + charmap.platform_id = TT_PLATFORM_APPLE_UNICODE; + charmap.encoding_id = TT_APPLE_ID_DEFAULT; if ( unicode_charmap ) { charmap.encoding = FT_ENCODING_UNICODE; - charmap.platform_id = 3; - charmap.encoding_id = 1; + charmap.platform_id = TT_PLATFORM_MICROSOFT; + charmap.encoding_id = TT_MS_ID_UNICODE_CS; } error = FT_CMap_New( &bdf_cmap_class, NULL, &charmap, NULL ); @@ -571,8 +585,8 @@ THE SOFTWARE. charmap.face = FT_FACE( face ); charmap.encoding = FT_ENCODING_ADOBE_STANDARD; - charmap.platform_id = 7; - charmap.encoding_id = 0; + charmap.platform_id = TT_PLATFORM_ADOBE; + charmap.encoding_id = TT_ADOBE_ID_STANDARD; error = FT_CMap_New( &bdf_cmap_class, NULL, &charmap, NULL ); @@ -588,7 +602,7 @@ THE SOFTWARE. Fail: BDF_Face_Done( bdfface ); - return BDF_Err_Unknown_File_Format; + return FT_THROW( Unknown_File_Format ); } @@ -605,7 +619,7 @@ THE SOFTWARE. size->metrics.descender = -bdffont->font_descent << 6; size->metrics.max_advance = bdffont->bbx.width << 6; - return BDF_Err_Ok; + return FT_Err_Ok; } @@ -616,7 +630,7 @@ THE SOFTWARE. FT_Face face = size->face; FT_Bitmap_Size* bsize = face->available_sizes; bdf_font_t* bdffont = ( (BDF_Face)face )->bdffont; - FT_Error error = BDF_Err_Invalid_Pixel_Size; + FT_Error error = FT_ERR( Invalid_Pixel_Size ); FT_Long height; @@ -627,17 +641,17 @@ THE SOFTWARE. { case FT_SIZE_REQUEST_TYPE_NOMINAL: if ( height == ( ( bsize->y_ppem + 32 ) >> 6 ) ) - error = BDF_Err_Ok; + error = FT_Err_Ok; break; case FT_SIZE_REQUEST_TYPE_REAL_DIM: if ( height == ( bdffont->font_ascent + bdffont->font_descent ) ) - error = BDF_Err_Ok; + error = FT_Err_Ok; break; default: - error = BDF_Err_Unimplemented_Feature; + error = FT_THROW( Unimplemented_Feature ); break; } @@ -657,7 +671,7 @@ THE SOFTWARE. { BDF_Face bdf = (BDF_Face)FT_SIZE_FACE( size ); FT_Face face = FT_FACE( bdf ); - FT_Error error = BDF_Err_Ok; + FT_Error error = FT_Err_Ok; FT_Bitmap* bitmap = &slot->bitmap; bdf_glyph_t glyph; int bpp = bdf->bdffont->bpp; @@ -665,12 +679,20 @@ THE SOFTWARE. FT_UNUSED( load_flags ); - if ( !face || glyph_index >= (FT_UInt)face->num_glyphs ) + if ( !face ) + { + error = FT_THROW( Invalid_Face_Handle ); + goto Exit; + } + + if ( glyph_index >= (FT_UInt)face->num_glyphs ) { - error = BDF_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); goto Exit; } + FT_TRACE1(( "BDF_Glyph_Load: glyph index %d\n", glyph_index )); + /* index 0 is the undefined glyph */ if ( glyph_index == 0 ) glyph_index = bdf->default_glyph; @@ -759,8 +781,8 @@ THE SOFTWARE. case BDF_INTEGER: if ( prop->value.l > 0x7FFFFFFFL || prop->value.l < ( -1 - 0x7FFFFFFFL ) ) { - FT_TRACE1(( "bdf_get_bdf_property: " )); - FT_TRACE1(( "too large integer 0x%x is truncated\n" )); + FT_TRACE1(( "bdf_get_bdf_property:" + " too large integer 0x%x is truncated\n" )); } aproperty->type = BDF_PROPERTY_TYPE_INTEGER; aproperty->u.integer = (FT_Int32)prop->value.l; @@ -769,8 +791,8 @@ THE SOFTWARE. case BDF_CARDINAL: if ( prop->value.ul > 0xFFFFFFFFUL ) { - FT_TRACE1(( "bdf_get_bdf_property: " )); - FT_TRACE1(( "too large cardinal 0x%x is truncated\n" )); + FT_TRACE1(( "bdf_get_bdf_property:" + " too large cardinal 0x%x is truncated\n" )); } aproperty->type = BDF_PROPERTY_TYPE_CARDINAL; aproperty->u.cardinal = (FT_UInt32)prop->value.ul; @@ -783,7 +805,7 @@ THE SOFTWARE. } Fail: - return BDF_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); } @@ -845,9 +867,9 @@ THE SOFTWARE. 0, - (FT_Module_Constructor)0, - (FT_Module_Destructor) 0, - (FT_Module_Requester) bdf_driver_requester + 0, /* FT_Module_Constructor */ + 0, /* FT_Module_Destructor */ + bdf_driver_requester }, sizeof ( BDF_FaceRec ), @@ -861,15 +883,11 @@ THE SOFTWARE. 0, /* FT_Slot_InitFunc */ 0, /* FT_Slot_DoneFunc */ -#ifdef FT_CONFIG_OPTION_OLD_INTERNALS - ft_stub_set_char_sizes, - ft_stub_set_pixel_sizes, -#endif BDF_Glyph_Load, - 0, /* FT_Face_GetKerningFunc */ - 0, /* FT_Face_AttachFunc */ - 0, /* FT_Face_GetAdvancesFunc */ + 0, /* FT_Face_GetKerningFunc */ + 0, /* FT_Face_AttachFunc */ + 0, /* FT_Face_GetAdvancesFunc */ BDF_Size_Request, BDF_Size_Select diff --git a/src/3rdparty/freetype/src/bdf/bdfdrivr.h b/src/3rdparty/freetype/src/bdf/bdfdrivr.h index db7093bb45..ca0dae50d2 100644 --- a/src/3rdparty/freetype/src/bdf/bdfdrivr.h +++ b/src/3rdparty/freetype/src/bdf/bdfdrivr.h @@ -38,7 +38,7 @@ FT_BEGIN_HEADER #ifdef FT_CONFIG_OPTION_PIC #error "this module does not support PIC yet" -#endif +#endif typedef struct BDF_encoding_el_ diff --git a/src/3rdparty/freetype/src/bdf/bdferror.h b/src/3rdparty/freetype/src/bdf/bdferror.h index b27fa333bb..ea545aca06 100644 --- a/src/3rdparty/freetype/src/bdf/bdferror.h +++ b/src/3rdparty/freetype/src/bdf/bdferror.h @@ -1,5 +1,5 @@ /* - * Copyright 2001, 2002 Francesco Zappa Nardelli + * Copyright 2001, 2002, 2012 Francesco Zappa Nardelli * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -33,6 +33,7 @@ #undef __FTERRORS_H__ +#undef FT_ERR_PREFIX #define FT_ERR_PREFIX BDF_Err_ #define FT_ERR_BASE FT_Mod_Err_BDF diff --git a/src/3rdparty/freetype/src/bdf/bdflib.c b/src/3rdparty/freetype/src/bdf/bdflib.c index 5fa5868c71..abcfdee7be 100644 --- a/src/3rdparty/freetype/src/bdf/bdflib.c +++ b/src/3rdparty/freetype/src/bdf/bdflib.c @@ -1,6 +1,6 @@ /* * Copyright 2000 Computing Research Labs, New Mexico State University - * Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 + * Copyright 2001-2014 * Francesco Zappa Nardelli * * Permission is hereby granted, free of charge, to any person obtaining a @@ -169,6 +169,55 @@ sizeof ( _bdf_properties[0] ); + /* An auxiliary macro to parse properties, to be used in conditionals. */ + /* It behaves like `strncmp' but also tests the following character */ + /* whether it is a whitespace or NULL. */ + /* `property' is a constant string of length `n' to compare with. */ +#define _bdf_strncmp( name, property, n ) \ + ( ft_strncmp( name, property, n ) || \ + !( name[n] == ' ' || \ + name[n] == '\0' || \ + name[n] == '\n' || \ + name[n] == '\r' || \ + name[n] == '\t' ) ) + + /* Auto correction messages. */ +#define ACMSG1 "FONT_ASCENT property missing. " \ + "Added `FONT_ASCENT %hd'.\n" +#define ACMSG2 "FONT_DESCENT property missing. " \ + "Added `FONT_DESCENT %hd'.\n" +#define ACMSG3 "Font width != actual width. Old: %hd New: %hd.\n" +#define ACMSG4 "Font left bearing != actual left bearing. " \ + "Old: %hd New: %hd.\n" +#define ACMSG5 "Font ascent != actual ascent. Old: %hd New: %hd.\n" +#define ACMSG6 "Font descent != actual descent. Old: %hd New: %hd.\n" +#define ACMSG7 "Font height != actual height. Old: %hd New: %hd.\n" +#define ACMSG8 "Glyph scalable width (SWIDTH) adjustments made.\n" +#define ACMSG9 "SWIDTH field missing at line %ld. Set automatically.\n" +#define ACMSG10 "DWIDTH field missing at line %ld. Set to glyph width.\n" +#define ACMSG11 "SIZE bits per pixel field adjusted to %hd.\n" +#define ACMSG12 "Duplicate encoding %ld (%s) changed to unencoded.\n" +#define ACMSG13 "Glyph %ld extra rows removed.\n" +#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" + + /* Error messages. */ +#define ERRMSG1 "[line %ld] Missing `%s' line.\n" +#define ERRMSG2 "[line %ld] Font header corrupted or missing fields.\n" +#define ERRMSG3 "[line %ld] Font glyphs corrupted or missing fields.\n" +#define ERRMSG4 "[line %ld] BBX too big.\n" +#define ERRMSG5 "[line %ld] `%s' value too big.\n" +#define ERRMSG6 "[line %ld] Input line too long.\n" +#define ERRMSG7 "[line %ld] Font name too long.\n" +#define ERRMSG8 "[line %ld] Invalid `%s' value.\n" +#define ERRMSG9 "[line %ld] Invalid keyword.\n" + + /* Debug messages. */ +#define DBGMSG1 " [%6ld] %s" /* no \n */ +#define DBGMSG2 " (0x%lX)\n" + + /*************************************************************************/ /* */ /* Hash table utilities for the properties. */ @@ -217,7 +266,7 @@ { hashnode* obp = ht->table, *bp, *nbp; int i, sz = ht->size; - FT_Error error = BDF_Err_Ok; + FT_Error error = FT_Err_Ok; ht->size <<= 1; @@ -245,8 +294,8 @@ hash_init( hashtable* ht, FT_Memory memory ) { - int sz = INITIAL_HT_SIZE; - FT_Error error = BDF_Err_Ok; + int sz = INITIAL_HT_SIZE; + FT_Error error = FT_Err_Ok; ht->size = sz; @@ -285,8 +334,9 @@ hashtable* ht, FT_Memory memory ) { - hashnode nn, *bp = hash_bucket( key, ht ); - FT_Error error = BDF_Err_Ok; + hashnode nn; + hashnode* bp = hash_bucket( key, ht ); + FT_Error error = FT_Err_Ok; nn = *bp; @@ -377,7 +427,8 @@ bdf_font_t* font; bdf_options_t* opts; - unsigned long have[2048]; + unsigned long have[34816]; /* must be in sync with `nmod' and `umod' */ + /* arrays from `bdf_font_t' structure */ _bdf_list_t list; FT_Memory memory; @@ -418,20 +469,20 @@ _bdf_list_ensure( _bdf_list_t* list, unsigned long num_items ) /* same as _bdf_list_t.used */ { - FT_Error error = BDF_Err_Ok; + FT_Error error = FT_Err_Ok; if ( num_items > list->size ) { unsigned long oldsize = list->size; /* same as _bdf_list_t.size */ - unsigned long newsize = oldsize + ( oldsize >> 1 ) + 4; + unsigned long newsize = oldsize + ( oldsize >> 1 ) + 5; unsigned long bigsize = (unsigned long)( FT_INT_MAX / sizeof ( char* ) ); FT_Memory memory = list->memory; if ( oldsize == bigsize ) { - error = BDF_Err_Out_Of_Memory; + error = FT_THROW( Out_Of_Memory ); goto Exit; } else if ( newsize < oldsize || newsize > bigsize ) @@ -470,13 +521,18 @@ } + /* An empty string for empty fields. */ + + static const char empty[1] = { 0 }; /* XXX eliminate this */ + + static char * _bdf_list_join( _bdf_list_t* list, int c, unsigned long *alen ) { unsigned long i, j; - char *fp, *dp; + char* dp; *alen = 0; @@ -487,24 +543,26 @@ dp = list->field[0]; for ( i = j = 0; i < list->used; i++ ) { - fp = list->field[i]; + char* fp = list->field[i]; + + while ( *fp ) dp[j++] = *fp++; if ( i + 1 < list->used ) dp[j++] = (char)c; } - dp[j] = 0; + if ( dp != empty ) + dp[j] = 0; *alen = j; return dp; } - /* An empty string for empty fields. */ - - static const char empty[1] = { 0 }; /* XXX eliminate this */ - + /* The code below ensures that we have at least 4 + 1 `field' */ + /* elements in `list' (which are possibly NULL) so that we */ + /* don't have to check the number of fields in most cases. */ static FT_Error _bdf_list_split( _bdf_list_t* list, @@ -515,11 +573,19 @@ int mult, final_empty; char *sp, *ep, *end; char seps[32]; - FT_Error error = BDF_Err_Ok; + FT_Error error = FT_Err_Ok; /* Initialize the list. */ list->used = 0; + if ( list->size ) + { + list->field[0] = (char*)empty; + list->field[1] = (char*)empty; + list->field[2] = (char*)empty; + list->field[3] = (char*)empty; + list->field[4] = (char*)empty; + } /* If the line is empty, then simply return. */ if ( linelen == 0 || line[0] == 0 ) @@ -530,7 +596,7 @@ /* this, so an error is signaled. */ if ( separators == 0 || *separators == 0 ) { - error = BDF_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); goto Exit; } @@ -616,14 +682,14 @@ unsigned long lineno, buf_size; int refill, hold, to_skip; ptrdiff_t bytes, start, end, cursor, avail; - char* buf = 0; + char* buf = 0; FT_Memory memory = stream->memory; - FT_Error error = BDF_Err_Ok; + FT_Error error = FT_Err_Ok; if ( callback == 0 ) { - error = BDF_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); goto Exit; } @@ -637,7 +703,6 @@ lineno = 1; buf[0] = 0; start = 0; - end = 0; avail = 0; cursor = 0; refill = 1; @@ -648,8 +713,9 @@ { if ( refill ) { - bytes = (ptrdiff_t)FT_Stream_TryRead( stream, (FT_Byte*)buf + cursor, - (FT_ULong)(buf_size - cursor) ); + bytes = (ptrdiff_t)FT_Stream_TryRead( + stream, (FT_Byte*)buf + cursor, + (FT_ULong)( buf_size - cursor ) ); avail = cursor + bytes; cursor = 0; refill = 0; @@ -685,7 +751,8 @@ if ( buf_size >= 65536UL ) /* limit ourselves to 64KByte */ { - error = BDF_Err_Invalid_Argument; + FT_ERROR(( "_bdf_readstream: " ERRMSG6, lineno )); + error = FT_THROW( Invalid_Argument ); goto Exit; } @@ -700,7 +767,7 @@ { bytes = avail - start; - FT_MEM_COPY( buf, buf + start, bytes ); + FT_MEM_MOVE( buf, buf + start, bytes ); cursor = bytes; avail -= bytes; @@ -714,11 +781,15 @@ hold = buf[end]; buf[end] = 0; - /* XXX: Use encoding independent value for 0x1a */ - if ( buf[start] != '#' && buf[start] != 0x1a && end > start ) + /* XXX: Use encoding independent value for 0x1A */ + if ( buf[start] != '#' && buf[start] != 0x1A && end > start ) { - error = (*cb)( buf + start, end - start, lineno, + error = (*cb)( buf + start, (unsigned long)( end - start ), lineno, (void*)&cb, client_data ); + /* Redo if we have encountered CHARS without properties. */ + if ( error == -1 ) + error = (*cb)( buf + start, (unsigned long)( end - start ), lineno, + (void*)&cb, client_data ); if ( error ) break; } @@ -752,17 +823,17 @@ 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, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 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, - 0x00, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 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 odigits[32] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, + 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, @@ -770,7 +841,7 @@ static const unsigned char ddigits[32] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -778,16 +849,13 @@ static const unsigned char hdigits[32] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x03, - 0x7e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x03, + 0x7E, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; -#define isdigok( m, d ) (m[(d) >> 3] & ( 1 << ( (d) & 7 ) ) ) - - /* Routine to convert an ASCII string into an unsigned long integer. */ static unsigned long _bdf_atoul( char* s, @@ -825,7 +893,7 @@ s += 2; } - for ( v = 0; isdigok( dmap, *s ); s++ ) + for ( v = 0; sbitset( dmap, *s ); s++ ) v = v * base + a2i[(int)*s]; if ( end != 0 ) @@ -880,7 +948,7 @@ s += 2; } - for ( v = 0; isdigok( dmap, *s ); s++ ) + for ( v = 0; sbitset( dmap, *s ); s++ ) v = v * base + a2i[(int)*s]; if ( end != 0 ) @@ -935,7 +1003,7 @@ s += 2; } - for ( v = 0; isdigok( dmap, *s ); s++ ) + for ( v = 0; sbitset( dmap, *s ); s++ ) v = (short)( v * base + a2i[(int)*s] ); if ( end != 0 ) @@ -974,10 +1042,10 @@ size_t n; bdf_property_t* p; FT_Memory memory = font->memory; - FT_Error error = BDF_Err_Ok; + FT_Error error = FT_Err_Ok; - /* First check to see if the property has */ + /* First check whether the property has */ /* already been added or not. If it has, then */ /* simply ignore it. */ if ( hash_lookup( name, &(font->proptbl) ) ) @@ -993,7 +1061,7 @@ n = ft_strlen( name ) + 1; if ( n > FT_ULONG_MAX ) - return BDF_Err_Invalid_Argument; + return FT_THROW( Invalid_Argument ); if ( FT_NEW_ARRAY( p->name, n ) ) goto Exit; @@ -1073,33 +1141,6 @@ #define _BDF_GLYPH_HEIGHT_CHECK 0x80000000UL - /* Auto correction messages. */ -#define ACMSG1 "FONT_ASCENT property missing. " \ - "Added \"FONT_ASCENT %hd\".\n" -#define ACMSG2 "FONT_DESCENT property missing. " \ - "Added \"FONT_DESCENT %hd\".\n" -#define ACMSG3 "Font width != actual width. Old: %hd New: %hd.\n" -#define ACMSG4 "Font left bearing != actual left bearing. " \ - "Old: %hd New: %hd.\n" -#define ACMSG5 "Font ascent != actual ascent. Old: %hd New: %hd.\n" -#define ACMSG6 "Font descent != actual descent. Old: %hd New: %hd.\n" -#define ACMSG7 "Font height != actual height. Old: %hd New: %hd.\n" -#define ACMSG8 "Glyph scalable width (SWIDTH) adjustments made.\n" -#define ACMSG9 "SWIDTH field missing at line %ld. Set automatically.\n" -#define ACMSG10 "DWIDTH field missing at line %ld. Set to glyph width.\n" -#define ACMSG11 "SIZE bits per pixel field adjusted to %hd.\n" -#define ACMSG12 "Duplicate encoding %ld (%s) changed to unencoded.\n" -#define ACMSG13 "Glyph %ld extra rows removed.\n" -#define ACMSG14 "Glyph %ld extra columns removed.\n" -#define ACMSG15 "Incorrect glyph count: %ld indicated but %ld found.\n" - - /* Error messages. */ -#define ERRMSG1 "[line %ld] Missing \"%s\" line.\n" -#define ERRMSG2 "[line %ld] Font header corrupted or missing fields.\n" -#define ERRMSG3 "[line %ld] Font glyphs corrupted or missing fields.\n" -#define ERRMSG4 "[line %ld] BBX too big.\n" - - static FT_Error _bdf_add_comment( bdf_font_t* font, char* comment, @@ -1107,7 +1148,7 @@ { char* cp; FT_Memory memory = font->memory; - FT_Error error = BDF_Err_Ok; + FT_Error error = FT_Err_Ok; if ( FT_RENEW_ARRAY( font->comments, @@ -1131,18 +1172,21 @@ /* default specified in the options. */ static FT_Error _bdf_set_default_spacing( bdf_font_t* font, - bdf_options_t* opts ) + bdf_options_t* opts, + unsigned long lineno ) { size_t len; char name[256]; _bdf_list_t list; FT_Memory memory; - FT_Error error = BDF_Err_Ok; + FT_Error error = FT_Err_Ok; + + FT_UNUSED( lineno ); /* only used in debug mode */ if ( font == 0 || font->name == 0 || font->name[0] == 0 ) { - error = BDF_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); goto Exit; } @@ -1156,13 +1200,14 @@ /* Limit ourselves to 256 characters in the font name. */ if ( len >= 256 ) { - error = BDF_Err_Invalid_Argument; + FT_ERROR(( "_bdf_set_default_spacing: " ERRMSG7, lineno )); + error = FT_THROW( Invalid_Argument ); goto Exit; } FT_MEM_COPY( name, font->name, len ); - error = _bdf_list_split( &list, (char *)"-", name, len ); + error = _bdf_list_split( &list, (char *)"-", name, (unsigned long)len ); if ( error ) goto Fail; @@ -1235,7 +1280,8 @@ ep = line + linelen; /* Trim the leading whitespace if it exists. */ - *sp++ = 0; + if ( *sp ) + *sp++ = 0; while ( *sp && ( *sp == ' ' || *sp == '\t' ) ) sp++; @@ -1259,18 +1305,21 @@ static FT_Error - _bdf_add_property( bdf_font_t* font, - char* name, - char* value ) + _bdf_add_property( bdf_font_t* font, + char* name, + char* value, + unsigned long lineno ) { size_t propid; hashnode hn; bdf_property_t *prop, *fp; FT_Memory memory = font->memory; - FT_Error error = BDF_Err_Ok; + FT_Error error = FT_Err_Ok; + FT_UNUSED( lineno ); /* only used in debug mode */ - /* First, check to see if the property already exists in the font. */ + + /* First, check whether the property already exists in the font. */ if ( ( hn = hash_lookup( name, (hashtable *)font->internal ) ) != 0 ) { /* The property already exists in the font, so simply replace */ @@ -1371,7 +1420,8 @@ /* If the property happens to be a comment, then it doesn't need */ /* to be added to the internal hash table. */ - if ( ft_memcmp( name, "COMMENT", 7 ) != 0 ) { + if ( _bdf_strncmp( name, "COMMENT", 7 ) != 0 ) + { /* Add the property to the font property table. */ error = hash_insert( fp->name, font->props_used, @@ -1388,17 +1438,18 @@ /* FONT_ASCENT and FONT_DESCENT need to be assigned if they are */ /* present, and the SPACING property should override the default */ /* spacing. */ - if ( ft_memcmp( name, "DEFAULT_CHAR", 12 ) == 0 ) + if ( _bdf_strncmp( name, "DEFAULT_CHAR", 12 ) == 0 ) font->default_char = fp->value.l; - else if ( ft_memcmp( name, "FONT_ASCENT", 11 ) == 0 ) + else if ( _bdf_strncmp( name, "FONT_ASCENT", 11 ) == 0 ) font->font_ascent = fp->value.l; - else if ( ft_memcmp( name, "FONT_DESCENT", 12 ) == 0 ) + else if ( _bdf_strncmp( name, "FONT_DESCENT", 12 ) == 0 ) font->font_descent = fp->value.l; - else if ( ft_memcmp( name, "SPACING", 7 ) == 0 ) + else if ( _bdf_strncmp( name, "SPACING", 7 ) == 0 ) { if ( !fp->value.atom ) { - error = BDF_Err_Invalid_File_Format; + FT_ERROR(( "_bdf_add_property: " ERRMSG8, lineno, "SPACING" )); + error = FT_THROW( Invalid_File_Format ); goto Exit; } @@ -1439,7 +1490,7 @@ bdf_font_t* font; FT_Memory memory; - FT_Error error = BDF_Err_Ok; + FT_Error error = FT_Err_Ok; FT_UNUSED( call_data ); FT_UNUSED( lineno ); /* only used in debug mode */ @@ -1451,7 +1502,7 @@ memory = font->memory; /* Check for a comment. */ - if ( ft_memcmp( line, "COMMENT", 7 ) == 0 ) + if ( _bdf_strncmp( line, "COMMENT", 7 ) == 0 ) { linelen -= 7; @@ -1468,10 +1519,10 @@ /* The very first thing expected is the number of glyphs. */ if ( !( p->flags & _BDF_GLYPHS ) ) { - if ( ft_memcmp( line, "CHARS", 5 ) != 0 ) + if ( _bdf_strncmp( line, "CHARS", 5 ) != 0 ) { FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "CHARS" )); - error = BDF_Err_Missing_Chars_Field; + error = FT_THROW( Missing_Chars_Field ); goto Exit; } @@ -1486,9 +1537,10 @@ /* Limit ourselves to 1,114,112 glyphs in the font (this is the */ /* number of code points available in Unicode). */ - if ( p->cnt >= 1114112UL ) + if ( p->cnt >= 0x110000UL ) { - error = BDF_Err_Invalid_Argument; + FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG5, lineno, "CHARS" )); + error = FT_THROW( Invalid_Argument ); goto Exit; } @@ -1501,8 +1553,16 @@ } /* Check for the ENDFONT field. */ - if ( ft_memcmp( line, "ENDFONT", 7 ) == 0 ) + if ( _bdf_strncmp( line, "ENDFONT", 7 ) == 0 ) { + if ( p->flags & _BDF_GLYPH_BITS ) + { + /* Missing ENDCHAR field. */ + FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "ENDCHAR" )); + error = FT_THROW( Corrupted_Font_Glyphs ); + goto Exit; + } + /* Sort the glyphs by encoding. */ ft_qsort( (char *)font->glyphs, font->glyphs_used, @@ -1515,7 +1575,7 @@ } /* Check for the ENDCHAR field. */ - if ( ft_memcmp( line, "ENDCHAR", 7 ) == 0 ) + if ( _bdf_strncmp( line, "ENDCHAR", 7 ) == 0 ) { p->glyph_enc = 0; p->flags &= ~_BDF_GLYPH_BITS; @@ -1523,15 +1583,15 @@ goto Exit; } - /* Check to see whether a glyph is being scanned but should be */ - /* ignored because it is an unencoded glyph. */ + /* Check whether a glyph is being scanned but should be */ + /* ignored because it is an unencoded glyph. */ if ( ( p->flags & _BDF_GLYPH ) && p->glyph_enc == -1 && p->opts->keep_unencoded == 0 ) goto Exit; /* Check for the STARTCHAR field. */ - if ( ft_memcmp( line, "STARTCHAR", 9 ) == 0 ) + if ( _bdf_strncmp( line, "STARTCHAR", 9 ) == 0 ) { /* Set the character name in the parse info first until the */ /* encoding can be checked for an unencoded character. */ @@ -1547,7 +1607,8 @@ if ( !s ) { - error = BDF_Err_Invalid_File_Format; + FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG8, lineno, "STARTCHAR" )); + error = FT_THROW( Invalid_File_Format ); goto Exit; } @@ -1558,17 +1619,19 @@ p->flags |= _BDF_GLYPH; + FT_TRACE4(( DBGMSG1, lineno, s )); + goto Exit; } /* Check for the ENCODING field. */ - if ( ft_memcmp( line, "ENCODING", 8 ) == 0 ) + if ( _bdf_strncmp( line, "ENCODING", 8 ) == 0 ) { if ( !( p->flags & _BDF_GLYPH ) ) { /* Missing STARTCHAR field. */ FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "STARTCHAR" )); - error = BDF_Err_Missing_Startchar_Field; + error = FT_THROW( Missing_Startchar_Field ); goto Exit; } @@ -1578,17 +1641,34 @@ p->glyph_enc = _bdf_atol( p->list.field[1], 0, 10 ); - /* Check that the encoding is in the range [0,65536] because */ - /* otherwise p->have (a bitmap with static size) overflows. */ - if ( (size_t)p->glyph_enc >= sizeof ( p->have ) * 8 ) + /* Normalize negative encoding values. The specification only */ + /* allows -1, but we can be more generous here. */ + if ( p->glyph_enc < -1 ) + p->glyph_enc = -1; + + /* 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 ); + + if ( p->glyph_enc < -1 ) + p->glyph_enc = -1; + + FT_TRACE4(( DBGMSG2, p->glyph_enc )); + + /* Check that the encoding is in the Unicode range because */ + /* otherwise p->have (a bitmap with static size) overflows. */ + if ( p->glyph_enc > 0 && + (size_t)p->glyph_enc >= sizeof ( p->have ) / + sizeof ( unsigned long ) * 32 ) { - error = BDF_Err_Invalid_File_Format; + FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG5, lineno, "ENCODING" )); + error = FT_THROW( Invalid_File_Format ); goto Exit; } - /* Check to see whether this encoding has already been encountered. */ - /* If it has then change it to unencoded so it gets added if */ - /* indicated. */ + /* Check whether this encoding has already been encountered. */ + /* If it has then change it to unencoded so it gets added if */ + /* indicated. */ if ( p->glyph_enc >= 0 ) { if ( _bdf_glyph_modified( p->have, p->glyph_enc ) ) @@ -1627,8 +1707,8 @@ } else { - /* Unencoded glyph. Check to see whether it should */ - /* be added or not. */ + /* Unencoded glyph. Check whether it should */ + /* be added or not. */ if ( p->opts->keep_unencoded != 0 ) { /* Allocate the next unencoded glyph. */ @@ -1669,7 +1749,7 @@ else glyph = font->glyphs + ( font->glyphs_used - 1 ); - /* Check to see whether a bitmap is being constructed. */ + /* Check whether a bitmap is being constructed. */ if ( p->flags & _BDF_BITMAP ) { /* If there are more rows than are specified in the glyph metrics, */ @@ -1694,19 +1774,32 @@ for ( i = 0; i < nibbles; i++ ) { c = line[i]; + if ( !sbitset( hdigits, c ) ) + break; *bp = (FT_Byte)( ( *bp << 4 ) + a2i[c] ); if ( i + 1 < nibbles && ( i & 1 ) ) *++bp = 0; } + /* If any line has not enough columns, */ + /* indicate they have been padded with zero bits. */ + if ( i < nibbles && + !( p->flags & _BDF_GLYPH_WIDTH_CHECK ) ) + { + FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG16, glyph->encoding )); + p->flags |= _BDF_GLYPH_WIDTH_CHECK; + font->modified = 1; + } + /* Remove possible garbage at the right. */ mask_index = ( glyph->bbx.width * p->font->bpp ) & 7; if ( glyph->bbx.width ) *bp &= nibble_mask[mask_index]; /* If any line has extra columns, indicate they have been removed. */ - if ( ( line[nibbles] == '0' || a2i[(int)line[nibbles]] != 0 ) && - !( p->flags & _BDF_GLYPH_WIDTH_CHECK ) ) + if ( i == nibbles && + sbitset( hdigits, line[nibbles] ) && + !( p->flags & _BDF_GLYPH_WIDTH_CHECK ) ) { FT_TRACE2(( "_bdf_parse_glyphs: " ACMSG14, glyph->encoding )); p->flags |= _BDF_GLYPH_WIDTH_CHECK; @@ -1718,15 +1811,10 @@ } /* Expect the SWIDTH (scalable width) field next. */ - if ( ft_memcmp( line, "SWIDTH", 6 ) == 0 ) + if ( _bdf_strncmp( line, "SWIDTH", 6 ) == 0 ) { if ( !( p->flags & _BDF_ENCODING ) ) - { - /* Missing ENCODING field. */ - FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "ENCODING" )); - error = BDF_Err_Missing_Encoding_Field; - goto Exit; - } + goto Missing_Encoding; error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); if ( error ) @@ -1739,8 +1827,11 @@ } /* Expect the DWIDTH (scalable width) field next. */ - if ( ft_memcmp( line, "DWIDTH", 6 ) == 0 ) + if ( _bdf_strncmp( line, "DWIDTH", 6 ) == 0 ) { + if ( !( p->flags & _BDF_ENCODING ) ) + goto Missing_Encoding; + error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); if ( error ) goto Exit; @@ -1764,8 +1855,11 @@ } /* Expect the BBX field next. */ - if ( ft_memcmp( line, "BBX", 3 ) == 0 ) + if ( _bdf_strncmp( line, "BBX", 3 ) == 0 ) { + if ( !( p->flags & _BDF_ENCODING ) ) + goto Missing_Encoding; + error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); if ( error ) goto Exit; @@ -1829,7 +1923,7 @@ } /* And finally, gather up the bitmap. */ - if ( ft_memcmp( line, "BITMAP", 6 ) == 0 ) + if ( _bdf_strncmp( line, "BITMAP", 6 ) == 0 ) { unsigned long bitmap_size; @@ -1838,18 +1932,18 @@ { /* Missing BBX field. */ FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "BBX" )); - error = BDF_Err_Missing_Bbx_Field; + error = FT_THROW( Missing_Bbx_Field ); goto Exit; } /* Allocate enough space for the bitmap. */ - glyph->bpr = ( glyph->bbx.width * p->font->bpp + 7 ) >> 3; + glyph->bpr = ( glyph->bbx.width * p->font->bpp + 7 ) >> 3; bitmap_size = glyph->bpr * glyph->bbx.height; - if ( bitmap_size > 0xFFFFU ) + if ( glyph->bpr > 0xFFFFU || bitmap_size > 0xFFFFU ) { FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG4, lineno )); - error = BDF_Err_Bbx_Too_Big; + error = FT_THROW( Bbx_Too_Big ); goto Exit; } else @@ -1864,9 +1958,19 @@ goto Exit; } - error = BDF_Err_Invalid_File_Format; + FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG9, lineno )); + error = FT_THROW( Invalid_File_Format ); + goto Exit; + + Missing_Encoding: + /* Missing ENCODING field. */ + FT_ERROR(( "_bdf_parse_glyphs: " ERRMSG1, lineno, "ENCODING" )); + error = FT_THROW( Missing_Encoding_Field ); Exit: + if ( error && ( p->flags & _BDF_GLYPH ) ) + FT_FREE( p->glyph_name ); + return error; } @@ -1885,7 +1989,7 @@ char* name; char* value; char nbuf[128]; - FT_Error error = BDF_Err_Ok; + FT_Error error = FT_Err_Ok; FT_UNUSED( lineno ); @@ -1894,7 +1998,7 @@ p = (_bdf_parse_t *) client_data; /* Check for the end of the properties. */ - if ( ft_memcmp( line, "ENDPROPERTIES", 13 ) == 0 ) + if ( _bdf_strncmp( line, "ENDPROPERTIES", 13 ) == 0 ) { /* If the FONT_ASCENT or FONT_DESCENT properties have not been */ /* encountered yet, then make sure they are added as properties and */ @@ -1906,7 +2010,8 @@ { p->font->font_ascent = p->font->bbx.ascent; ft_sprintf( nbuf, "%hd", p->font->bbx.ascent ); - error = _bdf_add_property( p->font, (char *)"FONT_ASCENT", nbuf ); + error = _bdf_add_property( p->font, (char *)"FONT_ASCENT", + nbuf, lineno ); if ( error ) goto Exit; @@ -1918,7 +2023,8 @@ { p->font->font_descent = p->font->bbx.descent; ft_sprintf( nbuf, "%hd", p->font->bbx.descent ); - error = _bdf_add_property( p->font, (char *)"FONT_DESCENT", nbuf ); + error = _bdf_add_property( p->font, (char *)"FONT_DESCENT", + nbuf, lineno ); if ( error ) goto Exit; @@ -1933,24 +2039,24 @@ } /* Ignore the _XFREE86_GLYPH_RANGES properties. */ - if ( ft_memcmp( line, "_XFREE86_GLYPH_RANGES", 21 ) == 0 ) + if ( _bdf_strncmp( line, "_XFREE86_GLYPH_RANGES", 21 ) == 0 ) goto Exit; /* Handle COMMENT fields and properties in a special way to preserve */ /* the spacing. */ - if ( ft_memcmp( line, "COMMENT", 7 ) == 0 ) + if ( _bdf_strncmp( line, "COMMENT", 7 ) == 0 ) { name = value = line; value += 7; if ( *value ) *value++ = 0; - error = _bdf_add_property( p->font, name, value ); + error = _bdf_add_property( p->font, name, value, lineno ); if ( error ) goto Exit; } else if ( _bdf_is_atom( line, linelen, &name, &value, p->font ) ) { - error = _bdf_add_property( p->font, name, value ); + error = _bdf_add_property( p->font, name, value, lineno ); if ( error ) goto Exit; } @@ -1964,7 +2070,7 @@ _bdf_list_shift( &p->list, 1 ); value = _bdf_list_join( &p->list, ' ', &vlen ); - error = _bdf_add_property( p->font, name, value ); + error = _bdf_add_property( p->font, name, value, lineno ); if ( error ) goto Exit; } @@ -1989,7 +2095,7 @@ char *s; FT_Memory memory = NULL; - FT_Error error = BDF_Err_Ok; + FT_Error error = FT_Err_Ok; FT_UNUSED( lineno ); /* only used in debug mode */ @@ -2002,7 +2108,7 @@ /* Check for a comment. This is done to handle those fonts that have */ /* comments before the STARTFONT line for some reason. */ - if ( ft_memcmp( line, "COMMENT", 7 ) == 0 ) + if ( _bdf_strncmp( line, "COMMENT", 7 ) == 0 ) { if ( p->opts->keep_comments != 0 && p->font != 0 ) { @@ -2028,10 +2134,11 @@ { memory = p->memory; - if ( ft_memcmp( line, "STARTFONT", 9 ) != 0 ) + if ( _bdf_strncmp( line, "STARTFONT", 9 ) != 0 ) { - /* No STARTFONT field is a good indication of a problem. */ - error = BDF_Err_Missing_Startfont_Field; + /* we don't emit an error message since this code gets */ + /* explicitly caught one level higher */ + error = FT_THROW( Missing_Startfont_Field ); goto Exit; } @@ -2075,8 +2182,16 @@ } /* Check for the start of the properties. */ - if ( ft_memcmp( line, "STARTPROPERTIES", 15 ) == 0 ) + if ( _bdf_strncmp( line, "STARTPROPERTIES", 15 ) == 0 ) { + if ( !( p->flags & _BDF_FONT_BBX ) ) + { + /* Missing the FONTBOUNDINGBOX field. */ + FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONTBOUNDINGBOX" )); + error = FT_THROW( Missing_Fontboundingbox_Field ); + goto Exit; + } + error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); if ( error ) goto Exit; @@ -2084,7 +2199,10 @@ p->cnt = p->font->props_size = _bdf_atoul( p->list.field[1], 0, 10 ); if ( FT_NEW_ARRAY( p->font->props, p->cnt ) ) + { + p->font->props_size = 0; goto Exit; + } p->flags |= _BDF_PROPS; *next = _bdf_parse_properties; @@ -2093,13 +2211,13 @@ } /* Check for the FONTBOUNDINGBOX field. */ - if ( ft_memcmp( line, "FONTBOUNDINGBOX", 15 ) == 0 ) + 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" )); - error = BDF_Err_Missing_Size_Field; + error = FT_THROW( Missing_Size_Field ); goto Exit; } @@ -2124,7 +2242,7 @@ } /* The next thing to check for is the FONT field. */ - if ( ft_memcmp( line, "FONT", 4 ) == 0 ) + if ( _bdf_strncmp( line, "FONT", 4 ) == 0 ) { error = _bdf_list_split( &p->list, (char *)" +", line, linelen ); if ( error ) @@ -2135,17 +2253,21 @@ if ( !s ) { - error = BDF_Err_Invalid_File_Format; + FT_ERROR(( "_bdf_parse_start: " ERRMSG8, lineno, "FONT" )); + error = FT_THROW( Invalid_File_Format ); goto Exit; } + /* Allowing multiple `FONT' lines (which is invalid) doesn't hurt... */ + FT_FREE( p->font->name ); + if ( FT_NEW_ARRAY( p->font->name, slen + 1 ) ) goto Exit; FT_MEM_COPY( p->font->name, s, slen + 1 ); /* If the font name is an XLFD name, set the spacing to the one in */ /* the font name. If there is no spacing fall back on the default. */ - error = _bdf_set_default_spacing( p->font, p->opts ); + error = _bdf_set_default_spacing( p->font, p->opts, lineno ); if ( error ) goto Exit; @@ -2155,13 +2277,13 @@ } /* Check for the SIZE field. */ - if ( ft_memcmp( line, "SIZE", 4 ) == 0 ) + if ( _bdf_strncmp( line, "SIZE", 4 ) == 0 ) { if ( !( p->flags & _BDF_FONT_NAME ) ) { /* Missing the FONT field. */ FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONT" )); - error = BDF_Err_Missing_Font_Field; + error = FT_THROW( Missing_Font_Field ); goto Exit; } @@ -2208,7 +2330,49 @@ goto Exit; } - error = BDF_Err_Invalid_File_Format; + /* Check for the CHARS field -- font properties are optional */ + if ( _bdf_strncmp( line, "CHARS", 5 ) == 0 ) + { + char nbuf[128]; + + + if ( !( p->flags & _BDF_FONT_BBX ) ) + { + /* Missing the FONTBOUNDINGBOX field. */ + FT_ERROR(( "_bdf_parse_start: " ERRMSG1, lineno, "FONTBOUNDINGBOX" )); + error = FT_THROW( Missing_Fontboundingbox_Field ); + goto Exit; + } + + /* Add the two standard X11 properties which are required */ + /* for compiling fonts. */ + p->font->font_ascent = p->font->bbx.ascent; + ft_sprintf( nbuf, "%hd", p->font->bbx.ascent ); + error = _bdf_add_property( p->font, (char *)"FONT_ASCENT", + nbuf, lineno ); + if ( error ) + goto Exit; + FT_TRACE2(( "_bdf_parse_properties: " ACMSG1, p->font->bbx.ascent )); + + p->font->font_descent = p->font->bbx.descent; + ft_sprintf( nbuf, "%hd", p->font->bbx.descent ); + error = _bdf_add_property( p->font, (char *)"FONT_DESCENT", + nbuf, lineno ); + if ( error ) + goto Exit; + FT_TRACE2(( "_bdf_parse_properties: " ACMSG2, p->font->bbx.descent )); + + p->font->modified = 1; + + *next = _bdf_parse_glyphs; + + /* A special return value. */ + error = -1; + goto Exit; + } + + FT_ERROR(( "_bdf_parse_start: " ERRMSG9, lineno )); + error = FT_THROW( Invalid_File_Format ); Exit: return error; @@ -2229,10 +2393,10 @@ bdf_font_t* *font ) { unsigned long lineno = 0; /* make compiler happy */ - _bdf_parse_t *p; + _bdf_parse_t *p = NULL; - FT_Memory memory = extmemory; - FT_Error error = BDF_Err_Ok; + FT_Memory memory = extmemory; /* needed for FT_NEW */ + FT_Error error = FT_Err_Ok; if ( FT_NEW( p ) ) @@ -2254,7 +2418,6 @@ { /* If the font is not proportional, set the font's monowidth */ /* field to the width of the font bounding box. */ - memory = p->font->memory; if ( p->font->spacing != BDF_PROPORTIONAL ) p->font->monowidth = p->font->bbx.width; @@ -2320,22 +2483,20 @@ if ( p->flags & _BDF_START ) { + /* The ENDFONT field was never reached or did not exist. */ + if ( !( p->flags & _BDF_GLYPHS ) ) { - /* The ENDFONT field was never reached or did not exist. */ - if ( !( p->flags & _BDF_GLYPHS ) ) - { - /* Error happened while parsing header. */ - FT_ERROR(( "bdf_load_font: " ERRMSG2, lineno )); - error = BDF_Err_Corrupted_Font_Header; - goto Exit; - } - else - { - /* Error happened when parsing glyphs. */ - FT_ERROR(( "bdf_load_font: " ERRMSG3, lineno )); - error = BDF_Err_Corrupted_Font_Glyphs; - goto Exit; - } + /* Error happened while parsing header. */ + FT_ERROR(( "bdf_load_font: " ERRMSG2, lineno )); + error = FT_THROW( Corrupted_Font_Header ); + goto Exit; + } + else + { + /* Error happened when parsing glyphs. */ + FT_ERROR(( "bdf_load_font: " ERRMSG3, lineno )); + error = FT_THROW( Corrupted_Font_Glyphs ); + goto Exit; } } @@ -2344,7 +2505,8 @@ /* Make sure the comments are NULL terminated if they exist. */ memory = p->font->memory; - if ( p->font->comments_len > 0 ) { + if ( p->font->comments_len > 0 ) + { if ( FT_RENEW_ARRAY( p->font->comments, p->font->comments_len, p->font->comments_len + 1 ) ) @@ -2353,8 +2515,8 @@ p->font->comments[p->font->comments_len] = 0; } } - else if ( error == BDF_Err_Ok ) - error = BDF_Err_Invalid_File_Format; + else if ( error == FT_Err_Ok ) + error = FT_THROW( Invalid_File_Format ); *font = p->font; @@ -2448,8 +2610,8 @@ hash_free( &(font->proptbl), memory ); /* Free up the user defined properties. */ - for (prop = font->user_props, i = 0; - i < font->nuser_props; i++, prop++ ) + for ( prop = font->user_props, i = 0; + i < font->nuser_props; i++, prop++ ) { FT_FREE( prop->name ); if ( prop->format == BDF_ATOM ) |