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

This commit, together with the previous one, makes the startup of the
auto-hinter much faster.

Note, though, that the startup time for handling the diacritic database is
still rather large.  For example, loading `arial.ttf` version 7.00 followed
by auto-hinting a first Latin glyph is still approx. three times slower
than before the introduction of the database (this is because function
`hb_ot_layout_lookup_get_glyph_alternates` is called very often).

* src/autofit/afshaper.c (scripts): Rename this array to...
  (af_hb_scripts): ...this and export it.
  (af_shaper_get_coverage_hb): Updated.
* src/autofit/afshaper.h: Updated.

* src/autofit/afadjust.c (af_reverse_character_map_new): Pass the current
  script to `hb_ot_layout_collect_lookups` to make HarfBuzz check less
  lookups while searching for glyph alternates.
This commit is contained in:
Werner Lemberg
2025-05-19 05:37:23 +02:00
parent f68733d4a8
commit 3dd7fc42bc
3 changed files with 20 additions and 4 deletions

View File

@@ -1398,12 +1398,21 @@
hb_set_t *result_set = hb( set_create )();
hb_set_t *gsub_lookups = hb( set_create )();
hb_script_t script = af_hb_scripts[metrics->style_class->script];
unsigned int script_count = 1;
hb_tag_t script_tags[2];
/* Compute set of all GSUB lookups. */
hb( ot_tags_from_script_and_language )( script, NULL,
&script_count, script_tags,
NULL, NULL );
script_tags[1] = HB_TAG_NONE;
/* Compute set of all script-specific GSUB lookups. */
hb( ot_layout_collect_lookups )( hb_face,
HB_OT_TAG_GSUB,
NULL, NULL, NULL,
script_tags, NULL, NULL,
gsub_lookups );
/* Find all glyph alternates of the code points in */

View File

@@ -89,7 +89,8 @@
#define SCRIPT( s, S, d, h, H, ss ) h,
static const hb_script_t scripts[] =
FT_LOCAL_ARRAY_DEF( hb_script_t )
af_hb_scripts[] =
{
#include "afscript.h"
};
@@ -127,7 +128,7 @@
face = hb( font_get_face )( globals->hb_font );
coverage_tags = coverages[style_class->coverage];
script = scripts[style_class->script];
script = af_hb_scripts[style_class->script];
/* Convert a HarfBuzz script tag into the corresponding OpenType */
/* tag or tags -- some Indic scripts like Devanagari have an old */

View File

@@ -25,6 +25,12 @@
FT_BEGIN_HEADER
#ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
FT_LOCAL_ARRAY( hb_script_t )
af_hb_scripts[];
#endif
FT_Error
af_shaper_get_coverage( AF_FaceGlobals globals,
AF_StyleClass style_class,