Coverage Report

Created: 2021-08-22 09:07

/src/skia/third_party/externals/harfbuzz/src/hb-cff-interp-common.hh
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright © 2018 Adobe Inc.
3
 *
4
 *  This is part of HarfBuzz, a text shaping library.
5
 *
6
 * Permission is hereby granted, without written agreement and without
7
 * license or royalty fees, to use, copy, modify, and distribute this
8
 * software and its documentation for any purpose, provided that the
9
 * above copyright notice and the following two paragraphs appear in
10
 * all copies of this software.
11
 *
12
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16
 * DAMAGE.
17
 *
18
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
21
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23
 *
24
 * Adobe Author(s): Michiharu Ariza
25
 */
26
#ifndef HB_CFF_INTERP_COMMON_HH
27
#define HB_CFF_INTERP_COMMON_HH
28
29
namespace CFF {
30
31
using namespace OT;
32
33
typedef unsigned int op_code_t;
34
35
36
/* === Dict operators === */
37
38
/* One byte operators (0-31) */
39
0
#define OpCode_version      0 /* CFF Top */
40
0
#define OpCode_Notice     1 /* CFF Top */
41
0
#define OpCode_FullName     2 /* CFF Top */
42
0
#define OpCode_FamilyName   3 /* CFF Top */
43
0
#define OpCode_Weight     4 /* CFF Top */
44
0
#define OpCode_FontBBox     5 /* CFF Top */
45
0
#define OpCode_BlueValues   6 /* CFF Private, CFF2 Private */
46
0
#define OpCode_OtherBlues   7 /* CFF Private, CFF2 Private */
47
0
#define OpCode_FamilyBlues    8 /* CFF Private, CFF2 Private */
48
0
#define OpCode_FamilyOtherBlues   9 /* CFF Private, CFF2 Private */
49
0
#define OpCode_StdHW     10 /* CFF Private, CFF2 Private */
50
0
#define OpCode_StdVW     11 /* CFF Private, CFF2 Private */
51
0
#define OpCode_escape    12 /* All. Shared with CS */
52
0
#define OpCode_UniqueID    13 /* CFF Top */
53
0
#define OpCode_XUID    14 /* CFF Top */
54
0
#define OpCode_charset     15 /* CFF Top (0) */
55
0
#define OpCode_Encoding    16 /* CFF Top (0) */
56
0
#define OpCode_CharStrings   17 /* CFF Top, CFF2 Top */
57
0
#define OpCode_Private     18 /* CFF Top, CFF2 FD */
58
0
#define OpCode_Subrs     19 /* CFF Private, CFF2 Private */
59
0
#define OpCode_defaultWidthX   20 /* CFF Private (0) */
60
0
#define OpCode_nominalWidthX   21 /* CFF Private (0) */
61
0
#define OpCode_vsindexdict   22 /* CFF2 Private/CS */
62
0
#define OpCode_blenddict   23 /* CFF2 Private/CS */
63
0
#define OpCode_vstore    24 /* CFF2 Top */
64
#define OpCode_reserved25  25
65
#define OpCode_reserved26  26
66
#define OpCode_reserved27  27
67
68
/* Numbers */
69
0
#define OpCode_shortint    28 /* 16-bit integer, All */
70
0
#define OpCode_longintdict   29 /* 32-bit integer, All */
71
0
#define OpCode_BCD     30 /* Real number, CFF2 Top/FD */
72
#define OpCode_reserved31  31
73
74
/* 1-byte integers */
75
#define OpCode_OneByteIntFirst   32 /* All. beginning of the range of first byte ints */
76
#define OpCode_OneByteIntLast 246 /* All. ending of the range of first byte int */
77
78
/* 2-byte integers */
79
0
#define OpCode_TwoBytePosInt0 247 /* All. first byte of two byte positive int (+108 to +1131) */
80
0
#define OpCode_TwoBytePosInt1 248
81
0
#define OpCode_TwoBytePosInt2 249
82
0
#define OpCode_TwoBytePosInt3 250
83
84
0
#define OpCode_TwoByteNegInt0 251 /* All. first byte of two byte negative int (-1131 to -108) */
85
0
#define OpCode_TwoByteNegInt1 252
86
0
#define OpCode_TwoByteNegInt2 253
87
0
#define OpCode_TwoByteNegInt3 254
88
89
/* Two byte escape operators 12, (0-41) */
90
0
#define OpCode_ESC_Base   256
91
0
#define Make_OpCode_ESC(byte2)  ((op_code_t)(OpCode_ESC_Base + (byte2)))
92
93
0
inline op_code_t Unmake_OpCode_ESC (op_code_t op)  { return (op_code_t)(op - OpCode_ESC_Base); }
Unexecuted instantiation: CFF::Unmake_OpCode_ESC(unsigned int)
Unexecuted instantiation: CFF::Unmake_OpCode_ESC(unsigned int)
94
0
inline bool Is_OpCode_ESC (op_code_t op) { return op >= OpCode_ESC_Base; }
Unexecuted instantiation: CFF::Is_OpCode_ESC(unsigned int)
Unexecuted instantiation: CFF::Is_OpCode_ESC(unsigned int)
95
0
inline unsigned int OpCode_Size (op_code_t op) { return Is_OpCode_ESC (op) ? 2: 1; }
96
97
0
#define OpCode_Copyright  Make_OpCode_ESC(0) /* CFF Top */
98
0
#define OpCode_isFixedPitch Make_OpCode_ESC(1) /* CFF Top (false) */
99
0
#define OpCode_ItalicAngle  Make_OpCode_ESC(2) /* CFF Top (0) */
100
0
#define OpCode_UnderlinePosition Make_OpCode_ESC(3) /* CFF Top (-100) */
101
0
#define OpCode_UnderlineThickness Make_OpCode_ESC(4) /* CFF Top (50) */
102
0
#define OpCode_PaintType  Make_OpCode_ESC(5) /* CFF Top (0) */
103
0
#define OpCode_CharstringType Make_OpCode_ESC(6) /* CFF Top (2) */
104
0
#define OpCode_FontMatrix Make_OpCode_ESC(7) /* CFF Top, CFF2 Top (.001 0 0 .001 0 0)*/
105
0
#define OpCode_StrokeWidth  Make_OpCode_ESC(8) /* CFF Top (0) */
106
0
#define OpCode_BlueScale  Make_OpCode_ESC(9) /* CFF Private, CFF2 Private (0.039625) */
107
0
#define OpCode_BlueShift  Make_OpCode_ESC(10) /* CFF Private, CFF2 Private (7) */
108
0
#define OpCode_BlueFuzz   Make_OpCode_ESC(11) /* CFF Private, CFF2 Private (1) */
109
0
#define OpCode_StemSnapH  Make_OpCode_ESC(12) /* CFF Private, CFF2 Private */
110
0
#define OpCode_StemSnapV  Make_OpCode_ESC(13) /* CFF Private, CFF2 Private */
111
0
#define OpCode_ForceBold  Make_OpCode_ESC(14) /* CFF Private (false) */
112
#define OpCode_reservedESC15  Make_OpCode_ESC(15)
113
#define OpCode_reservedESC16  Make_OpCode_ESC(16)
114
0
#define OpCode_LanguageGroup  Make_OpCode_ESC(17) /* CFF Private, CFF2 Private (0) */
115
0
#define OpCode_ExpansionFactor  Make_OpCode_ESC(18) /* CFF Private, CFF2 Private (0.06) */
116
0
#define OpCode_initialRandomSeed Make_OpCode_ESC(19) /* CFF Private (0) */
117
0
#define OpCode_SyntheticBase  Make_OpCode_ESC(20) /* CFF Top */
118
0
#define OpCode_PostScript Make_OpCode_ESC(21) /* CFF Top */
119
0
#define OpCode_BaseFontName Make_OpCode_ESC(22) /* CFF Top */
120
0
#define OpCode_BaseFontBlend  Make_OpCode_ESC(23) /* CFF Top */
121
#define OpCode_reservedESC24  Make_OpCode_ESC(24)
122
#define OpCode_reservedESC25  Make_OpCode_ESC(25)
123
#define OpCode_reservedESC26  Make_OpCode_ESC(26)
124
#define OpCode_reservedESC27  Make_OpCode_ESC(27)
125
#define OpCode_reservedESC28  Make_OpCode_ESC(28)
126
#define OpCode_reservedESC29  Make_OpCode_ESC(29)
127
0
#define OpCode_ROS    Make_OpCode_ESC(30) /* CFF Top_CID */
128
0
#define OpCode_CIDFontVersion Make_OpCode_ESC(31) /* CFF Top_CID (0) */
129
0
#define OpCode_CIDFontRevision  Make_OpCode_ESC(32) /* CFF Top_CID (0) */
130
0
#define OpCode_CIDFontType  Make_OpCode_ESC(33) /* CFF Top_CID (0) */
131
0
#define OpCode_CIDCount   Make_OpCode_ESC(34) /* CFF Top_CID (8720) */
132
0
#define OpCode_UIDBase    Make_OpCode_ESC(35) /* CFF Top_CID */
133
0
#define OpCode_FDArray    Make_OpCode_ESC(36) /* CFF Top_CID, CFF2 Top */
134
0
#define OpCode_FDSelect   Make_OpCode_ESC(37) /* CFF Top_CID, CFF2 Top */
135
0
#define OpCode_FontName   Make_OpCode_ESC(38) /* CFF Top_CID */
136
137
138
/* === CharString operators === */
139
140
0
#define OpCode_hstem      1 /* CFF, CFF2 */
141
#define OpCode_Reserved2    2
142
0
#define OpCode_vstem      3 /* CFF, CFF2 */
143
0
#define OpCode_vmoveto      4 /* CFF, CFF2 */
144
0
#define OpCode_rlineto      5 /* CFF, CFF2 */
145
0
#define OpCode_hlineto      6 /* CFF, CFF2 */
146
0
#define OpCode_vlineto      7 /* CFF, CFF2 */
147
0
#define OpCode_rrcurveto    8 /* CFF, CFF2 */
148
#define OpCode_Reserved9    9
149
0
#define OpCode_callsubr    10 /* CFF, CFF2 */
150
0
#define OpCode_return    11 /* CFF */
151
//#define OpCode_escape    12 /* CFF, CFF2 */
152
#define OpCode_Reserved13  13
153
0
#define OpCode_endchar     14 /* CFF */
154
0
#define OpCode_vsindexcs   15 /* CFF2 */
155
0
#define OpCode_blendcs     16 /* CFF2 */
156
#define OpCode_Reserved17  17
157
0
#define OpCode_hstemhm     18 /* CFF, CFF2 */
158
0
#define OpCode_hintmask    19 /* CFF, CFF2 */
159
0
#define OpCode_cntrmask    20 /* CFF, CFF2 */
160
0
#define OpCode_rmoveto     21 /* CFF, CFF2 */
161
0
#define OpCode_hmoveto     22 /* CFF, CFF2 */
162
0
#define OpCode_vstemhm     23 /* CFF, CFF2 */
163
0
#define OpCode_rcurveline  24 /* CFF, CFF2 */
164
0
#define OpCode_rlinecurve  25 /* CFF, CFF2 */
165
0
#define OpCode_vvcurveto   26 /* CFF, CFF2 */
166
0
#define OpCode_hhcurveto   27 /* CFF, CFF2 */
167
//#define OpCode_shortint  28 /* CFF, CFF2 */
168
0
#define OpCode_callgsubr   29 /* CFF, CFF2 */
169
0
#define OpCode_vhcurveto   30 /* CFF, CFF2 */
170
0
#define OpCode_hvcurveto   31 /* CFF, CFF2 */
171
172
0
#define OpCode_fixedcs    255 /* 32-bit fixed */
173
174
/* Two byte escape operators 12, (0-41) */
175
0
#define OpCode_dotsection Make_OpCode_ESC(0) /* CFF (obsoleted) */
176
#define OpCode_ReservedESC1 Make_OpCode_ESC(1)
177
#define OpCode_ReservedESC2 Make_OpCode_ESC(2)
178
#define OpCode_and    Make_OpCode_ESC(3) /* CFF */
179
#define OpCode_or   Make_OpCode_ESC(4) /* CFF */
180
#define OpCode_not    Make_OpCode_ESC(5) /* CFF */
181
#define OpCode_ReservedESC6 Make_OpCode_ESC(6)
182
#define OpCode_ReservedESC7 Make_OpCode_ESC(7)
183
#define OpCode_ReservedESC8 Make_OpCode_ESC(8)
184
#define OpCode_abs    Make_OpCode_ESC(9) /* CFF */
185
#define OpCode_add    Make_OpCode_ESC(10) /* CFF */
186
#define OpCode_sub    Make_OpCode_ESC(11) /* CFF */
187
#define OpCode_div    Make_OpCode_ESC(12) /* CFF */
188
#define OpCode_ReservedESC13  Make_OpCode_ESC(13)
189
#define OpCode_neg    Make_OpCode_ESC(14) /* CFF */
190
#define OpCode_eq   Make_OpCode_ESC(15) /* CFF */
191
#define OpCode_ReservedESC16  Make_OpCode_ESC(16)
192
#define OpCode_ReservedESC17  Make_OpCode_ESC(17)
193
#define OpCode_drop   Make_OpCode_ESC(18) /* CFF */
194
#define OpCode_ReservedESC19  Make_OpCode_ESC(19)
195
#define OpCode_put    Make_OpCode_ESC(20) /* CFF */
196
#define OpCode_get    Make_OpCode_ESC(21) /* CFF */
197
#define OpCode_ifelse   Make_OpCode_ESC(22) /* CFF */
198
#define OpCode_random   Make_OpCode_ESC(23) /* CFF */
199
#define OpCode_mul    Make_OpCode_ESC(24) /* CFF */
200
//#define OpCode_reservedESC25  Make_OpCode_ESC(25)
201
#define OpCode_sqrt   Make_OpCode_ESC(26) /* CFF */
202
#define OpCode_dup    Make_OpCode_ESC(27) /* CFF */
203
#define OpCode_exch   Make_OpCode_ESC(28) /* CFF */
204
#define OpCode_index    Make_OpCode_ESC(29) /* CFF */
205
#define OpCode_roll   Make_OpCode_ESC(30) /* CFF */
206
#define OpCode_reservedESC31  Make_OpCode_ESC(31)
207
#define OpCode_reservedESC32  Make_OpCode_ESC(32)
208
#define OpCode_reservedESC33  Make_OpCode_ESC(33)
209
0
#define OpCode_hflex    Make_OpCode_ESC(34) /* CFF, CFF2 */
210
0
#define OpCode_flex   Make_OpCode_ESC(35) /* CFF, CFF2 */
211
0
#define OpCode_hflex1   Make_OpCode_ESC(36) /* CFF, CFF2 */
212
0
#define OpCode_flex1    Make_OpCode_ESC(37) /* CFF, CFF2 */
213
214
215
0
#define OpCode_Invalid    0xFFFFu
216
217
218
struct number_t
219
{
220
0
  void init () { set_real (0.0); }
221
0
  void fini () {}
222
223
0
  void set_int (int v)       { value = v; }
224
0
  int to_int () const        { return value; }
225
226
0
  void set_fixed (int32_t v) { value = v / 65536.0; }
227
0
  int32_t to_fixed () const  { return value * 65536.0; }
228
229
0
  void set_real (double v)   { value = v; }
230
0
  double to_real () const    { return value; }
231
232
  bool in_int_range () const
233
0
  { return ((double) (int16_t) to_int () == value); }
234
235
0
  bool operator >  (const number_t &n) const { return value > n.to_real (); }
236
0
  bool operator <  (const number_t &n) const { return n > *this; }
237
0
  bool operator >= (const number_t &n) const { return !(*this < n); }
238
0
  bool operator <= (const number_t &n) const { return !(*this > n); }
239
240
  const number_t &operator += (const number_t &n)
241
0
  {
242
0
    set_real (to_real () + n.to_real ());
243
244
0
    return *this;
245
0
  }
246
247
  protected:
248
  double value;
249
};
250
251
/* byte string */
252
struct UnsizedByteStr : UnsizedArrayOf <HBUINT8>
253
{
254
  // encode 2-byte int (Dict/CharString) or 4-byte int (Dict)
255
  template <typename T, typename V>
256
  static bool serialize_int (hb_serialize_context_t *c, op_code_t intOp, V value)
257
0
  {
258
0
    TRACE_SERIALIZE (this);
259
260
0
    HBUINT8 *p = c->allocate_size<HBUINT8> (1);
261
0
    if (unlikely (!p)) return_trace (false);
262
0
    *p = intOp;
263
264
0
    T *ip = c->allocate_size<T> (T::static_size);
265
0
    if (unlikely (!ip)) return_trace (false);
266
0
    return_trace (c->check_assign (*ip, value, HB_SERIALIZE_ERROR_INT_OVERFLOW));
267
0
  }
Unexecuted instantiation: bool CFF::UnsizedByteStr::serialize_int<OT::IntType<int, 4u>, int>(hb_serialize_context_t*, unsigned int, int)
Unexecuted instantiation: bool CFF::UnsizedByteStr::serialize_int<OT::IntType<short, 2u>, int>(hb_serialize_context_t*, unsigned int, int)
Unexecuted instantiation: bool CFF::UnsizedByteStr::serialize_int<OT::IntType<int, 4u>, int>(hb_serialize_context_t*, unsigned int, int)
Unexecuted instantiation: bool CFF::UnsizedByteStr::serialize_int<OT::IntType<short, 2u>, int>(hb_serialize_context_t*, unsigned int, int)
Unexecuted instantiation: bool CFF::UnsizedByteStr::serialize_int<OT::IntType<short, 2u>, unsigned int>(hb_serialize_context_t*, unsigned int, unsigned int)
268
269
  template <typename V>
270
  static bool serialize_int4 (hb_serialize_context_t *c, V value)
271
  { return serialize_int<HBINT32> (c, OpCode_longintdict, value); }
272
273
  template <typename V>
274
  static bool serialize_int2 (hb_serialize_context_t *c, V value)
275
0
  { return serialize_int<HBINT16> (c, OpCode_shortint, value); }
276
277
  /* Defining null_size allows a Null object may be created. Should be safe because:
278
   * A descendent struct Dict uses a Null pointer to indicate a missing table,
279
   * checked before access.
280
   * byte_str_t, a wrapper struct pairing a byte pointer along with its length, always
281
   * checks the length before access. A Null pointer is used as the initial pointer
282
   * along with zero length by the default ctor.
283
   */
284
  DEFINE_SIZE_MIN(0);
285
};
286
287
/* Holder of a section of byte string within a CFFIndex entry */
288
struct byte_str_t : hb_ubytes_t
289
{
290
  byte_str_t ()
291
0
    : hb_ubytes_t () {}
292
  byte_str_t (const UnsizedByteStr& s, unsigned int l)
293
0
    : hb_ubytes_t ((const unsigned char*)&s, l) {}
294
  byte_str_t (const unsigned char *s, unsigned int l)
295
0
    : hb_ubytes_t (s, l) {}
296
  byte_str_t (const hb_ubytes_t &ub)  /* conversion from hb_ubytes_t */
297
0
    : hb_ubytes_t (ub) {}
298
299
  /* sub-string */
300
  byte_str_t sub_str (unsigned int offset, unsigned int len_) const
301
0
  { return byte_str_t (hb_ubytes_t::sub_array (offset, len_)); }
302
303
  bool check_limit (unsigned int offset, unsigned int count) const
304
0
  { return (offset + count <= length); }
305
};
306
307
/* A byte string associated with the current offset and an error condition */
308
struct byte_str_ref_t
309
{
310
0
  byte_str_ref_t () { init (); }
311
312
  void init ()
313
0
  {
314
0
    str = byte_str_t ();
315
0
    offset = 0;
316
0
    error = false;
317
0
  }
318
319
0
  void fini () {}
320
321
  byte_str_ref_t (const byte_str_t &str_, unsigned int offset_ = 0)
322
0
    : str (str_), offset (offset_), error (false) {}
323
324
  void reset (const byte_str_t &str_, unsigned int offset_ = 0)
325
0
  {
326
0
    str = str_;
327
0
    offset = offset_;
328
0
    error = false;
329
0
  }
330
331
0
  const unsigned char& operator [] (int i) {
332
0
    if (unlikely ((unsigned int) (offset + i) >= str.length))
333
0
    {
334
0
      set_error ();
335
0
      return Null (unsigned char);
336
0
    }
337
0
    return str[offset + i];
338
0
  }
339
340
  /* Conversion to byte_str_t */
341
0
  operator byte_str_t () const { return str.sub_str (offset, str.length - offset); }
342
343
  byte_str_t sub_str (unsigned int offset_, unsigned int len_) const
344
0
  { return str.sub_str (offset_, len_); }
345
346
  bool avail (unsigned int count=1) const
347
0
  { return (!in_error () && str.check_limit (offset, count)); }
348
  void inc (unsigned int count=1)
349
0
  {
350
0
    if (likely (!in_error () && (offset <= str.length) && (offset + count <= str.length)))
351
0
    {
352
0
      offset += count;
353
0
    }
354
0
    else
355
0
    {
356
0
      offset = str.length;
357
0
      set_error ();
358
0
    }
359
0
  }
360
361
0
  void set_error ()      { error = true; }
362
0
  bool in_error () const { return error; }
363
364
  byte_str_t       str;
365
  unsigned int  offset; /* beginning of the sub-string within str */
366
367
  protected:
368
  bool    error;
369
};
370
371
typedef hb_vector_t<byte_str_t> byte_str_array_t;
372
373
/* stack */
374
template <typename ELEM, int LIMIT>
375
struct cff_stack_t
376
{
377
  void init ()
378
0
  {
379
0
    error = false;
380
0
    count = 0;
381
0
    elements.init ();
382
0
    elements.resize (kSizeLimit);
383
0
    for (unsigned int i = 0; i < elements.length; i++)
384
0
      elements[i].init ();
385
0
  }
Unexecuted instantiation: CFF::cff_stack_t<CFF::number_t, 513>::init()
Unexecuted instantiation: CFF::cff_stack_t<CFF::call_context_t, 10>::init()
Unexecuted instantiation: CFF::cff_stack_t<CFF::blend_arg_t, 513>::init()
386
0
  void fini () { elements.fini_deep (); }
Unexecuted instantiation: CFF::cff_stack_t<CFF::number_t, 513>::fini()
Unexecuted instantiation: CFF::cff_stack_t<CFF::call_context_t, 10>::fini()
Unexecuted instantiation: CFF::cff_stack_t<CFF::blend_arg_t, 513>::fini()
387
388
  ELEM& operator [] (unsigned int i)
389
0
  {
390
0
    if (unlikely (i >= count)) set_error ();
391
0
    return elements[i];
392
0
  }
Unexecuted instantiation: CFF::cff_stack_t<CFF::number_t, 513>::operator[](unsigned int)
Unexecuted instantiation: CFF::cff_stack_t<CFF::blend_arg_t, 513>::operator[](unsigned int)
Unexecuted instantiation: CFF::cff_stack_t<CFF::call_context_t, 10>::operator[](unsigned int)
393
394
  void push (const ELEM &v)
395
0
  {
396
0
    if (likely (count < elements.length))
397
0
      elements[count++] = v;
398
0
    else
399
0
      set_error ();
400
0
  }
401
  ELEM &push ()
402
0
  {
403
0
    if (likely (count < elements.length))
404
0
      return elements[count++];
405
0
    else
406
0
    {
407
0
      set_error ();
408
0
      return Crap (ELEM);
409
0
    }
410
0
  }
Unexecuted instantiation: CFF::cff_stack_t<CFF::number_t, 513>::push()
Unexecuted instantiation: CFF::cff_stack_t<CFF::blend_arg_t, 513>::push()
411
412
  ELEM& pop ()
413
0
  {
414
0
    if (likely (count > 0))
415
0
      return elements[--count];
416
0
    else
417
0
    {
418
0
      set_error ();
419
0
      return Crap (ELEM);
420
0
    }
421
0
  }
Unexecuted instantiation: CFF::cff_stack_t<CFF::number_t, 513>::pop()
Unexecuted instantiation: CFF::cff_stack_t<CFF::call_context_t, 10>::pop()
Unexecuted instantiation: CFF::cff_stack_t<CFF::blend_arg_t, 513>::pop()
422
  void pop (unsigned int n)
423
0
  {
424
0
    if (likely (count >= n))
425
0
      count -= n;
426
0
    else
427
0
      set_error ();
428
0
  }
Unexecuted instantiation: CFF::cff_stack_t<CFF::number_t, 513>::pop(unsigned int)
Unexecuted instantiation: CFF::cff_stack_t<CFF::blend_arg_t, 513>::pop(unsigned int)
429
430
  const ELEM& peek ()
431
0
  {
432
0
    if (unlikely (count < 0))
433
0
    {
434
0
      set_error ();
435
0
      return Null (ELEM);
436
0
    }
437
0
    return elements[count - 1];
438
0
  }
439
440
  void unpop ()
441
  {
442
    if (likely (count < elements.length))
443
      count++;
444
    else
445
      set_error ();
446
  }
447
448
  void clear () { count = 0; }
449
450
0
  bool in_error () const { return (error || elements.in_error ()); }
Unexecuted instantiation: CFF::cff_stack_t<CFF::number_t, 513>::in_error() const
Unexecuted instantiation: CFF::cff_stack_t<CFF::call_context_t, 10>::in_error() const
Unexecuted instantiation: CFF::cff_stack_t<CFF::blend_arg_t, 513>::in_error() const
451
0
  void set_error ()      { error = true; }
Unexecuted instantiation: CFF::cff_stack_t<CFF::number_t, 513>::set_error()
Unexecuted instantiation: CFF::cff_stack_t<CFF::call_context_t, 10>::set_error()
Unexecuted instantiation: CFF::cff_stack_t<CFF::blend_arg_t, 513>::set_error()
452
453
0
  unsigned int get_count () const { return count; }
Unexecuted instantiation: CFF::cff_stack_t<CFF::number_t, 513>::get_count() const
Unexecuted instantiation: CFF::cff_stack_t<CFF::call_context_t, 10>::get_count() const
Unexecuted instantiation: CFF::cff_stack_t<CFF::blend_arg_t, 513>::get_count() const
454
0
  bool is_empty () const          { return !count; }
Unexecuted instantiation: CFF::cff_stack_t<CFF::number_t, 513>::is_empty() const
Unexecuted instantiation: CFF::cff_stack_t<CFF::call_context_t, 10>::is_empty() const
455
456
  static constexpr unsigned kSizeLimit = LIMIT;
457
458
  protected:
459
  bool error;
460
  unsigned int count;
461
  hb_vector_t<ELEM> elements;
462
};
463
464
/* argument stack */
465
template <typename ARG=number_t>
466
struct arg_stack_t : cff_stack_t<ARG, 513>
467
{
468
  void push_int (int v)
469
0
  {
470
0
    ARG &n = S::push ();
471
0
    n.set_int (v);
472
0
  }
Unexecuted instantiation: CFF::arg_stack_t<CFF::number_t>::push_int(int)
Unexecuted instantiation: CFF::arg_stack_t<CFF::blend_arg_t>::push_int(int)
473
474
  void push_fixed (int32_t v)
475
0
  {
476
0
    ARG &n = S::push ();
477
0
    n.set_fixed (v);
478
0
  }
Unexecuted instantiation: CFF::arg_stack_t<CFF::number_t>::push_fixed(int)
Unexecuted instantiation: CFF::arg_stack_t<CFF::blend_arg_t>::push_fixed(int)
479
480
  void push_real (double v)
481
0
  {
482
0
    ARG &n = S::push ();
483
0
    n.set_real (v);
484
0
  }
485
486
0
  ARG& pop_num () { return this->pop (); }
487
488
0
  int pop_int ()  { return this->pop ().to_int (); }
Unexecuted instantiation: CFF::arg_stack_t<CFF::number_t>::pop_int()
Unexecuted instantiation: CFF::arg_stack_t<CFF::blend_arg_t>::pop_int()
489
490
  unsigned int pop_uint ()
491
0
  {
492
0
    int i = pop_int ();
493
0
    if (unlikely (i < 0))
494
0
    {
495
0
      i = 0;
496
0
      S::set_error ();
497
0
    }
498
0
    return (unsigned) i;
499
0
  }
Unexecuted instantiation: CFF::arg_stack_t<CFF::number_t>::pop_uint()
Unexecuted instantiation: CFF::arg_stack_t<CFF::blend_arg_t>::pop_uint()
500
501
  void push_longint_from_substr (byte_str_ref_t& str_ref)
502
0
  {
503
0
    push_int ((str_ref[0] << 24) | (str_ref[1] << 16) | (str_ref[2] << 8) | (str_ref[3]));
504
0
    str_ref.inc (4);
505
0
  }
506
507
  bool push_fixed_from_substr (byte_str_ref_t& str_ref)
508
0
  {
509
0
    if (unlikely (!str_ref.avail (4)))
510
0
      return false;
511
0
    push_fixed ((int32_t)*(const HBUINT32*)&str_ref[0]);
512
0
    str_ref.inc (4);
513
0
    return true;
514
0
  }
Unexecuted instantiation: CFF::arg_stack_t<CFF::number_t>::push_fixed_from_substr(CFF::byte_str_ref_t&)
Unexecuted instantiation: CFF::arg_stack_t<CFF::blend_arg_t>::push_fixed_from_substr(CFF::byte_str_ref_t&)
515
516
  hb_array_t<const ARG> get_subarray (unsigned int start) const
517
0
  { return S::elements.sub_array (start); }
518
519
  private:
520
  typedef cff_stack_t<ARG, 513> S;
521
};
522
523
/* an operator prefixed by its operands in a byte string */
524
struct op_str_t
525
{
526
0
  void init () {}
527
0
  void fini () {}
528
529
  op_code_t  op;
530
  byte_str_t str;
531
};
532
533
/* base of OP_SERIALIZER */
534
struct op_serializer_t
535
{
536
  protected:
537
  bool copy_opstr (hb_serialize_context_t *c, const op_str_t& opstr) const
538
0
  {
539
0
    TRACE_SERIALIZE (this);
540
541
0
    HBUINT8 *d = c->allocate_size<HBUINT8> (opstr.str.length);
542
0
    if (unlikely (!d)) return_trace (false);
543
0
    memcpy (d, &opstr.str[0], opstr.str.length);
544
0
    return_trace (true);
545
0
  }
Unexecuted instantiation: CFF::op_serializer_t::copy_opstr(hb_serialize_context_t*, CFF::op_str_t const&) const
Unexecuted instantiation: CFF::op_serializer_t::copy_opstr(hb_serialize_context_t*, CFF::op_str_t const&) const
546
};
547
548
template <typename VAL>
549
struct parsed_values_t
550
{
551
  void init ()
552
0
  {
553
0
    opStart = 0;
554
0
    values.init ();
555
0
  }
Unexecuted instantiation: CFF::parsed_values_t<CFF::cff1_top_dict_val_t>::init()
Unexecuted instantiation: CFF::parsed_values_t<CFF::op_str_t>::init()
Unexecuted instantiation: CFF::parsed_values_t<CFF::dict_val_t>::init()
Unexecuted instantiation: CFF::parsed_values_t<CFF::parsed_cs_op_t>::init()
556
0
  void fini () { values.fini_deep (); }
Unexecuted instantiation: CFF::parsed_values_t<CFF::cff1_top_dict_val_t>::fini()
Unexecuted instantiation: CFF::parsed_values_t<CFF::op_str_t>::fini()
Unexecuted instantiation: CFF::parsed_values_t<CFF::dict_val_t>::fini()
Unexecuted instantiation: CFF::parsed_values_t<CFF::parsed_cs_op_t>::fini()
557
558
  void add_op (op_code_t op, const byte_str_ref_t& str_ref = byte_str_ref_t ())
559
0
  {
560
0
    VAL *val = values.push ();
561
0
    val->op = op;
562
0
    val->str = str_ref.str.sub_str (opStart, str_ref.offset - opStart);
563
0
    opStart = str_ref.offset;
564
0
  }
Unexecuted instantiation: CFF::parsed_values_t<CFF::op_str_t>::add_op(unsigned int, CFF::byte_str_ref_t const&)
Unexecuted instantiation: CFF::parsed_values_t<CFF::cff1_top_dict_val_t>::add_op(unsigned int, CFF::byte_str_ref_t const&)
Unexecuted instantiation: CFF::parsed_values_t<CFF::parsed_cs_op_t>::add_op(unsigned int, CFF::byte_str_ref_t const&)
565
566
  void add_op (op_code_t op, const byte_str_ref_t& str_ref, const VAL &v)
567
0
  {
568
0
    VAL *val = values.push (v);
569
0
    val->op = op;
570
0
    val->str = str_ref.sub_str ( opStart, str_ref.offset - opStart);
571
0
    opStart = str_ref.offset;
572
0
  }
Unexecuted instantiation: CFF::parsed_values_t<CFF::cff1_top_dict_val_t>::add_op(unsigned int, CFF::byte_str_ref_t const&, CFF::cff1_top_dict_val_t const&)
Unexecuted instantiation: CFF::parsed_values_t<CFF::dict_val_t>::add_op(unsigned int, CFF::byte_str_ref_t const&, CFF::dict_val_t const&)
Unexecuted instantiation: CFF::parsed_values_t<CFF::parsed_cs_op_t>::add_op(unsigned int, CFF::byte_str_ref_t const&, CFF::parsed_cs_op_t const&)
573
574
  bool has_op (op_code_t op) const
575
0
  {
576
0
    for (unsigned int i = 0; i < get_count (); i++)
577
0
      if (get_value (i).op == op) return true;
578
0
    return false;
579
0
  }
580
581
0
  unsigned get_count () const { return values.length; }
Unexecuted instantiation: CFF::parsed_values_t<CFF::op_str_t>::get_count() const
Unexecuted instantiation: CFF::parsed_values_t<CFF::cff1_top_dict_val_t>::get_count() const
Unexecuted instantiation: CFF::parsed_values_t<CFF::parsed_cs_op_t>::get_count() const
582
0
  const VAL &get_value (unsigned int i)   const { return values[i]; }
Unexecuted instantiation: CFF::parsed_values_t<CFF::op_str_t>::get_value(unsigned int) const
Unexecuted instantiation: CFF::parsed_values_t<CFF::cff1_top_dict_val_t>::get_value(unsigned int) const
583
0
  const VAL &operator [] (unsigned int i) const { return get_value (i); }
Unexecuted instantiation: CFF::parsed_values_t<CFF::op_str_t>::operator[](unsigned int) const
Unexecuted instantiation: CFF::parsed_values_t<CFF::cff1_top_dict_val_t>::operator[](unsigned int) const
584
585
  unsigned int       opStart;
586
  hb_vector_t<VAL>   values;
587
};
588
589
template <typename ARG=number_t>
590
struct interp_env_t
591
{
592
  void init (const byte_str_t &str_)
593
0
  {
594
0
    str_ref.reset (str_);
595
0
    argStack.init ();
596
0
    error = false;
597
0
  }
Unexecuted instantiation: CFF::interp_env_t<CFF::number_t>::init(CFF::byte_str_t const&)
Unexecuted instantiation: CFF::interp_env_t<CFF::blend_arg_t>::init(CFF::byte_str_t const&)
598
0
  void fini () { argStack.fini (); }
Unexecuted instantiation: CFF::interp_env_t<CFF::number_t>::fini()
Unexecuted instantiation: CFF::interp_env_t<CFF::blend_arg_t>::fini()
599
600
  bool in_error () const
601
0
  { return error || str_ref.in_error () || argStack.in_error (); }
Unexecuted instantiation: CFF::interp_env_t<CFF::number_t>::in_error() const
Unexecuted instantiation: CFF::interp_env_t<CFF::blend_arg_t>::in_error() const
602
603
0
  void set_error () { error = true; }
Unexecuted instantiation: CFF::interp_env_t<CFF::number_t>::set_error()
Unexecuted instantiation: CFF::interp_env_t<CFF::blend_arg_t>::set_error()
604
605
  op_code_t fetch_op ()
606
0
  {
607
0
    op_code_t  op = OpCode_Invalid;
608
0
    if (unlikely (!str_ref.avail ()))
609
0
      return OpCode_Invalid;
610
0
    op = (op_code_t)(unsigned char)str_ref[0];
611
0
    if (op == OpCode_escape) {
612
0
      if (unlikely (!str_ref.avail ()))
613
0
  return OpCode_Invalid;
614
0
      op = Make_OpCode_ESC(str_ref[1]);
615
0
      str_ref.inc ();
616
0
    }
617
0
    str_ref.inc ();
618
0
    return op;
619
0
  }
Unexecuted instantiation: CFF::interp_env_t<CFF::number_t>::fetch_op()
Unexecuted instantiation: CFF::interp_env_t<CFF::blend_arg_t>::fetch_op()
620
621
0
  const ARG& eval_arg (unsigned int i) { return argStack[i]; }
622
623
0
  ARG& pop_arg () { return argStack.pop (); }
624
0
  void pop_n_args (unsigned int n) { argStack.pop (n); }
Unexecuted instantiation: CFF::interp_env_t<CFF::number_t>::pop_n_args(unsigned int)
Unexecuted instantiation: CFF::interp_env_t<CFF::blend_arg_t>::pop_n_args(unsigned int)
625
626
0
  void clear_args () { pop_n_args (argStack.get_count ()); }
Unexecuted instantiation: CFF::interp_env_t<CFF::number_t>::clear_args()
Unexecuted instantiation: CFF::interp_env_t<CFF::blend_arg_t>::clear_args()
627
628
  byte_str_ref_t
629
    str_ref;
630
  arg_stack_t<ARG>
631
    argStack;
632
  protected:
633
  bool    error;
634
};
635
636
typedef interp_env_t<> num_interp_env_t;
637
638
template <typename ARG=number_t>
639
struct opset_t
640
{
641
  static void process_op (op_code_t op, interp_env_t<ARG>& env)
642
0
  {
643
0
    switch (op) {
644
0
      case OpCode_shortint:
645
0
  env.argStack.push_int ((int16_t)((env.str_ref[0] << 8) | env.str_ref[1]));
646
0
  env.str_ref.inc (2);
647
0
  break;
648
649
0
      case OpCode_TwoBytePosInt0: case OpCode_TwoBytePosInt1:
650
0
      case OpCode_TwoBytePosInt2: case OpCode_TwoBytePosInt3:
651
0
  env.argStack.push_int ((int16_t)((op - OpCode_TwoBytePosInt0) * 256 + env.str_ref[0] + 108));
652
0
  env.str_ref.inc ();
653
0
  break;
654
655
0
      case OpCode_TwoByteNegInt0: case OpCode_TwoByteNegInt1:
656
0
      case OpCode_TwoByteNegInt2: case OpCode_TwoByteNegInt3:
657
0
  env.argStack.push_int ((-(int16_t)(op - OpCode_TwoByteNegInt0) * 256 - env.str_ref[0] - 108));
658
0
  env.str_ref.inc ();
659
0
  break;
660
661
0
      default:
662
  /* 1-byte integer */
663
0
  if (likely ((OpCode_OneByteIntFirst <= op) && (op <= OpCode_OneByteIntLast)))
664
0
  {
665
0
    env.argStack.push_int ((int)op - 139);
666
0
  } else {
667
    /* invalid unknown operator */
668
0
    env.clear_args ();
669
0
    env.set_error ();
670
0
  }
671
0
  break;
672
0
    }
673
0
  }
Unexecuted instantiation: CFF::opset_t<CFF::number_t>::process_op(unsigned int, CFF::interp_env_t<CFF::number_t>&)
Unexecuted instantiation: CFF::opset_t<CFF::blend_arg_t>::process_op(unsigned int, CFF::interp_env_t<CFF::blend_arg_t>&)
674
};
675
676
template <typename ENV>
677
struct interpreter_t
678
{
679
0
  ~interpreter_t() { fini (); }
Unexecuted instantiation: CFF::interpreter_t<CFF::cff1_top_dict_interp_env_t>::~interpreter_t()
Unexecuted instantiation: CFF::interpreter_t<CFF::interp_env_t<CFF::number_t> >::~interpreter_t()
Unexecuted instantiation: CFF::interpreter_t<CFF::cff2_priv_dict_interp_env_t>::~interpreter_t()
Unexecuted instantiation: CFF::interpreter_t<CFF::cff1_cs_interp_env_t>::~interpreter_t()
Unexecuted instantiation: CFF::interpreter_t<CFF::cff2_cs_interp_env_t>::~interpreter_t()
680
681
0
  void fini () { env.fini (); }
Unexecuted instantiation: CFF::interpreter_t<CFF::cff1_top_dict_interp_env_t>::fini()
Unexecuted instantiation: CFF::interpreter_t<CFF::interp_env_t<CFF::number_t> >::fini()
Unexecuted instantiation: CFF::interpreter_t<CFF::cff2_priv_dict_interp_env_t>::fini()
Unexecuted instantiation: CFF::interpreter_t<CFF::cff1_cs_interp_env_t>::fini()
Unexecuted instantiation: CFF::interpreter_t<CFF::cff2_cs_interp_env_t>::fini()
682
683
  ENV env;
684
};
685
686
} /* namespace CFF */
687
688
#endif /* HB_CFF_INTERP_COMMON_HH */