Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 1 | /* |
Behdad Esfahbod | 2409d5f | 2011-04-21 17:14:28 -0400 | [diff] [blame] | 2 | * Copyright © 2007,2008,2009,2010 Red Hat, Inc. |
Behdad Esfahbod | 5b93e8d | 2012-04-23 22:26:13 -0400 | [diff] [blame] | 3 | * Copyright © 2010,2012 Google, Inc. |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 4 | * |
Behdad Esfahbod | c755cb3 | 2010-04-22 00:11:43 -0400 | [diff] [blame] | 5 | * This is part of HarfBuzz, a text shaping library. |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 6 | * |
| 7 | * Permission is hereby granted, without written agreement and without |
| 8 | * license or royalty fees, to use, copy, modify, and distribute this |
| 9 | * software and its documentation for any purpose, provided that the |
| 10 | * above copyright notice and the following two paragraphs appear in |
| 11 | * all copies of this software. |
| 12 | * |
| 13 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
| 14 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
| 15 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
| 16 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 17 | * DAMAGE. |
| 18 | * |
| 19 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
| 20 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
| 22 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
| 23 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 24 | * |
| 25 | * Red Hat Author(s): Behdad Esfahbod |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 26 | * Google Author(s): Behdad Esfahbod |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 27 | */ |
| 28 | |
Behdad Esfahbod | 7a750ac | 2011-08-17 14:19:59 +0200 | [diff] [blame] | 29 | #ifndef HB_OT_LAYOUT_GSUB_TABLE_HH |
| 30 | #define HB_OT_LAYOUT_GSUB_TABLE_HH |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 31 | |
Behdad Esfahbod | 5f5b24f | 2009-08-02 20:03:12 -0400 | [diff] [blame] | 32 | #include "hb-ot-layout-gsubgpos-private.hh" |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 33 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 34 | |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 35 | namespace OT { |
| 36 | |
Behdad Esfahbod | 6f20f72 | 2009-05-17 20:28:01 -0400 | [diff] [blame] | 37 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 38 | struct SingleSubstFormat1 |
| 39 | { |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 40 | friend struct SingleSubst; |
| 41 | |
| 42 | private: |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 43 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 44 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 45 | { |
| 46 | TRACE_CLOSURE (); |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 47 | Coverage::Iter iter; |
| 48 | for (iter.init (this+coverage); iter.more (); iter.next ()) { |
| 49 | hb_codepoint_t glyph_id = iter.get_glyph (); |
| 50 | if (c->glyphs->has (glyph_id)) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 51 | c->glyphs->add ((glyph_id + deltaGlyphID) & 0xFFFF); |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 52 | } |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 53 | } |
| 54 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 55 | inline const Coverage &get_coverage (void) const |
| 56 | { |
| 57 | return this+coverage; |
| 58 | } |
| 59 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 60 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 61 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 62 | TRACE_APPLY (); |
Behdad Esfahbod | 99c2695 | 2012-05-13 15:45:18 +0200 | [diff] [blame] | 63 | hb_codepoint_t glyph_id = c->buffer->cur().codepoint; |
Behdad Esfahbod | 238c855 | 2009-05-17 00:22:37 -0400 | [diff] [blame] | 64 | unsigned int index = (this+coverage) (glyph_id); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 65 | if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 66 | |
Behdad Esfahbod | 52ebdff | 2011-09-27 12:38:16 -0400 | [diff] [blame] | 67 | /* According to the Adobe Annotated OpenType Suite, result is always |
| 68 | * limited to 16bit. */ |
| 69 | glyph_id = (glyph_id + deltaGlyphID) & 0xFFFF; |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 70 | c->replace_glyph (glyph_id); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 71 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 72 | return TRACE_RETURN (true); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 73 | } |
| 74 | |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 75 | inline bool serialize (hb_serialize_context_t *c, |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 76 | Supplier<GlyphID> &glyphs, |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 77 | unsigned int num_glyphs, |
Behdad Esfahbod | 1b38b4e | 2012-09-04 18:17:21 -0400 | [diff] [blame] | 78 | int delta) |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 79 | { |
| 80 | TRACE_SERIALIZE (); |
| 81 | if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); |
Behdad Esfahbod | abcc5ac | 2012-09-01 21:30:17 -0400 | [diff] [blame] | 82 | if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs, num_glyphs))) return TRACE_RETURN (false); |
Behdad Esfahbod | 4912030 | 2012-09-03 20:58:03 -0400 | [diff] [blame] | 83 | deltaGlyphID.set (delta); /* TODO(serilaize) overflow? */ |
Behdad Esfahbod | bc5be24 | 2012-09-01 20:48:22 -0400 | [diff] [blame] | 84 | return TRACE_RETURN (true); |
| 85 | } |
| 86 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 87 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 88 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 89 | return TRACE_RETURN (coverage.sanitize (c, this) && deltaGlyphID.sanitize (c)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 90 | } |
| 91 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 92 | protected: |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 93 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 238c855 | 2009-05-17 00:22:37 -0400 | [diff] [blame] | 94 | OffsetTo<Coverage> |
| 95 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 96 | * beginning of Substitution table */ |
| 97 | SHORT deltaGlyphID; /* Add to original GlyphID to get |
| 98 | * substitute GlyphID */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 99 | public: |
| 100 | DEFINE_SIZE_STATIC (6); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 101 | }; |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 102 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 103 | struct SingleSubstFormat2 |
| 104 | { |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 105 | friend struct SingleSubst; |
| 106 | |
| 107 | private: |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 108 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 109 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 110 | { |
| 111 | TRACE_CLOSURE (); |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 112 | Coverage::Iter iter; |
| 113 | for (iter.init (this+coverage); iter.more (); iter.next ()) { |
| 114 | if (c->glyphs->has (iter.get_glyph ())) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 115 | c->glyphs->add (substitute[iter.get_coverage ()]); |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 116 | } |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 117 | } |
| 118 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 119 | inline const Coverage &get_coverage (void) const |
| 120 | { |
| 121 | return this+coverage; |
| 122 | } |
| 123 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 124 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 125 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 126 | TRACE_APPLY (); |
Behdad Esfahbod | 99c2695 | 2012-05-13 15:45:18 +0200 | [diff] [blame] | 127 | hb_codepoint_t glyph_id = c->buffer->cur().codepoint; |
Behdad Esfahbod | 238c855 | 2009-05-17 00:22:37 -0400 | [diff] [blame] | 128 | unsigned int index = (this+coverage) (glyph_id); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 129 | if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 130 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 131 | if (unlikely (index >= substitute.len)) return TRACE_RETURN (false); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 132 | |
| 133 | glyph_id = substitute[index]; |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 134 | c->replace_glyph (glyph_id); |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 135 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 136 | return TRACE_RETURN (true); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 137 | } |
| 138 | |
Behdad Esfahbod | c61be03 | 2012-09-01 21:43:38 -0400 | [diff] [blame] | 139 | inline bool serialize (hb_serialize_context_t *c, |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 140 | Supplier<GlyphID> &glyphs, |
| 141 | Supplier<GlyphID> &substitutes, |
Behdad Esfahbod | c61be03 | 2012-09-01 21:43:38 -0400 | [diff] [blame] | 142 | unsigned int num_glyphs) |
| 143 | { |
| 144 | TRACE_SERIALIZE (); |
| 145 | if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); |
Behdad Esfahbod | c61be03 | 2012-09-01 21:43:38 -0400 | [diff] [blame] | 146 | if (unlikely (!substitute.serialize (c, substitutes, num_glyphs))) return TRACE_RETURN (false); |
Behdad Esfahbod | fabd311 | 2012-09-05 22:19:28 -0400 | [diff] [blame] | 147 | if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs, num_glyphs))) return TRACE_RETURN (false); |
Behdad Esfahbod | c61be03 | 2012-09-01 21:43:38 -0400 | [diff] [blame] | 148 | return TRACE_RETURN (true); |
| 149 | } |
| 150 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 151 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 152 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 153 | return TRACE_RETURN (coverage.sanitize (c, this) && substitute.sanitize (c)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 154 | } |
| 155 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 156 | protected: |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 157 | USHORT format; /* Format identifier--format = 2 */ |
Behdad Esfahbod | 238c855 | 2009-05-17 00:22:37 -0400 | [diff] [blame] | 158 | OffsetTo<Coverage> |
| 159 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 160 | * beginning of Substitution table */ |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 161 | ArrayOf<GlyphID> |
| 162 | substitute; /* Array of substitute |
| 163 | * GlyphIDs--ordered by Coverage Index */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 164 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 165 | DEFINE_SIZE_ARRAY (6, substitute); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 166 | }; |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 167 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 168 | struct SingleSubst |
| 169 | { |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 170 | friend struct SubstLookupSubTable; |
Behdad Esfahbod | b3b89b6 | 2012-09-04 21:13:17 -0400 | [diff] [blame] | 171 | friend struct SubstLookup; |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 172 | |
Behdad Esfahbod | 4f27ce7 | 2009-04-16 13:40:13 -0400 | [diff] [blame] | 173 | private: |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 174 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 175 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 176 | { |
| 177 | TRACE_CLOSURE (); |
| 178 | switch (u.format) { |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 179 | case 1: u.format1.closure (c); break; |
| 180 | case 2: u.format2.closure (c); break; |
| 181 | default: break; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 185 | inline const Coverage &get_coverage (void) const |
| 186 | { |
| 187 | switch (u.format) { |
| 188 | case 1: return u.format1.get_coverage (); |
| 189 | case 2: return u.format2.get_coverage (); |
| 190 | default:return Null(Coverage); |
| 191 | } |
| 192 | } |
| 193 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 194 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 195 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 196 | TRACE_APPLY (); |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 197 | switch (u.format) { |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 198 | case 1: return TRACE_RETURN (u.format1.apply (c)); |
| 199 | case 2: return TRACE_RETURN (u.format2.apply (c)); |
| 200 | default:return TRACE_RETURN (false); |
Behdad Esfahbod | 38b011a | 2009-05-04 20:21:57 -0400 | [diff] [blame] | 201 | } |
| 202 | } |
| 203 | |
Behdad Esfahbod | c61be03 | 2012-09-01 21:43:38 -0400 | [diff] [blame] | 204 | inline bool serialize (hb_serialize_context_t *c, |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 205 | Supplier<GlyphID> &glyphs, |
| 206 | Supplier<GlyphID> &substitutes, |
Behdad Esfahbod | c61be03 | 2012-09-01 21:43:38 -0400 | [diff] [blame] | 207 | unsigned int num_glyphs) |
| 208 | { |
| 209 | TRACE_SERIALIZE (); |
| 210 | if (unlikely (!c->extend_min (u.format))) return TRACE_RETURN (false); |
| 211 | unsigned int format = 2; |
Behdad Esfahbod | 1b38b4e | 2012-09-04 18:17:21 -0400 | [diff] [blame] | 212 | int delta; |
Behdad Esfahbod | c61be03 | 2012-09-01 21:43:38 -0400 | [diff] [blame] | 213 | if (num_glyphs) { |
| 214 | format = 1; |
Behdad Esfahbod | 4912030 | 2012-09-03 20:58:03 -0400 | [diff] [blame] | 215 | /* TODO(serialize) check for wrap-around */ |
Behdad Esfahbod | c61be03 | 2012-09-01 21:43:38 -0400 | [diff] [blame] | 216 | delta = substitutes[0] - glyphs[0]; |
| 217 | for (unsigned int i = 1; i < num_glyphs; i++) |
| 218 | if (delta != substitutes[i] - glyphs[i]) { |
| 219 | format = 2; |
| 220 | break; |
| 221 | } |
| 222 | } |
| 223 | u.format.set (format); |
| 224 | switch (u.format) { |
| 225 | case 1: return TRACE_RETURN (u.format1.serialize (c, glyphs, num_glyphs, delta)); |
| 226 | case 2: return TRACE_RETURN (u.format2.serialize (c, glyphs, substitutes, num_glyphs)); |
| 227 | default:return TRACE_RETURN (false); |
| 228 | } |
| 229 | } |
| 230 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 231 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 232 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 233 | if (!u.format.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 234 | switch (u.format) { |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 235 | case 1: return TRACE_RETURN (u.format1.sanitize (c)); |
| 236 | case 2: return TRACE_RETURN (u.format2.sanitize (c)); |
| 237 | default:return TRACE_RETURN (true); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 241 | protected: |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 242 | union { |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 243 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 244 | SingleSubstFormat1 format1; |
| 245 | SingleSubstFormat2 format2; |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 246 | } u; |
| 247 | }; |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 248 | |
| 249 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 250 | struct Sequence |
| 251 | { |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 252 | friend struct MultipleSubstFormat1; |
| 253 | |
| 254 | private: |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 255 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 256 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 257 | { |
| 258 | TRACE_CLOSURE (); |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 259 | unsigned int count = substitute.len; |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 260 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 261 | c->glyphs->add (substitute[i]); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 262 | } |
| 263 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 264 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 265 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 266 | TRACE_APPLY (); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 267 | if (unlikely (!substitute.len)) return TRACE_RETURN (false); |
Behdad Esfahbod | c9c6a78 | 2009-05-05 16:22:02 -0400 | [diff] [blame] | 268 | |
Behdad Esfahbod | ed2f136 | 2012-05-22 22:12:22 -0400 | [diff] [blame] | 269 | unsigned int klass = c->property & HB_OT_LAYOUT_GLYPH_CLASS_LIGATURE ? HB_OT_LAYOUT_GLYPH_CLASS_BASE_GLYPH : 0; |
Behdad Esfahbod | 3ec77d6 | 2012-06-08 21:44:06 -0400 | [diff] [blame] | 270 | unsigned int count = substitute.len; |
Behdad Esfahbod | ec57e0c | 2012-06-08 21:47:23 -0400 | [diff] [blame] | 271 | for (unsigned int i = 0; i < count; i++) { |
Behdad Esfahbod | 2ec3ba4 | 2012-07-29 22:02:24 -0400 | [diff] [blame] | 272 | set_lig_props_for_component (c->buffer->cur(), i); |
Behdad Esfahbod | 3ec77d6 | 2012-06-08 21:44:06 -0400 | [diff] [blame] | 273 | c->output_glyph (substitute.array[i], klass); |
Behdad Esfahbod | ec57e0c | 2012-06-08 21:47:23 -0400 | [diff] [blame] | 274 | } |
Behdad Esfahbod | 3ec77d6 | 2012-06-08 21:44:06 -0400 | [diff] [blame] | 275 | c->buffer->skip_glyph (); |
Behdad Esfahbod | c9c6a78 | 2009-05-05 16:22:02 -0400 | [diff] [blame] | 276 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 277 | return TRACE_RETURN (true); |
Behdad Esfahbod | c9c6a78 | 2009-05-05 16:22:02 -0400 | [diff] [blame] | 278 | } |
| 279 | |
Behdad Esfahbod | 1f07e33 | 2012-09-03 23:28:34 -0400 | [diff] [blame] | 280 | inline bool serialize (hb_serialize_context_t *c, |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 281 | Supplier<GlyphID> &glyphs, |
Behdad Esfahbod | 1f07e33 | 2012-09-03 23:28:34 -0400 | [diff] [blame] | 282 | unsigned int num_glyphs) |
| 283 | { |
| 284 | TRACE_SERIALIZE (); |
| 285 | if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); |
| 286 | if (unlikely (!substitute.serialize (c, glyphs, num_glyphs))) return TRACE_RETURN (false); |
| 287 | return TRACE_RETURN (true); |
| 288 | } |
| 289 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 290 | public: |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 291 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 292 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 293 | return TRACE_RETURN (substitute.sanitize (c)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 294 | } |
| 295 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 296 | protected: |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 297 | ArrayOf<GlyphID> |
| 298 | substitute; /* String of GlyphIDs to substitute */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 299 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 300 | DEFINE_SIZE_ARRAY (2, substitute); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 301 | }; |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 302 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 303 | struct MultipleSubstFormat1 |
| 304 | { |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 305 | friend struct MultipleSubst; |
| 306 | |
| 307 | private: |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 308 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 309 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 310 | { |
| 311 | TRACE_CLOSURE (); |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 312 | Coverage::Iter iter; |
| 313 | for (iter.init (this+coverage); iter.more (); iter.next ()) { |
| 314 | if (c->glyphs->has (iter.get_glyph ())) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 315 | (this+sequence[iter.get_coverage ()]).closure (c); |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 316 | } |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 317 | } |
| 318 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 319 | inline const Coverage &get_coverage (void) const |
| 320 | { |
| 321 | return this+coverage; |
| 322 | } |
| 323 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 324 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 325 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 326 | TRACE_APPLY (); |
Behdad Esfahbod | 30bd763 | 2009-04-15 22:56:15 -0400 | [diff] [blame] | 327 | |
Behdad Esfahbod | 99c2695 | 2012-05-13 15:45:18 +0200 | [diff] [blame] | 328 | unsigned int index = (this+coverage) (c->buffer->cur().codepoint); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 329 | if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 330 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 331 | return TRACE_RETURN ((this+sequence[index]).apply (c)); |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 332 | } |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 333 | |
Behdad Esfahbod | 1f07e33 | 2012-09-03 23:28:34 -0400 | [diff] [blame] | 334 | inline bool serialize (hb_serialize_context_t *c, |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 335 | Supplier<GlyphID> &glyphs, |
| 336 | Supplier<unsigned int> &substitute_len_list, |
Behdad Esfahbod | 1f07e33 | 2012-09-03 23:28:34 -0400 | [diff] [blame] | 337 | unsigned int num_glyphs, |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 338 | Supplier<GlyphID> &substitute_glyphs_list) |
Behdad Esfahbod | 1f07e33 | 2012-09-03 23:28:34 -0400 | [diff] [blame] | 339 | { |
| 340 | TRACE_SERIALIZE (); |
| 341 | if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); |
Behdad Esfahbod | 1f07e33 | 2012-09-03 23:28:34 -0400 | [diff] [blame] | 342 | if (unlikely (!sequence.serialize (c, num_glyphs))) return TRACE_RETURN (false); |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 343 | for (unsigned int i = 0; i < num_glyphs; i++) |
| 344 | if (unlikely (!sequence[i].serialize (c, this).serialize (c, |
| 345 | substitute_glyphs_list, |
| 346 | substitute_len_list[i]))) return TRACE_RETURN (false); |
| 347 | substitute_len_list.advance (num_glyphs); |
Behdad Esfahbod | fabd311 | 2012-09-05 22:19:28 -0400 | [diff] [blame] | 348 | if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs, num_glyphs))) return TRACE_RETURN (false); |
Behdad Esfahbod | 1f07e33 | 2012-09-03 23:28:34 -0400 | [diff] [blame] | 349 | return TRACE_RETURN (true); |
| 350 | } |
| 351 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 352 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 353 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 354 | return TRACE_RETURN (coverage.sanitize (c, this) && sequence.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 355 | } |
| 356 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 357 | protected: |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 358 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 238c855 | 2009-05-17 00:22:37 -0400 | [diff] [blame] | 359 | OffsetTo<Coverage> |
| 360 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 361 | * beginning of Substitution table */ |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 362 | OffsetArrayOf<Sequence> |
| 363 | sequence; /* Array of Sequence tables |
| 364 | * ordered by Coverage Index */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 365 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 366 | DEFINE_SIZE_ARRAY (6, sequence); |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 367 | }; |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 368 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 369 | struct MultipleSubst |
| 370 | { |
Behdad Esfahbod | 4f27ce7 | 2009-04-16 13:40:13 -0400 | [diff] [blame] | 371 | friend struct SubstLookupSubTable; |
Behdad Esfahbod | b3b89b6 | 2012-09-04 21:13:17 -0400 | [diff] [blame] | 372 | friend struct SubstLookup; |
Behdad Esfahbod | 4f27ce7 | 2009-04-16 13:40:13 -0400 | [diff] [blame] | 373 | |
| 374 | private: |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 375 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 376 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 377 | { |
| 378 | TRACE_CLOSURE (); |
| 379 | switch (u.format) { |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 380 | case 1: u.format1.closure (c); break; |
| 381 | default: break; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 382 | } |
| 383 | } |
| 384 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 385 | inline const Coverage &get_coverage (void) const |
| 386 | { |
| 387 | switch (u.format) { |
| 388 | case 1: return u.format1.get_coverage (); |
| 389 | default:return Null(Coverage); |
| 390 | } |
| 391 | } |
| 392 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 393 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 394 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 395 | TRACE_APPLY (); |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 396 | switch (u.format) { |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 397 | case 1: return TRACE_RETURN (u.format1.apply (c)); |
| 398 | default:return TRACE_RETURN (false); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | |
Behdad Esfahbod | 1f07e33 | 2012-09-03 23:28:34 -0400 | [diff] [blame] | 402 | inline bool serialize (hb_serialize_context_t *c, |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 403 | Supplier<GlyphID> &glyphs, |
| 404 | Supplier<unsigned int> &substitute_len_list, |
Behdad Esfahbod | 1f07e33 | 2012-09-03 23:28:34 -0400 | [diff] [blame] | 405 | unsigned int num_glyphs, |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 406 | Supplier<GlyphID> &substitute_glyphs_list) |
Behdad Esfahbod | 1f07e33 | 2012-09-03 23:28:34 -0400 | [diff] [blame] | 407 | { |
| 408 | TRACE_SERIALIZE (); |
| 409 | if (unlikely (!c->extend_min (u.format))) return TRACE_RETURN (false); |
| 410 | unsigned int format = 1; |
| 411 | u.format.set (format); |
| 412 | switch (u.format) { |
| 413 | case 1: return TRACE_RETURN (u.format1.serialize (c, glyphs, substitute_len_list, num_glyphs, substitute_glyphs_list)); |
| 414 | default:return TRACE_RETURN (false); |
| 415 | } |
| 416 | } |
| 417 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 418 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 419 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 420 | if (!u.format.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 421 | switch (u.format) { |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 422 | case 1: return TRACE_RETURN (u.format1.sanitize (c)); |
| 423 | default:return TRACE_RETURN (true); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 427 | protected: |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 428 | union { |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 429 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 430 | MultipleSubstFormat1 format1; |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 431 | } u; |
| 432 | }; |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 433 | |
| 434 | |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 435 | typedef ArrayOf<GlyphID> AlternateSet; /* Array of alternate GlyphIDs--in |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 436 | * arbitrary order */ |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 437 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 438 | struct AlternateSubstFormat1 |
| 439 | { |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 440 | friend struct AlternateSubst; |
| 441 | |
| 442 | private: |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 443 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 444 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 445 | { |
| 446 | TRACE_CLOSURE (); |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 447 | Coverage::Iter iter; |
| 448 | for (iter.init (this+coverage); iter.more (); iter.next ()) { |
| 449 | if (c->glyphs->has (iter.get_glyph ())) { |
| 450 | const AlternateSet &alt_set = this+alternateSet[iter.get_coverage ()]; |
| 451 | unsigned int count = alt_set.len; |
| 452 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 453 | c->glyphs->add (alt_set[i]); |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 454 | } |
| 455 | } |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 456 | } |
| 457 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 458 | inline const Coverage &get_coverage (void) const |
| 459 | { |
| 460 | return this+coverage; |
| 461 | } |
| 462 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 463 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 464 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 465 | TRACE_APPLY (); |
Behdad Esfahbod | 99c2695 | 2012-05-13 15:45:18 +0200 | [diff] [blame] | 466 | hb_codepoint_t glyph_id = c->buffer->cur().codepoint; |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 467 | |
Behdad Esfahbod | 238c855 | 2009-05-17 00:22:37 -0400 | [diff] [blame] | 468 | unsigned int index = (this+coverage) (glyph_id); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 469 | if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 470 | |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 471 | const AlternateSet &alt_set = this+alternateSet[index]; |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 472 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 473 | if (unlikely (!alt_set.len)) return TRACE_RETURN (false); |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 474 | |
Behdad Esfahbod | 99c2695 | 2012-05-13 15:45:18 +0200 | [diff] [blame] | 475 | hb_mask_t glyph_mask = c->buffer->cur().mask; |
Behdad Esfahbod | 3660894 | 2012-04-19 22:21:38 -0400 | [diff] [blame] | 476 | hb_mask_t lookup_mask = c->lookup_mask; |
| 477 | |
Behdad Esfahbod | dd22a8f | 2010-05-21 16:43:17 +0100 | [diff] [blame] | 478 | /* Note: This breaks badly if two features enabled this lookup together. */ |
Behdad Esfahbod | f7acd8d | 2010-05-20 17:26:35 +0100 | [diff] [blame] | 479 | unsigned int shift = _hb_ctz (lookup_mask); |
Behdad Esfahbod | 1cdbfd9 | 2010-05-20 17:47:28 +0100 | [diff] [blame] | 480 | unsigned int alt_index = ((lookup_mask & glyph_mask) >> shift); |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 481 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 482 | if (unlikely (alt_index > alt_set.len || alt_index == 0)) return TRACE_RETURN (false); |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 483 | |
Behdad Esfahbod | 1cdbfd9 | 2010-05-20 17:47:28 +0100 | [diff] [blame] | 484 | glyph_id = alt_set[alt_index - 1]; |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 485 | |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 486 | c->replace_glyph (glyph_id); |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 487 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 488 | return TRACE_RETURN (true); |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 489 | } |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 490 | |
Behdad Esfahbod | 2941683 | 2012-09-03 23:31:14 -0400 | [diff] [blame] | 491 | inline bool serialize (hb_serialize_context_t *c, |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 492 | Supplier<GlyphID> &glyphs, |
| 493 | Supplier<unsigned int> &alternate_len_list, |
Behdad Esfahbod | 2941683 | 2012-09-03 23:31:14 -0400 | [diff] [blame] | 494 | unsigned int num_glyphs, |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 495 | Supplier<GlyphID> &alternate_glyphs_list) |
Behdad Esfahbod | 2941683 | 2012-09-03 23:31:14 -0400 | [diff] [blame] | 496 | { |
| 497 | TRACE_SERIALIZE (); |
| 498 | if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); |
Behdad Esfahbod | 2941683 | 2012-09-03 23:31:14 -0400 | [diff] [blame] | 499 | if (unlikely (!alternateSet.serialize (c, num_glyphs))) return TRACE_RETURN (false); |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 500 | for (unsigned int i = 0; i < num_glyphs; i++) |
| 501 | if (unlikely (!alternateSet[i].serialize (c, this).serialize (c, |
| 502 | alternate_glyphs_list, |
| 503 | alternate_len_list[i]))) return TRACE_RETURN (false); |
| 504 | alternate_len_list.advance (num_glyphs); |
Behdad Esfahbod | fabd311 | 2012-09-05 22:19:28 -0400 | [diff] [blame] | 505 | if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs, num_glyphs))) return TRACE_RETURN (false); |
Behdad Esfahbod | 2941683 | 2012-09-03 23:31:14 -0400 | [diff] [blame] | 506 | return TRACE_RETURN (true); |
| 507 | } |
| 508 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 509 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 510 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 511 | return TRACE_RETURN (coverage.sanitize (c, this) && alternateSet.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 512 | } |
| 513 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 514 | protected: |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 515 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 238c855 | 2009-05-17 00:22:37 -0400 | [diff] [blame] | 516 | OffsetTo<Coverage> |
| 517 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 518 | * beginning of Substitution table */ |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 519 | OffsetArrayOf<AlternateSet> |
| 520 | alternateSet; /* Array of AlternateSet tables |
| 521 | * ordered by Coverage Index */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 522 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 523 | DEFINE_SIZE_ARRAY (6, alternateSet); |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 524 | }; |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 525 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 526 | struct AlternateSubst |
| 527 | { |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 528 | friend struct SubstLookupSubTable; |
Behdad Esfahbod | b3b89b6 | 2012-09-04 21:13:17 -0400 | [diff] [blame] | 529 | friend struct SubstLookup; |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 530 | |
| 531 | private: |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 532 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 533 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 534 | { |
| 535 | TRACE_CLOSURE (); |
| 536 | switch (u.format) { |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 537 | case 1: u.format1.closure (c); break; |
| 538 | default: break; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 542 | inline const Coverage &get_coverage (void) const |
| 543 | { |
| 544 | switch (u.format) { |
| 545 | case 1: return u.format1.get_coverage (); |
| 546 | default:return Null(Coverage); |
| 547 | } |
| 548 | } |
| 549 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 550 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 551 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 552 | TRACE_APPLY (); |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 553 | switch (u.format) { |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 554 | case 1: return TRACE_RETURN (u.format1.apply (c)); |
| 555 | default:return TRACE_RETURN (false); |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 556 | } |
| 557 | } |
| 558 | |
Behdad Esfahbod | 2941683 | 2012-09-03 23:31:14 -0400 | [diff] [blame] | 559 | inline bool serialize (hb_serialize_context_t *c, |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 560 | Supplier<GlyphID> &glyphs, |
| 561 | Supplier<unsigned int> &alternate_len_list, |
Behdad Esfahbod | 2941683 | 2012-09-03 23:31:14 -0400 | [diff] [blame] | 562 | unsigned int num_glyphs, |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 563 | Supplier<GlyphID> &alternate_glyphs_list) |
Behdad Esfahbod | 2941683 | 2012-09-03 23:31:14 -0400 | [diff] [blame] | 564 | { |
| 565 | TRACE_SERIALIZE (); |
| 566 | if (unlikely (!c->extend_min (u.format))) return TRACE_RETURN (false); |
| 567 | unsigned int format = 1; |
| 568 | u.format.set (format); |
| 569 | switch (u.format) { |
| 570 | case 1: return TRACE_RETURN (u.format1.serialize (c, glyphs, alternate_len_list, num_glyphs, alternate_glyphs_list)); |
| 571 | default:return TRACE_RETURN (false); |
| 572 | } |
| 573 | } |
| 574 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 575 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 576 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 577 | if (!u.format.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 578 | switch (u.format) { |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 579 | case 1: return TRACE_RETURN (u.format1.sanitize (c)); |
| 580 | default:return TRACE_RETURN (true); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 581 | } |
| 582 | } |
| 583 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 584 | protected: |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 585 | union { |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 586 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 587 | AlternateSubstFormat1 format1; |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 588 | } u; |
| 589 | }; |
Behdad Esfahbod | 52886ca | 2009-04-16 14:19:42 -0400 | [diff] [blame] | 590 | |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 591 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 592 | struct Ligature |
| 593 | { |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 594 | friend struct LigatureSet; |
| 595 | |
| 596 | private: |
Behdad Esfahbod | 3660894 | 2012-04-19 22:21:38 -0400 | [diff] [blame] | 597 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 598 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 599 | { |
| 600 | TRACE_CLOSURE (); |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 601 | unsigned int count = component.len; |
| 602 | for (unsigned int i = 1; i < count; i++) |
| 603 | if (!c->glyphs->has (component[i])) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 604 | return; |
| 605 | c->glyphs->add (ligGlyph); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 606 | } |
| 607 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 608 | inline bool would_apply (hb_would_apply_context_t *c) const |
Behdad Esfahbod | 3660894 | 2012-04-19 22:21:38 -0400 | [diff] [blame] | 609 | { |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 610 | if (c->len != component.len) |
| 611 | return false; |
| 612 | |
| 613 | for (unsigned int i = 1; i < c->len; i++) |
| 614 | if (likely (c->glyphs[i] != component[i])) |
| 615 | return false; |
| 616 | |
| 617 | return true; |
Behdad Esfahbod | 3660894 | 2012-04-19 22:21:38 -0400 | [diff] [blame] | 618 | } |
| 619 | |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 620 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 621 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 622 | TRACE_APPLY (); |
Behdad Esfahbod | e8cbaaf | 2009-05-18 02:03:58 -0400 | [diff] [blame] | 623 | unsigned int count = component.len; |
Behdad Esfahbod | 1feb834 | 2012-07-16 13:23:40 -0400 | [diff] [blame] | 624 | if (unlikely (count < 1)) return TRACE_RETURN (false); |
Behdad Esfahbod | 4ab9731 | 2012-01-16 22:05:08 -0500 | [diff] [blame] | 625 | |
Behdad Esfahbod | 191fa88 | 2012-08-28 22:58:55 -0400 | [diff] [blame] | 626 | unsigned int end_offset; |
| 627 | bool is_mark_ligature; |
| 628 | unsigned int total_component_count; |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 629 | |
Behdad Esfahbod | 191fa88 | 2012-08-28 22:58:55 -0400 | [diff] [blame] | 630 | if (likely (!match_input (c, count, |
| 631 | &component[1], |
| 632 | match_glyph, |
| 633 | NULL, |
| 634 | &end_offset, |
| 635 | &is_mark_ligature, |
| 636 | &total_component_count))) |
| 637 | return TRACE_RETURN (false); |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 638 | |
Behdad Esfahbod | fe20c0f | 2012-07-30 00:00:59 -0400 | [diff] [blame] | 639 | /* Deal, we are forming the ligature. */ |
Behdad Esfahbod | 191fa88 | 2012-08-28 22:58:55 -0400 | [diff] [blame] | 640 | c->buffer->merge_clusters (c->buffer->idx, c->buffer->idx + end_offset); |
Behdad Esfahbod | cb3d340 | 2012-07-29 20:37:38 -0400 | [diff] [blame] | 641 | |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 642 | ligate_input (c, |
| 643 | count, |
| 644 | &component[1], |
| 645 | ligGlyph, |
| 646 | match_glyph, |
| 647 | NULL, |
Behdad Esfahbod | a177d02 | 2012-08-28 23:18:22 -0400 | [diff] [blame] | 648 | is_mark_ligature, |
| 649 | total_component_count); |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 650 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 651 | return TRACE_RETURN (true); |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 652 | } |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 653 | |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 654 | inline bool serialize (hb_serialize_context_t *c, |
| 655 | GlyphID ligature, |
| 656 | Supplier<GlyphID> &components, /* Starting from second */ |
| 657 | unsigned int num_components /* Including first component */) |
| 658 | { |
| 659 | TRACE_SERIALIZE (); |
| 660 | if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); |
Behdad Esfahbod | fabd311 | 2012-09-05 22:19:28 -0400 | [diff] [blame] | 661 | ligGlyph = ligature; |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 662 | if (unlikely (!component.serialize (c, components, num_components))) return TRACE_RETURN (false); |
| 663 | return TRACE_RETURN (true); |
| 664 | } |
| 665 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 666 | public: |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 667 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 668 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 669 | return TRACE_RETURN (ligGlyph.sanitize (c) && component.sanitize (c)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 670 | } |
| 671 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 672 | protected: |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 673 | GlyphID ligGlyph; /* GlyphID of ligature to substitute */ |
Behdad Esfahbod | e8cbaaf | 2009-05-18 02:03:58 -0400 | [diff] [blame] | 674 | HeadlessArrayOf<GlyphID> |
| 675 | component; /* Array of component GlyphIDs--start |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 676 | * with the second component--ordered |
| 677 | * in writing direction */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 678 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 679 | DEFINE_SIZE_ARRAY (4, component); |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 680 | }; |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 681 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 682 | struct LigatureSet |
| 683 | { |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 684 | friend struct LigatureSubstFormat1; |
| 685 | |
| 686 | private: |
Behdad Esfahbod | 3660894 | 2012-04-19 22:21:38 -0400 | [diff] [blame] | 687 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 688 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 689 | { |
| 690 | TRACE_CLOSURE (); |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 691 | unsigned int num_ligs = ligature.len; |
| 692 | for (unsigned int i = 0; i < num_ligs; i++) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 693 | (this+ligature[i]).closure (c); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 694 | } |
| 695 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 696 | inline bool would_apply (hb_would_apply_context_t *c) const |
Behdad Esfahbod | 3660894 | 2012-04-19 22:21:38 -0400 | [diff] [blame] | 697 | { |
| 698 | unsigned int num_ligs = ligature.len; |
| 699 | for (unsigned int i = 0; i < num_ligs; i++) |
| 700 | { |
| 701 | const Ligature &lig = this+ligature[i]; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 702 | if (lig.would_apply (c)) |
Behdad Esfahbod | 3660894 | 2012-04-19 22:21:38 -0400 | [diff] [blame] | 703 | return true; |
| 704 | } |
| 705 | return false; |
| 706 | } |
| 707 | |
Behdad Esfahbod | 98370e8 | 2010-10-27 17:39:01 -0400 | [diff] [blame] | 708 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 709 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 710 | TRACE_APPLY (); |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 711 | unsigned int num_ligs = ligature.len; |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 712 | for (unsigned int i = 0; i < num_ligs; i++) |
| 713 | { |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 714 | const Ligature &lig = this+ligature[i]; |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 715 | if (lig.apply (c)) return TRACE_RETURN (true); |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 716 | } |
| 717 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 718 | return TRACE_RETURN (false); |
Behdad Esfahbod | bb3899a | 2009-05-05 13:25:13 -0400 | [diff] [blame] | 719 | } |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 720 | |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 721 | inline bool serialize (hb_serialize_context_t *c, |
| 722 | Supplier<GlyphID> &ligatures, |
| 723 | Supplier<unsigned int> &component_count_list, |
| 724 | unsigned int num_ligatures, |
| 725 | Supplier<GlyphID> &component_list /* Starting from second for each ligature */) |
| 726 | { |
| 727 | TRACE_SERIALIZE (); |
| 728 | if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); |
| 729 | if (unlikely (!ligature.serialize (c, num_ligatures))) return TRACE_RETURN (false); |
| 730 | for (unsigned int i = 0; i < num_ligatures; i++) |
| 731 | if (unlikely (!ligature[i].serialize (c, this).serialize (c, |
| 732 | ligatures[i], |
| 733 | component_list, |
| 734 | component_count_list[i]))) return TRACE_RETURN (false); |
Behdad Esfahbod | fabd311 | 2012-09-05 22:19:28 -0400 | [diff] [blame] | 735 | ligatures.advance (num_ligatures); |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 736 | component_count_list.advance (num_ligatures); |
| 737 | return TRACE_RETURN (true); |
| 738 | } |
| 739 | |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 740 | public: |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 741 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 742 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 743 | return TRACE_RETURN (ligature.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 744 | } |
| 745 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 746 | protected: |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 747 | OffsetArrayOf<Ligature> |
| 748 | ligature; /* Array LigatureSet tables |
| 749 | * ordered by preference */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 750 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 751 | DEFINE_SIZE_ARRAY (2, ligature); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 752 | }; |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 753 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 754 | struct LigatureSubstFormat1 |
| 755 | { |
Behdad Esfahbod | a84e71a | 2009-04-16 16:53:40 -0400 | [diff] [blame] | 756 | friend struct LigatureSubst; |
| 757 | |
| 758 | private: |
Behdad Esfahbod | 3660894 | 2012-04-19 22:21:38 -0400 | [diff] [blame] | 759 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 760 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 761 | { |
| 762 | TRACE_CLOSURE (); |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 763 | Coverage::Iter iter; |
| 764 | for (iter.init (this+coverage); iter.more (); iter.next ()) { |
| 765 | if (c->glyphs->has (iter.get_glyph ())) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 766 | (this+ligatureSet[iter.get_coverage ()]).closure (c); |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 767 | } |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 768 | } |
| 769 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 770 | inline const Coverage &get_coverage (void) const |
| 771 | { |
| 772 | return this+coverage; |
| 773 | } |
| 774 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 775 | inline bool would_apply (hb_would_apply_context_t *c) const |
Behdad Esfahbod | 3660894 | 2012-04-19 22:21:38 -0400 | [diff] [blame] | 776 | { |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 777 | return (this+ligatureSet[(this+coverage) (c->glyphs[0])]).would_apply (c); |
Behdad Esfahbod | 3660894 | 2012-04-19 22:21:38 -0400 | [diff] [blame] | 778 | } |
| 779 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 780 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 781 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 782 | TRACE_APPLY (); |
Behdad Esfahbod | 99c2695 | 2012-05-13 15:45:18 +0200 | [diff] [blame] | 783 | hb_codepoint_t glyph_id = c->buffer->cur().codepoint; |
Behdad Esfahbod | a84e71a | 2009-04-16 16:53:40 -0400 | [diff] [blame] | 784 | |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 785 | unsigned int index = (this+coverage) (glyph_id); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 786 | if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); |
Behdad Esfahbod | aa3d7ad | 2009-05-17 23:17:56 -0400 | [diff] [blame] | 787 | |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 788 | const LigatureSet &lig_set = this+ligatureSet[index]; |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 789 | return TRACE_RETURN (lig_set.apply (c)); |
Behdad Esfahbod | a84e71a | 2009-04-16 16:53:40 -0400 | [diff] [blame] | 790 | } |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 791 | |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 792 | inline bool serialize (hb_serialize_context_t *c, |
| 793 | Supplier<GlyphID> &first_glyphs, |
| 794 | Supplier<unsigned int> &ligature_per_first_glyph_count_list, |
| 795 | unsigned int num_first_glyphs, |
| 796 | Supplier<GlyphID> &ligatures_list, |
| 797 | Supplier<unsigned int> &component_count_list, |
| 798 | Supplier<GlyphID> &component_list /* Starting from second for each ligature */) |
| 799 | { |
| 800 | TRACE_SERIALIZE (); |
| 801 | if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false); |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 802 | if (unlikely (!ligatureSet.serialize (c, num_first_glyphs))) return TRACE_RETURN (false); |
| 803 | for (unsigned int i = 0; i < num_first_glyphs; i++) |
| 804 | if (unlikely (!ligatureSet[i].serialize (c, this).serialize (c, |
| 805 | ligatures_list, |
| 806 | component_count_list, |
| 807 | ligature_per_first_glyph_count_list[i], |
| 808 | component_list))) return TRACE_RETURN (false); |
| 809 | ligature_per_first_glyph_count_list.advance (num_first_glyphs); |
Behdad Esfahbod | fabd311 | 2012-09-05 22:19:28 -0400 | [diff] [blame] | 810 | if (unlikely (!coverage.serialize (c, this).serialize (c, first_glyphs, num_first_glyphs))) return TRACE_RETURN (false); |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 811 | return TRACE_RETURN (true); |
| 812 | } |
| 813 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 814 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 815 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 816 | return TRACE_RETURN (coverage.sanitize (c, this) && ligatureSet.sanitize (c, this)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 817 | } |
| 818 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 819 | protected: |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 820 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 238c855 | 2009-05-17 00:22:37 -0400 | [diff] [blame] | 821 | OffsetTo<Coverage> |
| 822 | coverage; /* Offset to Coverage table--from |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 823 | * beginning of Substitution table */ |
Behdad Esfahbod | d79cae0 | 2009-05-18 13:50:15 -0400 | [diff] [blame] | 824 | OffsetArrayOf<LigatureSet> |
Behdad Esfahbod | c9a7cbe | 2009-05-17 01:22:51 -0400 | [diff] [blame] | 825 | ligatureSet; /* Array LigatureSet tables |
| 826 | * ordered by Coverage Index */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 827 | public: |
Behdad Esfahbod | 0eb9fc6 | 2010-05-10 19:01:17 -0400 | [diff] [blame] | 828 | DEFINE_SIZE_ARRAY (6, ligatureSet); |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 829 | }; |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 830 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 831 | struct LigatureSubst |
| 832 | { |
Behdad Esfahbod | a84e71a | 2009-04-16 16:53:40 -0400 | [diff] [blame] | 833 | friend struct SubstLookupSubTable; |
Behdad Esfahbod | b3b89b6 | 2012-09-04 21:13:17 -0400 | [diff] [blame] | 834 | friend struct SubstLookup; |
Behdad Esfahbod | a84e71a | 2009-04-16 16:53:40 -0400 | [diff] [blame] | 835 | |
| 836 | private: |
Behdad Esfahbod | 3660894 | 2012-04-19 22:21:38 -0400 | [diff] [blame] | 837 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 838 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 839 | { |
| 840 | TRACE_CLOSURE (); |
| 841 | switch (u.format) { |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 842 | case 1: u.format1.closure (c); break; |
| 843 | default: break; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 844 | } |
| 845 | } |
| 846 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 847 | inline const Coverage &get_coverage (void) const |
| 848 | { |
| 849 | switch (u.format) { |
| 850 | case 1: return u.format1.get_coverage (); |
| 851 | default:return Null(Coverage); |
| 852 | } |
| 853 | } |
| 854 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 855 | inline bool would_apply (hb_would_apply_context_t *c) const |
Behdad Esfahbod | 3660894 | 2012-04-19 22:21:38 -0400 | [diff] [blame] | 856 | { |
| 857 | switch (u.format) { |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 858 | case 1: return u.format1.would_apply (c); |
Behdad Esfahbod | 3660894 | 2012-04-19 22:21:38 -0400 | [diff] [blame] | 859 | default:return false; |
| 860 | } |
| 861 | } |
| 862 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 863 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 864 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 865 | TRACE_APPLY (); |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 866 | switch (u.format) { |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 867 | case 1: return TRACE_RETURN (u.format1.apply (c)); |
| 868 | default:return TRACE_RETURN (false); |
Behdad Esfahbod | a84e71a | 2009-04-16 16:53:40 -0400 | [diff] [blame] | 869 | } |
| 870 | } |
| 871 | |
Behdad Esfahbod | a930c68 | 2012-09-04 18:17:57 -0400 | [diff] [blame] | 872 | inline bool serialize (hb_serialize_context_t *c, |
| 873 | Supplier<GlyphID> &first_glyphs, |
| 874 | Supplier<unsigned int> &ligature_per_first_glyph_count_list, |
| 875 | unsigned int num_first_glyphs, |
| 876 | Supplier<GlyphID> &ligatures_list, |
| 877 | Supplier<unsigned int> &component_count_list, |
| 878 | Supplier<GlyphID> &component_list /* Starting from second for each ligature */) |
| 879 | { |
| 880 | TRACE_SERIALIZE (); |
| 881 | if (unlikely (!c->extend_min (u.format))) return TRACE_RETURN (false); |
| 882 | unsigned int format = 1; |
| 883 | u.format.set (format); |
| 884 | switch (u.format) { |
| 885 | case 1: return TRACE_RETURN (u.format1.serialize (c, first_glyphs, ligature_per_first_glyph_count_list, num_first_glyphs, |
| 886 | ligatures_list, component_count_list, component_list)); |
| 887 | default:return TRACE_RETURN (false); |
| 888 | } |
| 889 | } |
| 890 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 891 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 892 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 893 | if (!u.format.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 894 | switch (u.format) { |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 895 | case 1: return TRACE_RETURN (u.format1.sanitize (c)); |
| 896 | default:return TRACE_RETURN (true); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 897 | } |
| 898 | } |
| 899 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 900 | protected: |
Behdad Esfahbod | a84e71a | 2009-04-16 16:53:40 -0400 | [diff] [blame] | 901 | union { |
Behdad Esfahbod | f8dc67b | 2009-05-17 19:47:54 -0400 | [diff] [blame] | 902 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 903 | LigatureSubstFormat1 format1; |
Behdad Esfahbod | a84e71a | 2009-04-16 16:53:40 -0400 | [diff] [blame] | 904 | } u; |
| 905 | }; |
Behdad Esfahbod | a84e71a | 2009-04-16 16:53:40 -0400 | [diff] [blame] | 906 | |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 907 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 908 | static inline bool substitute_lookup (hb_apply_context_t *c, unsigned int lookup_index); |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 909 | static inline void closure_lookup (hb_closure_context_t *c, unsigned int lookup_index); |
Behdad Esfahbod | a162552 | 2009-05-17 07:52:11 -0400 | [diff] [blame] | 910 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 911 | struct ContextSubst : Context |
| 912 | { |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 913 | friend struct SubstLookupSubTable; |
| 914 | |
| 915 | private: |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 916 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 917 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 918 | { |
| 919 | TRACE_CLOSURE (); |
| 920 | return Context::closure (c, closure_lookup); |
| 921 | } |
| 922 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 923 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 0535b50 | 2009-08-28 17:14:33 -0400 | [diff] [blame] | 924 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 925 | TRACE_APPLY (); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 926 | return TRACE_RETURN (Context::apply (c, substitute_lookup)); |
Behdad Esfahbod | 0535b50 | 2009-08-28 17:14:33 -0400 | [diff] [blame] | 927 | } |
Behdad Esfahbod | cdb317b | 2009-05-06 00:12:29 -0400 | [diff] [blame] | 928 | }; |
Behdad Esfahbod | cdb317b | 2009-05-06 00:12:29 -0400 | [diff] [blame] | 929 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 930 | struct ChainContextSubst : ChainContext |
| 931 | { |
Behdad Esfahbod | d468f9a | 2009-05-21 22:31:33 -0400 | [diff] [blame] | 932 | friend struct SubstLookupSubTable; |
| 933 | |
| 934 | private: |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 935 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 936 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 937 | { |
| 938 | TRACE_CLOSURE (); |
| 939 | return ChainContext::closure (c, closure_lookup); |
| 940 | } |
| 941 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 942 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 0535b50 | 2009-08-28 17:14:33 -0400 | [diff] [blame] | 943 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 944 | TRACE_APPLY (); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 945 | return TRACE_RETURN (ChainContext::apply (c, substitute_lookup)); |
Behdad Esfahbod | 0535b50 | 2009-08-28 17:14:33 -0400 | [diff] [blame] | 946 | } |
Behdad Esfahbod | 9f721cf | 2009-05-16 19:59:15 -0400 | [diff] [blame] | 947 | }; |
Behdad Esfahbod | 9f721cf | 2009-05-16 19:59:15 -0400 | [diff] [blame] | 948 | |
Behdad Esfahbod | 4f27ce7 | 2009-04-16 13:40:13 -0400 | [diff] [blame] | 949 | |
Behdad Esfahbod | 6d08c7f | 2012-07-11 18:01:27 -0400 | [diff] [blame] | 950 | struct ExtensionSubst : Extension |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 951 | { |
Behdad Esfahbod | 4f27ce7 | 2009-04-16 13:40:13 -0400 | [diff] [blame] | 952 | friend struct SubstLookupSubTable; |
Behdad Esfahbod | a065f47 | 2010-04-22 20:15:11 -0400 | [diff] [blame] | 953 | friend struct SubstLookup; |
Behdad Esfahbod | 4f27ce7 | 2009-04-16 13:40:13 -0400 | [diff] [blame] | 954 | |
| 955 | private: |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 956 | inline const struct SubstLookupSubTable& get_subtable (void) const |
Behdad Esfahbod | 3b2c2df | 2010-04-22 16:51:42 -0400 | [diff] [blame] | 957 | { |
| 958 | unsigned int offset = get_offset (); |
Behdad Esfahbod | 64d3fc8 | 2010-05-03 22:51:19 -0400 | [diff] [blame] | 959 | if (unlikely (!offset)) return Null(SubstLookupSubTable); |
Behdad Esfahbod | 09766b1 | 2010-05-10 17:36:03 -0400 | [diff] [blame] | 960 | return StructAtOffset<SubstLookupSubTable> (this, offset); |
Behdad Esfahbod | 3b2c2df | 2010-04-22 16:51:42 -0400 | [diff] [blame] | 961 | } |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 962 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 963 | inline void closure (hb_closure_context_t *c) const; |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 964 | |
| 965 | inline const Coverage &get_coverage (void) const; |
| 966 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 967 | inline bool would_apply (hb_would_apply_context_t *c) const; |
Behdad Esfahbod | 3660894 | 2012-04-19 22:21:38 -0400 | [diff] [blame] | 968 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 969 | inline bool apply (hb_apply_context_t *c) const; |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 970 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 971 | inline bool sanitize (hb_sanitize_context_t *c); |
Behdad Esfahbod | a065f47 | 2010-04-22 20:15:11 -0400 | [diff] [blame] | 972 | |
| 973 | inline bool is_reverse (void) const; |
Behdad Esfahbod | 4f27ce7 | 2009-04-16 13:40:13 -0400 | [diff] [blame] | 974 | }; |
Behdad Esfahbod | 4f27ce7 | 2009-04-16 13:40:13 -0400 | [diff] [blame] | 975 | |
| 976 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 977 | struct ReverseChainSingleSubstFormat1 |
| 978 | { |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 979 | friend struct ReverseChainSingleSubst; |
| 980 | |
| 981 | private: |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 982 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 983 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 984 | { |
| 985 | TRACE_CLOSURE (); |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 986 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack); |
| 987 | |
| 988 | unsigned int count; |
| 989 | |
| 990 | count = backtrack.len; |
| 991 | for (unsigned int i = 0; i < count; i++) |
| 992 | if (!(this+backtrack[i]).intersects (c->glyphs)) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 993 | return; |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 994 | |
| 995 | count = lookahead.len; |
| 996 | for (unsigned int i = 0; i < count; i++) |
| 997 | if (!(this+lookahead[i]).intersects (c->glyphs)) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 998 | return; |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 999 | |
| 1000 | const ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead); |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 1001 | Coverage::Iter iter; |
| 1002 | for (iter.init (this+coverage); iter.more (); iter.next ()) { |
| 1003 | if (c->glyphs->has (iter.get_glyph ())) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1004 | c->glyphs->add (substitute[iter.get_coverage ()]); |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 1005 | } |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1006 | } |
| 1007 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1008 | inline const Coverage &get_coverage (void) const |
| 1009 | { |
| 1010 | return this+coverage; |
| 1011 | } |
| 1012 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1013 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1014 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1015 | TRACE_APPLY (); |
Behdad Esfahbod | 5df809b | 2012-05-13 15:17:51 +0200 | [diff] [blame] | 1016 | if (unlikely (c->nesting_level_left != MAX_NESTING_LEVEL)) |
| 1017 | return TRACE_RETURN (false); /* No chaining to this type */ |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 1018 | |
Behdad Esfahbod | 99c2695 | 2012-05-13 15:45:18 +0200 | [diff] [blame] | 1019 | unsigned int index = (this+coverage) (c->buffer->cur().codepoint); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1020 | if (likely (index == NOT_COVERED)) return TRACE_RETURN (false); |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 1021 | |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 1022 | const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack); |
| 1023 | const ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead); |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 1024 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1025 | if (match_backtrack (c, |
Behdad Esfahbod | b961518 | 2010-05-10 18:20:54 -0400 | [diff] [blame] | 1026 | backtrack.len, (USHORT *) backtrack.array, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 1027 | match_coverage, this) && |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1028 | match_lookahead (c, |
Behdad Esfahbod | b961518 | 2010-05-10 18:20:54 -0400 | [diff] [blame] | 1029 | lookahead.len, (USHORT *) lookahead.array, |
Behdad Esfahbod | 40cbefe | 2010-05-10 17:47:22 -0400 | [diff] [blame] | 1030 | match_coverage, this, |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 1031 | 1)) |
| 1032 | { |
Behdad Esfahbod | 7fbbf86 | 2012-07-30 18:36:42 -0400 | [diff] [blame] | 1033 | c->replace_glyph_inplace (substitute[index]); |
Behdad Esfahbod | 468e9cb | 2011-07-22 11:28:07 -0400 | [diff] [blame] | 1034 | c->buffer->idx--; /* Reverse! */ |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1035 | return TRACE_RETURN (true); |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 1036 | } |
| 1037 | |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1038 | return TRACE_RETURN (false); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1039 | } |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 1040 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1041 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1042 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1043 | if (!(coverage.sanitize (c, this) && backtrack.sanitize (c, this))) |
| 1044 | return TRACE_RETURN (false); |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 1045 | OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack); |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1046 | if (!lookahead.sanitize (c, this)) |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1047 | return TRACE_RETURN (false); |
Behdad Esfahbod | e961c86 | 2010-04-21 15:56:11 -0400 | [diff] [blame] | 1048 | ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1049 | return TRACE_RETURN (substitute.sanitize (c)); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1050 | } |
| 1051 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1052 | protected: |
Behdad Esfahbod | f45107f | 2009-05-17 20:13:02 -0400 | [diff] [blame] | 1053 | USHORT format; /* Format identifier--format = 1 */ |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 1054 | OffsetTo<Coverage> |
| 1055 | coverage; /* Offset to Coverage table--from |
| 1056 | * beginning of table */ |
| 1057 | OffsetArrayOf<Coverage> |
| 1058 | backtrack; /* Array of coverage tables |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 1059 | * in backtracking sequence, in glyph |
| 1060 | * sequence order */ |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 1061 | OffsetArrayOf<Coverage> |
| 1062 | lookaheadX; /* Array of coverage tables |
| 1063 | * in lookahead sequence, in glyph |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 1064 | * sequence order */ |
Behdad Esfahbod | 969afd7 | 2009-05-18 05:47:47 -0400 | [diff] [blame] | 1065 | ArrayOf<GlyphID> |
| 1066 | substituteX; /* Array of substitute |
| 1067 | * GlyphIDs--ordered by Coverage Index */ |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1068 | public: |
Behdad Esfahbod | bea34c7 | 2010-05-10 17:28:16 -0400 | [diff] [blame] | 1069 | DEFINE_SIZE_MIN (10); |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 1070 | }; |
Behdad Esfahbod | a16ecbf | 2008-01-23 17:01:55 -0500 | [diff] [blame] | 1071 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1072 | struct ReverseChainSingleSubst |
| 1073 | { |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1074 | friend struct SubstLookupSubTable; |
| 1075 | |
| 1076 | private: |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1077 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1078 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1079 | { |
| 1080 | TRACE_CLOSURE (); |
| 1081 | switch (u.format) { |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1082 | case 1: u.format1.closure (c); break; |
| 1083 | default: break; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1084 | } |
| 1085 | } |
| 1086 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1087 | inline const Coverage &get_coverage (void) const |
| 1088 | { |
| 1089 | switch (u.format) { |
| 1090 | case 1: return u.format1.get_coverage (); |
| 1091 | default:return Null(Coverage); |
| 1092 | } |
| 1093 | } |
| 1094 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1095 | inline bool apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1096 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1097 | TRACE_APPLY (); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1098 | switch (u.format) { |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1099 | case 1: return TRACE_RETURN (u.format1.apply (c)); |
| 1100 | default:return TRACE_RETURN (false); |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1101 | } |
| 1102 | } |
| 1103 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1104 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1105 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1106 | if (!u.format.sanitize (c)) return TRACE_RETURN (false); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1107 | switch (u.format) { |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1108 | case 1: return TRACE_RETURN (u.format1.sanitize (c)); |
| 1109 | default:return TRACE_RETURN (true); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1110 | } |
| 1111 | } |
| 1112 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1113 | protected: |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1114 | union { |
| 1115 | USHORT format; /* Format identifier */ |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 1116 | ReverseChainSingleSubstFormat1 format1; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1117 | } u; |
| 1118 | }; |
Behdad Esfahbod | ca5290f | 2009-05-17 20:48:27 -0400 | [diff] [blame] | 1119 | |
| 1120 | |
| 1121 | |
Behdad Esfahbod | 7586089 | 2008-01-23 18:02:28 -0500 | [diff] [blame] | 1122 | /* |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 1123 | * SubstLookup |
| 1124 | */ |
| 1125 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1126 | struct SubstLookupSubTable |
| 1127 | { |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 1128 | friend struct SubstLookup; |
| 1129 | |
Behdad Esfahbod | c6035cf | 2012-04-12 13:23:59 -0400 | [diff] [blame] | 1130 | enum Type { |
Behdad Esfahbod | ff05d25 | 2009-05-20 03:53:00 -0400 | [diff] [blame] | 1131 | Single = 1, |
| 1132 | Multiple = 2, |
| 1133 | Alternate = 3, |
| 1134 | Ligature = 4, |
| 1135 | Context = 5, |
| 1136 | ChainContext = 6, |
| 1137 | Extension = 7, |
Behdad Esfahbod | 8f034d5 | 2009-08-18 16:41:59 -0400 | [diff] [blame] | 1138 | ReverseChainSingle = 8 |
Behdad Esfahbod | ff05d25 | 2009-05-20 03:53:00 -0400 | [diff] [blame] | 1139 | }; |
| 1140 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1141 | inline void closure (hb_closure_context_t *c, |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1142 | unsigned int lookup_type) const |
| 1143 | { |
| 1144 | TRACE_CLOSURE (); |
| 1145 | switch (lookup_type) { |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1146 | case Single: u.single.closure (c); break; |
| 1147 | case Multiple: u.multiple.closure (c); break; |
| 1148 | case Alternate: u.alternate.closure (c); break; |
| 1149 | case Ligature: u.ligature.closure (c); break; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1150 | case Context: u.context.closure (c); break; |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1151 | case ChainContext: u.chainContext.closure (c); break; |
| 1152 | case Extension: u.extension.closure (c); break; |
| 1153 | case ReverseChainSingle: u.reverseChainContextSingle.closure (c); break; |
| 1154 | default: break; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1155 | } |
| 1156 | } |
| 1157 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1158 | inline const Coverage &get_coverage (unsigned int lookup_type) const |
Behdad Esfahbod | faf0f20 | 2012-06-09 03:02:36 -0400 | [diff] [blame] | 1159 | { |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1160 | switch (lookup_type) { |
| 1161 | case Single: return u.single.get_coverage (); |
| 1162 | case Multiple: return u.multiple.get_coverage (); |
| 1163 | case Alternate: return u.alternate.get_coverage (); |
| 1164 | case Ligature: return u.ligature.get_coverage (); |
| 1165 | case Context: return u.context.get_coverage (); |
| 1166 | case ChainContext: return u.chainContext.get_coverage (); |
| 1167 | case Extension: return u.extension.get_coverage (); |
| 1168 | case ReverseChainSingle: return u.reverseChainContextSingle.get_coverage (); |
| 1169 | default: return Null(Coverage); |
| 1170 | } |
Behdad Esfahbod | faf0f20 | 2012-06-09 03:02:36 -0400 | [diff] [blame] | 1171 | } |
| 1172 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1173 | inline bool would_apply (hb_would_apply_context_t *c, |
| 1174 | unsigned int lookup_type) const |
| 1175 | { |
| 1176 | TRACE_WOULD_APPLY (); |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 1177 | if (get_coverage (lookup_type).get_coverage (c->glyphs[0]) == NOT_COVERED) return false; |
| 1178 | if (c->len == 1) { |
| 1179 | switch (lookup_type) { |
| 1180 | case Single: |
| 1181 | case Multiple: |
| 1182 | case Alternate: |
| 1183 | case ReverseChainSingle: |
| 1184 | return true; |
| 1185 | } |
| 1186 | } |
Behdad Esfahbod | e6f7479 | 2012-07-28 18:34:58 -0400 | [diff] [blame] | 1187 | |
| 1188 | /* Only need to look further for lookups that support substitutions |
| 1189 | * of input longer than 1. */ |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1190 | switch (lookup_type) { |
Behdad Esfahbod | 74d1d88 | 2012-07-19 16:14:23 -0400 | [diff] [blame] | 1191 | case Ligature: return u.ligature.would_apply (c); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1192 | case Context: return u.context.would_apply (c); |
| 1193 | case ChainContext: return u.chainContext.would_apply (c); |
| 1194 | case Extension: return u.extension.would_apply (c); |
| 1195 | default: return false; |
| 1196 | } |
| 1197 | } |
| 1198 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1199 | inline bool apply (hb_apply_context_t *c, unsigned int lookup_type) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1200 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1201 | TRACE_APPLY (); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 1202 | switch (lookup_type) { |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1203 | case Single: return TRACE_RETURN (u.single.apply (c)); |
| 1204 | case Multiple: return TRACE_RETURN (u.multiple.apply (c)); |
| 1205 | case Alternate: return TRACE_RETURN (u.alternate.apply (c)); |
| 1206 | case Ligature: return TRACE_RETURN (u.ligature.apply (c)); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1207 | case Context: return TRACE_RETURN (u.context.apply (c)); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1208 | case ChainContext: return TRACE_RETURN (u.chainContext.apply (c)); |
| 1209 | case Extension: return TRACE_RETURN (u.extension.apply (c)); |
| 1210 | case ReverseChainSingle: return TRACE_RETURN (u.reverseChainContextSingle.apply (c)); |
| 1211 | default: return TRACE_RETURN (false); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 1212 | } |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 1213 | } |
| 1214 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1215 | inline bool sanitize (hb_sanitize_context_t *c, unsigned int lookup_type) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1216 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1217 | if (!u.header.sub_format.sanitize (c)) |
Behdad Esfahbod | faf0f20 | 2012-06-09 03:02:36 -0400 | [diff] [blame] | 1218 | return TRACE_RETURN (false); |
Behdad Esfahbod | fe9bc07 | 2010-05-10 21:39:24 -0400 | [diff] [blame] | 1219 | switch (lookup_type) { |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1220 | case Single: return TRACE_RETURN (u.single.sanitize (c)); |
| 1221 | case Multiple: return TRACE_RETURN (u.multiple.sanitize (c)); |
| 1222 | case Alternate: return TRACE_RETURN (u.alternate.sanitize (c)); |
| 1223 | case Ligature: return TRACE_RETURN (u.ligature.sanitize (c)); |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1224 | case Context: return TRACE_RETURN (u.context.sanitize (c)); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1225 | case ChainContext: return TRACE_RETURN (u.chainContext.sanitize (c)); |
| 1226 | case Extension: return TRACE_RETURN (u.extension.sanitize (c)); |
| 1227 | case ReverseChainSingle: return TRACE_RETURN (u.reverseChainContextSingle.sanitize (c)); |
| 1228 | default: return TRACE_RETURN (true); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1229 | } |
| 1230 | } |
| 1231 | |
Behdad Esfahbod | ec8d249 | 2012-07-24 15:40:37 -0400 | [diff] [blame] | 1232 | protected: |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 1233 | union { |
Behdad Esfahbod | 993c519 | 2012-06-09 02:48:16 -0400 | [diff] [blame] | 1234 | struct { |
| 1235 | USHORT sub_format; |
Behdad Esfahbod | 993c519 | 2012-06-09 02:48:16 -0400 | [diff] [blame] | 1236 | } header; |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 1237 | SingleSubst single; |
| 1238 | MultipleSubst multiple; |
| 1239 | AlternateSubst alternate; |
| 1240 | LigatureSubst ligature; |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1241 | ContextSubst context; |
Behdad Esfahbod | dacebca | 2010-05-10 19:45:41 -0400 | [diff] [blame] | 1242 | ChainContextSubst chainContext; |
| 1243 | ExtensionSubst extension; |
| 1244 | ReverseChainSingleSubst reverseChainContextSingle; |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 1245 | } u; |
Behdad Esfahbod | ed07422 | 2010-05-10 18:08:46 -0400 | [diff] [blame] | 1246 | public: |
Behdad Esfahbod | 993c519 | 2012-06-09 02:48:16 -0400 | [diff] [blame] | 1247 | DEFINE_SIZE_UNION (2, header.sub_format); |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 1248 | }; |
| 1249 | |
Behdad Esfahbod | 4f27ce7 | 2009-04-16 13:40:13 -0400 | [diff] [blame] | 1250 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1251 | struct SubstLookup : Lookup |
| 1252 | { |
Behdad Esfahbod | 6d08c7f | 2012-07-11 18:01:27 -0400 | [diff] [blame] | 1253 | inline const SubstLookupSubTable& get_subtable (unsigned int i) const |
| 1254 | { return this+CastR<OffsetArrayOf<SubstLookupSubTable> > (subTable)[i]; } |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 1255 | |
Behdad Esfahbod | a065f47 | 2010-04-22 20:15:11 -0400 | [diff] [blame] | 1256 | inline static bool lookup_type_is_reverse (unsigned int lookup_type) |
Behdad Esfahbod | 6d08c7f | 2012-07-11 18:01:27 -0400 | [diff] [blame] | 1257 | { return lookup_type == SubstLookupSubTable::ReverseChainSingle; } |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 1258 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1259 | inline bool is_reverse (void) const |
Behdad Esfahbod | a065f47 | 2010-04-22 20:15:11 -0400 | [diff] [blame] | 1260 | { |
| 1261 | unsigned int type = get_type (); |
Behdad Esfahbod | 6d08c7f | 2012-07-11 18:01:27 -0400 | [diff] [blame] | 1262 | if (unlikely (type == SubstLookupSubTable::Extension)) |
Behdad Esfahbod | 187454c | 2010-04-23 16:35:01 -0400 | [diff] [blame] | 1263 | return CastR<ExtensionSubst> (get_subtable(0)).is_reverse (); |
Behdad Esfahbod | a065f47 | 2010-04-22 20:15:11 -0400 | [diff] [blame] | 1264 | return lookup_type_is_reverse (type); |
| 1265 | } |
| 1266 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1267 | inline void closure (hb_closure_context_t *c) const |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1268 | { |
| 1269 | unsigned int lookup_type = get_type (); |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 1270 | unsigned int count = get_subtable_count (); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1271 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1272 | get_subtable (i).closure (c, lookup_type); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1273 | } |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 1274 | |
Behdad Esfahbod | a878c58 | 2012-08-01 21:18:54 -0400 | [diff] [blame] | 1275 | template <typename set_t> |
| 1276 | inline void add_coverage (set_t *glyphs) const |
| 1277 | { |
| 1278 | const Coverage *last = NULL; |
| 1279 | unsigned int count = get_subtable_count (); |
| 1280 | for (unsigned int i = 0; i < count; i++) { |
| 1281 | const Coverage *c = &get_subtable (i).get_coverage (get_type ()); |
| 1282 | if (c != last) { |
| 1283 | c->add_coverage (glyphs); |
| 1284 | last = c; |
| 1285 | } |
| 1286 | } |
| 1287 | } |
| 1288 | |
Behdad Esfahbod | 2bd9fe3 | 2012-09-04 15:15:19 -0400 | [diff] [blame] | 1289 | inline bool would_apply (hb_would_apply_context_t *c, const hb_set_digest_t *digest) const |
Behdad Esfahbod | 3660894 | 2012-04-19 22:21:38 -0400 | [diff] [blame] | 1290 | { |
Behdad Esfahbod | 472f229 | 2012-08-07 22:25:24 -0400 | [diff] [blame] | 1291 | if (unlikely (!c->len)) return false; |
Behdad Esfahbod | 2bd9fe3 | 2012-09-04 15:15:19 -0400 | [diff] [blame] | 1292 | if (!digest->may_have (c->glyphs[0])) return false; |
Behdad Esfahbod | 3660894 | 2012-04-19 22:21:38 -0400 | [diff] [blame] | 1293 | unsigned int lookup_type = get_type (); |
| 1294 | unsigned int count = get_subtable_count (); |
| 1295 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1296 | if (get_subtable (i).would_apply (c, lookup_type)) |
Behdad Esfahbod | 3660894 | 2012-04-19 22:21:38 -0400 | [diff] [blame] | 1297 | return true; |
| 1298 | return false; |
| 1299 | } |
| 1300 | |
Behdad Esfahbod | 41ae674 | 2012-04-11 17:11:05 -0400 | [diff] [blame] | 1301 | inline bool apply_once (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1302 | { |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 1303 | unsigned int lookup_type = get_type (); |
Behdad Esfahbod | 1376fb7 | 2010-04-29 02:19:21 -0400 | [diff] [blame] | 1304 | |
Behdad Esfahbod | 03f67bc | 2012-07-30 19:47:53 -0400 | [diff] [blame] | 1305 | if (!c->check_glyph_property (&c->buffer->cur(), c->lookup_props, &c->property)) |
Behdad Esfahbod | 923923f | 2009-05-22 17:58:09 -0400 | [diff] [blame] | 1306 | return false; |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 1307 | |
Behdad Esfahbod | 29d8644 | 2009-08-04 02:27:37 -0400 | [diff] [blame] | 1308 | unsigned int count = get_subtable_count (); |
| 1309 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1310 | if (get_subtable (i).apply (c, lookup_type)) |
Behdad Esfahbod | ecf17e8 | 2009-05-17 09:34:41 -0400 | [diff] [blame] | 1311 | return true; |
| 1312 | |
| 1313 | return false; |
| 1314 | } |
| 1315 | |
Behdad Esfahbod | 2bd9fe3 | 2012-09-04 15:15:19 -0400 | [diff] [blame] | 1316 | inline bool apply_string (hb_apply_context_t *c, const hb_set_digest_t *digest) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1317 | { |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 1318 | bool ret = false; |
| 1319 | |
Behdad Esfahbod | 1d3947a | 2012-09-04 22:42:17 -0400 | [diff] [blame] | 1320 | if (unlikely (!c->buffer->len || !c->lookup_mask)) |
Behdad Esfahbod | 19fc24f | 2009-05-17 09:45:32 -0400 | [diff] [blame] | 1321 | return false; |
| 1322 | |
Behdad Esfahbod | 650ac00 | 2012-04-23 13:17:09 -0400 | [diff] [blame] | 1323 | c->set_lookup (*this); |
Behdad Esfahbod | 41ae674 | 2012-04-11 17:11:05 -0400 | [diff] [blame] | 1324 | |
Behdad Esfahbod | 64d3fc8 | 2010-05-03 22:51:19 -0400 | [diff] [blame] | 1325 | if (likely (!is_reverse ())) |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1326 | { |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 1327 | /* in/out forward substitution */ |
Behdad Esfahbod | 650ac00 | 2012-04-23 13:17:09 -0400 | [diff] [blame] | 1328 | c->buffer->clear_output (); |
| 1329 | c->buffer->idx = 0; |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 1330 | |
Behdad Esfahbod | 1336ecd | 2012-08-01 21:46:36 -0400 | [diff] [blame] | 1331 | while (c->buffer->idx < c->buffer->len) |
| 1332 | { |
| 1333 | if ((c->buffer->cur().mask & c->lookup_mask) && |
Behdad Esfahbod | 2bd9fe3 | 2012-09-04 15:15:19 -0400 | [diff] [blame] | 1334 | digest->may_have (c->buffer->cur().codepoint) && |
Behdad Esfahbod | 1336ecd | 2012-08-01 21:46:36 -0400 | [diff] [blame] | 1335 | apply_once (c)) |
| 1336 | ret = true; |
| 1337 | else |
| 1338 | c->buffer->next_glyph (); |
| 1339 | } |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 1340 | if (ret) |
Behdad Esfahbod | 650ac00 | 2012-04-23 13:17:09 -0400 | [diff] [blame] | 1341 | c->buffer->swap_buffers (); |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1342 | } |
| 1343 | else |
| 1344 | { |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 1345 | /* in-place backward substitution */ |
Behdad Esfahbod | 0bc7a38 | 2012-10-29 22:02:45 -0700 | [diff] [blame] | 1346 | c->buffer->remove_output (); |
Behdad Esfahbod | 650ac00 | 2012-04-23 13:17:09 -0400 | [diff] [blame] | 1347 | c->buffer->idx = c->buffer->len - 1; |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1348 | do |
| 1349 | { |
Behdad Esfahbod | 1336ecd | 2012-08-01 21:46:36 -0400 | [diff] [blame] | 1350 | if ((c->buffer->cur().mask & c->lookup_mask) && |
Behdad Esfahbod | 2bd9fe3 | 2012-09-04 15:15:19 -0400 | [diff] [blame] | 1351 | digest->may_have (c->buffer->cur().codepoint) && |
Behdad Esfahbod | 1336ecd | 2012-08-01 21:46:36 -0400 | [diff] [blame] | 1352 | apply_once (c)) |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 1353 | ret = true; |
| 1354 | else |
Behdad Esfahbod | 650ac00 | 2012-04-23 13:17:09 -0400 | [diff] [blame] | 1355 | c->buffer->idx--; |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 1356 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1357 | } |
Behdad Esfahbod | 650ac00 | 2012-04-23 13:17:09 -0400 | [diff] [blame] | 1358 | while ((int) c->buffer->idx >= 0); |
Behdad Esfahbod | 5a0b791 | 2009-04-16 04:45:30 -0400 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | return ret; |
| 1362 | } |
Behdad Esfahbod | 29d8644 | 2009-08-04 02:27:37 -0400 | [diff] [blame] | 1363 | |
Behdad Esfahbod | b3b89b6 | 2012-09-04 21:13:17 -0400 | [diff] [blame] | 1364 | private: |
| 1365 | inline SubstLookupSubTable& serialize_subtable (hb_serialize_context_t *c, |
| 1366 | unsigned int i) |
| 1367 | { return CastR<OffsetArrayOf<SubstLookupSubTable> > (subTable)[i].serialize (c, this); } |
| 1368 | public: |
| 1369 | |
| 1370 | inline bool serialize_single (hb_serialize_context_t *c, |
| 1371 | uint32_t lookup_props, |
| 1372 | Supplier<GlyphID> &glyphs, |
| 1373 | Supplier<GlyphID> &substitutes, |
| 1374 | unsigned int num_glyphs) |
| 1375 | { |
| 1376 | TRACE_SERIALIZE (); |
| 1377 | if (unlikely (!Lookup::serialize (c, SubstLookupSubTable::Single, lookup_props, 1))) return TRACE_RETURN (false); |
| 1378 | return TRACE_RETURN (serialize_subtable (c, 0).u.single.serialize (c, glyphs, substitutes, num_glyphs)); |
| 1379 | } |
| 1380 | |
| 1381 | inline bool serialize_multiple (hb_serialize_context_t *c, |
| 1382 | uint32_t lookup_props, |
| 1383 | Supplier<GlyphID> &glyphs, |
| 1384 | Supplier<unsigned int> &substitute_len_list, |
| 1385 | unsigned int num_glyphs, |
| 1386 | Supplier<GlyphID> &substitute_glyphs_list) |
| 1387 | { |
| 1388 | TRACE_SERIALIZE (); |
| 1389 | if (unlikely (!Lookup::serialize (c, SubstLookupSubTable::Multiple, lookup_props, 1))) return TRACE_RETURN (false); |
| 1390 | return TRACE_RETURN (serialize_subtable (c, 0).u.multiple.serialize (c, glyphs, substitute_len_list, num_glyphs, |
| 1391 | substitute_glyphs_list)); |
| 1392 | } |
| 1393 | |
| 1394 | inline bool serialize_alternate (hb_serialize_context_t *c, |
| 1395 | uint32_t lookup_props, |
| 1396 | Supplier<GlyphID> &glyphs, |
| 1397 | Supplier<unsigned int> &alternate_len_list, |
| 1398 | unsigned int num_glyphs, |
| 1399 | Supplier<GlyphID> &alternate_glyphs_list) |
| 1400 | { |
| 1401 | TRACE_SERIALIZE (); |
| 1402 | if (unlikely (!Lookup::serialize (c, SubstLookupSubTable::Alternate, lookup_props, 1))) return TRACE_RETURN (false); |
| 1403 | return TRACE_RETURN (serialize_subtable (c, 0).u.alternate.serialize (c, glyphs, alternate_len_list, num_glyphs, |
| 1404 | alternate_glyphs_list)); |
| 1405 | } |
| 1406 | |
| 1407 | inline bool serialize_ligature (hb_serialize_context_t *c, |
| 1408 | uint32_t lookup_props, |
| 1409 | Supplier<GlyphID> &first_glyphs, |
| 1410 | Supplier<unsigned int> &ligature_per_first_glyph_count_list, |
| 1411 | unsigned int num_first_glyphs, |
| 1412 | Supplier<GlyphID> &ligatures_list, |
| 1413 | Supplier<unsigned int> &component_count_list, |
| 1414 | Supplier<GlyphID> &component_list /* Starting from second for each ligature */) |
| 1415 | { |
| 1416 | TRACE_SERIALIZE (); |
| 1417 | if (unlikely (!Lookup::serialize (c, SubstLookupSubTable::Ligature, lookup_props, 1))) return TRACE_RETURN (false); |
| 1418 | return TRACE_RETURN (serialize_subtable (c, 0).u.ligature.serialize (c, first_glyphs, ligature_per_first_glyph_count_list, num_first_glyphs, |
| 1419 | ligatures_list, component_count_list, component_list)); |
| 1420 | } |
| 1421 | |
| 1422 | inline bool sanitize (hb_sanitize_context_t *c) |
| 1423 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1424 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1425 | if (unlikely (!Lookup::sanitize (c))) return TRACE_RETURN (false); |
Behdad Esfahbod | 6d08c7f | 2012-07-11 18:01:27 -0400 | [diff] [blame] | 1426 | OffsetArrayOf<SubstLookupSubTable> &list = CastR<OffsetArrayOf<SubstLookupSubTable> > (subTable); |
Behdad Esfahbod | 338fe66 | 2012-07-28 18:53:01 -0400 | [diff] [blame] | 1427 | if (unlikely (!list.sanitize (c, this, get_type ()))) return TRACE_RETURN (false); |
| 1428 | |
| 1429 | if (unlikely (get_type () == SubstLookupSubTable::Extension)) |
| 1430 | { |
| 1431 | /* The spec says all subtables of an Extension lookup should |
| 1432 | * have the same type. This is specially important if one has |
| 1433 | * a reverse type! |
| 1434 | * |
| 1435 | * We just check that they are all either forward, or reverse. */ |
| 1436 | unsigned int type = get_subtable (0).u.extension.get_type (); |
| 1437 | unsigned int count = get_subtable_count (); |
| 1438 | for (unsigned int i = 1; i < count; i++) |
| 1439 | if (get_subtable (i).u.extension.get_type () != type) |
| 1440 | return TRACE_RETURN (false); |
| 1441 | } |
| 1442 | return TRACE_RETURN (true); |
Behdad Esfahbod | 29d8644 | 2009-08-04 02:27:37 -0400 | [diff] [blame] | 1443 | } |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 1444 | }; |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 1445 | |
Behdad Esfahbod | 29d8644 | 2009-08-04 02:27:37 -0400 | [diff] [blame] | 1446 | typedef OffsetListOf<SubstLookup> SubstLookupList; |
Behdad Esfahbod | c43562b | 2009-05-15 18:54:53 -0400 | [diff] [blame] | 1447 | |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 1448 | /* |
Behdad Esfahbod | ae9877d | 2011-08-17 14:43:45 +0200 | [diff] [blame] | 1449 | * GSUB -- The Glyph Substitution Table |
Behdad Esfahbod | 7586089 | 2008-01-23 18:02:28 -0500 | [diff] [blame] | 1450 | */ |
| 1451 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1452 | struct GSUB : GSUBGPOS |
| 1453 | { |
Behdad Esfahbod | a328d66 | 2009-08-04 20:27:05 -0400 | [diff] [blame] | 1454 | static const hb_tag_t Tag = HB_OT_TAG_GSUB; |
Behdad Esfahbod | 7586089 | 2008-01-23 18:02:28 -0500 | [diff] [blame] | 1455 | |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1456 | inline const SubstLookup& get_lookup (unsigned int i) const |
Behdad Esfahbod | 187454c | 2010-04-23 16:35:01 -0400 | [diff] [blame] | 1457 | { return CastR<SubstLookup> (GSUBGPOS::get_lookup (i)); } |
Behdad Esfahbod | 2d15e72 | 2009-04-15 19:50:16 -0400 | [diff] [blame] | 1458 | |
Behdad Esfahbod | a878c58 | 2012-08-01 21:18:54 -0400 | [diff] [blame] | 1459 | template <typename set_t> |
| 1460 | inline void add_coverage (set_t *glyphs, unsigned int lookup_index) const |
| 1461 | { get_lookup (lookup_index).add_coverage (glyphs); } |
| 1462 | |
Behdad Esfahbod | afbcc24 | 2012-08-02 08:36:40 -0400 | [diff] [blame] | 1463 | static inline void substitute_start (hb_font_t *font, hb_buffer_t *buffer); |
| 1464 | static inline void substitute_finish (hb_font_t *font, hb_buffer_t *buffer); |
Behdad Esfahbod | a9ad3d3 | 2011-07-28 15:42:18 -0400 | [diff] [blame] | 1465 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1466 | inline void closure_lookup (hb_closure_context_t *c, |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1467 | unsigned int lookup_index) const |
| 1468 | { return get_lookup (lookup_index).closure (c); } |
| 1469 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1470 | inline bool sanitize (hb_sanitize_context_t *c) { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1471 | TRACE_SANITIZE (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1472 | if (unlikely (!GSUBGPOS::sanitize (c))) return TRACE_RETURN (false); |
Behdad Esfahbod | 187454c | 2010-04-23 16:35:01 -0400 | [diff] [blame] | 1473 | OffsetTo<SubstLookupList> &list = CastR<OffsetTo<SubstLookupList> > (lookupList); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1474 | return TRACE_RETURN (list.sanitize (c, this)); |
Behdad Esfahbod | 29d8644 | 2009-08-04 02:27:37 -0400 | [diff] [blame] | 1475 | } |
Behdad Esfahbod | b365123 | 2010-05-10 16:57:29 -0400 | [diff] [blame] | 1476 | public: |
| 1477 | DEFINE_SIZE_STATIC (10); |
Behdad Esfahbod | 7586089 | 2008-01-23 18:02:28 -0500 | [diff] [blame] | 1478 | }; |
Behdad Esfahbod | c43562b | 2009-05-15 18:54:53 -0400 | [diff] [blame] | 1479 | |
| 1480 | |
Behdad Esfahbod | a9ad3d3 | 2011-07-28 15:42:18 -0400 | [diff] [blame] | 1481 | void |
Behdad Esfahbod | afbcc24 | 2012-08-02 08:36:40 -0400 | [diff] [blame] | 1482 | GSUB::substitute_start (hb_font_t *font, hb_buffer_t *buffer) |
Behdad Esfahbod | a9ad3d3 | 2011-07-28 15:42:18 -0400 | [diff] [blame] | 1483 | { |
Behdad Esfahbod | c2e42c3 | 2012-07-30 19:54:50 -0400 | [diff] [blame] | 1484 | HB_BUFFER_ALLOCATE_VAR (buffer, glyph_props); |
Behdad Esfahbod | a9844d4 | 2012-05-09 17:53:13 +0200 | [diff] [blame] | 1485 | HB_BUFFER_ALLOCATE_VAR (buffer, lig_props); |
Behdad Esfahbod | cee7187 | 2012-05-11 11:41:39 +0200 | [diff] [blame] | 1486 | HB_BUFFER_ALLOCATE_VAR (buffer, syllable); |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 1487 | |
Behdad Esfahbod | afbcc24 | 2012-08-02 08:36:40 -0400 | [diff] [blame] | 1488 | const GDEF &gdef = *hb_ot_layout_from_face (font->face)->gdef; |
Behdad Esfahbod | a9ad3d3 | 2011-07-28 15:42:18 -0400 | [diff] [blame] | 1489 | unsigned int count = buffer->len; |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 1490 | for (unsigned int i = 0; i < count; i++) { |
| 1491 | buffer->info[i].lig_props() = buffer->info[i].syllable() = 0; |
Behdad Esfahbod | c2e42c3 | 2012-07-30 19:54:50 -0400 | [diff] [blame] | 1492 | buffer->info[i].glyph_props() = gdef.get_glyph_props (buffer->info[i].codepoint); |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 1493 | } |
Behdad Esfahbod | a9ad3d3 | 2011-07-28 15:42:18 -0400 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | void |
Behdad Esfahbod | afbcc24 | 2012-08-02 08:36:40 -0400 | [diff] [blame] | 1497 | GSUB::substitute_finish (hb_font_t *font HB_UNUSED, hb_buffer_t *buffer HB_UNUSED) |
Behdad Esfahbod | a9ad3d3 | 2011-07-28 15:42:18 -0400 | [diff] [blame] | 1498 | { |
| 1499 | } |
| 1500 | |
| 1501 | |
Behdad Esfahbod | 887c4b4 | 2009-05-17 21:06:08 -0400 | [diff] [blame] | 1502 | /* Out-of-class implementation for methods recursing */ |
Behdad Esfahbod | c43562b | 2009-05-15 18:54:53 -0400 | [diff] [blame] | 1503 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1504 | inline void ExtensionSubst::closure (hb_closure_context_t *c) const |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 1505 | { |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1506 | get_subtable ().closure (c, get_type ()); |
Behdad Esfahbod | c64ddab | 2012-04-23 15:28:35 -0400 | [diff] [blame] | 1507 | } |
| 1508 | |
Behdad Esfahbod | 0b99429 | 2012-07-28 17:31:01 -0400 | [diff] [blame] | 1509 | inline const Coverage & ExtensionSubst::get_coverage (void) const |
| 1510 | { |
| 1511 | return get_subtable ().get_coverage (get_type ()); |
| 1512 | } |
| 1513 | |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1514 | inline bool ExtensionSubst::would_apply (hb_would_apply_context_t *c) const |
Behdad Esfahbod | 3660894 | 2012-04-19 22:21:38 -0400 | [diff] [blame] | 1515 | { |
Behdad Esfahbod | e72b360 | 2012-07-19 14:35:23 -0400 | [diff] [blame] | 1516 | return get_subtable ().would_apply (c, get_type ()); |
Behdad Esfahbod | 3660894 | 2012-04-19 22:21:38 -0400 | [diff] [blame] | 1517 | } |
| 1518 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1519 | inline bool ExtensionSubst::apply (hb_apply_context_t *c) const |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1520 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1521 | TRACE_APPLY (); |
Behdad Esfahbod | acea183 | 2012-05-11 02:33:11 +0200 | [diff] [blame] | 1522 | return TRACE_RETURN (get_subtable ().apply (c, get_type ())); |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1523 | } |
| 1524 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1525 | inline bool ExtensionSubst::sanitize (hb_sanitize_context_t *c) |
Behdad Esfahbod | 70de50c | 2009-08-04 00:58:28 -0400 | [diff] [blame] | 1526 | { |
Behdad Esfahbod | 3e2401f | 2009-08-28 17:17:11 -0400 | [diff] [blame] | 1527 | TRACE_SANITIZE (); |
Behdad Esfahbod | 6d08c7f | 2012-07-11 18:01:27 -0400 | [diff] [blame] | 1528 | if (unlikely (!Extension::sanitize (c))) return TRACE_RETURN (false); |
Behdad Esfahbod | 3b2c2df | 2010-04-22 16:51:42 -0400 | [diff] [blame] | 1529 | unsigned int offset = get_offset (); |
Behdad Esfahbod | 0ab8c86 | 2012-05-11 01:25:34 +0200 | [diff] [blame] | 1530 | if (unlikely (!offset)) return TRACE_RETURN (true); |
Behdad Esfahbod | 6d08c7f | 2012-07-11 18:01:27 -0400 | [diff] [blame] | 1531 | return TRACE_RETURN (StructAtOffset<SubstLookupSubTable> (this, offset).sanitize (c, get_type ())); |
Behdad Esfahbod | c43562b | 2009-05-15 18:54:53 -0400 | [diff] [blame] | 1532 | } |
| 1533 | |
Behdad Esfahbod | a065f47 | 2010-04-22 20:15:11 -0400 | [diff] [blame] | 1534 | inline bool ExtensionSubst::is_reverse (void) const |
| 1535 | { |
| 1536 | unsigned int type = get_type (); |
Behdad Esfahbod | 6d08c7f | 2012-07-11 18:01:27 -0400 | [diff] [blame] | 1537 | if (unlikely (type == SubstLookupSubTable::Extension)) |
Behdad Esfahbod | 187454c | 2010-04-23 16:35:01 -0400 | [diff] [blame] | 1538 | return CastR<ExtensionSubst> (get_subtable()).is_reverse (); |
Behdad Esfahbod | a065f47 | 2010-04-22 20:15:11 -0400 | [diff] [blame] | 1539 | return SubstLookup::lookup_type_is_reverse (type); |
| 1540 | } |
| 1541 | |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1542 | static inline void closure_lookup (hb_closure_context_t *c, unsigned int lookup_index) |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1543 | { |
Behdad Esfahbod | ea278d3 | 2012-07-27 02:12:28 -0400 | [diff] [blame] | 1544 | const GSUB &gsub = *(hb_ot_layout_from_face (c->face)->gsub); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1545 | const SubstLookup &l = gsub.get_lookup (lookup_index); |
| 1546 | |
| 1547 | if (unlikely (c->nesting_level_left == 0)) |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1548 | return; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1549 | |
| 1550 | c->nesting_level_left--; |
Behdad Esfahbod | 5caece6 | 2012-04-23 23:03:12 -0400 | [diff] [blame] | 1551 | l.closure (c); |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1552 | c->nesting_level_left++; |
Behdad Esfahbod | f94b0aa | 2012-04-23 13:04:38 -0400 | [diff] [blame] | 1553 | } |
| 1554 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1555 | static inline bool substitute_lookup (hb_apply_context_t *c, unsigned int lookup_index) |
Behdad Esfahbod | 4c44d83 | 2009-05-19 23:42:30 -0400 | [diff] [blame] | 1556 | { |
Behdad Esfahbod | ea278d3 | 2012-07-27 02:12:28 -0400 | [diff] [blame] | 1557 | const GSUB &gsub = *(hb_ot_layout_from_face (c->face)->gsub); |
Behdad Esfahbod | a162552 | 2009-05-17 07:52:11 -0400 | [diff] [blame] | 1558 | const SubstLookup &l = gsub.get_lookup (lookup_index); |
Behdad Esfahbod | c43562b | 2009-05-15 18:54:53 -0400 | [diff] [blame] | 1559 | |
Behdad Esfahbod | d7cfb3b | 2010-05-13 14:18:49 -0400 | [diff] [blame] | 1560 | if (unlikely (c->nesting_level_left == 0)) |
Behdad Esfahbod | eca8e33 | 2009-05-17 09:07:27 -0400 | [diff] [blame] | 1561 | return false; |
Behdad Esfahbod | eca8e33 | 2009-05-17 09:07:27 -0400 | [diff] [blame] | 1562 | |
Behdad Esfahbod | 650ac00 | 2012-04-23 13:17:09 -0400 | [diff] [blame] | 1563 | hb_apply_context_t new_c (*c); |
| 1564 | new_c.nesting_level_left--; |
| 1565 | new_c.set_lookup (l); |
Behdad Esfahbod | 41ae674 | 2012-04-11 17:11:05 -0400 | [diff] [blame] | 1566 | return l.apply_once (&new_c); |
Behdad Esfahbod | c43562b | 2009-05-15 18:54:53 -0400 | [diff] [blame] | 1567 | } |
| 1568 | |
| 1569 | |
Behdad Esfahbod | 7c8e844 | 2012-08-28 17:57:49 -0400 | [diff] [blame] | 1570 | } // namespace OT |
| 1571 | |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 1572 | |
Behdad Esfahbod | 7a750ac | 2011-08-17 14:19:59 +0200 | [diff] [blame] | 1573 | #endif /* HB_OT_LAYOUT_GSUB_TABLE_HH */ |