Commit graph

8369 commits

Author SHA1 Message Date
Alexei Podtelezhnikov
d6022b6d6e [smooth] Remove usage of setjmp and longjmp.
To support WASM targets with slow or unsupported setjmp and longjmp,
we eliminate these calls in favor of an error propagation model.
When gray_set_cell is out of cells, it raises an exception which is
later handled in gray_convert_glyph_inner.
This is a less invasive alternative to !385.

* src/smooth/ftgrays.c (gray_set_cell): Raise the overflow exception
and redirect all work to `cell_null`.
(gray_move,line,conic,cubic_to): Return the exception.
(gray_convert_glyph, gray_convert_glyph_inner): Handle the exception.
2025-07-26 07:00:51 -04:00
Werner Lemberg
b04db3872c [sfnt] Rewrite GPOS kerning support. (2/2)
The previous code had a fundamental flaw: it didn't validate the necessary
parts of the 'GPOS' table before accessing it, causing crashes with
malformed data (since `TT_CONFIG_OPTION_GPOS_KERNING` is off by default,
standard fuzzers don't catch these problems).  Additionally, it did a lot of
parsing while accessing kerning data, making it rather slow.

The new implementation fixes this.  After validation, offsets to the 'GPOS'
lookup subtables used in the 'kern' feature that correspond to 'simple'
kerning (i.e., similar to 'kern' table kerning) are stored in `TT_Face`;
this greatly simplifies and accelerates access to the kerning data.

Testing with font `SF-Pro.ttf` version '1.00', the validation time for the
'GPOS' table increases the start-up time of `FT_New_Face` by less than 1%,
while calls to `FT_Get_Kerning` become about 3.5 times faster.

* include/freetype/internal (gpos_kerning_available): Replace with...
  (gpos_lookups_kerning, num_gpos_lookups_kerning): ... these new fields.
  Update callers.

* src/ttgpos.c [TT_CONFIG_OPTION_GPOS_KERNING]: A new implementation.
2025-07-05 14:51:40 +02:00
Werner Lemberg
8ef26a803c [sfnt] Rewrite GPOS kerning support. (1/2)
This commit removes the previous implementation.
2025-07-05 14:51:40 +02:00
Werner Lemberg
ecbc1abfa8 [cff] Support GPOS kerning.
* src/cff/cffdrivr.c (cff_get_kerning) [TT_CONFIG_OPTION_GPOS_KERNING]: Add
  code similar to the one in `tt_get_kerning`.
2025-07-05 14:51:40 +02:00
Werner Lemberg
fb6a74269d * src/sfnt/ttkern.h (TT_FACE_HAS_KERNING): Remove macro.
Given that we also support (limited) 'GPOS' table kerning if
`TT_CONFIG_OPTION_GPOS_KERNING` is defined, the name of this macro is
misleading since it only is true for 'kern' table kerning.

* src/sfnt/sfobjs.c (sfn_load_face): Replace `TT_FACE_HAS_KERNING` with
  plain code.
2025-07-05 14:51:40 +02: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
f1cd6dbfa0 * src/truetype/ttobjs.c (tt_size_init_bytecode): Correct previous fix.
`FT_NEW_ARRAY` expects a signed value, not an unsigned one.
2025-07-01 21:32:47 +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
Alexei Podtelezhnikov
39d85f1692 * MSBuild.sln: Minor. 2025-06-30 09:32:19 -04:00
Werner Lemberg
d7e640b9c6 [doc] Revise font variation API. 2025-06-29 16:14:57 +02:00
Werner Lemberg
636aede94b [doc] Use 'Adobe MM', 'TrueType GX', and 'OpenType Font Variations'. 2025-06-29 06:23:38 +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
Werner Lemberg
2ab0357d38 [base] Add no-overwrite hash insert functions.
* src/base/fthash.c (ft_hash_num_insert_no_overwrite,
  ft_hash_str_insert_no_overwrite): New functions.
* include/freetype/internal/fthash.h: Updated.
2025-06-26 05:46:58 +02:00
Werner Lemberg
820df38734 [base] Add iterators for FT_Hash.
* src/base/fthash.c (ft_hash_num_iterator, ft_hash_str_iterator): New
  functions.
* include/freetype/internal/fthash.h: Updated.
2025-06-26 05:46:58 +02:00
Werner Lemberg
58be4879c5 [truetype] Add comment to explain heuristic limit for twilight points. 2025-06-24 13:31:34 +02:00
Alexei Podtelezhnikov
43940e4cb8 [truetype] Restore non-persistent CVT and storage.
According to specifications, CVT and storage area may or may not be
persistent after modifications by a glyf program.  FreeType had always
reset them, which was broken by the last commit.

* src/truetype/ttinterp.c (TT_Load_Context): Set CVT and storage here.
* src/truetype.ttobjs.c (tt_size_run_prep): Prioritize TT_Load_Context.
(tt_size_init_bytecode): Allocate but not set CVT and storage area.
2025-06-23 11:04:43 -04:00
Alexei Podtelezhnikov
36ddd0cba1 [truetype] Deduplicate 'codeRangeTable'.
* src/truetype/ttinterp.c (TT_Load_Context, TT_Save_Context): Do not
copy 'codeRangeTable'.
* src/truetype/ttobjs.h (TT_Size): Remove 'codeRangeTable'.
(TT_CodeRange_Tag, TT_CodeRange, TT_DefArray): Moved to...
* src/truetype/ttinterp.h: ... this header.1
2025-06-22 12:13:48 -04:00
Alexei Podtelezhnikov
c9cbfacb80 [truetype] Simplify bytecode allocations.
To avoid repeated synchronization, some TT_Size allocations are moved
TT_ExecContext for good.  The memory blocks are also consolidated.

* src/truetype/ttinterp.c (TT_{Load,Save,Done}_Context): Remove
synchronization and stack management.
* src/truetype/ttobjs.c (tt_size_{init,done}_bytecode): Manage allocations
and assign them to the execution context.
(tt_size_run_prep): Updated.
2025-06-21 23:30:24 -04:00
Alexei Podtelezhnikov
4c2437efa7 [truetype] Rework handling of rendering mode in bytecode.
This replaces a large number of confusing boolean constructs that
describe the target rendering mode in the execution context with
the straight mode variable.  It might fix some hidden bugs when
FT_LOAD_TARGET_XXX were used as flags, which they are not.

The condition that triggers the CV program re-execution is simplified.
These events due the rendering mode change are rather rare and unexpected
and, therefore, should not be over-analyzed. In v40, all mode changes
now trigger the CV program. In v35, only switches to/from mono do.

* src/truetype/ttinterp.h (TT_ExecContext): Replace 'grayscale',
'grayscale_cleartype', 'subpixel_hinting_lean', and 'vertical_lcd_lean'
with the rendering 'mode'.
* src/truetype/ttinterp.c (Ins_GETINFO): Updated.
* src/truetype/ttgload.c (tt_loader_init): Replace 'prep' re-execution
trigger and update 'backward_compatibility' condition.
(tt_loader_set_pp): Updated.
2025-06-21 22:59:29 -04:00
Alexei Podtelezhnikov
0e38fa753f * src/truetype/{ttinterp.c,ttobjs.c}: Minor. 2025-06-20 22:22:05 -04:00
Alexei Podtelezhnikov
1977060439 [truetype] Clean up bytecode execution triggers.
This avoids executing the CV program twice and cleans up the use of
'fpgm' and 'prep' triggers

* src/truetype/ttgload.c (tt_loader_init): Call 'tt_size_init_bytecode'
and 'tt_size_run_prep' explicitly and avoid the call repetition.
* src/truetype/ttobjs.c (tt_size_ready_bytecode): Removed as unused.
(tt_size_init, tt_size_init_bytecode, tt_size_done_bytecode): Remove some
'fpgm' and 'prep' triggers and update.
(tt_size_run_fpgm, tt_size_run_prep): Do not set the pedantic flag here.
* src/truetype/ttobjs.h: Update signatures.
2025-06-20 21:48:14 -04:00
Alexei Podtelezhnikov
b647de097f * src/truetype/ttgload.c (tt_loader_init, load_sbit_image): Clean up. 2025-06-20 20:34:10 -04:00
Alexei Podtelezhnikov
2041c65cd2 [truetype] Simplify twilight zone management.
* include/freetype/internal/tttypes.h (TT_GlyphZone): Remove 'memory'.
* src/truetype/ttobjs.c (tt_glyphzone_done): Use 'memory' as argument.
(tt_glyphzone_new, tt_glyphzone_done): Allocate/free as a single block.
(tt_size_init_bytecode, tt_size_done_bytecode): Updated.
* src/truetype/ttobjs.h (tt_glyphzone_done): Updated signature.
2025-06-20 20:20:54 -04: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
Alexei Podtelezhnikov
738905b34b [truetype] Revise twilight zone initiation.
This assures that twilight zone is reset before each CV program
execution, including after the rendering mode switch. Fixes #1344.

* src/truetype/ttobjs.c (tt_size_ready_bytecode): Relocate the GS
the twilight zone initiation from here...
(tt_size_run_prep): ... to this function, sho that it is always
done prior to the CV program execution.
* src/truetype/ttobjs.c (TT_Run_Context): Set twilight zone here...
(TT_Load_Context): ... rather than here, as it used to be.
2025-06-14 20:18:48 -04:00
Alexei Podtelezhnikov
04f68052f0 * src/base/ftrfork.c (FT_Raccess_Get_DataOffsets): Remove check.
The highest (sign) attribute bit is reserved and should be zero.
It is harmless to omit this check however. Fixes #1342.
2025-06-12 21:02:57 -04: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
Alexei Podtelezhnikov
3c14c52523 [truetype] Clean up TT_GlyphZone.
* include/freetype/internal/tttypes.h (TT_GlyphZone): Delete fields.
* src/truetype/ttobjs.c (tt_glyphzone_new, tt_glyphzone_done,
tt_size_init_bytecode): Updated.
2025-06-11 15:32:11 -04:00
Alexei Podtelezhnikov
1529bc6e6e [truetype] Use FT_ARRAY_ZERO.
* src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Updated.
* src/truetype/ttobjs.c (tt_check_trickyness_sfnt_ids,
tt_size_ready_bytecode): Updated.
2025-06-11 07:58:51 -04:00
Alexei Podtelezhnikov
5ab9e5c5de [truetype] Rearrange bytecode run.
This is a minor change with large code rearrangements.

* src/truetype/ttinterp.c (TT_RunIns): Just loop through instructions
and move all setup to...
(TT_Run_Context): ... here; relocated.
(Compute_Round): Replaced by simple assignment, removed.
2025-06-11 07:58:51 -04:00
Alexei Podtelezhnikov
68c62e193f [truetype] Relocate the interpreter pointer.
This reduces dereferencing when calling the interpreter.

* include/freetype/internal/tttypes.h (TT_Face): Move it from here...
* src/truetype/ttinterp.h (TT_ExecContext): ... to here.
* src/truetype/ttobjs.c (tt_size_init_bytecode):  Move its initialization
* src/truetype/ttinterp.c (TT_New_Context): ... to here.
(TT_Run_Context): Updated.
2025-06-11 07:58:51 -04:00
Alexei Podtelezhnikov
ecfefd8ccd [truetype] Clean up the loader initiation.
* include/freetype/internal/tttypes.h (TT_LoaderRec): Remove unused field.
* src/truetype/ttgload.c (tt_loader_init): Refactor.
2025-06-11 07:58:51 -04:00
Alexei Podtelezhnikov
5631650b1e [truetype] Modify bytecode initiation.
This reduces the number of function calls and data copying events.

* src/truetype/ttinterp.c (TT_Goto_CodeRange): Merge into...
(TT_Set_CodeRange): ... this function.
(TT_Load_Context): Do not set up any zones, copy GS, or prepare the
execution...
(TT_Run_Context): ... do this here instead..
* src/truetype/ttinterp.c (TT_Set_CodeRange): Update signature.
* src/truetype/ttobjs.c (tt_size_run_fpgm, tt_size_run_prep): Call
TT_Run_Context.
* src/truetype/ttgload.c (TT_Hint_Glyph, tt_loader_init): Updated.
2025-06-11 07:58:51 -04:00
Alexei Podtelezhnikov
70281e0f9d [truetype] Modify the graphics state management.
Instead of restoring persistent GS variables, we only save modifications
permitted by the CVT program. This reduces the context manipulations.

* src/truetype/ttobjs.h (TT_GraphicsState): Reorder fields.
* src/truetype/ttobjs.c (tt_size_run_fpgm, tt_size_run_prep):
Do not alter the context.

* src/truetype/ttgload.c (TT_Hint_Glyph): Do not reset GS.
(tt_loader_init): Fix potential issue in 'instruct_control' handling.
* src/truetype/ttinterp.c (TT_Run_Context): Fully reset GS.
(TT_Load_Conext): Rearrange and remove the 'size' check, already
performed in FT_Load_Glyph.
(TT_Save_Context): Save only modifiable GS parts.
(tt_default_graphics_state): Updated.
* src/truetype/ttinterp.h (TT_Run_Context): Update signature.
2025-06-11 07:58:51 -04:00
Werner Lemberg
a67b2bab9e [gxvar] Really fix setting of named-instance to Regular.
This fixes an ommission in commit cf06661c51.

* src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Initialize `error`.
2025-06-10 12:11:41 +02:00
Werner Lemberg
d736e74177 Two more link fixes. 2025-06-10 05:29:47 +02:00
Werner Lemberg
7f559fbe9a Update links.
Found with `linkchecker --check-extern index.html` running locally in the
'freetype-web' repository.
2025-06-10 04:56:50 +02:00
Behdad Esfahbod
cf06661c51 Fix setting of named-instance to Regular
Fixes https://gitlab.freedesktop.org/freetype/freetype/-/issues/1341

And more elaborate avoidance of loading face->blend if all coords
are zero.
2025-06-07 06:29:51 +02:00
Alexei Podtelezhnikov
320b72a295 * src/type42/t42objs.c (T42_Size_Init): Fix uninitialized use.
Found by Ozkan Sezer.
2025-06-04 07:51:46 -04: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
5bc2081741 [build] Revise visibility attributes usage in autotools and CMake.
* CMakeLists.txt: Set `C_VISIBILITY_PRESET` to hidden for non-Windows only.
  Windows handles exports with `DLL_EXPORT` defined, and old MinGW
  toolchains emit a lot of warnings about visibility attributes not being
  supported in this configuration.

* build/unix/configure.raw: Revise visibility attributes checks by compiling a
  better test program with `-Werror` in `CFLAGS` so that warnings correctly
  indicate unsupported configurations.
2025-06-04 09:23:06 +02:00
Ozkan Sezer
81f839a7d9 * CMakeLists.txt: Add support for FT_CONFIG_OPTION_USE_HARFBUZZ_DYNAMIC.
This commit introduces a new CMake option `FT_DYNAMIC_HARFBUZZ`.
2025-06-04 09:12:41 +02:00