OLD | NEW |
1 /* | 1 /* |
2 * Copyright © 2011,2012 Google, Inc. | 2 * Copyright © 2011,2012 Google, Inc. |
3 * | 3 * |
4 * This is part of HarfBuzz, a text shaping library. | 4 * This is part of HarfBuzz, a text shaping library. |
5 * | 5 * |
6 * Permission is hereby granted, without written agreement and without | 6 * Permission is hereby granted, without written agreement and without |
7 * license or royalty fees, to use, copy, modify, and distribute this | 7 * license or royalty fees, to use, copy, modify, and distribute this |
8 * software and its documentation for any purpose, provided that the | 8 * software and its documentation for any purpose, provided that the |
9 * above copyright notice and the following two paragraphs appear in | 9 * above copyright notice and the following two paragraphs appear in |
10 * all copies of this software. | 10 * all copies of this software. |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 { | 253 { |
254 case HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW: | 254 case HB_UNICODE_COMBINING_CLASS_DOUBLE_BELOW: |
255 case HB_UNICODE_COMBINING_CLASS_BELOW_LEFT: | 255 case HB_UNICODE_COMBINING_CLASS_BELOW_LEFT: |
256 case HB_UNICODE_COMBINING_CLASS_BELOW: | 256 case HB_UNICODE_COMBINING_CLASS_BELOW: |
257 case HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT: | 257 case HB_UNICODE_COMBINING_CLASS_BELOW_RIGHT: |
258 /* Add gap, fall-through. */ | 258 /* Add gap, fall-through. */ |
259 base_extents.height -= y_gap; | 259 base_extents.height -= y_gap; |
260 | 260 |
261 case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT: | 261 case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW_LEFT: |
262 case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW: | 262 case HB_UNICODE_COMBINING_CLASS_ATTACHED_BELOW: |
263 pos.y_offset += base_extents.y_bearing + base_extents.height - mark_extent
s.y_bearing; | 263 pos.y_offset = base_extents.y_bearing + base_extents.height - mark_extents
.y_bearing; |
| 264 /* Never shift up "below" marks. */ |
| 265 if ((y_gap > 0) == (pos.y_offset > 0)) |
| 266 { |
| 267 » base_extents.height -= pos.y_offset; |
| 268 » pos.y_offset = 0; |
| 269 } |
264 base_extents.height += mark_extents.height; | 270 base_extents.height += mark_extents.height; |
265 break; | 271 break; |
266 | 272 |
267 case HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE: | 273 case HB_UNICODE_COMBINING_CLASS_DOUBLE_ABOVE: |
268 case HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT: | 274 case HB_UNICODE_COMBINING_CLASS_ABOVE_LEFT: |
269 case HB_UNICODE_COMBINING_CLASS_ABOVE: | 275 case HB_UNICODE_COMBINING_CLASS_ABOVE: |
270 case HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT: | 276 case HB_UNICODE_COMBINING_CLASS_ABOVE_RIGHT: |
271 /* Add gap, fall-through. */ | 277 /* Add gap, fall-through. */ |
272 base_extents.y_bearing += y_gap; | 278 base_extents.y_bearing += y_gap; |
273 base_extents.height -= y_gap; | 279 base_extents.height -= y_gap; |
274 | 280 |
275 case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE: | 281 case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE: |
276 case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT: | 282 case HB_UNICODE_COMBINING_CLASS_ATTACHED_ABOVE_RIGHT: |
277 pos.y_offset += base_extents.y_bearing - (mark_extents.y_bearing + mark_ex
tents.height); | 283 pos.y_offset = base_extents.y_bearing - (mark_extents.y_bearing + mark_ext
ents.height); |
| 284 /* Don't shift down "above" marks too much. */ |
| 285 if ((y_gap > 0) != (pos.y_offset > 0)) |
| 286 { |
| 287 » unsigned int correction = -pos.y_offset / 2; |
| 288 » base_extents.y_bearing += correction; |
| 289 » base_extents.height -= correction; |
| 290 » pos.y_offset += correction; |
| 291 } |
278 base_extents.y_bearing -= mark_extents.height; | 292 base_extents.y_bearing -= mark_extents.height; |
279 base_extents.height += mark_extents.height; | 293 base_extents.height += mark_extents.height; |
280 break; | 294 break; |
281 } | 295 } |
282 } | 296 } |
283 | 297 |
284 static inline void | 298 static inline void |
285 position_around_base (const hb_ot_shape_plan_t *plan, | 299 position_around_base (const hb_ot_shape_plan_t *plan, |
286 hb_font_t *font, | 300 hb_font_t *font, |
287 hb_buffer_t *buffer, | 301 hb_buffer_t *buffer, |
288 unsigned int base, | 302 unsigned int base, |
289 unsigned int end) | 303 unsigned int end) |
290 { | 304 { |
291 hb_direction_t horiz_dir = HB_DIRECTION_INVALID; | 305 hb_direction_t horiz_dir = HB_DIRECTION_INVALID; |
292 hb_glyph_extents_t base_extents; | 306 hb_glyph_extents_t base_extents; |
293 if (!font->get_glyph_extents (buffer->info[base].codepoint, | 307 if (!font->get_glyph_extents (buffer->info[base].codepoint, |
294 &base_extents)) | 308 &base_extents)) |
295 { | 309 { |
296 /* If extents don't work, zero marks and go home. */ | 310 /* If extents don't work, zero marks and go home. */ |
297 zero_mark_advances (buffer, base + 1, end); | 311 zero_mark_advances (buffer, base + 1, end); |
298 return; | 312 return; |
299 } | 313 } |
300 base_extents.x_bearing += buffer->pos[base].x_offset; | 314 base_extents.x_bearing += buffer->pos[base].x_offset; |
301 base_extents.y_bearing += buffer->pos[base].y_offset; | 315 base_extents.y_bearing += buffer->pos[base].y_offset; |
302 | 316 |
303 unsigned int lig_id = get_lig_id (buffer->info[base]); | 317 unsigned int lig_id = _hb_glyph_info_get_lig_id (&buffer->info[base]); |
304 unsigned int num_lig_components = get_lig_num_comps (buffer->info[base]); | 318 unsigned int num_lig_components = _hb_glyph_info_get_lig_num_comps (&buffer->i
nfo[base]); |
305 | 319 |
306 hb_position_t x_offset = 0, y_offset = 0; | 320 hb_position_t x_offset = 0, y_offset = 0; |
307 if (HB_DIRECTION_IS_FORWARD (buffer->props.direction)) { | 321 if (HB_DIRECTION_IS_FORWARD (buffer->props.direction)) { |
308 x_offset -= buffer->pos[base].x_advance; | 322 x_offset -= buffer->pos[base].x_advance; |
309 y_offset -= buffer->pos[base].y_advance; | 323 y_offset -= buffer->pos[base].y_advance; |
310 } | 324 } |
311 | 325 |
312 hb_glyph_extents_t component_extents = base_extents; | 326 hb_glyph_extents_t component_extents = base_extents; |
313 unsigned int last_lig_component = (unsigned int) -1; | 327 unsigned int last_lig_component = (unsigned int) -1; |
314 unsigned int last_combining_class = 255; | 328 unsigned int last_combining_class = 255; |
315 hb_glyph_extents_t cluster_extents = base_extents; /* Initialization is just t
o shut gcc up. */ | 329 hb_glyph_extents_t cluster_extents = base_extents; /* Initialization is just t
o shut gcc up. */ |
316 for (unsigned int i = base + 1; i < end; i++) | 330 for (unsigned int i = base + 1; i < end; i++) |
317 if (_hb_glyph_info_get_modified_combining_class (&buffer->info[i])) | 331 if (_hb_glyph_info_get_modified_combining_class (&buffer->info[i])) |
318 { | 332 { |
319 if (num_lig_components > 1) { | 333 if (num_lig_components > 1) { |
320 » unsigned int this_lig_id = get_lig_id (buffer->info[i]); | 334 » unsigned int this_lig_id = _hb_glyph_info_get_lig_id (&buffer->info[i]); |
321 » unsigned int this_lig_component = get_lig_comp (buffer->info[i]) - 1; | 335 » unsigned int this_lig_component = _hb_glyph_info_get_lig_comp (&buffer->
info[i]) - 1; |
322 /* Conditions for attaching to the last component. */ | 336 /* Conditions for attaching to the last component. */ |
323 if (!lig_id || lig_id != this_lig_id || this_lig_component >= num_lig_co
mponents) | 337 if (!lig_id || lig_id != this_lig_id || this_lig_component >= num_lig_co
mponents) |
324 this_lig_component = num_lig_components - 1; | 338 this_lig_component = num_lig_components - 1; |
325 if (last_lig_component != this_lig_component) | 339 if (last_lig_component != this_lig_component) |
326 { | 340 { |
327 last_lig_component = this_lig_component; | 341 last_lig_component = this_lig_component; |
328 last_combining_class = 255; | 342 last_combining_class = 255; |
329 component_extents = base_extents; | 343 component_extents = base_extents; |
330 if (unlikely (horiz_dir == HB_DIRECTION_INVALID)) { | 344 if (unlikely (horiz_dir == HB_DIRECTION_INVALID)) { |
331 if (HB_DIRECTION_IS_HORIZONTAL (plan->props.direction)) | 345 if (HB_DIRECTION_IS_HORIZONTAL (plan->props.direction)) |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 position_cluster (plan, font, buffer, start, count); | 423 position_cluster (plan, font, buffer, start, count); |
410 } | 424 } |
411 | 425 |
412 | 426 |
413 /* Performs old-style TrueType kerning. */ | 427 /* Performs old-style TrueType kerning. */ |
414 void | 428 void |
415 _hb_ot_shape_fallback_kern (const hb_ot_shape_plan_t *plan, | 429 _hb_ot_shape_fallback_kern (const hb_ot_shape_plan_t *plan, |
416 hb_font_t *font, | 430 hb_font_t *font, |
417 hb_buffer_t *buffer) | 431 hb_buffer_t *buffer) |
418 { | 432 { |
419 unsigned int count = buffer->len; | |
420 hb_mask_t kern_mask = plan->map.get_1_mask (HB_DIRECTION_IS_HORIZONTAL (buffer
->props.direction) ? | 433 hb_mask_t kern_mask = plan->map.get_1_mask (HB_DIRECTION_IS_HORIZONTAL (buffer
->props.direction) ? |
421 HB_TAG ('k','e','r','n') : HB_TAG
('v','k','r','n')); | 434 HB_TAG ('k','e','r','n') : HB_TAG
('v','k','r','n')); |
| 435 if (!kern_mask) return; |
422 | 436 |
423 OT::hb_apply_context_t c (1, font, buffer, kern_mask, true/*auto_zwj*/); | 437 unsigned int count = buffer->len; |
| 438 |
| 439 OT::hb_apply_context_t c (1, font, buffer); |
| 440 c.set_lookup_mask (kern_mask); |
424 c.set_lookup_props (OT::LookupFlag::IgnoreMarks); | 441 c.set_lookup_props (OT::LookupFlag::IgnoreMarks); |
425 | 442 |
426 for (buffer->idx = 0; buffer->idx < count;) | 443 hb_glyph_info_t *info = buffer->info; |
| 444 hb_glyph_position_t *pos = buffer->pos; |
| 445 |
| 446 for (unsigned int idx = 0; idx < count;) |
427 { | 447 { |
428 OT::hb_apply_context_t::skipping_forward_iterator_t skippy_iter (&c, buffer-
>idx, 1); | 448 OT::hb_apply_context_t::skipping_forward_iterator_t skippy_iter (&c, idx, 1)
; |
429 if (!skippy_iter.next ()) | 449 if (!skippy_iter.next ()) |
430 { | 450 { |
431 buffer->idx++; | 451 idx++; |
432 continue; | 452 continue; |
433 } | 453 } |
434 | 454 |
435 hb_position_t x_kern, y_kern, kern1, kern2; | 455 hb_position_t x_kern, y_kern; |
436 font->get_glyph_kerning_for_direction (buffer->info[buffer->idx].codepoint, | 456 font->get_glyph_kerning_for_direction (info[idx].codepoint, |
437 » » » » » buffer->info[skippy_iter.idx].codepoi
nt, | 457 » » » » » info[skippy_iter.idx].codepoint, |
438 buffer->props.direction, | 458 buffer->props.direction, |
439 &x_kern, &y_kern); | 459 &x_kern, &y_kern); |
440 | 460 |
441 kern1 = x_kern >> 1; | 461 if (x_kern) |
442 kern2 = x_kern - kern1; | 462 { |
443 buffer->pos[buffer->idx].x_advance += kern1; | 463 hb_position_t kern1 = x_kern >> 1; |
444 buffer->pos[skippy_iter.idx].x_advance += kern2; | 464 hb_position_t kern2 = x_kern - kern1; |
445 buffer->pos[skippy_iter.idx].x_offset += kern2; | 465 pos[idx].x_advance += kern1; |
| 466 pos[skippy_iter.idx].x_advance += kern2; |
| 467 pos[skippy_iter.idx].x_offset += kern2; |
| 468 } |
446 | 469 |
447 kern1 = y_kern >> 1; | 470 if (y_kern) |
448 kern2 = y_kern - kern1; | 471 { |
449 buffer->pos[buffer->idx].y_advance += kern1; | 472 hb_position_t kern1 = y_kern >> 1; |
450 buffer->pos[skippy_iter.idx].y_advance += kern2; | 473 hb_position_t kern2 = y_kern - kern1; |
451 buffer->pos[skippy_iter.idx].y_offset += kern2; | 474 pos[idx].y_advance += kern1; |
| 475 pos[skippy_iter.idx].y_advance += kern2; |
| 476 pos[skippy_iter.idx].y_offset += kern2; |
| 477 } |
452 | 478 |
453 buffer->idx = skippy_iter.idx; | 479 idx = skippy_iter.idx; |
454 } | 480 } |
455 } | 481 } |
OLD | NEW |