See the added comment for an explanation.
This partially undoes commit f68733d4a8.
* src/autofit/afadjust.c (af_reverse_character_map_new): Always loop over all
elements of the adjustment database.
(in_range): Removed, no longer needed.
* src/truetype/ttobjs.c (tt_size_run_fpgm): Remove assignment that
is ignored and overridden later in 'Compute_Funcs'.
* src/truetype/ttinterp.c (TT_RunIns): Ditto.
(Ins_MIAP): Formatting.
* src/autofit/afadjust.c (af_get_glyph_alternates): Move creation and
deletion of the `helper_result` set to...
(af_reverse_character_map_new): ...this function.
Gain for `arial.ttf` version 7.00: approx. 1%.
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.
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.
* src/autofit/afglobal.h (AF_HAS_CMAP_ENTRY): New flag.
(AF_STYLE_MASK): Update value.
* src/autofit/afglobal.c (af_face_globals_compute_style_coverage): Set
`AF_HAS_CMAP_ENTRY`.
* src/autofit/afadjust.c (af_reverse_character_map_new): For the creation of
the reverse map, change code to handle glyphs with cmap entries before
glyphs without cmap entries. Doing so avoids some code redundancy and
reduces the number of hash lookups.
This is the clean-up from the previous commit.
* src/autofit/afadjust.c (af_reverse_character_map_entry_compare,
af_reverse_character_map_lookup, af_reverse_character_map_expand):
Removed.
* src/autofit/afadjust.h: Updated.
* src/autofit/aftypes.h (AF_ReverseMapEntry, AF_ReverseCharacterMap):
Removed.
This greatly simplifies the code.
* src/autofit/afadjust.c (af_reverse_character_map_new): Implement it.
(af_reverse_character_map_done): Updated.
* src/autofit/afadjust.h: Updated.
* src/autofit/aflatin.c
(af_glyph_hints_apply_vertical_separation_adjustments): Updated.
* src/autofit/aftypes.h: Include `fthash.h`.
(AF_StyleMetrics): Change type of `reverse_charmap` to `FT_Hash`.
If user explicitly sets variations to `NULL` after it being set to something
else, `face->blend` will still be non-`NULL`. The intention here however is
correctly captured by `FT_IS_VARIATION`.
* src/sfnt/ttmtx.c (tt_face_get_metrics): Use `FT_IS_VARIATION`.
I found that in hb-ft I need to sometime reset the face to the default
instance. However, calling `FT_Set_Var_Design_Coordinates` with no coords
was still slowing down at least the glyph-advance code by processing
variations.
Perhaps there's a better fix, but this handles the easy cases.
* src/base/ftmm.c (FT_Set_Var_Design_Coordinates): Implement it.
If the distance of the current pixel to the edge is less than or equal
to 0.5, skip further neighbor comparisons to avoid unnecessary
calculations. When the `USE_SQUARED_DISTANCES` macro is defined,
compare to 0.25 instead.
* src/sdf/ftbsdf.c (compare_neighbor): Add early return for pixels
close to edges to avoid unnecessary neighbor checks.
8% speed up in drawing GoogleSansFlex variable in HB benchmark-font.
* src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Use an allocation
pool instead of individual allocations.
The series of commits that introduced this adjustment support had some
flaws.
- If there were two diacritics on top of a base glyph, and the upper
diacritic was a tilde, the vertical centering correction was incorrectly
applied to the lower, non-tilde glyph instead of the tilde.
- The maximum value allowed to shift a glyph was too strict (and also not
handling rounding issues), causing some diacritics and combinations of
diacritics to be not shifted at all.
* src/autofit/aflatin.c
(af_glyph_hints_apply_vertical_separation_adjustments): Correctly handle
vertical centering correction.
The old algorithm removed segments from edges to make the auto-hinter ignore
a tilde. However, the implementation had two flaws.
- Edge array elements were moved around without reordering them afterwards.
- The linking between edges and segments wasn't correctly updated for moved
edges, which could cause endless loops.
Correcting both problems are non-trivial; additionally, a fix would make
the auto-hinter slower.
For these reasons, a new, simpler approach is taken: A new flag allows
points to be tagged as being ignored, and if such a point is enountered, it
doesn't get added to a segment.
Fixes issue #1333.
* src/autofit/afhints.h (AF_FLAG_IGNORE): New macro.
* src/autofit/aflatin.c (af_latin_hints_compute_segments, af_touch_contour):
Use it.
(af_remove_segments_containing_point, af_remove_top_points_from_edges,
af_remove_bottom_points_from_edges): Removed.
(af_latin_stretch_top_tilde): Call `af_touch_top_contours` and
`af_touch_bottom_contours` unconditionally.
(af_latin_hints_apply): Updated.
In the event that a CharString retrieved via the incremental interface
caused an error, the memory for that CharString was not being freed.
* src/type1/t1gload.c (T1_Parse_Glyph_And_Get_Char_String): Free charstring.