1
0
mirror of https://github.com/freetype/freetype.git synced 2025-04-18 11:24:00 +03:00

8186 Commits

Author SHA1 Message Date
Werner Lemberg
9536e4728f * src/autofit/afadjust.c (af_reverse_character_map_new): Check map limit.
Reported as

  https://issues.chromium.org/issues/410925355
2025-04-18 06:36:18 +02:00
Alexei Podtelezhnikov
6ed79d5b7a * include/freetype/internal/ftcalc.h: Fix fringe compilation. 2025-04-17 22:46:06 -04:00
Alexei Podtelezhnikov
4fad257a7e * src/base/ftcalc.c (ft_corner_orientation) [!FT_INT32]: Fix up. 2025-04-17 22:32:21 -04:00
Werner Lemberg
d6c2922875 [autofit] Don't access uninitialized memory.
Reported as

  https://bugs.ghostscript.com/show_bug.cgi?id=708295

* src/autofit/aflatin.c
  (af_glyph_hints_apply_vertical_separation_adjustments): Initialize all
  array elements of `contour_y_minima` and `contour_y_maxima`.
2025-04-17 19:36:51 +02:00
Alexei Podtelezhnikov
66e0d25ecb * src/truetype/ttinterp.c (TT_MulFix14,TT_DotFix14)[!FT_INT64]: Sync. 2025-04-17 15:37:27 +00:00
Alexei Podtelezhnikov
9eecaa0788 * src/truetype/ttinterp.c (TT_DotFix14): Silence UBSAN. 2025-04-17 12:44:37 +00:00
Alexei Podtelezhnikov
0a650e8c52 * src/base/ftcalc.c: Miscellaneous cleanups. 2025-04-16 22:54:54 -04:00
Werner Lemberg
cc849c32cf [autofit] Avoid crash.
Reported as

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

* src/autofit/aflatin.c (af_remove_segments_containing_point): Check
  `edge->last`.
