From d309df6f87216723d784e276d1de451e37803643 Mon Sep 17 00:00:00 2001 From: Consolatis <35009135+Consolatis@users.noreply.github.com> Date: Wed, 15 Jun 2022 01:16:32 +0200 Subject: [PATCH] src/common/font.c: Add font_width() --- include/common/font.h | 6 ++++++ src/common/font.c | 7 +++++++ 2 files changed, 13 insertions(+) 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) -- 2.52.0