hb-ot-layout-gsub-table.hh 43.2 KB
Newer Older
B
Behdad Esfahbod 已提交
1
/*
B
Behdad Esfahbod 已提交
2
 * Copyright © 2007,2008,2009,2010  Red Hat, Inc.
B
Behdad Esfahbod 已提交
3
 * Copyright © 2010,2012  Google, Inc.
B
Behdad Esfahbod 已提交
4
 *
B
Behdad Esfahbod 已提交
5
 *  This is part of HarfBuzz, a text shaping library.
B
Behdad Esfahbod 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * Permission is hereby granted, without written agreement and without
 * license or royalty fees, to use, copy, modify, and distribute this
 * software and its documentation for any purpose, provided that the
 * above copyright notice and the following two paragraphs appear in
 * all copies of this software.
 *
 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * Red Hat Author(s): Behdad Esfahbod
26
 * Google Author(s): Behdad Esfahbod
B
Behdad Esfahbod 已提交
27 28
 */

29 30
#ifndef HB_OT_LAYOUT_GSUB_TABLE_HH
#define HB_OT_LAYOUT_GSUB_TABLE_HH
B
Behdad Esfahbod 已提交
31

32
#include "hb-ot-layout-gsubgpos-private.hh"
B
Behdad Esfahbod 已提交
33

B
Behdad Esfahbod 已提交
34

35 36
namespace OT {

37

B
Behdad Esfahbod 已提交
38 39
struct SingleSubstFormat1
{
B
Behdad Esfahbod 已提交
40
  inline void closure (hb_closure_context_t *c) const
41
  {
B
Behdad Esfahbod 已提交
42
    TRACE_CLOSURE (this);
B
Behdad Esfahbod 已提交
43 44 45 46
    Coverage::Iter iter;
    for (iter.init (this+coverage); iter.more (); iter.next ()) {
      hb_codepoint_t glyph_id = iter.get_glyph ();
      if (c->glyphs->has (glyph_id))
B
Behdad Esfahbod 已提交
47
	c->glyphs->add ((glyph_id + deltaGlyphID) & 0xFFFF);
B
Behdad Esfahbod 已提交
48
    }
49 50
  }

51 52
  inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
  {
B
Behdad Esfahbod 已提交
53
    TRACE_COLLECT_GLYPHS (this);
54 55 56 57 58 59 60 61
    Coverage::Iter iter;
    for (iter.init (this+coverage); iter.more (); iter.next ()) {
      hb_codepoint_t glyph_id = iter.get_glyph ();
      c->input.add (glyph_id);
      c->output.add ((glyph_id + deltaGlyphID) & 0xFFFF);
    }
  }

62 63 64 65 66
  inline const Coverage &get_coverage (void) const
  {
    return this+coverage;
  }

67 68
  inline bool would_apply (hb_would_apply_context_t *c) const
  {
B
Behdad Esfahbod 已提交
69
    TRACE_WOULD_APPLY (this);
70
    return TRACE_RETURN (c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED);
71 72
  }

B
Behdad Esfahbod 已提交
73
  inline bool apply (hb_apply_context_t *c) const
B
Behdad Esfahbod 已提交
74
  {
B
Behdad Esfahbod 已提交
75
    TRACE_APPLY (this);
76
    hb_codepoint_t glyph_id = c->buffer->cur().codepoint;
77
    unsigned int index = (this+coverage).get_coverage (glyph_id);
78
    if (likely (index == NOT_COVERED)) return TRACE_RETURN (false);
B
Behdad Esfahbod 已提交
79

80 81 82
    /* According to the Adobe Annotated OpenType Suite, result is always
     * limited to 16bit. */
    glyph_id = (glyph_id + deltaGlyphID) & 0xFFFF;
83
    c->replace_glyph (glyph_id);
B
Behdad Esfahbod 已提交
84

85
    return TRACE_RETURN (true);
86
  }
B
Behdad Esfahbod 已提交
87

88
  inline bool serialize (hb_serialize_context_t *c,
89
			 Supplier<GlyphID> &glyphs,
90
			 unsigned int num_glyphs,
B
Minor  
Behdad Esfahbod 已提交
91
			 int delta)
92
  {
B
Behdad Esfahbod 已提交
93
    TRACE_SERIALIZE (this);
94
    if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false);
B
Behdad Esfahbod 已提交
95
    if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs, num_glyphs))) return TRACE_RETURN (false);
B
Minor  
Behdad Esfahbod 已提交
96
    deltaGlyphID.set (delta); /* TODO(serilaize) overflow? */
97 98 99
    return TRACE_RETURN (true);
  }

B
Behdad Esfahbod 已提交
100
  inline bool sanitize (hb_sanitize_context_t *c) {
B
Behdad Esfahbod 已提交
101
    TRACE_SANITIZE (this);
102
    return TRACE_RETURN (coverage.sanitize (c, this) && deltaGlyphID.sanitize (c));
B
Behdad Esfahbod 已提交
103 104
  }

105
  protected:
B
Behdad Esfahbod 已提交
106
  USHORT	format;			/* Format identifier--format = 1 */
B
Behdad Esfahbod 已提交
107 108
  OffsetTo<Coverage>
		coverage;		/* Offset to Coverage table--from
B
Behdad Esfahbod 已提交
109 110 111
					 * beginning of Substitution table */
  SHORT		deltaGlyphID;		/* Add to original GlyphID to get
					 * substitute GlyphID */
112 113
  public:
  DEFINE_SIZE_STATIC (6);
B
Behdad Esfahbod 已提交
114 115
};

B
Behdad Esfahbod 已提交
116 117
struct SingleSubstFormat2
{
B
Behdad Esfahbod 已提交
118
  inline void closure (hb_closure_context_t *c) const
119
  {
B
Behdad Esfahbod 已提交
120
    TRACE_CLOSURE (this);
B
Behdad Esfahbod 已提交
121 122 123
    Coverage::Iter iter;
    for (iter.init (this+coverage); iter.more (); iter.next ()) {
      if (c->glyphs->has (iter.get_glyph ()))
B
Behdad Esfahbod 已提交
124
	c->glyphs->add (substitute[iter.get_coverage ()]);
B
Behdad Esfahbod 已提交
125
    }
126 127
  }

128 129
  inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
  {
B
Behdad Esfahbod 已提交
130
    TRACE_COLLECT_GLYPHS (this);
131 132 133 134 135 136 137
    Coverage::Iter iter;
    for (iter.init (this+coverage); iter.more (); iter.next ()) {
      c->input.add (iter.get_glyph ());
      c->output.add (substitute[iter.get_coverage ()]);
    }
  }

138 139 140 141 142
  inline const Coverage &get_coverage (void) const
  {
    return this+coverage;
  }

143 144
  inline bool would_apply (hb_would_apply_context_t *c) const
  {
B
Behdad Esfahbod 已提交
145
    TRACE_WOULD_APPLY (this);
146
    return TRACE_RETURN (c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED);
147 148
  }

B
Behdad Esfahbod 已提交
149
  inline bool apply (hb_apply_context_t *c) const
B
Behdad Esfahbod 已提交
150
  {
B
Behdad Esfahbod 已提交
151
    TRACE_APPLY (this);
152
    hb_codepoint_t glyph_id = c->buffer->cur().codepoint;
153
    unsigned int index = (this+coverage).get_coverage (glyph_id);
154
    if (likely (index == NOT_COVERED)) return TRACE_RETURN (false);
155

156
    if (unlikely (index >= substitute.len)) return TRACE_RETURN (false);
157 158

    glyph_id = substitute[index];
159
    c->replace_glyph (glyph_id);
B
Behdad Esfahbod 已提交
160

161
    return TRACE_RETURN (true);
162
  }
B
Behdad Esfahbod 已提交
163

B
Behdad Esfahbod 已提交
164
  inline bool serialize (hb_serialize_context_t *c,
165 166
			 Supplier<GlyphID> &glyphs,
			 Supplier<GlyphID> &substitutes,
B
Behdad Esfahbod 已提交
167 168
			 unsigned int num_glyphs)
  {
B
Behdad Esfahbod 已提交
169
    TRACE_SERIALIZE (this);
B
Behdad Esfahbod 已提交
170 171
    if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false);
    if (unlikely (!substitute.serialize (c, substitutes, num_glyphs))) return TRACE_RETURN (false);
172
    if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs, num_glyphs))) return TRACE_RETURN (false);
B
Behdad Esfahbod 已提交
173 174 175
    return TRACE_RETURN (true);
  }

B
Behdad Esfahbod 已提交
176
  inline bool sanitize (hb_sanitize_context_t *c) {
B
Behdad Esfahbod 已提交
177
    TRACE_SANITIZE (this);
178
    return TRACE_RETURN (coverage.sanitize (c, this) && substitute.sanitize (c));
B
Behdad Esfahbod 已提交
179 180
  }

181
  protected:
B
Behdad Esfahbod 已提交
182
  USHORT	format;			/* Format identifier--format = 2 */
B
Behdad Esfahbod 已提交
183 184
  OffsetTo<Coverage>
		coverage;		/* Offset to Coverage table--from
B
Behdad Esfahbod 已提交
185
					 * beginning of Substitution table */
B
Behdad Esfahbod 已提交
186 187 188
  ArrayOf<GlyphID>
		substitute;		/* Array of substitute
					 * GlyphIDs--ordered by Coverage Index */
189
  public:
190
  DEFINE_SIZE_ARRAY (6, substitute);
B
Behdad Esfahbod 已提交
191 192
};

B
Behdad Esfahbod 已提交
193 194
struct SingleSubst
{
195 196
  template <typename context_t>
  inline typename context_t::return_t process (context_t *c) const
197
  {
B
Behdad Esfahbod 已提交
198
    TRACE_PROCESS (this);
199
    switch (u.format) {
B
Behdad Esfahbod 已提交
200 201 202
    case 1: return TRACE_RETURN (c->process (u.format1));
    case 2: return TRACE_RETURN (c->process (u.format2));
    default:return TRACE_RETURN (c->default_return_value ());
203 204 205
    }
  }

B
Behdad Esfahbod 已提交
206
  inline bool serialize (hb_serialize_context_t *c,
207 208
			 Supplier<GlyphID> &glyphs,
			 Supplier<GlyphID> &substitutes,
B
Behdad Esfahbod 已提交
209 210
			 unsigned int num_glyphs)
  {
B
Behdad Esfahbod 已提交
211
    TRACE_SERIALIZE (this);
B
Behdad Esfahbod 已提交
212 213
    if (unlikely (!c->extend_min (u.format))) return TRACE_RETURN (false);
    unsigned int format = 2;
B
Minor  
Behdad Esfahbod 已提交
214
    int delta;
B
Behdad Esfahbod 已提交
215 216
    if (num_glyphs) {
      format = 1;
B
Minor  
Behdad Esfahbod 已提交
217
      /* TODO(serialize) check for wrap-around */
B
Behdad Esfahbod 已提交
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
      delta = substitutes[0] - glyphs[0];
      for (unsigned int i = 1; i < num_glyphs; i++)
	if (delta != substitutes[i] - glyphs[i]) {
	  format = 2;
	  break;
	}
    }
    u.format.set (format);
    switch (u.format) {
    case 1: return TRACE_RETURN (u.format1.serialize (c, glyphs, num_glyphs, delta));
    case 2: return TRACE_RETURN (u.format2.serialize (c, glyphs, substitutes, num_glyphs));
    default:return TRACE_RETURN (false);
    }
  }

B
Behdad Esfahbod 已提交
233
  inline bool sanitize (hb_sanitize_context_t *c) {
B
Behdad Esfahbod 已提交
234
    TRACE_SANITIZE (this);
235
    if (!u.format.sanitize (c)) return TRACE_RETURN (false);
B
Behdad Esfahbod 已提交
236
    switch (u.format) {
237 238 239
    case 1: return TRACE_RETURN (u.format1.sanitize (c));
    case 2: return TRACE_RETURN (u.format2.sanitize (c));
    default:return TRACE_RETURN (true);
B
Behdad Esfahbod 已提交
240 241 242
    }
  }

243
  protected:
244
  union {
B
Behdad Esfahbod 已提交
245
  USHORT		format;		/* Format identifier */
B
Behdad Esfahbod 已提交
246 247
  SingleSubstFormat1	format1;
  SingleSubstFormat2	format2;
248
  } u;
B
Behdad Esfahbod 已提交
249
};
250

B
Behdad Esfahbod 已提交
251

B
Behdad Esfahbod 已提交
252 253
struct Sequence
{
B
Behdad Esfahbod 已提交
254
  inline void closure (hb_closure_context_t *c) const
255
  {
B
Behdad Esfahbod 已提交
256
    TRACE_CLOSURE (this);
B
Behdad Esfahbod 已提交
257 258
    unsigned int count = substitute.len;
    for (unsigned int i = 0; i < count; i++)
B
Behdad Esfahbod 已提交
259
      c->glyphs->add (substitute[i]);
260 261
  }

262 263
  inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
  {
B
Behdad Esfahbod 已提交
264
    TRACE_COLLECT_GLYPHS (this);
265 266 267 268 269
    unsigned int count = substitute.len;
    for (unsigned int i = 0; i < count; i++)
      c->output.add (substitute[i]);
  }

B
Behdad Esfahbod 已提交
270
  inline bool apply (hb_apply_context_t *c) const
B
Behdad Esfahbod 已提交
271
  {
B
Behdad Esfahbod 已提交
272
    TRACE_APPLY (this);
273
    if (unlikely (!substitute.len)) return TRACE_RETURN (false);
B
Behdad Esfahbod 已提交
274

275
    unsigned int klass = c->property & HB_OT_LAYOUT_GLYPH_PROPS_LIGATURE ? HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH : 0;
276
    unsigned int count = substitute.len;
277
    for (unsigned int i = 0; i < count; i++) {
B
Behdad Esfahbod 已提交
278
      set_lig_props_for_component (c->buffer->cur(), i);
279
      c->output_glyph (substitute.array[i], klass);
280
    }
281
    c->buffer->skip_glyph ();
B
Behdad Esfahbod 已提交
282

283
    return TRACE_RETURN (true);
B
Behdad Esfahbod 已提交
284 285
  }

286
  inline bool serialize (hb_serialize_context_t *c,
287
			 Supplier<GlyphID> &glyphs,
288 289
			 unsigned int num_glyphs)
  {
B
Behdad Esfahbod 已提交
290
    TRACE_SERIALIZE (this);
291 292 293 294 295
    if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false);
    if (unlikely (!substitute.serialize (c, glyphs, num_glyphs))) return TRACE_RETURN (false);
    return TRACE_RETURN (true);
  }

B
Behdad Esfahbod 已提交
296
  inline bool sanitize (hb_sanitize_context_t *c) {
B
Behdad Esfahbod 已提交
297
    TRACE_SANITIZE (this);
298
    return TRACE_RETURN (substitute.sanitize (c));
B
Behdad Esfahbod 已提交
299 300
  }

301
  protected:
B
Behdad Esfahbod 已提交
302 303
  ArrayOf<GlyphID>
		substitute;		/* String of GlyphIDs to substitute */
304
  public:
305
  DEFINE_SIZE_ARRAY (2, substitute);
B
Behdad Esfahbod 已提交
306 307
};

B
Behdad Esfahbod 已提交
308 309
struct MultipleSubstFormat1
{
B
Behdad Esfahbod 已提交
310
  inline void closure (hb_closure_context_t *c) const
311
  {
B
Behdad Esfahbod 已提交
312
    TRACE_CLOSURE (this);
B
Behdad Esfahbod 已提交
313 314 315
    Coverage::Iter iter;
    for (iter.init (this+coverage); iter.more (); iter.next ()) {
      if (c->glyphs->has (iter.get_glyph ()))
B
Behdad Esfahbod 已提交
316
	(this+sequence[iter.get_coverage ()]).closure (c);
B
Behdad Esfahbod 已提交
317
    }
318 319
  }

320 321
  inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
  {
B
Behdad Esfahbod 已提交
322
    TRACE_COLLECT_GLYPHS (this);
323 324 325 326 327 328
    (this+coverage).add_coverage (&c->input);
    unsigned int count = sequence.len;
    for (unsigned int i = 0; i < count; i++)
	(this+sequence[i]).collect_glyphs (c);
  }

329 330 331 332 333
  inline const Coverage &get_coverage (void) const
  {
    return this+coverage;
  }

334 335
  inline bool would_apply (hb_would_apply_context_t *c) const
  {
B
Behdad Esfahbod 已提交
336
    TRACE_WOULD_APPLY (this);
337
    return TRACE_RETURN (c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED);
338 339
  }

B
Behdad Esfahbod 已提交
340
  inline bool apply (hb_apply_context_t *c) const
B
Behdad Esfahbod 已提交
341
  {
B
Behdad Esfahbod 已提交
342
    TRACE_APPLY (this);
343

344
    unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
345
    if (likely (index == NOT_COVERED)) return TRACE_RETURN (false);
346

347
    return TRACE_RETURN ((this+sequence[index]).apply (c));
348
  }
B
Behdad Esfahbod 已提交
349

350
  inline bool serialize (hb_serialize_context_t *c,
351 352
			 Supplier<GlyphID> &glyphs,
			 Supplier<unsigned int> &substitute_len_list,
353
			 unsigned int num_glyphs,
354
			 Supplier<GlyphID> &substitute_glyphs_list)
355
  {
B
Behdad Esfahbod 已提交
356
    TRACE_SERIALIZE (this);
357 358
    if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false);
    if (unlikely (!sequence.serialize (c, num_glyphs))) return TRACE_RETURN (false);
359 360 361 362 363
    for (unsigned int i = 0; i < num_glyphs; i++)
      if (unlikely (!sequence[i].serialize (c, this).serialize (c,
								substitute_glyphs_list,
								substitute_len_list[i]))) return TRACE_RETURN (false);
    substitute_len_list.advance (num_glyphs);
364
    if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs, num_glyphs))) return TRACE_RETURN (false);
365 366 367
    return TRACE_RETURN (true);
  }

