2 * Copyright © 2019 Ebrahim Byagowi
4 * This is part of HarfBuzz, a text shaping library.
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.
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
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.
25 #ifndef HB_OT_META_TABLE_HH
26 #define HB_OT_META_TABLE_HH
28 #include "hb-open-type.hh"
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
35 #define HB_OT_TAG_meta HB_TAG ('m','e','t','a')
43 int cmp (hb_tag_t a) const { return tag.cmp (a); }
45 hb_tag_t get_tag () const { return tag; }
47 hb_blob_t *reference_entry (hb_blob_t *meta_blob) const
48 { return hb_blob_create_sub_blob (meta_blob, dataZ, dataLength); }
50 bool sanitize (hb_sanitize_context_t *c, const void *base) const
52 TRACE_SANITIZE (this);
53 return_trace (likely (c->check_struct (this) &&
54 dataZ.sanitize (c, base, dataLength)));
58 Tag tag; /* A tag indicating the type of metadata. */
59 LNNOffsetTo<UnsizedArrayOf<HBUINT8>>
60 dataZ; /* Offset in bytes from the beginning of the
61 * metadata table to the data for this tag. */
62 HBUINT32 dataLength; /* Length of the data. The data is not required to
63 * be padded to any byte boundary. */
65 DEFINE_SIZE_STATIC (12);
70 static constexpr hb_tag_t tableTag = HB_OT_TAG_meta;
74 void init (hb_face_t *face)
75 { table = hb_sanitize_context_t ().reference_table<meta> (face); }
76 void fini () { table.destroy (); }
78 hb_blob_t *reference_entry (hb_tag_t tag) const
79 { return table->dataMaps.lsearch (tag).reference_entry (table.get_blob ()); }
81 unsigned int get_entries (unsigned int start_offset,
83 hb_ot_meta_tag_t *entries) const
87 + table->dataMaps.sub_array (start_offset, count)
88 | hb_map (&DataMap::get_tag)
89 | hb_map ([](hb_tag_t tag) { return (hb_ot_meta_tag_t) tag; })
90 | hb_sink (hb_array (entries, *count))
93 return table->dataMaps.len;
97 hb_blob_ptr_t<meta> table;
100 bool sanitize (hb_sanitize_context_t *c) const
102 TRACE_SANITIZE (this);
103 return_trace (likely (c->check_struct (this) &&
105 dataMaps.sanitize (c, this)));
109 HBUINT32 version; /* Version number of the metadata table — set to 1. */
110 HBUINT32 flags; /* Flags — currently unused; set to 0. */
112 /* Per Apple specification:
113 * Offset from the beginning of the table to the data.
114 * Per OT specification:
115 * Reserved. Not used; should be set to 0. */
117 dataMaps;/* Array of data map records. */
119 DEFINE_SIZE_ARRAY (16, dataMaps);
122 struct meta_accelerator_t : meta::accelerator_t {};
127 #endif /* HB_OT_META_TABLE_HH */