Commit Graph

228 Commits

Author SHA1 Message Date
Dominik Röttsches a4c4566b6d [truetype, snft] Add service methods for `DeltaSetIdxMap` and `VarStore`.
This will be needed for 'COLR' v1 variation support.

* src/truetype/ttgxvar.h (GX_ItemVarData, GX_AxisCoords, GX_VarRegion,
GX_VarItemStore, GX_DeltaSetIdxMap): Move structures to...
* include/freetype/internal/ftmmtypes.h: ... this new file.

* include/freetype/internal/service/svmm.h (MultiMasters): Include
`ftmmtypes.h`.
(FT_Var_Load_Delta_Set_Idx_Map_Func, FT_Var_Load_Item_Var_Store_Func,
FT_Var_Get_Item_Delta_Func, FT_Var_Done_Item_Var_Store_Func,
FT_Var_Done_Delta_Set_Idx_Map_Func): New function typedefs.
(MultiMasters): Add them.
(FT_DEFINE_SERVICE_MULTIMASTERSREC): Updated.

* src/cff/cffdrivr.c (cff_load_item_variation_store,
cff_load_delta_set_index_mapping, cff_get_item_delta,
cff_done_item_variation_store, cff_done_delta_set_index_map): New wrapper
methods calling into mm service.
(cff_service_multi_masters): Updated.

* src/truetype/ttgxvar.c (ft_var_load_item_variation_store,
ft_var_load_delta_set_index_mapping, ft_var_get_item_delta,
ft_var_done_item_variation_store, ft_var_done_delta_set_index_map): Renamed
to ...
(tt_var_load_item_variation_store, tt_var_load_delta_set_index_mapping,
tt_var_get_item_delta, tt_var_done_item_variation_store,
tt_var_done_delta_set_index_map): ... this for consistency.
Mark them as non-static.
* src/truetype/ttgxvar.h: Add corresponding prototypes.

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

* src/type1/t1driver.c (t1_service_multi_masters): Updated.
2022-05-19 07:14:05 +02:00
Dominik Röttsches 5f19f49c81 [truetype] Move deallocation of `DeltaSetIdxMap` into own function.
This is a preparation for handling `DeltaSetIdxMap` and `VarStore` as a
FreeType service.

* src/truetype/ttgxvar.c (ft_var_done_delta_set_index_map): New function.
(tt_done_blend): Use it.
2022-05-19 06:09:17 +02:00
Werner Lemberg 5d49473f85 [truetype] Handle inner/outer index values 0xFFFF/0xFFFF.
This was introduced in OpenType 1.8.4.

* src/truetype/ttgxvar.c (ft_var_load_delta_set_index_mapping,
tt_hvadvance_adjust, ft_var_load_mvar, tt_apply_mvar): Handle special
inner/outer index values.
(ft_var_load_item_variation_store): Add test.

Fixes #1154.
2022-05-11 18:15:02 +02:00
Alexei Podtelezhnikov bee8886408 Clean-up - do not doubt FT_FREE.
* src/base/ftobjs.c (memory_stream_close): Do not reassign zero
after `FT_FREE`.
* src/sfnt/sfwoff.c (sfnt_stream_close): Ditto.
* src/sfnt/sfwoff2.c (stream_close): Ditto.
* src/psaux/psobjs.c (ps_parser_load_field): Ditto.
* src/truetype/ttgxvar.c (ft_var_load_avar, tt_set_mm_blend,
tt_set_mm_blend): Ditto.
2022-01-30 21:55:21 -05:00
Alexei Podtelezhnikov b34741c1cc Minor clean-ups.
* src/base/ftrfork.c (raccess_make_file_name): Do not set error.
* src/sfnt/sfdriver.c (get_win_string, get_apple_string): Ditto.
* src/cff/cffobjs.c (cff_strcpy): Do not confuse about error.
* src/psaux/psobjs.c (ps_table_done): Ditto.
* src/truetype/ttgxvar.c (ft_var_readpacked*, ft_var_load_avar): Ditto.
2022-01-27 22:55:34 -05:00
Werner Lemberg d0cfb4e1b2 Update all copyright notices. 2022-01-11 10:54:10 +01:00
Ben Wagner afb4ca0151 [truetype] Reset localpoints when varying cvt.
When iterating over the cvt tuples and reading in the points it is necessary
to set all of `localpoints`, `points`, and `point_count` in all cases.  The
existing code did not reset `localpoints` to `NULL` when there were no
private point numbers.  If the previous tuple did have private point numbers
and set `localpoints` to `ALL_POINTS` this would not be cleared and the
wrong branch would be taken later, leading to possible heap buffer overflow.

* src/truetype/ttgxvar.c (tt_face_vary_cvt): Reset `localpoints` to `NULL`
when it isn't valid.

Fixes: https://crbug.com/1284742
2022-01-06 19:13:00 +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
Alexei Podtelezhnikov c5cd2a3db4 * src/truetype/ttgxvar.c (ft_var_to_normalized): Edge optimization. 2021-11-10 08:46:26 -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
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 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
Werner Lemberg 2149b51f25 Handle various VC++ compiler warnings.
Fixes #1039.

* src/base/ftstroke.c (ft_stroker_inside, ft_stroker_outside):
Initialize `sigma`.

* src/sdf/ftsdf.c (sdf_generate_with_overlaps): Exit immediately if
function arguments are invalid.
* src/sdf/ftsdfrend.c (sdf_property_set) <"overlaps">: Fix cast.

* src/sfnt/sfwoff2.c (woff2_decompress)
[!FT_CONFIG_OPTION_USE_BROTLI]: Use `FT_UNUSED`.

* src/truetype/ttgxvar.c (TT_Get_MM_Var): Initialize `fvar_head`.
2021-03-13 19:08:09 +01:00
Werner Lemberg d924a66a5c * src/*: Don't use more than one '\n' in `FT_TRACE` and `FT_ERROR`.
This ensures good logging output, with all lines having a proper
prefix (if requested).

This is a continuation of a similar patch from 2020-12-02, which
missed some locations.
2021-02-04 07:46:46 +01:00
Werner Lemberg b6e8a71266 Update all copyright notices. 2021-01-17 07:18:48 +01:00
Werner Lemberg 272ae5ee2a * src/*: More fixes for using a '\n' in `FT_TRACE` and `FT_ERROR`. 2020-12-07 10:29:24 +01:00
Werner Lemberg a6adb25626 * src/*: Don't use more than one '\n' in `FT_TRACE` and `FT_ERROR`.
This ensures good logging output, with all lines having a proper
prefix (if requested).
2020-12-05 09:43:45 +01:00
Werner Lemberg 804e625def [truetype] Minor update to forthcoming OpenType 1.8.4 standard.
* src/truetype/ttgxvar.c (ft_var_load_item_variation_store): Limit
size of `regionCount`.
2020-10-28 13:34:52 +01:00
Werner Lemberg 8cfc41ae95 Fix `-Wformat' compiler warnings.
Problem reported by Priyesh kumar <priyeshkkumar@gmail.com>

* src/base/ftoutln.c (FT_Outline_Decompose): Fix number of arguments
to tracing macro.

* src/bdf/bdfdrivr.c (bdf_cmap_char_next, bdf_get_bdf_property):
Ditto.

* src/cache/ftcbasic.c (ftc_basic_family_get_count): Ditto.
Reformulate message.

* src/pcf/pcfdrivr.c (pcf_get_bdf_property): Ditto.

* src/sfnt/sfwoff2.c (woff2_open_font): Ditto.
Trace table offset, too.

* src/truetype/ttgxvar.c (ft_var_apply_tuple): Ditto.
2020-07-25 12:23:22 +02:00
David Turner e13391333f Make macros for header file names optional.
We no longer have to take care of the 8.3 file name limit; this
allows us (a) to introduce longer, meaningful file names, and (b) to
avoid macro names in `#include' lines altogether since some
compilers (most notably Visual C++) doesn't support this properly.

*/*: Replace

   #include FOO_H

with

   #include <freetype/foo.h>

or something similar.  Also update the documentation.
2020-06-08 13:31:55 +02:00
Ben Wagner 11975fe9f6 Fix state of `FT_Face' for buggy `gvar' tables (#57923).
By resetting the blend as implemented with this commit fonts with
invalid `gvar' tables may keep calling into `ft_var_load_gvar' from
`tt_set_mm_blend' and failing, but the font was invalid anyway and
we want to keep seeing the failure in `tt_set_mm_blend'.

* src/truetype/ttgxvar.c (ft_var_load_gvar): Calculate length of
offset array once.
Allocate arrays after `FT_FRAME_ENTER' (extra check before
allocating and avoid needing to free array later if error entering
frame).
Always call `FT_FRAME_EXIT'.
Consistently set counts immediately after array initialized.
Reset the blend (particularly `blend->glyphoffsets') on failure.
2020-02-29 20:29:14 +01:00
Ben Wagner 216e077600 [truetype] Add better checks for loading `gvar' table (#57905).
* src/truetype/ttgxvar.c (ft_var_load_gvar): Delay settings of any
`blend->xxxcount' values until the corresponding data has been
checked.
Also do some sanitizing to avoid a too early exit.

(TT_Vary_Apply_Glyph_Deltas): Improve tracing message.
2020-02-28 07:43:00 +01:00
Werner Lemberg e5038be704 Update all copyright notices. 2020-01-19 17:05:19 +01:00
Werner Lemberg 594156586b [truetype] Prevent crash in `TT_Set_Named_Instance' (#56813).
* src/truetype/ttgxvar.c (TT_Set_Named_Instance): Fix error
handling.
2019-08-27 14:07:14 +02:00
Werner Lemberg 7d1d3b9a0e [type1] Fix `FT_Get_Var_Axis_Flags' (#56804).
* src/type1/t1load.c (T1_Get_MM_Var): Allocate space for axis flags.
Also remove redundant assignment.
2019-08-26 09:08:56 +02:00
Werner Lemberg 49079ce297 [truetype] Fix 32bit builds (#56404).
Patch suggested by Ben Wagner <bungeman@google.com>.

* src/truetype/ttgxvar.c (FT_fixedToInt, FT_fixedToFdot6): Remove
harmful cast to unsigned type.
2019-05-29 08:08:53 +02:00
Werner Lemberg 306d2f6ccb [truetype] Draw glyphs without deltas in variation font (#56374).
* src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Always fill
`unrounded' array.
2019-05-23 14:41:57 +02:00
Werner Lemberg b0522701f8 [truetype] Actually scale varied CVT values.
Up to now, only the unscaled CVT values were varied; in other words,
the `CVAR' data was never used for bytecode hinting.

* src/truetype/ttgxvar.c (tt_cvt_ready_iterator): New auxiliary
function.
(tt_face_vary_cvt): Use it to trigger rescaling of CVT values.
2019-05-16 12:52:57 +02:00
Werner Lemberg 37580053b4 [truetype] Use 26.6 format for storing unscaled CVT values.
If `CVAR' data is applied to variation fonts, fractional values are
possible.

* include/freetype/internal/tttypes.h (TT_FaceRec): Change type of
`cvt' from `FT_Short' to `FT_Int32'.

* src/truetype/ttgxvar.c (FT_fdot6ToFixed): New macro.
(tt_face_vary_cvt): Use it to update code to 26.6 format.

* src/truetype/ttobjs.c (tt_size_run_prep): Update code to 26.6
format.

* src/truetype/ttpload.c (tt_face_load_cvt): Stora data in 26.6
format.
2019-05-16 12:15:54 +02:00
Werner Lemberg 94ebc24865 [truetype] Doh. Fix last commit to make it work.
Very embarassing :-)

Reported as

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

* src/truetype/ttgload.c (IS_DEFAULT_INSTANCE): Move up and add
argument; update all callers.
(TT_Process_Simple_Glyph): Use it.  The `unrounded' array is active
for variation fonts only, thus also enclose related code with
`#ifdef TT_CONFIG_OPTION_GX_VAR_SUPPORT ...  #endif' where
necessary.
Revert commit a113e5d from 2019-05-09, and don't use `extra_points2'
but allocate a temporary array.
Speed up the scaling of the `unrounded' array.

* src/truetype/ttgxvar.c (FT_fixedToInt, FT_FixedToFdot6): Fix type
conversions and rounding.  The unsigned type must have more or equal
bits to the signed type.
2019-05-13 06:34:33 +02:00
Werner Lemberg 1178227b39 [truetype] Increase precision of font variation (#54371).
This patch make FreeType use font units in 26.6 format internally
instead of integers.

* src/truetype/ttgxvar.c (FT_fixedToFdot6): New macro.
(TT_Vary_Apply_Glyph_Deltas): Add argument to output unrounded font
coordinates.
* src/truetype/ttgxvar.h: Updated.

* src/truetype/ttgload.c (TT_Process_Simple_Glyph): Use
`extra_points2' array to temporarily hold unrounded point
coordinates; use them to compute scaled coordinates and linear
advance width and height.
(load_truetype_code): Adjust similarly.
2019-05-11 10:01:57 +02:00
Werner Lemberg dc39f76cb7 * src/truetype/ttgxvar.c: More use of `FT_fdot14ToFixed'. 2019-05-07 10:09:55 +02:00
Werner Lemberg 7b84104720 Various clang 8.0 static analyzer fixes.
Reported by Sender Ghost <lightside@gmx.com>.

* src/autofit/afcjk.c (af_cjk_hints_compute_edges): Catch a corner
case where `edge->first' could be NULL.

* src/pfr/pfrobjs.c (pfr_slot_load): Remove unnecessary test of
`size'.

* src/raster/ftraster.c (Draw_Sweep): Catch a corner case where
`draw_right' might be NULL.

* src/sfnt/ttmtx.c (tt_face_get_metrics): Fix limit test for
`aadvance'.
Ensure `abearing' always hold a meaningful result.

* src/truetype/ttgload.c (load_truetype_glyph): Ensure `subglyph' is
not NULL before accessing it.
* src/truetype/ttgxvar.c (TT_Set_Named_Instance): Remove unnecessary
test of `namedstyle'.

* src/type42/t42parse.c (t42_parser_done): Ensure
`parser->root.funcs.done' is not NULL before accessing it.
2019-05-04 08:13:22 +02:00
Werner Lemberg af400438b7 Fix return value of `FT_Set_Named_Instance' (#56186).
* src/truetype/ttgxvar.c (TT_Set_Named_Instance): Correctly handle
internal return value -1 of `TT_Set_Var_Design'.
2019-04-22 07:44:01 +02:00
Werner Lemberg 7585997024 Update all copyright notices. 2019-02-23 10:07:09 +01:00
Werner Lemberg b66d6a9112 CHANGES: Document recent metrics change from Nikolaus. 2019-02-06 07:38:25 +01:00
Nikolaus Waxweiler a6feefdfef [truetype] Apply MVAR hasc, hdsc and hlgp metrics to current FT_Face metrics.
Instead of setting typo or win metrics as the new FT_Face metrics
indiscriminately, apply only typo deltas to the currently active FT_Face
metrics. This prevents line height differences when e.g. the default
outlines were used as the regular face and instances for everything else.

* src/truetype/ttgxvar.c (tt_apply_mvar): Implement.
2019-02-02 15:50:57 +00:00
Werner Lemberg f686ad46a3 Update copyright years. 2019-01-22 20:31:44 +01:00
Ben Wagner fb0d66d04c [truetype] Fix VF check from 2018-09-12 (#54973).
* src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Use correct
offsets for estimates.
2018-11-07 00:47:44 +01:00
Alexei Podtelezhnikov cc288e383b Minor. 2018-11-04 22:09:16 -05:00
Alexei Podtelezhnikov 1f43affc09 * src/truetype/ttgxvar.c: Use enum definitions. 2018-11-04 13:11:16 -05:00
Alexei Podtelezhnikov d95a12b88d * src/truetype/ttgxvar.c (ft_var_apply_tuple): Adjust condition. 2018-11-03 23:02:58 -04:00
Alexei Podtelezhnikov 547f82f20e * src/truetype/ttgxvar.c (ft_var_apply_tuple): Tracing tweaks. 2018-11-03 23:00:36 -04:00
Alexei Podtelezhnikov ce3feb0b9d Revert due to specs: [truetype] Speed up variation IUP.
This reverts commit 1e4496c54c.
2018-11-03 22:43:21 -04:00
Alexei Podtelezhnikov dfa86d65e5 Revert "[truetype] Speed up variation IUP."
This reverts commit 1e4496c54c.
2018-11-03 22:36:52 -04:00
Alexei Podtelezhnikov 61d50756b6 * src/truetype/ttgxvar.c (ft_var_get_item_delta): Fixed logic.
Reported and tested by Behdad.
2018-11-02 20:42:25 -04:00