Imported Upstream version 2.6.7
[platform/upstream/harfbuzz.git] / src / hb-ot-shape.cc
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 #include "hb.hh"
30
31 #ifndef HB_NO_OT_SHAPE
32
33 #ifdef HB_NO_OT_LAYOUT
34 #error "Cannot compile 'ot' shaper with HB_NO_OT_LAYOUT."
35 #endif
36
37 #include "hb-shaper-impl.hh"
38
39 #include "hb-ot-shape.hh"
40 #include "hb-ot-shape-complex.hh"
41 #include "hb-ot-shape-fallback.hh"
42 #include "hb-ot-shape-normalize.hh"
43
44 #include "hb-ot-face.hh"
45
46 #include "hb-set.hh"
47
48 #include "hb-aat-layout.hh"
49
50
51 #ifndef HB_NO_AAT_SHAPE
52 static inline bool
53 _hb_apply_morx (hb_face_t *face, const hb_segment_properties_t *props)
54 {
55   /* https://github.com/harfbuzz/harfbuzz/issues/2124 */
56   return hb_aat_layout_has_substitution (face) &&
57          (HB_DIRECTION_IS_HORIZONTAL (props->direction) || !hb_ot_layout_has_substitution (face));
58 }
59 #endif
60
61 /**
62  * SECTION:hb-ot-shape
63  * @title: hb-ot-shape
64  * @short_description: OpenType shaping support
65  * @include: hb-ot.h
66  *
67  * Support functions for OpenType shaping related queries.
68  **/
69
70
71 static void
72 hb_ot_shape_collect_features (hb_ot_shape_planner_t          *planner,
73                               const hb_feature_t             *user_features,
74                               unsigned int                    num_user_features);
75
76 hb_ot_shape_planner_t::hb_ot_shape_planner_t (hb_face_t                     *face,
77                                               const hb_segment_properties_t *props) :
78                                                 face (face),
79                                                 props (*props),
80                                                 map (face, props),
81                                                 aat_map (face, props)
82 #ifndef HB_NO_AAT_SHAPE
83                                                 , apply_morx (_hb_apply_morx (face, props))
84 #endif
85 {
86   shaper = hb_ot_shape_complex_categorize (this);
87
88   script_zero_marks = shaper->zero_width_marks != HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE;
89   script_fallback_mark_positioning = shaper->fallback_position;
90
91   /* https://github.com/harfbuzz/harfbuzz/issues/1528 */
92   if (apply_morx && shaper != &_hb_ot_complex_shaper_default)
93     shaper = &_hb_ot_complex_shaper_dumber;
94 }
95
96 void
97 hb_ot_shape_planner_t::compile (hb_ot_shape_plan_t           &plan,
98                                 const hb_ot_shape_plan_key_t &key)
99 {
100   plan.props = props;
101   plan.shaper = shaper;
102   map.compile (plan.map, key);
103 #ifndef HB_NO_AAT_SHAPE
104   if (apply_morx)
105     aat_map.compile (plan.aat_map);
106 #endif
107
108 #ifndef HB_NO_OT_SHAPE_FRACTIONS
109   plan.frac_mask = plan.map.get_1_mask (HB_TAG ('f','r','a','c'));
110   plan.numr_mask = plan.map.get_1_mask (HB_TAG ('n','u','m','r'));
111   plan.dnom_mask = plan.map.get_1_mask (HB_TAG ('d','n','o','m'));
112   plan.has_frac = plan.frac_mask || (plan.numr_mask && plan.dnom_mask);
113 #endif
114
115   plan.rtlm_mask = plan.map.get_1_mask (HB_TAG ('r','t','l','m'));
116   plan.has_vert = !!plan.map.get_1_mask (HB_TAG ('v','e','r','t'));
117
118   hb_tag_t kern_tag = HB_DIRECTION_IS_HORIZONTAL (props.direction) ?
119                       HB_TAG ('k','e','r','n') : HB_TAG ('v','k','r','n');
120 #ifndef HB_NO_OT_KERN
121   plan.kern_mask = plan.map.get_mask (kern_tag);
122   plan.requested_kerning = !!plan.kern_mask;
123 #endif
124 #ifndef HB_NO_AAT_SHAPE
125   plan.trak_mask = plan.map.get_mask (HB_TAG ('t','r','a','k'));
126   plan.requested_tracking = !!plan.trak_mask;
127 #endif
128
129   bool has_gpos_kern = plan.map.get_feature_index (1, kern_tag) != HB_OT_LAYOUT_NO_FEATURE_INDEX;
130   bool disable_gpos = plan.shaper->gpos_tag &&
131                       plan.shaper->gpos_tag != plan.map.chosen_script[1];
132
133   /*
134    * Decide who provides glyph classes. GDEF or Unicode.
135    */
136
137   if (!hb_ot_layout_has_glyph_classes (face))
138     plan.fallback_glyph_classes = true;
139
140   /*
141    * Decide who does substitutions. GSUB, morx, or fallback.
142    */
143
144 #ifndef HB_NO_AAT_SHAPE
145   plan.apply_morx = apply_morx;
146 #endif
147
148   /*
149    * Decide who does positioning. GPOS, kerx, kern, or fallback.
150    */
151
152   if (0)
153     ;
154 #ifndef HB_NO_AAT_SHAPE
155   else if (hb_aat_layout_has_positioning (face))
156     plan.apply_kerx = true;
157 #endif
158   else if (!apply_morx && !disable_gpos && hb_ot_layout_has_positioning (face))
159     plan.apply_gpos = true;
160
161   if (!plan.apply_kerx && (!has_gpos_kern || !plan.apply_gpos))
162   {
163     /* Apparently Apple applies kerx if GPOS kern was not applied. */
164 #ifndef HB_NO_AAT_SHAPE
165     if (hb_aat_layout_has_positioning (face))
166       plan.apply_kerx = true;
167     else
168 #endif
169 #ifndef HB_NO_OT_KERN
170     if (hb_ot_layout_has_kerning (face))
171       plan.apply_kern = true;
172 #endif
173   }
174
175   plan.zero_marks = script_zero_marks &&
176                     !plan.apply_kerx &&
177                     (!plan.apply_kern
178 #ifndef HB_NO_OT_KERN
179                      || !hb_ot_layout_has_machine_kerning (face)
180 #endif
181                     );
182   plan.has_gpos_mark = !!plan.map.get_1_mask (HB_TAG ('m','a','r','k'));
183
184   plan.adjust_mark_positioning_when_zeroing = !plan.apply_gpos &&
185                                               !plan.apply_kerx &&
186                                               (!plan.apply_kern
187 #ifndef HB_NO_OT_KERN
188                                                || !hb_ot_layout_has_cross_kerning (face)
189 #endif
190                                               );
191
192   plan.fallback_mark_positioning = plan.adjust_mark_positioning_when_zeroing &&
193                                    script_fallback_mark_positioning;
194
195 #ifndef HB_NO_AAT_SHAPE
196   /* Currently we always apply trak. */
197   plan.apply_trak = plan.requested_tracking && hb_aat_layout_has_tracking (face);
198 #endif
199 }
200
201 bool
202 hb_ot_shape_plan_t::init0 (hb_face_t                     *face,
203                            const hb_shape_plan_key_t     *key)
204 {
205   map.init ();
206 #ifndef HB_NO_AAT_SHAPE
207   aat_map.init ();
208 #endif
209
210   hb_ot_shape_planner_t planner (face,
211                                  &key->props);
212
213   hb_ot_shape_collect_features (&planner,
214                                 key->user_features,
215                                 key->num_user_features);
216
217   planner.compile (*this, key->ot);
218
219   if (shaper->data_create)
220   {
221     data = shaper->data_create (this);
222     if (unlikely (!data))
223       return false;
224   }
225
226   return true;
227 }
228
229 void
230 hb_ot_shape_plan_t::fini ()
231 {
232   if (shaper->data_destroy)
233     shaper->data_destroy (const_cast<void *> (data));
234
235   map.fini ();
236 #ifndef HB_NO_AAT_SHAPE
237   aat_map.fini ();
238 #endif
239 }
240
241 void
242 hb_ot_shape_plan_t::substitute (hb_font_t   *font,
243                                 hb_buffer_t *buffer) const
244 {
245 #ifndef HB_NO_AAT_SHAPE
246   if (unlikely (apply_morx))
247     hb_aat_layout_substitute (this, font, buffer);
248   else
249 #endif
250     map.substitute (this, font, buffer);
251 }
252
253 void
254 hb_ot_shape_plan_t::position (hb_font_t   *font,
255                               hb_buffer_t *buffer) const
256 {
257   if (this->apply_gpos)
258     map.position (this, font, buffer);
259 #ifndef HB_NO_AAT_SHAPE
260   else if (this->apply_kerx)
261     hb_aat_layout_position (this, font, buffer);
262 #endif
263 #ifndef HB_NO_OT_KERN
264   else if (this->apply_kern)
265     hb_ot_layout_kern (this, font, buffer);
266 #endif
267   else
268     _hb_ot_shape_fallback_kern (this, font, buffer);
269
270 #ifndef HB_NO_AAT_SHAPE
271   if (this->apply_trak)
272     hb_aat_layout_track (this, font, buffer);
273 #endif
274 }
275
276
277 static const hb_ot_map_feature_t
278 common_features[] =
279 {
280   {HB_TAG('a','b','v','m'), F_GLOBAL},
281   {HB_TAG('b','l','w','m'), F_GLOBAL},
282   {HB_TAG('c','c','m','p'), F_GLOBAL},
283   {HB_TAG('l','o','c','l'), F_GLOBAL},
284   {HB_TAG('m','a','r','k'), F_GLOBAL_MANUAL_JOINERS},
285   {HB_TAG('m','k','m','k'), F_GLOBAL_MANUAL_JOINERS},
286   {HB_TAG('r','l','i','g'), F_GLOBAL},
287 };
288
289
290 static const hb_ot_map_feature_t
291 horizontal_features[] =
292 {
293   {HB_TAG('c','a','l','t'), F_GLOBAL},
294   {HB_TAG('c','l','i','g'), F_GLOBAL},
295   {HB_TAG('c','u','r','s'), F_GLOBAL},
296   {HB_TAG('d','i','s','t'), F_GLOBAL},
297   {HB_TAG('k','e','r','n'), F_GLOBAL_HAS_FALLBACK},
298   {HB_TAG('l','i','g','a'), F_GLOBAL},
299   {HB_TAG('r','c','l','t'), F_GLOBAL},
300 };
301
302 static void
303 hb_ot_shape_collect_features (hb_ot_shape_planner_t          *planner,
304                               const hb_feature_t             *user_features,
305                               unsigned int                    num_user_features)
306 {
307   hb_ot_map_builder_t *map = &planner->map;
308
309   map->enable_feature (HB_TAG('r','v','r','n'));
310   map->add_gsub_pause (nullptr);
311
312   switch (planner->props.direction) {
313     case HB_DIRECTION_LTR:
314       map->enable_feature (HB_TAG ('l','t','r','a'));
315       map->enable_feature (HB_TAG ('l','t','r','m'));
316       break;
317     case HB_DIRECTION_RTL:
318       map->enable_feature (HB_TAG ('r','t','l','a'));
319       map->add_feature (HB_TAG ('r','t','l','m'));
320       break;
321     case HB_DIRECTION_TTB:
322     case HB_DIRECTION_BTT:
323     case HB_DIRECTION_INVALID:
324     default:
325       break;
326   }
327
328 #ifndef HB_NO_OT_SHAPE_FRACTIONS
329   /* Automatic fractions. */
330   map->add_feature (HB_TAG ('f','r','a','c'));
331   map->add_feature (HB_TAG ('n','u','m','r'));
332   map->add_feature (HB_TAG ('d','n','o','m'));
333 #endif
334
335   /* Random! */
336   map->enable_feature (HB_TAG ('r','a','n','d'), F_RANDOM, HB_OT_MAP_MAX_VALUE);
337
338 #ifndef HB_NO_AAT_SHAPE
339   /* Tracking.  We enable dummy feature here just to allow disabling
340    * AAT 'trak' table using features.
341    * https://github.com/harfbuzz/harfbuzz/issues/1303 */
342   map->enable_feature (HB_TAG ('t','r','a','k'), F_HAS_FALLBACK);
343 #endif
344
345   map->enable_feature (HB_TAG ('H','A','R','F'));
346
347   if (planner->shaper->collect_features)
348     planner->shaper->collect_features (planner);
349
350   map->enable_feature (HB_TAG ('B','U','Z','Z'));
351
352   for (unsigned int i = 0; i < ARRAY_LENGTH (common_features); i++)
353     map->add_feature (common_features[i]);
354
355   if (HB_DIRECTION_IS_HORIZONTAL (planner->props.direction))
356     for (unsigned int i = 0; i < ARRAY_LENGTH (horizontal_features); i++)
357       map->add_feature (horizontal_features[i]);
358   else
359   {
360     /* We really want to find a 'vert' feature if there's any in the font, no
361      * matter which script/langsys it is listed (or not) under.
362      * See various bugs referenced from:
363      * https://github.com/harfbuzz/harfbuzz/issues/63 */
364     map->enable_feature (HB_TAG ('v','e','r','t'), F_GLOBAL_SEARCH);
365   }
366
367   for (unsigned int i = 0; i < num_user_features; i++)
368   {
369     const hb_feature_t *feature = &user_features[i];
370     map->add_feature (feature->tag,
371                       (feature->start == HB_FEATURE_GLOBAL_START &&
372                        feature->end == HB_FEATURE_GLOBAL_END) ?  F_GLOBAL : F_NONE,
373                       feature->value);
374   }
375
376 #ifndef HB_NO_AAT_SHAPE
377   if (planner->apply_morx)
378   {
379     hb_aat_map_builder_t *aat_map = &planner->aat_map;
380     for (unsigned int i = 0; i < num_user_features; i++)
381     {
382       const hb_feature_t *feature = &user_features[i];
383       aat_map->add_feature (feature->tag, feature->value);
384     }
385   }
386 #endif
387
388   if (planner->shaper->override_features)
389     planner->shaper->override_features (planner);
390 }
391
392
393 /*
394  * shaper face data
395  */
396
397 struct hb_ot_face_data_t {};
398
399 hb_ot_face_data_t *
400 _hb_ot_shaper_face_data_create (hb_face_t *face)
401 {
402   return (hb_ot_face_data_t *) HB_SHAPER_DATA_SUCCEEDED;
403 }
404
405 void
406 _hb_ot_shaper_face_data_destroy (hb_ot_face_data_t *data)
407 {
408 }
409
410
411 /*
412  * shaper font data
413  */
414
415 struct hb_ot_font_data_t {};
416
417 hb_ot_font_data_t *
418 _hb_ot_shaper_font_data_create (hb_font_t *font HB_UNUSED)
419 {
420   return (hb_ot_font_data_t *) HB_SHAPER_DATA_SUCCEEDED;
421 }
422
423 void
424 _hb_ot_shaper_font_data_destroy (hb_ot_font_data_t *data HB_UNUSED)
425 {
426 }
427
428
429 /*
430  * shaper
431  */
432
433 struct hb_ot_shape_context_t
434 {
435   hb_ot_shape_plan_t *plan;
436   hb_font_t *font;
437   hb_face_t *face;
438   hb_buffer_t  *buffer;
439   const hb_feature_t *user_features;
440   unsigned int        num_user_features;
441
442   /* Transient stuff */
443   hb_direction_t target_direction;
444 };
445
446
447
448 /* Main shaper */
449
450
451 /* Prepare */
452
453 static void
454 hb_set_unicode_props (hb_buffer_t *buffer)
455 {
456   /* Implement enough of Unicode Graphemes here that shaping
457    * in reverse-direction wouldn't break graphemes.  Namely,
458    * we mark all marks and ZWJ and ZWJ,Extended_Pictographic
459    * sequences as continuations.  The foreach_grapheme()
460    * macro uses this bit.
461    *
462    * https://www.unicode.org/reports/tr29/#Regex_Definitions
463    */
464   unsigned int count = buffer->len;
465   hb_glyph_info_t *info = buffer->info;
466   for (unsigned int i = 0; i < count; i++)
467   {
468     _hb_glyph_info_set_unicode_props (&info[i], buffer);
469
470     /* Marks are already set as continuation by the above line.
471      * Handle Emoji_Modifier and ZWJ-continuation. */
472     if (unlikely (_hb_glyph_info_get_general_category (&info[i]) == HB_UNICODE_GENERAL_CATEGORY_MODIFIER_SYMBOL &&
473                   hb_in_range<hb_codepoint_t> (info[i].codepoint, 0x1F3FBu, 0x1F3FFu)))
474     {
475         _hb_glyph_info_set_continuation (&info[i]);
476     }
477 #ifndef HB_NO_EMOJI_SEQUENCES
478     else if (unlikely (_hb_glyph_info_is_zwj (&info[i])))
479     {
480       _hb_glyph_info_set_continuation (&info[i]);
481       if (i + 1 < count &&
482           _hb_unicode_is_emoji_Extended_Pictographic (info[i + 1].codepoint))
483       {
484         i++;
485         _hb_glyph_info_set_unicode_props (&info[i], buffer);
486         _hb_glyph_info_set_continuation (&info[i]);
487       }
488     }
489 #endif
490     /* Or part of the Other_Grapheme_Extend that is not marks.
491      * As of Unicode 11 that is just:
492      *
493      * 200C          ; Other_Grapheme_Extend # Cf       ZERO WIDTH NON-JOINER
494      * FF9E..FF9F    ; Other_Grapheme_Extend # Lm   [2] HALFWIDTH KATAKANA VOICED SOUND MARK..HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK
495      * E0020..E007F  ; Other_Grapheme_Extend # Cf  [96] TAG SPACE..CANCEL TAG
496      *
497      * ZWNJ is special, we don't want to merge it as there's no need, and keeping
498      * it separate results in more granular clusters.  Ignore Katakana for now.
499      * Tags are used for Emoji sub-region flag sequences:
500      * https://github.com/harfbuzz/harfbuzz/issues/1556
501      */
502     else if (unlikely (hb_in_range<hb_codepoint_t> (info[i].codepoint, 0xE0020u, 0xE007Fu)))
503       _hb_glyph_info_set_continuation (&info[i]);
504   }
505 }
506
507 static void
508 hb_insert_dotted_circle (hb_buffer_t *buffer, hb_font_t *font)
509 {
510   if (unlikely (buffer->flags & HB_BUFFER_FLAG_DO_NOT_INSERT_DOTTED_CIRCLE))
511     return;
512
513   if (!(buffer->flags & HB_BUFFER_FLAG_BOT) ||
514       buffer->context_len[0] ||
515       !_hb_glyph_info_is_unicode_mark (&buffer->info[0]))
516     return;
517
518   if (!font->has_glyph (0x25CCu))
519     return;
520
521   hb_glyph_info_t dottedcircle = {0};
522   dottedcircle.codepoint = 0x25CCu;
523   _hb_glyph_info_set_unicode_props (&dottedcircle, buffer);
524
525   buffer->clear_output ();
526
527   buffer->idx = 0;
528   hb_glyph_info_t info = dottedcircle;
529   info.cluster = buffer->cur().cluster;
530   info.mask = buffer->cur().mask;
531   buffer->output_info (info);
532   while (buffer->idx < buffer->len && buffer->successful)
533     buffer->next_glyph ();
534   buffer->swap_buffers ();
535 }
536
537 static void
538 hb_form_clusters (hb_buffer_t *buffer)
539 {
540   if (!(buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_NON_ASCII))
541     return;
542
543   if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES)
544     foreach_grapheme (buffer, start, end)
545       buffer->merge_clusters (start, end);
546   else
547     foreach_grapheme (buffer, start, end)
548       buffer->unsafe_to_break (start, end);
549 }
550
551 static void
552 hb_ensure_native_direction (hb_buffer_t *buffer)
553 {
554   hb_direction_t direction = buffer->props.direction;
555   hb_direction_t horiz_dir = hb_script_get_horizontal_direction (buffer->props.script);
556
557   /* TODO vertical:
558    * The only BTT vertical script is Ogham, but it's not clear to me whether OpenType
559    * Ogham fonts are supposed to be implemented BTT or not.  Need to research that
560    * first. */
561   if ((HB_DIRECTION_IS_HORIZONTAL (direction) &&
562        direction != horiz_dir && horiz_dir != HB_DIRECTION_INVALID) ||
563       (HB_DIRECTION_IS_VERTICAL   (direction) &&
564        direction != HB_DIRECTION_TTB))
565   {
566
567     if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS)
568       foreach_grapheme (buffer, start, end)
569       {
570         buffer->merge_clusters (start, end);
571         buffer->reverse_range (start, end);
572       }
573     else
574       foreach_grapheme (buffer, start, end)
575         /* form_clusters() merged clusters already, we don't merge. */
576         buffer->reverse_range (start, end);
577
578     buffer->reverse ();
579
580     buffer->props.direction = HB_DIRECTION_REVERSE (buffer->props.direction);
581   }
582 }
583
584
585 /*
586  * Substitute
587  */
588
589 static hb_codepoint_t
590 hb_vert_char_for (hb_codepoint_t u)
591 {
592   switch (u >> 8)
593   {
594     case 0x20: switch (u) {
595       case 0x2013u: return 0xfe32u; // EN DASH
596       case 0x2014u: return 0xfe31u; // EM DASH
597       case 0x2025u: return 0xfe30u; // TWO DOT LEADER
598       case 0x2026u: return 0xfe19u; // HORIZONTAL ELLIPSIS
599     } break;
600     case 0x30: switch (u) {
601       case 0x3001u: return 0xfe11u; // IDEOGRAPHIC COMMA
602       case 0x3002u: return 0xfe12u; // IDEOGRAPHIC FULL STOP
603       case 0x3008u: return 0xfe3fu; // LEFT ANGLE BRACKET
604       case 0x3009u: return 0xfe40u; // RIGHT ANGLE BRACKET
605       case 0x300au: return 0xfe3du; // LEFT DOUBLE ANGLE BRACKET
606       case 0x300bu: return 0xfe3eu; // RIGHT DOUBLE ANGLE BRACKET
607       case 0x300cu: return 0xfe41u; // LEFT CORNER BRACKET
608       case 0x300du: return 0xfe42u; // RIGHT CORNER BRACKET
609       case 0x300eu: return 0xfe43u; // LEFT WHITE CORNER BRACKET
610       case 0x300fu: return 0xfe44u; // RIGHT WHITE CORNER BRACKET
611       case 0x3010u: return 0xfe3bu; // LEFT BLACK LENTICULAR BRACKET
612       case 0x3011u: return 0xfe3cu; // RIGHT BLACK LENTICULAR BRACKET
613       case 0x3014u: return 0xfe39u; // LEFT TORTOISE SHELL BRACKET
614       case 0x3015u: return 0xfe3au; // RIGHT TORTOISE SHELL BRACKET
615       case 0x3016u: return 0xfe17u; // LEFT WHITE LENTICULAR BRACKET
616       case 0x3017u: return 0xfe18u; // RIGHT WHITE LENTICULAR BRACKET
617     } break;
618     case 0xfe: switch (u) {
619       case 0xfe4fu: return 0xfe34u; // WAVY LOW LINE
620     } break;
621     case 0xff: switch (u) {
622       case 0xff01u: return 0xfe15u; // FULLWIDTH EXCLAMATION MARK
623       case 0xff08u: return 0xfe35u; // FULLWIDTH LEFT PARENTHESIS
624       case 0xff09u: return 0xfe36u; // FULLWIDTH RIGHT PARENTHESIS
625       case 0xff0cu: return 0xfe10u; // FULLWIDTH COMMA
626       case 0xff1au: return 0xfe13u; // FULLWIDTH COLON
627       case 0xff1bu: return 0xfe14u; // FULLWIDTH SEMICOLON
628       case 0xff1fu: return 0xfe16u; // FULLWIDTH QUESTION MARK
629       case 0xff3bu: return 0xfe47u; // FULLWIDTH LEFT SQUARE BRACKET
630       case 0xff3du: return 0xfe48u; // FULLWIDTH RIGHT SQUARE BRACKET
631       case 0xff3fu: return 0xfe33u; // FULLWIDTH LOW LINE
632       case 0xff5bu: return 0xfe37u; // FULLWIDTH LEFT CURLY BRACKET
633       case 0xff5du: return 0xfe38u; // FULLWIDTH RIGHT CURLY BRACKET
634     } break;
635   }
636
637   return u;
638 }
639
640 static inline void
641 hb_ot_rotate_chars (const hb_ot_shape_context_t *c)
642 {
643   hb_buffer_t *buffer = c->buffer;
644   unsigned int count = buffer->len;
645   hb_glyph_info_t *info = buffer->info;
646
647   if (HB_DIRECTION_IS_BACKWARD (c->target_direction))
648   {
649     hb_unicode_funcs_t *unicode = buffer->unicode;
650     hb_mask_t rtlm_mask = c->plan->rtlm_mask;
651
652     for (unsigned int i = 0; i < count; i++) {
653       hb_codepoint_t codepoint = unicode->mirroring (info[i].codepoint);
654       if (unlikely (codepoint != info[i].codepoint && c->font->has_glyph (codepoint)))
655         info[i].codepoint = codepoint;
656       else
657         info[i].mask |= rtlm_mask;
658     }
659   }
660
661   if (HB_DIRECTION_IS_VERTICAL (c->target_direction) && !c->plan->has_vert)
662   {
663     for (unsigned int i = 0; i < count; i++) {
664       hb_codepoint_t codepoint = hb_vert_char_for (info[i].codepoint);
665       if (unlikely (codepoint != info[i].codepoint && c->font->has_glyph (codepoint)))
666         info[i].codepoint = codepoint;
667     }
668   }
669 }
670
671 static inline void
672 hb_ot_shape_setup_masks_fraction (const hb_ot_shape_context_t *c)
673 {
674 #ifdef HB_NO_OT_SHAPE_FRACTIONS
675   return;
676 #endif
677
678   if (!(c->buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_NON_ASCII) ||
679       !c->plan->has_frac)
680     return;
681
682   hb_buffer_t *buffer = c->buffer;
683
684   hb_mask_t pre_mask, post_mask;
685   if (HB_DIRECTION_IS_FORWARD (buffer->props.direction))
686   {
687     pre_mask = c->plan->numr_mask | c->plan->frac_mask;
688     post_mask = c->plan->frac_mask | c->plan->dnom_mask;
689   }
690   else
691   {
692     pre_mask = c->plan->frac_mask | c->plan->dnom_mask;
693     post_mask = c->plan->numr_mask | c->plan->frac_mask;
694   }
695
696   unsigned int count = buffer->len;
697   hb_glyph_info_t *info = buffer->info;
698   for (unsigned int i = 0; i < count; i++)
699   {
700     if (info[i].codepoint == 0x2044u) /* FRACTION SLASH */
701     {
702       unsigned int start = i, end = i + 1;
703       while (start &&
704              _hb_glyph_info_get_general_category (&info[start - 1]) ==
705              HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER)
706         start--;
707       while (end < count &&
708              _hb_glyph_info_get_general_category (&info[end]) ==
709              HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER)
710         end++;
711
712       buffer->unsafe_to_break (start, end);
713
714       for (unsigned int j = start; j < i; j++)
715         info[j].mask |= pre_mask;
716       info[i].mask |= c->plan->frac_mask;
717       for (unsigned int j = i + 1; j < end; j++)
718         info[j].mask |= post_mask;
719
720       i = end - 1;
721     }
722   }
723 }
724
725 static inline void
726 hb_ot_shape_initialize_masks (const hb_ot_shape_context_t *c)
727 {
728   hb_ot_map_t *map = &c->plan->map;
729   hb_buffer_t *buffer = c->buffer;
730
731   hb_mask_t global_mask = map->get_global_mask ();
732   buffer->reset_masks (global_mask);
733 }
734
735 static inline void
736 hb_ot_shape_setup_masks (const hb_ot_shape_context_t *c)
737 {
738   hb_ot_map_t *map = &c->plan->map;
739   hb_buffer_t *buffer = c->buffer;
740
741   hb_ot_shape_setup_masks_fraction (c);
742
743   if (c->plan->shaper->setup_masks)
744     c->plan->shaper->setup_masks (c->plan, buffer, c->font);
745
746   for (unsigned int i = 0; i < c->num_user_features; i++)
747   {
748     const hb_feature_t *feature = &c->user_features[i];
749     if (!(feature->start == HB_FEATURE_GLOBAL_START && feature->end == HB_FEATURE_GLOBAL_END)) {
750       unsigned int shift;
751       hb_mask_t mask = map->get_mask (feature->tag, &shift);
752       buffer->set_masks (feature->value << shift, mask, feature->start, feature->end);
753     }
754   }
755 }
756
757 static void
758 hb_ot_zero_width_default_ignorables (const hb_buffer_t *buffer)
759 {
760   if (!(buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES) ||
761       (buffer->flags & HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES) ||
762       (buffer->flags & HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES))
763     return;
764
765   unsigned int count = buffer->len;
766   hb_glyph_info_t *info = buffer->info;
767   hb_glyph_position_t *pos = buffer->pos;
768   unsigned int i = 0;
769   for (i = 0; i < count; i++)
770     if (unlikely (_hb_glyph_info_is_default_ignorable (&info[i])))
771       pos[i].x_advance = pos[i].y_advance = pos[i].x_offset = pos[i].y_offset = 0;
772 }
773
774 static void
775 hb_ot_hide_default_ignorables (hb_buffer_t *buffer,
776                                hb_font_t   *font)
777 {
778   if (!(buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES) ||
779       (buffer->flags & HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES))
780     return;
781
782   unsigned int count = buffer->len;
783   hb_glyph_info_t *info = buffer->info;
784
785   hb_codepoint_t invisible = buffer->invisible;
786   if (!(buffer->flags & HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES) &&
787       (invisible || font->get_nominal_glyph (' ', &invisible)))
788   {
789     /* Replace default-ignorables with a zero-advance invisible glyph. */
790     for (unsigned int i = 0; i < count; i++)
791     {
792       if (_hb_glyph_info_is_default_ignorable (&info[i]))
793         info[i].codepoint = invisible;
794     }
795   }
796   else
797     hb_ot_layout_delete_glyphs_inplace (buffer, _hb_glyph_info_is_default_ignorable);
798 }
799
800
801 static inline void
802 hb_ot_map_glyphs_fast (hb_buffer_t  *buffer)
803 {
804   /* Normalization process sets up glyph_index(), we just copy it. */
805   unsigned int count = buffer->len;
806   hb_glyph_info_t *info = buffer->info;
807   for (unsigned int i = 0; i < count; i++)
808     info[i].codepoint = info[i].glyph_index();
809
810   buffer->content_type = HB_BUFFER_CONTENT_TYPE_GLYPHS;
811 }
812
813 static inline void
814 hb_synthesize_glyph_classes (hb_buffer_t *buffer)
815 {
816   unsigned int count = buffer->len;
817   hb_glyph_info_t *info = buffer->info;
818   for (unsigned int i = 0; i < count; i++)
819   {
820     hb_ot_layout_glyph_props_flags_t klass;
821
822     /* Never mark default-ignorables as marks.
823      * They won't get in the way of lookups anyway,
824      * but having them as mark will cause them to be skipped
825      * over if the lookup-flag says so, but at least for the
826      * Mongolian variation selectors, looks like Uniscribe
827      * marks them as non-mark.  Some Mongolian fonts without
828      * GDEF rely on this.  Another notable character that
829      * this applies to is COMBINING GRAPHEME JOINER. */
830     klass = (_hb_glyph_info_get_general_category (&info[i]) !=
831              HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK ||
832              _hb_glyph_info_is_default_ignorable (&info[i])) ?
833             HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH :
834             HB_OT_LAYOUT_GLYPH_PROPS_MARK;
835     _hb_glyph_info_set_glyph_props (&info[i], klass);
836   }
837 }
838
839 static inline void
840 hb_ot_substitute_default (const hb_ot_shape_context_t *c)
841 {
842   hb_buffer_t *buffer = c->buffer;
843
844   hb_ot_rotate_chars (c);
845
846   HB_BUFFER_ALLOCATE_VAR (buffer, glyph_index);
847
848   _hb_ot_shape_normalize (c->plan, buffer, c->font);
849
850   hb_ot_shape_setup_masks (c);
851
852   /* This is unfortunate to go here, but necessary... */
853   if (c->plan->fallback_mark_positioning)
854     _hb_ot_shape_fallback_mark_position_recategorize_marks (c->plan, c->font, buffer);
855
856   hb_ot_map_glyphs_fast (buffer);
857
858   HB_BUFFER_DEALLOCATE_VAR (buffer, glyph_index);
859 }
860
861 static inline void
862 hb_ot_substitute_complex (const hb_ot_shape_context_t *c)
863 {
864   hb_buffer_t *buffer = c->buffer;
865
866   hb_ot_layout_substitute_start (c->font, buffer);
867
868   if (c->plan->fallback_glyph_classes)
869     hb_synthesize_glyph_classes (c->buffer);
870
871   c->plan->substitute (c->font, buffer);
872 }
873
874 static inline void
875 hb_ot_substitute_pre (const hb_ot_shape_context_t *c)
876 {
877   hb_ot_substitute_default (c);
878
879   _hb_buffer_allocate_gsubgpos_vars (c->buffer);
880
881   hb_ot_substitute_complex (c);
882 }
883
884 static inline void
885 hb_ot_substitute_post (const hb_ot_shape_context_t *c)
886 {
887   hb_ot_hide_default_ignorables (c->buffer, c->font);
888 #ifndef HB_NO_AAT_SHAPE
889   if (c->plan->apply_morx)
890     hb_aat_layout_remove_deleted_glyphs (c->buffer);
891 #endif
892
893   if (c->plan->shaper->postprocess_glyphs)
894     c->plan->shaper->postprocess_glyphs (c->plan, c->buffer, c->font);
895 }
896
897
898 /*
899  * Position
900  */
901
902 static inline void
903 adjust_mark_offsets (hb_glyph_position_t *pos)
904 {
905   pos->x_offset -= pos->x_advance;
906   pos->y_offset -= pos->y_advance;
907 }
908
909 static inline void
910 zero_mark_width (hb_glyph_position_t *pos)
911 {
912   pos->x_advance = 0;
913   pos->y_advance = 0;
914 }
915
916 static inline void
917 zero_mark_widths_by_gdef (hb_buffer_t *buffer, bool adjust_offsets)
918 {
919   unsigned int count = buffer->len;
920   hb_glyph_info_t *info = buffer->info;
921   for (unsigned int i = 0; i < count; i++)
922     if (_hb_glyph_info_is_mark (&info[i]))
923     {
924       if (adjust_offsets)
925         adjust_mark_offsets (&buffer->pos[i]);
926       zero_mark_width (&buffer->pos[i]);
927     }
928 }
929
930 static inline void
931 hb_ot_position_default (const hb_ot_shape_context_t *c)
932 {
933   hb_direction_t direction = c->buffer->props.direction;
934   unsigned int count = c->buffer->len;
935   hb_glyph_info_t *info = c->buffer->info;
936   hb_glyph_position_t *pos = c->buffer->pos;
937
938   if (HB_DIRECTION_IS_HORIZONTAL (direction))
939   {
940     c->font->get_glyph_h_advances (count, &info[0].codepoint, sizeof(info[0]),
941                                    &pos[0].x_advance, sizeof(pos[0]));
942     /* The nil glyph_h_origin() func returns 0, so no need to apply it. */
943     if (c->font->has_glyph_h_origin_func ())
944       for (unsigned int i = 0; i < count; i++)
945         c->font->subtract_glyph_h_origin (info[i].codepoint,
946                                           &pos[i].x_offset,
947                                           &pos[i].y_offset);
948   }
949   else
950   {
951     c->font->get_glyph_v_advances (count, &info[0].codepoint, sizeof(info[0]),
952                                    &pos[0].y_advance, sizeof(pos[0]));
953     for (unsigned int i = 0; i < count; i++)
954     {
955       c->font->subtract_glyph_v_origin (info[i].codepoint,
956                                         &pos[i].x_offset,
957                                         &pos[i].y_offset);
958     }
959   }
960   if (c->buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_SPACE_FALLBACK)
961     _hb_ot_shape_fallback_spaces (c->plan, c->font, c->buffer);
962 }
963
964 static inline void
965 hb_ot_position_complex (const hb_ot_shape_context_t *c)
966 {
967   unsigned int count = c->buffer->len;
968   hb_glyph_info_t *info = c->buffer->info;
969   hb_glyph_position_t *pos = c->buffer->pos;
970
971   /* If the font has no GPOS and direction is forward, then when
972    * zeroing mark widths, we shift the mark with it, such that the
973    * mark is positioned hanging over the previous glyph.  When
974    * direction is backward we don't shift and it will end up
975    * hanging over the next glyph after the final reordering.
976    *
977    * Note: If fallback positinoing happens, we don't care about
978    * this as it will be overriden.
979    */
980   bool adjust_offsets_when_zeroing = c->plan->adjust_mark_positioning_when_zeroing &&
981                                      HB_DIRECTION_IS_FORWARD (c->buffer->props.direction);
982
983   /* We change glyph origin to what GPOS expects (horizontal), apply GPOS, change it back. */
984
985   /* The nil glyph_h_origin() func returns 0, so no need to apply it. */
986   if (c->font->has_glyph_h_origin_func ())
987     for (unsigned int i = 0; i < count; i++)
988       c->font->add_glyph_h_origin (info[i].codepoint,
989                                    &pos[i].x_offset,
990                                    &pos[i].y_offset);
991
992   hb_ot_layout_position_start (c->font, c->buffer);
993
994   if (c->plan->zero_marks)
995     switch (c->plan->shaper->zero_width_marks)
996     {
997       case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY:
998         zero_mark_widths_by_gdef (c->buffer, adjust_offsets_when_zeroing);
999         break;
1000
1001       default:
1002       case HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE:
1003       case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE:
1004         break;
1005     }
1006
1007   c->plan->position (c->font, c->buffer);
1008
1009   if (c->plan->zero_marks)
1010     switch (c->plan->shaper->zero_width_marks)
1011     {
1012       case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE:
1013         zero_mark_widths_by_gdef (c->buffer, adjust_offsets_when_zeroing);
1014         break;
1015
1016       default:
1017       case HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE:
1018       case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY:
1019         break;
1020     }
1021
1022   /* Finish off.  Has to follow a certain order. */
1023   hb_ot_layout_position_finish_advances (c->font, c->buffer);
1024   hb_ot_zero_width_default_ignorables (c->buffer);
1025 #ifndef HB_NO_AAT_SHAPE
1026   if (c->plan->apply_morx)
1027     hb_aat_layout_zero_width_deleted_glyphs (c->buffer);
1028 #endif
1029   hb_ot_layout_position_finish_offsets (c->font, c->buffer);
1030
1031   /* The nil glyph_h_origin() func returns 0, so no need to apply it. */
1032   if (c->font->has_glyph_h_origin_func ())
1033     for (unsigned int i = 0; i < count; i++)
1034       c->font->subtract_glyph_h_origin (info[i].codepoint,
1035                                         &pos[i].x_offset,
1036                                         &pos[i].y_offset);
1037
1038   if (c->plan->fallback_mark_positioning)
1039     _hb_ot_shape_fallback_mark_position (c->plan, c->font, c->buffer,
1040                                          adjust_offsets_when_zeroing);
1041 }
1042
1043 static inline void
1044 hb_ot_position (const hb_ot_shape_context_t *c)
1045 {
1046   c->buffer->clear_positions ();
1047
1048   hb_ot_position_default (c);
1049
1050   hb_ot_position_complex (c);
1051
1052   if (HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction))
1053     hb_buffer_reverse (c->buffer);
1054
1055   _hb_buffer_deallocate_gsubgpos_vars (c->buffer);
1056 }
1057
1058 static inline void
1059 hb_propagate_flags (hb_buffer_t *buffer)
1060 {
1061   /* Propagate cluster-level glyph flags to be the same on all cluster glyphs.
1062    * Simplifies using them. */
1063
1064   if (!(buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_UNSAFE_TO_BREAK))
1065     return;
1066
1067   hb_glyph_info_t *info = buffer->info;
1068
1069   foreach_cluster (buffer, start, end)
1070   {
1071     unsigned int mask = 0;
1072     for (unsigned int i = start; i < end; i++)
1073       if (info[i].mask & HB_GLYPH_FLAG_UNSAFE_TO_BREAK)
1074       {
1075          mask = HB_GLYPH_FLAG_UNSAFE_TO_BREAK;
1076          break;
1077       }
1078     if (mask)
1079       for (unsigned int i = start; i < end; i++)
1080         info[i].mask |= mask;
1081   }
1082 }
1083
1084 /* Pull it all together! */
1085
1086 static void
1087 hb_ot_shape_internal (hb_ot_shape_context_t *c)
1088 {
1089   c->buffer->deallocate_var_all ();
1090   c->buffer->scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT;
1091   if (likely (!hb_unsigned_mul_overflows (c->buffer->len, HB_BUFFER_MAX_LEN_FACTOR)))
1092   {
1093     c->buffer->max_len = hb_max (c->buffer->len * HB_BUFFER_MAX_LEN_FACTOR,
1094                               (unsigned) HB_BUFFER_MAX_LEN_MIN);
1095   }
1096   if (likely (!hb_unsigned_mul_overflows (c->buffer->len, HB_BUFFER_MAX_OPS_FACTOR)))
1097   {
1098     c->buffer->max_ops = hb_max (c->buffer->len * HB_BUFFER_MAX_OPS_FACTOR,
1099                               (unsigned) HB_BUFFER_MAX_OPS_MIN);
1100   }
1101
1102   /* Save the original direction, we use it later. */
1103   c->target_direction = c->buffer->props.direction;
1104
1105   _hb_buffer_allocate_unicode_vars (c->buffer);
1106
1107   c->buffer->clear_output ();
1108
1109   hb_ot_shape_initialize_masks (c);
1110   hb_set_unicode_props (c->buffer);
1111   hb_insert_dotted_circle (c->buffer, c->font);
1112
1113   hb_form_clusters (c->buffer);
1114
1115   hb_ensure_native_direction (c->buffer);
1116
1117   if (c->plan->shaper->preprocess_text)
1118     c->plan->shaper->preprocess_text (c->plan, c->buffer, c->font);
1119
1120   hb_ot_substitute_pre (c);
1121   hb_ot_position (c);
1122   hb_ot_substitute_post (c);
1123
1124   hb_propagate_flags (c->buffer);
1125
1126   _hb_buffer_deallocate_unicode_vars (c->buffer);
1127
1128   c->buffer->props.direction = c->target_direction;
1129
1130   c->buffer->max_len = HB_BUFFER_MAX_LEN_DEFAULT;
1131   c->buffer->max_ops = HB_BUFFER_MAX_OPS_DEFAULT;
1132   c->buffer->deallocate_var_all ();
1133 }
1134
1135
1136 hb_bool_t
1137 _hb_ot_shape (hb_shape_plan_t    *shape_plan,
1138               hb_font_t          *font,
1139               hb_buffer_t        *buffer,
1140               const hb_feature_t *features,
1141               unsigned int        num_features)
1142 {
1143   hb_ot_shape_context_t c = {&shape_plan->ot, font, font->face, buffer, features, num_features};
1144   hb_ot_shape_internal (&c);
1145
1146   return true;
1147 }
1148
1149
1150 /**
1151  * hb_ot_shape_plan_collect_lookups:
1152  *
1153  * Since: 0.9.7
1154  **/
1155 void
1156 hb_ot_shape_plan_collect_lookups (hb_shape_plan_t *shape_plan,
1157                                   hb_tag_t         table_tag,
1158                                   hb_set_t        *lookup_indexes /* OUT */)
1159 {
1160   shape_plan->ot.collect_lookups (table_tag, lookup_indexes);
1161 }
1162
1163
1164 /* TODO Move this to hb-ot-shape-normalize, make it do decompose, and make it public. */
1165 static void
1166 add_char (hb_font_t          *font,
1167           hb_unicode_funcs_t *unicode,
1168           hb_bool_t           mirror,
1169           hb_codepoint_t      u,
1170           hb_set_t           *glyphs)
1171 {
1172   hb_codepoint_t glyph;
1173   if (font->get_nominal_glyph (u, &glyph))
1174     glyphs->add (glyph);
1175   if (mirror)
1176   {
1177     hb_codepoint_t m = unicode->mirroring (u);
1178     if (m != u && font->get_nominal_glyph (m, &glyph))
1179       glyphs->add (glyph);
1180   }
1181 }
1182
1183
1184 /**
1185  * hb_ot_shape_glyphs_closure:
1186  *
1187  * Since: 0.9.2
1188  **/
1189 void
1190 hb_ot_shape_glyphs_closure (hb_font_t          *font,
1191                             hb_buffer_t        *buffer,
1192                             const hb_feature_t *features,
1193                             unsigned int        num_features,
1194                             hb_set_t           *glyphs)
1195 {
1196   const char *shapers[] = {"ot", nullptr};
1197   hb_shape_plan_t *shape_plan = hb_shape_plan_create_cached (font->face, &buffer->props,
1198                                                              features, num_features, shapers);
1199
1200   bool mirror = hb_script_get_horizontal_direction (buffer->props.script) == HB_DIRECTION_RTL;
1201
1202   unsigned int count = buffer->len;
1203   hb_glyph_info_t *info = buffer->info;
1204   for (unsigned int i = 0; i < count; i++)
1205     add_char (font, buffer->unicode, mirror, info[i].codepoint, glyphs);
1206
1207   hb_set_t *lookups = hb_set_create ();
1208   hb_ot_shape_plan_collect_lookups (shape_plan, HB_OT_TAG_GSUB, lookups);
1209   hb_ot_layout_lookups_substitute_closure (font->face, lookups, glyphs);
1210
1211   hb_set_destroy (lookups);
1212
1213   hb_shape_plan_destroy (shape_plan);
1214 }
1215
1216
1217 #endif