B
Behdad Esfahbod 已提交
368
  inline bool sanitize (hb_sanitize_context_t *c) {
B
Behdad Esfahbod 已提交
369
    TRACE_SANITIZE (this);
370
    return TRACE_RETURN (coverage.sanitize (c, this) && sequence.sanitize (c, this));
B
Behdad Esfahbod 已提交
371 372
  }

373
  protected:
B
Behdad Esfahbod 已提交
374
  USHORT	format;			/* Format identifier--format = 1 */
B
Behdad Esfahbod 已提交
375 376
  OffsetTo<Coverage>
		coverage;		/* Offset to Coverage table--from
B
Behdad Esfahbod 已提交
377
					 * beginning of Substitution table */
B
Behdad Esfahbod 已提交
378 379 380
  OffsetArrayOf<Sequence>
		sequence;		/* Array of Sequence tables
					 * ordered by Coverage Index */
381
  public:
382
  DEFINE_SIZE_ARRAY (6, sequence);
B
Behdad Esfahbod 已提交
383
};
384

B
Behdad Esfahbod 已提交
385 386
struct MultipleSubst
{
387 388
  template <typename context_t>
  inline typename context_t::return_t process (context_t *c) const
389
  {
B
Behdad Esfahbod 已提交
390
    TRACE_PROCESS (this);
391
    switch (u.format) {
B
Behdad Esfahbod 已提交
392 393
    case 1: return TRACE_RETURN (c->process (u.format1));
    default:return TRACE_RETURN (c->default_return_value ());
394 395 396
    }
  }

397
  inline bool serialize (hb_serialize_context_t *c,
398 399
			 Supplier<GlyphID> &glyphs,
			 Supplier<unsigned int> &substitute_len_list,
400
			 unsigned int num_glyphs,
401
			 Supplier<GlyphID> &substitute_glyphs_list)
402
  {
B
Behdad Esfahbod 已提交
403
    TRACE_SERIALIZE (this);
404 405 406 407 408 409 410 411 412
    if (unlikely (!c->extend_min (u.format))) return TRACE_RETURN (false);
    unsigned int format = 1;
    u.format.set (format);
    switch (u.format) {
    case 1: return TRACE_RETURN (u.format1.serialize (c, glyphs, substitute_len_list, num_glyphs, substitute_glyphs_list));
    default:return TRACE_RETURN (false);
    }
  }

B
Behdad Esfahbod 已提交
413
  inline bool sanitize (hb_sanitize_context_t *c) {
B
Behdad Esfahbod 已提交
414
    TRACE_SANITIZE (this);
415
    if (!u.format.sanitize (c)) return TRACE_RETURN (false);
B
Behdad Esfahbod 已提交
416
    switch (u.format) {
417 418
    case 1: return TRACE_RETURN (u.format1.sanitize (c));
    default:return TRACE_RETURN (true);
B
Behdad Esfahbod 已提交
419 420 421
    }
  }

422
  protected:
423
  union {
B
Behdad Esfahbod 已提交
424
  USHORT		format;		/* Format identifier */
B
Behdad Esfahbod 已提交
425
  MultipleSubstFormat1	format1;
426 427 428
  } u;
};

B
Behdad Esfahbod 已提交
429

B
Behdad Esfahbod 已提交
430
typedef ArrayOf<GlyphID> AlternateSet;	/* Array of alternate GlyphIDs--in
B
Behdad Esfahbod 已提交
431 432
					 * arbitrary order */

B
Behdad Esfahbod 已提交
433 434
struct AlternateSubstFormat1
{
B
Behdad Esfahbod 已提交
435
  inline void closure (hb_closure_context_t *c) const
436
  {
B
Behdad Esfahbod 已提交
437
    TRACE_CLOSURE (this);
B
Behdad Esfahbod 已提交
438 439 440 441 442 443
    Coverage::Iter iter;
    for (iter.init (this+coverage); iter.more (); iter.next ()) {
      if (c->glyphs->has (iter.get_glyph ())) {
	const AlternateSet &alt_set = this+alternateSet[iter.get_coverage ()];
	unsigned int count = alt_set.len;
	for (unsigned int i = 0; i < count; i++)
B
Behdad Esfahbod 已提交
444
	  c->glyphs->add (alt_set[i]);
B
Behdad Esfahbod 已提交
445 446
      }
    }
447 448
  }

449 450
  inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
  {
B
Behdad Esfahbod 已提交
451
    TRACE_COLLECT_GLYPHS (this);
452 453 454 455 456 457 458 459 460 461
    Coverage::Iter iter;
    for (iter.init (this+coverage); iter.more (); iter.next ()) {
      c->input.add (iter.get_glyph ());
      const AlternateSet &alt_set = this+alternateSet[iter.get_coverage ()];
      unsigned int count = alt_set.len;
      for (unsigned int i = 0; i < count; i++)
	c->output.add (alt_set[i]);
    }
  }

462 463 464 465 466
  inline const Coverage &get_coverage (void) const
  {
    return this+coverage;
  }

467 468
  inline bool would_apply (hb_would_apply_context_t *c) const
  {
B
Behdad Esfahbod 已提交
469
    TRACE_WOULD_APPLY (this);
470
    return TRACE_RETURN (c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED);
471 472
  }

B
Behdad Esfahbod 已提交
473
  inline bool apply (hb_apply_context_t *c) const
B
Behdad Esfahbod 已提交
474
  {
B
Behdad Esfahbod 已提交
475
    TRACE_APPLY (this);
476
    hb_codepoint_t glyph_id = c->buffer->cur().codepoint;
477

478
    unsigned int index = (this+coverage).get_coverage (glyph_id);
479
    if (likely (index == NOT_COVERED)) return TRACE_RETURN (false);
480

B
Behdad Esfahbod 已提交
481
    const AlternateSet &alt_set = this+alternateSet[index];
482

483
    if (unlikely (!alt_set.len)) return TRACE_RETURN (false);
484

485
    hb_mask_t glyph_mask = c->buffer->cur().mask;
B
Behdad Esfahbod 已提交
486 487
    hb_mask_t lookup_mask = c->lookup_mask;

B
Behdad Esfahbod 已提交
488
    /* Note: This breaks badly if two features enabled this lookup together. */
B
Behdad Esfahbod 已提交
489
    unsigned int shift = _hb_ctz (lookup_mask);
B
Behdad Esfahbod 已提交
490
    unsigned int alt_index = ((lookup_mask & glyph_mask) >> shift);
491

492
    if (unlikely (alt_index > alt_set.len || alt_index == 0)) return TRACE_RETURN (false);
493

B
Behdad Esfahbod 已提交
494
    glyph_id = alt_set[alt_index - 1];
495

496
    c->replace_glyph (glyph_id);
497

498
    return TRACE_RETURN (true);
499
  }
B
Behdad Esfahbod 已提交
500

501
  inline bool serialize (hb_serialize_context_t *c,
502 503
			 Supplier<GlyphID> &glyphs,
			 Supplier<unsigned int> &alternate_len_list,
504
			 unsigned int num_glyphs,
505
			 Supplier<GlyphID> &alternate_glyphs_list)
506
  {
B
Behdad Esfahbod 已提交
507
    TRACE_SERIALIZE (this);
508 509
    if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false);
    if (unlikely (!alternateSet.serialize (c, num_glyphs))) return TRACE_RETURN (false);
510 511 512 513 514
    for (unsigned int i = 0; i < num_glyphs; i++)
      if (unlikely (!alternateSet[i].serialize (c, this).serialize (c,
								    alternate_glyphs_list,
								    alternate_len_list[i]))) return TRACE_RETURN (false);
    alternate_len_list.advance (num_glyphs);
515
    if (unlikely (!coverage.serialize (c, this).serialize (c, glyphs, num_glyphs))) return TRACE_RETURN (false);
516 517 518
    return TRACE_RETURN (true);
  }

B
Behdad Esfahbod 已提交
519
  inline bool sanitize (hb_sanitize_context_t *c) {
B
Behdad Esfahbod 已提交
520
    TRACE_SANITIZE (this);
521
    return TRACE_RETURN (coverage.sanitize (c, this) && alternateSet.sanitize (c, this));
B
Behdad Esfahbod 已提交
522 523
  }

524
  protected:
B
Behdad Esfahbod 已提交
525
  USHORT	format;			/* Format identifier--format = 1 */
B
Behdad Esfahbod 已提交
526 527
  OffsetTo<Coverage>
		coverage;		/* Offset to Coverage table--from
B
Behdad Esfahbod 已提交
528
					 * beginning of Substitution table */
B
Behdad Esfahbod 已提交
529 530 531
  OffsetArrayOf<AlternateSet>
		alternateSet;		/* Array of AlternateSet tables
					 * ordered by Coverage Index */
532
  public:
533
  DEFINE_SIZE_ARRAY (6, alternateSet);
B
Behdad Esfahbod 已提交
534
};
535

