tt_face_load_gasp( TT_Face face, FT_Stream stream ) { FT_Error error; FT_Memory memory = stream->memory; FT_UInt j,num_ranges; TT_GaspRange gaspranges; /* the gasp table is optional */ error = face->goto_table( face, TTAG_gasp, stream, 0 ); if ( error ) goto Exit; if ( FT_FRAME_ENTER( 4L ) ) goto Exit; face->gasp.version = FT_GET_USHORT(); face->gasp.numRanges = FT_GET_USHORT(); FT_FRAME_EXIT(); /* only support versions 0 and 1 of the table */ if ( face->gasp.version >= 2 ) { face->gasp.numRanges = 0; error = SFNT_Err_Invalid_Table; goto Exit; } num_ranges = face->gasp.numRanges; FT_TRACE3(( "numRanges: %u\n", num_ranges )); if ( FT_QNEW_ARRAY( gaspranges, num_ranges ) || FT_FRAME_ENTER( num_ranges * 4L ) ) goto Exit; face->gasp.gaspRanges = gaspranges; for ( j = 0; j < num_ranges; j++ ) { gaspranges[j].maxPPEM = FT_GET_USHORT(); gaspranges[j].gaspFlag = FT_GET_USHORT(); FT_TRACE3(( "gaspRange %d: rangeMaxPPEM %5d, rangeGaspBehavior 0x%x\n", j, gaspranges[j].maxPPEM, gaspranges[j].gaspFlag )); } FT_FRAME_EXIT(); Exit: return error; }
static FT_Error check_type1_format( FT_Stream stream, const char* header_string, size_t header_length ) { FT_Error error; FT_UShort tag; FT_Long size; if ( FT_STREAM_SEEK( 0 ) ) goto Exit; error = read_pfb_tag( stream, &tag, &size ); if ( error ) goto Exit; if ( tag != 0x8001U && FT_STREAM_SEEK( 0 ) ) goto Exit; if ( !FT_FRAME_ENTER( header_length ) ) { error = 0; if ( ft_memcmp( stream->cursor, header_string, header_length ) != 0 ) error = T1_Err_Unknown_File_Format; FT_FRAME_EXIT(); } Exit: return error; }
static void read_data_from_FT_Stream( png_structp png, png_bytep data, png_size_t length ) { FT_Error error; png_voidp p = png_get_io_ptr( png ); FT_Stream stream = (FT_Stream)p; if ( FT_FRAME_ENTER( length ) ) { FT_Error* e = (FT_Error*)png_get_error_ptr( png ); *e = FT_THROW( Invalid_Stream_Read ); png_error( png, NULL ); return; } memcpy( data, stream->cursor, length ); FT_FRAME_EXIT(); }
T1_Read_Metrics( FT_Face t1_face, FT_Stream stream ) { FT_Error error; FT_Byte* start; if ( FT_FRAME_ENTER( stream->size ) ) return error; start = (FT_Byte*)stream->cursor; if ( stream->size >= ft_strlen( "StartFontMetrics" ) && ft_strncmp( (const char*)start, "StartFontMetrics", ft_strlen( "StartFontMetrics" ) ) == 0 ) error = T1_Read_AFM( t1_face, stream ); else if ( stream->size > 6 && start[0] == 0x00 && start[1] == 0x01 && LITTLE_ENDIAN_UINT( start + 2 ) == stream->size ) error = T1_Read_PFM( t1_face, stream ); else error = T1_Err_Unknown_File_Format; FT_FRAME_EXIT(); return error; }
static FT_Error cff_index_load_offsets( CFF_Index idx ) { FT_Error error = 0; FT_Stream stream = idx->stream; FT_Memory memory = stream->memory; if ( idx->count > 0 && idx->offsets == NULL ) { FT_Byte offsize = idx->off_size; FT_ULong data_size; FT_Byte* p; FT_Byte* p_end; FT_ULong* poff; data_size = (FT_ULong)( idx->count + 1 ) * offsize; if ( FT_NEW_ARRAY( idx->offsets, idx->count + 1 ) || FT_STREAM_SEEK( idx->start + 3 ) || FT_FRAME_ENTER( data_size ) ) goto Exit; poff = idx->offsets; p = (FT_Byte*)stream->cursor; p_end = p + data_size; switch ( offsize ) { case 1: for ( ; p < p_end; p++, poff++ ) poff[0] = p[0]; break; case 2: for ( ; p < p_end; p += 2, poff++ ) poff[0] = FT_PEEK_USHORT( p ); break; case 3: for ( ; p < p_end; p += 3, poff++ ) poff[0] = FT_PEEK_OFF3( p ); break; default: for ( ; p < p_end; p += 4, poff++ ) poff[0] = FT_PEEK_ULONG( p ); } FT_FRAME_EXIT(); } Exit: if ( error ) FT_FREE( idx->offsets ); return error; }
static FT_UInt32 tt_synth_sfnt_checksum( FT_Stream stream, FT_ULong length ) { FT_Error error; FT_UInt32 checksum = 0; FT_UInt i; if ( FT_FRAME_ENTER( length ) ) return 0; for ( ; length > 3; length -= 4 ) checksum += (FT_UInt32)FT_GET_ULONG(); for ( i = 3; length > 0; length--, i-- ) checksum += (FT_UInt32)FT_GET_BYTE() << ( i * 8 ); FT_FRAME_EXIT(); return checksum; }
static FT_Error check_type1_format( FT_Stream stream, const char* header_string, size_t header_length ) { FT_Error error; FT_UShort tag; FT_ULong dummy; if ( FT_STREAM_SEEK( 0 ) ) goto Exit; error = read_pfb_tag( stream, &tag, &dummy ); if ( error ) goto Exit; /* We assume that the first segment in a PFB is always encoded as */ /* text. This might be wrong (and the specification doesn't insist */ /* on that), but we have never seen a counterexample. */ if ( tag != 0x8001U && FT_STREAM_SEEK( 0 ) ) goto Exit; if ( !FT_FRAME_ENTER( header_length ) ) { error = FT_Err_Ok; if ( ft_memcmp( stream->cursor, header_string, header_length ) != 0 ) error = FT_THROW( Unknown_File_Format ); FT_FRAME_EXIT(); } Exit: return error; }
static FT_Bool _tt_check_patents_in_range( FT_Stream stream, FT_ULong size ) { FT_Bool result = FALSE; FT_Error error; FT_Bytes p, end; if ( FT_FRAME_ENTER( size ) ) return 0; p = stream->cursor; end = p + size; while ( p < end ) { switch (p[0]) { case 0x06: /* SPvTL // */ case 0x07: /* SPvTL + */ case 0x08: /* SFvTL // */ case 0x09: /* SFvTL + */ case 0x0A: /* SPvFS */ case 0x0B: /* SFvFS */ result = TRUE; goto Exit; case 0x40: if ( p + 1 >= end ) goto Exit; p += p[1] + 2; break; case 0x41: if ( p + 1 >= end ) goto Exit; p += p[1] * 2 + 2; break; case 0x71: /* DELTAP2 */ case 0x72: /* DELTAP3 */ case 0x73: /* DELTAC0 */ case 0x74: /* DELTAC1 */ case 0x75: /* DELTAC2 */ result = TRUE; goto Exit; case 0xB0: case 0xB1: case 0xB2: case 0xB3: case 0xB4: case 0xB5: case 0xB6: case 0xB7: p += ( p[0] - 0xB0 ) + 2; break; case 0xB8: case 0xB9: case 0xBA: case 0xBB: case 0xBC: case 0xBD: case 0xBE: case 0xBF: p += ( p[0] - 0xB8 ) * 2 + 3; break; default: p += 1; break; } } Exit: FT_UNUSED( error ); FT_FRAME_EXIT(); return result; }
tt_face_load_name( TT_Face face, FT_Stream stream ) { FT_Error error; FT_Memory memory = stream->memory; FT_ULong table_pos, table_len; FT_ULong storage_start, storage_limit; FT_UInt count; TT_NameTable table; static const FT_Frame_Field name_table_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE TT_NameTableRec FT_FRAME_START( 6 ), FT_FRAME_USHORT( format ), FT_FRAME_USHORT( numNameRecords ), FT_FRAME_USHORT( storageOffset ), FT_FRAME_END }; static const FT_Frame_Field name_record_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE TT_NameEntryRec /* no FT_FRAME_START */ FT_FRAME_USHORT( platformID ), FT_FRAME_USHORT( encodingID ), FT_FRAME_USHORT( languageID ), FT_FRAME_USHORT( nameID ), FT_FRAME_USHORT( stringLength ), FT_FRAME_USHORT( stringOffset ), FT_FRAME_END }; table = &face->name_table; table->stream = stream; error = face->goto_table( face, TTAG_name, stream, &table_len ); if ( error ) goto Exit; table_pos = FT_STREAM_POS(); if ( FT_STREAM_READ_FIELDS( name_table_fields, table ) ) goto Exit; /* Some popular Asian fonts have an invalid `storageOffset' value */ /* (it should be at least "6 + 12*num_names"). However, the string */ /* offsets, computed as "storageOffset + entry->stringOffset", are */ /* valid pointers within the name table... */ /* */ /* We thus can't check `storageOffset' right now. */ /* */ storage_start = table_pos + 6 + 12*table->numNameRecords; storage_limit = table_pos + table_len; if ( storage_start > storage_limit ) { FT_ERROR(( "tt_face_load_name: invalid `name' table\n" )); error = SFNT_Err_Name_Table_Missing; goto Exit; } /* Allocate the array of name records. */ count = table->numNameRecords; table->numNameRecords = 0; if ( FT_NEW_ARRAY( table->names, count ) || FT_FRAME_ENTER( count * 12 ) ) goto Exit; /* Load the name records and determine how much storage is needed */ /* to hold the strings themselves. */ { TT_NameEntryRec* entry = table->names; for ( ; count > 0; count-- ) { if ( FT_STREAM_READ_FIELDS( name_record_fields, entry ) ) continue; /* check that the name is not empty */ if ( entry->stringLength == 0 ) continue; /* check that the name string is within the table */ entry->stringOffset += table_pos + table->storageOffset; if ( entry->stringOffset < storage_start || entry->stringOffset + entry->stringLength > storage_limit ) { /* invalid entry - ignore it */ entry->stringOffset = 0; entry->stringLength = 0; continue; } entry++; } table->numNameRecords = (FT_UInt)( entry - table->names ); } FT_FRAME_EXIT(); /* everything went well, update face->num_names */ face->num_names = (FT_UShort) table->numNameRecords; Exit: return error; }
tt_face_load_font_dir( TT_Face face, FT_Stream stream ) { SFNT_HeaderRec sfnt; FT_Error error; FT_Memory memory = stream->memory; TT_TableRec* entry; FT_Int nn; static const FT_Frame_Field offset_table_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE SFNT_HeaderRec FT_FRAME_START( 8 ), FT_FRAME_USHORT( num_tables ), FT_FRAME_USHORT( search_range ), FT_FRAME_USHORT( entry_selector ), FT_FRAME_USHORT( range_shift ), FT_FRAME_END }; FT_TRACE2(( "tt_face_load_font_dir: %08p\n", face )); /* read the offset table */ sfnt.offset = FT_STREAM_POS(); if ( FT_READ_ULONG( sfnt.format_tag ) || FT_STREAM_READ_FIELDS( offset_table_fields, &sfnt ) ) goto Exit; /* many fonts don't have these fields set correctly */ #if 0 if ( sfnt.search_range != 1 << ( sfnt.entry_selector + 4 ) || sfnt.search_range + sfnt.range_shift != sfnt.num_tables << 4 ) return SFNT_Err_Unknown_File_Format; #endif /* load the table directory */ FT_TRACE2(( "-- Number of tables: %10u\n", sfnt.num_tables )); FT_TRACE2(( "-- Format version: 0x%08lx\n", sfnt.format_tag )); /* check first */ error = check_table_dir( &sfnt, stream ); if ( error ) { FT_TRACE2(( "tt_face_load_font_dir:" " invalid table directory for TrueType\n" )); goto Exit; } face->num_tables = sfnt.num_tables; face->format_tag = sfnt.format_tag; if ( FT_QNEW_ARRAY( face->dir_tables, face->num_tables ) ) goto Exit; if ( FT_STREAM_SEEK( sfnt.offset + 12 ) || FT_FRAME_ENTER( face->num_tables * 16L ) ) goto Exit; entry = face->dir_tables; for ( nn = 0; nn < sfnt.num_tables; nn++ ) { entry->Tag = FT_GET_TAG4(); entry->CheckSum = FT_GET_ULONG(); entry->Offset = FT_GET_LONG(); entry->Length = FT_GET_LONG(); /* ignore invalid tables */ if ( entry->Offset + entry->Length > stream->size ) continue; else { FT_TRACE2(( " %c%c%c%c - %08lx - %08lx\n", (FT_Char)( entry->Tag >> 24 ), (FT_Char)( entry->Tag >> 16 ), (FT_Char)( entry->Tag >> 8 ), (FT_Char)( entry->Tag ), entry->Offset, entry->Length )); entry++; } } FT_FRAME_EXIT(); FT_TRACE2(( "table directory loaded\n\n" )); Exit: return error; }
pfr_phy_font_load( PFR_PhyFont phy_font, FT_Stream stream, FT_UInt32 offset, FT_UInt32 size ) { FT_Error error; FT_Memory memory = stream->memory; FT_UInt flags, num_aux; FT_Byte* p; FT_Byte* limit; phy_font->memory = memory; phy_font->offset = offset; if ( FT_STREAM_SEEK( offset ) || FT_FRAME_ENTER( size ) ) goto Exit; p = stream->cursor; limit = p + size; PFR_CHECK( 15 ); phy_font->font_ref_number = PFR_NEXT_USHORT( p ); phy_font->outline_resolution = PFR_NEXT_USHORT( p ); phy_font->metrics_resolution = PFR_NEXT_USHORT( p ); phy_font->bbox.xMin = PFR_NEXT_SHORT( p ); phy_font->bbox.yMin = PFR_NEXT_SHORT( p ); phy_font->bbox.xMax = PFR_NEXT_SHORT( p ); phy_font->bbox.yMax = PFR_NEXT_SHORT( p ); phy_font->flags = flags = PFR_NEXT_BYTE( p ); /* get the standard advance for non-proprotional fonts */ if ( !(flags & PFR_PHY_PROPORTIONAL) ) { PFR_CHECK( 2 ); phy_font->standard_advance = PFR_NEXT_SHORT( p ); } /* load the extra items when present */ if ( flags & PFR_PHY_EXTRA_ITEMS ) { error = pfr_extra_items_parse( &p, limit, pfr_phy_font_extra_items, phy_font ); if ( error ) goto Fail; } /* skip the aux bytes */ PFR_CHECK( 3 ); num_aux = PFR_NEXT_ULONG( p ); PFR_CHECK( num_aux ); p += num_aux; /* read the blue values */ { FT_UInt n, count; PFR_CHECK( 1 ); phy_font->num_blue_values = count = PFR_NEXT_BYTE( p ); PFR_CHECK( count * 2 ); if ( FT_NEW_ARRAY( phy_font->blue_values, count ) ) goto Fail; for ( n = 0; n < count; n++ ) phy_font->blue_values[n] = PFR_NEXT_SHORT( p ); } PFR_CHECK( 8 ); phy_font->blue_fuzz = PFR_NEXT_BYTE( p ); phy_font->blue_scale = PFR_NEXT_BYTE( p ); phy_font->vertical.standard = PFR_NEXT_USHORT( p ); phy_font->horizontal.standard = PFR_NEXT_USHORT( p ); /* read the character descriptors */ { FT_UInt n, count, Size; phy_font->num_chars = count = PFR_NEXT_USHORT( p ); phy_font->chars_offset = offset + ( p - stream->cursor ); if ( FT_NEW_ARRAY( phy_font->chars, count ) ) goto Fail; Size = 1 + 1 + 2; if ( flags & PFR_PHY_2BYTE_CHARCODE ) Size += 1; if ( flags & PFR_PHY_PROPORTIONAL ) Size += 2; if ( flags & PFR_PHY_ASCII_CODE ) Size += 1; if ( flags & PFR_PHY_2BYTE_GPS_SIZE ) Size += 1; if ( flags & PFR_PHY_3BYTE_GPS_OFFSET ) Size += 1; PFR_CHECK( count * Size ); for ( n = 0; n < count; n++ ) { PFR_Char cur = &phy_font->chars[n]; cur->char_code = ( flags & PFR_PHY_2BYTE_CHARCODE ) ? PFR_NEXT_USHORT( p ) : PFR_NEXT_BYTE( p ); cur->advance = ( flags & PFR_PHY_PROPORTIONAL ) ? PFR_NEXT_SHORT( p ) : phy_font->standard_advance; #if 0 cur->ascii = ( flags & PFR_PHY_ASCII_CODE ) ? PFR_NEXT_BYTE( p ) : 0; #else if ( flags & PFR_PHY_ASCII_CODE ) p += 1; #endif cur->gps_size = ( flags & PFR_PHY_2BYTE_GPS_SIZE ) ? PFR_NEXT_USHORT( p ) : PFR_NEXT_BYTE( p ); cur->gps_offset = ( flags & PFR_PHY_3BYTE_GPS_OFFSET ) ? PFR_NEXT_ULONG( p ) : PFR_NEXT_USHORT( p ); } } /* that's it !! */ Fail: FT_FRAME_EXIT(); Exit: return error; Too_Short: error = PFR_Err_Invalid_Table; FT_ERROR(( "pfr_phy_font_load: invalid physical font table\n" )); goto Fail; }
cid_parser_new( CID_Parser* parser, FT_Stream stream, FT_Memory memory, PSAux_Service psaux ) { FT_Error error; FT_ULong base_offset, offset, ps_len; FT_Byte buffer[256 + 10]; FT_Int buff_len; FT_Byte *cur, *limit; FT_Byte *arg1, *arg2; FT_MEM_ZERO( parser, sizeof ( *parser ) ); psaux->ps_parser_funcs->init( &parser->root, 0, 0, memory ); parser->stream = stream; base_offset = FT_STREAM_POS(); /* first of all, check the font format in the header */ if ( FT_FRAME_ENTER( 31 ) ) goto Exit; if ( ft_strncmp( (char *)stream->cursor, "%!PS-Adobe-3.0 Resource-CIDFont", 31 ) ) { FT_TRACE2(( "[not a valid CID-keyed font]\n" )); error = CID_Err_Unknown_File_Format; } FT_FRAME_EXIT(); if ( error ) goto Exit; Again: /* now, read the rest of the file until we find a `StartData' */ buff_len = 256; for (;;) { FT_Byte* p; FT_ULong top_position; /* fill input buffer */ limit = buffer + 256; buff_len -= 256; if ( buff_len > 0 ) FT_MEM_MOVE( buffer, limit, buff_len ); p = buffer + buff_len; if ( FT_STREAM_READ( p, 256 + 10 - buff_len ) ) goto Exit; top_position = FT_STREAM_POS() - buff_len; buff_len = 256 + 10; /* look for `StartData' */ for ( p = buffer; p < limit; p++ ) { if ( p[0] == 'S' && ft_strncmp( (char*)p, "StartData", 9 ) == 0 ) { /* save offset of binary data after `StartData' */ offset = (FT_ULong)( top_position - ( limit - p ) + 10 ); goto Found; } } } Found: /* we have found the start of the binary data. We will now */ /* rewind and extract the frame corresponding to the PostScript */ /* section */ ps_len = offset - base_offset; if ( FT_STREAM_SEEK( base_offset ) || FT_FRAME_EXTRACT( ps_len, parser->postscript ) ) goto Exit; parser->data_offset = offset; parser->postscript_len = ps_len; parser->root.base = parser->postscript; parser->root.cursor = parser->postscript; parser->root.limit = parser->root.cursor + ps_len; parser->num_dict = -1; /* Finally, we check whether `StartData' was real -- it could be */ /* in a comment or string. We also get its arguments to find out */ /* whether the data is represented in binary or hex format. */ arg1 = parser->root.cursor; cid_parser_skip_PS_token( parser ); cid_parser_skip_spaces ( parser ); arg2 = parser->root.cursor; cid_parser_skip_PS_token( parser ); cid_parser_skip_spaces ( parser ); limit = parser->root.limit; cur = parser->root.cursor; while ( cur < limit ) { if ( parser->root.error ) break; if ( *cur == 'S' && ft_strncmp( (char*)cur, "StartData", 9 ) == 0 ) { if ( ft_strncmp( (char*)arg1, "(Hex)", 5 ) == 0 ) parser->binary_length = ft_atol( (const char *)arg2 ); limit = parser->root.limit; cur = parser->root.cursor; goto Exit; } cid_parser_skip_PS_token( parser ); cid_parser_skip_spaces ( parser ); arg1 = arg2; arg2 = cur; cur = parser->root.cursor; } /* we haven't found the correct `StartData'; go back and continue */ /* searching */ FT_FRAME_RELEASE( parser->postscript ); if ( !FT_STREAM_SEEK( offset ) ) goto Again; Exit: return error; }
static FT_Error fnt_face_get_dll_font( FNT_Face face, FT_Int face_index ) { FT_Error error; FT_Stream stream = FT_FACE( face )->stream; FT_Memory memory = FT_FACE( face )->memory; WinMZ_HeaderRec mz_header; face->font = 0; /* does it begin with an MZ header? */ if ( FT_STREAM_SEEK( 0 ) || FT_STREAM_READ_FIELDS( winmz_header_fields, &mz_header ) ) goto Exit; error = FNT_Err_Unknown_File_Format; if ( mz_header.magic == WINFNT_MZ_MAGIC ) { /* yes, now look for an NE header in the file */ WinNE_HeaderRec ne_header; if ( FT_STREAM_SEEK( mz_header.lfanew ) || FT_STREAM_READ_FIELDS( winne_header_fields, &ne_header ) ) goto Exit; error = FNT_Err_Unknown_File_Format; if ( ne_header.magic == WINFNT_NE_MAGIC ) { /* good, now look into the resource table for each FNT resource */ FT_ULong res_offset = mz_header.lfanew + ne_header.resource_tab_offset; FT_UShort size_shift; FT_UShort font_count = 0; FT_ULong font_offset = 0; if ( FT_STREAM_SEEK( res_offset ) || FT_FRAME_ENTER( ne_header.rname_tab_offset - ne_header.resource_tab_offset ) ) goto Exit; size_shift = FT_GET_USHORT_LE(); for (;;) { FT_UShort type_id, count; type_id = FT_GET_USHORT_LE(); if ( !type_id ) break; count = FT_GET_USHORT_LE(); if ( type_id == 0x8008U ) { font_count = count; font_offset = (FT_ULong)( FT_STREAM_POS() + 4 + ( stream->cursor - stream->limit ) ); break; } stream->cursor += 4 + count * 12; } FT_FRAME_EXIT(); if ( !font_count || !font_offset ) { FT_TRACE2(( "this file doesn't contain any FNT resources!\n" )); error = FNT_Err_Unknown_File_Format; goto Exit; } face->root.num_faces = font_count; if ( face_index >= font_count ) { error = FNT_Err_Bad_Argument; goto Exit; } if ( FT_NEW( face->font ) ) goto Exit; if ( FT_STREAM_SEEK( font_offset + face_index * 12 ) || FT_FRAME_ENTER( 12 ) ) goto Fail; face->font->offset = (FT_ULong)FT_GET_USHORT_LE() << size_shift; face->font->fnt_size = (FT_ULong)FT_GET_USHORT_LE() << size_shift; face->font->size_shift = size_shift; stream->cursor += 8; FT_FRAME_EXIT(); error = fnt_font_load( face->font, stream ); } } Fail: if ( error ) fnt_font_done( face ); Exit: return error; }
static FT_Error cff_subfont_load( CFF_SubFont font, CFF_Index idx, FT_UInt font_index, FT_Stream stream, FT_ULong base_offset ) { FT_Error error; CFF_ParserRec parser; FT_Byte* dict = NULL; FT_ULong dict_len; CFF_FontRecDict top = &font->font_dict; CFF_Private priv = &font->private_dict; cff_parser_init( &parser, CFF_CODE_TOPDICT, &font->font_dict ); /* set defaults */ FT_MEM_ZERO( top, sizeof ( *top ) ); top->underline_position = -100L << 16; top->underline_thickness = 50L << 16; top->charstring_type = 2; top->font_matrix.xx = 0x10000L; top->font_matrix.yy = 0x10000L; top->cid_count = 8720; /* we use the implementation specific SID value 0xFFFF to indicate */ /* missing entries */ top->version = 0xFFFFU; top->notice = 0xFFFFU; top->copyright = 0xFFFFU; top->full_name = 0xFFFFU; top->family_name = 0xFFFFU; top->weight = 0xFFFFU; top->embedded_postscript = 0xFFFFU; top->cid_registry = 0xFFFFU; top->cid_ordering = 0xFFFFU; top->cid_font_name = 0xFFFFU; error = cff_index_access_element( idx, font_index, &dict, &dict_len ); if ( !error ) error = cff_parser_run( &parser, dict, dict + dict_len ); cff_index_forget_element( idx, &dict ); if ( error ) goto Exit; /* if it is a CID font, we stop there */ if ( top->cid_registry != 0xFFFFU ) goto Exit; /* parse the private dictionary, if any */ if ( top->private_offset && top->private_size ) { /* set defaults */ FT_MEM_ZERO( priv, sizeof ( *priv ) ); priv->blue_shift = 7; priv->blue_fuzz = 1; priv->lenIV = -1; priv->expansion_factor = (FT_Fixed)( 0.06 * 0x10000L ); priv->blue_scale = (FT_Fixed)( 0.039625 * 0x10000L * 1000 ); cff_parser_init( &parser, CFF_CODE_PRIVATE, priv ); if ( FT_STREAM_SEEK( base_offset + font->font_dict.private_offset ) || FT_FRAME_ENTER( font->font_dict.private_size ) ) goto Exit; error = cff_parser_run( &parser, (FT_Byte*)stream->cursor, (FT_Byte*)stream->limit ); FT_FRAME_EXIT(); if ( error ) goto Exit; /* ensure that `num_blue_values' is even */ priv->num_blue_values &= ~1; } /* read the local subrs, if any */ if ( priv->local_subrs_offset ) { if ( FT_STREAM_SEEK( base_offset + top->private_offset + priv->local_subrs_offset ) ) goto Exit; error = cff_index_init( &font->local_subrs_index, stream, 1 ); 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 ); if ( error ) goto Exit; } Exit: return error; }
static FT_Error cff_charset_load( CFF_Charset charset, FT_UInt num_glyphs, FT_Stream stream, FT_ULong base_offset, FT_ULong offset, FT_Bool invert ) { FT_Memory memory = stream->memory; FT_Error error = CFF_Err_Ok; FT_UShort glyph_sid; /* If the the offset is greater than 2, we have to parse the */ /* charset table. */ if ( offset > 2 ) { FT_UInt j; charset->offset = base_offset + offset; /* Get the format of the table. */ if ( FT_STREAM_SEEK( charset->offset ) || FT_READ_BYTE( charset->format ) ) goto Exit; /* Allocate memory for sids. */ if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) ) goto Exit; /* assign the .notdef glyph */ charset->sids[0] = 0; switch ( charset->format ) { case 0: if ( num_glyphs > 0 ) { if ( FT_FRAME_ENTER( ( num_glyphs - 1 ) * 2 ) ) goto Exit; for ( j = 1; j < num_glyphs; j++ ) charset->sids[j] = FT_GET_USHORT(); FT_FRAME_EXIT(); } break; case 1: case 2: { FT_UInt nleft; FT_UInt i; j = 1; while ( j < num_glyphs ) { /* Read the first glyph sid of the range. */ if ( FT_READ_USHORT( glyph_sid ) ) goto Exit; /* Read the number of glyphs in the range. */ if ( charset->format == 2 ) { if ( FT_READ_USHORT( nleft ) ) goto Exit; } else { if ( FT_READ_BYTE( nleft ) ) goto Exit; } /* Fill in the range of sids -- `nleft + 1' glyphs. */ for ( i = 0; j < num_glyphs && i <= nleft; i++, j++, glyph_sid++ ) charset->sids[j] = glyph_sid; } } break; default: FT_ERROR(( "cff_charset_load: invalid table format!\n" )); error = CFF_Err_Invalid_File_Format; goto Exit; } } else { /* Parse default tables corresponding to offset == 0, 1, or 2. */ /* CFF specification intimates the following: */ /* */ /* In order to use a predefined charset, the following must be */ /* true: The charset constructed for the glyphs in the font's */ /* charstrings dictionary must match the predefined charset in */ /* the first num_glyphs. */ charset->offset = offset; /* record charset type */ switch ( (FT_UInt)offset ) { case 0: if ( num_glyphs > 229 ) { FT_ERROR(( "cff_charset_load: implicit charset larger than\n" "predefined charset (Adobe ISO-Latin)!\n" )); error = CFF_Err_Invalid_File_Format; goto Exit; } /* Allocate memory for sids. */ if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) ) goto Exit; /* Copy the predefined charset into the allocated memory. */ FT_ARRAY_COPY( charset->sids, cff_isoadobe_charset, num_glyphs ); break; case 1: if ( num_glyphs > 166 ) { FT_ERROR(( "cff_charset_load: implicit charset larger than\n" "predefined charset (Adobe Expert)!\n" )); error = CFF_Err_Invalid_File_Format; goto Exit; } /* Allocate memory for sids. */ if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) ) goto Exit; /* Copy the predefined charset into the allocated memory. */ FT_ARRAY_COPY( charset->sids, cff_expert_charset, num_glyphs ); break; case 2: if ( num_glyphs > 87 ) { FT_ERROR(( "cff_charset_load: implicit charset larger than\n" "predefined charset (Adobe Expert Subset)!\n" )); error = CFF_Err_Invalid_File_Format; goto Exit; } /* Allocate memory for sids. */ if ( FT_NEW_ARRAY( charset->sids, num_glyphs ) ) goto Exit; /* Copy the predefined charset into the allocated memory. */ FT_ARRAY_COPY( charset->sids, cff_expertsubset_charset, num_glyphs ); break; default: error = CFF_Err_Invalid_File_Format; goto Exit; } } /* we have to invert the `sids' array for subsetted CID-keyed fonts */ if ( invert ) error = cff_charset_compute_cids( charset, num_glyphs, memory ); Exit: /* Clean up if there was an error. */ if ( error ) { FT_FREE( charset->sids ); FT_FREE( charset->cids ); charset->format = 0; charset->offset = 0; charset->sids = 0; } return error; }
static FT_Error pfr_sort_kerning_pairs( FT_Stream stream, PFR_PhyFont phy_font ) { FT_Error error; FT_Memory memory = stream->memory; PFR_KernPair pairs; PFR_KernItem item; PFR_Char chars = phy_font->chars; FT_UInt num_chars = phy_font->num_chars; FT_UInt count; /* create kerning pairs array */ if ( FT_NEW_ARRAY( phy_font->kern_pairs, phy_font->num_kern_pairs ) ) goto Exit; /* load all kerning items into the array, * converting character codes into glyph indices */ pairs = phy_font->kern_pairs; item = phy_font->kern_items; count = 0; for ( ; item; item = item->next ) { FT_UInt limit = count + item->pair_count; FT_Byte* p; if ( limit > phy_font->num_kern_pairs ) { error = PFR_Err_Invalid_Table; goto Exit; } if ( FT_STREAM_SEEK( item->offset ) || FT_FRAME_ENTER( item->pair_count * item->pair_size ) ) goto Exit; p = stream->cursor; for ( ; count < limit; count++ ) { PFR_KernPair pair = pairs + count; FT_UInt char1, char2; FT_Int kerning; if ( item->flags & PFR_KERN_2BYTE_CHAR ) { char1 = FT_NEXT_USHORT( p ); char2 = FT_NEXT_USHORT( p ); } else { char1 = FT_NEXT_BYTE( p ); char2 = FT_NEXT_BYTE( p ); } if ( item->flags & PFR_KERN_2BYTE_ADJ ) kerning = item->base_adj + FT_NEXT_SHORT( p ); else kerning = item->base_adj + FT_NEXT_CHAR( p ); pair->glyph1 = pfr_get_gindex( chars, num_chars, char1 ); pair->glyph2 = pfr_get_gindex( chars, num_chars, char2 ); pair->kerning = kerning; } FT_FRAME_EXIT(); } /* sort the resulting array */ ft_qsort( pairs, count, sizeof ( PFR_KernPairRec ), pfr_compare_kern_pairs ); Exit: if ( error ) { /* disable kerning data in case of error */ phy_font->num_kern_pairs = 0; } return error; }
static FT_Error cff_new_index( CFF_Index idx, FT_Stream stream, FT_Bool load ) { FT_Error error; FT_Memory memory = stream->memory; FT_UShort count; FT_MEM_ZERO( idx, sizeof ( *idx ) ); idx->stream = stream; if ( !FT_READ_USHORT( count ) && count > 0 ) { FT_Byte* p; FT_Byte offsize; FT_ULong data_size; FT_ULong* poff; /* there is at least one element; read the offset size, */ /* then access the offset table to compute the index's total size */ if ( FT_READ_BYTE( offsize ) ) goto Exit; idx->stream = stream; idx->count = count; idx->off_size = offsize; data_size = (FT_ULong)( count + 1 ) * offsize; if ( FT_NEW_ARRAY( idx->offsets, count + 1 ) || FT_FRAME_ENTER( data_size ) ) goto Exit; poff = idx->offsets; p = (FT_Byte*)stream->cursor; for ( ; (FT_Short)count >= 0; count-- ) { poff[0] = cff_get_offset( p, offsize ); poff++; p += offsize; } FT_FRAME_EXIT(); idx->data_offset = FT_STREAM_POS(); data_size = poff[-1] - 1; if ( load ) { /* load the data */ if ( FT_FRAME_EXTRACT( data_size, idx->bytes ) ) goto Exit; } else { /* skip the data */ if ( FT_STREAM_SKIP( data_size ) ) goto Exit; } } Exit: if ( error ) FT_FREE( idx->offsets ); return error; }
cid_load_glyph( T1_Decoder decoder, FT_UInt glyph_index ) { CID_Face face = (CID_Face)decoder->builder.face; CID_FaceInfo cid = &face->cid; FT_Byte* p; FT_UInt fd_select; FT_Stream stream = face->cid_stream; FT_Error error = CID_Err_Ok; FT_Byte* charstring = 0; FT_Memory memory = face->root.memory; FT_ULong glyph_length = 0; PSAux_Service psaux = (PSAux_Service)face->psaux; #ifdef FT_CONFIG_OPTION_INCREMENTAL FT_Incremental_InterfaceRec *inc = face->root.internal->incremental_interface; #endif FT_TRACE4(( "cid_load_glyph: glyph index %d\n", glyph_index )); #ifdef FT_CONFIG_OPTION_INCREMENTAL /* For incremental fonts get the character data using */ /* the callback function. */ if ( inc ) { FT_Data glyph_data; error = inc->funcs->get_glyph_data( inc->object, glyph_index, &glyph_data ); if ( error ) goto Exit; p = (FT_Byte*)glyph_data.pointer; fd_select = (FT_UInt)cid_get_offset( &p, (FT_Byte)cid->fd_bytes ); if ( glyph_data.length != 0 ) { glyph_length = glyph_data.length - cid->fd_bytes; (void)FT_ALLOC( charstring, glyph_length ); if ( !error ) ft_memcpy( charstring, glyph_data.pointer + cid->fd_bytes, glyph_length ); } inc->funcs->free_glyph_data( inc->object, &glyph_data ); if ( error ) goto Exit; } else #endif /* FT_CONFIG_OPTION_INCREMENTAL */ /* For ordinary fonts read the CID font dictionary index */ /* and charstring offset from the CIDMap. */ { FT_UInt entry_len = cid->fd_bytes + cid->gd_bytes; FT_ULong off1; if ( FT_STREAM_SEEK( cid->data_offset + cid->cidmap_offset + glyph_index * entry_len ) || FT_FRAME_ENTER( 2 * entry_len ) ) goto Exit; p = (FT_Byte*)stream->cursor; fd_select = (FT_UInt) cid_get_offset( &p, (FT_Byte)cid->fd_bytes ); off1 = (FT_ULong)cid_get_offset( &p, (FT_Byte)cid->gd_bytes ); p += cid->fd_bytes; glyph_length = cid_get_offset( &p, (FT_Byte)cid->gd_bytes ) - off1; FT_FRAME_EXIT(); if ( fd_select >= (FT_UInt)cid->num_dicts ) { error = CID_Err_Invalid_Offset; goto Exit; } if ( glyph_length == 0 ) goto Exit; if ( FT_ALLOC( charstring, glyph_length ) ) goto Exit; if ( FT_STREAM_READ_AT( cid->data_offset + off1, charstring, glyph_length ) ) goto Exit; } /* Now set up the subrs array and parse the charstrings. */ { CID_FaceDict dict; CID_Subrs cid_subrs = face->subrs + fd_select; FT_Int cs_offset; /* Set up subrs */ decoder->num_subrs = cid_subrs->num_subrs; decoder->subrs = cid_subrs->code; decoder->subrs_len = 0; /* Set up font matrix */ dict = cid->font_dicts + fd_select; decoder->font_matrix = dict->font_matrix; decoder->font_offset = dict->font_offset; decoder->lenIV = dict->private_dict.lenIV; /* Decode the charstring. */ /* Adjustment for seed bytes. */ cs_offset = ( decoder->lenIV >= 0 ? decoder->lenIV : 0 ); /* Decrypt only if lenIV >= 0. */ if ( decoder->lenIV >= 0 ) psaux->t1_decrypt( charstring, glyph_length, 4330 ); error = decoder->funcs.parse_charstrings( decoder, charstring + cs_offset, (FT_Int)glyph_length - cs_offset ); } FT_FREE( charstring ); #ifdef FT_CONFIG_OPTION_INCREMENTAL /* Incremental fonts can optionally override the metrics. */ if ( !error && inc && inc->funcs->get_glyph_metrics ) { FT_Incremental_MetricsRec metrics; metrics.bearing_x = FIXED_TO_INT( decoder->builder.left_bearing.x ); metrics.bearing_y = 0; metrics.advance = FIXED_TO_INT( decoder->builder.advance.x ); metrics.advance_v = FIXED_TO_INT( decoder->builder.advance.y ); error = inc->funcs->get_glyph_metrics( inc->object, glyph_index, FALSE, &metrics ); decoder->builder.left_bearing.x = INT_TO_FIXED( metrics.bearing_x ); decoder->builder.advance.x = INT_TO_FIXED( metrics.advance ); decoder->builder.advance.y = INT_TO_FIXED( metrics.advance_v ); } #endif /* FT_CONFIG_OPTION_INCREMENTAL */ Exit: return error; }
CID_New_Parser( CID_Parser* parser, FT_Stream stream, FT_Memory memory, PSAux_Service psaux ) { FT_Error error; FT_ULong base_offset, offset, ps_len; FT_Byte buffer[256 + 10]; FT_Int buff_len; FT_MEM_SET( parser, 0, sizeof ( *parser ) ); psaux->ps_parser_funcs->init( &parser->root, 0, 0, memory ); parser->stream = stream; base_offset = FT_STREAM_POS(); /* first of all, check the font format in the header */ if ( FT_FRAME_ENTER( 31 ) ) goto Exit; if ( ft_strncmp( (char *)stream->cursor, "%!PS-Adobe-3.0 Resource-CIDFont", 31 ) ) { FT_TRACE2(( "[not a valid CID-keyed font]\n" )); error = CID_Err_Unknown_File_Format; } FT_FRAME_EXIT(); if ( error ) goto Exit; /* now, read the rest of the file, until we find a `StartData' */ buff_len = 256; for (;;) { FT_Byte *p, *limit = buffer + 256; FT_ULong top_position; /* fill input buffer */ buff_len -= 256; if ( buff_len > 0 ) FT_MEM_MOVE( buffer, limit, buff_len ); p = buffer + buff_len; if ( FT_STREAM_READ( p, 256 + 10 - buff_len ) ) goto Exit; top_position = FT_STREAM_POS() - buff_len; buff_len = 256 + 10; /* look for `StartData' */ for ( p = buffer; p < limit; p++ ) { if ( p[0] == 'S' && ft_strncmp( (char*)p, "StartData", 9 ) == 0 ) { /* save offset of binary data after `StartData' */ offset = (FT_ULong)( top_position - ( limit - p ) + 10 ); goto Found; } } } Found: /* we have found the start of the binary data. We will now */ /* rewind and extract the frame of corresponding to the Postscript */ /* section */ ps_len = offset - base_offset; if ( FT_STREAM_SEEK( base_offset ) || FT_FRAME_EXTRACT( ps_len, parser->postscript ) ) goto Exit; parser->data_offset = offset; parser->postscript_len = ps_len; parser->root.base = parser->postscript; parser->root.cursor = parser->postscript; parser->root.limit = parser->root.cursor + ps_len; parser->num_dict = -1; Exit: return error; }
/* synthesized into a TTC with one offset table. */ static FT_Error sfnt_open_font(FT_Stream stream, TT_Face face) { FT_Memory memory = stream->memory; FT_Error error; FT_ULong tag, offset; static const FT_Frame_Field ttc_header_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE TTC_HeaderRec FT_FRAME_START(8), FT_FRAME_LONG(version), FT_FRAME_LONG(count), FT_FRAME_END }; face->ttc_header.tag = 0; face->ttc_header.version = 0; face->ttc_header.count = 0; offset = FT_STREAM_POS(); if (FT_READ_ULONG(tag)) return error; if (tag != 0x00010000UL && tag != TTAG_ttcf && tag != TTAG_OTTO && tag != TTAG_true && tag != TTAG_typ1 && tag != 0x00020000UL) return SFNT_Err_Unknown_File_Format; face->ttc_header.tag = TTAG_ttcf; if (tag == TTAG_ttcf) { FT_Int n; FT_TRACE3(("sfnt_open_font: file is a collection\n")); if (FT_STREAM_READ_FIELDS(ttc_header_fields, &face->ttc_header)) return error; /* now read the offsets of each font in the file */ if (FT_NEW_ARRAY(face->ttc_header.offsets, face->ttc_header.count)) return error; if (FT_FRAME_ENTER(face->ttc_header.count * 4L)) return error; for (n = 0; n < face->ttc_header.count; n++) face->ttc_header.offsets[n] = FT_GET_ULONG(); FT_FRAME_EXIT(); } else { FT_TRACE3(("sfnt_open_font: synthesize TTC\n")); face->ttc_header.version = 1 << 16; face->ttc_header.count = 1; if (FT_NEW(face->ttc_header.offsets)) return error; face->ttc_header.offsets[0] = offset; } return error; }
pfr_log_font_load( PFR_LogFont log_font, FT_Stream stream, FT_UInt idx, FT_UInt32 section_offset, FT_Bool size_increment ) { FT_UInt num_log_fonts; FT_UInt flags; FT_UInt32 offset; FT_UInt32 size; FT_Error error; if ( FT_STREAM_SEEK( section_offset ) || FT_READ_USHORT( num_log_fonts ) ) goto Exit; if ( idx >= num_log_fonts ) return FT_THROW( Invalid_Argument ); if ( FT_STREAM_SKIP( idx * 5 ) || FT_READ_USHORT( size ) || FT_READ_UOFF3 ( offset ) ) goto Exit; /* save logical font size and offset */ log_font->size = size; log_font->offset = offset; /* now, check the rest of the table before loading it */ { FT_Byte* p; FT_Byte* limit; FT_UInt local; if ( FT_STREAM_SEEK( offset ) || FT_FRAME_ENTER( size ) ) goto Exit; p = stream->cursor; limit = p + size; PFR_CHECK( 13 ); log_font->matrix[0] = PFR_NEXT_LONG( p ); log_font->matrix[1] = PFR_NEXT_LONG( p ); log_font->matrix[2] = PFR_NEXT_LONG( p ); log_font->matrix[3] = PFR_NEXT_LONG( p ); flags = PFR_NEXT_BYTE( p ); local = 0; if ( flags & PFR_LOG_STROKE ) { local++; if ( flags & PFR_LOG_2BYTE_STROKE ) local++; if ( ( flags & PFR_LINE_JOIN_MASK ) == PFR_LINE_JOIN_MITER ) local += 3; } if ( flags & PFR_LOG_BOLD ) { local++; if ( flags & PFR_LOG_2BYTE_BOLD ) local++; } PFR_CHECK( local ); if ( flags & PFR_LOG_STROKE ) { log_font->stroke_thickness = ( flags & PFR_LOG_2BYTE_STROKE ) ? PFR_NEXT_SHORT( p ) : PFR_NEXT_BYTE( p ); if ( ( flags & PFR_LINE_JOIN_MASK ) == PFR_LINE_JOIN_MITER ) log_font->miter_limit = PFR_NEXT_LONG( p ); } if ( flags & PFR_LOG_BOLD ) { log_font->bold_thickness = ( flags & PFR_LOG_2BYTE_BOLD ) ? PFR_NEXT_SHORT( p ) : PFR_NEXT_BYTE( p ); } if ( flags & PFR_LOG_EXTRA_ITEMS ) { error = pfr_extra_items_skip( &p, limit ); if ( error ) goto Fail; } PFR_CHECK( 5 ); log_font->phys_size = PFR_NEXT_USHORT( p ); log_font->phys_offset = PFR_NEXT_ULONG( p ); if ( size_increment ) { PFR_CHECK( 1 ); log_font->phys_size += (FT_UInt32)PFR_NEXT_BYTE( p ) << 16; } } Fail: FT_FRAME_EXIT(); Exit: return error; Too_Short: FT_ERROR(( "pfr_log_font_load: invalid logical font table\n" )); error = FT_THROW( Invalid_Table ); goto Fail; }
tt_face_load_hmtx( TT_Face face, FT_Stream stream, FT_Bool vertical ) { FT_Error error; FT_Memory memory = stream->memory; FT_ULong table_len; FT_Long num_shorts, num_longs, num_shorts_checked; TT_LongMetrics* longs; TT_ShortMetrics** shorts; FT_Byte* p; if ( vertical ) { void* lm = &face->vertical.long_metrics; void** sm = &face->vertical.short_metrics; error = face->goto_table( face, TTAG_vmtx, stream, &table_len ); if ( error ) goto Fail; num_longs = face->vertical.number_Of_VMetrics; if ( (FT_ULong)num_longs > table_len / 4 ) num_longs = (FT_Long)( table_len / 4 ); face->vertical.number_Of_VMetrics = 0; longs = (TT_LongMetrics*)lm; shorts = (TT_ShortMetrics**)sm; } else { void* lm = &face->horizontal.long_metrics; void** sm = &face->horizontal.short_metrics; error = face->goto_table( face, TTAG_hmtx, stream, &table_len ); if ( error ) goto Fail; num_longs = face->horizontal.number_Of_HMetrics; if ( (FT_ULong)num_longs > table_len / 4 ) num_longs = (FT_Long)( table_len / 4 ); face->horizontal.number_Of_HMetrics = 0; longs = (TT_LongMetrics*)lm; shorts = (TT_ShortMetrics**)sm; } /* never trust derived values */ num_shorts = face->max_profile.numGlyphs - num_longs; num_shorts_checked = ( table_len - num_longs * 4L ) / 2; if ( num_shorts < 0 ) { FT_ERROR(( "%cmtx has more metrics than glyphs.\n" )); /* Adobe simply ignores this problem. So we shall do the same. */ #if 0 error = vertical ? SFNT_Err_Invalid_Vert_Metrics : SFNT_Err_Invalid_Horiz_Metrics; goto Exit; #else num_shorts = 0; #endif } if ( FT_QNEW_ARRAY( *longs, num_longs ) || FT_QNEW_ARRAY( *shorts, num_shorts ) ) goto Fail; if ( FT_FRAME_ENTER( table_len ) ) goto Fail; p = stream->cursor; { TT_LongMetrics cur = *longs; TT_LongMetrics limit = cur + num_longs; for ( ; cur < limit; cur++ ) { cur->advance = FT_NEXT_USHORT( p ); cur->bearing = FT_NEXT_SHORT( p ); } } /* do we have an inconsistent number of metric values? */ { TT_ShortMetrics* cur = *shorts; TT_ShortMetrics* limit = cur + FT_MIN( num_shorts, num_shorts_checked ); for ( ; cur < limit; cur++ ) *cur = FT_NEXT_SHORT( p ); /* We fill up the missing left side bearings with the */ /* last valid value. Since this will occur for buggy CJK */ /* fonts usually only, nothing serious will happen. */ if ( num_shorts > num_shorts_checked && num_shorts_checked > 0 ) { FT_Short val = (*shorts)[num_shorts_checked - 1]; limit = *shorts + num_shorts; for ( ; cur < limit; cur++ ) *cur = val; } } FT_FRAME_EXIT(); if ( vertical ) face->vertical.number_Of_VMetrics = (FT_UShort)num_longs; else face->horizontal.number_Of_HMetrics = (FT_UShort)num_longs; Fail: return error; }
t42_parser_init( T42_Parser parser, FT_Stream stream, FT_Memory memory, PSAux_Service psaux ) { FT_Error error = FT_Err_Ok; FT_Long size; psaux->ps_parser_funcs->init( &parser->root, 0, 0, memory ); parser->stream = stream; parser->base_len = 0; parser->base_dict = 0; parser->in_memory = 0; /*******************************************************************/ /* */ /* Here a short summary of what is going on: */ /* */ /* When creating a new Type 42 parser, we try to locate and load */ /* the base dictionary, loading the whole font into memory. */ /* */ /* When `loading' the base dictionary, we only set up pointers */ /* in the case of a memory-based stream. Otherwise, we allocate */ /* and load the base dictionary in it. */ /* */ /* parser->in_memory is set if we have a memory stream. */ /* */ if ( FT_STREAM_SEEK( 0L ) || FT_FRAME_ENTER( 17 ) ) goto Exit; if ( ft_memcmp( stream->cursor, "%!PS-TrueTypeFont", 17 ) != 0 ) { FT_TRACE2(( " not a Type42 font\n" )); error = FT_THROW( Unknown_File_Format ); } FT_FRAME_EXIT(); if ( error || FT_STREAM_SEEK( 0 ) ) goto Exit; size = stream->size; /* now, try to load `size' bytes of the `base' dictionary we */ /* found previously */ /* if it is a memory-based resource, set up pointers */ if ( !stream->read ) { parser->base_dict = (FT_Byte*)stream->base + stream->pos; parser->base_len = size; parser->in_memory = 1; /* check that the `size' field is valid */ if ( FT_STREAM_SKIP( size ) ) goto Exit; } else { /* read segment in memory */ if ( FT_ALLOC( parser->base_dict, size ) || FT_STREAM_READ( parser->base_dict, size ) ) goto Exit; parser->base_len = size; } parser->root.base = parser->base_dict; parser->root.cursor = parser->base_dict; parser->root.limit = parser->root.cursor + parser->base_len; Exit: if ( error && !parser->in_memory ) FT_FREE( parser->base_dict ); return error; }
/* synthesized into a TTC with one offset table. */ static FT_Error sfnt_open_font( FT_Stream stream, TT_Face face ) { FT_Memory memory = stream->memory; FT_Error error; FT_ULong tag, offset; static const FT_Frame_Field ttc_header_fields[] = { #undef FT_STRUCTURE #define FT_STRUCTURE TTC_HeaderRec FT_FRAME_START( 8 ), FT_FRAME_LONG( version ), FT_FRAME_LONG( count ), /* this is ULong in the specs */ FT_FRAME_END }; face->ttc_header.tag = 0; face->ttc_header.version = 0; face->ttc_header.count = 0; offset = FT_STREAM_POS(); if ( FT_READ_ULONG( tag ) ) return error; if ( tag != 0x00010000UL && tag != TTAG_ttcf && tag != TTAG_OTTO && tag != TTAG_true && tag != TTAG_typ1 && tag != 0x00020000UL ) { FT_TRACE2(( " not a font using the SFNT container format\n" )); return FT_THROW( Unknown_File_Format ); } face->ttc_header.tag = TTAG_ttcf; if ( tag == TTAG_ttcf ) { FT_Int n; FT_TRACE3(( "sfnt_open_font: file is a collection\n" )); if ( FT_STREAM_READ_FIELDS( ttc_header_fields, &face->ttc_header ) ) return error; if ( face->ttc_header.count == 0 ) return FT_THROW( Invalid_Table ); /* a rough size estimate: let's conservatively assume that there */ /* is just a single table info in each subfont header (12 + 16*1 = */ /* 28 bytes), thus we have (at least) `12 + 4*count' bytes for the */ /* size of the TTC header plus `28*count' bytes for all subfont */ /* headers */ if ( (FT_ULong)face->ttc_header.count > stream->size / ( 28 + 4 ) ) return FT_THROW( Array_Too_Large ); /* now read the offsets of each font in the file */ if ( FT_NEW_ARRAY( face->ttc_header.offsets, face->ttc_header.count ) ) return error; if ( FT_FRAME_ENTER( face->ttc_header.count * 4L ) ) return error; for ( n = 0; n < face->ttc_header.count; n++ ) face->ttc_header.offsets[n] = FT_GET_ULONG(); FT_FRAME_EXIT(); } else { FT_TRACE3(( "sfnt_open_font: synthesize TTC\n" )); face->ttc_header.version = 1 << 16; face->ttc_header.count = 1; if ( FT_NEW( face->ttc_header.offsets ) ) return error; face->ttc_header.offsets[0] = offset; } return error; }
static FT_Error cff_encoding_load( CFF_Encoding encoding, CFF_Charset charset, FT_UInt num_glyphs, FT_Stream stream, FT_ULong base_offset, FT_ULong offset ) { FT_Error error = CFF_Err_Ok; FT_UInt count; FT_UInt j; FT_UShort glyph_sid; FT_UInt glyph_code; /* Check for charset->sids. If we do not have this, we fail. */ if ( !charset->sids ) { error = CFF_Err_Invalid_File_Format; goto Exit; } /* Zero out the code to gid/sid mappings. */ for ( j = 0; j < 256; j++ ) { encoding->sids [j] = 0; encoding->codes[j] = 0; } /* Note: The encoding table in a CFF font is indexed by glyph index; */ /* the first encoded glyph index is 1. Hence, we read the character */ /* code (`glyph_code') at index j and make the assignment: */ /* */ /* encoding->codes[glyph_code] = j + 1 */ /* */ /* We also make the assignment: */ /* */ /* encoding->sids[glyph_code] = charset->sids[j + 1] */ /* */ /* This gives us both a code to GID and a code to SID mapping. */ if ( offset > 1 ) { encoding->offset = base_offset + offset; /* we need to parse the table to determine its size */ if ( FT_STREAM_SEEK( encoding->offset ) || FT_READ_BYTE( encoding->format ) || FT_READ_BYTE( count ) ) goto Exit; switch ( encoding->format & 0x7F ) { case 0: { FT_Byte* p; /* By convention, GID 0 is always ".notdef" and is never */ /* coded in the font. Hence, the number of codes found */ /* in the table is `count+1'. */ /* */ encoding->count = count + 1; if ( FT_FRAME_ENTER( count ) ) goto Exit; p = (FT_Byte*)stream->cursor; for ( j = 1; j <= count; j++ ) { glyph_code = *p++; /* Make sure j is not too big. */ if ( j < num_glyphs ) { /* Assign code to GID mapping. */ encoding->codes[glyph_code] = (FT_UShort)j; /* Assign code to SID mapping. */ encoding->sids[glyph_code] = charset->sids[j]; } } FT_FRAME_EXIT(); } break; case 1: { FT_UInt nleft; FT_UInt i = 1; FT_UInt k; encoding->count = 0; /* Parse the Format1 ranges. */ for ( j = 0; j < count; j++, i += nleft ) { /* Read the first glyph code of the range. */ if ( FT_READ_BYTE( glyph_code ) ) goto Exit; /* Read the number of codes in the range. */ if ( FT_READ_BYTE( nleft ) ) goto Exit; /* Increment nleft, so we read `nleft + 1' codes/sids. */ nleft++; /* compute max number of character codes */ if ( (FT_UInt)nleft > encoding->count ) encoding->count = nleft; /* Fill in the range of codes/sids. */ for ( k = i; k < nleft + i; k++, glyph_code++ ) { /* Make sure k is not too big. */ if ( k < num_glyphs && glyph_code < 256 ) { /* Assign code to GID mapping. */ encoding->codes[glyph_code] = (FT_UShort)k; /* Assign code to SID mapping. */ encoding->sids[glyph_code] = charset->sids[k]; } } } /* simple check; one never knows what can be found in a font */ if ( encoding->count > 256 ) encoding->count = 256; } break; default: FT_ERROR(( "cff_encoding_load: invalid table format!\n" )); error = CFF_Err_Invalid_File_Format; goto Exit; } /* Parse supplemental encodings, if any. */ if ( encoding->format & 0x80 ) { FT_UInt gindex; /* count supplements */ if ( FT_READ_BYTE( count ) ) goto Exit; for ( j = 0; j < count; j++ ) { /* Read supplemental glyph code. */ if ( FT_READ_BYTE( glyph_code ) ) goto Exit; /* Read the SID associated with this glyph code. */ if ( FT_READ_USHORT( glyph_sid ) ) goto Exit; /* Assign code to SID mapping. */ encoding->sids[glyph_code] = glyph_sid; /* First, look up GID which has been assigned to */ /* SID glyph_sid. */ for ( gindex = 0; gindex < num_glyphs; gindex++ ) { if ( charset->sids[gindex] == glyph_sid ) { encoding->codes[glyph_code] = (FT_UShort)gindex; break; } } } } } else { /* We take into account the fact a CFF font can use a predefined */ /* encoding without containing all of the glyphs encoded by this */ /* encoding (see the note at the end of section 12 in the CFF */ /* specification). */ switch ( (FT_UInt)offset ) { case 0: /* First, copy the code to SID mapping. */ FT_ARRAY_COPY( encoding->sids, cff_standard_encoding, 256 ); goto Populate; case 1: /* First, copy the code to SID mapping. */ FT_ARRAY_COPY( encoding->sids, cff_expert_encoding, 256 ); Populate: /* Construct code to GID mapping from code to SID mapping */ /* and charset. */ encoding->count = 0; error = cff_charset_compute_cids( charset, num_glyphs, stream->memory ); if ( error ) goto Exit; for ( j = 0; j < 256; j++ ) { FT_UInt sid = encoding->sids[j]; FT_UInt gid = 0; if ( sid ) gid = cff_charset_cid_to_gindex( charset, sid ); if ( gid != 0 ) { encoding->codes[j] = (FT_UShort)gid; if ( encoding->count < j + 1 ) encoding->count = j + 1; } else { encoding->codes[j] = 0; encoding->sids [j] = 0; } } break; default: FT_ERROR(( "cff_encoding_load: invalid table format!\n" )); error = CFF_Err_Invalid_File_Format; goto Exit; } } Exit: /* Clean up if there was an error. */ return error; }
pfr_face_get_kerning( PFR_Face face, FT_UInt glyph1, FT_UInt glyph2, FT_Vector* kerning ) { FT_Error error; PFR_PhyFont phy_font = &face->phy_font; PFR_KernItem item = phy_font->kern_items; FT_UInt32 idx = PFR_KERN_INDEX( glyph1, glyph2 ); kerning->x = 0; kerning->y = 0; /* find the kerning item containing our pair */ while ( item ) { if ( item->pair1 <= idx && idx <= item->pair2 ) goto Found_Item; item = item->next; } /* not found */ goto Exit; Found_Item: { /* perform simply binary search within the item */ FT_UInt min, mid, max; FT_Stream stream = face->root.stream; FT_Byte* p; if ( FT_STREAM_SEEK( item->offset ) || FT_FRAME_ENTER( item->pair_count * item->pair_size ) ) goto Exit; min = 0; max = item->pair_count; while ( min < max ) { FT_UInt char1, char2, charcode; mid = ( min + max ) >> 1; p = stream->cursor + mid*item->pair_size; if ( item->flags & PFR_KERN_2BYTE_CHAR ) { char1 = FT_NEXT_USHORT( p ); char2 = FT_NEXT_USHORT( p ); } else { char1 = FT_NEXT_USHORT( p ); char2 = FT_NEXT_USHORT( p ); } charcode = PFR_KERN_INDEX( char1, char2 ); if ( idx == charcode ) { if ( item->flags & PFR_KERN_2BYTE_ADJ ) kerning->x = item->base_adj + FT_NEXT_SHORT( p ); else kerning->x = item->base_adj + FT_NEXT_CHAR( p ); break; } if ( idx > charcode ) min = mid + 1; else max = mid; } FT_FRAME_EXIT(); } Exit: return 0; }
pfr_phy_font_load( PFR_PhyFont phy_font, FT_Stream stream, FT_UInt32 offset, FT_UInt32 size ) { FT_Error error; FT_Memory memory = stream->memory; FT_UInt flags; FT_ULong num_aux; FT_Byte* p; FT_Byte* limit; phy_font->memory = memory; phy_font->offset = offset; phy_font->kern_items = NULL; phy_font->kern_items_tail = &phy_font->kern_items; if ( FT_STREAM_SEEK( offset ) || FT_FRAME_ENTER( size ) ) goto Exit; phy_font->cursor = stream->cursor; p = stream->cursor; limit = p + size; PFR_CHECK( 15 ); phy_font->font_ref_number = PFR_NEXT_USHORT( p ); phy_font->outline_resolution = PFR_NEXT_USHORT( p ); phy_font->metrics_resolution = PFR_NEXT_USHORT( p ); phy_font->bbox.xMin = PFR_NEXT_SHORT( p ); phy_font->bbox.yMin = PFR_NEXT_SHORT( p ); phy_font->bbox.xMax = PFR_NEXT_SHORT( p ); phy_font->bbox.yMax = PFR_NEXT_SHORT( p ); phy_font->flags = flags = PFR_NEXT_BYTE( p ); /* get the standard advance for non-proportional fonts */ if ( !(flags & PFR_PHY_PROPORTIONAL) ) { PFR_CHECK( 2 ); phy_font->standard_advance = PFR_NEXT_SHORT( p ); } /* load the extra items when present */ if ( flags & PFR_PHY_EXTRA_ITEMS ) { error = pfr_extra_items_parse( &p, limit, pfr_phy_font_extra_items, phy_font ); if ( error ) goto Fail; } /* In certain fonts, the auxiliary bytes contain interesting */ /* information. These are not in the specification but can be */ /* guessed by looking at the content of a few PFR0 fonts. */ PFR_CHECK( 3 ); num_aux = PFR_NEXT_ULONG( p ); if ( num_aux > 0 ) { FT_Byte* q = p; FT_Byte* q2; PFR_CHECK_SIZE( num_aux ); p += num_aux; while ( num_aux > 0 ) { FT_UInt length, type; if ( q + 4 > p ) break; length = PFR_NEXT_USHORT( q ); if ( length < 4 || length > num_aux ) break; q2 = q + length - 2; type = PFR_NEXT_USHORT( q ); switch ( type ) { case 1: /* this seems to correspond to the font's family name, padded to */ /* an even number of bytes with a zero byte appended if needed */ error = pfr_aux_name_load( q, length - 4U, memory, &phy_font->family_name ); if ( error ) goto Exit; break; case 2: if ( q + 32 > q2 ) break; q += 10; phy_font->ascent = PFR_NEXT_SHORT( q ); phy_font->descent = PFR_NEXT_SHORT( q ); phy_font->leading = PFR_NEXT_SHORT( q ); break; case 3: /* this seems to correspond to the font's style name, padded to */ /* an even number of bytes with a zero byte appended if needed */ error = pfr_aux_name_load( q, length - 4U, memory, &phy_font->style_name ); if ( error ) goto Exit; break; default: ; } q = q2; num_aux -= length; } } /* read the blue values */ { FT_UInt n, count; PFR_CHECK( 1 ); phy_font->num_blue_values = count = PFR_NEXT_BYTE( p ); PFR_CHECK( count * 2 ); if ( FT_NEW_ARRAY( phy_font->blue_values, count ) ) goto Fail; for ( n = 0; n < count; n++ ) phy_font->blue_values[n] = PFR_NEXT_SHORT( p ); } PFR_CHECK( 8 ); phy_font->blue_fuzz = PFR_NEXT_BYTE( p ); phy_font->blue_scale = PFR_NEXT_BYTE( p ); phy_font->vertical.standard = PFR_NEXT_USHORT( p ); phy_font->horizontal.standard = PFR_NEXT_USHORT( p ); /* read the character descriptors */ { FT_UInt n, count, Size; phy_font->num_chars = count = PFR_NEXT_USHORT( p ); phy_font->chars_offset = offset + (FT_Offset)( p - stream->cursor ); Size = 1 + 1 + 2; if ( flags & PFR_PHY_2BYTE_CHARCODE ) Size += 1; if ( flags & PFR_PHY_PROPORTIONAL ) Size += 2; if ( flags & PFR_PHY_ASCII_CODE ) Size += 1; if ( flags & PFR_PHY_2BYTE_GPS_SIZE ) Size += 1; if ( flags & PFR_PHY_3BYTE_GPS_OFFSET ) Size += 1; PFR_CHECK_SIZE( count * Size ); if ( FT_NEW_ARRAY( phy_font->chars, count ) ) goto Fail; for ( n = 0; n < count; n++ ) { PFR_Char cur = &phy_font->chars[n]; cur->char_code = ( flags & PFR_PHY_2BYTE_CHARCODE ) ? PFR_NEXT_USHORT( p ) : PFR_NEXT_BYTE( p ); cur->advance = ( flags & PFR_PHY_PROPORTIONAL ) ? PFR_NEXT_SHORT( p ) : phy_font->standard_advance; #if 0 cur->ascii = ( flags & PFR_PHY_ASCII_CODE ) ? PFR_NEXT_BYTE( p ) : 0; #else if ( flags & PFR_PHY_ASCII_CODE ) p += 1; #endif cur->gps_size = ( flags & PFR_PHY_2BYTE_GPS_SIZE ) ? PFR_NEXT_USHORT( p ) : PFR_NEXT_BYTE( p ); cur->gps_offset = ( flags & PFR_PHY_3BYTE_GPS_OFFSET ) ? PFR_NEXT_ULONG( p ) : PFR_NEXT_USHORT( p ); } } /* that's it! */ Fail: FT_FRAME_EXIT(); /* save position of bitmap info */ phy_font->bct_offset = FT_STREAM_POS(); phy_font->cursor = NULL; Exit: return error; Too_Short: error = FT_THROW( Invalid_Table ); FT_ERROR(( "pfr_phy_font_load: invalid physical font table\n" )); goto Fail; }
pfr_face_get_kerning( FT_Face pfrface, /* PFR_Face */ FT_UInt glyph1, FT_UInt glyph2, FT_Vector* kerning ) { PFR_Face face = (PFR_Face)pfrface; FT_Error error = FT_Err_Ok; PFR_PhyFont phy_font = &face->phy_font; FT_UInt32 code1, code2, pair; kerning->x = 0; kerning->y = 0; if ( glyph1 > 0 ) glyph1--; if ( glyph2 > 0 ) glyph2--; /* convert glyph indices to character codes */ if ( glyph1 > phy_font->num_chars || glyph2 > phy_font->num_chars ) goto Exit; code1 = phy_font->chars[glyph1].char_code; code2 = phy_font->chars[glyph2].char_code; pair = PFR_KERN_INDEX( code1, code2 ); /* now search the list of kerning items */ { PFR_KernItem item = phy_font->kern_items; FT_Stream stream = pfrface->stream; for ( ; item; item = item->next ) { if ( pair >= item->pair1 && pair <= item->pair2 ) goto FoundPair; } goto Exit; FoundPair: /* we found an item, now parse it and find the value if any */ if ( FT_STREAM_SEEK( item->offset ) || FT_FRAME_ENTER( item->pair_count * item->pair_size ) ) goto Exit; { FT_UInt count = item->pair_count; FT_UInt size = item->pair_size; FT_UInt power = 1 << FT_MSB( count ); FT_UInt probe = power * size; FT_UInt extra = count - power; FT_Byte* base = stream->cursor; FT_Bool twobytes = FT_BOOL( item->flags & 1 ); FT_Bool twobyte_adj = FT_BOOL( item->flags & 2 ); FT_Byte* p; FT_UInt32 cpair; if ( extra > 0 ) { p = base + extra * size; if ( twobytes ) cpair = FT_NEXT_ULONG( p ); else cpair = PFR_NEXT_KPAIR( p ); if ( cpair == pair ) goto Found; if ( cpair < pair ) { if ( twobyte_adj ) p += 2; else p++; base = p; } } while ( probe > size ) { probe >>= 1; p = base + probe; if ( twobytes ) cpair = FT_NEXT_ULONG( p ); else cpair = PFR_NEXT_KPAIR( p ); if ( cpair == pair ) goto Found; if ( cpair < pair ) base += probe; } p = base; if ( twobytes ) cpair = FT_NEXT_ULONG( p ); else cpair = PFR_NEXT_KPAIR( p ); if ( cpair == pair ) { FT_Int value; Found: if ( twobyte_adj ) value = FT_PEEK_SHORT( p ); else value = p[0]; kerning->x = item->base_adj + value; } } FT_FRAME_EXIT(); } Exit: return error; }
static const char* get_sfnt_postscript_name( TT_Face face ) { FT_Int n, found_win, found_apple; const char* result = NULL; /* shouldn't happen, but just in case to avoid memory leaks */ if ( face->root.internal->postscript_name ) return face->root.internal->postscript_name; /* scan the name table to see whether we have a Postscript name here, */ /* either in Macintosh or Windows platform encodings */ found_win = -1; found_apple = -1; for ( n = 0; n < face->num_names; n++ ) { TT_NameEntryRec* name = face->name_table.names + n; if ( name->nameID == 6 && name->stringLength > 0 ) { if ( name->platformID == 3 && name->encodingID == 1 && name->languageID == 0x409 ) found_win = n; if ( name->platformID == 1 && name->encodingID == 0 && name->languageID == 0 ) found_apple = n; } } if ( found_win != -1 ) { FT_Memory memory = face->root.memory; TT_NameEntryRec* name = face->name_table.names + found_win; FT_UInt len = name->stringLength / 2; FT_Error error; if ( !FT_ALLOC( result, name->stringLength + 1 ) ) { FT_Stream stream = face->name_table.stream; FT_String* r = (FT_String*)result; FT_Byte* p = (FT_Byte*)name->string; if ( FT_STREAM_SEEK( name->stringOffset ) || FT_FRAME_ENTER( name->stringLength ) ) { FT_FREE( result ); name->stringLength = 0; name->stringOffset = 0; FT_FREE( name->string ); goto Exit; } p = (FT_Byte*)stream->cursor; for ( ; len > 0; len--, p += 2 ) { if ( p[0] == 0 && p[1] >= 32 && p[1] < 128 ) *r++ = p[1]; } *r = '\0'; FT_FRAME_EXIT(); } goto Exit; } if ( found_apple != -1 ) { FT_Memory memory = face->root.memory; TT_NameEntryRec* name = face->name_table.names + found_apple; FT_UInt len = name->stringLength; FT_Error error; if ( !FT_ALLOC( result, len + 1 ) ) { FT_Stream stream = face->name_table.stream; if ( FT_STREAM_SEEK( name->stringOffset ) || FT_STREAM_READ( result, len ) ) { name->stringOffset = 0; name->stringLength = 0; FT_FREE( name->string ); FT_FREE( result ); goto Exit; } ((char*)result)[len] = '\0'; } } Exit: face->root.internal->postscript_name = result; return result; }
static FT_Error load_format_20( TT_Face face, FT_Stream stream, FT_ULong post_limit ) { FT_Memory memory = stream->memory; FT_Error error; FT_Int num_glyphs; FT_UShort num_names; FT_UShort* glyph_indices = NULL; FT_Char** name_strings = NULL; if ( FT_READ_USHORT( num_glyphs ) ) goto Exit; /* UNDOCUMENTED! The number of glyphs in this table can be smaller */ /* than the value in the maxp table (cf. cyberbit.ttf). */ /* There already exist fonts which have more than 32768 glyph names */ /* in this table, so the test for this threshold has been dropped. */ if ( num_glyphs > face->max_profile.numGlyphs ) { error = FT_THROW( Invalid_File_Format ); goto Exit; } /* load the indices */ { FT_Int n; if ( FT_NEW_ARRAY ( glyph_indices, num_glyphs ) || FT_FRAME_ENTER( num_glyphs * 2L ) ) goto Fail; for ( n = 0; n < num_glyphs; n++ ) glyph_indices[n] = FT_GET_USHORT(); FT_FRAME_EXIT(); } /* compute number of names stored in table */ { FT_Int n; num_names = 0; for ( n = 0; n < num_glyphs; n++ ) { FT_Int idx; idx = glyph_indices[n]; if ( idx >= 258 ) { idx -= 257; if ( idx > num_names ) num_names = (FT_UShort)idx; } } } /* now load the name strings */ { FT_UShort n; if ( FT_NEW_ARRAY( name_strings, num_names ) ) goto Fail; for ( n = 0; n < num_names; n++ ) { FT_UInt len; if ( FT_STREAM_POS() >= post_limit ) break; else { FT_TRACE6(( "load_format_20: %d byte left in post table\n", post_limit - FT_STREAM_POS() )); if ( FT_READ_BYTE( len ) ) goto Fail1; } if ( len > post_limit || FT_STREAM_POS() > post_limit - len ) { FT_Int d = (FT_Int)post_limit - (FT_Int)FT_STREAM_POS(); FT_ERROR(( "load_format_20:" " exceeding string length (%d)," " truncating at end of post table (%d byte left)\n", len, d )); len = (FT_UInt)FT_MAX( 0, d ); } if ( FT_NEW_ARRAY( name_strings[n], len + 1 ) || FT_STREAM_READ( name_strings[n], len ) ) goto Fail1; name_strings[n][len] = '\0'; } if ( n < num_names ) { FT_ERROR(( "load_format_20:" " all entries in post table are already parsed," " using NULL names for gid %d - %d\n", n, num_names - 1 )); for ( ; n < num_names; n++ ) if ( FT_NEW_ARRAY( name_strings[n], 1 ) ) goto Fail1; else name_strings[n][0] = '\0'; } } /* all right, set table fields and exit successfully */ { TT_Post_20 table = &face->postscript_names.names.format_20; table->num_glyphs = (FT_UShort)num_glyphs; table->num_names = (FT_UShort)num_names; table->glyph_indices = glyph_indices; table->glyph_names = name_strings; } return FT_Err_Ok; Fail1: { FT_UShort n; for ( n = 0; n < num_names; n++ ) FT_FREE( name_strings[n] ); } Fail: FT_FREE( name_strings ); FT_FREE( glyph_indices ); Exit: return error; }