Coverage Report

Created: 2025-07-07 10:01

/work/workdir/UnpackedTarball/harfbuzz/src/hb-ot-meta-table.hh
Line
Count
Source (jump to first uncovered line)
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
    hb_blob_t *reference_entry (hb_tag_t tag) const
80
0
    { return table->dataMaps.lsearch (tag).reference_entry (table.get_blob ()); }
81
82
    unsigned int get_entries (unsigned int      start_offset,
83
            unsigned int     *count,
84
            hb_ot_meta_tag_t *entries) const
85
0
    {
86
0
      if (count)
87
0
      {
88
0
  + table->dataMaps.as_array ().sub_array (start_offset, count)
89
0
  | hb_map (&DataMap::get_tag)
90
0
  | hb_map ([](hb_tag_t tag) { return (hb_ot_meta_tag_t) tag; })
91
0
  | hb_sink (hb_array (entries, *count))
92
0
  ;
93
0
      }
94
0
      return table->dataMaps.len;
95
0
    }
96
97
    private:
98
    hb_blob_ptr_t<meta> table;
99
  };
100
101
  bool sanitize (hb_sanitize_context_t *c) const
102
0
  {
103
0
    TRACE_SANITIZE (this);
104
0
    return_trace (likely (c->check_struct (this) &&
105
0
        hb_barrier () &&
106
0
        version == 1 &&
107
0
        dataMaps.sanitize (c, this)));
108
0
  }
109
110
  protected:
111
  HBUINT32  version;  /* Version number of the metadata table — set to 1. */
112
  HBUINT32  flags;    /* Flags — currently unused; set to 0. */
113
  HBUINT32  dataOffset;
114
        /* Per Apple specification:
115
         * Offset from the beginning of the table to the data.
116
         * Per OT specification:
117
         * Reserved. Not used; should be set to 0. */
118
  Array32Of<DataMap>
119
    dataMaps;/* Array of data map records. */
120
  public:
121
  DEFINE_SIZE_ARRAY (16, dataMaps);
122
};
123
124
struct meta_accelerator_t : meta::accelerator_t {
125
0
  meta_accelerator_t (hb_face_t *face) : meta::accelerator_t (face) {}
126
};
127
128
} /* namespace OT */
129
130
131
#endif /* HB_OT_META_TABLE_HH */