From e17c6fcbecf67a75bf8cd37995fac0e937b934cc Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 22 Jul 2021 19:22:19 +0200 Subject: render: color_dim(): retain alpha channel --- render.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'render.c') diff --git a/render.c b/render.c index 6e0e82bf..f4ebc086 100644 --- a/render.c +++ b/render.c @@ -246,9 +246,10 @@ color_hex_to_pixman(uint32_t color) static inline uint32_t color_dim(uint32_t color) { + uint32_t alpha = color & 0xff000000; int hue, sat, lum; rgb_to_hsl(color, &hue, &sat, &lum); - return hsl_to_rgb(hue, sat, lum / 1.5); + return alpha | hsl_to_rgb(hue, sat, lum / 1.5); } static inline uint32_t -- cgit v1.3 From 7067c57399177c0559658086cbf7997fe3b8057a Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 22 Jul 2021 19:22:52 +0200 Subject: render: render_osd(): set clip region, use background alpha MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Set clip region in render_osd(). This ensures we don’t step outside the pixman buffer when rendering the glyphs. Furthermore, don’t ignore the alpha channel in the background color. Move render_osd() to make it visible to the render_csd_*() functions. --- render.c | 114 ++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 61 insertions(+), 53 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index f4ebc086..94651c11 100644 --- a/render.c +++ b/render.c @@ -1576,6 +1576,67 @@ render_csd_part(struct terminal *term, pixman_image_unref(src); } +static void +render_osd(struct terminal *term, + struct wl_surface *surf, struct wl_subsurface *sub_surf, + struct buffer *buf, + const wchar_t *text, uint32_t _fg, uint32_t _bg, + unsigned x, unsigned y) +{ + pixman_region32_t clip; + pixman_region32_init_rect(&clip, 0, 0, buf->width, buf->height); + pixman_image_set_clip_region32(buf->pix[0], &clip); + pixman_region32_fini(&clip); + + uint16_t alpha = _bg >> 24 | (_bg >> 24 << 8); + pixman_color_t bg = color_hex_to_pixman_with_alpha(_bg, alpha); + pixman_image_fill_rectangles( + PIXMAN_OP_SRC, buf->pix[0], &bg, 1, + &(pixman_rectangle16_t){0, 0, buf->width, buf->height}); + + struct fcft_font *font = term->fonts[0]; + pixman_color_t fg = color_hex_to_pixman(_fg); + + const int x_ofs = term->font_x_ofs; + + for (size_t i = 0; i < wcslen(text); i++) { + const struct fcft_glyph *glyph = fcft_glyph_rasterize( + font, text[i], term->font_subpixel); + + if (glyph == NULL) + continue; + + pixman_image_t *src = pixman_image_create_solid_fill(&fg); + pixman_image_composite32( + PIXMAN_OP_OVER, src, glyph->pix, buf->pix[0], 0, 0, 0, 0, + x + x_ofs + glyph->x, y + font_baseline(term) - glyph->y, + glyph->width, glyph->height); + pixman_image_unref(src); + + x += term->cell_width; + } + + pixman_image_set_clip_region32(buf->pix[0], NULL); + + xassert(buf->width % term->scale == 0); + xassert(buf->height % term->scale == 0); + + quirk_weston_subsurface_desync_on(sub_surf); + wl_surface_attach(surf, buf->wl_buf, 0, 0); + wl_surface_damage_buffer(surf, 0, 0, buf->width, buf->height); + wl_surface_set_buffer_scale(surf, term->scale); + + struct wl_region *region = wl_compositor_create_region(term->wl->compositor); + if (region != NULL) { + wl_region_add(region, 0, 0, buf->width, buf->height); + wl_surface_set_opaque_region(surf, region); + wl_region_destroy(region); + } + + wl_surface_commit(surf); + quirk_weston_subsurface_desync_off(sub_surf); +} + static void render_csd_title(struct terminal *term, const struct csd_data *info, struct buffer *buf) @@ -1913,59 +1974,6 @@ render_csd(struct terminal *term) render_csd_title(term, &infos[CSD_SURF_TITLE], bufs[CSD_SURF_TITLE]); } -static void -render_osd(struct terminal *term, - struct wl_surface *surf, struct wl_subsurface *sub_surf, - struct buffer *buf, - const wchar_t *text, uint32_t _fg, uint32_t _bg, - unsigned x, unsigned y) -{ - pixman_color_t bg = color_hex_to_pixman(_bg); - pixman_image_fill_rectangles( - PIXMAN_OP_SRC, buf->pix[0], &bg, 1, - &(pixman_rectangle16_t){0, 0, buf->width, buf->height}); - - struct fcft_font *font = term->fonts[0]; - pixman_color_t fg = color_hex_to_pixman(_fg); - - const int x_ofs = term->font_x_ofs; - - for (size_t i = 0; i < wcslen(text); i++) { - const struct fcft_glyph *glyph = fcft_glyph_rasterize( - font, text[i], term->font_subpixel); - - if (glyph == NULL) - continue; - - pixman_image_t *src = pixman_image_create_solid_fill(&fg); - pixman_image_composite32( - PIXMAN_OP_OVER, src, glyph->pix, buf->pix[0], 0, 0, 0, 0, - x + x_ofs + glyph->x, y + font_baseline(term) - glyph->y, - glyph->width, glyph->height); - pixman_image_unref(src); - - x += term->cell_width; - } - - xassert(buf->width % term->scale == 0); - xassert(buf->height % term->scale == 0); - - quirk_weston_subsurface_desync_on(sub_surf); - wl_surface_attach(surf, buf->wl_buf, 0, 0); - wl_surface_damage_buffer(surf, 0, 0, buf->width, buf->height); - wl_surface_set_buffer_scale(surf, term->scale); - - struct wl_region *region = wl_compositor_create_region(term->wl->compositor); - if (region != NULL) { - wl_region_add(region, 0, 0, buf->width, buf->height); - wl_surface_set_opaque_region(surf, region); - wl_region_destroy(region); - } - - wl_surface_commit(surf); - quirk_weston_subsurface_desync_off(sub_surf); -} - static void render_scrollback_position(struct terminal *term) { -- cgit v1.3 From bbc26da87b821fcab684a9c1dfaa52d0538b278b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 22 Jul 2021 19:24:20 +0200 Subject: render: must now set alpha in bg color when calling render_osd() --- render.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 94651c11..c459dafa 100644 --- a/render.c +++ b/render.c @@ -2103,7 +2103,7 @@ render_scrollback_position(struct terminal *term) win->scrollback_indicator.surf, win->scrollback_indicator.sub, buf, text, - term->colors.table[0], term->colors.table[8 + 4], + term->colors.table[0], 0xffu << 24 | term->colors.table[8 + 4], width - margin - wcslen(text) * term->cell_width, margin); } @@ -2137,7 +2137,7 @@ render_render_timer(struct terminal *term, struct timeval render_time) win->render_timer.surf, win->render_timer.sub, buf, text, - term->colors.table[0], term->colors.table[8 + 1], + term->colors.table[0], 0xffu << 24 | term->colors.table[8 + 1], margin, margin); } @@ -2639,7 +2639,6 @@ render_search_box(struct terminal *term) pixman_image_set_clip_region32(buf->pix[0], &clip); pixman_region32_fini(&clip); - #define WINDOW_X(x) (margin + x) #define WINDOW_Y(y) (term->height - margin - height + y) @@ -3106,7 +3105,8 @@ render_urls(struct terminal *term) (term->margins.top + y) / term->scale); render_osd( - term, surf, sub_surf, bufs[i], label, fg, bg, x_margin, y_margin); + term, surf, sub_surf, bufs[i], label, + fg, 0xffu << 24 | bg, x_margin, y_margin); free(info[i].text); } -- cgit v1.3 From 468587b67f1c9c8dee6896d4319f0282a01ecb0d Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 22 Jul 2021 19:25:24 +0200 Subject: render: csd_title(): use render_osd() to render the current window title --- render.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index c459dafa..43d50b83 100644 --- a/render.c +++ b/render.c @@ -1643,26 +1643,40 @@ render_csd_title(struct terminal *term, const struct csd_data *info, { xassert(term->window->csd_mode == CSD_YES); - struct wl_surface *surf = term->window->csd.surface[CSD_SURF_TITLE].surf; + struct wl_surf_subsurf *surf = &term->window->csd.surface[CSD_SURF_TITLE]; xassert(info->width > 0 && info->height > 0); xassert(info->width % term->scale == 0); xassert(info->height % term->scale == 0); - uint32_t _color = term->conf->colors.fg; - uint16_t alpha = 0xffff; + uint32_t bg = term->conf->csd.color.title_set + ? term->conf->csd.color.title + : 0xffu << 24 | term->conf->colors.fg; + uint32_t fg = term->conf->csd.color.buttons_set + ? term->conf->csd.color.buttons + : term->conf->colors.bg; - if (term->conf->csd.color.title_set) { - _color = term->conf->csd.color.title; - alpha = _color >> 24 | (_color >> 24 << 8); + if (!term->visual_focus) { + bg = color_dim(bg); + fg = color_dim(fg); } - if (!term->visual_focus) - _color = color_dim(_color); + const wchar_t *title_text = L""; + wchar_t *_title_text = NULL; - pixman_color_t color = color_hex_to_pixman_with_alpha(_color, alpha); - render_csd_part(term, surf, buf, info->width, info->height, &color); - csd_commit(term, surf, buf); + int chars = mbstowcs(NULL, term->window_title, 0); + if (chars >= 0) { + _title_text = xmalloc((chars + 1) * sizeof(wchar_t)); + mbstowcs(_title_text, term->window_title, chars + 1); + title_text = _title_text; + } + + const int margin = 10 * term->scale; + render_osd(term, surf->surf, surf->sub, buf, title_text, fg, bg, + margin, (buf->height - term->fonts[0]->height) / 2); + + csd_commit(term, surf->surf, buf); + free(_title_text); } static void -- cgit v1.3 From 61e4035c23ef61a0fcca5f56a8ac50afa64349ea Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 22 Jul 2021 19:27:35 +0200 Subject: render: refresh CSDs when updating the title --- render.c | 1 + 1 file changed, 1 insertion(+) (limited to 'render.c') diff --git a/render.c b/render.c index 43d50b83..2e59a688 100644 --- a/render.c +++ b/render.c @@ -3141,6 +3141,7 @@ render_update_title(struct terminal *term) xdg_toplevel_set_title(term->window->xdg_toplevel, title); free(copy); + render_refresh_csd(term); } static void -- cgit v1.3 From 3d9536caff354e30bea463f4a7e617a9aa11ebc7 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 22 Jul 2021 19:34:19 +0200 Subject: render: refresh CSD in render_refresh_title(), not render_update_title() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes an issue where the CSD title sometimes got stuck on an “old” title. --- render.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'render.c') diff --git a/render.c b/render.c index 2e59a688..1a66288b 100644 --- a/render.c +++ b/render.c @@ -3141,7 +3141,6 @@ render_update_title(struct terminal *term) xdg_toplevel_set_title(term->window->xdg_toplevel, title); free(copy); - render_refresh_csd(term); } static void @@ -3691,6 +3690,8 @@ render_refresh_title(struct terminal *term) term->render.title.last_update = now; render_update_title(term); } + + render_refresh_csd(term); } void -- cgit v1.3 From 5fe23c0215502b41fb40032a89d55e574e73169f Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 22 Jul 2021 21:23:01 +0200 Subject: render: render_osd(): pass font as argument --- render.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 1a66288b..91499a43 100644 --- a/render.c +++ b/render.c @@ -1579,7 +1579,7 @@ render_csd_part(struct terminal *term, static void render_osd(struct terminal *term, struct wl_surface *surf, struct wl_subsurface *sub_surf, - struct buffer *buf, + struct fcft_font *font, struct buffer *buf, const wchar_t *text, uint32_t _fg, uint32_t _bg, unsigned x, unsigned y) { @@ -1594,11 +1594,15 @@ render_osd(struct terminal *term, PIXMAN_OP_SRC, buf->pix[0], &bg, 1, &(pixman_rectangle16_t){0, 0, buf->width, buf->height}); - struct fcft_font *font = term->fonts[0]; pixman_color_t fg = color_hex_to_pixman(_fg); - const int x_ofs = term->font_x_ofs; + const int advance = + (font->space_advance.x > 0 + ? font->space_advance.x + : font->max_advance.x) + + term_pt_or_px_as_pixels(term, &term->conf->letter_spacing); + for (size_t i = 0; i < wcslen(text); i++) { const struct fcft_glyph *glyph = fcft_glyph_rasterize( font, text[i], term->font_subpixel); @@ -1609,11 +1613,11 @@ render_osd(struct terminal *term, pixman_image_t *src = pixman_image_create_solid_fill(&fg); pixman_image_composite32( PIXMAN_OP_OVER, src, glyph->pix, buf->pix[0], 0, 0, 0, 0, - x + x_ofs + glyph->x, y + font_baseline(term) - glyph->y, + x + x_ofs + glyph->x, y + term->font_y_ofs + font->ascent - glyph->y, glyph->width, glyph->height); pixman_image_unref(src); - x += term->cell_width; + x += advance; } pixman_image_set_clip_region32(buf->pix[0], NULL); -- cgit v1.3 From 4a41575cb5d2738cf1fb341f0d4413dee1bf67cc Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 22 Jul 2021 21:23:29 +0200 Subject: render: render_osd() now needs a ‘font’ argument MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- render.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 91499a43..82720d22 100644 --- a/render.c +++ b/render.c @@ -2120,7 +2120,7 @@ render_scrollback_position(struct terminal *term) term, win->scrollback_indicator.surf, win->scrollback_indicator.sub, - buf, text, + term->fonts[0], buf, text, term->colors.table[0], 0xffu << 24 | term->colors.table[8 + 4], width - margin - wcslen(text) * term->cell_width, margin); } @@ -2154,7 +2154,7 @@ render_render_timer(struct terminal *term, struct timeval render_time) term, win->render_timer.surf, win->render_timer.sub, - buf, text, + term->fonts[0], buf, text, term->colors.table[0], 0xffu << 24 | term->colors.table[8 + 1], margin, margin); } @@ -3123,7 +3123,7 @@ render_urls(struct terminal *term) (term->margins.top + y) / term->scale); render_osd( - term, surf, sub_surf, bufs[i], label, + term, surf, sub_surf, term->fonts[0], bufs[i], label, fg, 0xffu << 24 | bg, x_margin, y_margin); free(info[i].text); -- cgit v1.3 From 0cf7a196163d51c344361bb2b79c145003dc3555 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 22 Jul 2021 21:23:59 +0200 Subject: render: csd_title(): use a custom font, sized based on the title bar’s height MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We still use the primary font, but use a custom size, based on the title bar’s height. This fixes an issue where the window title could be way too small, or way too big. And changed size when the terminal font size was changed. --- render.c | 11 ++++++++--- wayland.c | 33 +++++++++++++++++++++++++++++++++ wayland.h | 2 ++ 3 files changed, 43 insertions(+), 3 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 82720d22..8fb810b9 100644 --- a/render.c +++ b/render.c @@ -1675,9 +1675,14 @@ render_csd_title(struct terminal *term, const struct csd_data *info, title_text = _title_text; } - const int margin = 10 * term->scale; - render_osd(term, surf->surf, surf->sub, buf, title_text, fg, bg, - margin, (buf->height - term->fonts[0]->height) / 2); + struct wl_window *win = term->window; + const int margin = win->csd.font->space_advance.x > 0 + ? win->csd.font->space_advance.x + : win->csd.font->max_advance.x; + + render_osd(term, surf->surf, surf->sub, win->csd.font, + buf, title_text, fg, bg, margin, + (buf->height - win->csd.font->height) / 2); csd_commit(term, surf->surf, buf); free(_title_text); diff --git a/wayland.c b/wayland.c index 0679dee3..40852ec0 100644 --- a/wayland.c +++ b/wayland.c @@ -30,6 +30,33 @@ #include "util.h" #include "xmalloc.h" +static void +csd_reload_font(struct wl_window *win, int old_scale) +{ + struct terminal *term = win->term; + const struct config *conf = term->conf; + + const int scale = term->scale; + + bool enable_csd = win->csd_mode == CSD_YES && !win->is_fullscreen; + if (!enable_csd) + return; + if (win->csd.font != NULL && scale == old_scale) + return; + + fcft_destroy(win->csd.font); + + char pixelsize[32]; + snprintf(pixelsize, sizeof(pixelsize), + "pixelsize=%u", conf->csd.title_height * scale * 1 / 2); + + LOG_DBG("loading CSD font \"%s:%s\" (old-scale=%d, scale=%d)", + conf->fonts->arr[0].pattern, pixelsize, old_scale, scale); + + win->csd.font = fcft_from_name( + 1, &(const char *){conf->fonts->arr[0].pattern}, pixelsize); +} + static void csd_instantiate(struct wl_window *win) { @@ -46,6 +73,8 @@ csd_instantiate(struct wl_window *win) win, win->csd.surface[CSD_SURF_TITLE].surf, &win->csd.surface[i]); xassert(ret); } + + csd_reload_font(win, -1); } static void @@ -53,6 +82,9 @@ csd_destroy(struct wl_window *win) { struct terminal *term = win->term; + fcft_destroy(term->window->csd.font); + term->window->csd.font = NULL; + for (size_t i = 0; i < ALEN(win->csd.surface); i++) wayl_win_subsurface_destroy(&win->csd.surface[i]); shm_purge(term->render.chains.csd); @@ -294,6 +326,7 @@ update_term_for_output_change(struct terminal *term) render_resize(term, term->width / term->scale, term->height / term->scale); term_font_dpi_changed(term, old_scale); term_font_subpixel_changed(term); + csd_reload_font(term->window, old_scale); } static void diff --git a/wayland.h b/wayland.h index f62819a4..bc044169 100644 --- a/wayland.h +++ b/wayland.h @@ -20,6 +20,7 @@ #include #endif +#include #include #include "fdm.h" @@ -402,6 +403,7 @@ struct wl_window { struct { struct wl_surf_subsurf surface[CSD_SURF_COUNT]; + struct fcft_font *font; int move_timeout_fd; uint32_t serial; } csd; -- cgit v1.3 From 5c683d2c089e4b30b35d0f5b9c816e1a88ae6e10 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 22 Jul 2021 23:26:07 +0200 Subject: render: render_osd(): don’t assume a monospace font MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- render.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 8fb810b9..581d0cbb 100644 --- a/render.c +++ b/render.c @@ -1597,11 +1597,6 @@ render_osd(struct terminal *term, pixman_color_t fg = color_hex_to_pixman(_fg); const int x_ofs = term->font_x_ofs; - const int advance = - (font->space_advance.x > 0 - ? font->space_advance.x - : font->max_advance.x) - + term_pt_or_px_as_pixels(term, &term->conf->letter_spacing); for (size_t i = 0; i < wcslen(text); i++) { const struct fcft_glyph *glyph = fcft_glyph_rasterize( @@ -1617,7 +1612,7 @@ render_osd(struct terminal *term, glyph->width, glyph->height); pixman_image_unref(src); - x += advance; + x += glyph->advance.x; } pixman_image_set_clip_region32(buf->pix[0], NULL); -- cgit v1.3 From bf285ae00a749147fa15ac86bc38e8b1d7cae217 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 22 Jul 2021 23:27:05 +0200 Subject: render: render_osd(): don’t re-instantiate foreground color for each glyph MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- render.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'render.c') diff --git a/render.c b/render.c index 581d0cbb..d5e7a7d6 100644 --- a/render.c +++ b/render.c @@ -1597,6 +1597,7 @@ render_osd(struct terminal *term, pixman_color_t fg = color_hex_to_pixman(_fg); const int x_ofs = term->font_x_ofs; + pixman_image_t *src = pixman_image_create_solid_fill(&fg); for (size_t i = 0; i < wcslen(text); i++) { const struct fcft_glyph *glyph = fcft_glyph_rasterize( @@ -1615,6 +1616,7 @@ render_osd(struct terminal *term, x += glyph->advance.x; } + pixman_image_unref(src); pixman_image_set_clip_region32(buf->pix[0], NULL); xassert(buf->width % term->scale == 0); -- cgit v1.3 From e2e28db7deb762830bf3a3d178a561b8e683ff8a Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 22 Jul 2021 23:27:10 +0200 Subject: render: render_osd(): fix rendering of color bitmap glyphs --- render.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index d5e7a7d6..1f8c5809 100644 --- a/render.c +++ b/render.c @@ -1606,12 +1606,17 @@ render_osd(struct terminal *term, if (glyph == NULL) continue; - pixman_image_t *src = pixman_image_create_solid_fill(&fg); - pixman_image_composite32( - PIXMAN_OP_OVER, src, glyph->pix, buf->pix[0], 0, 0, 0, 0, - x + x_ofs + glyph->x, y + term->font_y_ofs + font->ascent - glyph->y, - glyph->width, glyph->height); - pixman_image_unref(src); + if (pixman_image_get_format(glyph->pix) == PIXMAN_a8r8g8b8) { + pixman_image_composite32( + PIXMAN_OP_OVER, glyph->pix, NULL, buf->pix[0], 0, 0, 0, 0, + x + x_ofs + glyph->x, y + term->font_y_ofs + font->ascent - glyph->y, + glyph->width, glyph->height); + } else { + pixman_image_composite32( + PIXMAN_OP_OVER, src, glyph->pix, buf->pix[0], 0, 0, 0, 0, + x + x_ofs + glyph->x, y + term->font_y_ofs + font->ascent - glyph->y, + glyph->width, glyph->height); + } x += glyph->advance.x; } -- cgit v1.3 From 7714fcde83c223f8143bb406eb2e2541ee932c4a Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Thu, 22 Jul 2021 23:35:00 +0200 Subject: render: render_osd(): use fcft_text_run_rasterize(), if available --- render.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 1f8c5809..f42279c9 100644 --- a/render.c +++ b/render.c @@ -1597,14 +1597,39 @@ render_osd(struct terminal *term, pixman_color_t fg = color_hex_to_pixman(_fg); const int x_ofs = term->font_x_ofs; - pixman_image_t *src = pixman_image_create_solid_fill(&fg); + const size_t len = wcslen(text); + struct fcft_text_run *text_run = NULL; + const struct fcft_glyph **glyphs = NULL; + const struct fcft_glyph *_glyphs[len]; + size_t glyph_count = 0; - for (size_t i = 0; i < wcslen(text); i++) { - const struct fcft_glyph *glyph = fcft_glyph_rasterize( - font, text[i], term->font_subpixel); + if (fcft_capabilities() & FCFT_CAPABILITY_TEXT_RUN_SHAPING) { + text_run = fcft_text_run_rasterize(font, len, text, term->font_subpixel); - if (glyph == NULL) - continue; + if (text_run != NULL) { + glyphs = text_run->glyphs; + glyph_count = text_run->count; + } + } + + if (glyphs == NULL) { + for (size_t i = 0; i < len; i++) { + const struct fcft_glyph *glyph = fcft_glyph_rasterize( + font, text[i], term->font_subpixel); + + if (glyph == NULL) + continue; + + _glyphs[glyph_count++] = glyph; + } + + glyphs = _glyphs; + } + + pixman_image_t *src = pixman_image_create_solid_fill(&fg); + + for (size_t i = 0; i < glyph_count; i++) { + const struct fcft_glyph *glyph = glyphs[i]; if (pixman_image_get_format(glyph->pix) == PIXMAN_a8r8g8b8) { pixman_image_composite32( @@ -1621,6 +1646,7 @@ render_osd(struct terminal *term, x += glyph->advance.x; } + fcft_text_run_destroy(text_run); pixman_image_unref(src); pixman_image_set_clip_region32(buf->pix[0], NULL); -- cgit v1.3