diff options
Diffstat (limited to 'common/pango.c')
-rw-r--r-- | common/pango.c | 18 |
1 files changed, 18 insertions, 0 deletions
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, | |||
109 | free(buf); | 109 | free(buf); |
110 | } | 110 | } |
111 | 111 | ||
112 | void get_text_metrics(const char *font, int *height, int *baseline) { | ||
113 | cairo_t *cairo = cairo_create(NULL); | ||
114 | PangoContext *pango = pango_cairo_create_context(cairo); | ||
115 | PangoFontDescription *description = pango_font_description_from_string(font); | ||
116 | PangoFontMetrics *metrics; | ||
117 | |||
118 | // When passing NULL as a language, pango uses the current locale. | ||
119 | metrics = pango_context_get_metrics(pango, description, NULL); | ||
120 | |||
121 | *baseline = pango_font_metrics_get_ascent(metrics) / PANGO_SCALE; | ||
122 | *height = *baseline + pango_font_metrics_get_descent(metrics) / PANGO_SCALE; | ||
123 | |||
124 | pango_font_metrics_unref(metrics); | ||
125 | pango_font_description_free(description); | ||
126 | g_object_unref(pango); | ||
127 | cairo_destroy(cairo); | ||
128 | } | ||
129 | |||
112 | void pango_printf(cairo_t *cairo, const char *font, | 130 | void pango_printf(cairo_t *cairo, const char *font, |
113 | double scale, bool markup, const char *fmt, ...) { | 131 | double scale, bool markup, const char *fmt, ...) { |
114 | va_list args; | 132 | va_list args; |