[cff, truetype] Improve prefix and suffix removal.
* src/cff/cffobjs.c (remove_style): Rewrite using pointers. (remove_subset_prefix): Unwrap loop and use `memmove`. * src/truetype/ttobjs.c (tt_skip_pdffont_random_tag): Unwrap loop and avoid `strlen`.
This commit is contained in:
parent
4904d1eb1b
commit
9c51e21e53
@ -421,32 +421,23 @@
|
||||
static void
|
||||
remove_subset_prefix( FT_String* name )
|
||||
{
|
||||
FT_Int32 idx = 0;
|
||||
FT_Int32 length = (FT_Int32)ft_strlen( name ) + 1;
|
||||
FT_Bool continue_search = 1;
|
||||
FT_UInt32 i = 0, idx = 0;
|
||||
|
||||
|
||||
while ( continue_search )
|
||||
/* six ASCII uppercase letters followed by a plus sign */
|
||||
while ( 'A' <= name[i] && name[i++] <= 'Z' &&
|
||||
'A' <= name[i] && name[i++] <= 'Z' &&
|
||||
'A' <= name[i] && name[i++] <= 'Z' &&
|
||||
'A' <= name[i] && name[i++] <= 'Z' &&
|
||||
'A' <= name[i] && name[i++] <= 'Z' &&
|
||||
'A' <= name[i] && name[i++] <= 'Z' &&
|
||||
name[i++] == '+' )
|
||||
{
|
||||
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];
|
||||
length -= 7;
|
||||
}
|
||||
}
|
||||
else
|
||||
continue_search = 0;
|
||||
idx = i;
|
||||
}
|
||||
|
||||
if ( idx )
|
||||
FT_MEM_MOVE( name, name + idx, ft_strlen( name + idx ) + 1 );
|
||||
}
|
||||
|
||||
|
||||
@ -456,42 +447,20 @@
|
||||
remove_style( FT_String* family_name,
|
||||
const FT_String* style_name )
|
||||
{
|
||||
FT_Int32 family_name_length, style_name_length;
|
||||
FT_String* f = family_name + ft_strlen( family_name );
|
||||
const FT_String* s = style_name + ft_strlen( style_name );
|
||||
|
||||
|
||||
family_name_length = (FT_Int32)ft_strlen( family_name );
|
||||
style_name_length = (FT_Int32)ft_strlen( style_name );
|
||||
/* compare strings moving backwards */
|
||||
while ( s > style_name )
|
||||
if ( f == family_name || *--s != *--f )
|
||||
return;
|
||||
|
||||
if ( family_name_length > style_name_length )
|
||||
{
|
||||
FT_Int idx;
|
||||
|
||||
|
||||
for ( idx = 1; idx <= style_name_length; idx++ )
|
||||
{
|
||||
if ( family_name[family_name_length - idx] !=
|
||||
style_name[style_name_length - idx] )
|
||||
break;
|
||||
}
|
||||
|
||||
if ( idx > style_name_length )
|
||||
{
|
||||
/* family_name ends with style_name; remove it */
|
||||
idx = family_name_length - style_name_length - 1;
|
||||
|
||||
/* also remove special characters */
|
||||
/* between real family name and style */
|
||||
while ( idx > 0 &&
|
||||
( family_name[idx] == '-' ||
|
||||
family_name[idx] == ' ' ||
|
||||
family_name[idx] == '_' ||
|
||||
family_name[idx] == '+' ) )
|
||||
idx--;
|
||||
|
||||
if ( idx > 0 )
|
||||
family_name[idx + 1] = '\0';
|
||||
}
|
||||
}
|
||||
/* terminate and remove special characters */
|
||||
do
|
||||
*f = '\0';
|
||||
while ( f-- > family_name &&
|
||||
( *f == '-' || *f == ' ' || *f == '_' || *f == '+' ) );
|
||||
}
|
||||
|
||||
|
||||
|
@ -152,18 +152,20 @@
|
||||
static const FT_String*
|
||||
tt_skip_pdffont_random_tag( const FT_String* name )
|
||||
{
|
||||
unsigned int i;
|
||||
if ( ft_isupper( name[0] ) &&
|
||||
ft_isupper( name[1] ) &&
|
||||
ft_isupper( name[2] ) &&
|
||||
ft_isupper( name[3] ) &&
|
||||
ft_isupper( name[4] ) &&
|
||||
ft_isupper( name[5] ) &&
|
||||
'+' == name[6] &&
|
||||
name[7] )
|
||||
{
|
||||
FT_TRACE7(( "name without randomization tag: %s\n", name + 7 ));
|
||||
return name + 7;
|
||||
}
|
||||
|
||||
|
||||
if ( ft_strlen( name ) < 8 || name[6] != '+' )
|
||||
return name;
|
||||
|
||||
for ( i = 0; i < 6; i++ )
|
||||
if ( !ft_isupper( name[i] ) )
|
||||
return name;
|
||||
|
||||
FT_TRACE7(( "name without randomization tag: %s\n", name + 7 ));
|
||||
return name + 7;
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user