tt_face_get_metrics( TT_Face face, FT_Bool vertical, FT_UInt gindex, FT_Short *abearing, FT_UShort *aadvance ) { FT_Error error; FT_Stream stream = face->root.stream; TT_HoriHeader* header; FT_ULong table_pos, table_size, table_end; FT_UShort k; #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT FT_Service_MetricsVariations var = (FT_Service_MetricsVariations)face->var; #endif if ( vertical ) { void* v = &face->vertical; header = (TT_HoriHeader*)v; table_pos = face->vert_metrics_offset; table_size = face->vert_metrics_size; } else { header = &face->horizontal; table_pos = face->horz_metrics_offset; table_size = face->horz_metrics_size; } table_end = table_pos + table_size; k = header->number_Of_HMetrics; if ( k > 0 ) { if ( gindex < (FT_UInt)k ) { table_pos += 4 * gindex; if ( table_pos + 4 > table_end ) goto NoData; if ( FT_STREAM_SEEK( table_pos ) || FT_READ_USHORT( *aadvance ) || FT_READ_SHORT( *abearing ) ) goto NoData; } else { table_pos += 4 * ( k - 1 ); if ( table_pos + 4 > table_end ) goto NoData; if ( FT_STREAM_SEEK( table_pos ) || FT_READ_USHORT( *aadvance ) ) goto NoData; table_pos += 4 + 2 * ( gindex - k ); if ( table_pos + 2 > table_end ) *abearing = 0; else { if ( !FT_STREAM_SEEK( table_pos ) ) (void)FT_READ_SHORT( *abearing ); } } } else { NoData: *abearing = 0; *aadvance = 0; } #ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT if ( var ) { FT_Face f = FT_FACE( face ); FT_Int a = (FT_Int)*aadvance; FT_Int b = (FT_Int)*abearing; if ( vertical ) { if ( var->vadvance_adjust ) var->vadvance_adjust( f, gindex, &a ); if ( var->tsb_adjust ) var->tsb_adjust( f, gindex, &b ); } else { if ( var->hadvance_adjust ) var->hadvance_adjust( f, gindex, &a ); if ( var->lsb_adjust ) var->lsb_adjust( f, gindex, &b ); } *aadvance = (FT_UShort)a; *abearing = (FT_Short)b; } #endif }
tt_face_get_metrics( TT_Face face, FT_Bool vertical, FT_UInt gindex, FT_Short *abearing, FT_UShort *aadvance ) { FT_Error error; FT_Stream stream = face->root.stream; TT_HoriHeader* header; FT_ULong table_pos, table_size, table_end; FT_UShort k; if ( vertical ) { void* v = &face->vertical; header = (TT_HoriHeader*)v; table_pos = face->vert_metrics_offset; table_size = face->vert_metrics_size; } else { header = &face->horizontal; table_pos = face->horz_metrics_offset; table_size = face->horz_metrics_size; } table_end = table_pos + table_size; k = header->number_Of_HMetrics; if ( k > 0 ) { if ( gindex < (FT_UInt)k ) { table_pos += 4 * gindex; if ( table_pos + 4 > table_end ) goto NoData; if ( FT_STREAM_SEEK( table_pos ) || FT_READ_USHORT( *aadvance ) || FT_READ_SHORT( *abearing ) ) goto NoData; } else { table_pos += 4 * ( k - 1 ); if ( table_pos + 4 > table_end ) goto NoData; if ( FT_STREAM_SEEK( table_pos ) || FT_READ_USHORT( *aadvance ) ) goto NoData; table_pos += 4 + 2 * ( gindex - k ); if ( table_pos + 2 > table_end ) *abearing = 0; else { if ( !FT_STREAM_SEEK( table_pos ) ) (void)FT_READ_SHORT( *abearing ); } } } else { NoData: *abearing = 0; *aadvance = 0; } return SFNT_Err_Ok; }
static FT_Bool _tt_face_check_patents( FT_Face face ) { FT_Stream stream = face->stream; FT_UInt gindex; FT_Error error; FT_Bool result; FT_Service_TTGlyf service; result = _tt_check_patents_in_table( face, TTAG_fpgm ); if ( result ) goto Exit; result = _tt_check_patents_in_table( face, TTAG_prep ); if ( result ) goto Exit; FT_FACE_FIND_SERVICE( face, service, TT_GLYF ); if ( service == NULL ) goto Exit; for ( gindex = 0; gindex < (FT_UInt)face->num_glyphs; gindex++ ) { FT_ULong offset, num_ins, size; FT_Int num_contours; offset = service->get_location( face, gindex, &size ); if ( size == 0 ) continue; if ( FT_STREAM_SEEK( offset ) || FT_READ_SHORT( num_contours ) ) continue; if ( num_contours >= 0 ) /* simple glyph */ { if ( FT_STREAM_SKIP( 8 + num_contours * 2 ) ) continue; } else /* compound glyph */ { FT_Bool has_instr = 0; if ( FT_STREAM_SKIP( 8 ) ) continue; /* now read each component */ for (;;) { FT_UInt flags, toskip; if( FT_READ_USHORT( flags ) ) break; toskip = 2 + 1 + 1; if ( ( flags & ( 1 << 0 ) ) != 0 ) /* ARGS_ARE_WORDS */ toskip += 2; if ( ( flags & ( 1 << 3 ) ) != 0 ) /* WE_HAVE_A_SCALE */ toskip += 2; else if ( ( flags & ( 1 << 6 ) ) != 0 ) /* WE_HAVE_X_Y_SCALE */ toskip += 4; else if ( ( flags & ( 1 << 7 ) ) != 0 ) /* WE_HAVE_A_2x2 */ toskip += 8; if ( ( flags & ( 1 << 8 ) ) != 0 ) /* WE_HAVE_INSTRUCTIONS */ has_instr = 1; if ( FT_STREAM_SKIP( toskip ) ) goto NextGlyph; if ( ( flags & ( 1 << 5 ) ) == 0 ) /* MORE_COMPONENTS */ break; } if ( !has_instr ) goto NextGlyph; } if ( FT_READ_USHORT( num_ins ) ) continue; result = _tt_check_patents_in_range( stream, num_ins ); if ( result ) goto Exit; NextGlyph: ; } Exit: return result; }