[CFF] Change spaces to tabs

This commit is contained in:
Behdad Esfahbod 2018-11-30 23:04:59 -05:00
parent 592f39b3c4
commit 825df6dbc7
16 changed files with 1454 additions and 1449 deletions

View File

@ -31,184 +31,189 @@ namespace CFF {
using namespace OT; using namespace OT;
typedef unsigned int OpCode; typedef unsigned int OpCode;
/* === Dict operators === */ /* === Dict operators === */
/* One byte operators (0-31) */ /* One byte operators (0-31) */
#define OpCode_version 0 /* CFF Top */ #define OpCode_version 0 /* CFF Top */
#define OpCode_Notice 1 /* CFF Top */ #define OpCode_Notice 1 /* CFF Top */
#define OpCode_FullName 2 /* CFF Top */ #define OpCode_FullName 2 /* CFF Top */
#define OpCode_FamilyName 3 /* CFF Top */ #define OpCode_FamilyName 3 /* CFF Top */
#define OpCode_Weight 4 /* CFF Top */ #define OpCode_Weight 4 /* CFF Top */
#define OpCode_FontBBox 5 /* CFF Top */ #define OpCode_FontBBox 5 /* CFF Top */
#define OpCode_BlueValues 6 /* CFF Private, CFF2 Private */ #define OpCode_BlueValues 6 /* CFF Private, CFF2 Private */
#define OpCode_OtherBlues 7 /* CFF Private, CFF2 Private */ #define OpCode_OtherBlues 7 /* CFF Private, CFF2 Private */
#define OpCode_FamilyBlues 8 /* CFF Private, CFF2 Private */ #define OpCode_FamilyBlues 8 /* CFF Private, CFF2 Private */
#define OpCode_FamilyOtherBlues 9 /* CFF Private, CFF2 Private */ #define OpCode_FamilyOtherBlues 9 /* CFF Private, CFF2 Private */
#define OpCode_StdHW 10 /* CFF Private, CFF2 Private */ #define OpCode_StdHW 10 /* CFF Private, CFF2 Private */
#define OpCode_StdVW 11 /* CFF Private, CFF2 Private */ #define OpCode_StdVW 11 /* CFF Private, CFF2 Private */
#define OpCode_escape 12 /* All. Shared with CS */ #define OpCode_escape 12 /* All. Shared with CS */
#define OpCode_UniqueID 13 /* CFF Top */ #define OpCode_UniqueID 13 /* CFF Top */
#define OpCode_XUID 14 /* CFF Top */ #define OpCode_XUID 14 /* CFF Top */
#define OpCode_charset 15 /* CFF Top (0) */ #define OpCode_charset 15 /* CFF Top (0) */
#define OpCode_Encoding 16 /* CFF Top (0) */ #define OpCode_Encoding 16 /* CFF Top (0) */
#define OpCode_CharStrings 17 /* CFF Top, CFF2 Top */ #define OpCode_CharStrings 17 /* CFF Top, CFF2 Top */
#define OpCode_Private 18 /* CFF Top, CFF2 FD */ #define OpCode_Private 18 /* CFF Top, CFF2 FD */
#define OpCode_Subrs 19 /* CFF Private, CFF2 Private */ #define OpCode_Subrs 19 /* CFF Private, CFF2 Private */
#define OpCode_defaultWidthX 20 /* CFF Private (0) */ #define OpCode_defaultWidthX 20 /* CFF Private (0) */
#define OpCode_nominalWidthX 21 /* CFF Private (0) */ #define OpCode_nominalWidthX 21 /* CFF Private (0) */
#define OpCode_vsindexdict 22 /* CFF2 Private/CS */ #define OpCode_vsindexdict 22 /* CFF2 Private/CS */
#define OpCode_blenddict 23 /* CFF2 Private/CS */ #define OpCode_blenddict 23 /* CFF2 Private/CS */
#define OpCode_vstore 24 /* CFF2 Top */ #define OpCode_vstore 24 /* CFF2 Top */
#define OpCode_reserved25 25 #define OpCode_reserved25 25
#define OpCode_reserved26 26 #define OpCode_reserved26 26
#define OpCode_reserved27 27 #define OpCode_reserved27 27
/* Numbers */ /* Numbers */
#define OpCode_shortint 28 /* 16-bit integer, All */ #define OpCode_shortint 28 /* 16-bit integer, All */
#define OpCode_longintdict 29 /* 32-bit integer, All */ #define OpCode_longintdict 29 /* 32-bit integer, All */
#define OpCode_BCD 30 /* real number, CFF2 Top/FD */ #define OpCode_BCD 30 /* Real number, CFF2 Top/FD */
#define OpCode_reserved31 31 #define OpCode_reserved31 31
/* 1-byte integers */ /* 1-byte integers */
#define OpCode_OneByteIntFirst 32 /* All. beginning of the range of first byte ints */ #define OpCode_OneByteIntFirst 32 /* All. beginning of the range of first byte ints */
#define OpCode_OneByteIntLast 246 /* All. ending of the range of first byte int */ #define OpCode_OneByteIntLast 246 /* All. ending of the range of first byte int */
/* 2-byte integers */ /* 2-byte integers */
#define OpCode_TwoBytePosInt0 247 /* All. first byte of two byte positive int (+108 to +1131) */ #define OpCode_TwoBytePosInt0 247 /* All. first byte of two byte positive int (+108 to +1131) */
#define OpCode_TwoBytePosInt1 248 #define OpCode_TwoBytePosInt1 248
#define OpCode_TwoBytePosInt2 249 #define OpCode_TwoBytePosInt2 249
#define OpCode_TwoBytePosInt3 250 #define OpCode_TwoBytePosInt3 250
#define OpCode_TwoByteNegInt0 251 /* All. first byte of two byte negative int (-1131 to -108) */ #define OpCode_TwoByteNegInt0 251 /* All. first byte of two byte negative int (-1131 to -108) */
#define OpCode_TwoByteNegInt1 252 #define OpCode_TwoByteNegInt1 252
#define OpCode_TwoByteNegInt2 253 #define OpCode_TwoByteNegInt2 253
#define OpCode_TwoByteNegInt3 254 #define OpCode_TwoByteNegInt3 254
/* Two byte escape operators 12, (0-41) */ /* Two byte escape operators 12, (0-41) */
#define OpCode_ESC_Base 256 #define OpCode_ESC_Base 256
#define Make_OpCode_ESC(byte2) ((OpCode)(OpCode_ESC_Base + (byte2))) #define Make_OpCode_ESC(byte2) ((OpCode)(OpCode_ESC_Base + (byte2)))
inline OpCode Unmake_OpCode_ESC (OpCode op) { return (OpCode)(op - OpCode_ESC_Base); } inline OpCode Unmake_OpCode_ESC (OpCode op) { return (OpCode)(op - OpCode_ESC_Base); }
inline bool Is_OpCode_ESC (OpCode op) { return op >= OpCode_ESC_Base; } inline bool Is_OpCode_ESC (OpCode op) { return op >= OpCode_ESC_Base; }
inline unsigned int OpCode_Size (OpCode op) { return Is_OpCode_ESC (op)? 2: 1; } inline unsigned int OpCode_Size (OpCode op) { return Is_OpCode_ESC (op) ? 2: 1; }
#define OpCode_Copyright Make_OpCode_ESC(0) /* CFF Top */ #define OpCode_Copyright Make_OpCode_ESC(0) /* CFF Top */
#define OpCode_isFixedPitch Make_OpCode_ESC(1) /* CFF Top (false) */ #define OpCode_isFixedPitch Make_OpCode_ESC(1) /* CFF Top (false) */
#define OpCode_ItalicAngle Make_OpCode_ESC(2) /* CFF Top (0) */ #define OpCode_ItalicAngle Make_OpCode_ESC(2) /* CFF Top (0) */
#define OpCode_UnderlinePosition Make_OpCode_ESC(3) /* CFF Top (-100) */ #define OpCode_UnderlinePosition Make_OpCode_ESC(3) /* CFF Top (-100) */
#define OpCode_UnderlineThickness Make_OpCode_ESC(4) /* CFF Top (50) */ #define OpCode_UnderlineThickness Make_OpCode_ESC(4) /* CFF Top (50) */
#define OpCode_PaintType Make_OpCode_ESC(5) /* CFF Top (0) */ #define OpCode_PaintType Make_OpCode_ESC(5) /* CFF Top (0) */
#define OpCode_CharstringType Make_OpCode_ESC(6) /* CFF Top (2) */ #define OpCode_CharstringType Make_OpCode_ESC(6) /* CFF Top (2) */
#define OpCode_FontMatrix Make_OpCode_ESC(7) /* CFF Top, CFF2 Top (.001 0 0 .001 0 0)*/ #define OpCode_FontMatrix Make_OpCode_ESC(7) /* CFF Top, CFF2 Top (.001 0 0 .001 0 0)*/
#define OpCode_StrokeWidth Make_OpCode_ESC(8) /* CFF Top (0) */ #define OpCode_StrokeWidth Make_OpCode_ESC(8) /* CFF Top (0) */
#define OpCode_BlueScale Make_OpCode_ESC(9) /* CFF Private, CFF2 Private (0.039625) */ #define OpCode_BlueScale Make_OpCode_ESC(9) /* CFF Private, CFF2 Private (0.039625) */
#define OpCode_BlueShift Make_OpCode_ESC(10) /* CFF Private, CFF2 Private (7) */ #define OpCode_BlueShift Make_OpCode_ESC(10) /* CFF Private, CFF2 Private (7) */
#define OpCode_BlueFuzz Make_OpCode_ESC(11) /* CFF Private, CFF2 Private (1) */ #define OpCode_BlueFuzz Make_OpCode_ESC(11) /* CFF Private, CFF2 Private (1) */
#define OpCode_StemSnapH Make_OpCode_ESC(12) /* CFF Private, CFF2 Private */ #define OpCode_StemSnapH Make_OpCode_ESC(12) /* CFF Private, CFF2 Private */
#define OpCode_StemSnapV Make_OpCode_ESC(13) /* CFF Private, CFF2 Private */ #define OpCode_StemSnapV Make_OpCode_ESC(13) /* CFF Private, CFF2 Private */
#define OpCode_ForceBold Make_OpCode_ESC(14) /* CFF Private (false) */ #define OpCode_ForceBold Make_OpCode_ESC(14) /* CFF Private (false) */
#define OpCode_reservedESC15 Make_OpCode_ESC(15) #define OpCode_reservedESC15 Make_OpCode_ESC(15)
#define OpCode_reservedESC16 Make_OpCode_ESC(16) #define OpCode_reservedESC16 Make_OpCode_ESC(16)
#define OpCode_LanguageGroup Make_OpCode_ESC(17) /* CFF Private, CFF2 Private (0) */ #define OpCode_LanguageGroup Make_OpCode_ESC(17) /* CFF Private, CFF2 Private (0) */
#define OpCode_ExpansionFactor Make_OpCode_ESC(18) /* CFF Private, CFF2 Private (0.06) */ #define OpCode_ExpansionFactor Make_OpCode_ESC(18) /* CFF Private, CFF2 Private (0.06) */
#define OpCode_initialRandomSeed Make_OpCode_ESC(19) /* CFF Private (0) */ #define OpCode_initialRandomSeed Make_OpCode_ESC(19) /* CFF Private (0) */
#define OpCode_SyntheticBase Make_OpCode_ESC(20) /* CFF Top */ #define OpCode_SyntheticBase Make_OpCode_ESC(20) /* CFF Top */
#define OpCode_PostScript Make_OpCode_ESC(21) /* CFF Top */ #define OpCode_PostScript Make_OpCode_ESC(21) /* CFF Top */
#define OpCode_BaseFontName Make_OpCode_ESC(22) /* CFF Top */ #define OpCode_BaseFontName Make_OpCode_ESC(22) /* CFF Top */
#define OpCode_BaseFontBlend Make_OpCode_ESC(23) /* CFF Top */ #define OpCode_BaseFontBlend Make_OpCode_ESC(23) /* CFF Top */
#define OpCode_reservedESC24 Make_OpCode_ESC(24) #define OpCode_reservedESC24 Make_OpCode_ESC(24)
#define OpCode_reservedESC25 Make_OpCode_ESC(25) #define OpCode_reservedESC25 Make_OpCode_ESC(25)
#define OpCode_reservedESC26 Make_OpCode_ESC(26) #define OpCode_reservedESC26 Make_OpCode_ESC(26)
#define OpCode_reservedESC27 Make_OpCode_ESC(27) #define OpCode_reservedESC27 Make_OpCode_ESC(27)
#define OpCode_reservedESC28 Make_OpCode_ESC(28) #define OpCode_reservedESC28 Make_OpCode_ESC(28)
#define OpCode_reservedESC29 Make_OpCode_ESC(29) #define OpCode_reservedESC29 Make_OpCode_ESC(29)
#define OpCode_ROS Make_OpCode_ESC(30) /* CFF Top_CID */ #define OpCode_ROS Make_OpCode_ESC(30) /* CFF Top_CID */
#define OpCode_CIDFontVersion Make_OpCode_ESC(31) /* CFF Top_CID (0) */ #define OpCode_CIDFontVersion Make_OpCode_ESC(31) /* CFF Top_CID (0) */
#define OpCode_CIDFontRevision Make_OpCode_ESC(32) /* CFF Top_CID (0) */ #define OpCode_CIDFontRevision Make_OpCode_ESC(32) /* CFF Top_CID (0) */
#define OpCode_CIDFontType Make_OpCode_ESC(33) /* CFF Top_CID (0) */ #define OpCode_CIDFontType Make_OpCode_ESC(33) /* CFF Top_CID (0) */
#define OpCode_CIDCount Make_OpCode_ESC(34) /* CFF Top_CID (8720) */ #define OpCode_CIDCount Make_OpCode_ESC(34) /* CFF Top_CID (8720) */
#define OpCode_UIDBase Make_OpCode_ESC(35) /* CFF Top_CID */ #define OpCode_UIDBase Make_OpCode_ESC(35) /* CFF Top_CID */
#define OpCode_FDArray Make_OpCode_ESC(36) /* CFF Top_CID, CFF2 Top */ #define OpCode_FDArray Make_OpCode_ESC(36) /* CFF Top_CID, CFF2 Top */
#define OpCode_FDSelect Make_OpCode_ESC(37) /* CFF Top_CID, CFF2 Top */ #define OpCode_FDSelect Make_OpCode_ESC(37) /* CFF Top_CID, CFF2 Top */
#define OpCode_FontName Make_OpCode_ESC(38) /* CFF Top_CID */ #define OpCode_FontName Make_OpCode_ESC(38) /* CFF Top_CID */
/* === CharString operators === */
#define OpCode_hstem 1 /* CFF, CFF2 */ /* === CharString operators === */
#define OpCode_Reserved2 2
#define OpCode_vstem 3 /* CFF, CFF2 */
#define OpCode_vmoveto 4 /* CFF, CFF2 */
#define OpCode_rlineto 5 /* CFF, CFF2 */
#define OpCode_hlineto 6 /* CFF, CFF2 */
#define OpCode_vlineto 7 /* CFF, CFF2 */
#define OpCode_rrcurveto 8 /* CFF, CFF2 */
#define OpCode_Reserved9 9
#define OpCode_callsubr 10 /* CFF, CFF2 */
#define OpCode_return 11 /* CFF */
// #define OpCode_escape 12 /* CFF, CFF2 */
#define OpCode_Reserved13 13
#define OpCode_endchar 14 /* CFF */
#define OpCode_vsindexcs 15 /* CFF2 */
#define OpCode_blendcs 16 /* CFF2 */
#define OpCode_Reserved17 17
#define OpCode_hstemhm 18 /* CFF, CFF2 */
#define OpCode_hintmask 19 /* CFF, CFF2 */
#define OpCode_cntrmask 20 /* CFF, CFF2 */
#define OpCode_rmoveto 21 /* CFF, CFF2 */
#define OpCode_hmoveto 22 /* CFF, CFF2 */
#define OpCode_vstemhm 23 /* CFF, CFF2 */
#define OpCode_rcurveline 24 /* CFF, CFF2 */
#define OpCode_rlinecurve 25 /* CFF, CFF2 */
#define OpCode_vvcurveto 26 /* CFF, CFF2 */
#define OpCode_hhcurveto 27 /* CFF, CFF2 */
// #define OpCode_shortint 28 /* CFF, CFF2 */
#define OpCode_callgsubr 29 /* CFF, CFF2 */
#define OpCode_vhcurveto 30 /* CFF, CFF2 */
#define OpCode_hvcurveto 31 /* CFF, CFF2 */
#define OpCode_fixedcs 255 /* 32-bit fixed */ #define OpCode_hstem 1 /* CFF, CFF2 */
#define OpCode_Reserved2 2
#define OpCode_vstem 3 /* CFF, CFF2 */
#define OpCode_vmoveto 4 /* CFF, CFF2 */
#define OpCode_rlineto 5 /* CFF, CFF2 */
#define OpCode_hlineto 6 /* CFF, CFF2 */
#define OpCode_vlineto 7 /* CFF, CFF2 */
#define OpCode_rrcurveto 8 /* CFF, CFF2 */
#define OpCode_Reserved9 9
#define OpCode_callsubr 10 /* CFF, CFF2 */
#define OpCode_return 11 /* CFF */
//#define OpCode_escape 12 /* CFF, CFF2 */
#define OpCode_Reserved13 13
#define OpCode_endchar 14 /* CFF */
#define OpCode_vsindexcs 15 /* CFF2 */
#define OpCode_blendcs 16 /* CFF2 */
#define OpCode_Reserved17 17
#define OpCode_hstemhm 18 /* CFF, CFF2 */
#define OpCode_hintmask 19 /* CFF, CFF2 */
#define OpCode_cntrmask 20 /* CFF, CFF2 */
#define OpCode_rmoveto 21 /* CFF, CFF2 */
#define OpCode_hmoveto 22 /* CFF, CFF2 */
#define OpCode_vstemhm 23 /* CFF, CFF2 */
#define OpCode_rcurveline 24 /* CFF, CFF2 */
#define OpCode_rlinecurve 25 /* CFF, CFF2 */
#define OpCode_vvcurveto 26 /* CFF, CFF2 */
#define OpCode_hhcurveto 27 /* CFF, CFF2 */
//#define OpCode_shortint 28 /* CFF, CFF2 */
#define OpCode_callgsubr 29 /* CFF, CFF2 */
#define OpCode_vhcurveto 30 /* CFF, CFF2 */
#define OpCode_hvcurveto 31 /* CFF, CFF2 */
#define OpCode_fixedcs 255 /* 32-bit fixed */
/* Two byte escape operators 12, (0-41) */ /* Two byte escape operators 12, (0-41) */
#define OpCode_dotsection Make_OpCode_ESC(0) /* CFF (obsoleted) */ #define OpCode_dotsection Make_OpCode_ESC(0) /* CFF (obsoleted) */
#define OpCode_ReservedESC1 Make_OpCode_ESC(1) #define OpCode_ReservedESC1 Make_OpCode_ESC(1)
#define OpCode_ReservedESC2 Make_OpCode_ESC(2) #define OpCode_ReservedESC2 Make_OpCode_ESC(2)
#define OpCode_and Make_OpCode_ESC(3) /* CFF */ #define OpCode_and Make_OpCode_ESC(3) /* CFF */
#define OpCode_or Make_OpCode_ESC(4) /* CFF */ #define OpCode_or Make_OpCode_ESC(4) /* CFF */
#define OpCode_not Make_OpCode_ESC(5) /* CFF */ #define OpCode_not Make_OpCode_ESC(5) /* CFF */
#define OpCode_ReservedESC6 Make_OpCode_ESC(6) #define OpCode_ReservedESC6 Make_OpCode_ESC(6)
#define OpCode_ReservedESC7 Make_OpCode_ESC(7) #define OpCode_ReservedESC7 Make_OpCode_ESC(7)
#define OpCode_ReservedESC8 Make_OpCode_ESC(8) #define OpCode_ReservedESC8 Make_OpCode_ESC(8)
#define OpCode_abs Make_OpCode_ESC(9) /* CFF */ #define OpCode_abs Make_OpCode_ESC(9) /* CFF */
#define OpCode_add Make_OpCode_ESC(10) /* CFF */ #define OpCode_add Make_OpCode_ESC(10) /* CFF */
#define OpCode_sub Make_OpCode_ESC(11) /* CFF */ #define OpCode_sub Make_OpCode_ESC(11) /* CFF */
#define OpCode_div Make_OpCode_ESC(12) /* CFF */ #define OpCode_div Make_OpCode_ESC(12) /* CFF */
#define OpCode_ReservedESC13 Make_OpCode_ESC(13) #define OpCode_ReservedESC13 Make_OpCode_ESC(13)
#define OpCode_neg Make_OpCode_ESC(14) /* CFF */ #define OpCode_neg Make_OpCode_ESC(14) /* CFF */
#define OpCode_eq Make_OpCode_ESC(15) /* CFF */ #define OpCode_eq Make_OpCode_ESC(15) /* CFF */
#define OpCode_ReservedESC16 Make_OpCode_ESC(16) #define OpCode_ReservedESC16 Make_OpCode_ESC(16)
#define OpCode_ReservedESC17 Make_OpCode_ESC(17) #define OpCode_ReservedESC17 Make_OpCode_ESC(17)
#define OpCode_drop Make_OpCode_ESC(18) /* CFF */ #define OpCode_drop Make_OpCode_ESC(18) /* CFF */
#define OpCode_ReservedESC19 Make_OpCode_ESC(19) #define OpCode_ReservedESC19 Make_OpCode_ESC(19)
#define OpCode_put Make_OpCode_ESC(20) /* CFF */ #define OpCode_put Make_OpCode_ESC(20) /* CFF */
#define OpCode_get Make_OpCode_ESC(21) /* CFF */ #define OpCode_get Make_OpCode_ESC(21) /* CFF */
#define OpCode_ifelse Make_OpCode_ESC(22) /* CFF */ #define OpCode_ifelse Make_OpCode_ESC(22) /* CFF */
#define OpCode_random Make_OpCode_ESC(23) /* CFF */ #define OpCode_random Make_OpCode_ESC(23) /* CFF */
#define OpCode_mul Make_OpCode_ESC(24) /* CFF */ #define OpCode_mul Make_OpCode_ESC(24) /* CFF */
// #define OpCode_reservedESC25 Make_OpCode_ESC(25) //#define OpCode_reservedESC25 Make_OpCode_ESC(25)
#define OpCode_sqrt Make_OpCode_ESC(26) /* CFF */ #define OpCode_sqrt Make_OpCode_ESC(26) /* CFF */
#define OpCode_dup Make_OpCode_ESC(27) /* CFF */ #define OpCode_dup Make_OpCode_ESC(27) /* CFF */
#define OpCode_exch Make_OpCode_ESC(28) /* CFF */ #define OpCode_exch Make_OpCode_ESC(28) /* CFF */
#define OpCode_index Make_OpCode_ESC(29) /* CFF */ #define OpCode_index Make_OpCode_ESC(29) /* CFF */
#define OpCode_roll Make_OpCode_ESC(30) /* CFF */ #define OpCode_roll Make_OpCode_ESC(30) /* CFF */
#define OpCode_reservedESC31 Make_OpCode_ESC(31) #define OpCode_reservedESC31 Make_OpCode_ESC(31)
#define OpCode_reservedESC32 Make_OpCode_ESC(32) #define OpCode_reservedESC32 Make_OpCode_ESC(32)
#define OpCode_reservedESC33 Make_OpCode_ESC(33) #define OpCode_reservedESC33 Make_OpCode_ESC(33)
#define OpCode_hflex Make_OpCode_ESC(34) /* CFF, CFF2 */ #define OpCode_hflex Make_OpCode_ESC(34) /* CFF, CFF2 */
#define OpCode_flex Make_OpCode_ESC(35) /* CFF, CFF2 */ #define OpCode_flex Make_OpCode_ESC(35) /* CFF, CFF2 */
#define OpCode_hflex1 Make_OpCode_ESC(36) /* CFF, CFF2 */ #define OpCode_hflex1 Make_OpCode_ESC(36) /* CFF, CFF2 */
#define OpCode_flex1 Make_OpCode_ESC(37) /* CFF, CFF2 */ #define OpCode_flex1 Make_OpCode_ESC(37) /* CFF, CFF2 */
#define OpCode_Invalid 0xFFFFu
#define OpCode_Invalid 65535
struct Number struct Number
{ {
@ -217,8 +222,8 @@ struct Number
inline void fini (void) inline void fini (void)
{} {}
inline void set_int (int v) { format = NumInt; u.int_val = v; } inline void set_int (int v) { format = NumInt; u.int_val = v; }
inline int to_int (void) const { return is_int ()? u.int_val: (int)to_real (); } inline int to_int (void) const { return is_int ()? u.int_val: (int)to_real (); }
inline void set_fixed (int32_t v) { format = NumFixed; u.fixed_val = v; } inline void set_fixed (int32_t v) { format = NumFixed; u.fixed_val = v; }
inline int32_t to_fixed (void) const inline int32_t to_fixed (void) const
{ {
@ -229,7 +234,7 @@ struct Number
else else
return (int32_t)(u.int_val << 16); return (int32_t)(u.int_val << 16);
} }
inline void set_real (float v) { format = NumReal; u.real_val = v; } inline void set_real (float v) { format = NumReal; u.real_val = v; }
inline float to_real (void) const inline float to_real (void) const
{ {
if (is_real ()) if (is_real ())
@ -246,11 +251,11 @@ struct Number
{ {
default: default:
case NumInt: case NumInt:
return u.int_val; return u.int_val;
case NumFixed: case NumFixed:
return (u.fixed_val + 0xFFFF) >> 16; return (u.fixed_val + 0xFFFF) >> 16;
case NumReal: case NumReal:
return (int)ceilf (u.real_val); return (int)ceilf (u.real_val);
} }
} }
@ -260,11 +265,11 @@ struct Number
{ {
default: default:
case NumInt: case NumInt:
return u.int_val; return u.int_val;
case NumFixed: case NumFixed:
return u.fixed_val >> 16; return u.fixed_val >> 16;
case NumReal: case NumReal:
return (int)floorf (u.real_val); return (int)floorf (u.real_val);
} }
} }
@ -454,7 +459,7 @@ struct SubByteStr
unsigned int offset; /* beginning of the sub-string within str */ unsigned int offset; /* beginning of the sub-string within str */
protected: protected:
bool error; bool error;
}; };
typedef hb_vector_t<ByteStr> ByteStrArray; typedef hb_vector_t<ByteStr> ByteStrArray;
@ -721,7 +726,7 @@ struct InterpEnv
op = (OpCode)(unsigned char)substr[0]; op = (OpCode)(unsigned char)substr[0];
if (op == OpCode_escape) { if (op == OpCode_escape) {
if (unlikely (!substr.avail ())) if (unlikely (!substr.avail ()))
return OpCode_Invalid; return OpCode_Invalid;
op = Make_OpCode_ESC(substr[1]); op = Make_OpCode_ESC(substr[1]);
substr.inc (); substr.inc ();
} }
@ -753,7 +758,7 @@ struct InterpEnv
SubByteStr substr; SubByteStr substr;
ArgStack<ARG> argStack; ArgStack<ARG> argStack;
protected: protected:
bool error; bool error;
}; };
typedef InterpEnv<> NumInterpEnv; typedef InterpEnv<> NumInterpEnv;
@ -765,33 +770,33 @@ struct OpSet
{ {
switch (op) { switch (op) {
case OpCode_shortint: case OpCode_shortint:
env.argStack.push_int ((int16_t)((env.substr[0] << 8) | env.substr[1])); env.argStack.push_int ((int16_t)((env.substr[0] << 8) | env.substr[1]));
env.substr.inc (2); env.substr.inc (2);
break; break;
case OpCode_TwoBytePosInt0: case OpCode_TwoBytePosInt1: case OpCode_TwoBytePosInt0: case OpCode_TwoBytePosInt1:
case OpCode_TwoBytePosInt2: case OpCode_TwoBytePosInt3: case OpCode_TwoBytePosInt2: case OpCode_TwoBytePosInt3:
env.argStack.push_int ((int16_t)((op - OpCode_TwoBytePosInt0) * 256 + env.substr[0] + 108)); env.argStack.push_int ((int16_t)((op - OpCode_TwoBytePosInt0) * 256 + env.substr[0] + 108));
env.substr.inc (); env.substr.inc ();
break; break;
case OpCode_TwoByteNegInt0: case OpCode_TwoByteNegInt1: case OpCode_TwoByteNegInt0: case OpCode_TwoByteNegInt1:
case OpCode_TwoByteNegInt2: case OpCode_TwoByteNegInt3: case OpCode_TwoByteNegInt2: case OpCode_TwoByteNegInt3:
env.argStack.push_int ((int16_t)(-(op - OpCode_TwoByteNegInt0) * 256 - env.substr[0] - 108)); env.argStack.push_int ((int16_t)(-(op - OpCode_TwoByteNegInt0) * 256 - env.substr[0] - 108));
env.substr.inc (); env.substr.inc ();
break; break;
default: default:
/* 1-byte integer */ /* 1-byte integer */
if (likely ((OpCode_OneByteIntFirst <= op) && (op <= OpCode_OneByteIntLast))) if (likely ((OpCode_OneByteIntFirst <= op) && (op <= OpCode_OneByteIntLast)))
{ {
env.argStack.push_int ((int)op - 139); env.argStack.push_int ((int)op - 139);
} else { } else {
/* invalid unknown operator */ /* invalid unknown operator */
env.clear_args (); env.clear_args ();
env.set_error (); env.set_error ();
} }
break; break;
} }
} }
}; };

View File

@ -51,7 +51,7 @@ struct CallContext
inline void fini (void) {} inline void fini (void) {}
SubByteStr substr; SubByteStr substr;
CSType type; CSType type;
unsigned int subr_num; unsigned int subr_num;
}; };
@ -150,7 +150,7 @@ struct CSInterpEnv : InterpEnv<ARG>
unsigned int subr_num; unsigned int subr_num;
if (unlikely (!popSubrNum (biasedSubrs, subr_num) if (unlikely (!popSubrNum (biasedSubrs, subr_num)
|| callStack.get_count () >= kMaxCallLimit)) || callStack.get_count () >= kMaxCallLimit))
{ {
SUPER::set_error (); SUPER::set_error ();
return; return;
@ -191,19 +191,19 @@ struct CSInterpEnv : InterpEnv<ARG>
public: public:
CallContext context; CallContext context;
bool endchar_flag; bool endchar_flag;
bool seen_moveto; bool seen_moveto;
bool seen_hintmask; bool seen_hintmask;
unsigned int hstem_count; unsigned int hstem_count;
unsigned int vstem_count; unsigned int vstem_count;
unsigned int hintmask_size; unsigned int hintmask_size;
CallStack callStack; CallStack callStack;
BiasedSubrs<SUBRS> globalSubrs; BiasedSubrs<SUBRS> globalSubrs;
BiasedSubrs<SUBRS> localSubrs; BiasedSubrs<SUBRS> localSubrs;
private: private:
Point pt; Point pt;
typedef InterpEnv<ARG> SUPER; typedef InterpEnv<ARG> SUPER;
}; };
@ -241,120 +241,120 @@ struct CSOpSet : OpSet<ARG>
switch (op) { switch (op) {
case OpCode_return: case OpCode_return:
env.returnFromSubr (); env.returnFromSubr ();
break; break;
case OpCode_endchar: case OpCode_endchar:
OPSET::check_width (op, env, param); OPSET::check_width (op, env, param);
env.set_endchar (true); env.set_endchar (true);
OPSET::flush_args_and_op (op, env, param); OPSET::flush_args_and_op (op, env, param);
break; break;
case OpCode_fixedcs: case OpCode_fixedcs:
env.argStack.push_fixed_from_substr (env.substr); env.argStack.push_fixed_from_substr (env.substr);
break; break;
case OpCode_callsubr: case OpCode_callsubr:
env.callSubr (env.localSubrs, CSType_LocalSubr); env.callSubr (env.localSubrs, CSType_LocalSubr);
break; break;
case OpCode_callgsubr: case OpCode_callgsubr:
env.callSubr (env.globalSubrs, CSType_GlobalSubr); env.callSubr (env.globalSubrs, CSType_GlobalSubr);
break; break;
case OpCode_hstem: case OpCode_hstem:
case OpCode_hstemhm: case OpCode_hstemhm:
OPSET::check_width (op, env, param); OPSET::check_width (op, env, param);
OPSET::process_hstem (op, env, param); OPSET::process_hstem (op, env, param);
break; break;
case OpCode_vstem: case OpCode_vstem:
case OpCode_vstemhm: case OpCode_vstemhm:
OPSET::check_width (op, env, param); OPSET::check_width (op, env, param);
OPSET::process_vstem (op, env, param); OPSET::process_vstem (op, env, param);
break; break;
case OpCode_hintmask: case OpCode_hintmask:
case OpCode_cntrmask: case OpCode_cntrmask:
OPSET::check_width (op, env, param); OPSET::check_width (op, env, param);
OPSET::process_hintmask (op, env, param); OPSET::process_hintmask (op, env, param);
break; break;
case OpCode_rmoveto: case OpCode_rmoveto:
OPSET::check_width (op, env, param); OPSET::check_width (op, env, param);
PATH::rmoveto (env, param); PATH::rmoveto (env, param);
OPSET::process_post_move (op, env, param); OPSET::process_post_move (op, env, param);
break; break;
case OpCode_hmoveto: case OpCode_hmoveto:
OPSET::check_width (op, env, param); OPSET::check_width (op, env, param);
PATH::hmoveto (env, param); PATH::hmoveto (env, param);
OPSET::process_post_move (op, env, param); OPSET::process_post_move (op, env, param);
break; break;
case OpCode_vmoveto: case OpCode_vmoveto:
OPSET::check_width (op, env, param); OPSET::check_width (op, env, param);
PATH::vmoveto (env, param); PATH::vmoveto (env, param);
OPSET::process_post_move (op, env, param); OPSET::process_post_move (op, env, param);
break; break;
case OpCode_rlineto: case OpCode_rlineto:
PATH::rlineto (env, param); PATH::rlineto (env, param);
process_post_path (op, env, param); process_post_path (op, env, param);
break; break;
case OpCode_hlineto: case OpCode_hlineto:
PATH::hlineto (env, param); PATH::hlineto (env, param);
process_post_path (op, env, param); process_post_path (op, env, param);
break; break;
case OpCode_vlineto: case OpCode_vlineto:
PATH::vlineto (env, param); PATH::vlineto (env, param);
process_post_path (op, env, param); process_post_path (op, env, param);
break; break;
case OpCode_rrcurveto: case OpCode_rrcurveto:
PATH::rrcurveto (env, param); PATH::rrcurveto (env, param);
process_post_path (op, env, param); process_post_path (op, env, param);
break; break;
case OpCode_rcurveline: case OpCode_rcurveline:
PATH::rcurveline (env, param); PATH::rcurveline (env, param);
process_post_path (op, env, param); process_post_path (op, env, param);
break; break;
case OpCode_rlinecurve: case OpCode_rlinecurve:
PATH::rlinecurve (env, param); PATH::rlinecurve (env, param);
process_post_path (op, env, param); process_post_path (op, env, param);
break; break;
case OpCode_vvcurveto: case OpCode_vvcurveto:
PATH::vvcurveto (env, param); PATH::vvcurveto (env, param);
process_post_path (op, env, param); process_post_path (op, env, param);
break; break;
case OpCode_hhcurveto: case OpCode_hhcurveto:
PATH::hhcurveto (env, param); PATH::hhcurveto (env, param);
process_post_path (op, env, param); process_post_path (op, env, param);
break; break;
case OpCode_vhcurveto: case OpCode_vhcurveto:
PATH::vhcurveto (env, param); PATH::vhcurveto (env, param);
process_post_path (op, env, param); process_post_path (op, env, param);
break; break;
case OpCode_hvcurveto: case OpCode_hvcurveto:
PATH::hvcurveto (env, param); PATH::hvcurveto (env, param);
process_post_path (op, env, param); process_post_path (op, env, param);
break; break;
case OpCode_hflex: case OpCode_hflex:
PATH::hflex (env, param); PATH::hflex (env, param);
OPSET::process_post_flex (op, env, param); OPSET::process_post_flex (op, env, param);
break; break;
case OpCode_flex: case OpCode_flex:
PATH::flex (env, param); PATH::flex (env, param);
OPSET::process_post_flex (op, env, param); OPSET::process_post_flex (op, env, param);
break; break;
case OpCode_hflex1: case OpCode_hflex1:
PATH::hflex1 (env, param); PATH::hflex1 (env, param);
OPSET::process_post_flex (op, env, param); OPSET::process_post_flex (op, env, param);
break; break;
case OpCode_flex1: case OpCode_flex1:
PATH::flex1 (env, param); PATH::flex1 (env, param);
OPSET::process_post_flex (op, env, param); OPSET::process_post_flex (op, env, param);
break; break;
default: default:
SUPER::process_op (op, env); SUPER::process_op (op, env);
break; break;
} }
} }
@ -433,11 +433,11 @@ struct CSOpSet : OpSet<ARG>
case OpCode_TwoBytePosInt2: case OpCode_TwoBytePosInt3: case OpCode_TwoBytePosInt2: case OpCode_TwoBytePosInt3:
case OpCode_TwoByteNegInt0: case OpCode_TwoByteNegInt1: case OpCode_TwoByteNegInt0: case OpCode_TwoByteNegInt1:
case OpCode_TwoByteNegInt2: case OpCode_TwoByteNegInt3: case OpCode_TwoByteNegInt2: case OpCode_TwoByteNegInt3:
return true; return true;
default: default:
/* 1-byte integer */ /* 1-byte integer */
return (OpCode_OneByteIntFirst <= op) && (op <= OpCode_OneByteIntLast); return (OpCode_OneByteIntFirst <= op) && (op <= OpCode_OneByteIntLast);
} }
} }
@ -630,47 +630,47 @@ struct PathProcs
for (; i + 8 <= env.argStack.get_count (); i += 8) for (; i + 8 <= env.argStack.get_count (); i += 8)
{ {
PATH::curve (env, param, pt1, pt2, pt3); PATH::curve (env, param, pt1, pt2, pt3);
pt1 = env.get_pt (); pt1 = env.get_pt ();
pt1.move_x (env.eval_arg (i)); pt1.move_x (env.eval_arg (i));
pt2 = pt1; pt2 = pt1;
pt2.move (env.eval_arg (i+1), env.eval_arg (i+2)); pt2.move (env.eval_arg (i+1), env.eval_arg (i+2));
pt3 = pt2; pt3 = pt2;
pt3.move_y (env.eval_arg (i+3)); pt3.move_y (env.eval_arg (i+3));
PATH::curve (env, param, pt1, pt2, pt3); PATH::curve (env, param, pt1, pt2, pt3);
pt1 = pt3; pt1 = pt3;
pt1.move_y (env.eval_arg (i+4)); pt1.move_y (env.eval_arg (i+4));
pt2 = pt1; pt2 = pt1;
pt2.move (env.eval_arg (i+5), env.eval_arg (i+6)); pt2.move (env.eval_arg (i+5), env.eval_arg (i+6));
pt3 = pt2; pt3 = pt2;
pt3.move_x (env.eval_arg (i+7)); pt3.move_x (env.eval_arg (i+7));
} }
if (i < env.argStack.get_count ()) if (i < env.argStack.get_count ())
pt3.move_y (env.eval_arg (i)); pt3.move_y (env.eval_arg (i));
PATH::curve (env, param, pt1, pt2, pt3); PATH::curve (env, param, pt1, pt2, pt3);
} }
else else
{ {
for (; i + 8 <= env.argStack.get_count (); i += 8) for (; i + 8 <= env.argStack.get_count (); i += 8)
{ {
pt1 = env.get_pt (); pt1 = env.get_pt ();
pt1.move_y (env.eval_arg (i)); pt1.move_y (env.eval_arg (i));
pt2 = pt1; pt2 = pt1;
pt2.move (env.eval_arg (i+1), env.eval_arg (i+2)); pt2.move (env.eval_arg (i+1), env.eval_arg (i+2));
pt3 = pt2; pt3 = pt2;
pt3.move_x (env.eval_arg (i+3)); pt3.move_x (env.eval_arg (i+3));
PATH::curve (env, param, pt1, pt2, pt3); PATH::curve (env, param, pt1, pt2, pt3);
pt1 = pt3; pt1 = pt3;
pt1.move_x (env.eval_arg (i+4)); pt1.move_x (env.eval_arg (i+4));
pt2 = pt1; pt2 = pt1;
pt2.move (env.eval_arg (i+5), env.eval_arg (i+6)); pt2.move (env.eval_arg (i+5), env.eval_arg (i+6));
pt3 = pt2; pt3 = pt2;
pt3.move_y (env.eval_arg (i+7)); pt3.move_y (env.eval_arg (i+7));
if ((env.argStack.get_count () - i < 16) && ((env.argStack.get_count () & 1) != 0)) if ((env.argStack.get_count () - i < 16) && ((env.argStack.get_count () & 1) != 0))
pt3.move_x (env.eval_arg (i+8)); pt3.move_x (env.eval_arg (i+8));
PATH::curve (env, param, pt1, pt2, pt3); PATH::curve (env, param, pt1, pt2, pt3);
} }
} }
} }
@ -691,47 +691,47 @@ struct PathProcs
for (; i + 8 <= env.argStack.get_count (); i += 8) for (; i + 8 <= env.argStack.get_count (); i += 8)
{ {
PATH::curve (env, param, pt1, pt2, pt3); PATH::curve (env, param, pt1, pt2, pt3);
pt1 = env.get_pt (); pt1 = env.get_pt ();
pt1.move_y (env.eval_arg (i)); pt1.move_y (env.eval_arg (i));
pt2 = pt1; pt2 = pt1;
pt2.move (env.eval_arg (i+1), env.eval_arg (i+2)); pt2.move (env.eval_arg (i+1), env.eval_arg (i+2));
pt3 = pt2; pt3 = pt2;
pt3.move_x (env.eval_arg (i+3)); pt3.move_x (env.eval_arg (i+3));
PATH::curve (env, param, pt1, pt2, pt3); PATH::curve (env, param, pt1, pt2, pt3);
pt1 = pt3; pt1 = pt3;
pt1.move_x (env.eval_arg (i+4)); pt1.move_x (env.eval_arg (i+4));
pt2 = pt1; pt2 = pt1;
pt2.move (env.eval_arg (i+5), env.eval_arg (i+6)); pt2.move (env.eval_arg (i+5), env.eval_arg (i+6));
pt3 = pt2; pt3 = pt2;
pt3.move_y (env.eval_arg (i+7)); pt3.move_y (env.eval_arg (i+7));
} }
if (i < env.argStack.get_count ()) if (i < env.argStack.get_count ())
pt3.move_x (env.eval_arg (i)); pt3.move_x (env.eval_arg (i));
PATH::curve (env, param, pt1, pt2, pt3); PATH::curve (env, param, pt1, pt2, pt3);
} }
else else
{ {
for (; i + 8 <= env.argStack.get_count (); i += 8) for (; i + 8 <= env.argStack.get_count (); i += 8)
{ {
pt1 = env.get_pt (); pt1 = env.get_pt ();
pt1.move_x (env.eval_arg (i)); pt1.move_x (env.eval_arg (i));
pt2 = pt1; pt2 = pt1;
pt2.move (env.eval_arg (i+1), env.eval_arg (i+2)); pt2.move (env.eval_arg (i+1), env.eval_arg (i+2));
pt3 = pt2; pt3 = pt2;
pt3.move_y (env.eval_arg (i+3)); pt3.move_y (env.eval_arg (i+3));
PATH::curve (env, param, pt1, pt2, pt3); PATH::curve (env, param, pt1, pt2, pt3);
pt1 = pt3; pt1 = pt3;
pt1.move_y (env.eval_arg (i+4)); pt1.move_y (env.eval_arg (i+4));
pt2 = pt1; pt2 = pt1;
pt2.move (env.eval_arg (i+5), env.eval_arg (i+6)); pt2.move (env.eval_arg (i+5), env.eval_arg (i+6));
pt3 = pt2; pt3 = pt2;
pt3.move_x (env.eval_arg (i+7)); pt3.move_x (env.eval_arg (i+7));
if ((env.argStack.get_count () - i < 16) && ((env.argStack.get_count () & 1) != 0)) if ((env.argStack.get_count () - i < 16) && ((env.argStack.get_count () & 1) != 0))
pt3.move_y (env.eval_arg (i+8)); pt3.move_y (env.eval_arg (i+8));
PATH::curve (env, param, pt1, pt2, pt3); PATH::curve (env, param, pt1, pt2, pt3);
} }
} }
} }
@ -824,7 +824,7 @@ struct PathProcs
Point d; Point d;
d.init (); d.init ();
for (unsigned int i = 0; i < 10; i += 2) for (unsigned int i = 0; i < 10; i += 2)
d.move (env.eval_arg (i), env.eval_arg (i+1)); d.move (env.eval_arg (i), env.eval_arg (i+1));
Point pt1 = env.get_pt (); Point pt1 = env.get_pt ();
pt1.move (env.eval_arg (0), env.eval_arg (1)); pt1.move (env.eval_arg (0), env.eval_arg (1));
@ -840,13 +840,13 @@ struct PathProcs
if (fabs (d.x.to_real ()) > fabs (d.y.to_real ())) if (fabs (d.x.to_real ()) > fabs (d.y.to_real ()))
{ {
pt6.move_x (env.eval_arg (10)); pt6.move_x (env.eval_arg (10));
pt6.y = env.get_pt ().y; pt6.y = env.get_pt ().y;
} }
else else
{ {
pt6.x = env.get_pt ().x; pt6.x = env.get_pt ().x;
pt6.move_y (env.eval_arg (10)); pt6.move_y (env.eval_arg (10));
} }
curve2 (env, param, pt1, pt2, pt3, pt4, pt5, pt6); curve2 (env, param, pt1, pt2, pt3, pt4, pt5, pt6);
@ -857,8 +857,8 @@ struct PathProcs
protected: protected:
static inline void curve2 (ENV &env, PARAM& param, static inline void curve2 (ENV &env, PARAM& param,
const Point &pt1, const Point &pt2, const Point &pt3, const Point &pt1, const Point &pt2, const Point &pt3,
const Point &pt4, const Point &pt5, const Point &pt6) const Point &pt4, const Point &pt5, const Point &pt6)
{ {
PATH::curve (env, param, pt1, pt2, pt3); PATH::curve (env, param, pt1, pt2, pt3);
PATH::curve (env, param, pt4, pt5, pt6); PATH::curve (env, param, pt4, pt5, pt6);
@ -875,9 +875,9 @@ struct CSInterpreter : Interpreter<ENV>
for (;;) { for (;;) {
OPSET::process_op (SUPER::env.fetch_op (), SUPER::env, param); OPSET::process_op (SUPER::env.fetch_op (), SUPER::env, param);
if (unlikely (SUPER::env.in_error ())) if (unlikely (SUPER::env.in_error ()))
return false; return false;
if (SUPER::env.is_endchar ()) if (SUPER::env.is_endchar ())
break; break;
} }
return true; return true;

View File

@ -45,7 +45,7 @@ struct DictVal : OpStr
{ {
} }
Number single_val; Number single_val;
}; };
typedef DictVal NumDictVal; typedef DictVal NumDictVal;
@ -73,10 +73,10 @@ struct TopDictValues : DictValues<OPSTR>
{ {
case OpCode_CharStrings: case OpCode_CharStrings:
case OpCode_FDArray: case OpCode_FDArray:
return OpCode_Size (OpCode_longintdict) + 4 + OpCode_Size (opstr.op); return OpCode_Size (OpCode_longintdict) + 4 + OpCode_Size (opstr.op);
default: default:
return opstr.str.len; return opstr.str.len;
} }
} }
@ -90,16 +90,16 @@ struct DictOpSet : OpSet<Number>
{ {
switch (op) { switch (op) {
case OpCode_longintdict: /* 5-byte integer */ case OpCode_longintdict: /* 5-byte integer */
env.argStack.push_longint_from_substr (env.substr); env.argStack.push_longint_from_substr (env.substr);
break; break;
case OpCode_BCD: /* real number */ case OpCode_BCD: /* real number */
env.argStack.push_real (parse_bcd (env.substr)); env.argStack.push_real (parse_bcd (env.substr));
break; break;
default: default:
OpSet<Number>::process_op (op, env); OpSet<Number>::process_op (op, env);
break; break;
} }
} }
@ -123,84 +123,84 @@ struct DictOpSet : OpSet<Number>
char d; char d;
if ((i & 1) == 0) if ((i & 1) == 0)
{ {
if (!substr.avail ()) if (!substr.avail ())
{ {
substr.set_error (); substr.set_error ();
return 0.0f; return 0.0f;
} }
byte = substr[0]; byte = substr[0];
substr.inc (); substr.inc ();
d = byte >> 4; d = byte >> 4;
} }
else else
d = byte & 0x0F; d = byte & 0x0F;
switch (d) switch (d)
{ {
case RESERVED: case RESERVED:
substr.set_error (); substr.set_error ();
return v; return v;
case END: case END:
value = (double)(neg? -int_part: int_part); value = (double)(neg? -int_part: int_part);
if (frac_count > 0) if (frac_count > 0)
value += (frac_part / pow (10.0, (double)frac_count)); value += (frac_part / pow (10.0, (double)frac_count));
if (exp_part != 0) if (exp_part != 0)
{ {
if (exp_neg) if (exp_neg)
value /= pow (10.0, (double)exp_part); value /= pow (10.0, (double)exp_part);
else else
value *= pow (10.0, (double)exp_part); value *= pow (10.0, (double)exp_part);
} }
return (float)value; return (float)value;
case NEG: case NEG:
if (i != 0) if (i != 0)
{ {
substr.set_error (); substr.set_error ();
return 0.0f; return 0.0f;
} }
neg = true; neg = true;
break; break;
case DECIMAL: case DECIMAL:
if (part != INT_PART) if (part != INT_PART)
{ {
substr.set_error (); substr.set_error ();
return v; return v;
} }
part = FRAC_PART; part = FRAC_PART;
break; break;
case EXP_NEG: case EXP_NEG:
exp_neg = true; exp_neg = true;
HB_FALLTHROUGH; HB_FALLTHROUGH;
case EXP_POS: case EXP_POS:
if (part == EXP_PART) if (part == EXP_PART)
{ {
substr.set_error (); substr.set_error ();
return v; return v;
} }
part = EXP_PART; part = EXP_PART;
break; break;
default: default:
switch (part) { switch (part) {
default: default:
case INT_PART: case INT_PART:
int_part = (int_part * 10) + d; int_part = (int_part * 10) + d;
break; break;
case FRAC_PART: case FRAC_PART:
frac_part = (frac_part * 10) + d; frac_part = (frac_part * 10) + d;
frac_count++; frac_count++;
break; break;
case EXP_PART: case EXP_PART:
exp_part = (exp_part * 10) + d; exp_part = (exp_part * 10) + d;
break; break;
} }
} }
} }
@ -225,9 +225,9 @@ struct DictOpSet : OpSet<Number>
case OpCode_ForceBold: case OpCode_ForceBold:
case OpCode_LanguageGroup: case OpCode_LanguageGroup:
case OpCode_ExpansionFactor: case OpCode_ExpansionFactor:
return true; return true;
default: default:
return false; return false;
} }
} }
}; };
@ -239,19 +239,19 @@ struct TopDictOpSet : DictOpSet
{ {
switch (op) { switch (op) {
case OpCode_CharStrings: case OpCode_CharStrings:
dictval.charStringsOffset = env.argStack.pop_uint (); dictval.charStringsOffset = env.argStack.pop_uint ();
env.clear_args (); env.clear_args ();
break; break;
case OpCode_FDArray: case OpCode_FDArray:
dictval.FDArrayOffset = env.argStack.pop_uint (); dictval.FDArrayOffset = env.argStack.pop_uint ();
env.clear_args (); env.clear_args ();
break; break;
case OpCode_FontMatrix: case OpCode_FontMatrix:
env.clear_args (); env.clear_args ();
break; break;
default: default:
DictOpSet::process_op (op, env); DictOpSet::process_op (op, env);
break; break;
} }
} }
}; };
@ -266,7 +266,7 @@ struct DictInterpreter : Interpreter<ENV>
{ {
OPSET::process_op (SUPER::env.fetch_op (), SUPER::env, param); OPSET::process_op (SUPER::env.fetch_op (), SUPER::env, param);
if (unlikely (SUPER::env.in_error ())) if (unlikely (SUPER::env.in_error ()))
return false; return false;
} }
return true; return true;

View File

@ -58,9 +58,9 @@ struct CFF1CSInterpEnv : CSInterpEnv<Number, CFF1Subrs>
{ {
if (has_width_) if (has_width_)
{ {
width = SUPER::argStack[0]; width = SUPER::argStack[0];
has_width = true; has_width = true;
arg_start = 1; arg_start = 1;
} }
} }
processed_width = true; processed_width = true;
@ -74,11 +74,11 @@ struct CFF1CSInterpEnv : CSInterpEnv<Number, CFF1Subrs>
inline void set_in_seac (bool _in_seac) { in_seac = _in_seac; } inline void set_in_seac (bool _in_seac) { in_seac = _in_seac; }
bool processed_width; bool processed_width;
bool has_width; bool has_width;
unsigned int arg_start; unsigned int arg_start;
Number width; Number width;
bool in_seac; bool in_seac;
private: private:
typedef CSInterpEnv<Number, CFF1Subrs> SUPER; typedef CSInterpEnv<Number, CFF1Subrs> SUPER;
@ -94,21 +94,21 @@ struct CFF1CSOpSet : CSOpSet<Number, OPSET, CFF1CSInterpEnv, PARAM, PATH>
{ {
switch (op) { switch (op) {
case OpCode_dotsection: case OpCode_dotsection:
SUPER::flush_args_and_op (op, env, param); SUPER::flush_args_and_op (op, env, param);
break; break;
case OpCode_endchar: case OpCode_endchar:
OPSET::check_width (op, env, param); OPSET::check_width (op, env, param);
if (env.argStack.get_count () >= 4) if (env.argStack.get_count () >= 4)
{ {
OPSET::process_seac (env, param); OPSET::process_seac (env, param);
} }
OPSET::flush_args_and_op (op, env, param); OPSET::flush_args_and_op (op, env, param);
env.set_endchar (true); env.set_endchar (true);
break; break;
default: default:
SUPER::process_op (op, env, param); SUPER::process_op (op, env, param);
} }
} }
@ -119,24 +119,24 @@ struct CFF1CSOpSet : CSOpSet<Number, OPSET, CFF1CSInterpEnv, PARAM, PATH>
bool has_width = false; bool has_width = false;
switch (op) switch (op)
{ {
case OpCode_endchar: case OpCode_endchar:
case OpCode_hstem: case OpCode_hstem:
case OpCode_hstemhm: case OpCode_hstemhm:
case OpCode_vstem: case OpCode_vstem:
case OpCode_vstemhm: case OpCode_vstemhm:
case OpCode_hintmask: case OpCode_hintmask:
case OpCode_cntrmask: case OpCode_cntrmask:
has_width = ((env.argStack.get_count () & 1) != 0); has_width = ((env.argStack.get_count () & 1) != 0);
break; break;
case OpCode_hmoveto: case OpCode_hmoveto:
case OpCode_vmoveto: case OpCode_vmoveto:
has_width = (env.argStack.get_count () > 1); has_width = (env.argStack.get_count () > 1);
break; break;
case OpCode_rmoveto: case OpCode_rmoveto:
has_width = (env.argStack.get_count () > 2); has_width = (env.argStack.get_count () > 2);
break; break;
default: default:
return; return;
} }
env.set_width (has_width); env.set_width (has_width);
} }

View File

