Commit Graph

131 Commits

Author SHA1 Message Date
Werner Lemberg d9ff6f20ad * src/truetype/ttgxvar.c (tt_done_blend): Free `vvar_table'.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=883
2017-03-16 20:20:51 +01:00
Werner Lemberg 981c23b75e Remove clang compiler warnings (#50548).
* include/freetype/internal/tttypes.h (TT_FaceRec): Make
`var_postscript_prefix_len' unsigned.

* src/autofit/afwarp.c (af_warper_compute_line_best): Remove
redundant assignment.

* src/cff/cffload.c (cff_subfont_load): Add casts.

* src/cff/cffparse.c (cff_parse_blend): Remove redundant assignment.

* src/sfnt/sfdriver.c (fmix32, murmur_hash_3_128): Add `static'
keyword.
Add casts.
(fixed2float): Add cast.
(sfnt_get_var_ps_name): Make `p' always initialized.
Add casts.

* src/truetype/ttgxvar.c (TT_Get_MM_Var): Add casts.
2017-03-15 11:35:26 +01:00
Werner Lemberg 34010f7c47 [sfnt] Implement PS names for font instances [3/3].
Everything is guarded with TT_CONFIG_OPTION_GX_VAR_SUPPORT.

* include/freetype/internal/tttypes.h (TT_FaceRec): New fields
`var_postscript_prefix' and `var_postscript_prefix_len'.

* src/sfnt/sfdriver.c: Include FT_TRUETYPE_IDS_H.
(sfnt_is_alphanumeric): New wrapperfunction for `ft_isalnum'.
(get_win_string, get_apple_string): Remove `const' from return
value.
(MAX_VALUE_DESCRIPTOR_LEN, MAX_PS_NAME_LEN): New macros.
(hexdigits): New array.
(sfnt_get_var_ps_name): New function, implementing Adobe TechNote
5902 to construct a PS name for a variation font instance.
(sfnt_get_ps_name): Call `sfnt_get_var_ps_name' for font instances.

* src/sfnt/sfobjs.c (sfnt_done_face): Updated.

* src/truetype/ttgxvar.c (tt_set_mm_blend): Reset
`face->postscript_name' to trigger recalculation for new instance
parameters.
2017-03-14 21:50:22 +01:00
Werner Lemberg 447a0b6263 [truetype] Ignore invalid MVAR tags.
Reported as

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

* src/truetype/ttgxvar.c (ft_var_load_mvar): Ignore value and emit
warning for invalid tags.
(tt_apply_mvar): Ignore invalid tags.
2017-03-13 07:42:34 +01:00
Werner Lemberg 5eb0fd5e97 [truetype] Store and use design coordinates also.
* include/freetype/internal/services/svmm.h (FT_Get_Var_Blend_Func):
Add `normalizedcoords' argument.

* src/truetype/ttgxvar.h (GX_BlendRec): Add `coords' field to store
the design coordinates of the current instance.
Updated.

* src/truetype/ttgxvar.c (TT_Set_MM_Blend): Move functionality to...
(tt_set_mm_blend): ... New function.
Convert data in `normalizedcoords' array to `coords' array on
demand.
(TT_Set_Var_Design): Store argument data in `coords' array.
(TT_Get_Var_Design): Get data from `coords' array.
(tt_get_var_blend): Updated.
(tt_done_blend): Updated.

* src/cff/cffload.c, src/cff/cffload.h (cff_get_var_blend): Updated.

* src/cff/cf2ft.c (cf2_getNormalizedVector): Updated.

* src/cff/cffobjs.c (cff_face_init): Updated.
2017-03-12 20:46:56 +01:00
Werner Lemberg 4a62922bf8 src/truetype/ttgxvar.[ch]: s/avar_checked/avar_loaded/. 2017-03-12 10:19:53 +01:00
Werner Lemberg 27fee7f8c6 [sfnt, truetype] Always provide default instance.
As documented in the OpenType specification, an entry for the
default instance may be omitted in the named instance table.  In
particular this means that even if there is no named instance table
in the font we actually do have a named instance, namely the default
instance.

For consistency, we always want the default instance in our list of
named instances.  If it is missing, we try to synthesize it.

* src/sfnt/sfobjs.c (sfnt_init_face): Check whether the default
instance is in the table of named instances.  Otherwise adjust
number of instances.

* src/truetype/ttgxvar.c: Include FT_TRUETYPE_IDS_H.
(TT_Get_MM_Var): Use `face->root.style_flags' as the number of named
instances.
Sythesize a named instance entry if necessary.
(tt_done_blend): Free `normalized_stylecoords'.
2017-03-06 20:45:44 +01:00
Werner Lemberg 588e38e070 [truetype] Make `TT_Set_MM_Blend' set named instance index.
* src/truetype/ttgxvar.h (GX_Blend): New array
`normalized_stylecoords'.

* src/truetype/ttgxvar.c (TT_Get_MM_Var): Allocate and fill
`normalized_stylecoords'.
(TT_Set_MM_Blend): Check instance tuple and adjust `face_index'
accordingly.
2017-03-04 11:04:24 +01:00
Werner Lemberg 4717696c12 [truetype] Split off designer/normalized conversion routines.
* src/truetype/ttgxvar.c (TT_Set_Var_Design): Split off conversion
code designer->normalized coordinates to...
(ft_var_to_normalized): ... New function.
(TT_Get_Var_Design): Split off conversion code normalized->designer
coordinates to...
(ft_var_to_design): ... New function.
2017-03-02 21:42:14 +01:00
Werner Lemberg f0cee1a22c * include/freetype/internal/tttypes.h (TT_Face): s/isCFF2/is_cff2/.
For orthogonality with other structure field names.

Update all users.
2017-02-23 08:23:39 +01:00
Werner Lemberg faa3c88254 [truetype] Implement `VVAR' table support.
* src/truetype/ttgxvar.h (GX_HVarTable): Renamed to...
(GX_HVVarTable): ...This.
(GX_Blend): Add fields for `VVAR' table handling.
Other minor updates.

* src/truetype/ttgxvar.c (ft_var_load_hvar): Renamed to...
(ft_var_load_hvvar): ...This.
Handle VVAR loading also (controlled by an additional parameter).
(tt_hadvance_adjust): Renamed to...
(tt_hvadvance_adjust): ...This.
Handle application of advance height also (controlled by an
additional parameter).
(tt_hadvance_adjust, tt_vadvance_adjust): Wrappers for
`tt_hvadvance_adjust'.

* src/truetype/ttdriver.c (tt_service_metrics_variations): Updated.
2017-02-06 13:13:02 +01:00
Werner Lemberg e80e4d811a [truetype] Fix sanity check for `gvar' table (#50184).
* src/truetype/ttgxvar.c (ft_var_load_gvar): There might be missing
variation data for some glyphs.
2017-01-31 08:32:07 +01:00
Werner Lemberg 9db55ad1af Typo. 2017-01-30 07:35:06 +01:00
Werner Lemberg f502092bcd [truetype] Minor updates for OpenType 1.8.1.
* src/truetype/ttgxvar.h (GX_MVarTable): `axisCount' has been
removed frem the specification; it is now reserved.

* src/truetype/ttgxvar.c (ft_var_load_mvar): Updated.
(GX_FVar_Head): Remove `countSizePairs'; the corresponding data
field in the `MVAR' table is now reserved.
(fvar_fields): Updated.
2017-01-23 11:47:40 +01:00
Werner Lemberg 79d52b9a8d [truetype] Avoid segfault for invalid variation data.
* src/truetype/ttgxvar.c (ft_var_load_item_variation_store): Assure
`itemCount' is not zero.

Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=441
2017-01-23 07:43:56 +01:00
Werner Lemberg 322b3be514 * src/truetype/ttgxvar.c (tt_apply_var): Handle underline parameters
also.
2017-01-15 13:57:25 +01:00
Werner Lemberg d718ac4ead [truetype] Provide metrics variation service.
* include/freetype/internal/services/svmetric.h
(FT_Metrics_Adjust_Func): Reduce number of necessary parameters.

* src/truetype/ttgxvar.c: Include FT_LIST_H.
(tt_size_reset_iterator): New auxiliary function for...
(tt_apply_var): New function.

* src/truetype/ttgxvar.h: Updated.

* src/truetype/ttdriver.c (tt_service_metrics_variations): Add
`tt_apply_mvar'.

* include/freetype/internal/ftserv.h (FT_ServiceCache): Add metrics
variation service.
2017-01-11 14:12:34 +01:00
Werner Lemberg 07ee1d250c [truetype] Parse `MVAR' table.
* src/truetype/ttgxvar.h (MVAR_TAG_XXX): New macros for MVAR tags.
(GX_Value, GX_MVarTable): New structures.
(GX_Blend): Add it.

* src/truetype/ttgxvar.c (GX_VALUE_SIZE, GX_VALUE_CASE,
GX_GASP_CASE): New macros.
(ft_var_get_value_pointer): New auxiliary function to get a pointer
to a value from various SFNT tables already stored in `TT_Face'.
(ft_var_load_mvar): New function.
(TT_Get_MM_Var): Call it.
(tt_done_blend): Updated.
2017-01-11 12:50:51 +01:00
Werner Lemberg 469ced7f7f [truetype] Again some GX code shuffling.
We need this later on for MVAR also.

* src/truetype/ttgxvar.c (tt_hadvance_adjust): Split off computing
an item store variation delta into...
(ft_var_get_item_delta): ...new function.
2017-01-08 09:28:34 +01:00
Werner Lemberg 0291913491 [truetype] More GX code shuffling.
We need this later on for MVAR also.

* src/truetype/ttgxvar.c (tt_done_blend): Split off handling of item
variation store into...
(ft_var_done_item_variation_store): ...new function.
2017-01-07 07:45:28 +01:00
Werner Lemberg fb90f00cbd [truetype] More generalization of GX stuff.
We need this later on for MVAR also.

* src/truetype/ttgxvar.c (ft_var_load_delta_set_index_mapping): Add
parameters for delta-set index mapping and item variation store.
(ft_var_load_item_variation_store): Add parameter for item variation
store.
s/hvarData/varData/.
Move allocation of `hvar_table' to...
(ft_var_load_hvar): ...this function.
Updated.
2017-01-06 22:23:52 +01:00
Werner Lemberg 0bd0112f4e [truetype] Some GX structure renames for generalization.
We need this later on for MVAR also.

* src/truetype/ttgxvar.h (GX_HVarData): Renamed to...
(GX_ItemVarData): ...this.
(GX_HVarRegion): Renamed to...
(GX_VarRegion): ...this.
(GX_HVStore): Renamed to...
(GX_ItemVarStore): ...this.
(GX_WidthMap): Renamed to...
(GX_DeltaSetIdxMap): ...this.

(GX_HVarTable): Updated.

* src/truetype/ttgxvar.c: Updated.
2017-01-06 21:32:49 +01:00
Werner Lemberg 9c814704c0 [truetype] Code shuffling.
* src/truetype/ttgxvar.c (): Split off loading of item variation
store and delta set index mapping into...
(ft_var_load_item_variation_store,
ft_var_load_delta_set_index_mapping): ... new functions.
2017-01-06 21:13:36 +01:00
Werner Lemberg 7e1cce58b5 [truetype] Add HVAR access without advance width map.
* src/truetype/ttgxvar.c (ft_var_load_hvar): Handle case where
`offsetToAdvanceWidthMapping' is zero.
(tt_hadvance_adjust): Implement direct deltaSet access by glyph
index.
2017-01-06 20:31:22 +01:00
Werner Lemberg 348d39c68a Comment. 2017-01-05 12:29:55 +01:00
Werner Lemberg 563ae78022 Update copyright year. 2017-01-04 20:16:34 +01:00
Werner Lemberg 248eaa4f60 Various fixes for clang's undefined behaviour sanitizer.
* src/cff/cffload.c (FT_fdot14ToFixed): Fix casting.
(cff_blend_doBlend): Don't left-shift negative numbers.
Handle 5-byte numbers byte by byte to avoid alignment issues.

* src/cff/cffparse.c (cff_parse): Handle 5-byte numbers byte by byte
to avoid alignment issues.

* src/cid/cidload (cid_read_subrs): Do nothing if we don't have any
subrs.

* src/psaux/t1decode.c (t1_decode_parse_charstring): Fix tracing.

* src/tools/glnames.py (main): Put `DEFINE_PSTABLES' guard around
definition of `ft_get_adobe_glyph_index'.

* src/psnames/pstables.h: Regenerated.

* src/psnames/psmodule.c: Inlude `pstables.h' twice to get both
declaration and definition.

* src/truetype/ttgxvar.c (FT_fdot14ToFixed, FT_intToFixed): Fix
casting.
2017-01-03 00:27:07 +01:00
Werner Lemberg e9a154e700 [truetype] Check axis count in HVAR table.
Reported as

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

* src/truetype/ttgxvar.c (ft_var_load_hvar): Check axis count.
(ft_var_load_avar): Fix tracing message.
2016-12-31 21:41:08 +01:00
Werner Lemberg 7591bf11d1 [truetype] Variation font API stability issues.
Make some functions work before a call to `TT_Set_MM_Blend'.

* src/truetype/ttgxvar.c (tt_hadvance_adjust): Exit immediately if
we don't blend.
(TT_Get_MM_Blend, TT_Get_Var_Design): Return default values if we
don't blend.
2016-12-29 21:39:06 +01:00
Werner Lemberg 91fc3bd7c9 * src/truetype/ttgxvar.c (TT_Get_MM_Var): Check axis data.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=348
2016-12-29 21:34:46 +01:00
Werner Lemberg 180185109b [truetype] Tracing fixes.
* src/truetype/ttgxvar.c (tt_hadvance_adjust): Emit correct
information.
(TT_Set_Var_Design): Fix typo.
(TT_Get_Var_Design): Fix typos.
2016-12-29 21:30:06 +01:00
Werner Lemberg 84b0d9927b */*: Use `0.5f' for tracing 16.16 numbers. 2016-12-29 10:38:51 +01:00
Werner Lemberg e5e3556fa2 [truetype, type1] Implement `FT_Get_Var_Design_Coordinates'.
* src/truetype/ttgxvar.c (TT_Get_Var_Design): Implement.
(TT_Set_Var_Design): Fix tracing.

* src/type1/t1load.c (T1_Get_Var_Design): Implement.
2016-12-27 06:49:37 +01:00
Werner Lemberg f80c4473b6 Replace `++foo' and `--foo' with `foo++' and `foo--', resp. 2016-12-26 23:57:45 +01:00
Werner Lemberg 4441f7b246 Replace `foo == NULL' and `foo != NULL' with `!foo' and `foo', resp.
Other minor formatting.
2016-12-26 17:08:17 +01:00
Werner Lemberg 7209110345 * src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Thinko.
I should really stop coding late in the evening...

Thanks again to Ben for checking.
2016-12-21 23:46:29 +01:00
Werner Lemberg d44daf9e9b * src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Thinko.
Don't apply deltas twice for non-phantom points.

Spotted by Ben Wagner.
2016-12-21 23:03:48 +01:00
Werner Lemberg 64a91137f1 [truetype, sfnt] Introduce font variation flags to `TT_Face'.
* include/freetype/internal/tttypes.h (TT_FACE_FLAG_VAR_XXX):
New macros describing available functionality of various OpenType
tables related to font variation.
(TT_Face): New fields `variation_support' and `mvar_support',
replacing and extending `use_fvar'.

* src/sfnt/sfobjs.c (sfnt_init_face, sfnt_load_face): Use
`variation_support'.

* src/truetype/ttgxvar.c (ft_var_load_hvar): Set `variation_support'
field.
(TT_Vary_Apply_Glyph_Deltas): Updated.
2016-12-21 19:30:33 +01:00
Werner Lemberg a8652c59da [truetype, cff] Extend `get_var_blend' function of MM service.
In particular, we need access to named instance data.

* include/freetype/internal/services/svmm.h (FT_Get_Var_Blend_Func):
Add argument for `FT_MM_Var'.

* src/cff/cffload.c (cff_get_var_blend): Updated.
* src/cff/cffload.h: Updated.

* src/cff/cf2ft.c (cf2_getNormalizedVector): Updated.

* src/truetype/ttgxvar.c (tt_get_var_blend): Updated.
Accept value `NULL' for arguments.
* src/truetype/ttgxvar.h: Updated.
2016-12-18 18:12:03 +01:00
Werner Lemberg 25f3ac2b9e [sfnt] Handle `fvar' with zero axes as a non-MM font.
This is better behaviour than exiting with an error.

* include/freetype/internal/tttypes.h (TT_Face): Add `use_fvar'
field.

* src/sfnt/sfobjs.c (sfnt_init_face): Compute `use_fvar', also
updating the validation code.
Use `use_fvar' to compute FT_FACE_FLAG_MULTIPLE_MASTERS.

* src/truetype/ttgxvar.c (TT_Get_MM_Var): Remove `fvar' validation
code.
2016-12-18 15:50:18 +01:00
Werner Lemberg 5d664b6d51 Use FT_SET_ERROR where useful. Other minor code formatting. 2016-12-17 20:47:42 +01:00
Werner Lemberg 7c75b166c8 [sfnt, truetype] Various sanitizing fixes.
* src/sfnt/sfobjs.c (sfnt_init_face): If the axis count in `fvar' is
zero, set `num_instances' to zero.

* src/truetype/ttgxvar.c (TT_Get_MM_Var): Handle `fvar' table with
zero axes as invalid.

* src/truetype/ttobjs.c (tt_face_init): Improve logic of loading
`loca', `cvt', `fpgm', and `prep' table.
2016-12-17 13:28:24 +01:00
Werner Lemberg df2cf43e94 [truetype] Fix `cvar' sanity test.
Reported by Dave Arnold.

* src/truetype/ttgxvar.c (tt_face_vary_cvt): Use tuple count mask.
2016-12-16 11:38:20 +01:00
Werner Lemberg 6862024854 [cff, truetype] Remove compiler warnings; fix `make multi'.
* src/cff/cf2font.h: Include `cffload.h'.

* src/cff/cffload.c: Include FT_MULTIPLE_MASTERS_H and
FT_SERVICE_MULTIPLE_MASTERS_H.
(cff_vstore_load): Eliminate `vsSize'.
(cff_load_private_dict): Tag as `FT_LOCAL_DEF'.

* src/cff/cffload.h: Include `cffobjs.h'.
Provide declaration for `cff_load_private_dict'.

* src/truetype/ttgxvar.c (ft_var_load_hvar): Eliminate
`minorVersion' and `map_offset'.
2016-12-16 11:15:17 +01:00
Dave Arnold edf4014854 [cff] Implement CFF2 support (2/2).
The font variation code.  All parts dependent on the GX code in the
`truetype' module are guarded with TT_CONFIG_OPTION_GX_VAR_SUPPORT.
In other words, you can still compile the `cff' module without
defining TT_CONFIG_OPTION_GX_VAR_SUPPORT (which brings you CFF2
support without font variation).

* src/cff/cf2font.c (cf2_font_setup): Add support for font
variation.
* src/cff/cf2font.h (CF2_Font): Add fields for variation data.

* src/cff/cf2ft.c (cf2_free_instance): Free blend data.
(cf2_getVStore, cf2_getNormalizedVector): New functions.
* src/cff/cf2ft.h: Updated.

* src/cff/cf2intrp.c: Include `cffload.h'.
(cf2_cmdRESERVED_15, cf2_cmdRESERVED_16): Replace with...
(cf2_cmdVSINDEX, cf2_cmdBLEND): ... this new enum values.
(cf2_doBlend): New function.
(cf2_interpT2CharString): Handle `vsindex' and `blend' opcodes.

* src/cff/cffload.c (FT_fdot14ToFixed): New macro.
(cff_vstore_done, cff_vstore_load): New functions.
(cff_blend_clear, cff_blend_doBlend, cff_blend_build_vector,
cff_blend_check_vector): New functions.
(cff_load_private_dict): Add arguments for blend vector.
Handle blend data.
(cff_subfont_load, cff_subfont_done): Updated.
(cff_font_load): Handle CFF2 variation store data.
(cff_font_done): Updated.
* src/cff/cffload.h: Include `cffparse.h'.
Updated.

* src/cff/cffobjs.c (cff_face_done): Updated.

* src/cff/cffparse.c: Include `cffload.h'.
(cff_parse_num): Handle internal value 255.
(cff_parse_vsindex, cff_parse_blend): New functions.
(CFF_FIELD_BLEND): New macro.
(cff_parser_run): Updated.
* src/cff/cffparse.h (cff_kind_blend): New enum value.

* src/cff/cfftoken.h: Handle `vstore', `vsindex', and `blend'
dictionary values.

* src/cff/cfftypes.h (CFF_VarData, CFF_AxisCoords, CFF_VarRegion,
CFF_VStore, CFF_Blend): New structures.
(CFF_FontRecDict): Add `vstore_offset' field.
(CFF_Private): Add `vsindex' field.
(CFF_SubFont): Add fields for blend data.
(CFF_Font): Add `vstore' field.

* src/truetype/ttgxvar.c (TT_Get_MM_Var): `CFF2' is equal to `gvar',
since glyph variation data is directly embedded.
(TT_Set_MM_Blend): Don't load `gvar' table for CFF2 fonts.
2016-12-15 21:56:44 +01:00
Werner Lemberg 3bd79cc257 [truetype] Provide HVAR advance width variation as a service.
Everything is guarded with TT_CONFIG_OPTION_GX_VAR_SUPPORT.

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

* src/truetype/ttgxvar.c (TT_Vary_Apply_Glyph_Deltas): Prevent
double adjustment of advance width.

* src/sfnt/ttmtx.c: Include FT_SERVICE_METRICS_VARIATIONS_H.
(tt_face_get_metrics): Apply metrics variations.
2016-12-15 14:34:57 +01:00
Dave Arnold aa0c4b4f55 [truetype] Provide function to apply `HVAR' advance width variation.
* src/truetype/ttgxvar.c (tt_hadvance_adjust): New function.
* src/truetype/ttgxvar.h: Updated.
2016-12-15 14:04:51 +01:00
Dave Arnold 097cd874ee [truetype] Add `HVAR' table parsing.
Note that this is not complete yet; it only handles advance width
variation.

Activation of the code follows in another commit.

* include/freetype/ftmm.h (FT_Var_Named_Style): Add `psid' member.

* src/truetype/ttgxvar.h (GX_HVarData, GX_AxisCoords, GX_HVarRegion,
GX_HVStore, GX_WidthMap): New auxiliary structures for...
(GX_HVarTable): ... HVAR main structure.
(GX_BlendRec): Add data for HVAR loading.

* src/truetype/ttgxvar.c (FT_FIXED_ONE, FT_fdot14ToFixed,
FT_intToFixed, FT_fixedToInt): New macros.
(ft_var_load_hvar): New function.
(TT_Get_MM_Var): Updated.
(tt_done_blend): Deallocate HVAR data.
2016-12-15 12:58:26 +01:00
Werner Lemberg ab22b43bac * src/truetype/ttgxvar.c (tt_get_var_blend): Fix compiler warning. 2016-12-14 18:34:55 +01:00
Werner Lemberg 8b174b4b96 [truetype, type1] Add `get_var_blend' to MM service.
For internal use; we want to share code between the forthcoming CFF2
support and TrueType.

* include/freetype/internal/services/svmm.h (FT_Get_Var_Blend_Func):
New typedef.
(MultiMasters): Add `get_var_blend'.
(FT_Service_MultiMasters): Updated.

* src/truetype/ttgxvar.c (tt_get_var_blend): 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.
2016-12-11 09:16:52 +01:00