B
Behdad Esfahbod 已提交
536 537
struct AlternateSubst
{
538 539
  template <typename context_t>
  inline typename context_t::return_t process (context_t *c) const
540
  {
B
Behdad Esfahbod 已提交
541
    TRACE_PROCESS (this);
542
    switch (u.format) {
B
Behdad Esfahbod 已提交
543 544
    case 1: return TRACE_RETURN (c->process (u.format1));
    default:return TRACE_RETURN (c->default_return_value ());
545 546 547
    }
  }

548
  inline bool serialize (hb_serialize_context_t *c,
549 550
			 Supplier<GlyphID> &glyphs,
			 Supplier<unsigned int> &alternate_len_list,
551
			 unsigned int num_glyphs,
552
			 Supplier<GlyphID> &alternate_glyphs_list)
553
  {
B
Behdad Esfahbod 已提交
554
    TRACE_SERIALIZE (this);
555 556 557 558 559 560 561 562 563
    if (unlikely (!c->extend_min (u.format))) return TRACE_RETURN (false);
    unsigned int format = 1;
    u.format.set (format);
    switch (u.format) {
    case 1: return TRACE_RETURN (u.format1.serialize (c, glyphs, alternate_len_list, num_glyphs, alternate_glyphs_list));
    default:return TRACE_RETURN (false);
    }
  }

B
Behdad Esfahbod 已提交
564
  inline bool sanitize (hb_sanitize_context_t *c) {
B
Behdad Esfahbod 已提交
565
    TRACE_SANITIZE (this);
566
    if (!u.format.sanitize (c)) return TRACE_RETURN (false);
B
Behdad Esfahbod 已提交
567
    switch (u.format) {
568 569
    case 1: return TRACE_RETURN (u.format1.sanitize (c));
    default:return TRACE_RETURN (true);
B
Behdad Esfahbod 已提交
570 571 572
    }
  }

573
  protected:
574
  union {
B
Behdad Esfahbod 已提交
575
  USHORT		format;		/* Format identifier */
B
Behdad Esfahbod 已提交
576
  AlternateSubstFormat1	format1;
577 578 579
  } u;
};

580

B
Behdad Esfahbod 已提交
581 582
struct Ligature
{
B
Behdad Esfahbod 已提交
583
  inline void closure (hb_closure_context_t *c) const
584
  {
B
Behdad Esfahbod 已提交
585
    TRACE_CLOSURE (this);
B
Behdad Esfahbod 已提交
586 587 588
    unsigned int count = component.len;
    for (unsigned int i = 1; i < count; i++)
      if (!c->glyphs->has (component[i]))
B
Behdad Esfahbod 已提交
589 590
        return;
    c->glyphs->add (ligGlyph);
591 592
  }

593 594
  inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
  {
B
Behdad Esfahbod 已提交
595
    TRACE_COLLECT_GLYPHS (this);
596 597 598 599 600 601
    unsigned int count = component.len;
    for (unsigned int i = 1; i < count; i++)
      c->input.add (component[i]);
    c->output.add (ligGlyph);
  }

602
  inline bool would_apply (hb_would_apply_context_t *c) const
B
Behdad Esfahbod 已提交
603
  {
B
Behdad Esfahbod 已提交
604
    TRACE_WOULD_APPLY (this);
605
    if (c->len != component.len)
606
      return TRACE_RETURN (false);
607 608 609

    for (unsigned int i = 1; i < c->len; i++)
      if (likely (c->glyphs[i] != component[i]))
610
	return TRACE_RETURN (false);
611

612
    return TRACE_RETURN (true);
B
Behdad Esfahbod 已提交
613 614
  }

615
  inline bool apply (hb_apply_context_t *c) const
B
Behdad Esfahbod 已提交
616
  {
B
Behdad Esfahbod 已提交
617
    TRACE_APPLY (this);
B
Behdad Esfahbod 已提交
618
    unsigned int count = component.len;
619
    if (unlikely (count < 1)) return TRACE_RETURN (false);
B
Behdad Esfahbod 已提交
620

B
Behdad Esfahbod 已提交
621 622 623
    unsigned int end_offset = 0;
    bool is_mark_ligature = false;
    unsigned int total_component_count = 0;
624 625 626 627 628 629 630 631 632

    if (likely (!match_input (c, count,
			      &component[1],
			      match_glyph,
			      NULL,
			      &end_offset,
			      &is_mark_ligature,
			      &total_component_count)))
      return TRACE_RETURN (false);
633

634
    /* Deal, we are forming the ligature. */
635
    c->buffer->merge_clusters (c->buffer->idx, c->buffer->idx + end_offset);
636

637 638 639 640 641 642 643 644
    ligate_input (c,
		  count,
		  &component[1],
		  ligGlyph,
		  match_glyph,
		  NULL,
		  is_mark_ligature,
		  total_component_count);
645

646
    return TRACE_RETURN (true);
647
  }
648

649 650 651 652 653
  inline bool serialize (hb_serialize_context_t *c,
			 GlyphID ligature,
			 Supplier<GlyphID> &components, /* Starting from second */
			 unsigned int num_components /* Including first component */)
  {
B
Behdad Esfahbod 已提交
654
    TRACE_SERIALIZE (this);
655
    if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false);
656
    ligGlyph = ligature;
657 658 659 660
    if (unlikely (!component.serialize (c, components, num_components))) return TRACE_RETURN (false);
    return TRACE_RETURN (true);
  }

B
Behdad Esfahbod 已提交
661
  public:
B
Behdad Esfahbod 已提交
662
  inline bool sanitize (hb_sanitize_context_t *c) {
B
Behdad Esfahbod 已提交
663
    TRACE_SANITIZE (this);
664
    return TRACE_RETURN (ligGlyph.sanitize (c) && component.sanitize (c));
B
Behdad Esfahbod 已提交
665 666
  }

667
  protected:
668
  GlyphID	ligGlyph;		/* GlyphID of ligature to substitute */
B
Behdad Esfahbod 已提交
669 670
  HeadlessArrayOf<GlyphID>
		component;		/* Array of component GlyphIDs--start
671 672
					 * with the second  component--ordered
					 * in writing direction */
673
  public:
674
  DEFINE_SIZE_ARRAY (4, component);
675
};
B
Behdad Esfahbod 已提交
676

B
Behdad Esfahbod 已提交
677 678
struct LigatureSet
{
B
Behdad Esfahbod 已提交
679
  inline void closure (hb_closure_context_t *c) const
680
  {
B
Behdad Esfahbod 已提交
681
    TRACE_CLOSURE (this);
B
Behdad Esfahbod 已提交
682 683
    unsigned int num_ligs = ligature.len;
    for (unsigned int i = 0; i < num_ligs; i++)
B
Behdad Esfahbod 已提交
684
      (this+ligature[i]).closure (c);
685 686
  }

687 688
  inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
  {
B
Behdad Esfahbod 已提交
689
    TRACE_COLLECT_GLYPHS (this);
690 691 692 693 694
    unsigned int num_ligs = ligature.len;
    for (unsigned int i = 0; i < num_ligs; i++)
      (this+ligature[i]).collect_glyphs (c);
  }

695
  inline bool would_apply (hb_would_apply_context_t *c) const
B
Behdad Esfahbod 已提交
696
  {
B
Behdad Esfahbod 已提交
697
    TRACE_WOULD_APPLY (this);
B
Behdad Esfahbod 已提交
698 699 700 701
    unsigned int num_ligs = ligature.len;
    for (unsigned int i = 0; i < num_ligs; i++)
    {
      const Ligature &lig = this+ligature[i];
702
      if (lig.would_apply (c))
703
        return TRACE_RETURN (true);
B
Behdad Esfahbod 已提交
704
    }
705
    return TRACE_RETURN (false);
B
Behdad Esfahbod 已提交
706 707
  }

708
  inline bool apply (hb_apply_context_t *c) const
B
Behdad Esfahbod 已提交
709
  {
B
Behdad Esfahbod 已提交
710
    TRACE_APPLY (this);
B
Behdad Esfahbod 已提交
711
    unsigned int num_ligs = ligature.len;
B
Behdad Esfahbod 已提交
712 713
    for (unsigned int i = 0; i < num_ligs; i++)
    {
B
Behdad Esfahbod 已提交
714
      const Ligature &lig = this+ligature[i];
715
      if (lig.apply (c)) return TRACE_RETURN (true);
716 717
    }

718
    return TRACE_RETURN (false);
719
  }
B
Behdad Esfahbod 已提交
720

721 722 723 724 725 726
  inline bool serialize (hb_serialize_context_t *c,
			 Supplier<GlyphID> &ligatures,
			 Supplier<unsigned int> &component_count_list,
			 unsigned int num_ligatures,
			 Supplier<GlyphID> &component_list /* Starting from second for each ligature */)
  {
B
Behdad Esfahbod 已提交
727
    TRACE_SERIALIZE (this);
728 729 730 731 732 733 734
    if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false);
    if (unlikely (!ligature.serialize (c, num_ligatures))) return TRACE_RETURN (false);
    for (unsigned int i = 0; i < num_ligatures; i++)
      if (unlikely (!ligature[i].serialize (c, this).serialize (c,
								ligatures[i],
								component_list,
								component_count_list[i]))) return TRACE_RETURN (false);
735
    ligatures.advance (num_ligatures);
736 737 738 739
    component_count_list.advance (num_ligatures);
    return TRACE_RETURN (true);
  }

