Commit graph

8327 commits

Author SHA1 Message Date
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
Behdad Esfahbod
8eae039923 Lift FT_Int64 type to global (internal) FreeType use.
* src/base/ftcalc.c (FT_Int64) [!FT_INT64]: Move declaration to...
* include/freetype/config/integer-types.h: ... this file.
  (FT_UInt64) [!FT_INT64]: New structure.
  (FT_INT64_ZERO): New macro.
2025-05-26 08:24:21 +02:00
Behdad Esfahbod
b8444f2fbb [gxvar] Move scalar computation into its own function.
* src/truetype/ttgxvar.c (tt_var_get_item_delta): Split off affected code
  into...
  (tt_calculate_scalar): ...this new function.
2025-05-26 08:23:52 +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
Alexei Podtelezhnikov
87501e2e72 [trueetype] Remove useless assignments.
* src/truetype/ttobjs.c (tt_size_run_fpgm): Remove assignment that
is ignored and overridden later in 'Compute_Funcs'.
* src/truetype/ttinterp.c (TT_RunIns): Ditto.
(Ins_MIAP): Formatting.
2025-05-25 22:21:21 -04: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
Behdad Esfahbod
5987a9f51d [ttmtx] Fix check for being non-default variation position.
If user explicitly sets variations to `NULL` after it being set to something
else, `face->blend` will still be non-`NULL`.  The intention here however is
correctly captured by `FT_IS_VARIATION`.

* src/sfnt/ttmtx.c (tt_face_get_metrics): Use `FT_IS_VARIATION`.
2025-05-23 08:23:51 +02:00
Behdad Esfahbod
75b84313cf [gxvar] Optimize loading of 'gvar' table.
* src/truetype/ttgxvar.c (tt_var_load_item_variation_store,
  tt_var_load_delta_set_index_mapping, ft_var_load_gvar): Use frames to
  reduce bounds checking.
  (TT_Vary_Apply_Glyph_Deltas): Better macro usage.
2025-05-23 08:06:02 +02:00
Behdad Esfahbod
42a649be49 [mm] Short-circuit setting face to default instance if already is so.
I found that in hb-ft I need to sometime reset the face to the default
instance.  However, calling `FT_Set_Var_Design_Coordinates` with no coords
was still slowing down at least the glyph-advance code by processing
variations.

Perhaps there's a better fix, but this handles the easy cases.

* src/base/ftmm.c (FT_Set_Var_Design_Coordinates): Implement it.
2025-05-22 05:12:07 +02:00
Behdad Esfahbod
702e4a1d32 * src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Fix allocation.
Bug was introduced in commit 582de1a4b6.
2025-05-22 04:57:17 +02:00