From 3dd7fc42bc76b3c826d0118747b89486b83081f8 Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Mon, 19 May 2025 05:37:23 +0200 Subject: [PATCH] [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. --- src/autofit/afadjust.c | 13 +++++++++++-- src/autofit/afshaper.c | 5 +++-- src/autofit/afshaper.h | 6 ++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/autofit/afadjust.c b/src/autofit/afadjust.c index a0904e063..8255e8783 100644 --- a/src/autofit/afadjust.c +++ b/src/autofit/afadjust.c @@ -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 */ diff --git a/src/autofit/afshaper.c b/src/autofit/afshaper.c index ae6c74f06..45e92a84d 100644 --- a/src/autofit/afshaper.c +++ b/src/autofit/afshaper.c @@ -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 */ diff --git a/src/autofit/afshaper.h b/src/autofit/afshaper.h index 4a4176f89..71ecdeb03 100644 --- a/src/autofit/afshaper.h +++ b/src/autofit/afshaper.h @@ -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,