diff --git a/draw.c b/draw.c index e21e415c..97c245ee 100644 --- a/draw.c +++ b/draw.c @@ -337,13 +337,14 @@ draw_context_init(draw_context_t *d, int phys_screen, * \param text Text to draw. * \param len Text to draw length. * \param data Optional parser data. + * \param ext Text extents. */ void draw_text(draw_context_t *ctx, font_t *font, PangoEllipsizeMode ellip, PangoWrapMode wrap, - area_t area, const char *text, ssize_t len, draw_parser_data_t *pdata) + area_t area, const char *text, ssize_t len, draw_parser_data_t *pdata, + area_t *ext) { int x, y; - PangoRectangle ext; draw_parser_data_t parser_data; if(!pdata) @@ -399,23 +400,22 @@ draw_text(draw_context_t *ctx, font_t *font, PangoEllipsizeMode ellip, PangoWrap pango_layout_set_wrap(ctx->layout, wrap); pango_layout_set_attributes(ctx->layout, pdata->attr_list); pango_layout_set_font_description(ctx->layout, font->desc); - pango_layout_get_pixel_extents(ctx->layout, NULL, &ext); x = area.x + pdata->margin.left; /* + 1 is added for rounding, so that in any case of doubt we rather draw * the text 1px lower than too high which usually results in a better type * face */ - y = area.y + (ctx->height - ext.height + 1) / 2 + pdata->margin.top; + y = area.y + (ctx->height - ext->height + 1) / 2 + pdata->margin.top; /* only honors alignment if enough space */ - if(ext.width < area.width) + if(ext->width < area.width) switch(pdata->align) { case AlignCenter: - x += (area.width - ext.width) / 2; + x += (area.width - ext->width) / 2; break; case AlignRight: - x += area.width - ext.width; + x += area.width - ext->width; break; default: break; @@ -860,7 +860,7 @@ draw_text_extents(font_t *font, const char *text, ssize_t len, draw_parser_data_ cairo_surface_destroy(surface); geom.width = ext.width; - geom.height = ext.height * 1.5; + geom.height = ext.height; return geom; } diff --git a/draw.h b/draw.h index fc0d4da8..443a1b52 100644 --- a/draw.h +++ b/draw.h @@ -177,7 +177,7 @@ typedef struct } border; } draw_parser_data_t; -void draw_text(draw_context_t *, font_t *, PangoEllipsizeMode, PangoWrapMode, area_t, const char *, ssize_t len, draw_parser_data_t *); +void draw_text(draw_context_t *, font_t *, PangoEllipsizeMode, PangoWrapMode, area_t, const char *, ssize_t len, draw_parser_data_t *, area_t *); void draw_rectangle(draw_context_t *, area_t, float, bool, const xcolor_t *); void draw_rectangle_gradient(draw_context_t *, area_t, float, bool, vector_t, const xcolor_t *, const xcolor_t *, const xcolor_t *); diff --git a/widgets/textbox.c b/widgets/textbox.c index ffe93c3e..35710d58 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -34,7 +34,7 @@ typedef struct /** Textbox width */ int width; /** Extents */ - int extents; + area_t extents; PangoEllipsizeMode ellip; PangoWrapMode wrap; /** Draw parser data */ @@ -55,7 +55,7 @@ textbox_geometry(widget_t *widget, int screen, int height, int width) geometry.width = width; else { - geometry.width = MIN(d->extents, width); + geometry.width = MIN(d->extents.width, width); if(d->pdata.bg_image) geometry.width = MAX(geometry.width, @@ -76,7 +76,7 @@ textbox_draw(widget_t *widget, draw_context_t *ctx, area_t geometry, int screen, wibox_t *p) { textbox_data_t *d = widget->data; - draw_text(ctx, globalconf.font, d->ellip, d->wrap, geometry, d->text, d->len, &d->pdata); + draw_text(ctx, globalconf.font, d->ellip, d->wrap, geometry, d->text, d->len, &d->pdata, &d->extents); } /** Delete a textbox widget. @@ -178,10 +178,10 @@ luaA_textbox_newindex(lua_State *L, awesome_token_t token) if(buf) { a_iso2utf8(&d->text, buf, len); - d->extents = draw_text_extents(globalconf.font, d->text, d->len, &d->pdata).width; + d->extents = draw_text_extents(globalconf.font, d->text, d->len, &d->pdata); } else - d->extents = 0; + p_clear(&d->extents, 1); } break; case A_TK_WIDTH: