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 | acdba3f | 2010-07-23 15:11:18 -0400 | [diff] [blame] | 43 | |
Behdad Esfahbod | a02d864 | 2012-08-08 18:04:29 -0400 | [diff] [blame] | 44 | static hb_tag_t common_features[] = { |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 45 | HB_TAG('c','c','m','p'), |
Behdad Esfahbod | 89a2bc9 | 2011-05-31 15:18:13 -0400 | [diff] [blame] | 46 | HB_TAG('l','o','c','l'), |
Behdad Esfahbod | 89a2bc9 | 2011-05-31 15:18:13 -0400 | [diff] [blame] | 47 | HB_TAG('m','a','r','k'), |
| 48 | HB_TAG('m','k','m','k'), |
| 49 | HB_TAG('r','l','i','g'), |
| 50 | }; |
| 51 | |
Behdad Esfahbod | d1deaa2 | 2012-05-09 15:04:13 +0200 | [diff] [blame] | 52 | |
Behdad Esfahbod | a02d864 | 2012-08-08 18:04:29 -0400 | [diff] [blame] | 53 | static hb_tag_t horizontal_features[] = { |
Behdad Esfahbod | 89a2bc9 | 2011-05-31 15:18:13 -0400 | [diff] [blame] | 54 | HB_TAG('c','a','l','t'), |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 55 | HB_TAG('c','l','i','g'), |
Behdad Esfahbod | bd09873 | 2010-05-21 18:06:35 +0100 | [diff] [blame] | 56 | HB_TAG('c','u','r','s'), |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 57 | HB_TAG('k','e','r','n'), |
Behdad Esfahbod | 2053f36 | 2014-08-02 16:31:16 -0400 | [diff] [blame] | 58 | HB_TAG('l','i','g','a'), |
Behdad Esfahbod | f4e48ad | 2012-08-07 21:12:49 -0400 | [diff] [blame] | 59 | HB_TAG('r','c','l','t'), |
Behdad Esfahbod | 89a2bc9 | 2011-05-31 15:18:13 -0400 | [diff] [blame] | 60 | }; |
| 61 | |
Behdad Esfahbod | a02d864 | 2012-08-08 18:04:29 -0400 | [diff] [blame] | 62 | static hb_tag_t vertical_features[] = { |
Behdad Esfahbod | 89a2bc9 | 2011-05-31 15:18:13 -0400 | [diff] [blame] | 63 | HB_TAG('v','e','r','t'), |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 64 | }; |
| 65 | |
Behdad Esfahbod | b9f199c | 2012-04-14 20:23:58 -0400 | [diff] [blame] | 66 | |
| 67 | |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 68 | static void |
Behdad Esfahbod | 90645fb | 2011-05-27 18:13:31 -0400 | [diff] [blame] | 69 | hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner, |
Behdad Esfahbod | 49baa1f | 2010-10-12 16:50:36 -0400 | [diff] [blame] | 70 | const hb_segment_properties_t *props, |
Behdad Esfahbod | 90645fb | 2011-05-27 18:13:31 -0400 | [diff] [blame] | 71 | const hb_feature_t *user_features, |
| 72 | unsigned int num_user_features) |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 73 | { |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 74 | hb_ot_map_builder_t *map = &planner->map; |
| 75 | |
Behdad Esfahbod | 895fb5d | 2010-10-12 16:00:21 -0400 | [diff] [blame] | 76 | switch (props->direction) { |
Behdad Esfahbod | 074ea78 | 2010-05-21 17:53:10 +0100 | [diff] [blame] | 77 | case HB_DIRECTION_LTR: |
Behdad Esfahbod | e7ffcfa | 2013-02-14 11:05:56 -0500 | [diff] [blame] | 78 | map->add_global_bool_feature (HB_TAG ('l','t','r','a')); |
| 79 | map->add_global_bool_feature (HB_TAG ('l','t','r','m')); |
Behdad Esfahbod | 074ea78 | 2010-05-21 17:53:10 +0100 | [diff] [blame] | 80 | break; |
| 81 | case HB_DIRECTION_RTL: |
Behdad Esfahbod | e7ffcfa | 2013-02-14 11:05:56 -0500 | [diff] [blame] | 82 | map->add_global_bool_feature (HB_TAG ('r','t','l','a')); |
Behdad Esfahbod | ec54486 | 2013-02-14 11:25:10 -0500 | [diff] [blame] | 83 | map->add_feature (HB_TAG ('r','t','l','m'), 1, F_NONE); |
Behdad Esfahbod | 0e235d0 | 2010-05-28 20:21:47 -0400 | [diff] [blame] | 84 | break; |
| 85 | case HB_DIRECTION_TTB: |
| 86 | case HB_DIRECTION_BTT: |
Behdad Esfahbod | 3286fc0 | 2011-03-16 14:53:32 -0300 | [diff] [blame] | 87 | case HB_DIRECTION_INVALID: |
Behdad Esfahbod | 0e235d0 | 2010-05-28 20:21:47 -0400 | [diff] [blame] | 88 | default: |
| 89 | break; |
| 90 | } |
| 91 | |
Behdad Esfahbod | 3aeee51 | 2013-12-22 16:17:54 -0500 | [diff] [blame] | 92 | map->add_feature (HB_TAG ('f','r','a','c'), 1, F_NONE); |
| 93 | map->add_feature (HB_TAG ('n','u','m','r'), 1, F_NONE); |
| 94 | map->add_feature (HB_TAG ('d','n','o','m'), 1, F_NONE); |
| 95 | |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 96 | if (planner->shaper->collect_features) |
Behdad Esfahbod | 16c6a27 | 2012-08-02 09:38:28 -0400 | [diff] [blame] | 97 | planner->shaper->collect_features (planner); |
Behdad Esfahbod | e04685e | 2010-05-28 20:37:06 -0400 | [diff] [blame] | 98 | |
Behdad Esfahbod | ee9c3a1 | 2013-02-15 06:22:26 -0500 | [diff] [blame] | 99 | for (unsigned int i = 0; i < ARRAY_LENGTH (common_features); i++) |
| 100 | map->add_global_bool_feature (common_features[i]); |
Behdad Esfahbod | 89a2bc9 | 2011-05-31 15:18:13 -0400 | [diff] [blame] | 101 | |
| 102 | if (HB_DIRECTION_IS_HORIZONTAL (props->direction)) |
Behdad Esfahbod | ee9c3a1 | 2013-02-15 06:22:26 -0500 | [diff] [blame] | 103 | for (unsigned int i = 0; i < ARRAY_LENGTH (horizontal_features); i++) |
Behdad Esfahbod | 038c98f | 2013-02-15 07:41:07 -0500 | [diff] [blame] | 104 | map->add_feature (horizontal_features[i], 1, F_GLOBAL | |
| 105 | (horizontal_features[i] == HB_TAG('k','e','r','n') ? |
| 106 | F_HAS_FALLBACK : F_NONE)); |
Behdad Esfahbod | 89a2bc9 | 2011-05-31 15:18:13 -0400 | [diff] [blame] | 107 | else |
Behdad Esfahbod | ee9c3a1 | 2013-02-15 06:22:26 -0500 | [diff] [blame] | 108 | for (unsigned int i = 0; i < ARRAY_LENGTH (vertical_features); i++) |
Behdad Esfahbod | 038c98f | 2013-02-15 07:41:07 -0500 | [diff] [blame] | 109 | map->add_feature (vertical_features[i], 1, F_GLOBAL | |
| 110 | (vertical_features[i] == HB_TAG('v','k','r','n') ? |
| 111 | F_HAS_FALLBACK : F_NONE)); |
Behdad Esfahbod | 89a2bc9 | 2011-05-31 15:18:13 -0400 | [diff] [blame] | 112 | |
Behdad Esfahbod | 693918e | 2012-07-30 21:08:51 -0400 | [diff] [blame] | 113 | if (planner->shaper->override_features) |
Behdad Esfahbod | 16c6a27 | 2012-08-02 09:38:28 -0400 | [diff] [blame] | 114 | planner->shaper->override_features (planner); |
Behdad Esfahbod | d96838e | 2012-07-16 20:26:57 -0400 | [diff] [blame] | 115 | |
Behdad Esfahbod | 895fb5d | 2010-10-12 16:00:21 -0400 | [diff] [blame] | 116 | for (unsigned int i = 0; i < num_user_features; i++) { |
| 117 | const hb_feature_t *feature = &user_features[i]; |
Behdad Esfahbod | ec54486 | 2013-02-14 11:25:10 -0500 | [diff] [blame] | 118 | map->add_feature (feature->tag, feature->value, |
| 119 | (feature->start == 0 && feature->end == (unsigned int) -1) ? |
| 120 | F_GLOBAL : F_NONE); |
Behdad Esfahbod | e04685e | 2010-05-28 20:37:06 -0400 | [diff] [blame] | 121 | } |
Behdad Esfahbod | e89b7d2 | 2010-10-08 12:29:59 -0400 | [diff] [blame] | 122 | } |
Behdad Esfahbod | 0e235d0 | 2010-05-28 20:21:47 -0400 | [diff] [blame] | 123 | |
| 124 | |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 125 | /* |
| 126 | * shaper face data |
| 127 | */ |
| 128 | |
| 129 | hb_ot_shaper_face_data_t * |
| 130 | _hb_ot_shaper_face_data_create (hb_face_t *face) |
| 131 | { |
| 132 | return _hb_ot_layout_create (face); |
| 133 | } |
| 134 | |
| 135 | void |
| 136 | _hb_ot_shaper_face_data_destroy (hb_ot_shaper_face_data_t *data) |
| 137 | { |
| 138 | _hb_ot_layout_destroy (data); |
| 139 | } |
| 140 | |
| 141 | |
| 142 | /* |
| 143 | * shaper font data |
| 144 | */ |
| 145 | |
| 146 | struct hb_ot_shaper_font_data_t {}; |
| 147 | |
| 148 | hb_ot_shaper_font_data_t * |
| 149 | _hb_ot_shaper_font_data_create (hb_font_t *font) |
| 150 | { |
| 151 | return (hb_ot_shaper_font_data_t *) HB_SHAPER_DATA_SUCCEEDED; |
| 152 | } |
| 153 | |
| 154 | void |
| 155 | _hb_ot_shaper_font_data_destroy (hb_ot_shaper_font_data_t *data) |
| 156 | { |
| 157 | } |
| 158 | |
| 159 | |
| 160 | /* |
| 161 | * shaper shape_plan data |
| 162 | */ |
| 163 | |
| 164 | hb_ot_shaper_shape_plan_data_t * |
| 165 | _hb_ot_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan, |
| 166 | const hb_feature_t *user_features, |
| 167 | unsigned int num_user_features) |
| 168 | { |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 169 | hb_ot_shape_plan_t *plan = (hb_ot_shape_plan_t *) calloc (1, sizeof (hb_ot_shape_plan_t)); |
| 170 | if (unlikely (!plan)) |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 171 | return NULL; |
| 172 | |
Behdad Esfahbod | 5393e3a | 2012-08-02 09:24:35 -0400 | [diff] [blame] | 173 | hb_ot_shape_planner_t planner (shape_plan); |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 174 | |
Behdad Esfahbod | 9b37b4c | 2012-11-12 18:23:38 -0800 | [diff] [blame] | 175 | planner.shaper = hb_ot_shape_complex_categorize (&planner); |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 176 | |
| 177 | hb_ot_shape_collect_features (&planner, &shape_plan->props, user_features, num_user_features); |
| 178 | |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 179 | planner.compile (*plan); |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 180 | |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 181 | if (plan->shaper->data_create) { |
| 182 | plan->data = plan->shaper->data_create (plan); |
| 183 | if (unlikely (!plan->data)) |
| 184 | return NULL; |
| 185 | } |
| 186 | |
| 187 | return plan; |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | void |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 191 | _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] | 192 | { |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 193 | if (plan->shaper->data_destroy) |
| 194 | plan->shaper->data_destroy (const_cast<void *> (plan->data)); |
Behdad Esfahbod | 4ba647e | 2012-07-30 09:53:06 -0400 | [diff] [blame] | 195 | |
Behdad Esfahbod | a8c6da9 | 2012-08-02 10:46:34 -0400 | [diff] [blame] | 196 | plan->finish (); |
| 197 | |
| 198 | free (plan); |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | |
| 202 | /* |
| 203 | * shaper |
| 204 | */ |
| 205 | |
Behdad Esfahbod | b9f199c | 2012-04-14 20:23:58 -0400 | [diff] [blame] | 206 | struct hb_ot_shape_context_t |
| 207 | { |
Behdad Esfahbod | b9f199c | 2012-04-14 20:23:58 -0400 | [diff] [blame] | 208 | hb_ot_shape_plan_t *plan; |
| 209 | hb_font_t *font; |
| 210 | hb_face_t *face; |
| 211 | hb_buffer_t *buffer; |
| 212 | const hb_feature_t *user_features; |
| 213 | unsigned int num_user_features; |
| 214 | |
| 215 | /* Transient stuff */ |
| 216 | hb_direction_t target_direction; |
Behdad Esfahbod | b9f199c | 2012-04-14 20:23:58 -0400 | [diff] [blame] | 217 | }; |
| 218 | |
Behdad Esfahbod | 2014b8d | 2009-12-20 20:58:26 +0100 | [diff] [blame] | 219 | |
| 220 | |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 221 | /* Main shaper */ |
| 222 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 223 | |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 224 | /* Prepare */ |
| 225 | |
Behdad Esfahbod | b9f199c | 2012-04-14 20:23:58 -0400 | [diff] [blame] | 226 | static void |
| 227 | hb_set_unicode_props (hb_buffer_t *buffer) |
Behdad Esfahbod | 3a852ae | 2010-11-03 16:37:24 -0400 | [diff] [blame] | 228 | { |
Behdad Esfahbod | aa72641 | 2011-07-21 11:34:59 -0400 | [diff] [blame] | 229 | unsigned int count = buffer->len; |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 230 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | 0e33614 | 2012-04-12 10:06:52 -0400 | [diff] [blame] | 231 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 232 | _hb_glyph_info_set_unicode_props (&info[i], buffer->unicode); |
Behdad Esfahbod | 3a852ae | 2010-11-03 16:37:24 -0400 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | static void |
Behdad Esfahbod | 6912e47 | 2012-09-01 20:38:45 -0400 | [diff] [blame] | 236 | hb_insert_dotted_circle (hb_buffer_t *buffer, hb_font_t *font) |
| 237 | { |
Behdad Esfahbod | 0c7df22 | 2012-11-13 14:42:35 -0800 | [diff] [blame] | 238 | if (!(buffer->flags & HB_BUFFER_FLAG_BOT) || |
Behdad Esfahbod | 763e546 | 2014-08-02 16:17:44 -0400 | [diff] [blame] | 239 | buffer->context_len[0] || |
Behdad Esfahbod | f2eb3fa | 2012-09-25 21:35:35 -0400 | [diff] [blame] | 240 | _hb_glyph_info_get_general_category (&buffer->info[0]) != |
Behdad Esfahbod | 6912e47 | 2012-09-01 20:38:45 -0400 | [diff] [blame] | 241 | HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) |
| 242 | return; |
| 243 | |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 244 | if (!font->has_glyph (0x25CCu)) |
Behdad Esfahbod | 6912e47 | 2012-09-01 20:38:45 -0400 | [diff] [blame] | 245 | return; |
| 246 | |
Behdad Esfahbod | 595d2b9 | 2014-07-26 18:44:15 -0400 | [diff] [blame] | 247 | hb_glyph_info_t dottedcircle = {0}; |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 248 | dottedcircle.codepoint = 0x25CCu; |
Behdad Esfahbod | 6912e47 | 2012-09-01 20:38:45 -0400 | [diff] [blame] | 249 | _hb_glyph_info_set_unicode_props (&dottedcircle, buffer->unicode); |
| 250 | |
| 251 | buffer->clear_output (); |
| 252 | |
| 253 | buffer->idx = 0; |
| 254 | hb_glyph_info_t info = dottedcircle; |
| 255 | info.cluster = buffer->cur().cluster; |
| 256 | info.mask = buffer->cur().mask; |
| 257 | buffer->output_info (info); |
| 258 | while (buffer->idx < buffer->len) |
| 259 | buffer->next_glyph (); |
| 260 | |
| 261 | buffer->swap_buffers (); |
| 262 | } |
| 263 | |
| 264 | static void |
Behdad Esfahbod | aa72641 | 2011-07-21 11:34:59 -0400 | [diff] [blame] | 265 | hb_form_clusters (hb_buffer_t *buffer) |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 266 | { |
Behdad Esfahbod | 376d587 | 2015-07-22 16:51:12 +0100 | [diff] [blame] | 267 | if (buffer->cluster_level != HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES) |
| 268 | return; |
| 269 | |
Behdad Esfahbod | a60e2cf | 2015-07-22 15:49:08 +0100 | [diff] [blame] | 270 | /* Loop duplicated in hb_ensure_native_direction(). */ |
Behdad Esfahbod | 701112d | 2015-07-22 15:42:20 +0100 | [diff] [blame] | 271 | unsigned int base = 0; |
Behdad Esfahbod | aa72641 | 2011-07-21 11:34:59 -0400 | [diff] [blame] | 272 | unsigned int count = buffer->len; |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 273 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 274 | for (unsigned int i = 1; i < count; i++) |
Behdad Esfahbod | 701112d | 2015-07-22 15:42:20 +0100 | [diff] [blame] | 275 | { |
| 276 | if (likely (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&info[i])))) |
| 277 | { |
| 278 | buffer->merge_clusters (base, i); |
| 279 | base = i; |
| 280 | } |
| 281 | } |
| 282 | buffer->merge_clusters (base, count); |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 283 | } |
| 284 | |
Behdad Esfahbod | 967240d | 2010-10-05 23:00:05 -0400 | [diff] [blame] | 285 | static void |
Behdad Esfahbod | aa72641 | 2011-07-21 11:34:59 -0400 | [diff] [blame] | 286 | hb_ensure_native_direction (hb_buffer_t *buffer) |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 287 | { |
Behdad Esfahbod | aa72641 | 2011-07-21 11:34:59 -0400 | [diff] [blame] | 288 | hb_direction_t direction = buffer->props.direction; |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 289 | |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 290 | /* TODO vertical: |
| 291 | * The only BTT vertical script is Ogham, but it's not clear to me whether OpenType |
| 292 | * Ogham fonts are supposed to be implemented BTT or not. Need to research that |
| 293 | * first. */ |
Behdad Esfahbod | aa72641 | 2011-07-21 11:34:59 -0400 | [diff] [blame] | 294 | if ((HB_DIRECTION_IS_HORIZONTAL (direction) && direction != hb_script_get_horizontal_direction (buffer->props.script)) || |
Behdad Esfahbod | 7403e05 | 2011-05-24 21:04:15 -0400 | [diff] [blame] | 295 | (HB_DIRECTION_IS_VERTICAL (direction) && direction != HB_DIRECTION_TTB)) |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 296 | { |
Behdad Esfahbod | a60e2cf | 2015-07-22 15:49:08 +0100 | [diff] [blame] | 297 | /* Same loop as hb_form_clusters(). |
| 298 | * Since form_clusters() merged clusters already, we don't merge. */ |
| 299 | unsigned int base = 0; |
| 300 | unsigned int count = buffer->len; |
| 301 | hb_glyph_info_t *info = buffer->info; |
| 302 | for (unsigned int i = 1; i < count; i++) |
| 303 | { |
| 304 | if (likely (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&info[i])))) |
| 305 | { |
| 306 | buffer->reverse_range (base, i); |
Behdad Esfahbod | 376d587 | 2015-07-22 16:51:12 +0100 | [diff] [blame] | 307 | if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS) |
| 308 | buffer->merge_clusters (base, i); |
Behdad Esfahbod | a60e2cf | 2015-07-22 15:49:08 +0100 | [diff] [blame] | 309 | base = i; |
| 310 | } |
| 311 | } |
| 312 | buffer->reverse_range (base, count); |
Behdad Esfahbod | 376d587 | 2015-07-22 16:51:12 +0100 | [diff] [blame] | 313 | if (buffer->cluster_level == HB_BUFFER_CLUSTER_LEVEL_MONOTONE_CHARACTERS) |
| 314 | buffer->merge_clusters (base, count); |
Behdad Esfahbod | a60e2cf | 2015-07-22 15:49:08 +0100 | [diff] [blame] | 315 | |
| 316 | buffer->reverse (); |
| 317 | |
Behdad Esfahbod | aa72641 | 2011-07-21 11:34:59 -0400 | [diff] [blame] | 318 | buffer->props.direction = HB_DIRECTION_REVERSE (buffer->props.direction); |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 319 | } |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | |
| 323 | /* Substitute */ |
| 324 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 325 | static inline void |
| 326 | hb_ot_mirror_chars (hb_ot_shape_context_t *c) |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 327 | { |
Behdad Esfahbod | bbbbe80 | 2010-12-07 16:22:02 -0500 | [diff] [blame] | 328 | if (HB_DIRECTION_IS_FORWARD (c->target_direction)) |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 329 | return; |
| 330 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 331 | hb_buffer_t *buffer = c->buffer; |
| 332 | hb_unicode_funcs_t *unicode = buffer->unicode; |
Behdad Esfahbod | 5497a8a | 2013-12-22 20:48:53 -0500 | [diff] [blame] | 333 | hb_mask_t rtlm_mask = c->plan->rtlm_mask; |
Behdad Esfahbod | 4e4ef24 | 2010-07-23 17:22:11 -0400 | [diff] [blame] | 334 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 335 | unsigned int count = buffer->len; |
| 336 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 337 | for (unsigned int i = 0; i < count; i++) { |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 338 | hb_codepoint_t codepoint = unicode->mirroring (info[i].codepoint); |
Behdad Esfahbod | 7b8b63a | 2015-07-22 15:24:26 +0100 | [diff] [blame] | 339 | if (likely (codepoint == info[i].codepoint || !c->font->has_glyph (codepoint))) |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 340 | info[i].mask |= rtlm_mask; |
Behdad Esfahbod | 1094a29 | 2010-05-21 17:58:20 +0100 | [diff] [blame] | 341 | else |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 342 | info[i].codepoint = codepoint; |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 346 | static inline void |
Behdad Esfahbod | 3aeee51 | 2013-12-22 16:17:54 -0500 | [diff] [blame] | 347 | hb_ot_shape_setup_masks_fraction (hb_ot_shape_context_t *c) |
| 348 | { |
Behdad Esfahbod | 5497a8a | 2013-12-22 20:48:53 -0500 | [diff] [blame] | 349 | if (!c->plan->has_frac) |
| 350 | return; |
| 351 | |
Behdad Esfahbod | 3aeee51 | 2013-12-22 16:17:54 -0500 | [diff] [blame] | 352 | hb_buffer_t *buffer = c->buffer; |
Behdad Esfahbod | 3aeee51 | 2013-12-22 16:17:54 -0500 | [diff] [blame] | 353 | |
| 354 | /* TODO look in pre/post context text also. */ |
| 355 | unsigned int count = buffer->len; |
| 356 | hb_glyph_info_t *info = buffer->info; |
| 357 | for (unsigned int i = 0; i < count; i++) |
| 358 | { |
Behdad Esfahbod | 7627100 | 2014-07-11 14:54:42 -0400 | [diff] [blame] | 359 | if (info[i].codepoint == 0x2044u) /* FRACTION SLASH */ |
Behdad Esfahbod | 3aeee51 | 2013-12-22 16:17:54 -0500 | [diff] [blame] | 360 | { |
Behdad Esfahbod | 3aeee51 | 2013-12-22 16:17:54 -0500 | [diff] [blame] | 361 | unsigned int start = i, end = i + 1; |
| 362 | while (start && |
| 363 | _hb_glyph_info_get_general_category (&info[start - 1]) == |
| 364 | HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER) |
| 365 | start--; |
| 366 | while (end < count && |
| 367 | _hb_glyph_info_get_general_category (&info[end]) == |
| 368 | HB_UNICODE_GENERAL_CATEGORY_DECIMAL_NUMBER) |
| 369 | end++; |
| 370 | |
Behdad Esfahbod | a7e8bbb | 2013-12-22 19:33:35 -0500 | [diff] [blame] | 371 | for (unsigned int j = start; j < i; j++) |
Behdad Esfahbod | 5497a8a | 2013-12-22 20:48:53 -0500 | [diff] [blame] | 372 | info[j].mask |= c->plan->numr_mask | c->plan->frac_mask; |
| 373 | info[i].mask |= c->plan->frac_mask; |
Behdad Esfahbod | a7e8bbb | 2013-12-22 19:33:35 -0500 | [diff] [blame] | 374 | for (unsigned int j = i + 1; j < end; j++) |
Behdad Esfahbod | 5497a8a | 2013-12-22 20:48:53 -0500 | [diff] [blame] | 375 | info[j].mask |= c->plan->frac_mask | c->plan->dnom_mask; |
Behdad Esfahbod | 3aeee51 | 2013-12-22 16:17:54 -0500 | [diff] [blame] | 376 | |
| 377 | i = end - 1; |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | static inline void |
Behdad Esfahbod | 7393251 | 2013-12-21 00:18:18 -0500 | [diff] [blame] | 383 | hb_ot_shape_initialize_masks (hb_ot_shape_context_t *c) |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 384 | { |
| 385 | hb_ot_map_t *map = &c->plan->map; |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 386 | hb_buffer_t *buffer = c->buffer; |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 387 | |
| 388 | hb_mask_t global_mask = map->get_global_mask (); |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 389 | buffer->reset_masks (global_mask); |
Behdad Esfahbod | 7393251 | 2013-12-21 00:18:18 -0500 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | static inline void |
| 393 | hb_ot_shape_setup_masks (hb_ot_shape_context_t *c) |
| 394 | { |
| 395 | hb_ot_map_t *map = &c->plan->map; |
| 396 | hb_buffer_t *buffer = c->buffer; |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 397 | |
Behdad Esfahbod | 3aeee51 | 2013-12-22 16:17:54 -0500 | [diff] [blame] | 398 | hb_ot_shape_setup_masks_fraction (c); |
| 399 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 400 | if (c->plan->shaper->setup_masks) |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 401 | c->plan->shaper->setup_masks (c->plan, buffer, c->font); |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 402 | |
| 403 | for (unsigned int i = 0; i < c->num_user_features; i++) |
| 404 | { |
| 405 | const hb_feature_t *feature = &c->user_features[i]; |
| 406 | if (!(feature->start == 0 && feature->end == (unsigned int)-1)) { |
| 407 | unsigned int shift; |
| 408 | hb_mask_t mask = map->get_mask (feature->tag, &shift); |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 409 | buffer->set_masks (feature->value << shift, mask, feature->start, feature->end); |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 410 | } |
| 411 | } |
| 412 | } |
| 413 | |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 414 | |
| 415 | static void |
| 416 | hb_ot_hide_default_ignorables (hb_ot_shape_context_t *c) |
| 417 | { |
| 418 | hb_buffer_t *buffer = c->buffer; |
| 419 | |
| 420 | if (buffer->flags & HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES) |
| 421 | return; |
| 422 | |
| 423 | unsigned int count = buffer->len; |
| 424 | hb_glyph_info_t *info = buffer->info; |
| 425 | hb_glyph_position_t *pos = buffer->pos; |
| 426 | unsigned int i = 0; |
| 427 | for (i = 0; i < count; i++) |
| 428 | { |
Behdad Esfahbod | 4ba796b | 2015-07-22 17:41:31 +0100 | [diff] [blame] | 429 | if (unlikely (_hb_glyph_info_is_default_ignorable (&info[i]))) |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 430 | break; |
| 431 | } |
| 432 | |
| 433 | /* No default-ignorables found; return. */ |
| 434 | if (i == count) |
| 435 | return; |
| 436 | |
| 437 | hb_codepoint_t space; |
| 438 | if (c->font->get_glyph (' ', 0, &space)) |
| 439 | { |
| 440 | /* Replace default-ignorables with a zero-advance space glyph. */ |
| 441 | for (/*continue*/; i < count; i++) |
| 442 | { |
Behdad Esfahbod | 4ba796b | 2015-07-22 17:41:31 +0100 | [diff] [blame] | 443 | if (_hb_glyph_info_is_default_ignorable (&info[i])) |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 444 | { |
| 445 | info[i].codepoint = space; |
| 446 | pos[i].x_advance = pos[i].y_advance = pos[i].x_offset = pos[i].y_offset = 0; |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | else |
| 451 | { |
Behdad Esfahbod | 2dbd3d2 | 2015-07-22 18:28:39 +0100 | [diff] [blame^] | 452 | /* Merge clusters and delete default-ignorables. |
| 453 | * NOTE! We can't use out-buffer as we have positioning data. */ |
| 454 | unsigned int j = i; |
| 455 | for (; i < count; i++) |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 456 | { |
Behdad Esfahbod | 2dbd3d2 | 2015-07-22 18:28:39 +0100 | [diff] [blame^] | 457 | if (_hb_glyph_info_is_default_ignorable (&info[i])) |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 458 | { |
Behdad Esfahbod | 2dbd3d2 | 2015-07-22 18:28:39 +0100 | [diff] [blame^] | 459 | /* Merge clusters. |
| 460 | * Same logic as buffer->delete_glyph(), but for in-place removal. */ |
| 461 | |
| 462 | unsigned int cluster = info[i].cluster; |
| 463 | if (i + 1 < count && cluster == info[i + 1].cluster) |
| 464 | continue; /* Cluster survives; do nothing. */ |
| 465 | |
| 466 | if (j) |
| 467 | { |
| 468 | /* Merge cluster backward. */ |
| 469 | if (cluster < info[j - 1].cluster) |
| 470 | { |
| 471 | unsigned int old_cluster = info[j - 1].cluster; |
| 472 | for (unsigned k = j; k && info[k - 1].cluster == old_cluster; k--) |
| 473 | info[k - 1].cluster = cluster; |
| 474 | } |
| 475 | continue; |
| 476 | } |
| 477 | |
| 478 | if (i + 1 < count) |
| 479 | buffer->merge_clusters (i, i + 2); /* Merge cluster forward. */ |
| 480 | |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 481 | continue; |
| 482 | } |
Behdad Esfahbod | 2dbd3d2 | 2015-07-22 18:28:39 +0100 | [diff] [blame^] | 483 | |
| 484 | if (j != i) |
| 485 | { |
| 486 | info[j] = info[i]; |
| 487 | pos[j] = pos[i]; |
| 488 | } |
| 489 | j++; |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 490 | } |
Behdad Esfahbod | 2dbd3d2 | 2015-07-22 18:28:39 +0100 | [diff] [blame^] | 491 | buffer->len = j; |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 492 | } |
| 493 | } |
| 494 | |
| 495 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 496 | static inline void |
Behdad Esfahbod | b00321e | 2012-08-09 22:33:32 -0400 | [diff] [blame] | 497 | hb_ot_map_glyphs_fast (hb_buffer_t *buffer) |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 498 | { |
Behdad Esfahbod | b00321e | 2012-08-09 22:33:32 -0400 | [diff] [blame] | 499 | /* Normalization process sets up glyph_index(), we just copy it. */ |
| 500 | unsigned int count = buffer->len; |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 501 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | b00321e | 2012-08-09 22:33:32 -0400 | [diff] [blame] | 502 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 503 | info[i].codepoint = info[i].glyph_index(); |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 504 | } |
| 505 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 506 | static inline void |
Behdad Esfahbod | 0ccf9b6 | 2012-08-29 11:53:26 -0400 | [diff] [blame] | 507 | hb_synthesize_glyph_classes (hb_ot_shape_context_t *c) |
| 508 | { |
| 509 | unsigned int count = c->buffer->len; |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 510 | hb_glyph_info_t *info = c->buffer->info; |
Behdad Esfahbod | 0ccf9b6 | 2012-08-29 11:53:26 -0400 | [diff] [blame] | 511 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | ec181e5 | 2014-07-16 13:10:03 -0400 | [diff] [blame] | 512 | { |
| 513 | hb_ot_layout_glyph_class_mask_t klass; |
| 514 | |
Behdad Esfahbod | 3b86142 | 2014-07-16 13:22:05 -0400 | [diff] [blame] | 515 | /* Never mark default-ignorables as marks. |
| 516 | * They won't get in the way of lookups anyway, |
| 517 | * but having them as mark will cause them to be skipped |
| 518 | * over if the lookup-flag says so, but at least for the |
| 519 | * Mongolian variation selectors, looks like Uniscribe |
| 520 | * marks them as non-mark. Some Mongolian fonts without |
| 521 | * GDEF rely on this. Another notable character that |
| 522 | * this applies to is COMBINING GRAPHEME JOINER. */ |
| 523 | klass = (_hb_glyph_info_get_general_category (&info[i]) != |
| 524 | HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK || |
| 525 | _hb_glyph_info_is_default_ignorable (&info[i])) ? |
Behdad Esfahbod | ec181e5 | 2014-07-16 13:10:03 -0400 | [diff] [blame] | 526 | HB_OT_LAYOUT_GLYPH_PROPS_BASE_GLYPH : |
| 527 | HB_OT_LAYOUT_GLYPH_PROPS_MARK; |
| 528 | _hb_glyph_info_set_glyph_props (&info[i], klass); |
| 529 | } |
Behdad Esfahbod | 0ccf9b6 | 2012-08-29 11:53:26 -0400 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | static inline void |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 533 | hb_ot_substitute_default (hb_ot_shape_context_t *c) |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 534 | { |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 535 | hb_buffer_t *buffer = c->buffer; |
| 536 | |
Behdad Esfahbod | fabd311 | 2012-09-05 22:19:28 -0400 | [diff] [blame] | 537 | if (c->plan->shaper->preprocess_text) |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 538 | c->plan->shaper->preprocess_text (c->plan, buffer, c->font); |
Behdad Esfahbod | 9f9f04c | 2012-08-11 18:34:13 -0400 | [diff] [blame] | 539 | |
Behdad Esfahbod | 7393251 | 2013-12-21 00:18:18 -0500 | [diff] [blame] | 540 | hb_ot_shape_initialize_masks (c); |
| 541 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 542 | hb_ot_mirror_chars (c); |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 543 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 544 | HB_BUFFER_ALLOCATE_VAR (buffer, glyph_index); |
Behdad Esfahbod | b00321e | 2012-08-09 22:33:32 -0400 | [diff] [blame] | 545 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 546 | _hb_ot_shape_normalize (c->plan, buffer, c->font); |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 547 | |
| 548 | hb_ot_shape_setup_masks (c); |
| 549 | |
Behdad Esfahbod | 3992b5e | 2012-09-01 19:20:41 -0400 | [diff] [blame] | 550 | /* This is unfortunate to go here, but necessary... */ |
| 551 | if (!hb_ot_layout_has_positioning (c->face)) |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 552 | _hb_ot_shape_fallback_position_recategorize_marks (c->plan, c->font, buffer); |
Behdad Esfahbod | 3992b5e | 2012-09-01 19:20:41 -0400 | [diff] [blame] | 553 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 554 | hb_ot_map_glyphs_fast (buffer); |
Behdad Esfahbod | b00321e | 2012-08-09 22:33:32 -0400 | [diff] [blame] | 555 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 556 | HB_BUFFER_DEALLOCATE_VAR (buffer, glyph_index); |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 557 | } |
| 558 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 559 | static inline void |
Behdad Esfahbod | c86f932 | 2011-07-25 00:44:50 -0400 | [diff] [blame] | 560 | hb_ot_substitute_complex (hb_ot_shape_context_t *c) |
| 561 | { |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 562 | hb_buffer_t *buffer = c->buffer; |
| 563 | |
Behdad Esfahbod | 8f3eebf | 2014-08-02 17:18:46 -0400 | [diff] [blame] | 564 | _hb_buffer_allocate_gsubgpos_vars (buffer); |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 565 | hb_ot_layout_substitute_start (c->font, buffer); |
Behdad Esfahbod | 05bd1b6 | 2012-07-30 19:30:01 -0400 | [diff] [blame] | 566 | |
Behdad Esfahbod | 5fecd8b | 2012-07-31 22:48:38 -0400 | [diff] [blame] | 567 | if (!hb_ot_layout_has_glyph_classes (c->face)) |
| 568 | hb_synthesize_glyph_classes (c); |
| 569 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 570 | c->plan->substitute (c->font, buffer); |
Behdad Esfahbod | c86f932 | 2011-07-25 00:44:50 -0400 | [diff] [blame] | 571 | |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 572 | hb_ot_layout_substitute_finish (c->font, buffer); |
Behdad Esfahbod | c86f932 | 2011-07-25 00:44:50 -0400 | [diff] [blame] | 573 | |
Behdad Esfahbod | c86f932 | 2011-07-25 00:44:50 -0400 | [diff] [blame] | 574 | return; |
| 575 | } |
| 576 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 577 | static inline void |
| 578 | hb_ot_substitute (hb_ot_shape_context_t *c) |
| 579 | { |
| 580 | hb_ot_substitute_default (c); |
| 581 | hb_ot_substitute_complex (c); |
| 582 | } |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 583 | |
| 584 | /* Position */ |
| 585 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 586 | static inline void |
Jonathan Kew | 798e418 | 2014-06-10 13:10:30 +0100 | [diff] [blame] | 587 | adjust_mark_offsets (hb_glyph_position_t *pos) |
| 588 | { |
| 589 | pos->x_offset -= pos->x_advance; |
| 590 | pos->y_offset -= pos->y_advance; |
| 591 | } |
| 592 | |
| 593 | static inline void |
| 594 | zero_mark_width (hb_glyph_position_t *pos) |
| 595 | { |
| 596 | pos->x_advance = 0; |
| 597 | pos->y_advance = 0; |
| 598 | } |
| 599 | |
| 600 | static inline void |
| 601 | zero_mark_widths_by_unicode (hb_buffer_t *buffer, bool adjust_offsets) |
Behdad Esfahbod | d785fa0 | 2013-05-20 09:18:52 -0400 | [diff] [blame] | 602 | { |
| 603 | unsigned int count = buffer->len; |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 604 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | d785fa0 | 2013-05-20 09:18:52 -0400 | [diff] [blame] | 605 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 606 | if (_hb_glyph_info_get_general_category (&info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) |
Behdad Esfahbod | d785fa0 | 2013-05-20 09:18:52 -0400 | [diff] [blame] | 607 | { |
Jonathan Kew | 798e418 | 2014-06-10 13:10:30 +0100 | [diff] [blame] | 608 | if (adjust_offsets) |
| 609 | adjust_mark_offsets (&buffer->pos[i]); |
| 610 | zero_mark_width (&buffer->pos[i]); |
Behdad Esfahbod | d785fa0 | 2013-05-20 09:18:52 -0400 | [diff] [blame] | 611 | } |
| 612 | } |
| 613 | |
| 614 | static inline void |
Jonathan Kew | 798e418 | 2014-06-10 13:10:30 +0100 | [diff] [blame] | 615 | zero_mark_widths_by_gdef (hb_buffer_t *buffer, bool adjust_offsets) |
Behdad Esfahbod | d785fa0 | 2013-05-20 09:18:52 -0400 | [diff] [blame] | 616 | { |
| 617 | unsigned int count = buffer->len; |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 618 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | d785fa0 | 2013-05-20 09:18:52 -0400 | [diff] [blame] | 619 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 620 | if (_hb_glyph_info_is_mark (&info[i])) |
Behdad Esfahbod | d785fa0 | 2013-05-20 09:18:52 -0400 | [diff] [blame] | 621 | { |
Jonathan Kew | 798e418 | 2014-06-10 13:10:30 +0100 | [diff] [blame] | 622 | if (adjust_offsets) |
| 623 | adjust_mark_offsets (&buffer->pos[i]); |
| 624 | zero_mark_width (&buffer->pos[i]); |
Behdad Esfahbod | d785fa0 | 2013-05-20 09:18:52 -0400 | [diff] [blame] | 625 | } |
| 626 | } |
| 627 | |
| 628 | static inline void |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 629 | hb_ot_position_default (hb_ot_shape_context_t *c) |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 630 | { |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 631 | hb_direction_t direction = c->buffer->props.direction; |
Behdad Esfahbod | 967240d | 2010-10-05 23:00:05 -0400 | [diff] [blame] | 632 | unsigned int count = c->buffer->len; |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 633 | hb_glyph_info_t *info = c->buffer->info; |
| 634 | hb_glyph_position_t *pos = c->buffer->pos; |
Behdad Esfahbod | 5680002 | 2013-02-12 09:44:57 -0500 | [diff] [blame] | 635 | for (unsigned int i = 0; i < count; i++) |
| 636 | { |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 637 | c->font->get_glyph_advance_for_direction (info[i].codepoint, |
| 638 | direction, |
| 639 | &pos[i].x_advance, |
| 640 | &pos[i].y_advance); |
| 641 | c->font->subtract_glyph_origin_for_direction (info[i].codepoint, |
| 642 | direction, |
| 643 | &pos[i].x_offset, |
| 644 | &pos[i].y_offset); |
Behdad Esfahbod | 5680002 | 2013-02-12 09:44:57 -0500 | [diff] [blame] | 645 | |
| 646 | } |
Behdad Esfahbod | 4b01109 | 2013-09-13 20:17:42 -0400 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | static inline bool |
| 650 | hb_ot_position_complex (hb_ot_shape_context_t *c) |
| 651 | { |
| 652 | bool ret = false; |
| 653 | unsigned int count = c->buffer->len; |
Jonathan Kew | 798e418 | 2014-06-10 13:10:30 +0100 | [diff] [blame] | 654 | bool has_positioning = hb_ot_layout_has_positioning (c->face); |
| 655 | /* If the font has no GPOS, AND, no fallback positioning will |
| 656 | * happen, AND, direction is forward, then when zeroing mark |
| 657 | * widths, we shift the mark with it, such that the mark |
| 658 | * is positioned hanging over the previous glyph. When |
| 659 | * direction is backward we don't shift and it will end up |
| 660 | * hanging over the next glyph after the final reordering. |
| 661 | * If fallback positinoing happens or GPOS is present, we don't |
| 662 | * care. |
| 663 | */ |
| 664 | bool adjust_offsets_when_zeroing = !(has_positioning || c->plan->shaper->fallback_position || |
| 665 | HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction)); |
Behdad Esfahbod | 5680002 | 2013-02-12 09:44:57 -0500 | [diff] [blame] | 666 | |
Behdad Esfahbod | 71b4c99 | 2013-10-28 00:20:59 +0100 | [diff] [blame] | 667 | switch (c->plan->shaper->zero_width_marks) |
Behdad Esfahbod | 5680002 | 2013-02-12 09:44:57 -0500 | [diff] [blame] | 668 | { |
Behdad Esfahbod | 127daf1 | 2013-05-20 09:11:35 -0400 | [diff] [blame] | 669 | case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY: |
Jonathan Kew | 798e418 | 2014-06-10 13:10:30 +0100 | [diff] [blame] | 670 | zero_mark_widths_by_gdef (c->buffer, adjust_offsets_when_zeroing); |
Behdad Esfahbod | 5680002 | 2013-02-12 09:44:57 -0500 | [diff] [blame] | 671 | break; |
| 672 | |
Behdad Esfahbod | 127daf1 | 2013-05-20 09:11:35 -0400 | [diff] [blame] | 673 | /* Not currently used for any shaper: |
| 674 | case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE_EARLY: |
Jonathan Kew | 798e418 | 2014-06-10 13:10:30 +0100 | [diff] [blame] | 675 | zero_mark_widths_by_unicode (c->buffer, adjust_offsets_when_zeroing); |
Behdad Esfahbod | 127daf1 | 2013-05-20 09:11:35 -0400 | [diff] [blame] | 676 | break; |
| 677 | */ |
| 678 | |
Behdad Esfahbod | 5680002 | 2013-02-12 09:44:57 -0500 | [diff] [blame] | 679 | default: |
| 680 | case HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE: |
Behdad Esfahbod | 127daf1 | 2013-05-20 09:11:35 -0400 | [diff] [blame] | 681 | case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE_LATE: |
| 682 | case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE: |
Behdad Esfahbod | 5680002 | 2013-02-12 09:44:57 -0500 | [diff] [blame] | 683 | break; |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 684 | } |
Behdad Esfahbod | c86f932 | 2011-07-25 00:44:50 -0400 | [diff] [blame] | 685 | |
Jonathan Kew | 798e418 | 2014-06-10 13:10:30 +0100 | [diff] [blame] | 686 | if (has_positioning) |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 687 | { |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 688 | hb_glyph_info_t *info = c->buffer->info; |
| 689 | hb_glyph_position_t *pos = c->buffer->pos; |
| 690 | |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 691 | /* Change glyph origin to what GPOS expects, apply GPOS, change it back. */ |
Behdad Esfahbod | c86f932 | 2011-07-25 00:44:50 -0400 | [diff] [blame] | 692 | |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 693 | for (unsigned int i = 0; i < count; i++) { |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 694 | c->font->add_glyph_origin_for_direction (info[i].codepoint, |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 695 | HB_DIRECTION_LTR, |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 696 | &pos[i].x_offset, |
| 697 | &pos[i].y_offset); |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 698 | } |
Behdad Esfahbod | c86f932 | 2011-07-25 00:44:50 -0400 | [diff] [blame] | 699 | |
Behdad Esfahbod | 8bb5deb | 2012-08-02 10:07:58 -0400 | [diff] [blame] | 700 | c->plan->position (c->font, c->buffer); |
Behdad Esfahbod | c86f932 | 2011-07-25 00:44:50 -0400 | [diff] [blame] | 701 | |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 702 | for (unsigned int i = 0; i < count; i++) { |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 703 | c->font->subtract_glyph_origin_for_direction (info[i].codepoint, |
Behdad Esfahbod | 8fbfda9 | 2012-08-01 19:03:46 -0400 | [diff] [blame] | 704 | HB_DIRECTION_LTR, |
Behdad Esfahbod | ac8cd51 | 2013-10-18 19:33:09 +0200 | [diff] [blame] | 705 | &pos[i].x_offset, |
| 706 | &pos[i].y_offset); |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 707 | } |
Behdad Esfahbod | 2118fdb | 2011-08-02 14:06:51 -0400 | [diff] [blame] | 708 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 709 | ret = true; |
Behdad Esfahbod | affaf8a | 2012-08-07 22:41:38 -0400 | [diff] [blame] | 710 | } |
Behdad Esfahbod | 2bc3b9a | 2012-07-31 23:08:25 -0400 | [diff] [blame] | 711 | |
Behdad Esfahbod | 71b4c99 | 2013-10-28 00:20:59 +0100 | [diff] [blame] | 712 | switch (c->plan->shaper->zero_width_marks) |
Behdad Esfahbod | 0291a65 | 2013-02-13 05:57:24 -0500 | [diff] [blame] | 713 | { |
Behdad Esfahbod | 127daf1 | 2013-05-20 09:11:35 -0400 | [diff] [blame] | 714 | case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE_LATE: |
Jonathan Kew | 798e418 | 2014-06-10 13:10:30 +0100 | [diff] [blame] | 715 | zero_mark_widths_by_unicode (c->buffer, adjust_offsets_when_zeroing); |
Behdad Esfahbod | 0291a65 | 2013-02-13 05:57:24 -0500 | [diff] [blame] | 716 | break; |
| 717 | |
Behdad Esfahbod | 127daf1 | 2013-05-20 09:11:35 -0400 | [diff] [blame] | 718 | case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE: |
Jonathan Kew | 798e418 | 2014-06-10 13:10:30 +0100 | [diff] [blame] | 719 | zero_mark_widths_by_gdef (c->buffer, adjust_offsets_when_zeroing); |
Behdad Esfahbod | 127daf1 | 2013-05-20 09:11:35 -0400 | [diff] [blame] | 720 | break; |
| 721 | |
Behdad Esfahbod | 0291a65 | 2013-02-13 05:57:24 -0500 | [diff] [blame] | 722 | default: |
| 723 | case HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE: |
Behdad Esfahbod | 127daf1 | 2013-05-20 09:11:35 -0400 | [diff] [blame] | 724 | //case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE_EARLY: |
| 725 | case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY: |
Behdad Esfahbod | 0291a65 | 2013-02-13 05:57:24 -0500 | [diff] [blame] | 726 | break; |
| 727 | } |
| 728 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 729 | return ret; |
Behdad Esfahbod | c86f932 | 2011-07-25 00:44:50 -0400 | [diff] [blame] | 730 | } |
| 731 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 732 | static inline void |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 733 | hb_ot_position (hb_ot_shape_context_t *c) |
| 734 | { |
Behdad Esfahbod | 4b01109 | 2013-09-13 20:17:42 -0400 | [diff] [blame] | 735 | hb_ot_layout_position_start (c->font, c->buffer); |
| 736 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 737 | hb_ot_position_default (c); |
| 738 | |
| 739 | hb_bool_t fallback = !hb_ot_position_complex (c); |
| 740 | |
Behdad Esfahbod | f0010df | 2015-07-22 17:36:23 +0100 | [diff] [blame] | 741 | /* Need to do this here, since position_finish and fallback positioning |
| 742 | * might be affected by width of default_ignorables. */ |
| 743 | hb_ot_hide_default_ignorables (c); |
| 744 | |
Behdad Esfahbod | 4b01109 | 2013-09-13 20:17:42 -0400 | [diff] [blame] | 745 | hb_ot_layout_position_finish (c->font, c->buffer); |
| 746 | |
Behdad Esfahbod | 865745b | 2012-11-14 13:48:26 -0800 | [diff] [blame] | 747 | if (fallback && c->plan->shaper->fallback_position) |
| 748 | _hb_ot_shape_fallback_position (c->plan, c->font, c->buffer); |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 749 | |
| 750 | if (HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction)) |
| 751 | hb_buffer_reverse (c->buffer); |
| 752 | |
Behdad Esfahbod | 865745b | 2012-11-14 13:48:26 -0800 | [diff] [blame] | 753 | /* Visual fallback goes here. */ |
| 754 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 755 | if (fallback) |
Behdad Esfahbod | ba87b8f | 2013-02-21 15:23:39 -0500 | [diff] [blame] | 756 | _hb_ot_shape_fallback_kern (c->plan, c->font, c->buffer); |
Behdad Esfahbod | 8f3eebf | 2014-08-02 17:18:46 -0400 | [diff] [blame] | 757 | |
| 758 | _hb_buffer_deallocate_gsubgpos_vars (c->buffer); |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 759 | } |
| 760 | |
| 761 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 762 | /* Pull it all together! */ |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 763 | |
Behdad Esfahbod | 967240d | 2010-10-05 23:00:05 -0400 | [diff] [blame] | 764 | static void |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 765 | hb_ot_shape_internal (hb_ot_shape_context_t *c) |
Behdad Esfahbod | 967240d | 2010-10-05 23:00:05 -0400 | [diff] [blame] | 766 | { |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 767 | c->buffer->deallocate_var_all (); |
| 768 | |
Behdad Esfahbod | d2ba016 | 2010-10-12 15:35:45 -0400 | [diff] [blame] | 769 | /* Save the original direction, we use it later. */ |
Behdad Esfahbod | bbbbe80 | 2010-12-07 16:22:02 -0500 | [diff] [blame] | 770 | c->target_direction = c->buffer->props.direction; |
Behdad Esfahbod | d2ba016 | 2010-10-12 15:35:45 -0400 | [diff] [blame] | 771 | |
Behdad Esfahbod | 101303d | 2013-10-18 00:42:39 +0200 | [diff] [blame] | 772 | _hb_buffer_allocate_unicode_vars (c->buffer); |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 773 | |
Behdad Esfahbod | 330a2af | 2012-06-08 20:40:02 -0400 | [diff] [blame] | 774 | c->buffer->clear_output (); |
| 775 | |
Behdad Esfahbod | d1deaa2 | 2012-05-09 15:04:13 +0200 | [diff] [blame] | 776 | hb_set_unicode_props (c->buffer); |
Behdad Esfahbod | 6912e47 | 2012-09-01 20:38:45 -0400 | [diff] [blame] | 777 | hb_insert_dotted_circle (c->buffer, c->font); |
Behdad Esfahbod | 4ff0d2d | 2011-07-22 16:15:32 -0400 | [diff] [blame] | 778 | hb_form_clusters (c->buffer); |
| 779 | |
Behdad Esfahbod | aa72641 | 2011-07-21 11:34:59 -0400 | [diff] [blame] | 780 | hb_ensure_native_direction (c->buffer); |
Behdad Esfahbod | 54d1a0d | 2011-07-21 01:11:09 -0400 | [diff] [blame] | 781 | |
Behdad Esfahbod | 5c60b70 | 2012-08-09 21:58:07 -0400 | [diff] [blame] | 782 | hb_ot_substitute (c); |
| 783 | hb_ot_position (c); |
Behdad Esfahbod | 655586f | 2011-07-21 00:51:18 -0400 | [diff] [blame] | 784 | |
Behdad Esfahbod | 101303d | 2013-10-18 00:42:39 +0200 | [diff] [blame] | 785 | _hb_buffer_deallocate_unicode_vars (c->buffer); |
Behdad Esfahbod | b65c060 | 2011-07-28 16:48:43 -0400 | [diff] [blame] | 786 | |
Behdad Esfahbod | bbbbe80 | 2010-12-07 16:22:02 -0500 | [diff] [blame] | 787 | c->buffer->props.direction = c->target_direction; |
Behdad Esfahbod | 9f9bcce | 2011-07-28 17:06:46 -0400 | [diff] [blame] | 788 | |
| 789 | c->buffer->deallocate_var_all (); |
Behdad Esfahbod | 967240d | 2010-10-05 23:00:05 -0400 | [diff] [blame] | 790 | } |
| 791 | |
Behdad Esfahbod | fd3d32d | 2010-10-12 16:57:47 -0400 | [diff] [blame] | 792 | |
Behdad Esfahbod | 02aeca9 | 2011-08-04 22:31:05 -0400 | [diff] [blame] | 793 | hb_bool_t |
Behdad Esfahbod | bd26b4d | 2012-07-26 22:05:39 -0400 | [diff] [blame] | 794 | _hb_ot_shape (hb_shape_plan_t *shape_plan, |
| 795 | hb_font_t *font, |
Behdad Esfahbod | 6bd9b47 | 2012-04-12 14:53:53 -0400 | [diff] [blame] | 796 | hb_buffer_t *buffer, |
| 797 | const hb_feature_t *features, |
| 798 | unsigned int num_features) |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 799 | { |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 800 | hb_ot_shape_context_t c = {HB_SHAPER_DATA_GET (shape_plan), font, font->face, buffer, features, num_features}; |
| 801 | hb_ot_shape_internal (&c); |
Behdad Esfahbod | 02aeca9 | 2011-08-04 22:31:05 -0400 | [diff] [blame] | 802 | |
Behdad Esfahbod | 0594a24 | 2012-06-05 20:35:40 -0400 | [diff] [blame] | 803 | return true; |
Behdad Esfahbod | ca663bb | 2010-05-21 14:34:23 +0100 | [diff] [blame] | 804 | } |
Behdad Esfahbod | 1827dc2 | 2012-04-24 16:56:37 -0400 | [diff] [blame] | 805 | |
| 806 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 807 | /** |
| 808 | * Since: 0.9.7 |
| 809 | **/ |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 810 | void |
| 811 | hb_ot_shape_plan_collect_lookups (hb_shape_plan_t *shape_plan, |
| 812 | hb_tag_t table_tag, |
| 813 | hb_set_t *lookup_indexes /* OUT */) |
Behdad Esfahbod | b00321e | 2012-08-09 22:33:32 -0400 | [diff] [blame] | 814 | { |
Behdad Esfahbod | 51bb498 | 2012-11-16 14:08:05 -0800 | [diff] [blame] | 815 | /* XXX Does the first part always succeed? */ |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 816 | HB_SHAPER_DATA_GET (shape_plan)->collect_lookups (table_tag, lookup_indexes); |
Behdad Esfahbod | b00321e | 2012-08-09 22:33:32 -0400 | [diff] [blame] | 817 | } |
| 818 | |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 819 | |
| 820 | /* TODO Move this to hb-ot-shape-normalize, make it do decompose, and make it public. */ |
| 821 | static void |
| 822 | add_char (hb_font_t *font, |
| 823 | hb_unicode_funcs_t *unicode, |
| 824 | hb_bool_t mirror, |
| 825 | hb_codepoint_t u, |
| 826 | hb_set_t *glyphs) |
| 827 | { |
| 828 | hb_codepoint_t glyph; |
| 829 | if (font->get_glyph (u, 0, &glyph)) |
| 830 | glyphs->add (glyph); |
| 831 | if (mirror) |
| 832 | { |
| 833 | hb_codepoint_t m = unicode->mirroring (u); |
| 834 | if (m != u && font->get_glyph (m, 0, &glyph)) |
| 835 | glyphs->add (glyph); |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | |
Sascha Brawer | 01c3a88 | 2015-06-01 13:22:01 +0200 | [diff] [blame] | 840 | /** |
| 841 | * Since: 0.9.2 |
| 842 | **/ |
Behdad Esfahbod | 1827dc2 | 2012-04-24 16:56:37 -0400 | [diff] [blame] | 843 | void |
| 844 | hb_ot_shape_glyphs_closure (hb_font_t *font, |
| 845 | hb_buffer_t *buffer, |
| 846 | const hb_feature_t *features, |
| 847 | unsigned int num_features, |
| 848 | hb_set_t *glyphs) |
| 849 | { |
| 850 | hb_ot_shape_plan_t plan; |
| 851 | |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 852 | const char *shapers[] = {"ot", NULL}; |
| 853 | hb_shape_plan_t *shape_plan = hb_shape_plan_create_cached (font->face, &buffer->props, |
| 854 | features, num_features, shapers); |
Behdad Esfahbod | 1827dc2 | 2012-04-24 16:56:37 -0400 | [diff] [blame] | 855 | |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 856 | 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] | 857 | |
Behdad Esfahbod | 1827dc2 | 2012-04-24 16:56:37 -0400 | [diff] [blame] | 858 | unsigned int count = buffer->len; |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 859 | hb_glyph_info_t *info = buffer->info; |
Behdad Esfahbod | 1827dc2 | 2012-04-24 16:56:37 -0400 | [diff] [blame] | 860 | for (unsigned int i = 0; i < count; i++) |
Behdad Esfahbod | 7cd33f2 | 2014-07-17 14:22:11 -0400 | [diff] [blame] | 861 | add_char (font, buffer->unicode, mirror, info[i].codepoint, glyphs); |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 862 | |
| 863 | hb_set_t lookups; |
| 864 | lookups.init (); |
| 865 | hb_ot_shape_plan_collect_lookups (shape_plan, HB_OT_TAG_GSUB, &lookups); |
Behdad Esfahbod | 1827dc2 | 2012-04-24 16:56:37 -0400 | [diff] [blame] | 866 | |
| 867 | /* And find transitive closure. */ |
| 868 | hb_set_t copy; |
| 869 | copy.init (); |
Behdad Esfahbod | 1827dc2 | 2012-04-24 16:56:37 -0400 | [diff] [blame] | 870 | do { |
| 871 | copy.set (glyphs); |
Behdad Esfahbod | f306410 | 2012-11-15 18:39:46 -0800 | [diff] [blame] | 872 | for (hb_codepoint_t lookup_index = -1; hb_set_next (&lookups, &lookup_index);) |
| 873 | hb_ot_layout_lookup_substitute_closure (font->face, lookup_index, glyphs); |
Behdad Esfahbod | aec89de | 2012-11-15 16:15:42 -0800 | [diff] [blame] | 874 | } while (!copy.is_equal (glyphs)); |
Behdad Esfahbod | e82061e | 2012-07-27 02:29:32 -0400 | [diff] [blame] | 875 | |
| 876 | hb_shape_plan_destroy (shape_plan); |
Behdad Esfahbod | 1827dc2 | 2012-04-24 16:56:37 -0400 | [diff] [blame] | 877 | } |