Commit Graph

8016 Commits

Author SHA1 Message Date
Werner Lemberg 19aca9666e [pfr] Signature fixes. 2023-05-07 15:57:06 +02:00
Werner Lemberg 3297a7a9e0 * src/cid/cidload.c: Signature fixes. 2023-05-07 15:23:46 +02:00
Werner Lemberg 4a28ff3db8 * src/cff/cffcmap.c: Signature fixes. 2023-05-07 14:59:50 +02:00
Werner Lemberg 563f401127 * src/type1/t1load.c: Signature fixes. 2023-05-07 14:59:50 +02:00
Werner Lemberg 95d635eab1 [truetype] Signature fixes. 2023-05-07 14:59:50 +02:00
Werner Lemberg e05c056220 [base] Signature fixes. 2023-05-07 14:59:50 +02:00
Werner Lemberg ff0ef828c9 * src/type42/t42drivr.c: Clean up interface.
Ensure that all driver functions use the signature of the service or driver.
This avoids pointer mismatches, which are technically undefined behaviour.
Recent compilers are more picky in catching them as part of Control Flow
Integrity tests.
2023-05-07 14:59:50 +02:00
Werner Lemberg 7cc5dfa297 * src/type1/*: Clean up interface.
Ensure that all driver functions use the signature of the service or driver.
This avoids pointer mismatches, which are technically undefined behaviour.
Recent compilers are more picky in catching them as part of Control Flow
Integrity tests.
2023-05-07 14:59:50 +02:00
Werner Lemberg 3a85bf0b3f * src/truetype/*: Clean up interface.
Ensure that all driver functions use the signature of the service or driver.
This avoids pointer mismatches, which are technically undefined behaviour.
Recent compilers are more picky in catching them as part of Control Flow
Integrity tests.
2023-05-07 14:59:50 +02:00
Werner Lemberg e245951c43 * src/sfnt/sfdriver.c, src/sfnt/ttbdf.c: Clean up interface.
Ensure that all driver functions use the signature of the service or driver.
This avoids pointer mismatches, which are technically undefined behaviour.
Recent compilers are more picky in catching them as part of Control Flow
Integrity tests.

* src/sfnt/sfdriver.c (sfnt_load_table): New wrapper function.
(sfnt_service_sfnt_table): Use it.
2023-05-07 14:59:50 +02:00
Werner Lemberg ceba488cf8 * src/psnames/psmodule.c: Use `FT_CALLBACK_DEF`. 2023-05-07 14:59:50 +02:00
Werner Lemberg 4360e20e31 * src/pfr/pfrdrivr.c: face -> pfrface, pfrface -> face. 2023-05-07 14:59:50 +02:00
Werner Lemberg 0685b0ad36 * src/pcf/pcfdrivr.c: Clean up interface.
Ensure that all driver functions use the signature of the service or driver.
This avoids pointer mismatches, which are technically undefined behaviour.
Recent compilers are more picky in catching them as part of Control Flow
Integrity tests.
2023-05-07 14:59:50 +02:00
Werner Lemberg b9ce8e33a7 * src/cid/cidriver.c: Clean up interface.
Ensure that all driver functions use the signature of the service or driver.
This avoids pointer mismatches, which are technically undefined behaviour.
Recent compilers are more picky in catching them as part of Control Flow
Integrity tests.
2023-05-07 14:59:50 +02:00
Werner Lemberg bc7466ad45 * src/bdf/bdfdrivr.c: Clean up interface.
Ensure that all driver functions use the signature of the service or driver.
This avoids pointer mismatches, which are technically undefined behaviour.
Recent compilers are more picky in catching them as part of Control Flow
Integrity tests.
2023-05-07 14:59:50 +02:00
Werner Lemberg c041411917 * src/cff/*: Clean up interface.
Ensure that all driver functions use the signature of the service or driver.
This avoids pointer mismatches, which are technically undefined behaviour.
Recent compilers are more picky in catching them as part of Control Flow
Integrity tests.
2023-05-07 14:59:21 +02:00
Werner Lemberg 8fe50c2adc [truetype] Fix style name handling for variation fonts.
* include/freetype/internal/tttypes.h (TT_FaceRec): New field
`non_var_style_name`.

* src/sfnt/sfobjs.c (sfnt_load_face): Initialize `non_var_style_name`.
(sfnt_done_face): Free `non_var_style_name`.

* src/truetype/ttgxvar.c (TT_Set_Named_Instance): Restore non-VF style name
if switching back to non-VF mode.
2023-05-06 18:53: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 7af8fd0063 * include/freetype/internal/services/svmm.h: Minor changes. 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 b5e57b041b [cid] Improve tracing messages; formatting. 2023-05-06 16:41:13 +02:00
Alexei Podtelezhnikov 9127c68f59 * src/cache/ftccache.c (ftc_node_hash_unlink): Minor. 2023-05-04 16:54:22 +00:00
Alexei Podtelezhnikov 345f88109b * src/cache/ftcmru.c (FTC_MruList_RemoveSelection): Purge backwards. 2023-05-03 23:33:32 -04:00
Alexei Podtelezhnikov f2f9754542 [cache] Revise list cleansing.
* src/cache/ftcmru.c (FTC_MruList_RemoveSelection): Use one loop to
do it.
* src/cache/ftcmanag.c (FTC_Manager_Compress, FTC_Manager_FlushN):
Streamline loops.
2023-05-03 23:02:04 -04:00
suzuki toshiya be15811c46 [t1cid] Improve cid_get_cid_from_glyph_index().
Update cid_get_cid_from_glyph_index() to
return an error and CID=0 in the case that
the specified glyph index points to an invalid
entry.

cidgload.h (cid_compute_fd_and_offsets):
Declare new helper function to set the
fd_select and 2 offsets to access the glyph
description data.

cidgload.c (cid_compute_fd_and_offsets):
Move the part loading fd_select and 2 offsets
from cid_load_glyph() to here.  If the loaded
parameters are broken, return the Invalid_Offset
error.  This function does not load the glyph
data, only fills these parameters.

(cid_load_glyph): Use new helper function in above.

cidriver.c (cid_get_cid_from_glyph_index):
Check whether the requested glyph index points
to a valid entry, by calling cid_compute_fd_and_offsets().
If it is valid, fill the cid by the glyph
index (=CID).  If it is invalid, return an
error and fill the cid by 0.
2023-05-03 01:31:37 +00:00
Werner Lemberg 77bbfc5960 API documentation: Re-organize chapters and sections
* Split the very long 'Base Interface' section into smaller sections.
* Split the 'Core API' chapter into two chapters.
* Remove single enumeration values from `@order` fields since they have no
  effect.
2023-04-30 14:42:11 +00:00
Alexei Podtelezhnikov 36a086b630 * src/sfnt/pngshim.c (Load_SBit_Png): Remove FALL_THROUGH warning. 2023-04-28 19:40:35 -04:00
Werner Lemberg 08268691aa * src/sfnt/ttload.c (tt_face_load_font_dir): Add another guard.
Reject 'OTTO' fonts with no valid tables.
2023-04-28 15:33:58 +02:00
Werner Lemberg 966ff5a55c * src/cff/cffdrivr/c (cff_get_ps_name): Avoid unnecessary crash.
The situation can happen if `FT_New_Face` (or one of its siblings) is called
with a negative index to get the number of contained faces, followed
immediately by a call to `FT_Get_Postscript_Name`.  While this is not a valid
use of the FreeType library there is no need for a crash.

Fixes #1219.
2023-04-28 15:25:20 +02:00
Werner Lemberg 17a0c5dfd5 * src/cff/cffdrivr.c (cff_ps_get_font_info): Reject 'CFF2' format. 2023-04-28 10:40:41 +02:00
Werner Lemberg 4908c1e84d * src/cid/cidgload.c (cid_load_glyph): Fix compiler warnings. 2023-04-28 06:54:25 +02:00
Werner Lemberg 13df1c7d29 Minor documentation updates. 2023-04-28 06:39:32 +02:00
Werner Lemberg 9a3d05d980 * src/ttgxvar.c: Minor changes.
(TT_Get_MM_Var): Improve tracing messages.
(tt_set_mm_blend): Minor speed-up.
2023-04-27 06:24:48 +02:00
Werner Lemberg cfe54d6ac3 s/this is,/that is,/ 2023-04-27 06:24:48 +02:00
Alexei Podtelezhnikov 7ab541a28b [bdf] Clean up the atom property parsing.
* src/bdflib.c (bdf_is_atom_): Refactor code with fewer checks.
(bdf_list_join_): Return NULL.
(bdf_add_comment_): Use const argument.
(bdf_get_property): Ditto, ditto, make the function static.
* src/bdf.h (bdf_get_property): Remove prototype.
2023-04-26 23:15:24 -04:00
Werner Lemberg 0a3836c97d Improve/add source comments and documentation. 2023-04-25 11:47:18 +02:00
Werner Lemberg 40676afc4c [sfnt] Fix handling of PS names for Variation Fonts.
* src/sfnt/sfdriver.c (get_win_string, get_apple_string): Continue
construction of string if an invalid character is encountered.

Fixes #1218.
2023-04-25 11:47:18 +02:00
suzuki toshiya f312b3402a [t1cid] Change the trace messages of the charstrings retrieval errors.
The t1cid driver catches 3 types of errors in
the charstrings retrieval;
A) The invalid FD number, there are 2 subtypes;
  A-1) FD number is the maximum number fitting to FDBytes.
  A-2) FD number is greater than num_dicts.
B) Declared length is overrunning.
C) Declared length is invalid (its end is before its head).

Considering that some widely distributed fonts
(e.g., "CJKV" book by O'Reilly) have A-1 errors
in the unimplemented glyphs, the trace level for
A-1 is calmed to level 1.

The errors A-2, B, and C would be irregular;
their trace levels are kept at level 0, but
the updated trace messages include the CID number.
2023-04-24 14:06:09 +09:00
suzuki toshiya 9806414c15 [truetype] Fix `make multi'.
* src/truetype/ttgxvar.c: Include freetype/internal/services/svmetric.h
for the FT_Service_MetricsVariations type definition.
2023-04-24 13:36:30 +09:00
Ben Wagner 8154d8e2be [services] FT_Size_Reset_Func to return FT_Error
The `MetricsVariations` `FT_Size_Reset_Func` is currently defined to
return `void`, but the implementations return `FT_Error`. Even though
the pointers passed will be the same at runtime, calling a function
through a pointer of a different type from the original function pointer
type is undefined behavior. This may be caught at runtime by Control
Flow Integrity with something like clang's `cfi-icall`.

Issue: https://crbug.com/1433651

* include/freetype/internal/services/svmetric.h (FT_Size_Reset_Func):
return `FT_Error` instead of `void`.
2023-04-19 13:48:59 -04:00
Ben Wagner c4fe77c3f0 [truetype] tt_size_reset_height to take FT_Size
The `MetricsVariations` `FT_Size_Reset_Func` is defined to take an
`FT_Size`. Because `tt_size_reset_height` is to be used as such a
function, it must also take an `FT_Size` instead of a `TT_Size`. Even
though the pointers passed will be the same at runtime, calling a
function through a pointer of a different type from the original
function pointer type is undefined behavior. This may be caught at
runtime by Control Flow Integrity with something like clang's
`cfi-icall`.

Issue: https://crbug.com/1433651

* src/truetype/ttobjs.h (tt_size_reset_height): take `FT_Size`

* src/truetype/ttobjs.c (tt_size_reset_height): take `FT_Size` and
update documentation
2023-04-17 12:32:04 -04:00
Werner Lemberg ea9fca0add * src/truetype/ttinterp.c: Remove outdated comments. 2023-04-13 06:34:32 +02:00
Ben Wagner e78e2d29a9 [sfnt, truetype] Add `size_reset` to `MetricsVariations`.
This is a generalization of commit

```
commit e6699596af
Author: Werner Lemberg <wl@gnu.org>
Date:   Thu Feb 2 11:38:04 2017 +0100

    [truetype] Fix MVAR post-action handling.
```

It is also possible for plain `CFF ` style fonts to contain an `fvar` and
`MVAR` table and use `cff_metrics_adjust`.  `tt_size_reset` should only be
called with `TT_Size` and never with `CFF_Size`.

Allow the "metrics-variations" service to specify the correct function (if
any) to reset `FT_Size`s after adjusting metrics.

* src/truetype/ttobjs.c (tt_size_reset): Split off some functionality
into...
(tt_size_reset_height): ... this new function.

* src/truetype/ttdriver.c (tt_service_metrics_variations): Add
`size_reset`.
(tt_size_select, tt_size_request): Updated.

* src/truetype/ttobjs.h: Updated.

* include/freetype/internal/services/svmetric.h (MetricsVariations): Add
`size_reset`.
(FT_DEFINE_SERVICE_METRICSVARIATIONSREC): Updated.

* include/freetype/internal/tttypes.h (TT_FaceRec_): Rename `var` to
`tt_var` and add `face_var`.

* src/cff/cffdrivr.c (cff_service_metrics_variations): Add `size_reset`.
(cff_hadvance_adjust, cff_metrics_adjust): Updated.

* src/cff/cffobjs.c (cff_face_init): Use `face_var`.

* src/sfnt/sfobjs.c (sfnt_init_face): Initialize `face_var`.

* src/sfnt/ttmtx.c (tt_face_get_metrics): Use `tt_var`.

* src/truetype/ttgxvar.c (tt_size_reset_iterator): Renamed to...
(ft_size_reset_iterator): ... this new function.
Call `size_reset`.
(tt_apply_mvar): Pass `size_reset` to `ft_size_reset_iterator`.

Fixes #1211
2023-04-11 10:20:58 +02:00
Alexei Podtelezhnikov e77d8ba87c * src/cff/cffcmap.c (cff_cmap_encoding_char_next): Abbreviate. 2023-04-10 15:17:17 -04:00
Alexei Podtelezhnikov 1a4c18f7cb Align `char_next` return types.
This is mostly cosmetic because FT_UInt and FT_UInt32 are likely identical.

* src/sfnt/ttcmap.c, src/cff/cffcmap.c, src/psaux/t1cmap.c,
src/psnames/psmodule.c, include/freetype/internal/service/svpcsmap.h,
src/pfr/pfrcmap.c, src/winfonts/winfnt.c (*_char_next): return FT_UInt.
2023-04-10 15:30:43 +00:00
Alexei Podtelezhnikov d25444333c [sfnt] Clean up CMAP{4,12,13} handling.
This moves the charcode overflow checks upstream and turns some
while-loops into the do-while ones to avoid the uninitialized warnings.
This should slightly reduce the number of checks and jumps.

* src/sfnt/ttcmap.c (tt_cmap{4,12,13}_next,
tt_cmap{4.12.13}_char_map_linear): Remove the charcode overflow check.
(tt_cmap{4,12,13}_char_map_binary): Ditto and use do-while.
(tt_cmap{12,13}_char_next): Add the overflow check.
2023-04-08 23:15:41 -04:00
Alexei Podtelezhnikov b0a4f99278 * src/sfnt/ttpost.c (load_format_25): Do not abort frame reading. 2023-04-02 22:45:48 -04:00
Alexei Podtelezhnikov 340767bf85 * src/sfnt/ttpost.c (load_format_*): Streamline frame reading. 2023-04-02 22:00:59 -04:00