From 2b3ccd6e266cc74740ee6157b643a0c409c5df64 Mon Sep 17 00:00:00 2001 From: suzuki toshiya Date: Tue, 24 Aug 2021 11:43:11 +0900 Subject: [PATCH] [truetype] New function to skip the randomization tag. * src/truetype/ttobjs.c (tt_skip_pdffont_random_tag): New function to skip the randomization tag in the names of the fonts embedded in a PDF. It is used by tt_check_trickyness_family(), to keep from mistaking "DLC" in the randomization tag as a tricky font name. See discussion in: https://lists.nongnu.org/archive/html/freetype-devel/2021-02/msg00002.html For technical detail about the randomization tag, please find PDF Reference 5.5.3 "Font Subsets". Thanks to Justyna Wawrzynska for pointing out the issue caused by the randomization tag. --- src/truetype/ttobjs.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/truetype/ttobjs.c b/src/truetype/ttobjs.c index 9c3d5838f..7525cb204 100644 --- a/src/truetype/ttobjs.c +++ b/src/truetype/ttobjs.c @@ -143,6 +143,30 @@ #endif /* TT_USE_BYTECODE_INTERPRETER */ + /* The fonts embedded in PDF changes their family names + * by the randomization tag. PDF Reference 5.5.3 "Font + * Subsets" defines its format as 6 uppercase letters and + * '+' sign. For safety, we do not skip the tag violating + * this rule. + */ + + static const FT_String* + tt_skip_pdffont_random_tag( const FT_String* name ) + { + unsigned int i; + + + if ( 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; + } + /* Compare the face with a list of well-known `tricky' fonts. */ /* This list shall be expanded as we find more of them. */ @@ -199,10 +223,12 @@ }; int nn; + const FT_String* name_without_tag; + name_without_tag = tt_skip_pdffont_random_tag( name ); for ( nn = 0; nn < TRICK_NAMES_COUNT; nn++ ) - if ( ft_strstr( name, trick_names[nn] ) ) + if ( ft_strstr( name_without_tag, trick_names[nn] ) ) return TRUE; return FALSE;