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.
The 'backward_compatibility' is only set in v40: no need to check
the interpreter version again and again. In addition, we now track
IUP in its lower bits. After both IUPx and IUPy have been called,
'backward_compatibility' becomes equal to 0x7.
* src/truetype/ttinterp.h (TT_ExecContextRec): Wrap 'iup?_called'
into 'backward_compatibility'.
* src/truetype/ttinterp.c (Ins_INSTCTRL): Sync 'backward_compatibility'.
(Direct_Move, Direct_Move_X/Y, Move_Zp2_Point,
Ins_FLIPPT,FLIPRGON,FLIPRGOFF,SHPIX,DELTAP): Updated.
(TT_RunIns): Do not mess with IUP flags.
* src/truetype/ttgload.c (tt_loader_init): Set 'backward_compatibility'.
(TT_Hint_Glyph): Updated.
* src/truetype/ttinterp.h (TT_Exec_ContextRec): Remove 'step_ins'.
* src/truetype/ttinterp.c (TT_RunIns, Ins_Goto_CodeRange,
Ins_JMPR,ENDF,PUSHW,NPUSHW): Set and use zero increment 'length' instead.
(Ins_CALL,LOOPCALL,UNKNOWN): Updated.
This commit does two things.
- Ignore accents that have too large heights. This situation can happen if
an accent outline is unexpectedly not the highest (or lowest) contour.
- Add a new adjustment flag `AF_ADJUST_NO_HEIGHT_CHECK` to override the
height check.
* src/autofit/afadjust.h (AF_ADJUST_NO_HEIGHT_CHECK): New macro.
* src/autofit/afadjust.c (adjustment_database): Updated.
* src/autofit/aflatin.c (af_latin_hints_apply): Handle new flag.
(af_glyph_hints_apply_vertical_separation_adjustments): Check limit.
* src/autofit/afadjust.h (AF_IGNORE_CAPITAL_TOP, AF_IGNORE_CAPITAL_BOTTOM,
AF_IGNORE_SMALL_TOP, AF_IGNORE_SMALL_BOTTOM): New macros.
* src/autofit/afadjust.c (af_reverse_character_map_new)
[FT_DEBUG_LEVEL_TRACE]: Updated.
Also fix debugging strings of other flags.
* src/autofit/afhints.h (AF_EDGE_NO_BLUE): New edge flag to make the
auto-hinter ignore the edge while assigning blue zones.
* src/autofit/aflatin.c (af_latin_hints_compute_blue_edges): Use it.
(af_prevent_top_blue_alignment, af_prevent_bottom_blue_alignment,
af_latin_get_base_glyph_blues, af_latin_ignore_top,
af_latin_ignore_bottom): New functions.
(af_latin_hints_apply): Updated.
Introduce blue zone properties that will be used to make the auto-hinter
ignore diacritics attached on the top or the bottom of a base character.
* src/autofit/afblue.hin (AF_BLUE_PROPERTY_LATIN_CAPITAL_BOTTOM,
AF_BLUE_PROPERTY_LATIN_SMALL_BOTTOM): New properties.
* src/autofit/afblue.dat: Use them.
* src/autofit/afblue.c, src/autofit/afblue.h: Rengenerated.
* src/autofit/aflatin.h (AF_LATIN_IS_CAPITAL_BOTTOM_BLUE,
AF_LATIN_IS_SMALL_BOTTOM_BLUE, AF_LATIN_BLUE_BOTTOM,
AF_LATIN_BLUE_BOTTOM_SMALL): New macros.
* src/autofit/aflatin.c (af_latin_metrics_init_blues)[FT_DEBUG_LEVEL_TRACE]:
Updated.
We now request HarfBuzz version 2.6.8 (published in June 2020) or newer to
simplify the setup; this version introduced function
`hb_ot_layout_lookup_get_glyph_alternates`, which we need for the adjustment
database of the auto-hinter.
No CMake support yet for dynamic loading.
* include/freetype/config/ftoption.h, devel/ftoption.h
(FT_CONFIG_OPTION_USE_HARFBUZZ_DYNAMIC): New configuration macro.
* builds/unix/configure.raw: Implement `--with-harfbuzz=dynamic`.
This gets tested automatically if we can't link with `libharfbuzz`.
(ft_option_set, ft_option_unset): Refine.
Require at least HarfBuzz version 2.6.8.
* meson.build: Do the same as `configure.raw`.
* meson_options.txt: Updated.
* CMakeLists.txt: Require at least HarfBuzz version 2.6.8.
Handle the case where loading HarfBuzz dynamically fails.
* src/autofit/ft-hb.c, src/autofit/ft-hb.h (ft_hb_enabled): New function.
* src/autofit/afglobal.c (af_face_globals_new, af_face_globals_free):
Guard HarfBuzz functions with `ft_hb_enabled`.
* src/autofit/aflatin.c (af_latin_metrics_init_widths,
af_latin_metrics_init_blues, af_latin_metrics_check_digits): Simplify
setup of `shaper_buf`.
Guard calls of `af_shaper_buf_create` with `ft_hb_enabled`.
* src/autofit/afcjk.c (af_cjk_metrics_init_widths,
af_cjk_metrics_init_blues, af_cjk_metrics_check_digits): Dito.
* src/autofit/afshaper.c: Guard all HarfBuzz function calls with
`ft_hb_enabled`.
This commit activates the mini-HarfBuzz header files and provides the
necessary infrastructure for dynamically loading HarfBuzz if
`FT_CONFIG_OPTION_USE_HARFBUZZ_DYNAMIC` is defined (this macro gets set up
in a follow-up commit).
* src/autofit/ft-hb.c: New file, providing `ft_hb_funcs_init` and
`ft_hb_funcs_done` for loading HarfBuzz dynamically. The name of the
library is hold in the macro `FT_LIBHARFBUZZ`, which can be overridden.
* src/autofit/ft-hb.h: Don't include `hb.h` but `ft-hb-types.h`.
(hb): Modified to handle both standard linking and dynamically
loading of HarfBuzz.
(HB_EXTERN): New macro to load `ft-hb-decls.h`.
* src/autofit/afadjust.c [FT_CONFIG_OPTION_USE_HARFBUZZ]: For the sake of
dynamically loading the HarfBuzz library, replace the compile-time macro
`HB_VERSION_ATLEAST` with a call to the run-time function
`hb_version_atleast` where necessary – a follow-up commit will set the
minimum version of HarfBuzz to 2.6.8, which provides all necessary
functions needed by FreeType.
* src/autofit/afmodule.h: Include `ft-hb.h`.
(AF_ModuleRec) [FT_CONFIG_OPTION_USE_HARFBUZZ_DYNAMIC]: Add `hb_funcs`
structure to hold pointers to the dynamically loaded HarfBuzz functions.
* src/autofit/afmodule.c (af_autofitter_init, af_autofitter_done)
[FT_CONFIG_OPTION_USE_HARFBUZZ_DYNAMIC]: Call `ft_hb_funcs_init` and
`ft_hb_funcs_done`.
* src/autofit/afshaper.h: Updated.
* src/autofit/autofit.c: Include `ft-hb.c`.
* src/autofit/rules.mk (AUTOF_DRV_SRC, AUTOF_DRV_H): Updated.
Add 'mini' HarfBuzz declarations to make FreeType independent on HarfBuzz
header files.
The files get activated in a follow-up commit.
* src/autofit/ft-hb-decls.h, src/autofit/ft-hb-types.h: New files, holding
verbatim (or slightly massaged) entries from public HarfBuzz header files.
* src/autofit/hb-script: New file.
A verbatim copy of a public HarfBuzz header file.
* src/autofit/afshaper.c: Move around code so that the non-HarfBuzz code is
present even if `FT_CONFIG_OPTION_USE_HARFBUZZ` is not defined. This is a
preliminary step to allow deactivation of HarfBuzz at run-time.
Pass `AF_FaceGlobals` to many functions, or provide it, tagged with
`FT_UNUSED`. We need this later on to access a dynamically linked HarfBuzz
library.
* src/autofit/ft-hb-ft.h (ft_hb_ft_font_create): Use `globals` argument.
Drop unused `destroy` argument.
* src/autofit/ft-hb-ft.c (ft_hb_ft_face_create, ft_hb_ft_font_create): Use
`globals` argument.
Drop unused `destroy` argument.
(ft_hb_ft_face_create, ft_hb_ft_reference_table): Cast `user_data` to
`AF_FaceGlobals`.
* src/autofit/afadjust.c (af_get_glyph_alternates_helper,
af_get_glyph_alternates): Add `globals` argument.
Update callers.
* src/autofit/afshaper.c, src/autofit/afshaper.h (af_shaper_buf_create,
af_shaper_buf_destroy): Use `globals` argument.
* src/autofit/afglobal.c (af_face_globals_new): Updated.
* src/autofit/afcjk.c (af_cjk_metrics_init_widths,
af_cjk_metrics_init_blues, af_cjk_metrics_check_digits): Updated.
* src/autofit/aflatin.c (af_latin_metrics_init_widths,
af_latin_metrics_init_blues, af_latin_metrics_check_digits): Updated.
* src/autofit/ft-hb.h: New file, defining the `hb` macro. Later on, we
provide a different definition of this macro depending on a yet-to-come
configuration option to support dynamic loading of HarfBuzz functions.
* src/autofit/afadjust.c, src/autofit/afglobal.c, src/autofit/afshaper.c,
stc/ft-hb-ft.c: Use it.