2025-04-16 19:42:02 +02:00
Alexei Podtelezhnikov
ccabe7ac02 [base, truetype] Silence UBSAN (cont'd).
* src/truetype/ttinterp.c (TT_MulFix14, TT_DotFix14): Use MUL_INT64.
* include/freetype/internal/ftcalc.c (FT_MulFix): Ditto.
2025-04-15 18:49:36 +00:00
Werner Lemberg
dc55f4e6c1 [autofit] Avoid unnecessary recomputation of HarfBuzz data.
Call the functions once per font instead of once per glyph.

* src/autofit/afadjust.c (af_all_glyph_variants): Move code to compute the
  `feature_tags` and `type_3_lookup_indices` sets to...
  (af_reverse_character_map_new): ...this function.
2025-04-15 12:54:54 +02:00
Werner Lemberg
d1ac9524fd [autofit] Fix creation of the adjustment database's reverse map.
Due to the way the reverse map array gets constructed with HarfBuzz, there
might be multiple, identical glyph index entries with different character
values in the array.  As an example, an OpenType feature like 'unic' might
map lowercase glyph 'ae' to uppercase glyph 'AE', in addition to the already
present cmap entry for 'AE'.

In most cases, this incorrect mapping is harmless (but still wrong).
However, there exist some lowercase/uppercase character pairs where the
diacritic for the uppercase character is on the other vertical side of the
base character as for the lowercase character.  An example is U+0122 (LATIN
CAPITAL LETTER G WITH CEDILLA) and U+0123 (LATIN SMALL LETTER G WITH
CEDILLA): the former has the cedilla below, the latter above.  A wrong
mapping would thus shift the base glyph 'G' up by a pixel instead of
shifting the cedilla down.

We fix this by always giving precedence to cmap entries.

* src/autofit/afadjust.c (af_reverse_character_map_entry_compare): Do a
  secondary sort on the character code.

  (af_reverse_character_map_lookup): Adjust binary search to return the
  first occurrence of an entry (i.e., the one with the lowest array index).

  (af_reverse_character_map_new)[FT_CONFIG_OPTION_USE_HARFBUZZ]: Implement
  cmap priority.
2025-04-15 12:53:34 +02:00
Werner Lemberg
057970696d [autofit] Reduce adjustment database lookups.
This is also in preparation for a follow-up commit.

* src/autofit/afadjust.h (af_lookup_vertical_separation_type,
  af_lookup_tilde_correction_type): Replaced with...
  (af_adjustment_database_lookup, af_reverse_character_map_lookup):
  ... this.

* src/autofit/afadjust.c (af_adjustment_database_lookup,
  af_adjustment_database_lookup): Updated.
  (af_lookup_vertical_separation_type, af_lookup_tilde_correction_type):
  Removed.
  (af_reverse_character_map_new)[FT_DEBUG_LEVEL_TRACE]: Updated.

* src/autofit/aflatin.c
  (af_glyph_hints_apply_vertical_separation_adjustments,
  af_latin_hints_apply): Updated.
2025-04-15 12:46:16 +02:00
Werner Lemberg
233cdea8f4 * src/afadjust.c (adjustment_database): Make it complete up to U+017F. 2025-04-15 12:46:16 +02:00
Werner Lemberg
535498a0f9 * src/autofit/afadjust.c (af_reverse_character_map_new): Add tracing code. 2025-04-15 12:46:16 +02:00
Werner Lemberg
c34e551cad * src/afadjust.c: Minor fixes. 2025-04-15 12:46:14 +02:00
Werner Lemberg
218c59a292 [autofit] Better vertical separation adjustment support. (2/2)
* src/autofit/aflatin.c
  (af_glyph_hints_apply_vertical_separation_adjustments): Handle diacritics
  with more than a single contour.
2025-04-15 12:45:09 +02:00
Werner Lemberg
52d4573e50 [autofit] Better vertical separation adjustment support. (1/2)
Test vertical maxima instead of vertical minima to identify the highest
contour (and vice versa to identify the lowest contour).  Doing so will
allow support of diacritics that consist of more than a single outline.

This works because of the topological constraints ensured by the adjustment
database.

* src/autofit/aflatin.c (af_find_highest_contour,
  af_glyph_hints_apply_vertical_separation_adjustments): Implement it.
2025-04-15 12:45:09 +02:00
Werner Lemberg
c6106cffe2 [autofit] Use new y extrema arrays.
* src/autofit/aflatin.c
  (af_glyph_hints_apply_vertical_separation_adjustments): Implement it.
2025-04-15 12:45:09 +02:00
Werner Lemberg
8d49ccd672 [autofit] Provide infrastructure for storing y extrema of contours.
We need this for better positioning support of diacritics.

* src/autofit/afhints.h (AF_GlyphHintsRec): New fields `contour_y_minima`
  and `contour_y_maxima`, together with its embedded variants.

* src/autofit/afhints.c (af_glyph_hints_done, af_glyph_hints_reload): Handle
  new arrays.
2025-04-15 12:45:09 +02:00
Werner Lemberg
53a5e2e65b [autofit] Avoid crash.
Reported as

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

* src/autofit/aflatin.c (af_remove_segments_containing_point): Check `edge`.
2025-04-15 06:58:52 +02:00
Werner Lemberg
558bde6e39 [autofit] Fix just introduced heap buffer overflow
Reported as

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

* src/autofit/afadjust.c [!FT_CONFIG_OPTION_USE_HARFBUZZ]: Synchronize with
  HarfBuzz code.
2025-04-14 21:37:18 +02:00
Werner Lemberg
ae3879c0a1 * docs/CHANGES: Mention Craig's GSoC 2023 project. 2025-04-14 06:51:01 +02:00
Craig White
24ac6c5d6a [autofit] Add GSUB table handling to reverse character map generation.
If HarfBuzz is enabled, the reverse character map generation now considers
GSUB entries when looking for glyphs that correspond to a code point.

* src/autofit/afadjust.c (af_all_glyph_variants_helper,
af_all_glyph_variants) [FT_CONFIG_OPTION_USE_HARFBUZZ]: New functions.

(af_reverse_character_map_new) [FT_CONFIG_OPTION_USE_HARFBUZZ]: Call new
code.
2025-04-14 06:50:00 +02:00
Craig White
771449f14a [autofit] Add tilde-unflattening algorithm.
* src/autofit/aflatin.c (af_find_highest_contour,
af_remove_segments_containing_point,
af_latin_remove_tilde_points_from_edges, af_latin_stretch_tilde,
af_latin_align_tilde): New functions.
(af_latin_hints_apply): Call tilde-unflatting code if necessary.
2025-04-14 06:50:00 +02:00
Craig White
7099b09e96 [autofit] Implement vertical separation adjustment.
* src/autofit/aflatin.c: Include `afadjust.h`.
(af_latin_metrics_init): Call `af_reverse_character_map_new`.
(af_latin_metrics_done): New function.

(af_move_contour_vertically, af_check_contour_horizontal_overlap,
af_glyph_hints_apply_vertical_separation_adjustments): New functions.

(af_latin_hints_apply): Call
`af_glyph_hints_apply_vertical_separation_adjustments`.

(af_latin_writing_system_class): Updated.

* src/autofit/aftypes.h (AF_StyleMetricsRec): Add `reverse_charmap` field.
2025-04-14 06:50:00 +02:00
Craig White
14ac6140fc [autofit] Add code for reverse charmaps and adjustment database lookup.
* src/autofit/aftypes.h (AF_ReverseMapEntry, AF_ReverseCharacterMap): New
structures.

* src/autofit/afadjust.c (af_adjustment_database_lookup,
af_reverse_character_map_entry_compare, af_reverse_character_map_lookup,
af_lookup_vertical_separation_type, af_lookup_tilde_correction_type,
af_reverse_character_map_expand, af_reverse_character_map_new,
af_reverse_character_map_done): New functions.

* src/autofit/afadjust.c: Updated.
2025-04-14 06:50:00 +02:00
Craig White
c46ebd7650 [autofit] Add adjustment database.
* src/autofit/afadjust.c, src/autofit/afadjust.h: New files.

* include/freetype/internal/fttrace.h: Add 'afadjust' component.

* src/autofit/autofit.c: Include `afadjust.c`.

* src/autofit/rules.mk (AUTOF_DRV_SRC): Add `afadjust.c`.
2025-04-14 06:50:00 +02:00
Craig White
f0660df3a9 [base] Make find_unicode_charmap a base function.
This is needed for forthcoming changes in the auto-hinter.

* include/freetype/internal/ftobjs.h, src/base/ftobjs.c: Updated.
2025-04-14 06:50:00 +02:00
Alexei Podtelezhnikov
6b6b643f7f * src/bdf/bdflib.c (hdigits): Removed.
Fixes #1325.
2025-04-12 15:06:59 -04:00
Alexei Podtelezhnikov
5416689d95 * include/freetype/internal/ftcalc.h (FT_MSB) [__CC_ARM]: Added. 2025-04-12 12:38:01 -04:00
Alexei Podtelezhnikov
58b3598c2a Typos in macros.
* include/freetype/internal/ftcalc.h: s/_M_X86/_M_IX86/.
* src/truetype/ttinterp.c: s/_M_X86/_M_IX86/.
2025-04-12 09:18:16 -04:00
Alexei Podtelezhnikov
f0acd2038a * docs/CHANGES: Updated. 2025-04-12 08:41:27 -04:00
Alexei Podtelezhnikov
c88bf8a216 [base, truetype] Silence UBSAN.
* src/truetype/ttinterp.c (TT_MulFix14_64): Use unsigned multiplication.
* include/freetype/internal/ftcalc.h (FT_MulFix_64): Ditto.
2025-04-11 22:58:26 -04:00
Alexei Podtelezhnikov
fb99fd63ec [base, truetype] Synchronize MulFix assembly.
* include/freetype/internal/ftcalc.h (FT_MulFix_*),
src/truetype/ttinterp.c (TT_MulFix14_*): Synchronize routines.
2025-04-11 22:57:27 -04:00
Alexei Podtelezhnikov
9175373673 [truetype] Modernize bytecode projections.
With 64-bit platforms widely available, it is more efficient to use
64-bit variables readily. It results in noticeable 10% improvement
in glyph loading speed.

* src/truetype/ttinterp.c (TT_MulFix14, TT_DotFix14) [FT_INT64]:
Prioritize available implementation with arguments adjusted based on
the use cases.
2025-04-10 19:58:48 +00:00
Alexei Podtelezhnikov
9a394e2dd1 [base] Update FT_MulFix inlining.
Resolves inconsistencies in 64-bit multiplication discussed in !355.
Importantly, FT_MulFix arguments and return value is FT_Long,
whatever sizeof FT_Long is on 64-bit platforms: 8 bytes on Linux or
4 bytes on Windows.

* include/freetype/internal/ftcalc.h (FT_MulFix_x86_64): Removed.
(FT_MulFix_64): Generalize and prioritize the inline implementation
for all 64-bit platforms ifdef FT_INT64.
* src/base/ftcalc.c (FT_MulFix)[FT_INT64]: Call 'FT_MulFix_64'.
* src/base/ftbase.c: Include 'ftcalc.c' after the FT_MulFix callers
to enable its inlining.
2025-04-09 16:09:01 +00:00
Alexei Podtelezhnikov
8f67545d72 [base] Update FT_MulFix inlining.
Resolves inconsistencies in 64-bit multiplication discussed in !355.                                                    Importantly, FT_MulFix arguments and return value is FT_Long,                                                           whatever sizeof FT_Long is on 64-bit platforms: 8 bytes on Linux or                                                     4 bytes on Windows.                                                                                                                                                                                                                             * include/freetype/internal/ftcalc.h (FT_MulFix_x86_64): Removed.                                                       (FT_MulFix_64): Generalize and prioritize the inline implementation
for all 64-bit platforms ifdef FT_INT64.                                                                                * src/base/ftcalc.c (FT_MulFix)[FT_INT64]: Call 'FT_MulFix_64'.                                                         * src/base/ftbase.c: Include 'ftcalc.c' after the FT_MulFix callers                                                     to enable its inlining.
2025-04-09 13:37:23 +00:00
Graham Asher
fc67794e15 Missing header wrappers.
* include/freetype/config/integer-types.h, src/smooth/ftgrays.h:
Add missing FT_BEGIN_HEADER and FT_END_HEADER.
* src/smooth/ftgrays.c: Cosmetics.
2025-04-04 19:54:50 -04:00
Alexei Podtelezhnikov
82090e67c2 [bdf] Clarify callback flow.
* src/bdf/bdflib.c (bdf_line_func_t_): Modify callback prototype.
(bdf_parse_*_): Updated.
(bdf_load_font, bdf_readstream_): Delay callback initiation.
2025-03-26 00:26:55 -04:00
Alexei Podtelezhnikov
7ede732490 * src/bdf/bdflib.c (bdf_readstream_): Relocate. 2025-03-25 22:03:23 -04:00
Alexei Podtelezhnikov
56b53a86e0 * src/bdf/bdflib.c (bdf_is_atom_): Do not check tabs. 2025-03-25 21:23:46 -04:00
Alexei Podtelezhnikov
7ddb53fcac * src/bdf/bdflib.c (_bdf_strncmp): Macro removed, callers updated. 2025-03-25 21:22:52 -04:00
Alexei Podtelezhnikov
5d4e649f74 .gitlab-ci.yml: Minor. 2025-02-26 15:35:25 +00:00
Tim-Philipp Müller
316bdc96ce * .gitlab-ci.yml: Switch to arm64 runners for macOS CI. 2025-02-26 15:32:27 +00:00
Behdad Esfahbod
d0c905c62a [sfnt/CPAL] Return early if user requested currently-set palette
Before, we were loading a palette (again and again) even if the
same was requested. Even if the font only had one palette...

For a font like NotoColorEmoji that has over 5000 colors in its
palette, this was dominating the COLRv1 loading times for HarfBuzz
(and I believe all other clients) because they have to set the
palette to get access to the colors.

* src/base/ftcolor.c (FT_Palette_Select): Check the current palette.
2025-02-24 19:13:39 -05:00
Alexei Podtelezhnikov
b1f4785087 * src/bdf/bdflib.c (bdf_parse_start_): Move setup of properties. 2025-01-28 22:49:21 -05:00
Alexei Podtelezhnikov
00a1567a13 [bdf] Treat all comments uniformly.
* src/bdf/bdflib.c (bdf_parse_start_): Reject fonts with initial
COMMENTs.
(bdf_parse_properties_): Skip COMMENTs so that...
(bdf_add_property_): Do not make exception for COMMENT.
(bdf_parse_glyphs_, bdf_add_comments): Updated.
2025-01-24 22:36:56 -05:00
Alexei Podtelezhnikov
fdae51ccb0 * src/bdf/bdflib.c (BDF_SWIDTH_ADJ_): Remove clashing flag and update. 2025-01-24 22:03:00 -05:00
Alexei Podtelezhnikov
bfe793ccec * src/bdf/bdflib.c (bdf_atous_): Remove unnecessary checks. 2025-01-22 21:17:57 -05:00
Alexei Podtelezhnikov
40a7458500 * src/bdf/bdflib.c (bdf_ato{i.ul.s.us}_]): Remove uncecessary checks. 2025-01-22 21:05:22 -05:00