From 7ade2c9f868bea65b12af0234459164ecab1fba3 Mon Sep 17 00:00:00 2001 From: Furkan Sahin Date: Wed, 18 Aug 2021 23:27:01 +0200 Subject: Use fixed titlebar heights Use fixed titlebar heights. The default height is calculated based on font metrics for the configured font and current locale. Some testing with titles with emoji and CJK characters (which are substantially higher in my setup) shows that the titlebars retain their initial value, text does shift up or down, and all titlebars always remain aligned. Also drop some also now-unecessary title_height calculations. Makes also needed to be updated, since they should be positioned with the same rules. --- common/pango.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'common') diff --git a/common/pango.c b/common/pango.c index dbc369dc..88932203 100644 --- a/common/pango.c +++ b/common/pango.c @@ -109,6 +109,24 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, free(buf); } +void get_text_metrics(const char *font, int *height, int *baseline) { + cairo_t *cairo = cairo_create(NULL); + PangoContext *pango = pango_cairo_create_context(cairo); + PangoFontDescription *description = pango_font_description_from_string(font); + PangoFontMetrics *metrics; + + // When passing NULL as a language, pango uses the current locale. + metrics = pango_context_get_metrics(pango, description, NULL); + + *baseline = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE; + *height = *baseline + pango_font_metrics_get_descent(metrics) / PANGO_SCALE; + + pango_font_metrics_unref(metrics); + pango_font_description_free(description); + g_object_unref(pango); + cairo_destroy(cairo); +} + void pango_printf(cairo_t *cairo, const char *font, double scale, bool markup, const char *fmt, ...) { va_list args; -- cgit v1.2.3