Commit Graph

5800 Commits

Author SHA1 Message Date
Alexei Podtelezhnikov 2edfd7e168 * src/autofit/aflatin.c (af_latin_metrics_scale_dim): Remove FT_ABS.
See
    https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=68679
2024-05-04 16:42:47 -04:00
Alexei Podtelezhnikov 7bd887f177 * src/sfnt/sfwoff2.c (woff2_open_font): Fix copy-paste typo. 2024-05-03 16:04:35 +00:00
Alexei Podtelezhnikov 3f28a6b6af [woff,woff2] Limit the number of tables and use FT_MSB.
The upper limit of 4095 is implied by the SFNT header format
where the multiplication by 16 would overflow without it.

* src/sfnt/sfwoff.c (woff_open_font): Updated.
* src/sfnt/sfwoff2.c (woff2_open_font): Ditto.
2024-05-03 15:44:57 +00:00
Ben Wanger 13d1180f45 [woff2] Disallow zero table font entries
The existing code already disallows zero table woff2 overall, but still
allows for individual CollectionFontEntry to create font instances with
zero tables. Such fonts are not useful so error early.

This also fixes an MSAN discovered issue where if a CollectionFontEntry
numTables is zero then the sfnt_header was not fully initialized.

* src/sfnt/sfwoff2.c (woff2_open_font): error on zero tables, always
initalize sfnt_header

Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=68384
2024-05-02 15:00:27 -04:00
Alexei Podtelezhnikov 4d50468478 [sfnt] Use faster macros in checksums.
* src/truetype/ttobjs.c (tt_synth_sfnt_checksum): Use FT_NEXT_XXX.
* src/sfnt/sfwoff2.c (compute_ULong_sum): Use macros.
2024-05-01 23:19:31 -04:00
Alexei Podtelezhnikov 13da904267 * src/sfnt/sfwoff2.c (compute_ULong_sum): Clean up. 2024-05-01 00:34:21 -04:00
Alexei Podtelezhnikov 5962d3c1b9 * src/cache/ftccache.c (FTC_Cache_RemoveFaceID): Remove nodes instantly. 2024-04-29 22:34:09 -04:00
Alexei Podtelezhnikov a209e1adcd [cache] Remove unused `node_reset`.
* src/cache/ftcmru.h (FTC_MruListClassRec): Remove `node_reset` field.
* src/cache/ftcbasic.c (ftc_basic_{image,sbit}_family_class): Ditto.
* src/cache/ftcmanag.c (ftc_face_list_class): Ditto.
(ftc_size_node_reset): Remove function.
* src/cache/ftcglyph.h: Fix comment.
2024-04-29 17:54:30 -04:00
Alexei Podtelezhnikov f8f0d1a1d9 * src/cache/ftcmru.c (FTC_MruList_New): Do not reset nodes.
Resetting of the size nodes can crash, if a parent face purge happens
simultaneously and destroys the node. It is safer to create a new node.
Fixes #1270, reopened with a separate issue.
2024-04-29 16:58:59 -04:00
Alexei Podtelezhnikov 1168b1b5b0 * src/cache/ftcimage.c (ftc_inode_weight): Formatting. 2024-04-27 20:44:01 -04:00
Alexei Podtelezhnikov 982bc83849 [cache] Minor tweaks.
* src/cache/ftcimage.c (ftc_inode_free): Remove unnecessary check.
* src/cache/ftcmanag.c (FTC_Manager_Done): Do not zero before freeing.
2024-04-21 15:53:05 -04:00
Alexei Podtelezhnikov 5a3bfa92d9 * src/cache/ftcbasic.c: Cosmetic harmonization. 2024-04-20 23:28:17 -04:00
Alexei Podtelezhnikov 23e1d64556 [cache] Reduce type mismatches.
* src/cache/ftcbasic.c (FTC_BasicAttrRec): Match type of `load_flags`
to its main purpose in `FT_Load_Glyph`.
(FTC_ImageCache_Lookup{,Scaler},FTC_SBitCache_Lookup{,Scaler}): Updated.
2024-04-20 12:01:58 -04:00
Alexei Podtelezhnikov 9a2d6d97b2 * src/cache/{ftcbasic.c,ftccmap.c}: Use FTC_INLINE. 2024-04-19 14:45:39 -04:00
Alexei Podtelezhnikov dbdcd75889 [cache] Tweak headers.
* src/cache/ftccback.h: Include less and move `ftc_node_destroy`...
* src/cache/ftccache.h: ... to here.
* src/cache/ftcmanag.c: Include less.
2024-04-19 14:02:43 -04:00
Alexei Podtelezhnikov db83e9c0ec * src/cache/ftcglyph.c [!FTC_INLINE]: Fix compilation. 2024-04-18 23:23:13 -04:00
Alexei Podtelezhnikov 12adfc212b [cache] Improve MRU list management.
* src/cache/ftcmru.c (FTC_MruList_Remove): Cosmetic.
(FTC_MruList_New): Accept only valid changes.
* src/cache/ftcmanag.c (ftc_size_node_done):  Simplify.
2024-04-17 15:07:23 +00:00
Alexei Podtelezhnikov d091bca546 [cache] Fix error handling.
Manipulate the cache after a face is requested or a size is looked up
successfully. Fixes #1270.