@ -52,7 +52,7 @@ struct BlendArg : Number
inline void set_real (float v) { reset_blends (); Number::set_real (v); } inline void set_real (float v) { reset_blends (); Number::set_real (v); }
inline void set_blends (unsigned int numValues_, unsigned int valueIndex_, inline void set_blends (unsigned int numValues_, unsigned int valueIndex_,
unsigned int numBlends, const BlendArg *blends_) unsigned int numBlends, const BlendArg *blends_)
{ {
numValues = numValues_; numValues = numValues_;
valueIndex = valueIndex_; valueIndex = valueIndex_;
@ -80,7 +80,7 @@ struct CFF2CSInterpEnv : CSInterpEnv<BlendArg, CFF2Subrs>
{ {
template <typename ACC> template <typename ACC>
inline void init (const ByteStr &str, ACC &acc, unsigned int fd, inline void init (const ByteStr &str, ACC &acc, unsigned int fd,
const int *coords_=nullptr, unsigned int num_coords_=0) const int *coords_=nullptr, unsigned int num_coords_=0)
{ {
SUPER::init (str, *acc.globalSubrs, *acc.privateDicts[fd].localSubrs); SUPER::init (str, *acc.globalSubrs, *acc.privateDicts[fd].localSubrs);
@ -133,10 +133,10 @@ struct CFF2CSInterpEnv : CSInterpEnv<BlendArg, CFF2Subrs>
region_count = varStore->varStore.get_region_index_count (get_ivs ()); region_count = varStore->varStore.get_region_index_count (get_ivs ());
if (do_blend) if (do_blend)
{ {
scalars.resize (region_count); scalars.resize (region_count);
varStore->varStore.get_scalars (get_ivs (), varStore->varStore.get_scalars (get_ivs (),
(int *)coords, num_coords, (int *)coords, num_coords,
&scalars[0], region_count); &scalars[0], region_count);
} }
seen_blend = true; seen_blend = true;
} }
@ -157,10 +157,10 @@ struct CFF2CSInterpEnv : CSInterpEnv<BlendArg, CFF2Subrs>
} }
inline unsigned int get_region_count (void) const { return region_count; } inline unsigned int get_region_count (void) const { return region_count; }
inline void set_region_count (unsigned int region_count_) { region_count = region_count_; } inline void set_region_count (unsigned int region_count_) { region_count = region_count_; }
inline unsigned int get_ivs (void) const { return ivs; } inline unsigned int get_ivs (void) const { return ivs; }
inline void set_ivs (unsigned int ivs_) { ivs = ivs_; } inline void set_ivs (unsigned int ivs_) { ivs = ivs_; }
inline bool seen_vsindex (void) const { return seen_vsindex_; } inline bool seen_vsindex (void) const { return seen_vsindex_; }
protected: protected:
inline void blend_arg (BlendArg &arg) inline void blend_arg (BlendArg &arg)
@ -169,13 +169,13 @@ struct CFF2CSInterpEnv : CSInterpEnv<BlendArg, CFF2Subrs>
{ {
if (likely (scalars.len == arg.deltas.len)) if (likely (scalars.len == arg.deltas.len))
{ {
float v = arg.to_real (); float v = arg.to_real ();
for (unsigned int i = 0; i < scalars.len; i++) for (unsigned int i = 0; i < scalars.len; i++)
{ {
v += scalars[i] * arg.deltas[i].to_real (); v += scalars[i] * arg.deltas[i].to_real ();
} }
arg.set_real (v); arg.set_real (v);
arg.deltas.resize (0); arg.deltas.resize (0);
} }
} }
} }
@ -183,13 +183,13 @@ struct CFF2CSInterpEnv : CSInterpEnv<BlendArg, CFF2Subrs>
protected: protected:
const int *coords; const int *coords;
unsigned int num_coords; unsigned int num_coords;
const CFF2VariationStore *varStore; const CFF2VariationStore *varStore;
unsigned int region_count; unsigned int region_count;
unsigned int ivs; unsigned int ivs;
hb_vector_t<float> scalars; hb_vector_t<float> scalars;
bool do_blend; bool do_blend;
bool seen_vsindex_; bool seen_vsindex_;
bool seen_blend; bool seen_blend;
typedef CSInterpEnv<BlendArg, CFF2Subrs> SUPER; typedef CSInterpEnv<BlendArg, CFF2Subrs> SUPER;
}; };
@ -201,30 +201,30 @@ struct CFF2CSOpSet : CSOpSet<BlendArg, OPSET, CFF2CSInterpEnv, PARAM, PATH>
switch (op) { switch (op) {
case OpCode_callsubr: case OpCode_callsubr:
case OpCode_callgsubr: case OpCode_callgsubr:
/* a subroutine number shoudln't be a blended value */ /* a subroutine number shoudln't be a blended value */
if (unlikely (env.argStack.peek ().blending ())) if (unlikely (env.argStack.peek ().blending ()))
{ {
env.set_error (); env.set_error ();
break; break;
} }
SUPER::process_op (op, env, param); SUPER::process_op (op, env, param);
break; break;
case OpCode_blendcs: case OpCode_blendcs:
OPSET::process_blend (env, param); OPSET::process_blend (env, param);
break; break;
case OpCode_vsindexcs: case OpCode_vsindexcs:
if (unlikely (env.argStack.peek ().blending ())) if (unlikely (env.argStack.peek ().blending ()))
{ {
env.set_error (); env.set_error ();
break; break;
} }
OPSET::process_vsindex (env, param); OPSET::process_vsindex (env, param);
break; break;
default: default:
SUPER::process_op (op, env, param); SUPER::process_op (op, env, param);
} }
} }

View File

@ -89,9 +89,9 @@ struct CFFIndex
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
return_trace (likely ((count.sanitize (c) && count == 0) || /* empty INDEX */ return_trace (likely ((count.sanitize (c) && count == 0) || /* empty INDEX */
(c->check_struct (this) && offSize >= 1 && offSize <= 4 && (c->check_struct (this) && offSize >= 1 && offSize <= 4 &&
c->check_array (offsets, offSize, count + 1) && c->check_array (offsets, offSize, count + 1) &&
c->check_array ((const HBUINT8*)data_base (), 1, max_offset () - 1)))); c->check_array ((const HBUINT8*)data_base (), 1, max_offset () - 1))));
} }
inline static unsigned int calculate_offset_array_size (unsigned int offSize, unsigned int count) inline static unsigned int calculate_offset_array_size (unsigned int offSize, unsigned int count)
@ -119,8 +119,8 @@ struct CFFIndex
} }
inline bool serialize (hb_serialize_context_t *c, inline bool serialize (hb_serialize_context_t *c,
unsigned int offSize_, unsigned int offSize_,
const ByteStrArray &byteArray) const ByteStrArray &byteArray)
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
if (byteArray.len == 0) if (byteArray.len == 0)
@ -136,33 +136,33 @@ struct CFFIndex
this->count.set (byteArray.len); this->count.set (byteArray.len);
this->offSize.set (offSize_); this->offSize.set (offSize_);
if (!unlikely (c->allocate_size<HBUINT8> (offSize_ * (byteArray.len + 1)))) if (!unlikely (c->allocate_size<HBUINT8> (offSize_ * (byteArray.len + 1))))
return_trace (false); return_trace (false);
/* serialize indices */ /* serialize indices */
unsigned int offset = 1; unsigned int offset = 1;
unsigned int i = 0; unsigned int i = 0;
for (; i < byteArray.len; i++) for (; i < byteArray.len; i++)
{ {
set_offset_at (i, offset); set_offset_at (i, offset);
offset += byteArray[i].get_size (); offset += byteArray[i].get_size ();
} }
set_offset_at (i, offset); set_offset_at (i, offset);
/* serialize data */ /* serialize data */
for (unsigned int i = 0; i < byteArray.len; i++) for (unsigned int i = 0; i < byteArray.len; i++)
{ {
ByteStr *dest = c->start_embed<ByteStr> (); ByteStr *dest = c->start_embed<ByteStr> ();
if (unlikely (dest == nullptr || if (unlikely (dest == nullptr ||
!dest->serialize (c, byteArray[i]))) !dest->serialize (c, byteArray[i])))
return_trace (false); return_trace (false);
} }
} }
return_trace (true); return_trace (true);
} }
inline bool serialize (hb_serialize_context_t *c, inline bool serialize (hb_serialize_context_t *c,
unsigned int offSize_, unsigned int offSize_,
const StrBuffArray &buffArray) const StrBuffArray &buffArray)
{ {
ByteStrArray byteArray; ByteStrArray byteArray;
byteArray.init (); byteArray.init ();
@ -221,9 +221,9 @@ struct CFFIndex
if (this != &Null(CFFIndex)) if (this != &Null(CFFIndex))
{ {
if (count > 0) if (count > 0)
return min_size + offset_array_size () + (offset_at (count) - 1); return min_size + offset_array_size () + (offset_at (count) - 1);
else else
return count.static_size; /* empty CFFIndex contains count only */ return count.static_size; /* empty CFFIndex contains count only */
} }
else else
return 0; return 0;
@ -242,7 +242,7 @@ struct CFFIndex
} }
public: public:
COUNT count; /* Number of object data. Note there are (count+1) offsets */ COUNT count; /* Number of object data. Note there are (count+1) offsets */
HBUINT8 offSize; /* The byte size of each offset in the offsets array. */ HBUINT8 offSize; /* The byte size of each offset in the offsets array. */
HBUINT8 offsets[VAR]; /* The array of (count + 1) offsets into objects array (1-base). */ HBUINT8 offsets[VAR]; /* The array of (count + 1) offsets into objects array (1-base). */
/* HBUINT8 data[VAR]; Object data */ /* HBUINT8 data[VAR]; Object data */
@ -262,12 +262,12 @@ struct CFFIndexOf : CFFIndex<COUNT>
template <typename DATA, typename PARAM1, typename PARAM2> template <typename DATA, typename PARAM1, typename PARAM2>
inline bool serialize (hb_serialize_context_t *c, inline bool serialize (hb_serialize_context_t *c,
unsigned int offSize_, unsigned int offSize_,
const DATA *dataArray, const DATA *dataArray,
unsigned int dataArrayLen, unsigned int dataArrayLen,
const hb_vector_t<unsigned int> &dataSizeArray, const hb_vector_t<unsigned int> &dataSizeArray,
const PARAM1 &param1, const PARAM1 &param1,
const PARAM2 &param2) const PARAM2 &param2)
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
/* serialize CFFIndex header */ /* serialize CFFIndex header */
@ -292,8 +292,8 @@ struct CFFIndexOf : CFFIndex<COUNT>
{ {
TYPE *dest = c->start_embed<TYPE> (); TYPE *dest = c->start_embed<TYPE> ();
if (unlikely (dest == nullptr || if (unlikely (dest == nullptr ||
!dest->serialize (c, dataArray[i], param1, param2))) !dest->serialize (c, dataArray[i], param1, param2)))
return_trace (false); return_trace (false);
} }
return_trace (true); return_trace (true);
} }
@ -301,10 +301,10 @@ struct CFFIndexOf : CFFIndex<COUNT>
/* in parallel to above */ /* in parallel to above */
template <typename DATA, typename PARAM> template <typename DATA, typename PARAM>
inline static unsigned int calculate_serialized_size (unsigned int &offSize_ /* OUT */, inline static unsigned int calculate_serialized_size (unsigned int &offSize_ /* OUT */,
const DATA *dataArray, const DATA *dataArray,
unsigned int dataArrayLen, unsigned int dataArrayLen,
hb_vector_t<unsigned int> &dataSizeArray, /* OUT */ hb_vector_t<unsigned int> &dataSizeArray, /* OUT */
const PARAM &param) const PARAM &param)
{ {
/* determine offset size */ /* determine offset size */
unsigned int totalDataSize = 0; unsigned int totalDataSize = 0;
@ -325,15 +325,15 @@ struct Dict : UnsizedByteStr
{ {
template <typename DICTVAL, typename OP_SERIALIZER, typename PARAM> template <typename DICTVAL, typename OP_SERIALIZER, typename PARAM>
inline bool serialize (hb_serialize_context_t *c, inline bool serialize (hb_serialize_context_t *c,
const DICTVAL &dictval, const DICTVAL &dictval,
OP_SERIALIZER& opszr, OP_SERIALIZER& opszr,
PARAM& param) PARAM& param)
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
for (unsigned int i = 0; i < dictval.get_count (); i++) for (unsigned int i = 0; i < dictval.get_count (); i++)
{ {
if (unlikely (!opszr.serialize (c, dictval[i], param))) if (unlikely (!opszr.serialize (c, dictval[i], param)))
return_trace (false); return_trace (false);
} }
return_trace (true); return_trace (true);
} }
@ -341,8 +341,8 @@ struct Dict : UnsizedByteStr
/* in parallel to above */ /* in parallel to above */
template <typename DICTVAL, typename OP_SERIALIZER, typename PARAM> template <typename DICTVAL, typename OP_SERIALIZER, typename PARAM>
inline static unsigned int calculate_serialized_size (const DICTVAL &dictval, inline static unsigned int calculate_serialized_size (const DICTVAL &dictval,
OP_SERIALIZER& opszr, OP_SERIALIZER& opszr,
PARAM& param) PARAM& param)
{ {
unsigned int size = 0; unsigned int size = 0;
for (unsigned int i = 0; i < dictval.get_count (); i++) for (unsigned int i = 0; i < dictval.get_count (); i++)
@ -352,7 +352,7 @@ struct Dict : UnsizedByteStr
template <typename DICTVAL, typename OP_SERIALIZER> template <typename DICTVAL, typename OP_SERIALIZER>
inline static unsigned int calculate_serialized_size (const DICTVAL &dictval, inline static unsigned int calculate_serialized_size (const DICTVAL &dictval,
OP_SERIALIZER& opszr) OP_SERIALIZER& opszr)
{ {
unsigned int size = 0; unsigned int size = 0;
for (unsigned int i = 0; i < dictval.get_count (); i++) for (unsigned int i = 0; i < dictval.get_count (); i++)
@ -471,9 +471,9 @@ struct FDArray : CFFIndexOf<COUNT, FontDict>
/* used by CFF1 */ /* used by CFF1 */
template <typename DICTVAL, typename OP_SERIALIZER> template <typename DICTVAL, typename OP_SERIALIZER>
inline bool serialize (hb_serialize_context_t *c, inline bool serialize (hb_serialize_context_t *c,
unsigned int offSize_, unsigned int offSize_,
const hb_vector_t<DICTVAL> &fontDicts, const hb_vector_t<DICTVAL> &fontDicts,
OP_SERIALIZER& opszr) OP_SERIALIZER& opszr)
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
if (unlikely (!c->extend_min (*this))) return_trace (false); if (unlikely (!c->extend_min (*this))) return_trace (false);
@ -497,7 +497,7 @@ struct FDArray : CFFIndexOf<COUNT, FontDict>
{ {
FontDict *dict = c->start_embed<FontDict> (); FontDict *dict = c->start_embed<FontDict> ();
if (unlikely (!dict->serialize (c, fontDicts[i], opszr, fontDicts[i]))) if (unlikely (!dict->serialize (c, fontDicts[i], opszr, fontDicts[i])))
return_trace (false); return_trace (false);
} }
return_trace (true); return_trace (true);
} }
@ -505,12 +505,12 @@ struct FDArray : CFFIndexOf<COUNT, FontDict>
/* used by CFF2 */ /* used by CFF2 */
template <typename DICTVAL, typename OP_SERIALIZER> template <typename DICTVAL, typename OP_SERIALIZER>
inline bool serialize (hb_serialize_context_t *c, inline bool serialize (hb_serialize_context_t *c,
unsigned int offSize_, unsigned int offSize_,
const hb_vector_t<DICTVAL> &fontDicts, const hb_vector_t<DICTVAL> &fontDicts,
unsigned int fdCount, unsigned int fdCount,
const Remap &fdmap, const Remap &fdmap,
OP_SERIALIZER& opszr, OP_SERIALIZER& opszr,
const hb_vector_t<TableInfo> &privateInfos) const hb_vector_t<TableInfo> &privateInfos)
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
if (unlikely (!c->extend_min (*this))) return_trace (false); if (unlikely (!c->extend_min (*this))) return_trace (false);
@ -525,8 +525,8 @@ struct FDArray : CFFIndexOf<COUNT, FontDict>
for (unsigned i = 0; i < fontDicts.len; i++) for (unsigned i = 0; i < fontDicts.len; i++)
if (fdmap.includes (i)) if (fdmap.includes (i))
{ {
CFFIndexOf<COUNT, FontDict>::set_offset_at (fid++, offset); CFFIndexOf<COUNT, FontDict>::set_offset_at (fid++, offset);
offset += FontDict::calculate_serialized_size (fontDicts[i], opszr); offset += FontDict::calculate_serialized_size (fontDicts[i], opszr);
} }
CFFIndexOf<COUNT, FontDict>::set_offset_at (fid, offset); CFFIndexOf<COUNT, FontDict>::set_offset_at (fid, offset);
@ -534,9 +534,9 @@ struct FDArray : CFFIndexOf<COUNT, FontDict>
for (unsigned int i = 0; i < fontDicts.len; i++) for (unsigned int i = 0; i < fontDicts.len; i++)
if (fdmap.includes (i)) if (fdmap.includes (i))
{ {
FontDict *dict = c->start_embed<FontDict> (); FontDict *dict = c->start_embed<FontDict> ();
if (unlikely (!dict->serialize (c, fontDicts[i], opszr, privateInfos[fdmap[i]]))) if (unlikely (!dict->serialize (c, fontDicts[i], opszr, privateInfos[fdmap[i]])))
return_trace (false); return_trace (false);
} }
return_trace (true); return_trace (true);
} }
@ -544,15 +544,15 @@ struct FDArray : CFFIndexOf<COUNT, FontDict>
/* in parallel to above */ /* in parallel to above */
template <typename OP_SERIALIZER, typename DICTVAL> template <typename OP_SERIALIZER, typename DICTVAL>
inline static unsigned int calculate_serialized_size (unsigned int &offSize_ /* OUT */, inline static unsigned int calculate_serialized_size (unsigned int &offSize_ /* OUT */,
const hb_vector_t<DICTVAL> &fontDicts, const hb_vector_t<DICTVAL> &fontDicts,
unsigned int fdCount, unsigned int fdCount,
const Remap &fdmap, const Remap &fdmap,
OP_SERIALIZER& opszr) OP_SERIALIZER& opszr)
{ {
unsigned int dictsSize = 0; unsigned int dictsSize = 0;
for (unsigned int i = 0; i < fontDicts.len; i++) for (unsigned int i = 0; i < fontDicts.len; i++)
if (fdmap.includes (i)) if (fdmap.includes (i))
dictsSize += FontDict::calculate_serialized_size (fontDicts[i], opszr); dictsSize += FontDict::calculate_serialized_size (fontDicts[i], opszr);
offSize_ = calcOffSize (dictsSize); offSize_ = calcOffSize (dictsSize);
return CFFIndex<COUNT>::calculate_serialized_size (offSize_, fdCount, dictsSize); return CFFIndex<COUNT>::calculate_serialized_size (offSize_, fdCount, dictsSize);
@ -568,7 +568,7 @@ struct FDSelect0 {
return_trace (false); return_trace (false);
for (unsigned int i = 0; i < c->get_num_glyphs (); i++) for (unsigned int i = 0; i < c->get_num_glyphs (); i++)
if (unlikely (!fds[i].sanitize (c))) if (unlikely (!fds[i].sanitize (c)))
return_trace (false); return_trace (false);
return_trace (true); return_trace (true);
} }
@ -614,9 +614,9 @@ struct FDSelect3_4 {
for (unsigned int i = 0; i < nRanges; i++) for (unsigned int i = 0; i < nRanges; i++)
{ {
if (unlikely (!ranges[i].sanitize (c, fdcount))) if (unlikely (!ranges[i].sanitize (c, fdcount)))
return_trace (false); return_trace (false);
if ((0 < i) && unlikely (ranges[i - 1].first >= ranges[i].first)) if ((0 < i) && unlikely (ranges[i - 1].first >= ranges[i].first))
return_trace (false); return_trace (false);
} }
if (unlikely (!sentinel().sanitize (c) || (sentinel() != c->get_num_glyphs ()))) if (unlikely (!sentinel().sanitize (c) || (sentinel() != c->get_num_glyphs ())))
return_trace (false); return_trace (false);
@ -629,7 +629,7 @@ struct FDSelect3_4 {
unsigned int i; unsigned int i;
for (i = 1; i < nRanges; i++) for (i = 1; i < nRanges; i++)
if (glyph < ranges[i].first) if (glyph < ranges[i].first)
break; break;
return (hb_codepoint_t)ranges[i - 1].fd; return (hb_codepoint_t)ranges[i - 1].fd;
} }
@ -637,7 +637,7 @@ struct FDSelect3_4 {
inline GID_TYPE &sentinel (void) { return StructAfter<GID_TYPE> (ranges[nRanges - 1]); } inline GID_TYPE &sentinel (void) { return StructAfter<GID_TYPE> (ranges[nRanges - 1]); }
inline const GID_TYPE &sentinel (void) const { return StructAfter<GID_TYPE> (ranges[nRanges - 1]); } inline const GID_TYPE &sentinel (void) const { return StructAfter<GID_TYPE> (ranges[nRanges - 1]); }
GID_TYPE nRanges; GID_TYPE nRanges;
FDSelect3_4_Range<GID_TYPE, FD_TYPE> ranges[VAR]; FDSelect3_4_Range<GID_TYPE, FD_TYPE> ranges[VAR];
/* GID_TYPE sentinel */ /* GID_TYPE sentinel */
@ -653,9 +653,9 @@ struct FDSelect {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
return_trace (likely (c->check_struct (this) && (format == 0 || format == 3) && return_trace (likely (c->check_struct (this) && (format == 0 || format == 3) &&
(format == 0)? (format == 0)?
u.format0.sanitize (c, fdcount): u.format0.sanitize (c, fdcount):
u.format3.sanitize (c, fdcount))); u.format3.sanitize (c, fdcount)));
} }
inline bool serialize (hb_serialize_context_t *c, const FDSelect &src, unsigned int num_glyphs) inline bool serialize (hb_serialize_context_t *c, const FDSelect &src, unsigned int num_glyphs)

View File

@ -276,8 +276,8 @@ struct CFF1CSOpSet_Extents : CFF1CSOpSet<CFF1CSOpSet_Extents, ExtentsParam, CFF1
Bounds base_bounds, accent_bounds; Bounds base_bounds, accent_bounds;
if (likely (!env.in_seac && base && accent if (likely (!env.in_seac && base && accent
&& _get_bounds (param.cff, base, base_bounds, true) && _get_bounds (param.cff, base, base_bounds, true)
&& _get_bounds (param.cff, accent, accent_bounds, true))) && _get_bounds (param.cff, accent, accent_bounds, true)))
{ {
param.bounds.merge (base_bounds); param.bounds.merge (base_bounds);
accent_bounds.offset (delta); accent_bounds.offset (delta);

View File

@ -47,10 +47,10 @@ enum CharsetID { ISOAdobeCharset = 0, ExpertCharset = 1, ExpertSubsetCharset = 2
typedef CFFIndex<HBUINT16> CFF1Index; typedef CFFIndex<HBUINT16> CFF1Index;
template <typename Type> struct CFF1IndexOf : CFFIndexOf<HBUINT16, Type> {}; template <typename Type> struct CFF1IndexOf : CFFIndexOf<HBUINT16, Type> {};
typedef CFFIndex<HBUINT16> CFF1Index; typedef CFFIndex<HBUINT16> CFF1Index;
typedef CFF1Index CFF1CharStrings; typedef CFF1Index CFF1CharStrings;
typedef FDArray<HBUINT16> CFF1FDArray; typedef FDArray<HBUINT16> CFF1FDArray;
typedef Subrs<HBUINT16> CFF1Subrs; typedef Subrs<HBUINT16> CFF1Subrs;
struct CFF1FDSelect : FDSelect {}; struct CFF1FDSelect : FDSelect {};
@ -114,14 +114,14 @@ struct Encoding1 {
{ {
if (glyph <= ranges[i].nLeft) if (glyph <= ranges[i].nLeft)
{ {
return (hb_codepoint_t)ranges[i].first + glyph; return (hb_codepoint_t)ranges[i].first + glyph;
} }
glyph -= (ranges[i].nLeft + 1); glyph -= (ranges[i].nLeft + 1);
} }
return CFF_UNDEF_CODE; return CFF_UNDEF_CODE;
} }
HBUINT8 nRanges; HBUINT8 nRanges;
Encoding1_Range ranges[VAR]; Encoding1_Range ranges[VAR];
DEFINE_SIZE_ARRAY (1, ranges); DEFINE_SIZE_ARRAY (1, ranges);
@ -151,13 +151,13 @@ struct CFF1SuppEncData {
{ {
for (unsigned int i = 0; i < nSups; i++) for (unsigned int i = 0; i < nSups; i++)
if (sid == supps[i].glyph) if (sid == supps[i].glyph)
codes.push (supps[i].code); codes.push (supps[i].code);
} }
inline unsigned int get_size (void) const inline unsigned int get_size (void) const
{ return HBUINT8::static_size + SuppEncoding::static_size * nSups; } { return HBUINT8::static_size + SuppEncoding::static_size * nSups; }
HBUINT8 nSups; HBUINT8 nSups;
SuppEncoding supps[VAR]; SuppEncoding supps[VAR];
DEFINE_SIZE_ARRAY (1, supps); DEFINE_SIZE_ARRAY (1, supps);
@ -191,10 +191,10 @@ struct Encoding {
/* serialize a subset Encoding */ /* serialize a subset Encoding */
inline bool serialize (hb_serialize_context_t *c, inline bool serialize (hb_serialize_context_t *c,
uint8_t format, uint8_t format,
unsigned int enc_count, unsigned int enc_count,
const hb_vector_t<code_pair>& code_ranges, const hb_vector_t<code_pair>& code_ranges,
const hb_vector_t<code_pair>& supp_codes) const hb_vector_t<code_pair>& supp_codes)
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
Encoding *dest = c->extend_min (*this); Encoding *dest = c->extend_min (*this);
@ -208,10 +208,10 @@ struct Encoding {
unsigned int glyph = 0; unsigned int glyph = 0;
for (unsigned int i = 0; i < code_ranges.len; i++) for (unsigned int i = 0; i < code_ranges.len; i++)
{ {
hb_codepoint_t code = code_ranges[i].code; hb_codepoint_t code = code_ranges[i].code;
for (int left = (int)code_ranges[i].glyph; left >= 0; left--) for (int left = (int)code_ranges[i].glyph; left >= 0; left--)
fmt0->codes[glyph++].set (code++); fmt0->codes[glyph++].set (code++);
assert ((glyph <= 0x100) && (code <= 0x100)); assert ((glyph <= 0x100) && (code <= 0x100));
} }
} }
else else
@ -221,9 +221,9 @@ struct Encoding {
fmt1->nRanges.set (code_ranges.len); fmt1->nRanges.set (code_ranges.len);
for (unsigned int i = 0; i < code_ranges.len; i++) for (unsigned int i = 0; i < code_ranges.len; i++)
{ {
assert ((code_ranges[i].code <= 0xFF) && (code_ranges[i].glyph <= 0xFF)); assert ((code_ranges[i].code <= 0xFF) && (code_ranges[i].glyph <= 0xFF));
fmt1->ranges[i].first.set (code_ranges[i].code); fmt1->ranges[i].first.set (code_ranges[i].code);
fmt1->ranges[i].nLeft.set (code_ranges[i].glyph); fmt1->ranges[i].nLeft.set (code_ranges[i].glyph);
} }
} }
if (supp_codes.len > 0) if (supp_codes.len > 0)
@ -233,8 +233,8 @@ struct Encoding {
suppData->nSups.set (supp_codes.len); suppData->nSups.set (supp_codes.len);
for (unsigned int i = 0; i < supp_codes.len; i++) for (unsigned int i = 0; i < supp_codes.len; i++)
{ {
suppData->supps[i].code.set (supp_codes[i].code); suppData->supps[i].code.set (supp_codes[i].code);
suppData->supps[i].glyph.set (supp_codes[i].glyph); /* actually SID */ suppData->supps[i].glyph.set (supp_codes[i].glyph); /* actually SID */
} }
} }
return_trace (true); return_trace (true);
@ -242,9 +242,9 @@ struct Encoding {
/* parallel to above: calculate the size of a subset Encoding */ /* parallel to above: calculate the size of a subset Encoding */
static inline unsigned int calculate_serialized_size ( static inline unsigned int calculate_serialized_size (
uint8_t format, uint8_t format,
unsigned int enc_count, unsigned int enc_count,
unsigned int supp_count) unsigned int supp_count)
{ {
unsigned int size = min_size; unsigned int size = min_size;
if (format == 0) if (format == 0)
@ -331,7 +331,7 @@ struct Charset0 {
for (unsigned int glyph = 1; glyph < num_glyphs; glyph++) for (unsigned int glyph = 1; glyph < num_glyphs; glyph++)
{ {
if (sids[glyph-1] == sid) if (sids[glyph-1] == sid)
return glyph; return glyph;
} }
return 0; return 0;
} }
@ -372,7 +372,7 @@ struct Charset1_2 {
for (unsigned int i = 0; num_glyphs > 0; i++) for (unsigned int i = 0; num_glyphs > 0; i++)
{ {
if (unlikely (!ranges[i].sanitize (c) || (num_glyphs < ranges[i].nLeft + 1))) if (unlikely (!ranges[i].sanitize (c) || (num_glyphs < ranges[i].nLeft + 1)))
return_trace (false); return_trace (false);
num_glyphs -= (ranges[i].nLeft + 1); num_glyphs -= (ranges[i].nLeft + 1);
} }
return_trace (true); return_trace (true);
@ -385,7 +385,7 @@ struct Charset1_2 {
for (unsigned int i = 0;; i++) for (unsigned int i = 0;; i++)
{ {
if (glyph <= ranges[i].nLeft) if (glyph <= ranges[i].nLeft)
return (hb_codepoint_t)ranges[i].first + glyph; return (hb_codepoint_t)ranges[i].first + glyph;
glyph -= (ranges[i].nLeft + 1); glyph -= (ranges[i].nLeft + 1);
} }
@ -399,7 +399,7 @@ struct Charset1_2 {
for (unsigned int i = 0;; i++) for (unsigned int i = 0;; i++)
{ {
if ((ranges[i].first <= sid) && sid <= ranges[i].first + ranges[i].nLeft) if ((ranges[i].first <= sid) && sid <= ranges[i].first + ranges[i].nLeft)
return glyph + (sid - ranges[i].first); return glyph + (sid - ranges[i].first);
glyph += (ranges[i].nLeft + 1); glyph += (ranges[i].nLeft + 1);
} }
@ -462,9 +462,9 @@ struct Charset {
/* serialize a subset Charset */ /* serialize a subset Charset */
inline bool serialize (hb_serialize_context_t *c, inline bool serialize (hb_serialize_context_t *c,
uint8_t format, uint8_t format,
unsigned int num_glyphs, unsigned int num_glyphs,
const hb_vector_t<code_pair>& sid_ranges) const hb_vector_t<code_pair>& sid_ranges)
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
Charset *dest = c->extend_min (*this); Charset *dest = c->extend_min (*this);
@ -477,9 +477,9 @@ struct Charset {
unsigned int glyph = 0; unsigned int glyph = 0;
for (unsigned int i = 0; i < sid_ranges.len; i++) for (unsigned int i = 0; i < sid_ranges.len; i++)
{ {
hb_codepoint_t sid = sid_ranges[i].code; hb_codepoint_t sid = sid_ranges[i].code;
for (int left = (int)sid_ranges[i].glyph; left >= 0; left--) for (int left = (int)sid_ranges[i].glyph; left >= 0; left--)
fmt0->sids[glyph++].set (sid++); fmt0->sids[glyph++].set (sid++);
} }
} }
else if (format == 1) else if (format == 1)
@ -488,9 +488,9 @@ struct Charset {
if (unlikely (fmt1 == nullptr)) return_trace (false); if (unlikely (fmt1 == nullptr)) return_trace (false);
for (unsigned int i = 0; i < sid_ranges.len; i++) for (unsigned int i = 0; i < sid_ranges.len; i++)
{ {
assert (sid_ranges[i].glyph <= 0xFF); assert (sid_ranges[i].glyph <= 0xFF);
fmt1->ranges[i].first.set (sid_ranges[i].code); fmt1->ranges[i].first.set (sid_ranges[i].code);
fmt1->ranges[i].nLeft.set (sid_ranges[i].glyph); fmt1->ranges[i].nLeft.set (sid_ranges[i].glyph);
} }
} }
else /* format 2 */ else /* format 2 */
@ -499,9 +499,9 @@ struct Charset {
if (unlikely (fmt2 == nullptr)) return_trace (false); if (unlikely (fmt2 == nullptr)) return_trace (false);
for (unsigned int i = 0; i < sid_ranges.len; i++) for (unsigned int i = 0; i < sid_ranges.len; i++)
{ {
assert (sid_ranges[i].glyph <= 0xFFFF); assert (sid_ranges[i].glyph <= 0xFFFF);
fmt2->ranges[i].first.set (sid_ranges[i].code); fmt2->ranges[i].first.set (sid_ranges[i].code);
fmt2->ranges[i].nLeft.set (sid_ranges[i].glyph); fmt2->ranges[i].nLeft.set (sid_ranges[i].glyph);
} }
} }
return_trace (true); return_trace (true);
@ -509,8 +509,8 @@ struct Charset {
/* parallel to above: calculate the size of a subset Charset */ /* parallel to above: calculate the size of a subset Charset */
static inline unsigned int calculate_serialized_size ( static inline unsigned int calculate_serialized_size (
uint8_t format, uint8_t format,
unsigned int count) unsigned int count)
{ {
unsigned int size = min_size; unsigned int size = min_size;
if (format == 0) if (format == 0)
@ -573,7 +573,7 @@ struct CFF1StringIndex : CFF1Index
if (unlikely ((strings.count == 0) || (sidmap.get_count () == 0))) if (unlikely ((strings.count == 0) || (sidmap.get_count () == 0)))
{ {
if (!unlikely (c->extend_min (this->count))) if (!unlikely (c->extend_min (this->count)))
return_trace (false); return_trace (false);
count.set (0); count.set (0);
return_trace (true); return_trace (true);
} }
@ -586,7 +586,7 @@ struct CFF1StringIndex : CFF1Index
{ {
hb_codepoint_t j = sidmap[i]; hb_codepoint_t j = sidmap[i];
if (j != CFF_UNDEF_CODE) if (j != CFF_UNDEF_CODE)
bytesArray[j] = strings[i]; bytesArray[j] = strings[i];
} }
bool result = CFF1Index::serialize (c, offSize_, bytesArray); bool result = CFF1Index::serialize (c, offSize_, bytesArray);
@ -604,7 +604,7 @@ struct CFF1StringIndex : CFF1Index
unsigned int dataSize = 0; unsigned int dataSize = 0;
for (unsigned int i = 0; i < count; i++) for (unsigned int i = 0; i < count; i++)
if (sidmap[i] != CFF_UNDEF_CODE) if (sidmap[i] != CFF_UNDEF_CODE)
dataSize += length_at (i); dataSize += length_at (i);
offSize = calcOffSize(dataSize); offSize = calcOffSize(dataSize);
return CFF1Index::calculate_serialized_size (offSize, sidmap.get_count (), dataSize); return CFF1Index::calculate_serialized_size (offSize, sidmap.get_count (), dataSize);
@ -655,23 +655,23 @@ struct NameDictValues
{ {
switch (op) { switch (op) {
case OpCode_version: case OpCode_version:
return version; return version;
case OpCode_Notice: case OpCode_Notice:
return notice; return notice;
case OpCode_Copyright: case OpCode_Copyright:
return copyright; return copyright;
case OpCode_FullName: case OpCode_FullName:
return fullName; return fullName;
case OpCode_FamilyName: case OpCode_FamilyName:
return familyName; return familyName;
case OpCode_Weight: case OpCode_Weight:
return weight; return weight;
case OpCode_PostScript: case OpCode_PostScript:
return postscript; return postscript;
case OpCode_FontName: case OpCode_FontName:
return fontName; return fontName;
default: default:
assert (0); assert (0);
} }
} }
@ -733,9 +733,9 @@ struct CFF1TopDictOpSet : TopDictOpSet<CFF1TopDictVal>
case OpCode_Weight: case OpCode_Weight:
case OpCode_PostScript: case OpCode_PostScript:
case OpCode_BaseFontName: case OpCode_BaseFontName:
dictval.nameSIDs[NameDictValues::name_op_to_index (op)] = env.argStack.pop_uint (); dictval.nameSIDs[NameDictValues::name_op_to_index (op)] = env.argStack.pop_uint ();
env.clear_args (); env.clear_args ();
break; break;
case OpCode_isFixedPitch: case OpCode_isFixedPitch:
case OpCode_ItalicAngle: case OpCode_ItalicAngle:
case OpCode_UnderlinePosition: case OpCode_UnderlinePosition:
@ -752,50 +752,50 @@ struct CFF1TopDictOpSet : TopDictOpSet<CFF1TopDictVal>
case OpCode_FontBBox: case OpCode_FontBBox:
case OpCode_XUID: case OpCode_XUID:
case OpCode_BaseFontBlend: case OpCode_BaseFontBlend:
env.clear_args (); env.clear_args ();
break; break;
case OpCode_CIDCount: case OpCode_CIDCount:
dictval.cidCount = env.argStack.pop_uint (); dictval.cidCount = env.argStack.pop_uint ();
env.clear_args (); env.clear_args ();
break; break;
case OpCode_ROS: case OpCode_ROS:
dictval.ros_supplement = env.argStack.pop_uint (); dictval.ros_supplement = env.argStack.pop_uint ();
dictval.nameSIDs[NameDictValues::ordering] = env.argStack.pop_uint (); dictval.nameSIDs[NameDictValues::ordering] = env.argStack.pop_uint ();
dictval.nameSIDs[NameDictValues::registry] = env.argStack.pop_uint (); dictval.nameSIDs[NameDictValues::registry] = env.argStack.pop_uint ();
env.clear_args (); env.clear_args ();
break; break;
case OpCode_Encoding: case OpCode_Encoding:
dictval.EncodingOffset = env.argStack.pop_uint (); dictval.EncodingOffset = env.argStack.pop_uint ();
env.clear_args (); env.clear_args ();
if (unlikely (dictval.EncodingOffset == 0)) return; if (unlikely (dictval.EncodingOffset == 0)) return;
break; break;
case OpCode_charset: case OpCode_charset:
dictval.CharsetOffset = env.argStack.pop_uint (); dictval.CharsetOffset = env.argStack.pop_uint ();
env.clear_args (); env.clear_args ();
if (unlikely (dictval.CharsetOffset == 0)) return; if (unlikely (dictval.CharsetOffset == 0)) return;
break; break;
case OpCode_FDSelect: case OpCode_FDSelect:
dictval.FDSelectOffset = env.argStack.pop_uint (); dictval.FDSelectOffset = env.argStack.pop_uint ();
env.clear_args (); env.clear_args ();
break; break;
case OpCode_Private: case OpCode_Private:
dictval.privateDictInfo.offset = env.argStack.pop_uint (); dictval.privateDictInfo.offset = env.argStack.pop_uint ();
dictval.privateDictInfo.size = env.argStack.pop_uint (); dictval.privateDictInfo.size = env.argStack.pop_uint ();
env.clear_args (); env.clear_args ();
break; break;
default: default:
env.last_offset = env.substr.offset; env.last_offset = env.substr.offset;
TopDictOpSet<CFF1TopDictVal>::process_op (op, env, dictval); TopDictOpSet<CFF1TopDictVal>::process_op (op, env, dictval);
/* Record this operand below if stack is empty, otherwise done */ /* Record this operand below if stack is empty, otherwise done */
if (!env.argStack.is_empty ()) return; if (!env.argStack.is_empty ()) return;
break; break;
} }
if (unlikely (env.in_error ())) return; if (unlikely (env.in_error ())) return;
@ -828,23 +828,23 @@ struct CFF1FontDictOpSet : DictOpSet
{ {
switch (op) { switch (op) {
case OpCode_FontName: case OpCode_FontName:
dictval.fontName = env.argStack.pop_uint (); dictval.fontName = env.argStack.pop_uint ();
env.clear_args (); env.clear_args ();
break; break;
case OpCode_FontMatrix: case OpCode_FontMatrix:
case OpCode_PaintType: case OpCode_PaintType:
env.clear_args (); env.clear_args ();
break; break;
case OpCode_Private: case OpCode_Private:
dictval.privateDictInfo.offset = env.argStack.pop_uint (); dictval.privateDictInfo.offset = env.argStack.pop_uint ();
dictval.privateDictInfo.size = env.argStack.pop_uint (); dictval.privateDictInfo.size = env.argStack.pop_uint ();
env.clear_args (); env.clear_args ();
break; break;
default: default:
DictOpSet::process_op (op, env); DictOpSet::process_op (op, env);
if (!env.argStack.is_empty ()) return; if (!env.argStack.is_empty ()) return;
break; break;
} }
if (unlikely (env.in_error ())) return; if (unlikely (env.in_error ())) return;
@ -873,9 +873,9 @@ struct CFF1PrivateDictValues_Base : DictValues<VAL>
unsigned int size = 0; unsigned int size = 0;
for (unsigned int i = 0; i < DictValues<VAL>::get_count; i++) for (unsigned int i = 0; i < DictValues<VAL>::get_count; i++)
if (DictValues<VAL>::get_value (i).op == OpCode_Subrs) if (DictValues<VAL>::get_value (i).op == OpCode_Subrs)
size += OpCode_Size (OpCode_shortint) + 2 + OpCode_Size (OpCode_Subrs); size += OpCode_Size (OpCode_shortint) + 2 + OpCode_Size (OpCode_Subrs);
else else
size += DictValues<VAL>::get_value (i).str.len; size += DictValues<VAL>::get_value (i).str.len;
return size; return size;
} }
@ -900,8 +900,8 @@ struct CFF1PrivateDictOpSet : DictOpSet
case OpCode_FamilyOtherBlues: case OpCode_FamilyOtherBlues:
case OpCode_StemSnapH: case OpCode_StemSnapH:
case OpCode_StemSnapV: case OpCode_StemSnapV:
env.clear_args (); env.clear_args ();
break; break;
case OpCode_StdHW: case OpCode_StdHW:
case OpCode_StdVW: case OpCode_StdVW:
case OpCode_BlueScale: case OpCode_BlueScale:
@ -913,18 +913,18 @@ struct CFF1PrivateDictOpSet : DictOpSet
case OpCode_initialRandomSeed: case OpCode_initialRandomSeed:
case OpCode_defaultWidthX: case OpCode_defaultWidthX:
case OpCode_nominalWidthX: case OpCode_nominalWidthX:
val.single_val = env.argStack.pop_num (); val.single_val = env.argStack.pop_num ();
env.clear_args (); env.clear_args ();
break; break;
case OpCode_Subrs: case OpCode_Subrs:
dictval.subrsOffset = env.argStack.pop_uint (); dictval.subrsOffset = env.argStack.pop_uint ();
env.clear_args (); env.clear_args ();
break; break;
default: default:
DictOpSet::process_op (op, env); DictOpSet::process_op (op, env);
if (!env.argStack.is_empty ()) return; if (!env.argStack.is_empty ()) return;
break; break;
} }
if (unlikely (env.in_error ())) return; if (unlikely (env.in_error ())) return;
@ -955,18 +955,18 @@ struct CFF1PrivateDictOpSet_Subset : DictOpSet
case OpCode_initialRandomSeed: case OpCode_initialRandomSeed:
case OpCode_defaultWidthX: case OpCode_defaultWidthX:
case OpCode_nominalWidthX: case OpCode_nominalWidthX:
env.clear_args (); env.clear_args ();
break; break;
case OpCode_Subrs: case OpCode_Subrs:
dictval.subrsOffset = env.argStack.pop_uint (); dictval.subrsOffset = env.argStack.pop_uint ();
env.clear_args (); env.clear_args ();
break; break;
default: default:
DictOpSet::process_op (op, env); DictOpSet::process_op (op, env);
if (!env.argStack.is_empty ()) return; if (!env.argStack.is_empty ()) return;
break; break;
} }
if (unlikely (env.in_error ())) return; if (unlikely (env.in_error ())) return;
@ -990,13 +990,13 @@ using namespace CFF;
struct cff1 struct cff1
{ {
static const hb_tag_t tableTag = HB_OT_TAG_cff1; static const hb_tag_t tableTag = HB_OT_TAG_cff1;
inline bool sanitize (hb_sanitize_context_t *c) const inline bool sanitize (hb_sanitize_context_t *c) const
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
return_trace (c->check_struct (this) && return_trace (c->check_struct (this) &&
likely (version.major == 1)); likely (version.major == 1));
} }
template <typename PRIVOPSET, typename PRIVDICTVAL> template <typename PRIVOPSET, typename PRIVDICTVAL>
@ -1028,37 +1028,37 @@ struct cff1
{ fini (); return; } { fini (); return; }
{ /* parse top dict */ { /* parse top dict */
const ByteStr topDictStr = (*topDictIndex)[0]; const ByteStr topDictStr = (*topDictIndex)[0];
if (unlikely (!topDictStr.sanitize (&sc))) { fini (); return; } if (unlikely (!topDictStr.sanitize (&sc))) { fini (); return; }
CFF1TopDict_Interpreter top_interp; CFF1TopDict_Interpreter top_interp;
top_interp.env.init (topDictStr); top_interp.env.init (topDictStr);
topDict.init (); topDict.init ();
if (unlikely (!top_interp.interpret (topDict))) { fini (); return; } if (unlikely (!top_interp.interpret (topDict))) { fini (); return; }
} }
if (is_predef_charset ()) if (is_predef_charset ())
charset = &Null(Charset); charset = &Null(Charset);
else else
{ {
charset = &StructAtOffsetOrNull<Charset> (cff, topDict.CharsetOffset); charset = &StructAtOffsetOrNull<Charset> (cff, topDict.CharsetOffset);
if (unlikely ((charset == &Null (Charset)) || !charset->sanitize (&sc))) { fini (); return; } if (unlikely ((charset == &Null (Charset)) || !charset->sanitize (&sc))) { fini (); return; }
} }
fdCount = 1; fdCount = 1;
if (is_CID ()) if (is_CID ())
{ {
fdArray = &StructAtOffsetOrNull<CFF1FDArray> (cff, topDict.FDArrayOffset); fdArray = &StructAtOffsetOrNull<CFF1FDArray> (cff, topDict.FDArrayOffset);
fdSelect = &StructAtOffsetOrNull<CFF1FDSelect> (cff, topDict.FDSelectOffset); fdSelect = &StructAtOffsetOrNull<CFF1FDSelect> (cff, topDict.FDSelectOffset);
if (unlikely ((fdArray == &Null(CFF1FDArray)) || !fdArray->sanitize (&sc) || if (unlikely ((fdArray == &Null(CFF1FDArray)) || !fdArray->sanitize (&sc) ||
(fdSelect == &Null(CFF1FDSelect)) || !fdSelect->sanitize (&sc, fdArray->count))) (fdSelect == &Null(CFF1FDSelect)) || !fdSelect->sanitize (&sc, fdArray->count)))
{ fini (); return; } { fini (); return; }
fdCount = fdArray->count; fdCount = fdArray->count;
} }
else else
{ {
fdArray = &Null(CFF1FDArray); fdArray = &Null(CFF1FDArray);
fdSelect = &Null(CFF1FDSelect); fdSelect = &Null(CFF1FDSelect);
} }
stringIndex = &StructAtOffset<CFF1StringIndex> (topDictIndex, topDictIndex->get_size ()); stringIndex = &StructAtOffset<CFF1StringIndex> (topDictIndex, topDictIndex->get_size ());
@ -1080,51 +1080,51 @@ struct cff1
privateDicts.resize (fdCount); privateDicts.resize (fdCount);
for (unsigned int i = 0; i < fdCount; i++) for (unsigned int i = 0; i < fdCount; i++)
privateDicts[i].init (); privateDicts[i].init ();
// parse CID font dicts and gather private dicts // parse CID font dicts and gather private dicts
if (is_CID ()) if (is_CID ())
{ {
for (unsigned int i = 0; i < fdCount; i++) for (unsigned int i = 0; i < fdCount; i++)
{ {
ByteStr fontDictStr = (*fdArray)[i]; ByteStr fontDictStr = (*fdArray)[i];
if (unlikely (!fontDictStr.sanitize (&sc))) { fini (); return; } if (unlikely (!fontDictStr.sanitize (&sc))) { fini (); return; }
CFF1FontDictValues *font; CFF1FontDictValues *font;
CFF1FontDict_Interpreter font_interp; CFF1FontDict_Interpreter font_interp;
font_interp.env.init (fontDictStr); font_interp.env.init (fontDictStr);
font = fontDicts.push (); font = fontDicts.push ();
font->init (); font->init ();
if (unlikely (!font_interp.interpret (*font))) { fini (); return; } if (unlikely (!font_interp.interpret (*font))) { fini (); return; }
PRIVDICTVAL *priv = &privateDicts[i]; PRIVDICTVAL *priv = &privateDicts[i];
const ByteStr privDictStr (StructAtOffset<UnsizedByteStr> (cff, font->privateDictInfo.offset), font->privateDictInfo.size); const ByteStr privDictStr (StructAtOffset<UnsizedByteStr> (cff, font->privateDictInfo.offset), font->privateDictInfo.size);
if (unlikely (!privDictStr.sanitize (&sc))) { fini (); return; } if (unlikely (!privDictStr.sanitize (&sc))) { fini (); return; }
DictInterpreter<PRIVOPSET, PRIVDICTVAL> priv_interp; DictInterpreter<PRIVOPSET, PRIVDICTVAL> priv_interp;
priv_interp.env.init (privDictStr); priv_interp.env.init (privDictStr);
priv->init (); priv->init ();
if (unlikely (!priv_interp.interpret (*priv))) { fini (); return; } if (unlikely (!priv_interp.interpret (*priv))) { fini (); return; }
priv->localSubrs = &StructAtOffsetOrNull<CFF1Subrs> (privDictStr.str, priv->subrsOffset); priv->localSubrs = &StructAtOffsetOrNull<CFF1Subrs> (privDictStr.str, priv->subrsOffset);
if (priv->localSubrs != &Null(CFF1Subrs) && if (priv->localSubrs != &Null(CFF1Subrs) &&
unlikely (!priv->localSubrs->sanitize (&sc))) unlikely (!priv->localSubrs->sanitize (&sc)))
{ fini (); return; } { fini (); return; }
} }
} }
else /* non-CID */ else /* non-CID */
{ {
CFF1TopDictValues *font = &topDict; CFF1TopDictValues *font = &topDict;
PRIVDICTVAL *priv = &privateDicts[0]; PRIVDICTVAL *priv = &privateDicts[0];
const ByteStr privDictStr (StructAtOffset<UnsizedByteStr> (cff, font->privateDictInfo.offset), font->privateDictInfo.size); const ByteStr privDictStr (StructAtOffset<UnsizedByteStr> (cff, font->privateDictInfo.offset), font->privateDictInfo.size);
if (unlikely (!privDictStr.sanitize (&sc))) { fini (); return; } if (unlikely (!privDictStr.sanitize (&sc))) { fini (); return; }
DictInterpreter<PRIVOPSET, PRIVDICTVAL> priv_interp; DictInterpreter<PRIVOPSET, PRIVDICTVAL> priv_interp;
priv_interp.env.init (privDictStr); priv_interp.env.init (privDictStr);
priv->init (); priv->init ();
if (unlikely (!priv_interp.interpret (*priv))) { fini (); return; } if (unlikely (!priv_interp.interpret (*priv))) { fini (); return; }
priv->localSubrs = &StructAtOffsetOrNull<CFF1Subrs> (privDictStr.str, priv->subrsOffset); priv->localSubrs = &StructAtOffsetOrNull<CFF1Subrs> (privDictStr.str, priv->subrsOffset);
if (priv->localSubrs != &Null(CFF1Subrs) && if (priv->localSubrs != &Null(CFF1Subrs) &&
unlikely (!priv->localSubrs->sanitize (&sc))) unlikely (!priv->localSubrs->sanitize (&sc)))
{ fini (); return; } { fini (); return; }
} }
} }
@ -1147,35 +1147,35 @@ struct cff1
{ {
hb_codepoint_t sid = lookup_standard_encoding_for_sid (code); hb_codepoint_t sid = lookup_standard_encoding_for_sid (code);
if (unlikely (sid == CFF_UNDEF_SID)) if (unlikely (sid == CFF_UNDEF_SID))
return 0; return 0;
if (charset != &Null(Charset)) if (charset != &Null(Charset))
return charset->get_glyph (sid, num_glyphs); return charset->get_glyph (sid, num_glyphs);
else if ((topDict.CharsetOffset == ISOAdobeCharset) else if ((topDict.CharsetOffset == ISOAdobeCharset)
&& (code <= 228 /*zcaron*/)) return sid; && (code <= 228 /*zcaron*/)) return sid;
return 0; return 0;
} }
protected: protected:
hb_blob_t *blob; hb_blob_t *blob;
hb_sanitize_context_t sc; hb_sanitize_context_t sc;
public: public:
const Charset *charset; const Charset *charset;
const CFF1NameIndex *nameIndex; const CFF1NameIndex *nameIndex;
const CFF1TopDictIndex *topDictIndex; const CFF1TopDictIndex *topDictIndex;
const CFF1StringIndex *stringIndex; const CFF1StringIndex *stringIndex;
const CFF1Subrs *globalSubrs; const CFF1Subrs *globalSubrs;
const CFF1CharStrings *charStrings; const CFF1CharStrings *charStrings;
const CFF1FDArray *fdArray; const CFF1FDArray *fdArray;
const CFF1FDSelect *fdSelect; const CFF1FDSelect *fdSelect;
unsigned int fdCount; unsigned int fdCount;
CFF1TopDictValues topDict; CFF1TopDictValues topDict;
hb_vector_t<CFF1FontDictValues> fontDicts; hb_vector_t<CFF1FontDictValues> fontDicts;
hb_vector_t<PRIVDICTVAL> privateDicts; hb_vector_t<PRIVDICTVAL> privateDicts;
unsigned int num_glyphs; unsigned int num_glyphs;
}; };
struct accelerator_t : accelerator_templ_t<CFF1PrivateDictOpSet, CFF1PrivateDictValues> struct accelerator_t : accelerator_templ_t<CFF1PrivateDictOpSet, CFF1PrivateDictValues>
@ -1195,15 +1195,15 @@ struct cff1
encoding = &Null(Encoding); encoding = &Null(Encoding);
if (is_CID ()) if (is_CID ())
{ {
if (unlikely (charset == &Null(Charset))) { fini (); return; } if (unlikely (charset == &Null(Charset))) { fini (); return; }
} }
else else
{ {
if (!is_predef_encoding ()) if (!is_predef_encoding ())
{ {
encoding = &StructAtOffsetOrNull<Encoding> (cff, topDict.EncodingOffset); encoding = &StructAtOffsetOrNull<Encoding> (cff, topDict.EncodingOffset);
if (unlikely ((encoding == &Null (Encoding)) || !encoding->sanitize (&sc))) { fini (); return; } if (unlikely ((encoding == &Null (Encoding)) || !encoding->sanitize (&sc))) { fini (); return; }
} }
} }
} }
@ -1212,53 +1212,53 @@ struct cff1
inline hb_codepoint_t glyph_to_code (hb_codepoint_t glyph) const inline hb_codepoint_t glyph_to_code (hb_codepoint_t glyph) const
{ {
if (encoding != &Null(Encoding)) if (encoding != &Null(Encoding))
return encoding->get_code (glyph); return encoding->get_code (glyph);
else else
{ {
hb_codepoint_t sid = glyph_to_sid (glyph); hb_codepoint_t sid = glyph_to_sid (glyph);
if (sid == 0) return 0; if (sid == 0) return 0;
hb_codepoint_t code = 0; hb_codepoint_t code = 0;
switch (topDict.EncodingOffset) switch (topDict.EncodingOffset)
{ {
case StandardEncoding: case StandardEncoding:
code = lookup_standard_encoding_for_code (sid); code = lookup_standard_encoding_for_code (sid);
break; break;
case ExpertEncoding: case ExpertEncoding:
code = lookup_expert_encoding_for_code (sid); code = lookup_expert_encoding_for_code (sid);
break; break;
default: default:
break; break;
} }
return code; return code;
} }
} }
inline hb_codepoint_t glyph_to_sid (hb_codepoint_t glyph) const inline hb_codepoint_t glyph_to_sid (hb_codepoint_t glyph) const
{ {
if (charset != &Null(Charset)) if (charset != &Null(Charset))
return charset->get_sid (glyph); return charset->get_sid (glyph);
else else
{ {
hb_codepoint_t sid = 0; hb_codepoint_t sid = 0;
switch (topDict.CharsetOffset) switch (topDict.CharsetOffset)
{ {
case ISOAdobeCharset: case ISOAdobeCharset:
if (glyph <= 228 /*zcaron*/) sid = glyph; if (glyph <= 228 /*zcaron*/) sid = glyph;
break; break;
case ExpertCharset: case ExpertCharset:
sid = lookup_expert_charset_for_sid (glyph); sid = lookup_expert_charset_for_sid (glyph);
break; break;
case ExpertSubsetCharset: case ExpertSubsetCharset:
sid = lookup_expert_subset_charset_for_sid (glyph); sid = lookup_expert_subset_charset_for_sid (glyph);
break; break;
default: default:
break; break;
} }
return sid; return sid;
} }
} }
const Encoding *encoding; const Encoding *encoding;
private: private:
typedef accelerator_templ_t<CFF1PrivateDictOpSet_Subset, CFF1PrivateDictValues_Subset> SUPER; typedef accelerator_templ_t<CFF1PrivateDictOpSet_Subset, CFF1PrivateDictValues_Subset> SUPER;
@ -1290,9 +1290,9 @@ struct cff1
HB_INTERNAL static hb_codepoint_t lookup_standard_encoding_for_sid (hb_codepoint_t code); HB_INTERNAL static hb_codepoint_t lookup_standard_encoding_for_sid (hb_codepoint_t code);
public: public:
FixedVersion<HBUINT8> version; /* Version of CFF table. set to 0x0100u */ FixedVersion<HBUINT8> version; /* Version of CFF table. set to 0x0100u */
OffsetTo<CFF1NameIndex, HBUINT8> nameIndex; /* headerSize = Offset to Name INDEX. */ OffsetTo<CFF1NameIndex, HBUINT8> nameIndex; /* headerSize = Offset to Name INDEX. */
HBUINT8 offSize; /* offset size (unused?) */ HBUINT8 offSize; /* offset size (unused?) */
public: public:
DEFINE_SIZE_STATIC (4); DEFINE_SIZE_STATIC (4);

