render: apply new baseline calculation everywhere

* URL jump labels
* Scrollback position indicator
* Line/box drawings characters

Closes #1430
This commit is contained in:
Daniel Eklöf 2023-07-23 17:35:57 +02:00
parent 0a61cfc3be
commit a36f67cbe3
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
5 changed files with 29 additions and 22 deletions

View file

@ -53,9 +53,15 @@
* Crash when copying text that contains invalid UTF-8 ([#1423][1423]).
* Wrong font size after suspending the monitor ([#1431][1431]).
* Vertical alignment in URL jump labels, and the scrollback position
indicator ([#1430][1430]).
* Regression: line- and box drawing characters not covering the full
height of the line, when a custom `line-height` is being used
([#1430][1430]).
[1423]: https://codeberg.org/dnkl/foot/issues/1423
[1431]: https://codeberg.org/dnkl/foot/issues/1431
[1430]: https://codeberg.org/dnkl/foot/issues/1430
### Security

View file

@ -3011,7 +3011,7 @@ box_drawing(const struct terminal *term, char32_t wc)
.cols = 1,
.pix = buf.pix,
.x = -term->font_x_ofs,
.y = term->font_y_ofs + term->fonts[0]->ascent,
.y = term_font_baseline(term),
.width = width,
.height = height,
.advance = {

View file

@ -302,17 +302,6 @@ color_brighten(const struct terminal *term, uint32_t color)
return hsl_to_rgb(hue, sat, min(100, lum * 1.3));
}
static inline int
font_baseline(const struct terminal *term)
{
const struct fcft_font *font = term->fonts[0];
const int line_height = term->cell_height;
const int font_height = font->ascent + font->descent;
const int glyph_top_y = round((line_height - font_height) / 2.);
return term->font_y_ofs + glyph_top_y + font->ascent;
}
static void
draw_unfocused_block(const struct terminal *term, pixman_image_t *pix,
const pixman_color_t *color, int x, int y, int cell_cols)
@ -335,7 +324,7 @@ draw_beam_cursor(const struct terminal *term, pixman_image_t *pix,
const struct fcft_font *font,
const pixman_color_t *color, int x, int y)
{
int baseline = y + font_baseline(term) - term->fonts[0]->ascent;
int baseline = y + term_font_baseline(term) - term->fonts[0]->ascent;
pixman_image_fill_rectangles(
PIXMAN_OP_SRC, pix, color,
1, &(pixman_rectangle16_t){
@ -347,7 +336,7 @@ draw_beam_cursor(const struct terminal *term, pixman_image_t *pix,
static int
underline_offset(const struct terminal *term, const struct fcft_font *font)
{
return font_baseline(term) -
return term_font_baseline(term) -
(term->conf->use_custom_underline_offset
? -term_pt_or_px_as_pixels(term, &term->conf->underline_offset)
: font->underline.position);
@ -401,7 +390,7 @@ draw_strikeout(const struct terminal *term, pixman_image_t *pix,
pixman_image_fill_rectangles(
PIXMAN_OP_SRC, pix, color,
1, &(pixman_rectangle16_t){
x, y + font_baseline(term) - font->strikeout.position,
x, y + term_font_baseline(term) - font->strikeout.position,
cols * term->cell_width, font->strikeout.thickness});
}
@ -767,13 +756,13 @@ render_cell(struct terminal *term, pixman_image_t *pix,
if (!(cell->attrs.blink && term->blink.state == BLINK_OFF)) {
pixman_image_composite32(
PIXMAN_OP_OVER, glyph->pix, NULL, pix, 0, 0, 0, 0,
pen_x + letter_x_ofs + g_x, y + font_baseline(term) - g_y,
pen_x + letter_x_ofs + g_x, y + term_font_baseline(term) - g_y,
glyph->width, glyph->height);
}
} else {
pixman_image_composite32(
PIXMAN_OP_OVER, clr_pix, glyph->pix, pix, 0, 0, 0, 0,
pen_x + letter_x_ofs + g_x, y + font_baseline(term) - g_y,
pen_x + letter_x_ofs + g_x, y + term_font_baseline(term) - g_y,
glyph->width, glyph->height);
/* Combining characters */
@ -813,7 +802,7 @@ render_cell(struct terminal *term, pixman_image_t *pix,
/* Some fonts use a negative offset, while others use a
* "normal" offset */
pen_x + x_ofs + g->x,
y + font_baseline(term) - g->y,
y + term_font_baseline(term) - g->y,
g->width, g->height);
}
}
@ -1937,12 +1926,12 @@ render_osd(struct terminal *term, const struct wayl_sub_surface *sub_surf,
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,
x + x_ofs + glyph->x, y + /*term->font_y_ofs + font->ascent*/ term_font_baseline(term) - 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,
x + x_ofs + glyph->x, y + /*term->font_y_ofs + font->ascent*/ term_font_baseline(term) - glyph->y,
glyph->width, glyph->height);
}
@ -3364,7 +3353,7 @@ render_search_box(struct terminal *term)
/* Glyph surface is a pre-rendered image (typically a color emoji...) */
pixman_image_composite32(
PIXMAN_OP_OVER, glyph->pix, NULL, 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_baseline(term) - glyph->y,
glyph->width, glyph->height);
} else {
int combining_ofs = width == 0
@ -3376,7 +3365,7 @@ render_search_box(struct terminal *term)
pixman_image_composite32(
PIXMAN_OP_OVER, src, glyph->pix, buf->pix[0], 0, 0, 0, 0,
x + x_ofs + combining_ofs + glyph->x,
y + font_baseline(term) - glyph->y,
y + term_font_baseline(term) - glyph->y,
glyph->width, glyph->height);
pixman_image_unref(src);
}

View file

@ -2166,6 +2166,17 @@ term_font_subpixel_changed(struct terminal *term)
render_refresh(term);
}
int
term_font_baseline(const struct terminal *term)
{
const struct fcft_font *font = term->fonts[0];
const int line_height = term->cell_height;
const int font_height = font->ascent + font->descent;
const int glyph_top_y = round((line_height - font_height) / 2.);
return term->font_y_ofs + glyph_top_y + font->ascent;
}
void
term_damage_rows(struct terminal *term, int start, int end)
{

View file

@ -742,6 +742,7 @@ bool term_font_size_decrease(struct terminal *term);
bool term_font_size_reset(struct terminal *term);
bool term_font_dpi_changed(struct terminal *term, float old_scale);
void term_font_subpixel_changed(struct terminal *term);
int term_font_baseline(const struct terminal *term);
int term_pt_or_px_as_pixels(
const struct terminal *term, const struct pt_or_px *pt_or_px);