aboutsummaryrefslogtreecommitdiffstats
path: root/common/pango.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-09-08 16:19:31 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-09-08 16:25:07 +1000
commit9215ca0f01f7d155191d11fd9caa2574387c6f84 (patch)
treea1defcadae4b1d07388fd9e6bfe2a09051aec777 /common/pango.c
parentFix gaps in title textures and vertically center them (diff)
downloadsway-9215ca0f01f7d155191d11fd9caa2574387c6f84.tar.gz
sway-9215ca0f01f7d155191d11fd9caa2574387c6f84.tar.zst
sway-9215ca0f01f7d155191d11fd9caa2574387c6f84.zip
Align titles to baseline
This does the following: * Adds a baseline argument to get_text_size (the baseline is the distance from the top of the texture to the baseline). * Stores the baseline in the container when calculating the title height. * Takes the baseline into account when calculating the config's max font height. * When rendering, pads the textures according to the baseline so they line up.
Diffstat (limited to 'common/pango.c')
-rw-r--r--common/pango.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/common/pango.c b/common/pango.c
index 92703f80..ea71ac4a 100644
--- a/common/pango.c
+++ b/common/pango.c
@@ -103,7 +103,7 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font,
103} 103}
104 104
105void get_text_size(cairo_t *cairo, const char *font, int *width, int *height, 105void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
106 double scale, bool markup, const char *fmt, ...) { 106 int *baseline, double scale, bool markup, const char *fmt, ...) {
107 static char buf[2048]; 107 static char buf[2048];
108 108
109 va_list args; 109 va_list args;
@@ -116,6 +116,9 @@ void get_text_size(cairo_t *cairo, const char *font, int *width, int *height,
116 PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup); 116 PangoLayout *layout = get_pango_layout(cairo, font, buf, scale, markup);
117 pango_cairo_update_layout(cairo, layout); 117 pango_cairo_update_layout(cairo, layout);
118 pango_layout_get_pixel_size(layout, width, height); 118 pango_layout_get_pixel_size(layout, width, height);
119 if (baseline) {
120 *baseline = pango_layout_get_baseline(layout) / PANGO_SCALE;
121 }
119 g_object_unref(layout); 122 g_object_unref(layout);
120} 123}
121 124