View File

@ -96,8 +96,8 @@ struct CFF2PathProcs_Extents : PathProcs<CFF2PathProcs_Extents, CFF2CSInterpEnv,
struct CFF2CSOpSet_Extents : CFF2CSOpSet<CFF2CSOpSet_Extents, ExtentsParam, CFF2PathProcs_Extents> {}; struct CFF2CSOpSet_Extents : CFF2CSOpSet<CFF2CSOpSet_Extents, ExtentsParam, CFF2PathProcs_Extents> {};
bool OT::cff2::accelerator_t::get_extents (hb_font_t *font, bool OT::cff2::accelerator_t::get_extents (hb_font_t *font,
hb_codepoint_t glyph, hb_codepoint_t glyph,
hb_glyph_extents_t *extents) const hb_glyph_extents_t *extents) const
{ {
if (unlikely (!is_valid () || (glyph >= num_glyphs))) return false; if (unlikely (!is_valid () || (glyph >= num_glyphs))) return false;

View File

@ -56,11 +56,11 @@ struct CFF2FDSelect
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
return_trace (likely (c->check_struct (this) && (format == 0 || format == 3 || format == 4) && return_trace (likely (c->check_struct (this) && (format == 0 || format == 3 || format == 4) &&
(format == 0)? (format == 0)?
u.format0.sanitize (c, fdcount): u.format0.sanitize (c, fdcount):
((format == 3)? ((format == 3)?
u.format3.sanitize (c, fdcount): u.format3.sanitize (c, fdcount):
u.format4.sanitize (c, fdcount)))); u.format4.sanitize (c, fdcount))));
} }
inline bool serialize (hb_serialize_context_t *c, const CFF2FDSelect &src, unsigned int num_glyphs) inline bool serialize (hb_serialize_context_t *c, const CFF2FDSelect &src, unsigned int num_glyphs)
@ -130,7 +130,7 @@ struct CFF2VariationStore
inline unsigned int get_size (void) const { return HBUINT16::static_size + size; } inline unsigned int get_size (void) const { return HBUINT16::static_size + size; }
HBUINT16 size; HBUINT16 size;
VariationStore varStore; VariationStore varStore;
DEFINE_SIZE_MIN (2 + VariationStore::min_size); DEFINE_SIZE_MIN (2 + VariationStore::min_size);
@ -158,13 +158,13 @@ struct CFF2TopDictValues : TopDictValues<>
OpCode op = get_value (i).op; OpCode op = get_value (i).op;
switch (op) switch (op)
{ {
case OpCode_vstore: case OpCode_vstore:
case OpCode_FDSelect: case OpCode_FDSelect:
size += OpCode_Size (OpCode_longintdict) + 4 + OpCode_Size (op); size += OpCode_Size (OpCode_longintdict) + 4 + OpCode_Size (op);
break; break;
default: default:
size += TopDictValues<>::calculate_serialized_op_size (get_value (i)); size += TopDictValues<>::calculate_serialized_op_size (get_value (i));
break; break;
} }
} }
return size; return size;
@ -180,27 +180,27 @@ struct CFF2TopDictOpSet : TopDictOpSet<>
{ {
switch (op) { switch (op) {
case OpCode_FontMatrix: case OpCode_FontMatrix:
{ {
DictVal val; DictVal val;
val.init (); val.init ();
dictval.add_op (op, env.substr); dictval.add_op (op, env.substr);
env.clear_args (); env.clear_args ();
} }
break; break;
case OpCode_vstore: case OpCode_vstore:
dictval.vstoreOffset = env.argStack.pop_uint (); dictval.vstoreOffset = env.argStack.pop_uint ();
env.clear_args (); env.clear_args ();
break; break;
case OpCode_FDSelect: case OpCode_FDSelect:
dictval.FDSelectOffset = env.argStack.pop_uint (); dictval.FDSelectOffset = env.argStack.pop_uint ();
env.clear_args (); env.clear_args ();
break; break;
default: default:
SUPER::process_op (op, env, dictval); SUPER::process_op (op, env, dictval);
/* Record this operand below if stack is empty, otherwise done */ /* Record this operand below if stack is empty, otherwise done */
if (!env.argStack.is_empty ()) return; if (!env.argStack.is_empty ()) return;
} }
if (unlikely (env.in_error ())) return; if (unlikely (env.in_error ())) return;
@ -233,15 +233,15 @@ struct CFF2FontDictOpSet : DictOpSet
{ {
switch (op) { switch (op) {
case OpCode_Private: case OpCode_Private:
dictval.privateDictInfo.offset = env.argStack.pop_uint (); dictval.privateDictInfo.offset = env.argStack.pop_uint ();
dictval.privateDictInfo.size = env.argStack.pop_uint (); dictval.privateDictInfo.size = env.argStack.pop_uint ();
env.clear_args (); env.clear_args ();
break; break;
default: default:
SUPER::process_op (op, env); SUPER::process_op (op, env);
if (!env.argStack.is_empty ()) if (!env.argStack.is_empty ())
return; return;
} }
if (unlikely (env.in_error ())) return; if (unlikely (env.in_error ())) return;
@ -274,9 +274,9 @@ struct CFF2PrivateDictValues_Base : DictValues<VAL>
unsigned int size = 0; unsigned int size = 0;
for (unsigned int i = 0; i < DictValues<VAL>::get_count; i++) for (unsigned int i = 0; i < DictValues<VAL>::get_count; i++)
if (DictValues<VAL>::get_value (i).op == OpCode_Subrs) if (DictValues<VAL>::get_value (i).op == OpCode_Subrs)
size += OpCode_Size (OpCode_shortint) + 2 + OpCode_Size (OpCode_Subrs); size += OpCode_Size (OpCode_shortint) + 2 + OpCode_Size (OpCode_Subrs);
else else
size += DictValues<VAL>::get_value (i).str.len; size += DictValues<VAL>::get_value (i).str.len;
return size; return size;
} }
@ -307,11 +307,11 @@ struct CFF2PrivDictInterpEnv : NumInterpEnv
} }
inline unsigned int get_ivs (void) const { return ivs; } inline unsigned int get_ivs (void) const { return ivs; }
inline void set_ivs (unsigned int ivs_) { ivs = ivs_; } inline void set_ivs (unsigned int ivs_) { ivs = ivs_; }
protected: protected:
unsigned int ivs; unsigned int ivs;
bool seen_vsindex; bool seen_vsindex;
}; };
struct CFF2PrivateDictOpSet : DictOpSet struct CFF2PrivateDictOpSet : DictOpSet
@ -329,33 +329,33 @@ struct CFF2PrivateDictOpSet : DictOpSet
case OpCode_BlueFuzz: case OpCode_BlueFuzz:
case OpCode_ExpansionFactor: case OpCode_ExpansionFactor:
case OpCode_LanguageGroup: case OpCode_LanguageGroup:
val.single_val = env.argStack.pop_num (); val.single_val = env.argStack.pop_num ();
env.clear_args (); env.clear_args ();
break; break;
case OpCode_BlueValues: case OpCode_BlueValues:
case OpCode_OtherBlues: case OpCode_OtherBlues:
case OpCode_FamilyBlues: case OpCode_FamilyBlues:
case OpCode_FamilyOtherBlues: case OpCode_FamilyOtherBlues:
case OpCode_StemSnapH: case OpCode_StemSnapH:
case OpCode_StemSnapV: case OpCode_StemSnapV:
env.clear_args (); env.clear_args ();
break; break;
case OpCode_Subrs: case OpCode_Subrs:
dictval.subrsOffset = env.argStack.pop_uint (); dictval.subrsOffset = env.argStack.pop_uint ();
env.clear_args (); env.clear_args ();
break; break;
case OpCode_vsindexdict: case OpCode_vsindexdict:
env.process_vsindex (); env.process_vsindex ();
dictval.ivs = env.get_ivs (); dictval.ivs = env.get_ivs ();
env.clear_args (); env.clear_args ();
break; break;
case OpCode_blenddict: case OpCode_blenddict:
break; break;
default: default:
DictOpSet::process_op (op, env); DictOpSet::process_op (op, env);
if (!env.argStack.is_empty ()) return; if (!env.argStack.is_empty ()) return;
break; break;
} }
if (unlikely (env.in_error ())) return; if (unlikely (env.in_error ())) return;
@ -382,22 +382,22 @@ struct CFF2PrivateDictOpSet_Subset : DictOpSet
case OpCode_StemSnapV: case OpCode_StemSnapV:
case OpCode_LanguageGroup: case OpCode_LanguageGroup:
case OpCode_ExpansionFactor: case OpCode_ExpansionFactor:
env.clear_args (); env.clear_args ();
break; break;
case OpCode_blenddict: case OpCode_blenddict:
env.clear_args (); env.clear_args ();
return; return;
case OpCode_Subrs: case OpCode_Subrs:
dictval.subrsOffset = env.argStack.pop_uint (); dictval.subrsOffset = env.argStack.pop_uint ();
env.clear_args (); env.clear_args ();
break; break;
default: default:
SUPER::process_op (op, env); SUPER::process_op (op, env);
if (!env.argStack.is_empty ()) return; if (!env.argStack.is_empty ()) return;
break; break;
} }
if (unlikely (env.in_error ())) return; if (unlikely (env.in_error ())) return;
@ -420,13 +420,13 @@ using namespace CFF;
struct cff2 struct cff2
{ {
static const hb_tag_t tableTag = HB_OT_TAG_cff2; static const hb_tag_t tableTag = HB_OT_TAG_cff2;
inline bool sanitize (hb_sanitize_context_t *c) const inline bool sanitize (hb_sanitize_context_t *c) const
{ {
TRACE_SANITIZE (this); TRACE_SANITIZE (this);
return_trace (c->check_struct (this) && return_trace (c->check_struct (this) &&
likely (version.major == 2)); likely (version.major == 2));
} }
template <typename PRIVOPSET, typename PRIVDICTVAL> template <typename PRIVOPSET, typename PRIVDICTVAL>
@ -450,12 +450,12 @@ struct cff2
{ fini (); return; } { fini (); return; }
{ /* parse top dict */ { /* parse top dict */
ByteStr topDictStr (cff2 + cff2->topDict, cff2->topDictSize); ByteStr topDictStr (cff2 + cff2->topDict, cff2->topDictSize);
if (unlikely (!topDictStr.sanitize (&sc))) { fini (); return; } if (unlikely (!topDictStr.sanitize (&sc))) { fini (); return; }
CFF2TopDict_Interpreter top_interp; CFF2TopDict_Interpreter top_interp;
top_interp.env.init (topDictStr); top_interp.env.init (topDictStr);
topDict.init (); topDict.init ();
if (unlikely (!top_interp.interpret (topDict))) { fini (); return; } if (unlikely (!top_interp.interpret (topDict))) { fini (); return; }
} }
globalSubrs = &StructAtOffset<CFF2Subrs> (cff2, cff2->topDict + cff2->topDictSize); globalSubrs = &StructAtOffset<CFF2Subrs> (cff2, cff2->topDict + cff2->topDictSize);
@ -465,9 +465,9 @@ struct cff2
fdSelect = &StructAtOffsetOrNull<CFF2FDSelect> (cff2, topDict.FDSelectOffset); fdSelect = &StructAtOffsetOrNull<CFF2FDSelect> (cff2, topDict.FDSelectOffset);
if (((varStore != &Null(CFF2VariationStore)) && unlikely (!varStore->sanitize (&sc))) || if (((varStore != &Null(CFF2VariationStore)) && unlikely (!varStore->sanitize (&sc))) ||
(charStrings == &Null(CFF2CharStrings)) || unlikely (!charStrings->sanitize (&sc)) || (charStrings == &Null(CFF2CharStrings)) || unlikely (!charStrings->sanitize (&sc)) ||
(fdArray == &Null(CFF2FDArray)) || unlikely (!fdArray->sanitize (&sc)) || (fdArray == &Null(CFF2FDArray)) || unlikely (!fdArray->sanitize (&sc)) ||
(((fdSelect != &Null(CFF2FDSelect)) && unlikely (!fdSelect->sanitize (&sc, fdArray->count))))) (((fdSelect != &Null(CFF2FDSelect)) && unlikely (!fdSelect->sanitize (&sc, fdArray->count)))))
{ fini (); return; } { fini (); return; }
num_glyphs = charStrings->count; num_glyphs = charStrings->count;
@ -480,26 +480,26 @@ struct cff2
/* parse font dicts and gather private dicts */ /* parse font dicts and gather private dicts */
for (unsigned int i = 0; i < fdCount; i++) for (unsigned int i = 0; i < fdCount; i++)
{ {
const ByteStr fontDictStr = (*fdArray)[i]; const ByteStr fontDictStr = (*fdArray)[i];
if (unlikely (!fontDictStr.sanitize (&sc))) { fini (); return; } if (unlikely (!fontDictStr.sanitize (&sc))) { fini (); return; }
CFF2FontDictValues *font; CFF2FontDictValues *font;
CFF2FontDict_Interpreter font_interp; CFF2FontDict_Interpreter font_interp;
font_interp.env.init (fontDictStr); font_interp.env.init (fontDictStr);
font = fontDicts.push (); font = fontDicts.push ();
font->init (); font->init ();
if (unlikely (!font_interp.interpret (*font))) { fini (); return; } if (unlikely (!font_interp.interpret (*font))) { fini (); return; }
const ByteStr privDictStr (StructAtOffsetOrNull<UnsizedByteStr> (cff2, font->privateDictInfo.offset), font->privateDictInfo.size); const ByteStr privDictStr (StructAtOffsetOrNull<UnsizedByteStr> (cff2, font->privateDictInfo.offset), font->privateDictInfo.size);
if (unlikely (!privDictStr.sanitize (&sc))) { fini (); return; } if (unlikely (!privDictStr.sanitize (&sc))) { fini (); return; }
DictInterpreter<PRIVOPSET, PRIVDICTVAL, CFF2PrivDictInterpEnv> priv_interp; DictInterpreter<PRIVOPSET, PRIVDICTVAL, CFF2PrivDictInterpEnv> priv_interp;
priv_interp.env.init(privDictStr); priv_interp.env.init(privDictStr);
privateDicts[i].init (); privateDicts[i].init ();
if (unlikely (!priv_interp.interpret (privateDicts[i]))) { fini (); return; } if (unlikely (!priv_interp.interpret (privateDicts[i]))) { fini (); return; }
privateDicts[i].localSubrs = &StructAtOffsetOrNull<CFF2Subrs> (privDictStr.str, privateDicts[i].subrsOffset); privateDicts[i].localSubrs = &StructAtOffsetOrNull<CFF2Subrs> (privDictStr.str, privateDicts[i].subrsOffset);
if (privateDicts[i].localSubrs != &Null(CFF2Subrs) && if (privateDicts[i].localSubrs != &Null(CFF2Subrs) &&
unlikely (!privateDicts[i].localSubrs->sanitize (&sc))) unlikely (!privateDicts[i].localSubrs->sanitize (&sc)))
{ fini (); return; } { fini (); return; }
} }
} }
@ -515,29 +515,29 @@ struct cff2
inline bool is_valid (void) const { return blob != nullptr; } inline bool is_valid (void) const { return blob != nullptr; }
protected: protected:
hb_blob_t *blob; hb_blob_t *blob;
hb_sanitize_context_t sc; hb_sanitize_context_t sc;
public: public:
CFF2TopDictValues topDict; CFF2TopDictValues topDict;
const CFF2Subrs *globalSubrs; const CFF2Subrs *globalSubrs;
const CFF2VariationStore *varStore; const CFF2VariationStore *varStore;
const CFF2CharStrings *charStrings; const CFF2CharStrings *charStrings;
const CFF2FDArray *fdArray; const CFF2FDArray *fdArray;
const CFF2FDSelect *fdSelect; const CFF2FDSelect *fdSelect;
unsigned int fdCount; unsigned int fdCount;
hb_vector_t<CFF2FontDictValues> fontDicts; hb_vector_t<CFF2FontDictValues> fontDicts;
hb_vector_t<PRIVDICTVAL> privateDicts; hb_vector_t<PRIVDICTVAL> privateDicts;
unsigned int num_glyphs; unsigned int num_glyphs;
}; };
struct accelerator_t : accelerator_templ_t<CFF2PrivateDictOpSet, CFF2PrivateDictValues> struct accelerator_t : accelerator_templ_t<CFF2PrivateDictOpSet, CFF2PrivateDictValues>
{ {
HB_INTERNAL bool get_extents (hb_font_t *font, HB_INTERNAL bool get_extents (hb_font_t *font,
hb_codepoint_t glyph, hb_codepoint_t glyph,
hb_glyph_extents_t *extents) const; hb_glyph_extents_t *extents) const;
}; };
typedef accelerator_templ_t<CFF2PrivateDictOpSet_Subset, CFF2PrivateDictValues_Subset> accelerator_subset_t; typedef accelerator_templ_t<CFF2PrivateDictOpSet_Subset, CFF2PrivateDictValues_Subset> accelerator_subset_t;
@ -561,9 +561,9 @@ struct cff2
} }
public: public:
FixedVersion<HBUINT8> version; /* Version of CFF2 table. set to 0x0200u */ FixedVersion<HBUINT8> version; /* Version of CFF2 table. set to 0x0200u */
OffsetTo<TopDict, HBUINT8, false> topDict; /* headerSize = Offset to Top DICT. */ OffsetTo<TopDict, HBUINT8, false> topDict; /* headerSize = Offset to Top DICT. */
HBUINT16 topDictSize; /* Top DICT size */ HBUINT16 topDictSize; /* Top DICT size */
public: public:
DEFINE_SIZE_STATIC (5); DEFINE_SIZE_STATIC (5);

View File

