Commit Graph

1519 Commits

Author SHA1 Message Date
Alexei Podtelezhnikov 47574f7ea4 Update all copyright notices. 2024-01-27 11:11:22 -05: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 49781ab72b Comment typos. 2023-09-24 20:09:17 -04:00
Alexei Podtelezhnikov 73490681a7 * src/base/ftcalc.c (FT_MOVE_SIGN): Enclose assignments. 2023-09-24 19:39:10 -04:00
Alexei Podtelezhnikov 95b0fe2a6d [base] Reintroduce `FT_SqrtFixed`.
The general square root calculations are not necessary in FreeType.
For vector normalization or length, FreeType uses special functions.
It is, however, required in the legacy CFF specifications.

* src/base/ftcalc.c (FT_SqrtFixed): New function that uses either
Babylonian or bit-wise algorithm, whichever is faster for the given
situation.
* include/freetype/internal/ftcalc.h (FT_SqrtFixed): Declare it.
2023-09-19 22:26:32 -04:00
Alexei Podtelezhnikov babe6af167 * src/base/ftcalc.c /* FT_SqrtFixed */: Fix defunct overflow. 2023-09-18 15:01:26 +00:00
Alexei Podtelezhnikov 6eb5f2be40 Update 2 files
- /src/base/ftcalc.c
- /include/freetype/internal/ftcalc.h
2023-09-13 17:02:31 +00:00
Ben Wagner 16f311d725 [base] Fix typo to correct predicate for call
* src/base/ftobj.c (FT_Get_Color_Glyph_Paint): check
`get_colr_glyph_paint` before calling `get_colr_glyph_paint` and not
`get_colr_layer`
2023-09-12 18:35:01 -04:00
Werner Lemberg 920c5502cc * Version 2.13.2 released.
==========================

Tag sources with `VER-2-13-2'.

* docs/VERSION.TXT: Add entry for version 2.13.2.
* docs/CHANGES: Updated.
* docs/release, docs/README, builds/macs/README: 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.13.1/2.13.2/, s/2131/2132/.

* include/freetype/freetype.h (FREETYPE_PATCH): Set to 2.

* builds/unix/configure.raw (version_info): Set to 26:1:20.
* CMakeLists.txt (VERSION_PATCH): Set to 2.
2023-08-25 20:12:52 +02:00
Alexei Podtelezhnikov 0c817334b7 * src/base/ftcalc.c (FT_MulAddFix): Simplify 32-bit rounding. 2023-08-25 17:57:47 +00:00
Alexei Podtelezhnikov 97251fd5aa [base] Improve the matrix degeneracy check.
Also fixes #1251.

* src/base/ftcalc.c (FT_Matrix_Check): To avoid overflow, scale by shifting.
* include/freetype/internal/ftcalc.h (FT_Matrix_Check): Update description.
2023-08-22 11:01:16 +00:00
Ben Wagner a9793feace [base] Avoid UB with memcpy
`FT_NEW_ARRAY(p, 0)` sets `p` to `NULL`. `FT_Stream_ReadAt` with a
memory based stream uses `FT_MEM_COPY` which is `memcpy` which specifies
that it is undefined behavior for either the `src` or `dst` to be
`NULL`. Instead of forcing all callers work around calling
`FT_Stream_Read` when `buffer == NULL && count == 0` do the check in
`FT_StreamRead`. This allows any call with `count == 0` to succesfully
read zero bytes without UB.

* src/base/ftstream.c (FT_Stream_ReadAt): skip `FT_MEM_COPY` when
`count == 0`. (FT_Stream_TryRead): ditto

Fixes: #1250
2023-08-17 13:25:31 -04:00
Alexei Podtelezhnikov 95a872085e * src/base/ftobjs.c (open_face_from_buffer): Silence `maybe-uninitialized`.
We never call this function without a `driver_name` (#1245).
2023-08-01 22:48:31 -04:00
Werner Lemberg e4586d960f * Version 2.13.1 released.
==========================

Tag sources with `VER-2-13-1'.

