Coverage Report

Created: 2023-09-25 06:24

/src/harfbuzz/src/OT/glyf/glyf-helpers.hh
Line
Count
Source (jump to first uncovered line)
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
0
{
24
0
  unsigned right_shift = short_offsets ? 1 : 0;
25
0
  unsigned offset = 0;
26
0
  TypeOut value;
27
0
  value = 0;
28
0
  *dest++ = value;
29
0
  hb_codepoint_t last = 0;
30
0
  for (auto _ : new_to_old_gid_list)
31
0
  {
32
0
    hb_codepoint_t gid = _.first;
33
0
    for (; last < gid; last++)
34
0
    {
35
0
      DEBUG_MSG (SUBSET, nullptr, "loca entry empty offset %u", offset);
36
0
      *dest++ = value;
37
0
    }
38
0
39
0
    unsigned padded_size = *it++;
40
0
    offset += padded_size;
41
0
    DEBUG_MSG (SUBSET, nullptr, "loca entry gid %u offset %u padded-size %u", gid, offset, padded_size);
42
0
    value = offset >> right_shift;
43
0
    *dest++ = value;
44
0
45
0
    last++; // Skip over gid
46
0
  }
47
0
  unsigned num_glyphs = num_offsets - 1;
48
0
  for (; last < num_glyphs; last++)
49
0
  {
50
0
    DEBUG_MSG (SUBSET, nullptr, "loca entry empty offset %u", offset);
51
0
    *dest++ = value;
52
0
  }
53
0
}
Unexecuted instantiation: hb-ot-face.cc:void OT::glyf_impl::_write_loca<hb_array_t<unsigned int const>&, OT::IntType<unsigned short, 2u>, (void*)0>(hb_array_t<unsigned int const>&, hb_vector_t<hb_pair_t<unsigned int, unsigned int>, true>, bool, OT::IntType<unsigned short, 2u>*, unsigned int)
Unexecuted instantiation: hb-ot-face.cc:void OT::glyf_impl::_write_loca<hb_array_t<unsigned int const>&, OT::IntType<unsigned int, 4u>, (void*)0>(hb_array_t<unsigned int const>&, hb_vector_t<hb_pair_t<unsigned int, unsigned int>, true>, bool, OT::IntType<unsigned int, 4u>*, unsigned int)
Unexecuted instantiation: hb-ot-font.cc:void OT::glyf_impl::_write_loca<hb_array_t<unsigned int const>&, OT::IntType<unsigned short, 2u>, (void*)0>(hb_array_t<unsigned int const>&, hb_vector_t<hb_pair_t<unsigned int, unsigned int>, true>, bool, OT::IntType<unsigned short, 2u>*, unsigned int)
Unexecuted instantiation: hb-ot-font.cc:void OT::glyf_impl::_write_loca<hb_array_t<unsigned int const>&, OT::IntType<unsigned int, 4u>, (void*)0>(hb_array_t<unsigned int const>&, hb_vector_t<hb_pair_t<unsigned int, unsigned int>, true>, bool, OT::IntType<unsigned int, 4u>*, unsigned int)
Unexecuted instantiation: hb-static.cc:void OT::glyf_impl::_write_loca<hb_array_t<unsigned int const>&, OT::IntType<unsigned short, 2u>, (void*)0>(hb_array_t<unsigned int const>&, hb_vector_t<hb_pair_t<unsigned int, unsigned int>, true>, bool, OT::IntType<unsigned short, 2u>*, unsigned int)
Unexecuted instantiation: hb-static.cc:void OT::glyf_impl::_write_loca<hb_array_t<unsigned int const>&, OT::IntType<unsigned int, 4u>, (void*)0>(hb_array_t<unsigned int const>&, hb_vector_t<hb_pair_t<unsigned int, unsigned int>, true>, bool, OT::IntType<unsigned int, 4u>*, unsigned int)
54
55
static bool
56
_add_head_and_set_loca_version (hb_subset_plan_t *plan, bool use_short_loca)
57
0
{
58
0
  hb_blob_t *head_blob = hb_sanitize_context_t ().reference_table<head> (plan->source);
59
0
  hb_blob_t *head_prime_blob = hb_blob_copy_writable_or_fail (head_blob);
60
0
  hb_blob_destroy (head_blob);
61
0
62
0
  if (unlikely (!head_prime_blob))
63
0
    return false;
64
0
65
0
  head *head_prime = (head *) hb_blob_get_data_writable (head_prime_blob, nullptr);
66
0
  head_prime->indexToLocFormat = use_short_loca ? 0 : 1;
67
0
  if (plan->normalized_coords)
68
0
  {
69
0
    head_prime->xMin = plan->head_maxp_info.xMin;
70
0
    head_prime->xMax = plan->head_maxp_info.xMax;
71
0
    head_prime->yMin = plan->head_maxp_info.yMin;
72
0
    head_prime->yMax = plan->head_maxp_info.yMax;
73
0
74
0
    unsigned orig_flag = head_prime->flags;
75
0
    if (plan->head_maxp_info.allXMinIsLsb)
76
0
      orig_flag |= 1 << 1;
77
0
    else
78
0
      orig_flag &= ~(1 << 1);
79
0
    head_prime->flags = orig_flag;
80
0
  }
81
0
  bool success = plan->add_table (HB_OT_TAG_head, head_prime_blob);
82
0
83
0
  hb_blob_destroy (head_prime_blob);
84
0
  return success;
85
0
}
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: hb-static.cc:OT::glyf_impl::_add_head_and_set_loca_version(hb_subset_plan_t*, bool)
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
0
{
94
0
  unsigned num_offsets = c->plan->num_output_glyphs () + 1;
95
0
  unsigned entry_size = use_short_loca ? 2 : 4;
96
0
97
0
  char *loca_prime_data = (char *) hb_malloc (entry_size * num_offsets);
98
0
99
0
  if (unlikely (!loca_prime_data)) return false;
100
0
101
0
  DEBUG_MSG (SUBSET, nullptr, "loca entry_size %u num_offsets %u size %u",
102
0
       entry_size, num_offsets, entry_size * num_offsets);
103
0
104
0
  if (use_short_loca)
105
0
    _write_loca (padded_offsets, c->plan->new_to_old_gid_list, true, (HBUINT16 *) loca_prime_data, num_offsets);
106
0
  else
107
0
    _write_loca (padded_offsets, c->plan->new_to_old_gid_list, false, (HBUINT32 *) loca_prime_data, num_offsets);
108
0
109
0
  hb_blob_t *loca_blob = hb_blob_create (loca_prime_data,
110
0
           entry_size * num_offsets,
111
0
           HB_MEMORY_MODE_WRITABLE,
112
0
           loca_prime_data,
113
0
           hb_free);
114
0
115
0
  bool result = c->plan->add_table (HB_OT_TAG_loca, loca_blob)
116
0
       && _add_head_and_set_loca_version (c->plan, use_short_loca);
117
0
118
0
  hb_blob_destroy (loca_blob);
119
0
  return result;
120
0
}
Unexecuted instantiation: hb-ot-face.cc:bool OT::glyf_impl::_add_loca_and_head<hb_array_t<unsigned int const>, (void*)0>(hb_subset_context_t*, hb_array_t<unsigned int const>, bool)
Unexecuted instantiation: hb-ot-font.cc:bool OT::glyf_impl::_add_loca_and_head<hb_array_t<unsigned int const>, (void*)0>(hb_subset_context_t*, hb_array_t<unsigned int const>, bool)
Unexecuted instantiation: hb-static.cc:bool OT::glyf_impl::_add_loca_and_head<hb_array_t<unsigned int const>, (void*)0>(hb_subset_context_t*, hb_array_t<unsigned int const>, bool)
121
122
123
} /* namespace glyf_impl */
124
} /* namespace OT */
125
126
127
#endif /* OT_GLYF_GLYF_HELPERS_HH */