8450 Commits

Author SHA1 Message Date
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
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
Werner Lemberg
2adb53616a Replace 'www.freetype.org' with 'freetype.org'. 2025-06-03 10:35:16 +02:00
Ozkan Sezer
f0679e7592 * builds/unix/configure.raw: Fix HarfBuzz library detection for MinGW.
Set `have_harfbuzz*` variables explicitly to dynamic for MinGW, since
Windows uses its own `LoadLibrary` call.

This fixes a MinGW configuration error:

```
checking for HARFBUZZ... no
checking for dlopen in -lc... no
checking for dlopen in -ldl... no
configure: error: harfbuzz support requested but library not found
```
2025-06-03 09:24:04 +02:00
Ozkan Sezer
3eb5188e8e * builds/unix/configure.raw: Improve check for dlopen.
Look for `dlopen` first in 'libc', then in 'libdl'.
2025-06-03 08:41:23 +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
5a07f41d0e [sfnt] FT_Load_Sfnt_Table can now also load a font's table directory.
Closes issue #1263.

* src/sfnt/ttload.c (tt_face_load_any): Implement it.
2025-05-28 09:52:44 +02:00
Werner Lemberg
3aeabbf87d [gzip] Update sources to zlib 1.13.1.
Fixes issue #1294.
2025-05-28 07:31:57 +02:00
Vítor Ramos
202297eb5c * src/base/ftobjs.c (FT_Load_Glyph): Loosen auto-hinting constraints.
Fixes issue #1320.
2025-05-27 13:57:05 +02:00
Werner Lemberg
d629c8bffa Update CHANGES file. 2025-05-27 08:41:13 +02:00
Behdad Esfahbod
f7fba637a4 [gxvar] Optimize out more bounds checking.
Big win, ~20% in measured mega-var font, HarfBuzz's `benchmark-font`
'glyph_h_advances' benchmark.

* src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Implement it in
  loops.
2025-05-27 08:30:53 +02:00
Behdad Esfahbod
c062514088 * src/truetype/ttgload.c (load_truetype_glyph): Use IS_DEFAULT_INSTANCE. 2025-05-27 07:08:03 +02:00
Behdad Esfahbod
f64c7db2fe [gxvar] Set doblend to FALSE if at default location.
* src/truetype/ttgxvar.c (tt_set_mm_blend, TT_Get_Var_Design): Do it.
2025-05-27 07:01:02 +02:00
Behdad Esfahbod
fa412cf5c5 [mm/gxvar] Always detect default instance and use optimized codepath.
Even if it was explicitly set by either design or normalized APIs.

Also update documentation.

* src/truetype/ttgxvar.c (TT_Set_MM_Blend, TT_Set_Var_Design): Use value -2
  of `error` to indicate that we have a non-default instance.
  (TT_Set_Named_Instance): Updated.

* src/base/ftmm.c (FT_Set_Var_Design_Coordinates,
  FT_Set_Var_Blend_Coordinates): Updated.
2025-05-27 07:00:08 +02:00
Alexei Podtelezhnikov
deef6d2a3c Typo. 2025-05-26 23:16:30 -04:00
Alexei Podtelezhnikov
31d05d089b * src/truetype/ttinterp.c (TT_Load_Context): Clean up. 2025-05-26 23:13:52 -04: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
e07e56c7f1 [gxvar] Speed up handling of deltas in ItemVariationStore. (3/3)
* src/base/ftcalc.c (FT_MulAddFix): Removed, no longer needed.
* include/freetype/internal/ftcalc.h: Updated.
2025-05-26 17:22:13 +02:00
Behdad Esfahbod
86ab14e03f [gxvar] Speed up handling of deltas in ItemVariationStore. (2/3)
Do all math in fixed integer and do a single divide at the end.

Also don't use an array to read deltas; just read them as we go, and skip
(branch-free) when scalar is 0.

30% speedup in measured mega-var font, HarfBuzz's `benchmark-font`
'glyph_h_advances' benchmark.
2025-05-26 17:22:11 +02:00
Behdad Esfahbod
fe6854ba57 [gxvar] Speed up handling of deltas in ItemVariationStore. (1/3)
* src/truetype/ttgxvar.c (ft_mul_add_delta_scalar, ft_round_and_shift16):
  New functions, reusing code from `ftcalc.c`.
2025-05-26 17:22:09 +02:00