summaryrefslogtreecommitdiff
path: root/gui-over.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-08-06 13:26:59 -0300
committerWerner Almesberger <werner@almesberger.net>2016-08-06 13:38:13 -0300
commitb3e7bfacea40336e4f855f662a8c88a31e94f007 (patch)
treed2363e120a15675b0a0cf7ae6fa53aa6badc0d32 /gui-over.c
parenta3628e3bcba354db50e9396387e695ba558ae998 (diff)
downloadeeshow-b3e7bfacea40336e4f855f662a8c88a31e94f007.tar.gz
eeshow-b3e7bfacea40336e4f855f662a8c88a31e94f007.tar.bz2
eeshow-b3e7bfacea40336e4f855f662a8c88a31e94f007.zip
eeshow/gui-over.c (overlay_draw): use Pango
Diffstat (limited to 'gui-over.c')
-rw-r--r--gui-over.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/gui-over.c b/gui-over.c
index 55d3f13..3b4550b 100644
--- a/gui-over.c
+++ b/gui-over.c
@@ -23,6 +23,7 @@
#include <math.h>
#include <cairo/cairo.h>
+#include <pango/pangocairo.h>
#include "util.h"
#include "gui-aoi.h"
@@ -66,14 +67,21 @@ static void rrect(cairo_t *cr, int x, int y, int w, int h, int r)
struct overlay *overlay_draw(struct overlay *over, cairo_t *cr, int *x, int *y)
{
- cairo_text_extents_t ext;
int w, h;
- cairo_set_font_size(cr, OVER_FONT_SIZE);
- cairo_text_extents(cr, over->s, &ext);
+ PangoLayout *layout;
+ PangoFontDescription *desc;
+ PangoRectangle ink_rect;
- w = ext.width + 2 * OVER_BORDER;
- h = ext.height + 2 * OVER_BORDER;
+ layout = pango_cairo_create_layout(cr);
+ pango_layout_set_text(layout, over->s, -1);
+ desc = pango_font_description_from_string("Helvetica Bold 12");
+ pango_layout_set_font_description(layout, desc);
+ pango_font_description_free(desc);
+
+ pango_layout_get_extents(layout, &ink_rect, NULL);
+ w = ink_rect.width / PANGO_SCALE + 2 * OVER_BORDER;
+ h = ink_rect.height / PANGO_SCALE + 2 * OVER_BORDER;
rrect(cr, *x, *y, w, h, OVER_RADIUS);
@@ -84,8 +92,11 @@ struct overlay *overlay_draw(struct overlay *over, cairo_t *cr, int *x, int *y)
cairo_stroke(cr);
cairo_set_source_rgb(cr, 0, 0, 0);
- cairo_move_to(cr, *x + OVER_BORDER, *y + OVER_BORDER + ext.height);
- cairo_show_text(cr, over->s);
+ cairo_move_to(cr, *x - ink_rect.x / PANGO_SCALE + OVER_BORDER,
+ *y - ink_rect.y / PANGO_SCALE + OVER_BORDER + 0*ink_rect.height);
+
+ pango_cairo_update_layout(cr, layout);
+ pango_cairo_show_layout(cr, layout);
if (over->hover || over->click) {
struct aoi aoi = {