Commit graph

782 commits

Author SHA1 Message Date
Werner Lemberg
ef54557bda [autofit] Prevent signed integer overflow.
Reported as

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

* src/autofit/aflatin.c (af_move_contour_vertically): Use `ADD_LONG`.
2026-04-03 06:27:32 +02:00
Werner Lemberg
675a94f5d0 [autofit] Prevent signed integer overflow.
Reported as

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

* src/autofit/aflatin.c
  (af_glyph_hints_apply_vertical_separation_adjustments): Use `ADD_LONG` and
  `SUB_LONG`.
2026-04-02 07:56:04 +02:00
Werner Lemberg
264b5fbf5b Update all copyright notices. 2026-03-11 17:27:07 +01:00
Harry Sintonen
a9babbcbc0 * src/autofit/ft-hb-ft.c (ft_hb_ft_reference_table): Use ft_sfree. 2026-01-13 15:39:29 +01:00
Werner Lemberg
b91f75bd02 [autofit] Prevent signed integer overflow.
Reported as

  https://issues.oss-fuzz.com/issues/473887994
  https://issues.oss-fuzz.com/issues/473912282

* src/autofit/afatin.c (af_latin_align_top_tilde,
  af_latin_align_bottom_tilde), src/autofit/afloader.c
  (af_loader_load_glyph): Use `FT_PIX_ROUND_LONG`, `FT_PIX_CEIL_LONG`, and
  `SUB_LONG`.
2026-01-07 07:19:07 +01:00
Werner Lemberg
4553f1c396 [autofit] Prevent signed integer overflow.
Reported as

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

* src/autofit/afloader.c (af_loader_load_glyph): Use `ADD_LONG`.
2026-01-06 05:41:15 +01:00
Werner Lemberg
7b72c0f238 [autofit] Prevent signed integer overflow.
Reported as

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

* src/autofit/aflatin.c (af_latin_stretch_top_tilde,
  af_latin_stretch_bottom_tilde): Use `MUL_LONG`.
2026-01-04 07:30:19 +01:00
Werner Lemberg
6a25214ae9 * src/autofit/afgsub.c (af_parse_gsub): Always init gsub_lookup_count.
Problem reported by Marc Schönefeld.
2025-11-29 07:00:41 +01:00
Werner Lemberg
582cea9ee1 [autofit] Fix handling of invalid GSUB lookup indices.
Problem reported by Marc Schönefeld.

HarfBuzz validates everything while processing OpenType tables in fonts.
However, the data returned by `hb_ot_layout_collect_lookups` is not
validated.  This commit adds proper checks.

* src/autofit/afglobal.h (AF_FaceGlobals): New field `gsub_lookup_count`.
* src/autofit/afgsub.c (af_parse_gsub): Set it.

* src/autofit/afadjust.c (af_reverse_character_map_new): Test result of
  `hb_set_next`.
2025-11-28 14:23:00 +01:00
Suzuki, Toshiya (鈴木俊哉)
184910dbef * src/autofit/afgsub.c: Evaluate FT_CONFIG_OPTION_USE_HARFBUZZ
after <freetype/freetype.h> and others.

Fixes issue #1360.
2025-11-05 10:32:03 +00:00
Werner Lemberg
4334f009e7 [autofit] Prevent signed integer overflow.
* src/autofit/aflatin.c (af_latin_stretch_top_tilde,
  af_latin_stretch_bottom_tilde, af_latin_align_top_tilde,
  af_latin_align_bottom_tilde,
  af_glyph_hints_apply_vertical_separation_adjustments): Use `ADD_LONG` and
  `SUB_LONG` for values that involve `FT_LONG_MAX` and `FT_LONG_MIN`.

Fixes issue #1363.
2025-09-28 08:13:38 +02:00
Werner Lemberg
53b9319bff * src/autofit/afgsub.c (af_map_lookup): Fix handling of lookup type 7.
Fixes issue #1356.
2025-09-10 14:14:43 +02:00
Behdad Esfahbod
e969f52986 [autofit] Fix HarfBuzz calling.
* src/autofit/afadjust.c (af_reverse_character_map_new)
  [FT_CONFIG_OPTION_USE_HARFBUZZ]: Use `ft_hb_enabled`.

