Coverage Report

Created: 2026-12-01 07:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/harfbuzz/src/hb-ot-meta-table.hh
Line
Count
Source
1
/*
2
 * Copyright © 2019  Ebrahim Byagowi
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
25
#ifndef HB_OT_META_TABLE_HH
26
#define HB_OT_META_TABLE_HH
27
28
#include "hb-open-type.hh"
29
30
/*
31
 * meta -- Metadata Table
32
 * https://docs.microsoft.com/en-us/typography/opentype/spec/meta
33
 * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6meta.html
34
 */
35
#define HB_OT_TAG_meta HB_TAG ('m','e','t','a')
36
37
38
namespace OT {
39
40
41
struct DataMap
42
{
43
0
  int cmp (hb_tag_t a) const { return tag.cmp (a); }
44
45
0
  hb_tag_t get_tag () const { return tag; }
46
47
  hb_blob_t *reference_entry (hb_blob_t *meta_blob) const
48
0
  { return hb_blob_create_sub_blob (meta_blob, dataZ, dataLength); }
49
50
  bool sanitize (hb_sanitize_context_t *c, const void *base) const
51
0
  {
52
0
    TRACE_SANITIZE (this);
53
0
    return_trace (likely (c->check_struct (this) &&
54
0
        hb_barrier () &&
55
0
        dataZ.sanitize (c, base, dataLength)));
56
0
  }
57
58
  protected:
59
  Tag   tag;    /* A tag indicating the type of metadata. */
60
  NNOffset32To<UnsizedArrayOf<HBUINT8>>
61
    dataZ;    /* Offset in bytes from the beginning of the
62
         * metadata table to the data for this tag. */
63
  HBUINT32  dataLength; /* Length of the data. The data is not required to
64
         * be padded to any byte boundary. */
65
  public:
66
  DEFINE_SIZE_STATIC (12);
67
};
68
69
struct meta
70
{
71
  static constexpr hb_tag_t tableTag = HB_OT_TAG_meta;
72
73
  struct accelerator_t
74
  {
75
    accelerator_t (hb_face_t *face)
76
0
    { table = hb_sanitize_context_t ().reference_table<meta> (face); }
77
0
    ~accelerator_t () { table.destroy (); }
78
79
0
    hb_blob_ptr_t<meta> borrow_sanitized_table () const { return table; }
80
81
    hb_blob_t *reference_entry (hb_tag_t tag) const
82
0
    { return table->dataMaps.lsearch (tag).reference_entry (table.get_blob ()); }
83
84
    unsigned int get_entries (unsigned int      start_offset,
85
            unsigned int     *count,
86
            hb_ot_meta_tag_t *entries) const
87
0
    {
88
0
      if (count && entries)
89
0
      {
90
0
  + table->dataMaps.as_array ().sub_array (start_offset, count)
91
0
  | hb_map (&DataMap::get_tag)
92
0
  | hb_map ([](hb_tag_t tag) { return (hb_ot_meta_tag_t) tag; })
93
0
  | hb_sink (hb_array (entries, *count))
94
0
  ;
95
0
      }
96
0
      return table->dataMaps.len;
97
0
    }
98
99
    private:
100
    hb_blob_ptr_t<meta> table;
101
  };
102
103
  bool sanitize (hb_sanitize_context_t *c) const
104
0
  {
105
0
    TRACE_SANITIZE (this);
106
0
    return_trace (likely (c->check_struct (this) &&
107
0
        hb_barrier () &&
108
0
        version == 1 &&
109
0
        dataMaps.sanitize (c, this)));
110
0
  }
111
112
  protected:
113
  HBUINT32  version;  /* Version number of the metadata table — set to 1. */
114
  HBUINT32  flags;    /* Flags — currently unused; set to 0. */
115
  HBUINT32  dataOffset;
116
        /* Per Apple specification:
117
         * Offset from the beginning of the table to the data.
118
         * Per OT specification:
119
         * Reserved. Not used; should be set to 0. */
120
  Array32Of<DataMap>
121
    dataMaps;/* Array of data map records. */
122
  public:
123
  DEFINE_SIZE_ARRAY (16, dataMaps);
124
};
125
126
struct meta_accelerator_t : meta::accelerator_t {
127
0
  meta_accelerator_t (hb_face_t *face) : meta::accelerator_t (face) {}
128
};
129
130
} /* namespace OT */
131
132
133
#endif /* HB_OT_META_TABLE_HH */