hb-ot-shape.cc revision 6bd9b479b8b2befbb0847282e93beade197c8038
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 Esfahbod
35acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod
36f6fd3780e12b23ff7ed3743497c8996e71dcb064Behdad Esfahbodhb_tag_t common_features[] = {
372014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod  HB_TAG('c','c','m','p'),
3889a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('l','o','c','l'),
3989a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('m','a','r','k'),
4089a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('m','k','m','k'),
4189a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('r','l','i','g'),
4289a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod};
4389a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod
4489a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbodhb_tag_t horizontal_features[] = {
4589a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('c','a','l','t'),
462014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod  HB_TAG('c','l','i','g'),
47bd0987386b3a4dddf208ccf1a70ebfff6242ba73Behdad Esfahbod  HB_TAG('c','u','r','s'),
482014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod  HB_TAG('k','e','r','n'),
49bd0987386b3a4dddf208ccf1a70ebfff6242ba73Behdad Esfahbod  HB_TAG('l','i','g','a'),
5089a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod};
5189a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod
5289a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod/* Note:
5389a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod * Technically speaking, vrt2 and vert are mutually exclusive.
5489a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod * According to the spec, valt and vpal are also mutually exclusive.
5589a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod * But we apply them all for now.
5689a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod */
5789a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbodhb_tag_t vertical_features[] = {
5889a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('v','a','l','t'),
5989a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('v','e','r','t'),
6089a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('v','k','r','n'),
6189a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('v','p','a','l'),
6289a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_TAG('v','r','t','2'),
632014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod};
642014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod
652014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbodstatic void
6690645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbodhb_ot_shape_collect_features (hb_ot_shape_planner_t          *planner,
6749baa1f69efb0e3c62e45bd59dd88459a84bf390Behdad Esfahbod			      const hb_segment_properties_t  *props,
6890645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod			      const hb_feature_t             *user_features,
6990645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod			      unsigned int                    num_user_features)
702014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod{
71895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod  switch (props->direction) {
720e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod    case HB_DIRECTION_LTR:
7390645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod      planner->map.add_bool_feature (HB_TAG ('l','t','r','a'));
7490645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod      planner->map.add_bool_feature (HB_TAG ('l','t','r','m'));
750e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod      break;
760e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod    case HB_DIRECTION_RTL:
7790645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod      planner->map.add_bool_feature (HB_TAG ('r','t','l','a'));
7890645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod      planner->map.add_bool_feature (HB_TAG ('r','t','l','m'), false);
790e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod      break;
800e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod    case HB_DIRECTION_TTB:
810e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod    case HB_DIRECTION_BTT:
823286fc0e9adc3f2874c9409e7fdb09e4d2b7dda1Behdad Esfahbod    case HB_DIRECTION_INVALID:
830e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod    default:
840e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod      break;
850e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod  }
860e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod
8789a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod#define ADD_FEATURES(array) \
8889a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  HB_STMT_START { \
8989a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod    for (unsigned int i = 0; i < ARRAY_LENGTH (array); i++) \
9089a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod      planner->map.add_bool_feature (array[i]); \
9189a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  } HB_STMT_END
9289a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod
9376f76812ac7cca8ac6935952a2360d5e151480faBehdad Esfahbod  hb_ot_shape_complex_collect_features (planner->shaper, &planner->map, props);
94e04685ee7be01695ec437fab50f919f1b7423c57Behdad Esfahbod
9589a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  ADD_FEATURES (common_features);
9689a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod
9789a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  if (HB_DIRECTION_IS_HORIZONTAL (props->direction))
9889a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod    ADD_FEATURES (horizontal_features);
9989a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod  else
10089a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod    ADD_FEATURES (vertical_features);
10189a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod
10289a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod#undef ADD_FEATURES
10389a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod
104895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod  for (unsigned int i = 0; i < num_user_features; i++) {
105895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod    const hb_feature_t *feature = &user_features[i];
10690645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod    planner->map.add_feature (feature->tag, feature->value, (feature->start == 0 && feature->end == (unsigned int) -1));
107e04685ee7be01695ec437fab50f919f1b7423c57Behdad Esfahbod  }
108e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbod}
109e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbod
110e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbod
111e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbodstatic void
11252601275d5e4000dada4f925fb78723eeeee7bd4Behdad Esfahbodhb_ot_shape_setup_masks (hb_ot_shape_context_t *c)
113e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbod{
114605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod  hb_mask_t global_mask = c->plan->map.get_global_mask ();
11557ac0ecb7843533b2e6e6d6c8a12b2a44437cc1cBehdad Esfahbod  c->buffer->reset_masks (global_mask);
1165b88908f12ad1d828dd6075fb8fc0036c2d6af3aBehdad Esfahbod
117acd88e659fdb2fa1cbf7171f0a1c7fbc81b9f298Behdad Esfahbod  hb_ot_shape_complex_setup_masks (c->plan->shaper, &c->plan->map, c->buffer, c->font);
1182989be4919242670c94825bded96db20a7b2035bBehdad Esfahbod
119d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod  for (unsigned int i = 0; i < c->num_user_features; i++)
120efe0d682e860ffd23a1d17c68c8273f17d51c1c9Behdad Esfahbod  {
121d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod    const hb_feature_t *feature = &c->user_features[i];
1224924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod    if (!(feature->start == 0 && feature->end == (unsigned int)-1)) {
1234924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod      unsigned int shift;
124605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod      hb_mask_t mask = c->plan->map.get_mask (feature->tag, &shift);
125bd7378b2ef9793de4e7f57b920f29f48ac9d0c25Behdad Esfahbod      c->buffer->set_masks (feature->value << shift, mask, feature->start, feature->end);
1264924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod    }
127efe0d682e860ffd23a1d17c68c8273f17d51c1c9Behdad Esfahbod  }
1282014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod}
1292014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod
1302014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod
131ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Main shaper */
132ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
133ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Prepare */
134ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
13534c22f816808d061a980cffca12de03beb437fa0Behdad Esfahbodvoid
13634c22f816808d061a980cffca12de03beb437fa0Behdad Esfahbod_hb_set_unicode_props (hb_buffer_t *buffer)
1373a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbod{
138aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbod  unsigned int count = buffer->len;
1390e3361464b00b76aa7375515163e0710a691db0cBehdad Esfahbod  for (unsigned int i = 0; i < count; i++)
14045412523dc295cb5ee12e096bfacb282cc925843Behdad Esfahbod    hb_glyph_info_set_unicode_props (&buffer->info[i], buffer->unicode);
1413a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbod}
1423a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbod
1433a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbodstatic void
144aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbodhb_form_clusters (hb_buffer_t *buffer)
145ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
146aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbod  unsigned int count = buffer->len;
147ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  for (unsigned int i = 1; i < count; i++)
148aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbod    if (FLAG (buffer->info[i].general_category()) &
1494a68684654e645882095c1189477146287ce9437Behdad Esfahbod	(FLAG (HB_UNICODE_GENERAL_CATEGORY_SPACING_MARK) |
1504a68684654e645882095c1189477146287ce9437Behdad Esfahbod	 FLAG (HB_UNICODE_GENERAL_CATEGORY_ENCLOSING_MARK) |
151d63adfc7d09b26764d9166da97372b21257e7611Behdad Esfahbod	 FLAG (HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK)))
152aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbod      buffer->info[i].cluster = buffer->info[i - 1].cluster;
153ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
154ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
155967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodstatic void
156aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbodhb_ensure_native_direction (hb_buffer_t *buffer)
157ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
158aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbod  hb_direction_t direction = buffer->props.direction;
159ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
1607403e055cd1463f38215ad9faedd61c3e1b66ac5Behdad Esfahbod  /* TODO vertical:
1617403e055cd1463f38215ad9faedd61c3e1b66ac5Behdad Esfahbod   * The only BTT vertical script is Ogham, but it's not clear to me whether OpenType
1627403e055cd1463f38215ad9faedd61c3e1b66ac5Behdad Esfahbod   * Ogham fonts are supposed to be implemented BTT or not.  Need to research that
1637403e055cd1463f38215ad9faedd61c3e1b66ac5Behdad Esfahbod   * first. */
164aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbod  if ((HB_DIRECTION_IS_HORIZONTAL (direction) && direction != hb_script_get_horizontal_direction (buffer->props.script)) ||
1657403e055cd1463f38215ad9faedd61c3e1b66ac5Behdad Esfahbod      (HB_DIRECTION_IS_VERTICAL   (direction) && direction != HB_DIRECTION_TTB))
166ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  {
167aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbod    hb_buffer_reverse_clusters (buffer);
168aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbod    buffer->props.direction = HB_DIRECTION_REVERSE (buffer->props.direction);
169ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  }
170ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
171ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
172ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
173ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Substitute */
174ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
175ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void
176aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbodhb_mirror_chars (hb_ot_shape_context_t *c)
177ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
178fb194b8794898f51eb596fa4092c26606889d376Behdad Esfahbod  hb_unicode_funcs_t *unicode = c->buffer->unicode;
179ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
180bbbbe80ec9bc45c5b685bc09c8f993e98496555cBehdad Esfahbod  if (HB_DIRECTION_IS_FORWARD (c->target_direction))
181ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod    return;
182ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
18339dede9ffffe732f78cbd092ccb3b48d77ddd66dBehdad Esfahbod  hb_mask_t rtlm_mask = c->plan->map.get_1_mask (HB_TAG ('r','t','l','m'));
1844e4ef24e46f273ad2bdda2f718223e05b37dd50fBehdad Esfahbod
185aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod  unsigned int count = c->buffer->len;
186ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  for (unsigned int i = 0; i < count; i++) {
187c4641723fbf6532b2e80a662e15573b31276bc73Behdad Esfahbod    hb_codepoint_t codepoint = hb_unicode_mirroring (unicode, c->buffer->info[i].codepoint);
188aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod    if (likely (codepoint == c->buffer->info[i].codepoint))
189bd7378b2ef9793de4e7f57b920f29f48ac9d0c25Behdad Esfahbod      c->buffer->info[i].mask |= rtlm_mask; /* XXX this should be moved to before setting user-feature masks */
1901094a294f6a44c47fc75867983f2b135a6442babBehdad Esfahbod    else
191aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod      c->buffer->info[i].codepoint = codepoint;
192ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  }
193ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
194ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
195ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void
196ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodhb_map_glyphs (hb_font_t    *font,
197ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod	       hb_buffer_t  *buffer)
198ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
1995d90a342e319068716429bf7af76c3896b61a0e5Behdad Esfahbod  hb_codepoint_t glyph;
2005d90a342e319068716429bf7af76c3896b61a0e5Behdad Esfahbod
201ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  if (unlikely (!buffer->len))
202ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod    return;
203ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
204a224b4d502d026fa642ee4098bf7bc0b4ba7ce27Behdad Esfahbod  buffer->clear_output ();
2055d90a342e319068716429bf7af76c3896b61a0e5Behdad Esfahbod
206ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  unsigned int count = buffer->len - 1;
207468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod  for (buffer->idx = 0; buffer->idx < count;) {
2086769f21d579a354e32577ec57348e97d2cb1b438Behdad Esfahbod    if (unlikely (_hb_unicode_is_variation_selector (buffer->info[buffer->idx + 1].codepoint))) {
209468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod      hb_font_get_glyph (font, buffer->info[buffer->idx].codepoint, buffer->info[buffer->idx + 1].codepoint, &glyph);
2100fd8c2f1be693616f19f2f1526369874763d6cf6Behdad Esfahbod      buffer->replace_glyph (glyph);
2119111b21ef99d5e53348176f683261b0101eb427fBehdad Esfahbod      buffer->skip_glyph ();
212ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod    } else {
213468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod      hb_font_get_glyph (font, buffer->info[buffer->idx].codepoint, 0, &glyph);
2140fd8c2f1be693616f19f2f1526369874763d6cf6Behdad Esfahbod      buffer->replace_glyph (glyph);
215ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod    }
216ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  }
217468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod  if (likely (buffer->idx < buffer->len)) {
218468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod    hb_font_get_glyph (font, buffer->info[buffer->idx].codepoint, 0, &glyph);
2190fd8c2f1be693616f19f2f1526369874763d6cf6Behdad Esfahbod    buffer->replace_glyph (glyph);
2200fd8c2f1be693616f19f2f1526369874763d6cf6Behdad Esfahbod  }
221468e9cb25c9bc14781b7013e447d763f93bf76a3Behdad Esfahbod  buffer->swap_buffers ();
222ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
223ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
224ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void
225967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_substitute_default (hb_ot_shape_context_t *c)
226ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
227b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod  hb_ot_layout_substitute_start (c->buffer);
228b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod
229b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod  hb_mirror_chars (c);
230b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod
23172657e4ce757dcb055a8db7291b68f96f0d34bfbBehdad Esfahbod  hb_map_glyphs (c->font, c->buffer);
232ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
233ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
234ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void
235c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbodhb_ot_substitute_complex (hb_ot_shape_context_t *c)
236c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod{
2372118fdb9f584e6735e904638e48bae48314372faBehdad Esfahbod  if (hb_ot_layout_has_substitution (c->face)) {
238b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod    c->plan->map.substitute (c->face, c->buffer);
2392118fdb9f584e6735e904638e48bae48314372faBehdad Esfahbod  }
240c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod
241b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod  hb_ot_layout_substitute_finish (c->buffer);
242c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod
243c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod  return;
244c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod}
245c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod
246ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
247ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Position */
248ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
249ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void
250967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_position_default (hb_ot_shape_context_t *c)
251ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
2528f0d7e0c3fd4b05c43ac449be4f374dc2dc56127Behdad Esfahbod  hb_ot_layout_position_start (c->buffer);
253ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
254967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod  unsigned int count = c->buffer->len;
255ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  for (unsigned int i = 0; i < count; i++) {
256744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod    hb_font_get_glyph_advance_for_direction (c->font, c->buffer->info[i].codepoint,
257744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod					     c->buffer->props.direction,
258744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod					     &c->buffer->pos[i].x_advance,
259744970af4d884cc87ffa645804578fec8df674a9Behdad Esfahbod					     &c->buffer->pos[i].y_advance);
2608b38faeede41e64eb0f6ac2e12ce51dd7138d50aBehdad Esfahbod    hb_font_subtract_glyph_origin_for_direction (c->font, c->buffer->info[i].codepoint,
2618b38faeede41e64eb0f6ac2e12ce51dd7138d50aBehdad Esfahbod						 c->buffer->props.direction,
2628b38faeede41e64eb0f6ac2e12ce51dd7138d50aBehdad Esfahbod						 &c->buffer->pos[i].x_offset,
2638b38faeede41e64eb0f6ac2e12ce51dd7138d50aBehdad Esfahbod						 &c->buffer->pos[i].y_offset);
264ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  }
265ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
266ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
267ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void
268c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbodhb_ot_position_complex (hb_ot_shape_context_t *c)
269c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod{
270c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod
271b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod  if (hb_ot_layout_has_positioning (c->face))
272b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod  {
273b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod    /* Change glyph origin to what GPOS expects, apply GPOS, change it back. */
274b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod
275b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod    unsigned int count = c->buffer->len;
276b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod    for (unsigned int i = 0; i < count; i++) {
277b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod      hb_font_add_glyph_origin_for_direction (c->font, c->buffer->info[i].codepoint,
278b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod					      HB_DIRECTION_LTR,
279b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod					      &c->buffer->pos[i].x_offset,
280b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod					      &c->buffer->pos[i].y_offset);
281b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod    }
282c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod
283b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod    c->plan->map.position (c->font, c->buffer);
284c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod
285b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod    for (unsigned int i = 0; i < count; i++) {
286b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod      hb_font_subtract_glyph_origin_for_direction (c->font, c->buffer->info[i].codepoint,
287b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod						   HB_DIRECTION_LTR,
288b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod						   &c->buffer->pos[i].x_offset,
289b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod						   &c->buffer->pos[i].y_offset);
290b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod    }
2912118fdb9f584e6735e904638e48bae48314372faBehdad Esfahbod
2922118fdb9f584e6735e904638e48bae48314372faBehdad Esfahbod    c->applied_position_complex = TRUE;
293c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod  }
294c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod
295c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod  hb_ot_layout_position_finish (c->buffer);
296c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod
297c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod  return;
298c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod}
299c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod
300c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbodstatic void
301967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_position_complex_fallback (hb_ot_shape_context_t *c HB_UNUSED)
302ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
303ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  /* TODO Mark pos */
304ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
305ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
306ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void
307967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_truetype_kern (hb_ot_shape_context_t *c)
308ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
309ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  /* TODO Check for kern=0 */
310967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod  unsigned int count = c->buffer->len;
311ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  for (unsigned int i = 1; i < count; i++) {
312a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod    hb_position_t x_kern, y_kern, kern1, kern2;
3137e2c85de305be59e1a6afa7d2061e4b7dd00acf7Behdad Esfahbod    hb_font_get_glyph_kerning_for_direction (c->font,
3147e2c85de305be59e1a6afa7d2061e4b7dd00acf7Behdad Esfahbod					     c->buffer->info[i - 1].codepoint, c->buffer->info[i].codepoint,
3157e2c85de305be59e1a6afa7d2061e4b7dd00acf7Behdad Esfahbod					     c->buffer->props.direction,
3167e2c85de305be59e1a6afa7d2061e4b7dd00acf7Behdad Esfahbod					     &x_kern, &y_kern);
317a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod
318a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod    kern1 = x_kern >> 1;
319a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod    kern2 = x_kern - kern1;
320967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod    c->buffer->pos[i - 1].x_advance += kern1;
321967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod    c->buffer->pos[i].x_advance += kern2;
322967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod    c->buffer->pos[i].x_offset += kern2;
323a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod
324a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod    kern1 = y_kern >> 1;
325a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod    kern2 = y_kern - kern1;
326a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod    c->buffer->pos[i - 1].y_advance += kern1;
327a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod    c->buffer->pos[i].y_advance += kern2;
328a513dbcf73ab1cc39a7c9653034904d0c6cd9fe9Behdad Esfahbod    c->buffer->pos[i].y_offset += kern2;
329ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod  }
330ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
331ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
332ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void
333967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_position_complex_fallback_visual (hb_ot_shape_context_t *c)
334ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
335967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod  hb_truetype_kern (c);
336ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
337ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
338ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
339ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Do it! */
340ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
341967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodstatic void
342fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbodhb_ot_shape_execute_internal (hb_ot_shape_context_t *c)
343ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{
344b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod  c->buffer->deallocate_var_all ();
345b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod
346d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod  /* Save the original direction, we use it later. */
347bbbbe80ec9bc45c5b685bc09c8f993e98496555cBehdad Esfahbod  c->target_direction = c->buffer->props.direction;
348d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod
349b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod  HB_BUFFER_ALLOCATE_VAR (c->buffer, general_category);
350b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod  HB_BUFFER_ALLOCATE_VAR (c->buffer, combining_class);
351b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod
352b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod  _hb_set_unicode_props (c->buffer); /* BUFFER: Set general_category and combining_class */
353fc96596b7c1c4e62491e951a3c256fb00dcde550Behdad Esfahbod
3544ff0d2d9dfc4f7e4880a4e964ca9872624508ea0Behdad Esfahbod  hb_form_clusters (c->buffer);
3554ff0d2d9dfc4f7e4880a4e964ca9872624508ea0Behdad Esfahbod
356aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbod  hb_ensure_native_direction (c->buffer);
35754d1a0d2b2c4ffe15494967122c6422ecb1fc80bBehdad Esfahbod
35811138ccff71f442da1fcf64faa0e1d22e083e775Behdad Esfahbod  _hb_ot_shape_normalize (c->font, c->buffer, hb_ot_shape_complex_normalization_preference (c->plan->shaper));
359655586fe5e1fadf2a2ef7826e61ee9a445ffa37aBehdad Esfahbod
360b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod  hb_ot_shape_setup_masks (c);
36198370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbod
3621094a294f6a44c47fc75867983f2b135a6442babBehdad Esfahbod  /* SUBSTITUTE */
363fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod  {
364967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod    hb_substitute_default (c);
365bbc7a99d01298f9be1ebaaceacbc9bc961e247e5Behdad Esfahbod
36636925f695d349a53d52ecc3a58f18240a6977463Behdad Esfahbod    hb_ot_substitute_complex (c);
367fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod  }
3681094a294f6a44c47fc75867983f2b135a6442babBehdad Esfahbod
3691094a294f6a44c47fc75867983f2b135a6442babBehdad Esfahbod  /* POSITION */
370fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod  {
371967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod    hb_position_default (c);
372ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
37336925f695d349a53d52ecc3a58f18240a6977463Behdad Esfahbod    hb_ot_position_complex (c);
374ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
375967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod    hb_bool_t position_fallback = !c->applied_position_complex;
376fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod    if (position_fallback)
377967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod      hb_position_complex_fallback (c);
378ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
379967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod    if (HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction))
380967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod      hb_buffer_reverse (c->buffer);
381ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
382fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod    if (position_fallback)
383967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod      hb_position_complex_fallback_visual (c);
384fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod  }
385ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod
386b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod  HB_BUFFER_DEALLOCATE_VAR (c->buffer, combining_class);
387b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod  HB_BUFFER_DEALLOCATE_VAR (c->buffer, general_category);
388b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod
389bbbbe80ec9bc45c5b685bc09c8f993e98496555cBehdad Esfahbod  c->buffer->props.direction = c->target_direction;
3909f9bcceca6321d5a5812f878de1de39901349a78Behdad Esfahbod
3919f9bcceca6321d5a5812f878de1de39901349a78Behdad Esfahbod  c->buffer->deallocate_var_all ();
392967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod}
393967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod
394376dafa6ed414e368e9dc1d5a2e0bfc8e55f410dBehdad Esfahbodstatic void
395605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbodhb_ot_shape_plan_internal (hb_ot_shape_plan_t       *plan,
396d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod			   hb_face_t                *face,
39749baa1f69efb0e3c62e45bd59dd88459a84bf390Behdad Esfahbod			   const hb_segment_properties_t  *props,
398d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod			   const hb_feature_t       *user_features,
399d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod			   unsigned int              num_user_features)
400d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod{
40190645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod  hb_ot_shape_planner_t planner;
40249baa1f69efb0e3c62e45bd59dd88459a84bf390Behdad Esfahbod
40390645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod  planner.shaper = hb_ot_shape_complex_categorize (props);
404d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod
40590645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod  hb_ot_shape_collect_features (&planner, props, user_features, num_user_features);
40690645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod
40790645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod  planner.compile (face, props, *plan);
408d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod}
409d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod
410376dafa6ed414e368e9dc1d5a2e0bfc8e55f410dBehdad Esfahbodstatic void
411fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbodhb_ot_shape_execute (hb_ot_shape_plan_t *plan,
412fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod		     hb_font_t          *font,
413fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod		     hb_buffer_t        *buffer,
414fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod		     const hb_feature_t *user_features,
415fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod		     unsigned int        num_user_features)
416fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod{
41772657e4ce757dcb055a8db7291b68f96f0d34bfbBehdad Esfahbod  hb_ot_shape_context_t c = {plan, font, font->face, buffer, user_features, num_user_features};
418fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod  hb_ot_shape_execute_internal (&c);
419fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod}
420fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod
42102aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbodhb_bool_t
4226bd9b479b8b2befbb0847282e93beade197c8038Behdad Esfahbod_hb_ot_shape (hb_font_t          *font,
4236bd9b479b8b2befbb0847282e93beade197c8038Behdad Esfahbod	      hb_buffer_t        *buffer,
4246bd9b479b8b2befbb0847282e93beade197c8038Behdad Esfahbod	      const hb_feature_t *features,
4256bd9b479b8b2befbb0847282e93beade197c8038Behdad Esfahbod	      unsigned int        num_features)
426967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod{
427e06d4eda7bbdb3a1be1f1ce8d98b059a0730f14dBehdad Esfahbod  hb_ot_shape_plan_t plan;
428967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod
42902aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod  buffer->guess_properties ();
43002aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod
43172657e4ce757dcb055a8db7291b68f96f0d34bfbBehdad Esfahbod  hb_ot_shape_plan_internal (&plan, font->face, &buffer->props, features, num_features);
43272657e4ce757dcb055a8db7291b68f96f0d34bfbBehdad Esfahbod  hb_ot_shape_execute (&plan, font, buffer, features, num_features);
43302aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod
43402aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod  return TRUE;
435ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod}
436