aboutsummaryrefslogtreecommitdiffstats
path: root/surfaces
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-27 23:12:16 +0100
committereunhhu <[email protected]>2026-09-27 23:12:16 +0100
commit0d9d4c50bbd4a33a309ccb498b6bc55509c1dfed (patch)
treefea456a0da127cb40897ecf29191d5fb8f777347 /surfaces
parent7b93a66dbffaf2b20b0a1925786f56db54066c9b (diff)
downloadvega-0d9d4c50bbd4a33a309ccb498b6bc55509c1dfed.tar.gz
vega-0d9d4c50bbd4a33a309ccb498b6bc55509c1dfed.zip
Centre a wide character's glyph in its two cells
A Hangul or CJK glyph is one em across, less than two cells of a monospace Latin font (1.2 em for DejaVu Sans Mono), and was drawn from the left of its cells, so syllables stood apart unevenly. A cached glyph now keeps its advance in pixels, and a wide character's glyph is drawn centred in its two cells.
Diffstat (limited to 'surfaces')
-rw-r--r--surfaces/pixels.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/surfaces/pixels.c b/surfaces/pixels.c
index f671143..304e96d 100644
--- a/surfaces/pixels.c
+++ b/surfaces/pixels.c
@@ -86,8 +86,12 @@ void vega_pixels(const VegaGrid *grid, VegaFace *face, uint32_t *out, size_t str
int x = (int)c * face->cell_width, y = (int)r * face->cell_height;
const VegaBitmap *glyph = vega_glyph(face->glyphs, cell->ch);
unsigned cells = vega_width(cell->ch) == 2 ? 2 : 1;
+ /* A wide character's glyph is centred in its two cells: a CJK font's full width is
+ * less than two cells of a monospace Latin font. */
+ int centred = glyph && cells == 2 && glyph->advance < 2 * face->cell_width
+ ? (2 * face->cell_width - glyph->advance) / 2 : 0;
if (!glyph) missing(out, stride, x, y, face->cell_width * (int)cells, face->cell_height, width, color);
- else draw(out, stride, width, height, glyph, x, y + face->baseline, color);
+ else draw(out, stride, width, height, glyph, x + centred, y + face->baseline, color);
if (cell->mark && (glyph = vega_glyph(face->glyphs, cell->mark)))
draw(out, stride, width, height, glyph, x, y + face->baseline, color);
}