8450 Commits

Author SHA1 Message Date
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
Werner Lemberg
013adc82b9 * src/truetype/ttgxvar.c (ft_var_apply_tuple): Remove redundant test.
This was erroneously added in commit e6e9110a8.
2025-05-21 17:28:52 +02:00
ColdPaleLight
11fa9da720 [sdf] Skip neighbor comparison for pixels near edges.
If the distance of the current pixel to the edge is less than or equal
to 0.5, skip further neighbor comparisons to avoid unnecessary
calculations. When the `USE_SQUARED_DISTANCES` macro is defined,
compare to 0.25 instead.

* src/sdf/ftbsdf.c (compare_neighbor): Add early return for pixels
  close to edges to avoid unnecessary neighbor checks.
2025-05-21 12:51:45 +00:00
Behdad Esfahbod (بهداد اسفهبد)
d7b6e947a3 [gxvar] Cache shared-tuple scalar values.
GoogleSansFlex HB benchmark-font draw results:

  Before:  2.13ms
  After:   1.65ms
  Speedup: 22%

* src/truetype/ttgxvar.h (GX_BlendRec): Add `tuplescalars` field.

* src/truetype/ttgxvar.c (ft_var_load_gvar): Allocate `tuplescalars` array.
  (tt_set_mm_blend): Set its values.
  (TT_Vary_Apply_Glyph_Deltas): Use it.
  (tt_done_blend): Deallocate it.
2025-05-21 14:39:22 +02:00
Behdad Esfahbod (بهداد اسفهبد)
582de1a4b6 [gxvar] Reduce number of mallocs.
8% speed up in drawing GoogleSansFlex variable in HB benchmark-font.

* src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Use an allocation
  pool instead of individual allocations.
2025-05-21 14:39:22 +02:00
Behdad Esfahbod (بهداد اسفهبد)
fd92af79d8 [gxvar] Another optimization in computing scalar.
Another ~6% speedup in GoogleSansFlex var drawing.

* src/truetype/ttgxvar.c (ft_var_apply_tuple): Test `ncv` for being zero.
2025-05-21 14:39:22 +02:00
Behdad Esfahbod (بهداد اسفهبد)
e7cc14ba16 [gxvar] Remove stale comment.
The code *does* check against start/end!
2025-05-21 14:39:20 +02:00
Behdad Esfahbod (بهداد اسفهبد)
e6e9110a8f * src/truetype/ttgxvar.c (ft_var_apply_tuple): Micro-optimize. 2025-05-21 14:16:11 +02:00
Behdad Esfahbod (بهداد اسفهبد)
14399c73c4 [gxvar] Inline two USHORT reads.
Speeds up GoogleSansFlex variable glyph drawing by ~13%.

  Before: 2.95ms
  After:  2.57ms

* src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Do it.
2025-05-21 14:14:02 +02:00
Behdad Esfahbod (بهداد اسفهبد)
0a574d50e8 [gxvar] Micro-optimize loop end condition.
* src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Do it.
2025-05-21 14:01:12 +02:00
Behdad Esfahbod
dc8efeff2a [truetype] Don't process mvar metrics if default instance.
GoogleSansFlex default-instance HarfBuzz benchmark-font draw:

  Before:  0.610ms
  After:   0.435ms
  Speedup: 28%

* src/truetype/ttobjs.c (tt_face_init) [TT_CONFIG_OPTION_GX_VAR_SUPPORT]:
  Check `instance_index`.
2025-05-21 09:09:01 +02:00
Alexei Podtelezhnikov
22511643da * src/truetype/ttinterp.c (Ins_MIRP,DELTAP,DELTAC): Minor. 2025-05-20 22:18:19 -04:00
Alexei Podtelezhnikov
8b4dcd935e [truetype] Update bytecode error handling.
* src/truetype/ttinterp.c (Ins_SHP,SHPIX,ALIGNRP): Return appropriate
error in case of stack underflow.
(Ins_IP): Ditto and remove redundant check.
2025-05-20 17:27:43 -04: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
Werner Lemberg
46edeb321c * src/afadjust.c (adjustment_database): Make it complete up to U+FFFF.
Also fix two entries.

This is for Unicode 17.0.
2025-05-19 05:14:25 +00:00
Werner Lemberg
d3fbbed91f [autofit] Fix vertical adjustment of (mainly) double diacritics.
The series of commits that introduced this adjustment support had some
flaws.

