| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright © 2009,2010 Red Hat, Inc. | 2 * Copyright © 2009,2010 Red Hat, Inc. |
| 3 * Copyright © 2010,2011 Google, Inc. | 3 * Copyright © 2010,2011 Google, Inc. |
| 4 * | 4 * |
| 5 * This is part of HarfBuzz, a text shaping library. | 5 * This is part of HarfBuzz, a text shaping library. |
| 6 * | 6 * |
| 7 * Permission is hereby granted, without written agreement and without | 7 * Permission is hereby granted, without written agreement and without |
| 8 * license or royalty fees, to use, copy, modify, and distribute this | 8 * license or royalty fees, to use, copy, modify, and distribute this |
| 9 * software and its documentation for any purpose, provided that the | 9 * software and its documentation for any purpose, provided that the |
| 10 * above copyright notice and the following two paragraphs appear in | 10 * above copyright notice and the following two paragraphs appear in |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 * Google Author(s): Behdad Esfahbod | 26 * Google Author(s): Behdad Esfahbod |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "hb-ot-map-private.hh" | 29 #include "hb-ot-map-private.hh" |
| 30 | 30 |
| 31 | 31 |
| 32 void | 32 void |
| 33 hb_ot_map_t::add_lookups (hb_face_t *face, | 33 hb_ot_map_t::add_lookups (hb_face_t *face, |
| 34 unsigned int table_index, | 34 unsigned int table_index, |
| 35 unsigned int feature_index, | 35 unsigned int feature_index, |
| 36 » » » hb_mask_t mask) | 36 » » » hb_mask_t mask, |
| 37 » » » bool auto_zwj) |
| 37 { | 38 { |
| 38 unsigned int lookup_indices[32]; | 39 unsigned int lookup_indices[32]; |
| 39 unsigned int offset, len; | 40 unsigned int offset, len; |
| 40 | 41 |
| 41 offset = 0; | 42 offset = 0; |
| 42 do { | 43 do { |
| 43 len = ARRAY_LENGTH (lookup_indices); | 44 len = ARRAY_LENGTH (lookup_indices); |
| 44 hb_ot_layout_feature_get_lookups (face, | 45 hb_ot_layout_feature_get_lookups (face, |
| 45 table_tags[table_index], | 46 table_tags[table_index], |
| 46 feature_index, | 47 feature_index, |
| 47 offset, &len, | 48 offset, &len, |
| 48 lookup_indices); | 49 lookup_indices); |
| 49 | 50 |
| 50 for (unsigned int i = 0; i < len; i++) { | 51 for (unsigned int i = 0; i < len; i++) { |
| 51 hb_ot_map_t::lookup_map_t *lookup = lookups[table_index].push (); | 52 hb_ot_map_t::lookup_map_t *lookup = lookups[table_index].push (); |
| 52 if (unlikely (!lookup)) | 53 if (unlikely (!lookup)) |
| 53 return; | 54 return; |
| 54 lookup->mask = mask; | 55 lookup->mask = mask; |
| 55 lookup->index = lookup_indices[i]; | 56 lookup->index = lookup_indices[i]; |
| 57 lookup->auto_zwj = auto_zwj; |
| 56 } | 58 } |
| 57 | 59 |
| 58 offset += len; | 60 offset += len; |
| 59 } while (len == ARRAY_LENGTH (lookup_indices)); | 61 } while (len == ARRAY_LENGTH (lookup_indices)); |
| 60 } | 62 } |
| 61 | 63 |
| 62 hb_ot_map_builder_t::hb_ot_map_builder_t (hb_face_t *face_, | 64 hb_ot_map_builder_t::hb_ot_map_builder_t (hb_face_t *face_, |
| 63 const hb_segment_properties_t *props_) | 65 const hb_segment_properties_t *props_) |
| 64 { | 66 { |
| 65 memset (this, 0, sizeof (*this)); | 67 memset (this, 0, sizeof (*this)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 77 hb_ot_tags_from_script (props.script, &script_tags[0], &script_tags[1]); | 79 hb_ot_tags_from_script (props.script, &script_tags[0], &script_tags[1]); |
| 78 language_tag = hb_ot_tag_from_language (props.language); | 80 language_tag = hb_ot_tag_from_language (props.language); |
| 79 | 81 |
| 80 for (unsigned int table_index = 0; table_index < 2; table_index++) { | 82 for (unsigned int table_index = 0; table_index < 2; table_index++) { |
| 81 hb_tag_t table_tag = table_tags[table_index]; | 83 hb_tag_t table_tag = table_tags[table_index]; |
| 82 found_script[table_index] = hb_ot_layout_table_choose_script (face, table_ta
g, script_tags, &script_index[table_index], &chosen_script[table_index]); | 84 found_script[table_index] = hb_ot_layout_table_choose_script (face, table_ta
g, script_tags, &script_index[table_index], &chosen_script[table_index]); |
| 83 hb_ot_layout_script_find_language (face, table_tag, script_index[table_index
], language_tag, &language_index[table_index]); | 85 hb_ot_layout_script_find_language (face, table_tag, script_index[table_index
], language_tag, &language_index[table_index]); |
| 84 } | 86 } |
| 85 } | 87 } |
| 86 | 88 |
| 87 void hb_ot_map_builder_t::add_feature (hb_tag_t tag, unsigned int value, bool gl
obal, bool has_fallback) | 89 void hb_ot_map_builder_t::add_feature (hb_tag_t tag, unsigned int value, |
| 90 » » » » hb_ot_map_feature_flags_t flags) |
| 88 { | 91 { |
| 89 feature_info_t *info = feature_infos.push(); | 92 feature_info_t *info = feature_infos.push(); |
| 90 if (unlikely (!info)) return; | 93 if (unlikely (!info)) return; |
| 91 info->tag = tag; | 94 info->tag = tag; |
| 92 info->seq = feature_infos.len; | 95 info->seq = feature_infos.len; |
| 93 info->max_value = value; | 96 info->max_value = value; |
| 94 info->global = global; | 97 info->flags = flags; |
| 95 info->has_fallback = has_fallback; | 98 info->default_value = (flags & F_GLOBAL) ? value : 0; |
| 96 info->default_value = global ? value : 0; | |
| 97 info->stage[0] = current_stage[0]; | 99 info->stage[0] = current_stage[0]; |
| 98 info->stage[1] = current_stage[1]; | 100 info->stage[1] = current_stage[1]; |
| 99 } | 101 } |
| 100 | 102 |
| 101 /* Keep the next two functions in sync. */ | 103 /* Keep the next two functions in sync. */ |
| 102 | 104 |
| 103 void hb_ot_map_t::substitute (const hb_ot_shape_plan_t *plan, hb_font_t *font, h
b_buffer_t *buffer) const | 105 void hb_ot_map_t::substitute (const hb_ot_shape_plan_t *plan, hb_font_t *font, h
b_buffer_t *buffer) const |
| 104 { | 106 { |
| 105 const unsigned int table_index = 0; | 107 const unsigned int table_index = 0; |
| 106 unsigned int i = 0; | 108 unsigned int i = 0; |
| 107 | 109 |
| 108 for (unsigned int pause_index = 0; pause_index < pauses[table_index].len; paus
e_index++) { | 110 for (unsigned int pause_index = 0; pause_index < pauses[table_index].len; paus
e_index++) { |
| 109 const pause_map_t *pause = &pauses[table_index][pause_index]; | 111 const pause_map_t *pause = &pauses[table_index][pause_index]; |
| 110 for (; i < pause->num_lookups; i++) | 112 for (; i < pause->num_lookups; i++) |
| 111 hb_ot_layout_substitute_lookup (font, buffer, lookups[table_index][i].inde
x, lookups[table_index][i].mask); | 113 hb_ot_layout_substitute_lookup (font, buffer, |
| 114 » » » » lookups[table_index][i].index, |
| 115 » » » » lookups[table_index][i].mask, |
| 116 » » » » lookups[table_index][i].auto_zwj); |
| 112 | 117 |
| 113 buffer->clear_output (); | 118 buffer->clear_output (); |
| 114 | 119 |
| 115 if (pause->callback) | 120 if (pause->callback) |
| 116 pause->callback (plan, font, buffer); | 121 pause->callback (plan, font, buffer); |
| 117 } | 122 } |
| 118 | 123 |
| 119 for (; i < lookups[table_index].len; i++) | 124 for (; i < lookups[table_index].len; i++) |
| 120 hb_ot_layout_substitute_lookup (font, buffer, lookups[table_index][i].index,
lookups[table_index][i].mask); | 125 hb_ot_layout_substitute_lookup (font, buffer, lookups[table_index][i].index, |
| 126 » » » » lookups[table_index][i].mask, |
| 127 » » » » lookups[table_index][i].auto_zwj); |
| 121 } | 128 } |
| 122 | 129 |
| 123 void hb_ot_map_t::position (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_
buffer_t *buffer) const | 130 void hb_ot_map_t::position (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_
buffer_t *buffer) const |
| 124 { | 131 { |
| 125 const unsigned int table_index = 1; | 132 const unsigned int table_index = 1; |
| 126 unsigned int i = 0; | 133 unsigned int i = 0; |
| 127 | 134 |
| 128 for (unsigned int pause_index = 0; pause_index < pauses[table_index].len; paus
e_index++) { | 135 for (unsigned int pause_index = 0; pause_index < pauses[table_index].len; paus
e_index++) { |
| 129 const pause_map_t *pause = &pauses[table_index][pause_index]; | 136 const pause_map_t *pause = &pauses[table_index][pause_index]; |
| 130 for (; i < pause->num_lookups; i++) | 137 for (; i < pause->num_lookups; i++) |
| 131 hb_ot_layout_position_lookup (font, buffer, lookups[table_index][i].index,
lookups[table_index][i].mask); | 138 hb_ot_layout_position_lookup (font, buffer, lookups[table_index][i].index, |
| 139 » » » » lookups[table_index][i].mask, |
| 140 » » » » lookups[table_index][i].auto_zwj); |
| 132 | 141 |
| 133 if (pause->callback) | 142 if (pause->callback) |
| 134 pause->callback (plan, font, buffer); | 143 pause->callback (plan, font, buffer); |
| 135 } | 144 } |
| 136 | 145 |
| 137 for (; i < lookups[table_index].len; i++) | 146 for (; i < lookups[table_index].len; i++) |
| 138 hb_ot_layout_position_lookup (font, buffer, lookups[table_index][i].index, l
ookups[table_index][i].mask); | 147 hb_ot_layout_position_lookup (font, buffer, lookups[table_index][i].index, |
| 148 » » » » lookups[table_index][i].mask, |
| 149 » » » » lookups[table_index][i].auto_zwj); |
| 139 } | 150 } |
| 140 | 151 |
| 141 void hb_ot_map_t::collect_lookups (unsigned int table_index, hb_set_t *lookups_o
ut) const | 152 void hb_ot_map_t::collect_lookups (unsigned int table_index, hb_set_t *lookups_o
ut) const |
| 142 { | 153 { |
| 143 for (unsigned int i = 0; i < lookups[table_index].len; i++) | 154 for (unsigned int i = 0; i < lookups[table_index].len; i++) |
| 144 hb_set_add (lookups_out, lookups[table_index][i].index); | 155 hb_set_add (lookups_out, lookups[table_index][i].index); |
| 145 } | 156 } |
| 146 | 157 |
| 147 void hb_ot_map_builder_t::add_pause (unsigned int table_index, hb_ot_map_t::paus
e_func_t pause_func) | 158 void hb_ot_map_builder_t::add_pause (unsigned int table_index, hb_ot_map_t::paus
e_func_t pause_func) |
| 148 { | 159 { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 169 return; | 180 return; |
| 170 | 181 |
| 171 /* Sort features and merge duplicates */ | 182 /* Sort features and merge duplicates */ |
| 172 { | 183 { |
| 173 feature_infos.sort (); | 184 feature_infos.sort (); |
| 174 unsigned int j = 0; | 185 unsigned int j = 0; |
| 175 for (unsigned int i = 1; i < feature_infos.len; i++) | 186 for (unsigned int i = 1; i < feature_infos.len; i++) |
| 176 if (feature_infos[i].tag != feature_infos[j].tag) | 187 if (feature_infos[i].tag != feature_infos[j].tag) |
| 177 feature_infos[++j] = feature_infos[i]; | 188 feature_infos[++j] = feature_infos[i]; |
| 178 else { | 189 else { |
| 179 » if (feature_infos[i].global) { | 190 » if (feature_infos[i].flags & F_GLOBAL) { |
| 180 » feature_infos[j].global = true; | 191 » feature_infos[j].flags |= F_GLOBAL; |
| 181 feature_infos[j].max_value = feature_infos[i].max_value; | 192 feature_infos[j].max_value = feature_infos[i].max_value; |
| 182 feature_infos[j].default_value = feature_infos[i].default_value; | 193 feature_infos[j].default_value = feature_infos[i].default_value; |
| 183 } else { | 194 } else { |
| 184 » feature_infos[j].global = false; | 195 » feature_infos[j].flags &= ~F_GLOBAL; |
| 185 feature_infos[j].max_value = MAX (feature_infos[j].max_value, feature_
infos[i].max_value); | 196 feature_infos[j].max_value = MAX (feature_infos[j].max_value, feature_
infos[i].max_value); |
| 197 /* Inherit default_value from j */ |
| 186 } | 198 } |
| 187 » feature_infos[j].has_fallback = feature_infos[j].has_fallback || feature
_infos[i].has_fallback; | 199 » feature_infos[j].flags |= (feature_infos[i].flags & F_HAS_FALLBACK); |
| 188 feature_infos[j].stage[0] = MIN (feature_infos[j].stage[0], feature_info
s[i].stage[0]); | 200 feature_infos[j].stage[0] = MIN (feature_infos[j].stage[0], feature_info
s[i].stage[0]); |
| 189 feature_infos[j].stage[1] = MIN (feature_infos[j].stage[1], feature_info
s[i].stage[1]); | 201 feature_infos[j].stage[1] = MIN (feature_infos[j].stage[1], feature_info
s[i].stage[1]); |
| 190 /* Inherit default_value from j */ | |
| 191 } | 202 } |
| 192 feature_infos.shrink (j + 1); | 203 feature_infos.shrink (j + 1); |
| 193 } | 204 } |
| 194 | 205 |
| 195 | 206 |
| 196 /* Allocate bits now */ | 207 /* Allocate bits now */ |
| 197 unsigned int next_bit = 1; | 208 unsigned int next_bit = 1; |
| 198 for (unsigned int i = 0; i < feature_infos.len; i++) { | 209 for (unsigned int i = 0; i < feature_infos.len; i++) { |
| 199 const feature_info_t *info = &feature_infos[i]; | 210 const feature_info_t *info = &feature_infos[i]; |
| 200 | 211 |
| 201 unsigned int bits_needed; | 212 unsigned int bits_needed; |
| 202 | 213 |
| 203 if (info->global && info->max_value == 1) | 214 if ((info->flags & F_GLOBAL) && info->max_value == 1) |
| 204 /* Uses the global bit */ | 215 /* Uses the global bit */ |
| 205 bits_needed = 0; | 216 bits_needed = 0; |
| 206 else | 217 else |
| 207 bits_needed = _hb_bit_storage (info->max_value); | 218 bits_needed = _hb_bit_storage (info->max_value); |
| 208 | 219 |
| 209 if (!info->max_value || next_bit + bits_needed > 8 * sizeof (hb_mask_t)) | 220 if (!info->max_value || next_bit + bits_needed > 8 * sizeof (hb_mask_t)) |
| 210 continue; /* Feature disabled, or not enough bits. */ | 221 continue; /* Feature disabled, or not enough bits. */ |
| 211 | 222 |
| 212 | 223 |
| 213 bool found = false; | 224 bool found = false; |
| 214 unsigned int feature_index[2]; | 225 unsigned int feature_index[2]; |
| 215 for (unsigned int table_index = 0; table_index < 2; table_index++) | 226 for (unsigned int table_index = 0; table_index < 2; table_index++) |
| 216 found |= hb_ot_layout_language_find_feature (face, | 227 found |= hb_ot_layout_language_find_feature (face, |
| 217 table_tags[table_index], | 228 table_tags[table_index], |
| 218 script_index[table_index], | 229 script_index[table_index], |
| 219 language_index[table_index], | 230 language_index[table_index], |
| 220 info->tag, | 231 info->tag, |
| 221 &feature_index[table_index]); | 232 &feature_index[table_index]); |
| 222 if (!found && !info->has_fallback) | 233 if (!found && !(info->flags & F_HAS_FALLBACK)) |
| 223 continue; | 234 continue; |
| 224 | 235 |
| 225 | 236 |
| 226 hb_ot_map_t::feature_map_t *map = m.features.push (); | 237 hb_ot_map_t::feature_map_t *map = m.features.push (); |
| 227 if (unlikely (!map)) | 238 if (unlikely (!map)) |
| 228 break; | 239 break; |
| 229 | 240 |
| 230 map->tag = info->tag; | 241 map->tag = info->tag; |
| 231 map->index[0] = feature_index[0]; | 242 map->index[0] = feature_index[0]; |
| 232 map->index[1] = feature_index[1]; | 243 map->index[1] = feature_index[1]; |
| 233 map->stage[0] = info->stage[0]; | 244 map->stage[0] = info->stage[0]; |
| 234 map->stage[1] = info->stage[1]; | 245 map->stage[1] = info->stage[1]; |
| 235 if (info->global && info->max_value == 1) { | 246 map->auto_zwj = !(info->flags & F_MANUAL_ZWJ); |
| 247 if ((info->flags & F_GLOBAL) && info->max_value == 1) { |
| 236 /* Uses the global bit */ | 248 /* Uses the global bit */ |
| 237 map->shift = 0; | 249 map->shift = 0; |
| 238 map->mask = 1; | 250 map->mask = 1; |
| 239 } else { | 251 } else { |
| 240 map->shift = next_bit; | 252 map->shift = next_bit; |
| 241 map->mask = (1 << (next_bit + bits_needed)) - (1 << next_bit); | 253 map->mask = (1 << (next_bit + bits_needed)) - (1 << next_bit); |
| 242 next_bit += bits_needed; | 254 next_bit += bits_needed; |
| 243 if (info->global) | 255 m.global_mask |= (info->default_value << map->shift) & map->mask; |
| 244 » m.global_mask |= (info->default_value << map->shift) & map->mask; | |
| 245 } | 256 } |
| 246 map->_1_mask = (1 << map->shift) & map->mask; | 257 map->_1_mask = (1 << map->shift) & map->mask; |
| 247 map->needs_fallback = !found; | 258 map->needs_fallback = !found; |
| 248 | 259 |
| 249 } | 260 } |
| 250 feature_infos.shrink (0); /* Done with these */ | 261 feature_infos.shrink (0); /* Done with these */ |
| 251 | 262 |
| 252 | 263 |
| 253 add_gsub_pause (NULL); | 264 add_gsub_pause (NULL); |
| 254 add_gpos_pause (NULL); | 265 add_gpos_pause (NULL); |
| 255 | 266 |
| 256 for (unsigned int table_index = 0; table_index < 2; table_index++) { | 267 for (unsigned int table_index = 0; table_index < 2; table_index++) { |
| 257 hb_tag_t table_tag = table_tags[table_index]; | 268 hb_tag_t table_tag = table_tags[table_index]; |
| 258 | 269 |
| 259 /* Collect lookup indices for features */ | 270 /* Collect lookup indices for features */ |
| 260 | 271 |
| 261 unsigned int required_feature_index; | 272 unsigned int required_feature_index; |
| 262 if (hb_ot_layout_language_get_required_feature_index (face, | 273 if (hb_ot_layout_language_get_required_feature_index (face, |
| 263 table_tag, | 274 table_tag, |
| 264 script_index[table_ind
ex], | 275 script_index[table_ind
ex], |
| 265 language_index[table_i
ndex], | 276 language_index[table_i
ndex], |
| 266 &required_feature_inde
x)) | 277 &required_feature_inde
x)) |
| 267 m.add_lookups (face, table_index, required_feature_index, 1); | 278 m.add_lookups (face, table_index, required_feature_index, 1, true); |
| 268 | 279 |
| 269 unsigned int pause_index = 0; | 280 unsigned int pause_index = 0; |
| 270 unsigned int last_num_lookups = 0; | 281 unsigned int last_num_lookups = 0; |
| 271 for (unsigned stage = 0; stage < current_stage[table_index]; stage++) | 282 for (unsigned stage = 0; stage < current_stage[table_index]; stage++) |
| 272 { | 283 { |
| 273 for (unsigned i = 0; i < m.features.len; i++) | 284 for (unsigned i = 0; i < m.features.len; i++) |
| 274 if (m.features[i].stage[table_index] == stage) | 285 if (m.features[i].stage[table_index] == stage) |
| 275 » m.add_lookups (face, table_index, m.features[i].index[table_index], m.
features[i].mask); | 286 » m.add_lookups (face, table_index, |
| 287 » » » m.features[i].index[table_index], |
| 288 » » » m.features[i].mask, |
| 289 » » » m.features[i].auto_zwj); |
| 276 | 290 |
| 277 /* Sort lookups and merge duplicates */ | 291 /* Sort lookups and merge duplicates */ |
| 278 if (last_num_lookups < m.lookups[table_index].len) | 292 if (last_num_lookups < m.lookups[table_index].len) |
| 279 { | 293 { |
| 280 m.lookups[table_index].sort (last_num_lookups, m.lookups[table_index].le
n); | 294 m.lookups[table_index].sort (last_num_lookups, m.lookups[table_index].le
n); |
| 281 | 295 |
| 282 unsigned int j = last_num_lookups; | 296 unsigned int j = last_num_lookups; |
| 283 for (unsigned int i = j + 1; i < m.lookups[table_index].len; i++) | 297 for (unsigned int i = j + 1; i < m.lookups[table_index].len; i++) |
| 284 if (m.lookups[table_index][i].index != m.lookups[table_index][j].index
) | 298 if (m.lookups[table_index][i].index != m.lookups[table_index][j].index
) |
| 285 m.lookups[table_index][++j] = m.lookups[table_index][i]; | 299 m.lookups[table_index][++j] = m.lookups[table_index][i]; |
| 286 else | 300 else |
| 301 { |
| 287 m.lookups[table_index][j].mask |= m.lookups[table_index][i].mask; | 302 m.lookups[table_index][j].mask |= m.lookups[table_index][i].mask; |
| 303 m.lookups[table_index][j].auto_zwj &= m.lookups[table_index][i].auto
_zwj; |
| 304 } |
| 288 m.lookups[table_index].shrink (j + 1); | 305 m.lookups[table_index].shrink (j + 1); |
| 289 } | 306 } |
| 290 | 307 |
| 291 last_num_lookups = m.lookups[table_index].len; | 308 last_num_lookups = m.lookups[table_index].len; |
| 292 | 309 |
| 293 if (pause_index < pauses[table_index].len && pauses[table_index][pause_ind
ex].stage == stage) { | 310 if (pause_index < pauses[table_index].len && pauses[table_index][pause_ind
ex].stage == stage) { |
| 294 hb_ot_map_t::pause_map_t *pause_map = m.pauses[table_index].push (); | 311 hb_ot_map_t::pause_map_t *pause_map = m.pauses[table_index].push (); |
| 295 if (likely (pause_map)) { | 312 if (likely (pause_map)) { |
| 296 pause_map->num_lookups = last_num_lookups; | 313 pause_map->num_lookups = last_num_lookups; |
| 297 pause_map->callback = pauses[table_index][pause_index].callback; | 314 pause_map->callback = pauses[table_index][pause_index].callback; |
| 298 } | 315 } |
| 299 | 316 |
| 300 pause_index++; | 317 pause_index++; |
| 301 } | 318 } |
| 302 } | 319 } |
| 303 } | 320 } |
| 304 } | 321 } |
| OLD | NEW |