8228 Commits

Author SHA1 Message Date
Werner Lemberg
5ee800c123 * docs/CHANGES: Updated. 2025-04-29 13:49:51 +02:00
Behdad Esfahbod
3c40134946 Provide configuration option to dynamically load the HarfBuzz library.
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.
2025-04-29 13:49:51 +02:00
Behdad Esfahbod
339f4d323d [autofit] Enable dynamic loading of HarfBuzz. (2/2)
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`.
2025-04-29 13:49:51 +02:00
Behdad Esfahbod
19823d1227 [autofit] Enable dynamic loading of HarfBuzz. (1/2)
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.
2025-04-29 13:49:51 +02:00
Behdad Esfahbod
574373906d [autofit] Some preparations for loading HarfBuzz dynamically. (4/4)
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.
2025-04-29 13:49:50 +02:00
Behdad Esfahbod
a0f71be1d6 [autofit] Some preparations for loading HarfBuzz dynamically. (3/4)
* 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.
2025-04-29 13:49:50 +02:00
Behdad Esfahbod
489e035787 [autofit] Some preparations for loading HarfBuzz dynamically. (2/4)
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.
2025-04-29 13:49:50 +02:00
Behdad Esfahbod
028b6d1e7b [autofit] Some preparations for loading HarfBuzz dynamically. (1/4)
* 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.
2025-04-29 13:49:50 +02:00
Behdad Esfahbod
571a746bfa [autofit] Rename 'ft-hb' to 'ft-hb-ft'.
Since it's a (shrinked) copy of 'hb-ft'.

* src/autofit/afglobal.c (af_face_globals_new), src/autofit/afshaper.h,
  src/autofit/autofit.c: Updated.

* src/autofit/ft-hb.c, src/autofit/ft-hb.h: Renamed to...
* src/autofit/ft-hb-ft.c, src/autofit/ft-hb-ft.h: ...this; updated.

* src/autofit/rules.mk (AUTOF_DRV_SRC): Updated.
2025-04-29 13:49:50 +02:00
Werner Lemberg
2d1abd3bbb [autofit] Extend adjustment database with characters up to U+1FFF.
This adds many pre-combined Latin glyphs, Cyrillic, Greek, and some
characters from other scripts (or rather, Unicode blocks).

Fixes issues #112 and #471.
2025-04-28 17:52:35 +00:00
Werner Lemberg
d38a13dd3c [autofit] Support diacritics with special vertical minima.
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.
2025-04-28 17:52:35 +00:00
Werner Lemberg
9eb6548d3d [autofit] More tilde stretch support. (3/3)
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.
2025-04-28 17:52:35 +00:00
Werner Lemberg
c6b45a7646 [autofit] More tilde stretch support. (2/3)
* 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.
2025-04-28 17:52:35 +00:00
Werner Lemberg
cbce230dcd [autofit] More tilde stretch support. (1/3)
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.
2025-04-28 17:52:35 +00:00
Werner Lemberg
7722a5b2b2 [autofit] Support two below/above accents for vertical adjustment. (2/2)
* src/autofit/afadjust.h (AF_ADJUST_UP2, AF_ADJUST_DOWN2): New macros.
* src/autofit/afadjust.c (af_reverse_character_map_new): Updated.

* src/autofit/aflatin.c
  (af_glyph_hints_apply_vertical_separation_adjustments): Implement it.
2025-04-28 17:52:35 +00:00
Werner Lemberg
40d4b57989 [autofit] Support two below/above accents for vertical adjustment. (1/2)
Some variable renamings.
2025-04-28 17:52:35 +00:00
Werner Lemberg
619305c43f [autofit] Routines for finding the second highest/lowest contour.
* src/autofit/aflatin.c (af_find_second_highest_contour,
  af_find_second_lowest_contour): New functions.
2025-04-28 17:52:35 +00:00
Werner Lemberg
7a2646e699 [autofit] Use more functions to reduce code.
* 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`,
2025-04-28 17:52:35 +00:00
Werner Lemberg
387c2d8063 * src/autofit/aflatin.c (af_compute_vertical_extrema): New function.
To be used in a follow-up commit.
2025-04-28 17:52:35 +00:00
Werner Lemberg
357032d1ce * src/autofit/aflatin.c: Some variable renaming. 2025-04-28 17:52:35 +00:00
Werner Lemberg
25369eca99 [autofit] Avoid recomputation of highest and lowest contour.
* src/autofit/aflatin.c (af_latin_hints_apply): Compute highest and lowest
  contour in this function.
  (af_latin_remove_top_tilde_points_from_edges,
  af_latin_remove_bottom_tilde_points_from_edges,
  af_latin_stretch_top_tilde, af_latin_stretch_bottom_tilde,
  af_latin_align_top_tilde, af_latin_align_bottom_tilde): Updated.
2025-04-28 17:52:35 +00:00
Werner Lemberg
64da9d4798 * src/aflatin.c (af_latin_trace_height): Remove.
Update caller.

The algorithm works fine.
2025-04-28 17:52:35 +00:00
Werner Lemberg
ba94c9547e [autofit] Support vertical stretching of tilde below base glyph. (2/2)
* 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.
2025-04-28 17:52:35 +00:00
Werner Lemberg
ec28f4880b [autofit] Support vertical stretching of tilde below base glyph. (1/2)
* src/autofit/aflatin.c (af_latin_remove_tilde_points_from_edges,
  af_latin_stretch_tilde, af_latin_align_tilde): Rename to...
  (af_latin_remove_top_tilde_points_from_edges, af_latin_stretch_top_tilde,
  af_latin_align_top_tilde): ...this.
  Update all callers.
  (af_latin_hints_apply): Rename `is_tilde` to `is_top_tilde`.
2025-04-28 17:52:35 +00:00
Werner Lemberg
8d1f51565a [autofit] Allow vertical adjustment at the top and bottom simultaneously.
This will be used to hint characters like U+1FB7 ('ᾷ').

* src/autofit/aflatin.c
  (af_glyph_hints_apply_vertical_separation_adjustments): Implement it.
2025-04-28 17:52:35 +00:00
Werner Lemberg
5e0b08713c * src/autofit/afadjust.c (af_reverse_character_map_new): Update tracing. 2025-04-28 17:52:35 +00:00
Werner Lemberg
162a93b101 [autofit] Indicate tilde handling with a flag macro, too.
* src/autofit/afadjust.h (AF_ADJUST_TILDE_TOP): New macro.
  (AF_AdjustmentDatabaseEntry): Remove field `apply_tilde`.

* src/autofit/afadjust.c (adjustment_database,
  af_reverse_character_map_new), src/autofit/aflatin.c
  (af_glyph_hints_apply_vertical_separation_adjustments,
  af_latin_hints_apply): Updated.
2025-04-28 17:52:35 +00:00
Werner Lemberg
582cc21bed [aflatin] Convert adjustment database enum to macros.
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.
2025-04-28 17:52:35 +00:00
Werner Lemberg
566e30c176 [autofit] Shorten adjustment enum names.
* src/autofit/afadjust.h (AF_VERTICAL_ADJUSTMENT_TOP_CONTOUR_UP,
  AF_VERTICAL_ADJUSTMENT_BOTTOM_CONTOUR_DOWN, AF_VERTICAL_ADJUSTMENT_NONE):
  Renamed to...
  (AF_ADJUST_UP, AF_ADJUST_DOWN, AF_ADJUST_NONE): ...this.

* src/autofit/afadjust.c (adjustment_database,
  af_reverse_character_map_expand), src/autofit/aflatin.c
  (af_glyph_hints_apply_vertical_separation_adjustments): Updated.
