Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1 | /* |
Behdad Esfahbod | 2409d5f | 2011-04-21 17:14:28 -0400 | [diff] [blame] | 2 | * Copyright © 2007,2008,2009 Red Hat, Inc. |
Behdad Esfahbod | 5b93e8d | 2012-04-23 22:26:13 -0400 | [diff] [blame] | 3 | * Copyright © 2010,2012 Google, Inc. |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 4 | * |
Behdad Esfahbod | c755cb3 | 2010-04-22 00:11:43 -0400 | [diff] [blame] | 5 | * This is part of HarfBuzz, a text shaping library. |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 6 | * |
| 7 | * Permission is hereby granted, without written agreement and without |
| 8 | * license or royalty fees, to use, copy, modify, and distribute this |
| 9 | * software and its documentation for any purpose, provided that the |
| 10 | * above copyright notice and the following two paragraphs appear in |
| 11 | * all copies of this software. |
| 12 | * |
| 13 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
| 14 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
| 15 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
| 16 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 17 | * DAMAGE. |
| 18 | * |
| 19 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
| 20 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
| 22 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
| 23 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 24 | * |
| 25 | * Red Hat Author(s): Behdad Esfahbod |
Behdad Esfahbod | 5bd1e95 | 2010-09-22 16:46:18 -0400 | [diff] [blame] | 26 | * Google Author(s): Behdad Esfahbod |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 27 | */ |
| 28 | |
Behdad Esfahbod | 5f5b24f | 2009-08-02 20:03:12 -0400 | [diff] [blame] | 29 | #ifndef HB_OT_LAYOUT_COMMON_PRIVATE_HH |
| 30 | #define HB_OT_LAYOUT_COMMON_PRIVATE_HH |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 31 | |
Behdad Esfahbod | 22da7fd | 2010-05-12 18:23:21 -0400 | [diff] [blame] | 32 | #include "hb-ot-layout-private.hh" |
Behdad Esfahbod | 7edb430 | 2009-08-04 22:06:57 -0400 | [diff] [blame] | 33 | #include "hb-open-type-private.hh" |
Behdad Esfahbod | 0b08adb | 2012-04-23 22:41:09 -0400 | [diff] [blame] | 34 | #include "hb-set-private.hh" |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 35 | |
| 36 | |
Behdad Esfahbod | 5ba4504 | 2015-11-02 15:43:08 -0800 | [diff] [blame] | 37 | #ifndef HB_MAX_NESTING_LEVEL |
| 38 | #define HB_MAX_NESTING_LEVEL 6 |
| 39 | #endif |
| 40 | #ifndef HB_MAX_CONTEXT_LENGTH |
| 41 | #define HB_MAX_CONTEXT_LENGTH 64 |
| 42 | #endif |
| 43 | |
| 44 | |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 45 | namespace OT { |
| 46 | |
| 47 | |
Behdad Esfahbod | 40c5892 | 2015-02-18 13:18:46 +0300 | [diff] [blame] | 48 | #define TRACE_DISPATCH(this, format) \ |
| 49 | hb_auto_trace_t<context_t::max_debug_depth, typename context_t::return_t> trace \ |
| 50 | (&c->debug_depth, c->get_name (), this, HB_FUNC, \ |
| 51 | "format %d", (int) format); |
| 52 | |
| 53 | |
Behdad Esfahbod | dadede0 | 2012-07-28 18:03:20 -0400 | [diff] [blame] | 54 | #define NOT_COVERED ((unsigned int) -1) |
Behdad Esfahbod | cd33cb9 | 2009-08-14 18:42:42 -0400 | [diff] [blame] | 55 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 56 | |
Behdad Esfahbod | cd33cb9 | 2009-08-14 18:42:42 -0400 | [diff] [blame] | 57 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 58 | /* |
| 59 | * |
| 60 | * OpenType Layout Common Table Formats |
| 61 | * |
| 62 | */ |
| 63 | |
Behdad Esfahbod | 2e8fb6c | 2009-05-18 04:37:37 -0400 | [diff] [blame] | 64 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 65 | /* |
| 66 | * Script, ScriptList, LangSys, Feature, FeatureList, Lookup, LookupList |
| 67 | */ |
| 68 | |
| 69 | template <typename Type> |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 70 | struct Record |
| 71 | { |
Behdad Esfahbod | 4e57371 | 2010-09-28 16:23:58 -0400 | [diff] [blame] | 72 | inline int cmp (hb_tag_t a) const { |
Behdad Esfahbod | 36b3862 | 2010-09-29 12:10:24 -0400 | [diff] [blame] | 73 | return tag.cmp (a); |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 74 | } |
| 75 | |
Behdad Esfahbod | 87e43b7 | 2012-12-14 17:48:23 -0500 | [diff] [blame] | 76 | struct sanitize_closure_t { |
| 77 | hb_tag_t tag; |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 78 | const void *list_base; |
Behdad Esfahbod | 87e43b7 | 2012-12-14 17:48:23 -0500 | [diff] [blame] | 79 | }; |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 80 | inline bool sanitize (hb_sanitize_context_t *c, const void *base) const |
| 81 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 82 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 87e43b7 | 2012-12-14 17:48:23 -0500 | [diff] [blame] | 83 | const sanitize_closure_t closure = {tag, base}; |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 84 | return_trace (c->check_struct (this) && offset.sanitize (c, base, &closure)); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 85 | } |
| 86 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 87 | Tag tag; /* 4-byte Tag identifier */ |
| 88 | OffsetTo<Type> |
| 89 | offset; /* Offset from beginning of object holding |
| 90 | * the Record */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 91 | public: |
| 92 | DEFINE_SIZE_STATIC (6); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | template <typename Type> |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 96 | struct RecordArrayOf : SortedArrayOf<Record<Type> > { |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 97 | inline const Tag& get_tag (unsigned int i) const |
| 98 | { |
Behdad Esfahbod | 4e22c7e | 2010-11-03 15:47:12 -0400 | [diff] [blame] | 99 | /* We cheat slightly and don't define separate Null objects |
| 100 | * for Record types. Instead, we return the correct Null(Tag) |
| 101 | * here. */ |
Behdad Esfahbod | 64d3fc8 | 2010-05-03 22:51:19 -0400 | [diff] [blame] | 102 | if (unlikely (i >= this->len)) return Null(Tag); |
Behdad Esfahbod | d3480ba | 2009-11-03 10:47:29 -0500 | [diff] [blame] | 103 | return (*this)[i].tag; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 104 | } |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 105 | inline unsigned int get_tags (unsigned int start_offset, |
| 106 | unsigned int *record_count /* IN/OUT */, |
| 107 | hb_tag_t *record_tags /* OUT */) const |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 108 | { |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 109 | if (record_count) { |
Behdad Esfahbod | 31f18ab | 2011-06-15 09:49:58 -0400 | [diff] [blame] | 110 | const Record<Type> *arr = this->sub_array (start_offset, record_count); |
Behdad Esfahbod | 48de373 | 2009-11-04 16:59:50 -0500 | [diff] [blame] | 111 | unsigned int count = *record_count; |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 112 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 31f18ab | 2011-06-15 09:49:58 -0400 | [diff] [blame] | 113 | record_tags[i] = arr[i].tag; |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 114 | } |
| 115 | return this->len; |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 116 | } |
| 117 | inline bool find_index (hb_tag_t tag, unsigned int *index) const |
| 118 | { |
Behdad Esfahbod | df554af | 2014-06-19 15:39:18 -0400 | [diff] [blame] | 119 | /* If we want to allow non-sorted data, we can lsearch(). */ |
| 120 | int i = this->/*lsearch*/bsearch (tag); |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 121 | if (i != -1) { |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 122 | if (index) *index = i; |
| 123 | return true; |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 124 | } else { |
| 125 | if (index) *index = Index::NOT_FOUND_INDEX; |
| 126 | return false; |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 127 | } |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 128 | } |
| 129 | }; |
| 130 | |
| 131 | template <typename Type> |
| 132 | struct RecordListOf : RecordArrayOf<Type> |
| 133 | { |
| 134 | inline const Type& operator [] (unsigned int i) const |
Behdad Esfahbod | 6bec81a | 2009-11-02 19:17:36 -0500 | [diff] [blame] | 135 | { return this+RecordArrayOf<Type>::operator [](i).offset; } |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 136 | |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 137 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 138 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 139 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 140 | return_trace (RecordArrayOf<Type>::sanitize (c, this)); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 141 | } |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 145 | struct RangeRecord |
| 146 | { |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 147 | inline int cmp (hb_codepoint_t g) const { |
Behdad Esfahbod | 797d76d | 2013-04-18 19:04:12 -0400 | [diff] [blame] | 148 | return g < start ? -1 : g <= end ? 0 : +1 ; |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 149 | } |
| 150 | |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 151 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 152 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 153 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 154 | return_trace (c->check_struct (this)); |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 155 | } |
| 156 | |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 157 | inline bool intersects (const hb_set_t *glyphs) const { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 158 | return glyphs->intersects (start, end); |
| 159 | } |
| 160 | |
Behdad Esfahbod | c8accf1 | 2012-08-01 21:05:57 -0400 | [diff] [blame] | 161 | template <typename set_t> |
| 162 | inline void add_coverage (set_t *glyphs) const { |
Behdad Esfahbod | 67bb9e8 | 2012-06-09 02:02:46 -0400 | [diff] [blame] | 163 | glyphs->add_range (start, end); |
| 164 | } |
| 165 | |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 166 | GlyphID start; /* First GlyphID in the range */ |
| 167 | GlyphID end; /* Last GlyphID in the range */ |
| 168 | USHORT value; /* Value */ |
| 169 | public: |
| 170 | DEFINE_SIZE_STATIC (6); |
| 171 | }; |
| 172 | DEFINE_NULL_DATA (RangeRecord, "\000\001"); |
| 173 | |
| 174 | |
Behdad Esfahbod | b5db4f1 | 2010-05-10 22:22:22 -0400 | [diff] [blame] | 175 | struct IndexArray : ArrayOf<Index> |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 176 | { |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 177 | inline unsigned int get_indexes (unsigned int start_offset, |
| 178 | unsigned int *_count /* IN/OUT */, |
| 179 | unsigned int *_indexes /* OUT */) const |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 180 | { |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 181 | if (_count) { |
Behdad Esfahbod | 31f18ab | 2011-06-15 09:49:58 -0400 | [diff] [blame] | 182 | const USHORT *arr = this->sub_array (start_offset, _count); |
Behdad Esfahbod | 48de373 | 2009-11-04 16:59:50 -0500 | [diff] [blame] | 183 | unsigned int count = *_count; |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 184 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 31f18ab | 2011-06-15 09:49:58 -0400 | [diff] [blame] | 185 | _indexes[i] = arr[i]; |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 186 | } |
| 187 | return this->len; |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 188 | } |
| 189 | }; |
| 190 | |
| 191 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 192 | struct Script; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 193 | struct LangSys; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 194 | struct Feature; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 195 | |
| 196 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 197 | struct LangSys |
| 198 | { |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 199 | inline unsigned int get_feature_count (void) const |
| 200 | { return featureIndex.len; } |
| 201 | inline hb_tag_t get_feature_index (unsigned int i) const |
| 202 | { return featureIndex[i]; } |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 203 | inline unsigned int get_feature_indexes (unsigned int start_offset, |
| 204 | unsigned int *feature_count /* IN/OUT */, |
| 205 | unsigned int *feature_indexes /* OUT */) const |
| 206 | { return featureIndex.get_indexes (start_offset, feature_count, feature_indexes); } |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 207 | |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 208 | inline bool has_required_feature (void) const { return reqFeatureIndex != 0xFFFFu; } |
Behdad Esfahbod | 3d44fb6 | 2010-05-10 22:22:54 -0400 | [diff] [blame] | 209 | inline unsigned int get_required_feature_index (void) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 210 | { |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 211 | if (reqFeatureIndex == 0xFFFFu) |
Behdad Esfahbod | b5db4f1 | 2010-05-10 22:22:22 -0400 | [diff] [blame] | 212 | return Index::NOT_FOUND_INDEX; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 213 | return reqFeatureIndex;; |
| 214 | } |
| 215 | |
Behdad Esfahbod | 87e43b7 | 2012-12-14 17:48:23 -0500 | [diff] [blame] | 216 | inline bool sanitize (hb_sanitize_context_t *c, |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 217 | const Record<LangSys>::sanitize_closure_t * = NULL) const |
| 218 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 219 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 220 | return_trace (c->check_struct (this) && featureIndex.sanitize (c)); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 221 | } |
| 222 | |
Behdad Esfahbod | 7d4ada6 | 2014-06-27 17:30:59 -0400 | [diff] [blame] | 223 | Offset<> lookupOrderZ; /* = Null (reserved for an offset to a |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 224 | * reordering table) */ |
| 225 | USHORT reqFeatureIndex;/* Index of a feature required for this |
| 226 | * language system--if no required features |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 227 | * = 0xFFFFu */ |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 228 | IndexArray featureIndex; /* Array of indices into the FeatureList */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 229 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 230 | DEFINE_SIZE_ARRAY (6, featureIndex); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 231 | }; |
Behdad Esfahbod | 65f46b0 | 2010-05-06 19:35:19 -0400 | [diff] [blame] | 232 | DEFINE_NULL_DATA (LangSys, "\0\0\xFF\xFF"); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 233 | |
| 234 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 235 | struct Script |
| 236 | { |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 237 | inline unsigned int get_lang_sys_count (void) const |
| 238 | { return langSys.len; } |
| 239 | inline const Tag& get_lang_sys_tag (unsigned int i) const |
| 240 | { return langSys.get_tag (i); } |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 241 | inline unsigned int get_lang_sys_tags (unsigned int start_offset, |
| 242 | unsigned int *lang_sys_count /* IN/OUT */, |
| 243 | hb_tag_t *lang_sys_tags /* OUT */) const |
| 244 | { return langSys.get_tags (start_offset, lang_sys_count, lang_sys_tags); } |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 245 | inline const LangSys& get_lang_sys (unsigned int i) const |
| 246 | { |
Behdad Esfahbod | b5db4f1 | 2010-05-10 22:22:22 -0400 | [diff] [blame] | 247 | if (i == Index::NOT_FOUND_INDEX) return get_default_lang_sys (); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 248 | return this+langSys[i].offset; |
| 249 | } |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 250 | inline bool find_lang_sys_index (hb_tag_t tag, unsigned int *index) const |
| 251 | { return langSys.find_index (tag, index); } |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 252 | |
Behdad Esfahbod | cc6c644 | 2009-05-25 03:10:06 -0400 | [diff] [blame] | 253 | inline bool has_default_lang_sys (void) const { return defaultLangSys != 0; } |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 254 | inline const LangSys& get_default_lang_sys (void) const { return this+defaultLangSys; } |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 255 | |
Behdad Esfahbod | 87e43b7 | 2012-12-14 17:48:23 -0500 | [diff] [blame] | 256 | inline bool sanitize (hb_sanitize_context_t *c, |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 257 | const Record<Script>::sanitize_closure_t * = NULL) const |
| 258 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 259 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 260 | return_trace (defaultLangSys.sanitize (c, this) && langSys.sanitize (c, this)); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 261 | } |
| 262 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 263 | protected: |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 264 | OffsetTo<LangSys> |
| 265 | defaultLangSys; /* Offset to DefaultLangSys table--from |
| 266 | * beginning of Script table--may be Null */ |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 267 | RecordArrayOf<LangSys> |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 268 | langSys; /* Array of LangSysRecords--listed |
| 269 | * alphabetically by LangSysTag */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 270 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 271 | DEFINE_SIZE_ARRAY (4, langSys); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 272 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 273 | |
| 274 | typedef RecordListOf<Script> ScriptList; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 275 | |
Behdad Esfahbod | 875a5cb | 2012-12-11 14:17:01 -0500 | [diff] [blame] | 276 | |
| 277 | /* http://www.microsoft.com/typography/otspec/features_pt.htm#size */ |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 278 | struct FeatureParamsSize |
| 279 | { |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 280 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 281 | { |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 282 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 283 | if (unlikely (!c->check_struct (this))) return_trace (false); |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 284 | |
| 285 | /* This subtable has some "history", if you will. Some earlier versions of |
| 286 | * Adobe tools calculated the offset of the FeatureParams sutable from the |
| 287 | * beginning of the FeatureList table! Now, that is dealt with in the |
| 288 | * Feature implementation. But we still need to be able to tell junk from |
| 289 | * real data. Note: We don't check that the nameID actually exists. |
| 290 | * |
| 291 | * Read Roberts wrote on 9/15/06 on opentype-list@indx.co.uk : |
| 292 | * |
| 293 | * Yes, it is correct that a new version of the AFDKO (version 2.0) will be |
| 294 | * coming out soon, and that the makeotf program will build a font with a |
| 295 | * 'size' feature that is correct by the specification. |
| 296 | * |
| 297 | * The specification for this feature tag is in the "OpenType Layout Tag |
| 298 | * Registry". You can see a copy of this at: |
| 299 | * http://partners.adobe.com/public/developer/opentype/index_tag8.html#size |
| 300 | * |
| 301 | * Here is one set of rules to determine if the 'size' feature is built |
| 302 | * correctly, or as by the older versions of MakeOTF. You may be able to do |
| 303 | * better. |
| 304 | * |
| 305 | * Assume that the offset to the size feature is according to specification, |
| 306 | * and make the following value checks. If it fails, assume the the size |
| 307 | * feature is calculated as versions of MakeOTF before the AFDKO 2.0 built it. |
| 308 | * If this fails, reject the 'size' feature. The older makeOTF's calculated the |
| 309 | * offset from the beginning of the FeatureList table, rather than from the |
| 310 | * beginning of the 'size' Feature table. |
| 311 | * |
| 312 | * If "design size" == 0: |
| 313 | * fails check |
| 314 | * |
| 315 | * Else if ("subfamily identifier" == 0 and |
| 316 | * "range start" == 0 and |
| 317 | * "range end" == 0 and |
| 318 | * "range start" == 0 and |
| 319 | * "menu name ID" == 0) |
| 320 | * passes check: this is the format used when there is a design size |
| 321 | * specified, but there is no recommended size range. |
| 322 | * |
| 323 | * Else if ("design size" < "range start" or |
| 324 | * "design size" > "range end" or |
| 325 | * "range end" <= "range start" or |
| 326 | * "menu name ID" < 256 or |
| 327 | * "menu name ID" > 32767 or |
| 328 | * menu name ID is not a name ID which is actually in the name table) |
| 329 | * fails test |
| 330 | * Else |
| 331 | * passes test. |
| 332 | */ |
| 333 | |
| 334 | if (!designSize) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 335 | return_trace (false); |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 336 | else if (subfamilyID == 0 && |
| 337 | subfamilyNameID == 0 && |
| 338 | rangeStart == 0 && |
| 339 | rangeEnd == 0) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 340 | return_trace (true); |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 341 | else if (designSize < rangeStart || |
| 342 | designSize > rangeEnd || |
| 343 | subfamilyNameID < 256 || |
| 344 | subfamilyNameID > 32767) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 345 | return_trace (false); |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 346 | else |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 347 | return_trace (true); |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 348 | } |
| 349 | |
Behdad Esfahbod | 875a5cb | 2012-12-11 14:17:01 -0500 | [diff] [blame] | 350 | USHORT designSize; /* Represents the design size in 720/inch |
| 351 | * units (decipoints). The design size entry |
| 352 | * must be non-zero. When there is a design |
| 353 | * size but no recommended size range, the |
| 354 | * rest of the array will consist of zeros. */ |
| 355 | USHORT subfamilyID; /* Has no independent meaning, but serves |
| 356 | * as an identifier that associates fonts |
| 357 | * in a subfamily. All fonts which share a |
| 358 | * Preferred or Font Family name and which |
| 359 | * differ only by size range shall have the |
| 360 | * same subfamily value, and no fonts which |
| 361 | * differ in weight or style shall have the |
| 362 | * same subfamily value. If this value is |
| 363 | * zero, the remaining fields in the array |
| 364 | * will be ignored. */ |
| 365 | USHORT subfamilyNameID;/* If the preceding value is non-zero, this |
| 366 | * value must be set in the range 256 - 32767 |
| 367 | * (inclusive). It records the value of a |
| 368 | * field in the name table, which must |
| 369 | * contain English-language strings encoded |
| 370 | * in Windows Unicode and Macintosh Roman, |
| 371 | * and may contain additional strings |
| 372 | * localized to other scripts and languages. |
| 373 | * Each of these strings is the name an |
| 374 | * application should use, in combination |
| 375 | * with the family name, to represent the |
| 376 | * subfamily in a menu. Applications will |
| 377 | * choose the appropriate version based on |
| 378 | * their selection criteria. */ |
| 379 | USHORT rangeStart; /* Large end of the recommended usage range |
| 380 | * (inclusive), stored in 720/inch units |
| 381 | * (decipoints). */ |
| 382 | USHORT rangeEnd; /* Small end of the recommended usage range |
| 383 | (exclusive), stored in 720/inch units |
| 384 | * (decipoints). */ |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 385 | public: |
| 386 | DEFINE_SIZE_STATIC (10); |
| 387 | }; |
| 388 | |
Behdad Esfahbod | 875a5cb | 2012-12-11 14:17:01 -0500 | [diff] [blame] | 389 | /* http://www.microsoft.com/typography/otspec/features_pt.htm#ssxx */ |
| 390 | struct FeatureParamsStylisticSet |
| 391 | { |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 392 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 393 | { |
Behdad Esfahbod | 875a5cb | 2012-12-11 14:17:01 -0500 | [diff] [blame] | 394 | TRACE_SANITIZE (this); |
| 395 | /* Right now minorVersion is at zero. Which means, any table supports |
| 396 | * the uiNameID field. */ |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 397 | return_trace (c->check_struct (this)); |
Behdad Esfahbod | 875a5cb | 2012-12-11 14:17:01 -0500 | [diff] [blame] | 398 | } |
| 399 | |
Behdad Esfahbod | e1ebf01 | 2013-11-26 18:00:35 -0500 | [diff] [blame] | 400 | USHORT version; /* (set to 0): This corresponds to a “minor” |
Behdad Esfahbod | 875a5cb | 2012-12-11 14:17:01 -0500 | [diff] [blame] | 401 | * version number. Additional data may be |
| 402 | * added to the end of this Feature Parameters |
| 403 | * table in the future. */ |
| 404 | |
| 405 | USHORT uiNameID; /* The 'name' table name ID that specifies a |
| 406 | * string (or strings, for multiple languages) |
| 407 | * for a user-interface label for this |
| 408 | * feature. The values of uiLabelNameId and |
| 409 | * sampleTextNameId are expected to be in the |
| 410 | * font-specific name ID range (256-32767), |
| 411 | * though that is not a requirement in this |
| 412 | * Feature Parameters specification. The |
| 413 | * user-interface label for the feature can |
| 414 | * be provided in multiple languages. An |
| 415 | * English string should be included as a |
| 416 | * fallback. The string should be kept to a |
| 417 | * minimal length to fit comfortably with |
| 418 | * different application interfaces. */ |
| 419 | public: |
| 420 | DEFINE_SIZE_STATIC (4); |
| 421 | }; |
| 422 | |
Behdad Esfahbod | a182dbc | 2013-11-26 17:53:41 -0500 | [diff] [blame] | 423 | /* http://www.microsoft.com/typography/otspec/features_ae.htm#cv01-cv99 */ |
Behdad Esfahbod | 0bae50a | 2012-12-11 16:01:31 -0500 | [diff] [blame] | 424 | struct FeatureParamsCharacterVariants |
| 425 | { |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 426 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 427 | { |
Behdad Esfahbod | 0bae50a | 2012-12-11 16:01:31 -0500 | [diff] [blame] | 428 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 429 | return_trace (c->check_struct (this) && |
| 430 | characters.sanitize (c)); |
Behdad Esfahbod | 0bae50a | 2012-12-11 16:01:31 -0500 | [diff] [blame] | 431 | } |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 432 | |
Behdad Esfahbod | 0bae50a | 2012-12-11 16:01:31 -0500 | [diff] [blame] | 433 | USHORT format; /* Format number is set to 0. */ |
| 434 | USHORT featUILableNameID; /* The ‘name’ table name ID that |
| 435 | * specifies a string (or strings, |
| 436 | * for multiple languages) for a |
| 437 | * user-interface label for this |
| 438 | * feature. (May be NULL.) */ |
| 439 | USHORT featUITooltipTextNameID;/* The ‘name’ table name ID that |
| 440 | * specifies a string (or strings, |
| 441 | * for multiple languages) that an |
| 442 | * application can use for tooltip |
| 443 | * text for this feature. (May be |
| 444 | * NULL.) */ |
| 445 | USHORT sampleTextNameID; /* The ‘name’ table name ID that |
| 446 | * specifies sample text that |
| 447 | * illustrates the effect of this |
| 448 | * feature. (May be NULL.) */ |
| 449 | USHORT numNamedParameters; /* Number of named parameters. (May |
| 450 | * be zero.) */ |
| 451 | USHORT firstParamUILabelNameID;/* The first ‘name’ table name ID |
| 452 | * used to specify strings for |
| 453 | * user-interface labels for the |
| 454 | * feature parameters. (Must be zero |
| 455 | * if numParameters is zero.) */ |
| 456 | ArrayOf<UINT24> |
| 457 | characters; /* Array of the Unicode Scalar Value |
| 458 | * of the characters for which this |
| 459 | * feature provides glyph variants. |
| 460 | * (May be zero.) */ |
| 461 | public: |
| 462 | DEFINE_SIZE_ARRAY (14, characters); |
| 463 | }; |
| 464 | |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 465 | struct FeatureParams |
| 466 | { |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 467 | inline bool sanitize (hb_sanitize_context_t *c, hb_tag_t tag) const |
| 468 | { |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 469 | TRACE_SANITIZE (this); |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 470 | if (tag == HB_TAG ('s','i','z','e')) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 471 | return_trace (u.size.sanitize (c)); |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 472 | if ((tag & 0xFFFF0000u) == HB_TAG ('s','s','\0','\0')) /* ssXX */ |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 473 | return_trace (u.stylisticSet.sanitize (c)); |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 474 | if ((tag & 0xFFFF0000u) == HB_TAG ('c','v','\0','\0')) /* cvXX */ |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 475 | return_trace (u.characterVariants.sanitize (c)); |
| 476 | return_trace (true); |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 477 | } |
| 478 | |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 479 | inline const FeatureParamsSize& get_size_params (hb_tag_t tag) const |
| 480 | { |
| 481 | if (tag == HB_TAG ('s','i','z','e')) |
| 482 | return u.size; |
| 483 | return Null(FeatureParamsSize); |
| 484 | } |
| 485 | |
| 486 | private: |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 487 | union { |
Behdad Esfahbod | 0bae50a | 2012-12-11 16:01:31 -0500 | [diff] [blame] | 488 | FeatureParamsSize size; |
| 489 | FeatureParamsStylisticSet stylisticSet; |
| 490 | FeatureParamsCharacterVariants characterVariants; |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 491 | } u; |
Behdad Esfahbod | 0bae50a | 2012-12-11 16:01:31 -0500 | [diff] [blame] | 492 | DEFINE_SIZE_STATIC (17); |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 493 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 494 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 495 | struct Feature |
| 496 | { |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 497 | inline unsigned int get_lookup_count (void) const |
| 498 | { return lookupIndex.len; } |
| 499 | inline hb_tag_t get_lookup_index (unsigned int i) const |
| 500 | { return lookupIndex[i]; } |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 501 | inline unsigned int get_lookup_indexes (unsigned int start_index, |
| 502 | unsigned int *lookup_count /* IN/OUT */, |
| 503 | unsigned int *lookup_tags /* OUT */) const |
| 504 | { return lookupIndex.get_indexes (start_index, lookup_count, lookup_tags); } |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 505 | |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 506 | inline const FeatureParams &get_feature_params (void) const |
| 507 | { return this+featureParams; } |
| 508 | |
Behdad Esfahbod | 87e43b7 | 2012-12-14 17:48:23 -0500 | [diff] [blame] | 509 | inline bool sanitize (hb_sanitize_context_t *c, |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 510 | const Record<Feature>::sanitize_closure_t *closure = NULL) const |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 511 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 512 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 9b54562 | 2012-12-17 13:55:36 -0500 | [diff] [blame] | 513 | if (unlikely (!(c->check_struct (this) && lookupIndex.sanitize (c)))) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 514 | return_trace (false); |
Behdad Esfahbod | 9b54562 | 2012-12-17 13:55:36 -0500 | [diff] [blame] | 515 | |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 516 | /* Some earlier versions of Adobe tools calculated the offset of the |
| 517 | * FeatureParams subtable from the beginning of the FeatureList table! |
| 518 | * |
| 519 | * If sanitizing "failed" for the FeatureParams subtable, try it with the |
| 520 | * alternative location. We would know sanitize "failed" if old value |
| 521 | * of the offset was non-zero, but it's zeroed now. |
Behdad Esfahbod | 1ffd23c | 2012-12-17 23:29:15 -0500 | [diff] [blame] | 522 | * |
| 523 | * Only do this for the 'size' feature, since at the time of the faulty |
| 524 | * Adobe tools, only the 'size' feature had FeatureParams defined. |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 525 | */ |
| 526 | |
Behdad Esfahbod | 586b606 | 2014-06-27 15:39:47 -0400 | [diff] [blame] | 527 | OffsetTo<FeatureParams> orig_offset = featureParams; |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 528 | if (unlikely (!featureParams.sanitize (c, this, closure ? closure->tag : HB_TAG_NONE))) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 529 | return_trace (false); |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 530 | |
Behdad Esfahbod | 9da552d | 2014-06-27 15:09:42 -0400 | [diff] [blame] | 531 | if (likely (orig_offset.is_null ())) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 532 | return_trace (true); |
Behdad Esfahbod | 9b54562 | 2012-12-17 13:55:36 -0500 | [diff] [blame] | 533 | |
Behdad Esfahbod | 1ffd23c | 2012-12-17 23:29:15 -0500 | [diff] [blame] | 534 | if (featureParams == 0 && closure && |
| 535 | closure->tag == HB_TAG ('s','i','z','e') && |
| 536 | closure->list_base && closure->list_base < this) |
Behdad Esfahbod | 9b54562 | 2012-12-17 13:55:36 -0500 | [diff] [blame] | 537 | { |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 538 | unsigned int new_offset_int = (unsigned int) orig_offset - |
Behdad Esfahbod | dac8602 | 2014-06-03 17:57:00 -0400 | [diff] [blame] | 539 | (((char *) this) - ((char *) closure->list_base)); |
Behdad Esfahbod | 9b54562 | 2012-12-17 13:55:36 -0500 | [diff] [blame] | 540 | |
Behdad Esfahbod | 586b606 | 2014-06-27 15:39:47 -0400 | [diff] [blame] | 541 | OffsetTo<FeatureParams> new_offset; |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 542 | /* Check that it did not overflow. */ |
| 543 | new_offset.set (new_offset_int); |
| 544 | if (new_offset == new_offset_int && |
Behdad Esfahbod | 51f5635 | 2014-06-04 18:42:32 -0400 | [diff] [blame] | 545 | c->try_set (&featureParams, new_offset) && |
Behdad Esfahbod | efe252e | 2012-12-17 23:21:05 -0500 | [diff] [blame] | 546 | !featureParams.sanitize (c, this, closure ? closure->tag : HB_TAG_NONE)) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 547 | return_trace (false); |
Behdad Esfahbod | da2fcfd | 2016-01-05 13:23:45 +0000 | [diff] [blame] | 548 | |
| 549 | if (c->edit_count > 1) |
| 550 | c->edit_count--; /* This was a "legitimate" edit; don't contribute to error count. */ |
Behdad Esfahbod | 9b54562 | 2012-12-17 13:55:36 -0500 | [diff] [blame] | 551 | } |
| 552 | |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 553 | return_trace (true); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 554 | } |
| 555 | |
Behdad Esfahbod | f54cce3 | 2012-11-26 14:02:31 +0200 | [diff] [blame] | 556 | OffsetTo<FeatureParams> |
| 557 | featureParams; /* Offset to Feature Parameters table (if one |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 558 | * has been defined for the feature), relative |
| 559 | * to the beginning of the Feature Table; = Null |
| 560 | * if not required */ |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 561 | IndexArray lookupIndex; /* Array of LookupList indices */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 562 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 563 | DEFINE_SIZE_ARRAY (4, lookupIndex); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 564 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 565 | |
| 566 | typedef RecordListOf<Feature> FeatureList; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 567 | |
| 568 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 569 | struct LookupFlag : USHORT |
| 570 | { |
Behdad Esfahbod | c6035cf | 2012-04-12 13:23:59 -0400 | [diff] [blame] | 571 | enum Flags { |
Behdad Esfahbod | 4fa77d3 | 2009-05-18 18:44:54 -0400 | [diff] [blame] | 572 | RightToLeft = 0x0001u, |
| 573 | IgnoreBaseGlyphs = 0x0002u, |
| 574 | IgnoreLigatures = 0x0004u, |
| 575 | IgnoreMarks = 0x0008u, |
Behdad Esfahbod | aa87d95 | 2009-10-29 03:00:44 -0400 | [diff] [blame] | 576 | IgnoreFlags = 0x000Eu, |
Behdad Esfahbod | d7df42d | 2009-05-26 13:04:59 -0400 | [diff] [blame] | 577 | UseMarkFilteringSet = 0x0010u, |
| 578 | Reserved = 0x00E0u, |
Behdad Esfahbod | 8f034d5 | 2009-08-18 16:41:59 -0400 | [diff] [blame] | 579 | MarkAttachmentType = 0xFF00u |
Behdad Esfahbod | 4fa77d3 | 2009-05-18 18:44:54 -0400 | [diff] [blame] | 580 | }; |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 581 | public: |
| 582 | DEFINE_SIZE_STATIC (2); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 583 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 584 | |
Behdad Esfahbod | aa7044d | 2015-11-04 16:25:57 -0800 | [diff] [blame] | 585 | } /* namespace OT */ |
| 586 | /* This has to be outside the namespace. */ |
Chun-wei Fan | 167c327 | 2015-11-09 17:17:56 +0800 | [diff] [blame] | 587 | HB_MARK_AS_FLAG_T (OT::LookupFlag::Flags); |
Behdad Esfahbod | aa7044d | 2015-11-04 16:25:57 -0800 | [diff] [blame] | 588 | namespace OT { |
| 589 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 590 | struct Lookup |
| 591 | { |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 592 | inline unsigned int get_subtable_count (void) const { return subTable.len; } |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 593 | |
Behdad Esfahbod | 70366f5 | 2015-02-18 13:09:54 +0300 | [diff] [blame] | 594 | template <typename SubTableType> |
| 595 | inline const SubTableType& get_subtable (unsigned int i) const |
| 596 | { return this+CastR<OffsetArrayOf<SubTableType> > (subTable)[i]; } |
| 597 | |
| 598 | template <typename SubTableType> |
| 599 | inline const OffsetArrayOf<SubTableType>& get_subtables (void) const |
| 600 | { return CastR<OffsetArrayOf<SubTableType> > (subTable); } |
| 601 | template <typename SubTableType> |
| 602 | inline OffsetArrayOf<SubTableType>& get_subtables (void) |
| 603 | { return CastR<OffsetArrayOf<SubTableType> > (subTable); } |
| 604 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 605 | inline unsigned int get_type (void) const { return lookupType; } |
Behdad Esfahbod | 8c69e65 | 2010-10-27 22:07:49 -0400 | [diff] [blame] | 606 | |
| 607 | /* lookup_props is a 32-bit integer where the lower 16-bit is LookupFlag and |
| 608 | * higher 16-bit is mark-filtering-set if the lookup uses one. |
| 609 | * Not to be confused with glyph_props which is very similar. */ |
| 610 | inline uint32_t get_props (void) const |
Behdad Esfahbod | d7df42d | 2009-05-26 13:04:59 -0400 | [diff] [blame] | 611 | { |
| 612 | unsigned int flag = lookupFlag; |
Behdad Esfahbod | 64d3fc8 | 2010-05-03 22:51:19 -0400 | [diff] [blame] | 613 | if (unlikely (flag & LookupFlag::UseMarkFilteringSet)) |
Behdad Esfahbod | d7df42d | 2009-05-26 13:04:59 -0400 | [diff] [blame] | 614 | { |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 615 | const USHORT &markFilteringSet = StructAfter<USHORT> (subTable); |
Behdad Esfahbod | 09c292e | 2009-05-26 19:48:16 -0400 | [diff] [blame] | 616 | flag += (markFilteringSet << 16); |
Behdad Esfahbod | d7df42d | 2009-05-26 13:04:59 -0400 | [diff] [blame] | 617 | } |
| 618 | return flag; |
| 619 | } |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 620 | |
Behdad Esfahbod | 40c5892 | 2015-02-18 13:18:46 +0300 | [diff] [blame] | 621 | template <typename SubTableType, typename context_t> |
| 622 | inline typename context_t::return_t dispatch (context_t *c) const |
| 623 | { |
| 624 | unsigned int lookup_type = get_type (); |
| 625 | TRACE_DISPATCH (this, lookup_type); |
| 626 | unsigned int count = get_subtable_count (); |
| 627 | for (unsigned int i = 0; i < count; i++) { |
| 628 | typename context_t::return_t r = get_subtable<SubTableType> (i).dispatch (c, lookup_type); |
| 629 | if (c->stop_sublookup_iteration (r)) |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 630 | return_trace (r); |
Behdad Esfahbod | 40c5892 | 2015-02-18 13:18:46 +0300 | [diff] [blame] | 631 | } |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 632 | return_trace (c->default_return_value ()); |
Behdad Esfahbod | 40c5892 | 2015-02-18 13:18:46 +0300 | [diff] [blame] | 633 | } |
| 634 | |
Behdad Esfahbod | 652d1e0 | 2012-09-04 20:00:44 -0400 | [diff] [blame] | 635 | inline bool serialize (hb_serialize_context_t *c, |
| 636 | unsigned int lookup_type, |
| 637 | uint32_t lookup_props, |
| 638 | unsigned int num_subtables) |
| 639 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 640 | TRACE_SERIALIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 641 | if (unlikely (!c->extend_min (*this))) return_trace (false); |
Behdad Esfahbod | 652d1e0 | 2012-09-04 20:00:44 -0400 | [diff] [blame] | 642 | lookupType.set (lookup_type); |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 643 | lookupFlag.set (lookup_props & 0xFFFFu); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 644 | if (unlikely (!subTable.serialize (c, num_subtables))) return_trace (false); |
Behdad Esfahbod | b3b89b6 | 2012-09-04 21:13:17 -0400 | [diff] [blame] | 645 | if (lookupFlag & LookupFlag::UseMarkFilteringSet) |
Behdad Esfahbod | 652d1e0 | 2012-09-04 20:00:44 -0400 | [diff] [blame] | 646 | { |
| 647 | USHORT &markFilteringSet = StructAfter<USHORT> (subTable); |
| 648 | markFilteringSet.set (lookup_props >> 16); |
| 649 | } |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 650 | return_trace (true); |
Behdad Esfahbod | 652d1e0 | 2012-09-04 20:00:44 -0400 | [diff] [blame] | 651 | } |
| 652 | |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 653 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 654 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 655 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 3b2c2df | 2010-04-22 16:51:42 -0400 | [diff] [blame] | 656 | /* Real sanitize of the subtables is done by GSUB/GPOS/... */ |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 657 | if (!(c->check_struct (this) && subTable.sanitize (c))) return_trace (false); |
Behdad Esfahbod | 652d1e0 | 2012-09-04 20:00:44 -0400 | [diff] [blame] | 658 | if (lookupFlag & LookupFlag::UseMarkFilteringSet) |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 659 | { |
Behdad Esfahbod | 8dddc23 | 2016-09-09 13:17:33 -0700 | [diff] [blame] | 660 | const USHORT &markFilteringSet = StructAfter<USHORT> (subTable); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 661 | if (!markFilteringSet.sanitize (c)) return_trace (false); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 662 | } |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 663 | return_trace (true); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 664 | } |
| 665 | |
Behdad Esfahbod | 70366f5 | 2015-02-18 13:09:54 +0300 | [diff] [blame] | 666 | private: |
Behdad Esfahbod | d7df42d | 2009-05-26 13:04:59 -0400 | [diff] [blame] | 667 | USHORT lookupType; /* Different enumerations for GSUB and GPOS */ |
| 668 | USHORT lookupFlag; /* Lookup qualifiers */ |
Behdad Esfahbod | 99d2817 | 2014-06-27 15:12:52 -0400 | [diff] [blame] | 669 | ArrayOf<Offset<> > |
Behdad Esfahbod | d7df42d | 2009-05-26 13:04:59 -0400 | [diff] [blame] | 670 | subTable; /* Array of SubTables */ |
Behdad Esfahbod | d3480ba | 2009-11-03 10:47:29 -0500 | [diff] [blame] | 671 | USHORT markFilteringSetX[VAR]; /* Index (base 0) into GDEF mark glyph sets |
Behdad Esfahbod | d7df42d | 2009-05-26 13:04:59 -0400 | [diff] [blame] | 672 | * structure. This field is only present if bit |
| 673 | * UseMarkFilteringSet of lookup flags is set. */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 674 | public: |
Behdad Esfahbod | 8dddc23 | 2016-09-09 13:17:33 -0700 | [diff] [blame] | 675 | DEFINE_SIZE_ARRAY2 (6, subTable, markFilteringSetX); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 676 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 677 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 678 | typedef OffsetListOf<Lookup> LookupList; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 679 | |
| 680 | |
| 681 | /* |
| 682 | * Coverage Table |
| 683 | */ |
| 684 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 685 | struct CoverageFormat1 |
| 686 | { |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 687 | friend struct Coverage; |
| 688 | |
| 689 | private: |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 690 | inline unsigned int get_coverage (hb_codepoint_t glyph_id) const |
| 691 | { |
Behdad Esfahbod | df554af | 2014-06-19 15:39:18 -0400 | [diff] [blame] | 692 | int i = glyphArray.bsearch (glyph_id); |
Behdad Esfahbod | dadede0 | 2012-07-28 18:03:20 -0400 | [diff] [blame] | 693 | ASSERT_STATIC (((unsigned int) -1) == NOT_COVERED); |
| 694 | return i; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 695 | } |
| 696 | |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 697 | inline bool serialize (hb_serialize_context_t *c, |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 698 | Supplier<GlyphID> &glyphs, |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 699 | unsigned int num_glyphs) |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 700 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 701 | TRACE_SERIALIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 702 | if (unlikely (!c->extend_min (*this))) return_trace (false); |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 703 | glyphArray.len.set (num_glyphs); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 704 | if (unlikely (!c->extend (glyphArray))) return_trace (false); |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 705 | for (unsigned int i = 0; i < num_glyphs; i++) |
Behdad Esfahbod | fabd311 | 2012-09-05 22:19:28 -0400 | [diff] [blame] | 706 | glyphArray[i] = glyphs[i]; |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 707 | glyphs.advance (num_glyphs); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 708 | return_trace (true); |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 709 | } |
| 710 | |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 711 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 712 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 713 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 714 | return_trace (glyphArray.sanitize (c)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 715 | } |
| 716 | |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 717 | inline bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) const { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 718 | return glyphs->has (glyphArray[index]); |
| 719 | } |
| 720 | |
Behdad Esfahbod | c8accf1 | 2012-08-01 21:05:57 -0400 | [diff] [blame] | 721 | template <typename set_t> |
| 722 | inline void add_coverage (set_t *glyphs) const { |
Behdad Esfahbod | 67bb9e8 | 2012-06-09 02:02:46 -0400 | [diff] [blame] | 723 | unsigned int count = glyphArray.len; |
| 724 | for (unsigned int i = 0; i < count; i++) |
| 725 | glyphs->add (glyphArray[i]); |
| 726 | } |
| 727 | |
Behdad Esfahbod | 365f27a | 2012-11-12 11:16:57 -0800 | [diff] [blame] | 728 | public: |
| 729 | /* Older compilers need this to be public. */ |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 730 | struct Iter { |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 731 | inline void init (const struct CoverageFormat1 &c_) { c = &c_; i = 0; }; |
| 732 | inline bool more (void) { return i < c->glyphArray.len; } |
| 733 | inline void next (void) { i++; } |
Behdad Esfahbod | eab418c | 2016-12-21 15:51:28 -0600 | [diff] [blame] | 734 | inline hb_codepoint_t get_glyph (void) { return c->glyphArray[i]; } |
| 735 | inline unsigned int get_coverage (void) { return i; } |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 736 | |
| 737 | private: |
| 738 | const struct CoverageFormat1 *c; |
| 739 | unsigned int i; |
| 740 | }; |
Behdad Esfahbod | 365f27a | 2012-11-12 11:16:57 -0800 | [diff] [blame] | 741 | private: |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 742 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 743 | protected: |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 744 | USHORT coverageFormat; /* Format identifier--format = 1 */ |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 745 | SortedArrayOf<GlyphID> |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 746 | glyphArray; /* Array of GlyphIDs--in numerical order */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 747 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 748 | DEFINE_SIZE_ARRAY (4, glyphArray); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 749 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 750 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 751 | struct CoverageFormat2 |
| 752 | { |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 753 | friend struct Coverage; |
| 754 | |
| 755 | private: |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 756 | inline unsigned int get_coverage (hb_codepoint_t glyph_id) const |
| 757 | { |
Behdad Esfahbod | df554af | 2014-06-19 15:39:18 -0400 | [diff] [blame] | 758 | int i = rangeRecord.bsearch (glyph_id); |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 759 | if (i != -1) { |
| 760 | const RangeRecord &range = rangeRecord[i]; |
| 761 | return (unsigned int) range.value + (glyph_id - range.start); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 762 | } |
| 763 | return NOT_COVERED; |
| 764 | } |
| 765 | |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 766 | inline bool serialize (hb_serialize_context_t *c, |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 767 | Supplier<GlyphID> &glyphs, |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 768 | unsigned int num_glyphs) |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 769 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 770 | TRACE_SERIALIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 771 | if (unlikely (!c->extend_min (*this))) return_trace (false); |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 772 | |
Behdad Esfahbod | 851b0db | 2016-04-08 23:46:55 -0700 | [diff] [blame] | 773 | if (unlikely (!num_glyphs)) |
| 774 | { |
| 775 | rangeRecord.len.set (0); |
| 776 | return_trace (true); |
| 777 | } |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 778 | |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 779 | unsigned int num_ranges = 1; |
| 780 | for (unsigned int i = 1; i < num_glyphs; i++) |
| 781 | if (glyphs[i - 1] + 1 != glyphs[i]) |
| 782 | num_ranges++; |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 783 | rangeRecord.len.set (num_ranges); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 784 | if (unlikely (!c->extend (rangeRecord))) return_trace (false); |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 785 | |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 786 | unsigned int range = 0; |
Behdad Esfahbod | fabd311 | 2012-09-05 22:19:28 -0400 | [diff] [blame] | 787 | rangeRecord[range].start = glyphs[0]; |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 788 | rangeRecord[range].value.set (0); |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 789 | for (unsigned int i = 1; i < num_glyphs; i++) |
| 790 | if (glyphs[i - 1] + 1 != glyphs[i]) { |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 791 | range++; |
Behdad Esfahbod | fabd311 | 2012-09-05 22:19:28 -0400 | [diff] [blame] | 792 | rangeRecord[range].start = glyphs[i]; |
| 793 | rangeRecord[range].value.set (i); |
| 794 | rangeRecord[range].end = glyphs[i]; |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 795 | } else { |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 796 | rangeRecord[range].end = glyphs[i]; |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 797 | } |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 798 | glyphs.advance (num_glyphs); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 799 | return_trace (true); |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 800 | } |
| 801 | |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 802 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 803 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 804 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 805 | return_trace (rangeRecord.sanitize (c)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 806 | } |
| 807 | |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 808 | inline bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) const { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 809 | unsigned int i; |
| 810 | unsigned int count = rangeRecord.len; |
| 811 | for (i = 0; i < count; i++) { |
| 812 | const RangeRecord &range = rangeRecord[i]; |
| 813 | if (range.value <= index && |
Behdad Esfahbod | 3f18236 | 2012-05-13 16:20:10 +0200 | [diff] [blame] | 814 | index < (unsigned int) range.value + (range.end - range.start) && |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 815 | range.intersects (glyphs)) |
| 816 | return true; |
| 817 | else if (index < range.value) |
| 818 | return false; |
| 819 | } |
| 820 | return false; |
| 821 | } |
| 822 | |
Behdad Esfahbod | c8accf1 | 2012-08-01 21:05:57 -0400 | [diff] [blame] | 823 | template <typename set_t> |
| 824 | inline void add_coverage (set_t *glyphs) const { |
Behdad Esfahbod | 67bb9e8 | 2012-06-09 02:02:46 -0400 | [diff] [blame] | 825 | unsigned int count = rangeRecord.len; |
| 826 | for (unsigned int i = 0; i < count; i++) |
| 827 | rangeRecord[i].add_coverage (glyphs); |
| 828 | } |
| 829 | |
Behdad Esfahbod | 365f27a | 2012-11-12 11:16:57 -0800 | [diff] [blame] | 830 | public: |
| 831 | /* Older compilers need this to be public. */ |
Behdad Esfahbod | eab418c | 2016-12-21 15:51:28 -0600 | [diff] [blame] | 832 | struct Iter |
| 833 | { |
| 834 | inline void init (const CoverageFormat2 &c_) |
| 835 | { |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 836 | c = &c_; |
| 837 | coverage = 0; |
| 838 | i = 0; |
| 839 | j = c->rangeRecord.len ? c_.rangeRecord[0].start : 0; |
| 840 | } |
| 841 | inline bool more (void) { return i < c->rangeRecord.len; } |
Behdad Esfahbod | eab418c | 2016-12-21 15:51:28 -0600 | [diff] [blame] | 842 | inline void next (void) |
| 843 | { |
| 844 | if (j >= c->rangeRecord[i].end) |
| 845 | { |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 846 | i++; |
Behdad Esfahbod | 0da132b | 2012-04-23 14:21:33 -0400 | [diff] [blame] | 847 | if (more ()) |
Behdad Esfahbod | eab418c | 2016-12-21 15:51:28 -0600 | [diff] [blame] | 848 | { |
Behdad Esfahbod | 0da132b | 2012-04-23 14:21:33 -0400 | [diff] [blame] | 849 | j = c->rangeRecord[i].start; |
Behdad Esfahbod | eab418c | 2016-12-21 15:51:28 -0600 | [diff] [blame] | 850 | coverage = c->rangeRecord[i].value; |
| 851 | } |
Behdad Esfahbod | 0da132b | 2012-04-23 14:21:33 -0400 | [diff] [blame] | 852 | return; |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 853 | } |
Behdad Esfahbod | eab418c | 2016-12-21 15:51:28 -0600 | [diff] [blame] | 854 | coverage++; |
Behdad Esfahbod | 0da132b | 2012-04-23 14:21:33 -0400 | [diff] [blame] | 855 | j++; |
| 856 | } |
Behdad Esfahbod | eab418c | 2016-12-21 15:51:28 -0600 | [diff] [blame] | 857 | inline hb_codepoint_t get_glyph (void) { return j; } |
| 858 | inline unsigned int get_coverage (void) { return coverage; } |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 859 | |
| 860 | private: |
| 861 | const struct CoverageFormat2 *c; |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 862 | unsigned int i, j, coverage; |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 863 | }; |
Behdad Esfahbod | 365f27a | 2012-11-12 11:16:57 -0800 | [diff] [blame] | 864 | private: |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 865 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 866 | protected: |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 867 | USHORT coverageFormat; /* Format identifier--format = 2 */ |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 868 | SortedArrayOf<RangeRecord> |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 869 | rangeRecord; /* Array of glyph ranges--ordered by |
| 870 | * Start GlyphID. rangeCount entries |
| 871 | * long */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 872 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 873 | DEFINE_SIZE_ARRAY (4, rangeRecord); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 874 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 875 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 876 | struct Coverage |
| 877 | { |
Behdad Esfahbod | 20b035d | 2009-08-10 19:00:36 -0400 | [diff] [blame] | 878 | inline unsigned int get_coverage (hb_codepoint_t glyph_id) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 879 | { |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 880 | switch (u.format) { |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 881 | case 1: return u.format1.get_coverage(glyph_id); |
| 882 | case 2: return u.format2.get_coverage(glyph_id); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 883 | default:return NOT_COVERED; |
| 884 | } |
| 885 | } |
| 886 | |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 887 | inline bool serialize (hb_serialize_context_t *c, |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 888 | Supplier<GlyphID> &glyphs, |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 889 | unsigned int num_glyphs) |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 890 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 891 | TRACE_SERIALIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 892 | if (unlikely (!c->extend_min (*this))) return_trace (false); |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 893 | unsigned int num_ranges = 1; |
| 894 | for (unsigned int i = 1; i < num_glyphs; i++) |
| 895 | if (glyphs[i - 1] + 1 != glyphs[i]) |
| 896 | num_ranges++; |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 897 | u.format.set (num_glyphs * 2 < num_ranges * 3 ? 1 : 2); |
| 898 | switch (u.format) { |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 899 | case 1: return_trace (u.format1.serialize (c, glyphs, num_glyphs)); |
| 900 | case 2: return_trace (u.format2.serialize (c, glyphs, num_glyphs)); |
| 901 | default:return_trace (false); |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 902 | } |
| 903 | } |
| 904 | |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 905 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 906 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 907 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 908 | if (!u.format.sanitize (c)) return_trace (false); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 909 | switch (u.format) { |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 910 | case 1: return_trace (u.format1.sanitize (c)); |
| 911 | case 2: return_trace (u.format2.sanitize (c)); |
| 912 | default:return_trace (true); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 913 | } |
| 914 | } |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 915 | |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 916 | inline bool intersects (const hb_set_t *glyphs) const { |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 917 | /* TODO speed this up */ |
| 918 | Coverage::Iter iter; |
| 919 | for (iter.init (*this); iter.more (); iter.next ()) { |
| 920 | if (glyphs->has (iter.get_glyph ())) |
| 921 | return true; |
| 922 | } |
| 923 | return false; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 924 | } |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 925 | |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 926 | inline bool intersects_coverage (const hb_set_t *glyphs, unsigned int index) const { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 927 | switch (u.format) { |
| 928 | case 1: return u.format1.intersects_coverage (glyphs, index); |
| 929 | case 2: return u.format2.intersects_coverage (glyphs, index); |
| 930 | default:return false; |
| 931 | } |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 932 | } |
| 933 | |
Behdad Esfahbod | c8accf1 | 2012-08-01 21:05:57 -0400 | [diff] [blame] | 934 | template <typename set_t> |
| 935 | inline void add_coverage (set_t *glyphs) const { |
Behdad Esfahbod | 67bb9e8 | 2012-06-09 02:02:46 -0400 | [diff] [blame] | 936 | switch (u.format) { |
| 937 | case 1: u.format1.add_coverage (glyphs); break; |
| 938 | case 2: u.format2.add_coverage (glyphs); break; |
| 939 | default: break; |
| 940 | } |
| 941 | } |
| 942 | |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 943 | struct Iter { |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 944 | Iter (void) : format (0) {}; |
| 945 | inline void init (const Coverage &c_) { |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 946 | format = c_.u.format; |
| 947 | switch (format) { |
Behdad Esfahbod | 48382e2 | 2013-07-30 18:25:39 -0400 | [diff] [blame] | 948 | case 1: u.format1.init (c_.u.format1); return; |
| 949 | case 2: u.format2.init (c_.u.format2); return; |
| 950 | default: return; |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 951 | } |
| 952 | } |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 953 | inline bool more (void) { |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 954 | switch (format) { |
| 955 | case 1: return u.format1.more (); |
| 956 | case 2: return u.format2.more (); |
Behdad Esfahbod | 48382e2 | 2013-07-30 18:25:39 -0400 | [diff] [blame] | 957 | default:return false; |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 958 | } |
| 959 | } |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 960 | inline void next (void) { |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 961 | switch (format) { |
Behdad Esfahbod | 0da132b | 2012-04-23 14:21:33 -0400 | [diff] [blame] | 962 | case 1: u.format1.next (); break; |
| 963 | case 2: u.format2.next (); break; |
| 964 | default: break; |
| 965 | } |
| 966 | } |
Behdad Esfahbod | eab418c | 2016-12-21 15:51:28 -0600 | [diff] [blame] | 967 | inline hb_codepoint_t get_glyph (void) { |
Behdad Esfahbod | 0da132b | 2012-04-23 14:21:33 -0400 | [diff] [blame] | 968 | switch (format) { |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 969 | case 1: return u.format1.get_glyph (); |
| 970 | case 2: return u.format2.get_glyph (); |
Behdad Esfahbod | 48382e2 | 2013-07-30 18:25:39 -0400 | [diff] [blame] | 971 | default:return 0; |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 972 | } |
| 973 | } |
Behdad Esfahbod | eab418c | 2016-12-21 15:51:28 -0600 | [diff] [blame] | 974 | inline unsigned int get_coverage (void) { |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 975 | switch (format) { |
| 976 | case 1: return u.format1.get_coverage (); |
| 977 | case 2: return u.format2.get_coverage (); |
Behdad Esfahbod | 48382e2 | 2013-07-30 18:25:39 -0400 | [diff] [blame] | 978 | default:return -1; |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 979 | } |
| 980 | } |
| 981 | |
| 982 | private: |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 983 | unsigned int format; |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 984 | union { |
| 985 | CoverageFormat1::Iter format1; |
| 986 | CoverageFormat2::Iter format2; |
| 987 | } u; |
| 988 | }; |
| 989 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 990 | protected: |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 991 | union { |
| 992 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 993 | CoverageFormat1 format1; |
| 994 | CoverageFormat2 format2; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 995 | } u; |
Behdad Esfahbod | ed07422 | 2010-05-10 18:08:46 -0400 | [diff] [blame] | 996 | public: |
Behdad Esfahbod | 596e471 | 2010-05-10 18:47:48 -0400 | [diff] [blame] | 997 | DEFINE_SIZE_UNION (2, format); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 998 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 999 | |
| 1000 | |
| 1001 | /* |
| 1002 | * Class Definition Table |
| 1003 | */ |
| 1004 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1005 | struct ClassDefFormat1 |
| 1006 | { |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1007 | friend struct ClassDef; |
| 1008 | |
| 1009 | private: |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 1010 | inline unsigned int get_class (hb_codepoint_t glyph_id) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1011 | { |
Behdad Esfahbod | ef79bdf | 2015-02-21 16:49:15 +0300 | [diff] [blame] | 1012 | unsigned int i = (unsigned int) (glyph_id - startGlyph); |
| 1013 | if (unlikely (i < classValue.len)) |
| 1014 | return classValue[i]; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1015 | return 0; |
| 1016 | } |
| 1017 | |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 1018 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1019 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1020 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1021 | return_trace (c->check_struct (this) && classValue.sanitize (c)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1022 | } |
| 1023 | |
Behdad Esfahbod | 89ca8ee | 2012-11-16 13:53:40 -0800 | [diff] [blame] | 1024 | template <typename set_t> |
| 1025 | inline void add_class (set_t *glyphs, unsigned int klass) const { |
| 1026 | unsigned int count = classValue.len; |
| 1027 | for (unsigned int i = 0; i < count; i++) |
| 1028 | if (classValue[i] == klass) |
| 1029 | glyphs->add (startGlyph + i); |
| 1030 | } |
| 1031 | |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 1032 | inline bool intersects_class (const hb_set_t *glyphs, unsigned int klass) const { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1033 | unsigned int count = classValue.len; |
Behdad Esfahbod | 6256784 | 2013-08-05 22:44:18 -0400 | [diff] [blame] | 1034 | if (klass == 0) |
| 1035 | { |
| 1036 | /* Match if there's any glyph that is not listed! */ |
| 1037 | hb_codepoint_t g = -1; |
| 1038 | if (!hb_set_next (glyphs, &g)) |
| 1039 | return false; |
| 1040 | if (g < startGlyph) |
| 1041 | return true; |
| 1042 | g = startGlyph + count - 1; |
| 1043 | if (hb_set_next (glyphs, &g)) |
| 1044 | return true; |
| 1045 | /* Fall through. */ |
| 1046 | } |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1047 | for (unsigned int i = 0; i < count; i++) |
| 1048 | if (classValue[i] == klass && glyphs->has (startGlyph + i)) |
| 1049 | return true; |
| 1050 | return false; |
| 1051 | } |
| 1052 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1053 | protected: |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1054 | USHORT classFormat; /* Format identifier--format = 1 */ |
| 1055 | GlyphID startGlyph; /* First GlyphID of the classValueArray */ |
| 1056 | ArrayOf<USHORT> |
| 1057 | classValue; /* Array of Class Values--one per GlyphID */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1058 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 1059 | DEFINE_SIZE_ARRAY (6, classValue); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1060 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1061 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1062 | struct ClassDefFormat2 |
| 1063 | { |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1064 | friend struct ClassDef; |
| 1065 | |
| 1066 | private: |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 1067 | inline unsigned int get_class (hb_codepoint_t glyph_id) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1068 | { |
Behdad Esfahbod | df554af | 2014-06-19 15:39:18 -0400 | [diff] [blame] | 1069 | int i = rangeRecord.bsearch (glyph_id); |
Behdad Esfahbod | 8e3d4ba | 2015-02-21 12:31:59 +0300 | [diff] [blame] | 1070 | if (unlikely (i != -1)) |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 1071 | return rangeRecord[i].value; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1072 | return 0; |
| 1073 | } |
| 1074 | |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 1075 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1076 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1077 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1078 | return_trace (rangeRecord.sanitize (c)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1079 | } |
| 1080 | |
Behdad Esfahbod | 89ca8ee | 2012-11-16 13:53:40 -0800 | [diff] [blame] | 1081 | template <typename set_t> |
| 1082 | inline void add_class (set_t *glyphs, unsigned int klass) const { |
| 1083 | unsigned int count = rangeRecord.len; |
| 1084 | for (unsigned int i = 0; i < count; i++) |
| 1085 | if (rangeRecord[i].value == klass) |
| 1086 | rangeRecord[i].add_coverage (glyphs); |
| 1087 | } |
| 1088 | |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 1089 | inline bool intersects_class (const hb_set_t *glyphs, unsigned int klass) const { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1090 | unsigned int count = rangeRecord.len; |
Behdad Esfahbod | 6256784 | 2013-08-05 22:44:18 -0400 | [diff] [blame] | 1091 | if (klass == 0) |
| 1092 | { |
| 1093 | /* Match if there's any glyph that is not listed! */ |
Behdad Esfahbod | 515a0ac | 2013-08-09 09:40:59 -0400 | [diff] [blame] | 1094 | hb_codepoint_t g = (hb_codepoint_t) -1; |
Behdad Esfahbod | 6256784 | 2013-08-05 22:44:18 -0400 | [diff] [blame] | 1095 | for (unsigned int i = 0; i < count; i++) |
| 1096 | { |
| 1097 | if (!hb_set_next (glyphs, &g)) |
| 1098 | break; |
| 1099 | if (g < rangeRecord[i].start) |
| 1100 | return true; |
| 1101 | g = rangeRecord[i].end; |
| 1102 | } |
Behdad Esfahbod | 515a0ac | 2013-08-09 09:40:59 -0400 | [diff] [blame] | 1103 | if (g != (hb_codepoint_t) -1 && hb_set_next (glyphs, &g)) |
Behdad Esfahbod | 6256784 | 2013-08-05 22:44:18 -0400 | [diff] [blame] | 1104 | return true; |
| 1105 | /* Fall through. */ |
| 1106 | } |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1107 | for (unsigned int i = 0; i < count; i++) |
| 1108 | if (rangeRecord[i].value == klass && rangeRecord[i].intersects (glyphs)) |
| 1109 | return true; |
| 1110 | return false; |
| 1111 | } |
| 1112 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1113 | protected: |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1114 | USHORT classFormat; /* Format identifier--format = 2 */ |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 1115 | SortedArrayOf<RangeRecord> |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1116 | rangeRecord; /* Array of glyph ranges--ordered by |
| 1117 | * Start GlyphID */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1118 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 1119 | DEFINE_SIZE_ARRAY (4, rangeRecord); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1120 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1121 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1122 | struct ClassDef |
| 1123 | { |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 1124 | inline unsigned int get_class (hb_codepoint_t glyph_id) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1125 | { |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1126 | switch (u.format) { |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 1127 | case 1: return u.format1.get_class(glyph_id); |
| 1128 | case 2: return u.format2.get_class(glyph_id); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1129 | default:return 0; |
| 1130 | } |
| 1131 | } |
| 1132 | |
Behdad Esfahbod | de2118e | 2015-02-17 17:27:44 +0300 | [diff] [blame] | 1133 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1134 | { |
Behdad Esfahbod | be218c6 | 2012-11-23 15:32:14 -0500 | [diff] [blame] | 1135 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1136 | if (!u.format.sanitize (c)) return_trace (false); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1137 | switch (u.format) { |
Behdad Esfahbod | b471590 | 2015-09-29 14:57:02 +0100 | [diff] [blame] | 1138 | case 1: return_trace (u.format1.sanitize (c)); |
| 1139 | case 2: return_trace (u.format2.sanitize (c)); |
| 1140 | default:return_trace (true); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1141 | } |
| 1142 | } |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 1143 | |
Behdad Esfahbod | 89ca8ee | 2012-11-16 13:53:40 -0800 | [diff] [blame] | 1144 | inline void add_class (hb_set_t *glyphs, unsigned int klass) const { |
| 1145 | switch (u.format) { |
| 1146 | case 1: u.format1.add_class (glyphs, klass); return; |
| 1147 | case 2: u.format2.add_class (glyphs, klass); return; |
| 1148 | default:return; |
| 1149 | } |
| 1150 | } |
| 1151 | |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 1152 | inline bool intersects_class (const hb_set_t *glyphs, unsigned int klass) const { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 1153 | switch (u.format) { |
| 1154 | case 1: return u.format1.intersects_class (glyphs, klass); |
| 1155 | case 2: return u.format2.intersects_class (glyphs, klass); |
| 1156 | default:return false; |
| 1157 | } |
| 1158 | } |
| 1159 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1160 | protected: |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1161 | union { |
| 1162 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 1163 | ClassDefFormat1 format1; |
| 1164 | ClassDefFormat2 format2; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1165 | } u; |
Behdad Esfahbod | ed07422 | 2010-05-10 18:08:46 -0400 | [diff] [blame] | 1166 | public: |
Behdad Esfahbod | 596e471 | 2010-05-10 18:47:48 -0400 | [diff] [blame] | 1167 | DEFINE_SIZE_UNION (2, format); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1168 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1169 | |
| 1170 | |
| 1171 | /* |
Behdad Esfahbod | dc9f229 | 2016-09-09 15:40:15 -0700 | [diff] [blame] | 1172 | * Item Variation Store |
| 1173 | */ |
| 1174 | |
| 1175 | struct VarRegionAxis |
| 1176 | { |
| 1177 | inline float evaluate (int coord) const |
| 1178 | { |
| 1179 | int start = startCoord, peak = peakCoord, end = endCoord; |
| 1180 | |
| 1181 | /* TODO Move these to sanitize(). */ |
| 1182 | if (unlikely (start > peak || peak > end)) |
| 1183 | return 1.; |
| 1184 | if (unlikely (start < 0 && end > 0 && peak != 0)) |
| 1185 | return 1.; |
| 1186 | |
| 1187 | if (peak == 0 || coord == peak) |
| 1188 | return 1.; |
| 1189 | |
| 1190 | if (coord <= start || end <= coord) |
| 1191 | return 0.; |
| 1192 | |
| 1193 | /* Interpolate */ |
| 1194 | if (coord < peak) |
| 1195 | return float (coord - start) / (peak - start); |
| 1196 | else |
| 1197 | return float (end - coord) / (end - peak); |
| 1198 | } |
| 1199 | |
| 1200 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1201 | { |
| 1202 | TRACE_SANITIZE (this); |
| 1203 | return_trace (c->check_struct (this)); |
| 1204 | /* TODO Handle invalid start/peak/end configs, so we don't |
| 1205 | * have to do that at runtime. */ |
| 1206 | } |
| 1207 | |
| 1208 | public: |
| 1209 | F2DOT14 startCoord; |
| 1210 | F2DOT14 peakCoord; |
| 1211 | F2DOT14 endCoord; |
| 1212 | public: |
| 1213 | DEFINE_SIZE_STATIC (6); |
| 1214 | }; |
| 1215 | |
| 1216 | struct VarRegionList |
| 1217 | { |
| 1218 | inline float evaluate (unsigned int region_index, |
| 1219 | int *coords, unsigned int coord_len) const |
| 1220 | { |
| 1221 | if (unlikely (region_index >= regionCount)) |
| 1222 | return 0.; |
| 1223 | |
| 1224 | const VarRegionAxis *axes = axesZ + (region_index * axisCount); |
| 1225 | |
| 1226 | float v = 1.; |
| 1227 | unsigned int count = MIN (coord_len, (unsigned int) axisCount); |
| 1228 | for (unsigned int i = 0; i < count; i++) |
| 1229 | { |
| 1230 | float factor = axes[i].evaluate (coords[i]); |
| 1231 | if (factor == 0.) |
| 1232 | return 0.; |
| 1233 | v *= factor; |
| 1234 | } |
| 1235 | return v; |
| 1236 | } |
| 1237 | |
| 1238 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1239 | { |
| 1240 | TRACE_SANITIZE (this); |
| 1241 | return_trace (c->check_struct (this) && |
| 1242 | c->check_array (axesZ, axesZ[0].static_size, |
| 1243 | (unsigned int) axisCount * (unsigned int) regionCount)); |
| 1244 | } |
| 1245 | |
| 1246 | protected: |
| 1247 | USHORT axisCount; |
| 1248 | USHORT regionCount; |
| 1249 | VarRegionAxis axesZ[VAR]; |
| 1250 | public: |
| 1251 | DEFINE_SIZE_ARRAY (4, axesZ); |
| 1252 | }; |
| 1253 | |
| 1254 | struct VarData |
| 1255 | { |
| 1256 | inline unsigned int get_row_size (void) const |
| 1257 | { return shortCount + regionIndices.len; } |
| 1258 | |
| 1259 | inline unsigned int get_size (void) const |
| 1260 | { return itemCount * get_row_size (); } |
| 1261 | |
| 1262 | inline float get_delta (unsigned int inner, |
| 1263 | int *coords, unsigned int coord_count, |
| 1264 | const VarRegionList ®ions) const |
| 1265 | { |
| 1266 | if (unlikely (inner >= itemCount)) |
| 1267 | return 0.; |
| 1268 | |
| 1269 | unsigned int count = regionIndices.len; |
| 1270 | unsigned int scount = shortCount; |
| 1271 | |
| 1272 | const BYTE *bytes = &StructAfter<BYTE> (regionIndices); |
| 1273 | const BYTE *row = bytes + inner * (scount + count); |
| 1274 | |
Behdad Esfahbod | dc9f229 | 2016-09-09 15:40:15 -0700 | [diff] [blame] | 1275 | float delta = 0.; |
| 1276 | unsigned int i = 0; |
| 1277 | |
| 1278 | const SHORT *scursor = reinterpret_cast<const SHORT *> (row); |
| 1279 | for (; i < scount; i++) |
| 1280 | { |
| 1281 | float scalar = regions.evaluate (regionIndices.array[i], coords, coord_count); |
| 1282 | delta += scalar * *scursor++; |
| 1283 | } |
| 1284 | const INT8 *bcursor = reinterpret_cast<const INT8 *> (scursor); |
| 1285 | for (; i < count; i++) |
| 1286 | { |
| 1287 | float scalar = regions.evaluate (regionIndices.array[i], coords, coord_count); |
| 1288 | delta += scalar * *bcursor++; |
| 1289 | } |
| 1290 | |
| 1291 | return delta; |
| 1292 | } |
| 1293 | |
| 1294 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1295 | { |
| 1296 | TRACE_SANITIZE (this); |
| 1297 | return_trace (c->check_struct (this) && |
| 1298 | regionIndices.sanitize(c) && |
| 1299 | shortCount <= regionIndices.len && |
| 1300 | c->check_array (&StructAfter<BYTE> (regionIndices), |
| 1301 | get_row_size (), itemCount)); |
| 1302 | } |
| 1303 | |
| 1304 | protected: |
| 1305 | USHORT itemCount; |
| 1306 | USHORT shortCount; |
| 1307 | ArrayOf<USHORT> regionIndices; |
| 1308 | BYTE bytesX[VAR]; |
| 1309 | public: |
| 1310 | DEFINE_SIZE_ARRAY2 (6, regionIndices, bytesX); |
| 1311 | }; |
| 1312 | |
Behdad Esfahbod | cf3de4d | 2016-09-10 00:22:24 -0700 | [diff] [blame] | 1313 | struct VariationStore |
Behdad Esfahbod | dc9f229 | 2016-09-09 15:40:15 -0700 | [diff] [blame] | 1314 | { |
| 1315 | inline float get_delta (unsigned int outer, unsigned int inner, |
| 1316 | int *coords, unsigned int coord_count) const |
| 1317 | { |
| 1318 | if (unlikely (outer >= dataSets.len)) |
| 1319 | return 0.; |
| 1320 | |
| 1321 | return (this+dataSets[outer]).get_delta (inner, |
| 1322 | coords, coord_count, |
| 1323 | this+regions); |
| 1324 | } |
| 1325 | |
Behdad Esfahbod | a4fca9f | 2017-01-23 11:56:08 -0800 | [diff] [blame] | 1326 | inline float get_delta (unsigned int index, |
| 1327 | int *coords, unsigned int coord_count) const |
| 1328 | { |
| 1329 | unsigned int outer = index >> 16; |
| 1330 | unsigned int inner = index & 0xFFFF; |
| 1331 | return get_delta (outer, inner, coords, coord_count); |
| 1332 | } |
| 1333 | |
Behdad Esfahbod | dc9f229 | 2016-09-09 15:40:15 -0700 | [diff] [blame] | 1334 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1335 | { |
| 1336 | TRACE_SANITIZE (this); |
| 1337 | return_trace (c->check_struct (this) && |
| 1338 | format == 1 && |
| 1339 | regions.sanitize (c, this) && |
| 1340 | dataSets.sanitize (c, this)); |
| 1341 | } |
| 1342 | |
| 1343 | protected: |
| 1344 | USHORT format; |
Behdad Esfahbod | 5e156fa | 2017-01-22 20:28:56 -0800 | [diff] [blame] | 1345 | LOffsetTo<VarRegionList> regions; |
Behdad Esfahbod | dc9f229 | 2016-09-09 15:40:15 -0700 | [diff] [blame] | 1346 | OffsetArrayOf<VarData, ULONG> dataSets; |
| 1347 | public: |
| 1348 | DEFINE_SIZE_ARRAY (8, dataSets); |
| 1349 | }; |
| 1350 | |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 1351 | /* |
| 1352 | * Feature Variations |
| 1353 | */ |
| 1354 | |
| 1355 | struct ConditionFormat1 |
| 1356 | { |
| 1357 | friend struct Condition; |
| 1358 | |
| 1359 | private: |
Behdad Esfahbod | 30c42b6 | 2016-09-10 03:32:39 -0700 | [diff] [blame] | 1360 | inline bool evaluate (const int *coords, unsigned int coord_len) const |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 1361 | { |
| 1362 | int coord = axisIndex < coord_len ? coords[axisIndex] : 0; |
| 1363 | return filterRangeMinValue <= coord && coord <= filterRangeMaxValue; |
| 1364 | } |
| 1365 | |
| 1366 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1367 | { |
| 1368 | TRACE_SANITIZE (this); |
| 1369 | return_trace (c->check_struct (this)); |
| 1370 | } |
| 1371 | |
| 1372 | protected: |
| 1373 | USHORT format; /* Format identifier--format = 1 */ |
| 1374 | USHORT axisIndex; |
| 1375 | F2DOT14 filterRangeMinValue; |
| 1376 | F2DOT14 filterRangeMaxValue; |
| 1377 | public: |
| 1378 | DEFINE_SIZE_STATIC (8); |
| 1379 | }; |
| 1380 | |
| 1381 | struct Condition |
| 1382 | { |
Behdad Esfahbod | 30c42b6 | 2016-09-10 03:32:39 -0700 | [diff] [blame] | 1383 | inline bool evaluate (const int *coords, unsigned int coord_len) const |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 1384 | { |
| 1385 | switch (u.format) { |
| 1386 | case 1: return u.format1.evaluate (coords, coord_len); |
| 1387 | default:return false; |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1392 | { |
| 1393 | TRACE_SANITIZE (this); |
| 1394 | if (!u.format.sanitize (c)) return_trace (false); |
| 1395 | switch (u.format) { |
| 1396 | case 1: return_trace (u.format1.sanitize (c)); |
| 1397 | default:return_trace (true); |
| 1398 | } |
| 1399 | } |
| 1400 | |
| 1401 | protected: |
| 1402 | union { |
| 1403 | USHORT format; /* Format identifier */ |
| 1404 | ConditionFormat1 format1; |
| 1405 | } u; |
| 1406 | public: |
| 1407 | DEFINE_SIZE_UNION (2, format); |
| 1408 | }; |
| 1409 | |
| 1410 | struct ConditionSet |
| 1411 | { |
Behdad Esfahbod | 30c42b6 | 2016-09-10 03:32:39 -0700 | [diff] [blame] | 1412 | inline bool evaluate (const int *coords, unsigned int coord_len) const |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 1413 | { |
| 1414 | unsigned int count = conditions.len; |
| 1415 | for (unsigned int i = 0; i < count; i++) |
| 1416 | if (!(this+conditions.array[i]).evaluate (coords, coord_len)) |
| 1417 | return false; |
| 1418 | return true; |
| 1419 | } |
| 1420 | |
| 1421 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1422 | { |
| 1423 | TRACE_SANITIZE (this); |
| 1424 | return_trace (conditions.sanitize (c, this)); |
| 1425 | } |
| 1426 | |
| 1427 | protected: |
| 1428 | OffsetArrayOf<Condition, ULONG> conditions; |
| 1429 | public: |
| 1430 | DEFINE_SIZE_ARRAY (2, conditions); |
| 1431 | }; |
| 1432 | |
| 1433 | struct FeatureTableSubstitutionRecord |
| 1434 | { |
Behdad Esfahbod | 4ebbeb7 | 2016-09-10 04:52:34 -0700 | [diff] [blame] | 1435 | friend struct FeatureTableSubstitution; |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 1436 | |
Behdad Esfahbod | 4ebbeb7 | 2016-09-10 04:52:34 -0700 | [diff] [blame] | 1437 | inline bool sanitize (hb_sanitize_context_t *c, const void *base) const |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 1438 | { |
| 1439 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 4ebbeb7 | 2016-09-10 04:52:34 -0700 | [diff] [blame] | 1440 | return_trace (c->check_struct (this) && feature.sanitize (c, base)); |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | protected: |
Behdad Esfahbod | 5e156fa | 2017-01-22 20:28:56 -0800 | [diff] [blame] | 1444 | USHORT featureIndex; |
| 1445 | LOffsetTo<Feature> feature; |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 1446 | public: |
| 1447 | DEFINE_SIZE_STATIC (6); |
| 1448 | }; |
| 1449 | |
| 1450 | struct FeatureTableSubstitution |
| 1451 | { |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 1452 | inline const Feature *find_substitute (unsigned int feature_index) const |
| 1453 | { |
| 1454 | unsigned int count = substitutions.len; |
| 1455 | for (unsigned int i = 0; i < count; i++) |
| 1456 | { |
Behdad Esfahbod | 4ebbeb7 | 2016-09-10 04:52:34 -0700 | [diff] [blame] | 1457 | const FeatureTableSubstitutionRecord &record = substitutions.array[i]; |
| 1458 | if (record.featureIndex == feature_index) |
| 1459 | return &(this+record.feature); |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 1460 | } |
| 1461 | return NULL; |
| 1462 | } |
| 1463 | |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 1464 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1465 | { |
| 1466 | TRACE_SANITIZE (this); |
| 1467 | return_trace (version.sanitize (c) && |
| 1468 | likely (version.major == 1) && |
| 1469 | substitutions.sanitize (c, this)); |
| 1470 | } |
| 1471 | |
| 1472 | protected: |
| 1473 | FixedVersion<> version; /* Version--0x00010000u */ |
Behdad Esfahbod | 4ebbeb7 | 2016-09-10 04:52:34 -0700 | [diff] [blame] | 1474 | ArrayOf<FeatureTableSubstitutionRecord> |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 1475 | substitutions; |
| 1476 | public: |
| 1477 | DEFINE_SIZE_ARRAY (6, substitutions); |
| 1478 | }; |
| 1479 | |
| 1480 | struct FeatureVariationRecord |
| 1481 | { |
| 1482 | friend struct FeatureVariations; |
| 1483 | |
| 1484 | inline bool sanitize (hb_sanitize_context_t *c, const void *base) const |
| 1485 | { |
| 1486 | TRACE_SANITIZE (this); |
| 1487 | return_trace (conditions.sanitize (c, base) && |
| 1488 | substitutions.sanitize (c, base)); |
| 1489 | } |
| 1490 | |
| 1491 | protected: |
Behdad Esfahbod | 5e156fa | 2017-01-22 20:28:56 -0800 | [diff] [blame] | 1492 | LOffsetTo<ConditionSet> |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 1493 | conditions; |
Behdad Esfahbod | 5e156fa | 2017-01-22 20:28:56 -0800 | [diff] [blame] | 1494 | LOffsetTo<FeatureTableSubstitution> |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 1495 | substitutions; |
| 1496 | public: |
| 1497 | DEFINE_SIZE_STATIC (8); |
| 1498 | }; |
| 1499 | |
| 1500 | struct FeatureVariations |
| 1501 | { |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 1502 | static const unsigned int NOT_FOUND_INDEX = 0xFFFFFFFFu; |
| 1503 | |
Behdad Esfahbod | 30c42b6 | 2016-09-10 03:32:39 -0700 | [diff] [blame] | 1504 | inline bool find_index (const int *coords, unsigned int coord_len, |
| 1505 | unsigned int *index) const |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 1506 | { |
| 1507 | unsigned int count = varRecords.len; |
| 1508 | for (unsigned int i = 0; i < count; i++) |
| 1509 | { |
| 1510 | const FeatureVariationRecord &record = varRecords.array[i]; |
| 1511 | if ((this+record.conditions).evaluate (coords, coord_len)) |
Behdad Esfahbod | 30c42b6 | 2016-09-10 03:32:39 -0700 | [diff] [blame] | 1512 | { |
| 1513 | *index = i; |
| 1514 | return true; |
| 1515 | } |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 1516 | } |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 1517 | *index = NOT_FOUND_INDEX; |
Behdad Esfahbod | 30c42b6 | 2016-09-10 03:32:39 -0700 | [diff] [blame] | 1518 | return false; |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
Behdad Esfahbod | ec87ba9 | 2016-09-10 03:53:11 -0700 | [diff] [blame] | 1521 | inline const Feature *find_substitute (unsigned int variations_index, |
| 1522 | unsigned int feature_index) const |
| 1523 | { |
| 1524 | const FeatureVariationRecord &record = varRecords[variations_index]; |
| 1525 | return (this+record.substitutions).find_substitute (feature_index); |
| 1526 | } |
| 1527 | |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 1528 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1529 | { |
| 1530 | TRACE_SANITIZE (this); |
| 1531 | return_trace (version.sanitize (c) && |
| 1532 | likely (version.major == 1) && |
| 1533 | varRecords.sanitize (c, this)); |
| 1534 | } |
| 1535 | |
| 1536 | protected: |
| 1537 | FixedVersion<> version; /* Version--0x00010000u */ |
Behdad Esfahbod | b732c53 | 2017-01-22 20:31:53 -0800 | [diff] [blame] | 1538 | LArrayOf<FeatureVariationRecord> |
Behdad Esfahbod | 59055b5 | 2016-09-10 01:24:28 -0700 | [diff] [blame] | 1539 | varRecords; |
| 1540 | public: |
| 1541 | DEFINE_SIZE_ARRAY (8, varRecords); |
| 1542 | }; |
| 1543 | |
Behdad Esfahbod | dc9f229 | 2016-09-09 15:40:15 -0700 | [diff] [blame] | 1544 | |
| 1545 | /* |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1546 | * Device Tables |
| 1547 | */ |
| 1548 | |
Behdad Esfahbod | 4c535a8 | 2016-03-02 12:21:36 +0900 | [diff] [blame] | 1549 | struct HintingDevice |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1550 | { |
Behdad Esfahbod | 4c535a8 | 2016-03-02 12:21:36 +0900 | [diff] [blame] | 1551 | friend struct Device; |
| 1552 | |
| 1553 | private: |
Behdad Esfahbod | b634beb | 2010-05-20 17:44:52 +0100 | [diff] [blame] | 1554 | |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 1555 | inline hb_position_t get_x_delta (hb_font_t *font) const |
| 1556 | { return get_delta (font->x_ppem, font->x_scale); } |
Behdad Esfahbod | b634beb | 2010-05-20 17:44:52 +0100 | [diff] [blame] | 1557 | |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 1558 | inline hb_position_t get_y_delta (hb_font_t *font) const |
| 1559 | { return get_delta (font->y_ppem, font->y_scale); } |
Behdad Esfahbod | b634beb | 2010-05-20 17:44:52 +0100 | [diff] [blame] | 1560 | |
Behdad Esfahbod | d163dc1 | 2016-01-12 13:05:01 +0000 | [diff] [blame] | 1561 | inline unsigned int get_size (void) const |
| 1562 | { |
| 1563 | unsigned int f = deltaFormat; |
| 1564 | if (unlikely (f < 1 || f > 3 || startSize > endSize)) return 3 * USHORT::static_size; |
| 1565 | return USHORT::static_size * (4 + ((endSize - startSize) >> (4 - f))); |
| 1566 | } |
| 1567 | |
| 1568 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1569 | { |
| 1570 | TRACE_SANITIZE (this); |
| 1571 | return_trace (c->check_struct (this) && c->check_range (this, this->get_size ())); |
| 1572 | } |
| 1573 | |
| 1574 | private: |
| 1575 | |
Behdad Esfahbod | da97541 | 2011-04-21 15:08:01 -0400 | [diff] [blame] | 1576 | inline int get_delta (unsigned int ppem, int scale) const |
Behdad Esfahbod | 5bd1e95 | 2010-09-22 16:46:18 -0400 | [diff] [blame] | 1577 | { |
| 1578 | if (!ppem) return 0; |
| 1579 | |
| 1580 | int pixels = get_delta_pixels (ppem); |
| 1581 | |
| 1582 | if (!pixels) return 0; |
| 1583 | |
Behdad Esfahbod | 83408cf | 2013-11-06 14:46:04 -0500 | [diff] [blame] | 1584 | return (int) (pixels * (int64_t) scale / ppem); |
Behdad Esfahbod | 5bd1e95 | 2010-09-22 16:46:18 -0400 | [diff] [blame] | 1585 | } |
Behdad Esfahbod | 5bd1e95 | 2010-09-22 16:46:18 -0400 | [diff] [blame] | 1586 | inline int get_delta_pixels (unsigned int ppem_size) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 1587 | { |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 1588 | unsigned int f = deltaFormat; |
Behdad Esfahbod | 64d3fc8 | 2010-05-03 22:51:19 -0400 | [diff] [blame] | 1589 | if (unlikely (f < 1 || f > 3)) |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 1590 | return 0; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1591 | |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 1592 | if (ppem_size < startSize || ppem_size > endSize) |
| 1593 | return 0; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1594 | |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 1595 | unsigned int s = ppem_size - startSize; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1596 | |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 1597 | unsigned int byte = deltaValue[s >> (4 - f)]; |
Behdad Esfahbod | 09c292e | 2009-05-26 19:48:16 -0400 | [diff] [blame] | 1598 | unsigned int bits = (byte >> (16 - (((s & ((1 << (4 - f)) - 1)) + 1) << f))); |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 1599 | unsigned int mask = (0xFFFFu >> (16 - (1 << f))); |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 1600 | |
| 1601 | int delta = bits & mask; |
| 1602 | |
Behdad Esfahbod | 15164d9 | 2009-08-04 13:57:41 -0400 | [diff] [blame] | 1603 | if ((unsigned int) delta >= ((mask + 1) >> 1)) |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 1604 | delta -= mask + 1; |
| 1605 | |
| 1606 | return delta; |
| 1607 | } |
| 1608 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1609 | protected: |
Behdad Esfahbod | 0795b78 | 2010-04-22 00:23:14 -0400 | [diff] [blame] | 1610 | USHORT startSize; /* Smallest size to correct--in ppem */ |
| 1611 | USHORT endSize; /* Largest size to correct--in ppem */ |
Behdad Esfahbod | caff7db | 2010-04-26 10:07:35 -0400 | [diff] [blame] | 1612 | USHORT deltaFormat; /* Format of DeltaValue array data: 1, 2, or 3 |
| 1613 | * 1 Signed 2-bit value, 8 values per uint16 |
| 1614 | * 2 Signed 4-bit value, 4 values per uint16 |
| 1615 | * 3 Signed 8-bit value, 2 values per uint16 |
| 1616 | */ |
Behdad Esfahbod | d3480ba | 2009-11-03 10:47:29 -0500 | [diff] [blame] | 1617 | USHORT deltaValue[VAR]; /* Array of compressed data */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 1618 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 1619 | DEFINE_SIZE_ARRAY (6, deltaValue); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1620 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 1621 | |
Behdad Esfahbod | 6d9d3c5 | 2016-03-01 19:12:08 +0900 | [diff] [blame] | 1622 | struct VariationDevice |
| 1623 | { |
Behdad Esfahbod | 4c535a8 | 2016-03-02 12:21:36 +0900 | [diff] [blame] | 1624 | friend struct Device; |
| 1625 | |
| 1626 | private: |
Behdad Esfahbod | 6d9d3c5 | 2016-03-01 19:12:08 +0900 | [diff] [blame] | 1627 | |
Behdad Esfahbod | cf3de4d | 2016-09-10 00:22:24 -0700 | [diff] [blame] | 1628 | inline hb_position_t get_x_delta (hb_font_t *font, const VariationStore &store) const |
Behdad Esfahbod | 26648ce | 2016-09-10 02:11:05 -0700 | [diff] [blame] | 1629 | { return font->em_scalef_x (get_delta (font, store)); } |
Behdad Esfahbod | 6d9d3c5 | 2016-03-01 19:12:08 +0900 | [diff] [blame] | 1630 | |
Behdad Esfahbod | cf3de4d | 2016-09-10 00:22:24 -0700 | [diff] [blame] | 1631 | inline hb_position_t get_y_delta (hb_font_t *font, const VariationStore &store) const |
Behdad Esfahbod | 26648ce | 2016-09-10 02:11:05 -0700 | [diff] [blame] | 1632 | { return font->em_scalef_y (get_delta (font, store)); } |
Behdad Esfahbod | 6d9d3c5 | 2016-03-01 19:12:08 +0900 | [diff] [blame] | 1633 | |
| 1634 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1635 | { |
| 1636 | TRACE_SANITIZE (this); |
Behdad Esfahbod | dc9f229 | 2016-09-09 15:40:15 -0700 | [diff] [blame] | 1637 | return_trace (c->check_struct (this)); |
Behdad Esfahbod | 6d9d3c5 | 2016-03-01 19:12:08 +0900 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | private: |
| 1641 | |
Behdad Esfahbod | 26648ce | 2016-09-10 02:11:05 -0700 | [diff] [blame] | 1642 | inline float get_delta (hb_font_t *font, const VariationStore &store) const |
Behdad Esfahbod | 6d9d3c5 | 2016-03-01 19:12:08 +0900 | [diff] [blame] | 1643 | { |
Behdad Esfahbod | 26648ce | 2016-09-10 02:11:05 -0700 | [diff] [blame] | 1644 | return store.get_delta (outerIndex, innerIndex, font->coords, font->num_coords); |
Behdad Esfahbod | 6d9d3c5 | 2016-03-01 19:12:08 +0900 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | protected: |
Behdad Esfahbod | dc9f229 | 2016-09-09 15:40:15 -0700 | [diff] [blame] | 1648 | USHORT outerIndex; |
| 1649 | USHORT innerIndex; |
| 1650 | USHORT deltaFormat; /* Format identifier for this table: 0x0x8000 */ |
Behdad Esfahbod | 6d9d3c5 | 2016-03-01 19:12:08 +0900 | [diff] [blame] | 1651 | public: |
Behdad Esfahbod | dc9f229 | 2016-09-09 15:40:15 -0700 | [diff] [blame] | 1652 | DEFINE_SIZE_STATIC (6); |
Behdad Esfahbod | 6d9d3c5 | 2016-03-01 19:12:08 +0900 | [diff] [blame] | 1653 | }; |
| 1654 | |
Behdad Esfahbod | 1f6ed35 | 2016-09-10 00:01:10 -0700 | [diff] [blame] | 1655 | struct DeviceHeader |
| 1656 | { |
| 1657 | protected: |
| 1658 | USHORT reserved1; |
| 1659 | USHORT reserved2; |
| 1660 | public: |
| 1661 | USHORT format; /* Format identifier */ |
| 1662 | public: |
| 1663 | DEFINE_SIZE_STATIC (6); |
| 1664 | }; |
| 1665 | |
Behdad Esfahbod | 4c535a8 | 2016-03-02 12:21:36 +0900 | [diff] [blame] | 1666 | struct Device |
| 1667 | { |
Behdad Esfahbod | 219cb29 | 2016-09-28 17:16:06 +0200 | [diff] [blame] | 1668 | inline hb_position_t get_x_delta (hb_font_t *font, const VariationStore &store=Null(VariationStore)) const |
Behdad Esfahbod | 4c535a8 | 2016-03-02 12:21:36 +0900 | [diff] [blame] | 1669 | { |
| 1670 | switch (u.b.format) |
| 1671 | { |
| 1672 | case 1: case 2: case 3: |
| 1673 | return u.hinting.get_x_delta (font); |
Behdad Esfahbod | dc9f229 | 2016-09-09 15:40:15 -0700 | [diff] [blame] | 1674 | case 0x8000: |
Behdad Esfahbod | 151d93d | 2016-09-09 17:03:11 -0700 | [diff] [blame] | 1675 | return u.variation.get_x_delta (font, store); |
Behdad Esfahbod | 4c535a8 | 2016-03-02 12:21:36 +0900 | [diff] [blame] | 1676 | default: |
| 1677 | return 0; |
| 1678 | } |
| 1679 | } |
Behdad Esfahbod | 219cb29 | 2016-09-28 17:16:06 +0200 | [diff] [blame] | 1680 | inline hb_position_t get_y_delta (hb_font_t *font, const VariationStore &store=Null(VariationStore)) const |
Behdad Esfahbod | 4c535a8 | 2016-03-02 12:21:36 +0900 | [diff] [blame] | 1681 | { |
| 1682 | switch (u.b.format) |
| 1683 | { |
| 1684 | case 1: case 2: case 3: |
Behdad Esfahbod | 85ec494 | 2016-09-10 00:25:16 -0700 | [diff] [blame] | 1685 | return u.hinting.get_y_delta (font); |
Behdad Esfahbod | dc9f229 | 2016-09-09 15:40:15 -0700 | [diff] [blame] | 1686 | case 0x8000: |
Behdad Esfahbod | 151d93d | 2016-09-09 17:03:11 -0700 | [diff] [blame] | 1687 | return u.variation.get_y_delta (font, store); |
Behdad Esfahbod | 4c535a8 | 2016-03-02 12:21:36 +0900 | [diff] [blame] | 1688 | default: |
| 1689 | return 0; |
| 1690 | } |
| 1691 | } |
| 1692 | |
| 1693 | inline bool sanitize (hb_sanitize_context_t *c) const |
| 1694 | { |
| 1695 | TRACE_SANITIZE (this); |
| 1696 | if (!u.b.format.sanitize (c)) return_trace (false); |
| 1697 | switch (u.b.format) { |
| 1698 | case 1: case 2: case 3: |
| 1699 | return_trace (u.hinting.sanitize (c)); |
Behdad Esfahbod | dc9f229 | 2016-09-09 15:40:15 -0700 | [diff] [blame] | 1700 | case 0x8000: |
Behdad Esfahbod | 4c535a8 | 2016-03-02 12:21:36 +0900 | [diff] [blame] | 1701 | return_trace (u.variation.sanitize (c)); |
| 1702 | default: |
| 1703 | return_trace (true); |
| 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | protected: |
| 1708 | union { |
Behdad Esfahbod | 1f6ed35 | 2016-09-10 00:01:10 -0700 | [diff] [blame] | 1709 | DeviceHeader b; |
Behdad Esfahbod | 4c535a8 | 2016-03-02 12:21:36 +0900 | [diff] [blame] | 1710 | HintingDevice hinting; |
| 1711 | VariationDevice variation; |
| 1712 | } u; |
| 1713 | public: |
| 1714 | DEFINE_SIZE_UNION (6, b); |
| 1715 | }; |
| 1716 | |
Behdad Esfahbod | 6d9d3c5 | 2016-03-01 19:12:08 +0900 | [diff] [blame] | 1717 | |
Behdad Esfahbod | 7d52e66 | 2012-11-16 18:49:54 -0800 | [diff] [blame] | 1718 | } /* namespace OT */ |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 1719 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 1720 | |
Behdad Esfahbod | 5f5b24f | 2009-08-02 20:03:12 -0400 | [diff] [blame] | 1721 | #endif /* HB_OT_LAYOUT_COMMON_PRIVATE_HH */ |