Commit Graph

5431 Commits

Author SHA1 Message Date
Werner Lemberg 6da5f95fcf [gxvalid] Fix minor compilation warning.
* src/gxvalid/gxvmort5.c (gxv_mort_subtable_type5_subtable_setup): Declare
as static.
2021-11-20 09:29:09 +01:00
Werner Lemberg f5ce182420 [smooth] Fix stand-alone compilation.
* src/smooth/ftgrays.c (FT_Trace_Enable, FT_Trace_Disable)[STANDALONE_]:
Define.
2021-11-20 07:58:40 +01:00
Werner Lemberg 8c8f51c558 Avoid undefined left-shifts.
We really have to use double casts to avoid issues with C's and C++'s
signedness propagation rules in implicit casts.

Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=41178
  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=41182

* include/freetype/config/public-macros.h (FT_STATIC_CAST,
FT_REINTERPRET_CAST): Modify macro to take two arguments.
Update all callers.
(FT_STATIC_BYTE_CAST): New macro.

* include/freetype/freetype.h (FT_ENC_TAG): Use `FT_STATIC_BYTE_CAST`.
* include/freetype/ftimage.h (FT_IMAGE_TAG): Ditto.
* include/freetype/fttypes.h (FT_MAKE_TAG): Ditto.
Use `FT_Tag` for casting.

* src/ftraster/ftmisc.h (FT_MAKE_TAG): Removed, no longer needed.
(FT_STATIC_BYTE_CAST): New macro.

* src/smooth/ftgrays.c (FT_STATIC_CAST): Replace with...
(FT_STATIC_BYTE_CAST): ... this.
2021-11-20 07:58:31 +01:00
Werner Lemberg 9079c5d91a Provide C++ versions for public macros with casts.
Many FreeType clients use C++.  However `g++ -Wold-style-cast` warns for
macros with C-style casts even for system header files; this also affects
directories included with `-isystem`.  While this could be seen as a problem
with g++, the problem is more a philosophical one: Over the time, C and C++
diverged more and more, and some features of C are no longer the 'right'
solution in C++.

* include/freetype/config/public-macros.h (FT_STATIC_CAST,
FT_REINTERPRET_CAST): New macros.

* include/freetype/freetype.h (FT_ENC_TAG, FT_LOAD_TARGET_,
FT_LOAD_TARGET_MODE): Use `FT_STATIC_CAST`.
Correctly handle negative 'signed char' input.
* include/freetype/ftimage.h (FT_IMAGE_TAG): Ditto.
* include/freetype/fttypes.h (FT_MAKE_TAG, FT_BOOL): Ditto.
* include/freetype/ftmodapi.h (FT_FACE_DRIVER_NAME): Use
`FT_REINTERPRET_CAST`.

* src/smooth/ftgrays.c (FT_STATIC_CAST)[STANDALONE_]: New macro.
[!STANDALONE]: Include `FT_CONFIG_CONFIG_H`.

