aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2014-08-30 15:19:26 +0300
committerEli Zaretskii2014-08-30 15:19:26 +0300
commit991b257bf8e216f036b30c5a79fdae63b4954e02 (patch)
treeb445ca8af25dac6178db0b2cc9a465f9718848be /src
parent5d84f5d6985b2f9d146519d3c8a2147fa3d9aafd (diff)
downloademacs-991b257bf8e216f036b30c5a79fdae63b4954e02.tar.gz
emacs-991b257bf8e216f036b30c5a79fdae63b4954e02.zip
Updated pushing and popping the bidi stack, and sos calculations.
Added the necessary members to bidi_stack.
Diffstat (limited to 'src')
-rw-r--r--src/bidi.c66
-rw-r--r--src/dispextern.h13
2 files changed, 65 insertions, 14 deletions
diff --git a/src/bidi.c b/src/bidi.c
index e01b77d0e96..a99fd748981 100644
--- a/src/bidi.c
+++ b/src/bidi.c
@@ -407,7 +407,6 @@ bidi_set_sos_type (struct bidi_it *bidi_it, int level_before, int level_after)
407 /* FIXME: should the default sos direction be user selectable? */ 407 /* FIXME: should the default sos direction be user selectable? */
408 bidi_it->sos = ((higher_level & 1) != 0 ? R2L : L2R); 408 bidi_it->sos = ((higher_level & 1) != 0 ? R2L : L2R);
409 409
410 /* FIXME: This needs to be reviewed!! */
411 bidi_it->prev.type = UNKNOWN_BT; 410 bidi_it->prev.type = UNKNOWN_BT;
412 bidi_it->last_strong.type = bidi_it->last_strong.type_after_w1 411 bidi_it->last_strong.type = bidi_it->last_strong.type_after_w1
413 = bidi_it->last_strong.orig_type = UNKNOWN_BT; 412 = bidi_it->last_strong.orig_type = UNKNOWN_BT;
@@ -425,21 +424,55 @@ static void
425bidi_push_embedding_level (struct bidi_it *bidi_it, 424bidi_push_embedding_level (struct bidi_it *bidi_it,
426 int level, bidi_dir_t override, bool isolate_status) 425 int level, bidi_dir_t override, bool isolate_status)
427{ 426{
427 struct bidi_stack st;
428
428 bidi_it->stack_idx++; 429 bidi_it->stack_idx++;
429 eassert (bidi_it->stack_idx < BIDI_MAXDEPTH+2+1); 430 eassert (bidi_it->stack_idx < BIDI_MAXDEPTH+2+1);
430 bidi_it->level_stack[bidi_it->stack_idx].level = level; 431 st = bidi_it->level_stack[bidi_it->stack_idx];
431 bidi_it->level_stack[bidi_it->stack_idx].override = override; 432 st.level = level;
432 bidi_it->level_stack[bidi_it->stack_idx].isolate_status = isolate_status; 433 st.override = override;
434 st.isolate_status = isolate_status;
435 if (isolate_status)
436 {
437 st.prev = bidi_it->prev;
438 st.last_strong = bidi_it->last_strong;
439 st.prev_for_neutral = bidi_it->prev_for_neutral;
440 st.next_for_neutral = bidi_it->next_for_neutral;
441 st.next_for_ws = bidi_it->next_for_ws;
442 st.next_en_pos = bidi_it->next_en_pos;
443 st.next_en_type = bidi_it->next_en_type;
444 st.sos = bidi_it->sos;
445 }
433} 446}
434 447
435/* Pop the embedding level and directional override status from the 448/* Pop from the stack the embedding level, the directional override
436 stack, and return the new level. */ 449 status, and optionally saved information for the isolating run
450 sequence. Return the new level. */
437static int 451static int
438bidi_pop_embedding_level (struct bidi_it *bidi_it) 452bidi_pop_embedding_level (struct bidi_it *bidi_it)
439{ 453{
440 /* UAX#9 says to ignore invalid PDFs. */ 454 /* UAX#9 says to ignore invalid PDFs (X7, last bullet)
455 and PDIs (X6a, 2nd bullet). */
441 if (bidi_it->stack_idx > 0) 456 if (bidi_it->stack_idx > 0)
442 bidi_it->stack_idx--; 457 {
458 bool isolate_status
459 = bidi_it->level_stack[bidi_it->stack_idx].isolate_status;
460 struct bidi_stack st;
461
462 st = bidi_it->level_stack[bidi_it->stack_idx];
463 if (isolate_status)
464 {
465 bidi_it->prev = st.prev;
466 bidi_it->last_strong = st.last_strong;
467 bidi_it->prev_for_neutral = st.prev_for_neutral;
468 bidi_it->next_for_neutral = st.next_for_neutral;
469 bidi_it->next_for_ws = st.next_for_ws;
470 bidi_it->next_en_pos = st.next_en_pos;
471 bidi_it->next_en_type = st.next_en_type;
472 bidi_it->sos = st.sos;
473 }
474 bidi_it->stack_idx--;
475 }
443 return bidi_it->level_stack[bidi_it->stack_idx].level; 476 return bidi_it->level_stack[bidi_it->stack_idx].level;
444} 477}
445 478
@@ -475,6 +508,9 @@ bidi_copy_it (struct bidi_it *to, struct bidi_it *from)
475 Caching the bidi iterator states 508 Caching the bidi iterator states
476 ***********************************************************************/ 509 ***********************************************************************/
477 510
511/* We allocate and de-allocate the cache in chunks of this size (in
512 characters). 200 was chosen as an upper limit for reasonably-long
513 lines in a text file/buffer. */
478#define BIDI_CACHE_CHUNK 200 514#define BIDI_CACHE_CHUNK 200
479static struct bidi_it *bidi_cache; 515static struct bidi_it *bidi_cache;
480static ptrdiff_t bidi_cache_size = 0; 516static ptrdiff_t bidi_cache_size = 0;
@@ -954,6 +990,7 @@ static void
954bidi_set_paragraph_end (struct bidi_it *bidi_it) 990bidi_set_paragraph_end (struct bidi_it *bidi_it)
955{ 991{
956 bidi_it->invalid_levels = 0; 992 bidi_it->invalid_levels = 0;
993 bidi_it->invalid_isolates = 0;
957 bidi_it->stack_idx = 0; 994 bidi_it->stack_idx = 0;
958 bidi_it->resolved_level = bidi_it->level_stack[0].level; 995 bidi_it->resolved_level = bidi_it->level_stack[0].level;
959} 996}
@@ -1016,7 +1053,6 @@ bidi_line_init (struct bidi_it *bidi_it)
1016 bidi_it->invalid_isolates = 0; /* X1 */ 1053 bidi_it->invalid_isolates = 0; /* X1 */
1017 /* Setting this to zero will force its recomputation the first time 1054 /* Setting this to zero will force its recomputation the first time
1018 we need it for W5. */ 1055 we need it for W5. */
1019 /* FIXME: Review this!!! */
1020 bidi_it->next_en_pos = 0; 1056 bidi_it->next_en_pos = 0;
1021 bidi_it->next_en_type = UNKNOWN_BT; 1057 bidi_it->next_en_type = UNKNOWN_BT;
1022 bidi_it->next_for_ws.type = UNKNOWN_BT; 1058 bidi_it->next_for_ws.type = UNKNOWN_BT;
@@ -2010,10 +2046,16 @@ bidi_resolve_weak (struct bidi_it *bidi_it)
2010 emacs_abort (); 2046 emacs_abort ();
2011 2047
2012 eassert (prev_level >= 0); 2048 eassert (prev_level >= 0);
2013 if (new_level != prev_level 2049 if (new_level > prev_level
2050 /* When the embedding level goes down, we only need to compute
2051 the type of sos if this level is not an isolate, because the
2052 sos type of the isolating sequence was already computed and
2053 saved on the stack. */
2054 || (new_level < prev_level
2055 && !bidi_it->level_stack[bidi_it->stack_idx].isolate_status)
2014 || bidi_it->type == NEUTRAL_B) 2056 || bidi_it->type == NEUTRAL_B)
2015 { 2057 {
2016 /* We've got a new embedding level run, compute the directional 2058 /* We've got a new isolating sequence, compute the directional
2017 type of sos and initialize per-run variables (UAX#9, clause 2059 type of sos and initialize per-run variables (UAX#9, clause
2018 X10). */ 2060 X10). */
2019 bidi_set_sos_type (bidi_it, prev_level, new_level); 2061 bidi_set_sos_type (bidi_it, prev_level, new_level);
@@ -2350,7 +2392,7 @@ bidi_resolve_neutral (struct bidi_it *bidi_it)
2350 /* FALLTHROUGH */ 2392 /* FALLTHROUGH */
2351 case NEUTRAL_B: 2393 case NEUTRAL_B:
2352 /* Marched all the way to the end of this level run. 2394 /* Marched all the way to the end of this level run.
2353 We need to use the eor type, whose information is 2395 We need to use the eos type, whose information is
2354 stored by bidi_set_sos_type in the prev_for_neutral 2396 stored by bidi_set_sos_type in the prev_for_neutral
2355 member. */ 2397 member. */
2356 if (saved_it.type != WEAK_BN 2398 if (saved_it.type != WEAK_BN
diff --git a/src/dispextern.h b/src/dispextern.h
index a5b78a6f952..5e90a4ef23b 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -1908,12 +1908,21 @@ struct bidi_saved_info {
1908 bidi_type_t orig_type; /* type as we found it in the buffer */ 1908 bidi_type_t orig_type; /* type as we found it in the buffer */
1909}; 1909};
1910 1910
1911/* Data type for keeping track of saved embedding levels, override 1911/* Data type for keeping track of information about saved embedding
1912 status, and isolate status information. */ 1912 levels, override status, isolate status, and isolating sequence
1913 runs. */
1913struct bidi_stack { 1914struct bidi_stack {
1914 char level; 1915 char level;
1915 bool isolate_status; 1916 bool isolate_status;
1916 bidi_dir_t override; 1917 bidi_dir_t override;
1918 struct bidi_saved_info prev;
1919 struct bidi_saved_info last_strong;
1920 struct bidi_saved_info next_for_neutral;
1921 struct bidi_saved_info prev_for_neutral;
1922 struct bidi_saved_info next_for_ws;
1923 ptrdiff_t next_en_pos;
1924 bidi_type_t next_en_type;
1925 bidi_dir_t sos;
1917}; 1926};
1918 1927
1919/* Data type for storing information about a string being iterated on. */ 1928/* Data type for storing information about a string being iterated on. */