B
Behdad Esfahbod 已提交
740
  inline bool sanitize (hb_sanitize_context_t *c) {
B
Behdad Esfahbod 已提交
741
    TRACE_SANITIZE (this);
742
    return TRACE_RETURN (ligature.sanitize (c, this));
B
Behdad Esfahbod 已提交
743 744
  }

745
  protected:
B
Behdad Esfahbod 已提交
746 747 748
  OffsetArrayOf<Ligature>
		ligature;		/* Array LigatureSet tables
					 * ordered by preference */
749
  public:
750
  DEFINE_SIZE_ARRAY (2, ligature);
B
Behdad Esfahbod 已提交
751 752
};

B
Behdad Esfahbod 已提交
753 754
struct LigatureSubstFormat1
{
B
Behdad Esfahbod 已提交
755
  inline void closure (hb_closure_context_t *c) const
756
  {
B
Behdad Esfahbod 已提交
757
    TRACE_CLOSURE (this);
B
Behdad Esfahbod 已提交
758 759 760
    Coverage::Iter iter;
    for (iter.init (this+coverage); iter.more (); iter.next ()) {
      if (c->glyphs->has (iter.get_glyph ()))
B
Behdad Esfahbod 已提交
761
	(this+ligatureSet[iter.get_coverage ()]).closure (c);
B
Behdad Esfahbod 已提交
762
    }
763 764
  }

765 766
  inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
  {
B
Behdad Esfahbod 已提交
767
    TRACE_COLLECT_GLYPHS (this);
768 769 770 771 772 773 774
    Coverage::Iter iter;
    for (iter.init (this+coverage); iter.more (); iter.next ()) {
      c->input.add (iter.get_glyph ());
      (this+ligatureSet[iter.get_coverage ()]).collect_glyphs (c);
    }
  }

775 776 777 778 779
  inline const Coverage &get_coverage (void) const
  {
    return this+coverage;
  }

780
  inline bool would_apply (hb_would_apply_context_t *c) const
B
Behdad Esfahbod 已提交
781
  {
B
Behdad Esfahbod 已提交
782
    TRACE_WOULD_APPLY (this);
783
    unsigned int index = (this+coverage).get_coverage (c->glyphs[0]);
784 785 786 787
    if (likely (index == NOT_COVERED)) return TRACE_RETURN (false);

    const LigatureSet &lig_set = this+ligatureSet[index];
    return TRACE_RETURN (lig_set.would_apply (c));
B
Behdad Esfahbod 已提交
788 789
  }

B
Behdad Esfahbod 已提交
790
  inline bool apply (hb_apply_context_t *c) const
B
Behdad Esfahbod 已提交
791
  {
B
Behdad Esfahbod 已提交
792
    TRACE_APPLY (this);
793
    hb_codepoint_t glyph_id = c->buffer->cur().codepoint;
794

795
    unsigned int index = (this+coverage).get_coverage (glyph_id);
796
    if (likely (index == NOT_COVERED)) return TRACE_RETURN (false);
797

B
Behdad Esfahbod 已提交
798
    const LigatureSet &lig_set = this+ligatureSet[index];
799
    return TRACE_RETURN (lig_set.apply (c));
800
  }
B
Behdad Esfahbod 已提交
801

802 803 804 805 806 807 808 809
  inline bool serialize (hb_serialize_context_t *c,
			 Supplier<GlyphID> &first_glyphs,
			 Supplier<unsigned int> &ligature_per_first_glyph_count_list,
			 unsigned int num_first_glyphs,
			 Supplier<GlyphID> &ligatures_list,
			 Supplier<unsigned int> &component_count_list,
			 Supplier<GlyphID> &component_list /* Starting from second for each ligature */)
  {
B
Behdad Esfahbod 已提交
810
    TRACE_SERIALIZE (this);
811 812 813 814 815 816 817 818 819
    if (unlikely (!c->extend_min (*this))) return TRACE_RETURN (false);
    if (unlikely (!ligatureSet.serialize (c, num_first_glyphs))) return TRACE_RETURN (false);
    for (unsigned int i = 0; i < num_first_glyphs; i++)
      if (unlikely (!ligatureSet[i].serialize (c, this).serialize (c,
								   ligatures_list,
								   component_count_list,
								   ligature_per_first_glyph_count_list[i],
								   component_list))) return TRACE_RETURN (false);
    ligature_per_first_glyph_count_list.advance (num_first_glyphs);
820
    if (unlikely (!coverage.serialize (c, this).serialize (c, first_glyphs, num_first_glyphs))) return TRACE_RETURN (false);
821 822 823
    return TRACE_RETURN (true);
  }

B
Behdad Esfahbod 已提交
824
  inline bool sanitize (hb_sanitize_context_t *c) {
B
Behdad Esfahbod 已提交
825
    TRACE_SANITIZE (this);
826
    return TRACE_RETURN (coverage.sanitize (c, this) && ligatureSet.sanitize (c, this));
B
Behdad Esfahbod 已提交
827 828
  }

829
  protected:
B
Behdad Esfahbod 已提交
830
  USHORT	format;			/* Format identifier--format = 1 */
B
Behdad Esfahbod 已提交
831 832
  OffsetTo<Coverage>
		coverage;		/* Offset to Coverage table--from
833
					 * beginning of Substitution table */
B
Behdad Esfahbod 已提交
834
  OffsetArrayOf<LigatureSet>
B
Behdad Esfahbod 已提交
835 836
		ligatureSet;		/* Array LigatureSet tables
					 * ordered by Coverage Index */
837
  public:
838
  DEFINE_SIZE_ARRAY (6, ligatureSet);
B
Behdad Esfahbod 已提交
839
};
840

B
Behdad Esfahbod 已提交
841 842
struct LigatureSubst
{
843 844
  template <typename context_t>
  inline typename context_t::return_t process (context_t *c) const
845
  {
B
Behdad Esfahbod 已提交
846
    TRACE_PROCESS (this);
847
    switch (u.format) {
B
Behdad Esfahbod 已提交
848 849
    case 1: return TRACE_RETURN (c->process (u.format1));
    default:return TRACE_RETURN (c->default_return_value ());
B
Behdad Esfahbod 已提交
850 851 852
    }
  }

853 854 855 856 857 858 859 860
  inline bool serialize (hb_serialize_context_t *c,
			 Supplier<GlyphID> &first_glyphs,
			 Supplier<unsigned int> &ligature_per_first_glyph_count_list,
			 unsigned int num_first_glyphs,
			 Supplier<GlyphID> &ligatures_list,
			 Supplier<unsigned int> &component_count_list,
			 Supplier<GlyphID> &component_list /* Starting from second for each ligature */)
  {
B
Behdad Esfahbod 已提交
861
    TRACE_SERIALIZE (this);
862 863 864 865 866 867 868 869 870 871
    if (unlikely (!c->extend_min (u.format))) return TRACE_RETURN (false);
    unsigned int format = 1;
    u.format.set (format);
    switch (u.format) {
    case 1: return TRACE_RETURN (u.format1.serialize (c, first_glyphs, ligature_per_first_glyph_count_list, num_first_glyphs,
						      ligatures_list, component_count_list, component_list));
    default:return TRACE_RETURN (false);
    }
  }

B
Behdad Esfahbod 已提交
872
  inline bool sanitize (hb_sanitize_context_t *c) {
B
Behdad Esfahbod 已提交
873
    TRACE_SANITIZE (this);
874
    if (!u.format.sanitize (c)) return TRACE_RETURN (false);
B
Behdad Esfahbod 已提交
875
    switch (u.format) {
876 877
    case 1: return TRACE_RETURN (u.format1.sanitize (c));
    default:return TRACE_RETURN (true);
B
Behdad Esfahbod 已提交
878 879 880
    }
  }

881
  protected:
882
  union {
B
Behdad Esfahbod 已提交
883
  USHORT		format;		/* Format identifier */
B
Behdad Esfahbod 已提交
884
  LigatureSubstFormat1	format1;
885 886 887
  } u;
};

B
Behdad Esfahbod 已提交
888

B
Minor  
Behdad Esfahbod 已提交
889
struct ContextSubst : Context {};
B
Behdad Esfahbod 已提交
890

B
Minor  
Behdad Esfahbod 已提交
891
struct ChainContextSubst : ChainContext {};
892

B
Behdad Esfahbod 已提交
893
struct ExtensionSubst : Extension<ExtensionSubst>
B
Behdad Esfahbod 已提交
894
{
895
  typedef struct SubstLookupSubTable LookupSubTable;
B
Behdad Esfahbod 已提交
896

B
Behdad Esfahbod 已提交
897
  inline bool is_reverse (void) const;
898 899 900
};


B
Behdad Esfahbod 已提交
901 902
struct ReverseChainSingleSubstFormat1
{
B
Behdad Esfahbod 已提交
903
  inline void closure (hb_closure_context_t *c) const
904
  {
B
Behdad Esfahbod 已提交
905
    TRACE_CLOSURE (this);
B
Behdad Esfahbod 已提交
906 907 908 909 910 911 912
    const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack);

    unsigned int count;

