Skip bidi if no RTL characters are present
This commit is contained in:
parent
e8d0a8f85c
commit
a06cec31e7
1 changed files with 152 additions and 138 deletions
290
normal/charset.c
290
normal/charset.c
|
@ -859,6 +859,7 @@ grub_bidi_line_logical_to_visual (const grub_uint32_t *logical,
|
||||||
unsigned run_start, run_end;
|
unsigned run_start, run_end;
|
||||||
struct grub_unicode_glyph *visual;
|
struct grub_unicode_glyph *visual;
|
||||||
unsigned cur_level;
|
unsigned cur_level;
|
||||||
|
int bidi_needed = 0;
|
||||||
|
|
||||||
auto void push_stack (unsigned new_override, unsigned new_level);
|
auto void push_stack (unsigned new_override, unsigned new_level);
|
||||||
void push_stack (unsigned new_override, unsigned new_level)
|
void push_stack (unsigned new_override, unsigned new_level)
|
||||||
|
@ -967,9 +968,11 @@ grub_bidi_line_logical_to_visual (const grub_uint32_t *logical,
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case GRUB_BIDI_TYPE_RLE:
|
case GRUB_BIDI_TYPE_RLE:
|
||||||
|
bidi_needed = 1;
|
||||||
push_stack (cur_override, (cur_level | 1) + 1);
|
push_stack (cur_override, (cur_level | 1) + 1);
|
||||||
break;
|
break;
|
||||||
case GRUB_BIDI_TYPE_RLO:
|
case GRUB_BIDI_TYPE_RLO:
|
||||||
|
bidi_needed = 1;
|
||||||
push_stack (OVERRIDE_R, (cur_level | 1) + 1);
|
push_stack (OVERRIDE_R, (cur_level | 1) + 1);
|
||||||
break;
|
break;
|
||||||
case GRUB_BIDI_TYPE_LRE:
|
case GRUB_BIDI_TYPE_LRE:
|
||||||
|
@ -983,6 +986,9 @@ grub_bidi_line_logical_to_visual (const grub_uint32_t *logical,
|
||||||
break;
|
break;
|
||||||
case GRUB_BIDI_TYPE_BN:
|
case GRUB_BIDI_TYPE_BN:
|
||||||
break;
|
break;
|
||||||
|
case GRUB_BIDI_TYPE_R:
|
||||||
|
case GRUB_BIDI_TYPE_AL:
|
||||||
|
bidi_needed = 1;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
if (join_state == JOIN_FORCE)
|
if (join_state == JOIN_FORCE)
|
||||||
|
@ -1017,166 +1023,174 @@ grub_bidi_line_logical_to_visual (const grub_uint32_t *logical,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (run_start = 0; run_start < visual_len; run_start = run_end)
|
if (bidi_needed)
|
||||||
{
|
{
|
||||||
unsigned prev_level, next_level, cur_run_level;
|
for (run_start = 0; run_start < visual_len; run_start = run_end)
|
||||||
unsigned last_type, last_strong_type;
|
|
||||||
for (run_end = run_start; run_end < visual_len &&
|
|
||||||
levels[run_end] == levels[run_start]; run_end++);
|
|
||||||
if (run_start == 0)
|
|
||||||
prev_level = base_level;
|
|
||||||
else
|
|
||||||
prev_level = levels[run_start - 1];
|
|
||||||
if (run_end == visual_len)
|
|
||||||
next_level = base_level;
|
|
||||||
else
|
|
||||||
next_level = levels[run_end];
|
|
||||||
cur_run_level = levels[run_start];
|
|
||||||
if (prev_level & 1)
|
|
||||||
last_type = GRUB_BIDI_TYPE_R;
|
|
||||||
else
|
|
||||||
last_type = GRUB_BIDI_TYPE_L;
|
|
||||||
last_strong_type = last_type;
|
|
||||||
for (i = run_start; i < run_end; i++)
|
|
||||||
{
|
{
|
||||||
switch (resolved_types[i])
|
unsigned prev_level, next_level, cur_run_level;
|
||||||
|
unsigned last_type, last_strong_type;
|
||||||
|
for (run_end = run_start; run_end < visual_len &&
|
||||||
|
levels[run_end] == levels[run_start]; run_end++);
|
||||||
|
if (run_start == 0)
|
||||||
|
prev_level = base_level;
|
||||||
|
else
|
||||||
|
prev_level = levels[run_start - 1];
|
||||||
|
if (run_end == visual_len)
|
||||||
|
next_level = base_level;
|
||||||
|
else
|
||||||
|
next_level = levels[run_end];
|
||||||
|
cur_run_level = levels[run_start];
|
||||||
|
if (prev_level & 1)
|
||||||
|
last_type = GRUB_BIDI_TYPE_R;
|
||||||
|
else
|
||||||
|
last_type = GRUB_BIDI_TYPE_L;
|
||||||
|
last_strong_type = last_type;
|
||||||
|
for (i = run_start; i < run_end; i++)
|
||||||
{
|
{
|
||||||
case GRUB_BIDI_TYPE_NSM:
|
switch (resolved_types[i])
|
||||||
resolved_types[i] = last_type;
|
{
|
||||||
break;
|
case GRUB_BIDI_TYPE_NSM:
|
||||||
case GRUB_BIDI_TYPE_EN:
|
resolved_types[i] = last_type;
|
||||||
if (last_strong_type == GRUB_BIDI_TYPE_AL)
|
break;
|
||||||
resolved_types[i] = GRUB_BIDI_TYPE_AN;
|
case GRUB_BIDI_TYPE_EN:
|
||||||
break;
|
if (last_strong_type == GRUB_BIDI_TYPE_AL)
|
||||||
case GRUB_BIDI_TYPE_L:
|
resolved_types[i] = GRUB_BIDI_TYPE_AN;
|
||||||
case GRUB_BIDI_TYPE_R:
|
break;
|
||||||
last_strong_type = resolved_types[i];
|
case GRUB_BIDI_TYPE_L:
|
||||||
break;
|
case GRUB_BIDI_TYPE_R:
|
||||||
case GRUB_BIDI_TYPE_ES:
|
last_strong_type = resolved_types[i];
|
||||||
if (last_type == GRUB_BIDI_TYPE_EN
|
break;
|
||||||
&& i + 1 < run_end
|
case GRUB_BIDI_TYPE_ES:
|
||||||
&& resolved_types[i + 1] == GRUB_BIDI_TYPE_EN)
|
if (last_type == GRUB_BIDI_TYPE_EN
|
||||||
resolved_types[i] = GRUB_BIDI_TYPE_EN;
|
&& i + 1 < run_end
|
||||||
else
|
&& resolved_types[i + 1] == GRUB_BIDI_TYPE_EN)
|
||||||
resolved_types[i] = GRUB_BIDI_TYPE_ON;
|
|
||||||
break;
|
|
||||||
case GRUB_BIDI_TYPE_ET:
|
|
||||||
{
|
|
||||||
unsigned j;
|
|
||||||
if (last_type == GRUB_BIDI_TYPE_EN)
|
|
||||||
{
|
|
||||||
resolved_types[i] = GRUB_BIDI_TYPE_EN;
|
resolved_types[i] = GRUB_BIDI_TYPE_EN;
|
||||||
break;
|
else
|
||||||
}
|
resolved_types[i] = GRUB_BIDI_TYPE_ON;
|
||||||
for (j = i; j < run_end
|
break;
|
||||||
&& resolved_types[j] == GRUB_BIDI_TYPE_ET; j++);
|
case GRUB_BIDI_TYPE_ET:
|
||||||
if (j != run_end && resolved_types[j] == GRUB_BIDI_TYPE_EN)
|
|
||||||
{
|
{
|
||||||
|
unsigned j;
|
||||||
|
if (last_type == GRUB_BIDI_TYPE_EN)
|
||||||
|
{
|
||||||
|
resolved_types[i] = GRUB_BIDI_TYPE_EN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
for (j = i; j < run_end
|
||||||
|
&& resolved_types[j] == GRUB_BIDI_TYPE_ET; j++);
|
||||||
|
if (j != run_end && resolved_types[j] == GRUB_BIDI_TYPE_EN)
|
||||||
|
{
|
||||||
|
for (; i < run_end
|
||||||
|
&& resolved_types[i] == GRUB_BIDI_TYPE_ET; i++)
|
||||||
|
resolved_types[i] = GRUB_BIDI_TYPE_EN;
|
||||||
|
i--;
|
||||||
|
break;
|
||||||
|
}
|
||||||
for (; i < run_end
|
for (; i < run_end
|
||||||
&& resolved_types[i] == GRUB_BIDI_TYPE_ET; i++)
|
&& resolved_types[i] == GRUB_BIDI_TYPE_ET; i++)
|
||||||
resolved_types[i] = GRUB_BIDI_TYPE_EN;
|
resolved_types[i] = GRUB_BIDI_TYPE_ON;
|
||||||
i--;
|
i--;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
for (; i < run_end
|
break;
|
||||||
&& resolved_types[i] == GRUB_BIDI_TYPE_ET; i++)
|
case GRUB_BIDI_TYPE_CS:
|
||||||
|
if (last_type == GRUB_BIDI_TYPE_EN
|
||||||
|
&& i + 1 < run_end
|
||||||
|
&& resolved_types[i + 1] == GRUB_BIDI_TYPE_EN)
|
||||||
|
{
|
||||||
|
resolved_types[i] = GRUB_BIDI_TYPE_EN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (last_type == GRUB_BIDI_TYPE_AN
|
||||||
|
&& i + 1 < run_end
|
||||||
|
&& (resolved_types[i + 1] == GRUB_BIDI_TYPE_AN
|
||||||
|
|| (resolved_types[i + 1] == GRUB_BIDI_TYPE_EN
|
||||||
|
&& last_strong_type == GRUB_BIDI_TYPE_AL)))
|
||||||
|
{
|
||||||
|
resolved_types[i] = GRUB_BIDI_TYPE_EN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
resolved_types[i] = GRUB_BIDI_TYPE_ON;
|
resolved_types[i] = GRUB_BIDI_TYPE_ON;
|
||||||
i--;
|
break;
|
||||||
break;
|
case GRUB_BIDI_TYPE_AL:
|
||||||
}
|
last_strong_type = resolved_types[i];
|
||||||
break;
|
resolved_types[i] = GRUB_BIDI_TYPE_R;
|
||||||
case GRUB_BIDI_TYPE_CS:
|
break;
|
||||||
if (last_type == GRUB_BIDI_TYPE_EN
|
default: /* Make GCC happy. */
|
||||||
&& i + 1 < run_end
|
|
||||||
&& resolved_types[i + 1] == GRUB_BIDI_TYPE_EN)
|
|
||||||
{
|
|
||||||
resolved_types[i] = GRUB_BIDI_TYPE_EN;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (last_type == GRUB_BIDI_TYPE_AN
|
last_type = resolved_types[i];
|
||||||
&& i + 1 < run_end
|
if (resolved_types[i] == GRUB_BIDI_TYPE_EN
|
||||||
&& (resolved_types[i + 1] == GRUB_BIDI_TYPE_AN
|
&& last_strong_type == GRUB_BIDI_TYPE_L)
|
||||||
|| (resolved_types[i + 1] == GRUB_BIDI_TYPE_EN
|
resolved_types[i] = GRUB_BIDI_TYPE_L;
|
||||||
&& last_strong_type == GRUB_BIDI_TYPE_AL)))
|
|
||||||
{
|
|
||||||
resolved_types[i] = GRUB_BIDI_TYPE_EN;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
resolved_types[i] = GRUB_BIDI_TYPE_ON;
|
|
||||||
break;
|
|
||||||
case GRUB_BIDI_TYPE_AL:
|
|
||||||
last_strong_type = resolved_types[i];
|
|
||||||
resolved_types[i] = GRUB_BIDI_TYPE_R;
|
|
||||||
break;
|
|
||||||
default: /* Make GCC happy. */
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
last_type = resolved_types[i];
|
if (prev_level & 1)
|
||||||
if (resolved_types[i] == GRUB_BIDI_TYPE_EN
|
last_type = GRUB_BIDI_TYPE_R;
|
||||||
&& last_strong_type == GRUB_BIDI_TYPE_L)
|
else
|
||||||
resolved_types[i] = GRUB_BIDI_TYPE_L;
|
last_type = GRUB_BIDI_TYPE_L;
|
||||||
}
|
for (i = run_start; i < run_end; )
|
||||||
if (prev_level & 1)
|
|
||||||
last_type = GRUB_BIDI_TYPE_R;
|
|
||||||
else
|
|
||||||
last_type = GRUB_BIDI_TYPE_L;
|
|
||||||
for (i = run_start; i < run_end; )
|
|
||||||
{
|
|
||||||
unsigned j;
|
|
||||||
unsigned next_type;
|
|
||||||
for (j = i; j < run_end &&
|
|
||||||
(resolved_types[j] == GRUB_BIDI_TYPE_B
|
|
||||||
|| resolved_types[j] == GRUB_BIDI_TYPE_S
|
|
||||||
|| resolved_types[j] == GRUB_BIDI_TYPE_WS
|
|
||||||
|| resolved_types[j] == GRUB_BIDI_TYPE_ON); j++);
|
|
||||||
if (j == i)
|
|
||||||
{
|
{
|
||||||
if (resolved_types[i] == GRUB_BIDI_TYPE_L)
|
unsigned j;
|
||||||
last_type = GRUB_BIDI_TYPE_L;
|
unsigned next_type;
|
||||||
|
for (j = i; j < run_end &&
|
||||||
|
(resolved_types[j] == GRUB_BIDI_TYPE_B
|
||||||
|
|| resolved_types[j] == GRUB_BIDI_TYPE_S
|
||||||
|
|| resolved_types[j] == GRUB_BIDI_TYPE_WS
|
||||||
|
|| resolved_types[j] == GRUB_BIDI_TYPE_ON); j++);
|
||||||
|
if (j == i)
|
||||||
|
{
|
||||||
|
if (resolved_types[i] == GRUB_BIDI_TYPE_L)
|
||||||
|
last_type = GRUB_BIDI_TYPE_L;
|
||||||
|
else
|
||||||
|
last_type = GRUB_BIDI_TYPE_R;
|
||||||
|
i++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (j == run_end)
|
||||||
|
next_type = (next_level & 1) ? GRUB_BIDI_TYPE_R : GRUB_BIDI_TYPE_L;
|
||||||
else
|
else
|
||||||
last_type = GRUB_BIDI_TYPE_R;
|
{
|
||||||
i++;
|
if (resolved_types[j] == GRUB_BIDI_TYPE_L)
|
||||||
|
next_type = GRUB_BIDI_TYPE_L;
|
||||||
|
else
|
||||||
|
next_type = GRUB_BIDI_TYPE_R;
|
||||||
|
}
|
||||||
|
if (next_type == last_type)
|
||||||
|
for (; i < j; i++)
|
||||||
|
resolved_types[i] = last_type;
|
||||||
|
else
|
||||||
|
for (; i < j; i++)
|
||||||
|
resolved_types[i] = (cur_run_level & 1) ? GRUB_BIDI_TYPE_R
|
||||||
|
: GRUB_BIDI_TYPE_L;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < visual_len; i++)
|
||||||
|
{
|
||||||
|
if (!(levels[i] & 1) && resolved_types[i] == GRUB_BIDI_TYPE_R)
|
||||||
|
{
|
||||||
|
levels[i]++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (j == run_end)
|
if (!(levels[i] & 1) && (resolved_types[i] == GRUB_BIDI_TYPE_AN
|
||||||
next_type = (next_level & 1) ? GRUB_BIDI_TYPE_R : GRUB_BIDI_TYPE_L;
|
|| resolved_types[i] == GRUB_BIDI_TYPE_EN))
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (resolved_types[j] == GRUB_BIDI_TYPE_L)
|
levels[i] += 2;
|
||||||
next_type = GRUB_BIDI_TYPE_L;
|
continue;
|
||||||
else
|
}
|
||||||
next_type = GRUB_BIDI_TYPE_R;
|
if ((levels[i] & 1) && (resolved_types[i] == GRUB_BIDI_TYPE_L
|
||||||
|
|| resolved_types[i] == GRUB_BIDI_TYPE_AN
|
||||||
|
|| resolved_types[i] == GRUB_BIDI_TYPE_EN))
|
||||||
|
{
|
||||||
|
levels[i]++;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (next_type == last_type)
|
|
||||||
for (; i < j; i++)
|
|
||||||
resolved_types[i] = last_type;
|
|
||||||
else
|
|
||||||
for (; i < j; i++)
|
|
||||||
resolved_types[i] = (cur_run_level & 1) ? GRUB_BIDI_TYPE_R
|
|
||||||
: GRUB_BIDI_TYPE_L;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
for (i = 0; i < visual_len; i++)
|
|
||||||
{
|
{
|
||||||
if (!(levels[i] & 1) && resolved_types[i] == GRUB_BIDI_TYPE_R)
|
for (i = 0; i < visual_len; i++)
|
||||||
{
|
levels[i] = 0;
|
||||||
levels[i]++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!(levels[i] & 1) && (resolved_types[i] == GRUB_BIDI_TYPE_AN
|
|
||||||
|| resolved_types[i] == GRUB_BIDI_TYPE_EN))
|
|
||||||
{
|
|
||||||
levels[i] += 2;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ((levels[i] & 1) && (resolved_types[i] == GRUB_BIDI_TYPE_L
|
|
||||||
|| resolved_types[i] == GRUB_BIDI_TYPE_AN
|
|
||||||
|| resolved_types[i] == GRUB_BIDI_TYPE_EN))
|
|
||||||
{
|
|
||||||
levels[i]++;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
grub_free (resolved_types);
|
grub_free (resolved_types);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue