From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Tue, 14 Jun 2022 23:16:32 +0000 (+0200) Subject: src/common/font.c: Add font_width() X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=d309df6f87216723d784e276d1de451e37803643;p=proto%2Flabwc.git src/common/font.c: Add font_width() --- diff --git a/include/common/font.h b/include/common/font.h index 5095bdf0..0576bc61 100644 --- a/include/common/font.h +++ b/include/common/font.h @@ -15,6 +15,12 @@ struct font { */ int font_height(struct font *font); +/** + * font_width - get font horizontal extents + * @font: description of font including family name and size + */ +int font_width(struct font *font, const char *string); + /** * font_buffer_create - Create ARGB8888 lab_data_buffer using pango * @buffer: buffer pointer diff --git a/src/common/font.c b/src/common/font.c index 75d98a01..fd709dc4 100644 --- a/src/common/font.c +++ b/src/common/font.c @@ -49,6 +49,13 @@ font_height(struct font *font) return rectangle.height; } +int +font_width(struct font *font, const char *string) +{ + PangoRectangle rectangle = font_extents(font, string); + return rectangle.width; +} + void font_buffer_update(struct lab_data_buffer **buffer, int max_width, const char *text, struct font *font, float *color, double scale)