Merge branch 'box-drawing'

Closes #198
This commit is contained in:
Daniel Eklöf 2021-01-03 00:08:08 +01:00
commit 5cc2f94668
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
9 changed files with 2159 additions and 1 deletions

View file

@ -28,6 +28,8 @@
* The fcft and tllist library subprojects are now handled via Meson
[wrap files](https://mesonbuild.com/Wrap-dependency-system-manual.html)
instead of needing to be manually cloned.
* Box drawing characters are now rendered by foot, instead of using
font glyphs (https://codeberg.org/dnkl/foot/issues/198)
### Deprecated

2086
box-drawing.c Normal file

File diff suppressed because it is too large Load diff

6
box-drawing.h Normal file
View file

@ -0,0 +1,6 @@
#pragma once
#include <fcft/fcft.h>
struct terminal;
struct fcft_glyph *box_drawing(const struct terminal *term, wchar_t wc);

View file

@ -26,6 +26,18 @@
#define UNUSED
#endif
#if HAS_ATTRIBUTE(noinline)
#define NOINLINE __attribute__((noinline))
#else
#define NOINLINE
#endif
#if HAS_ATTRIBUTE(const)
#define CONST __attribute__((__const__))
#else
#define CONST
#endif
#if GNUC_AT_LEAST(3, 0) || HAS_ATTRIBUTE(malloc)
#define MALLOC __attribute__((__malloc__))
#else

View file

@ -149,6 +149,7 @@ executable(
executable(
'foot',
'async.c', 'async.h',
'box-drawing.c', 'box-drawing.h',
'config.c', 'config.h',
'commands.c', 'commands.h',
'extract.c', 'extract.h',

View file

@ -16,6 +16,7 @@
#define LOG_MODULE "render"
#define LOG_ENABLE_DBG 0
#include "log.h"
#include "box-drawing.h"
#include "config.h"
#include "grid.h"
#include "hsl.h"
@ -449,7 +450,27 @@ render_cell(struct terminal *term, pixman_image_t *pix,
base = composed->base;
}
glyph = fcft_glyph_rasterize(font, base, term->font_subpixel);
if (unlikely((base >= 0x2500 && base <= 0x259f) ||
(base >= 0x1fb00 && base <= 0x1fb3b))) {
/* Box drawing characters */
size_t idx = base >= 0x1fb00 ? base - 0x1fb00 + 160 : base - 0x2500;
assert(idx < ALEN(term->box_drawing));
if (likely(term->box_drawing[idx] != NULL))
glyph = term->box_drawing[idx];
else {
mtx_lock(&term->render.workers.lock);
/* Parallel thread may have instantiated it while we took the lock */
if (term->box_drawing[idx] == NULL)
term->box_drawing[idx] = box_drawing(term, base);
mtx_unlock(&term->render.workers.lock);
glyph = term->box_drawing[idx];
assert(glyph != NULL);
}
} else
glyph = fcft_glyph_rasterize(font, base, term->font_subpixel);
}
const int cols_left = term->cols - col;

9
stride.h Normal file
View file

@ -0,0 +1,9 @@
#pragma once
#include <pixman.h>
static inline int
stride_for_format_and_width(pixman_format_code_t format, int width)
{
return (((PIXMAN_FORMAT_BPP(format) * width + 7) / 8 + 4 - 1) & -4);
}

View file

@ -618,6 +618,14 @@ term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4])
term->fonts[i] = fonts[i];
}
for (size_t i = 0; i < ALEN(term->box_drawing); i++) {
if (term->box_drawing[i] != NULL) {
pixman_image_unref(term->box_drawing[i]->pix);
free(term->box_drawing[i]);
term->box_drawing[i] = NULL;
}
}
const int old_cell_width = term->cell_width;
const int old_cell_height = term->cell_height;
@ -1412,6 +1420,13 @@ term_destroy(struct terminal *term)
for (size_t i = 0; i < 4; i++)
free(term->font_sizes[i]);
for (size_t i = 0; i < ALEN(term->box_drawing); i++) {
if (term->box_drawing[i] != NULL) {
pixman_image_unref(term->box_drawing[i]->pix);
free(term->box_drawing[i]);
}
}
free(term->search.buf);
if (term->render.workers.threads != NULL) {

View file

@ -261,6 +261,12 @@ struct terminal {
int font_scale;
enum fcft_subpixel font_subpixel;
/*
* 0-159: U+250U+259F
* 160-219: U+1FB00-1FB3B
*/
struct fcft_glyph *box_drawing[220];
bool is_sending_paste_data;
ptmx_buffer_list_t ptmx_buffers;
ptmx_buffer_list_t ptmx_paste_buffers;