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 | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 37 | namespace OT { |
| 38 | |
| 39 | |
Behdad Esfahbod | dadede0 | 2012-07-28 18:03:20 -0400 | [diff] [blame] | 40 | #define NOT_COVERED ((unsigned int) -1) |
Behdad Esfahbod | cd33cb9 | 2009-08-14 18:42:42 -0400 | [diff] [blame] | 41 | #define MAX_NESTING_LEVEL 8 |
| 42 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 43 | |
Behdad Esfahbod | cd33cb9 | 2009-08-14 18:42:42 -0400 | [diff] [blame] | 44 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 45 | /* |
| 46 | * |
| 47 | * OpenType Layout Common Table Formats |
| 48 | * |
| 49 | */ |
| 50 | |
Behdad Esfahbod | 2e8fb6c | 2009-05-18 04:37:37 -0400 | [diff] [blame] | 51 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 52 | /* |
| 53 | * Script, ScriptList, LangSys, Feature, FeatureList, Lookup, LookupList |
| 54 | */ |
| 55 | |
| 56 | template <typename Type> |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 57 | struct Record |
| 58 | { |
Behdad Esfahbod | 4e57371 | 2010-09-28 16:23:58 -0400 | [diff] [blame] | 59 | inline int cmp (hb_tag_t a) const { |
Behdad Esfahbod | 36b3862 | 2010-09-29 12:10:24 -0400 | [diff] [blame] | 60 | return tag.cmp (a); |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 61 | } |
| 62 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 63 | inline bool sanitize (hb_sanitize_context_t *c, void *base) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 64 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 65 | return TRACE_RETURN (c->check_struct (this) && offset.sanitize (c, base)); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 66 | } |
| 67 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 68 | Tag tag; /* 4-byte Tag identifier */ |
| 69 | OffsetTo<Type> |
| 70 | offset; /* Offset from beginning of object holding |
| 71 | * the Record */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 72 | public: |
| 73 | DEFINE_SIZE_STATIC (6); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | template <typename Type> |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 77 | struct RecordArrayOf : SortedArrayOf<Record<Type> > { |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 78 | inline const Tag& get_tag (unsigned int i) const |
| 79 | { |
Behdad Esfahbod | 4e22c7e | 2010-11-03 15:47:12 -0400 | [diff] [blame] | 80 | /* We cheat slightly and don't define separate Null objects |
| 81 | * for Record types. Instead, we return the correct Null(Tag) |
| 82 | * here. */ |
Behdad Esfahbod | 64d3fc8 | 2010-05-03 22:51:19 -0400 | [diff] [blame] | 83 | if (unlikely (i >= this->len)) return Null(Tag); |
Behdad Esfahbod | d3480ba | 2009-11-03 10:47:29 -0500 | [diff] [blame] | 84 | return (*this)[i].tag; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 85 | } |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 86 | inline unsigned int get_tags (unsigned int start_offset, |
| 87 | unsigned int *record_count /* IN/OUT */, |
| 88 | hb_tag_t *record_tags /* OUT */) const |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 89 | { |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 90 | if (record_count) { |
Behdad Esfahbod | 31f18ab | 2011-06-15 09:49:58 -0400 | [diff] [blame] | 91 | const Record<Type> *arr = this->sub_array (start_offset, record_count); |
Behdad Esfahbod | 48de373 | 2009-11-04 16:59:50 -0500 | [diff] [blame] | 92 | unsigned int count = *record_count; |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 93 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 31f18ab | 2011-06-15 09:49:58 -0400 | [diff] [blame] | 94 | record_tags[i] = arr[i].tag; |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 95 | } |
| 96 | return this->len; |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 97 | } |
| 98 | inline bool find_index (hb_tag_t tag, unsigned int *index) const |
| 99 | { |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 100 | int i = this->search (tag); |
| 101 | if (i != -1) { |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 102 | if (index) *index = i; |
| 103 | return true; |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 104 | } else { |
| 105 | if (index) *index = Index::NOT_FOUND_INDEX; |
| 106 | return false; |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 107 | } |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 108 | } |
| 109 | }; |
| 110 | |
| 111 | template <typename Type> |
| 112 | struct RecordListOf : RecordArrayOf<Type> |
| 113 | { |
| 114 | inline const Type& operator [] (unsigned int i) const |
Behdad Esfahbod | 6bec81a | 2009-11-02 19:17:36 -0500 | [diff] [blame] | 115 | { return this+RecordArrayOf<Type>::operator [](i).offset; } |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 116 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 117 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 118 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 119 | return TRACE_RETURN (RecordArrayOf<Type>::sanitize (c, this)); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 120 | } |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 124 | struct RangeRecord |
| 125 | { |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 126 | inline int cmp (hb_codepoint_t g) const { |
| 127 | hb_codepoint_t a = start, b = end; |
| 128 | return g < a ? -1 : g <= b ? 0 : +1 ; |
| 129 | } |
| 130 | |
| 131 | inline bool sanitize (hb_sanitize_context_t *c) { |
| 132 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 133 | return TRACE_RETURN (c->check_struct (this)); |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 134 | } |
| 135 | |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 136 | inline bool intersects (const hb_set_t *glyphs) const { |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 137 | return glyphs->intersects (start, end); |
| 138 | } |
| 139 | |
Behdad Esfahbod | c8accf1 | 2012-08-01 21:05:57 -0400 | [diff] [blame] | 140 | template <typename set_t> |
| 141 | inline void add_coverage (set_t *glyphs) const { |
Behdad Esfahbod | 67bb9e8 | 2012-06-09 02:02:46 -0400 | [diff] [blame] | 142 | glyphs->add_range (start, end); |
| 143 | } |
| 144 | |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 145 | GlyphID start; /* First GlyphID in the range */ |
| 146 | GlyphID end; /* Last GlyphID in the range */ |
| 147 | USHORT value; /* Value */ |
| 148 | public: |
| 149 | DEFINE_SIZE_STATIC (6); |
| 150 | }; |
| 151 | DEFINE_NULL_DATA (RangeRecord, "\000\001"); |
| 152 | |
| 153 | |
Behdad Esfahbod | b5db4f1 | 2010-05-10 22:22:22 -0400 | [diff] [blame] | 154 | struct IndexArray : ArrayOf<Index> |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 155 | { |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 156 | inline unsigned int get_indexes (unsigned int start_offset, |
| 157 | unsigned int *_count /* IN/OUT */, |
| 158 | unsigned int *_indexes /* OUT */) const |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 159 | { |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 160 | if (_count) { |
Behdad Esfahbod | 31f18ab | 2011-06-15 09:49:58 -0400 | [diff] [blame] | 161 | const USHORT *arr = this->sub_array (start_offset, _count); |
Behdad Esfahbod | 48de373 | 2009-11-04 16:59:50 -0500 | [diff] [blame] | 162 | unsigned int count = *_count; |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 163 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 31f18ab | 2011-06-15 09:49:58 -0400 | [diff] [blame] | 164 | _indexes[i] = arr[i]; |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 165 | } |
| 166 | return this->len; |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 167 | } |
| 168 | }; |
| 169 | |
| 170 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 171 | struct Script; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 172 | struct LangSys; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 173 | struct Feature; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 174 | |
| 175 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 176 | struct LangSys |
| 177 | { |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 178 | inline unsigned int get_feature_count (void) const |
| 179 | { return featureIndex.len; } |
| 180 | inline hb_tag_t get_feature_index (unsigned int i) const |
| 181 | { return featureIndex[i]; } |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 182 | inline unsigned int get_feature_indexes (unsigned int start_offset, |
| 183 | unsigned int *feature_count /* IN/OUT */, |
| 184 | unsigned int *feature_indexes /* OUT */) const |
| 185 | { return featureIndex.get_indexes (start_offset, feature_count, feature_indexes); } |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 186 | |
Behdad Esfahbod | cc6c644 | 2009-05-25 03:10:06 -0400 | [diff] [blame] | 187 | inline bool has_required_feature (void) const { return reqFeatureIndex != 0xffff; } |
Behdad Esfahbod | 3d44fb6 | 2010-05-10 22:22:54 -0400 | [diff] [blame] | 188 | inline unsigned int get_required_feature_index (void) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 189 | { |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 190 | if (reqFeatureIndex == 0xffff) |
Behdad Esfahbod | b5db4f1 | 2010-05-10 22:22:22 -0400 | [diff] [blame] | 191 | return Index::NOT_FOUND_INDEX; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 192 | return reqFeatureIndex;; |
| 193 | } |
| 194 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 195 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 196 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 197 | return TRACE_RETURN (c->check_struct (this) && featureIndex.sanitize (c)); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 198 | } |
| 199 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 200 | Offset lookupOrder; /* = Null (reserved for an offset to a |
| 201 | * reordering table) */ |
| 202 | USHORT reqFeatureIndex;/* Index of a feature required for this |
| 203 | * language system--if no required features |
| 204 | * = 0xFFFF */ |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 205 | IndexArray featureIndex; /* Array of indices into the FeatureList */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 206 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 207 | DEFINE_SIZE_ARRAY (6, featureIndex); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 208 | }; |
Behdad Esfahbod | 65f46b0 | 2010-05-06 19:35:19 -0400 | [diff] [blame] | 209 | DEFINE_NULL_DATA (LangSys, "\0\0\xFF\xFF"); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 210 | |
| 211 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 212 | struct Script |
| 213 | { |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 214 | inline unsigned int get_lang_sys_count (void) const |
| 215 | { return langSys.len; } |
| 216 | inline const Tag& get_lang_sys_tag (unsigned int i) const |
| 217 | { return langSys.get_tag (i); } |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 218 | inline unsigned int get_lang_sys_tags (unsigned int start_offset, |
| 219 | unsigned int *lang_sys_count /* IN/OUT */, |
| 220 | hb_tag_t *lang_sys_tags /* OUT */) const |
| 221 | { return langSys.get_tags (start_offset, lang_sys_count, lang_sys_tags); } |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 222 | inline const LangSys& get_lang_sys (unsigned int i) const |
| 223 | { |
Behdad Esfahbod | b5db4f1 | 2010-05-10 22:22:22 -0400 | [diff] [blame] | 224 | if (i == Index::NOT_FOUND_INDEX) return get_default_lang_sys (); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 225 | return this+langSys[i].offset; |
| 226 | } |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 227 | inline bool find_lang_sys_index (hb_tag_t tag, unsigned int *index) const |
| 228 | { return langSys.find_index (tag, index); } |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 229 | |
Behdad Esfahbod | cc6c644 | 2009-05-25 03:10:06 -0400 | [diff] [blame] | 230 | inline bool has_default_lang_sys (void) const { return defaultLangSys != 0; } |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 231 | inline const LangSys& get_default_lang_sys (void) const { return this+defaultLangSys; } |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 232 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 233 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 234 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 235 | return TRACE_RETURN (defaultLangSys.sanitize (c, this) && langSys.sanitize (c, this)); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 236 | } |
| 237 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 238 | protected: |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 239 | OffsetTo<LangSys> |
| 240 | defaultLangSys; /* Offset to DefaultLangSys table--from |
| 241 | * beginning of Script table--may be Null */ |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 242 | RecordArrayOf<LangSys> |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 243 | langSys; /* Array of LangSysRecords--listed |
| 244 | * alphabetically by LangSysTag */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 245 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 246 | DEFINE_SIZE_ARRAY (4, langSys); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 247 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 248 | |
| 249 | typedef RecordListOf<Script> ScriptList; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 250 | |
| 251 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 252 | struct Feature |
| 253 | { |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 254 | inline unsigned int get_lookup_count (void) const |
| 255 | { return lookupIndex.len; } |
| 256 | inline hb_tag_t get_lookup_index (unsigned int i) const |
| 257 | { return lookupIndex[i]; } |
Behdad Esfahbod | e21899b | 2009-11-04 16:36:14 -0500 | [diff] [blame] | 258 | inline unsigned int get_lookup_indexes (unsigned int start_index, |
| 259 | unsigned int *lookup_count /* IN/OUT */, |
| 260 | unsigned int *lookup_tags /* OUT */) const |
| 261 | { return lookupIndex.get_indexes (start_index, lookup_count, lookup_tags); } |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 262 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 263 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 264 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 265 | return TRACE_RETURN (c->check_struct (this) && lookupIndex.sanitize (c)); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 266 | } |
| 267 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 268 | Offset featureParams; /* Offset to Feature Parameters table (if one |
| 269 | * has been defined for the feature), relative |
| 270 | * to the beginning of the Feature Table; = Null |
| 271 | * if not required */ |
Behdad Esfahbod | bff3c0f | 2009-08-07 19:46:30 -0400 | [diff] [blame] | 272 | IndexArray lookupIndex; /* Array of LookupList indices */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 273 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 274 | DEFINE_SIZE_ARRAY (4, lookupIndex); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 275 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 276 | |
| 277 | typedef RecordListOf<Feature> FeatureList; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 278 | |
| 279 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 280 | struct LookupFlag : USHORT |
| 281 | { |
Behdad Esfahbod | c6035cf | 2012-04-12 13:23:59 -0400 | [diff] [blame] | 282 | enum Flags { |
Behdad Esfahbod | 4fa77d3 | 2009-05-18 18:44:54 -0400 | [diff] [blame] | 283 | RightToLeft = 0x0001u, |
| 284 | IgnoreBaseGlyphs = 0x0002u, |
| 285 | IgnoreLigatures = 0x0004u, |
| 286 | IgnoreMarks = 0x0008u, |
Behdad Esfahbod | aa87d95 | 2009-10-29 03:00:44 -0400 | [diff] [blame] | 287 | IgnoreFlags = 0x000Eu, |
Behdad Esfahbod | d7df42d | 2009-05-26 13:04:59 -0400 | [diff] [blame] | 288 | UseMarkFilteringSet = 0x0010u, |
| 289 | Reserved = 0x00E0u, |
Behdad Esfahbod | 8f034d5 | 2009-08-18 16:41:59 -0400 | [diff] [blame] | 290 | MarkAttachmentType = 0xFF00u |
Behdad Esfahbod | 4fa77d3 | 2009-05-18 18:44:54 -0400 | [diff] [blame] | 291 | }; |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 292 | public: |
| 293 | DEFINE_SIZE_STATIC (2); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 294 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 295 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 296 | struct Lookup |
| 297 | { |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 298 | inline unsigned int get_subtable_count (void) const { return subTable.len; } |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 299 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 300 | inline unsigned int get_type (void) const { return lookupType; } |
Behdad Esfahbod | 8c69e65 | 2010-10-27 22:07:49 -0400 | [diff] [blame] | 301 | |
| 302 | /* lookup_props is a 32-bit integer where the lower 16-bit is LookupFlag and |
| 303 | * higher 16-bit is mark-filtering-set if the lookup uses one. |
| 304 | * Not to be confused with glyph_props which is very similar. */ |
| 305 | inline uint32_t get_props (void) const |
Behdad Esfahbod | d7df42d | 2009-05-26 13:04:59 -0400 | [diff] [blame] | 306 | { |
| 307 | unsigned int flag = lookupFlag; |
Behdad Esfahbod | 64d3fc8 | 2010-05-03 22:51:19 -0400 | [diff] [blame] | 308 | if (unlikely (flag & LookupFlag::UseMarkFilteringSet)) |
Behdad Esfahbod | d7df42d | 2009-05-26 13:04:59 -0400 | [diff] [blame] | 309 | { |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 310 | const USHORT &markFilteringSet = StructAfter<USHORT> (subTable); |
Behdad Esfahbod | 09c292e | 2009-05-26 19:48:16 -0400 | [diff] [blame] | 311 | flag += (markFilteringSet << 16); |
Behdad Esfahbod | d7df42d | 2009-05-26 13:04:59 -0400 | [diff] [blame] | 312 | } |
| 313 | return flag; |
| 314 | } |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 315 | |
Behdad Esfahbod | 652d1e0 | 2012-09-04 20:00:44 -0400 | [diff] [blame] | 316 | inline bool serialize (hb_serialize_context_t *c, |
| 317 | unsigned int lookup_type, |
| 318 | uint32_t lookup_props, |
| 319 | unsigned int num_subtables) |
| 320 | { |
| 321 | TRACE_SERIALIZE (); |
| 322 | if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); |
| 323 | lookupType.set (lookup_type); |
| 324 | lookupFlag.set (lookup_props & 0xFFFF); |
| 325 | if (unlikely (!subTable.serialize (c, num_subtables))) return TRACE_RETURN (false); |
Behdad Esfahbod | b3b89b6 | 2012-09-04 21:13:17 -0400 | [diff] [blame] | 326 | if (lookupFlag & LookupFlag::UseMarkFilteringSet) |
Behdad Esfahbod | 652d1e0 | 2012-09-04 20:00:44 -0400 | [diff] [blame] | 327 | { |
| 328 | USHORT &markFilteringSet = StructAfter<USHORT> (subTable); |
| 329 | markFilteringSet.set (lookup_props >> 16); |
| 330 | } |
| 331 | return TRACE_RETURN (true); |
| 332 | } |
| 333 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 334 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 335 | TRACE_SANITIZE (); |
Behdad Esfahbod | 3b2c2df | 2010-04-22 16:51:42 -0400 | [diff] [blame] | 336 | /* Real sanitize of the subtables is done by GSUB/GPOS/... */ |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 337 | if (!(c->check_struct (this) && subTable.sanitize (c))) return TRACE_RETURN (false); |
Behdad Esfahbod | 652d1e0 | 2012-09-04 20:00:44 -0400 | [diff] [blame] | 338 | if (lookupFlag & LookupFlag::UseMarkFilteringSet) |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 339 | { |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 340 | USHORT &markFilteringSet = StructAfter<USHORT> (subTable); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 341 | if (!markFilteringSet.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 342 | } |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 343 | return TRACE_RETURN (true); |
Behdad Esfahbod | cd3827e | 2009-08-04 02:09:34 -0400 | [diff] [blame] | 344 | } |
| 345 | |
Behdad Esfahbod | d7df42d | 2009-05-26 13:04:59 -0400 | [diff] [blame] | 346 | USHORT lookupType; /* Different enumerations for GSUB and GPOS */ |
| 347 | USHORT lookupFlag; /* Lookup qualifiers */ |
Behdad Esfahbod | 3b2c2df | 2010-04-22 16:51:42 -0400 | [diff] [blame] | 348 | ArrayOf<Offset> |
Behdad Esfahbod | d7df42d | 2009-05-26 13:04:59 -0400 | [diff] [blame] | 349 | subTable; /* Array of SubTables */ |
Behdad Esfahbod | d3480ba | 2009-11-03 10:47:29 -0500 | [diff] [blame] | 350 | USHORT markFilteringSetX[VAR]; /* Index (base 0) into GDEF mark glyph sets |
Behdad Esfahbod | d7df42d | 2009-05-26 13:04:59 -0400 | [diff] [blame] | 351 | * structure. This field is only present if bit |
| 352 | * UseMarkFilteringSet of lookup flags is set. */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 353 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 354 | DEFINE_SIZE_ARRAY2 (6, subTable, markFilteringSetX); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 355 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 356 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 357 | typedef OffsetListOf<Lookup> LookupList; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 358 | |
| 359 | |
| 360 | /* |
| 361 | * Coverage Table |
| 362 | */ |
| 363 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 364 | struct CoverageFormat1 |
| 365 | { |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 366 | friend struct Coverage; |
| 367 | |
| 368 | private: |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 369 | inline unsigned int get_coverage (hb_codepoint_t glyph_id) const |
| 370 | { |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 371 | int i = glyphArray.search (glyph_id); |
Behdad Esfahbod | dadede0 | 2012-07-28 18:03:20 -0400 | [diff] [blame] | 372 | ASSERT_STATIC (((unsigned int) -1) == NOT_COVERED); |
| 373 | return i; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 374 | } |
| 375 | |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 376 | inline bool serialize (hb_serialize_context_t *c, |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 377 | Supplier<GlyphID> &glyphs, |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 378 | unsigned int num_glyphs) |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 379 | { |
| 380 | TRACE_SERIALIZE (); |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 381 | if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); |
| 382 | glyphArray.len.set (num_glyphs); |
| 383 | if (unlikely (!c->extend (glyphArray))) return TRACE_RETURN (false); |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 384 | for (unsigned int i = 0; i < num_glyphs; i++) |
Behdad Esfahbod | fabd311 | 2012-09-05 22:19:28 -0400 | [diff] [blame] | 385 | glyphArray[i] = glyphs[i]; |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 386 | glyphs.advance (num_glyphs); |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 387 | return TRACE_RETURN (true); |
| 388 | } |
| 389 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 390 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 391 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 392 | return TRACE_RETURN (glyphArray.sanitize (c)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 393 | } |
| 394 | |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 395 | 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] | 396 | return glyphs->has (glyphArray[index]); |
| 397 | } |
| 398 | |
Behdad Esfahbod | c8accf1 | 2012-08-01 21:05:57 -0400 | [diff] [blame] | 399 | template <typename set_t> |
| 400 | inline void add_coverage (set_t *glyphs) const { |
Behdad Esfahbod | 67bb9e8 | 2012-06-09 02:02:46 -0400 | [diff] [blame] | 401 | unsigned int count = glyphArray.len; |
| 402 | for (unsigned int i = 0; i < count; i++) |
| 403 | glyphs->add (glyphArray[i]); |
| 404 | } |
| 405 | |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 406 | struct Iter { |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 407 | inline void init (const struct CoverageFormat1 &c_) { c = &c_; i = 0; }; |
| 408 | inline bool more (void) { return i < c->glyphArray.len; } |
| 409 | inline void next (void) { i++; } |
| 410 | inline uint16_t get_glyph (void) { return c->glyphArray[i]; } |
| 411 | inline uint16_t get_coverage (void) { return i; } |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 412 | |
| 413 | private: |
| 414 | const struct CoverageFormat1 *c; |
| 415 | unsigned int i; |
| 416 | }; |
| 417 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 418 | protected: |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 419 | USHORT coverageFormat; /* Format identifier--format = 1 */ |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 420 | SortedArrayOf<GlyphID> |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 421 | glyphArray; /* Array of GlyphIDs--in numerical order */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 422 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 423 | DEFINE_SIZE_ARRAY (4, glyphArray); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 424 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 425 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 426 | struct CoverageFormat2 |
| 427 | { |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 428 | friend struct Coverage; |
| 429 | |
| 430 | private: |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 431 | inline unsigned int get_coverage (hb_codepoint_t glyph_id) const |
| 432 | { |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 433 | int i = rangeRecord.search (glyph_id); |
| 434 | if (i != -1) { |
| 435 | const RangeRecord &range = rangeRecord[i]; |
| 436 | return (unsigned int) range.value + (glyph_id - range.start); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 437 | } |
| 438 | return NOT_COVERED; |
| 439 | } |
| 440 | |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 441 | inline bool serialize (hb_serialize_context_t *c, |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 442 | Supplier<GlyphID> &glyphs, |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 443 | unsigned int num_glyphs) |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 444 | { |
| 445 | TRACE_SERIALIZE (); |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 446 | if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); |
| 447 | |
| 448 | if (unlikely (!num_glyphs)) return TRACE_RETURN (true); |
| 449 | |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 450 | unsigned int num_ranges = 1; |
| 451 | for (unsigned int i = 1; i < num_glyphs; i++) |
| 452 | if (glyphs[i - 1] + 1 != glyphs[i]) |
| 453 | num_ranges++; |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 454 | rangeRecord.len.set (num_ranges); |
| 455 | if (unlikely (!c->extend (rangeRecord))) return TRACE_RETURN (false); |
| 456 | |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 457 | unsigned int range = 0; |
Behdad Esfahbod | fabd311 | 2012-09-05 22:19:28 -0400 | [diff] [blame] | 458 | rangeRecord[range].start = glyphs[0]; |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 459 | rangeRecord[range].value.set (0); |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 460 | for (unsigned int i = 1; i < num_glyphs; i++) |
| 461 | if (glyphs[i - 1] + 1 != glyphs[i]) { |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 462 | range++; |
Behdad Esfahbod | fabd311 | 2012-09-05 22:19:28 -0400 | [diff] [blame] | 463 | rangeRecord[range].start = glyphs[i]; |
| 464 | rangeRecord[range].value.set (i); |
| 465 | rangeRecord[range].end = glyphs[i]; |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 466 | } else { |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 467 | rangeRecord[range].end = glyphs[i]; |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 468 | } |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 469 | glyphs.advance (num_glyphs); |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 470 | return TRACE_RETURN (true); |
| 471 | } |
| 472 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 473 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 474 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 475 | return TRACE_RETURN (rangeRecord.sanitize (c)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 476 | } |
| 477 | |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 478 | 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] | 479 | unsigned int i; |
| 480 | unsigned int count = rangeRecord.len; |
| 481 | for (i = 0; i < count; i++) { |
| 482 | const RangeRecord &range = rangeRecord[i]; |
| 483 | if (range.value <= index && |
Behdad Esfahbod | 3f18236 | 2012-05-13 16:20:10 +0200 | [diff] [blame] | 484 | index < (unsigned int) range.value + (range.end - range.start) && |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 485 | range.intersects (glyphs)) |
| 486 | return true; |
| 487 | else if (index < range.value) |
| 488 | return false; |
| 489 | } |
| 490 | return false; |
| 491 | } |
| 492 | |
Behdad Esfahbod | c8accf1 | 2012-08-01 21:05:57 -0400 | [diff] [blame] | 493 | template <typename set_t> |
| 494 | inline void add_coverage (set_t *glyphs) const { |
Behdad Esfahbod | 67bb9e8 | 2012-06-09 02:02:46 -0400 | [diff] [blame] | 495 | unsigned int count = rangeRecord.len; |
| 496 | for (unsigned int i = 0; i < count; i++) |
| 497 | rangeRecord[i].add_coverage (glyphs); |
| 498 | } |
| 499 | |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 500 | struct Iter { |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 501 | inline void init (const CoverageFormat2 &c_) { |
| 502 | c = &c_; |
| 503 | coverage = 0; |
| 504 | i = 0; |
| 505 | j = c->rangeRecord.len ? c_.rangeRecord[0].start : 0; |
| 506 | } |
| 507 | inline bool more (void) { return i < c->rangeRecord.len; } |
| 508 | inline void next (void) { |
| 509 | coverage++; |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 510 | if (j == c->rangeRecord[i].end) { |
| 511 | i++; |
Behdad Esfahbod | 0da132b | 2012-04-23 14:21:33 -0400 | [diff] [blame] | 512 | if (more ()) |
| 513 | j = c->rangeRecord[i].start; |
| 514 | return; |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 515 | } |
Behdad Esfahbod | 0da132b | 2012-04-23 14:21:33 -0400 | [diff] [blame] | 516 | j++; |
| 517 | } |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 518 | inline uint16_t get_glyph (void) { return j; } |
| 519 | inline uint16_t get_coverage (void) { return coverage; } |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 520 | |
| 521 | private: |
| 522 | const struct CoverageFormat2 *c; |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 523 | unsigned int i, j, coverage; |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 524 | }; |
| 525 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 526 | protected: |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 527 | USHORT coverageFormat; /* Format identifier--format = 2 */ |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 528 | SortedArrayOf<RangeRecord> |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 529 | rangeRecord; /* Array of glyph ranges--ordered by |
| 530 | * Start GlyphID. rangeCount entries |
| 531 | * long */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 532 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 533 | DEFINE_SIZE_ARRAY (4, rangeRecord); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 534 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 535 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 536 | struct Coverage |
| 537 | { |
Behdad Esfahbod | 00e23fc | 2010-04-20 23:50:45 -0400 | [diff] [blame] | 538 | inline unsigned int operator () (hb_codepoint_t glyph_id) const { return get_coverage (glyph_id); } |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 539 | |
Behdad Esfahbod | 20b035d | 2009-08-10 19:00:36 -0400 | [diff] [blame] | 540 | inline unsigned int get_coverage (hb_codepoint_t glyph_id) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 541 | { |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 542 | switch (u.format) { |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 543 | case 1: return u.format1.get_coverage(glyph_id); |
| 544 | case 2: return u.format2.get_coverage(glyph_id); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 545 | default:return NOT_COVERED; |
| 546 | } |
| 547 | } |
| 548 | |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 549 | inline bool serialize (hb_serialize_context_t *c, |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 550 | Supplier<GlyphID> &glyphs, |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 551 | unsigned int num_glyphs) |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 552 | { |
| 553 | TRACE_SERIALIZE (); |
Behdad Esfahbod | c61be03 | 2012-09-01 21:43:38 -0400 | [diff] [blame] | 554 | if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 555 | unsigned int num_ranges = 1; |
| 556 | for (unsigned int i = 1; i < num_glyphs; i++) |
| 557 | if (glyphs[i - 1] + 1 != glyphs[i]) |
| 558 | num_ranges++; |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 559 | u.format.set (num_glyphs * 2 < num_ranges * 3 ? 1 : 2); |
| 560 | switch (u.format) { |
| 561 | case 1: return TRACE_RETURN (u.format1.serialize (c, glyphs, num_glyphs)); |
| 562 | case 2: return TRACE_RETURN (u.format2.serialize (c, glyphs, num_glyphs)); |
Behdad Esfahbod | 9f2348d | 2012-08-29 21:08:59 -0400 | [diff] [blame] | 563 | default:return TRACE_RETURN (false); |
| 564 | } |
| 565 | } |
| 566 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 567 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 568 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 569 | if (!u.format.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 570 | switch (u.format) { |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 571 | case 1: return TRACE_RETURN (u.format1.sanitize (c)); |
| 572 | case 2: return TRACE_RETURN (u.format2.sanitize (c)); |
| 573 | default:return TRACE_RETURN (true); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 574 | } |
| 575 | } |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 576 | |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 577 | inline bool intersects (const hb_set_t *glyphs) const { |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 578 | /* TODO speed this up */ |
| 579 | Coverage::Iter iter; |
| 580 | for (iter.init (*this); iter.more (); iter.next ()) { |
| 581 | if (glyphs->has (iter.get_glyph ())) |
| 582 | return true; |
| 583 | } |
| 584 | return false; |
Behdad Esfahbod | 31081f7 | 2012-04-23 16:54:58 -0400 | [diff] [blame] | 585 | } |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 586 | |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 587 | 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] | 588 | switch (u.format) { |
| 589 | case 1: return u.format1.intersects_coverage (glyphs, index); |
| 590 | case 2: return u.format2.intersects_coverage (glyphs, index); |
| 591 | default:return false; |
| 592 | } |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 593 | } |
| 594 | |
Behdad Esfahbod | c8accf1 | 2012-08-01 21:05:57 -0400 | [diff] [blame] | 595 | template <typename set_t> |
| 596 | inline void add_coverage (set_t *glyphs) const { |
Behdad Esfahbod | 67bb9e8 | 2012-06-09 02:02:46 -0400 | [diff] [blame] | 597 | switch (u.format) { |
| 598 | case 1: u.format1.add_coverage (glyphs); break; |
| 599 | case 2: u.format2.add_coverage (glyphs); break; |
| 600 | default: break; |
| 601 | } |
| 602 | } |
| 603 | |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 604 | struct Iter { |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 605 | Iter (void) : format (0) {}; |
| 606 | inline void init (const Coverage &c_) { |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 607 | format = c_.u.format; |
| 608 | switch (format) { |
| 609 | case 1: return u.format1.init (c_.u.format1); |
| 610 | case 2: return u.format2.init (c_.u.format2); |
| 611 | default:return; |
| 612 | } |
| 613 | } |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 614 | inline bool more (void) { |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 615 | switch (format) { |
| 616 | case 1: return u.format1.more (); |
| 617 | case 2: return u.format2.more (); |
| 618 | default:return true; |
| 619 | } |
| 620 | } |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 621 | inline void next (void) { |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 622 | switch (format) { |
Behdad Esfahbod | 0da132b | 2012-04-23 14:21:33 -0400 | [diff] [blame] | 623 | case 1: u.format1.next (); break; |
| 624 | case 2: u.format2.next (); break; |
| 625 | default: break; |
| 626 | } |
| 627 | } |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 628 | inline uint16_t get_glyph (void) { |
Behdad Esfahbod | 0da132b | 2012-04-23 14:21:33 -0400 | [diff] [blame] | 629 | switch (format) { |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 630 | case 1: return u.format1.get_glyph (); |
| 631 | case 2: return u.format2.get_glyph (); |
| 632 | default:return true; |
| 633 | } |
| 634 | } |
| 635 | inline uint16_t get_coverage (void) { |
| 636 | switch (format) { |
| 637 | case 1: return u.format1.get_coverage (); |
| 638 | case 2: return u.format2.get_coverage (); |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 639 | default:return true; |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | private: |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 644 | unsigned int format; |
Behdad Esfahbod | 7d50d50 | 2012-04-23 13:02:14 -0400 | [diff] [blame] | 645 | union { |
| 646 | CoverageFormat1::Iter format1; |
| 647 | CoverageFormat2::Iter format2; |
| 648 | } u; |
| 649 | }; |
| 650 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 651 | protected: |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 652 | union { |
| 653 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 654 | CoverageFormat1 format1; |
| 655 | CoverageFormat2 format2; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 656 | } u; |
Behdad Esfahbod | ed07422 | 2010-05-10 18:08:46 -0400 | [diff] [blame] | 657 | public: |
Behdad Esfahbod | 596e471 | 2010-05-10 18:47:48 -0400 | [diff] [blame] | 658 | DEFINE_SIZE_UNION (2, format); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 659 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 660 | |
| 661 | |
| 662 | /* |
| 663 | * Class Definition Table |
| 664 | */ |
| 665 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 666 | struct ClassDefFormat1 |
| 667 | { |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 668 | friend struct ClassDef; |
| 669 | |
| 670 | private: |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 671 | inline unsigned int get_class (hb_codepoint_t glyph_id) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 672 | { |
Behdad Esfahbod | caf0412 | 2012-06-09 00:26:32 -0400 | [diff] [blame] | 673 | if (unlikely ((unsigned int) (glyph_id - startGlyph) < classValue.len)) |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 674 | return classValue[glyph_id - startGlyph]; |
| 675 | return 0; |
| 676 | } |
| 677 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 678 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 679 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 680 | return TRACE_RETURN (c->check_struct (this) && classValue.sanitize (c)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 681 | } |
| 682 | |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 683 | 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] | 684 | unsigned int count = classValue.len; |
| 685 | for (unsigned int i = 0; i < count; i++) |
| 686 | if (classValue[i] == klass && glyphs->has (startGlyph + i)) |
| 687 | return true; |
| 688 | return false; |
| 689 | } |
| 690 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 691 | protected: |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 692 | USHORT classFormat; /* Format identifier--format = 1 */ |
| 693 | GlyphID startGlyph; /* First GlyphID of the classValueArray */ |
| 694 | ArrayOf<USHORT> |
| 695 | classValue; /* Array of Class Values--one per GlyphID */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 696 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 697 | DEFINE_SIZE_ARRAY (6, classValue); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 698 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 699 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 700 | struct ClassDefFormat2 |
| 701 | { |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 702 | friend struct ClassDef; |
| 703 | |
| 704 | private: |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 705 | inline unsigned int get_class (hb_codepoint_t glyph_id) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 706 | { |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 707 | int i = rangeRecord.search (glyph_id); |
| 708 | if (i != -1) |
| 709 | return rangeRecord[i].value; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 710 | return 0; |
| 711 | } |
| 712 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 713 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 714 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 715 | return TRACE_RETURN (rangeRecord.sanitize (c)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 716 | } |
| 717 | |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 718 | 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] | 719 | unsigned int count = rangeRecord.len; |
| 720 | for (unsigned int i = 0; i < count; i++) |
| 721 | if (rangeRecord[i].value == klass && rangeRecord[i].intersects (glyphs)) |
| 722 | return true; |
| 723 | return false; |
| 724 | } |
| 725 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 726 | protected: |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 727 | USHORT classFormat; /* Format identifier--format = 2 */ |
Behdad Esfahbod | cc8a4ab | 2010-07-08 00:40:04 -0400 | [diff] [blame] | 728 | SortedArrayOf<RangeRecord> |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 729 | rangeRecord; /* Array of glyph ranges--ordered by |
| 730 | * Start GlyphID */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 731 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 732 | DEFINE_SIZE_ARRAY (4, rangeRecord); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 733 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 734 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 735 | struct ClassDef |
| 736 | { |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 737 | inline unsigned int operator () (hb_codepoint_t glyph_id) const { return get_class (glyph_id); } |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 738 | |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 739 | inline unsigned int get_class (hb_codepoint_t glyph_id) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 740 | { |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 741 | switch (u.format) { |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 742 | case 1: return u.format1.get_class(glyph_id); |
| 743 | case 2: return u.format2.get_class(glyph_id); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 744 | default:return 0; |
| 745 | } |
| 746 | } |
| 747 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 748 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 749 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 750 | if (!u.format.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 751 | switch (u.format) { |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 752 | case 1: return TRACE_RETURN (u.format1.sanitize (c)); |
| 753 | case 2: return TRACE_RETURN (u.format2.sanitize (c)); |
| 754 | default:return TRACE_RETURN (true); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 755 | } |
| 756 | } |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 757 | |
Behdad Esfahbod | 6a9be5b | 2012-04-23 22:23:17 -0400 | [diff] [blame] | 758 | 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] | 759 | switch (u.format) { |
| 760 | case 1: return u.format1.intersects_class (glyphs, klass); |
| 761 | case 2: return u.format2.intersects_class (glyphs, klass); |
| 762 | default:return false; |
| 763 | } |
| 764 | } |
| 765 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 766 | protected: |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 767 | union { |
| 768 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 769 | ClassDefFormat1 format1; |
| 770 | ClassDefFormat2 format2; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 771 | } u; |
Behdad Esfahbod | ed07422 | 2010-05-10 18:08:46 -0400 | [diff] [blame] | 772 | public: |
Behdad Esfahbod | 596e471 | 2010-05-10 18:47:48 -0400 | [diff] [blame] | 773 | DEFINE_SIZE_UNION (2, format); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 774 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 775 | |
| 776 | |
| 777 | /* |
| 778 | * Device Tables |
| 779 | */ |
| 780 | |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 781 | struct Device |
| 782 | { |
Behdad Esfahbod | b634beb | 2010-05-20 17:44:52 +0100 | [diff] [blame] | 783 | |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 784 | inline hb_position_t get_x_delta (hb_font_t *font) const |
| 785 | { return get_delta (font->x_ppem, font->x_scale); } |
Behdad Esfahbod | b634beb | 2010-05-20 17:44:52 +0100 | [diff] [blame] | 786 | |
Behdad Esfahbod | abcfe9b | 2011-05-11 00:02:02 -0400 | [diff] [blame] | 787 | inline hb_position_t get_y_delta (hb_font_t *font) const |
| 788 | { return get_delta (font->y_ppem, font->y_scale); } |
Behdad Esfahbod | b634beb | 2010-05-20 17:44:52 +0100 | [diff] [blame] | 789 | |
Behdad Esfahbod | da97541 | 2011-04-21 15:08:01 -0400 | [diff] [blame] | 790 | inline int get_delta (unsigned int ppem, int scale) const |
Behdad Esfahbod | 5bd1e95 | 2010-09-22 16:46:18 -0400 | [diff] [blame] | 791 | { |
| 792 | if (!ppem) return 0; |
| 793 | |
| 794 | int pixels = get_delta_pixels (ppem); |
| 795 | |
| 796 | if (!pixels) return 0; |
| 797 | |
Behdad Esfahbod | 5bd1e95 | 2010-09-22 16:46:18 -0400 | [diff] [blame] | 798 | return pixels * (int64_t) scale / ppem; |
| 799 | } |
| 800 | |
| 801 | |
| 802 | inline int get_delta_pixels (unsigned int ppem_size) const |
Behdad Esfahbod | 60d77cf | 2009-05-19 23:58:54 -0400 | [diff] [blame] | 803 | { |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 804 | unsigned int f = deltaFormat; |
Behdad Esfahbod | 64d3fc8 | 2010-05-03 22:51:19 -0400 | [diff] [blame] | 805 | if (unlikely (f < 1 || f > 3)) |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 806 | return 0; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 807 | |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 808 | if (ppem_size < startSize || ppem_size > endSize) |
| 809 | return 0; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 810 | |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 811 | unsigned int s = ppem_size - startSize; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 812 | |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 813 | unsigned int byte = deltaValue[s >> (4 - f)]; |
Behdad Esfahbod | 09c292e | 2009-05-26 19:48:16 -0400 | [diff] [blame] | 814 | unsigned int bits = (byte >> (16 - (((s & ((1 << (4 - f)) - 1)) + 1) << f))); |
| 815 | unsigned int mask = (0xFFFF >> (16 - (1 << f))); |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 816 | |
| 817 | int delta = bits & mask; |
| 818 | |
Behdad Esfahbod | 15164d9 | 2009-08-04 13:57:41 -0400 | [diff] [blame] | 819 | if ((unsigned int) delta >= ((mask + 1) >> 1)) |
Behdad Esfahbod | 056c7ec | 2009-05-18 19:47:52 -0400 | [diff] [blame] | 820 | delta -= mask + 1; |
| 821 | |
| 822 | return delta; |
| 823 | } |
| 824 | |
Behdad Esfahbod | 7f97d2c | 2010-10-01 18:58:50 -0400 | [diff] [blame] | 825 | inline unsigned int get_size (void) const |
Behdad Esfahbod | dc9c4d9 | 2009-08-04 12:26:26 -0400 | [diff] [blame] | 826 | { |
| 827 | unsigned int f = deltaFormat; |
Behdad Esfahbod | b961518 | 2010-05-10 18:20:54 -0400 | [diff] [blame] | 828 | if (unlikely (f < 1 || f > 3 || startSize > endSize)) return 3 * USHORT::static_size; |
| 829 | return USHORT::static_size * (4 + ((endSize - startSize) >> (4 - f))); |
Behdad Esfahbod | dc9c4d9 | 2009-08-04 12:26:26 -0400 | [diff] [blame] | 830 | } |
| 831 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 832 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 833 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 834 | return TRACE_RETURN (c->check_struct (this) && c->check_range (this, this->get_size ())); |
Behdad Esfahbod | dc9c4d9 | 2009-08-04 12:26:26 -0400 | [diff] [blame] | 835 | } |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 836 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 837 | protected: |
Behdad Esfahbod | 0795b78 | 2010-04-22 00:23:14 -0400 | [diff] [blame] | 838 | USHORT startSize; /* Smallest size to correct--in ppem */ |
| 839 | USHORT endSize; /* Largest size to correct--in ppem */ |
Behdad Esfahbod | caff7db | 2010-04-26 10:07:35 -0400 | [diff] [blame] | 840 | USHORT deltaFormat; /* Format of DeltaValue array data: 1, 2, or 3 |
| 841 | * 1 Signed 2-bit value, 8 values per uint16 |
| 842 | * 2 Signed 4-bit value, 4 values per uint16 |
| 843 | * 3 Signed 8-bit value, 2 values per uint16 |
| 844 | */ |
Behdad Esfahbod | d3480ba | 2009-11-03 10:47:29 -0500 | [diff] [blame] | 845 | USHORT deltaValue[VAR]; /* Array of compressed data */ |
Behdad Esfahbod | 569da92 | 2010-05-10 16:38:32 -0400 | [diff] [blame] | 846 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 847 | DEFINE_SIZE_ARRAY (6, deltaValue); |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 848 | }; |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 849 | |
| 850 | |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 851 | } // namespace OT |
| 852 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 853 | |
Behdad Esfahbod | 5f5b24f | 2009-08-02 20:03:12 -0400 | [diff] [blame] | 854 | #endif /* HB_OT_LAYOUT_COMMON_PRIVATE_HH */ |