hb-ot-shape.cc revision 91689de2603e4151e2a2d3a3852c61667f0c6264
1/*
2 * Copyright © 2009,2010  Red Hat, Inc.
3 * Copyright © 2010,2011,2012  Google, Inc.
4 *
5 *  This is part of HarfBuzz, a text shaping library.
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
26 * Google Author(s): Behdad Esfahbod
27 */
28
29#define HB_SHAPER ot
30#define hb_ot_shaper_face_data_t hb_ot_layout_t
31#define hb_ot_shaper_shape_plan_data_t hb_ot_shape_plan_t
32#include "hb-shaper-impl-private.hh"
33
34#include "hb-ot-shape-private.hh"
35#include "hb-ot-shape-complex-private.hh"
36#include "hb-ot-shape-fallback-private.hh"
37#include "hb-ot-shape-normalize-private.hh"
38
39#include "hb-ot-layout-private.hh"
40#include "hb-set-private.hh"
41
42
43static hb_tag_t common_features[] = {
44  HB_TAG('c','c','m','p'),
45  HB_TAG('l','i','g','a'),
46  HB_TAG('l','o','c','l'),
47  HB_TAG('m','a','r','k'),
48  HB_TAG('m','k','m','k'),
49  HB_TAG('r','l','i','g'),
50};
51
52
53static hb_tag_t horizontal_features[] = {
54  HB_TAG('c','a','l','t'),
55  HB_TAG('c','l','i','g'),
56  HB_TAG('c','u','r','s'),
57  HB_TAG('k','e','r','n'),
58  HB_TAG('r','c','l','t'),
59};
60
61static hb_tag_t vertical_features[] = {
62  HB_TAG('v','e','r','t'),
63};
64
65
66
67static void
68hb_ot_shape_collect_features (hb_ot_shape_planner_t          *planner,
69			      const hb_segment_properties_t  *props,
70			      const hb_feature_t             *user_features,
71			      unsigned int                    num_user_features)
72{
73  hb_ot_map_builder_t *map = &planner->map;
74
75  switch (props->direction) {
76    case HB_DIRECTION_LTR:
77      map->add_global_bool_feature (HB_TAG ('l','t','r','a'));
78      map->add_global_bool_feature (HB_TAG ('l','t','r','m'));
79      break;
80    case HB_DIRECTION_RTL:
81      map->add_global_bool_feature (HB_TAG ('r','t','l','a'));
82      map->add_feature (HB_TAG ('r','t','l','m'), 1, F_NONE);
83      break;
84    case HB_DIRECTION_TTB:
85    case HB_DIRECTION_BTT:
86    case HB_DIRECTION_INVALID:
87    default:
88      break;
89  }
90
91  if (planner->shaper->collect_features)
92    planner->shaper->collect_features (planner);
93
94  for (unsigned int i = 0; i < ARRAY_LENGTH (common_features); i++)
95    map->add_global_bool_feature (common_features[i]);
96
97  if (HB_DIRECTION_IS_HORIZONTAL (props->direction))
98    for (unsigned int i = 0; i < ARRAY_LENGTH (horizontal_features); i++)
99      map->add_feature (horizontal_features[i], 1, F_GLOBAL |
100			(horizontal_features[i] == HB_TAG('k','e','r','n') ?
101			 F_HAS_FALLBACK : F_NONE));
102  else
103    for (unsigned int i = 0; i < ARRAY_LENGTH (vertical_features); i++)
104      map->add_feature (vertical_features[i], 1, F_GLOBAL |
105			(vertical_features[i] == HB_TAG('v','k','r','n') ?
106			 F_HAS_FALLBACK : F_NONE));
107
108  if (planner->shaper->override_features)
109    planner->shaper->override_features (planner);
110
111  for (unsigned int i = 0; i < num_user_features; i++) {
112    const hb_feature_t *feature = &user_features[i];
113    map->add_feature (feature->tag, feature->value,
114		      (feature->start == 0 && feature->end == (unsigned int) -1) ?
115		       F_GLOBAL : F_NONE);
116  }
117}
118
119
120/*
121 * shaper face data
122 */
123
124hb_ot_shaper_face_data_t *
125_hb_ot_shaper_face_data_create (hb_face_t *face)
126{
127  return _hb_ot_layout_create (face);
128}
129
130void
131_hb_ot_shaper_face_data_destroy (hb_ot_shaper_face_data_t *data)
132{
133  _hb_ot_layout_destroy (data);
134}
135
136
137/*
138 * shaper font data
139 */
140
141struct hb_ot_shaper_font_data_t {};
142
143hb_ot_shaper_font_data_t *
144_hb_ot_shaper_font_data_create (hb_font_t *font)
145{
146  return (hb_ot_shaper_font_data_t *) HB_SHAPER_DATA_SUCCEEDED;
147}
148
149void
150_hb_ot_shaper_font_data_destroy (hb_ot_shaper_font_data_t *data)
151{
152}
153
154
155/*
156 * shaper shape_plan data
157 */
158
159hb_ot_shaper_shape_plan_data_t *
160_hb_ot_shaper_shape_plan_data_create (hb_shape_plan_t    *shape_plan,
161				      const hb_feature_t *user_features,
162				      unsigned int        num_user_features)
163{
164  hb_ot_shape_plan_t *plan = (hb_ot_shape_plan_t *) calloc (1, sizeof (hb_ot_shape_plan_t));
165  if (unlikely (!plan))
166    return NULL;
167
168  hb_ot_shape_planner_t planner (shape_plan);
169
170  planner.shaper = hb_ot_shape_complex_categorize (&planner);
171
172  hb_ot_shape_collect_features (&planner, &shape_plan->props, user_features, num_user_features);
173
174  planner.compile (*plan);
175
176  if (plan->shaper->data_create) {
177    plan->data = plan->shaper->data_create (plan);
178    if (unlikely (!plan->data))
179      return NULL;
180  }
181
182  return plan;
183}
184
185void
186_hb_ot_shaper_shape_plan_data_destroy (hb_ot_shaper_shape_plan_data_t *plan)
187{
188  if (plan->shaper->data_destroy)
189    plan->shaper->data_destroy (const_cast<void *> (plan->data));
190
191  plan->finish ();
192
193  free (plan);
194}
195
196
197/*
198 * shaper
199 */
200
201struct hb_ot_shape_context_t
202{
203  hb_ot_shape_plan_t *plan;
204  hb_font_t *font;
205  hb_face_t *face;
206  hb_buffer_t  *buffer;
207  const hb_feature_t *user_features;
208  unsigned int        num_user_features;
209
210  /* Transient stuff */
211  hb_direction_t target_direction;
212};
213
214
215
216/* Main shaper */
217
218
219/* Prepare */
220
221static void
222hb_set_unicode_props (hb_buffer_t *buffer)
223{
224  unsigned int count = buffer->len;
225  for (unsigned int i = 0; i < count; i++)
226    _hb_glyph_info_set_unicode_props (&buffer->info[i], buffer->unicode);
227}
228
229static void
230hb_insert_dotted_circle (hb_buffer_t *buffer, hb_font_t *font)
231{
232  if (!(buffer->flags & HB_BUFFER_FLAG_BOT) ||
233      _hb_glyph_info_get_general_category (&buffer->info[0]) !=
234      HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
235    return;
236
237  hb_codepoint_t dottedcircle_glyph;
238  if (!font->get_glyph (0x25CC, 0, &dottedcircle_glyph))
239    return;
240
241  hb_glyph_info_t dottedcircle;
242  dottedcircle.codepoint = 0x25CC;
243  _hb_glyph_info_set_unicode_props (&dottedcircle, buffer->unicode);
244
245  buffer->clear_output ();
246
247  buffer->idx = 0;
248  hb_glyph_info_t info = dottedcircle;
249  info.cluster = buffer->cur().cluster;
250  info.mask = buffer->cur().mask;
251  buffer->output_info (info);
252  while (buffer->idx < buffer->len)
253    buffer->next_glyph ();
254
255  buffer->swap_buffers ();
256}
257
258static void
259hb_form_clusters (hb_buffer_t *buffer)
260{
261  unsigned int count = buffer->len;
262  for (unsigned int i = 1; i < count; i++)
263    if (HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&buffer->info[i])))
264      buffer->merge_clusters (i - 1, i + 1);
265}
266
267static void
268hb_ensure_native_direction (hb_buffer_t *buffer)
269{
270  hb_direction_t direction = buffer->props.direction;
271
272  /* TODO vertical:
273   * The only BTT vertical script is Ogham, but it's not clear to me whether OpenType
274   * Ogham fonts are supposed to be implemented BTT or not.  Need to research that
275   * first. */
276  if ((HB_DIRECTION_IS_HORIZONTAL (direction) && direction != hb_script_get_horizontal_direction (buffer->props.script)) ||
277      (HB_DIRECTION_IS_VERTICAL   (direction) && direction != HB_DIRECTION_TTB))
278  {
279    hb_buffer_reverse_clusters (buffer);
280    buffer->props.direction = HB_DIRECTION_REVERSE (buffer->props.direction);
281  }
282}
283
284
285/* Substitute */
286
287static inline void
288hb_ot_mirror_chars (hb_ot_shape_context_t *c)
289{
290  if (HB_DIRECTION_IS_FORWARD (c->target_direction))
291    return;
292
293  hb_unicode_funcs_t *unicode = c->buffer->unicode;
294  hb_mask_t rtlm_mask = c->plan->map.get_1_mask (HB_TAG ('r','t','l','m'));
295
296  unsigned int count = c->buffer->len;
297  for (unsigned int i = 0; i < count; i++) {
298    hb_codepoint_t codepoint = unicode->mirroring (c->buffer->info[i].codepoint);
299    if (likely (codepoint == c->buffer->info[i].codepoint))
300      c->buffer->info[i].mask |= rtlm_mask;
301    else
302      c->buffer->info[i].codepoint = codepoint;
303  }
304}
305
306static inline void
307hb_ot_shape_setup_masks (hb_ot_shape_context_t *c)
308{
309  hb_ot_map_t *map = &c->plan->map;
310
311  hb_mask_t global_mask = map->get_global_mask ();
312  c->buffer->reset_masks (global_mask);
313
314  if (c->plan->shaper->setup_masks)
315    c->plan->shaper->setup_masks (c->plan, c->buffer, c->font);
316
317  for (unsigned int i = 0; i < c->num_user_features; i++)
318  {
319    const hb_feature_t *feature = &c->user_features[i];
320    if (!(feature->start == 0 && feature->end == (unsigned int)-1)) {
321      unsigned int shift;
322      hb_mask_t mask = map->get_mask (feature->tag, &shift);
323      c->buffer->set_masks (feature->value << shift, mask, feature->start, feature->end);
324    }
325  }
326}
327
328static inline void
329hb_ot_map_glyphs_fast (hb_buffer_t  *buffer)
330{
331  /* Normalization process sets up glyph_index(), we just copy it. */
332  unsigned int count = buffer->len;
333  for (unsigned int i = 0; i < count; i++)
334    buffer->info[i].codepoint = buffer->info[i].glyph_index();
335}
336
337static inline void
338hb_synthesize_glyph_classes (hb_ot_shape_context_t *c)
339{
340  unsigned int count = c->buffer->len;
341  for (unsigned int i = 0; i < count; i++)
342    _hb_glyph_info_set_glyph_props (&c->buffer->info[i],
343				    _hb_glyph_info_get_general_category (&c->buffer->info[i])
344				    == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK ?
345				    HB_OT_LAYOUT_GLYPH_PROPS_MARK :
346				    HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH);
347}
348
349static inline void
350hb_ot_substitute_default (hb_ot_shape_context_t *c)
351{
352  if (c->plan->shaper->preprocess_text)
353    c->plan->shaper->preprocess_text (c->plan, c->buffer, c->font);
354
355  hb_ot_mirror_chars (c);
356
357  HB_BUFFER_ALLOCATE_VAR (c->buffer, glyph_index);
358
359  _hb_ot_shape_normalize (c->plan, c->buffer, c->font);
360
361  hb_ot_shape_setup_masks (c);
362
363  /* This is unfortunate to go here, but necessary... */
364  if (!hb_ot_layout_has_positioning (c->face))
365    _hb_ot_shape_fallback_position_recategorize_marks (c->plan, c->font, c->buffer);
366
367  hb_ot_map_glyphs_fast (c->buffer);
368
369  HB_BUFFER_DEALLOCATE_VAR (c->buffer, glyph_index);
370}
371
372static inline void
373hb_ot_substitute_complex (hb_ot_shape_context_t *c)
374{
375  hb_ot_layout_substitute_start (c->font, c->buffer);
376
377  if (!hb_ot_layout_has_glyph_classes (c->face))
378    hb_synthesize_glyph_classes (c);
379
380  c->plan->substitute (c->font, c->buffer);
381
382  hb_ot_layout_substitute_finish (c->font, c->buffer);
383
384  return;
385}
386
387static inline void
388hb_ot_substitute (hb_ot_shape_context_t *c)
389{
390  hb_ot_substitute_default (c);
391  hb_ot_substitute_complex (c);
392}
393
394/* Position */
395
396static inline void
397zero_mark_widths_by_unicode (hb_buffer_t *buffer)
398{
399  unsigned int count = buffer->len;
400  for (unsigned int i = 0; i < count; i++)
401    if (_hb_glyph_info_get_general_category (&buffer->info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
402    {
403      buffer->pos[i].x_advance = 0;
404      buffer->pos[i].y_advance = 0;
405    }
406}
407
408static inline void
409zero_mark_widths_by_gdef (hb_buffer_t *buffer)
410{
411  unsigned int count = buffer->len;
412  for (unsigned int i = 0; i < count; i++)
413    if ((buffer->info[i].glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_MARK))
414    {
415      buffer->pos[i].x_advance = 0;
416      buffer->pos[i].y_advance = 0;
417    }
418}
419
420static inline void
421hb_ot_position_default (hb_ot_shape_context_t *c)
422{
423  unsigned int count = c->buffer->len;
424  for (unsigned int i = 0; i < count; i++)
425  {
426    c->font->get_glyph_advance_for_direction (c->buffer->info[i].codepoint,
427					      c->buffer->props.direction,
428					      &c->buffer->pos[i].x_advance,
429					      &c->buffer->pos[i].y_advance);
430    c->font->subtract_glyph_origin_for_direction (c->buffer->info[i].codepoint,
431						  c->buffer->props.direction,
432						  &c->buffer->pos[i].x_offset,
433						  &c->buffer->pos[i].y_offset);
434
435  }
436}
437
438static inline bool
439hb_ot_position_complex (hb_ot_shape_context_t *c)
440{
441  bool ret = false;
442  unsigned int count = c->buffer->len;
443
444  switch (c->plan->shaper->zero_width_marks)
445  {
446    case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY:
447      zero_mark_widths_by_gdef (c->buffer);
448      break;
449
450    /* Not currently used for any shaper:
451    case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE_EARLY:
452      zero_mark_widths_by_unicode (c->buffer);
453      break;
454    */
455
456    default:
457    case HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE:
458    case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE_LATE:
459    case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE:
460      break;
461  }
462
463  if (hb_ot_layout_has_positioning (c->face))
464  {
465    /* Change glyph origin to what GPOS expects, apply GPOS, change it back. */
466
467    for (unsigned int i = 0; i < count; i++) {
468      c->font->add_glyph_origin_for_direction (c->buffer->info[i].codepoint,
469					       HB_DIRECTION_LTR,
470					       &c->buffer->pos[i].x_offset,
471					       &c->buffer->pos[i].y_offset);
472    }
473
474    c->plan->position (c->font, c->buffer);
475
476    for (unsigned int i = 0; i < count; i++) {
477      c->font->subtract_glyph_origin_for_direction (c->buffer->info[i].codepoint,
478						    HB_DIRECTION_LTR,
479						    &c->buffer->pos[i].x_offset,
480						    &c->buffer->pos[i].y_offset);
481    }
482
483    ret = true;
484  }
485
486  switch (c->plan->shaper->zero_width_marks)
487  {
488    case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE_LATE:
489      zero_mark_widths_by_unicode (c->buffer);
490      break;
491
492    case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE:
493      zero_mark_widths_by_gdef (c->buffer);
494      break;
495
496    default:
497    case HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE:
498    //case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE_EARLY:
499    case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY:
500      break;
501  }
502
503  return ret;
504}
505
506static inline void
507hb_ot_position (hb_ot_shape_context_t *c)
508{
509  hb_ot_layout_position_start (c->font, c->buffer);
510
511  hb_ot_position_default (c);
512
513  hb_bool_t fallback = !hb_ot_position_complex (c);
514
515  hb_ot_layout_position_finish (c->font, c->buffer);
516
517  if (fallback && c->plan->shaper->fallback_position)
518    _hb_ot_shape_fallback_position (c->plan, c->font, c->buffer);
519
520  if (HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction))
521    hb_buffer_reverse (c->buffer);
522
523  /* Visual fallback goes here. */
524
525  if (fallback)
526    _hb_ot_shape_fallback_kern (c->plan, c->font, c->buffer);
527}
528
529
530/* Post-process */
531
532static void
533hb_ot_hide_default_ignorables (hb_ot_shape_context_t *c)
534{
535  if (c->buffer->flags & HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES)
536    return;
537
538  hb_codepoint_t space;
539  enum {
540    SPACE_DONT_KNOW,
541    SPACE_AVAILABLE,
542    SPACE_UNAVAILABLE
543  } space_status = SPACE_DONT_KNOW;
544
545  unsigned int count = c->buffer->len;
546  hb_glyph_info_t *info = c->buffer->info;
547  hb_glyph_position_t *pos = c->buffer->pos;
548  unsigned int j = 0;
549  for (unsigned int i = 0; i < count; i++)
550  {
551    if (unlikely (!_hb_glyph_info_is_ligated (&info[i]) &&
552		  _hb_glyph_info_is_default_ignorable (&info[i])))
553    {
554      if (space_status == SPACE_DONT_KNOW)
555	space_status = c->font->get_glyph (' ', 0, &space) ? SPACE_AVAILABLE : SPACE_UNAVAILABLE;
556
557      if (space_status == SPACE_AVAILABLE)
558      {
559	info[i].codepoint = space;
560	pos[i].x_advance = 0;
561	pos[i].y_advance = 0;
562      }
563      else
564	continue; /* Delete it. */
565    }
566    if (j != i)
567    {
568      info[j] = info[i];
569      pos[j] = pos[i];
570    }
571    j++;
572  }
573  c->buffer->len = j;
574}
575
576
577/* Pull it all together! */
578
579static void
580hb_ot_shape_internal (hb_ot_shape_context_t *c)
581{
582  c->buffer->deallocate_var_all ();
583
584  /* Save the original direction, we use it later. */
585  c->target_direction = c->buffer->props.direction;
586
587  HB_BUFFER_ALLOCATE_VAR (c->buffer, unicode_props0);
588  HB_BUFFER_ALLOCATE_VAR (c->buffer, unicode_props1);
589
590  c->buffer->clear_output ();
591
592  hb_set_unicode_props (c->buffer);
593  hb_insert_dotted_circle (c->buffer, c->font);
594  hb_form_clusters (c->buffer);
595
596  hb_ensure_native_direction (c->buffer);
597
598  hb_ot_substitute (c);
599  hb_ot_position (c);
600
601  hb_ot_hide_default_ignorables (c);
602
603  HB_BUFFER_DEALLOCATE_VAR (c->buffer, unicode_props1);
604  HB_BUFFER_DEALLOCATE_VAR (c->buffer, unicode_props0);
605
606  c->buffer->props.direction = c->target_direction;
607
608  c->buffer->deallocate_var_all ();
609}
610
611
612hb_bool_t
613_hb_ot_shape (hb_shape_plan_t    *shape_plan,
614	      hb_font_t          *font,
615	      hb_buffer_t        *buffer,
616	      const hb_feature_t *features,
617	      unsigned int        num_features)
618{
619  hb_ot_shape_context_t c = {HB_SHAPER_DATA_GET (shape_plan), font, font->face, buffer, features, num_features};
620  hb_ot_shape_internal (&c);
621
622  return true;
623}
624
625
626void
627hb_ot_shape_plan_collect_lookups (hb_shape_plan_t *shape_plan,
628				  hb_tag_t         table_tag,
629				  hb_set_t        *lookup_indexes /* OUT */)
630{
631  /* XXX Does the first part always succeed? */
632  HB_SHAPER_DATA_GET (shape_plan)->collect_lookups (table_tag, lookup_indexes);
633}
634
635
636/* TODO Move this to hb-ot-shape-normalize, make it do decompose, and make it public. */
637static void
638add_char (hb_font_t          *font,
639	  hb_unicode_funcs_t *unicode,
640	  hb_bool_t           mirror,
641	  hb_codepoint_t      u,
642	  hb_set_t           *glyphs)
643{
644  hb_codepoint_t glyph;
645  if (font->get_glyph (u, 0, &glyph))
646    glyphs->add (glyph);
647  if (mirror)
648  {
649    hb_codepoint_t m = unicode->mirroring (u);
650    if (m != u && font->get_glyph (m, 0, &glyph))
651      glyphs->add (glyph);
652  }
653}
654
655
656void
657hb_ot_shape_glyphs_closure (hb_font_t          *font,
658			    hb_buffer_t        *buffer,
659			    const hb_feature_t *features,
660			    unsigned int        num_features,
661			    hb_set_t           *glyphs)
662{
663  hb_ot_shape_plan_t plan;
664
665  const char *shapers[] = {"ot", NULL};
666  hb_shape_plan_t *shape_plan = hb_shape_plan_create_cached (font->face, &buffer->props,
667							     features, num_features, shapers);
668
669  bool mirror = hb_script_get_horizontal_direction (buffer->props.script) == HB_DIRECTION_RTL;
670
671  unsigned int count = buffer->len;
672  for (unsigned int i = 0; i < count; i++)
673    add_char (font, buffer->unicode, mirror, buffer->info[i].codepoint, glyphs);
674
675  hb_set_t lookups;
676  lookups.init ();
677  hb_ot_shape_plan_collect_lookups (shape_plan, HB_OT_TAG_GSUB, &lookups);
678
679  /* And find transitive closure. */
680  hb_set_t copy;
681  copy.init ();
682  do {
683    copy.set (glyphs);
684    for (hb_codepoint_t lookup_index = -1; hb_set_next (&lookups, &lookup_index);)
685      hb_ot_layout_lookup_substitute_closure (font->face, lookup_index, glyphs);
686  } while (!copy.is_equal (glyphs));
687
688  hb_shape_plan_destroy (shape_plan);
689}
690