@ -44,13 +44,13 @@ using namespace CFF;
bool bool
hb_plan_subset_cff_fdselect (const hb_vector_t<hb_codepoint_t> &glyphs, hb_plan_subset_cff_fdselect (const hb_vector_t<hb_codepoint_t> &glyphs,
unsigned int fdCount, unsigned int fdCount,
const FDSelect &src, /* IN */ const FDSelect &src, /* IN */
unsigned int &subset_fd_count /* OUT */, unsigned int &subset_fd_count /* OUT */,
unsigned int &subset_fdselect_size /* OUT */, unsigned int &subset_fdselect_size /* OUT */,
unsigned int &subset_fdselect_format /* OUT */, unsigned int &subset_fdselect_format /* OUT */,
hb_vector_t<code_pair> &fdselect_ranges /* OUT */, hb_vector_t<code_pair> &fdselect_ranges /* OUT */,
Remap &fdmap /* OUT */) Remap &fdmap /* OUT */)
{ {
subset_fd_count = 0; subset_fd_count = 0;
subset_fdselect_size = 0; subset_fdselect_size = 0;
@ -74,10 +74,10 @@ hb_plan_subset_cff_fdselect (const hb_vector_t<hb_codepoint_t> &glyphs,
if (fd != prev_fd) if (fd != prev_fd)
{ {
num_ranges++; num_ranges++;
prev_fd = fd; prev_fd = fd;
code_pair pair = { fd, i }; code_pair pair = { fd, i };
fdselect_ranges.push (pair); fdselect_ranges.push (pair);
} }
} }
@ -93,13 +93,13 @@ hb_plan_subset_cff_fdselect (const hb_vector_t<hb_codepoint_t> &glyphs,
/* create a fdmap */ /* create a fdmap */
if (!fdmap.reset (fdCount)) if (!fdmap.reset (fdCount))
{ {
hb_set_destroy (set); hb_set_destroy (set);
return false; return false;
} }
hb_codepoint_t fd = CFF_UNDEF_CODE; hb_codepoint_t fd = CFF_UNDEF_CODE;
while (set->next (&fd)) while (set->next (&fd))
fdmap.add (fd); fdmap.add (fd);
assert (fdmap.get_count () == subset_fd_count); assert (fdmap.get_count () == subset_fd_count);
hb_set_destroy (set); hb_set_destroy (set);
} }
@ -143,10 +143,10 @@ hb_plan_subset_cff_fdselect (const hb_vector_t<hb_codepoint_t> &glyphs,
template <typename FDSELECT3_4> template <typename FDSELECT3_4>
static inline bool static inline bool
serialize_fdselect_3_4 (hb_serialize_context_t *c, serialize_fdselect_3_4 (hb_serialize_context_t *c,
const unsigned int num_glyphs, const unsigned int num_glyphs,
const FDSelect &src, const FDSelect &src,
unsigned int size, unsigned int size,
const hb_vector_t<code_pair> &fdselect_ranges) const hb_vector_t<code_pair> &fdselect_ranges)
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
FDSELECT3_4 *p = c->allocate_size<FDSELECT3_4> (size); FDSELECT3_4 *p = c->allocate_size<FDSELECT3_4> (size);
@ -167,12 +167,12 @@ serialize_fdselect_3_4 (hb_serialize_context_t *c,
**/ **/
bool bool
hb_serialize_cff_fdselect (hb_serialize_context_t *c, hb_serialize_cff_fdselect (hb_serialize_context_t *c,
const unsigned int num_glyphs, const unsigned int num_glyphs,
const FDSelect &src, const FDSelect &src,
unsigned int fd_count, unsigned int fd_count,
unsigned int fdselect_format, unsigned int fdselect_format,
unsigned int size, unsigned int size,
const hb_vector_t<code_pair> &fdselect_ranges) const hb_vector_t<code_pair> &fdselect_ranges)
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
FDSelect *p = c->allocate_min<FDSelect> (); FDSelect *p = c->allocate_min<FDSelect> ();
@ -191,12 +191,12 @@ hb_serialize_cff_fdselect (hb_serialize_context_t *c,
unsigned int fd = fdselect_ranges[range_index++].code; unsigned int fd = fdselect_ranges[range_index++].code;
for (unsigned int i = 0; i < num_glyphs; i++) for (unsigned int i = 0; i < num_glyphs; i++)
{ {
if ((range_index < fdselect_ranges.len) && if ((range_index < fdselect_ranges.len) &&
(i >= fdselect_ranges[range_index].glyph)) (i >= fdselect_ranges[range_index].glyph))
{ {
fd = fdselect_ranges[range_index++].code; fd = fdselect_ranges[range_index++].code;
} }
p->fds[i].set (fd); p->fds[i].set (fd);
} }
break; break;
} }
@ -204,17 +204,17 @@ hb_serialize_cff_fdselect (hb_serialize_context_t *c,
case 3: case 3:
return serialize_fdselect_3_4<FDSelect3> (c, return serialize_fdselect_3_4<FDSelect3> (c,
num_glyphs, num_glyphs,
src, src,
size, size,
fdselect_ranges); fdselect_ranges);
case 4: case 4:
return serialize_fdselect_3_4<FDSelect4> (c, return serialize_fdselect_3_4<FDSelect4> (c,
num_glyphs, num_glyphs,
src, src,
size, size,
fdselect_ranges); fdselect_ranges);
default: default:
assert(false); assert(false);

View File

@ -57,26 +57,26 @@ struct StrEncoder
if ((-1131 <= v) && (v <= 1131)) if ((-1131 <= v) && (v <= 1131))
{ {
if ((-107 <= v) && (v <= 107)) if ((-107 <= v) && (v <= 107))
encode_byte (v + 139); encode_byte (v + 139);
else if (v > 0) else if (v > 0)
{ {
v -= 108; v -= 108;
encode_byte ((v >> 8) + OpCode_TwoBytePosInt0); encode_byte ((v >> 8) + OpCode_TwoBytePosInt0);
encode_byte (v & 0xFF); encode_byte (v & 0xFF);
} }
else else
{ {
v = -v - 108; v = -v - 108;
encode_byte ((v >> 8) + OpCode_TwoByteNegInt0); encode_byte ((v >> 8) + OpCode_TwoByteNegInt0);
encode_byte (v & 0xFF); encode_byte (v & 0xFF);
} }
} }
else else
{ {
if (unlikely (v < -32768)) if (unlikely (v < -32768))
v = -32768; v = -32768;
else if (unlikely (v > 32767)) else if (unlikely (v > 32767))
v = 32767; v = 32767;
encode_byte (OpCode_shortint); encode_byte (OpCode_shortint);
encode_byte ((v >> 8) & 0xFF); encode_byte ((v >> 8) & 0xFF);
encode_byte (v & 0xFF); encode_byte (v & 0xFF);
@ -163,24 +163,24 @@ template <typename OPSTR=OpStr>
struct CFFTopDict_OpSerializer : OpSerializer struct CFFTopDict_OpSerializer : OpSerializer
{ {
inline bool serialize (hb_serialize_context_t *c, inline bool serialize (hb_serialize_context_t *c,
const OPSTR &opstr, const OPSTR &opstr,
const CFFSubTableOffsets &offsets) const const CFFSubTableOffsets &offsets) const
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
switch (opstr.op) switch (opstr.op)
{ {
case OpCode_CharStrings: case OpCode_CharStrings:
return_trace (FontDict::serialize_offset4_op(c, opstr.op, offsets.charStringsInfo.offset)); return_trace (FontDict::serialize_offset4_op(c, opstr.op, offsets.charStringsInfo.offset));
case OpCode_FDArray: case OpCode_FDArray:
return_trace (FontDict::serialize_offset4_op(c, opstr.op, offsets.FDArrayInfo.offset)); return_trace (FontDict::serialize_offset4_op(c, opstr.op, offsets.FDArrayInfo.offset));
case OpCode_FDSelect: case OpCode_FDSelect:
return_trace (FontDict::serialize_offset4_op(c, opstr.op, offsets.FDSelectInfo.offset)); return_trace (FontDict::serialize_offset4_op(c, opstr.op, offsets.FDSelectInfo.offset));
default: default:
return_trace (copy_opstr (c, opstr)); return_trace (copy_opstr (c, opstr));
} }
return_trace (true); return_trace (true);
} }
@ -192,10 +192,10 @@ struct CFFTopDict_OpSerializer : OpSerializer
case OpCode_CharStrings: case OpCode_CharStrings:
case OpCode_FDArray: case OpCode_FDArray:
case OpCode_FDSelect: case OpCode_FDSelect:
return OpCode_Size (OpCode_longintdict) + 4 + OpCode_Size (opstr.op); return OpCode_Size (OpCode_longintdict) + 4 + OpCode_Size (opstr.op);
default: default:
return opstr.str.len; return opstr.str.len;
} }
} }
}; };
@ -203,8 +203,8 @@ struct CFFTopDict_OpSerializer : OpSerializer
struct CFFFontDict_OpSerializer : OpSerializer struct CFFFontDict_OpSerializer : OpSerializer
{ {
inline bool serialize (hb_serialize_context_t *c, inline bool serialize (hb_serialize_context_t *c,
const OpStr &opstr, const OpStr &opstr,
const TableInfo &privateDictInfo) const const TableInfo &privateDictInfo) const
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
@ -212,8 +212,8 @@ struct CFFFontDict_OpSerializer : OpSerializer
{ {
/* serialize the private dict size & offset as 2-byte & 4-byte integers */ /* serialize the private dict size & offset as 2-byte & 4-byte integers */
if (unlikely (!UnsizedByteStr::serialize_int2 (c, privateDictInfo.size) || if (unlikely (!UnsizedByteStr::serialize_int2 (c, privateDictInfo.size) ||
!UnsizedByteStr::serialize_int4 (c, privateDictInfo.offset))) !UnsizedByteStr::serialize_int4 (c, privateDictInfo.offset)))
return_trace (false); return_trace (false);
/* serialize the opcode */ /* serialize the opcode */
HBUINT8 *p = c->allocate_size<HBUINT8> (1); HBUINT8 *p = c->allocate_size<HBUINT8> (1);
@ -246,8 +246,8 @@ struct CFFPrivateDict_OpSerializer : OpSerializer
: desubroutinize (desubroutinize_), drop_hints (drop_hints_) {} : desubroutinize (desubroutinize_), drop_hints (drop_hints_) {}
inline bool serialize (hb_serialize_context_t *c, inline bool serialize (hb_serialize_context_t *c,
const OpStr &opstr, const OpStr &opstr,
const unsigned int subrsOffset) const const unsigned int subrsOffset) const
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
@ -256,25 +256,25 @@ struct CFFPrivateDict_OpSerializer : OpSerializer
if (opstr.op == OpCode_Subrs) if (opstr.op == OpCode_Subrs)
{ {
if (desubroutinize || (subrsOffset == 0)) if (desubroutinize || (subrsOffset == 0))
return_trace (true); return_trace (true);
else else
return_trace (FontDict::serialize_offset2_op (c, opstr.op, subrsOffset)); return_trace (FontDict::serialize_offset2_op (c, opstr.op, subrsOffset));
} }
else else
return_trace (copy_opstr (c, opstr)); return_trace (copy_opstr (c, opstr));
} }
inline unsigned int calculate_serialized_size (const OpStr &opstr, inline unsigned int calculate_serialized_size (const OpStr &opstr,
bool has_localsubr=true) const bool has_localsubr=true) const
{ {
if (drop_hints && DictOpSet::is_hint_op (opstr.op)) if (drop_hints && DictOpSet::is_hint_op (opstr.op))
return 0; return 0;
if (opstr.op == OpCode_Subrs) if (opstr.op == OpCode_Subrs)
{ {
if (desubroutinize || !has_localsubr) if (desubroutinize || !has_localsubr)
return 0; return 0;
else else
return OpCode_Size (OpCode_shortint) + 2 + OpCode_Size (opstr.op); return OpCode_Size (OpCode_shortint) + 2 + OpCode_Size (opstr.op);
} }
else else
return opstr.str.len; return opstr.str.len;
@ -288,15 +288,15 @@ struct CFFPrivateDict_OpSerializer : OpSerializer
struct FlattenParam struct FlattenParam
{ {
StrBuff &flatStr; StrBuff &flatStr;
bool drop_hints; bool drop_hints;
}; };
template <typename ACC, typename ENV, typename OPSET> template <typename ACC, typename ENV, typename OPSET>
struct SubrFlattener struct SubrFlattener
{ {
inline SubrFlattener (const ACC &acc_, inline SubrFlattener (const ACC &acc_,
const hb_vector_t<hb_codepoint_t> &glyphs_, const hb_vector_t<hb_codepoint_t> &glyphs_,
bool drop_hints_) bool drop_hints_)
: acc (acc_), : acc (acc_),
glyphs (glyphs_), glyphs (glyphs_),
drop_hints (drop_hints_) drop_hints (drop_hints_)
@ -317,7 +317,7 @@ struct SubrFlattener
interp.env.init (str, acc, fd); interp.env.init (str, acc, fd);
FlattenParam param = { flat_charstrings[i], drop_hints }; FlattenParam param = { flat_charstrings[i], drop_hints };
if (unlikely (!interp.interpret (param))) if (unlikely (!interp.interpret (param)))
return false; return false;
} }
return true; return true;
} }
@ -349,7 +349,7 @@ struct SubrClosures
{ {
local_closures[i] = hb_set_create (); local_closures[i] = hb_set_create ();
if (local_closures[i] == hb_set_get_empty ()) if (local_closures[i] == hb_set_get_empty ())
valid = false; valid = false;
} }
} }
@ -400,9 +400,9 @@ struct ParsedCSOp : OpStr
unsigned int subr_num; unsigned int subr_num;
protected: protected:
bool drop_flag : 1; bool drop_flag : 1;
bool keep_flag : 1; bool keep_flag : 1;
bool skip_flag : 1; bool skip_flag : 1;
}; };
struct ParsedCStr : ParsedValues<ParsedCSOp> struct ParsedCStr : ParsedValues<ParsedCSOp>
@ -427,7 +427,7 @@ struct ParsedCStr : ParsedValues<ParsedCSOp>
{ {
unsigned int parsed_len = get_count (); unsigned int parsed_len = get_count ();
if (likely (parsed_len > 0)) if (likely (parsed_len > 0))
values[parsed_len-1].set_skip (); values[parsed_len-1].set_skip ();
ParsedCSOp val; ParsedCSOp val;
val.init (subr_num); val.init (subr_num);
@ -445,7 +445,7 @@ struct ParsedCStr : ParsedValues<ParsedCSOp>
inline bool at_end (unsigned int pos) const inline bool at_end (unsigned int pos) const
{ {
return ((pos + 1 >= values.len) /* CFF2 */ return ((pos + 1 >= values.len) /* CFF2 */
|| (values[pos + 1].op == OpCode_return)); || (values[pos + 1].op == OpCode_return));
} }
inline bool is_parsed (void) const { return parsed; } inline bool is_parsed (void) const { return parsed; }
@ -492,9 +492,9 @@ struct ParsedCStrs : hb_vector_t<ParsedCStr>
struct SubrSubsetParam struct SubrSubsetParam
{ {
inline void init (ParsedCStr *parsed_charstring_, inline void init (ParsedCStr *parsed_charstring_,
ParsedCStrs *parsed_global_subrs_, ParsedCStrs *parsed_local_subrs_, ParsedCStrs *parsed_global_subrs_, ParsedCStrs *parsed_local_subrs_,
hb_set_t *global_closure_, hb_set_t *local_closure_, hb_set_t *global_closure_, hb_set_t *local_closure_,
bool drop_hints_) bool drop_hints_)
{ {
parsed_charstring = parsed_charstring_; parsed_charstring = parsed_charstring_;
current_parsed_str = parsed_charstring; current_parsed_str = parsed_charstring;
@ -510,17 +510,17 @@ struct SubrSubsetParam
switch (context.type) switch (context.type)
{ {
case CSType_CharString: case CSType_CharString:
return parsed_charstring; return parsed_charstring;
case CSType_LocalSubr: case CSType_LocalSubr:
if (likely (context.subr_num < parsed_local_subrs->len)) if (likely (context.subr_num < parsed_local_subrs->len))
return &(*parsed_local_subrs)[context.subr_num]; return &(*parsed_local_subrs)[context.subr_num];
break; break;
case CSType_GlobalSubr: case CSType_GlobalSubr:
if (likely (context.subr_num < parsed_global_subrs->len)) if (likely (context.subr_num < parsed_global_subrs->len))
return &(*parsed_global_subrs)[context.subr_num]; return &(*parsed_global_subrs)[context.subr_num];
break; break;
} }
return nullptr; return nullptr;
} }
@ -542,7 +542,7 @@ struct SubrSubsetParam
ParsedCStrs *parsed_local_subrs; ParsedCStrs *parsed_local_subrs;
hb_set_t *global_closure; hb_set_t *global_closure;
hb_set_t *local_closure; hb_set_t *local_closure;
bool drop_hints; bool drop_hints;
}; };
struct SubrRemap : Remap struct SubrRemap : Remap
@ -556,7 +556,7 @@ struct SubrRemap : Remap
for (hb_codepoint_t old_num = 0; old_num < len; old_num++) for (hb_codepoint_t old_num = 0; old_num < len; old_num++)
{ {
if (hb_set_has (closure, old_num)) if (hb_set_has (closure, old_num))
add (old_num); add (old_num);
} }
if (get_count () < 1240) if (get_count () < 1240)
@ -619,7 +619,7 @@ struct SubrRemaps
local_remaps.fini_deep (); local_remaps.fini_deep ();
} }
SubrRemap global_remap; SubrRemap global_remap;
hb_vector_t<SubrRemap> local_remaps; hb_vector_t<SubrRemap> local_remaps;
}; };
@ -683,12 +683,12 @@ struct SubrSubsetter
SubrSubsetParam param; SubrSubsetParam param;
param.init (&parsed_charstrings[i], param.init (&parsed_charstrings[i],
&parsed_global_subrs, &parsed_local_subrs[fd], &parsed_global_subrs, &parsed_local_subrs[fd],
closures.global_closure, closures.local_closures[fd], closures.global_closure, closures.local_closures[fd],
drop_hints); drop_hints);
if (unlikely (!interp.interpret (param))) if (unlikely (!interp.interpret (param)))
return false; return false;
/* finalize parsed string esp. copy CFF1 width or CFF2 vsindex to the parsed charstring for encoding */ /* finalize parsed string esp. copy CFF1 width or CFF2 vsindex to the parsed charstring for encoding */
SUBSETTER::finalize_parsed_str (interp.env, param, parsed_charstrings[i]); SUBSETTER::finalize_parsed_str (interp.env, param, parsed_charstrings[i]);
@ -699,33 +699,33 @@ struct SubrSubsetter
/* mark hint ops and arguments for drop */ /* mark hint ops and arguments for drop */
for (unsigned int i = 0; i < glyphs.len; i++) for (unsigned int i = 0; i < glyphs.len; i++)
{ {
unsigned int fd = acc.fdSelect->get_fd (glyphs[i]); unsigned int fd = acc.fdSelect->get_fd (glyphs[i]);
SubrSubsetParam param; SubrSubsetParam param;
param.init (&parsed_charstrings[i], param.init (&parsed_charstrings[i],
&parsed_global_subrs, &parsed_local_subrs[fd], &parsed_global_subrs, &parsed_local_subrs[fd],
closures.global_closure, closures.local_closures[fd], closures.global_closure, closures.local_closures[fd],
drop_hints); drop_hints);
DropHintsParam drop; DropHintsParam drop;
if (drop_hints_in_str (parsed_charstrings[i], param, drop)) if (drop_hints_in_str (parsed_charstrings[i], param, drop))
{ {
parsed_charstrings[i].set_hint_dropped (); parsed_charstrings[i].set_hint_dropped ();
if (drop.vsindex_dropped) if (drop.vsindex_dropped)
parsed_charstrings[i].set_vsindex_dropped (); parsed_charstrings[i].set_vsindex_dropped ();
} }
} }
/* after dropping hints recreate closures of actually used subrs */ /* after dropping hints recreate closures of actually used subrs */
closures.reset (); closures.reset ();
for (unsigned int i = 0; i < glyphs.len; i++) for (unsigned int i = 0; i < glyphs.len; i++)
{ {
unsigned int fd = acc.fdSelect->get_fd (glyphs[i]); unsigned int fd = acc.fdSelect->get_fd (glyphs[i]);
SubrSubsetParam param; SubrSubsetParam param;
param.init (&parsed_charstrings[i], param.init (&parsed_charstrings[i],
&parsed_global_subrs, &parsed_local_subrs[fd], &parsed_global_subrs, &parsed_local_subrs[fd],
closures.global_closure, closures.local_closures[fd], closures.global_closure, closures.local_closures[fd],
drop_hints); drop_hints);
collect_subr_refs_in_str (parsed_charstrings[i], param); collect_subr_refs_in_str (parsed_charstrings[i], param);
} }
} }
@ -742,7 +742,7 @@ struct SubrSubsetter
{ {
unsigned int fd = acc.fdSelect->get_fd (glyphs[i]); unsigned int fd = acc.fdSelect->get_fd (glyphs[i]);
if (unlikely (!encode_str (parsed_charstrings[i], fd, buffArray[i]))) if (unlikely (!encode_str (parsed_charstrings[i], fd, buffArray[i])))
return false; return false;
} }
return true; return true;
} }
@ -758,8 +758,8 @@ struct SubrSubsetter
hb_codepoint_t new_num = remap[old_num]; hb_codepoint_t new_num = remap[old_num];
if (new_num != CFF_UNDEF_CODE) if (new_num != CFF_UNDEF_CODE)
{ {
if (unlikely (!encode_str (subrs[old_num], fd, buffArray[new_num]))) if (unlikely (!encode_str (subrs[old_num], fd, buffArray[new_num])))
return false; return false;
} }
} }
return true; return true;
@ -780,8 +780,8 @@ struct SubrSubsetter
{ {
inline DropHintsParam (void) inline DropHintsParam (void)
: seen_moveto (false), : seen_moveto (false),
ends_in_hint (false), ends_in_hint (false),
vsindex_dropped (false) {} vsindex_dropped (false) {}
bool seen_moveto; bool seen_moveto;
bool ends_in_hint; bool ends_in_hint;
@ -789,8 +789,8 @@ struct SubrSubsetter
}; };
inline bool drop_hints_in_subr (ParsedCStr &str, unsigned int pos, inline bool drop_hints_in_subr (ParsedCStr &str, unsigned int pos,
ParsedCStrs &subrs, unsigned int subr_num, ParsedCStrs &subrs, unsigned int subr_num,
const SubrSubsetParam &param, DropHintsParam &drop) const SubrSubsetParam &param, DropHintsParam &drop)
{ {
drop.ends_in_hint = false; drop.ends_in_hint = false;
bool has_hint = drop_hints_in_str (subrs[subr_num], param, drop); bool has_hint = drop_hints_in_str (subrs[subr_num], param, drop);
@ -803,7 +803,7 @@ struct SubrSubsetter
/* if this subr call is at the end of the parent subr, propagate the flag /* if this subr call is at the end of the parent subr, propagate the flag
* otherwise reset the flag */ * otherwise reset the flag */
if (!str.at_end (pos)) if (!str.at_end (pos))
drop.ends_in_hint = false; drop.ends_in_hint = false;
} }
return has_hint; return has_hint;
@ -819,64 +819,64 @@ struct SubrSubsetter
bool has_hint = false; bool has_hint = false;
switch (str.values[pos].op) switch (str.values[pos].op)
{ {
case OpCode_callsubr: case OpCode_callsubr:
has_hint = drop_hints_in_subr (str, pos, has_hint = drop_hints_in_subr (str, pos,
*param.parsed_local_subrs, str.values[pos].subr_num, *param.parsed_local_subrs, str.values[pos].subr_num,
param, drop); param, drop);
break; break;
case OpCode_callgsubr: case OpCode_callgsubr:
has_hint = drop_hints_in_subr (str, pos, has_hint = drop_hints_in_subr (str, pos,
*param.parsed_global_subrs, str.values[pos].subr_num, *param.parsed_global_subrs, str.values[pos].subr_num,
param, drop); param, drop);
break; break;
case OpCode_rmoveto: case OpCode_rmoveto:
case OpCode_hmoveto: case OpCode_hmoveto:
case OpCode_vmoveto: case OpCode_vmoveto:
drop.seen_moveto = true; drop.seen_moveto = true;
break; break;
case OpCode_hintmask: case OpCode_hintmask:
case OpCode_cntrmask: case OpCode_cntrmask:
if (drop.seen_moveto) if (drop.seen_moveto)
{ {
str.values[pos].set_drop (); str.values[pos].set_drop ();
break; break;
} }
HB_FALLTHROUGH; HB_FALLTHROUGH;
case OpCode_hstemhm: case OpCode_hstemhm:
case OpCode_vstemhm: case OpCode_vstemhm:
case OpCode_hstem: case OpCode_hstem:
case OpCode_vstem: case OpCode_vstem:
has_hint = true; has_hint = true;
str.values[pos].set_drop (); str.values[pos].set_drop ();
if (str.at_end (pos)) if (str.at_end (pos))
drop.ends_in_hint = true; drop.ends_in_hint = true;
break; break;
case OpCode_dotsection: case OpCode_dotsection:
str.values[pos].set_drop (); str.values[pos].set_drop ();
break; break;
default: default:
/* NONE */ /* NONE */
break; break;
} }
if (has_hint) if (has_hint)
{ {
for (int i = pos - 1; i >= 0; i--) for (int i = pos - 1; i >= 0; i--)
{ {
ParsedCSOp &csop = str.values[(unsigned)i]; ParsedCSOp &csop = str.values[(unsigned)i];
if (csop.for_drop ()) if (csop.for_drop ())
break; break;
csop.set_drop (); csop.set_drop ();
if (csop.op == OpCode_vsindexcs) if (csop.op == OpCode_vsindexcs)
drop.vsindex_dropped = true; drop.vsindex_dropped = true;
} }
seen_hint |= has_hint; seen_hint |= has_hint;
} }
} }
@ -884,9 +884,9 @@ struct SubrSubsetter
} }
inline void collect_subr_refs_in_subr (ParsedCStr &str, unsigned int pos, inline void collect_subr_refs_in_subr (ParsedCStr &str, unsigned int pos,
unsigned int subr_num, ParsedCStrs &subrs, unsigned int subr_num, ParsedCStrs &subrs,
hb_set_t *closure, hb_set_t *closure,
const SubrSubsetParam &param) const SubrSubsetParam &param)
{ {
hb_set_add (closure, subr_num); hb_set_add (closure, subr_num);
collect_subr_refs_in_str (subrs[subr_num], param); collect_subr_refs_in_str (subrs[subr_num], param);
@ -898,22 +898,22 @@ struct SubrSubsetter
{ {
if (!str.values[pos].for_drop ()) if (!str.values[pos].for_drop ())
{ {
switch (str.values[pos].op) switch (str.values[pos].op)
{ {
case OpCode_callsubr: case OpCode_callsubr:
collect_subr_refs_in_subr (str, pos, collect_subr_refs_in_subr (str, pos,
str.values[pos].subr_num, *param.parsed_local_subrs, str.values[pos].subr_num, *param.parsed_local_subrs,
param.local_closure, param); param.local_closure, param);
break; break;
case OpCode_callgsubr: case OpCode_callgsubr:
collect_subr_refs_in_subr (str, pos, collect_subr_refs_in_subr (str, pos,
str.values[pos].subr_num, *param.parsed_global_subrs, str.values[pos].subr_num, *param.parsed_global_subrs,
param.global_closure, param); param.global_closure, param);
break; break;
default: break; default: break;
} }
} }
} }
} }
@ -929,42 +929,42 @@ struct SubrSubsetter
{ {
encoder.encode_num (str.prefix_num ()); encoder.encode_num (str.prefix_num ());
if (str.prefix_op () != OpCode_Invalid) if (str.prefix_op () != OpCode_Invalid)
encoder.encode_op (str.prefix_op ()); encoder.encode_op (str.prefix_op ());
} }
for (unsigned int i = 0; i < str.get_count(); i++) for (unsigned int i = 0; i < str.get_count(); i++)
{ {
const ParsedCSOp &opstr = str.values[i]; const ParsedCSOp &opstr = str.values[i];
if (!opstr.for_drop () && !opstr.for_skip ()) if (!opstr.for_drop () && !opstr.for_skip ())
{ {
switch (opstr.op) switch (opstr.op)
{ {
case OpCode_callsubr: case OpCode_callsubr:
encoder.encode_int (remaps.local_remaps[fd].biased_num (opstr.subr_num)); encoder.encode_int (remaps.local_remaps[fd].biased_num (opstr.subr_num));
encoder.encode_op (OpCode_callsubr); encoder.encode_op (OpCode_callsubr);
break; break;
case OpCode_callgsubr: case OpCode_callgsubr:
encoder.encode_int (remaps.global_remap.biased_num (opstr.subr_num)); encoder.encode_int (remaps.global_remap.biased_num (opstr.subr_num));
encoder.encode_op (OpCode_callgsubr); encoder.encode_op (OpCode_callgsubr);
break; break;
default: default:
encoder.copy_str (opstr.str); encoder.copy_str (opstr.str);
break; break;
} }
} }
} }
return !encoder.is_error (); return !encoder.is_error ();
} }
protected: protected:
SubrClosures closures; SubrClosures closures;
ParsedCStrs parsed_charstrings; ParsedCStrs parsed_charstrings;
ParsedCStrs parsed_global_subrs; ParsedCStrs parsed_global_subrs;
hb_vector_t<ParsedCStrs> parsed_local_subrs; hb_vector_t<ParsedCStrs> parsed_local_subrs;
SubrRemaps remaps; SubrRemaps remaps;
private: private:
typedef typename SUBRS::count_type subr_count_type; typedef typename SUBRS::count_type subr_count_type;
@ -973,21 +973,21 @@ struct SubrSubsetter
HB_INTERNAL bool HB_INTERNAL bool
hb_plan_subset_cff_fdselect (const hb_vector_t<hb_codepoint_t> &glyphs, hb_plan_subset_cff_fdselect (const hb_vector_t<hb_codepoint_t> &glyphs,
unsigned int fdCount, unsigned int fdCount,
const CFF::FDSelect &src, /* IN */ const CFF::FDSelect &src, /* IN */
unsigned int &subset_fd_count /* OUT */, unsigned int &subset_fd_count /* OUT */,
unsigned int &subset_fdselect_size /* OUT */, unsigned int &subset_fdselect_size /* OUT */,
unsigned int &subset_fdselect_format /* OUT */, unsigned int &subset_fdselect_format /* OUT */,
hb_vector_t<CFF::code_pair> &fdselect_ranges /* OUT */, hb_vector_t<CFF::code_pair> &fdselect_ranges /* OUT */,
CFF::Remap &fdmap /* OUT */); CFF::Remap &fdmap /* OUT */);
HB_INTERNAL bool HB_INTERNAL bool
hb_serialize_cff_fdselect (hb_serialize_context_t *c, hb_serialize_cff_fdselect (hb_serialize_context_t *c,
unsigned int num_glyphs, unsigned int num_glyphs,
const CFF::FDSelect &src, const CFF::FDSelect &src,
unsigned int fd_count, unsigned int fd_count,
unsigned int fdselect_format, unsigned int fdselect_format,
unsigned int size, unsigned int size,
const hb_vector_t<CFF::code_pair> &fdselect_ranges); const hb_vector_t<CFF::code_pair> &fdselect_ranges);
#endif /* HB_SUBSET_CFF_COMMON_HH */ #endif /* HB_SUBSET_CFF_COMMON_HH */

View File

@ -119,20 +119,20 @@ struct CFF1TopDictValuesMod : CFF1TopDictValues
struct TopDictModifiers struct TopDictModifiers
{ {
inline TopDictModifiers (const CFF1SubTableOffsets &offsets_, inline TopDictModifiers (const CFF1SubTableOffsets &offsets_,
const unsigned int (&nameSIDs_)[NameDictValues::ValCount]) const unsigned int (&nameSIDs_)[NameDictValues::ValCount])
: offsets (offsets_), : offsets (offsets_),
nameSIDs (nameSIDs_) nameSIDs (nameSIDs_)
{} {}
const CFF1SubTableOffsets &offsets; const CFF1SubTableOffsets &offsets;
const unsigned int (&nameSIDs)[NameDictValues::ValCount]; const unsigned int (&nameSIDs)[NameDictValues::ValCount];
}; };
struct CFF1TopDict_OpSerializer : CFFTopDict_OpSerializer<CFF1TopDictVal> struct CFF1TopDict_OpSerializer : CFFTopDict_OpSerializer<CFF1TopDictVal>
{ {
inline bool serialize (hb_serialize_context_t *c, inline bool serialize (hb_serialize_context_t *c,
const CFF1TopDictVal &opstr, const CFF1TopDictVal &opstr,
const TopDictModifiers &mod) const const TopDictModifiers &mod) const
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
@ -140,22 +140,22 @@ struct CFF1TopDict_OpSerializer : CFFTopDict_OpSerializer<CFF1TopDictVal>
switch (op) switch (op)
{ {
case OpCode_charset: case OpCode_charset:
return_trace (FontDict::serialize_offset4_op(c, op, mod.offsets.charsetInfo.offset)); return_trace (FontDict::serialize_offset4_op(c, op, mod.offsets.charsetInfo.offset));
case OpCode_Encoding: case OpCode_Encoding:
return_trace (FontDict::serialize_offset4_op(c, op, mod.offsets.encodingOffset)); return_trace (FontDict::serialize_offset4_op(c, op, mod.offsets.encodingOffset));
case OpCode_Private: case OpCode_Private:
{ {
if (unlikely (!UnsizedByteStr::serialize_int2 (c, mod.offsets.privateDictInfo.size))) if (unlikely (!UnsizedByteStr::serialize_int2 (c, mod.offsets.privateDictInfo.size)))
return_trace (false); return_trace (false);
if (unlikely (!UnsizedByteStr::serialize_int4 (c, mod.offsets.privateDictInfo.offset))) if (unlikely (!UnsizedByteStr::serialize_int4 (c, mod.offsets.privateDictInfo.offset)))
return_trace (false); return_trace (false);
HBUINT8 *p = c->allocate_size<HBUINT8> (1); HBUINT8 *p = c->allocate_size<HBUINT8> (1);
if (unlikely (p == nullptr)) return_trace (false); if (unlikely (p == nullptr)) return_trace (false);
p->set (OpCode_Private); p->set (OpCode_Private);
} }
break; break;
case OpCode_version: case OpCode_version:
case OpCode_Notice: case OpCode_Notice:
@ -166,23 +166,23 @@ struct CFF1TopDict_OpSerializer : CFFTopDict_OpSerializer<CFF1TopDictVal>
case OpCode_PostScript: case OpCode_PostScript:
case OpCode_BaseFontName: case OpCode_BaseFontName:
case OpCode_FontName: case OpCode_FontName:
return_trace (FontDict::serialize_offset2_op(c, op, mod.nameSIDs[NameDictValues::name_op_to_index (op)])); return_trace (FontDict::serialize_offset2_op(c, op, mod.nameSIDs[NameDictValues::name_op_to_index (op)]));
case OpCode_ROS: case OpCode_ROS:
{ {
/* for registry & ordering, reassigned SIDs are serialized /* for registry & ordering, reassigned SIDs are serialized
* for supplement, the original byte string is copied along with the op code */ * for supplement, the original byte string is copied along with the op code */
OpStr supp_op; OpStr supp_op;
supp_op.op = op; supp_op.op = op;
supp_op.str.str = opstr.str.str + opstr.last_arg_offset; supp_op.str.str = opstr.str.str + opstr.last_arg_offset;
assert (opstr.str.len >= opstr.last_arg_offset + 3); assert (opstr.str.len >= opstr.last_arg_offset + 3);
supp_op.str.len = opstr.str.len - opstr.last_arg_offset; supp_op.str.len = opstr.str.len - opstr.last_arg_offset;
return_trace (UnsizedByteStr::serialize_int2 (c, mod.nameSIDs[NameDictValues::registry]) && return_trace (UnsizedByteStr::serialize_int2 (c, mod.nameSIDs[NameDictValues::registry]) &&
UnsizedByteStr::serialize_int2 (c, mod.nameSIDs[NameDictValues::ordering]) && UnsizedByteStr::serialize_int2 (c, mod.nameSIDs[NameDictValues::ordering]) &&
copy_opstr (c, supp_op)); copy_opstr (c, supp_op));
} }
default: default:
return_trace (CFFTopDict_OpSerializer<CFF1TopDictVal>::serialize (c, opstr, mod.offsets)); return_trace (CFFTopDict_OpSerializer<CFF1TopDictVal>::serialize (c, opstr, mod.offsets));
} }
return_trace (true); return_trace (true);
} }
@ -194,10 +194,10 @@ struct CFF1TopDict_OpSerializer : CFFTopDict_OpSerializer<CFF1TopDictVal>
{ {
case OpCode_charset: case OpCode_charset:
case OpCode_Encoding: case OpCode_Encoding:
return OpCode_Size (OpCode_longintdict) + 4 + OpCode_Size (op); return OpCode_Size (OpCode_longintdict) + 4 + OpCode_Size (op);
case OpCode_Private: case OpCode_Private:
return OpCode_Size (OpCode_longintdict) + 4 + OpCode_Size (OpCode_shortint) + 2 + OpCode_Size (OpCode_Private); return OpCode_Size (OpCode_longintdict) + 4 + OpCode_Size (OpCode_shortint) + 2 + OpCode_Size (OpCode_Private);
case OpCode_version: case OpCode_version:
case OpCode_Notice: case OpCode_Notice:
@ -208,13 +208,13 @@ struct CFF1TopDict_OpSerializer : CFFTopDict_OpSerializer<CFF1TopDictVal>
case OpCode_PostScript: case OpCode_PostScript:
case OpCode_BaseFontName: case OpCode_BaseFontName:
case OpCode_FontName: case OpCode_FontName:
return OpCode_Size (OpCode_shortint) + 2 + OpCode_Size (op); return OpCode_Size (OpCode_shortint) + 2 + OpCode_Size (op);
case OpCode_ROS: case OpCode_ROS:
return ((OpCode_Size (OpCode_shortint) + 2) * 2) + (opstr.str.len - opstr.last_arg_offset)/* supplement + op */; return ((OpCode_Size (OpCode_shortint) + 2) * 2) + (opstr.str.len - opstr.last_arg_offset)/* supplement + op */;
default: default:
return CFFTopDict_OpSerializer<CFF1TopDictVal>::calculate_serialized_size (opstr); return CFFTopDict_OpSerializer<CFF1TopDictVal>::calculate_serialized_size (opstr);
} }
} }
}; };
@ -222,8 +222,8 @@ struct CFF1TopDict_OpSerializer : CFFTopDict_OpSerializer<CFF1TopDictVal>
struct FontDictValuesMod struct FontDictValuesMod
{ {
inline void init (const CFF1FontDictValues *base_, inline void init (const CFF1FontDictValues *base_,
unsigned int fontName_, unsigned int fontName_,
const TableInfo &privateDictInfo_) const TableInfo &privateDictInfo_)
{ {
base = base_; base = base_;
fontName = fontName_; fontName = fontName_;
@ -238,15 +238,15 @@ struct FontDictValuesMod
inline const OpStr &operator [] (unsigned int i) const { return (*base)[i]; } inline const OpStr &operator [] (unsigned int i) const { return (*base)[i]; }
const CFF1FontDictValues *base; const CFF1FontDictValues *base;
TableInfo privateDictInfo; TableInfo privateDictInfo;
unsigned int fontName; unsigned int fontName;
}; };
struct CFF1FontDict_OpSerializer : CFFFontDict_OpSerializer struct CFF1FontDict_OpSerializer : CFFFontDict_OpSerializer
{ {
inline bool serialize (hb_serialize_context_t *c, inline bool serialize (hb_serialize_context_t *c,
const OpStr &opstr, const OpStr &opstr,
const FontDictValuesMod &mod) const const FontDictValuesMod &mod) const
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
@ -284,16 +284,16 @@ struct CFF1CSOpSet_Flatten : CFF1CSOpSet<CFF1CSOpSet_Flatten, FlattenParam>
case OpCode_hintmask: case OpCode_hintmask:
case OpCode_cntrmask: case OpCode_cntrmask:
case OpCode_dotsection: case OpCode_dotsection:
if (param.drop_hints) if (param.drop_hints)
{ {
env.clear_args (); env.clear_args ();
return; return;
} }
HB_FALLTHROUGH; HB_FALLTHROUGH;
default: default:
SUPER::flush_args_and_op (op, env, param); SUPER::flush_args_and_op (op, env, param);
break; break;
} }
} }
static inline void flush_args (CFF1CSInterpEnv &env, FlattenParam& param) static inline void flush_args (CFF1CSInterpEnv &env, FlattenParam& param)
@ -324,7 +324,7 @@ struct CFF1CSOpSet_Flatten : CFF1CSOpSet<CFF1CSOpSet_Flatten, FlattenParam>
{ {
StrEncoder encoder (param.flatStr); StrEncoder encoder (param.flatStr);
for (unsigned int i = 0; i < env.hintmask_size; i++) for (unsigned int i = 0; i < env.hintmask_size; i++)
encoder.encode_byte (env.substr[i]); encoder.encode_byte (env.substr[i]);
} }
} }
@ -343,7 +343,7 @@ struct RangeList : hb_vector_t<code_pair>
code_pair &pair = (*this)[i - 1]; code_pair &pair = (*this)[i - 1];
unsigned int nLeft = last_glyph - pair.glyph - 1; unsigned int nLeft = last_glyph - pair.glyph - 1;
if (nLeft >= 0x100) if (nLeft >= 0x100)
two_byte = true; two_byte = true;
last_glyph = pair.glyph; last_glyph = pair.glyph;
pair.glyph = nLeft; pair.glyph = nLeft;
} }
@ -358,37 +358,37 @@ struct CFF1CSOpSet_SubrSubset : CFF1CSOpSet<CFF1CSOpSet_SubrSubset, SubrSubsetPa
switch (op) { switch (op) {
case OpCode_return: case OpCode_return:
param.current_parsed_str->add_op (op, env.substr); param.current_parsed_str->add_op (op, env.substr);
param.current_parsed_str->set_parsed (); param.current_parsed_str->set_parsed ();
env.returnFromSubr (); env.returnFromSubr ();
param.set_current_str (env); param.set_current_str (env);
break; break;
case OpCode_endchar: case OpCode_endchar:
param.current_parsed_str->add_op (op, env.substr); param.current_parsed_str->add_op (op, env.substr);
param.current_parsed_str->set_parsed (); param.current_parsed_str->set_parsed ();
SUPER::process_op (op, env, param); SUPER::process_op (op, env, param);
break; break;
case OpCode_callsubr: case OpCode_callsubr:
process_call_subr (op, CSType_LocalSubr, env, param, env.localSubrs, param.local_closure); process_call_subr (op, CSType_LocalSubr, env, param, env.localSubrs, param.local_closure);
break; break;
case OpCode_callgsubr: case OpCode_callgsubr:
process_call_subr (op, CSType_GlobalSubr, env, param, env.globalSubrs, param.global_closure); process_call_subr (op, CSType_GlobalSubr, env, param, env.globalSubrs, param.global_closure);
break; break;
default: default:
SUPER::process_op (op, env, param); SUPER::process_op (op, env, param);
param.current_parsed_str->add_op (op, env.substr); param.current_parsed_str->add_op (op, env.substr);
break; break;
} }
} }
protected: protected:
static inline void process_call_subr (OpCode op, CSType type, static inline void process_call_subr (OpCode op, CSType type,
CFF1CSInterpEnv &env, SubrSubsetParam& param, CFF1CSInterpEnv &env, SubrSubsetParam& param,
CFF1BiasedSubrs& subrs, hb_set_t *closure) CFF1BiasedSubrs& subrs, hb_set_t *closure)
{ {
SubByteStr substr = env.substr; SubByteStr substr = env.substr;
env.callSubr (subrs, type); env.callSubr (subrs, type);
@ -417,9 +417,9 @@ struct CFF1SubrSubsetter : SubrSubsetter<CFF1SubrSubsetter, CFF1Subrs, const OT:
{ {
ParsedCStr *parsed_str = param.get_parsed_str_for_context (env.callStack[i]); ParsedCStr *parsed_str = param.get_parsed_str_for_context (env.callStack[i]);
if (likely (parsed_str != nullptr)) if (likely (parsed_str != nullptr))
parsed_str->set_parsed (); parsed_str->set_parsed ();
else else
env.set_error (); env.set_error ();
} }
} }
}; };
@ -487,27 +487,27 @@ struct cff_subset_plan {
code = acc.glyph_to_code (orig_glyph); code = acc.glyph_to_code (orig_glyph);
if (code == CFF_UNDEF_CODE) if (code == CFF_UNDEF_CODE)
{ {
subset_enc_num_codes = glyph - 1; subset_enc_num_codes = glyph - 1;
break; break;
} }
if (code != last_code + 1) if (code != last_code + 1)
{ {
code_pair pair = { code, glyph }; code_pair pair = { code, glyph };
subset_enc_code_ranges.push (pair); subset_enc_code_ranges.push (pair);
} }
last_code = code; last_code = code;
if (encoding != &Null(Encoding)) if (encoding != &Null(Encoding))
{ {
hb_codepoint_t sid = acc.glyph_to_sid (orig_glyph); hb_codepoint_t sid = acc.glyph_to_sid (orig_glyph);
encoding->get_supplement_codes (sid, supp_codes); encoding->get_supplement_codes (sid, supp_codes);
for (unsigned int i = 0; i < supp_codes.len; i++) for (unsigned int i = 0; i < supp_codes.len; i++)
{ {
code_pair pair = { supp_codes[i], sid }; code_pair pair = { supp_codes[i], sid };
subset_enc_supp_codes.push (pair); subset_enc_supp_codes.push (pair);
} }
supp_size += SuppEncoding::static_size * supp_codes.len; supp_size += SuppEncoding::static_size * supp_codes.len;
} }
} }
supp_codes.fini (); supp_codes.fini ();
@ -524,9 +524,9 @@ struct cff_subset_plan {
subset_enc_format = 1; subset_enc_format = 1;
return Encoding::calculate_serialized_size ( return Encoding::calculate_serialized_size (
subset_enc_format, subset_enc_format,
subset_enc_format? subset_enc_code_ranges.len: subset_enc_num_codes, subset_enc_format? subset_enc_code_ranges.len: subset_enc_num_codes,
subset_enc_supp_codes.len); subset_enc_supp_codes.len);
} }
inline unsigned int plan_subset_charset (const OT::cff1::accelerator_subset_t &acc, hb_subset_plan_t *plan) inline unsigned int plan_subset_charset (const OT::cff1::accelerator_subset_t &acc, hb_subset_plan_t *plan)
@ -542,12 +542,12 @@ struct cff_subset_plan {
sid = acc.glyph_to_sid (orig_glyph); sid = acc.glyph_to_sid (orig_glyph);
if (!acc.is_CID ()) if (!acc.is_CID ())
sid = sidmap.add (sid); sid = sidmap.add (sid);
if (sid != last_sid + 1) if (sid != last_sid + 1)
{ {
code_pair pair = { sid, glyph }; code_pair pair = { sid, glyph };
subset_charset_ranges.push (pair); subset_charset_ranges.push (pair);
} }
last_sid = sid; last_sid = sid;
} }
@ -568,8 +568,8 @@ struct cff_subset_plan {
subset_charset_format = 2; subset_charset_format = 2;
return Charset::calculate_serialized_size ( return Charset::calculate_serialized_size (
subset_charset_format, subset_charset_format,
subset_charset_format? subset_charset_ranges.len: plan->glyphs.len); subset_charset_format? subset_charset_ranges.len: plan->glyphs.len);
} }
inline bool collect_sids_in_dicts (const OT::cff1::accelerator_subset_t &acc) inline bool collect_sids_in_dicts (const OT::cff1::accelerator_subset_t &acc)
@ -582,21 +582,21 @@ struct cff_subset_plan {
unsigned int sid = acc.topDict.nameSIDs[i]; unsigned int sid = acc.topDict.nameSIDs[i];
if (sid != CFF_UNDEF_SID) if (sid != CFF_UNDEF_SID)
{ {
(void)sidmap.add (sid); (void)sidmap.add (sid);
topDictModSIDs[i] = sidmap[sid]; topDictModSIDs[i] = sidmap[sid];
} }
} }
if (acc.fdArray != &Null(CFF1FDArray)) if (acc.fdArray != &Null(CFF1FDArray))
for (unsigned int i = 0; i < orig_fdcount; i++) for (unsigned int i = 0; i < orig_fdcount; i++)
if (fdmap.includes (i)) if (fdmap.includes (i))
(void)sidmap.add (acc.fontDicts[i].fontName); (void)sidmap.add (acc.fontDicts[i].fontName);
return true; return true;
} }
inline bool create (const OT::cff1::accelerator_subset_t &acc, inline bool create (const OT::cff1::accelerator_subset_t &acc,
hb_subset_plan_t *plan) hb_subset_plan_t *plan)
{ {
/* make sure notdef is first */ /* make sure notdef is first */
if ((plan->glyphs.len == 0) || (plan->glyphs[0] != 0)) return false; if ((plan->glyphs.len == 0) || (plan->glyphs[0] != 0)) return false;
@ -612,8 +612,8 @@ struct cff_subset_plan {
for (unsigned int glyph = 0; glyph < plan->glyphs.len; glyph++) for (unsigned int glyph = 0; glyph < plan->glyphs.len; glyph++)
{ {
if (plan->glyphs[glyph] != glyph) { if (plan->glyphs[glyph] != glyph) {
gid_renum = true; gid_renum = true;
break; break;
} }
} }
@ -635,32 +635,32 @@ struct cff_subset_plan {
bool need_to_add_set = (subset_charset && !acc.topDict.has_op (OpCode_charset)); bool need_to_add_set = (subset_charset && !acc.topDict.has_op (OpCode_charset));
if (need_to_add_enc || need_to_add_set) if (need_to_add_enc || need_to_add_set)
{ {
if (need_to_add_enc) if (need_to_add_enc)
topdict_mod.add_op (OpCode_Encoding); topdict_mod.add_op (OpCode_Encoding);
if (need_to_add_set) if (need_to_add_set)
topdict_mod.add_op (OpCode_charset); topdict_mod.add_op (OpCode_charset);
} }
offsets.topDictInfo.offset = final_size; offsets.topDictInfo.offset = final_size;
CFF1TopDict_OpSerializer topSzr; CFF1TopDict_OpSerializer topSzr;
unsigned int topDictSize = TopDict::calculate_serialized_size (topdict_mod, topSzr); unsigned int topDictSize = TopDict::calculate_serialized_size (topdict_mod, topSzr);
offsets.topDictInfo.offSize = calcOffSize(topDictSize); offsets.topDictInfo.offSize = calcOffSize(topDictSize);
final_size += CFF1IndexOf<TopDict>::calculate_serialized_size<CFF1TopDictValuesMod> final_size += CFF1IndexOf<TopDict>::calculate_serialized_size<CFF1TopDictValuesMod>
(offsets.topDictInfo.offSize, (offsets.topDictInfo.offSize,
&topdict_mod, 1, topdict_sizes, topSzr); &topdict_mod, 1, topdict_sizes, topSzr);
} }
/* Determine re-mapping of font index as fdmap among other info */ /* Determine re-mapping of font index as fdmap among other info */
if (acc.fdSelect != &Null(CFF1FDSelect)) if (acc.fdSelect != &Null(CFF1FDSelect))
{ {
if (unlikely (!hb_plan_subset_cff_fdselect (plan->glyphs, if (unlikely (!hb_plan_subset_cff_fdselect (plan->glyphs,
orig_fdcount, orig_fdcount,
*acc.fdSelect, *acc.fdSelect,
subset_fdcount, subset_fdcount,
offsets.FDSelectInfo.size, offsets.FDSelectInfo.size,
subset_fdselect_format, subset_fdselect_format,
subset_fdselect_ranges, subset_fdselect_ranges,
fdmap))) fdmap)))
return false; return false;
} }
else else
fdmap.identity (1); fdmap.identity (1);
@ -669,10 +669,10 @@ struct cff_subset_plan {
{ {
/* SIDs for name strings in dicts are added before glyph names so they fit in 16-bit int range */ /* SIDs for name strings in dicts are added before glyph names so they fit in 16-bit int range */
if (unlikely (!collect_sids_in_dicts (acc))) if (unlikely (!collect_sids_in_dicts (acc)))
return false; return false;
assert (sidmap.get_count () <= 0x8000); assert (sidmap.get_count () <= 0x8000);
if (subset_charset) if (subset_charset)
offsets.charsetInfo.size = plan_subset_charset (acc, plan); offsets.charsetInfo.size = plan_subset_charset (acc, plan);
topdict_mod.reassignSIDs (sidmap); topdict_mod.reassignSIDs (sidmap);
} }
@ -688,9 +688,9 @@ struct cff_subset_plan {
{ {
/* Flatten global & local subrs */ /* Flatten global & local subrs */
SubrFlattener<const OT::cff1::accelerator_subset_t, CFF1CSInterpEnv, CFF1CSOpSet_Flatten> SubrFlattener<const OT::cff1::accelerator_subset_t, CFF1CSInterpEnv, CFF1CSOpSet_Flatten>
flattener(acc, plan->glyphs, plan->drop_hints); flattener(acc, plan->glyphs, plan->drop_hints);
if (!flattener.flatten (subset_charstrings)) if (!flattener.flatten (subset_charstrings))
return false; return false;
/* no global/local subroutines */ /* no global/local subroutines */
offsets.globalSubrsInfo.size = CFF1Subrs::calculate_serialized_size (1, 0, 0); offsets.globalSubrsInfo.size = CFF1Subrs::calculate_serialized_size (1, 0, 0);
@ -699,14 +699,14 @@ struct cff_subset_plan {
{ {
/* Subset subrs: collect used subroutines, leaving all unused ones behind */ /* Subset subrs: collect used subroutines, leaving all unused ones behind */
if (!subr_subsetter.subset (acc, plan->glyphs, plan->drop_hints)) if (!subr_subsetter.subset (acc, plan->glyphs, plan->drop_hints))
return false; return false;
/* encode charstrings, global subrs, local subrs with new subroutine numbers */ /* encode charstrings, global subrs, local subrs with new subroutine numbers */
if (!subr_subsetter.encode_charstrings (acc, plan->glyphs, subset_charstrings)) if (!subr_subsetter.encode_charstrings (acc, plan->glyphs, subset_charstrings))
return false; return false;
if (!subr_subsetter.encode_globalsubrs (subset_globalsubrs)) if (!subr_subsetter.encode_globalsubrs (subset_globalsubrs))
return false; return false;
/* global subrs */ /* global subrs */
unsigned int dataSize = subset_globalsubrs.total_size (); unsigned int dataSize = subset_globalsubrs.total_size ();
@ -715,26 +715,26 @@ struct cff_subset_plan {
/* local subrs */ /* local subrs */
if (!offsets.localSubrsInfos.resize (orig_fdcount)) if (!offsets.localSubrsInfos.resize (orig_fdcount))
return false; return false;
if (!subset_localsubrs.resize (orig_fdcount)) if (!subset_localsubrs.resize (orig_fdcount))
return false; return false;
for (unsigned int fd = 0; fd < orig_fdcount; fd++) for (unsigned int fd = 0; fd < orig_fdcount; fd++)
{ {
subset_localsubrs[fd].init (); subset_localsubrs[fd].init ();
offsets.localSubrsInfos[fd].init (); offsets.localSubrsInfos[fd].init ();
if (fdmap.includes (fd)) if (fdmap.includes (fd))
{ {
if (!subr_subsetter.encode_localsubrs (fd, subset_localsubrs[fd])) if (!subr_subsetter.encode_localsubrs (fd, subset_localsubrs[fd]))
return false; return false;
unsigned int dataSize = subset_localsubrs[fd].total_size (); unsigned int dataSize = subset_localsubrs[fd].total_size ();
if (dataSize > 0) if (dataSize > 0)
{ {
offsets.localSubrsInfos[fd].offset = final_size; offsets.localSubrsInfos[fd].offset = final_size;
offsets.localSubrsInfos[fd].offSize = calcOffSize (dataSize); offsets.localSubrsInfos[fd].offSize = calcOffSize (dataSize);
offsets.localSubrsInfos[fd].size = CFF1Subrs::calculate_serialized_size (offsets.localSubrsInfos[fd].offSize, subset_localsubrs[fd].len, dataSize); offsets.localSubrsInfos[fd].size = CFF1Subrs::calculate_serialized_size (offsets.localSubrsInfos[fd].offSize, subset_localsubrs[fd].len, dataSize);
} }
} }
} }
} }
@ -771,8 +771,8 @@ struct cff_subset_plan {
CFF1FontDict_OpSerializer fontSzr; CFF1FontDict_OpSerializer fontSzr;
unsigned int dictsSize = 0; unsigned int dictsSize = 0;
for (unsigned int i = 0; i < acc.fontDicts.len; i++) for (unsigned int i = 0; i < acc.fontDicts.len; i++)
if (fdmap.includes (i)) if (fdmap.includes (i))
dictsSize += FontDict::calculate_serialized_size (acc.fontDicts[i], fontSzr); dictsSize += FontDict::calculate_serialized_size (acc.fontDicts[i], fontSzr);
offsets.FDArrayInfo.offSize = calcOffSize (dictsSize); offsets.FDArrayInfo.offSize = calcOffSize (dictsSize);
final_size += CFF1Index::calculate_serialized_size (offsets.FDArrayInfo.offSize, subset_fdcount, dictsSize); final_size += CFF1Index::calculate_serialized_size (offsets.FDArrayInfo.offSize, subset_fdcount, dictsSize);
@ -792,23 +792,23 @@ struct cff_subset_plan {
{ {
if (fdmap.includes (i)) if (fdmap.includes (i))
{ {
bool has_localsubrs = offsets.localSubrsInfos[i].size > 0; bool has_localsubrs = offsets.localSubrsInfos[i].size > 0;
CFFPrivateDict_OpSerializer privSzr (desubroutinize, plan->drop_hints); CFFPrivateDict_OpSerializer privSzr (desubroutinize, plan->drop_hints);
unsigned int priv_size = PrivateDict::calculate_serialized_size (acc.privateDicts[i], privSzr, has_localsubrs); unsigned int priv_size = PrivateDict::calculate_serialized_size (acc.privateDicts[i], privSzr, has_localsubrs);
TableInfo privInfo = { final_size, priv_size, 0 }; TableInfo privInfo = { final_size, priv_size, 0 };
FontDictValuesMod fontdict_mod; FontDictValuesMod fontdict_mod;
if (!acc.is_CID ()) if (!acc.is_CID ())
fontdict_mod.init ( &Null(CFF1FontDictValues), CFF_UNDEF_SID, privInfo ); fontdict_mod.init ( &Null(CFF1FontDictValues), CFF_UNDEF_SID, privInfo );
else else
fontdict_mod.init ( &acc.fontDicts[i], sidmap[acc.fontDicts[i].fontName], privInfo ); fontdict_mod.init ( &acc.fontDicts[i], sidmap[acc.fontDicts[i].fontName], privInfo );
fontdicts_mod.push (fontdict_mod); fontdicts_mod.push (fontdict_mod);
final_size += privInfo.size; final_size += privInfo.size;
if (!plan->desubroutinize && has_localsubrs) if (!plan->desubroutinize && has_localsubrs)
{ {
offsets.localSubrsInfos[i].offset = final_size; offsets.localSubrsInfos[i].offset = final_size;
final_size += offsets.localSubrsInfos[i].size; final_size += offsets.localSubrsInfos[i].size;
} }
} }
} }
@ -816,12 +816,12 @@ struct cff_subset_plan {
offsets.privateDictInfo = fontdicts_mod[0].privateDictInfo; offsets.privateDictInfo = fontdicts_mod[0].privateDictInfo;
return ((subset_charstrings.len == plan->glyphs.len) return ((subset_charstrings.len == plan->glyphs.len)
&& (fontdicts_mod.len == subset_fdcount)); && (fontdicts_mod.len == subset_fdcount));
} }
inline unsigned int get_final_size (void) const { return final_size; } inline unsigned int get_final_size (void) const { return final_size; }
unsigned int final_size; unsigned int final_size;
hb_vector_t<unsigned int> topdict_sizes; hb_vector_t<unsigned int> topdict_sizes;
CFF1TopDictValuesMod topdict_mod; CFF1TopDictValuesMod topdict_mod;
CFF1SubTableOffsets offsets; CFF1SubTableOffsets offsets;
@ -836,36 +836,36 @@ struct cff_subset_plan {
* set to CFF_UNDEF_CODE if excluded from subset */ * set to CFF_UNDEF_CODE if excluded from subset */
Remap fdmap; Remap fdmap;
StrBuffArray subset_charstrings; StrBuffArray subset_charstrings;
StrBuffArray subset_globalsubrs; StrBuffArray subset_globalsubrs;
hb_vector_t<StrBuffArray> subset_localsubrs; hb_vector_t<StrBuffArray> subset_localsubrs;
hb_vector_t<FontDictValuesMod> fontdicts_mod; hb_vector_t<FontDictValuesMod> fontdicts_mod;
bool drop_hints; bool drop_hints;
bool gid_renum; bool gid_renum;
bool subset_encoding; bool subset_encoding;
uint8_t subset_enc_format; uint8_t subset_enc_format;
unsigned int subset_enc_num_codes; unsigned int subset_enc_num_codes;
RangeList subset_enc_code_ranges; RangeList subset_enc_code_ranges;
hb_vector_t<code_pair> subset_enc_supp_codes; hb_vector_t<code_pair> subset_enc_supp_codes;
uint8_t subset_charset_format; uint8_t subset_charset_format;
RangeList subset_charset_ranges; RangeList subset_charset_ranges;
bool subset_charset; bool subset_charset;
RemapSID sidmap; RemapSID sidmap;
unsigned int topDictModSIDs[NameDictValues::ValCount]; unsigned int topDictModSIDs[NameDictValues::ValCount];
bool desubroutinize; bool desubroutinize;
CFF1SubrSubsetter subr_subsetter; CFF1SubrSubsetter subr_subsetter;
}; };
static inline bool _write_cff1 (const cff_subset_plan &plan, static inline bool _write_cff1 (const cff_subset_plan &plan,
const OT::cff1::accelerator_subset_t &acc, const OT::cff1::accelerator_subset_t &acc,
const hb_vector_t<hb_codepoint_t>& glyphs, const hb_vector_t<hb_codepoint_t>& glyphs,
unsigned int dest_sz, unsigned int dest_sz,
void *dest) void *dest)
{ {
hb_serialize_context_t c (dest, dest_sz); hb_serialize_context_t c (dest, dest_sz);
@ -902,8 +902,8 @@ static inline bool _write_cff1 (const cff_subset_plan &plan,
CFF1TopDict_OpSerializer topSzr; CFF1TopDict_OpSerializer topSzr;
TopDictModifiers modifier (plan.offsets, plan.topDictModSIDs); TopDictModifiers modifier (plan.offsets, plan.topDictModSIDs);
if (unlikely (!dest->serialize (&c, plan.offsets.topDictInfo.offSize, if (unlikely (!dest->serialize (&c, plan.offsets.topDictInfo.offSize,
&plan.topdict_mod, 1, &plan.topdict_mod, 1,
plan.topdict_sizes, topSzr, modifier))) plan.topdict_sizes, topSzr, modifier)))
{ {
DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF top dict"); DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF top dict");
return false; return false;
@ -943,10 +943,10 @@ static inline bool _write_cff1 (const cff_subset_plan &plan,
Encoding *dest = c.start_embed<Encoding> (); Encoding *dest = c.start_embed<Encoding> ();
if (unlikely (dest == nullptr)) return false; if (unlikely (dest == nullptr)) return false;
if (unlikely (!dest->serialize (&c, if (unlikely (!dest->serialize (&c,
plan.subset_enc_format, plan.subset_enc_format,
plan.subset_enc_num_codes, plan.subset_enc_num_codes,
plan.subset_enc_code_ranges, plan.subset_enc_code_ranges,
plan.subset_enc_supp_codes))) plan.subset_enc_supp_codes)))
{ {
DEBUG_MSG (SUBSET, nullptr, "failed to serialize Encoding"); DEBUG_MSG (SUBSET, nullptr, "failed to serialize Encoding");
return false; return false;
@ -960,9 +960,9 @@ static inline bool _write_cff1 (const cff_subset_plan &plan,
Charset *dest = c.start_embed<Charset> (); Charset *dest = c.start_embed<Charset> ();
if (unlikely (dest == nullptr)) return false; if (unlikely (dest == nullptr)) return false;
if (unlikely (!dest->serialize (&c, if (unlikely (!dest->serialize (&c,
plan.subset_charset_format, plan.subset_charset_format,
plan.num_glyphs, plan.num_glyphs,
plan.subset_charset_ranges))) plan.subset_charset_ranges)))
{ {
DEBUG_MSG (SUBSET, nullptr, "failed to serialize Charset"); DEBUG_MSG (SUBSET, nullptr, "failed to serialize Charset");
return false; return false;
@ -975,8 +975,8 @@ static inline bool _write_cff1 (const cff_subset_plan &plan,
assert (plan.offsets.FDSelectInfo.offset == c.head - c.start); assert (plan.offsets.FDSelectInfo.offset == c.head - c.start);
if (unlikely (!hb_serialize_cff_fdselect (&c, glyphs.len, *acc.fdSelect, acc.fdCount, if (unlikely (!hb_serialize_cff_fdselect (&c, glyphs.len, *acc.fdSelect, acc.fdCount,
plan.subset_fdselect_format, plan.offsets.FDSelectInfo.size, plan.subset_fdselect_format, plan.offsets.FDSelectInfo.size,
plan.subset_fdselect_ranges))) plan.subset_fdselect_ranges)))
{ {
DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF subset FDSelect"); DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF subset FDSelect");
return false; return false;
@ -991,8 +991,8 @@ static inline bool _write_cff1 (const cff_subset_plan &plan,
if (unlikely (fda == nullptr)) return false; if (unlikely (fda == nullptr)) return false;
CFF1FontDict_OpSerializer fontSzr; CFF1FontDict_OpSerializer fontSzr;
if (unlikely (!fda->serialize (&c, plan.offsets.FDArrayInfo.offSize, if (unlikely (!fda->serialize (&c, plan.offsets.FDArrayInfo.offSize,
plan.fontdicts_mod, plan.fontdicts_mod,
fontSzr))) fontSzr)))
{ {
DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF FDArray"); DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF FDArray");
return false; return false;
@ -1027,18 +1027,18 @@ static inline bool _write_cff1 (const cff_subset_plan &plan,
result = pd->serialize (&c, acc.privateDicts[i], privSzr, subroffset); result = pd->serialize (&c, acc.privateDicts[i], privSzr, subroffset);
if (unlikely (!result)) if (unlikely (!result))
{ {
DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF Private Dict[%d]", i); DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF Private Dict[%d]", i);
return false; return false;
} }
if (plan.offsets.localSubrsInfos[i].size > 0) if (plan.offsets.localSubrsInfos[i].size > 0)
{ {
CFF1Subrs *dest = c.start_embed <CFF1Subrs> (); CFF1Subrs *dest = c.start_embed <CFF1Subrs> ();
if (unlikely (dest == nullptr)) return false; if (unlikely (dest == nullptr)) return false;
if (unlikely (!dest->serialize (&c, plan.offsets.localSubrsInfos[i].offSize, plan.subset_localsubrs[i]))) if (unlikely (!dest->serialize (&c, plan.offsets.localSubrsInfos[i].offSize, plan.subset_localsubrs[i])))
{ {
DEBUG_MSG (SUBSET, nullptr, "failed to serialize local subroutines"); DEBUG_MSG (SUBSET, nullptr, "failed to serialize local subroutines");
return false; return false;
} }
} }
} }
} }
@ -1051,9 +1051,9 @@ static inline bool _write_cff1 (const cff_subset_plan &plan,
static bool static bool
_hb_subset_cff1 (const OT::cff1::accelerator_subset_t &acc, _hb_subset_cff1 (const OT::cff1::accelerator_subset_t &acc,
const char *data, const char *data,
hb_subset_plan_t *plan, hb_subset_plan_t *plan,
hb_blob_t **prime /* OUT */) hb_blob_t **prime /* OUT */)
{ {
cff_subset_plan cff_plan; cff_subset_plan cff_plan;
@ -1067,17 +1067,17 @@ _hb_subset_cff1 (const OT::cff1::accelerator_subset_t &acc,
char *cff_prime_data = (char *) calloc (1, cff_prime_size); char *cff_prime_data = (char *) calloc (1, cff_prime_size);
if (unlikely (!_write_cff1 (cff_plan, acc, plan->glyphs, if (unlikely (!_write_cff1 (cff_plan, acc, plan->glyphs,
cff_prime_size, cff_prime_data))) { cff_prime_size, cff_prime_data))) {
DEBUG_MSG(SUBSET, nullptr, "Failed to write a subset cff."); DEBUG_MSG(SUBSET, nullptr, "Failed to write a subset cff.");
free (cff_prime_data); free (cff_prime_data);
return false; return false;
} }
*prime = hb_blob_create (cff_prime_data, *prime = hb_blob_create (cff_prime_data,
cff_prime_size, cff_prime_size,
HB_MEMORY_MODE_READONLY, HB_MEMORY_MODE_READONLY,
cff_prime_data, cff_prime_data,
free); free);
return true; return true;
} }
@ -1089,7 +1089,7 @@ _hb_subset_cff1 (const OT::cff1::accelerator_subset_t &acc,
**/ **/
bool bool
hb_subset_cff1 (hb_subset_plan_t *plan, hb_subset_cff1 (hb_subset_plan_t *plan,
hb_blob_t **prime /* OUT */) hb_blob_t **prime /* OUT */)
{ {
hb_blob_t *cff_blob = hb_sanitize_context_t().reference_table<CFF::cff1> (plan->source); hb_blob_t *cff_blob = hb_sanitize_context_t().reference_table<CFF::cff1> (plan->source);
const char *data = hb_blob_get_data(cff_blob, nullptr); const char *data = hb_blob_get_data(cff_blob, nullptr);
@ -1097,7 +1097,7 @@ hb_subset_cff1 (hb_subset_plan_t *plan,
OT::cff1::accelerator_subset_t acc; OT::cff1::accelerator_subset_t acc;
acc.init(plan->source); acc.init(plan->source);
bool result = likely (acc.is_valid ()) && bool result = likely (acc.is_valid ()) &&
_hb_subset_cff1 (acc, data, plan, prime); _hb_subset_cff1 (acc, data, plan, prime);
hb_blob_destroy (cff_blob); hb_blob_destroy (cff_blob);
acc.fini (); acc.fini ();

View File

@ -33,6 +33,6 @@
HB_INTERNAL bool HB_INTERNAL bool
hb_subset_cff1 (hb_subset_plan_t *plan, hb_subset_cff1 (hb_subset_plan_t *plan,
hb_blob_t **cff_prime /* OUT */); hb_blob_t **cff_prime /* OUT */);
#endif /* HB_SUBSET_CFF1_HH */ #endif /* HB_SUBSET_CFF1_HH */

View File

@ -47,18 +47,18 @@ struct CFF2SubTableOffsets : CFFSubTableOffsets
struct CFF2TopDict_OpSerializer : CFFTopDict_OpSerializer<> struct CFF2TopDict_OpSerializer : CFFTopDict_OpSerializer<>
{ {
inline bool serialize (hb_serialize_context_t *c, inline bool serialize (hb_serialize_context_t *c,
const OpStr &opstr, const OpStr &opstr,
const CFF2SubTableOffsets &offsets) const const CFF2SubTableOffsets &offsets) const
{ {
TRACE_SERIALIZE (this); TRACE_SERIALIZE (this);
switch (opstr.op) switch (opstr.op)
{ {
case OpCode_vstore: case OpCode_vstore:
return_trace (FontDict::serialize_offset4_op(c, opstr.op, offsets.varStoreOffset)); return_trace (FontDict::serialize_offset4_op(c, opstr.op, offsets.varStoreOffset));
default: default:
return_trace (CFFTopDict_OpSerializer<>::serialize (c, opstr, offsets)); return_trace (CFFTopDict_OpSerializer<>::serialize (c, opstr, offsets));
} }
} }
@ -67,10 +67,10 @@ struct CFF2TopDict_OpSerializer : CFFTopDict_OpSerializer<>
switch (opstr.op) switch (opstr.op)
{ {
case OpCode_vstore: case OpCode_vstore:
return OpCode_Size (OpCode_longintdict) + 4 + OpCode_Size (opstr.op); return OpCode_Size (OpCode_longintdict) + 4 + OpCode_Size (opstr.op);
default: default:
return CFFTopDict_OpSerializer<>::calculate_serialized_size (opstr); return CFFTopDict_OpSerializer<>::calculate_serialized_size (opstr);
} }
} }
}; };
@ -83,8 +83,8 @@ struct CFF2CSOpSet_Flatten : CFF2CSOpSet<CFF2CSOpSet_Flatten, FlattenParam>
{ {
case OpCode_return: case OpCode_return:
case OpCode_endchar: case OpCode_endchar:
/* dummy opcodes in CFF2. ignore */ /* dummy opcodes in CFF2. ignore */
break; break;
case OpCode_hstem: case OpCode_hstem:
case OpCode_hstemhm: case OpCode_hstemhm:
@ -92,16 +92,16 @@ struct CFF2CSOpSet_Flatten : CFF2CSOpSet<CFF2CSOpSet_Flatten, FlattenParam>
case OpCode_vstemhm: case OpCode_vstemhm:
case OpCode_hintmask: case OpCode_hintmask:
case OpCode_cntrmask: case OpCode_cntrmask:
if (param.drop_hints) if (param.drop_hints)
{ {
env.clear_args (); env.clear_args ();
return; return;
} }
HB_FALLTHROUGH; HB_FALLTHROUGH;
default: default:
SUPER::flush_args_and_op (op, env, param); SUPER::flush_args_and_op (op, env, param);
break; break;
} }
} }
@ -112,15 +112,15 @@ struct CFF2CSOpSet_Flatten : CFF2CSOpSet<CFF2CSOpSet_Flatten, FlattenParam>
const BlendArg &arg = env.argStack[i]; const BlendArg &arg = env.argStack[i];
if (arg.blending ()) if (arg.blending ())
{ {
assert ((arg.numValues > 0) && (env.argStack.get_count () >= arg.numValues)); assert ((arg.numValues > 0) && (env.argStack.get_count () >= arg.numValues));
flatten_blends (arg, i, env, param); flatten_blends (arg, i, env, param);
i += arg.numValues; i += arg.numValues;
} }
else else
{ {
StrEncoder encoder (param.flatStr); StrEncoder encoder (param.flatStr);
encoder.encode_num (arg); encoder.encode_num (arg);
i++; i++;
} }
} }
SUPER::flush_args (env, param); SUPER::flush_args (env, param);
@ -134,7 +134,7 @@ struct CFF2CSOpSet_Flatten : CFF2CSOpSet<CFF2CSOpSet_Flatten, FlattenParam>
{ {
const BlendArg &arg1 = env.argStack[i + j]; const BlendArg &arg1 = env.argStack[i + j];
assert (arg1.blending () && (arg.numValues == arg1.numValues) && (arg1.valueIndex == j) && assert (arg1.blending () && (arg.numValues == arg1.numValues) && (arg1.valueIndex == j) &&
(arg1.deltas.len == env.get_region_count ())); (arg1.deltas.len == env.get_region_count ()));
encoder.encode_num (arg1); encoder.encode_num (arg1);
} }
/* flatten deltas for each value */ /* flatten deltas for each value */
@ -142,7 +142,7 @@ struct CFF2CSOpSet_Flatten : CFF2CSOpSet<CFF2CSOpSet_Flatten, FlattenParam>
{ {
const BlendArg &arg1 = env.argStack[i + j]; const BlendArg &arg1 = env.argStack[i + j];
for (unsigned int k = 0; k < arg1.deltas.len; k++) for (unsigned int k = 0; k < arg1.deltas.len; k++)
encoder.encode_num (arg1.deltas[k]); encoder.encode_num (arg1.deltas[k]);
} }
/* flatten the number of values followed by blend operator */ /* flatten the number of values followed by blend operator */
encoder.encode_int (arg.numValues); encoder.encode_int (arg.numValues);
@ -155,10 +155,10 @@ struct CFF2CSOpSet_Flatten : CFF2CSOpSet<CFF2CSOpSet_Flatten, FlattenParam>
{ {
case OpCode_return: case OpCode_return:
case OpCode_endchar: case OpCode_endchar:
return; return;
default: default:
StrEncoder encoder (param.flatStr); StrEncoder encoder (param.flatStr);
encoder.encode_op (op); encoder.encode_op (op);
} }
} }
@ -174,35 +174,35 @@ struct CFF2CSOpSet_SubrSubset : CFF2CSOpSet<CFF2CSOpSet_SubrSubset, SubrSubsetPa
switch (op) { switch (op) {
case OpCode_return: case OpCode_return:
param.current_parsed_str->set_parsed (); param.current_parsed_str->set_parsed ();
env.returnFromSubr (); env.returnFromSubr ();
param.set_current_str (env); param.set_current_str (env);
break; break;
case OpCode_endchar: case OpCode_endchar:
param.current_parsed_str->set_parsed (); param.current_parsed_str->set_parsed ();
SUPER::process_op (op, env, param); SUPER::process_op (op, env, param);
break; break;
case OpCode_callsubr: case OpCode_callsubr:
process_call_subr (op, CSType_LocalSubr, env, param, env.localSubrs, param.local_closure); process_call_subr (op, CSType_LocalSubr, env, param, env.localSubrs, param.local_closure);
break; break;
case OpCode_callgsubr: case OpCode_callgsubr:
process_call_subr (op, CSType_GlobalSubr, env, param, env.globalSubrs, param.global_closure); process_call_subr (op, CSType_GlobalSubr, env, param, env.globalSubrs, param.global_closure);
break; break;
default: default:
SUPER::process_op (op, env, param); SUPER::process_op (op, env, param);
param.current_parsed_str->add_op (op, env.substr); param.current_parsed_str->add_op (op, env.substr);
break; break;
} }
} }
protected: protected:
static inline void process_call_subr (OpCode op, CSType type, static inline void process_call_subr (OpCode op, CSType type,
CFF2CSInterpEnv &env, SubrSubsetParam& param, CFF2CSInterpEnv &env, SubrSubsetParam& param,
CFF2BiasedSubrs& subrs, hb_set_t *closure) CFF2BiasedSubrs& subrs, hb_set_t *closure)
{ {
SubByteStr substr = env.substr; SubByteStr substr = env.substr;
env.callSubr (subrs, type); env.callSubr (subrs, type);
@ -257,7 +257,7 @@ struct cff2_subset_plan {
} }
inline bool create (const OT::cff2::accelerator_subset_t &acc, inline bool create (const OT::cff2::accelerator_subset_t &acc,
hb_subset_plan_t *plan) hb_subset_plan_t *plan)
{ {
final_size = 0; final_size = 0;
orig_fdcount = acc.fdArray->count; orig_fdcount = acc.fdArray->count;
@ -279,9 +279,9 @@ struct cff2_subset_plan {
{ {
/* Flatten global & local subrs */ /* Flatten global & local subrs */
SubrFlattener<const OT::cff2::accelerator_subset_t, CFF2CSInterpEnv, CFF2CSOpSet_Flatten> SubrFlattener<const OT::cff2::accelerator_subset_t, CFF2CSInterpEnv, CFF2CSOpSet_Flatten>
flattener(acc, plan->glyphs, plan->drop_hints); flattener(acc, plan->glyphs, plan->drop_hints);
if (!flattener.flatten (subset_charstrings)) if (!flattener.flatten (subset_charstrings))
return false; return false;
/* no global/local subroutines */ /* no global/local subroutines */
offsets.globalSubrsInfo.size = CFF2Subrs::calculate_serialized_size (1, 0, 0); offsets.globalSubrsInfo.size = CFF2Subrs::calculate_serialized_size (1, 0, 0);
@ -290,14 +290,14 @@ struct cff2_subset_plan {
{ {
/* Subset subrs: collect used subroutines, leaving all unused ones behind */ /* Subset subrs: collect used subroutines, leaving all unused ones behind */
if (!subr_subsetter.subset (acc, plan->glyphs, plan->drop_hints)) if (!subr_subsetter.subset (acc, plan->glyphs, plan->drop_hints))
return false; return false;
/* encode charstrings, global subrs, local subrs with new subroutine numbers */ /* encode charstrings, global subrs, local subrs with new subroutine numbers */
if (!subr_subsetter.encode_charstrings (acc, plan->glyphs, subset_charstrings)) if (!subr_subsetter.encode_charstrings (acc, plan->glyphs, subset_charstrings))
return false; return false;
if (!subr_subsetter.encode_globalsubrs (subset_globalsubrs)) if (!subr_subsetter.encode_globalsubrs (subset_globalsubrs))
return false; return false;
/* global subrs */ /* global subrs */
unsigned int dataSize = subset_globalsubrs.total_size (); unsigned int dataSize = subset_globalsubrs.total_size ();
@ -306,26 +306,26 @@ struct cff2_subset_plan {
/* local subrs */ /* local subrs */
if (!offsets.localSubrsInfos.resize (orig_fdcount)) if (!offsets.localSubrsInfos.resize (orig_fdcount))
return false; return false;
if (!subset_localsubrs.resize (orig_fdcount)) if (!subset_localsubrs.resize (orig_fdcount))
return false; return false;
for (unsigned int fd = 0; fd < orig_fdcount; fd++) for (unsigned int fd = 0; fd < orig_fdcount; fd++)
{ {
subset_localsubrs[fd].init (); subset_localsubrs[fd].init ();
offsets.localSubrsInfos[fd].init (); offsets.localSubrsInfos[fd].init ();
if (fdmap.includes (fd)) if (fdmap.includes (fd))
{ {
if (!subr_subsetter.encode_localsubrs (fd, subset_localsubrs[fd])) if (!subr_subsetter.encode_localsubrs (fd, subset_localsubrs[fd]))
return false; return false;
unsigned int dataSize = subset_localsubrs[fd].total_size (); unsigned int dataSize = subset_localsubrs[fd].total_size ();
if (dataSize > 0) if (dataSize > 0)
{ {
offsets.localSubrsInfos[fd].offset = final_size; offsets.localSubrsInfos[fd].offset = final_size;
offsets.localSubrsInfos[fd].offSize = calcOffSize (dataSize); offsets.localSubrsInfos[fd].offSize = calcOffSize (dataSize);
offsets.localSubrsInfos[fd].size = CFF2Subrs::calculate_serialized_size (offsets.localSubrsInfos[fd].offSize, subset_localsubrs[fd].len, dataSize); offsets.localSubrsInfos[fd].size = CFF2Subrs::calculate_serialized_size (offsets.localSubrsInfos[fd].offSize, subset_localsubrs[fd].len, dataSize);
} }
} }
} }
} }
@ -345,14 +345,14 @@ struct cff2_subset_plan {
{ {
offsets.FDSelectInfo.offset = final_size; offsets.FDSelectInfo.offset = final_size;
if (unlikely (!hb_plan_subset_cff_fdselect (plan->glyphs, if (unlikely (!hb_plan_subset_cff_fdselect (plan->glyphs,
orig_fdcount, orig_fdcount,
*(const FDSelect *)acc.fdSelect, *(const FDSelect *)acc.fdSelect,
subset_fdcount, subset_fdcount,
offsets.FDSelectInfo.size, offsets.FDSelectInfo.size,
subset_fdselect_format, subset_fdselect_format,
subset_fdselect_ranges, subset_fdselect_ranges,
fdmap))) fdmap)))
return false; return false;
final_size += offsets.FDSelectInfo.size; final_size += offsets.FDSelectInfo.size;
} }
@ -365,8 +365,8 @@ struct cff2_subset_plan {
CFFFontDict_OpSerializer fontSzr; CFFFontDict_OpSerializer fontSzr;
unsigned int dictsSize = 0; unsigned int dictsSize = 0;
for (unsigned int i = 0; i < acc.fontDicts.len; i++) for (unsigned int i = 0; i < acc.fontDicts.len; i++)
if (fdmap.includes (i)) if (fdmap.includes (i))
dictsSize += FontDict::calculate_serialized_size (acc.fontDicts[i], fontSzr); dictsSize += FontDict::calculate_serialized_size (acc.fontDicts[i], fontSzr);
offsets.FDArrayInfo.offSize = calcOffSize (dictsSize); offsets.FDArrayInfo.offSize = calcOffSize (dictsSize);
final_size += CFF2Index::calculate_serialized_size (offsets.FDArrayInfo.offSize, subset_fdcount, dictsSize); final_size += CFF2Index::calculate_serialized_size (offsets.FDArrayInfo.offSize, subset_fdcount, dictsSize);
@ -386,18 +386,18 @@ struct cff2_subset_plan {
{ {
if (fdmap.includes (i)) if (fdmap.includes (i))
{ {
bool has_localsubrs = offsets.localSubrsInfos[i].size > 0; bool has_localsubrs = offsets.localSubrsInfos[i].size > 0;
CFFPrivateDict_OpSerializer privSzr (desubroutinize, drop_hints); CFFPrivateDict_OpSerializer privSzr (desubroutinize, drop_hints);
unsigned int priv_size = PrivateDict::calculate_serialized_size (acc.privateDicts[i], privSzr, has_localsubrs); unsigned int priv_size = PrivateDict::calculate_serialized_size (acc.privateDicts[i], privSzr, has_localsubrs);
TableInfo privInfo = { final_size, priv_size, 0 }; TableInfo privInfo = { final_size, priv_size, 0 };
privateDictInfos.push (privInfo); privateDictInfos.push (privInfo);
final_size += privInfo.size; final_size += privInfo.size;
if (!plan->desubroutinize && has_localsubrs) if (!plan->desubroutinize && has_localsubrs)
{ {
offsets.localSubrsInfos[i].offset = final_size; offsets.localSubrsInfos[i].offset = final_size;
final_size += offsets.localSubrsInfos[i].size; final_size += offsets.localSubrsInfos[i].size;
} }
} }
} }
@ -406,7 +406,7 @@ struct cff2_subset_plan {
inline unsigned int get_final_size (void) const { return final_size; } inline unsigned int get_final_size (void) const { return final_size; }
unsigned int final_size; unsigned int final_size;
CFF2SubTableOffsets offsets; CFF2SubTableOffsets offsets;
unsigned int orig_fdcount; unsigned int orig_fdcount;
@ -416,21 +416,21 @@ struct cff2_subset_plan {
Remap fdmap; Remap fdmap;
StrBuffArray subset_charstrings; StrBuffArray subset_charstrings;
StrBuffArray subset_globalsubrs; StrBuffArray subset_globalsubrs;
hb_vector_t<StrBuffArray> subset_localsubrs; hb_vector_t<StrBuffArray> subset_localsubrs;
hb_vector_t<TableInfo> privateDictInfos; hb_vector_t<TableInfo> privateDictInfos;
bool drop_hints; bool drop_hints;
bool desubroutinize; bool desubroutinize;
CFF2SubrSubsetter subr_subsetter; CFF2SubrSubsetter subr_subsetter;
}; };
static inline bool _write_cff2 (const cff2_subset_plan &plan, static inline bool _write_cff2 (const cff2_subset_plan &plan,
const OT::cff2::accelerator_subset_t &acc, const OT::cff2::accelerator_subset_t &acc,
const hb_vector_t<hb_codepoint_t>& glyphs, const hb_vector_t<hb_codepoint_t>& glyphs,
unsigned int dest_sz, unsigned int dest_sz,
void *dest) void *dest)
{ {
hb_serialize_context_t c (dest, dest_sz); hb_serialize_context_t c (dest, dest_sz);
@ -486,8 +486,8 @@ static inline bool _write_cff2 (const cff2_subset_plan &plan,
assert (plan.offsets.FDSelectInfo.offset == c.head - c.start); assert (plan.offsets.FDSelectInfo.offset == c.head - c.start);
if (unlikely (!hb_serialize_cff_fdselect (&c, glyphs.len, *(const FDSelect *)acc.fdSelect, acc.fdArray->count, if (unlikely (!hb_serialize_cff_fdselect (&c, glyphs.len, *(const FDSelect *)acc.fdSelect, acc.fdArray->count,
plan.subset_fdselect_format, plan.offsets.FDSelectInfo.size, plan.subset_fdselect_format, plan.offsets.FDSelectInfo.size,
plan.subset_fdselect_ranges))) plan.subset_fdselect_ranges)))
{ {
DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF2 subset FDSelect"); DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF2 subset FDSelect");
return false; return false;
@ -501,8 +501,8 @@ static inline bool _write_cff2 (const cff2_subset_plan &plan,
if (unlikely (fda == nullptr)) return false; if (unlikely (fda == nullptr)) return false;
CFFFontDict_OpSerializer fontSzr; CFFFontDict_OpSerializer fontSzr;
if (unlikely (!fda->serialize (&c, plan.offsets.FDArrayInfo.offSize, if (unlikely (!fda->serialize (&c, plan.offsets.FDArrayInfo.offSize,
acc.fontDicts, plan.subset_fdcount, plan.fdmap, acc.fontDicts, plan.subset_fdcount, plan.fdmap,
fontSzr, plan.privateDictInfos))) fontSzr, plan.privateDictInfos)))
{ {
DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF2 FDArray"); DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF2 FDArray");
return false; return false;
@ -537,18 +537,18 @@ static inline bool _write_cff2 (const cff2_subset_plan &plan,
result = pd->serialize (&c, acc.privateDicts[i], privSzr, subroffset); result = pd->serialize (&c, acc.privateDicts[i], privSzr, subroffset);
if (unlikely (!result)) if (unlikely (!result))
{ {
DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF Private Dict[%d]", i); DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF Private Dict[%d]", i);
return false; return false;
} }
if (plan.offsets.localSubrsInfos[i].size > 0) if (plan.offsets.localSubrsInfos[i].size > 0)
{ {
CFF2Subrs *dest = c.start_embed <CFF2Subrs> (); CFF2Subrs *dest = c.start_embed <CFF2Subrs> ();
if (unlikely (dest == nullptr)) return false; if (unlikely (dest == nullptr)) return false;
if (unlikely (!dest->serialize (&c, plan.offsets.localSubrsInfos[i].offSize, plan.subset_localsubrs[i]))) if (unlikely (!dest->serialize (&c, plan.offsets.localSubrsInfos[i].offSize, plan.subset_localsubrs[i])))
{ {
DEBUG_MSG (SUBSET, nullptr, "failed to serialize local subroutines"); DEBUG_MSG (SUBSET, nullptr, "failed to serialize local subroutines");
return false; return false;
} }
} }
} }
} }
@ -561,9 +561,9 @@ static inline bool _write_cff2 (const cff2_subset_plan &plan,
static bool static bool
_hb_subset_cff2 (const OT::cff2::accelerator_subset_t &acc, _hb_subset_cff2 (const OT::cff2::accelerator_subset_t &acc,
const char *data, const char *data,
hb_subset_plan_t *plan, hb_subset_plan_t *plan,
hb_blob_t **prime /* OUT */) hb_blob_t **prime /* OUT */)
{ {
cff2_subset_plan cff2_plan; cff2_subset_plan cff2_plan;
@ -577,17 +577,17 @@ _hb_subset_cff2 (const OT::cff2::accelerator_subset_t &acc,
char *cff2_prime_data = (char *) calloc (1, cff2_prime_size); char *cff2_prime_data = (char *) calloc (1, cff2_prime_size);
if (unlikely (!_write_cff2 (cff2_plan, acc, plan->glyphs, if (unlikely (!_write_cff2 (cff2_plan, acc, plan->glyphs,
cff2_prime_size, cff2_prime_data))) { cff2_prime_size, cff2_prime_data))) {
DEBUG_MSG(SUBSET, nullptr, "Failed to write a subset cff2."); DEBUG_MSG(SUBSET, nullptr, "Failed to write a subset cff2.");
free (cff2_prime_data); free (cff2_prime_data);
return false; return false;
} }
*prime = hb_blob_create (cff2_prime_data, *prime = hb_blob_create (cff2_prime_data,
cff2_prime_size, cff2_prime_size,
HB_MEMORY_MODE_READONLY, HB_MEMORY_MODE_READONLY,
cff2_prime_data, cff2_prime_data,
free); free);
return true; return true;
} }
@ -599,7 +599,7 @@ _hb_subset_cff2 (const OT::cff2::accelerator_subset_t &acc,
**/ **/
bool bool
hb_subset_cff2 (hb_subset_plan_t *plan, hb_subset_cff2 (hb_subset_plan_t *plan,
hb_blob_t **prime /* OUT */) hb_blob_t **prime /* OUT */)
{ {
hb_blob_t *cff2_blob = hb_sanitize_context_t().reference_table<CFF::cff2> (plan->source); hb_blob_t *cff2_blob = hb_sanitize_context_t().reference_table<CFF::cff2> (plan->source);
const char *data = hb_blob_get_data(cff2_blob, nullptr); const char *data = hb_blob_get_data(cff2_blob, nullptr);
@ -607,7 +607,7 @@ hb_subset_cff2 (hb_subset_plan_t *plan,
OT::cff2::accelerator_subset_t acc; OT::cff2::accelerator_subset_t acc;
acc.init(plan->source); acc.init(plan->source);
bool result = likely (acc.is_valid ()) && bool result = likely (acc.is_valid ()) &&
_hb_subset_cff2 (acc, data, plan, prime); _hb_subset_cff2 (acc, data, plan, prime);
hb_blob_destroy (cff2_blob); hb_blob_destroy (cff2_blob);
acc.fini (); acc.fini ();

View File

@ -33,6 +33,6 @@
HB_INTERNAL bool HB_INTERNAL bool
hb_subset_cff2 (hb_subset_plan_t *plan, hb_subset_cff2 (hb_subset_plan_t *plan,
hb_blob_t **cff2_prime /* OUT */); hb_blob_t **cff2_prime /* OUT */);
#endif /* HB_SUBSET_CFF2_HH */ #endif /* HB_SUBSET_CFF2_HH */