aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-01-04 17:32:55 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-01-21 10:53:05 +0000
commitd10fc3dc797708127ff235a60c0f26627885baa3 (patch)
tree422ab475e1bee5d3399fbb8d7853be39cc32bab6
parentinput: don’t try to close an invalid FD (diff)
render: draw combining characters on top of colored bitmap glyphs (emoji)
-rw-r--r--CHANGELOG.md2
-rw-r--r--render.c50
2 files changed, 36 insertions, 16 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 73e64399..1f42147e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -42,6 +42,8 @@
properly erasing the cell overflowed **into**.
* `word-delimiters` option ignores `#` and subsequent characters
(https://codeberg.org/dnkl/foot/issues/270)
+* Combining characters not being rendered when composed with colored
+ bitmap glyhps (i.e. colored emojis).
### Security
diff --git a/render.c b/render.c
index 2951c466..2220c127 100644
--- a/render.c
+++ b/render.c
@@ -534,26 +534,44 @@ render_cell(struct terminal *term, pixman_image_t *pix,
x + glyph->x, y + font_baseline(term) - glyph->y,
glyph->width, glyph->height);
- /* Combining characters */
- if (composed != NULL) {
- for (size_t i = 0; i < composed->count; i++) {
- const struct fcft_glyph *g = fcft_glyph_rasterize(
- font, composed->combining[i], term->font_subpixel);
+ }
- if (g == NULL)
- continue;
+ /* Combining characters */
+ if (composed != NULL) {
+ for (size_t i = 0; i < composed->count; i++) {
+ const struct fcft_glyph *g = fcft_glyph_rasterize(
+ font, composed->combining[i], term->font_subpixel);
- pixman_image_composite32(
- PIXMAN_OP_OVER, clr_pix, g->pix, pix, 0, 0, 0, 0,
- /* Some fonts use a negative offset, while others use a
- * "normal" offset */
- x + (g->x < 0 ? term->cell_width : 0) + g->x,
- y + font_baseline(term) - g->y,
- g->width, g->height);
- }
+ if (g == NULL)
+ continue;
+
+ /*
+ * Fonts _should_ assume the pen position is now
+ * *after* the base glyph, and thus use negative
+ * offsets for combining glyphs.
+ *
+ * Not all fonts behave like this however, and we
+ * try to accomodate both variants.
+ *
+ * Since we haven't moved our pen position yet, we
+ * add a full cell width to the offset (or two, in
+ * case of double-width characters).
+ *
+ * If the font does *not* use negative offsets,
+ * we'd normally use an offset of 0. However, to
+ * somewhat deal with double-width glyphs we use
+ * an offset of *one* cell.
+ */
+ int x_ofs = g->x < 0
+ ? cell_cols * term->cell_width
+ : (cell_cols - 1) * term->cell_width;
+
+ pixman_image_composite32(
+ PIXMAN_OP_OVER, clr_pix, g->pix, pix, 0, 0, 0, 0,
+ x + x_ofs + g->x, y + font_baseline(term) - g->y,
+ g->width, g->height);
}
}
-
}
pixman_image_unref(clr_pix);