    count = backtrack.len;
    for (unsigned int i = 0; i < count; i++)
      if (!(this+backtrack[i]).intersects (c->glyphs))
B
Behdad Esfahbod 已提交
913
        return;
B
Behdad Esfahbod 已提交
914 915 916 917

    count = lookahead.len;
    for (unsigned int i = 0; i < count; i++)
      if (!(this+lookahead[i]).intersects (c->glyphs))
B
Behdad Esfahbod 已提交
918
        return;
B
Behdad Esfahbod 已提交
919 920 921 922 923

    const ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead);
    Coverage::Iter iter;
    for (iter.init (this+coverage); iter.more (); iter.next ()) {
      if (c->glyphs->has (iter.get_glyph ()))
B
Behdad Esfahbod 已提交
924
	c->glyphs->add (substitute[iter.get_coverage ()]);
B
Behdad Esfahbod 已提交
925
    }
926 927
  }

928 929
  inline void collect_glyphs (hb_collect_glyphs_context_t *c) const
  {
B
Behdad Esfahbod 已提交
930 931
    TRACE_COLLECT_GLYPHS (this);

932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951
    const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack);

    unsigned int count;

    (this+coverage).add_coverage (&c->input);

    count = backtrack.len;
    for (unsigned int i = 0; i < count; i++)
      (this+backtrack[i]).add_coverage (&c->before);

    count = lookahead.len;
    for (unsigned int i = 0; i < count; i++)
      (this+lookahead[i]).add_coverage (&c->after);

    const ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead);
    count = substitute.len;
    for (unsigned int i = 0; i < count; i++)
      c->output.add (substitute[i]);
  }

952 953 954 955 956
  inline const Coverage &get_coverage (void) const
  {
    return this+coverage;
  }

957 958
  inline bool would_apply (hb_would_apply_context_t *c) const
  {
B
Behdad Esfahbod 已提交
959
    TRACE_WOULD_APPLY (this);
960
    return TRACE_RETURN (c->len == 1 && (this+coverage).get_coverage (c->glyphs[0]) != NOT_COVERED);
961 962
  }

B
Behdad Esfahbod 已提交
963
  inline bool apply (hb_apply_context_t *c) const
B
Behdad Esfahbod 已提交
964
  {
B
Behdad Esfahbod 已提交
965
    TRACE_APPLY (this);
966 967
    if (unlikely (c->nesting_level_left != MAX_NESTING_LEVEL))
      return TRACE_RETURN (false); /* No chaining to this type */
968

969
    unsigned int index = (this+coverage).get_coverage (c->buffer->cur().codepoint);
970
    if (likely (index == NOT_COVERED)) return TRACE_RETURN (false);
971

972 973
    const OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
    const ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead);
974

B
Behdad Esfahbod 已提交
975
    if (match_backtrack (c,
B
Behdad Esfahbod 已提交
976
			 backtrack.len, (USHORT *) backtrack.array,
B
Behdad Esfahbod 已提交
977
			 match_coverage, this) &&
B
Behdad Esfahbod 已提交
978
        match_lookahead (c,
B
Behdad Esfahbod 已提交
979
			 lookahead.len, (USHORT *) lookahead.array,
B
Behdad Esfahbod 已提交
980
			 match_coverage, this,
981 982
			 1))
    {
B
Behdad Esfahbod 已提交
983
      c->replace_glyph_inplace (substitute[index]);
984
      c->buffer->idx--; /* Reverse! */
985
      return TRACE_RETURN (true);
986 987
    }

988
    return TRACE_RETURN (false);
989
  }
B
Behdad Esfahbod 已提交
990

B
Behdad Esfahbod 已提交
991
  inline bool sanitize (hb_sanitize_context_t *c) {
B
Behdad Esfahbod 已提交
992
    TRACE_SANITIZE (this);
993 994
    if (!(coverage.sanitize (c, this) && backtrack.sanitize (c, this)))
      return TRACE_RETURN (false);
995
    OffsetArrayOf<Coverage> &lookahead = StructAfter<OffsetArrayOf<Coverage> > (backtrack);
B
Behdad Esfahbod 已提交
996
    if (!lookahead.sanitize (c, this))
997
      return TRACE_RETURN (false);
998
    ArrayOf<GlyphID> &substitute = StructAfter<ArrayOf<GlyphID> > (lookahead);
999
    return TRACE_RETURN (substitute.sanitize (c));
B
Behdad Esfahbod 已提交
1000 1001
  }

1002
  protected:
B
Behdad Esfahbod 已提交
1003
  USHORT	format;			/* Format identifier--format = 1 */
1004 1005 1006 1007 1008
  OffsetTo<Coverage>
		coverage;		/* Offset to Coverage table--from
					 * beginning of table */
  OffsetArrayOf<Coverage>
		backtrack;		/* Array of coverage tables
B
Behdad Esfahbod 已提交
1009 1010
					 * in backtracking sequence, in  glyph
					 * sequence order */
1011 1012 1013
  OffsetArrayOf<Coverage>
		lookaheadX;		/* Array of coverage tables
					 * in lookahead sequence, in glyph
B
Behdad Esfahbod 已提交
1014
					 * sequence order */
1015 1016 1017
  ArrayOf<GlyphID>
		substituteX;		/* Array of substitute
					 * GlyphIDs--ordered by Coverage Index */
1018
  public:
B
Behdad Esfahbod 已提交
1019
  DEFINE_SIZE_MIN (10);
B
Behdad Esfahbod 已提交
1020 1021
};

B
Behdad Esfahbod 已提交
1022 1023
struct ReverseChainSingleSubst
{
1024 1025
  template <typename context_t>
  inline typename context_t::return_t process (context_t *c) const
1026
  {
B
Behdad Esfahbod 已提交
1027
    TRACE_PROCESS (this);
1028
    switch (u.format) {
B
Behdad Esfahbod 已提交
1029 1030
    case 1: return TRACE_RETURN (c->process (u.format1));
    default:return TRACE_RETURN (c->default_return_value ());
1031 1032 1033
    }
  }

B
Behdad Esfahbod 已提交
1034
  inline bool sanitize (hb_sanitize_context_t *c) {
B
Behdad Esfahbod 已提交
1035
    TRACE_SANITIZE (this);
1036
    if (!u.format.sanitize (c)) return TRACE_RETURN (false);
B
Behdad Esfahbod 已提交
1037
    switch (u.format) {
1038 1039
    case 1: return TRACE_RETURN (u.format1.sanitize (c));
    default:return TRACE_RETURN (true);
B
Behdad Esfahbod 已提交
1040 1041 1042
    }
  }

1043
  protected:
1044 1045
  union {
  USHORT				format;		/* Format identifier */
B
Behdad Esfahbod 已提交
1046
  ReverseChainSingleSubstFormat1	format1;
1047 1048 1049 1050 1051
  } u;
};



B
Behdad Esfahbod 已提交
1052 1053 1054 1055
/*
 * SubstLookup
 */

B
Behdad Esfahbod 已提交
1056 1057
struct SubstLookupSubTable
{
B
Behdad Esfahbod 已提交
1058 1059
  friend struct SubstLookup;

B
Behdad Esfahbod 已提交
1060
  enum Type {
1061 1062 1063 1064 1065 1066 1067
    Single		= 1,
    Multiple		= 2,
    Alternate		= 3,
    Ligature		= 4,
    Context		= 5,
    ChainContext	= 6,
    Extension		= 7,
1068
    ReverseChainSingle	= 8
1069 1070
  };

1071 1072
  template <typename context_t>
  inline typename context_t::return_t process (context_t *c, unsigned int lookup_type) const
1073
  {
B
Behdad Esfahbod 已提交
1074
    TRACE_PROCESS (this);
1075
    switch (lookup_type) {
B
Behdad Esfahbod 已提交
1076 1077 1078 1079 1080 1081 1082 1083 1084
    case Single:		return TRACE_RETURN (u.single.process (c));
    case Multiple:		return TRACE_RETURN (u.multiple.process (c));
    case Alternate:		return TRACE_RETURN (u.alternate.process (c));
    case Ligature:		return TRACE_RETURN (u.ligature.process (c));
    case Context:		return TRACE_RETURN (u.context.process (c));
    case ChainContext:		return TRACE_RETURN (u.chainContext.process (c));
    case Extension:		return TRACE_RETURN (u.extension.process (c));
    case ReverseChainSingle:	return TRACE_RETURN (u.reverseChainContextSingle.process (c));
    default:			return TRACE_RETURN (c->default_return_value ());
1085 1086 1087
    }
  }

B
Behdad Esfahbod 已提交
1088
  inline bool sanitize (hb_sanitize_context_t *c, unsigned int lookup_type) {
B
Behdad Esfahbod 已提交
1089
    TRACE_SANITIZE (this);
1090
    if (!u.header.sub_format.sanitize (c))
1091
      return TRACE_RETURN (false);
1092
    switch (lookup_type) {
1093 1094 1095 1096
    case Single:		return TRACE_RETURN (u.single.sanitize (c));
    case Multiple:		return TRACE_RETURN (u.multiple.sanitize (c));
    case Alternate:		return TRACE_RETURN (u.alternate.sanitize (c));
    case Ligature:		return TRACE_RETURN (u.ligature.sanitize (c));
1097
    case Context:		return TRACE_RETURN (u.context.sanitize (c));
1098 1099 1100 1101
    case ChainContext:		return TRACE_RETURN (u.chainContext.sanitize (c));
    case Extension:		return TRACE_RETURN (u.extension.sanitize (c));
    case ReverseChainSingle:	return TRACE_RETURN (u.reverseChainContextSingle.sanitize (c));
    default:			return TRACE_RETURN (true);
B
Behdad Esfahbod 已提交
1102 1103 1104
    }
  }

1105
  protected:
B
Behdad Esfahbod 已提交
1106
  union {
1107 1108 1109
  struct {
    USHORT			sub_format;
  } header;
B
Behdad Esfahbod 已提交
1110 1111 1112 1113
  SingleSubst			single;
  MultipleSubst			multiple;
  AlternateSubst		alternate;
  LigatureSubst			ligature;
1114
  ContextSubst			context;
B
Behdad Esfahbod 已提交
1115 1116 1117
  ChainContextSubst		chainContext;
  ExtensionSubst		extension;
  ReverseChainSingleSubst	reverseChainContextSingle;
B
Behdad Esfahbod 已提交
1118
  } u;
B
Behdad Esfahbod 已提交
1119
  public:
1120
  DEFINE_SIZE_UNION (2, header.sub_format);
B
Behdad Esfahbod 已提交
1121 1122
};

