aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-08-03 16:10:41 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-08-05 16:25:01 +0000
commit1c43fdbea4751de9a84d24be8320712c85045414 (patch)
tree4da4c7dc7f0f99d773ad54bdd9b7d9829ca88e32
parentterm: disable debug logging (diff)
box-drawing: add U+1FB3C-U+1FB6F, U+1FB9A and U+1FB9B
These are the “wedges” from the Unicode 13 “Legacy Computing” symbols. Closes #474
-rw-r--r--CHANGELOG.md3
-rw-r--r--box-drawing.c221
-rw-r--r--render.c11
-rw-r--r--terminal.h8
4 files changed, 228 insertions, 15 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 086b1483..31343451 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -37,6 +37,9 @@
* `-Ddocs=disabled|enabled|auto` meson command line option.
* Support for `~`-expansion in the `include` directive
(https://codeberg.org/dnkl/foot/issues/659).
+* Unicode 13 characters U+1FB3C - U+1FB6F, U+1FB9A and U+1FB9B to list
+ of box drawing characters rendered by foot itself (rather than using
+ font glyphs) (https://codeberg.org/dnkl/foot/issues/474).
### Changed
diff --git a/box-drawing.c b/box-drawing.c
index b06fc322..817beacd 100644
--- a/box-drawing.c
+++ b/box-drawing.c
@@ -21,6 +21,7 @@ enum thickness {
struct buf {
uint8_t *data;
pixman_image_t *pix;
+ pixman_format_code_t format;
int width;
int height;
int stride;
@@ -52,6 +53,7 @@ change_buffer_format(struct buf *buf, pixman_format_code_t new_format)
buf->data = new_data;
buf->pix = new_pix;
+ buf->format = new_format;
buf->stride = stride;
}
@@ -1257,7 +1259,7 @@ set_a1_bit(uint8_t *data, size_t ofs, size_t bit_no)
static void
draw_box_drawings_light_arc(struct buf *buf, wchar_t wc)
{
- const pixman_format_code_t fmt = pixman_image_get_format(buf->pix);
+ const pixman_format_code_t fmt = buf->format;
const int supersample = fmt == PIXMAN_a8 ? 4 : 1;
const int height = buf->height * supersample;
const int width = buf->width * supersample;
@@ -1763,7 +1765,7 @@ draw_pixman_shade(struct buf *buf, uint16_t v)
static void
draw_light_shade(struct buf *buf)
{
- pixman_format_code_t fmt = pixman_image_get_format(buf->pix);
+ pixman_format_code_t fmt = buf->format;
if (buf->solid_shades && fmt == PIXMAN_a1)
change_buffer_format(buf, PIXMAN_a8);
@@ -1786,7 +1788,7 @@ draw_light_shade(struct buf *buf)
static void
draw_medium_shade(struct buf *buf)
{
- pixman_format_code_t fmt = pixman_image_get_format(buf->pix);
+ pixman_format_code_t fmt = buf->format;
if (buf->solid_shades && fmt == PIXMAN_a1)
change_buffer_format(buf, PIXMAN_a8);
@@ -1809,7 +1811,7 @@ draw_medium_shade(struct buf *buf)
static void
draw_dark_shade(struct buf *buf)
{
- pixman_format_code_t fmt = pixman_image_get_format(buf->pix);
+ pixman_format_code_t fmt = buf->format;
if (buf->solid_shades && fmt == PIXMAN_a1)
change_buffer_format(buf, PIXMAN_a8);
@@ -2133,6 +2135,183 @@ draw_sextant(struct buf *buf, wchar_t wc)
sextant_lower_right(buf);
}
+static void NOINLINE
+draw_wedge_triangle(struct buf *buf, wchar_t wc)
+{
+ const int width = buf->width;
+ const int height = buf->height;
+ const double width_f = width;
+ const double height_f = height;
+
+ int p1_x, p1_y, p2_x, p2_y, p3_x, p3_y;
+
+ IGNORE_WARNING("-Wpedantic");
+
+ switch (wc) {
+ /* Lower left */
+ case 0x1fb3c ... 0x1fb40: {
+ size_t idx = wc - 0x1fb3c;
+ p1_x = 0; p1_y = (idx < 2 ? 2 * height / 3 :
+ idx < 4 ? height / 3 :
+ 0);
+ p2_x = 0; p2_y = height;
+ p3_x = idx % 2 ? width : round(width_f / 2.); p3_y = height;
+ break;
+ }
+
+ /* Lower right */
+ case 0x1fb47 ... 0x1fb4b: {
+ size_t idx = wc - 0x1fb47;
+ p1_x = width; p1_y = (idx < 2 ? 2 * height / 3 :
+ idx < 4 ? height / 3 :
+ 0);
+ p2_x = width; p2_y = height;
+ p3_x = idx % 2 ? 0 : width / 2; p3_y = height;
+ break;
+ }
+
+ /* Upper left */
+ case 0x1fb57 ... 0x1fb5b: {
+ size_t idx = wc - 0x1fb57;
+ p1_x = 0; p1_y = 0;
+ p2_x = 0; p2_y = (idx < 2 ? round(height_f / 3.) :
+ idx < 4 ? round(2. * height_f / 3.) :
+ height);
+ p3_x = idx % 2 ? width : round(width_f / 2.); p3_y = 0;
+ break;
+ }
+
+ /* Upper right */
+ case 0x1fb62 ... 0x1fb66: {
+ size_t idx = wc - 0x1fb62;
+ p1_x = width; p1_y = 0;
+ p2_x = width; p2_y = (idx < 2 ? round(height_f / 3.) :
+ idx < 4 ? round(2. * height_f / 3.) :
+ height);
+ p3_x = idx % 2 ? 0 : width / 2; p3_y = 0;
+ break;
+ }
+
+ case 0x1fb46:
+ p1_x = 0; p1_y = round(2. * height_f / 3.);
+ p2_x = width; p2_y = height / 3;
+ p3_x = width; p3_y = p1_y;
+ break;
+
+ case 0x1fb51:
+ p1_x = 0; p1_y = height / 3;
+ p2_x = 0; p2_y = round(2. * height_f / 3.);
+ p3_x = width; p3_y = p2_y;
+ break;
+
+ case 0x1fb5c:
+ p1_x = 0; p1_y = height / 3;
+ p2_x = 0; p2_y = round(2. * height_f / 3.);
+ p3_x = width; p3_y = p1_y;
+ break;
+
+ case 0x1fb67:
+ p1_x = 0; p1_y = height / 3;
+ p2_x = width; p2_y = p1_y;
+ p3_x = width; p3_y = round(2. * height_f / 3.);
+ break;
+
+ case 0x1fb6c:
+ p1_x = 0; p1_y = 0;
+ p2_x = round(width_f / 2.); p2_y = round(height_f / 2.);
+ p3_x = 0; p3_y = height;
+ break;
+
+ case 0x1fb6d:
+ p1_x = 0; p1_y = 0;
+ p2_x = width / 2; p2_y = round(height_f / 2.);
+ p3_x = width; p3_y = 0;
+ break;
+
+ case 0x1fb6e:
+ p1_x = width; p1_y = 0;
+ p2_x = width / 2; p2_y = round(height_f / 2.);
+ p3_x = width; p3_y = height;
+ break;
+
+ case 0x1fb6f:
+ p1_x = 0; p1_y = height;
+ p2_x = width / 2; p2_y = round(height_f / 2.);
+ p3_x = width; p3_y = height;
+ break;
+
+ default:
+ BUG("unimplemented Unicode codepoint");
+ break;
+ }
+
+ UNIGNORE_WARNINGS;
+
+ const pixman_triangle_t tri = {
+ .p1 = {.x = pixman_int_to_fixed(p1_x), .y = pixman_int_to_fixed(p1_y)},
+ .p2 = {.x = pixman_int_to_fixed(p2_x), .y = pixman_int_to_fixed(p2_y)},
+ .p3 = {.x = pixman_int_to_fixed(p3_x), .y = pixman_int_to_fixed(p3_y)},
+ };
+
+ pixman_image_t *src = pixman_image_create_solid_fill(&white);
+ pixman_composite_triangles(
+ PIXMAN_OP_OVER, src, buf->pix, buf->format, 0, 0, 0, 0, 1, &tri);
+ pixman_image_unref(src);
+}
+
+static void
+draw_wedge_triangle_inverted(struct buf *buf, wchar_t wc)
+{
+ IGNORE_WARNING("-Wpedantic");
+
+ switch (wc) {
+ case 0x1fb41 ... 0x1fb45: wc = wc - 0x1fb41 + 0x1fb57; break;
+ case 0x1fb4c ... 0x1fb50: wc = wc - 0x1fb4c + 0x1fb62; break;
+ case 0x1fb52 ... 0x1fb56: wc = wc - 0x1fb52 + 0x1fb3c; break;
+ case 0x1fb5d ... 0x1fb61: wc = wc - 0x1fb5d + 0x1fb47; break;
+ case 0x1fb68 ... 0x1fb6b: wc = wc - 0x1fb68 + 0x1fb6c; break;
+ }
+
+ UNIGNORE_WARNINGS;
+
+ draw_wedge_triangle(buf, wc);
+
+ pixman_image_t *src = pixman_image_create_solid_fill(&white);
+ pixman_image_composite(PIXMAN_OP_OUT, src, NULL, buf->pix, 0, 0, 0, 0, 0, 0, buf->width, buf->height);
+ pixman_image_unref(src);
+}
+
+static void
+draw_wedge_triangle_and_box(struct buf *buf, wchar_t wc)
+{
+ draw_wedge_triangle(buf, wc);
+
+ const int width = buf->width;
+ const int height = buf->height;
+
+ pixman_box32_t box;
+
+ switch (wc) {
+ case 0x1fb46:
+ case 0x1fb51:
+ box = (pixman_box32_t){
+ .x1 = 0, .y1 = round(2. * height / 3.),
+ .x2 = width, .y2 = height,
+ };
+ break;
+
+ case 0x1fb5c:
+ case 0x1fb67:
+ box = (pixman_box32_t){
+ .x1 = 0, .y1 = 0,
+ .x2 = width, .y2 = height / 3,
+ };
+ break;
+ }
+
+ pixman_image_fill_boxes(PIXMAN_OP_SRC, buf->pix, &white, 1, &box);
+}
+
static void
draw_left_and_lower_one_eighth_block(struct buf *buf)
{
@@ -2382,6 +2561,39 @@ draw_glyph(struct buf *buf, wchar_t wc)
case 0x1fb00 ... 0x1fb3b: draw_sextant(buf, wc); break;
+ case 0x1fb3c ... 0x1fb40:
+ case 0x1fb47 ... 0x1fb4b:
+ case 0x1fb57 ... 0x1fb5b:
+ case 0x1fb62 ... 0x1fb66:
+ case 0x1fb6c ... 0x1fb6f:
+ draw_wedge_triangle(buf, wc);
+ break;
+
+ case 0x1fb41 ... 0x1fb45:
+ case 0x1fb4c ... 0x1fb50:
+ case 0x1fb52 ... 0x1fb56:
+ case 0x1fb5d ... 0x1fb61:
+ case 0x1fb68 ... 0x1fb6b:
+ draw_wedge_triangle_inverted(buf, wc);
+ break;
+
+ case 0x1fb46:
+ case 0x1fb51:
+ case 0x1fb5c:
+ case 0x1fb67:
+ draw_wedge_triangle_and_box(buf, wc);
+ break;
+
+ case 0x1fb9a:
+ draw_wedge_triangle(buf, 0x1fb6d);
+ draw_wedge_triangle(buf, 0x1fb6f);
+ break;
+
+ case 0x1fb9b:
+ draw_wedge_triangle(buf, 0x1fb6c);
+ draw_wedge_triangle(buf, 0x1fb6e);
+ break;
+
case 0x1fb70: draw_vertical_one_eighth_block_2(buf); break;
case 0x1fb71: draw_vertical_one_eighth_block_3(buf); break;
case 0x1fb72: draw_vertical_one_eighth_block_4(buf); break;
@@ -2443,6 +2655,7 @@ box_drawing(const struct terminal *term, wchar_t wc)
struct buf buf = {
.data = data,
.pix = pix,
+ .format = fmt,
.width = width,
.height = height,
.stride = stride,
diff --git a/render.c b/render.c
index d338301c..b8a013f1 100644
--- a/render.c
+++ b/render.c
@@ -538,18 +538,15 @@ render_cell(struct terminal *term, pixman_image_t *pix,
*/
/* Unicode 13 sextants */
- (base >= 0x1fb00 && base <= 0x1fb3b) ||
-
- /* Unicode 13 partial blocks */
- /* TODO: there's more here! */
- (base >= 0x1fb70 && base <= 0x1fb8b)) &&
+ (base >= 0x1fb00 && base <= 0x1fb8b) ||
+ (base >= 0x1fb9a && base <= 0x1fb9b)) &&
likely(!term->conf->box_drawings_uses_font_glyphs))
{
/* Box drawing characters */
size_t idx = base >= 0x1fb00
- ? (base >= 0x1fb70
- ? base - 0x1fb70 + 220
+ ? (base >= 0x1fb9a
+ ? base - 0x1fb9a + 300
: base - 0x1fb00 + 160)
: base - 0x2500;
xassert(idx < ALEN(term->box_drawing));
diff --git a/terminal.h b/terminal.h
index 6e8aa264..74a8f2de 100644
--- a/terminal.h
+++ b/terminal.h
@@ -334,11 +334,11 @@ struct terminal {
enum fcft_subpixel font_subpixel;
/*
- * 0-159: U+250U+259F
- * 160-219: U+1FB00-1FB3B
- * 220-247: U+1FB70-1FB8B
+ * 0-159: U+02500+0259F
+ * 160-299: U+1FB00-1FB8B
+ * 300-301: U+1FB9A-1FB9B
*/
- struct fcft_glyph *box_drawing[248];
+ struct fcft_glyph *box_drawing[302];
bool is_sending_paste_data;
ptmx_buffer_list_t ptmx_buffers;