hb-ot-shape.cc revision f6fd3780e12b23ff7ed3743497c8996e71dcb064
12014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod/*
22409d5f8d7dd8b535ce5ea29e933f7db27d33793Behdad Esfahbod * Copyright © 2009,2010  Red Hat, Inc.
3359dcaa0d33271025ca42a5f54ecbac7ae3b56d3Behdad Esfahbod * Copyright © 2010,2011  Google, Inc.
42014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod *
5c755cb3e3ac55156d0d2ec05adea7a650b97cc41Behdad Esfahbod *  This is part of HarfBuzz, a text shaping library.
62014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod *
72014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod * Permission is hereby granted, without written agreement and without
82014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod * license or royalty fees, to use, copy, modify, and distribute this
92014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod * software and its documentation for any purpose, provided that the
102014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod * above copyright notice and the following two paragraphs appear in
112014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod * all copies of this software.
122014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod *
132014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
142014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
152014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
162014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
172014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod * DAMAGE.
182014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod *
192014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
202014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
212014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod * FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
222014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
232014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
242014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod *
252014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod * Red Hat Author(s): Behdad Esfahbod
26476c94218b4f5b8e119e82b0e10b641e0c10bf56Behdad Esfahbod * Google Author(s): Behdad Esfahbod
272014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod */
282014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod
294924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod#include "hb-ot-shape-private.hh"
3013403bc67a01e0d4908fb964093fd02ddd11c580Behdad Esfahbod#include "hb-ot-shape-complex-private.hh"
312014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod
3272657e4ce757dcb055a8db7291b68f96f0d34bfbBehdad Esfahbod#include "hb-font-private.hh"
3372657e4ce757dcb055a8db7291b68f96f0d34bfbBehdad Esfahbod
34acdba3f90b232fc12fcb200dca2584481b339118Behdad EsfahbodHB_BEGIN_DECLS
35acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod
36acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod
37f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbodhb_tag_t common_features[] = {
382014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod  HB_TAG('c','c','m','p'),
3989a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('l','o','c','l'),
4089a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('m','a','r','k'),
4189a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('m','k','m','k'),
4289a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('r','l','i','g'),
4389a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod};
4489a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod
4589a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbodhb_tag_t horizontal_features[] = {
4689a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('c','a','l','t'),
472014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod  HB_TAG('c','l','i','g'),
48bd0987386b3a4dddf208ccf1a70ebfff6242ba73Behdad Esfahbod  HB_TAG('c','u','r','s'),
492014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod  HB_TAG('k','e','r','n'),
50bd0987386b3a4dddf208ccf1a70ebfff6242ba73Behdad Esfahbod  HB_TAG('l','i','g','a'),
5189a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod};
5289a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod
5389a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod/* Note:
5489a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod * Technically speaking, vrt2 and vert are mutually exclusive.
5589a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod * According to the spec, valt and vpal are also mutually exclusive.
5689a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod * But we apply them all for now.
5789a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod */
5889a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbodhb_tag_t vertical_features[] = {
5989a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('v','a','l','t'),
6089a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('v','e','r','t'),
6189a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('v','k','r','n'),
6289a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('v','p','a','l'),
6389a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('v','r','t','2'),
642014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod};
652014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod
662014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbodstatic void
6790645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbodhb_ot_shape_collect_features (hb_ot_shape_planner_t          *planner,
6849baa1f69efb0e3c62e45bd59dd88459a84bf390Behdad Esfahbod			      const hb_segment_properties_t  *props,
6990645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod			      const hb_feature_t             *user_features,
7090645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod			      unsigned int                    num_user_features)
712014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod{
72895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod  switch (props->direction) {
730e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod    case HB_DIRECTION_LTR:
7490645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod      planner->map.add_bool_feature (HB_TAG ('l','t','r','a'));
7590645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod      planner->map.add_bool_feature (HB_TAG ('l','t','r','m'));
760e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod      break;
770e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod    case HB_DIRECTION_RTL:
7890645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod      planner->map.add_bool_feature (HB_TAG ('r','t','l','a'));
7990645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod      planner->map.add_bool_feature (HB_TAG ('r','t','l','m'), false);
800e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod      break;
810e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod    case HB_DIRECTION_TTB:
820e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod    case HB_DIRECTION_BTT:
833286fc0e9adc3f2874c9409e7fdb09e4d2b7dda1Behdad Esfahbod    case HB_DIRECTION_INVALID:
840e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod    default:
850e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod      break;
860e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod  }
870e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod
8889a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod#define ADD_FEATURES(array) \
8989a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_STMT_START { \
9089a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod    for (unsigned int i = 0; i < ARRAY_LENGTH (array); i++) \
9189a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod      planner->map.add_bool_feature (array[i]); \
9289a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  } HB_STMT_END
9389a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod
9476f76812ac7cca8ac6935952a2360d5e151480faBehdad Esfahbod  hb_ot_shape_complex_collect_features (planner->shaper, &planner->map, props);
95e04685ee7be01695ec437fab50f919f1b7423c57Behdad Esfahbod
9689a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  ADD_FEATURES (common_features);
9789a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod
9889a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  if (HB_DIRECTION_IS_HORIZONTAL (props->direction))
9989a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod    ADD_FEATURES (horizontal_features);
10089a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  else
10189a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod    ADD_FEATURES (vertical_features);
10289a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod
10389a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod#undef ADD_FEATURES
10489a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod
105895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod  for (unsigned int i = 0; i < num_user_features; i++) {
106895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod    const hb_feature_t *feature = &user_features[i];
10790645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod    planner->map.add_feature (feature->tag, feature->value, (feature->start == 0 && feature->end == (unsigned int) -1));
108e04685ee7be01695ec437fab50f919f1b7423c57Behdad Esfahbod  }
109e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbod}
110e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbod
111e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbod
112e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbodstatic void
11352601275d5e4000dada4f925fb78723eeeee7bd4Behdad Esfahbodhb_ot_shape_setup_masks (hb_ot_shape_context_t *c)
114e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbod{
115605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod  hb_mask_t global_mask = c->plan->map.get_global_mask ();
11657ac0ecb7843533b2e6e6d6c8a12b2a44437cc1cBehdad Esfahbod  c->buffer->reset_masks (global_mask);
1175b88908f12ad1d828dd6075fb8fc0036c2d6af3aBehdad Esfahbod
11876f76812ac7cca8ac6935952a2360d5e151480faBehdad Esfahbod  hb_ot_shape_complex_setup_masks (c->plan->shaper, &c->plan->map, c->buffer); /* BUFFER: Clobbers var2 */
1192989be4919242670c94825bded96db20a7b2035bBehdad Esfahbod
120d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod  for (unsigned int i = 0; i < c->num_user_features; i++)
121efe0d682e860ffd23a1d17c68c8273f17d51c1c9Behdad Esfahbod  {
122d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod    const hb_feature_t *feature = &c->user_features[i];
1234924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod    if (!(feature->start == 0 && feature->end == (unsigned int)-1)) {
1244924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod      unsigned int shift;
125605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod      hb_mask_t mask = c->plan->map.get_mask (feature->tag, &shift);
126bd7378b2ef9793de4e7f57b920f29f48ac9d0c25Behdad Esfahbod      c->buffer->set_masks (feature->value << shift, mask, feature->start, feature->end);
1274924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod    }
128efe0d682e860ffd23a1d17c68c8273f17d51c1c9Behdad Esfahbod  }
1292014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod}
1302014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod
1312014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod
132967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodstatic void
13336925f695d349a53d52ecc3a58f18240a6977463Behdad Esfahbodhb_ot_substitute_complex (hb_ot_shape_context_t *c)
1342014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod{
135967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod  if (!hb_ot_layout_has_substitution (c->face))
136967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod    return;
1372014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod
138605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod  c->plan->map.substitute (c->face, c->buffer);
1392014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod
140967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod  c->applied_substitute_complex = TRUE;
141967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod  return;
1422014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod}
1432014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod
144967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodstatic void
14536925f695d349a53d52ecc3a58f18240a6977463Behdad Esfahbodhb_ot_position_complex (hb_ot_shape_context_t *c)
1462014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod{
1472014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod
148967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod  if (!hb_ot_layout_has_positioning (c->face))
149967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod    return;
1502014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod
15160fbb36096e344e9af79409ce8cfe3f1f7b0d321Behdad Esfahbod  unsigned int count = c->buffer->len;
15260fbb36096e344e9af79409ce8cfe3f1f7b0d321Behdad Esfahbod  for (unsigned int i = 0; i < count; i++) {
15360fbb36096e344e9af79409ce8cfe3f1f7b0d321Behdad Esfahbod    hb_font_add_glyph_origin_for_direction (c->font, c->buffer->info[i].codepoint,
15460fbb36096e344e9af79409ce8cfe3f1f7b0d321Behdad Esfahbod					    HB_DIRECTION_LTR,
15560fbb36096e344e9af79409ce8cfe3f1f7b0d321Behdad Esfahbod					    &c->buffer->pos[i].x_offset,
15660fbb36096e344e9af79409ce8cfe3f1f7b0d321Behdad Esfahbod					    &c->buffer->pos[i].y_offset);
15760fbb36096e344e9af79409ce8cfe3f1f7b0d321Behdad Esfahbod  }
15860fbb36096e344e9af79409ce8cfe3f1f7b0d321Behdad Esfahbod
159b9452bfc1696457e156e79037c863903da5454fcBehdad Esfahbod  c->plan->map.position (c->font, c->buffer);
1602014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod
16160fbb36096e344e9af79409ce8cfe3f1f7b0d321Behdad Esfahbod  for (unsigned int i = 0; i < count; i++) {
16260fbb36096e344e9af79409ce8cfe3f1f7b0d321Behdad Esfahbod    hb_font_subtract_glyph_origin_for_direction (c->font, c->buffer->info[i].codepoint,
16360fbb36096e344e9af79409ce8cfe3f1f7b0d321Behdad Esfahbod						 HB_DIRECTION_LTR,
16460fbb36096e344e9af79409ce8cfe3f1f7b0d321Behdad Esfahbod						 &c->buffer->pos[i].x_offset,
16560fbb36096e344e9af79409ce8cfe3f1f7b0d321Behdad Esfahbod						 &c->buffer->pos[i].y_offset);
16660fbb36096e344e9af79409ce8cfe3f1f7b0d321Behdad Esfahbod  }
16760fbb36096e344e9af79409ce8cfe3f1f7b0d321Behdad Esfahbod
1681e7c1fcbc33599faefc32d4a28e5d8506d2c56faBehdad Esfahbod  hb_ot_layout_position_finish (c->buffer);
1692014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod
170967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod  c->applied_position_complex = TRUE;
171967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod  return;
1722014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod}
173ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
174ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
175ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Main shaper */
176ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
177ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Prepare */
178ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
179ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic inline hb_bool_t
180ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodis_variation_selector (hb_codepoint_t unicode)
181ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
182ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  return unlikely ((unicode >=  0x180B && unicode <=  0x180D) || /* MONGOLIAN FREE VARIATION SELECTOR ONE..THREE */
183ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod		   (unicode >=  0xFE00 && unicode <=  0xFE0F) || /* VARIATION SELECTOR-1..16 */
184ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod		   (unicode >= 0xE0100 && unicode <= 0xE01EF));  /* VARIATION SELECTOR-17..256 */
185ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
186ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
187ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void
1883a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbodhb_set_unicode_props (hb_ot_shape_context_t *c)
1893a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbod{
190fb194b8794898f51eb596fa4092c26606889d376Behdad Esfahbod  hb_unicode_funcs_t *unicode = c->buffer->unicode;
1913a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbod  hb_glyph_info_t *info = c->buffer->info;
1923a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbod
1933a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbod  unsigned int count = c->buffer->len;
1943a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbod  for (unsigned int i = 1; i < count; i++) {
195c4641723fbf6532b2e80a662e15573b31276bc73Behdad Esfahbod    info[i].general_category() = hb_unicode_general_category (unicode, info[i].codepoint);
196c4641723fbf6532b2e80a662e15573b31276bc73Behdad Esfahbod    info[i].combining_class() = hb_unicode_combining_class (unicode, info[i].codepoint);
1973a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbod  }
1983a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbod}
1993a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbod
2003a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbodstatic void
2016b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbodhb_form_clusters (hb_ot_shape_context_t *c)
202ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
2036b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod  unsigned int count = c->buffer->len;
204ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  for (unsigned int i = 1; i < count; i++)
20563b177e45c2405272da3fa6c26fe11ae37950bd0Behdad Esfahbod    /* TODO: Match other mark types too? */
20699b74760a4cddc798ab44b5ca897486bbb9c76d6Behdad Esfahbod    if (c->buffer->info[i].general_category() == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)
2076b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod      c->buffer->info[i].cluster = c->buffer->info[i - 1].cluster;
208ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
209ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
210967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodstatic void
2116b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbodhb_ensure_native_direction (hb_ot_shape_context_t *c)
212ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
2136b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod  hb_direction_t direction = c->buffer->props.direction;
214ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
2157403e055cd1463f38215ad9faedd61c3e1b66ac5Behdad Esfahbod  /* TODO vertical:
2167403e055cd1463f38215ad9faedd61c3e1b66ac5Behdad Esfahbod   * The only BTT vertical script is Ogham, but it's not clear to me whether OpenType
2177403e055cd1463f38215ad9faedd61c3e1b66ac5Behdad Esfahbod   * Ogham fonts are supposed to be implemented BTT or not.  Need to research that
2187403e055cd1463f38215ad9faedd61c3e1b66ac5Behdad Esfahbod   * first. */
2197403e055cd1463f38215ad9faedd61c3e1b66ac5Behdad Esfahbod  if ((HB_DIRECTION_IS_HORIZONTAL (direction) && direction != hb_script_get_horizontal_direction (c->buffer->props.script)) ||
2207403e055cd1463f38215ad9faedd61c3e1b66ac5Behdad Esfahbod      (HB_DIRECTION_IS_VERTICAL   (direction) && direction != HB_DIRECTION_TTB))
221ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  {
2226b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod    hb_buffer_reverse_clusters (c->buffer);
2236b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod    c->buffer->props.direction = HB_DIRECTION_REVERSE (c->buffer->props.direction);
224ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  }
225ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
226ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
22798370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbodstatic void
22898370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbodhb_reset_glyph_infos (hb_ot_shape_context_t *c)
22998370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbod{
23098370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbod  unsigned int count = c->buffer->len;
23198370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbod  for (unsigned int i = 0; i < count; i++)
23298370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbod    c->buffer->info[i].var1.u32 = c->buffer->info[i].var2.u32 = 0;
23398370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbod}
23498370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbod
235ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
236ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Substitute */
237ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
238ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void
239aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbodhb_mirror_chars (hb_ot_shape_context_t *c)
240ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
241fb194b8794898f51eb596fa4092c26606889d376Behdad Esfahbod  hb_unicode_funcs_t *unicode = c->buffer->unicode;
242ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
243bbbbe80ec9bc45c5b685bc09c8f993e98496555cBehdad Esfahbod  if (HB_DIRECTION_IS_FORWARD (c->target_direction))
244ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod    return;
245ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
24639dede9ffffe732f78cbd092ccb3b48d77ddd66dBehdad Esfahbod  hb_mask_t rtlm_mask = c->plan->map.get_1_mask (HB_TAG ('r','t','l','m'));
2474e4ef24e46f273ad2bdda2f718223e05b37dd50fBehdad Esfahbod
248aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod  unsigned int count = c->buffer->len;
249ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  for (unsigned int i = 0; i < count; i++) {
250c4641723fbf6532b2e80a662e15573b31276bc73Behdad Esfahbod    hb_codepoint_t codepoint = hb_unicode_mirroring (unicode, c->buffer->info[i].codepoint);
251aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod    if (likely (codepoint == c->buffer->info[i].codepoint))
252bd7378b2ef9793de4e7f57b920f29f48ac9d0c25Behdad Esfahbod      c->buffer->info[i].mask |= rtlm_mask; /* XXX this should be moved to before setting user-feature masks */
2531094a294f6a44c47fc75867983f2b135a6442babBehdad Esfahbod    else
254aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod      c->buffer->info[i].codepoint = codepoint;
255ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  }
256ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
257ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
258ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void
259ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodhb_map_glyphs (hb_font_t    *font,
260ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod	       hb_buffer_t  *buffer)
261ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
262ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  if (unlikely (!buffer->len))
263ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod    return;
264ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
2650fd8c2f1be693616f19f2f1526369874763d6cf6Behdad Esfahbod  hb_codepoint_t glyph;
266a224b4d502d026fa642ee4098bf7bc0b4ba7ce27Behdad Esfahbod  buffer->clear_output ();
267ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  unsigned int count = buffer->len - 1;
268a224b4d502d026fa642ee4098bf7bc0b4ba7ce27Behdad Esfahbod  for (buffer->i = 0; buffer->i < count;) {
269a224b4d502d026fa642ee4098bf7bc0b4ba7ce27Behdad Esfahbod    if (unlikely (is_variation_selector (buffer->info[buffer->i + 1].codepoint))) {
2700fd8c2f1be693616f19f2f1526369874763d6cf6Behdad Esfahbod      hb_font_get_glyph (font, buffer->info[buffer->i].codepoint, buffer->info[buffer->i + 1].codepoint, &glyph);
2710fd8c2f1be693616f19f2f1526369874763d6cf6Behdad Esfahbod      buffer->replace_glyph (glyph);
272a224b4d502d026fa642ee4098bf7bc0b4ba7ce27Behdad Esfahbod      buffer->i++;
273ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod    } else {
2740fd8c2f1be693616f19f2f1526369874763d6cf6Behdad Esfahbod      hb_font_get_glyph (font, buffer->info[buffer->i].codepoint, 0, &glyph);
2750fd8c2f1be693616f19f2f1526369874763d6cf6Behdad Esfahbod      buffer->replace_glyph (glyph);
276ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod    }
277ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  }
2780fd8c2f1be693616f19f2f1526369874763d6cf6Behdad Esfahbod  if (likely (buffer->i < buffer->len)) {
2790fd8c2f1be693616f19f2f1526369874763d6cf6Behdad Esfahbod    hb_font_get_glyph (font, buffer->info[buffer->i].codepoint, 0, &glyph);
2800fd8c2f1be693616f19f2f1526369874763d6cf6Behdad Esfahbod    buffer->replace_glyph (glyph);
2810fd8c2f1be693616f19f2f1526369874763d6cf6Behdad Esfahbod  }
282a224b4d502d026fa642ee4098bf7bc0b4ba7ce27Behdad Esfahbod  buffer->swap ();
283ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
284ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
285ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void
286967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_substitute_default (hb_ot_shape_context_t *c)
287ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
28872657e4ce757dcb055a8db7291b68f96f0d34bfbBehdad Esfahbod  hb_map_glyphs (c->font, c->buffer);
289ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
290ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
291ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void
292967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_substitute_complex_fallback (hb_ot_shape_context_t *c HB_UNUSED)
293ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
294ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  /* TODO Arabic */
295ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
296ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
297ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
298ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Position */
299ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
300ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void
301967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_position_default (hb_ot_shape_context_t *c)
302ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
3038f0d7e0c3fd4b05c43ac449be4f374dc2dc56127Behdad Esfahbod  hb_ot_layout_position_start (c->buffer);
304ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
305967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod  unsigned int count = c->buffer->len;
306ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  for (unsigned int i = 0; i < count; i++) {
307744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod    hb_font_get_glyph_advance_for_direction (c->font, c->buffer->info[i].codepoint,
308744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod					     c->buffer->props.direction,
309744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod					     &c->buffer->pos[i].x_advance,
310744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod					     &c->buffer->pos[i].y_advance);
3118b38faeede41e64eb0f6ac2e12ce51dd7138d50aBehdad Esfahbod    hb_font_subtract_glyph_origin_for_direction (c->font, c->buffer->info[i].codepoint,
3128b38faeede41e64eb0f6ac2e12ce51dd7138d50aBehdad Esfahbod						 c->buffer->props.direction,
3138b38faeede41e64eb0f6ac2e12ce51dd7138d50aBehdad Esfahbod						 &c->buffer->pos[i].x_offset,
3148b38faeede41e64eb0f6ac2e12ce51dd7138d50aBehdad Esfahbod						 &c->buffer->pos[i].y_offset);
315ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  }
316ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
317ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
318ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void
319967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_position_complex_fallback (hb_ot_shape_context_t *c HB_UNUSED)
320ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
321ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  /* TODO Mark pos */
322ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
323ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
324ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void
325967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_truetype_kern (hb_ot_shape_context_t *c)
326ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
327ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  /* TODO Check for kern=0 */
328967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod  unsigned int count = c->buffer->len;
329ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  for (unsigned int i = 1; i < count; i++) {
330a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod    hb_position_t x_kern, y_kern, kern1, kern2;
3317e2c85de305be59e1a6afa7d2061e4b7dd00acf7Behdad Esfahbod    hb_font_get_glyph_kerning_for_direction (c->font,
3327e2c85de305be59e1a6afa7d2061e4b7dd00acf7Behdad Esfahbod					     c->buffer->info[i - 1].codepoint, c->buffer->info[i].codepoint,
3337e2c85de305be59e1a6afa7d2061e4b7dd00acf7Behdad Esfahbod					     c->buffer->props.direction,
3347e2c85de305be59e1a6afa7d2061e4b7dd00acf7Behdad Esfahbod					     &x_kern, &y_kern);
335a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod
336a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod    kern1 = x_kern >> 1;
337a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod    kern2 = x_kern - kern1;
338967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod    c->buffer->pos[i - 1].x_advance += kern1;
339967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod    c->buffer->pos[i].x_advance += kern2;
340967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod    c->buffer->pos[i].x_offset += kern2;
341a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod
342a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod    kern1 = y_kern >> 1;
343a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod    kern2 = y_kern - kern1;
344a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod    c->buffer->pos[i - 1].y_advance += kern1;
345a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod    c->buffer->pos[i].y_advance += kern2;
346a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod    c->buffer->pos[i].y_offset += kern2;
347ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  }
348ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
349ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
350ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void
351967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_position_complex_fallback_visual (hb_ot_shape_context_t *c)
352ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
353967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod  hb_truetype_kern (c);
354ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
355ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
356ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
357ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Do it! */
358ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
359967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodstatic void
360fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbodhb_ot_shape_execute_internal (hb_ot_shape_context_t *c)
361ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
362d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod  /* Save the original direction, we use it later. */
363bbbbe80ec9bc45c5b685bc09c8f993e98496555cBehdad Esfahbod  c->target_direction = c->buffer->props.direction;
364d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod
3653a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbod  hb_reset_glyph_infos (c); /* BUFFER: Clear buffer var1 and var2 */
366ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
3673a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbod  hb_set_unicode_props (c); /* BUFFER: Set general_category and combining_class in var1 */
3683a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbod
369ee8aaf976a6eb42be49b63b4c51c7a0a338e0298Behdad Esfahbod  hb_ensure_native_direction (c);
370ee8aaf976a6eb42be49b63b4c51c7a0a338e0298Behdad Esfahbod
3713a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbod  hb_form_clusters (c);
372fc96596b7c1c4e62491e951a3c256fb00dcde550Behdad Esfahbod
3733a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbod  hb_ot_shape_setup_masks (c); /* BUFFER: Clobbers var2 */
37498370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbod
3751094a294f6a44c47fc75867983f2b135a6442babBehdad Esfahbod  /* SUBSTITUTE */
376fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod  {
377fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod    /* Mirroring needs to see the original direction */
378aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod    hb_mirror_chars (c);
379ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
380967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod    hb_substitute_default (c);
381bbc7a99d01298f9be1ebaaceacbc9bc961e247e5Behdad Esfahbod
38236925f695d349a53d52ecc3a58f18240a6977463Behdad Esfahbod    hb_ot_substitute_complex (c);
383ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
384967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod    if (!c->applied_substitute_complex)
385967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod      hb_substitute_complex_fallback (c);
386fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod  }
3871094a294f6a44c47fc75867983f2b135a6442babBehdad Esfahbod
3881094a294f6a44c47fc75867983f2b135a6442babBehdad Esfahbod  /* POSITION */
389fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod  {
390967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod    hb_position_default (c);
391ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
39236925f695d349a53d52ecc3a58f18240a6977463Behdad Esfahbod    hb_ot_position_complex (c);
393ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
394967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod    hb_bool_t position_fallback = !c->applied_position_complex;
395fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod    if (position_fallback)
396967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod      hb_position_complex_fallback (c);
397ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
398967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod    if (HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction))
399967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod      hb_buffer_reverse (c->buffer);
400ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
401fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod    if (position_fallback)
402967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod      hb_position_complex_fallback_visual (c);
403fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod  }
404ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
405bbbbe80ec9bc45c5b685bc09c8f993e98496555cBehdad Esfahbod  c->buffer->props.direction = c->target_direction;
406967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod}
407967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod
408376dafa6ed414e368e9dc1d5a2e0bfc8e55f410dBehdad Esfahbodstatic void
409605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbodhb_ot_shape_plan_internal (hb_ot_shape_plan_t       *plan,
410d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod			   hb_face_t                *face,
41149baa1f69efb0e3c62e45bd59dd88459a84bf390Behdad Esfahbod			   const hb_segment_properties_t  *props,
412d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod			   const hb_feature_t       *user_features,
413d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod			   unsigned int              num_user_features)
414d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod{
41590645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod  hb_ot_shape_planner_t planner;
41649baa1f69efb0e3c62e45bd59dd88459a84bf390Behdad Esfahbod
41790645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod  planner.shaper = hb_ot_shape_complex_categorize (props);
418d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod
41990645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod  hb_ot_shape_collect_features (&planner, props, user_features, num_user_features);
42090645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod
42190645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod  planner.compile (face, props, *plan);
422d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod}
423d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod
424376dafa6ed414e368e9dc1d5a2e0bfc8e55f410dBehdad Esfahbodstatic void
425fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbodhb_ot_shape_execute (hb_ot_shape_plan_t *plan,
426fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod		     hb_font_t          *font,
427fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod		     hb_buffer_t        *buffer,
428fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod		     const hb_feature_t *user_features,
429fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod		     unsigned int        num_user_features)
430fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod{
43172657e4ce757dcb055a8db7291b68f96f0d34bfbBehdad Esfahbod  hb_ot_shape_context_t c = {plan, font, font->face, buffer, user_features, num_user_features};
432fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod  hb_ot_shape_execute_internal (&c);
433fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod}
434fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod
435fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbodvoid
4365814dfa3f5aa41bc3df06b78980d57d7bea0ba58Behdad Esfahbodhb_ot_shape (hb_font_t          *font,
4375814dfa3f5aa41bc3df06b78980d57d7bea0ba58Behdad Esfahbod	     hb_buffer_t        *buffer,
4385814dfa3f5aa41bc3df06b78980d57d7bea0ba58Behdad Esfahbod	     const hb_feature_t *features,
4395814dfa3f5aa41bc3df06b78980d57d7bea0ba58Behdad Esfahbod	     unsigned int        num_features)
440967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod{
441e06d4eda7bbdb3a1be1f1ce8d98b059a0730f14dBehdad Esfahbod  hb_ot_shape_plan_t plan;
442967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod
44372657e4ce757dcb055a8db7291b68f96f0d34bfbBehdad Esfahbod  hb_ot_shape_plan_internal (&plan, font->face, &buffer->props, features, num_features);
44472657e4ce757dcb055a8db7291b68f96f0d34bfbBehdad Esfahbod  hb_ot_shape_execute (&plan, font, buffer, features, num_features);
445ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
446acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod
447acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod
448acdba3f90b232fc12fcb200dca2584481b339118Behdad EsfahbodHB_END_DECLS
449