Fixes issue #1354.
2025-09-08 05:57:19 +02:00
Werner Lemberg
32cb53904c Update all copyright notices. 2025-09-06 06:14:03 +02:00
Werner Lemberg
23fa1e3550 Updating CHANGES file; minor fixes elsewhere (mostly formatting). 2025-08-23 19:21:19 +02:00
Alexei Podtelezhnikov
508c30e086 * src/autofit/afgsub.c: Fix a warning.
Fixes [-Wunused-function] warning without HarfBuzz.
2025-08-14 10:33:30 -04:00
Werner Lemberg
0fd0cf33fd [autofit] Remove globals->gsub_length.
We completely validate the accessed data from the 'GSUB' table, making this
field unnecessary.

* src/autofit/afglobal.h (AF_FaceGlobalsRec): Remove `gsub_length` field.

* src/autofit/afglobal.c (af_face_globals_new), src/autofit/afgsub.c
  (af_parse_gsub): Updated.
2025-07-05 14:51:07 +02:00
Werner Lemberg
5e6715101f * src/autofit/afgsub.c: Include tttables.h and afgsub.h.
This fixes 'make multi' compilation with clang.

Reported as

  https://gitlab.freedesktop.org/freetype/freetype/-/merge_requests/381#note_2984610
2025-07-01 19:09:46 +02:00
Werner Lemberg
01695ea72a Various minor fixes.
As reported by clang 19.

* src/autofit/afadjust.c (adjustment_database): Make it static.

* src/base/ftdbgmem.c (FT_MEM_SIZE_MIN): Remove unused macro.

* src/psaux/psobjs.c (skip_procedure), src/truetype/ttinterp.c (Ins_IF,
  Ins_ELSE, Ins_FDEF, Ins_IDEF): Add `default` clause.
2025-07-01 18:06:17 +02:00
Werner Lemberg
f1be739219 More signedness fixes.
As reported by clang 19.

* src/autofit/afadjust.c (add_substitute): Make first argument unsigned.
  Update all callers.
  Other minor signedness fixes.
  (af_reverse_character_map_new): Minor signedness fixes.

* src/autofit/afgsub.c (af_hash_insert): Minor signedness fixes.

* src/autofit/aflatin.c
  (af_glyph_hints_apply_vertical_separation_adjustments): Make third
  argument unsigned.
  Update all callers.
  Other minor signedness fixes.
  (af_latin_hints_apply): Minor signedness fixes.

* src/bdf/bdflib.c (bdf_parse_bitmap_): Minor signedness fix.