* docs/VERSION.TXT: Add entry for version 2.13.1.
* docs/CHANGES: Updated.
* docs/release, docs/README, builds/macs/README: 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.13.0/2.13/1/, s/2130/2131/.

* include/freetype/freetype.h (FREETYPE_PATCH): Set to 1.

* builds/unix/configure.raw (version_info): Set to 26:0:20.
* CMakeLists.txt (VERSION_PATCH): Set to 1.

* subprojects/libpng.wrap, subprojects/zlib.wrap, subprojects/dlg: Updated.
2023-06-24 08:11:05 +02:00
Werner Lemberg 416d4c25f1 Add new load flag `FT_LOAD_NO_SVG`.
Modern color fonts often contain both an 'SVG' and 'COLR' table.  FreeType
always preferred 'SVG' over 'COLR' (this was a design decision), however,
this might not be the right choice for the user.  The new flags makes
FreeType ignore the 'SVG' table while loading a glyph.

Fixes #1229.

* include/freetype/freetype.h (FT_LOAD_NO_SVG): New macro.

* src/base/ftobjs.c (FT_Load_Glyph), src/cff/cffgload.c (cff_slot_load),
src/truetype/ttgload.c (TT_Load_Glyph): Use it.
2023-05-15 16:04:15 +02:00
Werner Lemberg e05c056220 [base] Signature fixes. 2023-05-07 14:59:50 +02:00
Werner Lemberg c8a24209d3 [truetype] Fix PostScript name handling for variation fonts.
A variation font's PostScript name of a named instance is usually different
from the PostScript name of an unnamed instance.  However, if a change
between a named instance and an unnamed instance with exactly the same
design axis values happened, it was possible that the PostScript name wasn't
correctly updated.

This commit reorganizes the code to handle this issue within the top-level
API functions, using a new service to trigger recomputation of the
PostScript name.

* include/freetype/internal/services/svmm.h (FT_Construct_PS_Name_Func): New
typedef.
(FT_Service_MultiMasters): New field `construct_ps_name`.
(FT_DEFINE_SERVICE_MULTIMASTERSREC): Updated.

* src/base/ftmm.c (FT_Set_Var_Design_Coordinates,
FT_Set_MM_Blend_Coordinates, FT_Set_Var_Blend_Coordinates): Call
`mm->construct_ps_name` to handle `postscript_name`.
(FT_Set_Named_Instance): Call `mm->construct_ps_name` to handle
`postscript_name`.
Use shortcut.
* src/cff/cffdrivr.c (cff_construct_ps_name): New function.
(cff_service_multi_masters): Updated.

* src/truetype/ttgxvar.c (tt_set_mm_blend): Don't handle `postscript_name`.
(TT_Set_MM_Blend): Simplify.
(TT_Set_Named_Instance): Return -1 if axis values haven't changed.
Don't set `face_index`.
(tt_construct_ps_name): New function.

* src/truetype/ttgxvar.h: Updated.

* src/truetype/ttdriver.c (tt_service_gx_multi_masters): Updated.

* src/type1/t1driver.c (t1_service_multi_masters): Updated.

* src/type1/t1load.c (T1_Set_MM_Blend): Simplify.
2023-05-06 18:53:50 +02:00
Werner Lemberg 6713b1e41a [truetype] Fix deactivation of variation font handling.
According to the documentation, the functions `FT_Set_Named_Instance`,
`FT_Set_MM_Design_Coordinates`, `FT_Set_Var_Design_Coordinates`, and
`FT_Set_Var_Blend_Coordinates` can unset the `FT_FACE_FLAG_VARIATION` flag.
(The same is true for `FT_Set_MM_WeightVector` but this information was
accidentally omitted from the documentation.)

However, if a call of these functions didn't change the axis values this
could fail because internal shortcuts exited too early.

This commit reorganizes the code to handle `FT_FACE_FLAG_VARIATION` in the
top-level API functions, also taking care of the issue at hand.

