2020-08-05 20:14:17 +01:00
|
|
|
#include <cairo.h>
|
|
|
|
|
#include <pango/pangocairo.h>
|
|
|
|
|
|
|
|
|
|
#include "common/font.h"
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
static PangoRectangle
|
|
|
|
|
font_extents(const char *font_description, const char *string)
|
2020-08-05 20:14:17 +01:00
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
2020-08-14 17:57:18 +01:00
|
|
|
cairo_destroy(c);
|
|
|
|
|
cairo_surface_destroy(surface);
|
2020-08-05 20:14:17 +01:00
|
|
|
pango_font_description_free(font);
|
2020-08-14 17:57:18 +01:00
|
|
|
g_object_unref(layout);
|
2020-08-05 20:14:17 +01:00
|
|
|
return rect;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-28 20:41:41 +01:00
|
|
|
int
|
|
|
|
|
font_height(const char *font_description)
|
2020-08-05 20:14:17 +01:00
|
|
|
{
|
|
|
|
|
PangoRectangle rectangle;
|
|
|
|
|
rectangle = font_extents(font_description, "abcdefg");
|
|
|
|
|
return rectangle.height;
|
|
|
|
|
}
|