Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 1 | /* |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 2 | * Copyright (C) 2007,2008,2009 Red Hat, Inc. |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 3 | * |
| 4 | * This is part of HarfBuzz, an OpenType Layout engine 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 | * Red Hat Author(s): Behdad Esfahbod |
| 25 | */ |
| 26 | |
Behdad Esfahbod | 5f5b24f | 2009-08-02 20:03:12 -0400 | [diff] [blame] | 27 | #ifndef HB_OT_LAYOUT_GSUB_PRIVATE_HH |
| 28 | #define HB_OT_LAYOUT_GSUB_PRIVATE_HH |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 29 | |
Behdad Esfahbod | 5f5b24f | 2009-08-02 20:03:12 -0400 | [diff] [blame] | 30 | #include "hb-ot-layout-gsubgpos-private.hh" |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 31 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 32 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 33 | struct SingleSubstFormat1 |
| 34 | { |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 35 | friend struct SingleSubst; |
| 36 | |
| 37 | private: |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 38 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 39 | inline bool apply (APPLY_ARG_DEF) const |
| 40 | { |
| 41 | hb_codepoint_t glyph_id = IN_CURGLYPH (); |
Behdad Esfahbod | 238c855 | 2009-05-17 00:22:37 -0400 | [diff] [blame] | 42 | unsigned int index = (this+coverage) (glyph_id); |
Behdad Esfahbod | 4acaffd | 2009-05-18 05:29:29 -0400 | [diff] [blame] | 43 | if (HB_LIKELY (index == NOT_COVERED)) |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 44 | return false; |
| 45 | |
| 46 | glyph_id += deltaGlyphID; |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 47 | _hb_buffer_replace_glyph (buffer, glyph_id); |
| 48 | |
Behdad Esfahbod | 4189b92 | 2009-05-26 17:31:56 -0400 | [diff] [blame] | 49 | /* We inherit the old glyph class to the substituted glyph */ |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 50 | if (_hb_ot_layout_has_new_glyph_classes (context->face)) |
| 51 | _hb_ot_layout_set_glyph_property (context->face, glyph_id, property); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 52 | |
| 53 | return true; |
| 54 | } |
| 55 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 56 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 57 | return SANITIZE_THIS (coverage) && SANITIZE (deltaGlyphID); |
| 58 | } |
| 59 | |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 60 | private: |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 61 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 238c855 | 2009-05-17 00:22:37 -0400 | [diff] [blame] | 62 | OffsetTo<Coverage> |
| 63 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 64 | * beginning of Substitution table */ |
| 65 | SHORT deltaGlyphID; /* Add to original GlyphID to get |
| 66 | * substitute GlyphID */ |
| 67 | }; |
| 68 | ASSERT_SIZE (SingleSubstFormat1, 6); |
| 69 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 70 | struct SingleSubstFormat2 |
| 71 | { |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 72 | friend struct SingleSubst; |
| 73 | |
| 74 | private: |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 75 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 76 | inline bool apply (APPLY_ARG_DEF) const |
| 77 | { |
| 78 | hb_codepoint_t glyph_id = IN_CURGLYPH (); |
Behdad Esfahbod | 238c855 | 2009-05-17 00:22:37 -0400 | [diff] [blame] | 79 | unsigned int index = (this+coverage) (glyph_id); |
Behdad Esfahbod | 4acaffd | 2009-05-18 05:29:29 -0400 | [diff] [blame] | 80 | if (HB_LIKELY (index == NOT_COVERED)) |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 81 | return false; |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 82 | |
Behdad Esfahbod | 4acaffd | 2009-05-18 05:29:29 -0400 | [diff] [blame] | 83 | if (HB_UNLIKELY (index >= substitute.len)) |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 84 | return false; |
| 85 | |
| 86 | glyph_id = substitute[index]; |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 87 | _hb_buffer_replace_glyph (buffer, glyph_id); |
| 88 | |
Behdad Esfahbod | 4189b92 | 2009-05-26 17:31:56 -0400 | [diff] [blame] | 89 | /* We inherit the old glyph class to the substituted glyph */ |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 90 | if (_hb_ot_layout_has_new_glyph_classes (context->face)) |
| 91 | _hb_ot_layout_set_glyph_property (context->face, glyph_id, property); |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 92 | |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 93 | return true; |
| 94 | } |
| 95 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 96 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 97 | return SANITIZE_THIS (coverage) && SANITIZE (substitute); |
| 98 | } |
| 99 | |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 100 | private: |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 101 | USHORT format; /* Format identifier--format = 2 */ |
Behdad Esfahbod | 238c855 | 2009-05-17 00:22:37 -0400 | [diff] [blame] | 102 | OffsetTo<Coverage> |
| 103 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 104 | * beginning of Substitution table */ |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 105 | ArrayOf<GlyphID> |
| 106 | substitute; /* Array of substitute |
| 107 | * GlyphIDs--ordered by Coverage Index */ |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 108 | }; |
| 109 | ASSERT_SIZE (SingleSubstFormat2, 6); |
| 110 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 111 | struct SingleSubst |
| 112 | { |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 113 | friend struct SubstLookupSubTable; |
| 114 | |
Behdad Esfahbod | 4f27ce7 | 2009-04-16 13:40:13 -0400 | [diff] [blame] | 115 | private: |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 116 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 117 | inline bool apply (APPLY_ARG_DEF) const |
| 118 | { |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 119 | switch (u.format) { |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 120 | case 1: return u.format1->apply (APPLY_ARG); |
| 121 | case 2: return u.format2->apply (APPLY_ARG); |
Behdad Esfahbod | 38b011a | 2009-05-04 20:21:57 -0400 | [diff] [blame] | 122 | default:return false; |
| 123 | } |
| 124 | } |
| 125 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 126 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 127 | if (!SANITIZE (u.format)) return false; |
| 128 | switch (u.format) { |
| 129 | case 1: return u.format1->sanitize (SANITIZE_ARG); |
| 130 | case 2: return u.format2->sanitize (SANITIZE_ARG); |
| 131 | default:return true; |
| 132 | } |
| 133 | } |
| 134 | |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 135 | private: |
| 136 | union { |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 137 | USHORT format; /* Format identifier */ |
| 138 | SingleSubstFormat1 format1[]; |
| 139 | SingleSubstFormat2 format2[]; |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 140 | } u; |
| 141 | }; |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 142 | ASSERT_SIZE (SingleSubst, 2); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 143 | |
| 144 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 145 | struct Sequence |
| 146 | { |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 147 | friend struct MultipleSubstFormat1; |
| 148 | |
| 149 | private: |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 150 | inline bool apply (APPLY_ARG_DEF) const |
| 151 | { |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 152 | if (HB_UNLIKELY (!substitute.len)) |
Behdad Esfahbod | c9c6a78 | 2009-05-05 16:22:02 -0400 | [diff] [blame] | 153 | return false; |
| 154 | |
Behdad Esfahbod | 88a5f5a | 2009-05-25 03:39:11 -0400 | [diff] [blame] | 155 | _hb_buffer_add_output_glyphs (buffer, 1, |
| 156 | substitute.len, (const uint16_t *) substitute.array, |
| 157 | 0xFFFF, 0xFFFF); |
Behdad Esfahbod | c9c6a78 | 2009-05-05 16:22:02 -0400 | [diff] [blame] | 158 | |
Behdad Esfahbod | 4189b92 | 2009-05-26 17:31:56 -0400 | [diff] [blame] | 159 | /* This is a guess only ... */ |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 160 | if (_hb_ot_layout_has_new_glyph_classes (context->face)) |
Behdad Esfahbod | c9c6a78 | 2009-05-05 16:22:02 -0400 | [diff] [blame] | 161 | { |
Behdad Esfahbod | 4189b92 | 2009-05-26 17:31:56 -0400 | [diff] [blame] | 162 | if (property == HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE) |
Behdad Esfahbod | c9c6a78 | 2009-05-05 16:22:02 -0400 | [diff] [blame] | 163 | property = HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH; |
| 164 | |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 165 | unsigned int count = substitute.len; |
| 166 | for (unsigned int n = 0; n < count; n++) |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 167 | _hb_ot_layout_set_glyph_property (context->face, substitute[n], property); |
Behdad Esfahbod | c9c6a78 | 2009-05-05 16:22:02 -0400 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | return true; |
| 171 | } |
| 172 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 173 | public: |
| 174 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 175 | return SANITIZE (substitute); |
| 176 | } |
| 177 | |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 178 | private: |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 179 | ArrayOf<GlyphID> |
| 180 | substitute; /* String of GlyphIDs to substitute */ |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 181 | }; |
Behdad Esfahbod | 8b83580 | 2009-05-16 22:48:14 -0400 | [diff] [blame] | 182 | ASSERT_SIZE (Sequence, 2); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 183 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 184 | struct MultipleSubstFormat1 |
| 185 | { |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 186 | friend struct MultipleSubst; |
| 187 | |
| 188 | private: |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 189 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 190 | inline bool apply (APPLY_ARG_DEF) const |
| 191 | { |
Behdad Esfahbod | 30bd763 | 2009-04-15 22:56:15 -0400 | [diff] [blame] | 192 | |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 193 | unsigned int index = (this+coverage) (IN_CURGLYPH ()); |
Behdad Esfahbod | 4acaffd | 2009-05-18 05:29:29 -0400 | [diff] [blame] | 194 | if (HB_LIKELY (index == NOT_COVERED)) |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 195 | return false; |
| 196 | |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 197 | return (this+sequence[index]).apply (APPLY_ARG); |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 198 | } |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 199 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 200 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 201 | return SANITIZE_THIS2 (coverage, sequence); |
| 202 | } |
| 203 | |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 204 | private: |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 205 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 238c855 | 2009-05-17 00:22:37 -0400 | [diff] [blame] | 206 | OffsetTo<Coverage> |
| 207 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 208 | * beginning of Substitution table */ |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 209 | OffsetArrayOf<Sequence> |
| 210 | sequence; /* Array of Sequence tables |
| 211 | * ordered by Coverage Index */ |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 212 | }; |
| 213 | ASSERT_SIZE (MultipleSubstFormat1, 6); |
| 214 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 215 | struct MultipleSubst |
| 216 | { |
Behdad Esfahbod | 4f27ce7 | 2009-04-16 13:40:13 -0400 | [diff] [blame] | 217 | friend struct SubstLookupSubTable; |
| 218 | |
| 219 | private: |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 220 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 221 | inline bool apply (APPLY_ARG_DEF) const |
| 222 | { |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 223 | switch (u.format) { |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 224 | case 1: return u.format1->apply (APPLY_ARG); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 225 | default:return false; |
| 226 | } |
| 227 | } |
| 228 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 229 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 230 | if (!SANITIZE (u.format)) return false; |
| 231 | switch (u.format) { |
| 232 | case 1: return u.format1->sanitize (SANITIZE_ARG); |
| 233 | default:return true; |
| 234 | } |
| 235 | } |
| 236 | |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 237 | private: |
| 238 | union { |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 239 | USHORT format; /* Format identifier */ |
| 240 | MultipleSubstFormat1 format1[]; |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 241 | } u; |
| 242 | }; |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 243 | ASSERT_SIZE (MultipleSubst, 2); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 244 | |
| 245 | |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 246 | typedef ArrayOf<GlyphID> AlternateSet; /* Array of alternate GlyphIDs--in |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 247 | * arbitrary order */ |
Behdad Esfahbod | 8b83580 | 2009-05-16 22:48:14 -0400 | [diff] [blame] | 248 | ASSERT_SIZE (AlternateSet, 2); |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 249 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 250 | struct AlternateSubstFormat1 |
| 251 | { |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 252 | friend struct AlternateSubst; |
| 253 | |
| 254 | private: |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 255 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 256 | inline bool apply (APPLY_ARG_DEF) const |
| 257 | { |
Behdad Esfahbod | a84e71a | 2009-04-16 16:53:40 -0400 | [diff] [blame] | 258 | hb_codepoint_t glyph_id = IN_CURGLYPH (); |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 259 | |
Behdad Esfahbod | 238c855 | 2009-05-17 00:22:37 -0400 | [diff] [blame] | 260 | unsigned int index = (this+coverage) (glyph_id); |
Behdad Esfahbod | 4acaffd | 2009-05-18 05:29:29 -0400 | [diff] [blame] | 261 | if (HB_LIKELY (index == NOT_COVERED)) |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 262 | return false; |
| 263 | |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 264 | const AlternateSet &alt_set = this+alternateSet[index]; |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 265 | |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 266 | if (HB_UNLIKELY (!alt_set.len)) |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 267 | return false; |
| 268 | |
| 269 | unsigned int alt_index = 0; |
| 270 | |
| 271 | /* XXX callback to user to choose alternate |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 272 | if (context->face->altfunc) |
| 273 | alt_index = (context->face->altfunc)(context->layout, buffer, |
Behdad Esfahbod | d6aae5f | 2009-05-18 04:25:22 -0400 | [diff] [blame] | 274 | buffer->out_pos, glyph_id, |
| 275 | alt_set.len, alt_set.array); |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 276 | */ |
| 277 | |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 278 | if (HB_UNLIKELY (alt_index >= alt_set.len)) |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 279 | return false; |
| 280 | |
| 281 | glyph_id = alt_set[alt_index]; |
| 282 | |
Behdad Esfahbod | 15c3e75 | 2009-05-17 06:03:42 -0400 | [diff] [blame] | 283 | _hb_buffer_replace_glyph (buffer, glyph_id); |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 284 | |
Behdad Esfahbod | 4189b92 | 2009-05-26 17:31:56 -0400 | [diff] [blame] | 285 | /* We inherit the old glyph class to the substituted glyph */ |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 286 | if (_hb_ot_layout_has_new_glyph_classes (context->face)) |
| 287 | _hb_ot_layout_set_glyph_property (context->face, glyph_id, property); |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 288 | |
| 289 | return true; |
| 290 | } |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 291 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 292 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 293 | return SANITIZE_THIS2 (coverage, alternateSet); |
| 294 | } |
| 295 | |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 296 | private: |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 297 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 238c855 | 2009-05-17 00:22:37 -0400 | [diff] [blame] | 298 | OffsetTo<Coverage> |
| 299 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 300 | * beginning of Substitution table */ |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 301 | OffsetArrayOf<AlternateSet> |
| 302 | alternateSet; /* Array of AlternateSet tables |
| 303 | * ordered by Coverage Index */ |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 304 | }; |
| 305 | ASSERT_SIZE (AlternateSubstFormat1, 6); |
| 306 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 307 | struct AlternateSubst |
| 308 | { |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 309 | friend struct SubstLookupSubTable; |
| 310 | |
| 311 | private: |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 312 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 313 | inline bool apply (APPLY_ARG_DEF) const |
| 314 | { |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 315 | switch (u.format) { |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 316 | case 1: return u.format1->apply (APPLY_ARG); |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 317 | default:return false; |
| 318 | } |
| 319 | } |
| 320 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 321 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 322 | if (!SANITIZE (u.format)) return false; |
| 323 | switch (u.format) { |
| 324 | case 1: return u.format1->sanitize (SANITIZE_ARG); |
| 325 | default:return true; |
| 326 | } |
| 327 | } |
| 328 | |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 329 | private: |
| 330 | union { |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 331 | USHORT format; /* Format identifier */ |
| 332 | AlternateSubstFormat1 format1[]; |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 333 | } u; |
| 334 | }; |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 335 | ASSERT_SIZE (AlternateSubst, 2); |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 336 | |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 337 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 338 | struct Ligature |
| 339 | { |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 340 | friend struct LigatureSet; |
| 341 | |
| 342 | private: |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 343 | inline bool apply (APPLY_ARG_DEF, bool is_mark) const |
| 344 | { |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 345 | unsigned int i, j; |
Behdad Esfahbod | e8cbaaf | 2009-05-18 02:03:58 -0400 | [diff] [blame] | 346 | unsigned int count = component.len; |
Behdad Esfahbod | 122f21f | 2009-05-18 04:21:53 -0400 | [diff] [blame] | 347 | unsigned int end = MIN (buffer->in_length, buffer->in_pos + context_length); |
| 348 | if (HB_UNLIKELY (buffer->in_pos + count > end)) |
| 349 | return false; |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 350 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 351 | for (i = 1, j = buffer->in_pos + 1; i < count; i++, j++) |
| 352 | { |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 353 | while (_hb_ot_layout_skip_mark (context->face, IN_INFO (j), lookup_flag, &property)) |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 354 | { |
Behdad Esfahbod | 122f21f | 2009-05-18 04:21:53 -0400 | [diff] [blame] | 355 | if (HB_UNLIKELY (j + count - i == end)) |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 356 | return false; |
| 357 | j++; |
| 358 | } |
| 359 | |
Behdad Esfahbod | 5130c35 | 2009-05-26 15:45:41 -0400 | [diff] [blame] | 360 | if (!(property & HB_OT_LAYOUT_GLYPH_CLASS_MARK)) |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 361 | is_mark = FALSE; |
| 362 | |
Behdad Esfahbod | 4189b92 | 2009-05-26 17:31:56 -0400 | [diff] [blame] | 363 | if (HB_LIKELY (IN_GLYPH (j) != component[i])) |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 364 | return false; |
| 365 | } |
Behdad Esfahbod | 4189b92 | 2009-05-26 17:31:56 -0400 | [diff] [blame] | 366 | /* This is just a guess ... */ |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 367 | if (_hb_ot_layout_has_new_glyph_classes (context->face)) |
| 368 | _hb_ot_layout_set_glyph_class (context->face, ligGlyph, |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 369 | is_mark ? HB_OT_LAYOUT_GLYPH_CLASS_MARK |
| 370 | : HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE); |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 371 | |
| 372 | if (j == buffer->in_pos + i) /* No input glyphs skipped */ |
| 373 | /* We don't use a new ligature ID if there are no skipped |
| 374 | glyphs and the ligature already has an ID. */ |
Behdad Esfahbod | 88a5f5a | 2009-05-25 03:39:11 -0400 | [diff] [blame] | 375 | _hb_buffer_add_output_glyphs (buffer, i, |
| 376 | 1, (const uint16_t *) &ligGlyph, |
| 377 | 0xFFFF, |
| 378 | IN_LIGID (buffer->in_pos) ? |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 379 | 0xFFFF : _hb_buffer_allocate_lig_id (buffer)); |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 380 | else |
| 381 | { |
Behdad Esfahbod | c968fc2 | 2009-05-25 04:04:24 -0400 | [diff] [blame] | 382 | unsigned int lig_id = _hb_buffer_allocate_lig_id (buffer); |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 383 | _hb_buffer_add_output_glyph (buffer, ligGlyph, 0xFFFF, lig_id); |
| 384 | |
| 385 | /* Now we must do a second loop to copy the skipped glyphs to |
| 386 | `out' and assign component values to it. We start with the |
| 387 | glyph after the first component. Glyphs between component |
| 388 | i and i+1 belong to component i. Together with the lig_id |
| 389 | value it is later possible to check whether a specific |
| 390 | component value really belongs to a given ligature. */ |
| 391 | |
Behdad Esfahbod | 19fc24f | 2009-05-17 09:45:32 -0400 | [diff] [blame] | 392 | for ( i = 1; i < count; i++ ) |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 393 | { |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 394 | while (_hb_ot_layout_skip_mark (context->face, IN_CURINFO (), lookup_flag, NULL)) |
Behdad Esfahbod | 4189b92 | 2009-05-26 17:31:56 -0400 | [diff] [blame] | 395 | _hb_buffer_add_output_glyph (buffer, IN_CURGLYPH (), i - 1, lig_id); |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 396 | |
| 397 | (buffer->in_pos)++; |
| 398 | } |
| 399 | |
Behdad Esfahbod | d6aae5f | 2009-05-18 04:25:22 -0400 | [diff] [blame] | 400 | /* TODO We should possibly reassign lig_id and component for any |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 401 | * components of a previous ligature that s now being removed as part of |
| 402 | * this ligature. */ |
| 403 | } |
| 404 | |
| 405 | return true; |
| 406 | } |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 407 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 408 | public: |
| 409 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 410 | return SANITIZE2 (ligGlyph, component); |
| 411 | } |
| 412 | |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 413 | private: |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 414 | GlyphID ligGlyph; /* GlyphID of ligature to substitute */ |
Behdad Esfahbod | e8cbaaf | 2009-05-18 02:03:58 -0400 | [diff] [blame] | 415 | HeadlessArrayOf<GlyphID> |
| 416 | component; /* Array of component GlyphIDs--start |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 417 | * with the second component--ordered |
| 418 | * in writing direction */ |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 419 | }; |
Behdad Esfahbod | 8b83580 | 2009-05-16 22:48:14 -0400 | [diff] [blame] | 420 | ASSERT_SIZE (Ligature, 4); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 421 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 422 | struct LigatureSet |
| 423 | { |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 424 | friend struct LigatureSubstFormat1; |
| 425 | |
| 426 | private: |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 427 | inline bool apply (APPLY_ARG_DEF, bool is_mark) const |
| 428 | { |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 429 | unsigned int num_ligs = ligature.len; |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 430 | for (unsigned int i = 0; i < num_ligs; i++) |
| 431 | { |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 432 | const Ligature &lig = this+ligature[i]; |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 433 | if (lig.apply (APPLY_ARG, is_mark)) |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 434 | return true; |
| 435 | } |
| 436 | |
| 437 | return false; |
| 438 | } |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 439 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 440 | public: |
| 441 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 442 | return SANITIZE_THIS (ligature); |
| 443 | } |
| 444 | |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 445 | private: |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 446 | OffsetArrayOf<Ligature> |
| 447 | ligature; /* Array LigatureSet tables |
| 448 | * ordered by preference */ |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 449 | }; |
Behdad Esfahbod | 8b83580 | 2009-05-16 22:48:14 -0400 | [diff] [blame] | 450 | ASSERT_SIZE (LigatureSet, 2); |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 451 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 452 | struct LigatureSubstFormat1 |
| 453 | { |
Behdad Esfahbod | a84e71a | 2009-04-16 16:53:40 -0400 | [diff] [blame] | 454 | friend struct LigatureSubst; |
| 455 | |
| 456 | private: |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 457 | inline bool apply (APPLY_ARG_DEF) const |
| 458 | { |
Behdad Esfahbod | a84e71a | 2009-04-16 16:53:40 -0400 | [diff] [blame] | 459 | hb_codepoint_t glyph_id = IN_CURGLYPH (); |
| 460 | |
Behdad Esfahbod | 5130c35 | 2009-05-26 15:45:41 -0400 | [diff] [blame] | 461 | bool first_is_mark = !!(property & HB_OT_LAYOUT_GLYPH_CLASS_MARK); |
Behdad Esfahbod | a84e71a | 2009-04-16 16:53:40 -0400 | [diff] [blame] | 462 | |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 463 | unsigned int index = (this+coverage) (glyph_id); |
Behdad Esfahbod | 4acaffd | 2009-05-18 05:29:29 -0400 | [diff] [blame] | 464 | if (HB_LIKELY (index == NOT_COVERED)) |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 465 | return false; |
| 466 | |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 467 | const LigatureSet &lig_set = this+ligatureSet[index]; |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 468 | return lig_set.apply (APPLY_ARG, first_is_mark); |
Behdad Esfahbod | a84e71a | 2009-04-16 16:53:40 -0400 | [diff] [blame] | 469 | } |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 470 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 471 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 472 | return SANITIZE_THIS2 (coverage, ligatureSet); |
| 473 | } |
| 474 | |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 475 | private: |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 476 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 238c855 | 2009-05-17 00:22:37 -0400 | [diff] [blame] | 477 | OffsetTo<Coverage> |
| 478 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 479 | * beginning of Substitution table */ |
Behdad Esfahbod | d79cae0 | 2009-05-18 13:50:15 -0400 | [diff] [blame] | 480 | OffsetArrayOf<LigatureSet> |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 481 | ligatureSet; /* Array LigatureSet tables |
| 482 | * ordered by Coverage Index */ |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 483 | }; |
| 484 | ASSERT_SIZE (LigatureSubstFormat1, 6); |
| 485 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 486 | struct LigatureSubst |
| 487 | { |
Behdad Esfahbod | a84e71a | 2009-04-16 16:53:40 -0400 | [diff] [blame] | 488 | friend struct SubstLookupSubTable; |
| 489 | |
| 490 | private: |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 491 | inline bool apply (APPLY_ARG_DEF) const |
| 492 | { |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 493 | switch (u.format) { |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 494 | case 1: return u.format1->apply (APPLY_ARG); |
Behdad Esfahbod | a84e71a | 2009-04-16 16:53:40 -0400 | [diff] [blame] | 495 | default:return false; |
| 496 | } |
| 497 | } |
| 498 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 499 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 500 | if (!SANITIZE (u.format)) return false; |
| 501 | switch (u.format) { |
| 502 | case 1: return u.format1->sanitize (SANITIZE_ARG); |
| 503 | default:return true; |
| 504 | } |
| 505 | } |
| 506 | |
Behdad Esfahbod | a84e71a | 2009-04-16 16:53:40 -0400 | [diff] [blame] | 507 | private: |
| 508 | union { |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 509 | USHORT format; /* Format identifier */ |
| 510 | LigatureSubstFormat1 format1[]; |
Behdad Esfahbod | a84e71a | 2009-04-16 16:53:40 -0400 | [diff] [blame] | 511 | } u; |
| 512 | }; |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 513 | ASSERT_SIZE (LigatureSubst, 2); |
Behdad Esfahbod | a84e71a | 2009-04-16 16:53:40 -0400 | [diff] [blame] | 514 | |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 515 | |
Behdad Esfahbod | c43562b | 2009-05-15 18:54:53 -0400 | [diff] [blame] | 516 | |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 517 | static inline bool substitute_lookup (APPLY_ARG_DEF, unsigned int lookup_index); |
Behdad Esfahbod | a162552 | 2009-05-17 07:52:11 -0400 | [diff] [blame] | 518 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 519 | struct ContextSubst : Context |
| 520 | { |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 521 | friend struct SubstLookupSubTable; |
| 522 | |
| 523 | private: |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 524 | inline bool apply (APPLY_ARG_DEF) const |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 525 | { return Context::apply (APPLY_ARG, substitute_lookup); } |
Behdad Esfahbod | cdb317b | 2009-05-06 00:12:29 -0400 | [diff] [blame] | 526 | }; |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 527 | ASSERT_SIZE (ContextSubst, 2); |
Behdad Esfahbod | cdb317b | 2009-05-06 00:12:29 -0400 | [diff] [blame] | 528 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 529 | struct ChainContextSubst : ChainContext |
| 530 | { |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 531 | friend struct SubstLookupSubTable; |
| 532 | |
| 533 | private: |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 534 | inline bool apply (APPLY_ARG_DEF) const |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 535 | { return ChainContext::apply (APPLY_ARG, substitute_lookup); } |
Behdad Esfahbod | 9f721cf | 2009-05-16 19:59:15 -0400 | [diff] [blame] | 536 | }; |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 537 | ASSERT_SIZE (ChainContextSubst, 2); |
Behdad Esfahbod | 9f721cf | 2009-05-16 19:59:15 -0400 | [diff] [blame] | 538 | |
Behdad Esfahbod | 4f27ce7 | 2009-04-16 13:40:13 -0400 | [diff] [blame] | 539 | |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 540 | struct ExtensionSubst : Extension |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 541 | { |
Behdad Esfahbod | 4f27ce7 | 2009-04-16 13:40:13 -0400 | [diff] [blame] | 542 | friend struct SubstLookupSubTable; |
| 543 | |
| 544 | private: |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 545 | inline const struct SubstLookupSubTable& get_subtable (void) const |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 546 | { return CONST_CAST (SubstLookupSubTable, Extension::get_subtable (), 0); } |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 547 | |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 548 | inline bool apply (APPLY_ARG_DEF) const; |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 549 | |
| 550 | inline bool sanitize (SANITIZE_ARG_DEF); |
Behdad Esfahbod | 4f27ce7 | 2009-04-16 13:40:13 -0400 | [diff] [blame] | 551 | }; |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 552 | ASSERT_SIZE (ExtensionSubst, 2); |
Behdad Esfahbod | 4f27ce7 | 2009-04-16 13:40:13 -0400 | [diff] [blame] | 553 | |
| 554 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 555 | struct ReverseChainSingleSubstFormat1 |
| 556 | { |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 557 | friend struct ReverseChainSingleSubst; |
| 558 | |
| 559 | private: |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 560 | inline bool apply (APPLY_ARG_DEF) const |
| 561 | { |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 562 | if (HB_UNLIKELY (context_length != NO_CONTEXT)) |
| 563 | return false; /* No chaining to this type */ |
| 564 | |
| 565 | unsigned int index = (this+coverage) (IN_CURGLYPH ()); |
| 566 | if (HB_LIKELY (index == NOT_COVERED)) |
| 567 | return false; |
| 568 | |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 569 | const OffsetArrayOf<Coverage> &lookahead = CONST_CAST (OffsetArrayOf<Coverage>, backtrack, backtrack.get_size ()); |
| 570 | const ArrayOf<GlyphID> &substitute = CONST_CAST (ArrayOf<GlyphID>, lookahead, lookahead.get_size ()); |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 571 | |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 572 | if (match_backtrack (APPLY_ARG, |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 573 | backtrack.len, (USHORT *) backtrack.array, |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 574 | match_coverage, DECONST_CHARP(this)) && |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 575 | match_lookahead (APPLY_ARG, |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 576 | lookahead.len, (USHORT *) lookahead.array, |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 577 | match_coverage, DECONST_CHARP(this), |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 578 | 1)) |
| 579 | { |
Behdad Esfahbod | 4189b92 | 2009-05-26 17:31:56 -0400 | [diff] [blame] | 580 | IN_CURGLYPH () = substitute[index]; |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 581 | buffer->in_pos--; /* Reverse! */ |
| 582 | return true; |
| 583 | } |
| 584 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 585 | return false; |
| 586 | } |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 587 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 588 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 589 | if (!SANITIZE_THIS2 (coverage, backtrack)) |
| 590 | return false; |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 591 | OffsetArrayOf<Coverage> &lookahead = CAST (OffsetArrayOf<Coverage>, backtrack, backtrack.get_size ()); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 592 | if (!SANITIZE_THIS (lookahead)) |
| 593 | return false; |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 594 | ArrayOf<GlyphID> &substitute = CAST (ArrayOf<GlyphID>, lookahead, lookahead.get_size ()); |
Behdad Esfahbod | 9bd629c | 2009-08-04 21:42:23 -0400 | [diff] [blame] | 595 | return SANITIZE (substitute); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 596 | } |
| 597 | |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 598 | private: |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 599 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 600 | OffsetTo<Coverage> |
| 601 | coverage; /* Offset to Coverage table--from |
| 602 | * beginning of table */ |
| 603 | OffsetArrayOf<Coverage> |
| 604 | backtrack; /* Array of coverage tables |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 605 | * in backtracking sequence, in glyph |
| 606 | * sequence order */ |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 607 | OffsetArrayOf<Coverage> |
| 608 | lookaheadX; /* Array of coverage tables |
| 609 | * in lookahead sequence, in glyph |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 610 | * sequence order */ |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 611 | ArrayOf<GlyphID> |
| 612 | substituteX; /* Array of substitute |
| 613 | * GlyphIDs--ordered by Coverage Index */ |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 614 | }; |
| 615 | ASSERT_SIZE (ReverseChainSingleSubstFormat1, 10); |
| 616 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 617 | struct ReverseChainSingleSubst |
| 618 | { |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 619 | friend struct SubstLookupSubTable; |
| 620 | |
| 621 | private: |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 622 | inline bool apply (APPLY_ARG_DEF) const |
| 623 | { |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 624 | switch (u.format) { |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 625 | case 1: return u.format1->apply (APPLY_ARG); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 626 | default:return false; |
| 627 | } |
| 628 | } |
| 629 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 630 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 631 | if (!SANITIZE (u.format)) return false; |
| 632 | switch (u.format) { |
| 633 | case 1: return u.format1->sanitize (SANITIZE_ARG); |
| 634 | default:return true; |
| 635 | } |
| 636 | } |
| 637 | |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 638 | private: |
| 639 | union { |
| 640 | USHORT format; /* Format identifier */ |
| 641 | ReverseChainSingleSubstFormat1 format1[]; |
| 642 | } u; |
| 643 | }; |
| 644 | ASSERT_SIZE (ReverseChainSingleSubst, 2); |
| 645 | |
| 646 | |
| 647 | |
Behdad Esfahbod | 7586089 | 2008-01-23 18:02:28 -0500 | [diff] [blame] | 648 | /* |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 649 | * SubstLookup |
| 650 | */ |
| 651 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 652 | struct SubstLookupSubTable |
| 653 | { |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 654 | friend struct SubstLookup; |
| 655 | |
Behdad Esfahbod | ff05d25 | 2009-05-20 03:53:00 -0400 | [diff] [blame] | 656 | enum { |
| 657 | Single = 1, |
| 658 | Multiple = 2, |
| 659 | Alternate = 3, |
| 660 | Ligature = 4, |
| 661 | Context = 5, |
| 662 | ChainContext = 6, |
| 663 | Extension = 7, |
| 664 | ReverseChainSingle = 8, |
| 665 | }; |
| 666 | |
Behdad Esfahbod | 923923f | 2009-05-22 17:58:09 -0400 | [diff] [blame] | 667 | bool apply (APPLY_ARG_DEF, unsigned int lookup_type) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 668 | { |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 669 | switch (lookup_type) { |
Behdad Esfahbod | ff05d25 | 2009-05-20 03:53:00 -0400 | [diff] [blame] | 670 | case Single: return u.single->apply (APPLY_ARG); |
| 671 | case Multiple: return u.multiple->apply (APPLY_ARG); |
| 672 | case Alternate: return u.alternate->apply (APPLY_ARG); |
| 673 | case Ligature: return u.ligature->apply (APPLY_ARG); |
| 674 | case Context: return u.context->apply (APPLY_ARG); |
| 675 | case ChainContext: return u.chainContext->apply (APPLY_ARG); |
| 676 | case Extension: return u.extension->apply (APPLY_ARG); |
| 677 | case ReverseChainSingle: return u.reverseChainContextSingle->apply (APPLY_ARG); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 678 | default:return false; |
| 679 | } |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 680 | } |
| 681 | |
Behdad Esfahbod | dc9c4d9 | 2009-08-04 12:26:26 -0400 | [diff] [blame] | 682 | bool sanitize (SANITIZE_ARG_DEF) { |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 683 | if (!SANITIZE (u.format)) return false; |
| 684 | switch (u.format) { |
| 685 | case Single: return u.single->sanitize (SANITIZE_ARG); |
| 686 | case Multiple: return u.multiple->sanitize (SANITIZE_ARG); |
| 687 | case Alternate: return u.alternate->sanitize (SANITIZE_ARG); |
| 688 | case Ligature: return u.ligature->sanitize (SANITIZE_ARG); |
| 689 | case Context: return u.context->sanitize (SANITIZE_ARG); |
| 690 | case ChainContext: return u.chainContext->sanitize (SANITIZE_ARG); |
| 691 | case Extension: return u.extension->sanitize (SANITIZE_ARG); |
| 692 | case ReverseChainSingle: return u.reverseChainContextSingle->sanitize (SANITIZE_ARG); |
| 693 | default:return true; |
| 694 | } |
| 695 | } |
| 696 | |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 697 | private: |
| 698 | union { |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 699 | USHORT format; |
| 700 | SingleSubst single[]; |
| 701 | MultipleSubst multiple[]; |
| 702 | AlternateSubst alternate[]; |
| 703 | LigatureSubst ligature[]; |
| 704 | ContextSubst context[]; |
Behdad Esfahbod | 64e67f7 | 2009-05-18 15:32:40 -0400 | [diff] [blame] | 705 | ChainContextSubst chainContext[]; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 706 | ExtensionSubst extension[]; |
| 707 | ReverseChainSingleSubst reverseChainContextSingle[]; |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 708 | } u; |
| 709 | }; |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 710 | ASSERT_SIZE (SubstLookupSubTable, 2); |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 711 | |
Behdad Esfahbod | 4f27ce7 | 2009-04-16 13:40:13 -0400 | [diff] [blame] | 712 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 713 | struct SubstLookup : Lookup |
| 714 | { |
| 715 | inline const SubstLookupSubTable& get_subtable (unsigned int i) const |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 716 | { return CONST_CAST (SubstLookupSubTable, Lookup::get_subtable (i), 0); } |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 717 | |
| 718 | /* Like get_type(), but looks through extension lookups. |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 719 | * Never returns Extension */ |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 720 | inline unsigned int get_effective_type (void) const |
| 721 | { |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 722 | unsigned int type = get_type (); |
| 723 | |
Behdad Esfahbod | ff05d25 | 2009-05-20 03:53:00 -0400 | [diff] [blame] | 724 | if (HB_UNLIKELY (type == SubstLookupSubTable::Extension)) |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 725 | { |
Behdad Esfahbod | 8533bb9 | 2009-05-18 06:00:12 -0400 | [diff] [blame] | 726 | unsigned int count = get_subtable_count (); |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 727 | type = get_subtable(0).u.extension->get_type (); |
Behdad Esfahbod | 8533bb9 | 2009-05-18 06:00:12 -0400 | [diff] [blame] | 728 | /* The spec says all subtables should have the same type. |
| 729 | * This is specially important if one has a reverse type! */ |
| 730 | for (unsigned int i = 1; i < count; i++) |
| 731 | if (get_subtable(i).u.extension->get_type () != type) |
| 732 | return 0; |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | return type; |
| 736 | } |
| 737 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 738 | inline bool is_reverse (void) const |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 739 | { return HB_UNLIKELY (get_effective_type () == SubstLookupSubTable::ReverseChainSingle); } |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 740 | |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 741 | inline bool apply_once (hb_ot_layout_context_t *context, |
Behdad Esfahbod | 923923f | 2009-05-22 17:58:09 -0400 | [diff] [blame] | 742 | hb_buffer_t *buffer, |
| 743 | unsigned int context_length, |
| 744 | unsigned int nesting_level_left) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 745 | { |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 746 | unsigned int lookup_type = get_type (); |
Behdad Esfahbod | 30bd763 | 2009-04-15 22:56:15 -0400 | [diff] [blame] | 747 | unsigned int lookup_flag = get_flag (); |
Behdad Esfahbod | 923923f | 2009-05-22 17:58:09 -0400 | [diff] [blame] | 748 | unsigned int property; |
| 749 | |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 750 | if (!_hb_ot_layout_check_glyph_property (context->face, IN_CURINFO (), lookup_flag, &property)) |
Behdad Esfahbod | 923923f | 2009-05-22 17:58:09 -0400 | [diff] [blame] | 751 | return false; |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 752 | |
Behdad Esfahbod | 29d8644 | 2009-08-04 02:27:37 -0400 | [diff] [blame] | 753 | unsigned int count = get_subtable_count (); |
| 754 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | eb0dfc8 | 2009-05-18 18:22:44 -0400 | [diff] [blame] | 755 | if (get_subtable (i).apply (APPLY_ARG, lookup_type)) |
Behdad Esfahbod | ecf17e8 | 2009-05-17 09:34:41 -0400 | [diff] [blame] | 756 | return true; |
| 757 | |
| 758 | return false; |
| 759 | } |
| 760 | |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 761 | bool apply_string (hb_ot_layout_context_t *context, |
Behdad Esfahbod | 2a8e6ac | 2009-05-18 18:21:44 -0400 | [diff] [blame] | 762 | hb_buffer_t *buffer, |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 763 | hb_ot_layout_feature_mask_t mask) const |
| 764 | { |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 765 | bool ret = false; |
| 766 | |
Behdad Esfahbod | 19fc24f | 2009-05-17 09:45:32 -0400 | [diff] [blame] | 767 | if (HB_UNLIKELY (!buffer->in_length)) |
| 768 | return false; |
| 769 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 770 | if (HB_LIKELY (!is_reverse ())) |
| 771 | { |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 772 | /* in/out forward substitution */ |
| 773 | _hb_buffer_clear_output (buffer); |
| 774 | buffer->in_pos = 0; |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 775 | while (buffer->in_pos < buffer->in_length) |
| 776 | { |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 777 | if ((~IN_PROPERTIES (buffer->in_pos) & mask) && |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 778 | apply_once (context, buffer, NO_CONTEXT, MAX_NESTING_LEVEL)) |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 779 | ret = true; |
| 780 | else |
Behdad Esfahbod | 15c3e75 | 2009-05-17 06:03:42 -0400 | [diff] [blame] | 781 | _hb_buffer_next_glyph (buffer); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 782 | |
| 783 | } |
| 784 | if (ret) |
| 785 | _hb_buffer_swap (buffer); |
| 786 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 787 | } |
| 788 | else |
| 789 | { |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 790 | |
| 791 | /* in-place backward substitution */ |
| 792 | buffer->in_pos = buffer->in_length - 1; |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 793 | do |
| 794 | { |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 795 | if ((~IN_PROPERTIES (buffer->in_pos) & mask) && |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 796 | apply_once (context, buffer, NO_CONTEXT, MAX_NESTING_LEVEL)) |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 797 | ret = true; |
| 798 | else |
| 799 | buffer->in_pos--; |
| 800 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 801 | } |
| 802 | while ((int) buffer->in_pos >= 0); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | return ret; |
| 806 | } |
Behdad Esfahbod | 29d8644 | 2009-08-04 02:27:37 -0400 | [diff] [blame] | 807 | |
| 808 | inline bool sanitize (SANITIZE_ARG_DEF) { |
| 809 | if (Lookup::sanitize (SANITIZE_ARG)) return false; |
| 810 | OffsetArrayOf<SubstLookupSubTable> &list = (OffsetArrayOf<SubstLookupSubTable> &) subTable; |
| 811 | return SANITIZE_THIS (list); |
| 812 | } |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 813 | }; |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 814 | ASSERT_SIZE (SubstLookup, 6); |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 815 | |
Behdad Esfahbod | 29d8644 | 2009-08-04 02:27:37 -0400 | [diff] [blame] | 816 | typedef OffsetListOf<SubstLookup> SubstLookupList; |
| 817 | ASSERT_SIZE (SubstLookupList, 2); |
Behdad Esfahbod | c43562b | 2009-05-15 18:54:53 -0400 | [diff] [blame] | 818 | |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 819 | /* |
Behdad Esfahbod | 7586089 | 2008-01-23 18:02:28 -0500 | [diff] [blame] | 820 | * GSUB |
| 821 | */ |
| 822 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 823 | struct GSUB : GSUBGPOS |
| 824 | { |
Behdad Esfahbod | a328d66 | 2009-08-04 20:27:05 -0400 | [diff] [blame] | 825 | static const hb_tag_t Tag = HB_OT_TAG_GSUB; |
Behdad Esfahbod | 7586089 | 2008-01-23 18:02:28 -0500 | [diff] [blame] | 826 | |
Behdad Esfahbod | 5876bf1 | 2009-05-24 00:53:28 -0400 | [diff] [blame] | 827 | static inline const GSUB& get_for_data (const char *data) |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 828 | { return (const GSUB&) GSUBGPOS::get_for_data (data); } |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 829 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 830 | inline const SubstLookup& get_lookup (unsigned int i) const |
Behdad Esfahbod | 79420ad | 2009-05-26 12:24:16 -0400 | [diff] [blame] | 831 | { return (const SubstLookup&) GSUBGPOS::get_lookup (i); } |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 832 | |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 833 | inline bool substitute_lookup (hb_ot_layout_context_t *context, |
Behdad Esfahbod | fc36d94 | 2009-05-15 20:11:10 -0400 | [diff] [blame] | 834 | hb_buffer_t *buffer, |
| 835 | unsigned int lookup_index, |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 836 | hb_ot_layout_feature_mask_t mask) const |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 837 | { return get_lookup (lookup_index).apply_string (context, buffer, mask); } |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 838 | |
Behdad Esfahbod | 29d8644 | 2009-08-04 02:27:37 -0400 | [diff] [blame] | 839 | |
Behdad Esfahbod | e49a84c | 2009-08-04 14:33:23 -0400 | [diff] [blame] | 840 | bool sanitize (SANITIZE_ARG_DEF) { |
Behdad Esfahbod | 29d8644 | 2009-08-04 02:27:37 -0400 | [diff] [blame] | 841 | if (GSUBGPOS::sanitize (SANITIZE_ARG)) return false; |
Behdad Esfahbod | ad3a3cd | 2009-08-04 12:13:52 -0400 | [diff] [blame] | 842 | OffsetTo<SubstLookupList> &list = CAST(OffsetTo<SubstLookupList>, lookupList, 0); |
Behdad Esfahbod | 29d8644 | 2009-08-04 02:27:37 -0400 | [diff] [blame] | 843 | return SANITIZE_THIS (list); |
| 844 | } |
Behdad Esfahbod | 7586089 | 2008-01-23 18:02:28 -0500 | [diff] [blame] | 845 | }; |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 846 | ASSERT_SIZE (GSUB, 10); |
Behdad Esfahbod | c43562b | 2009-05-15 18:54:53 -0400 | [diff] [blame] | 847 | |
| 848 | |
Behdad Esfahbod | 887c4b4 | 2009-05-17 21:06:08 -0400 | [diff] [blame] | 849 | /* Out-of-class implementation for methods recursing */ |
Behdad Esfahbod | c43562b | 2009-05-15 18:54:53 -0400 | [diff] [blame] | 850 | |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 851 | inline bool ExtensionSubst::apply (APPLY_ARG_DEF) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 852 | { |
Behdad Esfahbod | 6cf2a52 | 2009-05-17 21:11:49 -0400 | [diff] [blame] | 853 | unsigned int lookup_type = get_type (); |
| 854 | |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 855 | if (HB_UNLIKELY (lookup_type == SubstLookupSubTable::Extension)) |
Behdad Esfahbod | 6cf2a52 | 2009-05-17 21:11:49 -0400 | [diff] [blame] | 856 | return false; |
| 857 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 858 | return get_subtable ().apply (APPLY_ARG, lookup_type); |
| 859 | } |
| 860 | |
| 861 | inline bool ExtensionSubst::sanitize (SANITIZE_ARG_DEF) |
| 862 | { |
Behdad Esfahbod | 2b5a59c | 2009-08-04 11:38:50 -0400 | [diff] [blame] | 863 | return Extension::sanitize (SANITIZE_ARG) && |
Behdad Esfahbod | 1893948 | 2009-08-04 14:27:56 -0400 | [diff] [blame] | 864 | (&(Extension::get_subtable ()) == &Null(LookupSubTable) || |
Behdad Esfahbod | 5ff4e13 | 2009-08-04 21:35:32 -0400 | [diff] [blame] | 865 | get_type () == SubstLookupSubTable::Extension || |
Behdad Esfahbod | 1893948 | 2009-08-04 14:27:56 -0400 | [diff] [blame] | 866 | DECONST_CAST (SubstLookupSubTable, get_subtable (), 0).sanitize (SANITIZE_ARG)); |
Behdad Esfahbod | c43562b | 2009-05-15 18:54:53 -0400 | [diff] [blame] | 867 | } |
| 868 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 869 | static inline bool substitute_lookup (APPLY_ARG_DEF, unsigned int lookup_index) |
| 870 | { |
Behdad Esfahbod | 23c86aa | 2009-08-03 21:40:20 -0400 | [diff] [blame] | 871 | const GSUB &gsub = *(context->face->ot_layout.gsub); |
Behdad Esfahbod | a162552 | 2009-05-17 07:52:11 -0400 | [diff] [blame] | 872 | const SubstLookup &l = gsub.get_lookup (lookup_index); |
Behdad Esfahbod | c43562b | 2009-05-15 18:54:53 -0400 | [diff] [blame] | 873 | |
Behdad Esfahbod | eca8e33 | 2009-05-17 09:07:27 -0400 | [diff] [blame] | 874 | if (HB_UNLIKELY (nesting_level_left == 0)) |
| 875 | return false; |
| 876 | nesting_level_left--; |
| 877 | |
| 878 | if (HB_UNLIKELY (context_length < 1)) |
| 879 | return false; |
| 880 | |
Behdad Esfahbod | 0ead481 | 2009-08-02 17:41:36 -0400 | [diff] [blame] | 881 | return l.apply_once (context, buffer, context_length, nesting_level_left); |
Behdad Esfahbod | c43562b | 2009-05-15 18:54:53 -0400 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | |
Behdad Esfahbod | 5f5b24f | 2009-08-02 20:03:12 -0400 | [diff] [blame] | 885 | #endif /* HB_OT_LAYOUT_GSUB_PRIVATE_HH */ |