Fixes #1116.
2021-11-18 19:28:07 +00:00
Werner Lemberg 238245cd66 Fix clang++ warnings.
* src/*: Initialize some variables to NULL.
2021-11-16 22:08:47 +01:00
Werner Lemberg e4f7673e46 [truetype] Updates for the forthcoming OpenType 1.9 standard (2/2).
* src/truetype/ttgxvar.c (ft_var_load_item_variation_store):
s/shortDeltaCount/wordDeltaCount/ (as done in the specification, too).
Recognize new format and reject it for now.
2021-11-16 20:13:58 +00:00
Werner Lemberg 93e6b3e8e9 [truetype] Updates for the forthcoming OpenType 1.9 standard (1/2).
This is in preparation for implementing `DeltaSetIndexMap` format 1, which
is used by `COLR` v1 tables, and which allows 32bit indices.

  https://docs.microsoft.com/en-us/typography/opentype/otspec190/delta/otvarcommonformats_delta.html

* src/truetype/ttgxvar.h (GX_DeltaSetIdxMapRec): Change type of `mapCount`
to `FT_ULong`.

* src/truetype/ttgxvar.c (ft_var_load_delta_set_index_mapping): Add argument
for passing the table size; update caller.
Implement new format.
2021-11-16 20:13:58 +00:00
Werner Lemberg d31bafcb9c Fix clang warnings.
* src/gxvalid/gxvcmmn.h (GXV_SET_ERR_IF_PARANOID): Use 'do' block.
* src/gxvalid/gxvmod.c (GXV_TABLE_LOAD, GXV_TABLE_VALIDATE): Ditto.

* src/smooth/ftgrays.c (gray_convert_glyph): Add cast.

* src/type1/t1gload.c (T1_Parse_Glyph_And_Get_Char_String): Remove cast.
* src/type1/t1load.c (read_binay_data): Use `FT_ULong` for `size` parameter.
(parse_subrs, parse_charstrings, parse_dict): Ditto; also add some casts.
2021-11-14 11:02:54 +01:00
Dominik Röttsches 9597fd7b40 [sfnt] Avoid undefined shifts in `COLR` v1 paint parsing
* src/sfnt/ttcolr.c (read_paint, tt_face_get_paint): Tighten shift
behavior by using multiplication, mostly using macros from ftcalc.h.

Fixes: https://bugs.chromium.org/p/chromium/issues/detail?id=1269168
2021-11-13 06:48:23 +00:00
Alexei Podtelezhnikov c5cd2a3db4 * src/truetype/ttgxvar.c (ft_var_to_normalized): Edge optimization. 2021-11-10 08:46:26 -05:00
Werner Lemberg d899b200f6 * src/sfnt/sfobjs.c (sfnt_open_font): Fix typo. 2021-11-08 12:27:04 +01:00
Werner Lemberg b86f96bce6 * src/gxvalid.*, src/otvalid.*: Fix `-Wformat` warnings. 2021-11-08 11:44:02 +01:00
Werner Lemberg cce782281b [pshinter] Fix C++ compilation.
* src/pshinter/pshalgo.c (psh_compute_dir): Fix type of `result`.
(psh_hint_table_find_strong_points): Add cast.
2021-11-08 09:41:54 +01:00
Werner Lemberg 7ef266045f [sfnt] Reduce footprint if WOFF and WOFF2 support is not needed.
Based on a patch from metarutaiga (MR !106).  The gist of this commit is
that it doesn't make sense to support WOFF without compression (which would
be only possible in WOFF 1.0 anyway).

* src/sfnt/sfobjs.c (sfnt_open_font): Guard WOFF code with
`FT_CONFIG_OPTION_USE_ZLIB` block.
Guard WOFF2 code with `FT_CONFIG_OPTION_USE_BROTLI` block.

* src/sfnt/sfwoff.c, src/sfnt/sfwoff.h: Guard files with
`FT_CONFIG_OPTION_USE_ZLIB` blocks, not parts of the code.

* src/sfnt/sfwoff2.c, src/sfnt/sfwoff2.h, src/sfnt/woff2tags.c,
src/sfnt/woff2tags.h: Guard files with `FT_CONFIG_OPTION_USE_BROTLI` blocks,
not parts of the code.

Fixes #1111.
2021-11-08 08:56:37 +01:00
Werner Lemberg bb4e049abe [truetype] Make trickyness checks depend on TT_USE_BYTECODE_INTERPRETER.
Based on a patch from metarutaiga (MR !106).

* src/truetype/ttobjs.c (tt_skip_pdffont_random_tag,
tt_check_trickyness_family, tt_synth_sfnt_checksum, tt_get_sfnt_checksum,
tt_check_trickyness_sfnt_ids, tt_check_trickyness): Put functions into a
`TT_USE_BYTECODE_INTERPRETER` block.
(tt_face_init): Put trickyness checks into a `TT_USE_BYTECODE_INTERPRETER`
block.

Fixes #1111.
2021-11-08 08:22:13 +01:00
Alexei Podtelezhnikov 9ebdc9cb1b * src/sfnt/ttload.c (tt_face_load_gasp): Fix a type mismatch warning. 2021-11-07 23:21:40 -05:00
Alexei Podtelezhnikov 7f4b9bfbc9 [dlg] Define DLG_STATIC explicitly.
DLG_STATIC is intended to disable Windows DLL linking attributes.
It does not hurt to define it explicitly when we wrap DLG code.
This fixes tons of LNK4286 and C4273 warnings from MSVC if we
forget to define DLG_STATIC as a compiler option.

* builds/windows/vc2010/freetype.vcxproj: Remove DLG_STATIC option.
* src/dlg/dlgwrap.c [FT_DEBUG_LOGGING]: Define DLG_STATIC.
* include/freetype/internal/ftdebug.h [FT_DEBUG_LOGGING]: Ditto.
2021-11-07 10:20:16 -05:00
Alexei Podtelezhnikov c693377ed3 [dlg] Lighten up the inclusions.
The DLG wrapper needs to know if FT_DEBUG_LOGGING is defined in
`ftoption.h`. It does not need entire FreeType.

* src/dlg/dlgwrap.c: Include FT_CONFIG_OPTIONS_H directly.
2021-11-07 10:05:05 -05:00
Alexei Podtelezhnikov cb9e7b7aac [truetype] Avoid some memory zeroing in variations.
* src/truetype/ttgxvar.c (ft_var_readpackeddeltas, ft_var_load_avar,
ft_var_load_item_variation_store, ft_var_load_gvar): Use FT_QNEW_ARRAY
if memory immediately initialized or discarded otherwise.
2021-11-06 22:59:31 -04:00
Jany Belluz fc55291b1c [truetype] Fix handling of packed deltas in Variation Fonts.
* src/truetype/ttgxvar (ft_var_readpackeddeltas): Don't expect the number of
bytes used to encode the deltas to be higher than the number of encoded
values.  The specification allows a very compact encoding; for example, a
list of 200 zeros can be encoded with just a couple of bytes.

We now count the consumed bytes to make sure to not read more than expected.
2021-11-05 13:53:45 +01:00
Jany Belluz 9ed5332fe6 [truetype] Fix CVAR handling of tuples for all points.
* src/truetype/ttgxvar (tt_face_vary_cvt): Function
`ft_var_readpackedpoints`, when it returns `ALL_POINTS`, also sets
`point_count` to value 0.  However, the CVAR code was incorrectly expecting
that `point_count` would be set to match the length of the CVT table.
2021-11-04 12:09:01 +01:00
Jany Belluz 23d1d8ada8 * src/truetype/ttgxvar.c: Fix typos in macros that guard CVAR code. 2021-11-04 12:07:47 +01:00
Dominik Röttsches d3d3ff76d1 [sfnt] Clarify `COLR` v1 FT_Paint* format representations
* include/freetype/ftcolor.h (FT_PaintLinearGradient,
FT_PaintRadialGradient, FT_PaintSweepGradient, FT_PaintTransform,
FT_PaintTranslate, FT_PaintScale, FT_PaintRotate, FT_PaintSkew): Clarify
16.16 fixed point representation of struct fields.
* src/sfnt/ttcolr.c (read_paint): Shift coordinates for
FT_PaintLinearGradient, FT_PaintRadialGradient, FT_PaintSweepGradient
accordingly.

Fixes: https://gitlab.freedesktop.org/freetype/freetype/-/issues/1110
2021-11-03 08:28:10 +00:00
Alexei Podtelezhnikov 94cb3a2eb9 * src/truetype/ttgload.c (load_truetype_glyph): Fix MSVC warning C4312. 2021-10-29 10:31:59 -04:00
Alexei Podtelezhnikov 793c012635 [woff] Optimize table tagging.
* include/freetype/internal/wofftypes.h (WOFF_TableRec): Use
32-bit tag.
* src/sfnt/sfwoff.c (woff_open_font): Use 32-bit tag.
2021-10-27 22:36:11 -04:00
Alexei Podtelezhnikov a577bbcb5b [woff2] Optimize table tagging.
Fixes #1107.

* include/freetype/internal/wofftypes.h (WOFF2_TableRec): Use
32-bit tag.
* src/sfnt/sfwoff2.c (compare_tags, find_table, woff2_open_font):
Use 32-bit tag.
* src/sfnt/woff2tags.[ch] (woff2_known_tags): Use static storage and
return 32-bit tag.
2021-10-27 22:24:27 -04:00
Werner Lemberg 80b13f5732 Formatting. 2021-10-26 10:57:17 +02:00
Ben Wagner 535c67dda7 [mm] Tolerate missing Blend dictionary entries
In a Multiple Master font, the Blend dictionary must contain valid
Private, FontInfo, and FontBBox. The current code will error if any of
these are present and invalid, but will not error and will provide
uninitialized data if the Blend dictionary exists but does not contain
one of these entries. This change reverts to the older behavior of
treating any missing entries as containing all zero data and not
returning an error.

In the future it may be best to keep track of when these are actually
initialized and error if they are not.

* src/type1/t1load.c (t1_allocate_blend): Zero initiailize.
2021-10-25 22:38:05 -04:00
Ben Wagner 65be4b2112 [mm] Delay setting blend weight and design position.
Previously the `blend->weight_vector`, `blend->default_weight_vector`,
and `blend->design_pos` were set early to allocated but uninitialized
memory under the assumption that the memory would eventually be
initialized. However, it is possible that some of the required
keywords may not actually be present, leaving the memory uninitialized.
This is different from a present but invalid table, which would produce
an error.

Reported as
  https://bugs.chromium.org/p/chromium/issues/detail?id=1261762

* src/type1/t1load.c (t1_allocate_blend): Remove early allocation and
initialization.
(parse_blend_design_positions, parse_weight_vector): Parse into local
and assign to blend if valid.
(T1_Open_Face): Check that if a blend exists that it has the weight
vector and design positions.
2021-10-21 09:55:28 -04:00
Ben Wagner b5e003f1f2 [cff] Commit vstore data and regions on allocation.
The vstore->regionCount and vstore->dataCount were read directly
from the data. However, vstore->varRegionList and vstore->varData
would still contain uninitialized entries with uninitialized
pointers in the event of an error, leading to issues when attempting
to clean up.

Reportd as
  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=40104

* src/cff/cffload.c (cff_vstore_load): Read the region and data counts
into locals and update the vstore counts immediately after each entry
becomes free-able.
2021-10-21 09:48:38 -04:00
Ben Wagner fde91ab8f1 [sfnt] Delay setting gasp ranges and count until computed.
Previously, the gasp.numRanges was set and gasp.gaspRanges was
allocated and assigned before a possible early exit if the frame could
not be entered. It is also possible that the gaspRanges allocation
could fail but the numRanges still be set to non-zero. In such cases
an error would be returned, but the face would have a gasp in an
inconsistent state which may still be accessed.

Reported as
  https://bugs.chromium.org/p/chromium/issues/detail?id=1261450

* src/sfnt/ttload.c (tt_face_load_gasp): Delay setting gasp.numRanges
and gasp.gaspRanges until after the ranges are initialized.
2021-10-20 11:45:15 -04:00
Ben Wagner 6d12e3a0ca [sfnt] Delay setting names and langTags until computed.
Previously, the table->names and table->langTags fields were created
pointing to uninitialized memory and an early exit could happen if the
frame could not be entered. The caller would then be unable to properly
dispose of the memory as the string fields had not been initialized.

Reported as
  https://bugs.chromium.org/p/chromium/issues/detail?id=1261343

* src/sfnt/ttload.c (tt_face_load_name): delay setting table->langTags
and table->names until after the memory they will point to is fully
initialized.
2021-10-20 11:38:16 -04:00
Werner Lemberg 8ef8072ba1 [bdf, cid, pfr, winfonts] Improve rejection of other font formats.
This is mainly for better diagnostics of malformed fonts.

* src/bdf/bdflib.c (_bfd_readstream): Stop font format testing if the first
input line is too long or doesn't end with `\r` or `\n`.

* src/cid/cidparse.c (cid_parser_new): Don't handle too short input as an
error but as an unknown format.

* src/pfr/pfrobjs.c (pfr_face_init): Ditto.

* src/winfonts/winfnt.c (fnt_font_load, fnt_face_get_dll_font): Ditto.
2021-10-19 22:59:46 +02:00
Alexei Podtelezhnikov 38b349c41b [pcf] Zero out the allocated properties.
Fallout reported as
  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=40033

* src/pcf/pcfread.c (pcf_get_properties): Use FT_NEW_ARRAY and zero
out `properties` in case of failure.
2021-10-18 20:35:28 -04:00
Alexei Podtelezhnikov 986d503f4a * src/sfnt/ttload.c (tt_face_load_name): NULL-initialize langTag.
Another attempt to fix fallout reported as
  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=40024
2021-10-17 09:14:27 -04:00
Alexei Podtelezhnikov 30ca63d4fb [bdf] Fix up user properties.
Fallout reported as
  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=40027

* src/bdf/bdflib.c (_bdf_add_property): Cosmetic NULL.
(bdf_create_property): Limit allocations to customary signed
FT_Long and NULL-initialize unused storage.
(bdf_free_font): Do not free unused storage.
2021-10-16 23:02:47 -04:00
Alexei Podtelezhnikov afd1cb2881 * src/sfnt/ttload.c (tt_face_load_name): Accounting fix.
Fallout reported as
  https://crbug.com/40024
2021-10-16 20:25:11 -04:00
Ben Wagner c71eb22dde Fix typos in memory macros.
FT_QNEW_ARRAY and FT_QRENEW_ARRAY were using the non-Q
FT_MEM_NEW_ARRAY and FT_MEM_RENEW_ARRAY. Change these to use the Q
versions. Also fix the one issue discovered in tt_face_load_name
where table->names is created with FT_QNEW_ARRAY but the extra
string member is not initialized to NULL.

* include/freetype/internal/ftmemory.h (FT_Q(RE)NEW_ARRAY):
Use FT_MEM_Q(RE)NEW_ARRAY as needed.

* src/sfnt/ttload.c (tt_face_load_name): Initialize `entry->string`.
2021-10-15 22:18:38 -04:00
Ben Wagner 8406ae5324 [truetype] Reload context after re-executing `prep`.
When a different hinting mode from the current is selected, the `prep` table
must be re-executed with the new mode.  After this happens the context must
be re-loaded in preparation for the glyph program to be run.

Fixes #1104.

* truetype/ttgload.c (tt_loader_init): Add call to `TT_Load_Context`.
2021-10-15 22:37:31 +02:00
Werner Lemberg 0b92c56c34 [truetype] Minor documentation improvements. 2021-10-15 19:02:41 +02:00
Alexei Podtelezhnikov e294a95ca8 * src/cid/cidload.c (parse_fd_array): Protect against trancation. 2021-10-11 23:25:29 -04:00
Alexei Podtelezhnikov 1029eb9377 [type1] Revert to signed size for binary data.
Recently introduced and reported as
  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=39838

* src/type1/t1load.c (read_binary_data): Reject negative size.
(parse_subrs, parse_charstrings): Use customary signed size.
2021-10-11 22:25:14 -04:00
Alexei Podtelezhnikov 77bd46e959 [psaux] Signedness revisions.
Unsigned indexes are easier to check.

* src/psaux/cffdecode.c (cff_decoder_parse_charstrings): Updated.
* src/psaux/psintrp.c (cf2_interpT2CharString): Ditto.
* src/psaux/t1decode.c (t1_decoder_parse_charstrings): Ditto.
* src/type1/t1load.c (read_binary_data): Ditto.
2021-10-10 23:12:12 -04:00
Alexei Podtelezhnikov 3b036820d6 [cid] Signedness revisions.
Unsigned checks are simpler.

* include/freetype/t1tables.h (CID_FaceInfoRec): Change to unsignd
`num_dicts`.
* src/cid/cidparse.h (CID_Parser): Change to unsigned `num_dict`.

* src/cid/cidgload.c (cid_load_glyph): Updated.
* src/cid/cidload.c (cid_load_keyword, parse_fd_array,
parse_expansion_factor, parse_font_name, cid_read_subrs,
cid_face_open): Updated.
* src/cid/cidobjs.c (cid_face_done): Updated.
* src/cid/cidparse.c (cid_parser_new): Updated.
2021-10-10 23:11:10 -04:00
Alexei Podtelezhnikov 012b4f2d48 * src/cid/cidload.c (cid_face_open): Streamline CIDCount check. 2021-10-08 22:14:12 -04:00
Alexei Podtelezhnikov 946df22165 * src/cid/cidload.c (cid_face_open): Streamline SubrCount check. 2021-10-07 22:44:53 -04:00
Alexei Podtelezhnikov 0313a11c4c * src/cid/cidgload.c (cid_load_glyph): Fortify incremental loading. 2021-10-07 22:43:12 -04:00
Alexei Podtelezhnikov 22befeef82 Signedness revisions.
This eliminates explicit casting by switching to unsigned fields.
The revisions mostly impact the handling of CID fonts.

* include/freetype/fttypes.h (FT_Data): Change to unsigned `length`.
* include/freetype/t1tables.h (CID_FaceDictRec): Ditto for `sd_bytes`.
(CID_FaceInfoRec): Ditto for `gd_bytes` and `gd_bytes`.
* include/freetype/internal/tttypes.h (TT_LoaderRec): Ditto for
`byte_len`.

* src/cid/cidgload.c (cid_load_glyph): Updated.
* src/cid/cidload.h (cid_get_offset): Update argument.
* src/cid/cidload.c (cid_get_offset, cid_read_subrs, cid_face_open):
Updated.
* src/cff/cffgload.c (cff_get_glyph_data, cff_free_glyph_data):
Updated.
* src/psaux/psft.c (cf2_getT1SeacComponent): Updated.
* src/truetype/ttgload.c (TT_Process_Composite_Glyph,
load_truetype_glyph): Updated.
2021-10-07 22:41:56 -04:00
Alexei Podtelezhnikov 0f23ae2e80 * src/smooth/ftgrays.c (FT_DIV_MOD): Limit the ARM workaround. 2021-10-05 16:28:40 -04:00
Alexei Podtelezhnikov ec6a458821 [pshinter] Additional clean-ups.
* src/pshinter/pshalgo.h (psh_hint_table_find_strong_points): Streamline code.
* src/pshinter/pshalgo.h (PSH_Glyph): Remove unused fields.
2021-10-04 23:10:59 -04:00
Alexei Podtelezhnikov 227445f613 [pshinter] More convenient direction definition.
It is easier to check directions using flags than integer values.

* src/pshinter/pshalgo.h (PSH_Dir): Redefine directions.
(PSH_PointRec): Use them as an enum type.

* src/pshinter/pshalgo.c (psh_compute_dir): Modify return type.
(psh_glyph_init, psh_hint_table_find_strong_points,
psh_glyph_find_blue_points): Update users.
2021-10-03 22:48:23 -04:00
Alexei Podtelezhnikov d102a51438 [pshinter] Remove unnecessary check.
* src/pshinter/pshalgo.c (psh_hint_table_find_strong_points): Do not
check if direction is defined before checking how.
2021-10-03 22:45:42 -04:00
Alexei Podtelezhnikov 68fae526c4 * src/autofit/afhints.c (af_glyph_hints_reload): Decrease casting. 2021-09-30 22:59:04 -04:00
Alexei Podtelezhnikov 1d79c892cf * src/tools/apinames.c: Facilitate OpenVMS linker options. 2021-09-29 22:17:31 -04:00
Alexei Podtelezhnikov dd0ccdc3d3 * src/winfonts/winfnt.c (FNT_Face_Init): Correct reallocation. 2021-09-28 22:57:58 -04:00
Alexei Podtelezhnikov a69320a9b2 [bdf] Simplify comment collection or lack thereof.
BDF comments are neither actually collected nor retrieved. There is
no need to be fancy with delimiters.

* src/bdf/bdflib.c (_add_bdf_comment): Delimit comments with zeros...
(bdf_load_font): ...and do not null-terminate comments additionally.
(_bdf_parse_glyphs): Check if comments are kept, which they are not.
(_bdf_parse_start): Minor clean up.
2021-09-24 22:06:44 -04:00
Alexei Podtelezhnikov a29e020059 Use NULL for pointers only.
* src/bdf/bdflib.c (*): Code changes.
* include/freetype/freetype.h: Comments only.
* src/cff/cffload.c, src/cff/cffobjs.c: Ditto.
* src/winfonts/winfnt.c: Ditto.
2021-09-23 23:10:26 -04:00
Alexei Podtelezhnikov 90b14882ec [bdf, pcf] Minor optimization.
* src/pcf/pcfread.c (pcf_load_font): Do not call `FT_MulDiv` for a
small job.
* src/bdf/bdfdrivr.c (BDF_Face_Init): Ditto.
* src/bdf/bdflib.c (_bdf_parse_glyphs): Fix a comment.
2021-09-22 20:20:04 -04:00
Alexei Podtelezhnikov b4dddd8244 [base] Initialize stream memory earlier.
With Windows memory management tracking heap, it is important to use
it during the stream opening fallback. In Unix, the argument is
unused, but it is better to set it correctly.

* src/base/ftobjs.c (FT_Stream_New): Set memory before calling
`FT_Stream_Open`.
* builds/windows/ftsystem.c, builds/unix/ftsystem.c (FT_Stream_Open,
ft_close_stream_by_free): Call `ft_alloc` and `ft_free` with proper
memory argumment.
2021-09-22 00:30:03 -04:00
Alexei Podtelezhnikov 892e7eadc9 * src/bdf/bdflib.c (_bdf_parse_{start,glyphs}): Use appropriate scanner. 2021-09-21 14:39:21 +00:00
Alexei Podtelezhnikov 6190360967 Minor. 2021-09-20 22:18:29 -04:00
Alexei Podtelezhnikov 71969d1edf * src/cff/cffdrivr.c (cff_ps_get_font_{info,extra}): Use FT_QNEW. 2021-09-20 14:31:45 -04:00
Alexei Podtelezhnikov 529158983d [cache] Minor clean-ups.
* src/cache/ftccache.h (FTC_CACHE_LOOKUP_CMP): Remove parantheses.
* src/cache/ftccache.c (FTC_Cache_Lookup): Ditto.
(FTC_Cache_RemoveFaceID): Remove unnecessary variable.
2021-09-18 07:05:55 -04:00
Edwin Steiner 6e1ef98a04 [cff] Explicitly set StandardEncoding or ExpertEncoding offsets.
Fixes #1097.

* src/cff/cffload.c (cff_encoding_load): Set special offset values.
2021-09-16 23:08:46 -04:00
Alexei Podtelezhnikov fce74b7365 [cache] Miscellaneous clean-ups.
* src/cache/ftccache.c (ftc_get_top_node_for_hash, FTC_Cache_Clear):
Remove barely used variables.
(ftc_cache_add): Adjust casting.
* src/cache/ftccmap.c (FTC_CMapCache_Lookup): Remove casting.
* src/cache/ftcsbits.c (ftc_snode_load): Remove casting.
2021-09-16 17:03:19 -04:00
Alexei Podtelezhnikov 79d14cc256 * src/cff/cffload.c (cff_fd_select_get): Remove casting. 2021-09-16 16:41:56 -04:00
Alexei Podtelezhnikov ae516e6a43 * src/pcf/pcfread.c (pcf_read_TOC): Remove casting. 2021-09-16 16:39:23 -04:00
Alexei Podtelezhnikov 801b7540dc Minor type adjustments.
* src/cff/cffobjs.c (cff_face_init): Reduce casting.
* src/truetype/ttobjs.c (tt_size_ready_bytecode): Ditto.
* src/type1/t1load.c (T1_Set_MM_Design): Ditto.
2021-09-14 22:55:50 -04:00
Alexei Podtelezhnikov 49270c1701 Replace boolean allocation macros with MEM ones.
* src/base/ftbitmap.c (FT_Bitmap_Copy): Use MEM-macro.
* src/base/ftobjs.c (ft_glyphslot_alloc_bitmap): Ditto.
* src/bzip2/ftbzip2.c (ft_bzip2_alloc): Ditto.
* src/cache/ftccache.c (ftc_cache_init): Ditto
* src/gzip/ftgzip.c (ft_gzip_alloc): Ditto.
* src/psnames/psmodule.c (ps_unicodes_init): Ditto.
* src/sfnt/sfobjs.c (sfnt_load_face): Ditto.
* src/sfnt/ttload.c (tt_face_load_name): Ditto.
2021-09-14 21:32:43 -04:00
Alexei Podtelezhnikov 9a4c846e60 [cache] Revert to some zeroing.
* src/cache/ftccache.c (ftc_cache_init, ftc_cache_resize): Zero
`buckets` again to fix some crashes.
2021-09-14 21:25:47 -04:00
Alexei Podtelezhnikov 0a8ee851e0 * src/pshinter/pshrec.c (ps_mask_table_merge_all): Tweak loops.
Fixes fallout from 731d0b6856 reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=38685
2021-09-14 10:26:37 -04:00
Alexei Podtelezhnikov 731d0b6856 [cff, pshinter] Clean up unsigned counters.
Loops with unsigned decrement can be reliably stopped when the counter
wraps around after reaching zero.

* src/cff/cffload.c (cff_charset_compute_cids): Use unsigned counter.
* src/pshinter/pshalgo.c (psh_hint_table_activate_mask): Ditto.
* src/pshinter/pshrec.c (ps_mask_table_merge): Ditto.
2021-09-13 16:29:08 -04:00
Alexei Podtelezhnikov 058f3f2d7d [bdf, psnames, sfnt] Avoid some memory zeroing.
* src/bdf/bdfdrivr.c (BDF_Face_Init): Use Q-macro.
* src/sfnt/sfobjs.c (sfnt_load_face): Ditto.
* src/psnames/psmodule.c (src/psnames/psmodule.c): Remove zero.
2021-09-13 16:24:25 -04:00
Alexei Podtelezhnikov 59b43ae663 * src/base/ftobjs.c (FT_CMap_New): Revert to zeroing.
Fixes fallout from c1fa7aa2bc, reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=38641
2021-09-13 16:16:18 -04:00
Alexei Podtelezhnikov 073ff2d77e [truetype] Clean up `exec` initialization.
* src/truetype/ttinterp.c (Init_Context): Absorbed into...
(TT_New_Context): ... this function.
2021-09-13 00:04:45 -04:00
Alexei Podtelezhnikov fab94f9fcc [truetype] Avoid some memory zeroing.
* src/truetype/ttgload.c (load_truetype_glyph): Use Q-macro.
* src/truetype/ttinterp.c (Update_Max): Ditto.
* src/truetype/ttpload.c (src/truetype/ttpload.c): Ditto.
2021-09-12 23:30:07 -04:00
Alexei Podtelezhnikov c1fa7aa2bc [base] Avoid some memory zeroing.
* src/base/ftobjs.c (FT_New_Size, FT_CMap_New, FT_CMap_Done,
ft_open_face_internal, ft_open_face_internal): Use Q-macros.
2021-09-12 23:25:46 -04:00
Alexei Podtelezhnikov a8e8d9d7a4 [cache, psaux] Remove zeros.
* src/cache/ftcmru.c (FTC_MruList_New): Remove initialization.
* src/psaux/psstack.c (cf2_stack_init): Ditto.
2021-09-12 23:21:32 -04:00
Alexei Podtelezhnikov 9870b6c07e [cache] Avoid some memory zeroing.
* src/cache/ftcmru.c (FTC_MruList_New): Use Q-macro.
* src/cache/ftcmanag.c (FTC_Manager_RegisterCache): Ditto.
* src/cache/ftccache.c (ftc_cache_init, ftc_cache_resize): Ditto.
2021-09-12 14:32:22 -04:00
Alexei Podtelezhnikov 2d57b05928 * src/cache/ftcmanag.c (FTC_Manager_New): Add missing zero.
Fixes fall out from a7b199d081.
2021-09-11 10:38:08 -04:00
Alexei Podtelezhnikov 5b626281f1 [truetype] Tweak `hdmx` checking.
Fixes #1096.

* src/truetype/ttpload.c (tt_face_load_hdmx): Account for padding.
2021-09-10 10:19:07 -04:00
Alexei Podtelezhnikov e942a31007 [truetype] Tweak `loca` clamping.
Fixes #1095.

* src/truetype/ttpload.c (tt_face_load_loca): Fix up clamping.
* include/freetype/internal/tttypes.h (TT_Face): Correct docs.
2021-09-09 22:17:46 -04:00
Alexei Podtelezhnikov c350aac099 Fortify memory debugging (cont'd).
* src/base/ftdbgmem.c (FT_DumpMemory): Check for active debugger.
(ft_mem_table_destroy): Move `FT_DumpMemory` call from here...
(ft_mem_debug_done): ... to here.
2021-09-08 12:18:23 -04:00
Alexei Podtelezhnikov 63806aad9f Fortify memory debugging.
These changes are neccessary to properly recover `memory->user` that
holds the Windows heap handle now.

* src/base/ftdbgmem.c (ft_mem_debug_init): Handle all table allocations,
initializations, and sizing instead of...
(ft_mem_table_new): ... this function removed.
(ft_mem_debug_done): Better check for the active debugger and free the
debugger table here instead of...
(ft_mem_table_destroy): ... here.
2021-09-08 10:54:44 -04:00
Werner Lemberg 77dcc5ed6a src/tools/ftrandom/ftrandom.c (_XOPEN_SOURCE): Set to 600.
This allows C99 compilation on Solaris.

Problem reported by Mojca Miklavec.
2021-09-07 18:51:53 -07:00
Werner Lemberg 60a93ea231 [dlg] Synchronize with upstream.
* src/dlg/dlgwrap.c (_XOPEN_SOURCE): Set to 600.

Fixes #1093.
2021-09-07 06:40:55 -07:00
Alexei Podtelezhnikov aee1fd3bb8 Cosmetic zeros. 2021-09-03 22:13:22 -04:00
Alexei Podtelezhnikov 7bf655b228 * src/bdf/bdflib.c (_bdf_parse_start): Keep parser memory. 2021-09-03 11:31:41 -04:00
Alexei Podtelezhnikov 7f8f0c1c70 [smooth, raster, sdf] Clean up initialization calls.
* src/raster/ftraster.c (ft_black_init): Removed.
(ft_black_new): Clean up.
* src/sdf/ftbsdf.c (bsdf_raster_new): Ditto.
* src/sdf/ftsdf.c (sdf_raster_new): Ditto.
* src/smooth/ftgrays.c (gray_raster_new): Ditto.
2021-09-02 23:30:31 -04:00
Alexei Podtelezhnikov a7b199d081 * src/cache/ftcmanag.c (FTC_Manager_New): Avoid some zeroing. 2021-09-02 22:58:50 -04:00
Alexei Podtelezhnikov 0a6f0f8fed * src/bdf/bdflib.c (bdf_load_font): Remove memory shuffling. 2021-09-02 22:52:21 -04:00
Alexei Podtelezhnikov a81cf5aade Cosmetic zeros. 2021-09-02 22:10:57 -04:00
Alexei Podtelezhnikov 7482c98f15 [base] Clean up stream reading.
* src/base/ftstream.c (FT_Stream_ReadUShort, FT_Stream_ReadUOffset,
FT_Stream_ReadULong and their LE variants): Remove unnecessary
initialization and slightly refactor.
(FT_Stream_GetByte, FT_Stream_ReadByte): Rename to return unsigned
value and align with sister functions.

* include/freetype/internal/ftstream.h (FT_Stream_GetByte,
FT_Stream_ReadByte): Update prototypes and caller macros.
2021-09-01 22:18:29 -04:00
Alexei Podtelezhnikov 612925ff22 s/0/NULL/ where appropriate. 2021-09-01 21:37:21 -04:00
Alexei Podtelezhnikov b6c11d494e [smooth] Reduce shift in multiply-shift optimization.
* src/smooth/ftgrays.c (FT_UDIVPREP, FT_UDIV): Reduce shift.

Smaller shifts that keep the division operands of FT_UDIVPREP within
32 bits result in slightly faster divisions, which is noticeable in
the overall performance.  The loss of precision is tolerable until the
divisors (the components dx and dy) approach 32 - PIXEL_BITS. With
PIXEL_BITS = 8, this corresponds to 65,000 pixels or the bitmap size
that we refuse to render anyway.

Using `ftbench -p -s60 -t5 -bc timesi.ttf`,

Before: 8.52 us/op
After:  8.32 us/op
2021-08-30 07:09:53 -04:00
Werner Lemberg d1c2000504 [truetype] Fix compilation if !TT_CONFIG_OPTION_BYTECODE_INTERPRETER.
* src/truetype/ttgxvar.c (tt_cvt_ready_iterator): Compile function
conditionally.
(tt_face_vary_cvt) [!TT_CONFIG_OPTION_BYTECODE_INTERPRETER]: Add code.

Fixes #1091.
2021-08-28 07:36:08 +02:00
Ben Wagner a842a0984b [smooth] Detect SSE2 with MSVC for x86
MSVC does not set `__SSE2__`. Instead one must check whether `_M_IX86_FP` is
defined and greater than or equal to 2.

* src/smooth/ftgrays.c (FT_SSE2): New macro.
Use it where appropriate.
2021-08-27 09:20:26 +02:00
Alexei Podtelezhnikov 3785393d1a Expand comment (cont'd). 2021-08-26 15:31:11 +00:00
Alexei Podtelezhnikov 686e2a5eb3 Expand comment. 2021-08-25 23:18:43 +00:00
Alexei Podtelezhnikov f7f9cb0dde * src/smooth/ftgrays.c (gray_render_conic): Refactor redundancy. 2021-08-24 15:29:06 -04:00
suzuki toshiya 5031835790 [truetype] Fix for the family name shorter than 8 characters.
* src/truetype/ttobjs.c (tt_skip_pdffont_random_tag):
If the family name to be checked is shorter than 8 characters,
do not check its syntax.
2021-08-25 00:31:26 +09:00
suzuki toshiya c4fc0e690c [truetype] Simplify `trick_names'.
* src/truetype/ttobjs.c (tt_check_trickyness_family): For the case
that the beginning part of a long tricky family name is already
registered as another tricky family name, no need to double-check
the longer one.  Such long tricky family names are removed from
the `trick_names'.
2021-08-24 16:58:11 +09:00
suzuki toshiya 992382ba29 [truetype] Add 2 tricky font names.
Additional fix for the issue #1087.

* src/truetype/ttobjs.c (tt_check_trickyness_family): Add 2 tricky
font names reported in #1087.
2021-08-24 16:51:54 +09:00
suzuki toshiya 2b3ccd6e26 [truetype] New function to skip the randomization tag.
* src/truetype/ttobjs.c (tt_skip_pdffont_random_tag):
New function to skip the randomization tag in the names of the
fonts embedded in a PDF.  It is used by tt_check_trickyness_family(),
to keep from mistaking "DLC" in the randomization tag as a
tricky font name. See discussion in:

https://lists.nongnu.org/archive/html/freetype-devel/2021-02/msg00002.html

For technical detail about the randomization tag, please find
PDF Reference 5.5.3 "Font Subsets".  Thanks to Justyna Wawrzynska
for pointing out the issue caused by the randomization tag.
2021-08-24 16:49:34 +09:00
suzuki toshiya 1c23982dd2 [truetype] Add checksums for 2 tricky fonts.
Thanks to Ting717 for providing sample PDF. Fixes #1087.

* src/truetype/ttobjs.c (tt_check_trickyness_sfnt_ids): Add
checksums for 2 tricky fonts `DFHei-Bd-WIN-HK-BF' and
`DFMing-Md-WIN-HK-BF'.
2021-08-24 16:46:06 +09:00
Alexei Podtelezhnikov 78f2bd0bd3 Whitespace formatting. 2021-08-22 22:32:07 -04:00
Alexei Podtelezhnikov d92aa23fd7 Decorate const arguments.
* src/base/ftglyph.c (FT_Glyph_Transform, FT_Glyph_To_Bitmap): Do it.
* include/freetype/ftglyph.h (FT_Glyph_Transform, FT_Glyph_To_Bitmap):
Do it.
2021-08-22 13:12:45 -04:00
Alexei Podtelezhnikov d62d583d92 [smooth] Clean up the null cell usage.
Put the null cell at the end of the pool and store it explicitly so that
we can use it as both the limit and the dumpster.

* src/smooth/ftgrays.c (gray_TWorker): Store the last `cell_null` and
remove unnecesary fields.
(NULL_CELL_PTR, CELL_IS_NULL): Remove in favor of explicit `cell_null`.
(gray_dump_cells, gray_set_cell, gray_sweep{,_direct}): Update callers.
(gray_convert_glyph_inner): Trace remaining cells (oh well).
(gray_convert_glyph): Set up `cell_null` and slightly improve the pool
management.
2021-08-20 23:40:49 -04:00
Alexei Podtelezhnikov 6e9d8d314f [base] Restore quiet no-op rendering of bitmap glyphs.
Fixes #1076.

* src/base/ftobjs.c (FT_Render_Glyph_Internal): Discard an error when
rendering a bitmap glyph.
2021-08-20 16:01:32 -04:00
Alexei Podtelezhnikov de3b5c201c [smooth] Fortify 64-bit algorithm.
* src/smooth/ftgrays.c (FT_UDIVPREP, FT_UDIV): s/long/FT_Int64/ and
s/unsigned long/FT_UInt64/.
(gray_render_line): Adjust a critical variable type.
2021-08-20 13:51:40 -04:00
Dominik Röttsches 633fe08764 [sfnt] Fix format expectation for `COLR` v1 ClipList
* src/sfnt/ttcolr.c (tt_face_get_color_glyph_clipbox): Change ClipList
format expectation to 1 instead of 0 to make it compliant with the
latest spec.
2021-08-19 21:35:08 +00:00
Alexei Podtelezhnikov 857038399a Use FT_INT64 instead of FT_LONG64.
* include/freetype/config/integer-types.h: Remove synonymous FT_LONG64.
* include/freetype/internal/ftcalc.h: s/FT_LONG64/FT_INT64/.
* src/base/ftcalc.c: Ditto.
* src/base/fttrigon.c: Ditto.
* src/smooth/ftgrays.c: Ditto.
2021-08-18 23:05:51 -04:00
Werner Lemberg f44c2d5860 * src/sdf/ftsdf.c (get_control_box): Fix compiler warning. 2021-08-18 08:52:21 +02:00
Werner Lemberg f11f3ed15b [base] Fix ppem size overflow.
Fixes #1086.

* src/base/ftobjs.c (FT_Request_Metrics): Add return value.
Check whether ppem values fit into unsigned short values.
(FT_Request_Size): Updated.

* include/freetype/internal/ftobjs.h: Updated.

* src/cff/cffobjs.c (cff_size_request), src/cid/cidobjs.c
(cid_size_request), src/truetype/ttdriver.c (tt_size_request),
src/type1/t1objs.c (T1_Size_Request): Updated.
2021-08-18 07:27:02 +02:00
Werner Lemberg fed5521016 * src/sfnt/ttcolr.c (tt_face_get_color_glyph_clipbox): Minor fix. 2021-08-09 19:27:34 +02:00
Werner Lemberg 18fc64e6a3 [smooth] Avoid integer overflow.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=36243

* src/smooth/ftgrays.c(ADD_LONG, SUB_LONG, MUL_LONG, NEG_LONG)
[STANDALONE_]: Removed, unused.
(ADD_INT) [STANDALONE_]: New macro.
(FT_INTEGRATE): Use ADD_INT.
2021-08-07 17:16:52 +02:00
Dominik Röttsches 47cf8ebf4a [sfnt] Add API for retrieving a 'COLR' v1 'ClipBox' table.
The optional 'COLR' v1 glyph-specific clip box helps upstream graphics
libraries allocate a sufficiently large bitmap for a glyph without having to
traverse the glyph graph for that.  See

  https://github.com/googlefonts/colr-gradients-spec/issues/251

for background on the introduction of this specification change.

* include/freetype/ftcolor.h (FT_ClipBox): New structure.
(FT_Get_Color_Glyph_ClipBox): New function declaration.

* include/freetype/internal/sfnt.h (TT_Get_Color_Glyph_ClipBox_Func):
New function type.
(SFNT_Interface, FT_DEFINE_SFNT_INTERFACE): Use it.

* src/base/ftobjs.c (FT_Get_Color_Glyph_ClipBox): New function to link API
with SFNT implementation.

* src/sfnt/sfdriver.c (sfnt_interface): Updated.
* src/sfnt/ttcolr.c (Colr): New field `clip_list`.
(tt_face_load_colr): Parse global clip list offset.
(tt_face_get_color_glyph_clipbox): New function to find the clip box for a
glyph id from the clip list array.
* src/sfnt/ttcolr.h: Updated.
2021-08-07 14:44:05 +02:00
Werner Lemberg 6be8bfe499 [smooth] Fix left shifts of negative numbers.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=36241

* src/smooth/ftgrays.c (LEFT_SHIFT): New macro.
(gray_render_conic) [BEZIER_USE_DDA]: Use it.
2021-08-06 08:31:22 +02:00
Anuj Verma be6ab31900 [sdf] Fix out-of-range-access.
* src/sdf/ftbsdf.c (first_pass, second_pass): Fix range during forward pass.
Otherwise the index goes out of range for the last column.

Fixes issue #1077.
2021-08-02 06:49:50 +02:00
Anuj Verma ebcc96e559 Fix invalid memory access in `bsdf` rasterizer.
Do not generate SDF from bitmap if the `FT_GLYPH_OWN_BITMAP` flag is not
set.  In some cases the bitmap buffer is freed but still points to a valid
address; to handle those cases check the flag before accessing the memory.

* src/sdf/ftsdfrend.c (ft_bsdf_render): Handle the above case.
Also, return an error message if the bitmap's rows/pitch is invalid,
otherwise `slot->buffer` might be assigned to some invalid memory location.
(ft_sdf_render): Same as above.
Plus, move the outline back to original state after rasterization and not if
any error occurs.

Signed-off-by: Anuj Verma <anujv@iitbhilai.ac.in>
2021-08-02 05:51:15 +02:00
Werner Lemberg d2367abac0 src/sfnt/ttcolr.c: Minor formatting. 2021-07-29 08:16:25 +02:00
Dominik Röttsches 30a82e1e5d [sfnt] 'COLR' v1 PaintSweepGradient spec update
* src/sfnt/ttcolr.c (read_paint): PaintSweepGradient follows other
spec changes and now has the angles specified as F2DOT14, reflect
that in the implementation.
* include/freetype/ftcolor.h (FT_PaintSweepGradient): Update
documentation.
2021-07-29 06:12:51 +00:00
Dominik Röttsches 5c0ac7a435 [sfnt] Retrieve affine matrix from offset in 'COLR' v1 parsing.
* src/sfnt/ttcolr.c (read_paint): Implement spec change where
affine transform matrix is now referenced by offset instead of
being placed inline in the PaintTransform table.
2021-07-29 06:05:18 +00:00
Dominik Röttsches 66189807b8 [sfnt] 'COLR' v1 PaintSkew related spec updates
* src/sfnt/ttcolr.c (read_paint): Implement spec changes around
PaintSkew, PaintSkewAroundCenter.  Update parsing to read shorter
values as changed in the spec.
* include/freetype/ftcolor.h (FT_PaintSkew): Update documentation.
2021-07-29 06:01:34 +00:00
Dominik Röttsches 48df0fa652 [sfnt] PaintRotate/PaintRotateAroundCenter spec updates
* src/sfnt/ttcolr.c (read_paint): Implement spec change where
PaintRotate and PaintRotateAroundCenter were split for a more
compact format definition.  Update parsing to read shorter values
as changed in the spec.
* include/freetype/ftcolor.h (FT_PaintRotate): Update documentation.
2021-07-29 05:59:30 +00:00
Dominik Röttsches d7bdcb1bb5 [sfnt] 'COLR' v1 PaintTranslate and PaintScale precision
* src/sfnt/ttcolr.c (read_paint): Implement spec changes in
PaintTranslate and PaintScale and friends.  Update parsing to read
new shorter values.
2021-07-29 05:56:15 +00:00
Werner Lemberg c2fa51d9bd Fix some `cppcheck` warnings.
* src/bzip2/ftbzip2.c (ft_bzip2_file_skip_output), src/gzip/ftgzip.c
(ft_gzip_file_skip_output): Reduce scope of `delta`.

* src/psaux/psintrp.c, src/psaux/psintrp.h (cf2_interpT2CharString): Add
`const` to `buf` parameter.

* src/raster/ftraster.c (DelOld): Add `const` to `profile` parameter.
(Vertical_Sweep_Span): Reduce scope of `target`.
(FT_Outline_Get_CBox): Reduce scope of `xMin`, `xMax`, `yMin`, `yMax`.

* src/smooth/ftgrays.c (gray_render_conic): Reduce scope of `split`.
(gray_sweep, gray_sweep_direct): Reduce scope of `area`.

* src/tools/apinames.c (names_dump) <OUTPUT_WATCOM_LBC>: Reduce scope of
`temp`.
2021-07-24 20:32:16 +02:00
Ben Wagner 5bcaf51b61 [autofit] Split `afwrtsys.h`.
The header file `afwrtsys.h` has two distinct functions: to include the
required writing system headers and also to generate code for each writing
system.  At each current use site only one or the other is used, with
various macro trickery selecting one or the other.  Split this header into
`afws-decl.h` for the required writing system declarations and `afws-iter.h`
for iterating over the writing systems to generate code.

The motivation for this change is that the Visual C++ compiler treats the
standard include guard idiom like `#pragma once` 'if no non-comment code or
preprocessor directive comes before or after the standard form of the
idiom'.  It appears to check this after macro expansion, so if
`WRITING_SYSTEM` expands to empty the bottom of `afwrtsys.h` is empty and
looks like the standard include guard idiom which is treated like `#pragma
once`, so subsequent inclusion of `afwrtsys.h` is elided.

Fixes #1075.

* src/autofit/afglobal.c (af_writing_system_classes), src/autofit/aftypes.h
(AF_WritingSystem), src/autofit/rules.mk (AUTOF_DRV_H): Updated.

* src/autofit/afwrtsys.h: Split into...
* src/autofit/afws-decl.h, src/autofit/afws-iter.h: New files.
2021-07-24 07:29:17 +02:00
Werner Lemberg 801cd842e2 * Version 2.11.0 released.
==========================

Tag sources with `VER-2-11-0'.

* docs/VERSION.TXT: Add entry for version 2.11.0.
* docs/CHANGES: Updated.

* README, src/base/ftver.rc, builds/windows/vc2010/index.html,
builds/windows/visualc/index.html,
builds/windows/visualce/index.html,
builds/wince/vc2005-ce/index.html,
builds/wince/vc2008-ce/index.html, docs/freetype-config.1:
s/2.10.4/2.11.0/, s/2104/2110/.

* include/freetype/freetype.h (FREETYPE_MINOR): Set to 11.
(FREETYPE_PATCH): Set to 0.

* builds/unix/configure.raw (version_info): Set to 24:0:18.
* CMakeLists.txt (VERSION_MINOR): Set to 11.
(VERSION_PATCH): Set to 0.

* builds/toplevel.mk (dist): Ignore more git-related files.
2021-07-19 18:07:51 +02:00
David Turner 357b353c2a * src/smooth/ftgrays.c: Fix compilation if `FT_LONG64` is undefined.
The code assumed that if `__SSE2__` is defined, then 64-bit integer
types are available.  This is not the case apparently for certain
multilib compiler targets like 'x86_32.x86' used by Gentoo.

This patch fixes the issue by disabling the special code path when
64-bit integer types are not available.

Fixes #1071.
2021-07-17 08:31:20 +02:00
Werner Lemberg 552fc97fe5 [smooth] Minor fixes.
* src/smooth/ftgrays.c (gray_render_conic): Move variable and
structure declarations to beginning of function.  Inspite of C99
compliance we still do this for the sake of backward compatibility.
This also avoids a shadowing declaration of `count`.
(gray_convert_glyph_inner): Fix typo.
2021-07-16 07:49:20 +02:00
Werner Lemberg 93771d619f Formatting and ChangeLog additions for previous commits. 2021-07-16 07:40:56 +02:00
Ben Wagner c37c087382 Guard inclusion of emmintrin.h
Guard inclusion of emmintrin.h with "#ifdef __SSE2__". The gcc version
of this header, xmmintrin.h, and mmintrin.h check that the appropriate
defines are set before defining anything (are internally guarded).
However the clang versions of these includes are not internally guarded.
As a result of this, externally guard the inclusion of these headers.
2021-07-15 11:33:16 -04:00
David Turner 56cc2ad446 [smooth] Implement Bezier quadratic arc flattenning with DDA
Benchmarking shows that this provides a very slighty performance
boost when rendering fonts with lots of quadratic bezier arcs,
compared to the recursive arc splitting, but only when SSE2 is
available, or on 64-bit CPUs.

On a 2017 Core i5-7300U CPU on Linux/x86_64:

  ./ftbench -p -s10 -t5 -cb .../DroidSansFallbackFull.ttf

    Before: 4.033 us/op  (best of 5 runs for all numbers)
    After:  3.876 us/op

  ./ftbench -p -s60 -t5 -cb .../DroidSansFallbackFull.ttf

    Before: 13.467 us/op
    After:  13.385 us/op
2021-07-15 13:25:58 +02:00
David Turner 86b9c9347f [smooth] Minor speedup to smooth rasterizer
This speeds up the smooth rasterizer by avoiding a
conditional branches in the hot path. Namely:

- Define a fixed "null cell" which will be pointed
  to whenever the current cell is outside of the current
  target region. This avoids a "ras.cell != NULL"
  check in the FT_INTEGRATE() macro.

- Also use the null cell as a sentinel at the end of
  all ycells[] linked-lists, by setting its x coordinate
  to INT_MAX. This avoids a 'if (!cell)' check in
  gray_set_cell() as well.

- Slightly change the worker struct fields to perform
  a little less operations during rendering.

Example results (on a 2013 Corei5-3337U CPU)

  out/ftbench -p -s10 -t5 -bc /usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf

    Before: 5.472 us/op
    After:  5.275 us/op

  out/ftbench -p -s60 -t5 -bc /usr/share/fonts/truetype/droid/DroidSansFallbackFull.ttf

    Before: 17.988 us/op
    After:  17.389 us/op
2021-07-15 13:25:48 +02:00
Oleg Oshmyan 5d27b10f4c [base] Fix `FT_Open_Face`'s handling of user-supplied streams.
This was already true (though undocumented) most of the time, but
not if `FT_NEW` inside `FT_Stream_New` failed or if the
`FT_OPEN_XXX` flags were bad.

Normally, `FT_Open_Face` calls `FT_Stream_New`, which returns the
user-supplied stream unchanged, and in case of any subsequent error
in `FT_Open_Face`, the stream is closed via `FT_Stream_Free`.

Up to now, however, `FT_Stream_New` allocates a new stream even if
it is already given one by the user.  If this allocation fails, the
user-supplied stream is not returned to `FT_Open_Face` and never
closed.  Moreover, the user cannot detect this situation: all they
see is that `FT_Open_Face` returns `FT_Err_Out_Of_Memory`, but that
can also happen after a different allocation fails within the main
body of `FT_Open_Face`, when the user's stream has already been
closed by `FT_Open_Face`.  It is plausible that the user stream's
`close` method frees memory allocated for the stream object itself,
so the user cannot defensively free it upon `FT_Open_Face` failure
lest it ends up doubly freed.  All in all, this ends up leaking the
memory/resources used by user's stream.

Furthermore, `FT_Stream_New` simply returns an error if the
`FT_OPEN_XXX` flags are unsupported, which can mean either an
invalid combination of flags or a perfectly innocent
`FT_OPEN_STREAM` on a FreeType build that lacks stream support.
With this patch, the user-supplied stream is closed even in these
cases, so the user can be sure that if `FT_Open_Face` failed, the
stream is definitely closed.

* src/base/ftobjs.c (FT_Stream_New): Don't allocate a buffer
unnecessarily.
Move error-handling code to make the control flow more obvious.
Close user-supplied stream if the flags are unsupported.
`FT_Stream_Open` always sets `pathname.pointer`, so remove the
redundant (re)assignment.  None of the `FT_Stream_Open...` functions
uses `stream->memory`, so keep just one assignment at the end,
shared among all possible control flow paths.
('Unsupported flags' that may need a stream closure can be either an
invalid combination of multiple `FT_OPEN_XXX` mode flags or a clean
`FT_OPEN_STREAM` flag on a FreeType build that lacks stream
support.)
2021-07-13 11:00:48 +02:00
Oleg Oshmyan a4c8f21ae7 [base] Reject combinations of incompatible `FT_OPEN_XXX` flags.
The three modes are mutually exclusive, and the documentation of the
`FT_OPEN_XXX` constants notes this.  However, there was no check to
validate this in the code, and the documentation on `FT_Open_Args`
claimed that the corresponding bits were checked in a well-defined
order, implying it was valid (if useless) to specify more than one.
Ironically, this documented order did not agree with the actual
code, so it could not be relied upon; hopefully, nobody did this and
nobody will be hurt by the new validation.

Even if multiple mode bits were allowed, they could cause memory
leaks: if both `FT_OPEN_STREAM` and `stream` are set along with
either `FT_OPEN_MEMORY` or `FT_OPEN_PATHNAME`, then `FT_Stream_New`
allocated a new stream but `FT_Open_Face` marked it as an 'external'
stream, so the stream object was never released.

* src/base/ftobjs.c (FT_Stream_New): Reject incompatible
`FT_OPEN_XXX` flags.
2021-07-13 10:44:38 +02:00
Anuj Verma e592982a83 [sdf] Improve documentation. 2021-07-13 10:00:22 +02:00
Werner Lemberg 825b7ea2f2 [autofit] More clean-ups.
* src/autofit/afhints.h (AF_GlyphHintsRec): Remove the no longer
needed fields `xmin_delta` and `xmax_delta`.

* src/autofit/afhints.c (af_glyph_hints_reload),
src/autofit/afloader.c (af_loader_load_glyph): Updated.
2021-07-12 22:11:24 +02:00
David Turner a212668c9f Remove obsolete AF_Angle type and related sources.
Move the af_sort_xxx() functions from afangles.c to afhints.c
in order to get rid of the obsolete angle-related types,
macros and function definitions.
2021-07-12 09:25:39 +02:00
David Turner 2f11522a2a Remove experimental auto-hinting 'warp' mode.
This feature was always experimental, and probably nevery worked
properly. This patch completely removes it from the source code,
except for a documentation block describing it for historical
purpose.
2021-07-12 09:25:22 +02:00
David Turner 15e889800a Remove experimental "Latin2" writing system (FT_OPTION_AUTOFIT2)
This code has always been experimental and was never compiled
anyway (FT_OPTION_AUTOFIT2 does not appear in ftoption.h or even
any of our build files).
2021-07-12 09:25:07 +02:00
Werner Lemberg 89c60eca67 * src/base/ftlcdfil.c (FT_Library_SetLcdGeometry): Fix argument.
Reported by Hin-Tak.
2021-07-05 05:41:53 +02:00
Ben Wagner d3dc2da9b2 * src/truetype/ttgxvar.c (tt_set_mm_blend): Test `coords`.
It is undefined behavior to pass `NULL` to `memcpy`.  `coords' is
passed to `memcpy` but `TT_Get_MM_Blend` and `TT_Get_Var_Design`
explictly call `tt_set_mm_blend` with `coords` as `NULL`.  In
addition, `TT_Set_MM_Blend` has a similar possible issue.
2021-07-01 07:02:04 +02:00
Dominik Röttsches 286da6c528 [sfnt] Support PaintScale in 'COLR' v1 parsing.
* include/freetype/ftcolor.h (FT_PaintFormat): Renumber values, add
`FT_COLR_PAINTFORMAT_SCALE`.
(FT_PaintScale): New structure to represent 'PaintScale*' tables.
(FT_COLR_Paint): Updated.

* src/sfnt/ttcolr.c (FT_PaintFormat_Internal): New enumeration.
(read_paint): Parse 'PaintScale' and friends.
2021-07-01 06:49:03 +02:00
Dominik Röttsches 0348c627b1 [sfnt] Handle fonts without layer list in 'COLR' v1.
'COLR' v1 fonts do not necessarily need to have a layer list; for
this reason, 'fontTools' recently started generating fonts in a way
that drops the layer list if there are no layers in it.  This
results in the layer list offset becoming zero, which FreeType
treated as an invalid table.  Fix that and handle the case for layer
list offset being 0.  This slightly changes how we need to calculate
the starting offset for paints.

* src/sfnt/ttcolr.c (tt_face_load_colr): Handle case of layer list
offset being zero without outright rejecting table.
2021-07-01 06:15:22 +02:00
Alexei Podtelezhnikov f27b4834b7 * src/raster/ftraster.c (Render_Single_Pass): Simplify `band_stack'. 2021-06-30 10:54:59 -04:00
Werner Lemberg 90ecac4118 Update `CHANGES` file; other minor doc fixes. 2021-06-30 10:23:42 +02:00
Alexei Podtelezhnikov 69c3516c88 [raster] Do not skip the second pass without dropout control.
The second pass also fixes horizontal lines through the pixel centers.

* src/raster/ftraster.c (black_TWorker): Do not use `second_pass'.
(Render_Glyph): Skip the second pass only with the appropriate flag.
2021-06-29 23:51:23 -04:00
Alexei Podtelezhnikov 3696ac5a18 [raster] Handle sub-band stack locally.
* src/raster/ftraster.c (black_TWorker): Move `band_stack' from here..
(Render_Single_Pass): ... to here and accept limit arguments.
(Render_Glyph): Updated.
2021-06-29 23:27:10 -04:00
Alexei Podtelezhnikov c852388df7 [raster] Handle Bézier stack locally.
* src/raster/ftraster.c (black_TWorker): Move `arcs' from here...
(Conic_To, Cubic_To): ... to here to tighten their scope.
(Bezier_Up, Bezier_Down): ... Take the current `arc' argument.
2021-06-28 23:26:10 -04:00
Dominik Röttsches 7d4e55c329 [sfnt] Improve paint limit checks
Paint tables can appear before the `base_glyphs_v1` offset if the
font is produced with the layer list before the base glyph list.  In
this case paint tables can occur after the layer list but before the
base glyph list.  Checks in the 'COLR' v1 code were rejecting fonts
with this layout.  Improve these checks by calculating a minimum
offset after which paint tables can occur and use that in safety
checks.

* src/sfnt/ttcolr.c (Colr, tt_face_load_colr): Declare
`paint_start_v1` and calculate that as the minimum of the end of
layer list and base glyph list.
(get_child_table_pointer, read_paint, tt_face_get_paint_layers):
Use that in safety checks.
2021-06-28 18:02:55 +02:00
Alexei Podtelezhnikov 3a278381ae [raster] Clean up vertical sweep.
* src/raster/ftraster.c (black_TWorker): Replace the current line
offset with the pointer and drop the increment.
(Function_Sweep_Init): Take values as arguments instead of pointers.
(Vertical_Sweep_*, Horizontal_Sweep_Init, Draw_Sweep): Updated.
2021-06-28 10:22:03 -04:00
Alexei Podtelezhnikov fb4511eb9a [raster] Make `band_top' local variable.
* src/raster/ftraster.c (black_TWorker): Move `band_top' from here...
(Render_Single_Pass): ... to here, and refactor.
(Render_Glyph): Updated.
2021-06-26 08:49:20 -04:00
Alexei Podtelezhnikov f6370e2f05 [raster] Adjust sub-band bisecting limits.
We can bisect a band until it is just a single scan line.  This might
be slow and cause time-outs but if we need to impose limits it should
be elsewhere.

* src/raster/ftraster.c (Render_Single_Pass): Tweak sub-banding.
2021-06-25 22:59:39 -04:00
Alexei Podtelezhnikov bc1029b9c5 * src/raster/ftraster.c (Render_Single_Pass): Remove dead code. 2021-06-25 18:20:57 -04:00
Alexei Podtelezhnikov 1e0cef9e72 [smooth, raster] Fix up and align error codes.
FT_Render_Glyph picked up FAILURE or 1 returned from the raster
function, which became a confusing error code. Instead, return
Raster_Overflow in the unlikely event that banding does not help or
another meaningful error.

* src/smooth/ftgrays.c (gray_convert_glyph_inner, gray_convert_glyph):
Use Raster_Overflow when the rendering pool is exhausted and return it
if banding does not help.
(gray_raster_render): Use Smooth_Err_Ok.

* src/raster/ftraster.c (Render_Single_Pass): Return Raster_Overflow
if banding does not help or another error code.
2021-06-24 00:19:50 -04:00
Alexei Podtelezhnikov d8ac180c88 [smooth, raster] Remove synonymous error macros.
* src/smooth/ftgays.c [STANDALONE_]: s/ErrRaster_/Smooth_Err_/.
(gray_convert_glyph_inner): Updated accordingly.

* src/raster/ftraster.c [STANDALONE_]: Do not abbreviate error macros.
(New_Profile, End_Profile, Insert_Y_Turn, Line_Up, Bezier_Up,
Decompose_Curve, Draw_Sweep, Render_Single_Pass, ft_black_render):
Updated accordingly.
2021-06-23 23:32:02 -04:00
Dominik Röttsches 4cb21b9a92 [sfnt] s/PaintTransformed/PaintTransform/, s/transformed/transform/.
* include/freetype/ftcolor.h (FT_PaintTransformed, FT_PaintFormat,
FT_COLR_Paint): Do it to make it harmonize with other names such as
'PaintTranslate'.

* src/sfnt/ttcolr.c (read_paint, tt_face_get_paint): Ditto.
2021-06-22 20:50:48 +02:00
Werner Lemberg 008e42a12c ftver.rc: Update copyright year. 2021-06-19 15:45:46 +02:00
Werner Lemberg b460a50610 [truetype] Fix integer overflow.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=35312

* src/truetype/ttinterp.c (Ins_JMPR): Use `ADD_LONG`.
2021-06-19 07:03:40 +02:00
Werner Lemberg 232243e749 Prevent hinting if there are too many segments.
This speeds up handling of broken glyphs.

Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=35309

* src/autofit/aflatin.c (af_latin_hints_compute_segments): Implement
it.
2021-06-19 06:41:01 +02:00
Alexei Podtelezhnikov 61bac75963 * src/sdf/ftsdfrend.c (ft_(b)sdf_render): Do not FT_ERROR routinely. 2021-06-18 17:38:00 -04:00
David Turner f8c5c54680 Fix for issue 1063
See https://gitlab.freedesktop.org/freetype/freetype/-/issues/1063
for more details on the bug.
2021-06-16 10:31:12 +02:00
Alexei Podtelezhnikov c6fcd61228 Add a comment. 2021-06-15 22:49:21 -04:00
Alexei Podtelezhnikov 8336d53cff [type42] Fix new memory leak.
We need to inverse inheritance of FT_GlyphSlot_Internal so that we
have a chance to free the rendered bitmap from the parent slot.

* src/type42/t42objs.c (T42_GlyphSlot_Init): Remove the internal parts
of the child `ttslot' and replace it with the parent structure.
(T42_GlyphSlot_Done): Updated accordingly.
2021-06-12 22:33:08 -04:00
Werner Lemberg db0f2c448e [psaux] Fix another assertion.
* src/psaux/psintrp.c (cf2_interpT2CharString)
<cf2_escCALLOTHERSUBR>: Convert assertion into error, since the
problem can happen with invalid user input.

Test case is file

  fuzzing/corpora/legacy/oss-fuzz/5754332360212480-unknown-read

in the `freetype2-testing` repository.
2021-06-12 10:13:08 +02:00
Werner Lemberg a34afe6786 [psaux] Fix assertions.
* src/psaux/pshints.c (cf2_hintmap_adjustHints): Check for overflow
before emitting an assertion error.
2021-06-12 08:40:16 +02:00
Alexei Podtelezhnikov 9bfecfd2b6 * src/truetype/ttinterp.c (TT_RunIns): Optimize tracing. 2021-06-09 23:34:04 -04:00
Alexei Podtelezhnikov 7833e308ef [sdf] Fix SDF positioning.
* src/sdf/ftsdfrend.c (ft_sdf_render, ft_bsdf_render): Add padding to
`bitmap_top' and `bitmap_left'.

* sdf/sdf/ftsdf.c (sdf_generate_with_overlaps): Fix VC++ warning.
2021-06-09 10:40:30 -04:00
Werner Lemberg 08f66322e3 More various documentation improvements and fixes. 2021-06-08 18:23:16 +02:00
Werner Lemberg b24cfc8dcc [sfnt] Sanitize cmap4 table better.
Fixes #1062.

* src/sfnt/ttcmap.c (tt_cmap4_validate): Handle a too-small value of
`length` gracefully.
2021-06-08 15:26:41 +02:00
Dominik Röttsches ee6d03d369 [sfnt] Pointer validity check when reading COLR 'v1' layers
* src/sfnt/ttcolr.c (tt_face_get_paint_layers): In addition to the
existing sanity checks, ensure that the pointer to the layer to be
read is within the 'COLR' v1 table.
2021-06-08 14:29:11 +03:00
Werner Lemberg 41fa19fcea * src/sdf/ftsdfcommon.c: Fix inclusion of header files. 2021-06-08 10:32:20 +02:00
Werner Lemberg 35b21c71e5 [sdf] Make `make multi` work.
* src/sdf/ftsdf.c: Include `ftbitmap.h`.

* src/sdf/ftsdfcommon.h: Move function bodies to `ftsdfcommon.c`.
Include `ftobjs.h` to get definitions of `FT_LOCAL` and friends.

* src/sdf/ftsdfcommon.c: New file.

* src/sdf/rules.mk, src/sdf/sdf.c: Updated.
2021-06-08 09:06:39 +02:00
Werner Lemberg 36ee71714f [sdf] Formatting and improved comments. 2021-06-08 09:00:39 +02:00
Anuj Verma 2b1d556269 [sdf] Use 8 bits for final SDF output instead of 16bits.
Since 8-bits is enough to represent SDF data we no longer require
16-bits for  this purpose. Also, we now normalize the output data
to use the entire 8-bit range efficiently. For example: if we use
3.5 format with a spread of 1 we basically only use the starting
5-bits. By normalizing we can use the entire 8-bit range.

* include/freetype/freetype.h (FT_Render_Mode): Updated description
for `FT_RENDER_MODE_SDF` regarding this change.

* include/freetype/ftimage.h (FT_Pixel_Mode): Removed
`FT_PIXEL_MODE_GRAY16` since no longer required.

* include/freetype/fttypes.h (FT_F6Dot10): Removed since no longer
required.

* src/sdf/ftsdfrend.c (ft_sdf_render, ft_bsdf_render): Allocate 8-bit
bitmap instead of 16-bit buffer.

* src/sdf/ftsdfcommon.h (map_fixed_to_sdf): Added function to convert
16.16 distance value to our desired format.

* src/sdf/ftsdf.c (sdf_generate_with_overlaps,
sdf_generate_bounding_box): Use the new `map_fixed_to_sdf` function
and also use 8-bit output buffer.

* src/sdf/ftbsdf.c (finalize_sdf): Output to a 8-bit buffer instead
of 16-bit buffer.
2021-06-08 08:29:34 +05:30
Ben Wagner 2a6665a4c0 [sfnt] Fix fallout from 2021-05-29 change.
* src/sfnt/ttcolr.c (find_base_glyph_record,
find_base_glyph_v1_record): Adjust binary search.

Needs to be updated with change to unsigned.
2021-06-02 07:19:07 +02:00
Werner Lemberg 7ca7da9d13 * src/autofit/aflatin.c (af_latin_metrics_scale_dim): Fix tracing.
Problem reported by Alexei.
2021-06-02 06:59:01 +02:00
Werner Lemberg 0abbc9f512 [psaux] Fix MSVC compiler warnings.
* src/psaux/afmparse.c (afm_parse_track_kern, afm_parse_kern_pairs):
Add cast.
2021-06-02 06:36:11 +02:00
Werner Lemberg 6e253b26b2 Typos in previous commit. 2021-05-29 11:07:10 +02:00
Werner Lemberg a50c39aa8e Fix compilation errors and (some) warnings for clang++.
* src/autofit/afmodule.c (AF_GlyphHintsRec): Make it static.

* src/cache/ftcache.c (FTC_Cache_NewNode), src/cache/ftcsbits.c
(ftc_snode_compare): Remove semicolon.

* src/cff/cffparse.c (cff_parser_run): Add `break` statement.

* src/cid/cidload.c (cid_hex_to_binary): Add cast.

* src/sdf/ftbsdf.c (CHECK_NEIGHBOR): Use `do {} while(0)` loop.
(bsdf_init_distance_map, finalize_sdf, bsdf_raster_render): Add
casts.
* src/sdf/ftsdf.c (sdf_generate_bounding_box,
sdf_generate_with_overlaps): Ditto.
* src/sdf/ftsdfcommon.h (square_root): Ditto.
* src/sdf/ftsdfrend.c (sdf_property_get, ft_sdf_render,
ft_bsdf_render): Ditto.

* src/sfnt/ttcolr.c (find_base_glyph_record,
find_base_glyph_v1_record): Fix variable signedness.
(read_color_line): Add cast.
(read_paint): Add casts.
Fix signedness issue.
(tt_face_get_colorline_stops) Fix signedness issues.

* src/sfnt/ttpost.c (load_format_20): Add casts.

* src/truetype/ttsubpix.c (TWEAK_RULES, TWEAK_RULES_EXCEPTIONS):
Remove final semicolons.
2021-05-29 09:51:04 +02:00
Alexei Podtelezhnikov 28eee3636c [type42] Fix auto-hinting.
The autohinter could not access the base (unscaled) outline in the
child TrueType glyph slot. We now share the internal parts between
the parent and child glyph slots. Fixes #1057.

* src/type42/t42objs.c (T42_GlyphSlot_Init): Remove the internal parts
of `T42_GlyphSlot' and replace it with the child TrueType structure.
(T42_GlyphSlot_Done): Updated accordingly.
2021-05-27 11:38:56 -04:00
Werner Lemberg 0d1c306e51 [psaux] Guard and trace AFM kern data allocation.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=31543

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

* src/psaux/afmparse.c (FT_COMPONENT): Define.
(afm_parse_track_kern, afm_parse_kern_pairs): Protect against
allocations bombs.
Add tracing.
(afm_parse_kern_data): Don't allow multiple kern data sections.
2021-05-25 11:27:56 +02:00
Alexei Podtelezhnikov 2468e59af1 [type42] Avoid some memory zeroing.
* src/type42/t42objs.c (T42_Open_Face): Tweak allocation macro.
* src/type42/t42parse.c (t42_parse_sfnts): Ditto.
2021-05-20 22:20:36 -04:00
Ben Wagner 06e21ffedf [gzip] Use exact type for `ft_gzip_alloc` and `ft_gzip_free`.
While a function pointer may be cast to another function pointer
type, it is required to cast the function pointer back to the
original function pointer type before calling it.  If a parameter is
a pointer the exact pointer type is required.  Using a pointer to a
different underlying type is technically undefined behavior.  The
wrapper functions `ft_gzip_alloc` and `ft_gzip_free` took
`FT_Memory` (a `FT_MemoryRec_*`) instead of `voidpf` (`void*`), so
when gzip calls these callbacks through `alloc_func` or `free_func`
it invokes undefined behavior.  On most platforms this works out as
expected, but newer undefined behavior detectors and targets like
wasm can detect this and will produce an error.

* src/gzip/ftgzip.c (ft_gzip_alloc, ft_gzip_free): Update signatures
to exactly match `alloc_func` and `free_func`, respectively.
Internally, cast the `void*` opaque pointer to `FT_Memory`.
2021-05-19 09:07:33 +02:00
Alexei Podtelezhnikov 1bc801b0d6 [sfnt] Additional guards on the POST table.
Fixes timeout (#1055) analyzed by Ben Wagner, reported as

  https://crbug.com/1194092

* src/sfnt/ttload.c (tt_face_load_post): Check POST format.
* src/sfnt/sfobjs.c (sfnt_load_face): Synthesize the missing unicode
charmap only if the glyph names exist.
* src/psnames/psmodule.c (ps_unicode_value): Short cut ".notdef" and
".null".
2021-05-16 23:12:01 -04:00
Daniel McArdle de15165774 [psaux] Use doubling allocation strategy for CF2_ArrStack.
Fixes timeout reported as

  https://crbug.com/1206181

* src/psaux/psarrst.c (cf2_arrstack_{push,init}): Implement it.
* src/psaux/psarrst.h (CF2_ArrStackiRec): Drop `chunk'.
2021-05-13 23:08:31 -04:00
Alexei Podtelezhnikov 2d3f5dd294 * src/smooth/ftgrays.c (FT_MAX_GRAY_SPANS): Increase from 10 to 16.
Ten was barely enough for two slanted stems. Sixteen can actually fit
a bit more complicated scanlines.
2021-05-12 17:24:35 -04:00
Alexei Podtelezhnikov c653b8d2f1 * src/smooth/ftgrays.c (FT_GRAY_SET): Adjust for better code. 2021-05-12 16:17:21 -04:00
Alexei Podtelezhnikov 8f43d324d1 [smooth] Faster bitmap sweeping.
Selecting the fill rule or checking the direct mode each time we call
`gray_hline' is sub-optimal.  This effectively splits the direct mode
into a separate code path while inlining `gray_hline' and saving 5-7%
of rendering time.

* src/smooth/ftgrays.c (gray_hline): Eliminated in favor of...
(FT_FILL_RULE, FT_GRAY_SET): ... these new macros...
(gray_sweep): ... inlined here.
(gray_sweep_direct): New function that handles the direct span buffer.
(gray_TWorker): Remove the span buffer.
(gray_raster_render, gray_convert_glyph): Updated.
2021-05-12 00:04:59 -04:00
Alexei Podtelezhnikov b070264521 * src/smooth/ftgrays.c (gray_hline): Simplify even-odd computations.
It is too bad the even-odd rule is not used much.
2021-05-10 22:06:01 -04:00
Alexei Podtelezhnikov 967a34eee3 [type1] Avoid MM memory zeroing.
* src/type1/t1load.c (t1_allocate_blend, parse_blend_design_map):
Tweak allocation macros.
* src/type1/t1objs.c (T1_Face_Done): Minor.
2021-05-07 19:17:48 -04:00
Alexei Podtelezhnikov 2f62d8e075 * src/bdf/bdflib.c (_bdf_list_ensure): Tweak allocation macro. 2021-05-07 09:33:41 -04:00
Alexei Podtelezhnikov 79ed536d01 * src/psaux/psobjs.c (ps_parser_load_field): Tweak allocation macro. 2021-05-06 23:46:46 -04:00
Alexei Podtelezhnikov 44c59414eb * src/sfnt/sfobjs.c (sfnt_load_face): Tweak allocation macro. 2021-05-06 22:54:03 -04:00
Alexei Podtelezhnikov 998c7c0f1c * src/cid/cidload.c (cid_read_subrs): Tweak allocation macro. 2021-05-06 22:51:37 -04:00
Alexei Podtelezhnikov 2d95784885 * src/base/ftrfork.c (FT_Raccess_Get_DataOffsets): Tweak allocation. 2021-05-06 22:49:13 -04:00
Alexei Podtelezhnikov 8150ed0db2 [cff,psaux] Avoid memory zeroing (contd.).
* src/cff/cffload.c (cff_blend_doBlend, cff_blend_build_vector): Tweak
allocation macros.
* src/psaux/psarrst.c (cf2_arrstack_setNumElements): Ditto.
* src/psaux/psstack.c (cf2_stack_init): Ditto.
2021-05-05 23:30:46 -04:00
Ben Wagner 82fd32d674 * src/cid/cidload.c (cid_hex_to_binary): Improve return value.
Add argument to return the actual number of bytes that were decoded.
The actual number of bytes decoded can be quite variable depending
on the number of ignored 'whitespace' bytes or early termination
with `>`.
(cid_face_open): Updated to use this calculated value.  This avoids
trusting `parser->binary_length` is always be correct and reading
uninitialized bits if fewer are actually decoded.

First reported as

  https://crbug.com/1203240
2021-05-04 08:56:10 +02:00