1
0
mirror of https://github.com/rkd77/elinks.git synced 2025-05-18 00:48:57 -04:00

[sixel] Added images also for tables

Idea is to first add normal characters as placeholders,
render document as text and later copy images there.
Characters are indexes for images. 33, 34, 35 and so on.
Later I'll change them to invisible characters.
This commit is contained in:
Witold Filipczyk 2025-01-23 18:25:37 +01:00
parent 7bbf2e7ef9
commit b781d91e6a
6 changed files with 57 additions and 7 deletions

View File

@ -135,6 +135,8 @@ struct html_context {
* html/tables.c */
int table_level;
int image_number;
/* For:
* html/parser/forms.c
* html/parser/link.c

View File

@ -232,7 +232,7 @@ static void
html_img_sixel(struct html_context *html_context, char *a,
char *html, char *eof, char **end)
{
if (!html_context->options->sixel || !html_context->part->document || html_context->table_level) {
if (!html_context->options->sixel || !html_context->document) {
return;
}
char *elsix = get_attr_val(a, "elsix", html_context->doc_cp);
@ -259,11 +259,34 @@ html_img_sixel(struct html_context *html_context, char *a,
mem_free(data);
struct document *document = html_context->document;
html_linebrk(html_context, a, html, eof, end);
put_chrs(html_context, " ", 6);
ln_break(html_context, 1);
int lineno = html_context->part->cy + html_context->part->box.y - 1;
int how_many = add_image_to_document(document, &pixels, lineno) + 1;
int lineno = html_context->part->cy + html_context->part->box.y;
struct image *im = NULL;
int how_many = add_image_to_document(document, &pixels, lineno, &im);
done_string(&pixels);
ln_break(html_context, how_many);
if (!im) {
return;
}
int xw = (im->width + document->options.cell_width - 1) / document->options.cell_width;
int y;
unsigned char ch[2] = {33,0};
im->image_number = html_context->image_number++;
ch[0] += im->image_number;
for (y = 0; y < how_many; y++) {
int x;
for (x = 0; x < xw; x++) {
put_chrs(html_context, (const char *)ch, 1);
}
ln_break(html_context, 1);
}
}
#endif

View File

@ -663,7 +663,7 @@ add_document_line(struct plain_renderer *renderer,
break;
}
add_bytes_to_string(&pixels, line + line_pos, end + 2 - line - line_pos);
how_many = add_image_to_document(document, &pixels, lineno) + 1;
how_many = add_image_to_document(document, &pixels, lineno, NULL) + 1;
done_string(&pixels);
realloc_line(document, pos - startpos, lineno);

View File

@ -827,7 +827,7 @@ delete_image(struct image *im)
}
int
add_image_to_document(struct document *doc, struct string *pixels, int lineno)
add_image_to_document(struct document *doc, struct string *pixels, int lineno, struct image **imagine)
{
unsigned char *indexed_pixels = NULL;
unsigned char *palette = NULL;
@ -840,6 +840,10 @@ add_image_to_document(struct document *doc, struct string *pixels, int lineno)
struct image *im = mem_calloc(1, sizeof(*im));
SIXELSTATUS status;
if (imagine) {
*imagine = NULL;
}
if (!im) {
return 0;
}
@ -900,6 +904,10 @@ end:
sixel_frame_unref(frame);
sixel_decoder_unref(decoder);
if (imagine) {
*imagine = im;
}
return ile;
}

View File

@ -22,6 +22,7 @@ struct image {
int y;
int width;
int height;
int image_number;
};
void delete_image(struct image *im);
@ -29,7 +30,7 @@ void delete_image(struct image *im);
void try_to_draw_images(struct terminal *term);
/* return height of image in terminal rows */
int add_image_to_document(struct document *doc, struct string *pixels, int lineno);
int add_image_to_document(struct document *doc, struct string *pixels, int lineno, struct image **imagine);
struct image *copy_frame(struct image *src, struct el_box *box, int cell_width, int cell_height, int dx, int dy);

View File

@ -488,11 +488,26 @@ draw_doc(struct session *ses, struct document_view *doc_view, int active)
if (doc_view->document->options.sixel) {
struct image *im2;
struct line *data = doc_view->document->data;
foreach (im2, doc_view->document->images) {
struct image im;
copy_struct(&im, im2);
int x;
int found = 0;
for (x = 0; x < data[im.y].length; x++) {
if ((im.image_number == data[im.y].ch.chars[x].data - 33) && (im.image_number == data[im.y].ch.chars[x+1].data - 33)) {
found = 1;
break;
}
}
if (!found) {
continue;
}
im.x += box->x;
im.y += box->y;
@ -515,6 +530,7 @@ draw_doc(struct session *ses, struct document_view *doc_view, int active)
struct image *im_copy = copy_frame(&im, box, term->cell_width, term->cell_height, vs->x, vs->y);
if (im_copy) {
im_copy->x += x;
add_to_list(term->images, im_copy);
}
}