This adds many pre-combined Latin glyphs, Cyrillic, Greek, and some
characters from other scripts (or rather, Unicode blocks).
Fixes issues #112 and #471.
This code catches situations like U+1F90 ('ᾐ'), where some fonts have
exactly the same vertical minimum for the lower accent as for the base
glyph.
* src/autofit/aflatin.c (af_find_highest_contour, af_find_lowest_contour):
Handle it.
The auto-hinter now supports up to four tilde glyphs (two above and two
below a base character).
Note that diacritics above (or below) a tilde are now also ignored by the
auto-hinter.
* src/autofit/afadjust.h (AF_ADJUST_TILDE_TOP2, AF_ADJUST_TILDE_BOTTOM2):
New macros.
* src/autofit/afadjust.c (af_reverse_character_map_new): Updated.
* src/autofit/aflatin.c (af_remove_top_points_from_edges,
af_remove_bottom_points_from_edges): Make functions also handle all
contours higher (or lower) of the given one in the argument.
(af_touch_top_contours, af_touch_bottom_contours): New functions.
(af_latin_stretch_top_tilde, af_latin_stretch_bottom_tilde): Use it to
also handle all contours higher (or lower) than the tilde contour.
* (af_latin_hints_apply): Handle more tilde glyphs.
* src/autofit/aflatin.c (af_latin_stretch_top_tilde,
af_latin_stretch_bottom_tilde): Return vertical size difference between
stretched and original contour.
(af_latin_align_top_tilde, af_latin_align_bottom_tilde): Return applied
delta.
(af_latin_hints_apply): Updated; the return values are not used yet.
Move some existing code that we soon need elsewhere into separate functions.
* src/autofit/aflatin.c (af_move_contours_up, af_move_contours, down): New
functions.
(af_glyph_hints_apply_vertical_separation_adjustments): Use them.
(af_touch_contour): New function.
(af_latin_stretch_top_tilde, af_latin_stretch_bottom_tilde): Use it.
(af_latin_remove_top_tilde_points_from_edges,
af_latin_remove_bottom_tilde_points_from_edges): Renamed to...
(af_remove_top_points_from_edges, af_remove_bottom_points_from_edges):
...this.
Update callers.
* src/autofit/aflatin.c (af_find_highest_contour, af_find_lowest_contour):
Updated.
(af_glyph_hints_apply_vertical_separation_adjustments): Use
`af_compute_vertical_extrema`, `af_find_highest_contour`, and
`af_find_lowest_contour`.
(af_latin_hints_apply): Use `af_compute_vertical_extrema`,
* src/autofit/afadjust.h (AF_ADJUST_TILDE_BOTTOM): New macro.
* src/autofit/afadjust.c (af_reverse_character_map_new): Updated.
* src/autofit/aflatin.c (af_find_lowest_contour,
af_latin_remove_bottom_tilde_points_from_edges,
af_latin_stretch_bottom_tilde, af_latin_align_bottom_tilde): New functions
in analogy to the top tilde versions.
(af_glyph_hints_apply_vertical_separation_adjustments): Add support in
analogy to the top tilde code.
(af_latin_hints_apply): Updated.
We are going to add more values, and we want to use combinations of them.
* src/autofit/afadjust.h (AF_VerticalSeparationAdjustmentType): Replace
with...
(AF_ADJUST_UP, AF_ADJUST_DOWN, AF_ADJUST_NONE): ... new macros.
(AF_AdjustmentDatabaseEntry): Rename field
`vertical_separation_adjustment_type` to `flags`.
* src/autofit/afadjust.c (af_reverse_character_map_new),
src/autofit/aflatin.c
(af_glyph_hints_apply_vertical_separation_adjustments): Updated.
As it turns out, the original implementation using
`hb_ot_shape_glyphs_closure` is extremely slow if a font has a rich set of
OpenType features. For example, this function was called 66954 times while
loading font `arial.ttf` version 7.00, increasing FreeType's startup time by
a factor of 10, which is unacceptable.
The new algorithm uses a completely different, more low-level approach, no
longer working with OpenType features but with OpenType lookups. It relies
on function `hb_ot_layout_lookup_get_glyph_alternates`, also replacing
recursion with a simple loop. In total, this brings the additional startup
time back to an acceptable range of a few percent.
A side effect of the new approach is that it catches more alternate forms:
the old code didn't properly handle script-specific features.
To make the change more readable, this commit only adds new code.
Reported as
https://bugs.ghostscript.com/show_bug.cgi?id=708295
* src/autofit/aflatin.c
(af_glyph_hints_apply_vertical_separation_adjustments): Initialize all
array elements of `contour_y_minima` and `contour_y_maxima`.
Call the functions once per font instead of once per glyph.
* src/autofit/afadjust.c (af_all_glyph_variants): Move code to compute the
`feature_tags` and `type_3_lookup_indices` sets to...
(af_reverse_character_map_new): ...this function.
Due to the way the reverse map array gets constructed with HarfBuzz, there
might be multiple, identical glyph index entries with different character
values in the array. As an example, an OpenType feature like 'unic' might
map lowercase glyph 'ae' to uppercase glyph 'AE', in addition to the already
present cmap entry for 'AE'.
In most cases, this incorrect mapping is harmless (but still wrong).
However, there exist some lowercase/uppercase character pairs where the
diacritic for the uppercase character is on the other vertical side of the
base character as for the lowercase character. An example is U+0122 (LATIN
CAPITAL LETTER G WITH CEDILLA) and U+0123 (LATIN SMALL LETTER G WITH
CEDILLA): the former has the cedilla below, the latter above. A wrong
mapping would thus shift the base glyph 'G' up by a pixel instead of
shifting the cedilla down.
We fix this by always giving precedence to cmap entries.
* src/autofit/afadjust.c (af_reverse_character_map_entry_compare): Do a
secondary sort on the character code.
(af_reverse_character_map_lookup): Adjust binary search to return the
first occurrence of an entry (i.e., the one with the lowest array index).
(af_reverse_character_map_new)[FT_CONFIG_OPTION_USE_HARFBUZZ]: Implement
cmap priority.