diff options
| author | Eli Zaretskii | 2014-10-16 16:18:00 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2014-10-16 16:18:00 +0300 |
| commit | e23e97d504fcb6c5d4da734c40be70de506352f4 (patch) | |
| tree | dc9e9a036708a14fa3e4051bf52785696361f11e | |
| parent | b8ec977659df3970a6c8afb7a5b79c9b61e08307 (diff) | |
| download | emacs-e23e97d504fcb6c5d4da734c40be70de506352f4.tar.gz emacs-e23e97d504fcb6c5d4da734c40be70de506352f4.zip | |
Cherry-pick a fix from trunk; fix level handling in bidi_resolve_brackets.
| -rw-r--r-- | src/bidi.c | 60 |
1 files changed, 47 insertions, 13 deletions
diff --git a/src/bidi.c b/src/bidi.c index 464879ddf98..76929b62198 100644 --- a/src/bidi.c +++ b/src/bidi.c | |||
| @@ -2450,7 +2450,7 @@ bidi_find_bracket_pairs (struct bidi_it *bidi_it) | |||
| 2450 | } | 2450 | } |
| 2451 | else if (bidi_get_category (bidi_it->type_after_wn) != NEUTRAL) | 2451 | else if (bidi_get_category (bidi_it->type_after_wn) != NEUTRAL) |
| 2452 | { | 2452 | { |
| 2453 | unsigned flag; | 2453 | unsigned flag = 0; |
| 2454 | int sp; | 2454 | int sp; |
| 2455 | 2455 | ||
| 2456 | /* Whenever we see a strong type, update the flags of | 2456 | /* Whenever we see a strong type, update the flags of |
| @@ -2472,8 +2472,11 @@ bidi_find_bracket_pairs (struct bidi_it *bidi_it) | |||
| 2472 | default: | 2472 | default: |
| 2473 | break; | 2473 | break; |
| 2474 | } | 2474 | } |
| 2475 | for (sp = bpa_sp; sp >= 0; sp--) | 2475 | if (flag) |
| 2476 | bpa_stack[sp].flags |= flag; | 2476 | { |
| 2477 | for (sp = bpa_sp; sp >= 0; sp--) | ||
| 2478 | bpa_stack[sp].flags |= flag; | ||
| 2479 | } | ||
| 2477 | } | 2480 | } |
| 2478 | old_sidx = bidi_it->stack_idx; | 2481 | old_sidx = bidi_it->stack_idx; |
| 2479 | type = bidi_resolve_weak (bidi_it); | 2482 | type = bidi_resolve_weak (bidi_it); |
| @@ -2517,6 +2520,27 @@ bidi_find_bracket_pairs (struct bidi_it *bidi_it) | |||
| 2517 | return retval; | 2520 | return retval; |
| 2518 | } | 2521 | } |
| 2519 | 2522 | ||
| 2523 | static void | ||
| 2524 | bidi_record_prev_for_neutral (struct bidi_saved_info *info, int level) | ||
| 2525 | { | ||
| 2526 | int idx; | ||
| 2527 | |||
| 2528 | for (idx = bidi_cache_last_idx + 1; idx < bidi_cache_idx; idx++) | ||
| 2529 | { | ||
| 2530 | int lev = bidi_cache[idx].level_stack[bidi_cache[idx].stack_idx].level; | ||
| 2531 | |||
| 2532 | if (bidi_cache[idx].type_after_wn == NEUTRAL_B) | ||
| 2533 | return; /* no cache slot to update */ | ||
| 2534 | if (lev <= level) | ||
| 2535 | { | ||
| 2536 | eassert (lev == level); | ||
| 2537 | bidi_cache[idx].prev_for_neutral = *info; | ||
| 2538 | break; | ||
| 2539 | } | ||
| 2540 | } | ||
| 2541 | eassert (idx < bidi_cache_idx); | ||
| 2542 | } | ||
| 2543 | |||
| 2520 | static bidi_type_t | 2544 | static bidi_type_t |
| 2521 | bidi_resolve_brackets (struct bidi_it *bidi_it) | 2545 | bidi_resolve_brackets (struct bidi_it *bidi_it) |
| 2522 | { | 2546 | { |
| @@ -2526,7 +2550,14 @@ bidi_resolve_brackets (struct bidi_it *bidi_it) | |||
| 2526 | int ch; | 2550 | int ch; |
| 2527 | struct bidi_saved_info tem_info; | 2551 | struct bidi_saved_info tem_info; |
| 2528 | 2552 | ||
| 2529 | bidi_remember_char (&tem_info, bidi_it, 1); | 2553 | /* Record the prev_for_neutral type either from the previous |
| 2554 | character, if it was a strong or AN/EN, or from the | ||
| 2555 | prev_for_neutral information recvorded previously. */ | ||
| 2556 | if (bidi_it->type == STRONG_L || bidi_it->type == STRONG_R | ||
| 2557 | || bidi_it->type == WEAK_AN || bidi_it->type == WEAK_EN) | ||
| 2558 | bidi_remember_char (&tem_info, bidi_it, 1); | ||
| 2559 | else | ||
| 2560 | tem_info = bidi_it->prev_for_neutral; | ||
| 2530 | if (!bidi_it->first_elt) | 2561 | if (!bidi_it->first_elt) |
| 2531 | { | 2562 | { |
| 2532 | type = bidi_cache_find (bidi_it->charpos + bidi_it->nchars, 1, bidi_it); | 2563 | type = bidi_cache_find (bidi_it->charpos + bidi_it->nchars, 1, bidi_it); |
| @@ -2540,10 +2571,18 @@ bidi_resolve_brackets (struct bidi_it *bidi_it) | |||
| 2540 | } | 2571 | } |
| 2541 | else | 2572 | else |
| 2542 | { | 2573 | { |
| 2574 | /* If the cached state shows an increase of embedding level due | ||
| 2575 | to an isolate initiator, we need to update the 1st cached | ||
| 2576 | state of the next run of the current isolating sequence with | ||
| 2577 | the prev_for_neutral information, so that it will be picked | ||
| 2578 | up when we advanced to that next run. */ | ||
| 2579 | if (bidi_it->level_stack[bidi_it->stack_idx].level > prev_level | ||
| 2580 | && bidi_it->level_stack[bidi_it->stack_idx].isolate_status) | ||
| 2581 | bidi_record_prev_for_neutral (&tem_info, prev_level); | ||
| 2543 | if (type == NEUTRAL_ON | 2582 | if (type == NEUTRAL_ON |
| 2544 | && bidi_paired_bracket_type (ch) == BIDI_BRACKET_OPEN) | 2583 | && bidi_paired_bracket_type (ch) == BIDI_BRACKET_OPEN) |
| 2545 | { | 2584 | { |
| 2546 | if (bidi_it->level_stack[bidi_it->stack_idx].level == prev_level) | 2585 | if (bidi_it->level_stack[bidi_it->stack_idx].level <= prev_level) |
| 2547 | { | 2586 | { |
| 2548 | if (bidi_it->bracket_pairing_pos > 0) | 2587 | if (bidi_it->bracket_pairing_pos > 0) |
| 2549 | { | 2588 | { |
| @@ -2555,20 +2594,15 @@ bidi_resolve_brackets (struct bidi_it *bidi_it) | |||
| 2555 | else | 2594 | else |
| 2556 | { | 2595 | { |
| 2557 | /* Higher levels were not BPA-resolved yet, even if | 2596 | /* Higher levels were not BPA-resolved yet, even if |
| 2558 | cached by bidi_find_bracket_pairs. Lower levels were | 2597 | cached by bidi_find_bracket_pairs. Force application |
| 2559 | probably processed by bidi_find_bracket_pairs, but we | 2598 | of BPA to the new level now. */ |
| 2560 | have no easy way of retaining the prev_for_neutral | ||
| 2561 | from the previous level run of the isolating | ||
| 2562 | sequence. Force application of BPA now. */ | ||
| 2563 | if (bidi_find_bracket_pairs (bidi_it)) | 2599 | if (bidi_find_bracket_pairs (bidi_it)) |
| 2564 | resolve_bracket = true; | 2600 | resolve_bracket = true; |
| 2565 | } | 2601 | } |
| 2566 | } | 2602 | } |
| 2567 | /* Keep track of the prev_for_neutral type, needed for resolving | 2603 | /* Keep track of the prev_for_neutral type, needed for resolving |
| 2568 | brackets below and for resolving neutrals in bidi_resolve_neutral. */ | 2604 | brackets below and for resolving neutrals in bidi_resolve_neutral. */ |
| 2569 | if (bidi_it->level_stack[bidi_it->stack_idx].level == prev_level | 2605 | if (bidi_it->level_stack[bidi_it->stack_idx].level == prev_level) |
| 2570 | && (tem_info.type == STRONG_L || tem_info.type == STRONG_R | ||
| 2571 | || tem_info.type == WEAK_AN || tem_info.type == WEAK_EN)) | ||
| 2572 | bidi_it->prev_for_neutral = tem_info; | 2606 | bidi_it->prev_for_neutral = tem_info; |
| 2573 | } | 2607 | } |
| 2574 | 2608 | ||