hb-ot-shape.cc revision 57ac0ecb7843533b2e6e6d6c8a12b2a44437cc1c
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" 302014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 31acdba3f90b232fc12fcb200dca2584481b339118Behdad EsfahbodHB_BEGIN_DECLS 32acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod 33acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod 3475f3469ca6d626b08eb411984a2ba7fd48ca5b5fBehdad Esfahbod/* XXX vertical */ 352014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbodhb_tag_t default_features[] = { 36bd0987386b3a4dddf208ccf1a70ebfff6242ba73Behdad Esfahbod HB_TAG('c','a','l','t'), 372014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod HB_TAG('c','c','m','p'), 382014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod HB_TAG('c','l','i','g'), 39bd0987386b3a4dddf208ccf1a70ebfff6242ba73Behdad Esfahbod HB_TAG('c','s','w','h'), 40bd0987386b3a4dddf208ccf1a70ebfff6242ba73Behdad Esfahbod HB_TAG('c','u','r','s'), 412014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod HB_TAG('k','e','r','n'), 42bd0987386b3a4dddf208ccf1a70ebfff6242ba73Behdad Esfahbod HB_TAG('l','i','g','a'), 43bd0987386b3a4dddf208ccf1a70ebfff6242ba73Behdad Esfahbod HB_TAG('l','o','c','l'), 442014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod HB_TAG('m','a','r','k'), 452014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod HB_TAG('m','k','m','k'), 46bd0987386b3a4dddf208ccf1a70ebfff6242ba73Behdad Esfahbod HB_TAG('r','l','i','g') 472014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod}; 482014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 492014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbodstatic void 50605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbodhb_ot_shape_collect_features (hb_ot_shape_plan_t *plan, 5149baa1f69efb0e3c62e45bd59dd88459a84bf390Behdad Esfahbod const hb_segment_properties_t *props, 52895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod const hb_feature_t *user_features, 53895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod unsigned int num_user_features) 542014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod{ 55895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod switch (props->direction) { 560e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod case HB_DIRECTION_LTR: 57605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod plan->map.add_bool_feature (HB_TAG ('l','t','r','a')); 58605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod plan->map.add_bool_feature (HB_TAG ('l','t','r','m')); 590e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod break; 600e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod case HB_DIRECTION_RTL: 61605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod plan->map.add_bool_feature (HB_TAG ('r','t','l','a')); 62605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod plan->map.add_bool_feature (HB_TAG ('r','t','l','m'), false); 630e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod break; 640e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod case HB_DIRECTION_TTB: 650e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod case HB_DIRECTION_BTT: 660e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod default: 670e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod break; 680e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod } 690e235d0fc9bdeeaffa7215c21abc5d40767a10c7Behdad Esfahbod 70d9c726078828d50db62e05407a3f38f2e7607533Behdad Esfahbod for (unsigned int i = 0; i < ARRAY_LENGTH (default_features); i++) 71605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod plan->map.add_bool_feature (default_features[i]); 72e04685ee7be01695ec437fab50f919f1b7423c57Behdad Esfahbod 7349baa1f69efb0e3c62e45bd59dd88459a84bf390Behdad Esfahbod hb_ot_shape_complex_collect_features (plan, props); 74e04685ee7be01695ec437fab50f919f1b7423c57Behdad Esfahbod 75895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod for (unsigned int i = 0; i < num_user_features; i++) { 76895fb5d364e7ae5d9d2e34b9f68b8651804369efBehdad Esfahbod const hb_feature_t *feature = &user_features[i]; 77605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod plan->map.add_feature (feature->tag, feature->value, (feature->start == 0 && feature->end == (unsigned int) -1)); 78e04685ee7be01695ec437fab50f919f1b7423c57Behdad Esfahbod } 79e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbod} 80e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbod 81e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbod 82e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbodstatic void 8352601275d5e4000dada4f925fb78723eeeee7bd4Behdad Esfahbodhb_ot_shape_setup_masks (hb_ot_shape_context_t *c) 84e89b7d2a61b7f58e6c7cec00d5ce2246dee1e8a1Behdad Esfahbod{ 85605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod hb_mask_t global_mask = c->plan->map.get_global_mask (); 8657ac0ecb7843533b2e6e6d6c8a12b2a44437cc1cBehdad Esfahbod c->buffer->reset_masks (global_mask); 875b88908f12ad1d828dd6075fb8fc0036c2d6af3aBehdad Esfahbod 88d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod for (unsigned int i = 0; i < c->num_user_features; i++) 89efe0d682e860ffd23a1d17c68c8273f17d51c1c9Behdad Esfahbod { 90d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod const hb_feature_t *feature = &c->user_features[i]; 914924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod if (!(feature->start == 0 && feature->end == (unsigned int)-1)) { 924924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod unsigned int shift; 93605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod hb_mask_t mask = c->plan->map.get_mask (feature->tag, &shift); 9457ac0ecb7843533b2e6e6d6c8a12b2a44437cc1cBehdad Esfahbod c->buffer->add_masks (feature->value << shift, mask, feature->start, feature->end); 954924affe0f0adf75f2a0e2137a71206b0576d63fBehdad Esfahbod } 96efe0d682e860ffd23a1d17c68c8273f17d51c1c9Behdad Esfahbod } 97efe0d682e860ffd23a1d17c68c8273f17d51c1c9Behdad Esfahbod 985b88908f12ad1d828dd6075fb8fc0036c2d6af3aBehdad Esfahbod /* complex */ 992014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod} 1002014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 1012014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 102967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodstatic void 10336925f695d349a53d52ecc3a58f18240a6977463Behdad Esfahbodhb_ot_substitute_complex (hb_ot_shape_context_t *c) 1042014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod{ 105967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod if (!hb_ot_layout_has_substitution (c->face)) 106967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod return; 1072014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 108605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod c->plan->map.substitute (c->face, c->buffer); 1092014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 110967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod c->applied_substitute_complex = TRUE; 111967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod return; 1122014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod} 1132014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 114967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodstatic void 11536925f695d349a53d52ecc3a58f18240a6977463Behdad Esfahbodhb_ot_position_complex (hb_ot_shape_context_t *c) 1162014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod{ 1172014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 118967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod if (!hb_ot_layout_has_positioning (c->face)) 119967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod return; 1202014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 121605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod c->plan->map.position (c->font, c->face, c->buffer); 1222014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 123967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_ot_layout_position_finish (c->font, c->face, c->buffer); 1242014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod 125967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod c->applied_position_complex = TRUE; 126967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod return; 1272014b8d110231b13e524008282ece7451f1ae9e7Behdad Esfahbod} 128ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 129ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 130ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Main shaper */ 131ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 132ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Prepare */ 133ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 134ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic inline hb_bool_t 135ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodis_variation_selector (hb_codepoint_t unicode) 136ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 137ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod return unlikely ((unicode >= 0x180B && unicode <= 0x180D) || /* MONGOLIAN FREE VARIATION SELECTOR ONE..THREE */ 138ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod (unicode >= 0xFE00 && unicode <= 0xFE0F) || /* VARIATION SELECTOR-1..16 */ 139ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod (unicode >= 0xE0100 && unicode <= 0xE01EF)); /* VARIATION SELECTOR-17..256 */ 140ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 141ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 142ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void 1436b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbodhb_form_clusters (hb_ot_shape_context_t *c) 144ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 1456b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod unsigned int count = c->buffer->len; 146ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod for (unsigned int i = 1; i < count; i++) 1476b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod if (c->buffer->unicode->v.get_general_category (c->buffer->info[i].codepoint) == HB_CATEGORY_NON_SPACING_MARK) 1486b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod c->buffer->info[i].cluster = c->buffer->info[i - 1].cluster; 149ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 150ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 151967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodstatic void 1526b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbodhb_ensure_native_direction (hb_ot_shape_context_t *c) 153ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 1546b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod hb_direction_t direction = c->buffer->props.direction; 155ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 156ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod /* TODO vertical */ 157967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod if (HB_DIRECTION_IS_HORIZONTAL (direction) && 1586b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod direction != _hb_script_get_horizontal_direction (c->buffer->props.script)) 159ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod { 1606b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod hb_buffer_reverse_clusters (c->buffer); 1616b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod c->buffer->props.direction = HB_DIRECTION_REVERSE (c->buffer->props.direction); 162ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod } 163ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 164ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 165ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 166ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Substitute */ 167ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 168ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void 169aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbodhb_mirror_chars (hb_ot_shape_context_t *c) 170ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 171aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod hb_unicode_get_mirroring_func_t get_mirroring = c->buffer->unicode->v.get_mirroring; 172ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 173aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod if (HB_DIRECTION_IS_FORWARD (c->buffer->props.direction)) 174ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod return; 175ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 176605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod hb_mask_t rtlm_mask = c->plan->map.get_mask (HB_TAG ('r','t','l','m')); 1774e4ef24e46f273ad2bdda2f718223e05b37dd50fBehdad Esfahbod 178aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod unsigned int count = c->buffer->len; 179ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod for (unsigned int i = 0; i < count; i++) { 180aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod hb_codepoint_t codepoint = get_mirroring (c->buffer->info[i].codepoint); 181aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod if (likely (codepoint == c->buffer->info[i].codepoint)) 182aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod c->buffer->info[i].mask |= rtlm_mask; 1831094a294f6a44c47fc75867983f2b135a6442babBehdad Esfahbod else 184aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod c->buffer->info[i].codepoint = codepoint; 185ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod } 186ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 187ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 188ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void 189ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodhb_map_glyphs (hb_font_t *font, 190ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod hb_face_t *face, 191ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod hb_buffer_t *buffer) 192ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 193ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod if (unlikely (!buffer->len)) 194ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod return; 195ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 196a224b4d502d026fa642ee4098bf7bc0b4ba7ce27Behdad Esfahbod buffer->clear_output (); 197ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod unsigned int count = buffer->len - 1; 198a224b4d502d026fa642ee4098bf7bc0b4ba7ce27Behdad Esfahbod for (buffer->i = 0; buffer->i < count;) { 199a224b4d502d026fa642ee4098bf7bc0b4ba7ce27Behdad Esfahbod if (unlikely (is_variation_selector (buffer->info[buffer->i + 1].codepoint))) { 200a224b4d502d026fa642ee4098bf7bc0b4ba7ce27Behdad Esfahbod buffer->add_output_glyph (hb_font_get_glyph (font, face, buffer->info[buffer->i].codepoint, buffer->info[buffer->i + 1].codepoint)); 201a224b4d502d026fa642ee4098bf7bc0b4ba7ce27Behdad Esfahbod buffer->i++; 202ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod } else { 203a224b4d502d026fa642ee4098bf7bc0b4ba7ce27Behdad Esfahbod buffer->add_output_glyph (hb_font_get_glyph (font, face, buffer->info[buffer->i].codepoint, 0)); 204ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod } 205ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod } 206f2a1b411b1d48c3dfac0df8e78c848d9aa3bb047Behdad Esfahbod if (likely (buffer->i < buffer->len)) 207f2a1b411b1d48c3dfac0df8e78c848d9aa3bb047Behdad Esfahbod buffer->add_output_glyph (hb_font_get_glyph (font, face, buffer->info[buffer->i].codepoint, 0)); 208a224b4d502d026fa642ee4098bf7bc0b4ba7ce27Behdad Esfahbod buffer->swap (); 209ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 210ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 211ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void 212967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_substitute_default (hb_ot_shape_context_t *c) 213ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 214967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_map_glyphs (c->font, c->face, c->buffer); 215ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 216ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 217ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void 218967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_substitute_complex_fallback (hb_ot_shape_context_t *c HB_UNUSED) 219ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 220ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod /* TODO Arabic */ 221ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 222ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 223ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 224ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Position */ 225ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 226ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void 227967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_position_default (hb_ot_shape_context_t *c) 228ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 229967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_buffer_clear_positions (c->buffer); 230ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 231967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod unsigned int count = c->buffer->len; 232ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod for (unsigned int i = 0; i < count; i++) { 233ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod hb_glyph_metrics_t metrics; 234967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_font_get_glyph_metrics (c->font, c->face, c->buffer->info[i].codepoint, &metrics); 235967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod c->buffer->pos[i].x_advance = metrics.x_advance; 236967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod c->buffer->pos[i].y_advance = metrics.y_advance; 237ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod } 238ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 239ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 240ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void 241967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_position_complex_fallback (hb_ot_shape_context_t *c HB_UNUSED) 242ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 243ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod /* TODO Mark pos */ 244ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 245ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 246ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void 247967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_truetype_kern (hb_ot_shape_context_t *c) 248ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 249ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod /* TODO Check for kern=0 */ 250967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod unsigned int count = c->buffer->len; 251ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod for (unsigned int i = 1; i < count; i++) { 252ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod hb_position_t kern, kern1, kern2; 253967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod kern = hb_font_get_kerning (c->font, c->face, c->buffer->info[i - 1].codepoint, c->buffer->info[i].codepoint); 254ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod kern1 = kern >> 1; 255ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod kern2 = kern - kern1; 256967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod c->buffer->pos[i - 1].x_advance += kern1; 257967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod c->buffer->pos[i].x_advance += kern2; 258967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod c->buffer->pos[i].x_offset += kern2; 259ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod } 260ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 261ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 262ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbodstatic void 263967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_position_complex_fallback_visual (hb_ot_shape_context_t *c) 264ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 265967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_truetype_kern (c); 266ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 267ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 268ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 269ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod/* Do it! */ 270ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 271967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodstatic void 272fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbodhb_ot_shape_execute_internal (hb_ot_shape_context_t *c) 273ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod{ 274d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod /* Save the original direction, we use it later. */ 275d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod c->original_direction = c->buffer->props.direction; 276d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod 2776b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod hb_form_clusters (c); 278ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 279fc96596b7c1c4e62491e951a3c256fb00dcde550Behdad Esfahbod hb_ot_shape_setup_masks (c); 280fc96596b7c1c4e62491e951a3c256fb00dcde550Behdad Esfahbod 2811094a294f6a44c47fc75867983f2b135a6442babBehdad Esfahbod /* SUBSTITUTE */ 282fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod { 283fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod /* Mirroring needs to see the original direction */ 284aa9c450bb2d7c3c9e36ea32e3558250391a0582dBehdad Esfahbod hb_mirror_chars (c); 285ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 2866b7e6758626268ba1c7c266128e618ec73ae2c0fBehdad Esfahbod hb_ensure_native_direction (c); 287ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 288967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_substitute_default (c); 289bbc7a99d01298f9be1ebaaceacbc9bc961e247e5Behdad Esfahbod 29036925f695d349a53d52ecc3a58f18240a6977463Behdad Esfahbod hb_ot_substitute_complex (c); 291ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 292967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod if (!c->applied_substitute_complex) 293967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_substitute_complex_fallback (c); 294fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod } 2951094a294f6a44c47fc75867983f2b135a6442babBehdad Esfahbod 2961094a294f6a44c47fc75867983f2b135a6442babBehdad Esfahbod /* POSITION */ 297fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod { 298967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_position_default (c); 299ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 30036925f695d349a53d52ecc3a58f18240a6977463Behdad Esfahbod hb_ot_position_complex (c); 301ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 302967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_bool_t position_fallback = !c->applied_position_complex; 303fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod if (position_fallback) 304967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_position_complex_fallback (c); 305ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 306967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod if (HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction)) 307967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_buffer_reverse (c->buffer); 308ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 309fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod if (position_fallback) 310967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_position_complex_fallback_visual (c); 311fdc322a82047c4bda9fa3dab4338a0eac1c1bde7Behdad Esfahbod } 312ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod 313967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod c->buffer->props.direction = c->original_direction; 314967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod} 315967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod 316967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodvoid 317605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbodhb_ot_shape_plan_internal (hb_ot_shape_plan_t *plan, 318d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod hb_face_t *face, 31949baa1f69efb0e3c62e45bd59dd88459a84bf390Behdad Esfahbod const hb_segment_properties_t *props, 320d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod const hb_feature_t *user_features, 321d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod unsigned int num_user_features) 322d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod{ 32349baa1f69efb0e3c62e45bd59dd88459a84bf390Behdad Esfahbod plan->shaper = hb_ot_shape_complex_categorize (props); 32449baa1f69efb0e3c62e45bd59dd88459a84bf390Behdad Esfahbod 325605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod hb_ot_shape_collect_features (plan, props, user_features, num_user_features); 326d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod 327605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod plan->map.compile (face, props); 328d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod} 329d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod 330d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbodvoid 331fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbodhb_ot_shape_execute (hb_ot_shape_plan_t *plan, 332fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod hb_font_t *font, 333fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod hb_face_t *face, 334fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod hb_buffer_t *buffer, 335fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod const hb_feature_t *user_features, 336fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod unsigned int num_user_features) 337fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod{ 338fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod hb_ot_shape_context_t c = {plan, font, face, buffer, user_features, num_user_features}; 339fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod hb_ot_shape_execute_internal (&c); 340fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod} 341fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod 342fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbodvoid 343967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbodhb_ot_shape (hb_font_t *font, 344967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_face_t *face, 345967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod hb_buffer_t *buffer, 346d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod const hb_feature_t *user_features, 347d2ba016ca1ba7489537768b619980d5159b5870cBehdad Esfahbod unsigned int num_user_features) 348967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod{ 349605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod hb_ot_shape_plan_t plan; 350967240dd8b96802345ef273e75427066e91ea8fbBehdad Esfahbod 351605ed468f380f86d642031f6451447d270cb6de1Behdad Esfahbod hb_ot_shape_plan_internal (&plan, face, &buffer->props, user_features, num_user_features); 352fd3d32d31cb6d74a9994b6850d539fd0b707d941Behdad Esfahbod hb_ot_shape_execute (&plan, font, face, buffer, user_features, num_user_features); 353ca663bb23c16f6a1f04efa6e10dad0e3e7c260a3Behdad Esfahbod} 354acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod 355acdba3f90b232fc12fcb200dca2584481b339118Behdad Esfahbod 356acdba3f90b232fc12fcb200dca2584481b339118Behdad EsfahbodHB_END_DECLS 357