Coverage Report

Created: 2024-01-17 16:56

/src/harfbuzz/src/hb-cff1-interp-cs.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_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
    : SUPER (str, acc.globalSubrs, acc.privateDicts[fd].localSubrs)
44
53.1k
  {
45
53.1k
    processed_width = false;
46
53.1k
    has_width = false;
47
53.1k
    arg_start = 0;
48
53.1k
    in_seac = false;
49
53.1k
  }
50
51
  void set_width (bool has_width_)
52
47.8k
  {
53
47.8k
    if (likely (!processed_width && (SUPER::argStack.get_count () > 0)))
54
44.0k
    {
55
44.0k
      if (has_width_)
56
18.4k
      {
57
18.4k
  width = SUPER::argStack[0];
58
18.4k
  has_width = true;
59
18.4k
  arg_start = 1;
60
18.4k
      }
61
44.0k
    }
62
47.8k
    processed_width = true;
63
47.8k
  }
64
65
  void clear_args ()
66
795k
  {
67
795k
    arg_start = 0;
68
795k
    SUPER::clear_args ();
69
795k
  }
70
71
53.1k
  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
5.51M
  {
91
5.51M
    switch (op) {
92
600
      case OpCode_dotsection:
93
600
  SUPER::flush_args_and_op (op, env, param);
94
600
  break;
95
96
39.2k
      case OpCode_endchar:
97
39.2k
  OPSET::check_width (op, env, param);
98
39.2k
  if (env.argStack.get_count () >= 4)
99
2.75k
  {
100
2.75k
    OPSET::process_seac (env, param);
101
2.75k
  }
102
39.2k
  OPSET::flush_args_and_op (op, env, param);
103
39.2k
  env.set_endchar (true);
104
39.2k
  break;
105
106
5.47M
      default:
107
5.47M
  SUPER::process_op (op, env, param);
108
5.51M
    }
109
5.51M
  }
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
3.52M
  {
91
3.52M
    switch (op) {
92
466
      case OpCode_dotsection:
93
466
  SUPER::flush_args_and_op (op, env, param);
94
466
  break;
95
96
29.3k
      case OpCode_endchar:
97
29.3k
  OPSET::check_width (op, env, param);
98
29.3k
  if (env.argStack.get_count () >= 4)
99
1.80k
  {
100
1.80k
    OPSET::process_seac (env, param);
101
1.80k
  }
102
29.3k
  OPSET::flush_args_and_op (op, env, param);
103
29.3k
  env.set_endchar (true);
104
29.3k
  break;
105
106
3.49M
      default:
107
3.49M
  SUPER::process_op (op, env, param);
108
3.52M
    }
109
3.52M
  }
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
1.99M
  {
91
1.99M
    switch (op) {
92
134
      case OpCode_dotsection:
93
134
  SUPER::flush_args_and_op (op, env, param);
94
134
  break;
95
96
9.95k
      case OpCode_endchar:
97
9.95k
  OPSET::check_width (op, env, param);
98
9.95k
  if (env.argStack.get_count () >= 4)
99
952
  {
100
952
    OPSET::process_seac (env, param);
101
952
  }
102
9.95k
  OPSET::flush_args_and_op (op, env, param);
103
9.95k
  env.set_endchar (true);
104
9.95k
  break;
105
106
1.98M
      default:
107
1.98M
  SUPER::process_op (op, env, param);
108
1.99M
    }
109
1.99M
  }
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
271k
  {
113
271k
    if (!env.processed_width)
114
47.8k
    {
115
47.8k
      bool  has_width = false;
116
47.8k
      switch (op)
117
47.8k
      {
118
4.72k
  case OpCode_endchar:
119
9.28k
  case OpCode_hstem:
120
10.9k
  case OpCode_hstemhm:
121
11.7k
  case OpCode_vstem:
122
12.3k
  case OpCode_vstemhm:
123
12.9k
  case OpCode_hintmask:
124
13.8k
  case OpCode_cntrmask:
125
13.8k
    has_width = ((env.argStack.get_count () & 1) != 0);
126
13.8k
    break;
127
10.1k
  case OpCode_hmoveto:
128
11.4k
  case OpCode_vmoveto:
129
11.4k
    has_width = (env.argStack.get_count () > 1);
130
11.4k
    break;
131
22.5k
  case OpCode_rmoveto:
132
22.5k
    has_width = (env.argStack.get_count () > 2);
133
22.5k
    break;
134
0
  default:
135
0
    return;
136
47.8k
      }
137
47.8k
      env.set_width (has_width);
138
47.8k
    }
139
271k
  }
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
191k
  {
113
191k
    if (!env.processed_width)
114
35.0k
    {
115
35.0k
      bool  has_width = false;
116
35.0k
      switch (op)
117
35.0k
      {
118
3.63k
  case OpCode_endchar:
119
6.74k
  case OpCode_hstem:
120
7.90k
  case OpCode_hstemhm:
121
8.57k
  case OpCode_vstem:
122
9.05k
  case OpCode_vstemhm:
123
9.46k
  case OpCode_hintmask:
124
10.2k
  case OpCode_cntrmask:
125
10.2k
    has_width = ((env.argStack.get_count () & 1) != 0);
126
10.2k
    break;
127
8.11k
  case OpCode_hmoveto:
128
9.16k
  case OpCode_vmoveto:
129
9.16k
    has_width = (env.argStack.get_count () > 1);
130
9.16k
    break;
131
15.6k
  case OpCode_rmoveto:
132
15.6k
    has_width = (env.argStack.get_count () > 2);
133
15.6k
    break;
134
0
  default:
135
0
    return;
136
35.0k
      }
137
35.0k
      env.set_width (has_width);
138
35.0k
    }
139
191k
  }
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
80.4k
  {
113
80.4k
    if (!env.processed_width)
114
12.7k
    {
115
12.7k
      bool  has_width = false;
116
12.7k
      switch (op)
117
12.7k
      {
118
1.09k
  case OpCode_endchar:
119
2.53k
  case OpCode_hstem:
120
3.04k
  case OpCode_hstemhm:
121
3.19k
  case OpCode_vstem:
122
3.31k
  case OpCode_vstemhm:
123
3.44k
  case OpCode_hintmask:
124
3.63k
  case OpCode_cntrmask:
125
3.63k
    has_width = ((env.argStack.get_count () & 1) != 0);
126
3.63k
    break;
127
2.03k
  case OpCode_hmoveto:
128
2.28k
  case OpCode_vmoveto:
129
2.28k
    has_width = (env.argStack.get_count () > 1);
130
2.28k
    break;
131
6.86k
  case OpCode_rmoveto:
132
6.86k
    has_width = (env.argStack.get_count () > 2);
133
6.86k
    break;
134
0
  default:
135
0
    return;
136
12.7k
      }
137
12.7k
      env.set_width (has_width);
138
12.7k
    }
139
80.4k
  }
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
795k
  {
147
795k
    SUPER::flush_args (env, param);
148
795k
    env.clear_args ();  /* pop off width */
149
795k
  }
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
527k
  {
147
527k
    SUPER::flush_args (env, param);
148
527k
    env.clear_args ();  /* pop off width */
149
527k
  }
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
267k
  {
147
267k
    SUPER::flush_args (env, param);
148
267k
    env.clear_args ();  /* pop off width */
149
267k
  }
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 */