Coverage Report

Created: 2026-05-30 06:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/harfbuzz/src/OT/glyf/glyf-helpers.hh
Line
Count
Source
1
#ifndef OT_GLYF_GLYF_HELPERS_HH
2
#define OT_GLYF_GLYF_HELPERS_HH
3
4
5
#include "../../hb-open-type.hh"
6
#include "../../hb-subset-plan.hh"
7
8
#include "loca.hh"
9
10
11
namespace OT {
12
namespace glyf_impl {
13
14
15
template<typename IteratorIn, typename TypeOut,
16
   hb_requires (hb_is_source_of (IteratorIn, unsigned int))>
17
static void
18
_write_loca (IteratorIn&& it,
19
       const hb_sorted_vector_t<hb_codepoint_pair_t> new_to_old_gid_list,
20
       bool short_offsets,
21
       TypeOut *dest,
22
       unsigned num_offsets)
23
7.41k
{
24
7.41k
  unsigned right_shift = short_offsets ? 1 : 0;
25
7.41k
  unsigned offset = 0;
26
7.41k
  TypeOut value;
27
7.41k
  value = 0;
28
7.41k
  *dest++ = value;
29
7.41k
  hb_codepoint_t last = 0;
30
7.41k
  for (auto _ : new_to_old_gid_list)
31
2.41M
  {
32
2.41M
    hb_codepoint_t gid = _.first;
33
23.9M
    for (; last < gid; last++)
34
21.4M
    {
35
21.4M
      DEBUG_MSG (SUBSET, nullptr, "loca entry empty offset %u", offset);
36
21.4M
      *dest++ = value;
37
21.4M
    }
38
39
2.41M
    unsigned padded_size = *it++;
40
2.41M
    offset += padded_size;
41
2.41M
    DEBUG_MSG (SUBSET, nullptr, "loca entry gid %" PRIu32 " offset %u padded-size %u", gid, offset, padded_size);
42
2.41M
    value = offset >> right_shift;
43
2.41M
    *dest++ = value;
44
45
2.41M
    last++; // Skip over gid
46
2.41M
  }
47
7.41k
  unsigned num_glyphs = num_offsets - 1;
48
11.1M
  for (; last < num_glyphs; last++)
49
11.1M
  {
50
11.1M
    DEBUG_MSG (SUBSET, nullptr, "loca entry empty offset %u", offset);
51
11.1M
    *dest++ = value;
52
11.1M
  }
53
7.41k
}
Unexecuted instantiation: hb-common.cc:_ZN2OT9glyf_implL11_write_locaIR10hb_array_tIKjENS_7NumTypeILb1EtLj2EEETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEvOS9_11hb_vector_tI9hb_pair_tIjjELb1EEbPT0_j
Unexecuted instantiation: hb-common.cc:_ZN2OT9glyf_implL11_write_locaIR10hb_array_tIKjENS_7NumTypeILb1EjLj4EEETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEvOS9_11hb_vector_tI9hb_pair_tIjjELb1EEbPT0_j
Unexecuted instantiation: hb-ot-face.cc:_ZN2OT9glyf_implL11_write_locaIR10hb_array_tIKjENS_7NumTypeILb1EtLj2EEETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEvOS9_11hb_vector_tI9hb_pair_tIjjELb1EEbPT0_j
Unexecuted instantiation: hb-ot-face.cc:_ZN2OT9glyf_implL11_write_locaIR10hb_array_tIKjENS_7NumTypeILb1EjLj4EEETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEvOS9_11hb_vector_tI9hb_pair_tIjjELb1EEbPT0_j
Unexecuted instantiation: hb-ot-font.cc:_ZN2OT9glyf_implL11_write_locaIR10hb_array_tIKjENS_7NumTypeILb1EtLj2EEETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEvOS9_11hb_vector_tI9hb_pair_tIjjELb1EEbPT0_j
Unexecuted instantiation: hb-ot-font.cc:_ZN2OT9glyf_implL11_write_locaIR10hb_array_tIKjENS_7NumTypeILb1EjLj4EEETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEvOS9_11hb_vector_tI9hb_pair_tIjjELb1EEbPT0_j
Unexecuted instantiation: VARC.cc:_ZN2OT9glyf_implL11_write_locaIR10hb_array_tIKjENS_7NumTypeILb1EtLj2EEETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEvOS9_11hb_vector_tI9hb_pair_tIjjELb1EEbPT0_j
Unexecuted instantiation: VARC.cc:_ZN2OT9glyf_implL11_write_locaIR10hb_array_tIKjENS_7NumTypeILb1EjLj4EEETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEvOS9_11hb_vector_tI9hb_pair_tIjjELb1EEbPT0_j
Unexecuted instantiation: hb-subset-plan.cc:_ZN2OT9glyf_implL11_write_locaIR10hb_array_tIKjENS_7NumTypeILb1EtLj2EEETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEvOS9_11hb_vector_tI9hb_pair_tIjjELb1EEbPT0_j
Unexecuted instantiation: hb-subset-plan.cc:_ZN2OT9glyf_implL11_write_locaIR10hb_array_tIKjENS_7NumTypeILb1EjLj4EEETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEvOS9_11hb_vector_tI9hb_pair_tIjjELb1EEbPT0_j
Unexecuted instantiation: hb-subset-plan-var.cc:_ZN2OT9glyf_implL11_write_locaIR10hb_array_tIKjENS_7NumTypeILb1EtLj2EEETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEvOS9_11hb_vector_tI9hb_pair_tIjjELb1EEbPT0_j
Unexecuted instantiation: hb-subset-plan-var.cc:_ZN2OT9glyf_implL11_write_locaIR10hb_array_tIKjENS_7NumTypeILb1EjLj4EEETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEvOS9_11hb_vector_tI9hb_pair_tIjjELb1EEbPT0_j
hb-subset-table-other.cc:_ZN2OT9glyf_implL11_write_locaIR10hb_array_tIKjENS_7NumTypeILb1EtLj2EEETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEvOS9_11hb_vector_tI9hb_pair_tIjjELb1EEbPT0_j
Line
Count
Source
23
4.78k
{
24
4.78k
  unsigned right_shift = short_offsets ? 1 : 0;
25
4.78k
  unsigned offset = 0;
26
4.78k
  TypeOut value;
27
4.78k
  value = 0;
28
4.78k
  *dest++ = value;
29
4.78k
  hb_codepoint_t last = 0;
30
4.78k
  for (auto _ : new_to_old_gid_list)
31
242k
  {
32
242k
    hb_codepoint_t gid = _.first;
33
2.17M
    for (; last < gid; last++)
34
1.93M
    {
35
1.93M
      DEBUG_MSG (SUBSET, nullptr, "loca entry empty offset %u", offset);
36
1.93M
      *dest++ = value;
37
1.93M
    }
38
39
242k
    unsigned padded_size = *it++;
40
242k
    offset += padded_size;
41
242k
    DEBUG_MSG (SUBSET, nullptr, "loca entry gid %" PRIu32 " offset %u padded-size %u", gid, offset, padded_size);
42
242k
    value = offset >> right_shift;
43
242k
    *dest++ = value;
44
45
242k
    last++; // Skip over gid
46
242k
  }
47
4.78k
  unsigned num_glyphs = num_offsets - 1;
48
4.29M
  for (; last < num_glyphs; last++)
49
4.28M
  {
50
4.28M
    DEBUG_MSG (SUBSET, nullptr, "loca entry empty offset %u", offset);
51
4.28M
    *dest++ = value;
52
4.28M
  }
53
4.78k
}
hb-subset-table-other.cc:_ZN2OT9glyf_implL11_write_locaIR10hb_array_tIKjENS_7NumTypeILb1EjLj4EEETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEvOS9_11hb_vector_tI9hb_pair_tIjjELb1EEbPT0_j
Line
Count
Source
23
2.62k
{
24
2.62k
  unsigned right_shift = short_offsets ? 1 : 0;
25
2.62k
  unsigned offset = 0;
26
2.62k
  TypeOut value;
27
2.62k
  value = 0;
28
2.62k
  *dest++ = value;
29
2.62k
  hb_codepoint_t last = 0;
30
2.62k
  for (auto _ : new_to_old_gid_list)
31
2.17M
  {
32
2.17M
    hb_codepoint_t gid = _.first;
33
21.7M
    for (; last < gid; last++)
34
19.5M
    {
35
19.5M
      DEBUG_MSG (SUBSET, nullptr, "loca entry empty offset %u", offset);
36
19.5M
      *dest++ = value;
37
19.5M
    }
38
39
2.17M
    unsigned padded_size = *it++;
40
2.17M
    offset += padded_size;
41
2.17M
    DEBUG_MSG (SUBSET, nullptr, "loca entry gid %" PRIu32 " offset %u padded-size %u", gid, offset, padded_size);
42
2.17M
    value = offset >> right_shift;
43
2.17M
    *dest++ = value;
44
45
2.17M
    last++; // Skip over gid
46
2.17M
  }
47
2.62k
  unsigned num_glyphs = num_offsets - 1;
48
6.84M
  for (; last < num_glyphs; last++)
49
6.83M
  {
50
6.83M
    DEBUG_MSG (SUBSET, nullptr, "loca entry empty offset %u", offset);
51
6.83M
    *dest++ = value;
52
6.83M
  }
53
2.62k
}
54
55
static bool
56
_add_head_and_set_loca_version (hb_subset_plan_t *plan, bool use_short_loca)
57
7.41k
{
58
7.41k
  hb_blob_t *head_blob = hb_sanitize_context_t ().reference_table<head> (plan->source);
59
7.41k
  hb_blob_t *head_prime_blob = hb_blob_copy_writable_or_fail (head_blob);
60
7.41k
  hb_blob_destroy (head_blob);
61
62
7.41k
  if (unlikely (!head_prime_blob))
63
4.28k
    return false;
64
65
3.12k
  head *head_prime = (head *) hb_blob_get_data_writable (head_prime_blob, nullptr);
66
3.12k
  head_prime->indexToLocFormat = use_short_loca ? 0 : 1;
67
3.12k
  if (plan->normalized_coords)
68
323
  {
69
323
    head_prime->xMin = plan->head_maxp_info.xMin;
70
323
    head_prime->xMax = plan->head_maxp_info.xMax;
71
323
    head_prime->yMin = plan->head_maxp_info.yMin;
72
323
    head_prime->yMax = plan->head_maxp_info.yMax;
73
74
323
    unsigned orig_flag = head_prime->flags;
75
323
    if (plan->head_maxp_info.allXMinIsLsb)
76
232
      orig_flag |= 1 << 1;
77
91
    else
78
91
      orig_flag &= ~(1 << 1);
79
323
    head_prime->flags = orig_flag;
80
323
  }
81
3.12k
  bool success = plan->add_table (HB_OT_TAG_head, head_prime_blob);
82
83
3.12k
  hb_blob_destroy (head_prime_blob);
84
3.12k
  return success;
85
7.41k
}
Unexecuted instantiation: hb-common.cc:OT::glyf_impl::_add_head_and_set_loca_version(hb_subset_plan_t*, bool)
Unexecuted instantiation: hb-ot-face.cc:OT::glyf_impl::_add_head_and_set_loca_version(hb_subset_plan_t*, bool)
Unexecuted instantiation: hb-ot-font.cc:OT::glyf_impl::_add_head_and_set_loca_version(hb_subset_plan_t*, bool)
Unexecuted instantiation: VARC.cc:OT::glyf_impl::_add_head_and_set_loca_version(hb_subset_plan_t*, bool)
Unexecuted instantiation: hb-subset-plan.cc:OT::glyf_impl::_add_head_and_set_loca_version(hb_subset_plan_t*, bool)
Unexecuted instantiation: hb-subset-plan-var.cc:OT::glyf_impl::_add_head_and_set_loca_version(hb_subset_plan_t*, bool)
hb-subset-table-other.cc:OT::glyf_impl::_add_head_and_set_loca_version(hb_subset_plan_t*, bool)
Line
Count
Source
57
7.41k
{
58
7.41k
  hb_blob_t *head_blob = hb_sanitize_context_t ().reference_table<head> (plan->source);
59
7.41k
  hb_blob_t *head_prime_blob = hb_blob_copy_writable_or_fail (head_blob);
60
7.41k
  hb_blob_destroy (head_blob);
61
62
7.41k
  if (unlikely (!head_prime_blob))
63
4.28k
    return false;
64
65
3.12k
  head *head_prime = (head *) hb_blob_get_data_writable (head_prime_blob, nullptr);
66
3.12k
  head_prime->indexToLocFormat = use_short_loca ? 0 : 1;
67
3.12k
  if (plan->normalized_coords)
68
323
  {
69
323
    head_prime->xMin = plan->head_maxp_info.xMin;
70
323
    head_prime->xMax = plan->head_maxp_info.xMax;
71
323
    head_prime->yMin = plan->head_maxp_info.yMin;
72
323
    head_prime->yMax = plan->head_maxp_info.yMax;
73
74
323
    unsigned orig_flag = head_prime->flags;
75
323
    if (plan->head_maxp_info.allXMinIsLsb)
76
232
      orig_flag |= 1 << 1;
77
91
    else
78
91
      orig_flag &= ~(1 << 1);
79
323
    head_prime->flags = orig_flag;
80
323
  }
81
3.12k
  bool success = plan->add_table (HB_OT_TAG_head, head_prime_blob);
82
83
3.12k
  hb_blob_destroy (head_prime_blob);
84
3.12k
  return success;
85
7.41k
}
86
87
template<typename Iterator,
88
   hb_requires (hb_is_source_of (Iterator, unsigned int))>
89
static bool
90
_add_loca_and_head (hb_subset_context_t *c,
91
        Iterator padded_offsets,
92
        bool use_short_loca)
93
7.41k
{
94
7.41k
  unsigned num_offsets = c->plan->num_output_glyphs () + 1;
95
7.41k
  unsigned entry_size = use_short_loca ? 2 : 4;
96
97
7.41k
  char *loca_prime_data = (char *) hb_malloc (entry_size * num_offsets);
98
99
7.41k
  if (unlikely (!loca_prime_data)) return false;
100
101
7.41k
  DEBUG_MSG (SUBSET, nullptr, "loca entry_size %u num_offsets %u size %u",
102
7.41k
       entry_size, num_offsets, entry_size * num_offsets);
103
104
7.41k
  if (use_short_loca)
105
4.78k
    _write_loca (padded_offsets, c->plan->new_to_old_gid_list, true, (HBUINT16 *) loca_prime_data, num_offsets);
106
2.62k
  else
107
2.62k
    _write_loca (padded_offsets, c->plan->new_to_old_gid_list, false, (HBUINT32 *) loca_prime_data, num_offsets);
108
109
7.41k
  hb_blob_t *loca_blob = hb_blob_create (loca_prime_data,
110
7.41k
           entry_size * num_offsets,
111
7.41k
           HB_MEMORY_MODE_WRITABLE,
112
7.41k
           loca_prime_data,
113
7.41k
           hb_free);
114
115
7.41k
  bool result = c->plan->add_table (HB_OT_TAG_loca, loca_blob)
116
7.41k
       && _add_head_and_set_loca_version (c->plan, use_short_loca);
117
118
7.41k
  hb_blob_destroy (loca_blob);
119
7.41k
  return result;
120
7.41k
}
Unexecuted instantiation: hb-common.cc:_ZN2OT9glyf_implL18_add_loca_and_headI10hb_array_tIKjETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEbP19hb_subset_context_tS6_b
Unexecuted instantiation: hb-ot-face.cc:_ZN2OT9glyf_implL18_add_loca_and_headI10hb_array_tIKjETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEbP19hb_subset_context_tS6_b
Unexecuted instantiation: hb-ot-font.cc:_ZN2OT9glyf_implL18_add_loca_and_headI10hb_array_tIKjETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEbP19hb_subset_context_tS6_b
Unexecuted instantiation: VARC.cc:_ZN2OT9glyf_implL18_add_loca_and_headI10hb_array_tIKjETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEbP19hb_subset_context_tS6_b
Unexecuted instantiation: hb-subset-plan.cc:_ZN2OT9glyf_implL18_add_loca_and_headI10hb_array_tIKjETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEbP19hb_subset_context_tS6_b
Unexecuted instantiation: hb-subset-plan-var.cc:_ZN2OT9glyf_implL18_add_loca_and_headI10hb_array_tIKjETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEbP19hb_subset_context_tS6_b
hb-subset-table-other.cc:_ZN2OT9glyf_implL18_add_loca_and_headI10hb_array_tIKjETnPN12hb_enable_ifIXsr15hb_is_source_ofIT_jEE5valueEvE4typeELPv0EEEbP19hb_subset_context_tS6_b
Line
Count
Source
93
7.41k
{
94
7.41k
  unsigned num_offsets = c->plan->num_output_glyphs () + 1;
95
7.41k
  unsigned entry_size = use_short_loca ? 2 : 4;
96
97
7.41k
  char *loca_prime_data = (char *) hb_malloc (entry_size * num_offsets);
98
99
7.41k
  if (unlikely (!loca_prime_data)) return false;
100
101
7.41k
  DEBUG_MSG (SUBSET, nullptr, "loca entry_size %u num_offsets %u size %u",
102
7.41k
       entry_size, num_offsets, entry_size * num_offsets);
103
104
7.41k
  if (use_short_loca)
105
4.78k
    _write_loca (padded_offsets, c->plan->new_to_old_gid_list, true, (HBUINT16 *) loca_prime_data, num_offsets);
106
2.62k
  else
107
2.62k
    _write_loca (padded_offsets, c->plan->new_to_old_gid_list, false, (HBUINT32 *) loca_prime_data, num_offsets);
108
109
7.41k
  hb_blob_t *loca_blob = hb_blob_create (loca_prime_data,
110
7.41k
           entry_size * num_offsets,
111
7.41k
           HB_MEMORY_MODE_WRITABLE,
112
7.41k
           loca_prime_data,
113
7.41k
           hb_free);
114
115
7.41k
  bool result = c->plan->add_table (HB_OT_TAG_loca, loca_blob)
116
7.41k
       && _add_head_and_set_loca_version (c->plan, use_short_loca);
117
118
7.41k
  hb_blob_destroy (loca_blob);
119
7.41k
  return result;
120
7.41k
}
121
122
123
} /* namespace glyf_impl */
124
} /* namespace OT */
125
126
127
#endif /* OT_GLYF_GLYF_HELPERS_HH */