Coverage Report

Created: 2026-05-16 06:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/harfbuzz/src/hb-cff1-interp-cs.hh
Line
Count
Source
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_CFF1_INTERP_CS_HH
27
#define HB_CFF1_INTERP_CS_HH
28
29
#include "hb.hh"
30
#include "hb-cff-interp-cs-common.hh"
31
32
namespace CFF {
33
34
using namespace OT;
35
36
typedef biased_subrs_t<CFF1Subrs>   cff1_biased_subrs_t;
37
38
struct cff1_cs_interp_env_t : cs_interp_env_t<number_t, CFF1Subrs>
39
{
40
  template <typename ACC>
41
  cff1_cs_interp_env_t (const hb_ubytes_t &str, ACC &acc, unsigned int fd,
42
      const int *coords_=nullptr, unsigned int num_coords_=0)
43
744
    : SUPER (str, acc.globalSubrs, acc.privateDicts[fd].localSubrs)
44
744
  {
45
744
    processed_width = false;
46
744
    has_width = false;
47
744
    arg_start = 0;
48
744
    in_seac = false;
49
744
  }
CFF::cff1_cs_interp_env_t::cff1_cs_interp_env_t<OT::cff1::accelerator_t const>(hb_array_t<unsigned char const> const&, OT::cff1::accelerator_t const&, unsigned int, int const*, unsigned int)
Line
Count
Source
43
744
    : SUPER (str, acc.globalSubrs, acc.privateDicts[fd].localSubrs)
44
744
  {
45
744
    processed_width = false;
46
744
    has_width = false;
47
744
    arg_start = 0;
48
744
    in_seac = false;
49
744
  }
Unexecuted instantiation: CFF::cff1_cs_interp_env_t::cff1_cs_interp_env_t<OT::cff1::accelerator_subset_t const>(hb_array_t<unsigned char const> const&, OT::cff1::accelerator_subset_t const&, unsigned int, int const*, unsigned int)
50
51
  void set_width (bool has_width_)
52
618
  {
53
618
    if (likely (!processed_width && (SUPER::argStack.get_count () > 0)))
54
559
    {
55
559
      if (has_width_)
56
357
      {
57
357
  width = SUPER::argStack[0];
58
357
  has_width = true;
59
357
  arg_start = 1;
60
357
      }
61
559
    }
62
618
    processed_width = true;
63
618
  }
64
65
  void clear_args ()
66
6.65k
  {
67
6.65k
    arg_start = 0;
68
6.65k
    SUPER::clear_args ();
69
6.65k
  }
70
71
744
  void set_in_seac (bool _in_seac) { in_seac = _in_seac; }
72
73
  bool    processed_width;
74
  bool    has_width;
75
  unsigned int  arg_start;
76
  number_t  width;
77
  bool    in_seac;
78
79
  private:
80
  typedef cs_interp_env_t<number_t, CFF1Subrs> SUPER;
81
};
82
83
template <typename OPSET, typename PARAM, typename PATH=path_procs_null_t<cff1_cs_interp_env_t, PARAM>>
84
struct cff1_cs_opset_t : cs_opset_t<number_t, OPSET, cff1_cs_interp_env_t, PARAM, PATH>
85
{
86
  /* PostScript-originated legacy opcodes (OpCode_add etc) are unsupported */
87
  /* Type 1-originated deprecated opcodes, seac behavior of endchar and dotsection are supported */
88
89
  static void process_op (op_code_t op, cff1_cs_interp_env_t &env, PARAM& param)
90
13.0M
  {
91
13.0M
    switch (op) {
92
0
      case OpCode_dotsection:
93
0
  SUPER::flush_args_and_op (op, env, param);
94
0
  break;
95
96
515
      case OpCode_endchar:
97
515
  OPSET::check_width (op, env, param);
98
515
  if (env.argStack.get_count () >= 4)
99
6
  {
100
6
    OPSET::process_seac (env, param);
101
6
  }
102
515
  OPSET::flush_args_and_op (op, env, param);
103
515
  env.set_endchar (true);
104
515
  break;
105
106
13.0M
      default:
107
13.0M
  SUPER::process_op (op, env, param);
108
13.0M
    }
109
13.0M
  }
CFF::cff1_cs_opset_t<cff1_cs_opset_extents_t, cff1_extents_param_t, cff1_path_procs_extents_t>::process_op(unsigned int, CFF::cff1_cs_interp_env_t&, cff1_extents_param_t&)
Line
Count
Source
90
400k
  {
91
400k
    switch (op) {
92
0
      case OpCode_dotsection:
93
0
  SUPER::flush_args_and_op (op, env, param);
94
0
  break;
95
96
34
      case OpCode_endchar:
97
34
  OPSET::check_width (op, env, param);
98
34
  if (env.argStack.get_count () >= 4)
99
0
  {
100
0
    OPSET::process_seac (env, param);
101
0
  }
102
34
  OPSET::flush_args_and_op (op, env, param);
103
34
  env.set_endchar (true);
104
34
  break;
105
106
400k
      default:
107
400k
  SUPER::process_op (op, env, param);
108
400k
    }
109
400k
  }
CFF::cff1_cs_opset_t<cff1_cs_opset_path_t, cff1_path_param_t, cff1_path_procs_path_t>::process_op(unsigned int, CFF::cff1_cs_interp_env_t&, cff1_path_param_t&)
Line
Count
Source
90
12.6M
  {
91
12.6M
    switch (op) {
92
0
      case OpCode_dotsection:
93
0
  SUPER::flush_args_and_op (op, env, param);
94
0
  break;
95
96
481
      case OpCode_endchar:
97
481
  OPSET::check_width (op, env, param);
98
481
  if (env.argStack.get_count () >= 4)
99
6
  {
100
6
    OPSET::process_seac (env, param);
101
6
  }
102
481
  OPSET::flush_args_and_op (op, env, param);
103
481
  env.set_endchar (true);
104
481
  break;
105
106
12.6M
      default:
107
12.6M
  SUPER::process_op (op, env, param);
108
12.6M
    }
109
12.6M
  }
Unexecuted instantiation: CFF::cff1_cs_opset_t<cff1_cs_opset_seac_t, get_seac_param_t, CFF::path_procs_null_t<CFF::cff1_cs_interp_env_t, get_seac_param_t> >::process_op(unsigned int, CFF::cff1_cs_interp_env_t&, get_seac_param_t&)
110
111
  static void check_width (op_code_t op, cff1_cs_interp_env_t &env, PARAM& param)
112
2.29k
  {
113
2.29k
    if (!env.processed_width)
114
618
    {
115
618
      bool  has_width = false;
116
618
      switch (op)
117
618
      {
118
97
  case OpCode_endchar:
119
296
  case OpCode_hstem:
120
356
  case OpCode_hstemhm:
121
368
  case OpCode_vstem:
122
368
  case OpCode_vstemhm:
123
368
  case OpCode_hintmask:
124
368
  case OpCode_cntrmask:
125
368
    has_width = ((env.argStack.get_count () & 1) != 0);
126
368
    break;
127
18
  case OpCode_hmoveto:
128
21
  case OpCode_vmoveto:
129
21
    has_width = (env.argStack.get_count () > 1);
130
21
    break;
131
229
  case OpCode_rmoveto:
132
229
    has_width = (env.argStack.get_count () > 2);
133
229
    break;
134
0
  default:
135
0
    return;
136
618
      }
137
618
      env.set_width (has_width);
138
618
    }
139
2.29k
  }
CFF::cff1_cs_opset_t<cff1_cs_opset_extents_t, cff1_extents_param_t, cff1_path_procs_extents_t>::check_width(unsigned int, CFF::cff1_cs_interp_env_t&, cff1_extents_param_t&)
Line
Count
Source
112
155
  {
113
155
    if (!env.processed_width)
114
36
    {
115
36
      bool  has_width = false;
116
36
      switch (op)
117
36
      {
118
15
  case OpCode_endchar:
119
26
  case OpCode_hstem:
120
29
  case OpCode_hstemhm:
121
29
  case OpCode_vstem:
122
29
  case OpCode_vstemhm:
123
29
  case OpCode_hintmask:
124
29
  case OpCode_cntrmask:
125
29
    has_width = ((env.argStack.get_count () & 1) != 0);
126
29
    break;
127
6
  case OpCode_hmoveto:
128
6
  case OpCode_vmoveto:
129
6
    has_width = (env.argStack.get_count () > 1);
130
6
    break;
131
1
  case OpCode_rmoveto:
132
1
    has_width = (env.argStack.get_count () > 2);
133
1
    break;
134
0
  default:
135
0
    return;
136
36
      }
137
36
      env.set_width (has_width);
138
36
    }
139
155
  }
CFF::cff1_cs_opset_t<cff1_cs_opset_path_t, cff1_path_param_t, cff1_path_procs_path_t>::check_width(unsigned int, CFF::cff1_cs_interp_env_t&, cff1_path_param_t&)
Line
Count
Source
112
2.13k
  {
113
2.13k
    if (!env.processed_width)
114
582
    {
115
582
      bool  has_width = false;
116
582
      switch (op)
117
582
      {
118
82
  case OpCode_endchar:
119
270
  case OpCode_hstem:
120
327
  case OpCode_hstemhm:
121
339
  case OpCode_vstem:
122
339
  case OpCode_vstemhm:
123
339
  case OpCode_hintmask:
124
339
  case OpCode_cntrmask:
125
339
    has_width = ((env.argStack.get_count () & 1) != 0);
126
339
    break;
127
12
  case OpCode_hmoveto:
128
15
  case OpCode_vmoveto:
129
15
    has_width = (env.argStack.get_count () > 1);
130
15
    break;
131
228
  case OpCode_rmoveto:
132
228
    has_width = (env.argStack.get_count () > 2);
133
228
    break;
134
0
  default:
135
0
    return;
136
582
      }
137
582
      env.set_width (has_width);
138
582
    }
139
2.13k
  }
Unexecuted instantiation: CFF::cff1_cs_opset_t<cff1_cs_opset_seac_t, get_seac_param_t, CFF::path_procs_null_t<CFF::cff1_cs_interp_env_t, get_seac_param_t> >::check_width(unsigned int, CFF::cff1_cs_interp_env_t&, get_seac_param_t&)
140
141
  static void process_seac (cff1_cs_interp_env_t &env, PARAM& param)
142
  {
143
  }
144
145
  static void flush_args (cff1_cs_interp_env_t &env, PARAM& param)
146
6.65k
  {
147
6.65k
    SUPER::flush_args (env, param);
148
6.65k
    env.clear_args ();  /* pop off width */
149
6.65k
  }
CFF::cff1_cs_opset_t<cff1_cs_opset_extents_t, cff1_extents_param_t, cff1_path_procs_extents_t>::flush_args(CFF::cff1_cs_interp_env_t&, cff1_extents_param_t&)
Line
Count
Source
146
299
  {
147
299
    SUPER::flush_args (env, param);
148
299
    env.clear_args ();  /* pop off width */
149
299
  }
CFF::cff1_cs_opset_t<cff1_cs_opset_path_t, cff1_path_param_t, cff1_path_procs_path_t>::flush_args(CFF::cff1_cs_interp_env_t&, cff1_path_param_t&)
Line
Count
Source
146
6.35k
  {
147
6.35k
    SUPER::flush_args (env, param);
148
6.35k
    env.clear_args ();  /* pop off width */
149
6.35k
  }
Unexecuted instantiation: CFF::cff1_cs_opset_t<cff1_cs_opset_seac_t, get_seac_param_t, CFF::path_procs_null_t<CFF::cff1_cs_interp_env_t, get_seac_param_t> >::flush_args(CFF::cff1_cs_interp_env_t&, get_seac_param_t&)
150
151
  private:
152
  typedef cs_opset_t<number_t, OPSET, cff1_cs_interp_env_t, PARAM, PATH>  SUPER;
153
};
154
155
template <typename OPSET, typename PARAM>
156
using cff1_cs_interpreter_t = cs_interpreter_t<cff1_cs_interp_env_t, OPSET, PARAM>;
157
158
} /* namespace CFF */
159
160
#endif /* HB_CFF1_INTERP_CS_HH */