box-drawing: initial set of LIGHT box drawings

* 2500
* 2502
* 250c
* 2510
* 2514
* 2518
* 251c
* 2524
* 252c
* 2534
* 253c
This commit is contained in:
Daniel Eklöf 2020-12-26 18:47:55 +01:00
parent 736c88c3fb
commit fc95c7f48c
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -11,12 +11,145 @@
#include "xmalloc.h"
static void
draw_glyph(wchar_t wc, pixman_image_t *pix, int width, int height, int stride)
hline(uint8_t *buf, int x1, int x2, int y, int thick, int stride)
{
for (size_t row = y; row < y + thick; row++) {
for (size_t col = x1; col < x2; col++) {
size_t idx = col / 8;
size_t bit_no = col % 8;
buf[row * stride + idx] |= 1 << bit_no;
}
}
}
static void
vline(uint8_t *buf, int y1, int y2, int x, int thick, int stride)
{
for (size_t row = y1; row < y2; row++) {
for (size_t col = x; col < x + thick; col++) {
size_t idx = col / 8;
size_t bit_no = col % 8;
buf[row * stride + idx] |= 1 << bit_no;
}
}
}
static void
draw_box_drawings_light_horizontal(uint8_t *buf, int width, int height, int stride, int dpi)
{
const int thick = 1 * dpi / 72;
hline(buf, 0, width, (height - thick) / 2, thick, stride);
}
static void
draw_box_drawings_heavy_horizontal(uint8_t *buf, int width, int height, int stride, int dpi)
{
assert(false);
}
static void
draw_box_drawings_light_vertical(uint8_t *buf, int width, int height, int stride, int dpi)
{
int thick = 1 * dpi / 72;
vline(buf, 0, height, (width - thick) / 2, thick, stride);
}
static void
draw_box_drawings_light_down_and_right(uint8_t *buf, int width, int height, int stride, int dpi)
{
int thick = 1 * dpi / 72;
int hmid = (height - thick) / 2;
int vmid = (width - thick) / 2;
hline(buf, vmid, width, hmid, thick, stride);
vline(buf, hmid, height, vmid, thick, stride);
}
static void
draw_box_drawings_light_down_and_left(uint8_t *buf, int width, int height, int stride, int dpi)
{
int thick = 1 * dpi / 72;
int hmid = (height - thick) / 2;
int vmid = (width - thick) / 2;
hline(buf, 0, vmid, hmid, thick, stride);
vline(buf, hmid, height, vmid, thick, stride);
}
static void
draw_box_drawings_light_up_and_right(uint8_t *buf, int width, int height, int stride, int dpi)
{
int thick = 1 * dpi / 72;
int hmid = (height - thick) / 2;
int vmid = (width - thick) / 2;
hline(buf, vmid, width, hmid, thick, stride);
vline(buf, 0, hmid, vmid, thick, stride);
}
static void
draw_box_drawings_light_up_and_left(uint8_t *buf, int width, int height, int stride, int dpi)
{
int thick = 1 * dpi / 72;
int hmid = (height - thick) / 2;
int vmid = (width - thick) / 2;
hline(buf, 0, vmid, hmid, thick, stride);
vline(buf, 0, hmid + 1, vmid, thick, stride);
}
static void
draw_box_drawings_light_vertical_and_right(uint8_t *buf, int width, int height, int stride, int dpi)
{
int thick = 1 * dpi / 72;
int hmid = (height - thick) / 2;
int vmid = (width - thick) / 2;
hline(buf, vmid, width, hmid, thick, stride);
vline(buf, 0, height, vmid, thick, stride);
}
static void
draw_box_drawings_light_vertical_and_left(uint8_t *buf, int width, int height, int stride, int dpi)
{
int thick = 1 * dpi / 72;
int hmid = (height - thick) / 2;
int vmid = (width - thick) / 2;
hline(buf, 0, vmid, hmid, thick, stride);
vline(buf, 0, height, vmid, thick, stride);
}
static void
draw_box_drawings_light_down_and_horizontal(uint8_t *buf, int width, int height, int stride, int dpi)
{
int thick = 1 * dpi / 72;
int hmid = (height - thick) / 2;
int vmid = (width - thick) / 2;
hline(buf, 0, width, hmid, thick, stride);
vline(buf, hmid, height, vmid, thick, stride);
}
static void
draw_box_drawings_light_up_and_horizontal(uint8_t *buf, int width, int height, int stride, int dpi)
{
int thick = 1 * dpi / 72;
int hmid = (height - thick) / 2;
int vmid = (width - thick) / 2;
hline(buf, 0, width, hmid, thick, stride);
vline(buf, 0, hmid, vmid, thick, stride);
}
static void
draw_box_drawings_light_vertical_and_horizontal(uint8_t *buf, int width, int height, int stride, int dpi)
{
draw_box_drawings_light_vertical(buf, width, height, stride, dpi);
draw_box_drawings_light_horizontal(buf, width, height, stride, dpi);
}
static void
draw_glyph(wchar_t wc, uint8_t *buf, int width, int height, int stride, int dpi)
{
switch (wc) {
case 0x2500:
case 0x2501:
case 0x2502:
case 0x2500: draw_box_drawings_light_horizontal(buf, width, height, stride, dpi); break;
case 0x2501: draw_box_drawings_heavy_horizontal(buf, width, height, stride, dpi); break;
case 0x2502: draw_box_drawings_light_vertical(buf, width, height, stride, dpi); break;
case 0x250c: draw_box_drawings_light_down_and_right(buf, width, height, stride, dpi); break;
case 0x2503:
case 0x2504:
case 0x2505:
@ -26,33 +159,39 @@ draw_glyph(wchar_t wc, pixman_image_t *pix, int width, int height, int stride)
case 0x2509:
case 0x250a:
case 0x250b:
case 0x250c:
case 0x250d:
case 0x250e:
case 0x250f:
LOG_WARN("unimplemented: box drawing: wc=%04lx", (long)wc);
break;
case 0x2510: draw_box_drawings_light_down_and_left(buf, width, height, stride, dpi); break;
case 0x2514: draw_box_drawings_light_up_and_right(buf, width, height, stride, dpi); break;
case 0x2518: draw_box_drawings_light_up_and_left(buf, width, height, stride, dpi); break;
case 0x251c: draw_box_drawings_light_vertical_and_right(buf, width, height, stride, dpi); break;
case 0x2510:
case 0x2511:
case 0x2512:
case 0x2513:
case 0x2514:
case 0x2515:
case 0x2516:
case 0x2517:
case 0x2518:
case 0x2519:
case 0x251a:
case 0x251b:
case 0x251c:
case 0x251d:
case 0x251e:
case 0x251f:
LOG_WARN("unimplemented: box drawing: wc=%04lx", (long)wc);
break;
case 0x2524: draw_box_drawings_light_vertical_and_left(buf, width, height, stride, dpi); break;
case 0x252c: draw_box_drawings_light_down_and_horizontal(buf, width, height, stride, dpi); break;
case 0x2520:
case 0x2521:
case 0x2522:
case 0x2523:
case 0x2524:
case 0x2525:
case 0x2526:
case 0x2527:
@ -60,16 +199,19 @@ draw_glyph(wchar_t wc, pixman_image_t *pix, int width, int height, int stride)
case 0x2529:
case 0x252a:
case 0x252b:
case 0x252c:
case 0x252d:
case 0x252e:
case 0x252f:
LOG_WARN("unimplemented: box drawing: wc=%04lx", (long)wc);
break;
case 0x2534: draw_box_drawings_light_up_and_horizontal(buf, width, height, stride, dpi); break;
case 0x253c: draw_box_drawings_light_vertical_and_horizontal(buf, width, height, stride, dpi); break;
case 0x2530:
case 0x2531:
case 0x2532:
case 0x2533:
case 0x2534:
case 0x2535:
case 0x2536:
case 0x2537:
@ -77,10 +219,11 @@ draw_glyph(wchar_t wc, pixman_image_t *pix, int width, int height, int stride)
case 0x2539:
case 0x253a:
case 0x253b:
case 0x253c:
case 0x253d:
case 0x253e:
case 0x253f:
LOG_WARN("unimplemented: box drawing: wc=%04lx", (long)wc);
break;
case 0x2540:
case 0x2541:
@ -98,6 +241,8 @@ draw_glyph(wchar_t wc, pixman_image_t *pix, int width, int height, int stride)
case 0x254d:
case 0x254e:
case 0x254f:
LOG_WARN("unimplemented: box drawing: wc=%04lx", (long)wc);
break;
case 0x2550:
case 0x2551:
@ -115,6 +260,8 @@ draw_glyph(wchar_t wc, pixman_image_t *pix, int width, int height, int stride)
case 0x255d:
case 0x255e:
case 0x255f:
LOG_WARN("unimplemented: box drawing: wc=%04lx", (long)wc);
break;
case 0x2560:
case 0x2561:
@ -132,6 +279,8 @@ draw_glyph(wchar_t wc, pixman_image_t *pix, int width, int height, int stride)
case 0x256d:
case 0x256e:
case 0x256f:
LOG_WARN("unimplemented: box drawing: wc=%04lx", (long)wc);
break;
case 0x2570:
case 0x2571:
@ -149,6 +298,8 @@ draw_glyph(wchar_t wc, pixman_image_t *pix, int width, int height, int stride)
case 0x257d:
case 0x257e:
case 0x257f:
LOG_WARN("unimplemented: box drawing: wc=%04lx", (long)wc);
break;
case 0x2580:
case 0x2581:
@ -166,6 +317,8 @@ draw_glyph(wchar_t wc, pixman_image_t *pix, int width, int height, int stride)
case 0x258d:
case 0x258e:
case 0x258f:
LOG_WARN("unimplemented: box drawing: wc=%04lx", (long)wc);
break;
case 0x2590:
case 0x2591:
@ -184,7 +337,6 @@ draw_glyph(wchar_t wc, pixman_image_t *pix, int width, int height, int stride)
case 0x259e:
case 0x259f:
LOG_WARN("unimplemented: box drawing: wc=%04lx", (long)wc);
//assert(false);
break;
}
}
@ -208,7 +360,7 @@ box_drawing(struct terminal *term, wchar_t wc)
abort();
}
draw_glyph(wc, pix, width, height, stride);
draw_glyph(wc, data, width, height, stride, term->font_dpi);
struct fcft_glyph *glyph = xmalloc(sizeof(*glyph));
*glyph = (struct fcft_glyph){