From 4c39089a4d4901950110067024663d7a8a833bb2 Mon Sep 17 00:00:00 2001 From: Dave Arnold Date: Thu, 29 Sep 2016 16:54:53 -0700 Subject: [PATCH] Add separate parsing tables for CFF2 Limit Top, Font and Private dicts to operators allowed by spec Remove duplicate constants (CFFCODE vs CFF_CODE) Allow more than 256 Font Dicts (subfonts) in CFF2 --- src/cff/cf2font.c | 2 +- src/cff/cffload.c | 16 ++++++++------ src/cff/cffparse.c | 3 --- src/cff/cffparse.h | 7 +++++-- src/cff/cfftoken.h | 52 +++++++++++++++++++++++++++++++++++++++++----- src/cff/cfftypes.h | 3 +++ 6 files changed, 66 insertions(+), 17 deletions(-) diff --git a/src/cff/cf2font.c b/src/cff/cf2font.c index 4d5554460..87b0fab6f 100644 --- a/src/cff/cf2font.c +++ b/src/cff/cf2font.c @@ -417,7 +417,7 @@ font->lenNormalizedVector != lenNormalizedV || ( lenNormalizedV && memcmp( normalizedV, - &font->lastNormalizedVector, + font->lastNormalizedVector, lenNormalizedV * sizeof( *normalizedV ) ) != 0 ) ) { font->lastVsindex = subFont->font_dict.vsindex; diff --git a/src/cff/cffload.c b/src/cff/cffload.c index f792261c5..1342368e6 100644 --- a/src/cff/cffload.c +++ b/src/cff/cffload.c @@ -1469,7 +1469,8 @@ FT_UInt font_index, FT_Stream stream, FT_ULong base_offset, - FT_Library library ) + FT_Library library, + FT_UInt code ) { FT_Error error; CFF_ParserRec parser; @@ -1480,7 +1481,7 @@ cff_parser_init( &parser, - CFF_CODE_TOPDICT, + code, &font->font_dict, library, 0, @@ -1552,7 +1553,7 @@ priv->blue_scale = (FT_Fixed)( 0.039625 * 0x10000L * 1000 ); cff_parser_init( &parser, - CFF_CODE_PRIVATE, + code == CFF2_CODE_FONTDICT ? CFF2_CODE_PRIVATE : CFF_CODE_PRIVATE, priv, library, top->num_designs, @@ -1746,7 +1747,8 @@ subfont_index, stream, base_offset, - library ); + library, + cff2 ? CFF2_CODE_TOPDICT : CFF_CODE_TOPDICT ); if ( error ) goto Exit; @@ -1775,7 +1777,8 @@ if ( error ) goto Exit; - if ( fd_index.count > CFF_MAX_CID_FONTS ) + /* Font Dicts are not limited to 256 for CFF2 */ + if ( !cff2 && fd_index.count > CFF_MAX_CID_FONTS ) { FT_TRACE0(( "cff_font_load: FD array too large in CID font\n" )); goto Fail_CID; @@ -1796,7 +1799,8 @@ sub = font->subfonts[idx]; FT_TRACE4(( "parsing subfont %u\n", idx )); error = cff_subfont_load( sub, &fd_index, idx, - stream, base_offset, library ); + stream, base_offset, library, + cff2 ? CFF2_CODE_FONTDICT : CFF_CODE_TOPDICT ); if ( error ) goto Fail_CID; } diff --git a/src/cff/cffparse.c b/src/cff/cffparse.c index f007f858c..5a429d70c 100644 --- a/src/cff/cffparse.c +++ b/src/cff/cffparse.c @@ -820,9 +820,6 @@ #define CFF_FIELD_BOOL( code, name, id ) \ CFF_FIELD( code, name, id, cff_kind_bool ) -#define CFFCODE_TOPDICT 0x1000 -#define CFFCODE_PRIVATE 0x2000 - #ifndef FT_CONFIG_OPTION_PIC diff --git a/src/cff/cffparse.h b/src/cff/cffparse.h index 0134efbf0..7c0801596 100644 --- a/src/cff/cffparse.h +++ b/src/cff/cffparse.h @@ -30,8 +30,11 @@ FT_BEGIN_HEADER #define CFF_MAX_STACK_DEPTH 193 -#define CFF_CODE_TOPDICT 0x1000 -#define CFF_CODE_PRIVATE 0x2000 +#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 typedef struct CFF_ParserRec_ diff --git a/src/cff/cfftoken.h b/src/cff/cfftoken.h index 77e93afb5..c6712daf7 100644 --- a/src/cff/cfftoken.h +++ b/src/cff/cfftoken.h @@ -20,7 +20,7 @@ #define FT_STRUCTURE CFF_FontRecDictRec #undef CFFCODE -#define CFFCODE CFFCODE_TOPDICT +#define CFFCODE CFF_CODE_TOPDICT CFF_FIELD_STRING ( 0, version, "Version" ) CFF_FIELD_STRING ( 1, notice, "Notice" ) @@ -45,9 +45,6 @@ CFF_FIELD_NUM ( 16, encoding_offset, "Encoding" ) CFF_FIELD_NUM ( 17, charstrings_offset, "CharStrings" ) CFF_FIELD_CALLBACK( 18, private_dict, "Private" ) - CFF_FIELD_NUM ( 22, vsindex, "vsindex" ) - CFF_FIELD_NUM ( 24, vstore_offset, "vstore" ) - CFF_FIELD_NUM ( 25, maxstack, "maxstack" ) CFF_FIELD_NUM ( 0x114, synthetic_base, "SyntheticBase" ) CFF_FIELD_STRING ( 0x115, embedded_postscript, "PostScript" ) @@ -81,7 +78,7 @@ #undef FT_STRUCTURE #define FT_STRUCTURE CFF_PrivateRec #undef CFFCODE -#define CFFCODE CFFCODE_PRIVATE +#define CFFCODE CFF_CODE_PRIVATE CFF_FIELD_DELTA ( 6, blue_values, 14, "BlueValues" ) CFF_FIELD_DELTA ( 7, other_blues, 10, "OtherBlues" ) @@ -104,6 +101,51 @@ CFF_FIELD_NUM ( 20, default_width, "defaultWidthX" ) CFF_FIELD_NUM ( 21, nominal_width, "nominalWidthX" ) +#undef FT_STRUCTURE +#define FT_STRUCTURE CFF_FontRecDictRec + +#undef CFFCODE +#define CFFCODE CFF2_CODE_TOPDICT + + CFF_FIELD_CALLBACK( 0x107, font_matrix, "FontMatrix" ) + CFF_FIELD_NUM ( 17, charstrings_offset, "CharStrings" ) + CFF_FIELD_NUM ( 0x124, cid_fd_array_offset, "FDArray" ) + CFF_FIELD_NUM ( 0x125, cid_fd_select_offset, "FDSelect" ) + CFF_FIELD_NUM ( 24, vstore_offset, "vstore" ) + CFF_FIELD_NUM ( 25, maxstack, "maxstack" ) + +#undef FT_STRUCTURE +#define FT_STRUCTURE CFF_FontRecDictRec + +#undef CFFCODE +#define CFFCODE CFF2_CODE_FONTDICT + + CFF_FIELD_CALLBACK( 18, private_dict, "Private" ) + CFF_FIELD_CALLBACK( 0x107, font_matrix, "FontMatrix" ) + CFF_FIELD_STRING ( 0x126, cid_font_name, "FontName" ) + +#undef FT_STRUCTURE +#define FT_STRUCTURE CFF_PrivateRec + +#undef CFFCODE +#define CFFCODE CFF2_CODE_PRIVATE + + CFF_FIELD_DELTA ( 6, blue_values, 14, "BlueValues" ) + CFF_FIELD_DELTA ( 7, other_blues, 10, "OtherBlues" ) + CFF_FIELD_DELTA ( 8, family_blues, 14, "FamilyBlues" ) + CFF_FIELD_DELTA ( 9, family_other_blues, 10, "FamilyOtherBlues" ) + CFF_FIELD_FIXED_1000( 0x109, blue_scale, "BlueScale" ) + CFF_FIELD_NUM ( 0x10A, blue_shift, "BlueShift" ) + CFF_FIELD_NUM ( 0x10B, blue_fuzz, "BlueFuzz" ) + CFF_FIELD_NUM ( 10, standard_width, "StdHW" ) + CFF_FIELD_NUM ( 11, standard_height, "StdVW" ) + CFF_FIELD_DELTA ( 0x10C, snap_widths, 13, "StemSnapH" ) + CFF_FIELD_DELTA ( 0x10D, snap_heights, 13, "StemSnapV" ) + CFF_FIELD_NUM ( 0x111, language_group, "LanguageGroup" ) + CFF_FIELD_FIXED ( 0x112, expansion_factor, "ExpansionFactor" ) + CFF_FIELD_NUM ( 22, vsindex, "vsindex" ) CFF_FIELD_BLEND ( 31, "blend" ) + CFF_FIELD_NUM ( 19, local_subrs_offset, "Subrs" ) + /* END */ diff --git a/src/cff/cfftypes.h b/src/cff/cfftypes.h index ee0308681..379c1d056 100644 --- a/src/cff/cfftypes.h +++ b/src/cff/cfftypes.h @@ -223,6 +223,9 @@ FT_BEGIN_HEADER FT_Pos default_width; FT_Pos nominal_width; + /* fields for CFF2 */ + FT_UInt vsindex; + } CFF_PrivateRec, *CFF_Private;