mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-23 05:33:57 -04:00
box-drawing: pre-calculate the LIGHT and HEAVY thicknesses
This commit is contained in:
parent
3dbb906325
commit
8473deeed3
1 changed files with 16 additions and 4 deletions
|
|
@ -14,8 +14,8 @@
|
||||||
#include "xmalloc.h"
|
#include "xmalloc.h"
|
||||||
|
|
||||||
enum thickness {
|
enum thickness {
|
||||||
LIGHT = 1,
|
LIGHT,
|
||||||
HEAVY = 3,
|
HEAVY,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct buf {
|
struct buf {
|
||||||
|
|
@ -28,6 +28,7 @@ struct buf {
|
||||||
float cell_size;
|
float cell_size;
|
||||||
float base_thickness;
|
float base_thickness;
|
||||||
bool solid_shades;
|
bool solid_shades;
|
||||||
|
int thickness[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
static const pixman_color_t white = {0xffff, 0xffff, 0xffff, 0xffff};
|
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
|
static int NOINLINE
|
||||||
_thickness(struct buf *buf, enum thickness thick)
|
_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
|
static void NOINLINE
|
||||||
_hline(struct buf *buf, int x1, int x2, int y, int thick)
|
_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,
|
.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",
|
LOG_DBG("LIGHT=%d, HEAVY=%d",
|
||||||
_thickness(&buf, LIGHT), _thickness(&buf, HEAVY));
|
_thickness(&buf, LIGHT), _thickness(&buf, HEAVY));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue