Commit graph

8439 commits

Author SHA1 Message Date
Werner Lemberg
a37e11c379 [autofit] Better handling of characters with attached diacritics. (1/3)
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.
2025-05-10 05:03:48 +00:00
Alexei Podtelezhnikov
9629cc0e83 * src/raster/ftraster.c (Line_Up): Use 64-bit calculations.
Attempt to fix #1332.
2025-05-09 16:31:16 -04:00
Werner Lemberg
6fa8725a41 [sfnt] Avoid allocation bomb in compressed SVG documents.
Reported as

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

* src/sfnt/ttsvg.c (MAX_SVG_SIZE): New macro.
  (tt_face_load_svg_doc): Reject too large buffer.
2025-05-09 13:27:51 +02:00
Werner Lemberg
04455084cf * include/freetype/ttnameid.h (TT_UCR_*): Define with unsigned long.
(TT_UCR_PHAGSPA): Fix definition.

Fixes issue #1300.
2025-05-08 07:49:10 +02:00
Werner Lemberg
c2789e7558 [doc] Mention that there is no rendering support for 'COLR' v1 tables.
Handles issue #1319.
2025-05-08 07:03:31 +02:00
Alexei Podtelezhnikov
35513a4d9b * src/truetype/ttinterp.c (TT_DotFix14): Silence UBSAN. 2025-05-07 18:53:21 -04:00
Alexei Podtelezhnikov
c1278179dc * src/cff/cffgload.c (cff_slot_load): Fix autohinter scaling.
Fixes #1330.
2025-05-07 17:57:42 -04:00
Werner Lemberg
ab0fe6d55e [autofit] Avoid division by zero.
Fixes issue #1331.

* src/autofit/aflatin.c (af_latin_stretch_bottom_tilde): Don't divide by
  zero.
2025-05-05 19:38:04 +02:00
Carlo Bramini
c26c150cf2 Fix Cygwin visibility attributes.
Reported as compilation warnings in #1329.

* include/freetype/config/public-macros.h: Check __CYGWIN__.
* include/freetype/internal/compiler-macros.h: Ditto.
2025-05-04 07:22:46 -04:00
KatekovAnton
bff01fbdcc * CMakeLists.txt: Fix cmake 4 error by specifying the policy version. 2025-05-03 09:53:14 +02:00
Werner Lemberg
79912716e7 * docs/CHANGES: Updated. 2025-04-29 19:18:12 +00:00
Behdad Esfahbod (بهداد اسفهبد)
5d2fd7608a 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 19:18:12 +00:00
Behdad Esfahbod (بهداد اسفهبد)
97bb53ee0a [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 19:18:12 +00:00
Behdad Esfahbod (بهداد اسفهبد)
7651fe00be [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 19:18:12 +00:00
Behdad Esfahbod (بهداد اسفهبد)
b512ce3ec7 [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 19:18:12 +00:00
Behdad Esfahbod (بهداد اسفهبد)
9242c88f93 [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 19:18:12 +00:00
Behdad Esfahbod (بهداد اسفهبد)
e9d030720c [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 19:18:12 +00:00
Behdad Esfahbod (بهداد اسفهبد)
8b443d70fe [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 19:18:12 +00:00
Behdad Esfahbod (بهداد اسفهبد)
3eb4eadea5 [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 19:18:12 +00:00
Werner Lemberg
f35bb75954 * src/autofit/aflatin.c (af_latin_stretch_top_tilde): Don't divide by zero.
Reported as

  https://issues.oss-fuzz.com/issues/414320186
2025-04-29 21:14:21 +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