* src/truetype/ttobjs.c (tt_size_init_bytecode): Minor signedness fix.
2025-07-01 18:00:12 +02:00
Werner Lemberg
8d82c9fa4d */*: Fix trivial signedness issues with format strings in trace messages.
As reported with clang 19's `-Wformat` option.
2025-07-01 17:08:37 +02:00
Werner Lemberg
346d8fae7a Fix make multi.
Reported as

  https://gitlab.freedesktop.org/freetype/freetype/-/merge_requests/381#note_2984253

* src/base/fthash.c: Include `ftobjs.h`.
* src/autofit/afgsub.c: Include `afglobal.h`.
2025-07-01 05:18:47 +02:00
Werner Lemberg
61bacf3dae Set minimum HarfBuzz version back to 2.0.0.
Due to the new GSUB parsing we no longer need
`hb_ot_layout_lookup_get_glyph_alternates`.

This partially reverts commit 5d2fd7608a.

* CMakeLists.txt (HARFBUZZ_MIN_VERSION), meson.build (harfbuzz_dep),
  builds/unix/configure.raw (harfbuzz_pkg): Set version to 2.0.0.

* src/autofit/ft-hb-decls.h: Remove entry for
  `hb_ot_layout_lookup_get_glyph_alternates`.
2025-06-26 05:46:58 +02:00
Werner Lemberg
6a982bde85 [autofit] Speed up computation of af_reverse_character_map_new. (4/4)
With this commit, the start-up time for creating the reverse character map
gets reduced from more than 300% to about 25% (as tested with `arial.ttf`
version 7.00).

* src/autofit/afadjust.c [FT_CONFIG_OPTION_USE_HARFBUZZ]: Include
  `afgsub.h`.
  (add_substitute): New auxiliary function to recursively add elements to
  the reverse cmap.
  (af_reverse_character_map_new): New code that replaces the old code
  removed in the previous commit.
2025-06-26 05:46:58 +02:00
Werner Lemberg
9e8b642b10 [autofit] Speed up computation of af_reverse_character_map_new. (3/4)
Rip out some HarfBuzz code of `af_reverse_character_map_new`.  The new code
comes immediately in a follow-up commit, making it easier to follow the
changes.

* src/autofit/afadjust.c (af_get_glyph_alternates_helper,
  af_get_glyph_alternates): Remove.
  (af_reverse_character_map_new): Remove code to create the `*map` hash.
2025-06-26 05:46:58 +02:00
Werner Lemberg
9bfb8e80c4 [autofit] Speed up computation of af_reverse_character_map_new. (2/4)
Create an array of GSUB lookup indices for `SingleSubst` and
`AlternateSubst` lookup types to exit early if we have different types.

Also improve tracing.

* src/autofit/afglobal.h (AF_FaceGlobals) [FT_CONFIG_OPTION_USE_HARFBUZZ]:
  New fields `gsub_length`, `gsub`, and `gsub_lookups_single_alternate`.

* src/autofit/afglobal.c [FT_CONFIG_OPTION_USE_HARFBUZZ]: Include
  `afgsub.h`.
  (af_face_globals_new) [FT_CONFIG_OPTION_USE_HARFBUZZ]: Call
  `af_parse_gsub` to fill `gsub_lookups_single_alternate`.
  (af_face_globals_free): Updated.

* src/autofit/afadjust.c (af_get_glyph_alternates_helper): Exit early if we
  possible.
  (af_reverse_character_map_new): Trace GSUB lookup indices to be checked.
2025-06-26 05:46:58 +02:00
Werner Lemberg
cda418a4a5 [autofit] Speed up computation of af_reverse_character_map_new. (1/4)
Using HarfBuzz's API functions to construct the reverse map is too slow; we
have to call `hb_ot_layout_lookup_get_glyph_alternates` far too often
because it can only handle a single glyph at a time.  For this reason we are
going to parse the GSUB table by ourselves.

The new non-local functions are `af_parse_gsub` and `af_map_lookup`.

* src/autofit/afgsub.c, src/autofit/afgsub.h: New files for parsing,
  validating, and mapping the `SingleSubst` and `AlternateSubst` subtable
  types of a GSUB table.

* src/autofit/autofit.c, src/autofit/rules.mk (AUTOF_DRV_SRC): Updated.
2025-06-26 05:46:58 +02:00
Behdad Esfahbod
3ccc27dc52 [autofit] Really fix handling of RTLD_DEFAULT.
This commit actually implements what commit 43ec023e1a describes.

* src/autofit/ft-hb.c (FT_RTLD_FLAGS): New macro for `dlopen`; it uses
  `RTLD_GLOBAL` only if `RTLD_DEFAULT` is available.
2025-06-19 08:15:33 +02:00
Werner Lemberg
fc051dc0be [autofit] Ignore virtual glyph indices from GSUB lookups.
Reported as

  https://issues.chromium.org/issues/420401651

* src/autofit/afadjust.c (af_reverse_character_map_new): Implement it.
2025-06-12 10:20:07 +02:00
Ozkan Sezer
bd28cf7a80 [autofit] Fix -Wunused-but-set-variable warning in Windows builds.
With this commit, the following warning gets removed.

```
In file included from src/autofit/autofit.c:21:0:
src/autofit/ft-hb.c: In function 'ft_hb_funcs_init':
src/autofit/ft-hb.c:75:35: warning:
  variable 'version_atleast' set but not used [-Wunused-but-set-variable]
     ft_hb_version_atleast_func_t  version_atleast = NULL;
                                   ^~~~~~~~~~~~~~~
```

* src/autofit/ft-hb.c (ft_hb_funcs_init): Move `NULL` check of
  `version_atleast` out of ifdefs.
2025-06-04 09:26:09 +02:00
Ozkan Sezer
1518bc83d2 * src/autofit/ft-hb.c: Fix definition of _GNU_SOURCE.
Commit 43ec023e1a defined the macro too late.
2025-06-03 12:40:38 +02:00
Behdad Esfahbod
43ec023e1a * src/autofit/ft-hb.c: Fix usage of RTLD_DEFAULT.
Using `RTLD_DEFAULT` we see whether the process already has HarfBuzz linked
in, and reuse it.  If this symbol is not defined it is tempting to use
`RTLD_GLOBAL` instead, which would make the library available to the whole
process.  However, without `RTLD_DEFAULT`, we would risk loading a second
HarfBuzz library, and if the linker mixes them up, probably giving symbols
from the new library to other clients, we might get into trouble.  For this
reason, we do not pass `RTLD_GLOBAL` to `dlopen`; the default is
`RTLD_LOCAL`, and the rest of the process won't see the loaded HarfBuzz and
hopefully all be happy.
2025-06-03 07:56:13 +02:00
Werner Lemberg
c6abd1e40a [autofit] Fix integer overflow.
Reported as

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

* src/autofit/aflatin.c (af_latin_stretch_top_tilde,
  af_latin_stretch_bottom_tilde): Use `SUB_LONG`.
2025-05-26 20:24:55 +02:00
Werner Lemberg
57a8730450 [autofit] Make the accent database work for more glyphs (again).
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.
2025-05-26 06:42:01 +02:00
Werner Lemberg
ed0ab8790d [autofit] Minor code cleanup.
* src/autofit/afadjust.c (af_reverse_character_map_new): Rename `result_set`
  to `glyph_alternates` and move its clearing to...
  (af_get_glyph_alternates): ...this function.
  (af_get_glyph_alternates_helper): s/result/helper_result/.
2025-05-25 04:50:46 +00:00
Werner Lemberg
a312820c86 [autofit] Speed up construction of reverse character map. (4/4)
* 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%.
2025-05-25 04:50:46 +00:00
Werner Lemberg
c0e7df6131 [autofit] Speed up construction of reverse character map. (3/4)
* src/autofit/afadjust.c (af_reverse_character_map_new): Fold two loops into
  one.
  Gain for `arial.ttf` version 7.00: approx. 1%.
2025-05-25 04:50:46 +00:00
Werner Lemberg
3dd7fc42bc [autofit] Speed up construction of reverse character map. (2/4)
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.
2025-05-25 04:50:46 +00:00
Werner Lemberg
f68733d4a8 [autofit] Speed up construction of reverse character map. (1/4)
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.
2025-05-25 04:50:46 +00:00
Werner Lemberg
4514f05158 [autofit] Avoid variable shadowing.
* src/autofit/afadjust.c (af_reverse_character_map_new): Do it.
2025-05-25 04:50:46 +00:00
Werner Lemberg
fd33c037ae [autofit] Minor speedup of reverse charmap creation.
* 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.
2025-05-25 04:50:46 +00:00
Werner Lemberg
541ad3d3cb [autofit] Whitespace. 2025-05-25 04:50:46 +00:00
Werner Lemberg
72e0c0711a [autofit] Use FT_Offset.
* src/autofit/afadjust.c (af_adjustment_database_lookup,
  af_reverse_character_map_new): Do it.
2025-05-25 04:50:46 +00:00
Werner Lemberg
47e35a5837 [autofit] Simplify return value of af_adjustment_database_lookup.
* src/autofit/adfadjust.h (af_adjustment_database_lookup): Return integer.
  (AF_AdjustmentDatabaseEntry): Move structure to...
* src/autofit/afadjust.c: ...this file.
  (af_adjustment_database_lookup, af_reverse_character_map_new): Updated.
* src/autofit/aflatin.c
  (af_glyph_hints_apply_vertical_separation_adjustments): Updated.
2025-05-25 04:50:46 +00:00
Werner Lemberg
94e93c7c75 [autofit] Remove no longer used functions and structures.
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.
2025-05-25 04:50:46 +00:00
Werner Lemberg
2492b5477b [autofit] Use a hash for handling vertical accent adjustments.
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`.
2025-05-25 04:50:46 +00:00
Werner Lemberg
701541662c * src/autofit/aflatin.c (af_latin_hints_apply): Improve code legibility. 2025-05-25 04:50:46 +00:00
Werner Lemberg
9dc66cbd0c [autofit] Use FT_LONG_MIN and FT_LONG_MAX for FT_Pos variables.
* src/autofit/aflatin.c (af_latin_metrics_init_blues,
  af_compute_vertical_extrema, af_find_highest_contour,
  af_find_second_highest_contour, af_find_lowest_contour,
  af_find_second_lowest_contour, af_check_contour_horizontal_overlap):
  Updated.
2025-05-25 04:50:46 +00:00
Werner Lemberg
d6e087d11b [autofit] Fix uninitialized variables.
* src/autofit/aflatin.c (af_latin_stretch_top_tilde,
  af_latin_stretch_bottom_tilde): Initialize `min_measurement`.
2025-05-25 04:50:46 +00:00
Werner Lemberg
b87f48a73e * src/aflatin.c (af_latin_hint_edges): Refine fix for serif handling.
Commit 11432424 (from 2025-May-12) was too aggressive; it is now restricted
to edges that are not too far away.
2025-05-19 15:48:24 +02:00