simplify buf handling
This commit is contained in:
parent
e47521ef51
commit
1a643a20bd
|
@ -127,7 +127,7 @@ draw_text(DrawCtx *ctx,
|
||||||
{
|
{
|
||||||
int nw = 0;
|
int nw = 0;
|
||||||
ssize_t len, olen;
|
ssize_t len, olen;
|
||||||
char *buf, *utf8;
|
char *buf = NULL, *utf8 = NULL;
|
||||||
cairo_font_face_t *font_face;
|
cairo_font_face_t *font_face;
|
||||||
|
|
||||||
draw_rectangle(ctx, area, True, bg);
|
draw_rectangle(ctx, area, True, bg);
|
||||||
|
@ -135,17 +135,14 @@ draw_text(DrawCtx *ctx,
|
||||||
if(!(len = olen = a_strlen(text)))
|
if(!(len = olen = a_strlen(text)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* copy text to buffer */
|
|
||||||
buf = a_strdup(text);
|
|
||||||
|
|
||||||
/* try to convert it to UTF-8 */
|
/* try to convert it to UTF-8 */
|
||||||
if((utf8 = draw_iso2utf8(buf)))
|
if((utf8 = draw_iso2utf8(text)))
|
||||||
{
|
{
|
||||||
/* conversion success */
|
|
||||||
p_delete(&buf);
|
|
||||||
buf = utf8;
|
buf = utf8;
|
||||||
len = olen = a_strlen(buf);
|
len = olen = a_strlen(buf);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
buf = a_strdup(text);
|
||||||
|
|
||||||
/* check that the text is not too long */
|
/* check that the text is not too long */
|
||||||
while(len && (nw = (draw_textwidth(ctx->display, font, buf)) + padding * 2) > area.width)
|
while(len && (nw = (draw_textwidth(ctx->display, font, buf)) + padding * 2) > area.width)
|
||||||
|
@ -193,6 +190,7 @@ draw_text(DrawCtx *ctx,
|
||||||
cairo_show_text(ctx->cr, buf);
|
cairo_show_text(ctx->cr, buf);
|
||||||
|
|
||||||
cairo_font_face_destroy(font_face);
|
cairo_font_face_destroy(font_face);
|
||||||
|
|
||||||
p_delete(&buf);
|
p_delete(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue