2018-06-03 09:01:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* cffparse.h
|
|
|
|
*
|
|
|
|
* CFF token stream parser (specification)
|
|
|
|
*
|
2023-01-17 09:18:25 +01:00
|
|
|
* Copyright (C) 1996-2023 by
|
2018-06-03 09:01:17 +02:00
|
|
|
* David Turner, Robert Wilhelm, and Werner Lemberg.
|
|
|
|
*
|
|
|
|
* This file is part of the FreeType project, and may only be used,
|
|
|
|
* modified, and distributed under the terms of the FreeType project
|
|
|
|
* license, LICENSE.TXT. By continuing to use, modify, or distribute
|
|
|
|
* this file you indicate that you have read the license and
|
|
|
|
* understand and accept it fully.
|
|
|
|
*
|
|
|
|
*/
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
|
2016-01-12 21:37:13 +01:00
|
|
|
#ifndef CFFPARSE_H_
|
|
|
|
#define CFFPARSE_H_
|
2000-12-08 03:42:29 +01:00
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
|
2020-06-08 13:31:55 +02:00
|
|
|
#include <freetype/internal/cfftypes.h>
|
|
|
|
#include <freetype/internal/ftobjs.h>
|
2000-12-08 03:42:29 +01:00
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
|
2000-12-08 03:42:29 +01:00
|
|
|
FT_BEGIN_HEADER
|
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
|
[cff] Implement CFF2 support (1/2).
This commit does not contain the blend code for font variation
support, which follows in another commit.
You should ignore whitespace while inspecting this commit.
* include/freetype/internal/tttypes.h (TT_Face): Add `isCFF2'
member.
* src/cff/cf2font.h (CF2_Font): Add `isCFF2' member.
* src/cff/cf2ft.c (cf2_decoder_parse_charstrings): Handle `isCFF2'
flag.
(cf2_getMaxstack): New function.
* src/cff/cf2ft.h: Updated.
* src/cff/cf2intrp.c (cf2_escRESERVED_38): New enum.
(cf2_interpT2CharString): Handle CFF2 differences.
Add tracing message for errors.
* src/cff/cffdrivr.c (cff_get_glyph_name, cff_get_name_index):
Update for CFF2.
* src/cff/cffload.c (FT_FIXED_ONE): New macro.
(cff_index_init, cff_index_load_offsets, cff_index_access_element,
cff_index_get_name, cff_ft_select_get, cff_load_private_dict,
cff_subfont_load, cff_font_load): Handle CFF2.
* src/cff/cffload.h: Updated.
* src/cff/cffobjs.c (cff_face_init): Handle CFF2.
* src/cff/cffparse.c (cff_parse_maxstack): New function.
(CFFCODE_TOPDICT, CFFCODE_PRIVATE): Removed
* src/cff/cffparse.h (CFF2_MAX_STACK, CFF2_DEFAULT_STACK): New
macros.
(CFF2_CODE_TOPDICT, CFF2_CODE_FONTDICT, CFF2_CODE_PRIVATE): New
macros.
* src/cff/cfftoken.h: Add fields for CFF2 dictionaries (but no blend
stuff).
* src/cff/cfftypes.h (CFF_Index): Add `hdr_size' field.
(CFF_FontRecDict): Add `maxstack' field.
(CFF_Private): Add `subfont' field.
(CFF_Font): Add `top_dict_length' and `cff2' fields.
* src/sfnt/sfobjs.c (sfnt_load_face): Handle `CFF2' table.
2016-12-15 20:27:47 +01:00
|
|
|
/* CFF uses constant parser stack size; */
|
|
|
|
/* CFF2 can increase from default 193 */
|
2000-12-08 03:42:29 +01:00
|
|
|
#define CFF_MAX_STACK_DEPTH 96
|
2017-03-30 21:07:17 +02:00
|
|
|
|
|
|
|
/*
|
2018-06-03 09:01:17 +02:00
|
|
|
* There are plans to remove the `maxstack' operator in a forthcoming
|
|
|
|
* revision of the CFF2 specification, increasing the (then static) stack
|
|
|
|
* size to 513. By making the default stack size equal to the maximum
|
|
|
|
* stack size, the operator is essentially disabled, which has the
|
|
|
|
* desired effect in FreeType.
|
2017-03-30 21:07:17 +02:00
|
|
|
*/
|
[cff] Implement CFF2 support (1/2).
This commit does not contain the blend code for font variation
support, which follows in another commit.
You should ignore whitespace while inspecting this commit.
* include/freetype/internal/tttypes.h (TT_Face): Add `isCFF2'
member.
* src/cff/cf2font.h (CF2_Font): Add `isCFF2' member.
* src/cff/cf2ft.c (cf2_decoder_parse_charstrings): Handle `isCFF2'
flag.
(cf2_getMaxstack): New function.
* src/cff/cf2ft.h: Updated.
* src/cff/cf2intrp.c (cf2_escRESERVED_38): New enum.
(cf2_interpT2CharString): Handle CFF2 differences.
Add tracing message for errors.
* src/cff/cffdrivr.c (cff_get_glyph_name, cff_get_name_index):
Update for CFF2.
* src/cff/cffload.c (FT_FIXED_ONE): New macro.
(cff_index_init, cff_index_load_offsets, cff_index_access_element,
cff_index_get_name, cff_ft_select_get, cff_load_private_dict,
cff_subfont_load, cff_font_load): Handle CFF2.
* src/cff/cffload.h: Updated.
* src/cff/cffobjs.c (cff_face_init): Handle CFF2.
* src/cff/cffparse.c (cff_parse_maxstack): New function.
(CFFCODE_TOPDICT, CFFCODE_PRIVATE): Removed
* src/cff/cffparse.h (CFF2_MAX_STACK, CFF2_DEFAULT_STACK): New
macros.
(CFF2_CODE_TOPDICT, CFF2_CODE_FONTDICT, CFF2_CODE_PRIVATE): New
macros.
* src/cff/cfftoken.h: Add fields for CFF2 dictionaries (but no blend
stuff).
* src/cff/cfftypes.h (CFF_Index): Add `hdr_size' field.
(CFF_FontRecDict): Add `maxstack' field.
(CFF_Private): Add `subfont' field.
(CFF_Font): Add `top_dict_length' and `cff2' fields.
* src/sfnt/sfobjs.c (sfnt_load_face): Handle `CFF2' table.
2016-12-15 20:27:47 +01:00
|
|
|
#define CFF2_MAX_STACK 513
|
2017-03-30 21:07:17 +02:00
|
|
|
#define CFF2_DEFAULT_STACK 513
|
[cff] Implement CFF2 support (1/2).
This commit does not contain the blend code for font variation
support, which follows in another commit.
You should ignore whitespace while inspecting this commit.
* include/freetype/internal/tttypes.h (TT_Face): Add `isCFF2'
member.
* src/cff/cf2font.h (CF2_Font): Add `isCFF2' member.
* src/cff/cf2ft.c (cf2_decoder_parse_charstrings): Handle `isCFF2'
flag.
(cf2_getMaxstack): New function.
* src/cff/cf2ft.h: Updated.
* src/cff/cf2intrp.c (cf2_escRESERVED_38): New enum.
(cf2_interpT2CharString): Handle CFF2 differences.
Add tracing message for errors.
* src/cff/cffdrivr.c (cff_get_glyph_name, cff_get_name_index):
Update for CFF2.
* src/cff/cffload.c (FT_FIXED_ONE): New macro.
(cff_index_init, cff_index_load_offsets, cff_index_access_element,
cff_index_get_name, cff_ft_select_get, cff_load_private_dict,
cff_subfont_load, cff_font_load): Handle CFF2.
* src/cff/cffload.h: Updated.
* src/cff/cffobjs.c (cff_face_init): Handle CFF2.
* src/cff/cffparse.c (cff_parse_maxstack): New function.
(CFFCODE_TOPDICT, CFFCODE_PRIVATE): Removed
* src/cff/cffparse.h (CFF2_MAX_STACK, CFF2_DEFAULT_STACK): New
macros.
(CFF2_CODE_TOPDICT, CFF2_CODE_FONTDICT, CFF2_CODE_PRIVATE): New
macros.
* src/cff/cfftoken.h: Add fields for CFF2 dictionaries (but no blend
stuff).
* src/cff/cfftypes.h (CFF_Index): Add `hdr_size' field.
(CFF_FontRecDict): Add `maxstack' field.
(CFF_Private): Add `subfont' field.
(CFF_Font): Add `top_dict_length' and `cff2' fields.
* src/sfnt/sfobjs.c (sfnt_load_face): Handle `CFF2' table.
2016-12-15 20:27:47 +01:00
|
|
|
|
|
|
|
#define CFF_CODE_TOPDICT 0x1000
|
|
|
|
#define CFF_CODE_PRIVATE 0x2000
|
|
|
|
#define CFF2_CODE_TOPDICT 0x3000
|
|
|
|
#define CFF2_CODE_FONTDICT 0x4000
|
|
|
|
#define CFF2_CODE_PRIVATE 0x5000
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
|
2002-03-20 10:44:20 +01:00
|
|
|
typedef struct CFF_ParserRec_
|
2000-12-08 03:42:29 +01:00
|
|
|
{
|
2016-02-15 20:41:58 +01:00
|
|
|
FT_Library library;
|
|
|
|
FT_Byte* start;
|
|
|
|
FT_Byte* limit;
|
|
|
|
FT_Byte* cursor;
|
2000-12-08 03:42:29 +01:00
|
|
|
|
2016-12-15 11:22:15 +01:00
|
|
|
FT_Byte** stack;
|
2016-02-15 20:41:58 +01:00
|
|
|
FT_Byte** top;
|
2016-12-15 11:22:15 +01:00
|
|
|
FT_UInt stackSize; /* allocated size */
|
2000-12-08 03:42:29 +01:00
|
|
|
|
2019-03-31 12:08:49 +02:00
|
|
|
#ifdef CFF_CONFIG_OPTION_OLD_ENGINE
|
|
|
|
FT_ListRec t2_strings;
|
|
|
|
#endif /* CFF_CONFIG_OPTION_OLD_ENGINE */
|
|
|
|
|
2016-02-15 20:41:58 +01:00
|
|
|
FT_UInt object_code;
|
|
|
|
void* object;
|
2000-12-08 03:42:29 +01:00
|
|
|
|
2016-02-15 20:41:58 +01:00
|
|
|
FT_UShort num_designs; /* a copy of `CFF_FontRecDict->num_designs' */
|
|
|
|
FT_UShort num_axes; /* a copy of `CFF_FontRecDict->num_axes' */
|
2016-02-14 16:03:15 +01:00
|
|
|
|
2002-03-20 10:44:20 +01:00
|
|
|
} CFF_ParserRec, *CFF_Parser;
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
|
2016-12-15 12:17:22 +01:00
|
|
|
FT_LOCAL( FT_Long )
|
|
|
|
cff_parse_num( CFF_Parser parser,
|
|
|
|
FT_Byte** d );
|
|
|
|
|
2023-07-14 18:58:55 +02:00
|
|
|
FT_LOCAL( FT_Fixed )
|
|
|
|
cff_parse_fixed( CFF_Parser parser,
|
|
|
|
FT_Byte** d );
|
|
|
|
|
2016-12-15 11:22:15 +01:00
|
|
|
FT_LOCAL( FT_Error )
|
* src/cff/cffcmap.c, src/cff/cffcmap.h, Jamfile, rules.mk: new files added
to support charmaps for CFF fonts
* src/cff/cffload.c, src/cff/cffload.h, src/cff/cffobjs.c,
src/cff/cffobjs.h, src/cff/cffparse.c, src/cffparse.h, src/cff/cffgload.c,
src/cff/cffgload.h: adding support for CFF charmaps, reformatting the
sources, and removing some bugs in the Encoding and Charset loaders
2002-07-10 18:52:06 +02:00
|
|
|
cff_parser_init( CFF_Parser parser,
|
2002-03-30 17:41:09 +01:00
|
|
|
FT_UInt code,
|
2009-04-05 16:34:40 +02:00
|
|
|
void* object,
|
2016-02-14 16:03:15 +01:00
|
|
|
FT_Library library,
|
2016-12-15 11:22:15 +01:00
|
|
|
FT_UInt stackSize,
|
2016-02-15 20:41:58 +01:00
|
|
|
FT_UShort num_designs,
|
|
|
|
FT_UShort num_axes );
|
2001-06-27 21:46:12 +02:00
|
|
|
|
2016-12-15 11:22:15 +01:00
|
|
|
FT_LOCAL( void )
|
|
|
|
cff_parser_done( CFF_Parser parser );
|
|
|
|
|
2002-03-01 03:26:22 +01:00
|
|
|
FT_LOCAL( FT_Error )
|
* src/cff/cffcmap.c, src/cff/cffcmap.h, Jamfile, rules.mk: new files added
to support charmaps for CFF fonts
* src/cff/cffload.c, src/cff/cffload.h, src/cff/cffobjs.c,
src/cff/cffobjs.h, src/cff/cffparse.c, src/cffparse.h, src/cff/cffgload.c,
src/cff/cffgload.h: adding support for CFF charmaps, reformatting the
sources, and removing some bugs in the Encoding and Charset loaders
2002-07-10 18:52:06 +02:00
|
|
|
cff_parser_run( CFF_Parser parser,
|
2002-03-30 17:41:09 +01:00
|
|
|
FT_Byte* start,
|
|
|
|
FT_Byte* limit );
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
|
2009-04-05 16:34:40 +02:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
cff_kind_none = 0,
|
|
|
|
cff_kind_num,
|
|
|
|
cff_kind_fixed,
|
|
|
|
cff_kind_fixed_thousand,
|
|
|
|
cff_kind_string,
|
|
|
|
cff_kind_bool,
|
|
|
|
cff_kind_delta,
|
[CFF] Extract `BlueValues` as `Fixed` rather than `Int`.
This is a follow-up to commit 26a7f047,
[cff] Make blend operator work with floats in private dicts.
which addressed the 'party baseline' bug. However, the reporting user
indicated that the default location and some other points in design space
rendered OK, but other points in design space still had problems. The most
obvious issue being that the x-heights of lower-case letters did not align;
see
https://github.com/adobe-fonts/source-serif/issues/121#issuecomment-1773794136
After some analysis we determined that this was due to an interaction
between `BlueValue` rounding and the zone-based algorithm. In short, for a
point to be considered in a zone it must fall within the bounds of the zone.
(There is a slop factor in some cases, but only a very small one.) In the
Adobe-contributed side of the code, point values are not integer-rounded,
instead they're kept as (some form of) fixed. Rounding just the `BlueValues`
means that points that need to be considered within a zone will fall outside
of it at some points in design space.
The majority of this patch changes the storage and parsing of `BlueValues`
to keep them as `FT_Fixed`. No significant code changes were needed because
the values are converted to `Fixed` anyway when stored in `CF_BlueRec`. No
attempt was made to address problems in the older pshinter code beyond
converting the values from `FT_Fixed` to `FT_Short` when copying the private
dictionary. (However, as the point values are also rounded in that code,
the problem is much less likely to occur, although inconsistency between
rounding and truncation could cause an analogous problem.)
* include/freetype/internal/cfftypes.h (CFF_PrivateRec): Use `FT_Fixed` for
`blue_values`, `other_blues`, `family_blues`, and `family_other_blues`.
* src/cff/cffload.c (cff_blend_doBlend): Updated.
* src/cff/cffobjs.c (CFF_fixedToInt): New macro.
(cff_make_private_dict): Use it.
* src/cff/cffparse.h (cff_kind_delta_fixed): New enum value.
* src/cff/cffparse.c (do_fixed): Updated.
(CFF_FIELD_DELTA, CFF_FIELD_DELTA_FIXED, CFF_DELTA_KIND): New set of macros,
replacing `CFF_FIELD_DELTA`.
(cff_parser_run): Updated to handle fixed-float deltas.
* src/cff/cfftoken.h: Updated to use `CFF_FIELD_DELTA_FIXED` for blue
values.
* src/psaux/psblues.c (cf2_blueToFixed): Removed, no longer needed.
(cf2_blues_init): Updated.
* src/pxaux/psft.c, src/pxaux/psft.h (cf2_getBlueValues, cf2_getOtherBlues,
cf2_getFamilyBlues, cf2_getFamilyOtherBlues): Updated signatures.
* src/psaux/psobjs.c (t1_make_subfont): Updated.
2023-12-14 06:59:05 +01:00
|
|
|
cff_kind_delta_fixed,
|
2009-04-05 16:34:40 +02:00
|
|
|
cff_kind_callback,
|
[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
|
|
|
cff_kind_blend,
|
2009-04-05 16:34:40 +02:00
|
|
|
|
|
|
|
cff_kind_max /* do not remove */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* now generate handlers for the most simple fields */
|
|
|
|
typedef FT_Error (*CFF_Field_Reader)( CFF_Parser parser );
|
|
|
|
|
|
|
|
typedef struct CFF_Field_Handler_
|
|
|
|
{
|
|
|
|
int kind;
|
|
|
|
int code;
|
|
|
|
FT_UInt offset;
|
|
|
|
FT_Byte size;
|
|
|
|
CFF_Field_Reader reader;
|
|
|
|
FT_UInt array_max;
|
|
|
|
FT_UInt count_offset;
|
|
|
|
|
[cff] Better tracing of the parsing process.
* src/cff/cffload.c (cff_subfont_load, cff_font_load): Decorate with
FT_TRACE.
* src/cff/cffparse.c (cff_parse_font_matrix, cff_parse_font_bbox,
cff_parse_private_dict, cff_parse_cid_ros): Updated.
(CFF_FIELD_NUM, CFF_FIELD_FIXED, CFF_FIELD_FIXED_1000,
CFF_FIELD_STRING, CFF_FIELD_BOOL, CFF_FIELD_CALLBACK, CFF_FIELD,
CFF_FIELD_DELTA): Add argument for ID.
(cff_parser_run): Decorate with FT_TRACE.
* src/cff/cffparse.h (CFF_Field_Handler) [FT_DEBUG_LEVEL_TRACE]: Add
`id' member.
* src/cff/cfftoken.h: Add IDs to all fields.
2011-08-25 13:41:16 +02:00
|
|
|
#ifdef FT_DEBUG_LEVEL_TRACE
|
|
|
|
const char* id;
|
|
|
|
#endif
|
|
|
|
|
2009-04-05 16:34:40 +02:00
|
|
|
} CFF_Field_Handler;
|
|
|
|
|
|
|
|
|
2000-12-08 03:42:29 +01:00
|
|
|
FT_END_HEADER
|
|
|
|
|
2000-12-08 17:17:16 +01:00
|
|
|
|
2016-01-12 21:37:13 +01:00
|
|
|
#endif /* CFFPARSE_H_ */
|
2000-12-08 03:42:29 +01:00
|
|
|
|
|
|
|
|
|
|
|
/* END */
|