* src/cache/ftcmanag.c (ftc_size_node_init, ftc_size_node_reset,
ftc_face_node_init): Check for errors before accepting a change.
* src/cache/ftcmru.c (FTC_MruList_New): Do nothing if reset fails.
2024-04-17 00:33:14 -04:00
Alexei Podtelezhnikov b3a6a20a80 [smooth] Switch to vertical bisections.
With horizontal bisections, the smallest section is a whole single
scanline. Almost horizontal lines or other complex scanlines can
easily overflow the rendering pool. Switching to vertical bisections
splits the scanlines and should rule out the overflows.  Fixes #1269.

* src/smooth/ftgrays.c (gray_convert_glyph): Bisect vertically.
2024-04-14 15:37:57 -04:00
Alexei Podtelezhnikov fff58f5424 * src/smooth/ftgrays.c (gray_convert_glyph): Refactor for convenience. 2024-04-14 15:12:31 -04:00
Alexei Podtelezhnikov 674d629b5e [smooth] Store persistent clipping box.
* src/smooth/ftgrays.c (gray_TWorker, gray_raster_render): Add and set
the new structure field.
(gray_convert_glyph): Use it.
2024-04-14 13:06:01 -04:00
Ben Wanger f42ce25563 [colr] Ensure enough bytes for PaintColrLayers
* src/sfnt/ttcolr.c (read_paint): check that there are five additional
bytes to be read when reading PaintColrLayers.

Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66566
2024-03-08 14:55:12 -05:00
Ben Wagner 17545d4bf7 Avoid n^2 scanning for binary data.
When creating a CID parser the location of the 'StartData' or '/sfnts'
tokens needs to be known.  However, the token parser requires that the
entire document be in memory and flattening the entire stream into memory is
to be avoided.

To avoid forcing the entire stream into memory, previously this code would
scan through the stream looking for 'StartData' or '/sfnts' as strings.
However, these strings could have been in a comment or string token, so the
stream would be read into memory up to that point and the parser run to
check that these strings were actually tokens.  This forced a parser restart
from the beginning each time; as a result, data with many 'StartData'
non-tokens would take n^2 time to check.

* src/cid/cidparse.c (cid_parser_new): Change algorithm to make the initial
scan look for the last possible 'StartData' or '/sfnts' string in the
stream.  The stream is read forward instead of backward as a typical normal
CID font will have one 'StartData' toward the beginning of the data and it
it much faster to read the data from beginning to end instead of end to
beginning.  For memory-based fonts the limit is set to the end of the stream
since the stream is already in memory.  Then the parser is run once to look
for 'StartData' or '/sfnts' tokens.  If they are found the parser is re-set
to reflect this new information.

Reported as

  https://issues.chromium.org/issues/40201695
2024-03-08 17:47:43 +01:00
Ben Wanger 2a790a9f49 [cff, truetype] Always set up default variable instance.
For default variable instances `cff_face_init` did not set the blend.  This
mostly worked as later use of the unset blend produced the default
variation.  However, if a user called `TT_Get_MM_Var` the blend would be
partially set up, but not fully.  In particular the number of axes, the axis
definitions, and the instance locations would be set up, but not the current
instance location (`coords` and `normalizedcoords`).  This could lead to the
default instances of CFF2 fonts erroring on any use of `blend`.

