hb-ot-shape.cc revision 038c98f6866fe1177b04bd2ae3bb461b2f0fd1ed
12014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod/* 22409d5f8d7dd8b535ce5ea29e933f7db27d33793Behdad Esfahbod * Copyright © 2009,2010 Red Hat, Inc. 307d682806349aee81f53114778ce0beb23909ed7Behdad Esfahbod * Copyright © 2010,2011,2012 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 29027857d0412477fb4427dcb8a8c45287c272e143Behdad Esfahbod#define HB_SHAPER ot 30027857d0412477fb4427dcb8a8c45287c272e143Behdad Esfahbod#define hb_ot_shaper_face_data_t hb_ot_layout_t 31e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod#define hb_ot_shaper_shape_plan_data_t hb_ot_shape_plan_t 32027857d0412477fb4427dcb8a8c45287c272e143Behdad Esfahbod#include "hb-shaper-impl-private.hh" 33027857d0412477fb4427dcb8a8c45287c272e143Behdad Esfahbod 344924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod#include "hb-ot-shape-private.hh" 3516c6a27b4bffc19026944c7bea9cf0a3a8ff1d8fBehdad Esfahbod#include "hb-ot-shape-complex-private.hh" 369c929abdcfef44c0193a2917b20981df37ade21cBehdad Esfahbod#include "hb-ot-shape-fallback-private.hh" 37affaf8a0e5aa38e5820455f789eebf916e02eb7bBehdad Esfahbod#include "hb-ot-shape-normalize-private.hh" 382014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 39b70021f7c81a0ed08475b14b07291f662cd9f905Behdad Esfahbod#include "hb-ot-layout-private.hh" 401827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod#include "hb-set-private.hh" 4172657e4ce757dcb055a8db7291b68f96f0d34bfbBehdad Esfahbod 42acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod 43a02d86484be870615297abfc7be9f94645434762Behdad Esfahbodstatic hb_tag_t common_features[] = { 442014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod HB_TAG('c','c','m','p'), 45a5f1834f57ea3fb254f5c7d372747de316fcc8f1Behdad Esfahbod HB_TAG('l','i','g','a'), 4689a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod HB_TAG('l','o','c','l'), 4789a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod HB_TAG('m','a','r','k'), 4889a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod HB_TAG('m','k','m','k'), 4989a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod HB_TAG('r','l','i','g'), 5089a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod}; 5189a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod 52d1deaa2f5bd028e8076265cba92cffa4fa2834acBehdad Esfahbod 53a02d86484be870615297abfc7be9f94645434762Behdad Esfahbodstatic hb_tag_t horizontal_features[] = { 5489a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod HB_TAG('c','a','l','t'), 552014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod HB_TAG('c','l','i','g'), 56bd0987386b3a4dddf208ccf1a70ebfff6242ba73Behdad Esfahbod HB_TAG('c','u','r','s'), 572014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod HB_TAG('k','e','r','n'), 58f4e48adcdd4315ce09e755f87a0f801d88194f42Behdad Esfahbod HB_TAG('r','c','l','t'), 5989a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod}; 6089a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod 6189a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod/* Note: 6289a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod * Technically speaking, vrt2 and vert are mutually exclusive. 6389a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod * According to the spec, valt and vpal are also mutually exclusive. 6489a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod * But we apply them all for now. 6589a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod */ 66a02d86484be870615297abfc7be9f94645434762Behdad Esfahbodstatic hb_tag_t vertical_features[] = { 6789a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod HB_TAG('v','a','l','t'), 6889a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod HB_TAG('v','e','r','t'), 6989a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod HB_TAG('v','k','r','n'), 7089a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod HB_TAG('v','p','a','l'), 7189a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod HB_TAG('v','r','t','2'), 722014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod}; 732014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 74b9f199c8e38cc5ed0d73845568630f3bcbdd4374Behdad Esfahbod 75b9f199c8e38cc5ed0d73845568630f3bcbdd4374Behdad Esfahbod 762014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbodstatic void 7790645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbodhb_ot_shape_collect_features (hb_ot_shape_planner_t *planner, 7849baa1f69efb0e3c62e45bd59dd88459a84bf390Behdad Esfahbod const hb_segment_properties_t *props, 7990645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod const hb_feature_t *user_features, 8090645fb24bcbb78183576d3641a99560d87e49f2Behdad Esfahbod unsigned int num_user_features) 812014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod{ 828bb5deba9630d35878eb6edb4643ecfabf99f15fBehdad Esfahbod hb_ot_map_builder_t *map = &planner->map; 838bb5deba9630d35878eb6edb4643ecfabf99f15fBehdad Esfahbod 84895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod switch (props->direction) { 850e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod case HB_DIRECTION_LTR: 86e7ffcfafb1108801ac504f18f820e497226bf07fBehdad Esfahbod map->add_global_bool_feature (HB_TAG ('l','t','r','a')); 87e7ffcfafb1108801ac504f18f820e497226bf07fBehdad Esfahbod map->add_global_bool_feature (HB_TAG ('l','t','r','m')); 880e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod break; 890e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod case HB_DIRECTION_RTL: 90e7ffcfafb1108801ac504f18f820e497226bf07fBehdad Esfahbod map->add_global_bool_feature (HB_TAG ('r','t','l','a')); 91ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod map->add_feature (HB_TAG ('r','t','l','m'), 1, F_NONE); 920e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod break; 930e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod case HB_DIRECTION_TTB: 940e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod case HB_DIRECTION_BTT: 953286fc0e9adc3f2874c9409e7fdb09e4d2b7dda1Behdad Esfahbod case HB_DIRECTION_INVALID: 960e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod default: 970e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod break; 980e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod } 990e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod 100693918ef8541014a5ef7dfb91c6ea0ae36d9c368Behdad Esfahbod if (planner->shaper->collect_features) 10116c6a27b4bffc19026944c7bea9cf0a3a8ff1d8fBehdad Esfahbod planner->shaper->collect_features (planner); 102e04685ee7be01695ec437fab50f919f1b7423c57Behdad Esfahbod 103ee9c3a17d0bf263c5eee479fd778db97cff8e189Behdad Esfahbod for (unsigned int i = 0; i < ARRAY_LENGTH (common_features); i++) 104ee9c3a17d0bf263c5eee479fd778db97cff8e189Behdad Esfahbod map->add_global_bool_feature (common_features[i]); 10589a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod 10689a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod if (HB_DIRECTION_IS_HORIZONTAL (props->direction)) 107ee9c3a17d0bf263c5eee479fd778db97cff8e189Behdad Esfahbod for (unsigned int i = 0; i < ARRAY_LENGTH (horizontal_features); i++) 108038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod map->add_feature (horizontal_features[i], 1, F_GLOBAL | 109038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod (horizontal_features[i] == HB_TAG('k','e','r','n') ? 110038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod F_HAS_FALLBACK : F_NONE)); 11189a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod else 112ee9c3a17d0bf263c5eee479fd778db97cff8e189Behdad Esfahbod for (unsigned int i = 0; i < ARRAY_LENGTH (vertical_features); i++) 113038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod map->add_feature (vertical_features[i], 1, F_GLOBAL | 114038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod (vertical_features[i] == HB_TAG('v','k','r','n') ? 115038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod F_HAS_FALLBACK : F_NONE)); 11689a2bc9ba674e7e57fec1fd8ce7648a44f3aab63Behdad Esfahbod 117693918ef8541014a5ef7dfb91c6ea0ae36d9c368Behdad Esfahbod if (planner->shaper->override_features) 11816c6a27b4bffc19026944c7bea9cf0a3a8ff1d8fBehdad Esfahbod planner->shaper->override_features (planner); 119d96838ef951ce6170eb2dc576ebcba2262cf7008Behdad Esfahbod 120895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod for (unsigned int i = 0; i < num_user_features; i++) { 121895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod const hb_feature_t *feature = &user_features[i]; 122ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod map->add_feature (feature->tag, feature->value, 123ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod (feature->start == 0 && feature->end == (unsigned int) -1) ? 124ec5448667b30ad662401c2b4f5fc0da524c013fdBehdad Esfahbod F_GLOBAL : F_NONE); 125e04685ee7be01695ec437fab50f919f1b7423c57Behdad Esfahbod } 126e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbod} 127e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbod 128e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbod 129e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod/* 130e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod * shaper face data 131e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod */ 132e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 133e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbodhb_ot_shaper_face_data_t * 134e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod_hb_ot_shaper_face_data_create (hb_face_t *face) 135e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod{ 136e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod return _hb_ot_layout_create (face); 137e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod} 138e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 139e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbodvoid 140e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod_hb_ot_shaper_face_data_destroy (hb_ot_shaper_face_data_t *data) 141e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod{ 142e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod _hb_ot_layout_destroy (data); 143e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod} 144e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 145e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 146e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod/* 147e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod * shaper font data 148e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod */ 149e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 150e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbodstruct hb_ot_shaper_font_data_t {}; 151e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 152e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbodhb_ot_shaper_font_data_t * 153e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod_hb_ot_shaper_font_data_create (hb_font_t *font) 154e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod{ 155e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod return (hb_ot_shaper_font_data_t *) HB_SHAPER_DATA_SUCCEEDED; 156e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod} 157e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 158e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbodvoid 159e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod_hb_ot_shaper_font_data_destroy (hb_ot_shaper_font_data_t *data) 160e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod{ 161e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod} 162e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 163e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 164e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod/* 165e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod * shaper shape_plan data 166e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod */ 167e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 168e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbodhb_ot_shaper_shape_plan_data_t * 169e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod_hb_ot_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan, 170e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod const hb_feature_t *user_features, 171e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod unsigned int num_user_features) 172e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod{ 173a8c6da90f4c6e8d27a3a1b758a55476776d9f750Behdad Esfahbod hb_ot_shape_plan_t *plan = (hb_ot_shape_plan_t *) calloc (1, sizeof (hb_ot_shape_plan_t)); 174a8c6da90f4c6e8d27a3a1b758a55476776d9f750Behdad Esfahbod if (unlikely (!plan)) 175e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod return NULL; 176e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 1775393e3a62ba09fd7bcf3767b36225c8f49badb9dBehdad Esfahbod hb_ot_shape_planner_t planner (shape_plan); 178e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 1799b37b4c5800b158f61602d2aba8a01349e24d251Behdad Esfahbod planner.shaper = hb_ot_shape_complex_categorize (&planner); 180e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 181e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod hb_ot_shape_collect_features (&planner, &shape_plan->props, user_features, num_user_features); 182e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 183a8c6da90f4c6e8d27a3a1b758a55476776d9f750Behdad Esfahbod planner.compile (*plan); 184e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 185a8c6da90f4c6e8d27a3a1b758a55476776d9f750Behdad Esfahbod if (plan->shaper->data_create) { 186a8c6da90f4c6e8d27a3a1b758a55476776d9f750Behdad Esfahbod plan->data = plan->shaper->data_create (plan); 187a8c6da90f4c6e8d27a3a1b758a55476776d9f750Behdad Esfahbod if (unlikely (!plan->data)) 188a8c6da90f4c6e8d27a3a1b758a55476776d9f750Behdad Esfahbod return NULL; 189a8c6da90f4c6e8d27a3a1b758a55476776d9f750Behdad Esfahbod } 190a8c6da90f4c6e8d27a3a1b758a55476776d9f750Behdad Esfahbod 191a8c6da90f4c6e8d27a3a1b758a55476776d9f750Behdad Esfahbod return plan; 192e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod} 193e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 194e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbodvoid 195a8c6da90f4c6e8d27a3a1b758a55476776d9f750Behdad Esfahbod_hb_ot_shaper_shape_plan_data_destroy (hb_ot_shaper_shape_plan_data_t *plan) 196e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod{ 197a8c6da90f4c6e8d27a3a1b758a55476776d9f750Behdad Esfahbod if (plan->shaper->data_destroy) 198a8c6da90f4c6e8d27a3a1b758a55476776d9f750Behdad Esfahbod plan->shaper->data_destroy (const_cast<void *> (plan->data)); 199a8c6da90f4c6e8d27a3a1b758a55476776d9f750Behdad Esfahbod 200a8c6da90f4c6e8d27a3a1b758a55476776d9f750Behdad Esfahbod plan->finish (); 2014ba647eecf0f70917ac4229af1f2dd3c62fcb7d5Behdad Esfahbod 202a8c6da90f4c6e8d27a3a1b758a55476776d9f750Behdad Esfahbod free (plan); 203e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod} 204e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 205e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 206e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod/* 207e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod * shaper 208e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod */ 209e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 210b9f199c8e38cc5ed0d73845568630f3bcbdd4374Behdad Esfahbodstruct hb_ot_shape_context_t 211b9f199c8e38cc5ed0d73845568630f3bcbdd4374Behdad Esfahbod{ 212b9f199c8e38cc5ed0d73845568630f3bcbdd4374Behdad Esfahbod hb_ot_shape_plan_t *plan; 213b9f199c8e38cc5ed0d73845568630f3bcbdd4374Behdad Esfahbod hb_font_t *font; 214b9f199c8e38cc5ed0d73845568630f3bcbdd4374Behdad Esfahbod hb_face_t *face; 215b9f199c8e38cc5ed0d73845568630f3bcbdd4374Behdad Esfahbod hb_buffer_t *buffer; 216b9f199c8e38cc5ed0d73845568630f3bcbdd4374Behdad Esfahbod const hb_feature_t *user_features; 217b9f199c8e38cc5ed0d73845568630f3bcbdd4374Behdad Esfahbod unsigned int num_user_features; 218b9f199c8e38cc5ed0d73845568630f3bcbdd4374Behdad Esfahbod 219b9f199c8e38cc5ed0d73845568630f3bcbdd4374Behdad Esfahbod /* Transient stuff */ 220b9f199c8e38cc5ed0d73845568630f3bcbdd4374Behdad Esfahbod hb_direction_t target_direction; 221b9f199c8e38cc5ed0d73845568630f3bcbdd4374Behdad Esfahbod}; 222b9f199c8e38cc5ed0d73845568630f3bcbdd4374Behdad Esfahbod 2232014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 2242014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 225ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Main shaper */ 226ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 2275c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod 228ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Prepare */ 229ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 230b9f199c8e38cc5ed0d73845568630f3bcbdd4374Behdad Esfahbodstatic void 231b9f199c8e38cc5ed0d73845568630f3bcbdd4374Behdad Esfahbodhb_set_unicode_props (hb_buffer_t *buffer) 2323a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbod{ 233aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbod unsigned int count = buffer->len; 2340e3361464b00b76aa7375515163e0710a691db0cBehdad Esfahbod for (unsigned int i = 0; i < count; i++) 235d1deaa2f5bd028e8076265cba92cffa4fa2834acBehdad Esfahbod _hb_glyph_info_set_unicode_props (&buffer->info[i], buffer->unicode); 2363a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbod} 2373a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbod 2383a852ae7fe6edfaadd75625d27515a3689503395Behdad Esfahbodstatic void 2396912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbodhb_insert_dotted_circle (hb_buffer_t *buffer, hb_font_t *font) 2406912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod{ 2410c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbod if (!(buffer->flags & HB_BUFFER_FLAG_BOT) || 242f2eb3fa9dca8d21fae20c9b9dddad3245df74a05Behdad Esfahbod _hb_glyph_info_get_general_category (&buffer->info[0]) != 2436912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) 2446912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod return; 2456912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod 2466912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod hb_codepoint_t dottedcircle_glyph; 2476912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod if (!font->get_glyph (0x25CC, 0, &dottedcircle_glyph)) 2486912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod return; 2496912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod 2506912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod hb_glyph_info_t dottedcircle; 2516912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod dottedcircle.codepoint = 0x25CC; 2526912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod _hb_glyph_info_set_unicode_props (&dottedcircle, buffer->unicode); 2536912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod 2546912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod buffer->clear_output (); 2556912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod 2566912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod buffer->idx = 0; 2576912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod hb_glyph_info_t info = dottedcircle; 2586912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod info.cluster = buffer->cur().cluster; 2596912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod info.mask = buffer->cur().mask; 2606912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod buffer->output_info (info); 2616912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod while (buffer->idx < buffer->len) 2626912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod buffer->next_glyph (); 2636912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod 2646912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod buffer->swap_buffers (); 2656912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod} 2666912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod 2676912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbodstatic void 268aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbodhb_form_clusters (hb_buffer_t *buffer) 269ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 270aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbod unsigned int count = buffer->len; 271ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod for (unsigned int i = 1; i < count; i++) 272028a1706f898bfcee0d14acfba47ebe1de09f0c4Behdad Esfahbod if (HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&buffer->info[i]))) 273330a2af3ff0e12c01b3b451357b8bdc83b2e9b47Behdad Esfahbod buffer->merge_clusters (i - 1, i + 1); 274ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 275ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 276967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodstatic void 277aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbodhb_ensure_native_direction (hb_buffer_t *buffer) 278ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 279aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbod hb_direction_t direction = buffer->props.direction; 280ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 2817403e055cd1463f38215ad9faedd61c3e1b66ac5Behdad Esfahbod /* TODO vertical: 2827403e055cd1463f38215ad9faedd61c3e1b66ac5Behdad Esfahbod * The only BTT vertical script is Ogham, but it's not clear to me whether OpenType 2837403e055cd1463f38215ad9faedd61c3e1b66ac5Behdad Esfahbod * Ogham fonts are supposed to be implemented BTT or not. Need to research that 2847403e055cd1463f38215ad9faedd61c3e1b66ac5Behdad Esfahbod * first. */ 285aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbod if ((HB_DIRECTION_IS_HORIZONTAL (direction) && direction != hb_script_get_horizontal_direction (buffer->props.script)) || 2867403e055cd1463f38215ad9faedd61c3e1b66ac5Behdad Esfahbod (HB_DIRECTION_IS_VERTICAL (direction) && direction != HB_DIRECTION_TTB)) 287ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod { 288aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbod hb_buffer_reverse_clusters (buffer); 289aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbod buffer->props.direction = HB_DIRECTION_REVERSE (buffer->props.direction); 290ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod } 291ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 292ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 293ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 294ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Substitute */ 295ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 2965c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbodstatic inline void 2975c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbodhb_ot_mirror_chars (hb_ot_shape_context_t *c) 298ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 299bbbbe80ec9bc45c5b685bc09c8f993e98496555cBehdad Esfahbod if (HB_DIRECTION_IS_FORWARD (c->target_direction)) 300ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod return; 301ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 3025c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod hb_unicode_funcs_t *unicode = c->buffer->unicode; 30339dede9ffffe732f78cbd092ccb3b48d77ddd66dBehdad Esfahbod hb_mask_t rtlm_mask = c->plan->map.get_1_mask (HB_TAG ('r','t','l','m')); 3044e4ef24e46f273ad2bdda2f718223e05b37dd50fBehdad Esfahbod 305aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod unsigned int count = c->buffer->len; 306ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod for (unsigned int i = 0; i < count; i++) { 307208f70f0553d73d2908b21b9552298029482a8b9Behdad Esfahbod hb_codepoint_t codepoint = unicode->mirroring (c->buffer->info[i].codepoint); 308aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod if (likely (codepoint == c->buffer->info[i].codepoint)) 30912c0875eafa4bd92db650e5acca046d99594d1e6Behdad Esfahbod c->buffer->info[i].mask |= rtlm_mask; 3101094a294f6a44c47fc75867983f2b135a6442babBehdad Esfahbod else 311aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod c->buffer->info[i].codepoint = codepoint; 312ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod } 313ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 314ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 3155c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbodstatic inline void 3165c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbodhb_ot_shape_setup_masks (hb_ot_shape_context_t *c) 3175c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod{ 3185c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod hb_ot_map_t *map = &c->plan->map; 3195c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod 3205c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod hb_mask_t global_mask = map->get_global_mask (); 3215c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod c->buffer->reset_masks (global_mask); 3225c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod 3235c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod if (c->plan->shaper->setup_masks) 3245c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod c->plan->shaper->setup_masks (c->plan, c->buffer, c->font); 3255c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod 3265c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod for (unsigned int i = 0; i < c->num_user_features; i++) 3275c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod { 3285c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod const hb_feature_t *feature = &c->user_features[i]; 3295c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod if (!(feature->start == 0 && feature->end == (unsigned int)-1)) { 3305c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod unsigned int shift; 3315c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod hb_mask_t mask = map->get_mask (feature->tag, &shift); 3325c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod c->buffer->set_masks (feature->value << shift, mask, feature->start, feature->end); 3335c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod } 3345c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod } 3355c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod} 3365c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod 3375c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbodstatic inline void 338b00321ea78793d9b3592b5173a9800e6322424feBehdad Esfahbodhb_ot_map_glyphs_fast (hb_buffer_t *buffer) 339ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 340b00321ea78793d9b3592b5173a9800e6322424feBehdad Esfahbod /* Normalization process sets up glyph_index(), we just copy it. */ 341b00321ea78793d9b3592b5173a9800e6322424feBehdad Esfahbod unsigned int count = buffer->len; 342b00321ea78793d9b3592b5173a9800e6322424feBehdad Esfahbod for (unsigned int i = 0; i < count; i++) 343b00321ea78793d9b3592b5173a9800e6322424feBehdad Esfahbod buffer->info[i].codepoint = buffer->info[i].glyph_index(); 344ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 345ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 3465c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbodstatic inline void 3470ccf9b64736559a230425fd131c9eb8aa3048221Behdad Esfahbodhb_synthesize_glyph_classes (hb_ot_shape_context_t *c) 3480ccf9b64736559a230425fd131c9eb8aa3048221Behdad Esfahbod{ 3490ccf9b64736559a230425fd131c9eb8aa3048221Behdad Esfahbod unsigned int count = c->buffer->len; 3500ccf9b64736559a230425fd131c9eb8aa3048221Behdad Esfahbod for (unsigned int i = 0; i < count; i++) 3510ccf9b64736559a230425fd131c9eb8aa3048221Behdad Esfahbod c->buffer->info[i].glyph_props() = _hb_glyph_info_get_general_category (&c->buffer->info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK ? 3525a08ecf9200a6ac9b4ebb7ec5c13dcb42d8820ceBehdad Esfahbod HB_OT_LAYOUT_GLYPH_PROPS_MARK : 3535a08ecf9200a6ac9b4ebb7ec5c13dcb42d8820ceBehdad Esfahbod HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH; 3540ccf9b64736559a230425fd131c9eb8aa3048221Behdad Esfahbod} 3550ccf9b64736559a230425fd131c9eb8aa3048221Behdad Esfahbod 3560ccf9b64736559a230425fd131c9eb8aa3048221Behdad Esfahbodstatic inline void 3575c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbodhb_ot_substitute_default (hb_ot_shape_context_t *c) 358ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 359fabd3113a98c5f4114f48920fa7ea38bd65a8d32Behdad Esfahbod if (c->plan->shaper->preprocess_text) 3609f9f04c2229227bb0712166e824157bbbf5cef80Behdad Esfahbod c->plan->shaper->preprocess_text (c->plan, c->buffer, c->font); 3619f9f04c2229227bb0712166e824157bbbf5cef80Behdad Esfahbod 3625c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod hb_ot_mirror_chars (c); 3635c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod 364b00321ea78793d9b3592b5173a9800e6322424feBehdad Esfahbod HB_BUFFER_ALLOCATE_VAR (c->buffer, glyph_index); 365b00321ea78793d9b3592b5173a9800e6322424feBehdad Esfahbod 366eba312c8d1b2bbe8cb9b6414e843e78d2c521aa4Behdad Esfahbod _hb_ot_shape_normalize (c->plan, c->buffer, c->font); 3675c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod 3685c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod hb_ot_shape_setup_masks (c); 369b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod 3703992b5ec4cb43d114d87ff7ee2b992bcf819c9cdBehdad Esfahbod /* This is unfortunate to go here, but necessary... */ 3713992b5ec4cb43d114d87ff7ee2b992bcf819c9cdBehdad Esfahbod if (!hb_ot_layout_has_positioning (c->face)) 3723992b5ec4cb43d114d87ff7ee2b992bcf819c9cdBehdad Esfahbod _hb_ot_shape_fallback_position_recategorize_marks (c->plan, c->font, c->buffer); 3733992b5ec4cb43d114d87ff7ee2b992bcf819c9cdBehdad Esfahbod 374b00321ea78793d9b3592b5173a9800e6322424feBehdad Esfahbod hb_ot_map_glyphs_fast (c->buffer); 375b00321ea78793d9b3592b5173a9800e6322424feBehdad Esfahbod 376b00321ea78793d9b3592b5173a9800e6322424feBehdad Esfahbod HB_BUFFER_DEALLOCATE_VAR (c->buffer, glyph_index); 377ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 378ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 3795c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbodstatic inline void 380c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbodhb_ot_substitute_complex (hb_ot_shape_context_t *c) 381c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod{ 382afbcc24be01a64bdb5c05c63880269145fa1d3c8Behdad Esfahbod hb_ot_layout_substitute_start (c->font, c->buffer); 38305bd1b63426e07d1df7a1b40bf845dc94ab995a8Behdad Esfahbod 3845fecd8b0355894ceda14b3d3c654f20c3d5e77f4Behdad Esfahbod if (!hb_ot_layout_has_glyph_classes (c->face)) 3855fecd8b0355894ceda14b3d3c654f20c3d5e77f4Behdad Esfahbod hb_synthesize_glyph_classes (c); 3865fecd8b0355894ceda14b3d3c654f20c3d5e77f4Behdad Esfahbod 387fabd3113a98c5f4114f48920fa7ea38bd65a8d32Behdad Esfahbod c->plan->substitute (c->font, c->buffer); 388c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod 389afbcc24be01a64bdb5c05c63880269145fa1d3c8Behdad Esfahbod hb_ot_layout_substitute_finish (c->font, c->buffer); 390c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod 391c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod return; 392c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod} 393c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod 3945c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbodstatic inline void 3955c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbodhb_ot_substitute (hb_ot_shape_context_t *c) 3965c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod{ 3975c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod hb_ot_substitute_default (c); 3985c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod hb_ot_substitute_complex (c); 3995c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod} 400ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 401ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Position */ 402ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 4035c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbodstatic inline void 4045c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbodhb_ot_position_default (hb_ot_shape_context_t *c) 405ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 40605bd1b63426e07d1df7a1b40bf845dc94ab995a8Behdad Esfahbod hb_ot_layout_position_start (c->font, c->buffer); 407ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 408967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod unsigned int count = c->buffer->len; 409568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod for (unsigned int i = 0; i < count; i++) 410568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod { 4118fbfda920e0b3bb4ab7afb732826026964b79be9Behdad Esfahbod c->font->get_glyph_advance_for_direction (c->buffer->info[i].codepoint, 4128fbfda920e0b3bb4ab7afb732826026964b79be9Behdad Esfahbod c->buffer->props.direction, 4138fbfda920e0b3bb4ab7afb732826026964b79be9Behdad Esfahbod &c->buffer->pos[i].x_advance, 4148fbfda920e0b3bb4ab7afb732826026964b79be9Behdad Esfahbod &c->buffer->pos[i].y_advance); 4158fbfda920e0b3bb4ab7afb732826026964b79be9Behdad Esfahbod c->font->subtract_glyph_origin_for_direction (c->buffer->info[i].codepoint, 4168fbfda920e0b3bb4ab7afb732826026964b79be9Behdad Esfahbod c->buffer->props.direction, 4178fbfda920e0b3bb4ab7afb732826026964b79be9Behdad Esfahbod &c->buffer->pos[i].x_offset, 4188fbfda920e0b3bb4ab7afb732826026964b79be9Behdad Esfahbod &c->buffer->pos[i].y_offset); 419568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod 420568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod } 421568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod 4220291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod /* Zero'ing mark widths by GDEF (as used in Myanmar spec) happens 4230291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod * *before* GPOS. */ 424568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod switch (c->plan->shaper->zero_width_marks) 425568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod { 426568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF: 427568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod for (unsigned int i = 0; i < count; i++) 428568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod if ((c->buffer->info[i].glyph_props() & HB_OT_LAYOUT_GLYPH_PROPS_MARK)) 429568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod { 430568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod c->buffer->pos[i].x_advance = 0; 431568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod c->buffer->pos[i].y_advance = 0; 432568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod } 433568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod break; 434568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod 435568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod default: 436568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod case HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE: 4370291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE: 438568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod break; 439ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod } 440ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 441ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 4425c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbodstatic inline bool 443c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbodhb_ot_position_complex (hb_ot_shape_context_t *c) 444c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod{ 4455c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod bool ret = false; 4460291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod unsigned int count = c->buffer->len; 447c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod 448b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod if (hb_ot_layout_has_positioning (c->face)) 449b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod { 450b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod /* Change glyph origin to what GPOS expects, apply GPOS, change it back. */ 451b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod 452b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod for (unsigned int i = 0; i < count; i++) { 4538fbfda920e0b3bb4ab7afb732826026964b79be9Behdad Esfahbod c->font->add_glyph_origin_for_direction (c->buffer->info[i].codepoint, 4548fbfda920e0b3bb4ab7afb732826026964b79be9Behdad Esfahbod HB_DIRECTION_LTR, 4558fbfda920e0b3bb4ab7afb732826026964b79be9Behdad Esfahbod &c->buffer->pos[i].x_offset, 4568fbfda920e0b3bb4ab7afb732826026964b79be9Behdad Esfahbod &c->buffer->pos[i].y_offset); 457b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod } 458c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod 4598bb5deba9630d35878eb6edb4643ecfabf99f15fBehdad Esfahbod c->plan->position (c->font, c->buffer); 460c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod 461b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod for (unsigned int i = 0; i < count; i++) { 4628fbfda920e0b3bb4ab7afb732826026964b79be9Behdad Esfahbod c->font->subtract_glyph_origin_for_direction (c->buffer->info[i].codepoint, 4638fbfda920e0b3bb4ab7afb732826026964b79be9Behdad Esfahbod HB_DIRECTION_LTR, 4648fbfda920e0b3bb4ab7afb732826026964b79be9Behdad Esfahbod &c->buffer->pos[i].x_offset, 4658fbfda920e0b3bb4ab7afb732826026964b79be9Behdad Esfahbod &c->buffer->pos[i].y_offset); 466b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod } 4672118fdb9f584e6735e904638e48bae48314372faBehdad Esfahbod 4685c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod ret = true; 469affaf8a0e5aa38e5820455f789eebf916e02eb7bBehdad Esfahbod } 4702bc3b9a616cedbc56ff4a915f9e3439ff3a6bf13Behdad Esfahbod 4710291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod /* Zero'ing mark widths by Unicode happens 4720291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod * *after* GPOS. */ 4730291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod switch (c->plan->shaper->zero_width_marks) 4740291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod { 4750291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE: 4760291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod for (unsigned int i = 0; i < count; i++) 4770291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod if (_hb_glyph_info_get_general_category (&c->buffer->info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) 4780291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod { 4790291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod c->buffer->pos[i].x_advance = 0; 4800291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod c->buffer->pos[i].y_advance = 0; 4810291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod } 4820291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod break; 4830291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod 4840291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod default: 4850291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod case HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE: 4860291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF: 4870291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod break; 4880291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod } 4890291a6528685f1f593707655943fb2360579cb9eBehdad Esfahbod 490568000274c8edb5f41bc4f876ce21fcc8bdaeed8Behdad Esfahbod hb_ot_layout_position_finish (c->font, c->buffer); 491c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod 4925c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod return ret; 493c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod} 494c86f932015bdf5803572b0904d343d3bc033e009Behdad Esfahbod 4955c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbodstatic inline void 4965c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbodhb_ot_truetype_kern (hb_ot_shape_context_t *c) 497ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 498967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod unsigned int count = c->buffer->len; 499038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod hb_mask_t kern_mask = c->plan->map.get_1_mask (HB_DIRECTION_IS_HORIZONTAL (c->buffer->props.direction) ? 500038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod HB_TAG ('k','e','r','n') : HB_TAG ('v','k','r','n')); 501038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod 502038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod if (unlikely (!count)) return; 503038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod 504038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod bool enabled = c->buffer->info[0].mask & kern_mask; 505038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod for (unsigned int i = 1; i < count; i++) 506038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod { 507038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod bool next = c->buffer->info[i].mask & kern_mask; 508038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod if (enabled && next) 509038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod { 510038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod hb_position_t x_kern, y_kern, kern1, kern2; 511038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod c->font->get_glyph_kerning_for_direction (c->buffer->info[i - 1].codepoint, c->buffer->info[i].codepoint, 512038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod c->buffer->props.direction, 513038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod &x_kern, &y_kern); 514038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod 515038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod kern1 = x_kern >> 1; 516038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod kern2 = x_kern - kern1; 517038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod c->buffer->pos[i - 1].x_advance += kern1; 518038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod c->buffer->pos[i].x_advance += kern2; 519038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod c->buffer->pos[i].x_offset += kern2; 520038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod 521038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod kern1 = y_kern >> 1; 522038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod kern2 = y_kern - kern1; 523038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod c->buffer->pos[i - 1].y_advance += kern1; 524038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod c->buffer->pos[i].y_advance += kern2; 525038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod c->buffer->pos[i].y_offset += kern2; 526038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod } 527038c98f6866fe1177b04bd2ae3bb461b2f0fd1edBehdad Esfahbod enabled = next; 528ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod } 529ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 530ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 5315c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbodstatic inline void 5325c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbodhb_ot_position (hb_ot_shape_context_t *c) 5335c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod{ 5345c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod hb_ot_position_default (c); 5355c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod 5365c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod hb_bool_t fallback = !hb_ot_position_complex (c); 5375c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod 538865745b5b87236651f5663cae3461db9cb505eedBehdad Esfahbod if (fallback && c->plan->shaper->fallback_position) 539865745b5b87236651f5663cae3461db9cb505eedBehdad Esfahbod _hb_ot_shape_fallback_position (c->plan, c->font, c->buffer); 5405c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod 5415c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod if (HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction)) 5425c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod hb_buffer_reverse (c->buffer); 5435c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod 544865745b5b87236651f5663cae3461db9cb505eedBehdad Esfahbod /* Visual fallback goes here. */ 545865745b5b87236651f5663cae3461db9cb505eedBehdad Esfahbod 5465c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod if (fallback) 547865745b5b87236651f5663cae3461db9cb505eedBehdad Esfahbod hb_ot_truetype_kern (c); 548ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 549ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 5505c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod 5515c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod/* Post-process */ 5525c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod 553d1deaa2f5bd028e8076265cba92cffa4fa2834acBehdad Esfahbodstatic void 5540c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbodhb_ot_hide_default_ignorables (hb_ot_shape_context_t *c) 555d1deaa2f5bd028e8076265cba92cffa4fa2834acBehdad Esfahbod{ 5560c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbod if (c->buffer->flags & HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES) 5570c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbod return; 5580c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbod 559784f29d061a2939562eca0c4943feb01174aee00Behdad Esfahbod hb_codepoint_t space = 0; 560d1deaa2f5bd028e8076265cba92cffa4fa2834acBehdad Esfahbod 561d1deaa2f5bd028e8076265cba92cffa4fa2834acBehdad Esfahbod unsigned int count = c->buffer->len; 562d1deaa2f5bd028e8076265cba92cffa4fa2834acBehdad Esfahbod for (unsigned int i = 0; i < count; i++) 563b70021f7c81a0ed08475b14b07291f662cd9f905Behdad Esfahbod if (unlikely (!is_a_ligature (c->buffer->info[i]) && 564cf3afd8979b1db76d437f428cbd51cb363e0d18eBehdad Esfahbod _hb_glyph_info_is_default_ignorable (&c->buffer->info[i]))) 565784f29d061a2939562eca0c4943feb01174aee00Behdad Esfahbod { 566784f29d061a2939562eca0c4943feb01174aee00Behdad Esfahbod if (!space) { 567784f29d061a2939562eca0c4943feb01174aee00Behdad Esfahbod /* We assume that the space glyph is not gid0. */ 568784f29d061a2939562eca0c4943feb01174aee00Behdad Esfahbod if (unlikely (!c->font->get_glyph (' ', 0, &space)) || !space) 569784f29d061a2939562eca0c4943feb01174aee00Behdad Esfahbod return; /* No point! */ 570784f29d061a2939562eca0c4943feb01174aee00Behdad Esfahbod } 571d1deaa2f5bd028e8076265cba92cffa4fa2834acBehdad Esfahbod c->buffer->info[i].codepoint = space; 572d1deaa2f5bd028e8076265cba92cffa4fa2834acBehdad Esfahbod c->buffer->pos[i].x_advance = 0; 573d1deaa2f5bd028e8076265cba92cffa4fa2834acBehdad Esfahbod c->buffer->pos[i].y_advance = 0; 574d1deaa2f5bd028e8076265cba92cffa4fa2834acBehdad Esfahbod } 575d1deaa2f5bd028e8076265cba92cffa4fa2834acBehdad Esfahbod} 576d1deaa2f5bd028e8076265cba92cffa4fa2834acBehdad Esfahbod 577ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 5785c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod/* Pull it all together! */ 579ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 580967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodstatic void 581e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbodhb_ot_shape_internal (hb_ot_shape_context_t *c) 582ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 583b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod c->buffer->deallocate_var_all (); 584b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod 585d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod /* Save the original direction, we use it later. */ 586bbbbe80ec9bc45c5b685bc09c8f993e98496555cBehdad Esfahbod c->target_direction = c->buffer->props.direction; 587d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod 588d1deaa2f5bd028e8076265cba92cffa4fa2834acBehdad Esfahbod HB_BUFFER_ALLOCATE_VAR (c->buffer, unicode_props0); 589d1deaa2f5bd028e8076265cba92cffa4fa2834acBehdad Esfahbod HB_BUFFER_ALLOCATE_VAR (c->buffer, unicode_props1); 590b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod 591330a2af3ff0e12c01b3b451357b8bdc83b2e9b47Behdad Esfahbod c->buffer->clear_output (); 592330a2af3ff0e12c01b3b451357b8bdc83b2e9b47Behdad Esfahbod 593d1deaa2f5bd028e8076265cba92cffa4fa2834acBehdad Esfahbod hb_set_unicode_props (c->buffer); 5946912e476dd92639c3ddf07ca51c8d4a262c8b3a5Behdad Esfahbod hb_insert_dotted_circle (c->buffer, c->font); 5954ff0d2d9dfc4f7e4880a4e964ca9872624508ea0Behdad Esfahbod hb_form_clusters (c->buffer); 5964ff0d2d9dfc4f7e4880a4e964ca9872624508ea0Behdad Esfahbod 597aa7264123a088936f2043b45d4d41ca7413fabe5Behdad Esfahbod hb_ensure_native_direction (c->buffer); 59854d1a0d2b2c4ffe15494967122c6422ecb1fc80bBehdad Esfahbod 5995c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod hb_ot_substitute (c); 6005c60b70c89b4e0a6512d9fd1ab5394dd76feb742Behdad Esfahbod hb_ot_position (c); 601ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 6020c7df2222862122ebbdc8665a21d6771ef5e0252Behdad Esfahbod hb_ot_hide_default_ignorables (c); 603d1deaa2f5bd028e8076265cba92cffa4fa2834acBehdad Esfahbod 604d1deaa2f5bd028e8076265cba92cffa4fa2834acBehdad Esfahbod HB_BUFFER_DEALLOCATE_VAR (c->buffer, unicode_props1); 605d1deaa2f5bd028e8076265cba92cffa4fa2834acBehdad Esfahbod HB_BUFFER_DEALLOCATE_VAR (c->buffer, unicode_props0); 606b65c06025d2b54a44f716e030d4b10072c65bea8Behdad Esfahbod 607bbbbe80ec9bc45c5b685bc09c8f993e98496555cBehdad Esfahbod c->buffer->props.direction = c->target_direction; 6089f9bcceca6321d5a5812f878de1de39901349a78Behdad Esfahbod 6099f9bcceca6321d5a5812f878de1de39901349a78Behdad Esfahbod c->buffer->deallocate_var_all (); 610967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod} 611967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod 612fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod 61302aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbodhb_bool_t 614bd26b4d21f59312805d294f46f15182adbcc47daBehdad Esfahbod_hb_ot_shape (hb_shape_plan_t *shape_plan, 615bd26b4d21f59312805d294f46f15182adbcc47daBehdad Esfahbod hb_font_t *font, 6166bd9b479b8b2befbb0847282e93beade197c8038Behdad Esfahbod hb_buffer_t *buffer, 6176bd9b479b8b2befbb0847282e93beade197c8038Behdad Esfahbod const hb_feature_t *features, 6186bd9b479b8b2befbb0847282e93beade197c8038Behdad Esfahbod unsigned int num_features) 619967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod{ 620e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod hb_ot_shape_context_t c = {HB_SHAPER_DATA_GET (shape_plan), font, font->face, buffer, features, num_features}; 621e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod hb_ot_shape_internal (&c); 62202aeca985b570763342c35e99af90025bfa088d5Behdad Esfahbod 6230594a2448440208efa0acac9a5d8d52d43108289Behdad Esfahbod return true; 624ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 6251827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod 6261827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod 627f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbodvoid 628f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbodhb_ot_shape_plan_collect_lookups (hb_shape_plan_t *shape_plan, 629f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod hb_tag_t table_tag, 630f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod hb_set_t *lookup_indexes /* OUT */) 631f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod{ 63251bb498b7b07bff4a447405b72f09b68d07a3e95Behdad Esfahbod /* XXX Does the first part always succeed? */ 633f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod HB_SHAPER_DATA_GET (shape_plan)->collect_lookups (table_tag, lookup_indexes); 634f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod} 635b00321ea78793d9b3592b5173a9800e6322424feBehdad Esfahbod 636f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod 637f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod/* TODO Move this to hb-ot-shape-normalize, make it do decompose, and make it public. */ 638f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbodstatic void 639f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbodadd_char (hb_font_t *font, 640f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod hb_unicode_funcs_t *unicode, 641f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod hb_bool_t mirror, 642f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod hb_codepoint_t u, 643f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod hb_set_t *glyphs) 644b00321ea78793d9b3592b5173a9800e6322424feBehdad Esfahbod{ 645f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod hb_codepoint_t glyph; 646f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod if (font->get_glyph (u, 0, &glyph)) 647f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod glyphs->add (glyph); 648f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod if (mirror) 649f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod { 650f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod hb_codepoint_t m = unicode->mirroring (u); 651f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod if (m != u && font->get_glyph (m, 0, &glyph)) 652f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod glyphs->add (glyph); 653f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod } 654b00321ea78793d9b3592b5173a9800e6322424feBehdad Esfahbod} 655b00321ea78793d9b3592b5173a9800e6322424feBehdad Esfahbod 656f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod 6571827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbodvoid 6581827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbodhb_ot_shape_glyphs_closure (hb_font_t *font, 6591827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod hb_buffer_t *buffer, 6601827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod const hb_feature_t *features, 6611827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod unsigned int num_features, 6621827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod hb_set_t *glyphs) 6631827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod{ 6641827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod hb_ot_shape_plan_t plan; 6651827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod 6663f82f8ff07a9d16a7c047129658c1bbedfdb5436Behdad Esfahbod buffer->guess_segment_properties (); 6671827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod 668f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod const char *shapers[] = {"ot", NULL}; 669f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod hb_shape_plan_t *shape_plan = hb_shape_plan_create_cached (font->face, &buffer->props, 670f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod features, num_features, shapers); 6711827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod 672f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod bool mirror = hb_script_get_horizontal_direction (buffer->props.script) == HB_DIRECTION_RTL; 6731827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod 6741827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod unsigned int count = buffer->len; 6751827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod for (unsigned int i = 0; i < count; i++) 676f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod add_char (font, buffer->unicode, mirror, buffer->info[i].codepoint, glyphs); 677f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod 678f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod hb_set_t lookups; 679f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod lookups.init (); 680f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod hb_ot_shape_plan_collect_lookups (shape_plan, HB_OT_TAG_GSUB, &lookups); 6811827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod 6821827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod /* And find transitive closure. */ 6831827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod hb_set_t copy; 6841827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod copy.init (); 6851827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod do { 6861827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod copy.set (glyphs); 687f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod for (hb_codepoint_t lookup_index = -1; hb_set_next (&lookups, &lookup_index);) 688f30641038ba96e83950729b1bd9d86d2e98e46c5Behdad Esfahbod hb_ot_layout_lookup_substitute_closure (font->face, lookup_index, glyphs); 689aec89de5641fbe1c3031d63dd5f40ec99bf2a538Behdad Esfahbod } while (!copy.is_equal (glyphs)); 690e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod 691e82061e8db922f0ddbefd5a184ee2f9f967b9a05Behdad Esfahbod hb_shape_plan_destroy (shape_plan); 6921827dc208c867e433a95237d1ed3fc7a73d1d9a7Behdad Esfahbod} 693