Coverage Report

Created: 2023-06-07 06:14

/src/harfbuzz/src/OT/Layout/GPOS/GPOS.hh
Line
Count
Source (jump to first uncovered line)
1
#ifndef OT_LAYOUT_GPOS_GPOS_HH
2
#define OT_LAYOUT_GPOS_GPOS_HH
3
4
#include "../../../hb-ot-layout-common.hh"
5
#include "../../../hb-ot-layout-gsubgpos.hh"
6
#include "Common.hh"
7
#include "PosLookup.hh"
8
9
namespace OT {
10
11
using Layout::GPOS_impl::PosLookup;
12
13
namespace Layout {
14
15
static void
16
propagate_attachment_offsets (hb_glyph_position_t *pos,
17
                              unsigned int len,
18
                              unsigned int i,
19
                              hb_direction_t direction,
20
                              unsigned nesting_level = HB_MAX_NESTING_LEVEL);
21
22
/*
23
 * GPOS -- Glyph Positioning
24
 * https://docs.microsoft.com/en-us/typography/opentype/spec/gpos
25
 */
26
27
struct GPOS : GSUBGPOS
28
{
29
  static constexpr hb_tag_t tableTag = HB_OT_TAG_GPOS;
30
31
  using Lookup = PosLookup;
32
33
  const PosLookup& get_lookup (unsigned int i) const
34
3
  { return static_cast<const PosLookup &> (GSUBGPOS::get_lookup (i)); }
35
36
  static inline void position_start (hb_font_t *font, hb_buffer_t *buffer);
37
  static inline void position_finish_advances (hb_font_t *font, hb_buffer_t *buffer);
38
  static inline void position_finish_offsets (hb_font_t *font, hb_buffer_t *buffer);
39
40
  bool subset (hb_subset_context_t *c) const
41
0
  {
42
0
    hb_subset_layout_context_t l (c, tableTag);
43
0
    return GSUBGPOS::subset<PosLookup> (&l);
44
0
  }
45
46
  bool sanitize (hb_sanitize_context_t *c) const
47
18
  {
48
18
    TRACE_SANITIZE (this);
49
18
    return_trace (GSUBGPOS::sanitize<PosLookup> (c));
50
18
  }
51
52
  HB_INTERNAL bool is_blocklisted (hb_blob_t *blob,
53
                                   hb_face_t *face) const;
54
55
  void collect_variation_indices (hb_collect_variation_indices_context_t *c) const
56
0
  {
57
0
    for (unsigned i = 0; i < GSUBGPOS::get_lookup_count (); i++)
58
0
    {
59
0
      if (!c->gpos_lookups->has (i)) continue;
60
0
      const PosLookup &l = get_lookup (i);
61
0
      l.dispatch (c);
62
0
    }
63
0
  }
64
65
  void closure_lookups (hb_face_t      *face,
66
                        const hb_set_t *glyphs,
67
                        hb_set_t       *lookup_indexes /* IN/OUT */) const
68
0
  { GSUBGPOS::closure_lookups<PosLookup> (face, glyphs, lookup_indexes); }
69
70
  typedef GSUBGPOS::accelerator_t<GPOS> accelerator_t;
71
};
72
73
74
static void
75
propagate_attachment_offsets (hb_glyph_position_t *pos,
76
                              unsigned int len,
77
                              unsigned int i,
78
                              hb_direction_t direction,
79
                              unsigned nesting_level)
80
0
{
81
  /* Adjusts offsets of attached glyphs (both cursive and mark) to accumulate
82
   * offset of glyph they are attached to. */
83
0
  int chain = pos[i].attach_chain(), type = pos[i].attach_type();
84
0
  if (likely (!chain))
85
0
    return;
86
87
0
  pos[i].attach_chain() = 0;
88
89
0
  unsigned int j = (int) i + chain;
90
91
0
  if (unlikely (j >= len))
92
0
    return;
93
94
0
  if (unlikely (!nesting_level))
95
0
    return;
96
97
0
  propagate_attachment_offsets (pos, len, j, direction, nesting_level - 1);
98
99
0
  assert (!!(type & GPOS_impl::ATTACH_TYPE_MARK) ^ !!(type & GPOS_impl::ATTACH_TYPE_CURSIVE));
100
101
0
  if (type & GPOS_impl::ATTACH_TYPE_CURSIVE)
102
0
  {
103
0
    if (HB_DIRECTION_IS_HORIZONTAL (direction))
104
0
      pos[i].y_offset += pos[j].y_offset;
105
0
    else
106
0
      pos[i].x_offset += pos[j].x_offset;
107
0
  }
108
0
  else /*if (type & GPOS_impl::ATTACH_TYPE_MARK)*/
109
0
  {
110
0
    pos[i].x_offset += pos[j].x_offset;
111
0
    pos[i].y_offset += pos[j].y_offset;
112
113
0
    assert (j < i);
114
0
    if (HB_DIRECTION_IS_FORWARD (direction))
115
0
      for (unsigned int k = j; k < i; k++) {
116
0
        pos[i].x_offset -= pos[k].x_advance;
117
0
        pos[i].y_offset -= pos[k].y_advance;
118
0
      }
119
0
    else
120
0
      for (unsigned int k = j + 1; k < i + 1; k++) {
121
0
        pos[i].x_offset += pos[k].x_advance;
122
0
        pos[i].y_offset += pos[k].y_advance;
123
0
      }
124
0
  }
125
0
}
Unexecuted instantiation: hb-ot-face.cc:OT::Layout::propagate_attachment_offsets(hb_glyph_position_t*, unsigned int, unsigned int, hb_direction_t, unsigned int)
Unexecuted instantiation: hb-aat-layout.cc:OT::Layout::propagate_attachment_offsets(hb_glyph_position_t*, unsigned int, unsigned int, hb_direction_t, unsigned int)
Unexecuted instantiation: hb-ot-layout.cc:OT::Layout::propagate_attachment_offsets(hb_glyph_position_t*, unsigned int, unsigned int, hb_direction_t, unsigned int)
Unexecuted instantiation: hb-ot-shape-fallback.cc:OT::Layout::propagate_attachment_offsets(hb_glyph_position_t*, unsigned int, unsigned int, hb_direction_t, unsigned int)
126
127
void
128
GPOS::position_start (hb_font_t *font HB_UNUSED, hb_buffer_t *buffer)
129
204k
{
130
204k
  unsigned int count = buffer->len;
131
3.13M
  for (unsigned int i = 0; i < count; i++)
132
2.93M
    buffer->pos[i].attach_chain() = buffer->pos[i].attach_type() = 0;
133
204k
}
134
135
void
136
GPOS::position_finish_advances (hb_font_t *font HB_UNUSED, hb_buffer_t *buffer HB_UNUSED)
137
204k
{
138
  //_hb_buffer_assert_gsubgpos_vars (buffer);
139
204k
}
140
141
void
142
GPOS::position_finish_offsets (hb_font_t *font, hb_buffer_t *buffer)
143
204k
{
144
204k
  _hb_buffer_assert_gsubgpos_vars (buffer);
145
146
204k
  unsigned int len;
147
204k
  hb_glyph_position_t *pos = hb_buffer_get_glyph_positions (buffer, &len);
148
204k
  hb_direction_t direction = buffer->props.direction;
149
150
  /* Handle attachments */
151
204k
  if (buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_GPOS_ATTACHMENT)
152
0
    for (unsigned i = 0; i < len; i++)
153
0
      propagate_attachment_offsets (pos, len, i, direction);
154
155
204k
  if (unlikely (font->slant))
156
0
  {
157
0
    for (unsigned i = 0; i < len; i++)
158
0
      if (unlikely (pos[i].y_offset))
159
0
        pos[i].x_offset += roundf (font->slant_xy * pos[i].y_offset);
160
0
  }
161
204k
}
162
163
}
164
165
struct GPOS_accelerator_t : Layout::GPOS::accelerator_t {
166
18
  GPOS_accelerator_t (hb_face_t *face) : Layout::GPOS::accelerator_t (face) {}
167
};
168
169
}
170
171
#endif  /* OT_LAYOUT_GPOS_GPOS_HH */