1123

B
Behdad Esfahbod 已提交
1124 1125
struct SubstLookup : Lookup
{
1126 1127
  inline const SubstLookupSubTable& get_subtable (unsigned int i) const
  { return this+CastR<OffsetArrayOf<SubstLookupSubTable> > (subTable)[i]; }
B
Behdad Esfahbod 已提交
1128

B
Behdad Esfahbod 已提交
1129
  inline static bool lookup_type_is_reverse (unsigned int lookup_type)
1130
  { return lookup_type == SubstLookupSubTable::ReverseChainSingle; }
B
Behdad Esfahbod 已提交
1131 1132

  inline bool is_reverse (void) const
B
Behdad Esfahbod 已提交
1133
  {
B
Behdad Esfahbod 已提交
1134
    unsigned int type = get_type ();
1135
    if (unlikely (type == SubstLookupSubTable::Extension))
1136
      return CastR<ExtensionSubst> (get_subtable(0)).is_reverse ();
B
Behdad Esfahbod 已提交
1137
    return lookup_type_is_reverse (type);
B
Behdad Esfahbod 已提交
1138 1139
  }

1140 1141
  template <typename context_t>
  inline typename context_t::return_t process (context_t *c) const
1142
  {
B
Behdad Esfahbod 已提交
1143
    TRACE_PROCESS (this);
1144
    unsigned int lookup_type = get_type ();
B
Behdad Esfahbod 已提交
1145
    unsigned int count = get_subtable_count ();
1146 1147 1148
    for (unsigned int i = 0; i < count; i++) {
      typename context_t::return_t r = get_subtable (i).process (c, lookup_type);
      if (c->stop_sublookup_iteration (r))
B
Behdad Esfahbod 已提交
1149
        return TRACE_RETURN (r);
1150
    }
B
Behdad Esfahbod 已提交
1151
    return TRACE_RETURN (c->default_return_value ());
1152
  }
1153 1154
  template <typename context_t>
  static inline typename context_t::return_t process_recurse_func (context_t *c, unsigned int lookup_index);
B
Behdad Esfahbod 已提交
1155

1156 1157
  inline hb_closure_context_t::return_t closure (hb_closure_context_t *c) const
  {
B
Behdad Esfahbod 已提交
1158
    TRACE_CLOSURE (this);
1159
    c->set_recurse_func (process_recurse_func<hb_closure_context_t>);
B
Behdad Esfahbod 已提交
1160 1161 1162 1163 1164 1165 1166 1167
    return TRACE_RETURN (process (c));
  }

  inline hb_collect_glyphs_context_t::return_t collect_glyphs_lookup (hb_collect_glyphs_context_t *c) const
  {
    TRACE_COLLECT_GLYPHS (this);
    c->set_recurse_func (process_recurse_func<hb_collect_glyphs_context_t>);
    return TRACE_RETURN (process (c));
1168 1169
  }

B
Behdad Esfahbod 已提交
1170 1171 1172
  template <typename set_t>
  inline void add_coverage (set_t *glyphs) const
  {
1173
    hb_get_coverage_context_t c;
B
Behdad Esfahbod 已提交
1174 1175 1176
    const Coverage *last = NULL;
    unsigned int count = get_subtable_count ();
    for (unsigned int i = 0; i < count; i++) {
1177 1178 1179 1180
      const Coverage *coverage = &get_subtable (i).process (&c, get_type ());
      if (coverage != last) {
        coverage->add_coverage (glyphs);
        last = coverage;
B
Behdad Esfahbod 已提交
1181 1182 1183 1184
      }
    }
  }

B
Behdad Esfahbod 已提交
1185
  inline bool would_apply (hb_would_apply_context_t *c, const hb_set_digest_t *digest) const
B
Behdad Esfahbod 已提交
1186
  {
B
Behdad Esfahbod 已提交
1187
    TRACE_WOULD_APPLY (this);
1188 1189 1190
    if (unlikely (!c->len))  return TRACE_RETURN (false);
    if (!digest->may_have (c->glyphs[0]))  return TRACE_RETURN (false);
      return TRACE_RETURN (process (c));
B
Behdad Esfahbod 已提交
1191 1192
  }

1193
  inline bool apply_once (hb_apply_context_t *c) const
B
Behdad Esfahbod 已提交
1194
  {
B
Behdad Esfahbod 已提交
1195
    TRACE_APPLY (this);
1196
    if (!c->check_glyph_property (&c->buffer->cur(), c->lookup_props, &c->property))
B
Behdad Esfahbod 已提交
1197 1198
      return TRACE_RETURN (false);
    return TRACE_RETURN (process (c));
B
Behdad Esfahbod 已提交
1199
  }
1200

1201
  static bool apply_recurse_func (hb_apply_context_t *c, unsigned int lookup_index);
B
Behdad Esfahbod 已提交
1202
  inline bool apply_string (hb_apply_context_t *c, const hb_set_digest_t *digest) const
B
Behdad Esfahbod 已提交
1203
  {
1204 1205
    bool ret = false;

B
Minor  
Behdad Esfahbod 已提交
1206
    if (unlikely (!c->buffer->len || !c->lookup_mask))
B
Behdad Esfahbod 已提交
1207 1208
      return false;

1209
    c->set_recurse_func (apply_recurse_func);
B
Behdad Esfahbod 已提交
1210
    c->set_lookup (*this);
1211

1212
    if (likely (!is_reverse ()))
B
Behdad Esfahbod 已提交
1213
    {
1214
	/* in/out forward substitution */
B
Behdad Esfahbod 已提交
1215 1216
	c->buffer->clear_output ();
	c->buffer->idx = 0;
1217

1218 1219 1220
	while (c->buffer->idx < c->buffer->len)
	{
	  if ((c->buffer->cur().mask & c->lookup_mask) &&
B
Behdad Esfahbod 已提交
1221
	      digest->may_have (c->buffer->cur().codepoint) &&
1222 1223 1224 1225 1226
	      apply_once (c))
	    ret = true;
	  else
	    c->buffer->next_glyph ();
	}
1227
	if (ret)
B
Behdad Esfahbod 已提交
1228
	  c->buffer->swap_buffers ();
B
Behdad Esfahbod 已提交
1229 1230 1231
    }
    else
    {
1232
	/* in-place backward substitution */
B
Behdad Esfahbod 已提交
1233
	c->buffer->remove_output ();
B
Behdad Esfahbod 已提交
1234
	c->buffer->idx = c->buffer->len - 1;
B
Behdad Esfahbod 已提交
1235 1236
	do
	{
1237
	  if ((c->buffer->cur().mask & c->lookup_mask) &&
B
Behdad Esfahbod 已提交
1238
	      digest->may_have (c->buffer->cur().codepoint) &&
1239
	      apply_once (c))
1240 1241
	    ret = true;
	  else
B
Behdad Esfahbod 已提交
1242
	    c->buffer->idx--;
1243

B
Behdad Esfahbod 已提交
1244
	}
B
Behdad Esfahbod 已提交
1245
	while ((int) c->buffer->idx >= 0);
1246 1247 1248 1249
    }

    return ret;
  }
B
Behdad Esfahbod 已提交
1250

1251 1252 1253 1254 1255 1256 1257 1258 1259 1260
  inline SubstLookupSubTable& serialize_subtable (hb_serialize_context_t *c,
						  unsigned int i)
  { return CastR<OffsetArrayOf<SubstLookupSubTable> > (subTable)[i].serialize (c, this); }

