]> git.mdlowis.com Git - proto/labwc.git/commitdiff
src/common/font.c: Add font_width()
authorConsolatis <35009135+Consolatis@users.noreply.github.com>
Tue, 14 Jun 2022 23:16:32 +0000 (01:16 +0200)
committerJohan Malm <johanmalm@users.noreply.github.com>
Wed, 15 Jun 2022 15:14:02 +0000 (16:14 +0100)
include/common/font.h
src/common/font.c

index 5095bdf0b611fa649de71bb5b4ea3edf55bd68a0..0576bc6119e52a9a84635459fb80f7bfbabcfc67 100644 (file)
@@ -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
index 75d98a0118fc02004c2b00a0f03dbffec6fd4b4e..fd709dc4221c7c94ce8b5e212eb945ab9f2236df 100644 (file)
@@ -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)