Coverage Report

Created: 2026-10-30 06:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/harfbuzz/src/hb-ot-shape.hh
Line
Count
Source
1
/*
2
 * Copyright © 2010  Google, 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
 * Google Author(s): Behdad Esfahbod
25
 */
26
27
#ifndef HB_OT_SHAPE_HH
28
#define HB_OT_SHAPE_HH
29
30
#include "hb.hh"
31
32
#include "hb-ot-map.hh"
33
#include "hb-aat-map.hh"
34
35
36
HB_INTERNAL bool
37
_hb_ot_layout_table_get_feature_variations_state (hb_face_t             *face,
38
               hb_tag_t               table_tag,
39
               const int             *coords,
40
               unsigned int           num_coords,
41
               unsigned int          *variations_index,
42
               hb_vector_t<unsigned> *lookup_conditions);
43
44
HB_INTERNAL bool
45
_hb_ot_layout_feature_get_lookup_variations (hb_face_t *face,
46
                                             hb_tag_t table_tag,
47
                                             unsigned feature_index,
48
                                             unsigned variations_index,
49
                                             hb_sorted_array_t<const unsigned> conditions,
50
                                             hb_set_t *lookup_indexes);
51
52
struct hb_ot_shape_plan_key_t
53
{
54
  unsigned int variations_index[2];
55
  /* Sorted offsets of distinct true conditions within FeatureVariations.
56
   * Different outcomes may conservatively separate equivalent lookup sets. */
57
  hb_vector_t<unsigned> lookup_conditions[2];
58
59
  bool init (hb_face_t *face,
60
       const int *coords,
61
       unsigned   num_coords)
62
112k
  {
63
336k
    for (unsigned int table_index = 0; table_index < 2; table_index++)
64
224k
      if (unlikely (!_hb_ot_layout_table_get_feature_variations_state (
65
224k
      face,
66
224k
      table_tags[table_index],
67
224k
      coords,
68
224k
      num_coords,
69
224k
      &variations_index[table_index],
70
224k
      &lookup_conditions[table_index])))
71
0
      {
72
0
  for (auto &v : lookup_conditions)
73
0
    v.fini ();
74
0
  return false;
75
0
      }
76
112k
    return true;
77
112k
  }
78
79
  void fini ()
80
1.72k
  {
81
1.72k
    for (auto &v : lookup_conditions)
82
3.44k
      v.fini ();
83
1.72k
  }
84
85
  bool get_lookup_variations (hb_face_t *face,
86
                              unsigned int table_index,
87
            unsigned int feature_index,
88
            hb_set_t *lookups) const
89
109
  {
90
109
    return _hb_ot_layout_feature_get_lookup_variations (
91
109
  face, table_tags[table_index], feature_index, variations_index[table_index],
92
109
  lookup_conditions[table_index].as_sorted_array (), lookups);
93
109
  }
94
95
  bool equal (const hb_ot_shape_plan_key_t *other)
96
108k
  {
97
108k
    return variations_index[0] == other->variations_index[0] &&
98
108k
     variations_index[1] == other->variations_index[1] &&
99
108k
     lookup_conditions[0] == other->lookup_conditions[0] &&
100
108k
     lookup_conditions[1] == other->lookup_conditions[1];
101
108k
  }
102
};
103
104
105
struct hb_shape_plan_key_t;
106
107
struct hb_ot_shape_plan_t
108
{
109
1.72k
  ~hb_ot_shape_plan_t () { fini (); }
110
111
  hb_segment_properties_t props;
112
  const struct hb_ot_shaper_t *shaper;
113
  hb_ot_map_t map;
114
  hb_aat_map_t aat_map;
115
  const void *data;
116
#ifndef HB_NO_OT_SHAPE_FRACTIONS
117
  hb_mask_t frac_mask, numr_mask, dnom_mask;
118
#else
119
  static constexpr hb_mask_t frac_mask = 0;
120
  static constexpr hb_mask_t numr_mask = 0;
121
  static constexpr hb_mask_t dnom_mask = 0;
122
#endif
123
  hb_mask_t rtlm_mask;
124
#ifndef HB_NO_OT_KERN
125
  hb_mask_t kern_mask;
126
#else
127
  static constexpr hb_mask_t kern_mask = 0;
128
#endif
129
130
#ifndef HB_NO_OT_KERN
131
  bool requested_kerning : 1;
132
#else
133
  static constexpr bool requested_kerning = false;
134
#endif
135
#ifndef HB_NO_OT_SHAPE_FRACTIONS
136
  bool has_frac : 1;
137
#else
138
  static constexpr bool has_frac = false;
139
#endif
140
  bool has_vert : 1;
141
  bool has_gpos_mark : 1;
142
  bool zero_marks : 1;
143
  bool fallback_glyph_classes : 1;
144
  bool fallback_mark_positioning : 1;
145
  bool adjust_mark_positioning_when_zeroing : 1;
146
147
  bool apply_gpos : 1;
148
#ifndef HB_NO_OT_KERN
149
  bool apply_kern : 1;
150
#else
151
  static constexpr bool apply_kern = false;
152
#endif
153
  bool apply_fallback_kern : 1;
154
#ifndef HB_NO_AAT_SHAPE
155
  bool apply_kerx : 1;
156
  bool apply_morx : 1;
157
  bool apply_trak : 1;
158
#else
159
  static constexpr bool apply_kerx = false;
160
  static constexpr bool apply_morx = false;
161
  static constexpr bool apply_trak = false;
162
#endif
163
164
  void collect_lookups (hb_tag_t table_tag, hb_set_t *lookups) const
165
0
  {
166
0
    unsigned int table_index;
167
0
    switch (table_tag) {
168
0
      case HB_OT_TAG_GSUB: table_index = 0; break;
169
0
      case HB_OT_TAG_GPOS: table_index = 1; break;
170
0
      default: return;
171
0
    }
172
0
    map.collect_lookups (table_index, lookups);
173
0
  }
174
175
  HB_INTERNAL bool init0 (hb_face_t                     *face,
176
        const hb_shape_plan_key_t     *key);
177
  HB_INTERNAL void fini ();
178
179
  HB_INTERNAL void substitute (hb_font_t *font, hb_buffer_t *buffer) const;
180
  HB_INTERNAL void position (hb_font_t *font, hb_buffer_t *buffer) const;
181
};
182
183
struct hb_shape_plan_t;
184
185
struct hb_ot_shape_planner_t
186
{
187
  /* In the order that they are filled in. */
188
  hb_face_t *face;
189
  hb_segment_properties_t props;
190
  hb_ot_map_builder_t map;
191
#ifndef HB_NO_AAT_SHAPE
192
  hb_aat_map_builder_t aat_map;
193
  bool apply_morx : 1;
194
#else
195
  static constexpr bool apply_morx = false;
196
#endif
197
  bool script_zero_marks : 1;
198
  bool script_fallback_position : 1;
199
  const struct hb_ot_shaper_t *shaper;
200
201
  HB_INTERNAL hb_ot_shape_planner_t (hb_face_t                     *face,
202
             const hb_segment_properties_t &props);
203
204
  HB_INTERNAL void compile (hb_ot_shape_plan_t           &plan,
205
          const hb_ot_shape_plan_key_t &key);
206
};
207
208
209
#endif /* HB_OT_SHAPE_HH */