box-drawing: pre-calculate the LIGHT and HEAVY thicknesses

This commit is contained in:
Daniel Eklöf 2021-05-07 18:01:21 +02:00
parent 3dbb906325
commit 8473deeed3
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -14,8 +14,8 @@
#include "xmalloc.h"
enum thickness {
LIGHT = 1,
HEAVY = 3,
LIGHT,
HEAVY,
};
struct buf {
@ -28,6 +28,7 @@ struct buf {
float cell_size;
float base_thickness;
bool solid_shades;
int thickness[2];
};
static const pixman_color_t white = {0xffff, 0xffff, 0xffff, 0xffff};
@ -57,9 +58,17 @@ change_buffer_format(struct buf *buf, pixman_format_code_t new_format)
static int NOINLINE
_thickness(struct buf *buf, enum thickness thick)
{
return max((int)(buf->base_thickness * buf->dpi / 72.0 * buf->cell_size), 1) * thick;
int multiplier = thick * 2 + 1;
xassert((thick == LIGHT && multiplier == 1) ||
(thick == HEAVY && multiplier == 3));
return
max(
(int)(buf->base_thickness * buf->dpi / 72.0 * buf->cell_size), 1)
* multiplier;
}
#define thickness(thick) _thickness(buf, thick)
#define thickness(thick) buf->thickness[thick]
static void NOINLINE
_hline(struct buf *buf, int x1, int x2, int y, int thick)
@ -2433,6 +2442,9 @@ box_drawing(const struct terminal *term, wchar_t wc)
.solid_shades = term->conf->tweak.box_drawing_solid_shades,
};
buf.thickness[LIGHT] = _thickness(&buf, LIGHT);
buf.thickness[HEAVY] = _thickness(&buf, HEAVY);
LOG_DBG("LIGHT=%d, HEAVY=%d",
_thickness(&buf, LIGHT), _thickness(&buf, HEAVY));