* src/base/ftmm.c (FT_Set_MM_Design_Coordinates, FT_Set_MM_WeightVector,
FT_Set_Var_Design_Coordinates, FT_Set_MM_Blend_Coordinates,
FT_Set_Var_Blend_Coordinates): Handle `FT_FACE_FLAG_VARIATION`.

* src/truetype/ttgxvar.c (TT_Set_MM_Blend, TT_Set_Var_Design,
TT_Set_Named_Instance) Don't handle `FT_FACE_FLAG_VARIATION`.

* src/type1/t1load.c (T1_Set_MM_Blend, T1_Set_MM_WeightVector,
T1_Set_MM_Design): Ditto.

* src/cff/cffobjs.c (cff_face_init): Use `FT_Set_Named_Instance` instead of
low-level functions.

* src/truetype/ttobjs.c (tt_face_init): Ditto.
2023-05-06 18:53:50 +02:00
Werner Lemberg fdcb14a2ee s/set_instance/set_named_instance/
* include/freetype/internal/services/svmm.h (FT_Set_Instance_Func): Renamed
to...
(FT_Set_Named_Instance_Func): ...this.
(FT_Service_MultiMasters): Rename `set_instance` to `set_named_instance`.
(FT_DEFINE_SERVICE_MULTIMASTERSREC): Updated.

* src/base/ftmm.c (FT_Set_Named_Instance): Updated.

* src/cff/cffdrivr.c (cff_set_instance): Renamed to...
(cff_set_named_instance): ...this.
(cff_service_multi_masters): Updated.
* src/cff/cffobjs.c (cff_face_init): Updated.

* src/truetype/ttdriver.c (tt_service_gx_multi_masters): Updated.

* src/type1/t1driver.c (t1_service_multi_masters): Updated.
2023-05-06 18:53:50 +02:00
Werner Lemberg fb982e78a7 New Variation Font function `FT_Get_Default_Named_Instance`.
* include/freetype/ftmm.h, src/base/ftmm.c (FT_Get_Default_Named_Instance):
New function.

* include/freetype/internal/services/svmm.h
(FT_Get_Default_Named_Instance_Func): New typedef.
(FT_Service_MultiMasters): New field `get_default_named_instance`.
(FT_DEFINE_SERVICE_MULTIMASTERSREC): Updated.

* include/freetype/internal/tttypes.h (TT_Face): New field
`var_default_named_instance`.

* src/sfnt/sfobjc.s (sfnt_init_face): Initialize
`var_default_named_instance`.

* src/cff/cffdrivr.c (cff_get_default_named_instance): New function.
(cff_service_multi_masters): Updated.

* src/truetype/ttgxvar.c (TT_Get_MM_Var): Initialize
`var_default_named_instance`.
(TT_Get_Default_Named_Instance): New function.
* src/truetype/ttgxvar.h: Updated.
* src/truetype/ttdriver.c (tt_service_gx_multi_masters): Updated.

* src/type1/t1driver.c (t1_service_multi_masters): Updated.

* docs/CHANGES: Updated.
2023-05-06 18:53:50 +02:00
Werner Lemberg cfe54d6ac3 s/this is,/that is,/ 2023-04-27 06:24:48 +02:00
Alexei Podtelezhnikov dd78d4a774 * src/base/ftsynth.c (FT_GlyphSlot_AdjustWeight): New API. 2023-03-16 03:28:59 +00:00
Alexei Podtelezhnikov fc01e7dd67 Fix a couple of MSVC warnings.
* src/base/ftcalc.c (FT_MulAddFix): Add cast.
* src/sfnt/ttcolr.c (tt_face_get_colorline_stops, read_paint): Ditto.
2023-03-05 22:05:24 -05:00
Werner Lemberg d399657f1b * src/*: Replace leading underscores with trailing ones in dummy variables.
This is to avoid clang warnings.
2023-02-26 20:18:54 +01:00
Tamir Duberstein 3f2ac7d890 * src/base/ftsystem.c (ft_ansi_stream_io): Avoid undefined behaviour.
Also short-circuit on `offset` to avoid checking `count` a second time when
`ft_ansi_stream_io` is used for reading.

Per ISO/IEC 9899:

  If an argument to a function has an invalid value (such as a value outside
  the domain of the function, or a pointer outside the address space of the
  program, or a null pointer, or apointer to non-modifiable storage when the
  corresponding parameter is not const-qualified) or a type (after
  promotion) not expected by a function with variable number of arguments,
  the behavior is undefined.  If a function argument is described as being
  an array, the pointer actually passed to the function shall have a value
  such that all address computations and accesses to objects (that would be
  valid if the pointer did point to the first element of such an array) are
  in fact valid.

Per IEEE Std 1003.1:

  size_t fread(void *restrict ptr, size_t size, size_t nitems,
               FILE *restrict stream);

  The `fread` function shall read into the array pointed to by `ptr` up to
  `nitems` elements whose size is specified by `size` in bytes, from the
  stream pointed to by `stream`.

Since the first argument to `fread` is described as being an array, its
behavior is undefined when that argument is a null pointer.

Per the documentation on `ft_ansi_stream_io`:

  If `count' is zero (this is, the function is used for seeking), a non-zero
  return value indicates an error.

Thus the intent is clear, and the call to `fread` can be skipped, avoiding
undefined behaviour.
2023-02-25 05:20:57 +01:00
Alexei Podtelezhnikov 78464d1b0c * src/base/ftoutln.c (FT_Outline_Check): Fix C4701 warning. 2023-02-20 22:31:21 -05:00
Alexei Podtelezhnikov fecd19b449 * src/base/ftstroke.c (FT_Stroker_ParseOutline): Clean up contour indexing. 2023-02-20 17:13:40 +00:00
Alexei Podtelezhnikov 34ed28d0fb [base] Clean up contour indexing.
* src/base/ftoutln.c (FT_Outline_Reverse, FT_Outline_EmboldenXY,
FT_Outline_Get_Orientation): Set the first and last indexes together.
(FT_Outline_Decompose): Ditto and check them more stringently.
* src/smooth/ftgrays.c (FT_Outline_Decompose)[STANDALONE_]: Ditto.
2023-02-20 16:33:45 +00:00
Alexei Podtelezhnikov 713580f41d * src/base/ftoutln.c (FT_Outline_Check): Update error code, clean up. 2023-02-20 15:58:04 +00:00
Alex Ringlein 74ea5454cc * src/base/ftoutln.c (FT_Outline_Reverse): Anchor first contour points.
A cubic contour has to always start from an on-point. Therefore, we
should not swap the first with the last point, which might be off, and
obtain an invalid contour. This does not matter for conic contours.
If anything, it also saves one swap there. Fixes #1207.
2023-02-16 22:38:35 -05:00
Werner Lemberg de8b92dd7e * Version 2.13 released.
==========================

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

* docs/VERSION.TXT: Add entry for version 2.13.
* 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.12.1/2.13/, s/2121/2130/.

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

* builds/unix/configure.raw (version_info): Set to 25:0:19.
* CMakeLists.txt (VERSION_MINOR): Set to 13.
(VERSION_PATCH): Set to 0.
2023-02-09 07:24:52 +01:00
Werner Lemberg ac5babe876 Fix 'fall-through' warning messages.
Modern compilers get more insistent on that...

* include/freetype/internal/compiler-macros.h (FALL_THROUGH): Define.
* src/*: Use it instead of `/* fall through */` comments.
2023-02-08 21:09:32 +01:00
Werner Lemberg be724c8142 For debugging, avoid implicit conversion from integer to double.
Otherwise we get zillions of clang 15 warnings.

* src/autofit/afcjk.c, src/autofit/afhints.c, src/autofit/aflatin.c,
src/base/ftobjs.c, src/base/ftoutln.c, src/cff/cffparse.c,
src/raster/ftraster.c, src/sfnt/pngshim.c, src/truetype/ttgload.c,
src/truetype/ttgxvar.c, src/truetype/ttobjs.c, src/type1/t1gload.c: Use
`double` cast in debugging and tracing macros.
2023-02-08 21:09:32 +01:00
Werner Lemberg 37bc7c2604 Avoid reserved identifiers that are globally defined.
This is mandated by the C99 standard, and clang 15 produces zillions of
warnings otherwise.

* devel/ftoption.h, include/freetype/config/ftoption.h,
include/freetype/internal/ftmemory.h, src/autofit/afhints.h,
src/autofit/afmodule.c, src/autofit/aftypes.h, src/base/ftadvanc.c,
src/base/ftdbgmem.c, src/base/ftstream.c, src/bdf/bdflib.c,
src/truetype/ttinterp.c: Replace identifiers of the form `_foo` with `foo_`.
2023-02-08 21:09:30 +01:00
Alexei Podtelezhnikov 27b2cd4101 * src/base/ftsynth.c (FT_GlyphSlot_Slant): Add vertical slant.
* include/freetype/ftsynth.h (FT_GlyphSlot_Slant): Update it.
2023-02-07 23:03:18 -05:00
Werner Lemberg e97544a739 Minor changes.
Comment fixes, typos, removing of unnecessary parentheses.
2023-01-28 17:04:38 +01:00
Werner Lemberg bacc48e616 Whitespace. 2023-01-28 17:04:11 +01:00
Ben Wagner d680908af2 [base] Fix typo.
* src/base/ftobjs.c (open_face_PS_from_sfnt_stream): Request module 't1cid',
not 'cid'.
2023-01-18 09:00:21 +01:00
Ben Wagner 188019eb70 [base] Return error if requested driver is not found.
In `open_face_from_buffer` it is possible that a driver is requested but
FreeType was built without the requested module.  Return an error in this
case to indicate that the request could not be satisfied, rather than trying
all existing driver modules.

* src/base/ftobjs.c (open_face_from_buffer): Return `FT_Err_Missing_Module`
if a driver is specified but not found.
2023-01-18 08:37:51 +01:00
Werner Lemberg 65f8523706 Update all copyright notices. 2023-01-17 09:18:25 +01:00
Ben Wagner 29f83d1dd5 [base] 'close' callback may not use `stream->memory`.
The documentation for `FT_StreamRec::memory` states that it 'shouldn't be
touched by stream implementations'.  This is true even for internal
implementations of the 'close' callback, since it is not guaranteed that
`memory` will even be set when the 'close' callback occurs.

* src/base/ftobjs.c (new_memory_stream): stash current `memory` in
`stream->descriptor`.
(memory_stream_close): Use it.
2023-01-17 08:59:25 +01:00
Ben Wagner 0d4f887c79 [base] Always close user-provided stream.
The `FT_Open_Face` documentation states

> If `FT_OPEN_STREAM` is set in `args->flags`, the stream in `args->stream`
> is automatically closed before this function returns any error (including
> `FT_Err_Invalid_Argument`).

However, if the user provides a stream in `args.stream` with
`FT_OPEN_STREAM` set and a `close` function, but then for some reason passes
NULL for `aface` and a non-negative `face_index`, the error
`Invalid_Argument` is returned but the `close` callback will not be called
on the user-provided stream.  This may cause resource leaks if the caller is
depending on the `close` callback to free resources.

The difficulty is that a user may fill out a `FT_StreamRec` and pass its
address as `args.stream`, but the stream isn't really 'live' until
`FT_Stream_New` is called on it (and `memory` is set).  In particular, it
cannot really be cleaned up properly in `ft_open_face_internal` until the
stream pointer has been copied into the `stream` local variable.

* src/base/ftobj.c (ft_open_face_internal): Ensure that user-provided
`args.stream.close` is called even with early errors.
2023-01-17 08:54:11 +01:00
Ben Wagner 13983b058e [base] Fix leak of internal stream marked external.
`open_face_from_buffer` allocates a new `FT_Stream` to pass to
`ft_open_face_internal`.  Because this is an `FT_OPEN_STREAM`,
`ft_open_face_internal` will mark this as an 'external stream', which the
caller must free.  However, `open_face_from_buffer` cannot directly free it
because the stream must last as long as the face.  There is currently an
attempt at this by clearing the 'external stream' bit after
`open_face_from_buffer` returns successfully.  However, this is too late as
the original stream may have already been closed and the stream on the face
may not be the same stream as originally passed.

It is tempting to use `FT_OPEN_MEMORY` and let `ft_open_face_internal`
create the stream internally.  However, with this method there is no means
to pass through a 'close' function to the created stream to free the
underlying data, which must be owned by the stream.

A possibility is to check on success if the stream of the face is the same
as the original stream.  If it is then unset the external flag.  If not,
then free the original stream.  Unfortunately, while no current
implementation does so, it is possible that the face still has the original
stream somewhere other than as the `FT_FaceRec::stream`.  The stream needs
to remain available for the life of the face or until it is closed,
whichever comes earlier.

The approach taken here is to let the stream own itself.  When the stream is
closed it will free itself.

* src/base/ftobjs.c (memory_stream_close): Free `stream`.
(open_face_from_buffer): Simplify error handling, since
`ft_open_face_internal` always closes `args.stream` on any error.

Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=54930
2023-01-17 08:48:33 +01:00
Ben Wagner 15afb55458 [base] Report used stream's external status.
In `open_face` the initial stream is set on the face, along with the
information about if FreeType is the owner of the stream object itself.  The
loaders may in the course of their work replace this stream with a new
stream (as is the case for 'woff' and 'woff2'), which may have a different
ownership than the initial stream object (likely the original stream object
is owned by the user and is external, while the new stream object is created
internally to FreeType and is internal).  When the stream is replaced, the
face's flags are updated with the new ownership status.

However, `open_face` cannot itself free this stream as its caller
`ft_open_face_internal` is responsible for this.  In addition, in the case
of an error `open_face` cannot return an actual face with the new stream and
its ownership status to the caller.  As a result, it must pass this
information back to the caller as a sort of "failed face" so that the caller
can clean up.

`open_face` was already passing back the new stream but was not passing back
the stream ownership information.  As a result the stream may not have been
free'd when needed.

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

* src/base/ftobjs.c (open_face): Pass back the ownership information as
well.
(ft_open_face_internal): Updated.
2023-01-05 22:05:02 +01:00
Alexei Podtelezhnikov 81a456b28f * src/base/ftobjs.c (FT_Request_Metrics): Avoid division by zero.
The division-by-zero might happen in broken fonts (see #1194).
Instead of returning a huge number from FT_DivFix and failing
to scale later, we now bail immediately.
2023-01-04 22:41:34 -05:00
Luca Bacci aca4ec5907 * src/base/ftdbgmem.c (ft_mem_source_compare): Add FT_COMPARE_DEF.
Closes !230.
2022-11-22 22:34:41 -05:00
suzuki toshiya 32cfab4be7 [build] fix for make multi
Fix "make multi" by MR !223

* include/freetype/internal/services/svmm.h: include ftmm.h to define FT_Get_MM_Func.
* src/truetype/ttgxvar.h: include ftmmtypes.h to use GX_AVarTable properly.
* src/base/ftmac.c: include ftdebug.h to use FT_THROW() properly.
2022-11-08 14:23:37 +09:00
Liu Kunpeng(柳鲲鹏) bb59c3c958 * src/base/ftsynth.c (FT_GlyphSlot_Slant): New API with custom slant.
* include/freetype/ftsynth.h (FT_GlyphSlot_Slant): Declare it.
2022-10-16 22:10:19 -04:00
Ali Chraghi 5faa1df8b9 [base] FT_Attach_Stream: Make `parameters` argument constant. 2022-09-29 19:30:20 +02:00
Alexei Podtelezhnikov c9c326312f [base] Clean up the bitmap flow control.
* src/base/ftbitmap.c (FT_Bitmap_Copy): Flip the copy if its pitch
is trully opposite, zero is not a positive value.
(FT_Bitmap_Convert): Set negative pitch as needed, accept negative
alignment values.
2022-09-22 20:40:21 -04:00