Commit graph

8276 commits

Author SHA1 Message Date
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
Alexei Podtelezhnikov
408957dca0 [truetype] Finalize bytecode changes.
* src/truetype/ttinterp.c: Formatting, minor.
(TT_Goto_CodeRange): Initialize 'iniRange' here...
(TT_RunIns): ... instead of here.
* docs/CHANGES: Updated.
2025-05-13 17:07:31 -04:00
Alexei Podtelezhnikov
2f2dfad597 [truetype] Streamline backward compatibility.
The 'backward_compatibility' is only set in v40: no need to check
the interpreter version again and again. In addition, we now track
IUP in its lower bits.  After both IUPx and IUPy have been called,
'backward_compatibility' becomes equal to 0x7.

* src/truetype/ttinterp.h (TT_ExecContextRec): Wrap 'iup?_called'
into 'backward_compatibility'.
* src/truetype/ttinterp.c (Ins_INSTCTRL): Sync 'backward_compatibility'.
(Direct_Move, Direct_Move_X/Y, Move_Zp2_Point,
Ins_FLIPPT,FLIPRGON,FLIPRGOFF,SHPIX,DELTAP): Updated.
(TT_RunIns): Do not mess with IUP flags.
* src/truetype/ttgload.c (tt_loader_init): Set 'backward_compatibility'.
(TT_Hint_Glyph): Updated.
2025-05-13 09:15:06 -04:00
Alexei Podtelezhnikov
4792cff5c3 [truetype] Optimize bytecode movements.
Replacing FT_MulDiv with FT_MulFix gives large performance gains.

* src/truetype/ttinterp.h (TT_ExecContextRec): Store "projected"
freedom vector.
* src/truetype/ttinterp.c (Compute_Funcs): Compute "projected"
freedom vector.
(Direct_Move, Direct_Move_Orig, Compute_Point_displacement): Use it.
2025-05-10 14:10:26 -04:00
Alexei Podtelezhnikov
55e60b9f53 [truetype] Simplify stack access.
* src/truetype/ttinterp.c (Ins_MINDEX,CINDEX): Use local stack pointers.
(Ins_DELTAP,DELTAC): Ditto; limit the number of pairs before looping.
2025-05-10 14:10:26 -04:00
Alexei Podtelezhnikov
c71b9dad3f [truetype] Tweak bytecode looping.
* src/truetype/ttinterp.c (Ins_FLIPPT,SHP,SHPIX,IP,ALIGNRP): Handle
counters and stack locally.
(TT_RunIns): Updated.
2025-05-10 14:10:26 -04:00
Alexei Podtelezhnikov
8c04ecd890 [truetype] Tweak bytecode initiation.
* src/truetype/ttinterp.c (TT_Load_Context): Init stack tops.
* src/truetype/ttinterp.h (TT_ExecContextRec): Document it and clean.
* src/truetype/ttobjs.c (tt_size_run_prep,fpgm): Updated.
* src/truetype/ttgload.c (tt_loader_init): Minor.
2025-05-10 14:10:26 -04:00
Alexei Podtelezhnikov
c3a5513508 [truetype] Modify stack handling.
* src/truetype/ttinterp.c (Ins_GETVARIATION): Increment stack.
(Ins_NPUSHB,NPUSHW,PUSHB,PUSHW): Handle the code stack here, ...
(TT_RunIns): ... instead of here. Consolidate error handling.
(SkipCode): Remove preemptive check.
2025-05-10 14:10:26 -04:00
Alexei Podtelezhnikov
b0febf5d91 [truetype] Modify bytecode steps.
* src/truetype/ttinterp.h (TT_Exec_ContextRec): Remove 'step_ins'.
* src/truetype/ttinterp.c (TT_RunIns, Ins_Goto_CodeRange,
Ins_JMPR,ENDF,PUSHW,NPUSHW): Set and use zero increment 'length' instead.
(Ins_CALL,LOOPCALL,UNKNOWN): Updated.
2025-05-10 14:10:25 -04:00
Werner Lemberg
3e079bd75e [autofit] Add safety check for accent adjustments.
This commit does two things.

- Ignore accents that have too large heights.  This situation can happen if
  an accent outline is unexpectedly not the highest (or lowest) contour.
- Add a new adjustment flag `AF_ADJUST_NO_HEIGHT_CHECK` to override the
  height check.

* src/autofit/afadjust.h (AF_ADJUST_NO_HEIGHT_CHECK): New macro.

* src/autofit/afadjust.c (adjustment_database): Updated.

* src/autofit/aflatin.c (af_latin_hints_apply): Handle new flag.
  (af_glyph_hints_apply_vertical_separation_adjustments): Check limit.
2025-05-10 05:03:48 +00:00
Werner Lemberg
d32c637d6e [autofit] Better handling of characters with attached diacritics. (3/3)
Fixes issue #136.

* src/autofit/afadjust.c (adjustment_database): Updated.
2025-05-10 05:03:48 +00:00
Werner Lemberg
620daa3c6a [autofit] Better handling of characters with attached diacritics. (2/3)
* src/autofit/afadjust.h (AF_IGNORE_CAPITAL_TOP, AF_IGNORE_CAPITAL_BOTTOM,
  AF_IGNORE_SMALL_TOP, AF_IGNORE_SMALL_BOTTOM): New macros.

* src/autofit/afadjust.c (af_reverse_character_map_new)
  [FT_DEBUG_LEVEL_TRACE]: Updated.
  Also fix debugging strings of other flags.

* src/autofit/afhints.h (AF_EDGE_NO_BLUE): New edge flag to make the
  auto-hinter ignore the edge while assigning blue zones.

