[autofit] Speed up construction of reverse character map. (1/4)

Build reverse cmap for characters of the current script style only.

* src/autofit/afadjust.c (in_range): New function.
  (af_reverse_character_map_new): Pass `AF_StyleMetrics` instead of
  `AF_FaceGlobals` so that we can access the current script style.
  Use `in_range` to limit tested code points.
* src/autofit/afadjust.h: Updated.
* src/autofit/aflatin.c (af_latin_metrics_init): Updated.
This commit is contained in:
Werner Lemberg
2025-05-19 05:23:29 +02:00
parent 4514f05158
commit f68733d4a8
3 changed files with 44 additions and 15 deletions

View File

@@ -1309,26 +1309,48 @@
#endif /* FT_CONFIG_OPTION_USE_HARFBUZZ */
static FT_Bool
in_range( FT_UInt32 codepoint,
AF_Script_UniRange ranges )
{
AF_Script_UniRange range;
for ( range = ranges; range->first != 0; range++ )
if ( codepoint >= range->first && codepoint <= range->last )
return TRUE;
return FALSE;
}
FT_LOCAL_DEF( FT_Error )
af_reverse_character_map_new( FT_Hash *map,
AF_FaceGlobals globals )
af_reverse_character_map_new( FT_Hash *map,
AF_StyleMetrics metrics )
{
FT_Error error;
FT_Face face = globals->face;
FT_Memory memory = face->memory;
AF_FaceGlobals globals = metrics->globals;
FT_Face face = globals->face;
FT_Memory memory = face->memory;
AF_ScriptClass script_class =
af_script_classes[metrics->style_class->script];
AF_Script_UniRange ranges = script_class->script_uni_ranges;
FT_CharMap old_charmap;
FT_UInt32 codepoint;
FT_Offset i;
FT_TRACE4(( "af_reverse_character_map_new:"
" building reverse character map (style `%s')\n",
af_style_names[metrics->style_class->style] ));
/* Search for a unicode charmap. */
/* If there isn't one, create a blank map. */
FT_TRACE4(( "af_reverse_character_map_new:"
" building reverse character map\n" ));
/* Back up `face->charmap` because `find_unicode_charmap` sets it. */
old_charmap = face->charmap;
@@ -1346,10 +1368,14 @@
/* Insert all glyphs from the database that have entries in the cmap. */
for ( i = 0; i < AF_ADJUSTMENT_DATABASE_LENGTH; i++ )
{
FT_UInt32 codepoint = adjustment_database[i].codepoint;
FT_Int glyph = FT_Get_Char_Index( face, codepoint );
FT_Int glyph;
codepoint = adjustment_database[i].codepoint;
if ( !in_range( codepoint, ranges ) )
continue;
glyph = FT_Get_Char_Index( face, codepoint );
if ( glyph == 0 )
continue;
@@ -1372,7 +1398,6 @@
hb_set_t *result_set = hb( set_create )();
hb_set_t *gsub_lookups = hb( set_create )();
FT_UInt32 codepoint;
/* Compute set of all GSUB lookups. */
@@ -1390,8 +1415,13 @@
hb_codepoint_t glyph;
codepoint = adjustment_database[i].codepoint;
codepoint = adjustment_database[i].codepoint;
if ( !in_range( codepoint, ranges ) )
continue;
cmap_glyph = FT_Get_Char_Index( face, codepoint );
if ( cmap_glyph == 0 )
continue;
af_get_glyph_alternates( globals,
hb_font,
@@ -1449,7 +1479,6 @@
for ( cnt = 0; cnt < globals->glyph_count; cnt++ )
{
size_t* val;
FT_Int codepoint;
FT_UInt32 adj_type;
const char* flag_names[] =

View File

@@ -113,8 +113,8 @@ FT_BEGIN_HEADER
/* Allocate and populate the reverse character map, */
/* using the character map within the face. */
FT_LOCAL( FT_Error )
af_reverse_character_map_new( FT_Hash *map,
AF_FaceGlobals globals );
af_reverse_character_map_new( FT_Hash *map,
AF_StyleMetrics metrics );
/* Free the reverse character map. */
FT_LOCAL( FT_Error )

View File

@@ -1163,7 +1163,7 @@
}
af_reverse_character_map_new( &metrics->root.reverse_charmap,
metrics->root.globals );
&metrics->root );
Exit:
face->charmap = oldmap;