From 47ed6413ce8f2586b8d542dc46055e075a47022e Mon Sep 17 00:00:00 2001 From: marha Date: Fri, 6 Aug 2010 10:14:25 +0000 Subject: Updated to freetype 2.4.1 --- freetype/src/cff/cffcmap.c | 31 +++---- freetype/src/cff/cffdrivr.c | 78 +++++++----------- freetype/src/cff/cffgload.c | 47 ++++++----- freetype/src/cff/cffload.c | 193 ++++++++++++++++++++++++++------------------ freetype/src/cff/cffload.h | 16 ++-- freetype/src/cff/cffobjs.c | 134 +++++++++++++++++++----------- freetype/src/cff/cffparse.c | 21 +++-- freetype/src/cff/cffpic.c | 16 ++-- freetype/src/cff/cfftypes.h | 21 +++-- 9 files changed, 313 insertions(+), 244 deletions(-) (limited to 'freetype/src/cff') diff --git a/freetype/src/cff/cffcmap.c b/freetype/src/cff/cffcmap.c index 46d603e3a..129837110 100644 --- a/freetype/src/cff/cffcmap.c +++ b/freetype/src/cff/cffcmap.c @@ -4,7 +4,7 @@ /* */ /* CFF character mapping table (cmap) support (body). */ /* */ -/* Copyright 2002, 2003, 2004, 2005, 2006, 2007 by */ +/* Copyright 2002, 2003, 2004, 2005, 2006, 2007, 2010 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -120,27 +120,15 @@ /*************************************************************************/ FT_CALLBACK_DEF( const char* ) - cff_sid_to_glyph_name( TT_Face face, - FT_UInt idx ) + cff_sid_to_glyph_name( TT_Face face, + FT_UInt idx ) { - CFF_Font cff = (CFF_Font)face->extra.data; - CFF_Charset charset = &cff->charset; - FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames; - FT_UInt sid = charset->sids[idx]; - - - return cff_index_get_sid_string( &cff->string_index, sid, psnames ); - } - - - FT_CALLBACK_DEF( void ) - cff_sid_free_glyph_name( TT_Face face, - const char* gname ) - { - FT_Memory memory = FT_FACE_MEMORY( face ); + CFF_Font cff = (CFF_Font)face->extra.data; + CFF_Charset charset = &cff->charset; + FT_UInt sid = charset->sids[idx]; - FT_FREE( gname ); + return cff_index_get_sid_string( cff, sid ); } @@ -155,14 +143,15 @@ /* can't build Unicode map for CID-keyed font */ + /* because we don't know glyph names. */ if ( !charset->sids ) - return CFF_Err_Invalid_Argument; + return CFF_Err_No_Unicode_Glyph_Name; return psnames->unicodes_init( memory, unicodes, cff->num_glyphs, (PS_GetGlyphNameFunc)&cff_sid_to_glyph_name, - (PS_FreeGlyphNameFunc)&cff_sid_free_glyph_name, + (PS_FreeGlyphNameFunc)NULL, (FT_Pointer)face ); } diff --git a/freetype/src/cff/cffdrivr.c b/freetype/src/cff/cffdrivr.c index dad0b65d8..39f04ee1b 100644 --- a/freetype/src/cff/cffdrivr.c +++ b/freetype/src/cff/cffdrivr.c @@ -4,7 +4,8 @@ /* */ /* OpenType font driver implementation (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by */ +/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, */ +/* 2010 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -22,7 +23,6 @@ #include FT_INTERNAL_STREAM_H #include FT_INTERNAL_SFNT_H #include FT_SERVICE_CID_H -#include FT_SERVICE_POSTSCRIPT_CMAPS_H #include FT_SERVICE_POSTSCRIPT_INFO_H #include FT_SERVICE_POSTSCRIPT_NAME_H #include FT_SERVICE_TT_CMAP_H @@ -228,16 +228,13 @@ FT_Pointer buffer, FT_UInt buffer_max ) { - CFF_Font font = (CFF_Font)face->extra.data; - FT_Memory memory = FT_FACE_MEMORY( face ); - FT_String* gname; - FT_UShort sid; - FT_Service_PsCMaps psnames; - FT_Error error; + CFF_Font font = (CFF_Font)face->extra.data; + FT_String* gname; + FT_UShort sid; + FT_Error error; - FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_CMAPS ); - if ( !psnames ) + if ( !font->psnames ) { FT_ERROR(( "cff_get_glyph_name:" " cannot get glyph name from CFF & CEF fonts\n" @@ -251,12 +248,11 @@ sid = font->charset.sids[glyph_index]; /* now, lookup the name itself */ - gname = cff_index_get_sid_string( &font->string_index, sid, psnames ); + gname = cff_index_get_sid_string( font, sid ); if ( gname ) FT_STRCPYN( buffer, gname, buffer_max ); - FT_FREE( gname ); error = CFF_Err_Ok; Exit: @@ -271,11 +267,9 @@ CFF_Font cff; CFF_Charset charset; FT_Service_PsCMaps psnames; - FT_Memory memory = FT_FACE_MEMORY( face ); FT_String* name; FT_UShort sid; FT_UInt i; - FT_Int result; cff = (CFF_FontRec *)face->extra.data; @@ -290,19 +284,14 @@ sid = charset->sids[i]; if ( sid > 390 ) - name = cff_index_get_name( &cff->string_index, sid - 391 ); + name = cff_index_get_string( cff, sid - 391 ); else name = (FT_String *)psnames->adobe_std_strings( sid ); if ( !name ) continue; - result = ft_strcmp( glyph_name, name ); - - if ( sid > 390 ) - FT_FREE( name ); - - if ( !result ) + if ( !ft_strcmp( glyph_name, name ) ) return i; } @@ -333,35 +322,29 @@ PS_FontInfoRec* afont_info ) { CFF_Font cff = (CFF_Font)face->extra.data; - FT_Error error = FT_Err_Ok; + FT_Error error = CFF_Err_Ok; if ( cff && cff->font_info == NULL ) { - CFF_FontRecDict dict = &cff->top_font.font_dict; - PS_FontInfoRec *font_info; - FT_Memory memory = face->root.memory; - FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames; + CFF_FontRecDict dict = &cff->top_font.font_dict; + PS_FontInfoRec *font_info; + FT_Memory memory = face->root.memory; if ( FT_ALLOC( font_info, sizeof ( *font_info ) ) ) goto Fail; - font_info->version = cff_index_get_sid_string( &cff->string_index, - dict->version, - psnames ); - font_info->notice = cff_index_get_sid_string( &cff->string_index, - dict->notice, - psnames ); - font_info->full_name = cff_index_get_sid_string( &cff->string_index, - dict->full_name, - psnames ); - font_info->family_name = cff_index_get_sid_string( &cff->string_index, - dict->family_name, - psnames ); - font_info->weight = cff_index_get_sid_string( &cff->string_index, - dict->weight, - psnames ); + font_info->version = cff_index_get_sid_string( cff, + dict->version ); + font_info->notice = cff_index_get_sid_string( cff, + dict->notice ); + font_info->full_name = cff_index_get_sid_string( cff, + dict->full_name ); + font_info->family_name = cff_index_get_sid_string( cff, + dict->family_name ); + font_info->weight = cff_index_get_sid_string( cff, + dict->weight ); font_info->italic_angle = dict->italic_angle; font_info->is_fixed_pitch = dict->is_fixed_pitch; font_info->underline_position = (FT_Short)dict->underline_position; @@ -467,8 +450,7 @@ if ( cff ) { - CFF_FontRecDict dict = &cff->top_font.font_dict; - FT_Service_PsCMaps psnames = (FT_Service_PsCMaps)cff->psnames; + CFF_FontRecDict dict = &cff->top_font.font_dict; if ( dict->cid_registry == 0xFFFFU ) @@ -480,18 +462,16 @@ if ( registry ) { if ( cff->registry == NULL ) - cff->registry = cff_index_get_sid_string( &cff->string_index, - dict->cid_registry, - psnames ); + cff->registry = cff_index_get_sid_string( cff, + dict->cid_registry ); *registry = cff->registry; } if ( ordering ) { if ( cff->ordering == NULL ) - cff->ordering = cff_index_get_sid_string( &cff->string_index, - dict->cid_ordering, - psnames ); + cff->ordering = cff_index_get_sid_string( cff, + dict->cid_ordering ); *ordering = cff->ordering; } diff --git a/freetype/src/cff/cffgload.c b/freetype/src/cff/cffgload.c index 9330c0588..347041cfe 100644 --- a/freetype/src/cff/cffgload.c +++ b/freetype/src/cff/cffgload.c @@ -22,7 +22,6 @@ #include FT_INTERNAL_STREAM_H #include FT_INTERNAL_SFNT_H #include FT_OUTLINE_H -#include FT_INTERNAL_POSTSCRIPT_HINTS_H #include "cffobjs.h" #include "cffload.h" @@ -394,7 +393,7 @@ /* initialize Type2 decoder */ decoder->cff = cff; - decoder->num_globals = cff->num_global_subrs; + decoder->num_globals = cff->global_subrs_index.count; decoder->globals = cff->global_subrs; decoder->globals_bias = cff_compute_bias( cff->top_font.font_dict.charstring_type, @@ -430,7 +429,7 @@ goto Exit; } - FT_TRACE4(( "glyph index %d (subfont %d):\n", glyph_index, fd_index )); + FT_TRACE3(( "glyph index %d (subfont %d):\n", glyph_index, fd_index )); sub = cff->subfonts[fd_index]; @@ -445,10 +444,10 @@ } #ifdef FT_DEBUG_LEVEL_TRACE else - FT_TRACE4(( "glyph index %d:\n", glyph_index )); + FT_TRACE3(( "glyph index %d:\n", glyph_index )); #endif - decoder->num_locals = sub->num_local_subrs; + decoder->num_locals = sub->local_subrs_index.count; decoder->locals = sub->local_subrs; decoder->locals_bias = cff_compute_bias( decoder->cff->top_font.font_dict.charstring_type, @@ -812,10 +811,10 @@ charstring_len ); decoder->seac = FALSE; + cff_free_glyph_data( face, &charstring, charstring_len ); + if ( error ) goto Exit; - - cff_free_glyph_data( face, &charstring, charstring_len ); } /* Save the left bearing, advance and glyph width of the base */ @@ -842,10 +841,10 @@ charstring_len ); decoder->seac = FALSE; + cff_free_glyph_data( face, &charstring, charstring_len ); + if ( error ) goto Exit; - - cff_free_glyph_data( face, &charstring, charstring_len ); } /* Restore the left side bearing, advance and glyph width */ @@ -1340,6 +1339,14 @@ decoder->num_hints += num_args / 2; } + /* In a valid charstring there must be at least one byte */ + /* after `hintmask' or `cntrmask' (e.g., for a `return' */ + /* instruction). Additionally, there must be space for */ + /* `num_hints' bits. */ + + if ( ( ip + ( ( decoder->num_hints + 7 ) >> 3 ) ) >= limit ) + goto Syntax_Error; + if ( hinter ) { if ( op == cff_op_hintmask ) @@ -1358,20 +1365,18 @@ FT_UInt maskbyte; - FT_TRACE4(( " (maskbytes: " )); + FT_TRACE4(( " (maskbytes:" )); for ( maskbyte = 0; - maskbyte < (FT_UInt)(( decoder->num_hints + 7 ) >> 3); + maskbyte < (FT_UInt)( ( decoder->num_hints + 7 ) >> 3 ); maskbyte++, ip++ ) - FT_TRACE4(( "0x%02X", *ip )); + FT_TRACE4(( " 0x%02X", *ip )); FT_TRACE4(( ")\n" )); } #else ip += ( decoder->num_hints + 7 ) >> 3; #endif - if ( ip >= limit ) - goto Syntax_Error; args = stack; break; @@ -2276,6 +2281,8 @@ /* this is the implementation described for `unknown' other */ /* subroutines in the Type1 spec. */ args -= 2 + ( args[-2] >> 16 ); + if ( args < stack ) + goto Stack_Underflow; break; case cff_op_pop: @@ -2668,11 +2675,15 @@ /* this scaling is only relevant if the PS hinter isn't active */ if ( cff->num_subfonts ) { - FT_Byte fd_index = cff_fd_select_get( &cff->fd_select, - glyph_index ); + FT_ULong top_upm, sub_upm; + FT_Byte fd_index = cff_fd_select_get( &cff->fd_select, + glyph_index ); + + if ( fd_index >= cff->num_subfonts ) + fd_index = cff->num_subfonts - 1; - FT_ULong top_upm = cff->top_font.font_dict.units_per_em; - FT_ULong sub_upm = cff->subfonts[fd_index]->font_dict.units_per_em; + top_upm = cff->top_font.font_dict.units_per_em; + sub_upm = cff->subfonts[fd_index]->font_dict.units_per_em; font_matrix = cff->subfonts[fd_index]->font_dict.font_matrix; diff --git a/freetype/src/cff/cffload.c b/freetype/src/cff/cffload.c index 64d139572..42e77309a 100644 --- a/freetype/src/cff/cffload.c +++ b/freetype/src/cff/cffload.c @@ -4,7 +4,8 @@ /* */ /* OpenType and CFF data/program tables loader (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by */ +/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, */ +/* 2010 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -20,7 +21,6 @@ #include FT_INTERNAL_DEBUG_H #include FT_INTERNAL_OBJECTS_H #include FT_INTERNAL_STREAM_H -#include FT_SERVICE_POSTSCRIPT_CMAPS_H #include FT_TRUETYPE_TAGS_H #include FT_TYPE1_TABLES_H @@ -251,7 +251,7 @@ if ( offsize < 1 || offsize > 4 ) { - error = FT_Err_Invalid_Table; + error = CFF_Err_Invalid_Table; goto Exit; } @@ -377,18 +377,21 @@ } - /* allocate a table containing pointers to an index's elements */ + /* Allocate a table containing pointers to an index's elements. */ + /* The `pool' argument makes this function convert the index */ + /* entries to C-style strings (this is, NULL-terminated). */ static FT_Error cff_index_get_pointers( CFF_Index idx, - FT_Byte*** table ) + FT_Byte*** table, + FT_Byte** pool ) { - FT_Error error = CFF_Err_Ok; - FT_Memory memory = idx->stream->memory; - FT_ULong n, offset, old_offset; + FT_Error error = CFF_Err_Ok; + FT_Memory memory = idx->stream->memory; FT_Byte** t; + FT_Byte* new_bytes = NULL; - *table = 0; + *table = NULL; if ( idx->offsets == NULL ) { @@ -397,28 +400,65 @@ goto Exit; } - if ( idx->count > 0 && !FT_NEW_ARRAY( t, idx->count + 1 ) ) + if ( idx->count > 0 && + !FT_NEW_ARRAY( t, idx->count + 1 ) && + ( !pool || !FT_ALLOC( new_bytes, + idx->data_size + idx->count ) ) ) { - old_offset = 1; - for ( n = 0; n <= idx->count; n++ ) + FT_ULong n, cur_offset; + FT_ULong extra = 0; + FT_Byte* org_bytes = idx->bytes; + + + /* at this point, `idx->offsets' can't be NULL */ + cur_offset = idx->offsets[0] - 1; + + /* sanity check */ + if ( cur_offset >= idx->data_size ) { - /* at this point, `idx->offsets' can't be NULL */ - offset = idx->offsets[n]; - if ( !offset ) - offset = old_offset; + FT_TRACE0(( "cff_index_get_pointers:" + " invalid first offset value %d set to zero\n", + cur_offset )); + cur_offset = 0; + } - /* two sanity checks for invalid offset tables */ - else if ( offset < old_offset ) - offset = old_offset; + if ( !pool ) + t[0] = org_bytes + cur_offset; + else + t[0] = new_bytes + cur_offset; + + for ( n = 1; n <= idx->count; n++ ) + { + FT_ULong next_offset = idx->offsets[n] - 1; - else if ( offset - 1 >= idx->data_size && n < idx->count ) - offset = old_offset; - t[n] = idx->bytes + offset - 1; + /* empty slot + two sanity checks for invalid offset tables */ + if ( next_offset == 0 || + next_offset < cur_offset || + ( next_offset >= idx->data_size && n < idx->count ) ) + next_offset = cur_offset; - old_offset = offset; + if ( !pool ) + t[n] = org_bytes + next_offset; + else + { + t[n] = new_bytes + next_offset + extra; + + if ( next_offset != cur_offset ) + { + FT_MEM_COPY( t[n - 1], org_bytes + cur_offset, t[n] - t[n - 1] ); + t[n][0] = '\0'; + t[n] += 1; + extra++; + } + } + + cur_offset = next_offset; } *table = t; + + if ( pool ) + *pool = new_bytes; } Exit: @@ -526,10 +566,12 @@ } + /* get an entry from Name INDEX */ FT_LOCAL_DEF( FT_String* ) - cff_index_get_name( CFF_Index idx, - FT_UInt element ) + cff_index_get_name( CFF_Font font, + FT_UInt element ) { + CFF_Index idx = &font->name_index; FT_Memory memory = idx->stream->memory; FT_Byte* bytes; FT_ULong byte_len; @@ -553,42 +595,35 @@ } + /* get an entry from String INDEX */ FT_LOCAL_DEF( FT_String* ) - cff_index_get_sid_string( CFF_Index idx, - FT_UInt sid, - FT_Service_PsCMaps psnames ) + cff_index_get_string( CFF_Font font, + FT_UInt element ) + { + return ( element < font->num_strings ) + ? (FT_String*)font->strings[element] + : NULL; + } + + + FT_LOCAL_DEF( FT_String* ) + cff_index_get_sid_string( CFF_Font font, + FT_UInt sid ) { /* value 0xFFFFU indicates a missing dictionary entry */ if ( sid == 0xFFFFU ) - return 0; + return NULL; /* if it is not a standard string, return it */ if ( sid > 390 ) - return cff_index_get_name( idx, sid - 391 ); + return cff_index_get_string( font, sid - 391 ); /* CID-keyed CFF fonts don't have glyph names */ - if ( !psnames ) - return 0; - - /* that's a standard string, fetch a copy from the PSName module */ - { - FT_String* name = 0; - const char* adobe_name = psnames->adobe_std_strings( sid ); - - - if ( adobe_name ) - { - FT_Memory memory = idx->stream->memory; - FT_Error error; - - - (void)FT_STRDUP( name, adobe_name ); - - FT_UNUSED( error ); - } + if ( !font->psnames ) + return NULL; - return name; - } + /* this is a standard string */ + return (FT_String *)font->psnames->adobe_std_strings( sid ); } @@ -734,7 +769,7 @@ FT_UInt num_glyphs, FT_Memory memory ) { - FT_Error error = FT_Err_Ok; + FT_Error error = CFF_Err_Ok; FT_UInt i; FT_Long j; FT_UShort max_cid = 0; @@ -894,14 +929,16 @@ /* check whether the range contains at least one valid glyph; */ /* the constant is given in the CFF specification */ - if ( glyph_sid >= 65000L ) { + if ( glyph_sid >= 65000L ) + { FT_ERROR(( "cff_charset_load: invalid SID range\n" )); error = CFF_Err_Invalid_File_Format; goto Exit; } /* try to rescue some of the SIDs if `nleft' is too large */ - if ( nleft > 65000L - 1L || glyph_sid >= 65000L - nleft ) { + if ( nleft > 65000L - 1L || glyph_sid >= 65000L - nleft ) + { FT_ERROR(( "cff_charset_load: invalid SID range trimmed\n" )); nleft = ( FT_UInt )( 65000L - 1L - glyph_sid ); } @@ -1361,9 +1398,8 @@ if ( error ) goto Exit; - font->num_local_subrs = font->local_subrs_index.count; error = cff_index_get_pointers( &font->local_subrs_index, - &font->local_subrs ); + &font->local_subrs, NULL ); if ( error ) goto Exit; } @@ -1409,9 +1445,11 @@ FT_Memory memory = stream->memory; FT_ULong base_offset; CFF_FontRecDict dict; + CFF_IndexRec string_index; FT_ZERO( font ); + FT_ZERO( &string_index ); font->stream = stream; font->memory = memory; @@ -1438,15 +1476,20 @@ /* read the name, top dict, string and global subrs index */ if ( FT_SET_ERROR( cff_index_init( &font->name_index, - stream, 0 ) ) || + stream, 0 ) ) || FT_SET_ERROR( cff_index_init( &font->font_dict_index, - stream, 0 ) ) || - FT_SET_ERROR( cff_index_init( &font->string_index, - stream, 0 ) ) || + stream, 0 ) ) || + FT_SET_ERROR( cff_index_init( &string_index, + stream, 1 ) ) || FT_SET_ERROR( cff_index_init( &font->global_subrs_index, - stream, 1 ) ) ) + stream, 1 ) ) || + FT_SET_ERROR( cff_index_get_pointers( &string_index, + &font->strings, + &font->string_pool ) ) ) goto Exit; + font->num_strings = string_index.count; + /* well, we don't really forget the `disabled' fonts... */ font->num_faces = font->name_index.count; if ( face_index >= (FT_Int)font->num_faces ) @@ -1542,12 +1585,10 @@ goto Exit; } - /* explicit the global subrs */ - font->num_global_subrs = font->global_subrs_index.count; - font->num_glyphs = font->charstrings_index.count; + font->num_glyphs = font->charstrings_index.count; error = cff_index_get_pointers( &font->global_subrs_index, - &font->global_subrs ) ; + &font->global_subrs, NULL ); if ( error ) goto Exit; @@ -1579,9 +1620,11 @@ /* get the font name (/CIDFontName for CID-keyed fonts, */ /* /FontName otherwise) */ - font->font_name = cff_index_get_name( &font->name_index, face_index ); + font->font_name = cff_index_get_name( font, face_index ); Exit: + cff_index_done( &string_index ); + return error; } @@ -1594,7 +1637,6 @@ cff_index_done( &font->global_subrs_index ); - cff_index_done( &font->string_index ); cff_index_done( &font->font_dict_index ); cff_index_done( &font->name_index ); cff_index_done( &font->charstrings_index ); @@ -1617,21 +1659,12 @@ CFF_Done_FD_Select( &font->fd_select, font->stream ); - if (font->font_info != NULL) - { - FT_FREE( font->font_info->version ); - FT_FREE( font->font_info->notice ); - FT_FREE( font->font_info->full_name ); - FT_FREE( font->font_info->family_name ); - FT_FREE( font->font_info->weight ); - FT_FREE( font->font_info ); - } - - FT_FREE( font->registry ); - FT_FREE( font->ordering ); + FT_FREE( font->font_info ); - FT_FREE( font->global_subrs ); FT_FREE( font->font_name ); + FT_FREE( font->global_subrs ); + FT_FREE( font->strings ); + FT_FREE( font->string_pool ); } diff --git a/freetype/src/cff/cffload.h b/freetype/src/cff/cffload.h index 2b313acf0..c755de9a2 100644 --- a/freetype/src/cff/cffload.h +++ b/freetype/src/cff/cffload.h @@ -4,7 +4,7 @@ /* */ /* OpenType & CFF data/program tables loader (specification). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2007, 2008 by */ +/* Copyright 1996-2001, 2002, 2003, 2007, 2008, 2010 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -22,7 +22,6 @@ #include #include "cfftypes.h" -#include FT_SERVICE_POSTSCRIPT_CMAPS_H FT_BEGIN_HEADER @@ -32,13 +31,12 @@ FT_BEGIN_HEADER FT_LOCAL( FT_String* ) - cff_index_get_name( CFF_Index idx, - FT_UInt element ); + cff_index_get_string( CFF_Font font, + FT_UInt element ); FT_LOCAL( FT_String* ) - cff_index_get_sid_string( CFF_Index idx, - FT_UInt sid, - FT_Service_PsCMaps psnames ); + cff_index_get_sid_string( CFF_Font font, + FT_UInt sid ); FT_LOCAL( FT_Error ) @@ -51,6 +49,10 @@ FT_BEGIN_HEADER cff_index_forget_element( CFF_Index idx, FT_Byte** pbytes ); + FT_LOCAL( FT_String* ) + cff_index_get_name( CFF_Font font, + FT_UInt element ); + FT_LOCAL( FT_UInt ) cff_charset_cid_to_gindex( CFF_Charset charset, diff --git a/freetype/src/cff/cffobjs.c b/freetype/src/cff/cffobjs.c index bd56c4ba1..f8b07c356 100644 --- a/freetype/src/cff/cffobjs.c +++ b/freetype/src/cff/cffobjs.c @@ -4,7 +4,8 @@ /* */ /* OpenType objects manager (body). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 by */ +/* Copyright 1996-2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, */ +/* 2010 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -24,8 +25,6 @@ #include FT_TRUETYPE_IDS_H #include FT_TRUETYPE_TAGS_H #include FT_INTERNAL_SFNT_H -#include FT_SERVICE_POSTSCRIPT_CMAPS_H -#include FT_INTERNAL_POSTSCRIPT_HINTS_H #include "cffobjs.h" #include "cffload.h" #include "cffcmap.h" @@ -58,7 +57,7 @@ { CFF_Face face = (CFF_Face)size->root.face; CFF_Font font = (CFF_Font)face->extra.data; - PSHinter_Service pshinter = (PSHinter_Service)font->pshinter; + PSHinter_Service pshinter = font->pshinter; FT_Module module; @@ -349,7 +348,7 @@ { CFF_Face face = (CFF_Face)slot->face; CFF_Font font = (CFF_Font)face->extra.data; - PSHinter_Service pshinter = (PSHinter_Service)font->pshinter; + PSHinter_Service pshinter = font->pshinter; if ( pshinter ) @@ -395,6 +394,41 @@ } + /* Strip all subset prefixes of the form `ABCDEF+'. Usually, there */ + /* is only one, but font names like `APCOOG+JFABTD+FuturaBQ-Bold' */ + /* have been seen in the wild. */ + + static void + remove_subset_prefix( FT_String* name ) + { + FT_Int32 idx = 0; + FT_Int32 length = strlen( name ) + 1; + FT_Bool continue_search = 1; + + + while ( continue_search ) + { + if ( length >= 7 && name[6] == '+' ) + { + for ( idx = 0; idx < 6; idx++ ) + { + /* ASCII uppercase letters */ + if ( !( 'A' <= name[idx] && name[idx] <= 'Z' ) ) + continue_search = 0; + } + + if ( continue_search ) + { + for ( idx = 7; idx < length; idx++ ) + name[idx - 7] = name[idx]; + } + } + else + continue_search = 0; + } + } + + FT_LOCAL_DEF( FT_Error ) cff_face_init( FT_Stream stream, FT_Face cffface, /* CFF_Face */ @@ -412,14 +446,6 @@ FT_Library library = cffface->driver->root.library; -#if 0 - FT_FACE_FIND_GLOBAL_SERVICE( face, sfnt, SFNT ); - FT_FACE_FIND_GLOBAL_SERVICE( face, psnames, POSTSCRIPT_NAMES ); - FT_FACE_FIND_GLOBAL_SERVICE( face, pshinter, POSTSCRIPT_HINTER ); - - if ( !sfnt ) - goto Bad_Format; -#else sfnt = (SFNT_Service)FT_Get_Module_Interface( library, "sfnt" ); if ( !sfnt ) @@ -429,7 +455,6 @@ pshinter = (PSHinter_Service)FT_Get_Module_Interface( library, "pshinter" ); -#endif /* create input stream from resource */ if ( FT_STREAM_SEEK( 0 ) ) @@ -514,7 +539,7 @@ goto Exit; cff->pshinter = pshinter; - cff->psnames = (void*)psnames; + cff->psnames = psnames; cffface->face_index = face_index; @@ -678,24 +703,22 @@ (FT_Short)( dict->underline_thickness >> 16 ); /* retrieve font family & style name */ - cffface->family_name = cff_index_get_name( &cff->name_index, - face_index ); - + cffface->family_name = cff_index_get_name( cff, face_index ); if ( cffface->family_name ) { - char* full = cff_index_get_sid_string( &cff->string_index, - dict->full_name, - psnames ); + char* full = cff_index_get_sid_string( cff, + dict->full_name ); char* fullp = full; char* family = cffface->family_name; - char* family_name = 0; + char* family_name = NULL; + remove_subset_prefix( cffface->family_name ); + if ( dict->family_name ) { - family_name = cff_index_get_sid_string( &cff->string_index, - dict->family_name, - psnames); + family_name = cff_index_get_sid_string( cff, + dict->family_name ); if ( family_name ) family = family_name; } @@ -738,23 +761,18 @@ } break; } - - if ( family_name ) - FT_FREE( family_name ); - FT_FREE( full ); } } else { char *cid_font_name = - cff_index_get_sid_string( &cff->string_index, - dict->cid_font_name, - psnames ); + cff_index_get_sid_string( cff, + dict->cid_font_name ); /* do we have a `/FontName' for a CID-keyed font? */ if ( cid_font_name ) - cffface->family_name = cid_font_name; + cffface->family_name = cff_strcpy( memory, cid_font_name ); } if ( style_name ) @@ -797,16 +815,14 @@ flags |= FT_STYLE_FLAG_ITALIC; { - char *weight = cff_index_get_sid_string( &cff->string_index, - dict->weight, - psnames ); + char *weight = cff_index_get_sid_string( cff, + dict->weight ); if ( weight ) if ( !ft_strcmp( weight, "Bold" ) || !ft_strcmp( weight, "Black" ) ) flags |= FT_STYLE_FLAG_BOLD; - FT_FREE( weight ); } /* double check */ @@ -849,13 +865,14 @@ { cmap = cffface->charmaps[nn]; - /* Windows Unicode (3,1)? */ - if ( cmap->platform_id == 3 && cmap->encoding_id == 1 ) + /* Windows Unicode? */ + if ( cmap->platform_id == TT_PLATFORM_MICROSOFT && + cmap->encoding_id == TT_MS_ID_UNICODE_CS ) goto Skip_Unicode; - /* Deprecated Unicode platform id? */ - if ( cmap->platform_id == 0 ) - goto Skip_Unicode; /* Standard Unicode (deprecated) */ + /* Apple Unicode platform id? */ + if ( cmap->platform_id == TT_PLATFORM_APPLE_UNICODE ) + goto Skip_Unicode; /* Apple Unicode */ } /* since CID-keyed fonts don't contain glyph names, we can't */ @@ -863,28 +880,51 @@ if ( pure_cff && cff->top_font.font_dict.cid_registry != 0xFFFFU ) goto Exit; +#ifdef FT_MAX_CHARMAP_CACHEABLE + if ( nn + 1 > FT_MAX_CHARMAP_CACHEABLE ) + { + FT_ERROR(( "cff_face_init: no Unicode cmap is found, " + "and too many subtables (%d) to add synthesized cmap\n", + nn )); + goto Exit; + } +#endif + /* we didn't find a Unicode charmap -- synthesize one */ cmaprec.face = cffface; - cmaprec.platform_id = 3; - cmaprec.encoding_id = 1; + cmaprec.platform_id = TT_PLATFORM_MICROSOFT; + cmaprec.encoding_id = TT_MS_ID_UNICODE_CS; cmaprec.encoding = FT_ENCODING_UNICODE; nn = (FT_UInt)cffface->num_charmaps; - FT_CMap_New( &FT_CFF_CMAP_UNICODE_CLASS_REC_GET, NULL, &cmaprec, NULL ); + error = FT_CMap_New( &FT_CFF_CMAP_UNICODE_CLASS_REC_GET, NULL, + &cmaprec, NULL ); + if ( error && FT_Err_No_Unicode_Glyph_Name != error ) + goto Exit; + error = FT_Err_Ok; /* if no Unicode charmap was previously selected, select this one */ if ( cffface->charmap == NULL && nn != (FT_UInt)cffface->num_charmaps ) cffface->charmap = cffface->charmaps[nn]; Skip_Unicode: +#ifdef FT_MAX_CHARMAP_CACHEABLE + if ( nn > FT_MAX_CHARMAP_CACHEABLE ) + { + FT_ERROR(( "cff_face_init: Unicode cmap is found, " + "but too many preceding subtables (%d) to access\n", + nn - 1 )); + goto Exit; + } +#endif if ( encoding->count > 0 ) { FT_CMap_Class clazz; cmaprec.face = cffface; - cmaprec.platform_id = 7; /* Adobe platform id */ + cmaprec.platform_id = TT_PLATFORM_ADOBE; /* Adobe platform id */ if ( encoding->offset == 0 ) { @@ -905,7 +945,7 @@ clazz = &FT_CFF_CMAP_ENCODING_CLASS_REC_GET; } - FT_CMap_New( clazz, NULL, &cmaprec, NULL ); + error = FT_CMap_New( clazz, NULL, &cmaprec, NULL ); } } } diff --git a/freetype/src/cff/cffparse.c b/freetype/src/cff/cffparse.c index 01266a193..0d11a7278 100644 --- a/freetype/src/cff/cffparse.c +++ b/freetype/src/cff/cffparse.c @@ -4,7 +4,7 @@ /* */ /* CFF token stream parser (body) */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2004, 2007, 2008, 2009 by */ +/* Copyright 1996-2001, 2002, 2003, 2004, 2007, 2008, 2009, 2010 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -137,26 +137,23 @@ FT_UInt nib; FT_UInt phase; - FT_Long result, number, rest, exponent; + FT_Long result, number, exponent; FT_Int sign = 0, exponent_sign = 0; FT_Long exponent_add, integer_length, fraction_length; if ( scaling ) - *scaling = 0; + *scaling = 0; result = 0; number = 0; - rest = 0; exponent = 0; exponent_add = 0; integer_length = 0; fraction_length = 0; - FT_UNUSED( rest ); - /* First of all, read the integer part. */ phase = 4; @@ -332,11 +329,19 @@ goto Exit; /* Remove non-significant digits. */ - if ( integer_length < 0 ) { + if ( integer_length < 0 ) + { number /= power_tens[-integer_length]; fraction_length += integer_length; } + /* this can only happen if exponent was non-zero */ + if ( fraction_length == 10 ) + { + number /= 10; + fraction_length -= 1; + } + /* Convert into 16.16 format. */ if ( fraction_length > 0 ) { @@ -702,7 +707,7 @@ clazz[i].count_offset = 0; *output_class = clazz; - return FT_Err_Ok; + return CFF_Err_Ok; } diff --git a/freetype/src/cff/cffpic.c b/freetype/src/cff/cffpic.c index 568956d6a..5d01bd45e 100644 --- a/freetype/src/cff/cffpic.c +++ b/freetype/src/cff/cffpic.c @@ -4,7 +4,7 @@ /* */ /* The FreeType position independent code services for cff module. */ /* */ -/* Copyright 2009 by */ +/* Copyright 2009, 2010 by */ /* Oran Agra and Mickey Gabel. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -59,18 +59,20 @@ } } + FT_Error - cff_driver_class_pic_init( FT_Library library ) + cff_driver_class_pic_init( FT_Library library ) { - FT_PIC_Container* pic_container = &library->pic_container; - FT_Error error = FT_Err_Ok; - CffModulePIC* container; - FT_Memory memory = library->memory; + FT_PIC_Container* pic_container = &library->pic_container; + FT_Error error = CFF_Err_Ok; + CffModulePIC* container; + FT_Memory memory = library->memory; + /* allocate pointer, clear and set global container pointer */ if ( FT_ALLOC ( container, sizeof ( *container ) ) ) return error; - FT_MEM_SET( container, 0, sizeof(*container) ); + FT_MEM_SET( container, 0, sizeof ( *container ) ); pic_container->cff = container; /* initialize pointer table - this is how the module usually expects this data */ diff --git a/freetype/src/cff/cfftypes.h b/freetype/src/cff/cfftypes.h index df92e9a1a..d40535765 100644 --- a/freetype/src/cff/cfftypes.h +++ b/freetype/src/cff/cfftypes.h @@ -5,7 +5,7 @@ /* Basic OpenType/CFF type definitions and interface (specification */ /* only). */ /* */ -/* Copyright 1996-2001, 2002, 2003, 2006, 2007, 2008 by */ +/* Copyright 1996-2001, 2002, 2003, 2006, 2007, 2008, 2010 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ @@ -24,6 +24,9 @@ #include #include FT_FREETYPE_H #include FT_TYPE1_TABLES_H +#include FT_INTERNAL_SERVICE_H +#include FT_SERVICE_POSTSCRIPT_CMAPS_H +#include FT_INTERNAL_POSTSCRIPT_HINTS_H FT_BEGIN_HEADER @@ -204,8 +207,7 @@ FT_BEGIN_HEADER CFF_PrivateRec private_dict; CFF_IndexRec local_subrs_index; - FT_UInt num_local_subrs; - FT_Byte** local_subrs; + FT_Byte** local_subrs; /* array of pointers into Local Subrs INDEX data */ } CFF_SubFontRec, *CFF_SubFont; @@ -229,7 +231,6 @@ FT_BEGIN_HEADER CFF_IndexRec name_index; CFF_IndexRec top_dict_index; - CFF_IndexRec string_index; CFF_IndexRec global_subrs_index; CFF_EncodingRec encoding; @@ -241,9 +242,15 @@ FT_BEGIN_HEADER CFF_IndexRec local_subrs_index; FT_String* font_name; - FT_UInt num_global_subrs; + + /* array of pointers into Global Subrs INDEX data */ FT_Byte** global_subrs; + /* array of pointers into String INDEX data stored at string_pool */ + FT_UInt num_strings; + FT_Byte** strings; + FT_Byte* string_pool; + CFF_SubFontRec top_font; FT_UInt num_subfonts; CFF_SubFont subfonts[CFF_MAX_CID_FONTS]; @@ -251,10 +258,10 @@ FT_BEGIN_HEADER CFF_FDSelectRec fd_select; /* interface to PostScript hinter */ - void* pshinter; + PSHinter_Service pshinter; /* interface to Postscript Names service */ - void* psnames; + FT_Service_PsCMaps psnames; /* since version 2.3.0 */ PS_FontInfoRec* font_info; /* font info dictionary */ -- cgit v1.2.3