diff options
Diffstat (limited to 'src/3rdparty/freetype/src/winfonts/winfnt.c')
-rw-r--r-- | src/3rdparty/freetype/src/winfonts/winfnt.c | 205 |
1 files changed, 120 insertions, 85 deletions
diff --git a/src/3rdparty/freetype/src/winfonts/winfnt.c b/src/3rdparty/freetype/src/winfonts/winfnt.c index 6b3a4e17f2..4705c53963 100644 --- a/src/3rdparty/freetype/src/winfonts/winfnt.c +++ b/src/3rdparty/freetype/src/winfonts/winfnt.c @@ -4,7 +4,7 @@ /* */ /* FreeType font driver for Windows FNT/FON files */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2006, 2007, 2008, 2009 by */ +/* Copyright 1996-2004, 2006-2014 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* Copyright 2003 Huw D M Davies for Codeweavers */ /* Copyright 2007 Dmitry Timoshkov for Codeweavers */ @@ -23,6 +23,7 @@ #include FT_INTERNAL_DEBUG_H #include FT_INTERNAL_STREAM_H #include FT_INTERNAL_OBJECTS_H +#include FT_TRUETYPE_IDS_H #include "winfnt.h" #include "fnterrs.h" @@ -71,12 +72,12 @@ FT_FRAME_START( 248 ), FT_FRAME_ULONG_LE ( magic ), /* PE00 */ - FT_FRAME_USHORT_LE ( machine ), /* 0x014c - i386 */ + FT_FRAME_USHORT_LE ( machine ), /* 0x014C - i386 */ FT_FRAME_USHORT_LE ( number_of_sections ), FT_FRAME_SKIP_BYTES( 12 ), FT_FRAME_USHORT_LE ( size_of_optional_header ), FT_FRAME_SKIP_BYTES( 2 ), - FT_FRAME_USHORT_LE ( magic32 ), /* 0x10b */ + FT_FRAME_USHORT_LE ( magic32 ), /* 0x10B */ FT_FRAME_SKIP_BYTES( 110 ), FT_FRAME_ULONG_LE ( rsrc_virtual_address ), FT_FRAME_ULONG_LE ( rsrc_size ), @@ -223,8 +224,8 @@ if ( header->version != 0x200 && header->version != 0x300 ) { - FT_TRACE2(( "[not a valid FNT file]\n" )); - error = FNT_Err_Unknown_File_Format; + FT_TRACE2(( " not a Windows FNT file\n" )); + error = FT_THROW( Unknown_File_Format ); goto Exit; } @@ -233,8 +234,8 @@ if ( header->file_size < size ) { - FT_TRACE2(( "[not a valid FNT file]\n" )); - error = FNT_Err_Unknown_File_Format; + FT_TRACE2(( " not a Windows FNT file\n" )); + error = FT_THROW( Unknown_File_Format ); goto Exit; } @@ -252,7 +253,7 @@ if ( header->file_type & 1 ) { FT_TRACE2(( "[can't handle vector FNT fonts]\n" )); - error = FNT_Err_Unknown_File_Format; + error = FT_THROW( Unknown_File_Format ); goto Exit; } @@ -283,7 +284,7 @@ FT_STREAM_READ_FIELDS( winmz_header_fields, &mz_header ) ) goto Exit; - error = FNT_Err_Unknown_File_Format; + error = FT_ERR( Unknown_File_Format ); if ( mz_header.magic == WINFNT_MZ_MAGIC ) { /* yes, now look for an NE header in the file */ @@ -296,7 +297,7 @@ FT_STREAM_READ_FIELDS( winne_header_fields, &ne_header ) ) goto Exit; - error = FNT_Err_Unknown_File_Format; + error = FT_ERR( Unknown_File_Format ); if ( ne_header.magic == WINFNT_NE_MAGIC ) { /* good, now look into the resource table for each FNT resource */ @@ -343,7 +344,7 @@ if ( !font_count || !font_offset ) { FT_TRACE2(( "this file doesn't contain any FNT resources\n" )); - error = FNT_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Exit; } @@ -352,7 +353,7 @@ if ( font_count * 118UL > stream->size ) { FT_TRACE2(( "invalid number of faces\n" )); - error = FNT_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Exit; } @@ -360,7 +361,7 @@ if ( face_index >= font_count ) { - error = FNT_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); goto Exit; } else if ( face_index < 0 ) @@ -411,12 +412,12 @@ pe32_header.rsrc_size )); if ( pe32_header.magic != WINFNT_PE_MAGIC /* check full signature */ || - pe32_header.machine != 0x014c /* i386 */ || - pe32_header.size_of_optional_header != 0xe0 /* FIXME */ || - pe32_header.magic32 != 0x10b ) + pe32_header.machine != 0x014C /* i386 */ || + pe32_header.size_of_optional_header != 0xE0 /* FIXME */ || + pe32_header.magic32 != 0x10B ) { FT_TRACE2(( "this file has an invalid PE header\n" )); - error = FNT_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Exit; } @@ -439,7 +440,7 @@ } FT_TRACE2(( "this file doesn't contain any resources\n" )); - error = FNT_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Exit; Found_rsrc_section: @@ -461,7 +462,7 @@ if ( !(dir_entry1.offset & 0x80000000UL ) /* DataIsDirectory */ ) { - error = FNT_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Exit; } @@ -485,7 +486,7 @@ if ( !(dir_entry2.offset & 0x80000000UL ) /* DataIsDirectory */ ) { - error = FNT_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Exit; } @@ -509,7 +510,7 @@ if ( dir_entry2.offset & 0x80000000UL /* DataIsDirectory */ ) { - error = FNT_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Exit; } @@ -560,13 +561,13 @@ if ( !face->root.num_faces ) { FT_TRACE2(( "this file doesn't contain any RT_FONT resources\n" )); - error = FNT_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Exit; } if ( face_index >= face->root.num_faces ) { - error = FNT_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); goto Exit; } } @@ -590,11 +591,14 @@ static FT_Error - fnt_cmap_init( FNT_CMap cmap ) + fnt_cmap_init( FNT_CMap cmap, + FT_Pointer pointer ) { FNT_Face face = (FNT_Face)FT_CMAP_FACE( cmap ); FNT_Font font = face->font; + FT_UNUSED( pointer ); + cmap->first = (FT_UInt32) font->header.first_char; cmap->count = (FT_UInt32)( font->header.last_char - cmap->first + 1 ); @@ -664,8 +668,9 @@ static void - FNT_Face_Done( FNT_Face face ) + FNT_Face_Done( FT_Face fntface ) /* FNT_Face */ { + FNT_Face face = (FNT_Face)fntface; FT_Memory memory; @@ -676,18 +681,19 @@ fnt_font_done( face ); - FT_FREE( face->root.available_sizes ); - face->root.num_fixed_sizes = 0; + FT_FREE( fntface->available_sizes ); + fntface->num_fixed_sizes = 0; } static FT_Error FNT_Face_Init( FT_Stream stream, - FNT_Face face, + FT_Face fntface, /* FNT_Face */ FT_Int face_index, FT_Int num_params, FT_Parameter* params ) { + FNT_Face face = (FNT_Face)fntface; FT_Error error; FT_Memory memory = FT_FACE_MEMORY( face ); @@ -695,12 +701,14 @@ FT_UNUSED( params ); + FT_TRACE2(( "Windows FNT driver\n" )); + /* try to load font from a DLL */ error = fnt_face_get_dll_font( face, face_index ); if ( !error && face_index < 0 ) goto Exit; - if ( error == FNT_Err_Unknown_File_Format ) + if ( FT_ERR_EQ( error, Unknown_File_Format ) ) { /* this didn't work; try to load a single FNT font */ FNT_Font font; @@ -708,7 +716,7 @@ if ( FT_NEW( face->font ) ) goto Exit; - face->root.num_faces = 1; + fntface->num_faces = 1; font = face->font; font->offset = 0; @@ -719,7 +727,7 @@ if ( !error ) { if ( face_index > 0 ) - error = FNT_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); else if ( face_index < 0 ) goto Exit; } @@ -738,8 +746,8 @@ root->face_index = face_index; - root->face_flags = FT_FACE_FLAG_FIXED_SIZES | - FT_FACE_FLAG_HORIZONTAL; + root->face_flags |= FT_FACE_FLAG_FIXED_SIZES | + FT_FACE_FLAG_HORIZONTAL; if ( font->header.avg_width == font->header.max_width ) root->face_flags |= FT_FACE_FLAG_FIXED_WIDTH; @@ -802,15 +810,16 @@ 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; charmap.face = root; if ( font->header.charset == FT_WinFNT_ID_MAC ) { charmap.encoding = FT_ENCODING_APPLE_ROMAN; - charmap.platform_id = 1; -/* charmap.encoding_id = 0; */ + charmap.platform_id = TT_PLATFORM_MACINTOSH; +/* charmap.encoding_id = TT_MAC_ID_ROMAN; */ } error = FT_CMap_New( fnt_cmap_class, @@ -825,7 +834,14 @@ root->charmap = root->charmaps[0]; } - /* setup remaining flags */ + /* set up remaining flags */ + + if ( font->header.last_char < font->header.first_char ) + { + FT_TRACE2(( "invalid number of glyphs\n" )); + error = FT_THROW( Invalid_File_Format ); + goto Fail; + } /* reserve one slot for the .notdef glyph at index 0 */ root->num_glyphs = font->header.last_char - @@ -834,7 +850,7 @@ if ( font->header.face_name_offset >= font->header.file_size ) { FT_TRACE2(( "invalid family name offset\n" )); - error = FNT_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Fail; } family_size = font->header.file_size - font->header.face_name_offset; @@ -872,7 +888,7 @@ goto Exit; Fail: - FNT_Face_Done( face ); + FNT_Face_Done( fntface ); Exit: return error; @@ -880,11 +896,14 @@ static FT_Error - FNT_Size_Select( FT_Size size ) + FNT_Size_Select( FT_Size size, + FT_ULong strike_index ) { FNT_Face face = (FNT_Face)size->face; FT_WinFNT_Header header = &face->font->header; + FT_UNUSED( strike_index ); + FT_Select_Metrics( size->face, 0 ); @@ -893,7 +912,7 @@ header->ascent ) * 64; size->metrics.max_advance = header->max_width * 64; - return FNT_Err_Ok; + return FT_Err_Ok; } @@ -904,7 +923,7 @@ FNT_Face face = (FNT_Face)size->face; FT_WinFNT_Header header = &face->font->header; FT_Bitmap_Size* bsize = size->face->available_sizes; - FT_Error error = FNT_Err_Invalid_Pixel_Size; + FT_Error error = FT_ERR( Invalid_Pixel_Size ); FT_Long height; @@ -915,23 +934,23 @@ { case FT_SIZE_REQUEST_TYPE_NOMINAL: if ( height == ( ( bsize->y_ppem + 32 ) >> 6 ) ) - error = FNT_Err_Ok; + error = FT_Err_Ok; break; case FT_SIZE_REQUEST_TYPE_REAL_DIM: if ( height == header->pixel_height ) - error = FNT_Err_Ok; + error = FT_Err_Ok; break; default: - error = FNT_Err_Unimplemented_Feature; + error = FT_THROW( Unimplemented_Feature ); break; } if ( error ) return error; else - return FNT_Size_Select( size ); + return FNT_Size_Select( size, 0 ); } @@ -942,8 +961,8 @@ FT_Int32 load_flags ) { FNT_Face face = (FNT_Face)FT_SIZE_FACE( size ); - FNT_Font font = face->font; - FT_Error error = FNT_Err_Ok; + FNT_Font font; + FT_Error error = FT_Err_Ok; FT_Byte* p; FT_Int len; FT_Bitmap* bitmap = &slot->bitmap; @@ -953,26 +972,46 @@ FT_UNUSED( load_flags ); - if ( !face || !font || + if ( !face ) + { + error = FT_THROW( Invalid_Face_Handle ); + goto Exit; + } + + font = face->font; + + if ( !font || glyph_index >= (FT_UInt)( FT_FACE( face )->num_glyphs ) ) { - error = FNT_Err_Invalid_Argument; + error = FT_THROW( Invalid_Argument ); goto Exit; } + FT_TRACE1(( "FNT_Load_Glyph: glyph index %d\n", glyph_index )); + if ( glyph_index > 0 ) glyph_index--; /* revert to real index */ else - glyph_index = font->header.default_char; /* the .notdef glyph */ + glyph_index = font->header.default_char; /* the `.notdef' glyph */ new_format = FT_BOOL( font->header.version == 0x300 ); len = new_format ? 6 : 4; - /* jump to glyph entry */ - p = font->fnt_frame + ( new_format ? 148 : 118 ) + len * glyph_index; + /* get glyph width and offset */ + offset = ( new_format ? 148 : 118 ) + len * glyph_index; + + if ( offset >= font->header.file_size - 2 - ( new_format ? 4 : 2 ) ) + { + FT_TRACE2(( "invalid FNT offset\n" )); + error = FT_THROW( Invalid_File_Format ); + goto Exit; + } + + p = font->fnt_frame + offset; bitmap->width = FT_NEXT_SHORT_LE( p ); + /* jump to glyph entry */ if ( new_format ) offset = FT_NEXT_ULONG_LE( p ); else @@ -981,7 +1020,7 @@ if ( offset >= font->header.file_size ) { FT_TRACE2(( "invalid FNT offset\n" )); - error = FNT_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Exit; } @@ -1000,10 +1039,10 @@ bitmap->rows = font->header.pixel_height; bitmap->pixel_mode = FT_PIXEL_MODE_MONO; - if ( offset + pitch * bitmap->rows >= font->header.file_size ) + if ( offset + pitch * bitmap->rows > font->header.file_size ) { FT_TRACE2(( "invalid bitmap width\n" )); - error = FNT_Err_Invalid_File_Format; + error = FT_THROW( Invalid_File_Format ); goto Exit; } @@ -1076,10 +1115,10 @@ static FT_Module_Interface - winfnt_get_service( FT_Driver driver, + winfnt_get_service( FT_Module module, const FT_String* service_id ) { - FT_UNUSED( driver ); + FT_UNUSED( module ); return ft_service_list_lookup( winfnt_services, service_id ); } @@ -1101,34 +1140,30 @@ 0, - (FT_Module_Constructor)0, - (FT_Module_Destructor) 0, - (FT_Module_Requester) winfnt_get_service + 0, /* FT_Module_Constructor */ + 0, /* FT_Module_Destructor */ + winfnt_get_service }, - sizeof( FNT_FaceRec ), - sizeof( FT_SizeRec ), - sizeof( FT_GlyphSlotRec ), - - (FT_Face_InitFunc) FNT_Face_Init, - (FT_Face_DoneFunc) FNT_Face_Done, - (FT_Size_InitFunc) 0, - (FT_Size_DoneFunc) 0, - (FT_Slot_InitFunc) 0, - (FT_Slot_DoneFunc) 0, - -#ifdef FT_CONFIG_OPTION_OLD_INTERNALS - ft_stub_set_char_sizes, - ft_stub_set_pixel_sizes, -#endif - (FT_Slot_LoadFunc) FNT_Load_Glyph, - - (FT_Face_GetKerningFunc) 0, - (FT_Face_AttachFunc) 0, - (FT_Face_GetAdvancesFunc) 0, - - (FT_Size_RequestFunc) FNT_Size_Request, - (FT_Size_SelectFunc) FNT_Size_Select + sizeof ( FNT_FaceRec ), + sizeof ( FT_SizeRec ), + sizeof ( FT_GlyphSlotRec ), + + FNT_Face_Init, + FNT_Face_Done, + 0, /* FT_Size_InitFunc */ + 0, /* FT_Size_DoneFunc */ + 0, /* FT_Slot_InitFunc */ + 0, /* FT_Slot_DoneFunc */ + + FNT_Load_Glyph, + + 0, /* FT_Face_GetKerningFunc */ + 0, /* FT_Face_AttachFunc */ + 0, /* FT_Face_GetAdvancesFunc */ + + FNT_Size_Request, + FNT_Size_Select }; |