[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2] master 9c51e21e5: [cff, truetype] Improve prefix and suffix
From: |
Werner Lemberg |
Subject: |
[freetype2] master 9c51e21e5: [cff, truetype] Improve prefix and suffix removal. |
Date: |
Thu, 7 Sep 2023 23:58:53 -0400 (EDT) |
branch: master
commit 9c51e21e53e5a97e287b450b1784c3a0979603f0
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>
[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`.
---
src/cff/cffobjs.c | 79 ++++++++++++++++-----------------------------------
src/truetype/ttobjs.c | 24 +++++++++-------
2 files changed, 37 insertions(+), 66 deletions(-)
diff --git a/src/cff/cffobjs.c b/src/cff/cffobjs.c
index 6d08620c4..4b710745f 100644
--- a/src/cff/cffobjs.c
+++ b/src/cff/cffobjs.c
@@ -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 == '+' ) );
}
diff --git a/src/truetype/ttobjs.c b/src/truetype/ttobjs.c
index 5b56af711..9126f9eab 100644
--- a/src/truetype/ttobjs.c
+++ b/src/truetype/ttobjs.c
@@ -152,18 +152,20 @@
static const FT_String*
tt_skip_pdffont_random_tag( const FT_String* name )
{
- unsigned int i;
-
-
- if ( ft_strlen( name ) < 8 || name[6] != '+' )
- return name;
-
- for ( i = 0; i < 6; i++ )
- if ( !ft_isupper( name[i] ) )
- return name;
+ 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;
+ }
- FT_TRACE7(( "name without randomization tag: %s\n", name + 7 ));
- return name + 7;
+ return name;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2] master 9c51e21e5: [cff, truetype] Improve prefix and suffix removal.,
Werner Lemberg <=