Ensure the default variable instance is fully set up by always calling
`FT_Set_Named_Instance` on a variable face.

* src/cff/cffobjs.c (cff_face_init): Call `FT_Set_Named_Instance` on
default instances.
* src/truetype/ttobjs.c (tt_face_init): Ditto.

Fixes #1268.
2024-02-29 07:06:46 +01:00
Werner Lemberg 546237e1bb * src/truetype/ttgxvar.c (ft_var_to_normalized): Integer overflow.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66543
2024-02-23 11:55:53 +01:00
Alexei Podtelezhnikov 47574f7ea4 Update all copyright notices. 2024-01-27 11:11:22 -05:00
Alexei Podtelezhnikov 4f0256c13f * src/sfnt/ttgpos.c (tt_gpos_get_glyph_class): Fix warning C4018. 2024-01-27 10:47:10 -05:00
David Saltzman 8f286c86ef Add support for kerning from 'GPOS' tables.
This commit adds support for kerning from 'GPOS' tables, while maintaining
support for basic 'kern' tables.  `FT_HAS_KERNING` will be true for a font
with either available and `FT_Get_Kerning` will still use the basic 'kern'
table data if avilable, otherwise check the GPOS 'kern' feature.

This feature is disabled by default; it can be enabled with the
`TT_CONFIG_OPTION_GPOS_KERNING` flag.

Only basic kerning (pair positioning with just an x advance) is supported
from the GPOS layout features; support for that was added to make the
existing `FT_Get_Kerning` API more consistently functional.  FreeType does
not intend to extend itself to further GPOS functionality though; a
higher-level library like HarfBuzz can be used instead for that.

* include/freetype/config/ftoption.h, include/devel/ftoption.h
(TT_CONFIG_OPTION_GPOS_KERNING): New configuration option.

* include/freetype/internal/fttrace.h: Add `ttgpos` trace handler.

* include/freetype/internal/sfnt.h (SFNT_Interface): Add `load_gpos` and
`get_gpos_kerning` fields.
(FT_DEFINE_SFNT_INTERFACE): Updated.

* include/freetype/internal/tttypes.h: Include `fttypes.h`.
(TT_FaceRec) [TT_CONFIG_OPTION_GPOS_KERNING]: Add `gpos_table` and
`gpos_kerning_available` fields.

* src/sfnt/ttgpos.c, src/sfnt/ttgpos.h: New files.

* src/sfnt/sfdriver.c [TT_CONFIG_OPTION_GPOS_KERNING]: Include `ttgpos.h`.
(sfnt_interface): Updated.

* src/sfnt/sfnt.c: Include `ttgpos.c`.

* src/sfnt/sfobjs.c [TT_CONFIG_OPTION_GPOS_KERNING]: Include `ttgpos.h`.
(sfnt_load_face) [TT_CONFIG_OPTION_GPOS_KERNING]: Load and free GPOS kerning
data; check GPOS kerning availability.

* src/truetype/ttdriver.c (tt_get_kerning): Use GPOS kerning if there's no
'kern' table.
2024-01-27 10:55:04 +01:00
Alexei Podtelezhnikov 5761778246 [smooth] Remove SSE2.
As a result of 7b308a29dd, the regular 64-bit execution is now faster
than SSE2. The rendering speed of script fonts at 64 ppem or larger is
improved by about 3% without SSE2. See !314 for the testing results.   

* src/smooth/ftgrays.c (gray_render_conic)[FT_INT64]: Remove SSE2 code.
2024-01-14 13:03:51 +00:00
Ozkan Sezer 7bac4d146a * src/sfnt/ttcolr.c (find_base_glyph_v1_record): Fix build in C90 mode. 2024-01-08 20:27:03 +01:00
Alexei Podtelezhnikov cc081d7cce [base] Fix up Mac resource forks and dfonts.
* src/base/ftobjs.c (IsMacResource): Assign `face_index`.
* src/base/ftmac.c (FT_New_Face_From_Suitcase): Ditto after rework.
2024-01-06 19:22:36 -05:00
Alexei Podtelezhnikov 4a85ff0b79 [sfnt] Restrict POST version 1.0.
A font has surfaced with `post` version 1.0 and fewer than 258 glyphs.
Its glyphs did not correspond to their names. We now reject such `post`
strictly following specifications.

