hb-ot-shape.cc revision 1e7c1fcbc33599faefc32d4a28e5d8506d2c56fa
12014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod/* 20e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod * Copyright (C) 2009,2010 Red Hat, Inc. 3476c94218b4f5b8e119e82b0e10b641e0c10bf56Behdad Esfahbod * Copyright (C) 2010 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 32acdba3f90b232fc12fcb200dca2584481b339118Behdad EsfahbodHB_BEGIN_DECLS 33acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod 34acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod 3575f3469ca6d626b08eb411984a2ba7fd48ca5b5fBehdad Esfahbod/* XXX vertical */ 362014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbodhb_tag_t default_features[] = { 37bd0987386b3a4dddf208ccf1a70ebfff6242ba73Behdad Esfahbod HB_TAG('c','a','l','t'), 382014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod HB_TAG('c','c','m','p'), 392014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod HB_TAG('c','l','i','g'), 40bd0987386b3a4dddf208ccf1a70ebfff6242ba73Behdad Esfahbod HB_TAG('c','s','w','h'), 41bd0987386b3a4dddf208ccf1a70ebfff6242ba73Behdad Esfahbod HB_TAG('c','u','r','s'), 422014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod HB_TAG('k','e','r','n'), 43bd0987386b3a4dddf208ccf1a70ebfff6242ba73Behdad Esfahbod HB_TAG('l','i','g','a'), 44bd0987386b3a4dddf208ccf1a70ebfff6242ba73Behdad Esfahbod HB_TAG('l','o','c','l'), 452014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod HB_TAG('m','a','r','k'), 462014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod HB_TAG('m','k','m','k'), 47bd0987386b3a4dddf208ccf1a70ebfff6242ba73Behdad Esfahbod HB_TAG('r','l','i','g') 482014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod}; 492014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 502014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbodstatic void 51605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbodhb_ot_shape_collect_features (hb_ot_shape_plan_t *plan, 5249baa1f69efb0e3c62e45bd59dd88459a84bf390Behdad Esfahbod const hb_segment_properties_t *props, 53895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod const hb_feature_t *user_features, 54895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod unsigned int num_user_features) 552014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod{ 56895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod switch (props->direction) { 570e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod case HB_DIRECTION_LTR: 58605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod plan->map.add_bool_feature (HB_TAG ('l','t','r','a')); 59605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod plan->map.add_bool_feature (HB_TAG ('l','t','r','m')); 600e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod break; 610e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod case HB_DIRECTION_RTL: 62605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod plan->map.add_bool_feature (HB_TAG ('r','t','l','a')); 63605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod plan->map.add_bool_feature (HB_TAG ('r','t','l','m'), false); 640e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod break; 650e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod case HB_DIRECTION_TTB: 660e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod case HB_DIRECTION_BTT: 670e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod default: 680e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod break; 690e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod } 700e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod 71d9c726078828d50db62e05407a3f38f2e7607533Behdad Esfahbod for (unsigned int i = 0; i < ARRAY_LENGTH (default_features); i++) 72605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod plan->map.add_bool_feature (default_features[i]); 73e04685ee7be01695ec437fab50f919f1b7423c57Behdad Esfahbod 7449baa1f69efb0e3c62e45bd59dd88459a84bf390Behdad Esfahbod hb_ot_shape_complex_collect_features (plan, props); 75e04685ee7be01695ec437fab50f919f1b7423c57Behdad Esfahbod 76895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod for (unsigned int i = 0; i < num_user_features; i++) { 77895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod const hb_feature_t *feature = &user_features[i]; 78605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod plan->map.add_feature (feature->tag, feature->value, (feature->start == 0 && feature->end == (unsigned int) -1)); 79e04685ee7be01695ec437fab50f919f1b7423c57Behdad Esfahbod } 80e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbod} 81e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbod 82e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbod 83e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbodstatic void 8452601275d5e4000dada4f925fb78723eeeee7bd4Behdad Esfahbodhb_ot_shape_setup_masks (hb_ot_shape_context_t *c) 85e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbod{ 86605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod hb_mask_t global_mask = c->plan->map.get_global_mask (); 8757ac0ecb7843533b2e6e6d6c8a12b2a44437cc1cBehdad Esfahbod c->buffer->reset_masks (global_mask); 885b88908f12ad1d828dd6075fb8fc0036c2d6af3aBehdad Esfahbod 892989be4919242670c94825bded96db20a7b2035bBehdad Esfahbod hb_ot_shape_complex_setup_masks (c); 902989be4919242670c94825bded96db20a7b2035bBehdad Esfahbod 91d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod for (unsigned int i = 0; i < c->num_user_features; i++) 92efe0d682e860ffd23a1d17c68c8273f17d51c1c9Behdad Esfahbod { 93d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod const hb_feature_t *feature = &c->user_features[i]; 944924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod if (!(feature->start == 0 && feature->end == (unsigned int)-1)) { 954924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod unsigned int shift; 96605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod hb_mask_t mask = c->plan->map.get_mask (feature->tag, &shift); 97bd7378b2ef9793de4e7f57b920f29f48ac9d0c25Behdad Esfahbod c->buffer->set_masks (feature->value << shift, mask, feature->start, feature->end); 984924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod } 99efe0d682e860ffd23a1d17c68c8273f17d51c1c9Behdad Esfahbod } 1002014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod} 1012014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 1022014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 103967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodstatic void 10436925f695d349a53d52ecc3a58f18240a6977463Behdad Esfahbodhb_ot_substitute_complex (hb_ot_shape_context_t *c) 1052014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod{ 106967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod if (!hb_ot_layout_has_substitution (c->face)) 107967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod return; 1082014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 109605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod c->plan->map.substitute (c->face, c->buffer); 1102014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 111967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod c->applied_substitute_complex = TRUE; 112967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod return; 1132014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod} 1142014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 115967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodstatic void 11636925f695d349a53d52ecc3a58f18240a6977463Behdad Esfahbodhb_ot_position_complex (hb_ot_shape_context_t *c) 1172014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod{ 1182014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 119967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod if (!hb_ot_layout_has_positioning (c->face)) 120967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod return; 1212014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 122605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod c->plan->map.position (c->font, c->face, c->buffer); 1232014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 1241e7c1fcbc33599faefc32d4a28e5d8506d2c56faBehdad Esfahbod hb_ot_layout_position_finish (c->buffer); 1252014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 126967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod c->applied_position_complex = TRUE; 127967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod return; 1282014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod} 129ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 130ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 131ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Main shaper */ 132ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 133ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Prepare */ 134ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 135ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic inline hb_bool_t 136ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodis_variation_selector (hb_codepoint_t unicode) 137ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 138ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod return unlikely ((unicode >= 0x180B && unicode <= 0x180D) || /* MONGOLIAN FREE VARIATION SELECTOR ONE..THREE */ 139ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod (unicode >= 0xFE00 && unicode <= 0xFE0F) || /* VARIATION SELECTOR-1..16 */ 140ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod (unicode >= 0xE0100 && unicode <= 0xE01EF)); /* VARIATION SELECTOR-17..256 */ 141ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 142ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 143ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void 1446b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbodhb_form_clusters (hb_ot_shape_context_t *c) 145ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 1466b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod unsigned int count = c->buffer->len; 147ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod for (unsigned int i = 1; i < count; i++) 1486b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod if (c->buffer->unicode->v.get_general_category (c->buffer->info[i].codepoint) == HB_CATEGORY_NON_SPACING_MARK) 1496b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod c->buffer->info[i].cluster = c->buffer->info[i - 1].cluster; 150ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 151ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 152967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodstatic void 1536b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbodhb_ensure_native_direction (hb_ot_shape_context_t *c) 154ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 1556b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod hb_direction_t direction = c->buffer->props.direction; 156ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 157ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod /* TODO vertical */ 158967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod if (HB_DIRECTION_IS_HORIZONTAL (direction) && 1596b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod direction != _hb_script_get_horizontal_direction (c->buffer->props.script)) 160ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod { 1616b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod hb_buffer_reverse_clusters (c->buffer); 1626b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod c->buffer->props.direction = HB_DIRECTION_REVERSE (c->buffer->props.direction); 163ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod } 164ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 165ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 16698370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbodstatic void 16798370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbodhb_reset_glyph_infos (hb_ot_shape_context_t *c) 16898370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbod{ 16998370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbod unsigned int count = c->buffer->len; 17098370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbod for (unsigned int i = 0; i < count; i++) 17198370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbod c->buffer->info[i].var1.u32 = c->buffer->info[i].var2.u32 = 0; 17298370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbod} 17398370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbod 174ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 175ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Substitute */ 176ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 177ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void 178aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbodhb_mirror_chars (hb_ot_shape_context_t *c) 179ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 180aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod hb_unicode_get_mirroring_func_t get_mirroring = c->buffer->unicode->v.get_mirroring; 181ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 182aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod if (HB_DIRECTION_IS_FORWARD (c->buffer->props.direction)) 183ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod return; 184ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 18539dede9ffffe732f78cbd092ccb3b48d77ddd66dBehdad Esfahbod hb_mask_t rtlm_mask = c->plan->map.get_1_mask (HB_TAG ('r','t','l','m')); 1864e4ef24e46f273ad2bdda2f718223e05b37dd50fBehdad Esfahbod 187aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod unsigned int count = c->buffer->len; 188ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod for (unsigned int i = 0; i < count; i++) { 189aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod hb_codepoint_t codepoint = get_mirroring (c->buffer->info[i].codepoint); 190aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod if (likely (codepoint == c->buffer->info[i].codepoint)) 191bd7378b2ef9793de4e7f57b920f29f48ac9d0c25Behdad Esfahbod c->buffer->info[i].mask |= rtlm_mask; /* XXX this should be moved to before setting user-feature masks */ 1921094a294f6a44c47fc75867983f2b135a6442babBehdad Esfahbod else 193aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod c->buffer->info[i].codepoint = codepoint; 194ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod } 195ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 196ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 197ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void 198ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodhb_map_glyphs (hb_font_t *font, 199ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod hb_face_t *face, 200ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod hb_buffer_t *buffer) 201ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 202ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod if (unlikely (!buffer->len)) 203ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod return; 204ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 205a224b4d502d026fa642ee4098bf7bc0b4ba7ce27Behdad Esfahbod buffer->clear_output (); 206ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod unsigned int count = buffer->len - 1; 207a224b4d502d026fa642ee4098bf7bc0b4ba7ce27Behdad Esfahbod for (buffer->i = 0; buffer->i < count;) { 208a224b4d502d026fa642ee4098bf7bc0b4ba7ce27Behdad Esfahbod if (unlikely (is_variation_selector (buffer->info[buffer->i + 1].codepoint))) { 209dd2ffd282c059194fd87fb1664e2e0cdb56a87a0Behdad Esfahbod buffer->replace_glyph (hb_font_get_glyph (font, face, buffer->info[buffer->i].codepoint, buffer->info[buffer->i + 1].codepoint)); 210a224b4d502d026fa642ee4098bf7bc0b4ba7ce27Behdad Esfahbod buffer->i++; 211ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod } else { 212dd2ffd282c059194fd87fb1664e2e0cdb56a87a0Behdad Esfahbod buffer->replace_glyph (hb_font_get_glyph (font, face, buffer->info[buffer->i].codepoint, 0)); 213ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod } 214ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod } 215f2a1b411b1d48c3dfac0df8e78c848d9aa3bb047Behdad Esfahbod if (likely (buffer->i < buffer->len)) 216dd2ffd282c059194fd87fb1664e2e0cdb56a87a0Behdad Esfahbod buffer->replace_glyph (hb_font_get_glyph (font, face, buffer->info[buffer->i].codepoint, 0)); 217a224b4d502d026fa642ee4098bf7bc0b4ba7ce27Behdad Esfahbod buffer->swap (); 218ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 219ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 220ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void 221967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_substitute_default (hb_ot_shape_context_t *c) 222ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 223967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_map_glyphs (c->font, c->face, c->buffer); 224ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 225ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 226ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void 227967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_substitute_complex_fallback (hb_ot_shape_context_t *c HB_UNUSED) 228ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 229ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod /* TODO Arabic */ 230ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 231ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 232ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 233ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Position */ 234ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 235ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void 236967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_position_default (hb_ot_shape_context_t *c) 237ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 238967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_buffer_clear_positions (c->buffer); 239ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 240967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod unsigned int count = c->buffer->len; 241ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod for (unsigned int i = 0; i < count; i++) { 242502f4cba3e0bcd625d31f8fd295b8b18e2d02a5aBehdad Esfahbod hb_font_get_glyph_advance (c->font, c->face, c->buffer->info[i].codepoint, 243502f4cba3e0bcd625d31f8fd295b8b18e2d02a5aBehdad Esfahbod &c->buffer->pos[i].x_advance, 244502f4cba3e0bcd625d31f8fd295b8b18e2d02a5aBehdad Esfahbod &c->buffer->pos[i].y_advance); 245ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod } 246ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 247ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 248ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void 249967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_position_complex_fallback (hb_ot_shape_context_t *c HB_UNUSED) 250ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 251ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod /* TODO Mark pos */ 252ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 253ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 254ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void 255967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_truetype_kern (hb_ot_shape_context_t *c) 256ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 257ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod /* TODO Check for kern=0 */ 258967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod unsigned int count = c->buffer->len; 259ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod for (unsigned int i = 1; i < count; i++) { 260ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod hb_position_t kern, kern1, kern2; 261967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod kern = hb_font_get_kerning (c->font, c->face, c->buffer->info[i - 1].codepoint, c->buffer->info[i].codepoint); 262ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod kern1 = kern >> 1; 263ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod kern2 = kern - kern1; 264967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod c->buffer->pos[i - 1].x_advance += kern1; 265967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod c->buffer->pos[i].x_advance += kern2; 266967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod c->buffer->pos[i].x_offset += kern2; 267ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod } 268ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 269ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 270ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void 271967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_position_complex_fallback_visual (hb_ot_shape_context_t *c) 272ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 273967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_truetype_kern (c); 274ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 275ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 276ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 277ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Do it! */ 278ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 279967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodstatic void 280fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbodhb_ot_shape_execute_internal (hb_ot_shape_context_t *c) 281ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 282d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod /* Save the original direction, we use it later. */ 283d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod c->original_direction = c->buffer->props.direction; 284d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod 2856b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod hb_form_clusters (c); 286ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 287fc96596b7c1c4e62491e951a3c256fb00dcde550Behdad Esfahbod hb_ot_shape_setup_masks (c); 288fc96596b7c1c4e62491e951a3c256fb00dcde550Behdad Esfahbod 28998370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbod hb_reset_glyph_infos (c); 29098370e89d1bff248737b482d129c2a4deb8bfd95Behdad Esfahbod 2911094a294f6a44c47fc75867983f2b135a6442babBehdad Esfahbod /* SUBSTITUTE */ 292fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod { 293fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod /* Mirroring needs to see the original direction */ 294aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod hb_mirror_chars (c); 295ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 2966b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod hb_ensure_native_direction (c); 297ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 298967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_substitute_default (c); 299bbc7a99d01298f9be1ebaaceacbc9bc961e247e5Behdad Esfahbod 30036925f695d349a53d52ecc3a58f18240a6977463Behdad Esfahbod hb_ot_substitute_complex (c); 301ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 302967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod if (!c->applied_substitute_complex) 303967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_substitute_complex_fallback (c); 304fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod } 3051094a294f6a44c47fc75867983f2b135a6442babBehdad Esfahbod 3061094a294f6a44c47fc75867983f2b135a6442babBehdad Esfahbod /* POSITION */ 307fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod { 308967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_position_default (c); 309ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 31036925f695d349a53d52ecc3a58f18240a6977463Behdad Esfahbod hb_ot_position_complex (c); 311ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 312967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_bool_t position_fallback = !c->applied_position_complex; 313fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod if (position_fallback) 314967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_position_complex_fallback (c); 315ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 316967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod if (HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction)) 317967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_buffer_reverse (c->buffer); 318ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 319fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod if (position_fallback) 320967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_position_complex_fallback_visual (c); 321fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod } 322ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 323967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod c->buffer->props.direction = c->original_direction; 324967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod} 325967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod 326967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodvoid 327605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbodhb_ot_shape_plan_internal (hb_ot_shape_plan_t *plan, 328d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod hb_face_t *face, 32949baa1f69efb0e3c62e45bd59dd88459a84bf390Behdad Esfahbod const hb_segment_properties_t *props, 330d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod const hb_feature_t *user_features, 331d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod unsigned int num_user_features) 332d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod{ 33349baa1f69efb0e3c62e45bd59dd88459a84bf390Behdad Esfahbod plan->shaper = hb_ot_shape_complex_categorize (props); 33449baa1f69efb0e3c62e45bd59dd88459a84bf390Behdad Esfahbod 335605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod hb_ot_shape_collect_features (plan, props, user_features, num_user_features); 336d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod 337605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod plan->map.compile (face, props); 338d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod} 339d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod 340d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbodvoid 341fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbodhb_ot_shape_execute (hb_ot_shape_plan_t *plan, 342fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod hb_font_t *font, 343fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod hb_face_t *face, 344fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod hb_buffer_t *buffer, 345fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod const hb_feature_t *user_features, 346fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod unsigned int num_user_features) 347fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod{ 348fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod hb_ot_shape_context_t c = {plan, font, face, buffer, user_features, num_user_features}; 349fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod hb_ot_shape_execute_internal (&c); 350fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod} 351fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod 352fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbodvoid 353967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_ot_shape (hb_font_t *font, 354967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_face_t *face, 355967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_buffer_t *buffer, 356d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod const hb_feature_t *user_features, 357d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod unsigned int num_user_features) 358967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod{ 359605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod hb_ot_shape_plan_t plan; 360967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod 361605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod hb_ot_shape_plan_internal (&plan, face, &buffer->props, user_features, num_user_features); 362fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod hb_ot_shape_execute (&plan, font, face, buffer, user_features, num_user_features); 363ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 364acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod 365acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod 366acdba3f90b232fc12fcb200dca2584481b339118Behdad EsfahbodHB_END_DECLS 367