mirror of
https://github.com/rkd77/elinks.git
synced 2025-01-03 14:57:44 -05:00
Added: split line after any double-width character in html renderer.
Note: there are ugly bug (feature?) - when there isn't enought room for whole double-width char two double-chars are displayed. Can be seen on table with double-width chars reduced as much as possible.
This commit is contained in:
parent
dd05c89d49
commit
7951d7bf22
@ -210,6 +210,10 @@ realloc_spaces(struct part *part, int length)
|
|||||||
|
|
||||||
if (!ALIGN_SPACES(&part->spaces, part->spaces_len, length))
|
if (!ALIGN_SPACES(&part->spaces, part->spaces_len, length))
|
||||||
return -1;
|
return -1;
|
||||||
|
#ifdef CONFIG_UTF_8
|
||||||
|
if (!ALIGN_SPACES(&part->char_width, part->spaces_len, length))
|
||||||
|
return -1;
|
||||||
|
#endif
|
||||||
|
|
||||||
part->spaces_len = length;
|
part->spaces_len = length;
|
||||||
|
|
||||||
@ -438,6 +442,7 @@ set_hline(struct html_context *html_context, unsigned char *chars, int charslen,
|
|||||||
if (*chars == NBSP_CHAR) {
|
if (*chars == NBSP_CHAR) {
|
||||||
schar->data = ' ';
|
schar->data = ' ';
|
||||||
part->spaces[x] = html_context->options->wrap_nbsp;
|
part->spaces[x] = html_context->options->wrap_nbsp;
|
||||||
|
part->char_width[x] = 1;
|
||||||
chars++;
|
chars++;
|
||||||
} else {
|
} else {
|
||||||
unicode_val_T data;
|
unicode_val_T data;
|
||||||
@ -452,15 +457,27 @@ set_hline(struct html_context *html_context, unsigned char *chars, int charslen,
|
|||||||
schar->attr = SCREEN_ATTR_FRAME;
|
schar->attr = SCREEN_ATTR_FRAME;
|
||||||
copy_screen_chars(&POS(x, y), schar, 1);
|
copy_screen_chars(&POS(x, y), schar, 1);
|
||||||
schar->attr = attr;
|
schar->attr = attr;
|
||||||
|
part->char_width[x] = 0;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
schar->data = (uint16_t)data;
|
if (unicode_to_cell(data) == 2) {
|
||||||
|
schar->data = (unicode_val_T)data;
|
||||||
|
part->char_width[x] = 2;
|
||||||
|
copy_screen_chars(&POS(x++, y), schar, 1);
|
||||||
|
schar->data = UCS_NO_CHAR;
|
||||||
|
part->spaces[x] = 0;
|
||||||
|
part->char_width[x] = 0;
|
||||||
|
} else {
|
||||||
|
part->char_width[x] = unicode_to_cell(data);
|
||||||
|
schar->data = (unicode_val_T)data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
copy_screen_chars(&POS(x, y), schar, 1);
|
copy_screen_chars(&POS(x, y), schar, 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (; charslen > 0; charslen--, x++, chars++) {
|
for (; charslen > 0; charslen--, x++, chars++) {
|
||||||
|
part->char_width[x] = 1;
|
||||||
if (*chars == NBSP_CHAR) {
|
if (*chars == NBSP_CHAR) {
|
||||||
schar->data = ' ';
|
schar->data = ' ';
|
||||||
part->spaces[x] = html_context->options->wrap_nbsp;
|
part->spaces[x] = html_context->options->wrap_nbsp;
|
||||||
@ -482,12 +499,23 @@ set_hline(struct html_context *html_context, unsigned char *chars, int charslen,
|
|||||||
|
|
||||||
part->spaces[x] = (*chars == ' ');
|
part->spaces[x] = (*chars == ' ');
|
||||||
data = utf_8_to_unicode(&chars, end);
|
data = utf_8_to_unicode(&chars, end);
|
||||||
if (data == UCS_NO_CHAR) chars++;
|
part->char_width[x] = unicode_to_cell(data);
|
||||||
|
if (part->char_width[x] == 2) {
|
||||||
|
x++;
|
||||||
|
part->spaces[x] = 0;
|
||||||
|
part->char_width[x] = 0;
|
||||||
|
}
|
||||||
|
if (data == UCS_NO_CHAR) {
|
||||||
|
chars++;
|
||||||
|
part->char_width[x] = 0;
|
||||||
|
x++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
len = x - x2;
|
len = x - x2;
|
||||||
} else {
|
} else {
|
||||||
for (; charslen > 0; charslen--, x++, chars++) {
|
for (; charslen > 0; charslen--, x++, chars++) {
|
||||||
part->spaces[x] = (*chars == ' ');
|
part->spaces[x] = (*chars == ' ');
|
||||||
|
part->char_width[x] = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -766,29 +794,53 @@ split_line_at(struct html_context *html_context, int width)
|
|||||||
if (part->document) {
|
if (part->document) {
|
||||||
assert(part->document->data);
|
assert(part->document->data);
|
||||||
if_assert_failed return 0;
|
if_assert_failed return 0;
|
||||||
assertm(POS(width, part->cy).data == ' ',
|
#ifdef CONFIG_UTF_8
|
||||||
"bad split: %c", POS(width, part->cy).data);
|
if (html_context->options->utf8
|
||||||
move_chars(html_context, width + 1, part->cy, par_format.leftmargin, part->cy + 1);
|
&& width < part->spaces_len && part->char_width[width] == 2) {
|
||||||
del_chars(html_context, width, part->cy);
|
move_chars(html_context, width, part->cy, par_format.leftmargin, part->cy + 1);
|
||||||
|
del_chars(html_context, width, part->cy);
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
assertm(POS(width, part->cy).data == ' ',
|
||||||
|
"bad split: %c", POS(width, part->cy).data);
|
||||||
|
move_chars(html_context, width + 1, part->cy, par_format.leftmargin, part->cy + 1);
|
||||||
|
del_chars(html_context, width, part->cy);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
width++; /* Since we were using (x + 1) only later... */
|
#ifdef CONFIG_UTF_8
|
||||||
|
if (!(html_context->options->utf8
|
||||||
|
&& width < part->spaces_len
|
||||||
|
&& part->char_width[width] == 2))
|
||||||
|
#endif
|
||||||
|
width++; /* Since we were using (x + 1) only later... */
|
||||||
|
|
||||||
tmp = part->spaces_len - width;
|
tmp = part->spaces_len - width;
|
||||||
if (tmp > 0) {
|
if (tmp > 0) {
|
||||||
/* 0 is possible and I'm paranoid ... --Zas */
|
/* 0 is possible and I'm paranoid ... --Zas */
|
||||||
memmove(part->spaces, part->spaces + width, tmp);
|
memmove(part->spaces, part->spaces + width, tmp);
|
||||||
|
#ifdef CONFIG_UTF_8
|
||||||
|
memmove(part->char_width, part->char_width + width, tmp);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(tmp >= 0);
|
assert(tmp >= 0);
|
||||||
if_assert_failed tmp = 0;
|
if_assert_failed tmp = 0;
|
||||||
memset(part->spaces + tmp, 0, width);
|
memset(part->spaces + tmp, 0, width);
|
||||||
|
#ifdef CONFIG_UTF_8
|
||||||
|
memset(part->char_width + tmp, 0, width);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (par_format.leftmargin > 0) {
|
if (par_format.leftmargin > 0) {
|
||||||
tmp = part->spaces_len - par_format.leftmargin;
|
tmp = part->spaces_len - par_format.leftmargin;
|
||||||
assertm(tmp > 0, "part->spaces_len - par_format.leftmargin == %d", tmp);
|
assertm(tmp > 0, "part->spaces_len - par_format.leftmargin == %d", tmp);
|
||||||
/* So tmp is zero, memmove() should survive that. Don't recover. */
|
/* So tmp is zero, memmove() should survive that. Don't recover. */
|
||||||
memmove(part->spaces + par_format.leftmargin, part->spaces, tmp);
|
memmove(part->spaces + par_format.leftmargin, part->spaces, tmp);
|
||||||
|
#ifdef CONFIG_UTF_8
|
||||||
|
memmove(part->char_width + par_format.leftmargin, part->char_width, tmp);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
part->cy++;
|
part->cy++;
|
||||||
@ -826,13 +878,38 @@ split_line(struct html_context *html_context)
|
|||||||
assert(part);
|
assert(part);
|
||||||
if_assert_failed return 0;
|
if_assert_failed return 0;
|
||||||
|
|
||||||
for (x = overlap(par_format); x >= par_format.leftmargin; x--)
|
#ifdef CONFIG_UTF_8
|
||||||
if (x < part->spaces_len && part->spaces[x])
|
if (html_context->options->utf8) {
|
||||||
return split_line_at(html_context, x);
|
for (x = overlap(par_format); x >= par_format.leftmargin; x--) {
|
||||||
|
|
||||||
for (x = par_format.leftmargin; x < part->cx ; x++)
|
if (x < part->spaces_len && (part->spaces[x]
|
||||||
if (x < part->spaces_len && part->spaces[x])
|
|| (part->char_width[x] == 2
|
||||||
return split_line_at(html_context, x);
|
/* Ugly hack. If we haven't place for
|
||||||
|
* double-width characters we print two
|
||||||
|
* double-width characters. */
|
||||||
|
&& x != par_format.leftmargin)))
|
||||||
|
return split_line_at(html_context, x);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (x = par_format.leftmargin; x < part->cx ; x++) {
|
||||||
|
if (x < part->spaces_len && (part->spaces[x]
|
||||||
|
|| (part->char_width[x] == 2
|
||||||
|
/* We want to break line after _second_
|
||||||
|
* double-width character. */
|
||||||
|
&& x > par_format.leftmargin)))
|
||||||
|
return split_line_at(html_context, x);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
for (x = overlap(par_format); x >= par_format.leftmargin; x--)
|
||||||
|
if (x < part->spaces_len && part->spaces[x])
|
||||||
|
return split_line_at(html_context, x);
|
||||||
|
|
||||||
|
for (x = par_format.leftmargin; x < part->cx ; x++)
|
||||||
|
if (x < part->spaces_len && part->spaces[x])
|
||||||
|
return split_line_at(html_context, x);
|
||||||
|
}
|
||||||
|
|
||||||
/* Make sure that we count the right margin to the total
|
/* Make sure that we count the right margin to the total
|
||||||
* actual box width. */
|
* actual box width. */
|
||||||
@ -1593,6 +1670,9 @@ end:
|
|||||||
part->cx = -1;
|
part->cx = -1;
|
||||||
part->xa = 0;
|
part->xa = 0;
|
||||||
memset(part->spaces, 0, part->spaces_len);
|
memset(part->spaces, 0, part->spaces_len);
|
||||||
|
#ifdef CONFIG_UTF_8
|
||||||
|
memset(part->char_width, 0, part->spaces_len);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -2014,6 +2094,9 @@ format_html_part(struct html_context *html_context,
|
|||||||
|
|
||||||
done_link_state_info();
|
done_link_state_info();
|
||||||
mem_free_if(part->spaces);
|
mem_free_if(part->spaces);
|
||||||
|
#ifdef CONFIG_UTF_8
|
||||||
|
mem_free_if(part->char_width);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (document) {
|
if (document) {
|
||||||
struct node *node = document->nodes.next;
|
struct node *node = document->nodes.next;
|
||||||
|
@ -23,6 +23,10 @@ struct part {
|
|||||||
|
|
||||||
unsigned char *spaces;
|
unsigned char *spaces;
|
||||||
int spaces_len;
|
int spaces_len;
|
||||||
|
#ifdef CONFIG_UTF_8
|
||||||
|
unsigned char *char_width;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
struct box box;
|
struct box box;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user