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 { cmpOT::DataMap43 int cmp (hb_tag_t a) const { return tag.cmp (a); } 44 get_tagOT::DataMap45 hb_tag_t get_tag () const { return tag; } 46 reference_entryOT::DataMap47 hb_blob_t *reference_entry (hb_blob_t *meta_blob) const 48 { return hb_blob_create_sub_blob (meta_blob, dataZ, dataLength); } 49 sanitizeOT::DataMap50 bool sanitize (hb_sanitize_context_t *c, const void *base) const 51 { 52 TRACE_SANITIZE (this); 53 return_trace (likely (c->check_struct (this) && 54 hb_barrier () && 55 dataZ.sanitize (c, base, dataLength))); 56 } 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 { accelerator_tOT::meta::accelerator_t75 accelerator_t (hb_face_t *face) 76 { table = hb_sanitize_context_t ().reference_table<meta> (face); } ~accelerator_tOT::meta::accelerator_t77 ~accelerator_t () { table.destroy (); } 78 reference_entryOT::meta::accelerator_t79 hb_blob_t *reference_entry (hb_tag_t tag) const 80 { return table->dataMaps.lsearch (tag).reference_entry (table.get_blob ()); } 81 get_entriesOT::meta::accelerator_t82 unsigned int get_entries (unsigned int start_offset, 83 unsigned int *count, 84 hb_ot_meta_tag_t *entries) const 85 { 86 if (count) 87 { 88 + table->dataMaps.as_array ().sub_array (start_offset, count) 89 | hb_map (&DataMap::get_tag) 90 | hb_map ([](hb_tag_t tag) { return (hb_ot_meta_tag_t) tag; }) 91 | hb_sink (hb_array (entries, *count)) 92 ; 93 } 94 return table->dataMaps.len; 95 } 96 97 private: 98 hb_blob_ptr_t<meta> table; 99 }; 100 sanitizeOT::meta101 bool sanitize (hb_sanitize_context_t *c) const 102 { 103 TRACE_SANITIZE (this); 104 return_trace (likely (c->check_struct (this) && 105 hb_barrier () && 106 version == 1 && 107 dataMaps.sanitize (c, this))); 108 } 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 { meta_accelerator_tOT::meta_accelerator_t125 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 */ 132