Base rc.title_height on font vertical extents

This commit is contained in:
Johan Malm 2020-08-05 20:14:17 +01:00
parent 4d1363dcae
commit 2297e43cc0
11 changed files with 123 additions and 26 deletions

41
src/common/font.c Normal file
View file

@ -0,0 +1,41 @@
#include <cairo.h>
#include <pango/pangocairo.h>
#include "common/font.h"
static PangoRectangle font_extents(const char *font_description,
const char *string)
{
PangoRectangle rect;
cairo_surface_t *surface;
cairo_t *c;
PangoLayout *layout;
PangoFontDescription *font;
surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1);
c = cairo_create(surface);
layout = pango_cairo_create_layout(c);
font = pango_font_description_from_string(font_description);
pango_layout_set_font_description(layout, font);
pango_layout_set_text(layout, string, -1);
pango_layout_set_single_paragraph_mode(layout, TRUE);
pango_layout_set_width(layout, -1);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_MIDDLE);
pango_layout_get_extents(layout, NULL, &rect);
pango_extents_to_pixels(&rect, NULL);
/* we put a 2 px edge on each side - because Openbox does it :) */
rect.width += 4;
g_object_unref(layout);
pango_font_description_free(font);
return rect;
}
int font_height(const char *font_description)
{
PangoRectangle rectangle;
rectangle = font_extents(font_description, "abcdefg");
return rectangle.height;
}

View file

@ -1,4 +1,5 @@
labwc_sources += files(
'buf.c',
'font.c',
'spawn.c',
)