  inline bool serialize_single (hb_serialize_context_t *c,
				uint32_t lookup_props,
			        Supplier<GlyphID> &glyphs,
			        Supplier<GlyphID> &substitutes,
			        unsigned int num_glyphs)
  {
B
Behdad Esfahbod 已提交
1261
    TRACE_SERIALIZE (this);
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272
    if (unlikely (!Lookup::serialize (c, SubstLookupSubTable::Single, lookup_props, 1))) return TRACE_RETURN (false);
    return TRACE_RETURN (serialize_subtable (c, 0).u.single.serialize (c, glyphs, substitutes, num_glyphs));
  }

  inline bool serialize_multiple (hb_serialize_context_t *c,
				  uint32_t lookup_props,
				  Supplier<GlyphID> &glyphs,
				  Supplier<unsigned int> &substitute_len_list,
				  unsigned int num_glyphs,
				  Supplier<GlyphID> &substitute_glyphs_list)
  {
B
Behdad Esfahbod 已提交
1273
    TRACE_SERIALIZE (this);
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285
    if (unlikely (!Lookup::serialize (c, SubstLookupSubTable::Multiple, lookup_props, 1))) return TRACE_RETURN (false);
    return TRACE_RETURN (serialize_subtable (c, 0).u.multiple.serialize (c, glyphs, substitute_len_list, num_glyphs,
									 substitute_glyphs_list));
  }

  inline bool serialize_alternate (hb_serialize_context_t *c,
				   uint32_t lookup_props,
				   Supplier<GlyphID> &glyphs,
				   Supplier<unsigned int> &alternate_len_list,
				   unsigned int num_glyphs,
				   Supplier<GlyphID> &alternate_glyphs_list)
  {
B
Behdad Esfahbod 已提交
1286
    TRACE_SERIALIZE (this);
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300
    if (unlikely (!Lookup::serialize (c, SubstLookupSubTable::Alternate, lookup_props, 1))) return TRACE_RETURN (false);
    return TRACE_RETURN (serialize_subtable (c, 0).u.alternate.serialize (c, glyphs, alternate_len_list, num_glyphs,
									  alternate_glyphs_list));
  }

  inline bool serialize_ligature (hb_serialize_context_t *c,
				  uint32_t lookup_props,
				  Supplier<GlyphID> &first_glyphs,
				  Supplier<unsigned int> &ligature_per_first_glyph_count_list,
				  unsigned int num_first_glyphs,
				  Supplier<GlyphID> &ligatures_list,
				  Supplier<unsigned int> &component_count_list,
				  Supplier<GlyphID> &component_list /* Starting from second for each ligature */)
  {
B
Behdad Esfahbod 已提交
1301
    TRACE_SERIALIZE (this);
1302 1303 1304 1305 1306 1307 1308
    if (unlikely (!Lookup::serialize (c, SubstLookupSubTable::Ligature, lookup_props, 1))) return TRACE_RETURN (false);
    return TRACE_RETURN (serialize_subtable (c, 0).u.ligature.serialize (c, first_glyphs, ligature_per_first_glyph_count_list, num_first_glyphs,
									 ligatures_list, component_count_list, component_list));
  }

  inline bool sanitize (hb_sanitize_context_t *c)
  {
B
Behdad Esfahbod 已提交
1309
    TRACE_SANITIZE (this);
1310
    if (unlikely (!Lookup::sanitize (c))) return TRACE_RETURN (false);
1311
    OffsetArrayOf<SubstLookupSubTable> &list = CastR<OffsetArrayOf<SubstLookupSubTable> > (subTable);
B
Behdad Esfahbod 已提交
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
    if (unlikely (!list.sanitize (c, this, get_type ()))) return TRACE_RETURN (false);

    if (unlikely (get_type () == SubstLookupSubTable::Extension))
    {
      /* The spec says all subtables of an Extension lookup should
       * have the same type.  This is specially important if one has
       * a reverse type!
       *
       * We just check that they are all either forward, or reverse. */
      unsigned int type = get_subtable (0).u.extension.get_type ();
      unsigned int count = get_subtable_count ();
      for (unsigned int i = 1; i < count; i++)
        if (get_subtable (i).u.extension.get_type () != type)
	  return TRACE_RETURN (false);
    }
    return TRACE_RETURN (true);
B
Behdad Esfahbod 已提交
1328
  }
B
Behdad Esfahbod 已提交
1329 1330
};

B
Behdad Esfahbod 已提交
1331
typedef OffsetListOf<SubstLookup> SubstLookupList;
1332

B
Minor  
Behdad Esfahbod 已提交
1333
/*
B
Behdad Esfahbod 已提交
1334
 * GSUB -- The Glyph Substitution Table
B
Minor  
Behdad Esfahbod 已提交
1335 1336
 */

B
Behdad Esfahbod 已提交
1337 1338
struct GSUB : GSUBGPOS
{
B
Behdad Esfahbod 已提交
1339
  static const hb_tag_t Tag	= HB_OT_TAG_GSUB;
B
Minor  
Behdad Esfahbod 已提交
1340

B
Behdad Esfahbod 已提交
1341
  inline const SubstLookup& get_lookup (unsigned int i) const
1342
  { return CastR<SubstLookup> (GSUBGPOS::get_lookup (i)); }
B
Behdad Esfahbod 已提交
1343

1344 1345
  static inline void substitute_start (hb_font_t *font, hb_buffer_t *buffer);
  static inline void substitute_finish (hb_font_t *font, hb_buffer_t *buffer);
B
Behdad Esfahbod 已提交
1346

B
Behdad Esfahbod 已提交
1347
  inline bool sanitize (hb_sanitize_context_t *c) {
B
Behdad Esfahbod 已提交
1348
    TRACE_SANITIZE (this);
1349
    if (unlikely (!GSUBGPOS::sanitize (c))) return TRACE_RETURN (false);
1350
    OffsetTo<SubstLookupList> &list = CastR<OffsetTo<SubstLookupList> > (lookupList);
1351
    return TRACE_RETURN (list.sanitize (c, this));
B
Behdad Esfahbod 已提交
1352
  }
1353 1354
  public:
  DEFINE_SIZE_STATIC (10);
B
Minor  
Behdad Esfahbod 已提交
1355
};
1356 1357


B
Behdad Esfahbod 已提交
1358
void
1359
GSUB::substitute_start (hb_font_t *font, hb_buffer_t *buffer)
B
Behdad Esfahbod 已提交
1360
{
B
Minor  
Behdad Esfahbod 已提交
1361
  HB_BUFFER_ALLOCATE_VAR (buffer, glyph_props);
1362
  HB_BUFFER_ALLOCATE_VAR (buffer, lig_props);
1363
  HB_BUFFER_ALLOCATE_VAR (buffer, syllable);
1364

1365
  const GDEF &gdef = *hb_ot_layout_from_face (font->face)->gdef;
B
Behdad Esfahbod 已提交
1366
  unsigned int count = buffer->len;
1367 1368
  for (unsigned int i = 0; i < count; i++) {
    buffer->info[i].lig_props() = buffer->info[i].syllable() = 0;
B
Minor  
Behdad Esfahbod 已提交
1369
    buffer->info[i].glyph_props() = gdef.get_glyph_props (buffer->info[i].codepoint);
1370
  }
B
Behdad Esfahbod 已提交
1371 1372 1373
}

void
1374
GSUB::substitute_finish (hb_font_t *font HB_UNUSED, hb_buffer_t *buffer HB_UNUSED)
B
Behdad Esfahbod 已提交
1375 1376 1377 1378
{
}


B
Behdad Esfahbod 已提交
1379
/* Out-of-class implementation for methods recursing */
1380

B
Behdad Esfahbod 已提交
1381 1382 1383
inline bool ExtensionSubst::is_reverse (void) const
{
  unsigned int type = get_type ();
1384
  if (unlikely (type == SubstLookupSubTable::Extension))
1385
    return CastR<ExtensionSubst> (get_subtable<SubstLookupSubTable>()).is_reverse ();
B
Behdad Esfahbod 已提交
1386 1387 1388
  return SubstLookup::lookup_type_is_reverse (type);
}

1389 1390
template <typename context_t>
inline typename context_t::return_t SubstLookup::process_recurse_func (context_t *c, unsigned int lookup_index)
1391 1392 1393 1394 1395 1396
{
  const GSUB &gsub = *(hb_ot_layout_from_face (c->face)->gsub);
  const SubstLookup &l = gsub.get_lookup (lookup_index);
  return l.process (c);
}

1397
inline bool SubstLookup::apply_recurse_func (hb_apply_context_t *c, unsigned int lookup_index)
B
Behdad Esfahbod 已提交
1398
{
1399
  const GSUB &gsub = *(hb_ot_layout_from_face (c->face)->gsub);
1400
  const SubstLookup &l = gsub.get_lookup (lookup_index);
1401 1402
  unsigned int saved_lookup_props = c->lookup_props;
  unsigned int saved_property = c->property;
1403
  c->set_lookup (l);
1404 1405 1406 1407
  bool ret = l.apply_once (c);
  c->lookup_props = saved_lookup_props;
  c->property = saved_property;
  return ret;
1408 1409 1410
}


B
Behdad Esfahbod 已提交
1411
} /* namespace OT */
1412

B
Behdad Esfahbod 已提交
1413

1414
#endif /* HB_OT_LAYOUT_GSUB_TABLE_HH */