Behdad Esfahbod | a0175e7 | 2017-08-17 16:55:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2017 Google, Inc. |
| 3 | * |
| 4 | * This is part of HarfBuzz, a text shaping library. |
| 5 | * |
| 6 | * Permission is hereby granted, without written agreement and without |
| 7 | * license or royalty fees, to use, copy, modify, and distribute this |
| 8 | * software and its documentation for any purpose, provided that the |
| 9 | * above copyright notice and the following two paragraphs appear in |
| 10 | * all copies of this software. |
| 11 | * |
| 12 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
| 13 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
| 14 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
| 15 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 16 | * DAMAGE. |
| 17 | * |
| 18 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
| 19 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
| 21 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
| 22 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 23 | * |
| 24 | * Google Author(s): Behdad Esfahbod |
| 25 | */ |
| 26 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 27 | #ifndef HB_AAT_LAYOUT_COMMON_HH |
| 28 | #define HB_AAT_LAYOUT_COMMON_HH |
Behdad Esfahbod | a0175e7 | 2017-08-17 16:55:54 -0700 | [diff] [blame] | 29 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 30 | #include "hb-aat-layout.hh" |
Ebrahim Byagowi | 47cf9a9 | 2018-12-08 10:20:25 +0330 | [diff] [blame] | 31 | #include "hb-open-type.hh" |
Behdad Esfahbod | a0175e7 | 2017-08-17 16:55:54 -0700 | [diff] [blame] | 32 | |
| 33 | |
| 34 | namespace AAT { |
| 35 | |
| 36 | using namespace OT; |
| 37 | |
| 38 | |
| 39 | /* |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 40 | * Lookup Table |
| 41 | */ |
| 42 | |
| 43 | template <typename T> struct Lookup; |
| 44 | |
| 45 | template <typename T> |
| 46 | struct LookupFormat0 |
| 47 | { |
| 48 | friend struct Lookup<T>; |
| 49 | |
| 50 | private: |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 51 | const T* get_value (hb_codepoint_t glyph_id, unsigned int num_glyphs) const |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 52 | { |
Behdad Esfahbod | 748b989 | 2018-01-09 17:55:17 +0100 | [diff] [blame] | 53 | if (unlikely (glyph_id >= num_glyphs)) return nullptr; |
| 54 | return &arrayZ[glyph_id]; |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 55 | } |
| 56 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 57 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 58 | { |
| 59 | TRACE_SANITIZE (this); |
Behdad Esfahbod | be70738 | 2018-07-17 18:45:25 +0200 | [diff] [blame] | 60 | return_trace (arrayZ.sanitize (c, c->get_num_glyphs ())); |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 61 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 62 | bool sanitize (hb_sanitize_context_t *c, const void *base) const |
Ebrahim Byagowi | b8b00fb | 2018-11-08 18:53:14 +0330 | [diff] [blame] | 63 | { |
| 64 | TRACE_SANITIZE (this); |
| 65 | return_trace (arrayZ.sanitize (c, c->get_num_glyphs (), base)); |
| 66 | } |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 67 | |
| 68 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 69 | HBUINT16 format; /* Format identifier--format = 0 */ |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 70 | UnsizedArrayOf<T> |
| 71 | arrayZ; /* Array of lookup values, indexed by glyph index. */ |
| 72 | public: |
Behdad Esfahbod | 3b9fd17 | 2018-11-22 01:18:55 -0500 | [diff] [blame] | 73 | DEFINE_SIZE_UNBOUNDED (2); |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | |
| 77 | template <typename T> |
| 78 | struct LookupSegmentSingle |
| 79 | { |
Behdad Esfahbod | 5d4b037 | 2019-01-22 12:11:24 +0100 | [diff] [blame] | 80 | static constexpr unsigned TerminationWordCount = 2u; |
Behdad Esfahbod | 3d30972 | 2018-11-24 23:12:28 -0500 | [diff] [blame] | 81 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 82 | int cmp (hb_codepoint_t g) const |
| 83 | { return g < first ? -1 : g <= last ? 0 : +1 ; } |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 84 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 85 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 86 | { |
| 87 | TRACE_SANITIZE (this); |
| 88 | return_trace (c->check_struct (this) && value.sanitize (c)); |
| 89 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 90 | bool sanitize (hb_sanitize_context_t *c, const void *base) const |
Ebrahim Byagowi | b8b00fb | 2018-11-08 18:53:14 +0330 | [diff] [blame] | 91 | { |
| 92 | TRACE_SANITIZE (this); |
| 93 | return_trace (c->check_struct (this) && value.sanitize (c, base)); |
| 94 | } |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 95 | |
| 96 | GlyphID last; /* Last GlyphID in this segment */ |
| 97 | GlyphID first; /* First GlyphID in this segment */ |
| 98 | T value; /* The lookup value (only one) */ |
| 99 | public: |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 100 | DEFINE_SIZE_STATIC (4 + T::static_size); |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | template <typename T> |
| 104 | struct LookupFormat2 |
| 105 | { |
| 106 | friend struct Lookup<T>; |
| 107 | |
| 108 | private: |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 109 | const T* get_value (hb_codepoint_t glyph_id) const |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 110 | { |
| 111 | const LookupSegmentSingle<T> *v = segments.bsearch (glyph_id); |
Behdad Esfahbod | 748b989 | 2018-01-09 17:55:17 +0100 | [diff] [blame] | 112 | return v ? &v->value : nullptr; |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 113 | } |
| 114 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 115 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 116 | { |
| 117 | TRACE_SANITIZE (this); |
| 118 | return_trace (segments.sanitize (c)); |
| 119 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 120 | bool sanitize (hb_sanitize_context_t *c, const void *base) const |
Ebrahim Byagowi | b8b00fb | 2018-11-08 18:53:14 +0330 | [diff] [blame] | 121 | { |
| 122 | TRACE_SANITIZE (this); |
| 123 | return_trace (segments.sanitize (c, base)); |
| 124 | } |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 125 | |
| 126 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 127 | HBUINT16 format; /* Format identifier--format = 2 */ |
Behdad Esfahbod | 3515c8b | 2018-10-07 22:27:00 -0400 | [diff] [blame] | 128 | VarSizedBinSearchArrayOf<LookupSegmentSingle<T> > |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 129 | segments; /* The actual segments. These must already be sorted, |
| 130 | * according to the first word in each one (the last |
| 131 | * glyph in each segment). */ |
| 132 | public: |
| 133 | DEFINE_SIZE_ARRAY (8, segments); |
| 134 | }; |
| 135 | |
| 136 | template <typename T> |
| 137 | struct LookupSegmentArray |
| 138 | { |
Behdad Esfahbod | 5d4b037 | 2019-01-22 12:11:24 +0100 | [diff] [blame] | 139 | static constexpr unsigned TerminationWordCount = 2u; |
Behdad Esfahbod | 3d30972 | 2018-11-24 23:12:28 -0500 | [diff] [blame] | 140 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 141 | const T* get_value (hb_codepoint_t glyph_id, const void *base) const |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 142 | { |
Behdad Esfahbod | 748b989 | 2018-01-09 17:55:17 +0100 | [diff] [blame] | 143 | return first <= glyph_id && glyph_id <= last ? &(base+valuesZ)[glyph_id - first] : nullptr; |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 144 | } |
| 145 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 146 | int cmp (hb_codepoint_t g) const |
| 147 | { return g < first ? -1 : g <= last ? 0 : +1; } |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 148 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 149 | bool sanitize (hb_sanitize_context_t *c, const void *base) const |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 150 | { |
| 151 | TRACE_SANITIZE (this); |
| 152 | return_trace (c->check_struct (this) && |
| 153 | first <= last && |
| 154 | valuesZ.sanitize (c, base, last - first + 1)); |
| 155 | } |
Ebrahim Byagowi | b8b00fb | 2018-11-08 18:53:14 +0330 | [diff] [blame] | 156 | template <typename T2> |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 157 | bool sanitize (hb_sanitize_context_t *c, const void *base, T2 user_data) const |
Ebrahim Byagowi | b8b00fb | 2018-11-08 18:53:14 +0330 | [diff] [blame] | 158 | { |
| 159 | TRACE_SANITIZE (this); |
| 160 | return_trace (c->check_struct (this) && |
| 161 | first <= last && |
| 162 | valuesZ.sanitize (c, base, last - first + 1, user_data)); |
| 163 | } |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 164 | |
| 165 | GlyphID last; /* Last GlyphID in this segment */ |
| 166 | GlyphID first; /* First GlyphID in this segment */ |
Behdad Esfahbod | 7e6bd51 | 2019-01-17 18:24:18 -0500 | [diff] [blame] | 167 | NNOffsetTo<UnsizedArrayOf<T> > |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 168 | valuesZ; /* A 16-bit offset from the start of |
| 169 | * the table to the data. */ |
| 170 | public: |
| 171 | DEFINE_SIZE_STATIC (6); |
| 172 | }; |
| 173 | |
| 174 | template <typename T> |
| 175 | struct LookupFormat4 |
| 176 | { |
| 177 | friend struct Lookup<T>; |
| 178 | |
| 179 | private: |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 180 | const T* get_value (hb_codepoint_t glyph_id) const |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 181 | { |
| 182 | const LookupSegmentArray<T> *v = segments.bsearch (glyph_id); |
Behdad Esfahbod | 748b989 | 2018-01-09 17:55:17 +0100 | [diff] [blame] | 183 | return v ? v->get_value (glyph_id, this) : nullptr; |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 184 | } |
| 185 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 186 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 187 | { |
| 188 | TRACE_SANITIZE (this); |
| 189 | return_trace (segments.sanitize (c, this)); |
| 190 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 191 | bool sanitize (hb_sanitize_context_t *c, const void *base) const |
Ebrahim Byagowi | b8b00fb | 2018-11-08 18:53:14 +0330 | [diff] [blame] | 192 | { |
| 193 | TRACE_SANITIZE (this); |
| 194 | return_trace (segments.sanitize (c, this, base)); |
| 195 | } |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 196 | |
| 197 | protected: |
Behdad Esfahbod | 2c824d3 | 2018-10-11 16:41:01 -0400 | [diff] [blame] | 198 | HBUINT16 format; /* Format identifier--format = 4 */ |
Behdad Esfahbod | 3515c8b | 2018-10-07 22:27:00 -0400 | [diff] [blame] | 199 | VarSizedBinSearchArrayOf<LookupSegmentArray<T> > |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 200 | segments; /* The actual segments. These must already be sorted, |
| 201 | * according to the first word in each one (the last |
| 202 | * glyph in each segment). */ |
| 203 | public: |
| 204 | DEFINE_SIZE_ARRAY (8, segments); |
| 205 | }; |
| 206 | |
| 207 | template <typename T> |
| 208 | struct LookupSingle |
| 209 | { |
Behdad Esfahbod | 5d4b037 | 2019-01-22 12:11:24 +0100 | [diff] [blame] | 210 | static constexpr unsigned TerminationWordCount = 1u; |
Behdad Esfahbod | 3d30972 | 2018-11-24 23:12:28 -0500 | [diff] [blame] | 211 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 212 | int cmp (hb_codepoint_t g) const { return glyph.cmp (g); } |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 213 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 214 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 215 | { |
| 216 | TRACE_SANITIZE (this); |
| 217 | return_trace (c->check_struct (this) && value.sanitize (c)); |
| 218 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 219 | bool sanitize (hb_sanitize_context_t *c, const void *base) const |
Ebrahim Byagowi | b8b00fb | 2018-11-08 18:53:14 +0330 | [diff] [blame] | 220 | { |
| 221 | TRACE_SANITIZE (this); |
| 222 | return_trace (c->check_struct (this) && value.sanitize (c, base)); |
| 223 | } |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 224 | |
| 225 | GlyphID glyph; /* Last GlyphID */ |
| 226 | T value; /* The lookup value (only one) */ |
| 227 | public: |
Behdad Esfahbod | 2c824d3 | 2018-10-11 16:41:01 -0400 | [diff] [blame] | 228 | DEFINE_SIZE_STATIC (2 + T::static_size); |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 229 | }; |
| 230 | |
| 231 | template <typename T> |
| 232 | struct LookupFormat6 |
| 233 | { |
| 234 | friend struct Lookup<T>; |
| 235 | |
| 236 | private: |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 237 | const T* get_value (hb_codepoint_t glyph_id) const |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 238 | { |
| 239 | const LookupSingle<T> *v = entries.bsearch (glyph_id); |
Behdad Esfahbod | 748b989 | 2018-01-09 17:55:17 +0100 | [diff] [blame] | 240 | return v ? &v->value : nullptr; |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 241 | } |
| 242 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 243 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 244 | { |
| 245 | TRACE_SANITIZE (this); |
| 246 | return_trace (entries.sanitize (c)); |
| 247 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 248 | bool sanitize (hb_sanitize_context_t *c, const void *base) const |
Ebrahim Byagowi | b8b00fb | 2018-11-08 18:53:14 +0330 | [diff] [blame] | 249 | { |
| 250 | TRACE_SANITIZE (this); |
| 251 | return_trace (entries.sanitize (c, base)); |
| 252 | } |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 253 | |
| 254 | protected: |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 255 | HBUINT16 format; /* Format identifier--format = 6 */ |
Behdad Esfahbod | 3515c8b | 2018-10-07 22:27:00 -0400 | [diff] [blame] | 256 | VarSizedBinSearchArrayOf<LookupSingle<T> > |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 257 | entries; /* The actual entries, sorted by glyph index. */ |
| 258 | public: |
| 259 | DEFINE_SIZE_ARRAY (8, entries); |
| 260 | }; |
| 261 | |
| 262 | template <typename T> |
| 263 | struct LookupFormat8 |
| 264 | { |
| 265 | friend struct Lookup<T>; |
| 266 | |
| 267 | private: |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 268 | const T* get_value (hb_codepoint_t glyph_id) const |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 269 | { |
Behdad Esfahbod | 44af1f9 | 2018-10-14 14:52:17 -0700 | [diff] [blame] | 270 | return firstGlyph <= glyph_id && glyph_id - firstGlyph < glyphCount ? |
| 271 | &valueArrayZ[glyph_id - firstGlyph] : nullptr; |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 272 | } |
| 273 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 274 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 275 | { |
| 276 | TRACE_SANITIZE (this); |
| 277 | return_trace (c->check_struct (this) && valueArrayZ.sanitize (c, glyphCount)); |
| 278 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 279 | bool sanitize (hb_sanitize_context_t *c, const void *base) const |
Ebrahim Byagowi | b8b00fb | 2018-11-08 18:53:14 +0330 | [diff] [blame] | 280 | { |
| 281 | TRACE_SANITIZE (this); |
| 282 | return_trace (c->check_struct (this) && valueArrayZ.sanitize (c, glyphCount, base)); |
| 283 | } |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 284 | |
| 285 | protected: |
Behdad Esfahbod | 44af1f9 | 2018-10-14 14:52:17 -0700 | [diff] [blame] | 286 | HBUINT16 format; /* Format identifier--format = 8 */ |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 287 | GlyphID firstGlyph; /* First glyph index included in the trimmed array. */ |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 288 | HBUINT16 glyphCount; /* Total number of glyphs (equivalent to the last |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 289 | * glyph minus the value of firstGlyph plus 1). */ |
| 290 | UnsizedArrayOf<T> |
| 291 | valueArrayZ; /* The lookup values (indexed by the glyph index |
| 292 | * minus the value of firstGlyph). */ |
| 293 | public: |
| 294 | DEFINE_SIZE_ARRAY (6, valueArrayZ); |
| 295 | }; |
| 296 | |
| 297 | template <typename T> |
Behdad Esfahbod | f7c0b43 | 2018-10-19 15:23:49 -0700 | [diff] [blame] | 298 | struct LookupFormat10 |
| 299 | { |
| 300 | friend struct Lookup<T>; |
| 301 | |
| 302 | private: |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 303 | const typename T::type get_value_or_null (hb_codepoint_t glyph_id) const |
Behdad Esfahbod | f7c0b43 | 2018-10-19 15:23:49 -0700 | [diff] [blame] | 304 | { |
| 305 | if (!(firstGlyph <= glyph_id && glyph_id - firstGlyph < glyphCount)) |
| 306 | return Null(T); |
| 307 | |
| 308 | const HBUINT8 *p = &valueArrayZ[(glyph_id - firstGlyph) * valueSize]; |
| 309 | |
| 310 | unsigned int v = 0; |
| 311 | unsigned int count = valueSize; |
| 312 | for (unsigned int i = 0; i < count; i++) |
| 313 | v = (v << 8) | *p++; |
| 314 | |
| 315 | return v; |
| 316 | } |
| 317 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 318 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | f7c0b43 | 2018-10-19 15:23:49 -0700 | [diff] [blame] | 319 | { |
| 320 | TRACE_SANITIZE (this); |
| 321 | return_trace (c->check_struct (this) && |
| 322 | valueSize <= 4 && |
| 323 | valueArrayZ.sanitize (c, glyphCount * valueSize)); |
| 324 | } |
| 325 | |
| 326 | protected: |
| 327 | HBUINT16 format; /* Format identifier--format = 8 */ |
| 328 | HBUINT16 valueSize; /* Byte size of each value. */ |
| 329 | GlyphID firstGlyph; /* First glyph index included in the trimmed array. */ |
| 330 | HBUINT16 glyphCount; /* Total number of glyphs (equivalent to the last |
| 331 | * glyph minus the value of firstGlyph plus 1). */ |
| 332 | UnsizedArrayOf<HBUINT8> |
| 333 | valueArrayZ; /* The lookup values (indexed by the glyph index |
| 334 | * minus the value of firstGlyph). */ |
| 335 | public: |
Behdad Esfahbod | 00fdbca | 2018-10-20 12:04:51 -0700 | [diff] [blame] | 336 | DEFINE_SIZE_ARRAY (8, valueArrayZ); |
Behdad Esfahbod | f7c0b43 | 2018-10-19 15:23:49 -0700 | [diff] [blame] | 337 | }; |
| 338 | |
| 339 | template <typename T> |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 340 | struct Lookup |
| 341 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 342 | const T* get_value (hb_codepoint_t glyph_id, unsigned int num_glyphs) const |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 343 | { |
| 344 | switch (u.format) { |
| 345 | case 0: return u.format0.get_value (glyph_id, num_glyphs); |
| 346 | case 2: return u.format2.get_value (glyph_id); |
| 347 | case 4: return u.format4.get_value (glyph_id); |
| 348 | case 6: return u.format6.get_value (glyph_id); |
| 349 | case 8: return u.format8.get_value (glyph_id); |
Behdad Esfahbod | 748b989 | 2018-01-09 17:55:17 +0100 | [diff] [blame] | 350 | default:return nullptr; |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 354 | const typename T::type get_value_or_null (hb_codepoint_t glyph_id, unsigned int num_glyphs) const |
Behdad Esfahbod | 7727e73 | 2018-10-10 13:24:51 -0400 | [diff] [blame] | 355 | { |
Behdad Esfahbod | f7c0b43 | 2018-10-19 15:23:49 -0700 | [diff] [blame] | 356 | switch (u.format) { |
| 357 | /* Format 10 cannot return a pointer. */ |
| 358 | case 10: return u.format10.get_value_or_null (glyph_id); |
| 359 | default: |
| 360 | const T *v = get_value (glyph_id, num_glyphs); |
| 361 | return v ? *v : Null(T); |
| 362 | } |
Behdad Esfahbod | 7727e73 | 2018-10-10 13:24:51 -0400 | [diff] [blame] | 363 | } |
| 364 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 365 | typename T::type get_class (hb_codepoint_t glyph_id, |
| 366 | unsigned int num_glyphs, |
| 367 | unsigned int outOfRange) const |
Behdad Esfahbod | 5b4a789 | 2018-11-28 14:46:26 -0500 | [diff] [blame] | 368 | { |
| 369 | const T *v = get_value (glyph_id, num_glyphs); |
| 370 | return v ? *v : outOfRange; |
| 371 | } |
| 372 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 373 | bool sanitize (hb_sanitize_context_t *c) const |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 374 | { |
| 375 | TRACE_SANITIZE (this); |
| 376 | if (!u.format.sanitize (c)) return_trace (false); |
| 377 | switch (u.format) { |
| 378 | case 0: return_trace (u.format0.sanitize (c)); |
| 379 | case 2: return_trace (u.format2.sanitize (c)); |
| 380 | case 4: return_trace (u.format4.sanitize (c)); |
| 381 | case 6: return_trace (u.format6.sanitize (c)); |
| 382 | case 8: return_trace (u.format8.sanitize (c)); |
Behdad Esfahbod | f7c0b43 | 2018-10-19 15:23:49 -0700 | [diff] [blame] | 383 | case 10: return_trace (u.format10.sanitize (c)); |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 384 | default:return_trace (true); |
| 385 | } |
| 386 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 387 | bool sanitize (hb_sanitize_context_t *c, const void *base) const |
Ebrahim Byagowi | b8b00fb | 2018-11-08 18:53:14 +0330 | [diff] [blame] | 388 | { |
| 389 | TRACE_SANITIZE (this); |
| 390 | if (!u.format.sanitize (c)) return_trace (false); |
| 391 | switch (u.format) { |
| 392 | case 0: return_trace (u.format0.sanitize (c, base)); |
| 393 | case 2: return_trace (u.format2.sanitize (c, base)); |
| 394 | case 4: return_trace (u.format4.sanitize (c, base)); |
| 395 | case 6: return_trace (u.format6.sanitize (c, base)); |
| 396 | case 8: return_trace (u.format8.sanitize (c, base)); |
Behdad Esfahbod | c99d13d | 2019-01-17 17:56:27 -0500 | [diff] [blame] | 397 | case 10: return_trace (false); /* We don't support format10 here currently. */ |
Ebrahim Byagowi | b8b00fb | 2018-11-08 18:53:14 +0330 | [diff] [blame] | 398 | default:return_trace (true); |
| 399 | } |
| 400 | } |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 401 | |
| 402 | protected: |
| 403 | union { |
Behdad Esfahbod | 6b19178 | 2018-01-10 03:07:30 +0100 | [diff] [blame] | 404 | HBUINT16 format; /* Format identifier */ |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 405 | LookupFormat0<T> format0; |
| 406 | LookupFormat2<T> format2; |
| 407 | LookupFormat4<T> format4; |
| 408 | LookupFormat6<T> format6; |
| 409 | LookupFormat8<T> format8; |
Behdad Esfahbod | f7c0b43 | 2018-10-19 15:23:49 -0700 | [diff] [blame] | 410 | LookupFormat10<T> format10; |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 411 | } u; |
| 412 | public: |
Behdad Esfahbod | 9e8a9b8 | 2018-10-17 21:41:25 -0700 | [diff] [blame] | 413 | DEFINE_SIZE_UNION (2, format); |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 414 | }; |
Behdad Esfahbod | 9e8a9b8 | 2018-10-17 21:41:25 -0700 | [diff] [blame] | 415 | /* Lookup 0 has unbounded size (dependant on num_glyphs). So we need to defined |
| 416 | * special NULL objects for Lookup<> objects, but since it's template our macros |
| 417 | * don't work. So we have to hand-code them here. UGLY. */ |
| 418 | } /* Close namespace. */ |
| 419 | /* Ugly hand-coded null objects for template Lookup<> :(. */ |
| 420 | extern HB_INTERNAL const unsigned char _hb_Null_AAT_Lookup[2]; |
| 421 | template <> |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 422 | /*static*/ inline const AAT::Lookup<OT::HBUINT16>& Null<AAT::Lookup<OT::HBUINT16> > () |
| 423 | { return *reinterpret_cast<const AAT::Lookup<OT::HBUINT16> *> (_hb_Null_AAT_Lookup); } |
Behdad Esfahbod | 9e8a9b8 | 2018-10-17 21:41:25 -0700 | [diff] [blame] | 424 | template <> |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 425 | /*static*/ inline const AAT::Lookup<OT::HBUINT32>& Null<AAT::Lookup<OT::HBUINT32> > () |
| 426 | { return *reinterpret_cast<const AAT::Lookup<OT::HBUINT32> *> (_hb_Null_AAT_Lookup); } |
Behdad Esfahbod | 9e8a9b8 | 2018-10-17 21:41:25 -0700 | [diff] [blame] | 427 | template <> |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 428 | /*static*/ inline const AAT::Lookup<OT::Offset<OT::HBUINT16, false> >& Null<AAT::Lookup<OT::Offset<OT::HBUINT16, false> > > () |
| 429 | { return *reinterpret_cast<const AAT::Lookup<OT::Offset<OT::HBUINT16, false> > *> (_hb_Null_AAT_Lookup); } |
Behdad Esfahbod | 9e8a9b8 | 2018-10-17 21:41:25 -0700 | [diff] [blame] | 430 | namespace AAT { |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 431 | |
Behdad Esfahbod | 102af61 | 2018-10-25 17:29:32 -0700 | [diff] [blame] | 432 | enum { DELETED_GLYPH = 0xFFFF }; |
Behdad Esfahbod | 470fe5b | 2018-01-09 15:48:51 +0100 | [diff] [blame] | 433 | |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 434 | /* |
Behdad Esfahbod | c0383c6 | 2018-11-06 15:07:19 -0500 | [diff] [blame] | 435 | * (Extended) State Table |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 436 | */ |
| 437 | |
| 438 | template <typename T> |
| 439 | struct Entry |
| 440 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 441 | bool sanitize (hb_sanitize_context_t *c, unsigned int count) const |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 442 | { |
| 443 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 17f01af | 2018-01-11 18:54:49 +0100 | [diff] [blame] | 444 | /* Note, we don't recurse-sanitize data because we don't access it. |
| 445 | * That said, in our DEFINE_SIZE_STATIC we access T::static_size, |
| 446 | * which ensures that data has a simple sanitize(). To be determined |
Behdad Esfahbod | 39bd07a | 2018-10-26 21:01:11 -0700 | [diff] [blame] | 447 | * if I need to remove that as well. |
| 448 | * |
Behdad Esfahbod | ba38378 | 2018-11-24 00:27:57 -0500 | [diff] [blame] | 449 | * HOWEVER! Because we are a template, our DEFINE_SIZE_STATIC |
| 450 | * assertion wouldn't be checked, hence the line below. */ |
| 451 | static_assert (T::static_size, ""); |
| 452 | |
Behdad Esfahbod | 17f01af | 2018-01-11 18:54:49 +0100 | [diff] [blame] | 453 | return_trace (c->check_struct (this)); |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | public: |
Behdad Esfahbod | 17f01af | 2018-01-11 18:54:49 +0100 | [diff] [blame] | 457 | HBUINT16 newState; /* Byte offset from beginning of state table |
| 458 | * to the new state. Really?!?! Or just state |
| 459 | * number? The latter in morx for sure. */ |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 460 | HBUINT16 flags; /* Table specific. */ |
| 461 | T data; /* Optional offsets to per-glyph tables. */ |
| 462 | public: |
| 463 | DEFINE_SIZE_STATIC (4 + T::static_size); |
| 464 | }; |
| 465 | |
| 466 | template <> |
| 467 | struct Entry<void> |
| 468 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 469 | bool sanitize (hb_sanitize_context_t *c, unsigned int count /*XXX Unused?*/) const |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 470 | { |
| 471 | TRACE_SANITIZE (this); |
| 472 | return_trace (c->check_struct (this)); |
| 473 | } |
| 474 | |
| 475 | public: |
| 476 | HBUINT16 newState; /* Byte offset from beginning of state table to the new state. */ |
| 477 | HBUINT16 flags; /* Table specific. */ |
| 478 | public: |
| 479 | DEFINE_SIZE_STATIC (4); |
| 480 | }; |
| 481 | |
Ebrahim Byagowi | b053cab | 2018-10-30 18:41:34 +0330 | [diff] [blame] | 482 | template <typename Types, typename Extra> |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 483 | struct StateTable |
| 484 | { |
Ebrahim Byagowi | b053cab | 2018-10-30 18:41:34 +0330 | [diff] [blame] | 485 | typedef typename Types::HBUINT HBUINT; |
| 486 | typedef typename Types::HBUSHORT HBUSHORT; |
Behdad Esfahbod | f9a9c0f | 2018-11-28 14:51:56 -0500 | [diff] [blame] | 487 | typedef typename Types::ClassTypeNarrow ClassType; |
Ebrahim Byagowi | b053cab | 2018-10-30 18:41:34 +0330 | [diff] [blame] | 488 | |
Behdad Esfahbod | 4653e6c | 2018-09-14 11:31:33 +0200 | [diff] [blame] | 489 | enum State |
| 490 | { |
| 491 | STATE_START_OF_TEXT = 0, |
| 492 | STATE_START_OF_LINE = 1, |
| 493 | }; |
| 494 | enum Class |
| 495 | { |
| 496 | CLASS_END_OF_TEXT = 0, |
| 497 | CLASS_OUT_OF_BOUNDS = 1, |
| 498 | CLASS_DELETED_GLYPH = 2, |
| 499 | CLASS_END_OF_LINE = 3, |
| 500 | }; |
| 501 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 502 | int new_state (unsigned int newState) const |
Behdad Esfahbod | 84efe04 | 2018-12-02 12:38:53 -0500 | [diff] [blame] | 503 | { return Types::extended ? newState : ((int) newState - (int) stateArrayTable) / (int) nClasses; } |
Behdad Esfahbod | 0cf282a | 2018-10-30 20:51:44 -0700 | [diff] [blame] | 504 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 505 | unsigned int get_class (hb_codepoint_t glyph_id, unsigned int num_glyphs) const |
Behdad Esfahbod | 1f1c85a | 2018-01-11 22:43:57 +0100 | [diff] [blame] | 506 | { |
Behdad Esfahbod | 102af61 | 2018-10-25 17:29:32 -0700 | [diff] [blame] | 507 | if (unlikely (glyph_id == DELETED_GLYPH)) return CLASS_DELETED_GLYPH; |
Behdad Esfahbod | d5c0ca2 | 2018-11-07 12:08:44 -0500 | [diff] [blame] | 508 | return (this+classTable).get_class (glyph_id, num_glyphs, 1); |
Behdad Esfahbod | 1f1c85a | 2018-01-11 22:43:57 +0100 | [diff] [blame] | 509 | } |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 510 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 511 | const Entry<Extra> *get_entries () const |
Ebrahim Byagowi | 7ee5c52 | 2018-12-12 15:14:37 +0330 | [diff] [blame] | 512 | { return (this+entryTable).arrayZ; } |
Behdad Esfahbod | 17f01af | 2018-01-11 18:54:49 +0100 | [diff] [blame] | 513 | |
Behdad Esfahbod | 299eca0 | 2019-01-24 17:17:00 +0100 | [diff] [blame] | 514 | const Entry<Extra> &get_entry (int state, unsigned int klass) const |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 515 | { |
Behdad Esfahbod | 299eca0 | 2019-01-24 17:17:00 +0100 | [diff] [blame] | 516 | if (unlikely (klass >= nClasses)) |
| 517 | klass = StateTable<Types, Entry<Extra> >::CLASS_OUT_OF_BOUNDS; |
Behdad Esfahbod | 680cbc2 | 2018-01-11 18:15:53 +0100 | [diff] [blame] | 518 | |
Behdad Esfahbod | c2527a1 | 2018-10-30 19:26:16 -0700 | [diff] [blame] | 519 | const HBUSHORT *states = (this+stateArrayTable).arrayZ; |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 520 | const Entry<Extra> *entries = (this+entryTable).arrayZ; |
| 521 | |
Behdad Esfahbod | 680cbc2 | 2018-01-11 18:15:53 +0100 | [diff] [blame] | 522 | unsigned int entry = states[state * nClasses + klass]; |
Behdad Esfahbod | 006386b | 2018-11-07 18:04:53 -0500 | [diff] [blame] | 523 | DEBUG_MSG (APPLY, nullptr, "e%u", entry); |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 524 | |
Behdad Esfahbod | 299eca0 | 2019-01-24 17:17:00 +0100 | [diff] [blame] | 525 | return entries[entry]; |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 526 | } |
| 527 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 528 | bool sanitize (hb_sanitize_context_t *c, |
| 529 | unsigned int *num_entries_out = nullptr) const |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 530 | { |
| 531 | TRACE_SANITIZE (this); |
Behdad Esfahbod | 12fffce | 2018-01-15 15:41:51 -0500 | [diff] [blame] | 532 | if (unlikely (!(c->check_struct (this) && |
Behdad Esfahbod | c4e36f9 | 2019-01-24 17:06:16 +0100 | [diff] [blame] | 533 | nClasses >= 4 /* Ensure pre-defined classes fit. */ && |
Behdad Esfahbod | 12fffce | 2018-01-15 15:41:51 -0500 | [diff] [blame] | 534 | classTable.sanitize (c, this)))) return_trace (false); |
Behdad Esfahbod | 680cbc2 | 2018-01-11 18:15:53 +0100 | [diff] [blame] | 535 | |
Behdad Esfahbod | c2527a1 | 2018-10-30 19:26:16 -0700 | [diff] [blame] | 536 | const HBUSHORT *states = (this+stateArrayTable).arrayZ; |
Behdad Esfahbod | 680cbc2 | 2018-01-11 18:15:53 +0100 | [diff] [blame] | 537 | const Entry<Extra> *entries = (this+entryTable).arrayZ; |
| 538 | |
Behdad Esfahbod | e940530 | 2018-10-11 15:56:17 -0400 | [diff] [blame] | 539 | unsigned int num_classes = nClasses; |
Behdad Esfahbod | 006386b | 2018-11-07 18:04:53 -0500 | [diff] [blame] | 540 | if (unlikely (hb_unsigned_mul_overflows (num_classes, states[0].static_size))) |
| 541 | return_trace (false); |
| 542 | unsigned int row_stride = num_classes * states[0].static_size; |
Behdad Esfahbod | e940530 | 2018-10-11 15:56:17 -0400 | [diff] [blame] | 543 | |
Behdad Esfahbod | 006386b | 2018-11-07 18:04:53 -0500 | [diff] [blame] | 544 | /* Apple 'kern' table has this peculiarity: |
| 545 | * |
| 546 | * "Because the stateTableOffset in the state table header is (strictly |
| 547 | * speaking) redundant, some 'kern' tables use it to record an initial |
| 548 | * state where that should not be StartOfText. To determine if this is |
| 549 | * done, calculate what the stateTableOffset should be. If it's different |
| 550 | * from the actual stateTableOffset, use it as the initial state." |
| 551 | * |
| 552 | * We implement this by calling the initial state zero, but allow *negative* |
| 553 | * states if the start state indeed was not the first state. Since the code |
| 554 | * is shared, this will also apply to 'mort' table. The 'kerx' / 'morx' |
| 555 | * tables are not affected since those address states by index, not offset. |
| 556 | */ |
| 557 | |
| 558 | int min_state = 0; |
| 559 | int max_state = 0; |
Behdad Esfahbod | 680cbc2 | 2018-01-11 18:15:53 +0100 | [diff] [blame] | 560 | unsigned int num_entries = 0; |
| 561 | |
Behdad Esfahbod | 006386b | 2018-11-07 18:04:53 -0500 | [diff] [blame] | 562 | int state_pos = 0; |
| 563 | int state_neg = 0; |
Behdad Esfahbod | 680cbc2 | 2018-01-11 18:15:53 +0100 | [diff] [blame] | 564 | unsigned int entry = 0; |
Behdad Esfahbod | 006386b | 2018-11-07 18:04:53 -0500 | [diff] [blame] | 565 | while (min_state < state_neg || state_pos <= max_state) |
Behdad Esfahbod | 680cbc2 | 2018-01-11 18:15:53 +0100 | [diff] [blame] | 566 | { |
Behdad Esfahbod | 006386b | 2018-11-07 18:04:53 -0500 | [diff] [blame] | 567 | if (min_state < state_neg) |
| 568 | { |
| 569 | /* Negative states. */ |
| 570 | if (unlikely (hb_unsigned_mul_overflows (min_state, num_classes))) |
| 571 | return_trace (false); |
Behdad Esfahbod | e014405 | 2018-11-12 14:23:31 -0500 | [diff] [blame] | 572 | if (unlikely (!c->check_range (&states[min_state * num_classes], |
| 573 | -min_state, |
| 574 | row_stride))) |
Behdad Esfahbod | 006386b | 2018-11-07 18:04:53 -0500 | [diff] [blame] | 575 | return_trace (false); |
Behdad Esfahbod | c4623db | 2019-01-24 17:10:12 +0100 | [diff] [blame] | 576 | if ((c->max_ops -= state_neg - min_state) <= 0) |
Behdad Esfahbod | 006386b | 2018-11-07 18:04:53 -0500 | [diff] [blame] | 577 | return_trace (false); |
| 578 | { /* Sweep new states. */ |
| 579 | const HBUSHORT *stop = &states[min_state * num_classes]; |
| 580 | if (unlikely (stop > states)) |
| 581 | return_trace (false); |
| 582 | for (const HBUSHORT *p = states; stop < p; p--) |
| 583 | num_entries = MAX<unsigned int> (num_entries, *(p - 1) + 1); |
| 584 | state_neg = min_state; |
| 585 | } |
| 586 | } |
Behdad Esfahbod | e940530 | 2018-10-11 15:56:17 -0400 | [diff] [blame] | 587 | |
Behdad Esfahbod | 006386b | 2018-11-07 18:04:53 -0500 | [diff] [blame] | 588 | if (state_pos <= max_state) |
| 589 | { |
| 590 | /* Positive states. */ |
Behdad Esfahbod | e014405 | 2018-11-12 14:23:31 -0500 | [diff] [blame] | 591 | if (unlikely (!c->check_range (states, |
| 592 | max_state + 1, |
| 593 | row_stride))) |
Behdad Esfahbod | 006386b | 2018-11-07 18:04:53 -0500 | [diff] [blame] | 594 | return_trace (false); |
Behdad Esfahbod | c4623db | 2019-01-24 17:10:12 +0100 | [diff] [blame] | 595 | if ((c->max_ops -= max_state - state_pos + 1) <= 0) |
Behdad Esfahbod | 006386b | 2018-11-07 18:04:53 -0500 | [diff] [blame] | 596 | return_trace (false); |
| 597 | { /* Sweep new states. */ |
| 598 | if (unlikely (hb_unsigned_mul_overflows ((max_state + 1), num_classes))) |
| 599 | return_trace (false); |
| 600 | const HBUSHORT *stop = &states[(max_state + 1) * num_classes]; |
| 601 | if (unlikely (stop < states)) |
| 602 | return_trace (false); |
| 603 | for (const HBUSHORT *p = &states[state_pos * num_classes]; p < stop; p++) |
| 604 | num_entries = MAX<unsigned int> (num_entries, *p + 1); |
| 605 | state_pos = max_state + 1; |
| 606 | } |
Behdad Esfahbod | 680cbc2 | 2018-01-11 18:15:53 +0100 | [diff] [blame] | 607 | } |
| 608 | |
Behdad Esfahbod | 9507b05 | 2018-09-10 23:18:07 +0200 | [diff] [blame] | 609 | if (unlikely (!c->check_array (entries, num_entries))) |
Behdad Esfahbod | 680cbc2 | 2018-01-11 18:15:53 +0100 | [diff] [blame] | 610 | return_trace (false); |
Behdad Esfahbod | c4623db | 2019-01-24 17:10:12 +0100 | [diff] [blame] | 611 | if ((c->max_ops -= num_entries - entry) <= 0) |
Behdad Esfahbod | 8378030 | 2018-10-17 22:34:16 -0700 | [diff] [blame] | 612 | return_trace (false); |
Behdad Esfahbod | 680cbc2 | 2018-01-11 18:15:53 +0100 | [diff] [blame] | 613 | { /* Sweep new entries. */ |
| 614 | const Entry<Extra> *stop = &entries[num_entries]; |
| 615 | for (const Entry<Extra> *p = &entries[entry]; p < stop; p++) |
Behdad Esfahbod | 0cf282a | 2018-10-30 20:51:44 -0700 | [diff] [blame] | 616 | { |
Behdad Esfahbod | 006386b | 2018-11-07 18:04:53 -0500 | [diff] [blame] | 617 | int newState = new_state (p->newState); |
| 618 | min_state = MIN (min_state, newState); |
| 619 | max_state = MAX (max_state, newState); |
Behdad Esfahbod | 0cf282a | 2018-10-30 20:51:44 -0700 | [diff] [blame] | 620 | } |
Behdad Esfahbod | 680cbc2 | 2018-01-11 18:15:53 +0100 | [diff] [blame] | 621 | entry = num_entries; |
| 622 | } |
| 623 | } |
| 624 | |
Behdad Esfahbod | 17f01af | 2018-01-11 18:54:49 +0100 | [diff] [blame] | 625 | if (num_entries_out) |
| 626 | *num_entries_out = num_entries; |
| 627 | |
Behdad Esfahbod | 680cbc2 | 2018-01-11 18:15:53 +0100 | [diff] [blame] | 628 | return_trace (true); |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | protected: |
Ebrahim Byagowi | b053cab | 2018-10-30 18:41:34 +0330 | [diff] [blame] | 632 | HBUINT nClasses; /* Number of classes, which is the number of indices |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 633 | * in a single line in the state array. */ |
Behdad Esfahbod | 7e6bd51 | 2019-01-17 18:24:18 -0500 | [diff] [blame] | 634 | NNOffsetTo<ClassType, HBUINT> |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 635 | classTable; /* Offset to the class table. */ |
Behdad Esfahbod | 7e6bd51 | 2019-01-17 18:24:18 -0500 | [diff] [blame] | 636 | NNOffsetTo<UnsizedArrayOf<HBUSHORT>, HBUINT> |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 637 | stateArrayTable;/* Offset to the state array. */ |
Behdad Esfahbod | 7e6bd51 | 2019-01-17 18:24:18 -0500 | [diff] [blame] | 638 | NNOffsetTo<UnsizedArrayOf<Entry<Extra> >, HBUINT> |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 639 | entryTable; /* Offset to the entry array. */ |
| 640 | |
| 641 | public: |
Behdad Esfahbod | 11dbf0f | 2018-10-30 21:49:59 -0700 | [diff] [blame] | 642 | DEFINE_SIZE_STATIC (4 * sizeof (HBUINT)); |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 643 | }; |
| 644 | |
Behdad Esfahbod | 5b4a789 | 2018-11-28 14:46:26 -0500 | [diff] [blame] | 645 | template <typename HBUCHAR> |
Ebrahim Byagowi | b053cab | 2018-10-30 18:41:34 +0330 | [diff] [blame] | 646 | struct ClassTable |
| 647 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 648 | unsigned int get_class (hb_codepoint_t glyph_id, unsigned int outOfRange) const |
Ebrahim Byagowi | b053cab | 2018-10-30 18:41:34 +0330 | [diff] [blame] | 649 | { |
Behdad Esfahbod | b11830c | 2018-11-06 15:23:18 -0500 | [diff] [blame] | 650 | unsigned int i = glyph_id - firstGlyph; |
| 651 | return i >= classArray.len ? outOfRange : classArray.arrayZ[i]; |
Ebrahim Byagowi | b053cab | 2018-10-30 18:41:34 +0330 | [diff] [blame] | 652 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 653 | unsigned int get_class (hb_codepoint_t glyph_id, |
| 654 | unsigned int num_glyphs HB_UNUSED, |
| 655 | unsigned int outOfRange) const |
Behdad Esfahbod | 5b4a789 | 2018-11-28 14:46:26 -0500 | [diff] [blame] | 656 | { |
| 657 | return get_class (glyph_id, outOfRange); |
| 658 | } |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 659 | bool sanitize (hb_sanitize_context_t *c) const |
Ebrahim Byagowi | b053cab | 2018-10-30 18:41:34 +0330 | [diff] [blame] | 660 | { |
| 661 | TRACE_SANITIZE (this); |
Behdad Esfahbod | b11830c | 2018-11-06 15:23:18 -0500 | [diff] [blame] | 662 | return_trace (c->check_struct (this) && classArray.sanitize (c)); |
Ebrahim Byagowi | b053cab | 2018-10-30 18:41:34 +0330 | [diff] [blame] | 663 | } |
| 664 | protected: |
Behdad Esfahbod | b11830c | 2018-11-06 15:23:18 -0500 | [diff] [blame] | 665 | GlyphID firstGlyph; /* First glyph index included in the trimmed array. */ |
Behdad Esfahbod | 5b4a789 | 2018-11-28 14:46:26 -0500 | [diff] [blame] | 666 | ArrayOf<HBUCHAR> classArray; /* The class codes (indexed by glyph index minus |
Behdad Esfahbod | b11830c | 2018-11-06 15:23:18 -0500 | [diff] [blame] | 667 | * firstGlyph). */ |
Ebrahim Byagowi | b053cab | 2018-10-30 18:41:34 +0330 | [diff] [blame] | 668 | public: |
Behdad Esfahbod | b11830c | 2018-11-06 15:23:18 -0500 | [diff] [blame] | 669 | DEFINE_SIZE_ARRAY (4, classArray); |
Ebrahim Byagowi | b053cab | 2018-10-30 18:41:34 +0330 | [diff] [blame] | 670 | }; |
| 671 | |
Behdad Esfahbod | 241ba7d | 2018-11-07 11:51:40 -0500 | [diff] [blame] | 672 | struct ObsoleteTypes |
Ebrahim Byagowi | b053cab | 2018-10-30 18:41:34 +0330 | [diff] [blame] | 673 | { |
Behdad Esfahbod | 39e1b6d | 2019-01-22 12:07:43 +0100 | [diff] [blame] | 674 | static constexpr bool extended = false; |
Ebrahim Byagowi | b053cab | 2018-10-30 18:41:34 +0330 | [diff] [blame] | 675 | typedef HBUINT16 HBUINT; |
| 676 | typedef HBUINT8 HBUSHORT; |
Behdad Esfahbod | f9a9c0f | 2018-11-28 14:51:56 -0500 | [diff] [blame] | 677 | typedef ClassTable<HBUINT8> ClassTypeNarrow; |
| 678 | typedef ClassTable<HBUINT16> ClassTypeWide; |
Behdad Esfahbod | 5b4a789 | 2018-11-28 14:46:26 -0500 | [diff] [blame] | 679 | |
Behdad Esfahbod | 36e90ef | 2018-10-31 15:09:09 -0700 | [diff] [blame] | 680 | template <typename T> |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 681 | static unsigned int offsetToIndex (unsigned int offset, |
| 682 | const void *base, |
| 683 | const T *array) |
Behdad Esfahbod | 36e90ef | 2018-10-31 15:09:09 -0700 | [diff] [blame] | 684 | { |
| 685 | return (offset - ((const char *) array - (const char *) base)) / sizeof (T); |
| 686 | } |
| 687 | template <typename T> |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 688 | static unsigned int byteOffsetToIndex (unsigned int offset, |
| 689 | const void *base, |
| 690 | const T *array) |
Behdad Esfahbod | 42a2b49 | 2018-11-28 15:24:30 -0500 | [diff] [blame] | 691 | { |
| 692 | return offsetToIndex (offset, base, array); |
| 693 | } |
| 694 | template <typename T> |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 695 | static unsigned int wordOffsetToIndex (unsigned int offset, |
| 696 | const void *base, |
| 697 | const T *array) |
Behdad Esfahbod | 36e90ef | 2018-10-31 15:09:09 -0700 | [diff] [blame] | 698 | { |
| 699 | return offsetToIndex (2 * offset, base, array); |
| 700 | } |
Ebrahim Byagowi | b053cab | 2018-10-30 18:41:34 +0330 | [diff] [blame] | 701 | }; |
Behdad Esfahbod | 241ba7d | 2018-11-07 11:51:40 -0500 | [diff] [blame] | 702 | struct ExtendedTypes |
Ebrahim Byagowi | b053cab | 2018-10-30 18:41:34 +0330 | [diff] [blame] | 703 | { |
Behdad Esfahbod | 39e1b6d | 2019-01-22 12:07:43 +0100 | [diff] [blame] | 704 | static constexpr bool extended = true; |
Ebrahim Byagowi | b053cab | 2018-10-30 18:41:34 +0330 | [diff] [blame] | 705 | typedef HBUINT32 HBUINT; |
| 706 | typedef HBUINT16 HBUSHORT; |
Behdad Esfahbod | f9a9c0f | 2018-11-28 14:51:56 -0500 | [diff] [blame] | 707 | typedef Lookup<HBUINT16> ClassTypeNarrow; |
| 708 | typedef Lookup<HBUINT16> ClassTypeWide; |
Behdad Esfahbod | 5b4a789 | 2018-11-28 14:46:26 -0500 | [diff] [blame] | 709 | |
Behdad Esfahbod | 36e90ef | 2018-10-31 15:09:09 -0700 | [diff] [blame] | 710 | template <typename T> |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 711 | static unsigned int offsetToIndex (unsigned int offset, |
Behdad Esfahbod | d25a2f1 | 2018-12-23 20:19:52 -0500 | [diff] [blame] | 712 | const void *base HB_UNUSED, |
| 713 | const T *array HB_UNUSED) |
Behdad Esfahbod | 36e90ef | 2018-10-31 15:09:09 -0700 | [diff] [blame] | 714 | { |
| 715 | return offset; |
| 716 | } |
| 717 | template <typename T> |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 718 | static unsigned int byteOffsetToIndex (unsigned int offset, |
Behdad Esfahbod | d25a2f1 | 2018-12-23 20:19:52 -0500 | [diff] [blame] | 719 | const void *base HB_UNUSED, |
| 720 | const T *array HB_UNUSED) |
Behdad Esfahbod | 42a2b49 | 2018-11-28 15:24:30 -0500 | [diff] [blame] | 721 | { |
| 722 | return offset / 2; |
| 723 | } |
| 724 | template <typename T> |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 725 | static unsigned int wordOffsetToIndex (unsigned int offset, |
Behdad Esfahbod | d25a2f1 | 2018-12-23 20:19:52 -0500 | [diff] [blame] | 726 | const void *base HB_UNUSED, |
| 727 | const T *array HB_UNUSED) |
Behdad Esfahbod | 36e90ef | 2018-10-31 15:09:09 -0700 | [diff] [blame] | 728 | { |
| 729 | return offset; |
| 730 | } |
Ebrahim Byagowi | b053cab | 2018-10-30 18:41:34 +0330 | [diff] [blame] | 731 | }; |
| 732 | |
| 733 | template <typename Types, typename EntryData> |
Behdad Esfahbod | 117cfe7 | 2018-01-12 00:01:36 +0100 | [diff] [blame] | 734 | struct StateTableDriver |
| 735 | { |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 736 | StateTableDriver (const StateTable<Types, EntryData> &machine_, |
| 737 | hb_buffer_t *buffer_, |
| 738 | hb_face_t *face_) : |
Behdad Esfahbod | 117cfe7 | 2018-01-12 00:01:36 +0100 | [diff] [blame] | 739 | machine (machine_), |
| 740 | buffer (buffer_), |
Behdad Esfahbod | 54e6efa | 2018-02-04 14:58:02 -0500 | [diff] [blame] | 741 | num_glyphs (face_->get_num_glyphs ()) {} |
Behdad Esfahbod | 117cfe7 | 2018-01-12 00:01:36 +0100 | [diff] [blame] | 742 | |
| 743 | template <typename context_t> |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 744 | void drive (context_t *c) |
Behdad Esfahbod | 117cfe7 | 2018-01-12 00:01:36 +0100 | [diff] [blame] | 745 | { |
Behdad Esfahbod | e6f283e | 2018-01-19 18:08:56 -0800 | [diff] [blame] | 746 | if (!c->in_place) |
| 747 | buffer->clear_output (); |
| 748 | |
Behdad Esfahbod | 006386b | 2018-11-07 18:04:53 -0500 | [diff] [blame] | 749 | int state = StateTable<Types, EntryData>::STATE_START_OF_TEXT; |
Behdad Esfahbod | 1bb8ed8 | 2018-10-25 17:33:48 -0700 | [diff] [blame] | 750 | for (buffer->idx = 0; buffer->successful;) |
Behdad Esfahbod | 117cfe7 | 2018-01-12 00:01:36 +0100 | [diff] [blame] | 751 | { |
Behdad Esfahbod | e6f283e | 2018-01-19 18:08:56 -0800 | [diff] [blame] | 752 | unsigned int klass = buffer->idx < buffer->len ? |
Behdad Esfahbod | 4831e61 | 2018-10-05 18:14:13 +0200 | [diff] [blame] | 753 | machine.get_class (buffer->info[buffer->idx].codepoint, num_glyphs) : |
Ebrahim Byagowi | b053cab | 2018-10-30 18:41:34 +0330 | [diff] [blame] | 754 | (unsigned) StateTable<Types, EntryData>::CLASS_END_OF_TEXT; |
Behdad Esfahbod | 006386b | 2018-11-07 18:04:53 -0500 | [diff] [blame] | 755 | DEBUG_MSG (APPLY, nullptr, "c%u at %u", klass, buffer->idx); |
Behdad Esfahbod | 1ec9051 | 2019-01-24 17:21:41 +0100 | [diff] [blame] | 756 | const Entry<EntryData> &entry = machine.get_entry (state, klass); |
Behdad Esfahbod | 117cfe7 | 2018-01-12 00:01:36 +0100 | [diff] [blame] | 757 | |
Behdad Esfahbod | 54e6efa | 2018-02-04 14:58:02 -0500 | [diff] [blame] | 758 | /* Unsafe-to-break before this if not in state 0, as things might |
Behdad Esfahbod | 7ee50af | 2018-10-06 21:31:44 +0200 | [diff] [blame] | 759 | * go differently if we start from state 0 here. |
| 760 | * |
| 761 | * Ugh. The indexing here is ugly... */ |
| 762 | if (state && buffer->backtrack_len () && buffer->idx < buffer->len) |
Behdad Esfahbod | 54e6efa | 2018-02-04 14:58:02 -0500 | [diff] [blame] | 763 | { |
Behdad Esfahbod | 2971e9d | 2018-02-06 11:48:04 -0500 | [diff] [blame] | 764 | /* If there's no action and we're just epsilon-transitioning to state 0, |
| 765 | * safe to break. */ |
| 766 | if (c->is_actionable (this, entry) || |
Behdad Esfahbod | 1ec9051 | 2019-01-24 17:21:41 +0100 | [diff] [blame] | 767 | !(entry.newState == StateTable<Types, EntryData>::STATE_START_OF_TEXT && |
| 768 | entry.flags == context_t::DontAdvance)) |
Behdad Esfahbod | 7ee50af | 2018-10-06 21:31:44 +0200 | [diff] [blame] | 769 | buffer->unsafe_to_break_from_outbuffer (buffer->backtrack_len () - 1, buffer->idx + 1); |
Behdad Esfahbod | 54e6efa | 2018-02-04 14:58:02 -0500 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | /* Unsafe-to-break if end-of-text would kick in here. */ |
| 773 | if (buffer->idx + 2 <= buffer->len) |
| 774 | { |
Behdad Esfahbod | 1ec9051 | 2019-01-24 17:21:41 +0100 | [diff] [blame] | 775 | const Entry<EntryData> &end_entry = machine.get_entry (state, StateTable<Types, EntryData>::CLASS_END_OF_TEXT); |
Behdad Esfahbod | 54e6efa | 2018-02-04 14:58:02 -0500 | [diff] [blame] | 776 | if (c->is_actionable (this, end_entry)) |
| 777 | buffer->unsafe_to_break (buffer->idx, buffer->idx + 2); |
| 778 | } |
| 779 | |
Behdad Esfahbod | b976940 | 2019-01-24 18:01:07 +0100 | [diff] [blame^] | 780 | c->transition (this, entry); |
Behdad Esfahbod | f760022 | 2018-01-12 11:09:21 +0100 | [diff] [blame] | 781 | |
Behdad Esfahbod | 1ec9051 | 2019-01-24 17:21:41 +0100 | [diff] [blame] | 782 | state = machine.new_state (entry.newState); |
Behdad Esfahbod | 1909072 | 2018-11-07 16:42:16 -0500 | [diff] [blame] | 783 | DEBUG_MSG (APPLY, nullptr, "s%d", state); |
Behdad Esfahbod | e6f283e | 2018-01-19 18:08:56 -0800 | [diff] [blame] | 784 | |
| 785 | if (buffer->idx == buffer->len) |
Behdad Esfahbod | 0cf282a | 2018-10-30 20:51:44 -0700 | [diff] [blame] | 786 | break; |
Behdad Esfahbod | e6f283e | 2018-01-19 18:08:56 -0800 | [diff] [blame] | 787 | |
Behdad Esfahbod | 1ec9051 | 2019-01-24 17:21:41 +0100 | [diff] [blame] | 788 | if (!(entry.flags & context_t::DontAdvance) || buffer->max_ops-- <= 0) |
Behdad Esfahbod | 0cf282a | 2018-10-30 20:51:44 -0700 | [diff] [blame] | 789 | buffer->next_glyph (); |
Behdad Esfahbod | 117cfe7 | 2018-01-12 00:01:36 +0100 | [diff] [blame] | 790 | } |
| 791 | |
Behdad Esfahbod | 57051b4 | 2018-01-12 11:42:25 +0100 | [diff] [blame] | 792 | if (!c->in_place) |
| 793 | { |
Behdad Esfahbod | 7efa382 | 2018-10-14 19:30:44 -0700 | [diff] [blame] | 794 | for (; buffer->successful && buffer->idx < buffer->len;) |
| 795 | buffer->next_glyph (); |
Behdad Esfahbod | 17335a8 | 2018-11-04 02:25:07 -0500 | [diff] [blame] | 796 | buffer->swap_buffers (); |
Behdad Esfahbod | 57051b4 | 2018-01-12 11:42:25 +0100 | [diff] [blame] | 797 | } |
Behdad Esfahbod | 117cfe7 | 2018-01-12 00:01:36 +0100 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | public: |
Ebrahim Byagowi | b053cab | 2018-10-30 18:41:34 +0330 | [diff] [blame] | 801 | const StateTable<Types, EntryData> &machine; |
Behdad Esfahbod | 117cfe7 | 2018-01-12 00:01:36 +0100 | [diff] [blame] | 802 | hb_buffer_t *buffer; |
Behdad Esfahbod | 117cfe7 | 2018-01-12 00:01:36 +0100 | [diff] [blame] | 803 | unsigned int num_glyphs; |
Behdad Esfahbod | 117cfe7 | 2018-01-12 00:01:36 +0100 | [diff] [blame] | 804 | }; |
| 805 | |
Behdad Esfahbod | ca42d96 | 2018-01-11 09:15:34 +0100 | [diff] [blame] | 806 | |
Behdad Esfahbod | 7bb4da7 | 2018-10-11 00:52:07 -0400 | [diff] [blame] | 807 | struct ankr; |
Behdad Esfahbod | 046690a | 2018-01-17 16:59:55 -0800 | [diff] [blame] | 808 | |
| 809 | struct hb_aat_apply_context_t : |
| 810 | hb_dispatch_context_t<hb_aat_apply_context_t, bool, HB_DEBUG_APPLY> |
| 811 | { |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 812 | const char *get_name () { return "APPLY"; } |
Behdad Esfahbod | 046690a | 2018-01-17 16:59:55 -0800 | [diff] [blame] | 813 | template <typename T> |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 814 | return_t dispatch (const T &obj) { return obj.apply (this); } |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 815 | static return_t default_return_value () { return false; } |
Behdad Esfahbod | 046690a | 2018-01-17 16:59:55 -0800 | [diff] [blame] | 816 | bool stop_sublookup_iteration (return_t r) const { return r; } |
| 817 | |
Behdad Esfahbod | c221dc0 | 2018-11-14 14:49:34 -0500 | [diff] [blame] | 818 | const hb_ot_shape_plan_t *plan; |
Behdad Esfahbod | 046690a | 2018-01-17 16:59:55 -0800 | [diff] [blame] | 819 | hb_font_t *font; |
| 820 | hb_face_t *face; |
| 821 | hb_buffer_t *buffer; |
Behdad Esfahbod | f07ce66 | 2018-01-19 16:52:01 -0800 | [diff] [blame] | 822 | hb_sanitize_context_t sanitizer; |
Behdad Esfahbod | b605db2 | 2018-11-04 12:58:02 -0500 | [diff] [blame] | 823 | const ankr *ankr_table; |
Behdad Esfahbod | 046690a | 2018-01-17 16:59:55 -0800 | [diff] [blame] | 824 | |
Behdad Esfahbod | 126ffdb | 2018-02-07 12:26:41 -0500 | [diff] [blame] | 825 | /* Unused. For debug tracing only. */ |
| 826 | unsigned int lookup_index; |
| 827 | unsigned int debug_depth; |
| 828 | |
Behdad Esfahbod | c221dc0 | 2018-11-14 14:49:34 -0500 | [diff] [blame] | 829 | HB_INTERNAL hb_aat_apply_context_t (const hb_ot_shape_plan_t *plan_, |
Behdad Esfahbod | b605db2 | 2018-11-04 12:58:02 -0500 | [diff] [blame] | 830 | hb_font_t *font_, |
| 831 | hb_buffer_t *buffer_, |
| 832 | hb_blob_t *blob = const_cast<hb_blob_t *> (&Null(hb_blob_t))); |
| 833 | |
Ebrahim Byagowi | e412008 | 2018-12-17 21:31:01 +0330 | [diff] [blame] | 834 | HB_INTERNAL ~hb_aat_apply_context_t (); |
Behdad Esfahbod | b605db2 | 2018-11-04 12:58:02 -0500 | [diff] [blame] | 835 | |
Behdad Esfahbod | 347ad45 | 2019-01-17 17:47:29 -0500 | [diff] [blame] | 836 | HB_INTERNAL void set_ankr_table (const AAT::ankr *ankr_table_); |
Behdad Esfahbod | f07ce66 | 2018-01-19 16:52:01 -0800 | [diff] [blame] | 837 | |
Ebrahim Byagowi | b2ebaa9 | 2018-12-16 22:38:10 +0330 | [diff] [blame] | 838 | void set_lookup_index (unsigned int i) { lookup_index = i; } |
Behdad Esfahbod | 046690a | 2018-01-17 16:59:55 -0800 | [diff] [blame] | 839 | }; |
| 840 | |
| 841 | |
Behdad Esfahbod | a0175e7 | 2017-08-17 16:55:54 -0700 | [diff] [blame] | 842 | } /* namespace AAT */ |
| 843 | |
| 844 | |
Behdad Esfahbod | c77ae40 | 2018-08-25 22:36:36 -0700 | [diff] [blame] | 845 | #endif /* HB_AAT_LAYOUT_COMMON_HH */ |