* src/autofit/aflatin.c (af_latin_hints_compute_blue_edges): Use it.
  (af_prevent_top_blue_alignment, af_prevent_bottom_blue_alignment,
  af_latin_get_base_glyph_blues, af_latin_ignore_top,
  af_latin_ignore_bottom): New functions.
  (af_latin_hints_apply): Updated.
2025-05-10 05:03:48 +00:00
Werner Lemberg
a37e11c379 [autofit] Better handling of characters with attached diacritics. (1/3)
Introduce blue zone properties that will be used to make the auto-hinter
ignore diacritics attached on the top or the bottom of a base character.

* src/autofit/afblue.hin (AF_BLUE_PROPERTY_LATIN_CAPITAL_BOTTOM,
  AF_BLUE_PROPERTY_LATIN_SMALL_BOTTOM): New properties.
* src/autofit/afblue.dat: Use them.

* src/autofit/afblue.c, src/autofit/afblue.h: Rengenerated.

* src/autofit/aflatin.h (AF_LATIN_IS_CAPITAL_BOTTOM_BLUE,
  AF_LATIN_IS_SMALL_BOTTOM_BLUE, AF_LATIN_BLUE_BOTTOM,
  AF_LATIN_BLUE_BOTTOM_SMALL): New macros.

* src/autofit/aflatin.c (af_latin_metrics_init_blues)[FT_DEBUG_LEVEL_TRACE]:
  Updated.
2025-05-10 05:03:48 +00:00
Alexei Podtelezhnikov
9629cc0e83 * src/raster/ftraster.c (Line_Up): Use 64-bit calculations.
Attempt to fix #1332.
2025-05-09 16:31:16 -04:00
Werner Lemberg
6fa8725a41 [sfnt] Avoid allocation bomb in compressed SVG documents.
Reported as

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

* src/sfnt/ttsvg.c (MAX_SVG_SIZE): New macro.
  (tt_face_load_svg_doc): Reject too large buffer.
2025-05-09 13:27:51 +02:00
Werner Lemberg
04455084cf * include/freetype/ttnameid.h (TT_UCR_*): Define with unsigned long.
(TT_UCR_PHAGSPA): Fix definition.

Fixes issue #1300.
2025-05-08 07:49:10 +02:00
Werner Lemberg
c2789e7558 [doc] Mention that there is no rendering support for 'COLR' v1 tables.
Handles issue #1319.
2025-05-08 07:03:31 +02:00
Alexei Podtelezhnikov
35513a4d9b * src/truetype/ttinterp.c (TT_DotFix14): Silence UBSAN. 2025-05-07 18:53:21 -04:00
Alexei Podtelezhnikov
c1278179dc * src/cff/cffgload.c (cff_slot_load): Fix autohinter scaling.
Fixes #1330.
2025-05-07 17:57:42 -04:00
Werner Lemberg
ab0fe6d55e [autofit] Avoid division by zero.
Fixes issue #1331.

* src/autofit/aflatin.c (af_latin_stretch_bottom_tilde): Don't divide by
  zero.
2025-05-05 19:38:04 +02:00
Carlo Bramini
c26c150cf2 Fix Cygwin visibility attributes.
Reported as compilation warnings in #1329.

* include/freetype/config/public-macros.h: Check __CYGWIN__.
* include/freetype/internal/compiler-macros.h: Ditto.
2025-05-04 07:22:46 -04:00
KatekovAnton
bff01fbdcc * CMakeLists.txt: Fix cmake 4 error by specifying the policy version. 2025-05-03 09:53:14 +02:00
Werner Lemberg
79912716e7 * docs/CHANGES: Updated. 2025-04-29 19:18:12 +00:00
Behdad Esfahbod (بهداد اسفهبد)
5d2fd7608a Provide configuration option to dynamically load the HarfBuzz library.
We now request HarfBuzz version 2.6.8 (published in June 2020) or newer to
simplify the setup; this version introduced function
`hb_ot_layout_lookup_get_glyph_alternates`, which we need for the adjustment
database of the auto-hinter.

No CMake support yet for dynamic loading.

* include/freetype/config/ftoption.h, devel/ftoption.h
  (FT_CONFIG_OPTION_USE_HARFBUZZ_DYNAMIC): New configuration macro.

* builds/unix/configure.raw: Implement `--with-harfbuzz=dynamic`.
  This gets tested automatically if we can't link with `libharfbuzz`.
  (ft_option_set, ft_option_unset): Refine.
  Require at least HarfBuzz version 2.6.8.

* meson.build: Do the same as `configure.raw`.
* meson_options.txt: Updated.

* CMakeLists.txt: Require at least HarfBuzz version 2.6.8.
2025-04-29 19:18:12 +00:00
Behdad Esfahbod (بهداد اسفهبد)
97bb53ee0a [autofit] Enable dynamic loading of HarfBuzz. (2/2)
Handle the case where loading HarfBuzz dynamically fails.

* src/autofit/ft-hb.c, src/autofit/ft-hb.h (ft_hb_enabled): New function.

* src/autofit/afglobal.c (af_face_globals_new, af_face_globals_free):
  Guard HarfBuzz functions with `ft_hb_enabled`.

* src/autofit/aflatin.c (af_latin_metrics_init_widths,
  af_latin_metrics_init_blues, af_latin_metrics_check_digits): Simplify
  setup of `shaper_buf`.
  Guard calls of `af_shaper_buf_create` with `ft_hb_enabled`.

* src/autofit/afcjk.c (af_cjk_metrics_init_widths,
  af_cjk_metrics_init_blues, af_cjk_metrics_check_digits): Dito.

* src/autofit/afshaper.c: Guard all HarfBuzz function calls with
  `ft_hb_enabled`.
2025-04-29 19:18:12 +00:00