mirror of
https://github.com/labwc/labwc.git
synced 2025-11-04 13:30:07 -05:00
Base rc.title_height on font vertical extents
This commit is contained in:
parent
4d1363dcae
commit
2297e43cc0
11 changed files with 123 additions and 26 deletions
41
src/common/font.c
Normal file
41
src/common/font.c
Normal 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;
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
labwc_sources += files(
|
||||
'buf.c',
|
||||
'font.c',
|
||||
'spawn.c',
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue