QtBase  v6.3.1
hb-cff-interp-common.hh
Go to the documentation of this file.
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 #define OpCode_version 0 /* CFF Top */
40 #define OpCode_Notice 1 /* CFF Top */
41 #define OpCode_FullName 2 /* CFF Top */
42 #define OpCode_FamilyName 3 /* CFF Top */
43 #define OpCode_Weight 4 /* CFF Top */
44 #define OpCode_FontBBox 5 /* CFF Top */
45 #define OpCode_BlueValues 6 /* CFF Private, CFF2 Private */
46 #define OpCode_OtherBlues 7 /* CFF Private, CFF2 Private */
47 #define OpCode_FamilyBlues 8 /* CFF Private, CFF2 Private */
48 #define OpCode_FamilyOtherBlues 9 /* CFF Private, CFF2 Private */
49 #define OpCode_StdHW 10 /* CFF Private, CFF2 Private */
50 #define OpCode_StdVW 11 /* CFF Private, CFF2 Private */
51 #define OpCode_escape 12 /* All. Shared with CS */
52 #define OpCode_UniqueID 13 /* CFF Top */
53 #define OpCode_XUID 14 /* CFF Top */
54 #define OpCode_charset 15 /* CFF Top (0) */
55 #define OpCode_Encoding 16 /* CFF Top (0) */
56 #define OpCode_CharStrings 17 /* CFF Top, CFF2 Top */
57 #define OpCode_Private 18 /* CFF Top, CFF2 FD */
58 #define OpCode_Subrs 19 /* CFF Private, CFF2 Private */
59 #define OpCode_defaultWidthX 20 /* CFF Private (0) */
60 #define OpCode_nominalWidthX 21 /* CFF Private (0) */
61 #define OpCode_vsindexdict 22 /* CFF2 Private/CS */
62 #define OpCode_blenddict 23 /* CFF2 Private/CS */
63 #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 #define OpCode_shortint 28 /* 16-bit integer, All */
70 #define OpCode_longintdict 29 /* 32-bit integer, All */
71 #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 #define OpCode_TwoBytePosInt0 247 /* All. first byte of two byte positive int (+108 to +1131) */
80 #define OpCode_TwoBytePosInt1 248
81 #define OpCode_TwoBytePosInt2 249
82 #define OpCode_TwoBytePosInt3 250
83 
84 #define OpCode_TwoByteNegInt0 251 /* All. first byte of two byte negative int (-1131 to -108) */
85 #define OpCode_TwoByteNegInt1 252
86 #define OpCode_TwoByteNegInt2 253
87 #define OpCode_TwoByteNegInt3 254
88 
89 /* Two byte escape operators 12, (0-41) */
90 #define OpCode_ESC_Base 256
91 #define Make_OpCode_ESC(byte2) ((op_code_t)(OpCode_ESC_Base + (byte2)))
92 
94 inline bool Is_OpCode_ESC (op_code_t op) { return op >= OpCode_ESC_Base; }
95 inline unsigned int OpCode_Size (op_code_t op) { return Is_OpCode_ESC (op) ? 2: 1; }
96 
97 #define OpCode_Copyright Make_OpCode_ESC(0) /* CFF Top */
98 #define OpCode_isFixedPitch Make_OpCode_ESC(1) /* CFF Top (false) */
99 #define OpCode_ItalicAngle Make_OpCode_ESC(2) /* CFF Top (0) */
100 #define OpCode_UnderlinePosition Make_OpCode_ESC(3) /* CFF Top (-100) */
101 #define OpCode_UnderlineThickness Make_OpCode_ESC(4) /* CFF Top (50) */
102 #define OpCode_PaintType Make_OpCode_ESC(5) /* CFF Top (0) */
103 #define OpCode_CharstringType Make_OpCode_ESC(6) /* CFF Top (2) */
104 #define OpCode_FontMatrix Make_OpCode_ESC(7) /* CFF Top, CFF2 Top (.001 0 0 .001 0 0)*/
105 #define OpCode_StrokeWidth Make_OpCode_ESC(8) /* CFF Top (0) */
106 #define OpCode_BlueScale Make_OpCode_ESC(9) /* CFF Private, CFF2 Private (0.039625) */
107 #define OpCode_BlueShift Make_OpCode_ESC(10) /* CFF Private, CFF2 Private (7) */
108 #define OpCode_BlueFuzz Make_OpCode_ESC(11) /* CFF Private, CFF2 Private (1) */
109 #define OpCode_StemSnapH Make_OpCode_ESC(12) /* CFF Private, CFF2 Private */
110 #define OpCode_StemSnapV Make_OpCode_ESC(13) /* CFF Private, CFF2 Private */
111 #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 #define OpCode_LanguageGroup Make_OpCode_ESC(17) /* CFF Private, CFF2 Private (0) */
115 #define OpCode_ExpansionFactor Make_OpCode_ESC(18) /* CFF Private, CFF2 Private (0.06) */
116 #define OpCode_initialRandomSeed Make_OpCode_ESC(19) /* CFF Private (0) */
117 #define OpCode_SyntheticBase Make_OpCode_ESC(20) /* CFF Top */
118 #define OpCode_PostScript Make_OpCode_ESC(21) /* CFF Top */
119 #define OpCode_BaseFontName Make_OpCode_ESC(22) /* CFF Top */
120 #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 #define OpCode_ROS Make_OpCode_ESC(30) /* CFF Top_CID */
128 #define OpCode_CIDFontVersion Make_OpCode_ESC(31) /* CFF Top_CID (0) */
129 #define OpCode_CIDFontRevision Make_OpCode_ESC(32) /* CFF Top_CID (0) */
130 #define OpCode_CIDFontType Make_OpCode_ESC(33) /* CFF Top_CID (0) */
131 #define OpCode_CIDCount Make_OpCode_ESC(34) /* CFF Top_CID (8720) */
132 #define OpCode_UIDBase Make_OpCode_ESC(35) /* CFF Top_CID */
133 #define OpCode_FDArray Make_OpCode_ESC(36) /* CFF Top_CID, CFF2 Top */
134 #define OpCode_FDSelect Make_OpCode_ESC(37) /* CFF Top_CID, CFF2 Top */
135 #define OpCode_FontName Make_OpCode_ESC(38) /* CFF Top_CID */
136 
137 
138 /* === CharString operators === */
139 
140 #define OpCode_hstem 1 /* CFF, CFF2 */
141 #define OpCode_Reserved2 2
142 #define OpCode_vstem 3 /* CFF, CFF2 */
143 #define OpCode_vmoveto 4 /* CFF, CFF2 */
144 #define OpCode_rlineto 5 /* CFF, CFF2 */
145 #define OpCode_hlineto 6 /* CFF, CFF2 */
146 #define OpCode_vlineto 7 /* CFF, CFF2 */
147 #define OpCode_rrcurveto 8 /* CFF, CFF2 */
148 #define OpCode_Reserved9 9
149 #define OpCode_callsubr 10 /* CFF, CFF2 */
150 #define OpCode_return 11 /* CFF */
151 //#define OpCode_escape 12 /* CFF, CFF2 */
152 #define OpCode_Reserved13 13
153 #define OpCode_endchar 14 /* CFF */
154 #define OpCode_vsindexcs 15 /* CFF2 */
155 #define OpCode_blendcs 16 /* CFF2 */
156 #define OpCode_Reserved17 17
157 #define OpCode_hstemhm 18 /* CFF, CFF2 */
158 #define OpCode_hintmask 19 /* CFF, CFF2 */
159 #define OpCode_cntrmask 20 /* CFF, CFF2 */
160 #define OpCode_rmoveto 21 /* CFF, CFF2 */
161 #define OpCode_hmoveto 22 /* CFF, CFF2 */
162 #define OpCode_vstemhm 23 /* CFF, CFF2 */
163 #define OpCode_rcurveline 24 /* CFF, CFF2 */
164 #define OpCode_rlinecurve 25 /* CFF, CFF2 */
165 #define OpCode_vvcurveto 26 /* CFF, CFF2 */
166 #define OpCode_hhcurveto 27 /* CFF, CFF2 */
167 //#define OpCode_shortint 28 /* CFF, CFF2 */
168 #define OpCode_callgsubr 29 /* CFF, CFF2 */
169 #define OpCode_vhcurveto 30 /* CFF, CFF2 */
170 #define OpCode_hvcurveto 31 /* CFF, CFF2 */
171 
172 #define OpCode_fixedcs 255 /* 32-bit fixed */
173 
174 /* Two byte escape operators 12, (0-41) */
175 #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 #define OpCode_hflex Make_OpCode_ESC(34) /* CFF, CFF2 */
210 #define OpCode_flex Make_OpCode_ESC(35) /* CFF, CFF2 */
211 #define OpCode_hflex1 Make_OpCode_ESC(36) /* CFF, CFF2 */
212 #define OpCode_flex1 Make_OpCode_ESC(37) /* CFF, CFF2 */
213 
214 
215 #define OpCode_Invalid 0xFFFFu
216 
217 
218 struct number_t
219 {
220  void set_int (int v) { value = v; }
221  int to_int () const { return value; }
222 
223  void set_fixed (int32_t v) { value = v / 65536.0; }
224  int32_t to_fixed () const { return value * 65536.0; }
225 
226  void set_real (double v) { value = v; }
227  double to_real () const { return value; }
228 
229  bool in_int_range () const
230  { return ((double) (int16_t) to_int () == value); }
231 
232  bool operator > (const number_t &n) const { return value > n.to_real (); }
233  bool operator < (const number_t &n) const { return n > *this; }
234  bool operator >= (const number_t &n) const { return !(*this < n); }
235  bool operator <= (const number_t &n) const { return !(*this > n); }
236 
238  {
239  set_real (to_real () + n.to_real ());
240 
241  return *this;
242  }
243 
244  protected:
245  double value = 0.;
246 };
247 
248 /* byte string */
249 struct UnsizedByteStr : UnsizedArrayOf <HBUINT8>
250 {
251  // encode 2-byte int (Dict/CharString) or 4-byte int (Dict)
252  template <typename T, typename V>
254  {
255  TRACE_SERIALIZE (this);
256 
257  HBUINT8 *p = c->allocate_size<HBUINT8> (1);
258  if (unlikely (!p)) return_trace (false);
259  *p = intOp;
260 
261  T *ip = c->allocate_size<T> (T::static_size);
262  if (unlikely (!ip)) return_trace (false);
263  return_trace (c->check_assign (*ip, value, HB_SERIALIZE_ERROR_INT_OVERFLOW));
264  }
265 
266  template <typename V>
268  { return serialize_int<HBINT32> (c, OpCode_longintdict, value); }
269 
270  template <typename V>
272  { return serialize_int<HBINT16> (c, OpCode_shortint, value); }
273 
274  /* Defining null_size allows a Null object may be created. Should be safe because:
275  * A descendent struct Dict uses a Null pointer to indicate a missing table,
276  * checked before access.
277  * byte_str_t, a wrapper struct pairing a byte pointer along with its length, always
278  * checks the length before access. A Null pointer is used as the initial pointer
279  * along with zero length by the default ctor.
280  */
282 };
283 
284 /* Holder of a section of byte string within a CFFIndex entry */
286 {
288  : hb_ubytes_t () {}
289  byte_str_t (const UnsizedByteStr& s, unsigned int l)
290  : hb_ubytes_t ((const unsigned char*)&s, l) {}
291  byte_str_t (const unsigned char *s, unsigned int l)
292  : hb_ubytes_t (s, l) {}
293  byte_str_t (const hb_ubytes_t &ub) /* conversion from hb_ubytes_t */
294  : hb_ubytes_t (ub) {}
295 
296  /* sub-string */
297  byte_str_t sub_str (unsigned int offset, unsigned int len_) const
298  { return byte_str_t (hb_ubytes_t::sub_array (offset, len_)); }
299 
300  bool check_limit (unsigned int offset, unsigned int count) const
301  { return (offset + count <= length); }
302 };
303 
304 /* A byte string associated with the current offset and an error condition */
306 {
307  byte_str_ref_t () { init (); }
308 
309  void init ()
310  {
311  str = byte_str_t ();
312  offset = 0;
313  error = false;
314  }
315 
316  void fini () {}
317 
318  byte_str_ref_t (const byte_str_t &str_, unsigned int offset_ = 0)
319  : str (str_), offset (offset_), error (false) {}
320 
321  void reset (const byte_str_t &str_, unsigned int offset_ = 0)
322  {
323  str = str_;
324  offset = offset_;
325  error = false;
326  }
327 
328  const unsigned char& operator [] (int i) {
329  if (unlikely ((unsigned int) (offset + i) >= str.length))
330  {
331  set_error ();
332  return Null (unsigned char);
333  }
334  return str[offset + i];
335  }
336 
337  /* Conversion to byte_str_t */
338  operator byte_str_t () const { return str.sub_str (offset, str.length - offset); }
339 
340  byte_str_t sub_str (unsigned int offset_, unsigned int len_) const
341  { return str.sub_str (offset_, len_); }
342 
343  bool avail (unsigned int count=1) const
344  { return (!in_error () && str.check_limit (offset, count)); }
345  void inc (unsigned int count=1)
346  {
347  if (likely (!in_error () && (offset <= str.length) && (offset + count <= str.length)))
348  {
349  offset += count;
350  }
351  else
352  {
353  offset = str.length;
354  set_error ();
355  }
356  }
357 
358  void set_error () { error = true; }
359  bool in_error () const { return error; }
360 
362  unsigned int offset; /* beginning of the sub-string within str */
363 
364  protected:
365  bool error;
366 };
367 
369 
370 /* stack */
371 template <typename ELEM, int LIMIT>
373 {
374  void init ()
375  {
376  error = false;
377  count = 0;
378  elements.init ();
380  }
381  void fini () { elements.fini (); }
382 
383  ELEM& operator [] (unsigned int i)
384  {
385  if (unlikely (i >= count)) set_error ();
386  return elements[i];
387  }
388 
389  void push (const ELEM &v)
390  {
391  if (likely (count < elements.length))
392  elements[count++] = v;
393  else
394  set_error ();
395  }
396  ELEM &push ()
397  {
398  if (likely (count < elements.length))
399  return elements[count++];
400  else
401  {
402  set_error ();
403  return Crap (ELEM);
404  }
405  }
406 
407  ELEM& pop ()
408  {
409  if (likely (count > 0))
410  return elements[--count];
411  else
412  {
413  set_error ();
414  return Crap (ELEM);
415  }
416  }
417  void pop (unsigned int n)
418  {
419  if (likely (count >= n))
420  count -= n;
421  else
422  set_error ();
423  }
424 
425  const ELEM& peek ()
426  {
427  if (unlikely (count < 0))
428  {
429  set_error ();
430  return Null (ELEM);
431  }
432  return elements[count - 1];
433  }
434 
435  void unpop ()
436  {
437  if (likely (count < elements.length))
438  count++;
439  else
440  set_error ();
441  }
442 
443  void clear () { count = 0; }
444 
445  bool in_error () const { return (error || elements.in_error ()); }
446  void set_error () { error = true; }
447 
448  unsigned int get_count () const { return count; }
449  bool is_empty () const { return !count; }
450 
451  static constexpr unsigned kSizeLimit = LIMIT;
452 
453  protected:
454  bool error;
455  unsigned int count;
457 };
458 
459 /* argument stack */
460 template <typename ARG=number_t>
461 struct arg_stack_t : cff_stack_t<ARG, 513>
462 {
463  void push_int (int v)
464  {
465  ARG &n = S::push ();
466  n.set_int (v);
467  }
468 
469  void push_fixed (int32_t v)
470  {
471  ARG &n = S::push ();
472  n.set_fixed (v);
473  }
474 
475  void push_real (double v)
476  {
477  ARG &n = S::push ();
478  n.set_real (v);
479  }
480 
481  ARG& pop_num () { return this->pop (); }
482 
483  int pop_int () { return this->pop ().to_int (); }
484 
485  unsigned int pop_uint ()
486  {
487  int i = pop_int ();
488  if (unlikely (i < 0))
489  {
490  i = 0;
491  S::set_error ();
492  }
493  return (unsigned) i;
494  }
495 
497  {
498  push_int ((str_ref[0] << 24) | (str_ref[1] << 16) | (str_ref[2] << 8) | (str_ref[3]));
499  str_ref.inc (4);
500  }
501 
503  {
504  if (unlikely (!str_ref.avail (4)))
505  return false;
506  push_fixed ((int32_t)*(const HBUINT32*)&str_ref[0]);
507  str_ref.inc (4);
508  return true;
509  }
510 
512  { return S::elements.sub_array (start); }
513 
514  private:
515  typedef cff_stack_t<ARG, 513> S;
516 };
517 
518 /* an operator prefixed by its operands in a byte string */
519 struct op_str_t
520 {
523 };
524 
525 /* base of OP_SERIALIZER */
527 {
528  protected:
529  bool copy_opstr (hb_serialize_context_t *c, const op_str_t& opstr) const
530  {
531  TRACE_SERIALIZE (this);
532 
533  HBUINT8 *d = c->allocate_size<HBUINT8> (opstr.str.length);
534  if (unlikely (!d)) return_trace (false);
535  memcpy (d, &opstr.str[0], opstr.str.length);
536  return_trace (true);
537  }
538 };
539 
540 template <typename VAL>
542 {
543  void init ()
544  {
545  opStart = 0;
546  values.init ();
547  }
548  void fini () { values.fini (); }
549 
550  void add_op (op_code_t op, const byte_str_ref_t& str_ref = byte_str_ref_t ())
551  {
552  VAL *val = values.push ();
553  val->op = op;
554  val->str = str_ref.str.sub_str (opStart, str_ref.offset - opStart);
555  opStart = str_ref.offset;
556  }
557 
558  void add_op (op_code_t op, const byte_str_ref_t& str_ref, const VAL &v)
559  {
560  VAL *val = values.push (v);
561  val->op = op;
562  val->str = str_ref.sub_str ( opStart, str_ref.offset - opStart);
563  opStart = str_ref.offset;
564  }
565 
566  bool has_op (op_code_t op) const
567  {
568  for (unsigned int i = 0; i < get_count (); i++)
569  if (get_value (i).op == op) return true;
570  return false;
571  }
572 
573  unsigned get_count () const { return values.length; }
574  const VAL &get_value (unsigned int i) const { return values[i]; }
575  const VAL &operator [] (unsigned int i) const { return get_value (i); }
576 
577  unsigned int opStart;
579 };
580 
581 template <typename ARG=number_t>
583 {
584  void init (const byte_str_t &str_)
585  {
586  str_ref.reset (str_);
587  argStack.init ();
588  error = false;
589  }
590  void fini () { argStack.fini (); }
591 
592  bool in_error () const
593  { return error || str_ref.in_error () || argStack.in_error (); }
594 
595  void set_error () { error = true; }
596 
598  {
600  if (unlikely (!str_ref.avail ()))
601  return OpCode_Invalid;
602  op = (op_code_t)(unsigned char)str_ref[0];
603  if (op == OpCode_escape) {
604  if (unlikely (!str_ref.avail ()))
605  return OpCode_Invalid;
606  op = Make_OpCode_ESC(str_ref[1]);
607  str_ref.inc ();
608  }
609  str_ref.inc ();
610  return op;
611  }
612 
613  const ARG& eval_arg (unsigned int i) { return argStack[i]; }
614 
615  ARG& pop_arg () { return argStack.pop (); }
616  void pop_n_args (unsigned int n) { argStack.pop (n); }
617 
618  void clear_args () { pop_n_args (argStack.get_count ()); }
619 
624  protected:
625  bool error;
626 };
627 
629 
630 template <typename ARG=number_t>
631 struct opset_t
632 {
634  {
635  switch (op) {
636  case OpCode_shortint:
637  env.argStack.push_int ((int16_t)((env.str_ref[0] << 8) | env.str_ref[1]));
638  env.str_ref.inc (2);
639  break;
640 
643  env.argStack.push_int ((int16_t)((op - OpCode_TwoBytePosInt0) * 256 + env.str_ref[0] + 108));
644  env.str_ref.inc ();
645  break;
646 
649  env.argStack.push_int ((-(int16_t)(op - OpCode_TwoByteNegInt0) * 256 - env.str_ref[0] - 108));
650  env.str_ref.inc ();
651  break;
652 
653  default:
654  /* 1-byte integer */
656  {
657  env.argStack.push_int ((int)op - 139);
658  } else {
659  /* invalid unknown operator */
660  env.clear_args ();
661  env.set_error ();
662  }
663  break;
664  }
665  }
666 };
667 
668 template <typename ENV>
670 {
672 
673  void fini () { env.fini (); }
674 
675  ENV env;
676 };
677 
678 } /* namespace CFF */
679 
680 #endif /* HB_CFF_INTERP_COMMON_HH */
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
auto V(a, v))) struct
Definition: hb-algs.hh:317
#define OpCode_Invalid
#define OpCode_shortint
#define OpCode_TwoBytePosInt1
#define Make_OpCode_ESC(byte2)
#define OpCode_OneByteIntLast
#define OpCode_longintdict
#define OpCode_TwoBytePosInt3
#define OpCode_TwoBytePosInt2
#define OpCode_TwoBytePosInt0
#define OpCode_escape
#define OpCode_ESC_Base
#define OpCode_TwoByteNegInt1
#define OpCode_TwoByteNegInt2
#define OpCode_OneByteIntFirst
#define OpCode_TwoByteNegInt3
#define OpCode_TwoByteNegInt0
#define TRACE_SERIALIZE(this)
Definition: hb-debug.hh:426
#define return_trace(RET)
Definition: hb-debug.hh:349
auto it unsigned count const
Definition: hb-iter.hh:848
#define Crap(Type)
Definition: hb-null.hh:159
@ HB_SERIALIZE_ERROR_INT_OVERFLOW
Definition: hb-serialize.hh:52
#define likely(expr)
Definition: hb.hh:250
#define unlikely(expr)
Definition: hb.hh:251
unsigned int OpCode_Size(op_code_t op)
interp_env_t num_interp_env_t
hb_vector_t< byte_str_t > byte_str_array_t
op_code_t Unmake_OpCode_ESC(op_code_t op)
bool Is_OpCode_ESC(op_code_t op)
unsigned int op_code_t
set set set set set set set macro pixldst1 op
EGLOutputLayerEXT EGLint EGLAttrib value
GLenum GLuint GLenum GLsizei length
Definition: qopengl.h:270
GLenum GLsizei GLsizei GLint * values
[16]
GLsizei const GLfloat * v
[13]
GLenum GLenum GLsizei count
GLuint start
GLenum GLuint GLintptr offset
GLfloat n
const GLubyte * c
Definition: qopenglext.h:12701
GLuint GLfloat * val
Definition: qopenglext.h:1513
GLdouble s
[6]
Definition: qopenglext.h:235
GLfloat GLfloat p
[1]
Definition: qopenglext.h:12698
stack push(command1)
#define ARG(...)
static bool serialize_int2(hb_serialize_context_t *c, V value)
static bool serialize_int4(hb_serialize_context_t *c, V value)
static bool serialize_int(hb_serialize_context_t *c, op_code_t intOp, V value)
void push_fixed(int32_t v)
bool push_fixed_from_substr(byte_str_ref_t &str_ref)
hb_array_t< const ARG > get_subarray(unsigned int start) const
void push_longint_from_substr(byte_str_ref_t &str_ref)
void push_real(double v)
const unsigned char & operator[](int i)
byte_str_ref_t(const byte_str_t &str_, unsigned int offset_=0)
byte_str_t sub_str(unsigned int offset_, unsigned int len_) const
void reset(const byte_str_t &str_, unsigned int offset_=0)
bool avail(unsigned int count=1) const
void inc(unsigned int count=1)
byte_str_t(const UnsizedByteStr &s, unsigned int l)
bool check_limit(unsigned int offset, unsigned int count) const
byte_str_t(const hb_ubytes_t &ub)
byte_str_t(const unsigned char *s, unsigned int l)
byte_str_t sub_str(unsigned int offset, unsigned int len_) const
static constexpr unsigned kSizeLimit
void pop(unsigned int n)
void push(const ELEM &v)
unsigned int get_count() const
ELEM & operator[](unsigned int i)
hb_vector_t< ELEM > elements
const ARG & eval_arg(unsigned int i)
void pop_n_args(unsigned int n)
void init(const byte_str_t &str_)
arg_stack_t< ARG > argStack
bool in_int_range() const
const number_t & operator+=(const number_t &n)
bool operator>(const number_t &n) const
int32_t to_fixed() const
void set_real(double v)
bool operator<(const number_t &n) const
bool operator>=(const number_t &n) const
bool operator<=(const number_t &n) const
double to_real() const
void set_fixed(int32_t v)
bool copy_opstr(hb_serialize_context_t *c, const op_str_t &opstr) const
static void process_op(op_code_t op, interp_env_t< ARG > &env)
void add_op(op_code_t op, const byte_str_ref_t &str_ref, const VAL &v)
bool has_op(op_code_t op) const
const VAL & get_value(unsigned int i) const
void add_op(op_code_t op, const byte_str_ref_t &str_ref=byte_str_ref_t())
const VAL & operator[](unsigned int i) const
hb_vector_t< VAL > values
Definition: hb-null.hh:93
Definition: main.cpp:38
unsigned int length
Definition: hb-array.hh:291
hb_array_t sub_array(unsigned int start_offset=0, unsigned int *seg_count=nullptr) const
Definition: hb-array.hh:231
void fini()
Definition: hb-vector.hh:86
void init()
Definition: hb-vector.hh:80
bool in_error() const
Definition: hb-vector.hh:203
unsigned int length
Definition: hb-vector.hh:76
bool resize(int size_)
Definition: hb-vector.hh:326