diff options
| author | Rémi Verschelde | 2016-07-22 23:29:25 +0200 |
|---|---|---|
| committer | Rémi Verschelde | 2016-07-22 23:29:25 +0200 |
| commit | 4d4cb1bfabc8545ad593149df65340389bcb7ab4 (patch) | |
| tree | e4639514ae7059a57a59933e8518215d827b9b3d /drivers/freetype/src/pcf | |
| parent | b13bbcecc31851099d49ac7f435ea7c80de5d9a3 (diff) | |
| download | godot-4d4cb1bfabc8545ad593149df65340389bcb7ab4.tar.gz godot-4d4cb1bfabc8545ad593149df65340389bcb7ab4.tar.zst godot-4d4cb1bfabc8545ad593149df65340389bcb7ab4.zip | |
FreeType: Update to upstream version 2.6.5
The only diffs to the upstream sources are to be found in `include/ft2build.h`
and `include/freetype/config/ftoption.h`.
Diffstat (limited to 'drivers/freetype/src/pcf')
| -rw-r--r-- | drivers/freetype/src/pcf/Jamfile | 7 | ||||
| -rw-r--r-- | drivers/freetype/src/pcf/pcf.h | 15 | ||||
| -rw-r--r-- | drivers/freetype/src/pcf/pcfdrivr.c | 155 | ||||
| -rw-r--r-- | drivers/freetype/src/pcf/pcfdrivr.h | 6 | ||||
| -rw-r--r-- | drivers/freetype/src/pcf/pcferror.h | 8 | ||||
| -rw-r--r-- | drivers/freetype/src/pcf/pcfread.c | 252 | ||||
| -rw-r--r-- | drivers/freetype/src/pcf/pcfread.h | 6 | ||||
| -rw-r--r-- | drivers/freetype/src/pcf/pcfutil.c | 12 | ||||
| -rw-r--r-- | drivers/freetype/src/pcf/pcfutil.h | 6 | ||||
| -rw-r--r-- | drivers/freetype/src/pcf/rules.mk | 5 |
10 files changed, 319 insertions, 153 deletions
diff --git a/drivers/freetype/src/pcf/Jamfile b/drivers/freetype/src/pcf/Jamfile index 752fcac2a..9ebe6a2cb 100644 --- a/drivers/freetype/src/pcf/Jamfile +++ b/drivers/freetype/src/pcf/Jamfile @@ -1,6 +1,6 @@ # FreeType 2 src/pcf Jamfile # -# Copyright 2001, 2003 by +# Copyright 2001-2016 by # David Turner, Robert Wilhelm, and Werner Lemberg. # # This file is part of the FreeType project, and may only be used, modified, @@ -16,7 +16,10 @@ SubDir FT2_TOP $(FT2_SRC_DIR) pcf ; if $(FT2_MULTI) { - _sources = pcfdrivr pcfread pcfutil ; + _sources = pcfdrivr + pcfread + pcfutil + ; } else { diff --git a/drivers/freetype/src/pcf/pcf.h b/drivers/freetype/src/pcf/pcf.h index af0ffc337..c726e5ec6 100644 --- a/drivers/freetype/src/pcf/pcf.h +++ b/drivers/freetype/src/pcf/pcf.h @@ -25,8 +25,8 @@ THE SOFTWARE. */ -#ifndef __PCF_H__ -#define __PCF_H__ +#ifndef PCF_H_ +#define PCF_H_ #include <ft2build.h> @@ -148,9 +148,9 @@ FT_BEGIN_HEADER int nprops; PCF_Property properties; - FT_Long nmetrics; + FT_ULong nmetrics; PCF_Metric metrics; - FT_Long nencodings; + FT_ULong nencodings; PCF_Encoding encodings; FT_Short defaultChar; @@ -226,12 +226,13 @@ FT_BEGIN_HEADER #define GLYPHPADOPTIONS 4 /* I'm not sure about this */ FT_LOCAL( FT_Error ) - pcf_load_font( FT_Stream, - PCF_Face ); + pcf_load_font( FT_Stream stream, + PCF_Face face, + FT_Long face_index ); FT_END_HEADER -#endif /* __PCF_H__ */ +#endif /* PCF_H_ */ /* END */ diff --git a/drivers/freetype/src/pcf/pcfdrivr.c b/drivers/freetype/src/pcf/pcfdrivr.c index df25a645a..0996d1079 100644 --- a/drivers/freetype/src/pcf/pcfdrivr.c +++ b/drivers/freetype/src/pcf/pcfdrivr.c @@ -2,7 +2,7 @@ FreeType font driver for pcf files - Copyright (C) 2000-2004, 2006-2011, 2013 by + Copyright (C) 2000-2004, 2006-2011, 2013, 2014 by Francesco Zappa Nardelli Permission is hereby granted, free of charge, to any person obtaining a copy @@ -48,7 +48,7 @@ THE SOFTWARE. #define FT_COMPONENT trace_pcfread #include FT_SERVICE_BDF_H -#include FT_SERVICE_XFREE86_NAME_H +#include FT_SERVICE_FONT_FORMAT_H /*************************************************************************/ @@ -64,7 +64,7 @@ THE SOFTWARE. typedef struct PCF_CMapRec_ { FT_CMapRec root; - FT_UInt num_encodings; + FT_ULong num_encodings; PCF_Encoding encodings; } PCF_CMapRec, *PCF_CMap; @@ -80,7 +80,7 @@ THE SOFTWARE. FT_UNUSED( init_data ); - cmap->num_encodings = (FT_UInt)face->nencodings; + cmap->num_encodings = face->nencodings; cmap->encodings = face->encodings; return FT_Err_Ok; @@ -104,7 +104,7 @@ THE SOFTWARE. { PCF_CMap cmap = (PCF_CMap)pcfcmap; PCF_Encoding encodings = cmap->encodings; - FT_UInt min, max, mid; + FT_ULong min, max, mid; FT_UInt result = 0; @@ -117,7 +117,7 @@ THE SOFTWARE. mid = ( min + max ) >> 1; - code = encodings[mid].enc; + code = (FT_ULong)encodings[mid].enc; if ( charcode == code ) { @@ -141,7 +141,7 @@ THE SOFTWARE. { PCF_CMap cmap = (PCF_CMap)pcfcmap; PCF_Encoding encodings = cmap->encodings; - FT_UInt min, max, mid; + FT_ULong min, max, mid; FT_ULong charcode = *acharcode + 1; FT_UInt result = 0; @@ -155,7 +155,7 @@ THE SOFTWARE. mid = ( min + max ) >> 1; - code = encodings[mid].enc; + code = (FT_ULong)encodings[mid].enc; if ( charcode == code ) { @@ -172,7 +172,7 @@ THE SOFTWARE. charcode = 0; if ( min < cmap->num_encodings ) { - charcode = encodings[min].enc; + charcode = (FT_ULong)encodings[min].enc; result = encodings[min].glyph + 1; } @@ -189,7 +189,7 @@ THE SOFTWARE. } - FT_CALLBACK_TABLE_DEF + static const FT_CMap_ClassRec pcf_cmap_class = { sizeof ( PCF_CMapRec ), @@ -218,25 +218,24 @@ THE SOFTWARE. FT_FREE( face->metrics ); /* free properties */ + if ( face->properties ) { - PCF_Property prop; - FT_Int i; + FT_Int i; - if ( face->properties ) + for ( i = 0; i < face->nprops; i++ ) { - for ( i = 0; i < face->nprops; i++ ) - { - prop = &face->properties[i]; + PCF_Property prop = &face->properties[i]; - if ( prop ) - { - FT_FREE( prop->name ); - if ( prop->isString ) - FT_FREE( prop->value.atom ); - } + + if ( prop ) + { + FT_FREE( prop->name ); + if ( prop->isString ) + FT_FREE( prop->value.atom ); } } + FT_FREE( face->properties ); } @@ -264,16 +263,15 @@ THE SOFTWARE. FT_Parameter* params ) { PCF_Face face = (PCF_Face)pcfface; - FT_Error error = FT_Err_Ok; + FT_Error error; FT_UNUSED( num_params ); FT_UNUSED( params ); - FT_UNUSED( face_index ); FT_TRACE2(( "PCF driver\n" )); - error = pcf_load_font( stream, face ); + error = pcf_load_font( stream, face, face_index ); if ( error ) { PCF_Face_Done( pcfface ); @@ -334,7 +332,7 @@ THE SOFTWARE. stream = pcfface->stream; - error = pcf_load_font( stream, face ); + error = pcf_load_font( stream, face, face_index ); if ( error ) goto Fail; @@ -347,6 +345,21 @@ THE SOFTWARE. #endif } + /* PCF cannot have multiple faces in a single font file. + * XXX: A non-zero face_index is already an invalid argument, but + * Type1, Type42 drivers have a convention to return + * an invalid argument error when the font could be + * opened by the specified driver. + */ + if ( face_index < 0 ) + goto Exit; + else if ( face_index > 0 && ( face_index & 0xFFFF ) > 0 ) + { + FT_ERROR(( "PCF_Face_Init: invalid face index\n" )); + PCF_Face_Done( pcfface ); + return FT_THROW( Invalid_Argument ); + } + /* set up charmap */ { FT_String *charset_registry = face->charset_registry; @@ -420,9 +433,9 @@ THE SOFTWARE. FT_Select_Metrics( size->face, strike_index ); - size->metrics.ascender = accel->fontAscent << 6; - size->metrics.descender = -accel->fontDescent << 6; - size->metrics.max_advance = accel->maxbounds.characterWidth << 6; + size->metrics.ascender = accel->fontAscent * 64; + size->metrics.descender = -accel->fontDescent * 64; + size->metrics.max_advance = accel->maxbounds.characterWidth * 64; return FT_Err_Ok; } @@ -477,14 +490,20 @@ THE SOFTWARE. FT_Error error = FT_Err_Ok; FT_Bitmap* bitmap = &slot->bitmap; PCF_Metric metric; - FT_Offset bytes; + FT_ULong bytes; FT_UNUSED( load_flags ); - FT_TRACE4(( "load_glyph %d ---", glyph_index )); + FT_TRACE1(( "PCF_Glyph_Load: glyph index %d\n", glyph_index )); + + if ( !face ) + { + error = FT_THROW( Invalid_Face_Handle ); + goto Exit; + } - if ( !face || glyph_index >= (FT_UInt)face->root.num_glyphs ) + if ( glyph_index >= (FT_UInt)face->root.num_glyphs ) { error = FT_THROW( Invalid_Argument ); goto Exit; @@ -497,8 +516,10 @@ THE SOFTWARE. metric = face->metrics + glyph_index; - bitmap->rows = metric->ascent + metric->descent; - bitmap->width = metric->rightSideBearing - metric->leftSideBearing; + bitmap->rows = (unsigned int)( metric->ascent + + metric->descent ); + bitmap->width = (unsigned int)( metric->rightSideBearing - + metric->leftSideBearing ); bitmap->num_grays = 1; bitmap->pixel_mode = FT_PIXEL_MODE_MONO; @@ -510,19 +531,19 @@ THE SOFTWARE. switch ( PCF_GLYPH_PAD( face->bitmapsFormat ) ) { case 1: - bitmap->pitch = ( bitmap->width + 7 ) >> 3; + bitmap->pitch = (int)( ( bitmap->width + 7 ) >> 3 ); break; case 2: - bitmap->pitch = ( ( bitmap->width + 15 ) >> 4 ) << 1; + bitmap->pitch = (int)( ( ( bitmap->width + 15 ) >> 4 ) << 1 ); break; case 4: - bitmap->pitch = ( ( bitmap->width + 31 ) >> 5 ) << 2; + bitmap->pitch = (int)( ( ( bitmap->width + 31 ) >> 5 ) << 2 ); break; case 8: - bitmap->pitch = ( ( bitmap->width + 63 ) >> 6 ) << 3; + bitmap->pitch = (int)( ( ( bitmap->width + 63 ) >> 6 ) << 3 ); break; default: @@ -530,7 +551,7 @@ THE SOFTWARE. } /* XXX: to do: are there cases that need repadding the bitmap? */ - bytes = bitmap->pitch * bitmap->rows; + bytes = (FT_ULong)bitmap->pitch * bitmap->rows; error = ft_glyphslot_alloc_bitmap( slot, (FT_ULong)bytes ); if ( error ) @@ -565,18 +586,16 @@ THE SOFTWARE. slot->bitmap_left = metric->leftSideBearing; slot->bitmap_top = metric->ascent; - slot->metrics.horiAdvance = metric->characterWidth << 6; - slot->metrics.horiBearingX = metric->leftSideBearing << 6; - slot->metrics.horiBearingY = metric->ascent << 6; - slot->metrics.width = ( metric->rightSideBearing - - metric->leftSideBearing ) << 6; - slot->metrics.height = bitmap->rows << 6; + slot->metrics.horiAdvance = (FT_Pos)( metric->characterWidth * 64 ); + slot->metrics.horiBearingX = (FT_Pos)( metric->leftSideBearing * 64 ); + slot->metrics.horiBearingY = (FT_Pos)( metric->ascent * 64 ); + slot->metrics.width = (FT_Pos)( ( metric->rightSideBearing - + metric->leftSideBearing ) * 64 ); + slot->metrics.height = (FT_Pos)( bitmap->rows * 64 ); ft_synthesize_vertical_metrics( &slot->metrics, ( face->accel.fontAscent + - face->accel.fontDescent ) << 6 ); - - FT_TRACE4(( " --- ok\n" )); + face->accel.fontDescent ) * 64 ); Exit: return error; @@ -640,8 +659,8 @@ THE SOFTWARE. static const FT_Service_BDFRec pcf_service_bdf = { - (FT_BDF_GetCharsetIdFunc)pcf_get_charset_id, - (FT_BDF_GetPropertyFunc) pcf_get_bdf_property + (FT_BDF_GetCharsetIdFunc)pcf_get_charset_id, /* get_charset_id */ + (FT_BDF_GetPropertyFunc) pcf_get_bdf_property /* get_property */ }; @@ -653,8 +672,8 @@ THE SOFTWARE. static const FT_ServiceDescRec pcf_services[] = { - { FT_SERVICE_ID_BDF, &pcf_service_bdf }, - { FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_PCF }, + { FT_SERVICE_ID_BDF, &pcf_service_bdf }, + { FT_SERVICE_ID_FONT_FORMAT, FT_FONT_FORMAT_PCF }, { NULL, NULL } }; @@ -681,32 +700,32 @@ THE SOFTWARE. 0x10000L, 0x20000L, - 0, + 0, /* module-specific interface */ - 0, /* FT_Module_Constructor */ - 0, /* FT_Module_Destructor */ - pcf_driver_requester + 0, /* FT_Module_Constructor module_init */ + 0, /* FT_Module_Destructor module_done */ + pcf_driver_requester /* FT_Module_Requester get_interface */ }, sizeof ( PCF_FaceRec ), sizeof ( FT_SizeRec ), sizeof ( FT_GlyphSlotRec ), - PCF_Face_Init, - PCF_Face_Done, - 0, /* FT_Size_InitFunc */ - 0, /* FT_Size_DoneFunc */ - 0, /* FT_Slot_InitFunc */ - 0, /* FT_Slot_DoneFunc */ + PCF_Face_Init, /* FT_Face_InitFunc init_face */ + PCF_Face_Done, /* FT_Face_DoneFunc done_face */ + 0, /* FT_Size_InitFunc init_size */ + 0, /* FT_Size_DoneFunc done_size */ + 0, /* FT_Slot_InitFunc init_slot */ + 0, /* FT_Slot_DoneFunc done_slot */ - PCF_Glyph_Load, + PCF_Glyph_Load, /* FT_Slot_LoadFunc load_glyph */ - 0, /* FT_Face_GetKerningFunc */ - 0, /* FT_Face_AttachFunc */ - 0, /* FT_Face_GetAdvancesFunc */ + 0, /* FT_Face_GetKerningFunc get_kerning */ + 0, /* FT_Face_AttachFunc attach_file */ + 0, /* FT_Face_GetAdvancesFunc get_advances */ - PCF_Size_Request, - PCF_Size_Select + PCF_Size_Request, /* FT_Size_RequestFunc request_size */ + PCF_Size_Select /* FT_Size_SelectFunc select_size */ }; diff --git a/drivers/freetype/src/pcf/pcfdrivr.h b/drivers/freetype/src/pcf/pcfdrivr.h index 54614951b..29d30497c 100644 --- a/drivers/freetype/src/pcf/pcfdrivr.h +++ b/drivers/freetype/src/pcf/pcfdrivr.h @@ -25,8 +25,8 @@ THE SOFTWARE. */ -#ifndef __PCFDRIVR_H__ -#define __PCFDRIVR_H__ +#ifndef PCFDRIVR_H_ +#define PCFDRIVR_H_ #include <ft2build.h> #include FT_INTERNAL_DRIVER_H @@ -42,7 +42,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* __PCFDRIVR_H__ */ +#endif /* PCFDRIVR_H_ */ /* END */ diff --git a/drivers/freetype/src/pcf/pcferror.h b/drivers/freetype/src/pcf/pcferror.h index e51fff8ea..add8ef223 100644 --- a/drivers/freetype/src/pcf/pcferror.h +++ b/drivers/freetype/src/pcf/pcferror.h @@ -22,12 +22,12 @@ /* */ /*************************************************************************/ -#ifndef __PCFERROR_H__ -#define __PCFERROR_H__ +#ifndef PCFERROR_H_ +#define PCFERROR_H_ #include FT_MODULE_ERRORS_H -#undef __FTERRORS_H__ +#undef FTERRORS_H_ #undef FT_ERR_PREFIX #define FT_ERR_PREFIX PCF_Err_ @@ -35,7 +35,7 @@ #include FT_ERRORS_H -#endif /* __PCFERROR_H__ */ +#endif /* PCFERROR_H_ */ /* END */ diff --git a/drivers/freetype/src/pcf/pcfread.c b/drivers/freetype/src/pcf/pcfread.c index 3c1bb7dfa..a86b45d6b 100644 --- a/drivers/freetype/src/pcf/pcfread.c +++ b/drivers/freetype/src/pcf/pcfread.c @@ -2,7 +2,7 @@ FreeType font driver for pcf fonts - Copyright 2000-2010, 2012, 2013 by + Copyright 2000-2010, 2012-2014 by Francesco Zappa Nardelli Permission is hereby granted, free of charge, to any person obtaining a copy @@ -78,7 +78,7 @@ THE SOFTWARE. FT_FRAME_START( 16 ), FT_FRAME_ULONG_LE( type ), FT_FRAME_ULONG_LE( format ), - FT_FRAME_ULONG_LE( size ), + FT_FRAME_ULONG_LE( size ), /* rounded up to a multiple of 4 */ FT_FRAME_ULONG_LE( offset ), FT_FRAME_END }; @@ -95,16 +95,29 @@ THE SOFTWARE. FT_Memory memory = FT_FACE( face )->memory; FT_UInt n; + FT_ULong size; - if ( FT_STREAM_SEEK ( 0 ) || - FT_STREAM_READ_FIELDS ( pcf_toc_header, toc ) ) + + if ( FT_STREAM_SEEK( 0 ) || + FT_STREAM_READ_FIELDS( pcf_toc_header, toc ) ) return FT_THROW( Cannot_Open_Resource ); - if ( toc->version != PCF_FILE_VERSION || - toc->count > FT_ARRAY_MAX( face->toc.tables ) || - toc->count == 0 ) + if ( toc->version != PCF_FILE_VERSION || + toc->count == 0 ) + return FT_THROW( Invalid_File_Format ); + + if ( stream->size < 16 ) return FT_THROW( Invalid_File_Format ); + /* we need 16 bytes per TOC entry */ + if ( toc->count > stream->size >> 4 ) + { + FT_TRACE0(( "pcf_read_TOC: adjusting number of tables" + " (from %d to %d)\n", + toc->count, stream->size >> 4 )); + toc->count = stream->size >> 4; + } + if ( FT_NEW_ARRAY( face->toc.tables, toc->count ) ) return FT_THROW( Out_Of_Memory ); @@ -144,13 +157,62 @@ THE SOFTWARE. if ( ( tables[i].size > tables[i + 1].offset ) || ( tables[i].offset > tables[i + 1].offset - tables[i].size ) ) - return FT_THROW( Invalid_Offset ); + { + error = FT_THROW( Invalid_Offset ); + goto Exit; + } } if ( !have_change ) break; } + /* + * We now check whether the `size' and `offset' values are reasonable: + * `offset' + `size' must not exceed the stream size. + * + * Note, however, that X11's `pcfWriteFont' routine (used by the + * `bdftopcf' program to create PDF font files) has two special + * features. + * + * - It always assigns the accelerator table a size of 100 bytes in the + * TOC, regardless of its real size, which can vary between 34 and 72 + * bytes. + * + * - Due to the way the routine is designed, it ships out the last font + * table with its real size, ignoring the TOC's size value. Since + * the TOC size values are always rounded up to a multiple of 4, the + * difference can be up to three bytes for all tables except the + * accelerator table, for which the difference can be as large as 66 + * bytes. + * + */ + + tables = face->toc.tables; + size = stream->size; + + for ( n = 0; n < toc->count - 1; n++ ) + { + /* we need two checks to avoid overflow */ + if ( ( tables->size > size ) || + ( tables->offset > size - tables->size ) ) + { + error = FT_THROW( Invalid_Table ); + goto Exit; + } + tables++; + } + + /* only check `tables->offset' for last table element ... */ + if ( ( tables->offset > size ) ) + { + error = FT_THROW( Invalid_Table ); + goto Exit; + } + /* ... and adjust `tables->size' to the real value if necessary */ + if ( tables->size > size - tables->offset ) + tables->size = size - tables->offset; + #ifdef FT_DEBUG_LEVEL_TRACE { @@ -380,7 +442,7 @@ THE SOFTWARE. int i; - for ( i = 0 ; i < face->nprops && !found; i++ ) + for ( i = 0; i < face->nprops && !found; i++ ) { if ( !ft_strcmp( properties[i].name, prop ) ) found = 1; @@ -397,14 +459,14 @@ THE SOFTWARE. pcf_get_properties( FT_Stream stream, PCF_Face face ) { - PCF_ParseProperty props = 0; + PCF_ParseProperty props = NULL; PCF_Property properties = NULL; FT_ULong nprops, i; FT_ULong format, size; FT_Error error; FT_Memory memory = FT_FACE( face )->memory; FT_ULong string_size; - FT_String* strings = 0; + FT_String* strings = NULL; error = pcf_seek_to_table_type( stream, @@ -434,9 +496,9 @@ THE SOFTWARE. goto Bail; FT_TRACE4(( " nprop = %d (truncate %d props)\n", - (int)nprops, nprops - (int)nprops )); + (int)nprops, nprops - (FT_ULong)(int)nprops )); - nprops = (int)nprops; + nprops = (FT_ULong)(int)nprops; /* rough estimate */ if ( nprops > size / PCF_PROPERTY_SIZE ) @@ -569,7 +631,7 @@ THE SOFTWARE. FT_Error error; FT_Memory memory = FT_FACE( face )->memory; FT_ULong format, size; - PCF_Metric metrics = 0; + PCF_Metric metrics = NULL; FT_ULong nmetrics, i; @@ -631,24 +693,40 @@ THE SOFTWARE. return FT_THROW( Out_Of_Memory ); metrics = face->metrics; - for ( i = 0; i < nmetrics; i++ ) + for ( i = 0; i < nmetrics; i++, metrics++ ) { - error = pcf_get_metric( stream, format, metrics + i ); + error = pcf_get_metric( stream, format, metrics ); - metrics[i].bits = 0; + metrics->bits = 0; FT_TRACE5(( " idx %d: width=%d, " "lsb=%d, rsb=%d, ascent=%d, descent=%d, swidth=%d\n", i, - ( metrics + i )->characterWidth, - ( metrics + i )->leftSideBearing, - ( metrics + i )->rightSideBearing, - ( metrics + i )->ascent, - ( metrics + i )->descent, - ( metrics + i )->attributes )); + metrics->characterWidth, + metrics->leftSideBearing, + metrics->rightSideBearing, + metrics->ascent, + metrics->descent, + metrics->attributes )); if ( error ) break; + + /* sanity checks -- those values are used in `PCF_Glyph_Load' to */ + /* compute a glyph's bitmap dimensions, thus setting them to zero in */ + /* case of an error disables this particular glyph only */ + if ( metrics->rightSideBearing < metrics->leftSideBearing || + metrics->ascent + metrics->descent < 0 ) + { + metrics->characterWidth = 0; + metrics->leftSideBearing = 0; + metrics->rightSideBearing = 0; + metrics->ascent = 0; + metrics->descent = 0; + + FT_TRACE0(( "pcf_get_metrics:" + " invalid metrics for glyph %d\n", i )); + } } if ( error ) @@ -699,8 +777,7 @@ THE SOFTWARE. FT_TRACE4(( " number of bitmaps: %d\n", nbitmaps )); - /* XXX: PCF_Face->nmetrics is singed FT_Long, see pcf.h */ - if ( face->nmetrics < 0 || nbitmaps != ( FT_ULong )face->nmetrics ) + if ( nbitmaps != face->nmetrics ) return FT_THROW( Invalid_File_Format ); if ( FT_NEW_ARRAY( offsets, nbitmaps ) ) @@ -728,9 +805,10 @@ THE SOFTWARE. if ( error ) goto Bail; - sizebitmaps = bitmapSizes[PCF_GLYPH_PAD_INDEX( format )]; + sizebitmaps = (FT_ULong)bitmapSizes[PCF_GLYPH_PAD_INDEX( format )]; - FT_TRACE4(( " padding %d implies a size of %ld\n", i, bitmapSizes[i] )); + FT_TRACE4(( " padding %d implies a size of %ld\n", + i, bitmapSizes[i] )); } FT_TRACE4(( " %d bitmaps, padding index %ld\n", @@ -750,7 +828,7 @@ THE SOFTWARE. " invalid offset to bitmap data of glyph %d\n", i )); } else - face->metrics[i].bits = stream->pos + offsets[i]; + face->metrics[i].bits = stream->pos + (FT_ULong)offsets[i]; } face->bitmapsFormat = format; @@ -770,8 +848,10 @@ THE SOFTWARE. FT_ULong format, size; int firstCol, lastCol; int firstRow, lastRow; - int nencoding, encodingOffset; - int i, j, k; + FT_ULong nencoding; + FT_UShort encodingOffset; + int i, j; + FT_ULong k; PCF_Encoding encoding = NULL; @@ -812,12 +892,22 @@ THE SOFTWARE. if ( !PCF_FORMAT_MATCH( format, PCF_DEFAULT_FORMAT ) ) return FT_THROW( Invalid_File_Format ); + /* sanity checks */ + if ( firstCol < 0 || + firstCol > lastCol || + lastCol > 0xFF || + firstRow < 0 || + firstRow > lastRow || + lastRow > 0xFF ) + return FT_THROW( Invalid_Table ); + FT_TRACE4(( "pdf_get_encodings:\n" )); FT_TRACE4(( " firstCol %d, lastCol %d, firstRow %d, lastRow %d\n", firstCol, lastCol, firstRow, lastRow )); - nencoding = ( lastCol - firstCol + 1 ) * ( lastRow - firstRow + 1 ); + nencoding = (FT_ULong)( lastCol - firstCol + 1 ) * + (FT_ULong)( lastRow - firstRow + 1 ); if ( FT_NEW_ARRAY( encoding, nencoding ) ) return FT_THROW( Out_Of_Memory ); @@ -831,15 +921,19 @@ THE SOFTWARE. { for ( j = firstCol; j <= lastCol; j++ ) { + /* X11's reference implementation uses the equivalent to */ + /* `FT_GET_SHORT', however PCF fonts with more than 32768 */ + /* characters (e.g. `unifont.pcf') clearly show that an */ + /* unsigned value is needed. */ if ( PCF_BYTE_ORDER( format ) == MSBFirst ) - encodingOffset = FT_GET_SHORT(); + encodingOffset = FT_GET_USHORT(); else - encodingOffset = FT_GET_SHORT_LE(); + encodingOffset = FT_GET_USHORT_LE(); - if ( encodingOffset != -1 ) + if ( encodingOffset != 0xFFFFU ) { encoding[k].enc = i * 256 + j; - encoding[k].glyph = (FT_Short)encodingOffset; + encoding[k].glyph = encodingOffset; FT_TRACE5(( " code %d (0x%04X): idx %d\n", encoding[k].enc, encoding[k].enc, encoding[k].glyph )); @@ -1094,9 +1188,11 @@ THE SOFTWARE. FT_LOCAL_DEF( FT_Error ) pcf_load_font( FT_Stream stream, - PCF_Face face ) + PCF_Face face, + FT_Long face_index ) { - FT_Error error = FT_Err_Ok; + FT_Face root = FT_FACE( face ); + FT_Error error; FT_Memory memory = FT_FACE( face )->memory; FT_Bool hasBDFAccelerators; @@ -1105,6 +1201,13 @@ THE SOFTWARE. if ( error ) goto Exit; + root->num_faces = 1; + root->face_index = 0; + + /* If we are performing a simple font format check, exit immediately. */ + if ( face_index < 0 ) + return FT_Err_Ok; + error = pcf_get_properties( stream, face ); if ( error ) goto Exit; @@ -1147,15 +1250,12 @@ THE SOFTWARE. /* now construct the face object */ { - FT_Face root = FT_FACE( face ); PCF_Property prop; - root->num_faces = 1; - root->face_index = 0; - root->face_flags = FT_FACE_FLAG_FIXED_SIZES | - FT_FACE_FLAG_HORIZONTAL | - FT_FACE_FLAG_FAST_GLYPHS; + root->face_flags |= FT_FACE_FLAG_FIXED_SIZES | + FT_FACE_FLAG_HORIZONTAL | + FT_FACE_FLAG_FAST_GLYPHS; if ( face->accel.constantWidth ) root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH; @@ -1179,7 +1279,7 @@ THE SOFTWARE. * * This implies bumping the number of `available' glyphs by 1. */ - root->num_glyphs = face->nmetrics + 1; + root->num_glyphs = (FT_Long)( face->nmetrics + 1 ); root->num_fixed_sizes = 1; if ( FT_NEW_ARRAY( root->available_sizes, 1 ) ) @@ -1192,51 +1292,91 @@ THE SOFTWARE. FT_MEM_ZERO( bsize, sizeof ( FT_Bitmap_Size ) ); + /* for simplicity, we take absolute values of integer properties */ + #if 0 bsize->height = face->accel.maxbounds.ascent << 6; #endif - bsize->height = (FT_Short)( face->accel.fontAscent + - face->accel.fontDescent ); + +#ifdef FT_DEBUG_LEVEL_TRACE + if ( face->accel.fontAscent + face->accel.fontDescent < 0 ) + FT_TRACE0(( "pcf_load_font: negative height\n" )); +#endif + bsize->height = FT_ABS( (FT_Short)( face->accel.fontAscent + + face->accel.fontDescent ) ); prop = pcf_find_property( face, "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(( "pcf_load_font: negative average width\n" )); +#endif + bsize->width = FT_ABS( (FT_Short)( ( prop->value.l ) + 5 ) / 10 ); + } else - bsize->width = (FT_Short)( bsize->height * 2/3 ); + bsize->width = (FT_Short)FT_MulDiv( bsize->height, 2, 3 ); prop = pcf_find_property( face, "POINT_SIZE" ); if ( prop ) + { +#ifdef FT_DEBUG_LEVEL_TRACE + if ( prop->value.l < 0 ) + FT_TRACE0(( "pcf_load_font: 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 ); + bsize->size = FT_MulDiv( FT_ABS( prop->value.l ), + 64 * 7200, + 72270L ); + } prop = pcf_find_property( face, "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(( "pcf_load_font: negative pixel size\n" )); +#endif + bsize->y_ppem = FT_ABS( (FT_Short)prop->value.l ) << 6; + } prop = pcf_find_property( face, "RESOLUTION_X" ); if ( prop ) - resolution_x = (FT_Short)prop->value.l; + { +#ifdef FT_DEBUG_LEVEL_TRACE + if ( prop->value.l < 0 ) + FT_TRACE0(( "pcf_load_font: negative X resolution\n" )); +#endif + resolution_x = FT_ABS( (FT_Short)prop->value.l ); + } prop = pcf_find_property( face, "RESOLUTION_Y" ); if ( prop ) - resolution_y = (FT_Short)prop->value.l; + { +#ifdef FT_DEBUG_LEVEL_TRACE + if ( prop->value.l < 0 ) + FT_TRACE0(( "pcf_load_font: negative Y resolution\n" )); +#endif + resolution_y = FT_ABS( (FT_Short)prop->value.l ); + } 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; } /* set up charset */ { - PCF_Property charset_registry = 0, charset_encoding = 0; + PCF_Property charset_registry, charset_encoding; charset_registry = pcf_find_property( face, "CHARSET_REGISTRY" ); diff --git a/drivers/freetype/src/pcf/pcfread.h b/drivers/freetype/src/pcf/pcfread.h index c9524f134..bed30e503 100644 --- a/drivers/freetype/src/pcf/pcfread.h +++ b/drivers/freetype/src/pcf/pcfread.h @@ -25,8 +25,8 @@ THE SOFTWARE. */ -#ifndef __PCFREAD_H__ -#define __PCFREAD_H__ +#ifndef PCFREAD_H_ +#define PCFREAD_H_ #include <ft2build.h> @@ -39,7 +39,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* __PCFREAD_H__ */ +#endif /* PCFREAD_H_ */ /* END */ diff --git a/drivers/freetype/src/pcf/pcfutil.c b/drivers/freetype/src/pcf/pcfutil.c index b91274f93..0451ee8de 100644 --- a/drivers/freetype/src/pcf/pcfutil.c +++ b/drivers/freetype/src/pcf/pcfutil.c @@ -66,11 +66,11 @@ in this Software without prior written authorization from The Open Group. TwoByteSwap( unsigned char* buf, size_t nbytes ) { - unsigned char c; - - for ( ; nbytes >= 2; nbytes -= 2, buf += 2 ) { + unsigned char c; + + c = buf[0]; buf[0] = buf[1]; buf[1] = c; @@ -85,11 +85,11 @@ in this Software without prior written authorization from The Open Group. FourByteSwap( unsigned char* buf, size_t nbytes ) { - unsigned char c; - - for ( ; nbytes >= 4; nbytes -= 4, buf += 4 ) { + unsigned char c; + + c = buf[0]; buf[0] = buf[3]; buf[3] = c; diff --git a/drivers/freetype/src/pcf/pcfutil.h b/drivers/freetype/src/pcf/pcfutil.h index ce10fb541..be986e756 100644 --- a/drivers/freetype/src/pcf/pcfutil.h +++ b/drivers/freetype/src/pcf/pcfutil.h @@ -25,8 +25,8 @@ THE SOFTWARE. */ -#ifndef __PCFUTIL_H__ -#define __PCFUTIL_H__ +#ifndef PCFUTIL_H_ +#define PCFUTIL_H_ #include <ft2build.h> @@ -49,7 +49,7 @@ FT_BEGIN_HEADER FT_END_HEADER -#endif /* __PCFUTIL_H__ */ +#endif /* PCFUTIL_H_ */ /* END */ diff --git a/drivers/freetype/src/pcf/rules.mk b/drivers/freetype/src/pcf/rules.mk index 78641528f..1b55daf4f 100644 --- a/drivers/freetype/src/pcf/rules.mk +++ b/drivers/freetype/src/pcf/rules.mk @@ -30,7 +30,10 @@ PCF_DIR := $(SRC_DIR)/pcf -PCF_COMPILE := $(FT_COMPILE) $I$(subst /,$(COMPILER_SEP),$(PCF_DIR)) +PCF_COMPILE := $(CC) $(ANSIFLAGS) \ + $I$(subst /,$(COMPILER_SEP),$(PCF_DIR)) \ + $(INCLUDE_FLAGS) \ + $(FT_CFLAGS) # pcf driver sources (i.e., C files) |