- If there were two diacritics on top of a base glyph, and the upper
  diacritic was a tilde, the vertical centering correction was incorrectly
  applied to the lower, non-tilde glyph instead of the tilde.

- The maximum value allowed to shift a glyph was too strict (and also not
  handling rounding issues), causing some diacritics and combinations of
  diacritics to be not shifted at all.

* src/autofit/aflatin.c
  (af_glyph_hints_apply_vertical_separation_adjustments): Correctly handle
  vertical centering correction.
2025-05-19 05:14:25 +00:00
Werner Lemberg
4c9f14f422 [autofit] Code hygiene.
* src/autofit/aflatin.c
  (af_glyph_hints_apply_vertical_separation_adjustments): Use more flag
  variables and improve trace messages.
2025-05-19 05:14:25 +00:00
Werner Lemberg
11432424cf * src/autofit/aflatin.c (af_latin_hint_edges): Fix handling of serifs.
This has been discovered while inspecting the auto-hinting results of
character 'Ễ' in font `arial.ttf` (version 7.00) at 13ppem.
2025-05-19 05:14:25 +00:00
Werner Lemberg
87f0b694af [autofit] Minor.
* src/autofit/aflatin.c (af_latin_hint_edges): Rename `has_serifs` to
  `has_non_stem_edges` and make it of type `FT_Bool`.
2025-05-19 05:14:25 +00:00
Werner Lemberg
fd66a29d10 [autofit] New algorithm for preventing hinting of tilde glyphs.
The old algorithm removed segments from edges to make the auto-hinter ignore
a tilde.  However, the implementation had two flaws.

- Edge array elements were moved around without reordering them afterwards.
- The linking between edges and segments wasn't correctly updated for moved
  edges, which could cause endless loops.

Correcting both problems are non-trivial; additionally, a fix would make
the auto-hinter slower.

For these reasons, a new, simpler approach is taken: A new flag allows
points to be tagged as being ignored, and if such a point is enountered, it
doesn't get added to a segment.

Fixes issue #1333.

* src/autofit/afhints.h (AF_FLAG_IGNORE): New macro.

* src/autofit/aflatin.c (af_latin_hints_compute_segments, af_touch_contour):
  Use it.
  (af_remove_segments_containing_point, af_remove_top_points_from_edges,
  af_remove_bottom_points_from_edges): Removed.
  (af_latin_stretch_top_tilde): Call `af_touch_top_contours` and
  `af_touch_bottom_contours` unconditionally.
  (af_latin_hints_apply): Updated.
2025-05-19 05:14:25 +00:00
Alexei Podtelezhnikov
89e3e98e47 * src/truetype/ttinterp.c (TT_DotFix14): Silence UBSAN. 2025-05-16 13:19:26 -04:00
Alexei Podtelezhnikov
8082aba5f2 * src/truetype/ttinterp.c (Ins_DELTAP): Flip if-else. 2025-05-15 22:27:52 -04:00
Alexei Podtelezhnikov
7172bd11ba [truetype] Optimize DELTAP and DELTAC.
* src/truetype/ttinterp.c (Ins_DELTAP,DELTAC): Perform PPEM range-
checking and manipulations outside the loop.
2025-05-14 23:17:23 -04:00
Alexei Podtelezhnikov
8a152c824a * src/truetype/ttinterp.c (Compute_Funcs): Replace shifts. 2025-05-14 14:56:21 -04:00
Alexei Podtelezhnikov
828916527c [truetype] Tighten code overflow checks.
Fixes #1336.

* src/truetype/ttinterp.c (Ins_NPUSHB,NPUSHW,PUSHB, PUSHW):
Tighten conditions.
2025-05-14 12:45:53 -04:00
Chris Liddell
0fcd10ee7e [type1] Fix memory leak on CharString error.
In the event that a CharString retrieved via the incremental interface
caused an error, the memory for that CharString was not being freed.

* src/type1/t1gload.c (T1_Parse_Glyph_And_Get_Char_String): Free charstring.
2025-05-14 11:09:17 +02:00
Werner Lemberg
15b7e8c3a9 Whitespace, formatting, minor spelling fix. 2025-05-14 10:20:04 +02:00
Werner Lemberg
8d18acba8c Adminstrativa. 2025-05-14 09:16:57 +02:00