2025-04-28 17:52:35 +00:00
Werner Lemberg
1da283b8ae * src/autofit/afranges.c: Updated to Unicode 17.0.
But no support for new scripts (volunteers welcomed).
2025-04-26 10:05:02 +02:00
Werner Lemberg
3ce99005fd * src/autofit/afranges.c: Updated to Unicode 16.0.
But no support for new scripts (volunteers welcomed).
2025-04-26 10:05:02 +02:00
Werner Lemberg
08a13fe202 * src/autofit/afranges.c: Updated to Unicode 15.1.
But no support for new scripts (volunteers welcomed).
2025-04-26 10:05:00 +02:00
Werner Lemberg
3019fa6cb1 * src/autofit/afranges.c: Updated to Unicode 14.0.
But no support for new scripts (volunteers welcomed).
2025-04-26 09:56:44 +02:00
Werner Lemberg
373aa74487 * src/autofit/afranges.c: Updated to Unicode 13.0.
But no support for new scripts (volunteers welcomed).
2025-04-26 09:56:41 +02:00
Werner Lemberg
12a9f65d7f * src/autofit/afranges.c: Updated to Unicode 12.0.
But no support for new scripts (volunteers welcomed).
2025-04-26 08:17:00 +02:00
Alexei Podtelezhnikov
3467c2177c * include/freetype/internal/ftcalc.h (FT_MulFix_64): Silence UBSAN. 2025-04-25 08:09:48 -04:00
Behdad Esfahbod
1019b1c2b9 * src/autofit/afadjust.c (af_get_glyph_alternates): Fix endless loop. 2025-04-22 06:20:22 +02:00
Werner Lemberg
b5b3fd579e * src/afadjust.c: Fix test for newer HarfBuzz version (second try). 2025-04-20 10:48:54 +02:00
Werner Lemberg
05f3cf135e * src/afadjust.c: Fix test for newer HarfBuzz version. 2025-04-20 10:29:32 +02:00
Werner Lemberg
a64b49ccfc [autofit] Request at least HarfBuzz 7.2.0 for diacritic support. (3/3)
This version (from April 2023) added 'SingleSubst' support to
`hb_ot_layout_lookup_get_glyph_alternates`.
2025-04-20 10:07:13 +02:00
Werner Lemberg
de98b1bab5 [autofit] Speed up creation of the adjustment database's reverse map. (2/3)
Remove the old code and activate the new one.
2025-04-20 10:05:48 +02:00
Werner Lemberg
573201be7d [autofit] Speed up creation of the adjustment database's reverse map. (1/3)
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.
2025-04-20 10:04:39 +02:00
Werner Lemberg
9536e4728f * src/autofit/afadjust.c (af_reverse_character_map_new): Check map limit.
Reported as

  https://issues.chromium.org/issues/410925355
2025-04-18 06:36:18 +02:00
Alexei Podtelezhnikov
6ed79d5b7a * include/freetype/internal/ftcalc.h: Fix fringe compilation. 2025-04-17 22:46:06 -04:00
Alexei Podtelezhnikov
4fad257a7e * src/base/ftcalc.c (ft_corner_orientation) [!FT_INT32]: Fix up. 2025-04-17 22:32:21 -04:00
Werner Lemberg
d6c2922875 [autofit] Don't access uninitialized memory.
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`.
2025-04-17 19:36:51 +02:00
Alexei Podtelezhnikov
66e0d25ecb * src/truetype/ttinterp.c (TT_MulFix14,TT_DotFix14)[!FT_INT64]: Sync. 2025-04-17 15:37:27 +00:00
Alexei Podtelezhnikov
9eecaa0788 * src/truetype/ttinterp.c (TT_DotFix14): Silence UBSAN. 2025-04-17 12:44:37 +00:00
Alexei Podtelezhnikov
0a650e8c52 * src/base/ftcalc.c: Miscellaneous cleanups. 2025-04-16 22:54:54 -04:00
Werner Lemberg
cc849c32cf [autofit] Avoid crash.
Reported as

  https://issues.oss-fuzz.com/issues/410811029

* src/autofit/aflatin.c (af_remove_segments_containing_point): Check
  `edge->last`.
2025-04-16 19:42:02 +02:00