* src/sfnt/ttpost.c (tt_face_get_ps_name): Check the number of glyphs
for version 1.0.
2024-01-04 21:38:51 -05:00
Werner Lemberg 57c4252ab5 [sfnt] Guard access in 'COLR' v1 glyph binary search.
Reported as

  https://bugs.chromium.org/p/chromium/issues/detail?id=1505216

* src/sfnt/ttcolr.c (find_base_glyph_v1_record): Guard access of the search
pointer during binary search.  The pointer needs to be checked as we go as
the test that compares number of v1 glyphs with table size at the time of
loading the table is not sufficient on its own.

A scenario is possible in which the `BaseGlyphRecord` list extends into
non-`BaseGlyphRecord` parts of the 'COLR' v1 table (but passed the size
comparison check).  Then, at those locations, invalid glyph ID values are
read and may provoke an invalid read due to reassigning min and max values
during the binary search.
2024-01-02 17:55:33 +01:00
Skef Iterum 8eab511017 [CFF] Extract `BlueValues` as `Fixed` rather than `Int`.
This is a follow-up to commit 26a7f047,

  [cff] Make blend operator work with floats in private dicts.

which addressed the 'party baseline' bug.  However, the reporting user
indicated that the default location and some other points in design space
rendered OK, but other points in design space still had problems.  The most
obvious issue being that the x-heights of lower-case letters did not align;
see

  https://github.com/adobe-fonts/source-serif/issues/121#issuecomment-1773794136

After some analysis we determined that this was due to an interaction
between `BlueValue` rounding and the zone-based algorithm.  In short, for a
point to be considered in a zone it must fall within the bounds of the zone.
(There is a slop factor in some cases, but only a very small one.)  In the
Adobe-contributed side of the code, point values are not integer-rounded,
instead they're kept as (some form of) fixed.  Rounding just the `BlueValues`
means that points that need to be considered within a zone will fall outside
of it at some points in design space.

The majority of this patch changes the storage and parsing of `BlueValues`
to keep them as `FT_Fixed`.  No significant code changes were needed because
the values are converted to `Fixed` anyway when stored in `CF_BlueRec`.  No
attempt was made to address problems in the older pshinter code beyond
converting the values from `FT_Fixed` to `FT_Short` when copying the private
dictionary.  (However, as the point values are also rounded in that code,
the problem is much less likely to occur, although inconsistency between
rounding and truncation could cause an analogous problem.)

* include/freetype/internal/cfftypes.h (CFF_PrivateRec): Use `FT_Fixed` for
`blue_values`, `other_blues`, `family_blues`, and `family_other_blues`.

* src/cff/cffload.c (cff_blend_doBlend): Updated.

* src/cff/cffobjs.c (CFF_fixedToInt): New macro.
(cff_make_private_dict): Use it.

* src/cff/cffparse.h (cff_kind_delta_fixed): New enum value.

* src/cff/cffparse.c (do_fixed): Updated.
(CFF_FIELD_DELTA, CFF_FIELD_DELTA_FIXED, CFF_DELTA_KIND): New set of macros,
replacing `CFF_FIELD_DELTA`.
(cff_parser_run): Updated to handle fixed-float deltas.

* src/cff/cfftoken.h: Updated to use `CFF_FIELD_DELTA_FIXED` for blue
values.

* src/psaux/psblues.c (cf2_blueToFixed): Removed, no longer needed.
(cf2_blues_init): Updated.

* src/pxaux/psft.c, src/pxaux/psft.h (cf2_getBlueValues, cf2_getOtherBlues,
cf2_getFamilyBlues, cf2_getFamilyOtherBlues): Updated signatures.

