Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 1 | /* |
Behdad Esfahbod | 2409d5f | 2011-04-21 17:14:28 -0400 | [diff] [blame] | 2 | * Copyright © 2009,2010 Red Hat, Inc. |
Behdad Esfahbod | 07d6828 | 2012-08-10 03:28:50 -0400 | [diff] [blame] | 3 | * Copyright © 2010,2011,2012 Google, Inc. |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 4 | * |
Behdad Esfahbod | c755cb3 | 2010-04-22 00:11:43 -0400 | [diff] [blame] | 5 | * This is part of HarfBuzz, a text shaping library. |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 6 | * |
| 7 | * Permission is hereby granted, without written agreement and without |
| 8 | * license or royalty fees, to use, copy, modify, and distribute this |
| 9 | * software and its documentation for any purpose, provided that the |
| 10 | * above copyright notice and the following two paragraphs appear in |
| 11 | * all copies of this software. |
| 12 | * |
| 13 | * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR |
| 14 | * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES |
| 15 | * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN |
| 16 | * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH |
| 17 | * DAMAGE. |
| 18 | * |
| 19 | * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
| 20 | * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS |
| 22 | * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO |
| 23 | * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 24 | * |
| 25 | * Red Hat Author(s): Behdad Esfahbod |
Behdad Esfahbod | 476c942 | 2010-10-07 17:47:33 -0400 | [diff] [blame] | 26 | * Google Author(s): Behdad Esfahbod |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 27 | */ |
| 28 | |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 29 | #define HB_SHAPER ot |
| 30 | #define hb_ot_shaper_face_data_t hb_ot_layout_t |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 31 | #define hb_ot_shaper_shape_plan_data_t hb_ot_shape_plan_t |
Behdad Esfahbod | 027857d | 2012-07-26 17:34:25 -0400 | [diff] [blame] | 32 | #include "hb-shaper-impl-private.hh" |
| 33 | |
Behdad Esfahbod | 4924aff | 2010-10-08 19:18:16 -0400 | [diff] [blame] | 34 | #include "hb-ot-shape-private.hh" |
Behdad Esfahbod | 16c6a27 | 2012-08-02 09:38:28 -0400 | [diff] [blame] | 35 | #include "hb-ot-shape-complex-private.hh" |
Behdad Esfahbod | 9c929ab | 2012-08-08 14:33:37 -0400 | [diff] [blame] | 36 | #include "hb-ot-shape-fallback-private.hh" |
Behdad Esfahbod | affaf8a | 2012-08-07 22:41:38 -0400 | [diff] [blame] | 37 | #include "hb-ot-shape-normalize-private.hh" |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 38 | |
Behdad Esfahbod | b70021f | 2012-07-23 20:18:17 -0400 | [diff] [blame] | 39 | #include "hb-ot-layout-private.hh" |
Behdad Esfahbod | 878a253 | 2014-07-16 13:21:26 -0400 | [diff] [blame] | 40 | #include "hb-unicode-private.hh" |
Behdad Esfahbod | 1827dc2 | 2012-04-24 16:56:37 -0400 | [diff] [blame] | 41 | #include "hb-set-private.hh" |
Behdad Esfahbod | 72657e4 | 2011-05-02 20:46:32 -0400 | [diff] [blame] | 42 | |
Behdad Esfahbod | 748b989 | 2018-01-09 17:55:17 +0100 | [diff] [blame] | 43 | #include "hb-ot-layout-gsubgpos-private.hh" |
Behdad Esfahbod | db5d430 | 2018-07-17 18:14:45 +0200 | [diff] [blame] | 44 | #include "hb-aat-layout-private.hh" |
Behdad Esfahbod | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 45 | |
Behdad Esfahbod | a02d864 | 2012-08-08 18:04:29 -0400 | [diff] [blame] | 46 | static hb_tag_t common_features[] = { |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 47 | HB_TAG('c','c','m','p'), |
Behdad Esfahbod | 89a2bc9 | 2011-05-31 15:18:13 -0400 | [diff] [blame] | 48 | HB_TAG('l','o','c','l'), |
Behdad Esfahbod | 89a2bc9 | 2011-05-31 15:18:13 -0400 | [diff] [blame] | 49 | HB_TAG('m','a','r','k'), |
| 50 | HB_TAG('m','k','m','k'), |
| 51 | HB_TAG('r','l','i','g'), |
| 52 | }; |
| 53 | |
Behdad Esfahbod | d1deaa2 | 2012-05-09 15:04:13 +0200 | [diff] [blame] | 54 | |
Behdad Esfahbod | a02d864 | 2012-08-08 18:04:29 -0400 | [diff] [blame] | 55 | static hb_tag_t horizontal_features[] = { |
Behdad Esfahbod | 89a2bc9 | 2011-05-31 15:18:13 -0400 | [diff] [blame] | 56 | HB_TAG('c','a','l','t'), |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 57 | HB_TAG('c','l','i','g'), |
Behdad Esfahbod | bd09873 | 2010-05-21 18:06:35 +0100 | [diff] [blame] | 58 | HB_TAG('c','u','r','s'), |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 59 | HB_TAG('k','e','r','n'), |
Behdad Esfahbod | 2053f36 | 2014-08-02 16:31:16 -0400 | [diff] [blame] | 60 | HB_TAG('l','i','g','a'), |
Behdad Esfahbod | f4e48ad | 2012-08-07 21:12:49 -0400 | [diff] [blame] | 61 | HB_TAG('r','c','l','t'), |
Behdad Esfahbod | 89a2bc9 | 2011-05-31 15:18:13 -0400 | [diff] [blame] | 62 | }; |
| 63 | |
Behdad Esfahbod | b9f199c | 2012-04-14 20:23:58 -0400 | [diff] [blame] | 64 | |
| 65 | |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 66 | static void |
Behdad Esfahbod | 90645fb | 2011-05-27 18:13:31 -0400 | [diff] [blame] | 67 | hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner, |
Behdad Esfahbod | 49baa1f | 2010-10-12 16:50:36 -0400 | [diff] [blame] | 68 | const hb_segment_properties_t *props, |
Behdad Esfahbod | 90645fb | 2011-05-27 18:13:31 -0400 | [diff] [blame] | 69 | const hb_feature_t *user_features, |
| 70 | unsigned int num_user_features) |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 71 | { |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 72 | hb_ot_map_builder_t *map = &planner->map; |
| 73 | |
Behdad Esfahbod | 0aedfd5 | 2016-09-28 17:05:43 +0200 | [diff] [blame] | 74 | map->add_global_bool_feature (HB_TAG('r','v','r','n')); |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 75 | map->add_gsub_pause (nullptr); |
Behdad Esfahbod | 0aedfd5 | 2016-09-28 17:05:43 +0200 | [diff] [blame] | 76 | |
Behdad Esfahbod | 895fb5d | 2010-10-12 16:00:21 -0400 | [diff] [blame] | 77 | switch (props->direction) { |
Behdad Esfahbod | 074ea78 | 2010-05-21 17:53:10 +0100 | [diff] [blame] | 78 | case HB_DIRECTION_LTR: |
Behdad Esfahbod | e7ffcfa | 2013-02-14 11:05:56 -0500 | [diff] [blame] | 79 | map->add_global_bool_feature (HB_TAG ('l','t','r','a')); |
| 80 | map->add_global_bool_feature (HB_TAG ('l','t','r','m')); |
Behdad Esfahbod | 074ea78 | 2010-05-21 17:53:10 +0100 | [diff] [blame] | 81 | break; |
| 82 | case HB_DIRECTION_RTL: |
Behdad Esfahbod | e7ffcfa | 2013-02-14 11:05:56 -0500 | [diff] [blame] | 83 | map->add_global_bool_feature (HB_TAG ('r','t','l','a')); |
Behdad Esfahbod | ec54486 | 2013-02-14 11:25:10 -0500 | [diff] [blame] | 84 | map->add_feature (HB_TAG ('r','t','l','m'), 1, F_NONE); |
Behdad Esfahbod | 0e235d0 | 2010-05-28 20:21:47 -0400 | [diff] [blame] | 85 | break; |
| 86 | case HB_DIRECTION_TTB: |
| 87 | case HB_DIRECTION_BTT: |
Behdad Esfahbod | 3286fc0 | 2011-03-16 14:53:32 -0300 | [diff] [blame] | 88 | case HB_DIRECTION_INVALID: |
Behdad Esfahbod | 0e235d0 | 2010-05-28 20:21:47 -0400 | [diff] [blame] | 89 | default: |
| 90 | break; |
| 91 | } |
| 92 | |
Behdad Esfahbod | 3aeee51 | 2013-12-22 16:17:54 -0500 | [diff] [blame] | 93 | map->add_feature (HB_TAG ('f','r','a','c'), 1, F_NONE); |
| 94 | map->add_feature (HB_TAG ('n','u','m','r'), 1, F_NONE); |
| 95 | map->add_feature (HB_TAG ('d','n','o','m'), 1, F_NONE); |
| 96 | |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 97 | if (planner->shaper->collect_features) |
Behdad Esfahbod | 16c6a27 | 2012-08-02 09:38:28 -0400 | [diff] [blame] | 98 | planner->shaper->collect_features (planner); |
Behdad Esfahbod | e04685e | 2010-05-28 20:37:06 -0400 | [diff] [blame] | 99 | |
Behdad Esfahbod | ee9c3a1 | 2013-02-15 06:22:26 -0500 | [diff] [blame] | 100 | for (unsigned int i = 0; i < ARRAY_LENGTH (common_features); i++) |
| 101 | map->add_global_bool_feature (common_features[i]); |
Behdad Esfahbod | 89a2bc9 | 2011-05-31 15:18:13 -0400 | [diff] [blame] | 102 | |
| 103 | if (HB_DIRECTION_IS_HORIZONTAL (props->direction)) |
Behdad Esfahbod | ee9c3a1 | 2013-02-15 06:22:26 -0500 | [diff] [blame] | 104 | for (unsigned int i = 0; i < ARRAY_LENGTH (horizontal_features); i++) |
Behdad Esfahbod | 038c98f | 2013-02-15 07:41:07 -0500 | [diff] [blame] | 105 | map->add_feature (horizontal_features[i], 1, F_GLOBAL | |
| 106 | (horizontal_features[i] == HB_TAG('k','e','r','n') ? |
| 107 | F_HAS_FALLBACK : F_NONE)); |
Behdad Esfahbod | 89a2bc9 | 2011-05-31 15:18:13 -0400 | [diff] [blame] | 108 | else |
Behdad Esfahbod | f327aac | 2015-07-23 11:32:59 +0100 | [diff] [blame] | 109 | { |
Behdad Esfahbod | 0f98fe8 | 2015-07-23 11:52:11 +0100 | [diff] [blame] | 110 | /* We really want to find a 'vert' feature if there's any in the font, no |
| 111 | * matter which script/langsys it is listed (or not) under. |
| 112 | * See various bugs referenced from: |
ebraminio | 7c6937e | 2017-11-20 14:49:22 -0500 | [diff] [blame] | 113 | * https://github.com/harfbuzz/harfbuzz/issues/63 */ |
Behdad Esfahbod | 0f98fe8 | 2015-07-23 11:52:11 +0100 | [diff] [blame] | 114 | map->add_feature (HB_TAG ('v','e','r','t'), 1, F_GLOBAL | F_GLOBAL_SEARCH); |
Behdad Esfahbod | f327aac | 2015-07-23 11:32:59 +0100 | [diff] [blame] | 115 | } |
Behdad Esfahbod | 89a2bc9 | 2011-05-31 15:18:13 -0400 | [diff] [blame] | 116 | |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 117 | if (planner->shaper->override_features) |
Behdad Esfahbod | 16c6a27 | 2012-08-02 09:38:28 -0400 | [diff] [blame] | 118 | planner->shaper->override_features (planner); |
Behdad Esfahbod | d96838e | 2012-07-16 20:26:57 -0400 | [diff] [blame] | 119 | |
Behdad Esfahbod | 895fb5d | 2010-10-12 16:00:21 -0400 | [diff] [blame] | 120 | for (unsigned int i = 0; i < num_user_features; i++) { |
| 121 | const hb_feature_t *feature = &user_features[i]; |
Behdad Esfahbod | ec54486 | 2013-02-14 11:25:10 -0500 | [diff] [blame] | 122 | map->add_feature (feature->tag, feature->value, |
| 123 | (feature->start == 0 && feature->end == (unsigned int) -1) ? |
| 124 | F_GLOBAL : F_NONE); |
Behdad Esfahbod | e04685e | 2010-05-28 20:37:06 -0400 | [diff] [blame] | 125 | } |
Behdad Esfahbod | e89b7d2 | 2010-10-08 12:29:59 -0400 | [diff] [blame] | 126 | } |
Behdad Esfahbod | 0e235d0 | 2010-05-28 20:21:47 -0400 | [diff] [blame] | 127 | |
| 128 | |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 129 | /* |
| 130 | * shaper face data |
| 131 | */ |
| 132 | |
Behdad Esfahbod | 466b3e5 | 2017-02-03 16:43:25 -0800 | [diff] [blame] | 133 | HB_SHAPER_DATA_ENSURE_DEFINE(ot, face) |
| 134 | |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 135 | hb_ot_shaper_face_data_t * |
| 136 | _hb_ot_shaper_face_data_create (hb_face_t *face) |
| 137 | { |
| 138 | return _hb_ot_layout_create (face); |
| 139 | } |
| 140 | |
| 141 | void |
| 142 | _hb_ot_shaper_face_data_destroy (hb_ot_shaper_face_data_t *data) |
| 143 | { |
| 144 | _hb_ot_layout_destroy (data); |
| 145 | } |
| 146 | |
| 147 | |
| 148 | /* |
| 149 | * shaper font data |
| 150 | */ |
| 151 | |
Behdad Esfahbod | 466b3e5 | 2017-02-03 16:43:25 -0800 | [diff] [blame] | 152 | HB_SHAPER_DATA_ENSURE_DEFINE(ot, font) |
| 153 | |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 154 | struct hb_ot_shaper_font_data_t {}; |
| 155 | |
| 156 | hb_ot_shaper_font_data_t * |
Behdad Esfahbod | 89137e3 | 2016-02-22 16:00:59 +0900 | [diff] [blame] | 157 | _hb_ot_shaper_font_data_create (hb_font_t *font HB_UNUSED) |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 158 | { |
| 159 | return (hb_ot_shaper_font_data_t *) HB_SHAPER_DATA_SUCCEEDED; |
| 160 | } |
| 161 | |
| 162 | void |
| 163 | _hb_ot_shaper_font_data_destroy (hb_ot_shaper_font_data_t *data) |
| 164 | { |
| 165 | } |
| 166 | |
| 167 | |
| 168 | /* |
| 169 | * shaper shape_plan data |
| 170 | */ |
| 171 | |
| 172 | hb_ot_shaper_shape_plan_data_t * |
| 173 | _hb_ot_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan, |
| 174 | const hb_feature_t *user_features, |
Behdad Esfahbod | 72ada4f | 2016-09-10 03:57:24 -0700 | [diff] [blame] | 175 | unsigned int num_user_features, |
| 176 | const int *coords, |
| 177 | unsigned int num_coords) |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 178 | { |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 179 | hb_ot_shape_plan_t *plan = (hb_ot_shape_plan_t *) calloc (1, sizeof (hb_ot_shape_plan_t)); |
| 180 | if (unlikely (!plan)) |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 181 | return nullptr; |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 182 | |
Behdad Esfahbod | f9abbf8 | 2018-06-02 15:30:59 -0700 | [diff] [blame] | 183 | plan->init (); |
| 184 | |
Behdad Esfahbod | 5393e3a | 2012-08-02 09:24:35 -0400 | [diff] [blame] | 185 | hb_ot_shape_planner_t planner (shape_plan); |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 186 | |
Behdad Esfahbod | 9b37b4c | 2012-11-12 18:23:38 -0800 | [diff] [blame] | 187 | planner.shaper = hb_ot_shape_complex_categorize (&planner); |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 188 | |
Behdad Esfahbod | 72ada4f | 2016-09-10 03:57:24 -0700 | [diff] [blame] | 189 | hb_ot_shape_collect_features (&planner, &shape_plan->props, |
| 190 | user_features, num_user_features); |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 191 | |
Behdad Esfahbod | 72ada4f | 2016-09-10 03:57:24 -0700 | [diff] [blame] | 192 | planner.compile (*plan, coords, num_coords); |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 193 | |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 194 | if (plan->shaper->data_create) { |
| 195 | plan->data = plan->shaper->data_create (plan); |
Behdad Esfahbod | 42c183f | 2018-07-27 14:55:29 -0700 | [diff] [blame] | 196 | if (unlikely (!plan->data)) |
| 197 | { |
| 198 | free (plan); |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 199 | return nullptr; |
prrace | 2e25d8f | 2018-07-27 13:58:27 -0700 | [diff] [blame] | 200 | } |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | return plan; |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | void |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 207 | _hb_ot_shaper_shape_plan_data_destroy (hb_ot_shaper_shape_plan_data_t *plan) |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 208 | { |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 209 | if (plan->shaper->data_destroy) |
| 210 | plan->shaper->data_destroy (const_cast<void *> (plan->data)); |
Behdad Esfahbod | 4ba647e | 2012-07-30 09:53:06 -0400 | [diff] [blame] | 211 | |
Behdad Esfahbod | a60ba79 | 2018-05-01 19:01:25 -0400 | [diff] [blame] | 212 | plan->fini (); |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 213 | |
| 214 | free (plan); |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | |
| 218 | /* |
| 219 | * shaper |
| 220 | */ |
| 221 | |
Behdad Esfahbod | b9f199c | 2012-04-14 20:23:58 -0400 | [diff] [blame] | 222 | struct hb_ot_shape_context_t |
| 223 | { |
Behdad Esfahbod | b9f199c | 2012-04-14 20:23:58 -0400 | [diff] [blame] | 224 | hb_ot_shape_plan_t *plan; |
| 225 | hb_font_t *font; |
| 226 | hb_face_t *face; |
| 227 | hb_buffer_t *buffer; |
| 228 | const hb_feature_t *user_features; |
| 229 | unsigned int num_user_features; |
| 230 | |
| 231 | /* Transient stuff */ |
Behdad Esfahbod | e2b8780 | 2016-12-22 14:40:19 -0600 | [diff] [blame] | 232 | bool fallback_positioning; |
| 233 | bool fallback_glyph_classes; |
Behdad Esfahbod | b9f199c | 2012-04-14 20:23:58 -0400 | [diff] [blame] | 234 | hb_direction_t target_direction; |
Behdad Esfahbod | b9f199c | 2012-04-14 20:23:58 -0400 | [diff] [blame] | 235 | }; |
| 236 | |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 237 | |
| 238 | |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 239 | /* Main shaper */ |
| 240 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 241 | |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 242 | /* Prepare */ |
| 243 | |
Behdad Esfahbod | b9f199c | 2012-04-14 20:23:58 -0400 | [diff] [blame] | 244 | static void |
| 245 | hb_set_unicode_props (hb_buffer_t *buffer) |
Behdad Esfahbod | 3a852ae | 2010-11-03 16:37:24 -0400 | [diff] [blame] | 246 | { |
Behdad Esfahbod | aa72641 | 2011-07-21 11:34:59 -0400 | [diff] [blame] | 247 | unsigned int count = buffer->len; |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 248 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | 0e33614 | 2012-04-12 10:06:52 -0400 | [diff] [blame] | 249 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 6986208 | 2015-11-04 18:46:22 -0800 | [diff] [blame] | 250 | _hb_glyph_info_set_unicode_props (&info[i], buffer); |
Behdad Esfahbod | 3a852ae | 2010-11-03 16:37:24 -0400 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | static void |
Behdad Esfahbod | 6912e47 | 2012-09-01 20:38:45 -0400 | [diff] [blame] | 254 | hb_insert_dotted_circle (hb_buffer_t *buffer, hb_font_t *font) |
| 255 | { |
Behdad Esfahbod | 0c7df22 | 2012-11-13 14:42:35 -0800 | [diff] [blame] | 256 | if (!(buffer->flags & HB_BUFFER_FLAG_BOT) || |
Behdad Esfahbod | 763e546 | 2014-08-02 16:17:44 -0400 | [diff] [blame] | 257 | buffer->context_len[0] || |
Behdad Esfahbod | f2eb3fa | 2012-09-25 21:35:35 -0400 | [diff] [blame] | 258 | _hb_glyph_info_get_general_category (&buffer->info[0]) != |
Behdad Esfahbod | 6912e47 | 2012-09-01 20:38:45 -0400 | [diff] [blame] | 259 | HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) |
| 260 | return; |
| 261 | |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 262 | if (!font->has_glyph (0x25CCu)) |
Behdad Esfahbod | 6912e47 | 2012-09-01 20:38:45 -0400 | [diff] [blame] | 263 | return; |
| 264 | |
Behdad Esfahbod | 595d2b9 | 2014-07-26 18:44:15 -0400 | [diff] [blame] | 265 | hb_glyph_info_t dottedcircle = {0}; |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 266 | dottedcircle.codepoint = 0x25CCu; |
Behdad Esfahbod | 6986208 | 2015-11-04 18:46:22 -0800 | [diff] [blame] | 267 | _hb_glyph_info_set_unicode_props (&dottedcircle, buffer); |
Behdad Esfahbod | 6912e47 | 2012-09-01 20:38:45 -0400 | [diff] [blame] | 268 | |
| 269 | buffer->clear_output (); |
| 270 | |
| 271 | buffer->idx = 0; |
| 272 | hb_glyph_info_t info = dottedcircle; |
| 273 | info.cluster = buffer->cur().cluster; |
| 274 | info.mask = buffer->cur().mask; |
| 275 | buffer->output_info (info); |
Behdad Esfahbod | 7185b27 | 2018-05-31 20:03:00 -0700 | [diff] [blame] | 276 | while (buffer->idx < buffer->len && buffer->successful) |
Behdad Esfahbod | 6912e47 | 2012-09-01 20:38:45 -0400 | [diff] [blame] | 277 | buffer->next_glyph (); |
| 278 | |
| 279 | buffer->swap_buffers (); |
| 280 | } |
| 281 | |
| 282 | static void |
Behdad Esfahbod | aa72641 | 2011-07-21 11:34:59 -0400 | [diff] [blame] | 283 | hb_form_clusters (hb_buffer_t *buffer) |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 284 | { |
Behdad Esfahbod | 7cc3480 | 2017-09-04 20:04:59 -0700 | [diff] [blame] | 285 | if (!(buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_NON_ASCII)) |
Behdad Esfahbod | 376d587 | 2015-07-22 16:51:12 +0100 | [diff] [blame] | 286 | return; |
| 287 | |
Behdad Esfahbod | 62c2711 | 2016-02-22 15:07:20 +0900 | [diff] [blame] | 288 | /* Loop duplicated in hb_ensure_native_direction(), and in _hb-coretext.cc */ |
Behdad Esfahbod | 701112d | 2015-07-22 15:42:20 +0100 | [diff] [blame] | 289 | unsigned int base = 0; |
Behdad Esfahbod | aa72641 | 2011-07-21 11:34:59 -0400 | [diff] [blame] | 290 | unsigned int count = buffer->len; |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 291 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 292 | for (unsigned int i = 1; i < count; i++) |
Behdad Esfahbod | 701112d | 2015-07-22 15:42:20 +0100 | [diff] [blame] | 293 | { |
Behdad Esfahbod | 815bdd7 | 2016-02-22 18:22:44 +0900 | [diff] [blame] | 294 | if (likely (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&info[i])) && |
| 295 | !_hb_glyph_info_is_joiner (&info[i]))) |
Behdad Esfahbod | 701112d | 2015-07-22 15:42:20 +0100 | [diff] [blame] | 296 | { |
Behdad Esfahbod | 7cc3480 | 2017-09-04 20:04:59 -0700 | [diff] [blame] | 297 | if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES) |
| 298 | buffer->merge_clusters (base, i); |
| 299 | else |
| 300 | buffer->unsafe_to_break (base, i); |
Behdad Esfahbod | 701112d | 2015-07-22 15:42:20 +0100 | [diff] [blame] | 301 | base = i; |
| 302 | } |
| 303 | } |
Behdad Esfahbod | 7cc3480 | 2017-09-04 20:04:59 -0700 | [diff] [blame] | 304 | if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES) |
| 305 | buffer->merge_clusters (base, count); |
| 306 | else |
| 307 | buffer->unsafe_to_break (base, count); |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 308 | } |
| 309 | |
Behdad Esfahbod | 967240d | 2010-10-05 23:00:05 -0400 | [diff] [blame] | 310 | static void |
Behdad Esfahbod | aa72641 | 2011-07-21 11:34:59 -0400 | [diff] [blame] | 311 | hb_ensure_native_direction (hb_buffer_t *buffer) |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 312 | { |
Behdad Esfahbod | aa72641 | 2011-07-21 11:34:59 -0400 | [diff] [blame] | 313 | hb_direction_t direction = buffer->props.direction; |
Behdad Esfahbod | f673cfb | 2018-05-07 13:58:32 -0700 | [diff] [blame] | 314 | hb_direction_t horiz_dir = hb_script_get_horizontal_direction (buffer->props.script); |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 315 | |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 316 | /* TODO vertical: |
| 317 | * The only BTT vertical script is Ogham, but it's not clear to me whether OpenType |
| 318 | * Ogham fonts are supposed to be implemented BTT or not. Need to research that |
| 319 | * first. */ |
Behdad Esfahbod | f673cfb | 2018-05-07 13:58:32 -0700 | [diff] [blame] | 320 | if ((HB_DIRECTION_IS_HORIZONTAL (direction) && |
| 321 | direction != horiz_dir && horiz_dir != HB_DIRECTION_INVALID) || |
| 322 | (HB_DIRECTION_IS_VERTICAL (direction) && |
| 323 | direction != HB_DIRECTION_TTB)) |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 324 | { |
Behdad Esfahbod | a60e2cf | 2015-07-22 15:49:08 +0100 | [diff] [blame] | 325 | /* Same loop as hb_form_clusters(). |
| 326 | * Since form_clusters() merged clusters already, we don't merge. */ |
| 327 | unsigned int base = 0; |
| 328 | unsigned int count = buffer->len; |
| 329 | hb_glyph_info_t *info = buffer->info; |
| 330 | for (unsigned int i = 1; i < count; i++) |
| 331 | { |
| 332 | if (likely (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&info[i])))) |
| 333 | { |
Behdad Esfahbod | 376d587 | 2015-07-22 16:51:12 +0100 | [diff] [blame] | 334 | if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS) |
| 335 | buffer->merge_clusters (base, i); |
Behdad Esfahbod | f883de6 | 2015-09-01 16:23:40 +0100 | [diff] [blame] | 336 | buffer->reverse_range (base, i); |
| 337 | |
Behdad Esfahbod | a60e2cf | 2015-07-22 15:49:08 +0100 | [diff] [blame] | 338 | base = i; |
| 339 | } |
| 340 | } |
Behdad Esfahbod | 376d587 | 2015-07-22 16:51:12 +0100 | [diff] [blame] | 341 | if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS) |
| 342 | buffer->merge_clusters (base, count); |
Behdad Esfahbod | f883de6 | 2015-09-01 16:23:40 +0100 | [diff] [blame] | 343 | buffer->reverse_range (base, count); |
Behdad Esfahbod | a60e2cf | 2015-07-22 15:49:08 +0100 | [diff] [blame] | 344 | |
| 345 | buffer->reverse (); |
| 346 | |
Behdad Esfahbod | aa72641 | 2011-07-21 11:34:59 -0400 | [diff] [blame] | 347 | buffer->props.direction = HB_DIRECTION_REVERSE (buffer->props.direction); |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 348 | } |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | |
| 352 | /* Substitute */ |
| 353 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 354 | static inline void |
| 355 | hb_ot_mirror_chars (hb_ot_shape_context_t *c) |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 356 | { |
Behdad Esfahbod | bbbbe80 | 2010-12-07 16:22:02 -0500 | [diff] [blame] | 357 | if (HB_DIRECTION_IS_FORWARD (c->target_direction)) |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 358 | return; |
| 359 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 360 | hb_buffer_t *buffer = c->buffer; |
| 361 | hb_unicode_funcs_t *unicode = buffer->unicode; |
Behdad Esfahbod | 5497a8a | 2013-12-22 20:48:53 -0500 | [diff] [blame] | 362 | hb_mask_t rtlm_mask = c->plan->rtlm_mask; |
Behdad Esfahbod | 4e4ef24 | 2010-07-23 17:22:11 -0400 | [diff] [blame] | 363 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 364 | unsigned int count = buffer->len; |
| 365 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 366 | for (unsigned int i = 0; i < count; i++) { |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 367 | hb_codepoint_t codepoint = unicode->mirroring (info[i].codepoint); |
Behdad Esfahbod | 7b8b63a | 2015-07-22 15:24:26 +0100 | [diff] [blame] | 368 | if (likely (codepoint == info[i].codepoint || !c->font->has_glyph (codepoint))) |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 369 | info[i].mask |= rtlm_mask; |
Behdad Esfahbod | 1094a29 | 2010-05-21 17:58:20 +0100 | [diff] [blame] | 370 | else |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 371 | info[i].codepoint = codepoint; |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 375 | static inline void |
Behdad Esfahbod | 3aeee51 | 2013-12-22 16:17:54 -0500 | [diff] [blame] | 376 | hb_ot_shape_setup_masks_fraction (hb_ot_shape_context_t *c) |
| 377 | { |
Behdad Esfahbod | e3e4bb0 | 2015-11-04 18:58:02 -0800 | [diff] [blame] | 378 | if (!(c->buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_NON_ASCII) || |
| 379 | !c->plan->has_frac) |
Behdad Esfahbod | 5497a8a | 2013-12-22 20:48:53 -0500 | [diff] [blame] | 380 | return; |
| 381 | |
Behdad Esfahbod | 3aeee51 | 2013-12-22 16:17:54 -0500 | [diff] [blame] | 382 | hb_buffer_t *buffer = c->buffer; |
Behdad Esfahbod | 3aeee51 | 2013-12-22 16:17:54 -0500 | [diff] [blame] | 383 | |
Khaled Hosny | 2452543 | 2017-01-18 22:48:13 +0200 | [diff] [blame] | 384 | hb_mask_t pre_mask, post_mask; |
| 385 | if (HB_DIRECTION_IS_FORWARD (buffer->props.direction)) |
| 386 | { |
| 387 | pre_mask = c->plan->numr_mask | c->plan->frac_mask; |
| 388 | post_mask = c->plan->frac_mask | c->plan->dnom_mask; |
| 389 | } |
| 390 | else |
| 391 | { |
| 392 | pre_mask = c->plan->frac_mask | c->plan->dnom_mask; |
| 393 | post_mask = c->plan->numr_mask | c->plan->frac_mask; |
| 394 | } |
| 395 | |
Behdad Esfahbod | 3aeee51 | 2013-12-22 16:17:54 -0500 | [diff] [blame] | 396 | unsigned int count = buffer->len; |
| 397 | hb_glyph_info_t *info = buffer->info; |
| 398 | for (unsigned int i = 0; i < count; i++) |
| 399 | { |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 400 | if (info[i].codepoint == 0x2044u) /* FRACTION SLASH */ |
Behdad Esfahbod | 3aeee51 | 2013-12-22 16:17:54 -0500 | [diff] [blame] | 401 | { |
Behdad Esfahbod | 3aeee51 | 2013-12-22 16:17:54 -0500 | [diff] [blame] | 402 | unsigned int start = i, end = i + 1; |
| 403 | while (start && |
| 404 | _hb_glyph_info_get_general_category (&info[start - 1]) == |
| 405 | HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER) |
| 406 | start--; |
| 407 | while (end < count && |
| 408 | _hb_glyph_info_get_general_category (&info[end]) == |
| 409 | HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER) |
| 410 | end++; |
| 411 | |
Behdad Esfahbod | c449d2d | 2017-08-30 17:28:22 -0700 | [diff] [blame] | 412 | buffer->unsafe_to_break (start, end); |
| 413 | |
Behdad Esfahbod | a7e8bbb | 2013-12-22 19:33:35 -0500 | [diff] [blame] | 414 | for (unsigned int j = start; j < i; j++) |
Khaled Hosny | 2452543 | 2017-01-18 22:48:13 +0200 | [diff] [blame] | 415 | info[j].mask |= pre_mask; |
Behdad Esfahbod | 5497a8a | 2013-12-22 20:48:53 -0500 | [diff] [blame] | 416 | info[i].mask |= c->plan->frac_mask; |
Behdad Esfahbod | a7e8bbb | 2013-12-22 19:33:35 -0500 | [diff] [blame] | 417 | for (unsigned int j = i + 1; j < end; j++) |
Khaled Hosny | 2452543 | 2017-01-18 22:48:13 +0200 | [diff] [blame] | 418 | info[j].mask |= post_mask; |
Behdad Esfahbod | 3aeee51 | 2013-12-22 16:17:54 -0500 | [diff] [blame] | 419 | |
| 420 | i = end - 1; |
| 421 | } |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | static inline void |
Behdad Esfahbod | 7393251 | 2013-12-21 00:18:18 -0500 | [diff] [blame] | 426 | hb_ot_shape_initialize_masks (hb_ot_shape_context_t *c) |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 427 | { |
| 428 | hb_ot_map_t *map = &c->plan->map; |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 429 | hb_buffer_t *buffer = c->buffer; |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 430 | |
| 431 | hb_mask_t global_mask = map->get_global_mask (); |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 432 | buffer->reset_masks (global_mask); |
Behdad Esfahbod | 7393251 | 2013-12-21 00:18:18 -0500 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | static inline void |
| 436 | hb_ot_shape_setup_masks (hb_ot_shape_context_t *c) |
| 437 | { |
| 438 | hb_ot_map_t *map = &c->plan->map; |
| 439 | hb_buffer_t *buffer = c->buffer; |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 440 | |
Behdad Esfahbod | 3aeee51 | 2013-12-22 16:17:54 -0500 | [diff] [blame] | 441 | hb_ot_shape_setup_masks_fraction (c); |
| 442 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 443 | if (c->plan->shaper->setup_masks) |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 444 | c->plan->shaper->setup_masks (c->plan, buffer, c->font); |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 445 | |
| 446 | for (unsigned int i = 0; i < c->num_user_features; i++) |
| 447 | { |
| 448 | const hb_feature_t *feature = &c->user_features[i]; |
| 449 | if (!(feature->start == 0 && feature->end == (unsigned int)-1)) { |
| 450 | unsigned int shift; |
| 451 | hb_mask_t mask = map->get_mask (feature->tag, &shift); |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 452 | buffer->set_masks (feature->value << shift, mask, feature->start, feature->end); |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | } |
| 456 | |
Behdad Esfahbod | 8cfbc30 | 2015-07-22 18:41:10 +0100 | [diff] [blame] | 457 | static void |
| 458 | hb_ot_zero_width_default_ignorables (hb_ot_shape_context_t *c) |
| 459 | { |
| 460 | hb_buffer_t *buffer = c->buffer; |
| 461 | |
Behdad Esfahbod | 6986208 | 2015-11-04 18:46:22 -0800 | [diff] [blame] | 462 | if (!(buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES) || |
Behdad Esfahbod | 3b1e97f | 2018-01-10 03:35:20 +0100 | [diff] [blame] | 463 | (buffer->flags & HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES) || |
| 464 | (buffer->flags & HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES)) |
Behdad Esfahbod | 8cfbc30 | 2015-07-22 18:41:10 +0100 | [diff] [blame] | 465 | return; |
| 466 | |
| 467 | unsigned int count = buffer->len; |
| 468 | hb_glyph_info_t *info = buffer->info; |
| 469 | hb_glyph_position_t *pos = buffer->pos; |
| 470 | unsigned int i = 0; |
| 471 | for (i = 0; i < count; i++) |
| 472 | if (unlikely (_hb_glyph_info_is_default_ignorable (&info[i]))) |
| 473 | pos[i].x_advance = pos[i].y_advance = pos[i].x_offset = pos[i].y_offset = 0; |
| 474 | } |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 475 | |
| 476 | static void |
| 477 | hb_ot_hide_default_ignorables (hb_ot_shape_context_t *c) |
| 478 | { |
| 479 | hb_buffer_t *buffer = c->buffer; |
| 480 | |
Behdad Esfahbod | 6986208 | 2015-11-04 18:46:22 -0800 | [diff] [blame] | 481 | if (!(buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES) || |
| 482 | (buffer->flags & HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES)) |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 483 | return; |
| 484 | |
| 485 | unsigned int count = buffer->len; |
| 486 | hb_glyph_info_t *info = buffer->info; |
| 487 | hb_glyph_position_t *pos = buffer->pos; |
| 488 | unsigned int i = 0; |
| 489 | for (i = 0; i < count; i++) |
| 490 | { |
Behdad Esfahbod | 4ba796b | 2015-07-22 17:41:31 +0100 | [diff] [blame] | 491 | if (unlikely (_hb_glyph_info_is_default_ignorable (&info[i]))) |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 492 | break; |
| 493 | } |
| 494 | |
| 495 | /* No default-ignorables found; return. */ |
| 496 | if (i == count) |
| 497 | return; |
| 498 | |
| 499 | hb_codepoint_t space; |
Behdad Esfahbod | 3b1e97f | 2018-01-10 03:35:20 +0100 | [diff] [blame] | 500 | if (!(buffer->flags & HB_BUFFER_FLAG_REMOVE_DEFAULT_IGNORABLES) && |
| 501 | c->font->get_nominal_glyph (' ', &space)) |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 502 | { |
| 503 | /* Replace default-ignorables with a zero-advance space glyph. */ |
| 504 | for (/*continue*/; i < count; i++) |
| 505 | { |
Behdad Esfahbod | 4ba796b | 2015-07-22 17:41:31 +0100 | [diff] [blame] | 506 | if (_hb_glyph_info_is_default_ignorable (&info[i])) |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 507 | info[i].codepoint = space; |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | else |
| 511 | { |
Behdad Esfahbod | 2dbd3d2 | 2015-07-22 18:28:39 +0100 | [diff] [blame] | 512 | /* Merge clusters and delete default-ignorables. |
| 513 | * NOTE! We can't use out-buffer as we have positioning data. */ |
| 514 | unsigned int j = i; |
| 515 | for (; i < count; i++) |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 516 | { |
Behdad Esfahbod | 2dbd3d2 | 2015-07-22 18:28:39 +0100 | [diff] [blame] | 517 | if (_hb_glyph_info_is_default_ignorable (&info[i])) |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 518 | { |
Behdad Esfahbod | 2dbd3d2 | 2015-07-22 18:28:39 +0100 | [diff] [blame] | 519 | /* Merge clusters. |
| 520 | * Same logic as buffer->delete_glyph(), but for in-place removal. */ |
| 521 | |
| 522 | unsigned int cluster = info[i].cluster; |
| 523 | if (i + 1 < count && cluster == info[i + 1].cluster) |
| 524 | continue; /* Cluster survives; do nothing. */ |
| 525 | |
| 526 | if (j) |
| 527 | { |
| 528 | /* Merge cluster backward. */ |
| 529 | if (cluster < info[j - 1].cluster) |
| 530 | { |
Behdad Esfahbod | e2a2b5b | 2017-08-10 20:10:12 -0700 | [diff] [blame] | 531 | unsigned int mask = info[i].mask; |
Behdad Esfahbod | 2dbd3d2 | 2015-07-22 18:28:39 +0100 | [diff] [blame] | 532 | unsigned int old_cluster = info[j - 1].cluster; |
| 533 | for (unsigned k = j; k && info[k - 1].cluster == old_cluster; k--) |
Behdad Esfahbod | e2a2b5b | 2017-08-10 20:10:12 -0700 | [diff] [blame] | 534 | buffer->set_cluster (info[k - 1], cluster, mask); |
Behdad Esfahbod | 2dbd3d2 | 2015-07-22 18:28:39 +0100 | [diff] [blame] | 535 | } |
| 536 | continue; |
| 537 | } |
| 538 | |
| 539 | if (i + 1 < count) |
| 540 | buffer->merge_clusters (i, i + 2); /* Merge cluster forward. */ |
| 541 | |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 542 | continue; |
| 543 | } |
Behdad Esfahbod | 2dbd3d2 | 2015-07-22 18:28:39 +0100 | [diff] [blame] | 544 | |
| 545 | if (j != i) |
| 546 | { |
| 547 | info[j] = info[i]; |
| 548 | pos[j] = pos[i]; |
| 549 | } |
| 550 | j++; |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 551 | } |
Behdad Esfahbod | 2dbd3d2 | 2015-07-22 18:28:39 +0100 | [diff] [blame] | 552 | buffer->len = j; |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 553 | } |
| 554 | } |
| 555 | |
| 556 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 557 | static inline void |
Behdad Esfahbod | b00321e | 2012-08-09 22:33:32 -0400 | [diff] [blame] | 558 | hb_ot_map_glyphs_fast (hb_buffer_t *buffer) |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 559 | { |
Behdad Esfahbod | b00321e | 2012-08-09 22:33:32 -0400 | [diff] [blame] | 560 | /* Normalization process sets up glyph_index(), we just copy it. */ |
| 561 | unsigned int count = buffer->len; |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 562 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | b00321e | 2012-08-09 22:33:32 -0400 | [diff] [blame] | 563 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 564 | info[i].codepoint = info[i].glyph_index(); |
Behdad Esfahbod | e47b772 | 2015-08-18 18:42:47 +0100 | [diff] [blame] | 565 | |
| 566 | buffer->content_type = HB_BUFFER_CONTENT_TYPE_GLYPHS; |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 567 | } |
| 568 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 569 | static inline void |
Behdad Esfahbod | 1a0f4aa | 2016-12-22 13:33:54 -0600 | [diff] [blame] | 570 | hb_synthesize_glyph_classes (hb_ot_shape_context_t *c) |
| 571 | { |
| 572 | unsigned int count = c->buffer->len; |
| 573 | hb_glyph_info_t *info = c->buffer->info; |
| 574 | for (unsigned int i = 0; i < count; i++) |
| 575 | { |
| 576 | hb_ot_layout_glyph_props_flags_t klass; |
| 577 | |
| 578 | /* Never mark default-ignorables as marks. |
| 579 | * They won't get in the way of lookups anyway, |
| 580 | * but having them as mark will cause them to be skipped |
| 581 | * over if the lookup-flag says so, but at least for the |
| 582 | * Mongolian variation selectors, looks like Uniscribe |
| 583 | * marks them as non-mark. Some Mongolian fonts without |
| 584 | * GDEF rely on this. Another notable character that |
| 585 | * this applies to is COMBINING GRAPHEME JOINER. */ |
| 586 | klass = (_hb_glyph_info_get_general_category (&info[i]) != |
| 587 | HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK || |
| 588 | _hb_glyph_info_is_default_ignorable (&info[i])) ? |
| 589 | HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH : |
| 590 | HB_OT_LAYOUT_GLYPH_PROPS_MARK; |
| 591 | _hb_glyph_info_set_glyph_props (&info[i], klass); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | static inline void |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 596 | hb_ot_substitute_default (hb_ot_shape_context_t *c) |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 597 | { |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 598 | hb_buffer_t *buffer = c->buffer; |
| 599 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 600 | hb_ot_mirror_chars (c); |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 601 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 602 | HB_BUFFER_ALLOCATE_VAR (buffer, glyph_index); |
Behdad Esfahbod | b00321e | 2012-08-09 22:33:32 -0400 | [diff] [blame] | 603 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 604 | _hb_ot_shape_normalize (c->plan, buffer, c->font); |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 605 | |
| 606 | hb_ot_shape_setup_masks (c); |
| 607 | |
Behdad Esfahbod | 3992b5e | 2012-09-01 19:20:41 -0400 | [diff] [blame] | 608 | /* This is unfortunate to go here, but necessary... */ |
Behdad Esfahbod | e2b8780 | 2016-12-22 14:40:19 -0600 | [diff] [blame] | 609 | if (c->fallback_positioning) |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 610 | _hb_ot_shape_fallback_position_recategorize_marks (c->plan, c->font, buffer); |
Behdad Esfahbod | 3992b5e | 2012-09-01 19:20:41 -0400 | [diff] [blame] | 611 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 612 | hb_ot_map_glyphs_fast (buffer); |
Behdad Esfahbod | b00321e | 2012-08-09 22:33:32 -0400 | [diff] [blame] | 613 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 614 | HB_BUFFER_DEALLOCATE_VAR (buffer, glyph_index); |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 615 | } |
| 616 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 617 | static inline void |
Behdad Esfahbod | c86f932 | 2011-07-25 00:44:50 -0400 | [diff] [blame] | 618 | hb_ot_substitute_complex (hb_ot_shape_context_t *c) |
| 619 | { |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 620 | hb_buffer_t *buffer = c->buffer; |
| 621 | |
| 622 | hb_ot_layout_substitute_start (c->font, buffer); |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 623 | |
Behdad Esfahbod | 1a0f4aa | 2016-12-22 13:33:54 -0600 | [diff] [blame] | 624 | if (!hb_ot_layout_has_glyph_classes (c->face)) |
| 625 | hb_synthesize_glyph_classes (c); |
| 626 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 627 | c->plan->substitute (c->font, buffer); |
Behdad Esfahbod | 748b989 | 2018-01-09 17:55:17 +0100 | [diff] [blame] | 628 | |
Behdad Esfahbod | db5d430 | 2018-07-17 18:14:45 +0200 | [diff] [blame] | 629 | if (0) /* XXX Call morx instead. */ |
| 630 | hb_aat_layout_substitute (c->font, c->buffer); |
Behdad Esfahbod | c86f932 | 2011-07-25 00:44:50 -0400 | [diff] [blame] | 631 | } |
| 632 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 633 | static inline void |
| 634 | hb_ot_substitute (hb_ot_shape_context_t *c) |
| 635 | { |
| 636 | hb_ot_substitute_default (c); |
Behdad Esfahbod | 0f40732 | 2015-11-04 22:28:44 -0800 | [diff] [blame] | 637 | |
| 638 | _hb_buffer_allocate_gsubgpos_vars (c->buffer); |
| 639 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 640 | hb_ot_substitute_complex (c); |
| 641 | } |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 642 | |
| 643 | /* Position */ |
| 644 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 645 | static inline void |
Jonathan Kew | 798e418 | 2014-06-10 13:10:30 +0100 | [diff] [blame] | 646 | adjust_mark_offsets (hb_glyph_position_t *pos) |
| 647 | { |
| 648 | pos->x_offset -= pos->x_advance; |
| 649 | pos->y_offset -= pos->y_advance; |
| 650 | } |
| 651 | |
| 652 | static inline void |
| 653 | zero_mark_width (hb_glyph_position_t *pos) |
| 654 | { |
| 655 | pos->x_advance = 0; |
| 656 | pos->y_advance = 0; |
| 657 | } |
| 658 | |
| 659 | static inline void |
Jonathan Kew | 798e418 | 2014-06-10 13:10:30 +0100 | [diff] [blame] | 660 | zero_mark_widths_by_gdef (hb_buffer_t *buffer, bool adjust_offsets) |
Behdad Esfahbod | d785fa0 | 2013-05-20 09:18:52 -0400 | [diff] [blame] | 661 | { |
| 662 | unsigned int count = buffer->len; |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 663 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | d785fa0 | 2013-05-20 09:18:52 -0400 | [diff] [blame] | 664 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 665 | if (_hb_glyph_info_is_mark (&info[i])) |
Behdad Esfahbod | d785fa0 | 2013-05-20 09:18:52 -0400 | [diff] [blame] | 666 | { |
Jonathan Kew | 798e418 | 2014-06-10 13:10:30 +0100 | [diff] [blame] | 667 | if (adjust_offsets) |
| 668 | adjust_mark_offsets (&buffer->pos[i]); |
| 669 | zero_mark_width (&buffer->pos[i]); |
Behdad Esfahbod | d785fa0 | 2013-05-20 09:18:52 -0400 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | |
| 673 | static inline void |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 674 | hb_ot_position_default (hb_ot_shape_context_t *c) |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 675 | { |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 676 | hb_direction_t direction = c->buffer->props.direction; |
Behdad Esfahbod | 967240d | 2010-10-05 23:00:05 -0400 | [diff] [blame] | 677 | unsigned int count = c->buffer->len; |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 678 | hb_glyph_info_t *info = c->buffer->info; |
| 679 | hb_glyph_position_t *pos = c->buffer->pos; |
Behdad Esfahbod | 5680002 | 2013-02-12 09:44:57 -0500 | [diff] [blame] | 680 | |
Behdad Esfahbod | bee901b | 2015-11-04 19:28:17 -0800 | [diff] [blame] | 681 | if (HB_DIRECTION_IS_HORIZONTAL (direction)) |
| 682 | { |
| 683 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | bee901b | 2015-11-04 19:28:17 -0800 | [diff] [blame] | 684 | pos[i].x_advance = c->font->get_glyph_h_advance (info[i].codepoint); |
Behdad Esfahbod | 67a36a7 | 2015-11-26 18:48:42 -0500 | [diff] [blame] | 685 | /* The nil glyph_h_origin() func returns 0, so no need to apply it. */ |
Behdad Esfahbod | 5bc28b5 | 2015-11-04 21:53:16 -0800 | [diff] [blame] | 686 | if (c->font->has_glyph_h_origin_func ()) |
| 687 | for (unsigned int i = 0; i < count; i++) |
| 688 | c->font->subtract_glyph_h_origin (info[i].codepoint, |
| 689 | &pos[i].x_offset, |
| 690 | &pos[i].y_offset); |
Behdad Esfahbod | bee901b | 2015-11-04 19:28:17 -0800 | [diff] [blame] | 691 | } |
| 692 | else |
| 693 | { |
| 694 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 67a36a7 | 2015-11-26 18:48:42 -0500 | [diff] [blame] | 695 | { |
Behdad Esfahbod | bee901b | 2015-11-04 19:28:17 -0800 | [diff] [blame] | 696 | pos[i].y_advance = c->font->get_glyph_v_advance (info[i].codepoint); |
Behdad Esfahbod | 67a36a7 | 2015-11-26 18:48:42 -0500 | [diff] [blame] | 697 | c->font->subtract_glyph_v_origin (info[i].codepoint, |
| 698 | &pos[i].x_offset, |
| 699 | &pos[i].y_offset); |
| 700 | } |
Behdad Esfahbod | 5680002 | 2013-02-12 09:44:57 -0500 | [diff] [blame] | 701 | } |
Behdad Esfahbod | 49ef630 | 2015-11-04 17:27:07 -0800 | [diff] [blame] | 702 | if (c->buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_SPACE_FALLBACK) |
| 703 | _hb_ot_shape_fallback_spaces (c->plan, c->font, c->buffer); |
Behdad Esfahbod | 4b01109 | 2013-09-13 20:17:42 -0400 | [diff] [blame] | 704 | } |
| 705 | |
Behdad Esfahbod | e2b8780 | 2016-12-22 14:40:19 -0600 | [diff] [blame] | 706 | static inline void |
Behdad Esfahbod | 4b01109 | 2013-09-13 20:17:42 -0400 | [diff] [blame] | 707 | hb_ot_position_complex (hb_ot_shape_context_t *c) |
| 708 | { |
Behdad Esfahbod | 4b01109 | 2013-09-13 20:17:42 -0400 | [diff] [blame] | 709 | unsigned int count = c->buffer->len; |
Behdad Esfahbod | 9786fcd | 2017-10-03 17:22:43 +0200 | [diff] [blame] | 710 | hb_glyph_info_t *info = c->buffer->info; |
| 711 | hb_glyph_position_t *pos = c->buffer->pos; |
Behdad Esfahbod | 8474231 | 2016-02-11 16:27:41 +0700 | [diff] [blame] | 712 | |
Jonathan Kew | 798e418 | 2014-06-10 13:10:30 +0100 | [diff] [blame] | 713 | /* If the font has no GPOS, AND, no fallback positioning will |
| 714 | * happen, AND, direction is forward, then when zeroing mark |
| 715 | * widths, we shift the mark with it, such that the mark |
| 716 | * is positioned hanging over the previous glyph. When |
| 717 | * direction is backward we don't shift and it will end up |
| 718 | * hanging over the next glyph after the final reordering. |
| 719 | * If fallback positinoing happens or GPOS is present, we don't |
| 720 | * care. |
| 721 | */ |
Behdad Esfahbod | e2b8780 | 2016-12-22 14:40:19 -0600 | [diff] [blame] | 722 | bool adjust_offsets_when_zeroing = c->fallback_positioning && |
| 723 | !c->plan->shaper->fallback_position && |
| 724 | HB_DIRECTION_IS_FORWARD (c->buffer->props.direction); |
Behdad Esfahbod | 5680002 | 2013-02-12 09:44:57 -0500 | [diff] [blame] | 725 | |
Behdad Esfahbod | 9786fcd | 2017-10-03 17:22:43 +0200 | [diff] [blame] | 726 | /* We change glyph origin to what GPOS expects (horizontal), apply GPOS, change it back. */ |
| 727 | |
| 728 | /* The nil glyph_h_origin() func returns 0, so no need to apply it. */ |
| 729 | if (c->font->has_glyph_h_origin_func ()) |
| 730 | for (unsigned int i = 0; i < count; i++) |
| 731 | c->font->add_glyph_h_origin (info[i].codepoint, |
| 732 | &pos[i].x_offset, |
| 733 | &pos[i].y_offset); |
| 734 | |
| 735 | hb_ot_layout_position_start (c->font, c->buffer); |
| 736 | |
Behdad Esfahbod | 71b4c99 | 2013-10-28 00:20:59 +0100 | [diff] [blame] | 737 | switch (c->plan->shaper->zero_width_marks) |
Behdad Esfahbod | 5680002 | 2013-02-12 09:44:57 -0500 | [diff] [blame] | 738 | { |
Behdad Esfahbod | 127daf1 | 2013-05-20 09:11:35 -0400 | [diff] [blame] | 739 | case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY: |
Jonathan Kew | 798e418 | 2014-06-10 13:10:30 +0100 | [diff] [blame] | 740 | zero_mark_widths_by_gdef (c->buffer, adjust_offsets_when_zeroing); |
Behdad Esfahbod | 5680002 | 2013-02-12 09:44:57 -0500 | [diff] [blame] | 741 | break; |
| 742 | |
| 743 | default: |
| 744 | case HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE: |
Behdad Esfahbod | 127daf1 | 2013-05-20 09:11:35 -0400 | [diff] [blame] | 745 | case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE: |
Behdad Esfahbod | 5680002 | 2013-02-12 09:44:57 -0500 | [diff] [blame] | 746 | break; |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 747 | } |
Behdad Esfahbod | c86f932 | 2011-07-25 00:44:50 -0400 | [diff] [blame] | 748 | |
Behdad Esfahbod | e2b8780 | 2016-12-22 14:40:19 -0600 | [diff] [blame] | 749 | if (likely (!c->fallback_positioning)) |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 750 | c->plan->position (c->font, c->buffer); |
Behdad Esfahbod | c86f932 | 2011-07-25 00:44:50 -0400 | [diff] [blame] | 751 | |
Behdad Esfahbod | 71b4c99 | 2013-10-28 00:20:59 +0100 | [diff] [blame] | 752 | switch (c->plan->shaper->zero_width_marks) |
Behdad Esfahbod | 0291a65 | 2013-02-13 05:57:24 -0500 | [diff] [blame] | 753 | { |
Behdad Esfahbod | 127daf1 | 2013-05-20 09:11:35 -0400 | [diff] [blame] | 754 | case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE: |
Jonathan Kew | 798e418 | 2014-06-10 13:10:30 +0100 | [diff] [blame] | 755 | zero_mark_widths_by_gdef (c->buffer, adjust_offsets_when_zeroing); |
Behdad Esfahbod | 127daf1 | 2013-05-20 09:11:35 -0400 | [diff] [blame] | 756 | break; |
| 757 | |
Behdad Esfahbod | 0291a65 | 2013-02-13 05:57:24 -0500 | [diff] [blame] | 758 | default: |
| 759 | case HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE: |
Behdad Esfahbod | 127daf1 | 2013-05-20 09:11:35 -0400 | [diff] [blame] | 760 | case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY: |
Behdad Esfahbod | 0291a65 | 2013-02-13 05:57:24 -0500 | [diff] [blame] | 761 | break; |
| 762 | } |
| 763 | |
Behdad Esfahbod | 7d8d58a | 2016-02-11 16:34:28 +0700 | [diff] [blame] | 764 | /* Finishing off GPOS has to follow a certain order. */ |
| 765 | hb_ot_layout_position_finish_advances (c->font, c->buffer); |
Behdad Esfahbod | 8474231 | 2016-02-11 16:27:41 +0700 | [diff] [blame] | 766 | hb_ot_zero_width_default_ignorables (c); |
Behdad Esfahbod | 7d8d58a | 2016-02-11 16:34:28 +0700 | [diff] [blame] | 767 | hb_ot_layout_position_finish_offsets (c->font, c->buffer); |
Behdad Esfahbod | 9786fcd | 2017-10-03 17:22:43 +0200 | [diff] [blame] | 768 | |
| 769 | /* The nil glyph_h_origin() func returns 0, so no need to apply it. */ |
| 770 | if (c->font->has_glyph_h_origin_func ()) |
| 771 | for (unsigned int i = 0; i < count; i++) |
| 772 | c->font->subtract_glyph_h_origin (info[i].codepoint, |
| 773 | &pos[i].x_offset, |
| 774 | &pos[i].y_offset); |
Behdad Esfahbod | c86f932 | 2011-07-25 00:44:50 -0400 | [diff] [blame] | 775 | } |
| 776 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 777 | static inline void |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 778 | hb_ot_position (hb_ot_shape_context_t *c) |
| 779 | { |
Behdad Esfahbod | 8474231 | 2016-02-11 16:27:41 +0700 | [diff] [blame] | 780 | c->buffer->clear_positions (); |
Behdad Esfahbod | 4b01109 | 2013-09-13 20:17:42 -0400 | [diff] [blame] | 781 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 782 | hb_ot_position_default (c); |
| 783 | |
Behdad Esfahbod | e2b8780 | 2016-12-22 14:40:19 -0600 | [diff] [blame] | 784 | hb_ot_position_complex (c); |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 785 | |
Behdad Esfahbod | e2b8780 | 2016-12-22 14:40:19 -0600 | [diff] [blame] | 786 | if (c->fallback_positioning && c->plan->shaper->fallback_position) |
Behdad Esfahbod | 865745b | 2012-11-14 13:48:26 -0800 | [diff] [blame] | 787 | _hb_ot_shape_fallback_position (c->plan, c->font, c->buffer); |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 788 | |
| 789 | if (HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction)) |
| 790 | hb_buffer_reverse (c->buffer); |
| 791 | |
Behdad Esfahbod | 865745b | 2012-11-14 13:48:26 -0800 | [diff] [blame] | 792 | /* Visual fallback goes here. */ |
| 793 | |
Behdad Esfahbod | e2b8780 | 2016-12-22 14:40:19 -0600 | [diff] [blame] | 794 | if (c->fallback_positioning) |
Behdad Esfahbod | ba87b8f | 2013-02-21 15:23:39 -0500 | [diff] [blame] | 795 | _hb_ot_shape_fallback_kern (c->plan, c->font, c->buffer); |
Behdad Esfahbod | 8f3eebf | 2014-08-02 17:18:46 -0400 | [diff] [blame] | 796 | |
| 797 | _hb_buffer_deallocate_gsubgpos_vars (c->buffer); |
Ebrahim Byagowi | 1ab16f4 | 2018-02-24 12:49:42 +0330 | [diff] [blame] | 798 | |
| 799 | //hb_aat_layout_position (c->font, c->buffer); |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 800 | } |
| 801 | |
Behdad Esfahbod | 1c17c2b | 2017-08-11 19:06:07 -0700 | [diff] [blame] | 802 | static inline void |
| 803 | hb_propagate_flags (hb_buffer_t *buffer) |
| 804 | { |
| 805 | /* Propagate cluster-level glyph flags to be the same on all cluster glyphs. |
| 806 | * Simplifies using them. */ |
| 807 | |
| 808 | if (!(buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_UNSAFE_TO_BREAK)) |
| 809 | return; |
| 810 | |
| 811 | hb_glyph_info_t *info = buffer->info; |
| 812 | |
| 813 | foreach_cluster (buffer, start, end) |
| 814 | { |
| 815 | unsigned int mask = 0; |
| 816 | for (unsigned int i = start; i < end; i++) |
| 817 | if (info[i].mask & HB_GLYPH_FLAG_UNSAFE_TO_BREAK) |
| 818 | { |
| 819 | mask = HB_GLYPH_FLAG_UNSAFE_TO_BREAK; |
| 820 | break; |
| 821 | } |
| 822 | if (mask) |
| 823 | for (unsigned int i = start; i < end; i++) |
| 824 | info[i].mask |= mask; |
| 825 | } |
| 826 | } |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 827 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 828 | /* Pull it all together! */ |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 829 | |
Behdad Esfahbod | 967240d | 2010-10-05 23:00:05 -0400 | [diff] [blame] | 830 | static void |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 831 | hb_ot_shape_internal (hb_ot_shape_context_t *c) |
Behdad Esfahbod | 967240d | 2010-10-05 23:00:05 -0400 | [diff] [blame] | 832 | { |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 833 | c->buffer->deallocate_var_all (); |
Behdad Esfahbod | 49ef630 | 2015-11-04 17:27:07 -0800 | [diff] [blame] | 834 | c->buffer->scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT; |
Behdad Esfahbod | bddeb2b | 2018-07-10 14:12:37 +0200 | [diff] [blame] | 835 | if (likely (!hb_unsigned_mul_overflows (c->buffer->len, HB_BUFFER_MAX_LEN_FACTOR))) |
Behdad Esfahbod | 4301703 | 2015-11-05 23:44:59 -0800 | [diff] [blame] | 836 | { |
Behdad Esfahbod | baf7779 | 2017-11-14 21:53:48 -0800 | [diff] [blame] | 837 | c->buffer->max_len = MAX (c->buffer->len * HB_BUFFER_MAX_LEN_FACTOR, |
Behdad Esfahbod | 4301703 | 2015-11-05 23:44:59 -0800 | [diff] [blame] | 838 | (unsigned) HB_BUFFER_MAX_LEN_MIN); |
| 839 | } |
Behdad Esfahbod | bddeb2b | 2018-07-10 14:12:37 +0200 | [diff] [blame] | 840 | if (likely (!hb_unsigned_mul_overflows (c->buffer->len, HB_BUFFER_MAX_OPS_FACTOR))) |
Behdad Esfahbod | baf7779 | 2017-11-14 21:53:48 -0800 | [diff] [blame] | 841 | { |
| 842 | c->buffer->max_ops = MAX (c->buffer->len * HB_BUFFER_MAX_OPS_FACTOR, |
| 843 | (unsigned) HB_BUFFER_MAX_OPS_MIN); |
| 844 | } |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 845 | |
Behdad Esfahbod | e2b8780 | 2016-12-22 14:40:19 -0600 | [diff] [blame] | 846 | bool disable_otl = c->plan->shaper->disable_otl && c->plan->shaper->disable_otl (c->plan); |
| 847 | //c->fallback_substitute = disable_otl || !hb_ot_layout_has_substitution (c->face); |
| 848 | c->fallback_positioning = disable_otl || !hb_ot_layout_has_positioning (c->face); |
| 849 | c->fallback_glyph_classes = disable_otl || !hb_ot_layout_has_glyph_classes (c->face); |
| 850 | |
Behdad Esfahbod | d2ba016 | 2010-10-12 15:35:45 -0400 | [diff] [blame] | 851 | /* Save the original direction, we use it later. */ |
Behdad Esfahbod | bbbbe80 | 2010-12-07 16:22:02 -0500 | [diff] [blame] | 852 | c->target_direction = c->buffer->props.direction; |
Behdad Esfahbod | d2ba016 | 2010-10-12 15:35:45 -0400 | [diff] [blame] | 853 | |
Behdad Esfahbod | 101303d | 2013-10-18 00:42:39 +0200 | [diff] [blame] | 854 | _hb_buffer_allocate_unicode_vars (c->buffer); |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 855 | |
Behdad Esfahbod | 330a2af | 2012-06-08 20:40:02 -0400 | [diff] [blame] | 856 | c->buffer->clear_output (); |
| 857 | |
Behdad Esfahbod | 7cc3480 | 2017-09-04 20:04:59 -0700 | [diff] [blame] | 858 | hb_ot_shape_initialize_masks (c); |
Behdad Esfahbod | d1deaa2 | 2012-05-09 15:04:13 +0200 | [diff] [blame] | 859 | hb_set_unicode_props (c->buffer); |
Behdad Esfahbod | 6912e47 | 2012-09-01 20:38:45 -0400 | [diff] [blame] | 860 | hb_insert_dotted_circle (c->buffer, c->font); |
Behdad Esfahbod | 7cc3480 | 2017-09-04 20:04:59 -0700 | [diff] [blame] | 861 | |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 862 | hb_form_clusters (c->buffer); |
| 863 | |
Behdad Esfahbod | aa72641 | 2011-07-21 11:34:59 -0400 | [diff] [blame] | 864 | hb_ensure_native_direction (c->buffer); |
Behdad Esfahbod | 54d1a0d | 2011-07-21 01:11:09 -0400 | [diff] [blame] | 865 | |
Behdad Esfahbod | 1368633 | 2015-11-05 13:24:15 -0800 | [diff] [blame] | 866 | if (c->plan->shaper->preprocess_text) |
| 867 | c->plan->shaper->preprocess_text (c->plan, c->buffer, c->font); |
| 868 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 869 | hb_ot_substitute (c); |
| 870 | hb_ot_position (c); |
Behdad Esfahbod | 655586f | 2011-07-21 00:51:18 -0400 | [diff] [blame] | 871 | |
Behdad Esfahbod | 8cfbc30 | 2015-07-22 18:41:10 +0100 | [diff] [blame] | 872 | hb_ot_hide_default_ignorables (c); |
| 873 | |
Behdad Esfahbod | 1368633 | 2015-11-05 13:24:15 -0800 | [diff] [blame] | 874 | if (c->plan->shaper->postprocess_glyphs) |
| 875 | c->plan->shaper->postprocess_glyphs (c->plan, c->buffer, c->font); |
| 876 | |
Behdad Esfahbod | 1c17c2b | 2017-08-11 19:06:07 -0700 | [diff] [blame] | 877 | hb_propagate_flags (c->buffer); |
| 878 | |
Behdad Esfahbod | 101303d | 2013-10-18 00:42:39 +0200 | [diff] [blame] | 879 | _hb_buffer_deallocate_unicode_vars (c->buffer); |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 880 | |
Behdad Esfahbod | bbbbe80 | 2010-12-07 16:22:02 -0500 | [diff] [blame] | 881 | c->buffer->props.direction = c->target_direction; |
Behdad Esfahbod | 9f9bcce | 2011-07-28 17:06:46 -0400 | [diff] [blame] | 882 | |
Behdad Esfahbod | 4301703 | 2015-11-05 23:44:59 -0800 | [diff] [blame] | 883 | c->buffer->max_len = HB_BUFFER_MAX_LEN_DEFAULT; |
Behdad Esfahbod | baf7779 | 2017-11-14 21:53:48 -0800 | [diff] [blame] | 884 | c->buffer->max_ops = HB_BUFFER_MAX_OPS_DEFAULT; |
Behdad Esfahbod | 9f9bcce | 2011-07-28 17:06:46 -0400 | [diff] [blame] | 885 | c->buffer->deallocate_var_all (); |
Behdad Esfahbod | 967240d | 2010-10-05 23:00:05 -0400 | [diff] [blame] | 886 | } |
| 887 | |
Behdad Esfahbod | fd3d32d | 2010-10-12 16:57:47 -0400 | [diff] [blame] | 888 | |
Behdad Esfahbod | 02aeca9 | 2011-08-04 22:31:05 -0400 | [diff] [blame] | 889 | hb_bool_t |
Behdad Esfahbod | bd26b4d | 2012-07-26 22:05:39 -0400 | [diff] [blame] | 890 | _hb_ot_shape (hb_shape_plan_t *shape_plan, |
| 891 | hb_font_t *font, |
Behdad Esfahbod | 6bd9b47 | 2012-04-12 14:53:53 -0400 | [diff] [blame] | 892 | hb_buffer_t *buffer, |
| 893 | const hb_feature_t *features, |
| 894 | unsigned int num_features) |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 895 | { |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 896 | hb_ot_shape_context_t c = {HB_SHAPER_DATA_GET (shape_plan), font, font->face, buffer, features, num_features}; |
| 897 | hb_ot_shape_internal (&c); |
Behdad Esfahbod | 02aeca9 | 2011-08-04 22:31:05 -0400 | [diff] [blame] | 898 | |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 899 | return true; |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 900 | } |
Behdad Esfahbod | 1827dc2 | 2012-04-24 16:56:37 -0400 | [diff] [blame] | 901 | |
| 902 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 903 | /** |
Behdad Esfahbod | 35d1858 | 2015-11-26 19:30:37 -0500 | [diff] [blame] | 904 | * hb_ot_shape_plan_collect_lookups: |
| 905 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 906 | * Since: 0.9.7 |
| 907 | **/ |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 908 | void |
| 909 | hb_ot_shape_plan_collect_lookups (hb_shape_plan_t *shape_plan, |
| 910 | hb_tag_t table_tag, |
| 911 | hb_set_t *lookup_indexes /* OUT */) |
Behdad Esfahbod | b00321e | 2012-08-09 22:33:32 -0400 | [diff] [blame] | 912 | { |
Behdad Esfahbod | 51bb498 | 2012-11-16 14:08:05 -0800 | [diff] [blame] | 913 | /* XXX Does the first part always succeed? */ |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 914 | HB_SHAPER_DATA_GET (shape_plan)->collect_lookups (table_tag, lookup_indexes); |
Behdad Esfahbod | b00321e | 2012-08-09 22:33:32 -0400 | [diff] [blame] | 915 | } |
| 916 | |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 917 | |
| 918 | /* TODO Move this to hb-ot-shape-normalize, make it do decompose, and make it public. */ |
| 919 | static void |
| 920 | add_char (hb_font_t *font, |
| 921 | hb_unicode_funcs_t *unicode, |
| 922 | hb_bool_t mirror, |
| 923 | hb_codepoint_t u, |
| 924 | hb_set_t *glyphs) |
| 925 | { |
| 926 | hb_codepoint_t glyph; |
Behdad Esfahbod | 8b5bc14 | 2016-02-24 19:05:23 +0900 | [diff] [blame] | 927 | if (font->get_nominal_glyph (u, &glyph)) |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 928 | glyphs->add (glyph); |
| 929 | if (mirror) |
| 930 | { |
| 931 | hb_codepoint_t m = unicode->mirroring (u); |
Behdad Esfahbod | 8b5bc14 | 2016-02-24 19:05:23 +0900 | [diff] [blame] | 932 | if (m != u && font->get_nominal_glyph (m, &glyph)) |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 933 | glyphs->add (glyph); |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 938 | /** |
Behdad Esfahbod | 35d1858 | 2015-11-26 19:30:37 -0500 | [diff] [blame] | 939 | * hb_ot_shape_glyphs_closure: |
| 940 | * |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 941 | * Since: 0.9.2 |
| 942 | **/ |
Behdad Esfahbod | 1827dc2 | 2012-04-24 16:56:37 -0400 | [diff] [blame] | 943 | void |
| 944 | hb_ot_shape_glyphs_closure (hb_font_t *font, |
| 945 | hb_buffer_t *buffer, |
| 946 | const hb_feature_t *features, |
| 947 | unsigned int num_features, |
| 948 | hb_set_t *glyphs) |
| 949 | { |
Behdad Esfahbod | dbdbfe3 | 2017-10-15 12:11:08 +0200 | [diff] [blame] | 950 | const char *shapers[] = {"ot", nullptr}; |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 951 | hb_shape_plan_t *shape_plan = hb_shape_plan_create_cached (font->face, &buffer->props, |
| 952 | features, num_features, shapers); |
Behdad Esfahbod | 1827dc2 | 2012-04-24 16:56:37 -0400 | [diff] [blame] | 953 | |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 954 | bool mirror = hb_script_get_horizontal_direction (buffer->props.script) == HB_DIRECTION_RTL; |
Behdad Esfahbod | 1827dc2 | 2012-04-24 16:56:37 -0400 | [diff] [blame] | 955 | |
Behdad Esfahbod | 1827dc2 | 2012-04-24 16:56:37 -0400 | [diff] [blame] | 956 | unsigned int count = buffer->len; |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 957 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | 1827dc2 | 2012-04-24 16:56:37 -0400 | [diff] [blame] | 958 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 959 | add_char (font, buffer->unicode, mirror, info[i].codepoint, glyphs); |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 960 | |
Behdad Esfahbod | 8b9d9b7 | 2017-10-22 17:48:06 -0400 | [diff] [blame] | 961 | hb_set_t *lookups = hb_set_create (); |
| 962 | hb_ot_shape_plan_collect_lookups (shape_plan, HB_OT_TAG_GSUB, lookups); |
Garret Rieger | 57badad | 2018-06-06 16:02:51 -0700 | [diff] [blame] | 963 | hb_ot_layout_lookups_substitute_closure (font->face, lookups, glyphs); |
Behdad Esfahbod | 8b9d9b7 | 2017-10-22 17:48:06 -0400 | [diff] [blame] | 964 | |
| 965 | hb_set_destroy (lookups); |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 966 | |
| 967 | hb_shape_plan_destroy (shape_plan); |
Behdad Esfahbod | 1827dc2 | 2012-04-24 16:56:37 -0400 | [diff] [blame] | 968 | } |