* src/psaux/psobjs.c (t1_make_subfont): Updated.
2023-12-14 07:17:01 +01:00
Skef Iterum 6f2bf6a582 [psaux] Improve tracing.
* src/psaux/psintrp.c (cf2_doBlend, cf2_interpT2CharString [cf2_cmdBLEND]):
Show blended values.
2023-12-14 06:55:33 +01:00
Werner Lemberg 9bf72966ed * src/truetype/ttgxvar.c (ft_var_to_normalized): Fix undefined left-shift.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=63723
2023-12-14 06:14:43 +01:00
Alexei Podtelezhnikov 01f23c39e0 * src/raster/ftraster.c (Draw_Sweep): Swap stub conditions. 2023-12-01 23:13:28 -05:00
Alexei Podtelezhnikov 5999d47d68 * src/raster/ftmisc.h (FT_MulDiv): Remove unused copy. 2023-12-01 20:50:16 -05:00
Alexei Podtelezhnikov 8f255c89e1 [raster] Speed up Bézier arches with extrema.
While it is recommended to have an explicit point at each curve
extrema, they might be missing or outline could be rotated. This
leads to excessive bisections in raster to find them.  This change
helps to decrease the number of bisections.  The scanline
intersections remain monotonous, of course.

* src/raster/ftraster.c (Conic_To, Cubic_To): Check that control
points cross the scanlines to bisect.
2023-11-27 22:44:36 -05:00
Alexei Podtelezhnikov efbae5476f [raster] Eliminate intensive flow checking.
* src/raster/ftraster.c (Draw_Sweep): Pass the flow increment.
(Increment): Accept the flow increment.
2023-11-24 10:23:36 -05:00
Alexei Podtelezhnikov 63d3a37eb7 * src/raster/ftraster.c: Comments, defines, includes, cleanups. 2023-11-23 17:50:04 -05:00
Alexei Podtelezhnikov df39b017d9 * src/raster/ftraster.c (FT_Outline_Get_CBox ) [STANDALONE_]: Removed. 2023-11-21 18:12:45 +00:00
Alexei Podtelezhnikov c62027d910 * src/raster/ftraster.c (Draw_Sweep): No-fault return.
(Render_Single_Pass): Updated.
2023-11-21 16:54:25 +00:00
Alexei Podtelezhnikov d77dd24b41 [raster] Sweep polishing.
* src/raster/ftraster.c (*_Sweep_Span): Polish.
(*_Sweep_Drop): Restore tracing, polish.
(Draw_Sweep): Simplify the dropout processing loop.
2023-11-21 15:16:56 +00:00
Alexei Podtelezhnikov da8e428977 [raster] Rearrange dropout control.
This reduces the code duplication.

* src/raster/ftraster.c (Function_Sweep_Span): Change signature.
(Vertical_Sweep_Drop, Horizontal_Sweep_Drop): Focus on pixel setting
and move duplicated the dropout control logic to...
(Draw_Sweep): ... this function and refactor.
(Vertical_Sweep_Span, Horizontal_Sweep_Span): Minor.
2023-11-21 00:53:50 -05:00
Alexei Podtelezhnikov d7c72ff919 [raster] Use bitwise dropout mode interpretation.
* src/raster/ftraster.c (Vertical_Sweep_Drop, Horizontal_Sweep_Drop,
Draw_Sweep, Render_GLyph): Interpret dropout mode using bit masks.
2023-11-20 22:46:36 -05:00
Alexei Podtelezhnikov 050a320764 [raster] Keep only bottom y-turns.
This results in noticeable performance improvement.

* src/raster/ftraster.c (Insert_Y_Turns): All bottom y-turns are still
sorted and stored; only the maximum top y-turn is recorded now. The
function is renamed.
(End_Profile): Updated accordingly.
(Convert_Glyph): Reserve space for the top value.
2023-11-15 23:41:56 -05:00
Alexei Podtelezhnikov fa59e0d64c * src/raster/ftraster.c (End_Profile): Reduce branching.
(InsNew): Tweak condition.
2023-11-15 16:55:57 +00:00
Alexei Podtelezhnikov c580926f35 * src/raster/ftraster.c (Draw_Sweep): Use more natural loop. 2023-11-15 15:17:50 +00:00
Alexei Podtelezhnikov b0265ccd33 [raster] Dissolve a loop.
* src/raster/ftraster.c (End_Profile): Set initial `X` here...
(Draw_Sweep): ... instead of here; delay the `start` decrement.
2023-11-14 23:32:06 -05:00